Skip to content

Commit 2555a39

Browse files
committed
p2p: ProcessAddrFetch(-seednode) is unnecessary if -connect is specified
1 parent 5974c49 commit 2555a39

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/init.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17991799
if (connect.size() != 1 || connect[0] != "0") {
18001800
connOptions.m_specified_outgoing = connect;
18011801
}
1802+
if (!connOptions.m_specified_outgoing.empty() && !connOptions.vSeedNodes.empty()) {
1803+
LogPrintf("-seednode is ignored when -connect is used\n");
1804+
}
1805+
1806+
if (args.IsArgSet("-dnsseed") && args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED) && args.IsArgSet("-proxy")) {
1807+
LogPrintf("-dnsseed is ignored when -connect is used and -proxy is specified\n");
1808+
}
18021809
}
18031810

18041811
const std::string& i2psam_arg = args.GetArg("-i2psam", "");

src/net.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,8 @@ void CConnman::ThreadDNSAddressSeed()
14651465
}
14661466

14671467
LogPrintf("Loading addresses from DNS seed %s\n", seed);
1468+
// If -proxy is in use, we make an ADDR_FETCH connection to the DNS resolved peer address
1469+
// for the base dns seed domain in chainparams
14681470
if (HaveNameProxy()) {
14691471
AddAddrFetch(seed);
14701472
} else {
@@ -1486,8 +1488,9 @@ void CConnman::ThreadDNSAddressSeed()
14861488
}
14871489
addrman.Add(vAdd, resolveSource);
14881490
} else {
1489-
// We now avoid directly using results from DNS Seeds which do not support service bit filtering,
1490-
// instead using them as a addrfetch to get nodes with our desired service bits.
1491+
// If the seed does not support a subdomain with our desired service bits,
1492+
// we make an ADDR_FETCH connection to the DNS resolved peer address for the
1493+
// base dns seed domain in chainparams
14911494
AddAddrFetch(seed);
14921495
}
14931496
}
@@ -1583,7 +1586,6 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
15831586
{
15841587
for (int64_t nLoop = 0;; nLoop++)
15851588
{
1586-
ProcessAddrFetch();
15871589
for (const std::string& strAddr : connect)
15881590
{
15891591
CAddress addr(CService(), NODE_NONE);

test/functional/feature_config_args.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,43 @@ def test_seed_peers(self):
224224
]):
225225
self.nodes[0].setmocktime(start + 65)
226226

227+
def test_connect_with_seednode(self):
228+
self.log.info('Test -connect with -seednode')
229+
seednode_ignored = ['-seednode is ignored when -connect is used\n']
230+
dnsseed_ignored = ['-dnsseed is ignored when -connect is used and -proxy is specified\n']
231+
addcon_thread_started = ['addcon thread start\n']
232+
self.stop_node(0)
233+
234+
# When -connect is supplied, expanding addrman via getaddr calls to ADDR_FETCH(-seednode)
235+
# nodes is irrelevant and -seednode is ignored.
236+
with self.nodes[0].assert_debug_log(expected_msgs=seednode_ignored):
237+
self.start_node(0, extra_args=['-connect=fakeaddress1', '-seednode=fakeaddress2'])
238+
239+
# With -proxy, an ADDR_FETCH connection is made to a peer that the dns seed resolves to.
240+
# ADDR_FETCH connections are not used when -connect is used.
241+
with self.nodes[0].assert_debug_log(expected_msgs=dnsseed_ignored):
242+
self.restart_node(0, extra_args=['-connect=fakeaddress1', '-dnsseed=1', '-proxy=1.2.3.4'])
243+
244+
# If the user did not disable -dnsseed, but it was soft-disabled because they provided -connect,
245+
# they shouldn't see a warning about -dnsseed being ignored.
246+
with self.nodes[0].assert_debug_log(expected_msgs=addcon_thread_started,
247+
unexpected_msgs=dnsseed_ignored):
248+
self.restart_node(0, extra_args=['-connect=fakeaddress1', '-proxy=1.2.3.4'])
249+
250+
# We have to supply expected_msgs as it's a required argument
251+
# The expected_msg must be something we are confident will be logged after the unexpected_msg
252+
# These cases test for -connect being supplied but only to disable it
253+
for connect_arg in ['-connect=0', '-noconnect']:
254+
with self.nodes[0].assert_debug_log(expected_msgs=addcon_thread_started,
255+
unexpected_msgs=seednode_ignored):
256+
self.restart_node(0, extra_args=[connect_arg, '-seednode=fakeaddress2'])
257+
227258
def run_test(self):
228259
self.test_log_buffer()
229260
self.test_args_log()
230261
self.test_seed_peers()
231262
self.test_networkactive()
263+
self.test_connect_with_seednode()
232264

233265
self.test_config_file_parser()
234266
self.test_invalid_command_line_options()

0 commit comments

Comments
 (0)