diff options
| author | Bitflash <btf01@proton.me> | 2026-07-30 15:41:26 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-30 15:41:26 -0300 |
| commit | 10f248876aaa77e840dcb0d9585aba2fde712130 (patch) | |
| tree | 0591b8a78a47345e97720090c231b2a31f7bce49 /src/main.cpp | |
| parent | 88a1e9973e34c972e965fe5dd16cd1f891885bba (diff) | |
net: notice a peer that has gone quiet, and stay audible to peers that check (#55)
A connection whose path dies silently -- NAT drops an idle mapping, a relay
restarts, a route changes -- never delivers FIN. Nothing becomes readable,
no error is raised, and the node simply stops hearing from that peer while
the socket looks perfectly healthy. #51 bounded this for the rendezvous
registration; the connection that comes out of the rendezvous had the same
hole, and so did every ordinary peer.
Stamp nLastRecv and nLastSend on the socket path and act on them:
- nothing at all within 60s of connecting, disconnect. In testing this
fired twice per run against dead .btf descriptors handed out by the
relay, which is where the ghosts have been coming from.
- queued to send for 10 minutes with nothing going out, disconnect.
- nothing received for 30 minutes, disconnect. A healthy peer relays a
block inventory about every two minutes, so this is fifteen intervals
of silence. Bitcoin used ninety minutes against ten-minute blocks.
Disconnecting is the whole cure: reconnection already works, and a peer we
cannot hear is worth what no peer is worth.
A node with nothing to relay would now look dead to a peer applying the
same rule, so send "ping" after ten minutes of having said nothing. It
carries no payload and expects no answer -- arriving is the entire content,
because the receive path has already stamped nLastRecv by the time it is
parsed. Requiring an answer would have read every node predating this
change as dead, since those ignore unknown commands rather than replying.
Verified on the live network: synced 0 to 3790 with five peers and no
spurious disconnects, then again with the interval cut to 20s, which put 54
pings on the wire with no peer dropping us and no exceptions.
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index d4fc6d0..f4e6ce2 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -2190,6 +2190,18 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) | |||
| 2190 | } | 2190 | } |
| 2191 | 2191 | ||
| 2192 | 2192 | ||
| 2193 | else if (strCommand == "ping") | ||
| 2194 | { | ||
| 2195 | // Nothing to do and nothing to answer. Arriving at all is the entire | ||
| 2196 | // content of the message: the receive path has already stamped | ||
| 2197 | // nLastRecv, which is what the sender wanted us to notice. | ||
| 2198 | // | ||
| 2199 | // Deliberately no reply. A node old enough not to know "ping" ignores | ||
| 2200 | // it as an unknown command and would never answer one, so a scheme | ||
| 2201 | // that required an answer would read every such peer as dead. | ||
| 2202 | } | ||
| 2203 | |||
| 2204 | |||
| 2193 | else | 2205 | else |
| 2194 | { | 2206 | { |
| 2195 | // Ignore unknown commands for extensibility | 2207 | // Ignore unknown commands for extensibility |
| @@ -2222,6 +2234,17 @@ bool SendMessages(CNode* pto) | |||
| 2222 | 2234 | ||
| 2223 | 2235 | ||
| 2224 | // | 2236 | // |
| 2237 | // Message: keep-alive ping | ||
| 2238 | // | ||
| 2239 | // Only when we have nothing else queued -- any real message serves the | ||
| 2240 | // same purpose. A peer with nothing to relay is otherwise silent, and | ||
| 2241 | // silence is exactly what the inactivity check disconnects on. | ||
| 2242 | // | ||
| 2243 | if (pto->nLastSend && GetTime() - pto->nLastSend > BTF_PING_INTERVAL_SECS && pto->vSend.empty()) | ||
| 2244 | pto->PushMessage("ping"); | ||
| 2245 | |||
| 2246 | |||
| 2247 | // | ||
| 2225 | // Message: inventory | 2248 | // Message: inventory |
| 2226 | // | 2249 | // |
| 2227 | vector<CInv> vInventoryToSend; | 2250 | vector<CInv> vInventoryToSend; |