Skip to content

Commit a78ca70

Browse files
committed
Merge bitcoin#29393: i2p: log connection was refused due to arbitrary port
5b358cd i2p: log connection was refused due to arbitrary port (brunoerg) Pull request description: For I2P, we do not try to connect if port is != 0. However, we do not have anything that indicates it or any error when trying to connect with port != 0. This PR adds a log for it. Also, it improves the functional test. With this log we can ensure the reason we won't connect is the port, in the current test, we cannot ensure it. ACKs for top commit: jonatack: ACK 5b358cd epiccurious: re-ACK 5b358cd. achow101: ACK 5b358cd kristapsk: re-ACK 5b358cd vasild: ACK 5b358cd Tree-SHA512: 027245afa771c9295fff0bfd17c251dca4a9f4c739e5773922de3c030a65ef05d96291edcbdeeaa50ba3add61f75f28d8c00be503e03fc33d3491d1956fc549f
2 parents c07935b + 5b358cd commit a78ca70

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/i2p.cpp

+1
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

+5-13
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)