Browse Source

Fix purge_expired_registrations to accept passed-in last_purge instead of static function var.

pull/110/head
Jiang Zihao 6 years ago
committed by emanuele-f
parent
commit
0edca7e16a
  1. 6
      edge_utils.c
  2. 7
      n2n.c
  3. 2
      n2n.h
  4. 3
      sn.c

6
edge_utils.c

@ -1481,6 +1481,8 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
size_t numPurged; size_t numPurged;
time_t lastIfaceCheck=0; time_t lastIfaceCheck=0;
time_t lastTransop=0; time_t lastTransop=0;
time_t last_purge_known = 0;
time_t last_purge_pending = 0;
#ifdef __ANDROID_NDK__ #ifdef __ANDROID_NDK__
time_t lastArpPeriod=0; time_t lastArpPeriod=0;
#endif #endif
@ -1570,8 +1572,8 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
/* Finished processing select data. */ /* Finished processing select data. */
update_supernode_reg(eee, nowTime); update_supernode_reg(eee, nowTime);
numPurged = purge_expired_registrations(&(eee->known_peers)); numPurged = purge_expired_registrations(&(eee->known_peers), &last_purge_known);
numPurged += purge_expired_registrations(&(eee->pending_peers)); numPurged += purge_expired_registrations(&(eee->pending_peers), &last_purge_pending);
if(numPurged > 0) { if(numPurged > 0) {
traceEvent(TRACE_NORMAL, "Peer removed: pending=%u, operational=%u", traceEvent(TRACE_NORMAL, "Peer removed: pending=%u, operational=%u",

7
n2n.c

@ -314,18 +314,17 @@ void peer_list_add(struct peer_info * * 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) {
static time_t last_purge = 0;
time_t now = time(NULL); time_t now = time(NULL);
size_t num_reg = 0; 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"); traceEvent(TRACE_INFO, "Purging old registrations");
num_reg = purge_peer_list(peer_list, now-REGISTRATION_TIMEOUT); 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); traceEvent(TRACE_INFO, "Remove %ld registrations", num_reg);
return num_reg; return num_reg;

2
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, size_t purge_peer_list( struct peer_info ** peer_list,
time_t purge_before ); time_t purge_before );
size_t clear_peer_list( struct peer_info ** peer_list ); 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 */ /* Edge conf */
void edge_init_conf_defaults(n2n_edge_conf_t *conf); void edge_init_conf_defaults(n2n_edge_conf_t *conf);

3
sn.c

@ -950,6 +950,7 @@ int main(int argc, char * const argv[]) {
static int run_loop(n2n_sn_t * sss) { static int run_loop(n2n_sn_t * sss) {
uint8_t pktbuf[N2N_SN_PKTBUF_SIZE]; uint8_t pktbuf[N2N_SN_PKTBUF_SIZE];
int keep_running=1; int keep_running=1;
time_t last_purge_edges = 0;
sss->start_time = time(NULL); sss->start_time = time(NULL);
@ -1024,7 +1025,7 @@ static int run_loop(n2n_sn_t * sss) {
traceEvent(TRACE_DEBUG, "timeout"); traceEvent(TRACE_DEBUG, "timeout");
} }
purge_expired_registrations(&(sss->edges)); purge_expired_registrations( &(sss->edges), &last_purge_edges );
} /* while */ } /* while */

Loading…
Cancel
Save