[or-cvs] r12847: clean up whitesapce and debug a little on geoip stuff. (in tor/trunk: . doc src/or)
nickm at seul.org
nickm at seul.org
Mon Dec 17 22:44:19 UTC 2007
Author: nickm
Date: 2007-12-17 17:44:18 -0500 (Mon, 17 Dec 2007)
New Revision: 12847
Modified:
tor/trunk/
tor/trunk/doc/TODO
tor/trunk/src/or/control.c
tor/trunk/src/or/geoip.c
tor/trunk/src/or/or.h
tor/trunk/src/or/router.c
Log:
r15532 at tombo: nickm | 2007-12-17 17:41:05 -0500
clean up whitesapce and debug a little on geoip stuff.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r15532] on d9e39d38-0f13-419c-a857-e10a0ce2aa0c
Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO 2007-12-17 22:44:16 UTC (rev 12846)
+++ tor/trunk/doc/TODO 2007-12-17 22:44:18 UTC (rev 12847)
@@ -38,11 +38,12 @@
o Code to store a GEOIP file in memory.
o Code to remember client IPs.
o Code to generate history lines
- - Controller interface
+ o Controller interface
- Track consecutive time up, not time since last-forgotten IP.
- Add log lines.
- Tests
- Mention in dir-spec.txt
+ - Mention in control-spec.txt
d let Vidalia use the geoip data too rather than doing its own
anonymized queries
o bridge address disbursal strategies
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2007-12-17 22:44:16 UTC (rev 12846)
+++ tor/trunk/src/or/control.c 2007-12-17 22:44:18 UTC (rev 12847)
@@ -1783,7 +1783,7 @@
PREFIX("dir/status/", dir,"Networkstatus docs as retrieved from a DirPort."),
PREFIX("exit-policy/default", policies,
"The default value appended to the configured exit policy."),
-
+ PREFIX("ip-to-country/", geoip, "Perform a GEOIP lookup"),
{ NULL, NULL, NULL, 0 }
};
Modified: tor/trunk/src/or/geoip.c
===================================================================
--- tor/trunk/src/or/geoip.c 2007-12-17 22:44:16 UTC (rev 12846)
+++ tor/trunk/src/or/geoip.c 2007-12-17 22:44:18 UTC (rev 12847)
@@ -31,11 +31,12 @@
char *c = tor_strdup(country);
tor_strlower(c);
smartlist_add(geoip_countries, c);
- idx = smartlist_len(geoip_countries) + 1;
+ idx = smartlist_len(geoip_countries) - 1;
strmap_set_lc(country_idxplus1_by_lc_code, country, (void*)(idx+1));
} else {
idx = ((uintptr_t)_idxplus1)-1;
}
+ tor_assert(!strcasecmp(smartlist_get(geoip_countries, idx), country));
ent = tor_malloc_zero(sizeof(geoip_entry_t));
ent->ip_low = low;
ent->ip_high = high;
@@ -80,19 +81,24 @@
geoip_countries = smartlist_create();
geoip_entries = smartlist_create();
country_idxplus1_by_lc_code = strmap_new();
+ log_info(LD_GENERAL, "Parsing GEOIP file.");
while (!feof(f)) {
char buf[512];
unsigned int low, high;
char b[3];
if (fgets(buf, sizeof(buf), f) == NULL)
break;
+ /* XXXX020 track full country name. */
if (sscanf(buf,"%u,%u,%2s", &low, &high, b) == 3) {
geoip_add_entry(low, high, b);
} else if (sscanf(buf,"\"%u\",\"%u\",\"%2s\",", &low, &high, b) == 3) {
geoip_add_entry(low, high, b);
+ } else {
+ log_warn(LD_GENERAL, "Unable to parse line from GEOIP file: %s",
+ escaped(buf));
}
}
- /*XXXX020 abort and return -1 if */
+ /*XXXX020 abort and return -1 if no entries/illformed?*/
fclose(f);
smartlist_sort(geoip_entries, _geoip_compare_entries);
@@ -257,6 +263,24 @@
return result;
}
+int
+getinfo_helper_geoip(control_connection_t *control_conn,
+ const char *question, char **answer)
+{
+ (void)control_conn;
+ if (geoip_is_loaded() && !strcmpstart(question, "ip-to-country/")) {
+ int c;
+ uint32_t ip;
+ struct in_addr in;
+ question += strlen("ip-to-country/");
+ if (tor_inet_aton(question, &in) != 0) {
+ ip = ntohl(in.s_addr);
+ c = geoip_get_country_by_ip(ip);
+ *answer = tor_strdup(geoip_get_country_name(c));
+ }
+ }
+ return 0;
+}
void
geoip_free_all(void)
@@ -284,3 +308,4 @@
country_idxplus1_by_lc_code = NULL;
geoip_entries = NULL;
}
+
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2007-12-17 22:44:16 UTC (rev 12846)
+++ tor/trunk/src/or/or.h 2007-12-17 22:44:18 UTC (rev 12847)
@@ -3210,6 +3210,8 @@
void geoip_remove_old_clients(time_t cutoff);
time_t geoip_get_history_start(void);
char *geoip_get_client_history(time_t now);
+int getinfo_helper_geoip(control_connection_t *control_conn,
+ const char *question, char **answer);
void geoip_free_all(void);
/********************************* hibernate.c **********************/
Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c 2007-12-17 22:44:16 UTC (rev 12846)
+++ tor/trunk/src/or/router.c 2007-12-17 22:44:18 UTC (rev 12847)
@@ -1731,7 +1731,6 @@
}
}
-
len = strlen(s);
strlcat(s+len, "router-signature\n", maxlen-len);
len += strlen(s+len);
More information about the tor-commits
mailing list