Skip to content

Commit 97f865b

Browse files
committed
Merge bitcoin/bitcoin#25989: init: abort if i2p/cjdns are chosen via -onlynet but are unreachable
68209a7 rpc: make addpeeraddress work with cjdns addresses (Martin Zumsande) a8a9ed6 init: Abort if i2p/cjdns are chosen via -onlynet but unreachable (Martin Zumsande) Pull request description: If the networks i2p / cjdns are chosen via `-onlynet` but the user forgot to provide `-i2psam` / `-cjdnsreachable`, no outbound connections will be made - it would be nice to inform the user about that. The solution proposed here mimics existing behavior for `-onlynet=onion` and non-specified `-onion`/`-proxy` where we already abort with an InitError - if reviewers would prefer to just print a warning, please say so. The second commit adds CJDNS support to the debug-only `addpeeraddress` RPC allowing to add CJDNS addresses to addrman for testing and debug purposes. (if `-cjdnsreachable=1`) This is the result of an [IRC discussion](https://bitcoin-irc.chaincode.com/bitcoin-core-dev/2022-09-01#848066;) with vasild. ACKs for top commit: vasild: ACK 68209a7 dergoegge: ACK 68209a7 Tree-SHA512: 6db9787f01820190f14f90a0b39e4206603421eb7521f792879094d8bbf4d4d0bfd70665eadcc40994ac7941a15ab5a8d65c4779fba5634c0e6fa66eb0972b8d
2 parents 7184fb8 + 68209a7 commit 97f865b

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/init.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12851285
}
12861286

12871287
if (!args.IsArgSet("-cjdnsreachable")) {
1288+
if (args.IsArgSet("-onlynet") && IsReachable(NET_CJDNS)) {
1289+
return InitError(
1290+
_("Outbound connections restricted to CJDNS (-onlynet=cjdns) but "
1291+
"-cjdnsreachable is not provided"));
1292+
}
12881293
SetReachable(NET_CJDNS, false);
12891294
}
12901295
// Now IsReachable(NET_CJDNS) is true if:
@@ -1757,6 +1762,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17571762
}
17581763
SetProxy(NET_I2P, Proxy{addr});
17591764
} else {
1765+
if (args.IsArgSet("-onlynet") && IsReachable(NET_I2P)) {
1766+
return InitError(
1767+
_("Outbound connections restricted to i2p (-onlynet=i2p) but "
1768+
"-i2psam is not provided"));
1769+
}
17601770
SetReachable(NET_I2P, false);
17611771
}
17621772

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ bool SeenLocal(const CService& addr);
164164
bool IsLocal(const CService& addr);
165165
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
166166
CService GetLocalAddress(const CNetAddr& addrPeer);
167+
CService MaybeFlipIPv6toCJDNS(const CService& service);
167168

168169

169170
extern bool fDiscover;

src/rpc/net.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ static RPCHelpMan addpeeraddress()
947947
bool success{false};
948948

949949
if (LookupHost(addr_string, net_addr, false)) {
950-
CAddress address{{net_addr, port}, ServiceFlags{NODE_NETWORK | NODE_WITNESS}};
950+
CService service{net_addr, port};
951+
CAddress address{MaybeFlipIPv6toCJDNS(service), ServiceFlags{NODE_NETWORK | NODE_WITNESS}};
951952
address.nTime = Now<NodeSeconds>();
952953
// The source address is set equal to the address. This is equivalent to the peer
953954
// announcing itself.

test/functional/feature_proxy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ def networks_dict(d):
332332
msg = "Error: Invalid -i2psam address or hostname: 'def:xyz'"
333333
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
334334

335+
self.log.info("Test passing invalid -onlynet=i2p without -i2psam raises expected init error")
336+
self.nodes[1].extra_args = ["-onlynet=i2p"]
337+
msg = "Error: Outbound connections restricted to i2p (-onlynet=i2p) but -i2psam is not provided"
338+
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
339+
340+
self.log.info("Test passing invalid -onlynet=cjdns without -cjdnsreachable raises expected init error")
341+
self.nodes[1].extra_args = ["-onlynet=cjdns"]
342+
msg = "Error: Outbound connections restricted to CJDNS (-onlynet=cjdns) but -cjdnsreachable is not provided"
343+
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)
344+
335345
self.log.info("Test passing -onlynet=onion with -onion=0/-noonion raises expected init error")
336346
msg = (
337347
"Error: Outbound connections restricted to Tor (-onlynet=onion) but "

0 commit comments

Comments
 (0)