From e9bb1a9e2d7fece81afc55aecda10f22c83e2677 Mon Sep 17 00:00:00 2001 From: Audric Date: Fri, 8 May 2026 21:03:06 +0200 Subject: [PATCH] fix(peer): heartbeat MsgPeerTgInterest re-sends to keep TTL alive The 60 s heartbeat path was inheriting the skip-when-unchanged gate from the 500 ms debounce path. Result: after the initial edge-triggered advertisement, an idle reflector with a stable monitor list would silently no-op every 60 s, the receiver's m_peer_interested_tgs[tg] timestamp never got refreshed, and its 600 s TTL elapsed. A passive monitor would go deaf 10 minutes after adding a foreign TG to monitoredTGs. Split the two call sites: heartbeat passes force=true (always send), debounce keeps force=false (skip when unchanged). The steady-state heartbeat is one frame per trunk per minute, which is what the receiver TTL needs. Doc note in PEER_PROTOCOL.md was wrong (claimed both timers skipped unchanged sends); corrected. Affects v1.3.9; ship as v1.3.10. --- docs/PEER_PROTOCOL.md | 12 ++++++++---- src/svxlink/reflector/TrunkLink.cpp | 21 ++++++++++++++------- src/svxlink/reflector/TrunkLink.h | 4 +++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/PEER_PROTOCOL.md b/docs/PEER_PROTOCOL.md index 68cbaa4..f811db7 100644 --- a/docs/PEER_PROTOCOL.md +++ b/docs/PEER_PROTOCOL.md @@ -276,10 +276,14 @@ Send cadence: - **Edge-triggered** on local-state changes that affect the set: client connect / disconnect, `MsgSelectTG`, `MsgTgMonitor`, and trunk hello completion. Coalesced with a 500 ms debounce so a client toggling its - monitor list one TG at a time sends one update, not many. -- **Periodic refresh** every 60 s as a safety net against lost deltas. - Both timers skip the actual send when the outgoing set is unchanged - since the last transmission, so an idle reflector generates no traffic. + monitor list one TG at a time sends one update, not many. This path + skips the actual send when the outgoing set is unchanged. +- **Periodic refresh** every 60 s — *always sends*, even when the + outgoing set is unchanged. The heartbeat is what keeps the receiver's + `m_peer_interested_tgs` entries from expiring at the 600 s TTL: every + receipt rewrites the timestamp, so an idle monitor stays known to its + peer indefinitely. Without this the monitor would go deaf 10 minutes + after the last edge-triggered change. Multi-hop propagation: when a reflector receives `MsgPeerTgInterest` from a peer P, it triggers a refresh on its other trunk links. Each other diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index f5fe4be..6629f7d 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -1826,14 +1826,22 @@ void TrunkLink::handleMsgPeerTgInterest(std::istream& is) void TrunkLink::onTgInterestTimer(Async::Timer*) { - sendTgInterest(); + // Periodic refresh: always re-send (force=true) so the receiver's + // m_peer_interested_tgs entries get their timestamp refreshed and the + // 600 s TTL stays alive even when the local set hasn't changed since + // the last debounce send. Without this, a passive monitor would go + // deaf after 600 s of no-op heartbeats. + sendTgInterest(/*force=*/true); } /* TrunkLink::onTgInterestTimer */ void TrunkLink::onTgInterestDebounce(Async::Timer* t) { t->setEnable(false); - sendTgInterest(); + // Edge-triggered: skip when the outgoing set is unchanged. The 60 s + // heartbeat above takes care of receiver-TTL upkeep, so this path can + // safely no-op on idle changes. + sendTgInterest(/*force=*/false); } /* TrunkLink::onTgInterestDebounce */ @@ -1872,16 +1880,15 @@ std::set TrunkLink::buildOutgoingTgInterest(void) const } /* TrunkLink::buildOutgoingTgInterest */ -void TrunkLink::sendTgInterest(void) +void TrunkLink::sendTgInterest(bool force) { if (!isActive()) return; std::set outgoing = buildOutgoingTgInterest(); - if (outgoing == m_last_sent_tg_interest) + if (!force && outgoing == m_last_sent_tg_interest) { - // Nothing changed since the last advertisement — let the receiver's TTL - // ride on the previous send. Keeps the heartbeat refresh from generating - // idle traffic when the monitored set is stable. + // Edge-triggered debounce path with nothing changed: skip. The 60 s + // heartbeat (force=true) will refresh the receiver's TTL. return; } diff --git a/src/svxlink/reflector/TrunkLink.h b/src/svxlink/reflector/TrunkLink.h index 00374a1..cfc1cfd 100644 --- a/src/svxlink/reflector/TrunkLink.h +++ b/src/svxlink/reflector/TrunkLink.h @@ -294,7 +294,9 @@ class TrunkLink : public sigc::trackable void handleMsgPeerNodeList(std::istream& is); void handleMsgPeerTgInterest(std::istream& is); - void sendTgInterest(void); + // force=true bypasses skip-when-unchanged so the periodic 60 s + // heartbeat refreshes the receiver's m_peer_interested_tgs TTL. + void sendTgInterest(bool force = false); void onTgInterestTimer(Async::Timer* t); void onTgInterestDebounce(Async::Timer* t); // Build the set we should advertise to this peer: local interest, plus