aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-10-19 16:01:41 -0400
committerAndrew Chow <github@achow101.com>2023-10-19 16:08:06 -0400
commit77f0ceb7175dbd00b51e27838a7167804d67646f (patch)
treef53c8e35a276b4b9ea483eea7da5aa36e05400ed /src/net.cpp
parent0655e9dd92ea4a86d3e76d5689d59a71cff61357 (diff)
parent5c8e15c451ec870b9dd4eb843ec6ca3ba64cda4f (diff)
Merge bitcoin/bitcoin#28077: I2P: also sleep after errors in Accept() & destroy the session if we get an unexpected error
5c8e15c451ec870b9dd4eb843ec6ca3ba64cda4f i2p: destroy the session if we get an unexpected error from the I2P router (Vasil Dimov) 762404a68c114e8831cdfae937627174544b55a7 i2p: also sleep after errors in Accept() (Vasil Dimov) Pull request description: ### Background In the `i2p::sam::Session` class: `Listen()` does: * if the session is not created yet * create the control socket and on it: * `HELLO` * `SESSION CREATE ID=sessid` * leave the control socked opened * create a new socket and on it: * `HELLO` * `STREAM ACCEPT ID=sessid` * read reply (`STREAM STATUS`), `Listen()` only succeeds if it contains `RESULT=OK` Then a wait starts, for a peer to connect. When connected, `Accept()` does: * on the socket from `STREAM ACCEPT` from `Listen()`: read the Base64 identification of the connecting peer ### Problem The I2P router may be in such a state that this happens in a quick succession (many times per second, see https://github.com/bitcoin/bitcoin/issues/22759#issuecomment-1609907115): `Listen()`-succeeds, `Accept()`-fails. `Accept()` fails because the I2P router sends something that is not Base64 on the socket: `STREAM STATUS RESULT=I2P_ERROR MESSAGE="Session was closed"` We only sleep after failed `Listen()` because the assumption was that if `Accept()` fails then the next `Listen()` will also fail. ### Solution Avoid filling the log with "Error accepting:" messages and sleep also after a failed `Accept()`. ### Extra changes * Reset the error waiting time after one successful connection. Otherwise the timer will remain high due to problems that have been solved long time in the past. * Increment the wait time less aggressively. * Handle the unexpected "Session was closed" message more gracefully (don't log stupid messages like `Cannot decode Base64: "STREAM STATUS...`) and destroy the session right way. ACKs for top commit: achow101: ACK 5c8e15c451ec870b9dd4eb843ec6ca3ba64cda4f jonatack: re-ACK 5c8e15c451ec870b9dd4eb843ec6ca3ba64cda4f Tree-SHA512: 1d47958c50eeae9eefcb668b8539fd092adead93328e4bf3355267819304b99ab41cbe1b5dbedbc3452c2bc389dc8330c0e27eb5ccb880e33dc46930a1592885
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/net.cpp b/src/net.cpp
index fecb4205ff..09a3d8617a 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2928,6 +2928,13 @@ void CConnman::ThreadI2PAcceptIncoming()
bool advertising_listen_addr = false;
i2p::Connection conn;
+ auto SleepOnFailure = [&]() {
+ interruptNet.sleep_for(err_wait);
+ if (err_wait < err_wait_cap) {
+ err_wait += 1s;
+ }
+ };
+
while (!interruptNet) {
if (!m_i2p_sam_session->Listen(conn)) {
@@ -2935,12 +2942,7 @@ void CConnman::ThreadI2PAcceptIncoming()
RemoveLocal(conn.me);
advertising_listen_addr = false;
}
-
- interruptNet.sleep_for(err_wait);
- if (err_wait < err_wait_cap) {
- err_wait *= 2;
- }
-
+ SleepOnFailure();
continue;
}
@@ -2950,11 +2952,14 @@ void CConnman::ThreadI2PAcceptIncoming()
}
if (!m_i2p_sam_session->Accept(conn)) {
+ SleepOnFailure();
continue;
}
CreateNodeFromAcceptedSocket(std::move(conn.sock), NetPermissionFlags::None,
CAddress{conn.me, NODE_NONE}, CAddress{conn.peer, NODE_NONE});
+
+ err_wait = err_wait_begin;
}
}