Skip to content

Commit 4f432bd

Browse files
committed
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 bitcoin/bitcoin#21389
1 parent 1f096f0 commit 4f432bd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/i2p.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ bool Session::Accept(Connection& conn)
172172

173173
bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)
174174
{
175+
// Refuse connecting to arbitrary ports. We don't specify any destination port to the SAM proxy
176+
// when connecting (SAM 3.1 does not use ports) and it forces/defaults it to I2P_SAM31_PORT.
177+
if (to.GetPort() != I2P_SAM31_PORT) {
178+
proxy_error = false;
179+
return false;
180+
}
181+
175182
proxy_error = true;
176183

177184
std::string session_id;

0 commit comments

Comments
 (0)