asmap bucketing ported from Komodo

This commit is contained in:
miodragpop
2020-09-30 14:28:55 +02:00
parent 9a3e68a832
commit 56d9c00749
19 changed files with 1562 additions and 119 deletions

View File

@@ -126,6 +126,9 @@ enum BindFlags {
};
static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h
//////////////////////////////////////////////////////////////////////////////
@@ -399,6 +402,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-zindex", strprintf(_("Maintain extra statistics about shielded transactions and payments (default: %u)"), 0));
strUsage += HelpMessageGroup(_("Connection options:"));
strUsage += HelpMessageOpt("-addnode=<ip>", _("Add a node to connect to and attempt to keep the connection open"));
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));
strUsage += HelpMessageOpt("-banscore=<n>", strprintf(_("Threshold for disconnecting misbehaving peers (default: %u)"), 100));
strUsage += HelpMessageOpt("-bantime=<n>", strprintf(_("Number of seconds to keep misbehaving peers from reconnecting (default: %u)"), 86400));
strUsage += HelpMessageOpt("-bind=<addr>", _("Bind to given address and always listen on it. Use [host]:port notation for IPv6"));
@@ -741,7 +745,7 @@ bool InitSanityCheck(void)
if (!glibc_sanity_test() || !glibcxx_sanity_test()) {
fprintf(stderr,"%s: glibc insanity!\n", __FUNCTION__);
return false;
}
}
return true;
}
@@ -806,8 +810,8 @@ static void ZC_LoadParams(
if (files_exist(sapling_spend, sapling_output)) {
LogPrintf("Found sapling params in /usr/share/hush\n");
found=true;
}
}
}
}
if (!found) {
// Try ..
@@ -816,8 +820,8 @@ static void ZC_LoadParams(
if (files_exist(sapling_spend, sapling_output)) {
LogPrintf("Found sapling params in ..\n");
found = true;
}
}
}
if (!found) {
// This will catch the case of any external software (i.e. GUI wallets) needing params and installed in same dir as hush3.git
@@ -826,7 +830,7 @@ static void ZC_LoadParams(
if (files_exist(sapling_spend, sapling_output)) {
LogPrintf("Found sapling params in ../hush3\n");
found = true;
}
}
}
if (!found) {
@@ -836,7 +840,7 @@ static void ZC_LoadParams(
if (files_exist(sapling_spend, sapling_output)) {
LogPrintf("Found sapling params in /Applications/Contents/MacOS\n");
found = true;
}
}
}
if (!found) {
@@ -846,7 +850,7 @@ static void ZC_LoadParams(
if (files_exist(sapling_spend, sapling_output)) {
LogPrintf("Found sapling params in /Applications/Contents/MacOS\n");
found = true;
}
}
}
if (!found) {
@@ -858,7 +862,7 @@ static void ZC_LoadParams(
LogPrintf("Found sapling params in ~/.zcash\n");
found = true;
}
}
}
if (!found) {
// No Sapling params, at least we tried
@@ -896,7 +900,7 @@ static void ZC_LoadParams(
static_assert( sizeof(boost::filesystem::path::value_type) == sizeof(codeunit), "librustzcash not configured correctly");
auto sapling_spend_str = sapling_spend.native();
auto sapling_spend_str = sapling_spend.native();
auto sapling_output_str = sapling_output.native();
LogPrintf("Loading Sapling (Spend) parameters from %s\n", sapling_spend.string().c_str());
@@ -1029,13 +1033,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
fprintf(stderr,"%s zmerge error\n", __FUNCTION__);
return InitError(_("RPC method z_mergetoaddress requires -experimentalfeatures."));
}
}
}
//fprintf(stderr,"%s tik2\n", __FUNCTION__);
// Set this early so that parameter interactions go to console
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
fLogIPs = GetBoolArg("-logips", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
fLogIPs = GetBoolArg("-logips", false);
LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
@@ -1084,6 +1088,31 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
}
// Read asmap file if configured
if (mapArgs.count("-asmap")) {
fs::path asmap_path = fs::path(GetArg("-asmap", ""));
if (asmap_path.empty()) {
asmap_path = DEFAULT_ASMAP_FILENAME;
}
if (!asmap_path.is_absolute()) {
asmap_path = GetDataDir() / asmap_path;
}
if (!fs::exists(asmap_path)) {
InitError(strprintf(_("Could not find asmap file %s"), asmap_path));
return false;
}
std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
if (asmap.size() == 0) {
InitError(strprintf(_("Could not parse asmap file %s"), asmap_path));
return false;
}
const uint256 asmap_version = SerializeHash(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 {
LogPrintf("Using /16 prefix for IP bucketing\n");
}
if (GetBoolArg("-salvagewallet", false)) {
// Rewrite just private keys: rescan to find transactions
if (SoftSetBoolArg("-rescan", true))
@@ -1530,7 +1559,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// -proxy sets a proxy for all outgoing network traffic
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
std::string proxyArg = GetArg("-proxy", "");
SetLimited(NET_TOR);
SetLimited(NET_ONION);
if (proxyArg != "" && proxyArg != "0") {
proxyType addrProxy = proxyType(CService(proxyArg, 9050), proxyRandomize);
if (!addrProxy.IsValid())
@@ -1538,9 +1567,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
SetProxy(NET_IPV4, addrProxy);
SetProxy(NET_IPV6, addrProxy);
SetProxy(NET_TOR, addrProxy);
SetProxy(NET_ONION, addrProxy);
SetNameProxy(addrProxy);
SetLimited(NET_TOR, false); // by default, -proxy sets onion as reachable, unless -noonion later
SetLimited(NET_ONION, false); // by default, -proxy sets onion as reachable, unless -noonion later
}
//fprintf(stderr,"%s tik20\n", __FUNCTION__);
@@ -1550,19 +1579,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
std::string onionArg = GetArg("-onion", "");
if (onionArg != "") {
if (onionArg == "0") { // Handle -noonion/-onion=0
SetLimited(NET_TOR); // set onions as unreachable
SetLimited(NET_ONION); // set onions as unreachable
} else {
proxyType addrOnion = proxyType(CService(onionArg, 9050), proxyRandomize);
if (!addrOnion.IsValid())
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
SetProxy(NET_TOR, addrOnion);
SetLimited(NET_TOR, false);
SetProxy(NET_ONION, addrOnion);
SetLimited(NET_ONION, false);
}
}
// see Step 2: parameter interactions for more information about these
fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
fDiscover = GetBoolArg("-discover", true);
fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
fDiscover = GetBoolArg("-discover", true);
fNameLookup = GetBoolArg("-dns", true);
//fprintf(stderr,"%s tik22\n", __FUNCTION__);
@@ -1624,7 +1653,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
boost::filesystem::path pathTLSTrustredDir(GetArg("-tlstrustdir", ""));
if (!boost::filesystem::exists(pathTLSTrustredDir))
return InitError(strprintf(_("Cannot find trusted certificates directory: '%s'"), pathTLSTrustredDir.string()));
}
}
#if ENABLE_ZMQ
pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs);
@@ -2142,7 +2171,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
LOCK(cs_main);
fHaveGenesis = (chainActive.Tip() != NULL);
MilliSleep(10);
}
}
if (!fHaveGenesis) {
MilliSleep(10);