Browse Source

Merge pull request #322 from switch-iot/fix_sn_purge_cmnt

Update purge logic of communities and edges for supernode
pull/329/head
Luca Deri 4 years ago
committed by GitHub
parent
commit
ceace349c6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      include/n2n_define.h
  2. 3
      src/n2n.c
  3. 49
      src/sn_utils.c

3
include/n2n_define.h

@ -35,6 +35,9 @@
#define IFACE_UPDATE_INTERVAL (30) /* sec. How long it usually takes to get an IP lease. */
#define TRANSOP_TICK_INTERVAL (10) /* sec */
#define PURGE_REGISTRATION_FREQUENCY 30
#define REGISTRATION_TIMEOUT 60
#define ETH_FRAMESIZE 14
#define IP4_SRCOFFSET 12
#define IP4_DSTOFFSET 16

3
src/n2n.c

@ -22,9 +22,6 @@
#include <assert.h>
#define PURGE_REGISTRATION_FREQUENCY 30
#define REGISTRATION_TIMEOUT 60
static const uint8_t broadcast_addr[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
static const uint8_t multicast_addr[6] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 }; /* First 3 bytes are meaningful */
static const uint8_t ipv6_multicast_addr[6] = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 }; /* First 2 bytes are meaningful */

49
src/sn_utils.c

@ -35,6 +35,10 @@ static int update_edge(n2n_sn_t *sss,
const n2n_sock_t *sender_sock,
time_t now);
static int purge_expired_communities(n2n_sn_t *sss,
time_t* p_last_purge,
time_t now);
static int process_mgmt(n2n_sn_t *sss,
const struct sockaddr_in *sender_sock,
const uint8_t *mgmt_buf,
@ -291,6 +295,35 @@ static int update_edge(n2n_sn_t *sss,
return 0;
}
static int purge_expired_communities(n2n_sn_t *sss,
time_t* p_last_purge,
time_t now)
{
struct sn_community *comm, *tmp;
size_t num_reg = 0;
if ((now - (*p_last_purge)) < PURGE_REGISTRATION_FREQUENCY) return 0;
traceEvent(TRACE_DEBUG, "Purging old communities and edges");
HASH_ITER(hh, sss->communities, comm, tmp) {
num_reg += purge_peer_list(&comm->edges, now - REGISTRATION_TIMEOUT);
if ((comm->edges == NULL) && (!sss->lock_communities)) {
traceEvent(TRACE_INFO, "Purging idle community %s", comm->community);
if (NULL != comm->header_encryption_ctx)
/* this should not happen as no 'locked' and thus only communities w/o encrypted header here */
free(comm->header_encryption_ctx);
HASH_DEL(sss->communities, comm);
free(comm);
}
}
(*p_last_purge) = now;
traceEvent(TRACE_DEBUG, "Remove %ld edges", num_reg);
return 0;
}
static int process_mgmt(n2n_sn_t *sss,
const struct sockaddr_in *sender_sock,
const uint8_t *mgmt_buf,
@ -781,7 +814,6 @@ int run_sn_loop(n2n_sn_t *sss, int *keep_running)
{
uint8_t pktbuf[N2N_SN_PKTBUF_SIZE];
time_t last_purge_edges = 0;
struct sn_community *comm, *tmp;
sss->start_time = time(NULL);
@ -866,20 +898,7 @@ int run_sn_loop(n2n_sn_t *sss, int *keep_running)
traceEvent(TRACE_DEBUG, "timeout");
}
HASH_ITER(hh, sss->communities, comm, tmp)
{
purge_expired_registrations(&comm->edges, &last_purge_edges);
if ((comm->edges == NULL) && (!sss->lock_communities))
{
traceEvent(TRACE_INFO, "Purging idle community %s", comm->community);
if (NULL != comm->header_encryption_ctx)
/* this should not happen as no 'locked' and thus only communities w/o encrypted header here */
free (comm->header_encryption_ctx);
HASH_DEL(sss->communities, comm);
free(comm);
}
}
purge_expired_communities(sss, &last_purge_edges, now);
} /* while */

Loading…
Cancel
Save