Use libevent to age past requests.

This commit is contained in:
Guus Sliepen 2007-05-17 23:14:42 +00:00
parent aaf1851315
commit a530f94e7c
3 changed files with 24 additions and 17 deletions

View file

@ -485,8 +485,6 @@ int main_loop(void)
if(routing_mode == RMODE_SWITCH) if(routing_mode == RMODE_SWITCH)
age_subnets(); age_subnets();
age_past_requests();
/* Should we regenerate our key? */ /* Should we regenerate our key? */
if(keyexpires < now) { if(keyexpires < now) {

View file

@ -195,19 +195,7 @@ static void free_past_request(past_request_t *r)
free(r); free(r);
} }
void init_requests(void) static struct event past_request_event;
{
cp();
past_request_tree = avl_alloc_tree((avl_compare_t) past_request_compare, (avl_action_t) free_past_request);
}
void exit_requests(void)
{
cp();
avl_delete_tree(past_request_tree);
}
bool seen_request(char *request) bool seen_request(char *request)
{ {
@ -225,11 +213,12 @@ bool seen_request(char *request)
new->request = xstrdup(request); new->request = xstrdup(request);
new->firstseen = now; new->firstseen = now;
avl_insert(past_request_tree, new); avl_insert(past_request_tree, new);
event_add(&past_request_event, &(struct timeval){10, 0});
return false; return false;
} }
} }
void age_past_requests(void) void age_past_requests(int fd, short events, void *data)
{ {
avl_node_t *node, *next; avl_node_t *node, *next;
past_request_t *p; past_request_t *p;
@ -250,4 +239,25 @@ void age_past_requests(void)
if(left || deleted) if(left || deleted)
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Aging past requests: deleted %d, left %d"), ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Aging past requests: deleted %d, left %d"),
deleted, left); deleted, left);
if(left)
event_add(&past_request_event, &(struct timeval){10, 0});
}
void init_requests(void)
{
cp();
past_request_tree = avl_alloc_tree((avl_compare_t) past_request_compare, (avl_action_t) free_past_request);
timeout_set(&past_request_event, age_past_requests, NULL);
}
void exit_requests(void)
{
cp();
avl_delete_tree(past_request_tree);
event_del(&past_request_event);
} }

View file

@ -79,7 +79,6 @@ extern bool check_id(const char *);
extern void init_requests(void); extern void init_requests(void);
extern void exit_requests(void); extern void exit_requests(void);
extern bool seen_request(char *); extern bool seen_request(char *);
extern void age_past_requests(void);
/* Requests */ /* Requests */