mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 06:33:44 +01:00
Futz with the clang patch a bit and tidy some geoip.c stuff
This commit is contained in:
parent
56bdc844ba
commit
547635c004
@ -278,19 +278,24 @@ geoip_is_loaded(void)
|
|||||||
return geoip_countries != NULL && geoip_entries != NULL;
|
return geoip_countries != NULL && geoip_entries != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_LAST_SEEN_IN_MINUTES 0x3FFFFFFFu
|
|
||||||
|
|
||||||
/** Entry in a map from IP address to the last time we've seen an incoming
|
/** Entry in a map from IP address to the last time we've seen an incoming
|
||||||
* connection from that IP address. Used by bridges only, to track which
|
* connection from that IP address. Used by bridges only, to track which
|
||||||
* countries have them blocked. */
|
* countries have them blocked. */
|
||||||
typedef struct clientmap_entry_t {
|
typedef struct clientmap_entry_t {
|
||||||
HT_ENTRY(clientmap_entry_t) node;
|
HT_ENTRY(clientmap_entry_t) node;
|
||||||
uint32_t ipaddr;
|
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 last_seen_in_minutes:30;
|
||||||
unsigned int action:2;
|
unsigned int action:2;
|
||||||
} clientmap_entry_t;
|
} 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. */
|
/** Map from client IP address to last time seen. */
|
||||||
static HT_HEAD(clientmap, clientmap_entry_t) client_history =
|
static HT_HEAD(clientmap, clientmap_entry_t) client_history =
|
||||||
@ -415,16 +420,16 @@ geoip_note_client_seen(geoip_client_action_t action,
|
|||||||
lookup.ipaddr = addr;
|
lookup.ipaddr = addr;
|
||||||
lookup.action = (int)action;
|
lookup.action = (int)action;
|
||||||
ent = HT_FIND(clientmap, &client_history, &lookup);
|
ent = HT_FIND(clientmap, &client_history, &lookup);
|
||||||
tor_assert(now / 60 <= MAX_LAST_SEEN_IN_MINUTES);
|
if (! ent) {
|
||||||
if (ent) {
|
|
||||||
ent->last_seen_in_minutes = (unsigned)(now/60);
|
|
||||||
} else {
|
|
||||||
ent = tor_malloc_zero(sizeof(clientmap_entry_t));
|
ent = tor_malloc_zero(sizeof(clientmap_entry_t));
|
||||||
ent->ipaddr = addr;
|
ent->ipaddr = addr;
|
||||||
ent->last_seen_in_minutes = (unsigned)(now/60);
|
|
||||||
ent->action = (int)action;
|
ent->action = (int)action;
|
||||||
HT_INSERT(clientmap, &client_history, ent);
|
HT_INSERT(clientmap, &client_history, ent);
|
||||||
}
|
}
|
||||||
|
if (now / 60 <= 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 ||
|
if (action == GEOIP_CLIENT_NETWORKSTATUS ||
|
||||||
action == GEOIP_CLIENT_NETWORKSTATUS_V2) {
|
action == GEOIP_CLIENT_NETWORKSTATUS_V2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user