From: Felix Fietkau Date: Fri, 16 Sep 2022 12:54:45 +0000 (+0200) Subject: pex: reduce unnecessary ping traffic X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1cbb1a543cb3377da422372e633a36d4f69dd9a5;p=project%2Funetd.git pex: reduce unnecessary ping traffic Only ping once after the idle time exceeds keepalive time. Do not ping if no endpoint address is known yet Signed-off-by: Felix Fietkau --- diff --git a/host.h b/host.h index 040c292..5eed711 100644 --- a/host.h +++ b/host.h @@ -21,6 +21,7 @@ struct network_peer { bool connected; bool handshake; bool has_local_ep_addr; + bool pinged; union network_addr local_ep_addr; union network_endpoint endpoint; diff --git a/pex.c b/pex.c index c15982d..7882084 100644 --- a/pex.c +++ b/pex.c @@ -343,8 +343,12 @@ network_pex_query_hosts(struct network *net) static void network_pex_send_ping(struct network *net, struct network_peer *peer) { + if (peer->state.pinged || !peer->state.endpoint.sa.sa_family) + return; + pex_msg_init(net, PEX_MSG_PING); pex_msg_send(net, peer); + peer->state.pinged = true; } static void diff --git a/wg.c b/wg.c index 9ac647f..64687f1 100644 --- a/wg.c +++ b/wg.c @@ -79,6 +79,7 @@ void wg_peer_set_last_handshake(struct network *net, struct network_peer *peer, if (peer->state.idle > sec) peer->state.idle = sec; wg_peer_set_connected(net, peer, true); + peer->state.pinged = false; } }