diff --git a/edge_utils.c b/edge_utils.c index 4a28ff0..728be79 100644 --- a/edge_utils.c +++ b/edge_utils.c @@ -1481,6 +1481,8 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) { size_t numPurged; time_t lastIfaceCheck=0; time_t lastTransop=0; + time_t last_purge_known = 0; + time_t last_purge_pending = 0; #ifdef __ANDROID_NDK__ time_t lastArpPeriod=0; #endif @@ -1570,8 +1572,8 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) { /* Finished processing select data. */ update_supernode_reg(eee, nowTime); - numPurged = purge_expired_registrations(&(eee->known_peers)); - numPurged += purge_expired_registrations(&(eee->pending_peers)); + numPurged = purge_expired_registrations(&(eee->known_peers), &last_purge_known); + numPurged += purge_expired_registrations(&(eee->pending_peers), &last_purge_pending); if(numPurged > 0) { traceEvent(TRACE_NORMAL, "Peer removed: pending=%u, operational=%u", diff --git a/n2n.c b/n2n.c index c105bda..b17cff9 100644 --- a/n2n.c +++ b/n2n.c @@ -314,18 +314,17 @@ void peer_list_add(struct peer_info * * list, } -size_t purge_expired_registrations(struct peer_info ** peer_list) { - static time_t last_purge = 0; +size_t purge_expired_registrations(struct peer_info ** peer_list, time_t* p_last_purge) { time_t now = time(NULL); size_t num_reg = 0; - if((now - last_purge) < PURGE_REGISTRATION_FREQUENCY) return 0; + if((now - (*p_last_purge)) < PURGE_REGISTRATION_FREQUENCY) return 0; traceEvent(TRACE_INFO, "Purging old registrations"); num_reg = purge_peer_list(peer_list, now-REGISTRATION_TIMEOUT); - last_purge = now; + (*p_last_purge) = now; traceEvent(TRACE_INFO, "Remove %ld registrations", num_reg); return num_reg; diff --git a/n2n.h b/n2n.h index daebde3..3c7b4da 100644 --- a/n2n.h +++ b/n2n.h @@ -279,7 +279,7 @@ size_t peer_list_size( const struct peer_info * list ); size_t purge_peer_list( struct peer_info ** peer_list, time_t purge_before ); size_t clear_peer_list( struct peer_info ** peer_list ); -size_t purge_expired_registrations( struct peer_info ** peer_list ); +size_t purge_expired_registrations( struct peer_info ** peer_list, time_t* p_last_purge ); /* Edge conf */ void edge_init_conf_defaults(n2n_edge_conf_t *conf); diff --git a/sn.c b/sn.c index e96a704..86c4b3b 100644 --- a/sn.c +++ b/sn.c @@ -950,6 +950,7 @@ int main(int argc, char * const argv[]) { static int run_loop(n2n_sn_t * sss) { uint8_t pktbuf[N2N_SN_PKTBUF_SIZE]; int keep_running=1; + time_t last_purge_edges = 0; sss->start_time = time(NULL); @@ -1024,7 +1025,7 @@ static int run_loop(n2n_sn_t * sss) { traceEvent(TRACE_DEBUG, "timeout"); } - purge_expired_registrations(&(sss->edges)); + purge_expired_registrations( &(sss->edges), &last_purge_edges ); } /* while */