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
pull/22112/head
Vasil Dimov 3 years ago
parent 1f096f091e
commit 4f432bd738
No known key found for this signature in database
GPG Key ID: 54DF06F64B55CBBF

@ -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;

Loading…
Cancel
Save