Skip to content

Commit 618b8d1

Browse files
jonatackfurszy
authored andcommitted
config: enable passing -asmap an absolute file path
- allow passing an absolute file path to the -asmap config arg - update the -asmap config help - add a functional test in feature_asmap.py
1 parent 8c7bdbe commit 618b8d1

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ std::string HelpMessage(HelpMessageMode mode)
475475

476476
strUsage += HelpMessageGroup(_("Connection options:"));
477477
strUsage += HelpMessageOpt("-addnode=<ip>", _("Add a node to connect to and attempt to keep the connection open"));
478-
strUsage += HelpMessageOpt("-asmap=<file>", strprintf("Specify asn mapping used for bucketing of the peers (default: %s). Path should be relative to the -datadir path.", DEFAULT_ASMAP_FILENAME);
478+
strUsage += HelpMessageOpt("-asmap=<file>", strprintf("Specify asn mapping used for bucketing of the peers (default: %s). Relative paths will be prefixed by the net-specific datadir location.", DEFAULT_ASMAP_FILENAME));
479479
strUsage += HelpMessageOpt("-banscore=<n>", strprintf(_("Threshold for disconnecting misbehaving peers (default: %u)"), DEFAULT_BANSCORE_THRESHOLD));
480480
strUsage += HelpMessageOpt("-bantime=<n>", strprintf(_("Number of seconds to keep misbehaving peers from reconnecting (default: %u)"), DEFAULT_MISBEHAVING_BANTIME));
481481
strUsage += HelpMessageOpt("-bind=<addr>", _("Bind to given address and always listen on it. Use [host]:port notation for IPv6"));
@@ -1969,11 +1969,13 @@ bool AppInitMain()
19691969

19701970
// Read asmap file if configured
19711971
if (gArgs.IsArgSet("-asmap")) {
1972-
std::string asmap_file = gArgs.GetArg("-asmap", "");
1973-
if (asmap_file.empty()) {
1974-
asmap_file = DEFAULT_ASMAP_FILENAME;
1972+
fs::path asmap_path = fs::path(gArgs.GetArg("-asmap", ""));
1973+
if (asmap_path.empty()) {
1974+
asmap_path = DEFAULT_ASMAP_FILENAME;
1975+
}
1976+
if (!asmap_path.is_absolute()) {
1977+
asmap_path = GetDataDir() / asmap_path;
19751978
}
1976-
const fs::path asmap_path = GetDataDir() / asmap_file;
19771979
std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
19781980
if (asmap.size() == 0) {
19791981
UIError(strprintf(_("Could not find or parse specified asmap: '%s'"), asmap_path));

test/functional/feature_asmap.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
99
1. `bitcoind` with no -asmap arg, using /16 prefix for IP bucketing
1010
11-
2. `bitcoind -asmap=<relative path>`, using the unit test skeleton asmap
11+
2. `bitcoind -asmap=<absolute path>`, using the unit test skeleton asmap
1212
13-
3. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap
13+
3. `bitcoind -asmap=<relative path>`, using the unit test skeleton asmap
1414
15-
4. `bitcoind -asmap` with no file specified, and a missing default asmap file
15+
4. `bitcoind -asmap/-asmap=` with no file specified, using the default asmap
16+
17+
5. `bitcoind -asmap` with no file specified and a missing default asmap file
1618
1719
The tests are order-independent. The slowest test (missing default asmap file)
1820
is placed last.
@@ -42,6 +44,15 @@ def test_without_asmap_arg(self):
4244
with self.node.assert_debug_log(['Using /16 prefix for IP bucketing']):
4345
self.start_node(0)
4446

47+
def test_asmap_with_absolute_path(self):
48+
self.log.info('Test bitcoind -asmap=<absolute path>')
49+
self.stop_node(0)
50+
filename = os.path.join(self.datadir, 'my-map-file.map')
51+
shutil.copyfile(self.asmap_raw, filename)
52+
with self.node.assert_debug_log(expected_messages(filename)):
53+
self.start_node(0, ['-asmap={}'.format(filename)])
54+
os.remove(filename)
55+
4556
def test_asmap_with_relative_path(self):
4657
self.log.info('Test bitcoind -asmap=<relative path>')
4758
self.stop_node(0)
@@ -74,6 +85,7 @@ def run_test(self):
7485
self.asmap_raw = os.path.join(os.path.dirname(os.path.realpath(__file__)), ASMAP)
7586

7687
self.test_without_asmap_arg()
88+
self.test_asmap_with_absolute_path()
7789
self.test_asmap_with_relative_path()
7890
self.test_default_asmap()
7991
#self.test_default_asmap_with_missing_file() // fixme

0 commit comments

Comments
 (0)