diff options
| author | Bitflash <btf01@proton.me> | 2026-07-31 17:40:58 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-31 17:40:58 -0300 |
| commit | d5bcd347cd8d156e3a6d4526fd2470741194a64a (patch) | |
| tree | 41e0820126fb7a0f1daebc8130054c64a00b9faf /src/net.h | |
| parent | 795e51612bd5b17dbbf8f0cbea64ee4c874b5a33 (diff) | |
net: a node could only ever watch 63 peers (#78)
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 26 |
1 files changed, 26 insertions, 0 deletions
| @@ -67,6 +67,30 @@ static const int BTF_RECV_TIMEOUT_SECS = 30 * 60; | |||
| 67 | static const int BTF_SEND_STALL_SECS = 10 * 60; | 67 | static const int BTF_SEND_STALL_SECS = 10 * 60; |
| 68 | static const int BTF_HANDSHAKE_GRACE_SECS = 60; | 68 | static const int BTF_HANDSHAKE_GRACE_SECS = 60; |
| 69 | 69 | ||
| 70 | // Ceiling on simultaneous connections. | ||
| 71 | // | ||
| 72 | // ThreadSocketHandler watches every peer through one select(), and select() | ||
| 73 | // cannot watch more descriptors than FD_SETSIZE. On Windows FD_SET simply | ||
| 74 | // stops adding once the set is full -- no error, no log -- so every socket | ||
| 75 | // past the limit stays open and is never read again. Nothing capped vNodes, | ||
| 76 | // so a node accepted connections it had no way to service, and because new | ||
| 77 | // entries go on the end of vNodes it was always the newest connection that | ||
| 78 | // starved, including the ones dialed to fix connectivity. | ||
| 79 | // | ||
| 80 | // Measured on two nodes before this ceiling existed: 277 and 90 CNode objects | ||
| 81 | // against 93 and 90 live sockets, and a status bar reporting hundreds of | ||
| 82 | // peers for a node that was really talking to thirty. | ||
| 83 | // | ||
| 84 | // 125 is Bitcoin's number and sits far below FD_SETSIZE on both platforms. | ||
| 85 | static const unsigned int MAX_CONNECTIONS = 125; | ||
| 86 | |||
| 87 | // A node marked for disconnect is normally held until its buffers drain, so | ||
| 88 | // a last message still goes out. But vSend cannot drain through a socket | ||
| 89 | // whose far end is gone, and that made such a node immortal: it stayed in | ||
| 90 | // vNodes, kept its socket open, and kept being counted. Force it out after | ||
| 91 | // this long regardless of what is still buffered. | ||
| 92 | static const int64 DISCONNECT_DRAIN_SECS = 60; | ||
| 93 | |||
| 70 | // Send a ping after this long with nothing to say, so a peer running the | 94 | // Send a ping after this long with nothing to say, so a peer running the |
| 71 | // inactivity check above does not mistake a quiet node for a dead one. Must | 95 | // inactivity check above does not mistake a quiet node for a dead one. Must |
| 72 | // stay well under BTF_RECV_TIMEOUT_SECS. | 96 | // stay well under BTF_RECV_TIMEOUT_SECS. |
| @@ -520,6 +544,7 @@ protected: | |||
| 520 | int nRefCount; | 544 | int nRefCount; |
| 521 | public: | 545 | public: |
| 522 | int64 nReleaseTime; | 546 | int64 nReleaseTime; |
| 547 | int64 nDisconnectSince; | ||
| 523 | map<uint256, CRequestTracker> mapRequests; | 548 | map<uint256, CRequestTracker> mapRequests; |
| 524 | CCriticalSection cs_mapRequests; | 549 | CCriticalSection cs_mapRequests; |
| 525 | 550 | ||
| @@ -572,6 +597,7 @@ public: | |||
| 572 | fDisconnect = false; | 597 | fDisconnect = false; |
| 573 | nRefCount = 0; | 598 | nRefCount = 0; |
| 574 | nReleaseTime = 0; | 599 | nReleaseTime = 0; |
| 600 | nDisconnectSince = 0; | ||
| 575 | nLastPexRecv = 0; | 601 | nLastPexRecv = 0; |
| 576 | pindexLastGetBlocksBegin = NULL; | 602 | pindexLastGetBlocksBegin = NULL; |
| 577 | hashLastGetBlocksEnd = 0; | 603 | hashLastGetBlocksEnd = 0; |