]> git.meshlink.io Git - meshlink/commitdiff
Use libevent to age past requests.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 17 May 2007 23:14:42 +0000 (23:14 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 17 May 2007 23:14:42 +0000 (23:14 +0000)
src/net.c
src/protocol.c
src/protocol.h

index b1b7a2f96a1de2364c2c66bcf0e53503aed1513f..e09734cf84779e7f08887df1929a7679030387c7 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -485,8 +485,6 @@ int main_loop(void)
                        if(routing_mode == RMODE_SWITCH)
                                age_subnets();
 
-                       age_past_requests();
-
                        /* Should we regenerate our key? */
 
                        if(keyexpires < now) {
index 2e93cff40582a0673840f26b97f10813cdc251ff..93f27514bcac73c4a685282334509647cd97a23e 100644 (file)
@@ -195,19 +195,7 @@ static void free_past_request(past_request_t *r)
        free(r);
 }
 
-void init_requests(void)
-{
-       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);
-}
+static struct event past_request_event;
 
 bool seen_request(char *request)
 {
@@ -225,11 +213,12 @@ bool seen_request(char *request)
                new->request = xstrdup(request);
                new->firstseen = now;
                avl_insert(past_request_tree, new);
+               event_add(&past_request_event, &(struct timeval){10, 0});
                return false;
        }
 }
 
-void age_past_requests(void)
+void age_past_requests(int fd, short events, void *data)
 {
        avl_node_t *node, *next;
        past_request_t *p;
@@ -250,4 +239,25 @@ void age_past_requests(void)
        if(left || deleted)
                ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Aging past requests: deleted %d, left %d"),
                           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);
 }
index 0664d4cfcd2b615b49ee13d40469d7d3eed00ac6..ab4ed78dc53427e53204afab483330d7ac31a728 100644 (file)
@@ -79,7 +79,6 @@ extern bool check_id(const char *);
 extern void init_requests(void);
 extern void exit_requests(void);
 extern bool seen_request(char *);
-extern void age_past_requests(void);
 
 /* Requests */