From 4bfe97781cdd4dcb9181625305b19de1ca275157 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 18 Mar 2019 08:25:32 -0400 Subject: [PATCH] relax ping to 10s of inactivity --- llarp/link/server.cpp | 3 ++- llarp/link/session.hpp | 3 +++ llarp/link/utp.cpp | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) 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) {