From a8a9ed67cc447d204304ccfd844c45fd76486c6a Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Thu, 1 Sep 2022 18:25:25 -0400 Subject: [PATCH 1/2] init: Abort if i2p/cjdns are chosen via -onlynet but unreachable ...because -i2psam or -cjdnsreachable are not provided. This mimics existing behavior for -onlynet=onion and non-specified proxy. --- src/init.cpp | 10 ++++++++++ test/functional/feature_proxy.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 20cb483a3a..606adb09a1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1284,6 +1284,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) } if (!args.IsArgSet("-cjdnsreachable")) { + if (args.IsArgSet("-onlynet") && IsReachable(NET_CJDNS)) { + return InitError( + _("Outbound connections restricted to CJDNS (-onlynet=cjdns) but " + "-cjdnsreachable is not provided")); + } SetReachable(NET_CJDNS, false); } // Now IsReachable(NET_CJDNS) is true if: @@ -1756,6 +1761,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) } SetProxy(NET_I2P, Proxy{addr}); } else { + if (args.IsArgSet("-onlynet") && IsReachable(NET_I2P)) { + return InitError( + _("Outbound connections restricted to i2p (-onlynet=i2p) but " + "-i2psam is not provided")); + } SetReachable(NET_I2P, false); } diff --git a/test/functional/feature_proxy.py b/test/functional/feature_proxy.py index d02d56d068..c90852562e 100755 --- a/test/functional/feature_proxy.py +++ b/test/functional/feature_proxy.py @@ -332,6 +332,16 @@ class ProxyTest(BitcoinTestFramework): msg = "Error: Invalid -i2psam address or hostname: 'def:xyz'" self.nodes[1].assert_start_raises_init_error(expected_msg=msg) + self.log.info("Test passing invalid -onlynet=i2p without -i2psam raises expected init error") + self.nodes[1].extra_args = ["-onlynet=i2p"] + msg = "Error: Outbound connections restricted to i2p (-onlynet=i2p) but -i2psam is not provided" + self.nodes[1].assert_start_raises_init_error(expected_msg=msg) + + self.log.info("Test passing invalid -onlynet=cjdns without -cjdnsreachable raises expected init error") + self.nodes[1].extra_args = ["-onlynet=cjdns"] + msg = "Error: Outbound connections restricted to CJDNS (-onlynet=cjdns) but -cjdnsreachable is not provided" + self.nodes[1].assert_start_raises_init_error(expected_msg=msg) + self.log.info("Test passing -onlynet=onion with -onion=0/-noonion raises expected init error") msg = ( "Error: Outbound connections restricted to Tor (-onlynet=onion) but " From 68209a7b5c0326e14508d9cf749771605bd6ffe7 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Thu, 1 Sep 2022 18:26:55 -0400 Subject: [PATCH 2/2] rpc: make addpeeraddress work with cjdns addresses This allows us to add cjdns addresses to addrman for testing and debug purposes (if -cjdnsreachable is true) --- src/net.h | 1 + src/rpc/net.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/net.h b/src/net.h index 66a228b3ec..044701a339 100644 --- a/src/net.h +++ b/src/net.h @@ -164,6 +164,7 @@ bool SeenLocal(const CService& addr); bool IsLocal(const CService& addr); bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr); CService GetLocalAddress(const CNetAddr& addrPeer); +CService MaybeFlipIPv6toCJDNS(const CService& service); extern bool fDiscover; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index e221b3462d..d701a180ab 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -947,7 +947,8 @@ static RPCHelpMan addpeeraddress() bool success{false}; if (LookupHost(addr_string, net_addr, false)) { - CAddress address{{net_addr, port}, ServiceFlags{NODE_NETWORK | NODE_WITNESS}}; + CService service{net_addr, port}; + CAddress address{MaybeFlipIPv6toCJDNS(service), ServiceFlags{NODE_NETWORK | NODE_WITNESS}}; address.nTime = Now(); // The source address is set equal to the address. This is equivalent to the peer // announcing itself.