aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-05-31 18:07:40 +0200
committerVasil Dimov <vd@FreeBSD.org>2021-07-09 11:19:37 +0200
commit4f432bd738c420512a86a51ab3e00323f396b89e (patch)
tree7ca2d736342bd8861265e9164b800abdf15867d1 /src
parent1f096f091ebd88efb18154b8894a38122c39624f (diff)
net: do not connect to I2P hosts on port!=0
When connecting to an I2P host we don't specify destination port and it is being forced to 0 by the SAM 3.1 proxy, so if we connect to the same host on two different ports, that would be actually two connections to the same service (listening on port 0). Fixes https://github.com/bitcoin/bitcoin/issues/21389
Diffstat (limited to 'src')
-rw-r--r--src/i2p.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/i2p.cpp b/src/i2p.cpp
index dbd4d46baa..5e7e42fb77 100644
--- a/src/i2p.cpp
+++ b/src/i2p.cpp
@@ -172,6 +172,13 @@ bool Session::Accept(Connection& conn)
bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)
{
+ // Refuse connecting to arbitrary ports. We don't specify any destination port to the SAM proxy
+ // when connecting (SAM 3.1 does not use ports) and it forces/defaults it to I2P_SAM31_PORT.
+ if (to.GetPort() != I2P_SAM31_PORT) {
+ proxy_error = false;
+ return false;
+ }
+
proxy_error = true;
std::string session_id;