|
@ -205,7 +205,7 @@ static int try_broadcast(n2n_sn_t * sss, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** Initialise some fields of the community structure **/ |
|
|
/** Initialise some fields of the community structure **/ |
|
|
int comm_init(struct sn_community *comm, char *cmn){ |
|
|
int comm_init(struct sn_community *comm, char *cmn) { |
|
|
|
|
|
|
|
|
strncpy((char*)comm->community, cmn, N2N_COMMUNITY_SIZE-1); |
|
|
strncpy((char*)comm->community, cmn, N2N_COMMUNITY_SIZE-1); |
|
|
comm->community[N2N_COMMUNITY_SIZE-1] = '\0'; |
|
|
comm->community[N2N_COMMUNITY_SIZE-1] = '\0'; |
|
@ -241,7 +241,7 @@ int sn_init(n2n_sn_t *sss) { |
|
|
sss->federation = (struct sn_community *)calloc(1,sizeof(struct sn_community)); |
|
|
sss->federation = (struct sn_community *)calloc(1,sizeof(struct sn_community)); |
|
|
|
|
|
|
|
|
/* Initialize the federation */ |
|
|
/* Initialize the federation */ |
|
|
if(sss->federation){ |
|
|
if(sss->federation) { |
|
|
strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE-1); |
|
|
strncpy(sss->federation->community, (char*)FEDERATION_NAME, N2N_COMMUNITY_SIZE-1); |
|
|
sss->federation->community[N2N_COMMUNITY_SIZE-1] = '\0'; |
|
|
sss->federation->community[N2N_COMMUNITY_SIZE-1] = '\0'; |
|
|
/* enable the flag for federation */ |
|
|
/* enable the flag for federation */ |
|
@ -256,7 +256,7 @@ int sn_init(n2n_sn_t *sss) { |
|
|
n2n_srand (n2n_seed()); |
|
|
n2n_srand (n2n_seed()); |
|
|
|
|
|
|
|
|
/* Random MAC address */ |
|
|
/* Random MAC address */ |
|
|
for(i=0; i<6; i++){ |
|
|
for(i=0; i<6; i++) { |
|
|
sss->mac_addr[i] = n2n_rand(); |
|
|
sss->mac_addr[i] = n2n_rand(); |
|
|
} |
|
|
} |
|
|
sss->mac_addr[0] &= ~0x01; /* Clear multicast bit */ |
|
|
sss->mac_addr[0] &= ~0x01; /* Clear multicast bit */ |
|
@ -510,16 +510,19 @@ static int find_edge_time_stamp_and_verify (struct peer_info * edges, |
|
|
return ( time_stamp_verify_and_update (stamp, previous_stamp, allow_jitter) ); |
|
|
return ( time_stamp_verify_and_update (stamp, previous_stamp, allow_jitter) ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int re_register_and_purge_supernodes(n2n_sn_t *sss, struct sn_community *comm, time_t now) { |
|
|
static int re_register_and_purge_supernodes(n2n_sn_t *sss, struct sn_community *comm, time_t now){ |
|
|
|
|
|
time_t time; |
|
|
time_t time; |
|
|
struct peer_info *peer, *tmp; |
|
|
struct peer_info *peer, *tmp; |
|
|
|
|
|
|
|
|
if(comm != NULL){ |
|
|
if(comm != NULL) { |
|
|
HASH_ITER(hh,comm->edges,peer,tmp){ |
|
|
HASH_ITER(hh,comm->edges,peer,tmp) { |
|
|
time = now - peer->last_seen; |
|
|
time = now - peer->last_seen; |
|
|
if(time <= ALLOWED_TIME) continue; |
|
|
if(time <= ALLOWED_TIME) continue; |
|
|
if((time < PURGE_FEDERATION_NODE_INTERVAL) || (peer->purgeable == SN_UNPURGEABLE)){ /* re-regitser (send REGISTER_SUPER) */ |
|
|
|
|
|
|
|
|
if((time < PURGE_FEDERATION_NODE_INTERVAL) |
|
|
|
|
|
|| (peer->purgeable == SN_UNPURGEABLE) /* FIX fcarli3 */ |
|
|
|
|
|
) { |
|
|
|
|
|
/* re-regitser (send REGISTER_SUPER) */ |
|
|
uint8_t pktbuf[N2N_PKT_BUF_SIZE] = {0}; |
|
|
uint8_t pktbuf[N2N_PKT_BUF_SIZE] = {0}; |
|
|
size_t idx; |
|
|
size_t idx; |
|
|
/* ssize_t sent; */ |
|
|
/* ssize_t sent; */ |
|
@ -561,7 +564,7 @@ static int re_register_and_purge_supernodes(n2n_sn_t *sss, struct sn_community * |
|
|
} |
|
|
} |
|
|
if(time >= PURGE_FEDERATION_NODE_INTERVAL) purge_expired_registrations(&(comm->edges),&time,PURGE_FEDERATION_NODE_INTERVAL);/* purge not-seen-long-time supernodes*/ |
|
|
if(time >= PURGE_FEDERATION_NODE_INTERVAL) purge_expired_registrations(&(comm->edges),&time,PURGE_FEDERATION_NODE_INTERVAL);/* purge not-seen-long-time supernodes*/ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 0; /* OK */ |
|
|
return 0; /* OK */ |
|
|
} |
|
|
} |
|
@ -733,29 +736,29 @@ static int sendto_mgmt(n2n_sn_t *sss, |
|
|
/** Search for a node in the federation list. If it has to add a new node, it creates a new peer_info and initializes it
|
|
|
/** Search for a node in the federation list. If it has to add a new node, it creates a new peer_info and initializes it
|
|
|
* Evaluate first the MAC parameter and if it's zero-MAC, then it can skip HASH_FIND_PEER by MAC and search by socket |
|
|
* Evaluate first the MAC parameter and if it's zero-MAC, then it can skip HASH_FIND_PEER by MAC and search by socket |
|
|
*/ |
|
|
*/ |
|
|
struct peer_info* add_sn_to_federation_by_mac_or_sock(n2n_sn_t *sss,n2n_sock_t *sock, n2n_mac_t *mac){ |
|
|
struct peer_info* add_sn_to_federation_by_mac_or_sock(n2n_sn_t *sss,n2n_sock_t *sock, n2n_mac_t *mac) { |
|
|
struct peer_info *scan, *tmp, *peer; |
|
|
struct peer_info *scan, *tmp, *peer; |
|
|
int found = 0; |
|
|
int found = 0; |
|
|
|
|
|
|
|
|
if(sss->federation != NULL){ |
|
|
if(sss->federation != NULL) { |
|
|
if(memcmp(mac,null_mac,sizeof(n2n_mac_t)) != 0){ /* not zero MAC */ |
|
|
if(memcmp(mac,null_mac,sizeof(n2n_mac_t)) != 0) { /* not zero MAC */ |
|
|
HASH_FIND_PEER(sss->federation->edges, mac, peer); |
|
|
HASH_FIND_PEER(sss->federation->edges, mac, peer); |
|
|
|
|
|
|
|
|
//REVISIT: make this dependent from last_seen and update socket
|
|
|
//REVISIT: make this dependent from last_seen and update socket
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(peer == NULL){ /* zero MAC, search by socket */ |
|
|
if(peer == NULL) { /* zero MAC, search by socket */ |
|
|
HASH_ITER(hh,sss->federation->edges,scan,tmp){ |
|
|
HASH_ITER(hh,sss->federation->edges,scan,tmp) { |
|
|
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t))){ |
|
|
if(memcmp(&(scan->sock), sock, sizeof(n2n_sock_t))) { |
|
|
memcpy(&(scan->mac_addr), sock, sizeof(n2n_mac_t)); |
|
|
memcpy(&(scan->mac_addr), sock, sizeof(n2n_mac_t)); |
|
|
peer = scan; |
|
|
peer = scan; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(peer == NULL){ |
|
|
if(peer == NULL) { |
|
|
peer = (struct peer_info*)calloc(1,sizeof(struct peer_info)); |
|
|
peer = (struct peer_info*)calloc(1,sizeof(struct peer_info)); |
|
|
if(peer){ |
|
|
if(peer) { |
|
|
memcpy(&(peer->sock),sock,sizeof(n2n_sock_t)); |
|
|
memcpy(&(peer->sock),sock,sizeof(n2n_sock_t)); |
|
|
memcpy(&(peer->mac_addr),mac, sizeof(n2n_mac_t)); |
|
|
memcpy(&(peer->mac_addr),mac, sizeof(n2n_mac_t)); |
|
|
HASH_ADD_PEER(sss->federation->edges,peer); |
|
|
HASH_ADD_PEER(sss->federation->edges,peer); |
|
@ -1065,7 +1068,7 @@ static int process_udp(n2n_sn_t * sss, |
|
|
n2n_sock_t *tmp_sock; |
|
|
n2n_sock_t *tmp_sock; |
|
|
n2n_mac_t *tmp_mac; |
|
|
n2n_mac_t *tmp_mac; |
|
|
|
|
|
|
|
|
if(from_supernode != comm->is_federation){ |
|
|
if(from_supernode != comm->is_federation) { |
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER: from_supernode value doesn't correspond to the internal federation marking"); |
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER: from_supernode value doesn't correspond to the internal federation marking"); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
@ -1152,7 +1155,7 @@ static int process_udp(n2n_sn_t * sss, |
|
|
memcpy(ack.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE); |
|
|
memcpy(ack.sock.addr.v4, &(sender_sock->sin_addr.s_addr), IPV4_SIZE); |
|
|
|
|
|
|
|
|
/* Add sender's data to federation (or update it) */ |
|
|
/* Add sender's data to federation (or update it) */ |
|
|
if(comm->is_federation == IS_FEDERATION){ |
|
|
if(comm->is_federation == IS_FEDERATION) { |
|
|
p = add_sn_to_federation_by_mac_or_sock(sss,&(ack.sock),&(reg.edgeMac)); |
|
|
p = add_sn_to_federation_by_mac_or_sock(sss,&(ack.sock),&(reg.edgeMac)); |
|
|
if(p) p->last_seen = now; |
|
|
if(p) p->last_seen = now; |
|
|
} |
|
|
} |
|
@ -1178,7 +1181,7 @@ static int process_udp(n2n_sn_t * sss, |
|
|
macaddr_str(mac_buf, reg.edgeMac), |
|
|
macaddr_str(mac_buf, reg.edgeMac), |
|
|
sock_to_cstr(sockbuf, &(ack.sock))); |
|
|
sock_to_cstr(sockbuf, &(ack.sock))); |
|
|
|
|
|
|
|
|
if(memcmp(reg.edgeMac, &null_mac, N2N_MAC_SIZE) != 0){ |
|
|
if(memcmp(reg.edgeMac, &null_mac, N2N_MAC_SIZE) != 0) { |
|
|
update_edge(sss, ®, comm, &(ack.sock), now); |
|
|
update_edge(sss, ®, comm, &(ack.sock), now); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1229,7 +1232,7 @@ static int process_udp(n2n_sn_t * sss, |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(from_supernode != comm->is_federation){ |
|
|
if(from_supernode != comm->is_federation) { |
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK: from_supernode value doesn't correspond to the internal federation marking."); |
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK: from_supernode value doesn't correspond to the internal federation marking."); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
@ -1253,7 +1256,7 @@ static int process_udp(n2n_sn_t * sss, |
|
|
|
|
|
|
|
|
if(comm->is_federation == IS_FEDERATION) { |
|
|
if(comm->is_federation == IS_FEDERATION) { |
|
|
HASH_FIND_PEER(sss->federation->edges, ack.edgeMac, scan); |
|
|
HASH_FIND_PEER(sss->federation->edges, ack.edgeMac, scan); |
|
|
if(scan != NULL){ |
|
|
if(scan != NULL) { |
|
|
scan->last_seen = now; |
|
|
scan->last_seen = now; |
|
|
} else { |
|
|
} else { |
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK due to an unknown supernode."); |
|
|
traceEvent(TRACE_DEBUG, "process_udp dropped REGISTER_SUPER_ACK due to an unknown supernode."); |
|
@ -1264,10 +1267,10 @@ static int process_udp(n2n_sn_t * sss, |
|
|
tmp_sock = (void*)&(ack.num_sn) + sizeof(ack.num_sn); |
|
|
tmp_sock = (void*)&(ack.num_sn) + sizeof(ack.num_sn); |
|
|
tmp_mac = (void*)tmp_sock + sizeof(n2n_sock_t); |
|
|
tmp_mac = (void*)tmp_sock + sizeof(n2n_sock_t); |
|
|
|
|
|
|
|
|
for(i=0; i<ack.num_sn; i++){ |
|
|
for(i=0; i<ack.num_sn; i++) { |
|
|
tmp = add_sn_to_federation_by_mac_or_sock(sss,tmp_sock,tmp_mac); |
|
|
tmp = add_sn_to_federation_by_mac_or_sock(sss,tmp_sock,tmp_mac); |
|
|
|
|
|
|
|
|
if(tmp){ |
|
|
if(tmp) { |
|
|
tmp->last_seen = now - TEST_TIME; |
|
|
tmp->last_seen = now - TEST_TIME; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1276,7 +1279,7 @@ static int process_udp(n2n_sn_t * sss, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
case MSG_TYPE_QUERY_PEER: { |
|
|
case MSG_TYPE_QUERY_PEER: { |
|
|
n2n_QUERY_PEER_t query; |
|
|
n2n_QUERY_PEER_t query; |
|
|
uint8_t encbuf[N2N_SN_PKTBUF_SIZE]; |
|
|
uint8_t encbuf[N2N_SN_PKTBUF_SIZE]; |
|
|