pex: reduce unnecessary ping traffic
authorFelix Fietkau <nbd@nbd.name>
Fri, 16 Sep 2022 12:54:45 +0000 (14:54 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 16 Sep 2022 12:57:25 +0000 (14:57 +0200)
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 <nbd@nbd.name>
host.h
pex.c
wg.c

diff --git a/host.h b/host.h
index 040c292f42fa7f086ce24b0cab64efea2609c8d3..5eed71175784fb8729dd4763ad3046294d909edc 100644 (file)
--- 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 c15982de76d24e32e1cc15eaab56987390671185..78820844632c7799eae21e75acc9ed4c6d588aad 100644 (file)
--- 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 9ac647f21a6f7b8f7a5db8c624e7b837aafb470b..64687f181983c351e32d44a1aa587c3db844c2f5 100644 (file)
--- 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;
        }
 }