@ -403,7 +403,7 @@ static int update_edge (n2n_sn_t *sss,
if ( NULL = = scan ) {
/* Not known */
if ( skip_add = = SN_ADD ) {
scan = ( struct peer_info * ) calloc ( 1 , sizeof ( struct peer_info ) ) ; /* deallocated in purge_expired_registration s */
scan = ( struct peer_info * ) calloc ( 1 , sizeof ( struct peer_info ) ) ; /* deallocated in purge_expired_node s */
memcpy ( & ( scan - > mac_addr ) , reg - > edgeMac , sizeof ( n2n_mac_t ) ) ;
scan - > dev_addr . net_addr = reg - > dev_addr . net_addr ;
scan - > dev_addr . net_bitlen = reg - > dev_addr . net_bitlen ;
@ -658,16 +658,20 @@ static int re_register_and_purge_supernodes (n2n_sn_t *sss, struct sn_community
return 0 ;
}
// purge long-time-not-seen supernodes
purge_expired_nodes ( & ( comm - > edges ) , p_last_re_reg_and_purge ,
RE_REG_AND_PURGE_FREQUENCY , LAST_SEEN_SN_INACTIVE ) ;
if ( comm ! = NULL ) {
HASH_ITER ( hh , comm - > edges , peer , tmp ) {
time = now - peer - > last_seen ;
if ( time < = LAST_SEEN_SN_ACTIVE ) {
continue ;
}
if ( ( time < LAST_SEEN_SN_INACTIVE )
| | ( peer - > purgeable = = SN_UNPURGEABLE ) ) {
/* re-regitser (send REGISTER_SUPER) */
/* re-register (send REGISTER_SUPER) */
uint8_t pktbuf [ N2N_PKT_BUF_SIZE ] = { 0 } ;
size_t idx ;
/* ssize_t sent; */
@ -708,17 +712,12 @@ static int re_register_and_purge_supernodes (n2n_sn_t *sss, struct sn_community
/* sent = */ sendto_sock ( sss , & ( peer - > sock ) , pktbuf , idx ) ;
}
if ( time > = LAST_SEEN_SN_INACTIVE ) {
purge_expired_registrations ( & ( comm - > edges ) , & time , LAST_SEEN_SN_INACTIVE ) ; /* purge not-seen-long-time supernodes*/
}
}
}
( * p_last_re_reg_and_purge ) = now ;
return 0 ; /* OK */
}
static int purge_expired_communities ( n2n_sn_t * sss ,
time_t * p_last_purge ,
time_t now ) {
@ -733,6 +732,10 @@ static int purge_expired_communities (n2n_sn_t *sss,
traceEvent ( TRACE_DEBUG , " Purging old communities and edges " ) ;
HASH_ITER ( hh , sss - > communities , comm , tmp ) {
// federation is taken care of in re_register_and_purge_supernodes()
if ( comm - > is_federation = = IS_FEDERATION )
continue ;
num_reg + = purge_peer_list ( & comm - > edges , now - REGISTRATION_TIMEOUT ) ;
if ( ( comm - > edges = = NULL ) & & ( comm - > purgeable = = COMMUNITY_PURGEABLE ) ) {
traceEvent ( TRACE_INFO , " Purging idle community %s " , comm - > community ) ;
@ -1306,8 +1309,6 @@ static int process_udp (n2n_sn_t * sss,
p = add_sn_to_list_by_mac_or_sock ( & ( sss - > federation - > edges ) , & ( ack . sock ) , reg . edgeMac , & skip_add ) ;
}
// REVISIT: consider adding last_seen
/* Skip random numbers of supernodes before payload assembling, calculating an appropriate random_number.
* That way , all supernodes have a chance to be propagated with REGISTER_SUPER_ACK . */
skip = HASH_COUNT ( sss - > federation - > edges ) - ( int ) ( REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE / REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE ) ;
@ -1321,7 +1322,7 @@ static int process_udp (n2n_sn_t * sss,
continue ;
}
if ( memcmp ( & ( peer - > sock ) , & ( ack . sock ) , sizeof ( n2n_sock_t ) ) = = 0 ) continue ; /* a supernode doesn't add itself to the payload */
if ( ( now - peer - > last_seen ) > = ( 2 * LAST_SEEN_SN_ACTIVE ) ) continue ; /* skip long-time-not-seen supernodes.
if ( ( now - peer - > last_seen ) > = LAST_SEEN_SN_NEW ) continue ; /* skip long-time-not-seen supernodes.
* We need to allow for a little extra time because supernodes sometimes exceed
* their SN_ACTIVE time before they get re - registred to . */
if ( ( ( + + num ) * REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE ) > REG_SUPER_ACK_PAYLOAD_SPACE ) break ; /* no more space available in REGISTER_SUPER_ACK payload */