#include <config.h>
gehe zum Quellcode dieser Datei
Makrodefinitionen | |
| #define | IPMAP_HOST 0 |
| #define | IPMAP_CITY 1 |
| #define | IPMAP_EXPIRE 2 |
| #define | IPMAP_STATUS 3 |
| #define | IPLOOKUP_HOST "127.0.0.1" |
| #define | IPLOOKUP_PORT 8711 |
| #define | IPLOOKUP_SAVE "/p/daemon/save/iplookup" |
| #define | STATUS_QUERYING 1 |
| #define | STATUS_AUTHORITATIVE 128 |
| #define | CACHE_TIME 86400 |
| #define | LARGE_CACHE_LIMIT 2000 |
| #define | QUERY_TIME 60 |
| #define | LOG(x) log_file("rumata/iplookup.log",strftime("%Y-%m-%d %H:%M:%S: ")+(x)+"\n") |
| #define | SEARCHING "<auf der Suche...>" |
Funktionen | |
| public void | create () |
| public void | reset () |
| static int | active_entry (string key, mixed *data) |
| static void | expire_cache_small () |
| static void | expire_cache_large (string *keys) |
| public void | update (string udp_reply) |
| static void | make_request (string ipnum) |
| public string | country (mixed ipnum) |
| public string | host (mixed ipnum) |
Variablen | |
| private mapping | ipmap |
| #define CACHE_TIME 86400 |
Definiert in Zeile 39 der Datei iplookup.c.
Wird benutzt von update().
| #define IPLOOKUP_HOST "127.0.0.1" |
Definiert in Zeile 30 der Datei iplookup.c.
Wird benutzt von make_request().
| #define IPLOOKUP_PORT 8711 |
Definiert in Zeile 31 der Datei iplookup.c.
Wird benutzt von make_request().
| #define IPLOOKUP_SAVE "/p/daemon/save/iplookup" |
Definiert in Zeile 32 der Datei iplookup.c.
| #define IPMAP_CITY 1 |
Definiert in Zeile 25 der Datei iplookup.c.
| #define IPMAP_EXPIRE 2 |
Definiert in Zeile 26 der Datei iplookup.c.
Wird benutzt von active_entry().
| #define IPMAP_HOST 0 |
Definiert in Zeile 24 der Datei iplookup.c.
| #define IPMAP_STATUS 3 |
Definiert in Zeile 27 der Datei iplookup.c.
| #define LARGE_CACHE_LIMIT 2000 |
Definiert in Zeile 43 der Datei iplookup.c.
Wird benutzt von reset().
| #define LOG | ( | x | ) | log_file("rumata/iplookup.log",strftime("%Y-%m-%d %H:%M:%S: ")+(x)+"\n") |
Definiert in Zeile 50 der Datei iplookup.c.
| #define QUERY_TIME 60 |
Definiert in Zeile 46 der Datei iplookup.c.
Wird benutzt von make_request().
| #define SEARCHING "<auf der Suche...>" |
Definiert in Zeile 119 der Datei iplookup.c.
Wird benutzt von country() und make_request().
| #define STATUS_AUTHORITATIVE 128 |
Definiert in Zeile 36 der Datei iplookup.c.
Wird benutzt von update().
| #define STATUS_QUERYING 1 |
Definiert in Zeile 35 der Datei iplookup.c.
Wird benutzt von make_request().
| static int active_entry | ( | string | key, | |
| mixed * | data | |||
| ) | [static] |
Definiert in Zeile 87 der Datei iplookup.c.
Benutzt IPMAP_EXPIRE.
00087 { 00088 return time() < data[IPMAP_EXPIRE]; 00089 }
| public string country | ( | mixed | ipnum | ) |
Definiert in Zeile 138 der Datei iplookup.c.
Benutzt expire(), host(), ipmap, make_request(), query_ip_number() und SEARCHING.
Wird benutzt von country(), efun_country(), finger_single(), get_location(), is_in(), QueryView() und scan().
00138 { 00139 string host,city; 00140 int expire,state; 00141 00142 if( objectp(ipnum) ) { 00143 ipnum = query_ip_number(ipnum); 00144 } 00145 if( !stringp(ipnum) ) { 00146 return "<undefined>"; 00147 } 00148 if( !m_contains( &host, &city, &expire, &state, ipmap, ipnum ) ) { 00149 make_request( ipnum ); 00150 return SEARCHING; 00151 } 00152 00153 return city; 00154 }


