Skip to content

Commit 5b358cd

Browse files
committed
i2p: log connection was refused due to arbitrary port
1 parent 4de8455 commit 5b358cd

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/i2p.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)
217217
// Refuse connecting to arbitrary ports. We don't specify any destination port to the SAM proxy
218218
// when connecting (SAM 3.1 does not use ports) and it forces/defaults it to I2P_SAM31_PORT.
219219
if (to.GetPort() != I2P_SAM31_PORT) {
220+
Log("Error connecting to %s, connection refused due to arbitrary port %s", to.ToStringAddrPort(), to.GetPort());
220221
proxy_error = false;
221222
return false;
222223
}

test/functional/p2p_i2p_ports.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,28 @@
66
Test ports handling for I2P hosts
77
"""
88

9-
import re
109

1110
from test_framework.test_framework import BitcoinTestFramework
1211

12+
PROXY = "127.0.0.1:60000"
1313

1414
class I2PPorts(BitcoinTestFramework):
1515
def set_test_params(self):
1616
self.num_nodes = 1
1717
# The test assumes that an I2P SAM proxy is not listening here.
18-
self.extra_args = [["-i2psam=127.0.0.1:60000"]]
18+
self.extra_args = [[f"-i2psam={PROXY}"]]
1919

2020
def run_test(self):
2121
node = self.nodes[0]
2222

2323
self.log.info("Ensure we don't try to connect if port!=0")
2424
addr = "zsxwyo6qcn3chqzwxnseusqgsnuw3maqnztkiypyfxtya4snkoka.b32.i2p:8333"
25-
raised = False
26-
try:
27-
with node.assert_debug_log(expected_msgs=[f"Error connecting to {addr}"]):
28-
node.addnode(node=addr, command="onetry")
29-
except AssertionError as e:
30-
raised = True
31-
if not re.search(r"Expected messages .* does not partially match log", str(e)):
32-
raise AssertionError(f"Assertion raised as expected, but with an unexpected message: {str(e)}")
33-
if not raised:
34-
raise AssertionError("Assertion should have been raised")
25+
with node.assert_debug_log(expected_msgs=[f"Error connecting to {addr}, connection refused due to arbitrary port 8333"]):
26+
node.addnode(node=addr, command="onetry")
3527

3628
self.log.info("Ensure we try to connect if port=0 and get an error due to missing I2P proxy")
3729
addr = "h3r6bkn46qxftwja53pxiykntegfyfjqtnzbm6iv6r5mungmqgmq.b32.i2p:0"
38-
with node.assert_debug_log(expected_msgs=[f"Error connecting to {addr}"]):
30+
with node.assert_debug_log(expected_msgs=[f"Error connecting to {addr}: Cannot connect to {PROXY}"]):
3931
node.addnode(node=addr, command="onetry")
4032

4133

0 commit comments

Comments
 (0)