Browse Source

Fix supernode handling REGISTER message from edge and let edge ask supernode to forward REGISTER message in case of non-p2p-reflection.

This is reliable way to PUNCH UDP HOLE (following STUN spec)
pull/110/head
yunbox 6 years ago
committed by Jiang Zihao
parent
commit
f48c170c26
  1. 8
      edge_utils.c
  2. 2
      sn.c

8
edge_utils.c

@ -370,6 +370,7 @@ static void register_with_local_peers(n2n_edge_t * eee) {
* Called from the main loop when Rx a packet for our device mac. * Called from the main loop when Rx a packet for our device mac.
*/ */
static void register_with_new_peer(n2n_edge_t * eee, static void register_with_new_peer(n2n_edge_t * eee,
uint8_t from_supernode,
const n2n_mac_t mac, const n2n_mac_t mac,
const n2n_sock_t * peer) { const n2n_sock_t * peer) {
/* REVISIT: purge of pending_peers not yet done. */ /* REVISIT: purge of pending_peers not yet done. */
@ -397,6 +398,9 @@ static void register_with_new_peer(n2n_edge_t * eee,
/* trace Sending REGISTER */ /* trace Sending REGISTER */
send_register(eee, &(scan->sock), mac); send_register(eee, &(scan->sock), mac);
if(from_supernode) {
send_register(eee, &(eee->supernode), mac);
}
register_with_local_peers(eee); register_with_local_peers(eee);
} }
@ -413,7 +417,7 @@ static void check_peer_registration_needed(n2n_edge_t * eee,
if(scan == NULL) { if(scan == NULL) {
/* Not in known_peers - start the REGISTER process. */ /* Not in known_peers - start the REGISTER process. */
register_with_new_peer(eee, mac, peer); register_with_new_peer(eee, from_supernode, mac, peer);
} else { } else {
/* Already in known_peers. */ /* Already in known_peers. */
time_t now = time(NULL); time_t now = time(NULL);
@ -571,7 +575,7 @@ static void check_known_peer_sock_change(n2n_edge_t * eee,
/* The peer has changed public socket. It can no longer be assumed to be reachable. */ /* The peer has changed public socket. It can no longer be assumed to be reachable. */
remove_peer_from_list(&eee->known_peers, prev, scan); remove_peer_from_list(&eee->known_peers, prev, scan);
register_with_new_peer(eee, mac, peer); register_with_new_peer(eee, from_supernode, mac, peer);
} else { } else {
/* Don't worry about what the supernode reports, it could be seeing a different socket. */ /* Don't worry about what the supernode reports, it could be seeing a different socket. */
} }

2
sn.c

@ -583,7 +583,7 @@ static int process_udp(n2n_sn_t * sss,
macaddr_str(mac_buf2, reg.dstMac), macaddr_str(mac_buf2, reg.dstMac),
((cmn.flags & N2N_FLAGS_FROM_SUPERNODE)?"from sn":"local")); ((cmn.flags & N2N_FLAGS_FROM_SUPERNODE)?"from sn":"local"));
if(0 != (cmn.flags & N2N_FLAGS_FROM_SUPERNODE)) { if(0 == (cmn.flags & N2N_FLAGS_FROM_SUPERNODE)) {
memcpy(&cmn2, &cmn, sizeof(n2n_common_t)); memcpy(&cmn2, &cmn, sizeof(n2n_common_t));
/* We are going to add socket even if it was not there before */ /* We are going to add socket even if it was not there before */

Loading…
Cancel
Save