aboutsummaryrefslogtreecommitdiff
path: root/src/or/geoip.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-03-18 12:44:37 -0400
committerNick Mathewson <nickm@torproject.org>2011-03-18 12:44:37 -0400
commit8b393afa94891cb7d4d0371ff38469fbabbe61b3 (patch)
treed2d2dcb2eb148b2d940e3b512e1a752c62e577d5 /src/or/geoip.c
parent1db6eb6cb7db46d8dde482f629fbc1c578310d52 (diff)
parentfe86be61b6d84fbb442b13aa52139e6a3892dac0 (diff)
downloadtor-8b393afa94891cb7d4d0371ff38469fbabbe61b3.tar.gz
tor-8b393afa94891cb7d4d0371ff38469fbabbe61b3.zip
Merge remote branch 'origin/maint-0.2.2'
Trivial Conflicts: configure.in
Diffstat (limited to 'src/or/geoip.c')
-rw-r--r--src/or/geoip.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c
index c99758e7f8..04289f312a 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -304,11 +304,18 @@ geoip_db_digest(void)
typedef struct clientmap_entry_t {
HT_ENTRY(clientmap_entry_t) node;
uint32_t ipaddr;
+ /** Time when we last saw this IP address, in MINUTES since the epoch.
+ *
+ * (This will run out of space around 4011 CE. If Tor is still in use around
+ * 4000 CE, please remember to add more bits to last_seen_in_minutes.) */
unsigned int last_seen_in_minutes:30;
unsigned int action:2;
} clientmap_entry_t;
-#define ACTION_MASK 3
+/** Largest allowable value for last_seen_in_minutes. (It's a 30-bit field,
+ * so it can hold up to (1u<<30)-1, or 0x3fffffffu.
+ */
+#define MAX_LAST_SEEN_IN_MINUTES 0X3FFFFFFFu
/** Map from client IP address to last time seen. */
static HT_HEAD(clientmap, clientmap_entry_t) client_history =
@@ -433,15 +440,16 @@ geoip_note_client_seen(geoip_client_action_t action,
lookup.ipaddr = addr;
lookup.action = (int)action;
ent = HT_FIND(clientmap, &client_history, &lookup);
- if (ent) {
- ent->last_seen_in_minutes = now / 60;
- } else {
+ if (! ent) {
ent = tor_malloc_zero(sizeof(clientmap_entry_t));
ent->ipaddr = addr;
- ent->last_seen_in_minutes = now / 60;
ent->action = (int)action;
HT_INSERT(clientmap, &client_history, ent);
}
+ if (now / 60 <= (int)MAX_LAST_SEEN_IN_MINUTES && now >= 0)
+ ent->last_seen_in_minutes = (unsigned)(now/60);
+ else
+ ent->last_seen_in_minutes = 0;
if (action == GEOIP_CLIENT_NETWORKSTATUS ||
action == GEOIP_CLIENT_NETWORKSTATUS_V2) {