| public void create | ( | ) |
Definiert in Zeile 66 der Datei iplookup.c.
Benutzt IPLOOKUP_SAVE, ipmap, LOG und restore_object().
00066 { 00067 seteuid(getuid()); 00068 restore_object( IPLOOKUP_SAVE ); 00069 00070 if( !mappingp(ipmap) || widthof(ipmap)!=4 ) { 00071 ipmap = m_allocate( 0, 4 ); 00072 LOG("restore failed, creating new ipmap"); 00073 } else { 00074 LOG(sprintf("created (%d entries)",sizeof(ipmap))); 00075 } 00076 }

| static void expire_cache_large | ( | string * | keys | ) | [static] |
Definiert in Zeile 100 der Datei iplookup.c.
Wird benutzt von reset().
00100 { 00101 if( !pointerp(keys) ) return; 00102 int next=0; 00103 foreach( string key: keys ) { 00104 if( get_eval_cost() < 100000 ) break; 00105 if( ipmap[key,IPMAP_EXPIRE] < time() ) { 00106 efun::m_delete( ipmap, key ); 00107 } 00108 next++; 00109 } 00110 LOG(sprintf("checking %d of %d",next,sizeof(keys))); 00111 if( next<sizeof(keys) ) { 00112 call_out( #'expire_cache_large, 6, keys[next..] ); 00113 } else { 00114 save_object( IPLOOKUP_SAVE ); 00115 LOG(sprintf("reset -> %d (done)",sizeof(ipmap))); 00116 } 00117 }

| static void expire_cache_small | ( | ) | [static] |
Definiert in Zeile 92 der Datei iplookup.c.
Benutzt ipmap.
Wird benutzt von reset().
00092 { 00093 int s = sizeof(ipmap); 00094 ipmap = filter( ipmap, #'active_entry ); 00095 save_object( IPLOOKUP_SAVE ); 00096 LOG(sprintf("reset (%d -> %d)",s,sizeof(ipmap))); 00097 }

| public string host | ( | mixed | ipnum | ) |
Definiert in Zeile 162 der Datei iplookup.c.
Benutzt expire(), ipmap, make_request() und query_ip_number().
Wird benutzt von country().
00162 { 00163 string host,city; 00164 int expire,state; 00165 00166 if( objectp(ipnum) ) { 00167 ipnum = query_ip_number(ipnum); 00168 } 00169 if( !stringp(ipnum) ) { 00170 return "<undefined>"; 00171 } 00172 if( !m_contains( &host, &city, &expire, &state, ipmap, ipnum ) ) { 00173 make_request( ipnum ); 00174 return ipnum; 00175 } 00176 00177 return host; 00178 }


| static void make_request | ( | string | ipnum | ) | [static] |
Definiert in Zeile 125 der Datei iplookup.c.
Benutzt IPLOOKUP_HOST, IPLOOKUP_PORT, ipmap, QUERY_TIME, SEARCHING und STATUS_QUERYING.
Wird benutzt von country() und host().
00125 { 00126 send_udp( IPLOOKUP_HOST, IPLOOKUP_PORT, ipnum ); 00127 ipmap += ([ ipnum : ipnum ; SEARCHING ; 00128 time()+QUERY_TIME ; STATUS_QUERYING 00129 ]); 00130 }

| public void reset | ( | void | ) |
Definiert in Zeile 78 der Datei iplookup.c.
Benutzt expire_cache_large(), expire_cache_small(), ipmap, LARGE_CACHE_LIMIT und LOG.
00078 { 00079 if( sizeof(ipmap) < LARGE_CACHE_LIMIT ) { 00080 expire_cache_small(); 00081 } else { 00082 LOG(sprintf("reset %d ->",sizeof(ipmap))); 00083 expire_cache_large( m_indices(ipmap) ); 00084 } 00085 }

| public void update | ( | string | udp_reply | ) |
Definiert in Zeile 183 der Datei iplookup.c.
Benutzt CACHE_TIME, IPLOOKUP_SAVE, ipmap, master, save_object() und STATUS_AUTHORITATIVE.
00183 { 00184 string* reply; 00185 if( previous_object()!=master() ) return; 00186 reply = explode(udp_reply,"\n"); 00187 if( sizeof(reply)<4 ) return; 00188 00189 if( reply[3] == "<unknown>" ) reply[3] = reply[1]; 00190 if( reply[2] == "<unknown>" ) reply[2] = "irgendwoher"; 00191 ipmap += ([ reply[1] : reply[3] ; reply[2] ; time()+CACHE_TIME ; 00192 STATUS_AUTHORITATIVE ]); 00193 save_object( IPLOOKUP_SAVE ); 00194 }

| private mapping ipmap |
Definiert in Zeile 23 der Datei iplookup.c.
Wird benutzt von country(), create(), expire_cache_small(), host(), make_request(), reset() und update().
1.6.3