diff --git a/llarp/link/server.cpp b/llarp/link/server.cpp index 8cd6fac76..96774d8cc 100644 --- a/llarp/link/server.cpp +++ b/llarp/link/server.cpp @@ -297,7 +297,8 @@ namespace llarp auto itr = range.first; while(itr != range.second) { - itr->second->SendKeepAlive(); + if(itr->second->ShouldPing()) + itr->second->SendKeepAlive(); ++itr; } } diff --git a/llarp/link/session.hpp b/llarp/link/session.hpp index 685abaf09..c85fe7ae2 100644 --- a/llarp/link/session.hpp +++ b/llarp/link/session.hpp @@ -61,6 +61,9 @@ namespace llarp /// renegotiate session when we have a new RC locally std::function< bool(void) > RenegotiateSession; + + /// return true if we should send an explicit keepalive message + std::function< bool(void) > ShouldPing; }; } // namespace llarp diff --git a/llarp/link/utp.cpp b/llarp/link/utp.cpp index ae030b35b..454cd56de 100644 --- a/llarp/link/utp.cpp +++ b/llarp/link/utp.cpp @@ -591,6 +591,11 @@ namespace llarp SendQueueBacklog = [&]() -> size_t { return sendq.size(); }; + ShouldPing = [&]() -> bool { + auto dlt = lastActive - parent->Now(); + return dlt >= 10000; + }; + SendKeepAlive = [&]() -> bool { if(state == eSessionReady) {