Browse Source

Fix connection stall when idle p2p refresh occurs

The edge received packets from the supernode and thought that the other
peer was still active, but the other peer had dropped the p2p connection
due to refresh
pull/128/head
emanuele-f 5 years ago
parent
commit
0e6db6361e
  1. 5
      edge_utils.c
  2. 7
      n2n.h

5
edge_utils.c

@ -422,6 +422,9 @@ static void check_peer_registration_needed(n2n_edge_t * eee,
/* Already in known_peers. */ /* Already in known_peers. */
time_t now = time(NULL); time_t now = time(NULL);
if(!from_supernode)
scan->last_p2p = now;
if((now - scan->last_seen) > 0 /* >= 1 sec */) { if((now - scan->last_seen) > 0 /* >= 1 sec */) {
/* Don't register too often */ /* Don't register too often */
check_known_peer_sock_change(eee, from_supernode, mac, peer, now); check_known_peer_sock_change(eee, from_supernode, mac, peer, now);
@ -1095,7 +1098,7 @@ static int find_peer_destination(n2n_edge_t * eee,
if((scan->last_seen > 0) && if((scan->last_seen > 0) &&
(memcmp(mac_address, scan->mac_addr, N2N_MAC_SIZE) == 0)) { (memcmp(mac_address, scan->mac_addr, N2N_MAC_SIZE) == 0)) {
if((now - scan->last_seen) >= (scan->timeout / 2)) { if((now - scan->last_p2p) >= (scan->timeout / 2)) {
/* Too much time passed since we saw the peer, need to register again /* Too much time passed since we saw the peer, need to register again
* since the peer address may have changed. */ * since the peer address may have changed. */
traceEvent(TRACE_DEBUG, "Refreshing idle known peer"); traceEvent(TRACE_DEBUG, "Refreshing idle known peer");

7
n2n.h

@ -173,6 +173,7 @@ struct peer_info {
n2n_sock_t sock; n2n_sock_t sock;
int timeout; int timeout;
time_t last_seen; time_t last_seen;
time_t last_p2p;
}; };
#define N2N_EDGE_SN_HOST_SIZE 48 #define N2N_EDGE_SN_HOST_SIZE 48
@ -245,7 +246,7 @@ int getTraceLevel();
void traceEvent(int eventTraceLevel, char* file, int line, char * format, ...); void traceEvent(int eventTraceLevel, char* file, int line, char * format, ...);
/* Tuntap API */ /* Tuntap API */
int tuntap_open(tuntap_dev *device, char *dev, const char *address_mode, char *device_ip, int tuntap_open(tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
char *device_mask, const char * device_mac, int mtu); char *device_mask, const char * device_mac, int mtu);
int tuntap_read(struct tuntap_dev *tuntap, unsigned char *buf, int len); int tuntap_read(struct tuntap_dev *tuntap, unsigned char *buf, int len);
int tuntap_write(struct tuntap_dev *tuntap, unsigned char *buf, int len); int tuntap_write(struct tuntap_dev *tuntap, unsigned char *buf, int len);
@ -267,7 +268,7 @@ void print_edge_stats(const n2n_edge_t *eee);
char* sock_to_cstr( n2n_sock_str_t out, char* sock_to_cstr( n2n_sock_str_t out,
const n2n_sock_t * sock ); const n2n_sock_t * sock );
SOCKET open_socket(int local_port, int bind_any); SOCKET open_socket(int local_port, int bind_any);
int sock_equal( const n2n_sock_t * a, int sock_equal( const n2n_sock_t * a,
const n2n_sock_t * b ); const n2n_sock_t * b );
/* Operations on peer_info lists. */ /* Operations on peer_info lists. */
@ -276,7 +277,7 @@ struct peer_info * find_peer_by_mac( struct peer_info * list,
void peer_list_add( struct peer_info * * list, void peer_list_add( struct peer_info * * list,
struct peer_info * newp ); struct peer_info * newp );
size_t peer_list_size( const struct peer_info * list ); 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, time_t* p_last_purge ); size_t purge_expired_registrations( struct peer_info ** peer_list, time_t* p_last_purge );

Loading…
Cancel
Save