Whenever idle time exceeds keepalive time, ping up to once
every 1+keepalive/2 interval. Avoids spuriously treating a peer as
disconnected.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
bool connected;
bool handshake;
bool has_local_ep_addr;
- bool pinged;
union network_addr local_ep_addr;
union network_endpoint endpoint;
uint64_t last_request;
uint64_t last_query_sent;
+ int ping_wait;
int last_handshake_diff;
int idle;
int num_net_queries;
static void
network_pex_send_ping(struct network *net, struct network_peer *peer)
{
- if (peer->state.pinged || !peer->state.endpoint.sa.sa_family)
+ if (peer->state.ping_wait > 0 || !peer->state.endpoint.sa.sa_family)
return;
pex_msg_init(net, PEX_MSG_PING);
pex_msg_send(net, peer);
- peer->state.pinged = true;
+ peer->state.ping_wait = 1 + net->net_config.keepalive / 2;
}
static void
peer->state.handshake = false;
peer->state.idle++;
+ if (peer->state.ping_wait > 0)
+ peer->state.ping_wait--;
if (peer->state.idle >= 2 * net->net_config.keepalive)
wg_peer_set_connected(net, peer, false);
if (peer->state.idle > net->net_config.keepalive)
if (peer->state.idle > sec)
peer->state.idle = sec;
wg_peer_set_connected(net, peer, true);
- peer->state.pinged = false;
}
}