Try hard to find asmap.dat in all scenarios: src, binary, packages
This commit is contained in:
51
src/init.cpp
51
src/init.cpp
@@ -1097,13 +1097,52 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
fs::path pwd = fs::path(cwd);
|
fs::path pwd = fs::path(cwd);
|
||||||
fs::path contrib = pwd / ".." / "contrib" / "asmap";
|
fs::path contrib = pwd / ".." / "contrib" / "asmap";
|
||||||
|
|
||||||
// if no filepath, use the default in contrib
|
// If no asmap given (default), look for one
|
||||||
|
// First we look in PWD, the most common case (binaries)
|
||||||
|
// Then we look in /usr/share/hush, for Debian packages
|
||||||
|
// then we look in ../contrib/asmap/ for compiling from source case
|
||||||
|
// finally we try the parent directory .. as a last resort
|
||||||
|
// if no asmap can be found, something is wrong, and we exit
|
||||||
if (asmap_path.empty()) {
|
if (asmap_path.empty()) {
|
||||||
asmap_path = contrib / DEFAULT_ASMAP_FILENAME;
|
// Most binaries will have it in PWD
|
||||||
}
|
asmap_path = pwd / DEFAULT_ASMAP_FILENAME;
|
||||||
if (!asmap_path.is_absolute()) {
|
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
asmap_path = GetDataDir() / asmap_path;
|
if(fs::exists(asmap_path)) {
|
||||||
|
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
} else {
|
||||||
|
// Debian Packages
|
||||||
|
asmap_path = fs::path("/usr/share/hush") / DEFAULT_ASMAP_FILENAME;
|
||||||
|
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
if(fs::exists(asmap_path)) {
|
||||||
|
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
} else {
|
||||||
|
// Source code
|
||||||
|
asmap_path = contrib / DEFAULT_ASMAP_FILENAME;
|
||||||
|
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
if(fs::exists(asmap_path)) {
|
||||||
|
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
} else {
|
||||||
|
// Last Resort: Check the parent directory
|
||||||
|
asmap_path = pwd / ".." / DEFAULT_ASMAP_FILENAME;
|
||||||
|
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
if(fs::exists(asmap_path)) {
|
||||||
|
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
|
} else {
|
||||||
|
// Shit is fucked up, die an honorable death
|
||||||
|
InitError(strprintf(_("Could not find any asmap file! Please report this bug to Hush Developers")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!asmap_path.is_absolute()) {
|
||||||
|
asmap_path = GetDataDir() / asmap_path;
|
||||||
|
}
|
||||||
|
printf("%s: looking for custom asmap file at %s\n", __func__, asmap_path.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: verify asmap_path is not a directory
|
||||||
if (!fs::exists(asmap_path)) {
|
if (!fs::exists(asmap_path)) {
|
||||||
InitError(strprintf(_("Could not find asmap file %s"), asmap_path));
|
InitError(strprintf(_("Could not find asmap file %s"), asmap_path));
|
||||||
return false;
|
return false;
|
||||||
@@ -1115,8 +1154,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
}
|
}
|
||||||
const uint256 asmap_version = SerializeHash(asmap);
|
const uint256 asmap_version = SerializeHash(asmap);
|
||||||
printf("%s: asmap version=%s with %lu mappings\n", __func__, asmap_version.ToString().c_str(), asmap.size());
|
printf("%s: asmap version=%s with %lu mappings\n", __func__, asmap_version.ToString().c_str(), asmap.size());
|
||||||
|
LogPrintf("Using asmap version %s for IP bucketing with %lu mappings\n", asmap_version.ToString(), asmap.size());
|
||||||
addrman.m_asmap = std::move(asmap); // //node.connman->SetAsmap(std::move(asmap));
|
addrman.m_asmap = std::move(asmap); // //node.connman->SetAsmap(std::move(asmap));
|
||||||
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LogPrintf("Using /16 prefix for IP bucketing, but why?\n");
|
LogPrintf("Using /16 prefix for IP bucketing, but why?\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user