diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-08-13 14:54:17 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-08-23 04:37:36 +0000 |
| commit | 0620e69d8cee549ce64d323682a39129900a4f1c (patch) | |
| tree | 09e189805bb64772fe9c04b4679c25131afdc3b2 /src/net.h | |
| parent | 88d12ee18e7a3df489cc600f92c4f68506d307fe (diff) | |
net: do not consume a header until the body is there, and cap what one can claim
Upstream #109's message-stall rework, hand-merged so it keeps the progress
timing this tree already had.
The old path consumed the header, found the payload short, inserted the header
back at the front of vRecv, then Sleep(100) inside the shared message thread.
A peer that announces a large payload and drips bytes made every pass pay an
O(n) insert and a 100 ms stall -- one peer slowing the thread that serves all
of them. Now the header is read from a copy and only skipped once the whole
body has arrived, so there is nothing to put back and nothing to sleep for.
Kept OURS, not upstream's, on the timeout: upstream restarts its clock only
when the (size, command) pair changes, which drops a peer sending one big
message slowly but honestly. This times the STALL -- the clock restarts on any
progress -- which is the distinction that matters on a slow link.
Also from #109: a header could announce 256 MB while serialize.h refuses
anything over MAX_SIZE (32 MB), so the check admitted an allocation the parser
would reject anyway and burned a peer slot for two minutes doing it.
MAX_PROTOCOL_MESSAGE_SIZE ties the two together. 8x less a peer can make us
hold, and this node takes public Stratum.
And #103's other half: ~CNode closed its socket with a raw closesocket(),
invisible to the accounting, and left hSocket set afterwards -- which is how a
descriptor number that now belongs to somebody else gets closed a second time.
(cherry picked from commit 2f25e2e07985e9bc732cadfbb3c9ac233895a814)
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 15 |
1 files changed, 15 insertions, 0 deletions
| @@ -146,6 +146,16 @@ static const int64 BTF_NO_PEER_HEIGHT_MAX_SECS = 20 * 60; | |||
| 146 | // minutes is far beyond that, and well inside BTF_RECV_TIMEOUT_SECS. | 146 | // minutes is far beyond that, and well inside BTF_RECV_TIMEOUT_SECS. |
| 147 | static const int64 BTF_MSG_WAIT_MAX_SECS = 2 * 60; | 147 | static const int64 BTF_MSG_WAIT_MAX_SECS = 2 * 60; |
| 148 | 148 | ||
| 149 | // Largest payload a peer may announce in a message header: MAX_PROTOCOL_MESSAGE_SIZE | ||
| 150 | // is defined further up this file. This tree reached the same cap by the same | ||
| 151 | // reasoning as upstream #109 -- a 256 MB allowance is eight times what the | ||
| 152 | // deserializer will accept (serialize.h throws above MAX_SIZE), so the header | ||
| 153 | // check admitted an allocation the parser would only reject later, after | ||
| 154 | // BTF_MSG_WAIT_MAX_SECS of a stalled peer slot -- so only the note survives. | ||
| 155 | // | ||
| 156 | // Both definitions were textually clean and 59 lines apart, so the replay onto | ||
| 157 | // upstream merged them without a conflict and only the compiler objected. | ||
| 158 | |||
| 149 | // Send a ping after this long with nothing to say, so a peer running the | 159 | // Send a ping after this long with nothing to say, so a peer running the |
| 150 | // inactivity check above does not mistake a quiet node for a dead one. Must | 160 | // inactivity check above does not mistake a quiet node for a dead one. Must |
| 151 | // stay well under BTF_RECV_TIMEOUT_SECS. | 161 | // stay well under BTF_RECV_TIMEOUT_SECS. |
| @@ -741,6 +751,11 @@ public: | |||
| 741 | { | 751 | { |
| 742 | if (hSocket != INVALID_SOCKET) | 752 | if (hSocket != INVALID_SOCKET) |
| 743 | { | 753 | { |
| 754 | // Route through BtfCloseSocket so the accounting sees this close. | ||
| 755 | // A raw closesocket() here was invisible to sockcount, which is | ||
| 756 | // why the leak numbers never added up, and leaving the descriptor | ||
| 757 | // set afterwards is how a number that now belongs to somebody else | ||
| 758 | // gets closed a second time. (#103) | ||
| 744 | BtfCloseSocket(hSocket); | 759 | BtfCloseSocket(hSocket); |
| 745 | hSocket = INVALID_SOCKET; | 760 | hSocket = INVALID_SOCKET; |
| 746 | } | 761 | } |