Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 1,088 Lines • ▼ Show 20 Lines | void InitParameterInteraction() { | ||||
} | } | ||||
if (IsArgSet("-whitebind")) { | if (IsArgSet("-whitebind")) { | ||||
if (SoftSetBoolArg("-listen", true)) | if (SoftSetBoolArg("-listen", true)) | ||||
LogPrintf("%s: parameter interaction: -whitebind set -> setting " | LogPrintf("%s: parameter interaction: -whitebind set -> setting " | ||||
"-listen=1\n", | "-listen=1\n", | ||||
__func__); | __func__); | ||||
} | } | ||||
if (mapMultiArgs.count("-connect") && | if (gArgs.IsArgSet("-connect")) { | ||||
mapMultiArgs.at("-connect").size() > 0) { | |||||
// when only connecting to trusted nodes, do not seed via DNS, or listen | // when only connecting to trusted nodes, do not seed via DNS, or listen | ||||
// by default. | // by default. | ||||
if (SoftSetBoolArg("-dnsseed", false)) | if (SoftSetBoolArg("-dnsseed", false)) | ||||
LogPrintf("%s: parameter interaction: -connect set -> setting " | LogPrintf("%s: parameter interaction: -connect set -> setting " | ||||
"-dnsseed=0\n", | "-dnsseed=0\n", | ||||
__func__); | __func__); | ||||
if (SoftSetBoolArg("-listen", false)) | if (SoftSetBoolArg("-listen", false)) | ||||
LogPrintf("%s: parameter interaction: -connect set -> setting " | LogPrintf("%s: parameter interaction: -connect set -> setting " | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | const int64_t blkprio = | ||||
GetArg("-blockprioritypercentage", DEFAULT_BLOCK_PRIORITY_PERCENTAGE); | GetArg("-blockprioritypercentage", DEFAULT_BLOCK_PRIORITY_PERCENTAGE); | ||||
if (!config.SetBlockPriorityPercentage(blkprio)) { | if (!config.SetBlockPriorityPercentage(blkprio)) { | ||||
return InitError(_("Block priority percentage has to belong to the " | return InitError(_("Block priority percentage has to belong to the " | ||||
"[0..100] interval.")); | "[0..100] interval.")); | ||||
} | } | ||||
// Make sure enough file descriptors are available | // Make sure enough file descriptors are available | ||||
int nBind = std::max( | int nBind = std::max( | ||||
(mapMultiArgs.count("-bind") ? mapMultiArgs.at("-bind").size() : 0) + | (gArgs.IsArgSet("-bind") ? gArgs.GetArgs("-bind").size() : 0) + | ||||
(mapMultiArgs.count("-whitebind") | (gArgs.IsArgSet("-whitebind") ? gArgs.GetArgs("-whitebind").size() | ||||
? mapMultiArgs.at("-whitebind").size() | |||||
: 0), | : 0), | ||||
size_t(1)); | size_t(1)); | ||||
nUserMaxConnections = | nUserMaxConnections = | ||||
GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); | GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); | ||||
nMaxConnections = std::max(nUserMaxConnections, 0); | nMaxConnections = std::max(nUserMaxConnections, 0); | ||||
// Trim requested connection counts, to fit into system limitations | // Trim requested connection counts, to fit into system limitations | ||||
nMaxConnections = | nMaxConnections = | ||||
std::max(std::min(nMaxConnections, | std::max(std::min(nMaxConnections, | ||||
(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - | (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - | ||||
MAX_ADDNODE_CONNECTIONS)), | MAX_ADDNODE_CONNECTIONS)), | ||||
0); | 0); | ||||
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + | nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + | ||||
MAX_ADDNODE_CONNECTIONS); | MAX_ADDNODE_CONNECTIONS); | ||||
if (nFD < MIN_CORE_FILEDESCRIPTORS) | if (nFD < MIN_CORE_FILEDESCRIPTORS) | ||||
return InitError(_("Not enough file descriptors available.")); | return InitError(_("Not enough file descriptors available.")); | ||||
nMaxConnections = | nMaxConnections = | ||||
std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS, | std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS, | ||||
nMaxConnections); | nMaxConnections); | ||||
if (nMaxConnections < nUserMaxConnections) | if (nMaxConnections < nUserMaxConnections) { | ||||
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, " | InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, " | ||||
"because of system limitations."), | "because of system limitations."), | ||||
nUserMaxConnections, nMaxConnections)); | nUserMaxConnections, nMaxConnections)); | ||||
} | |||||
// Step 3: parameter-to-internal-flags | // Step 3: parameter-to-internal-flags | ||||
if (gArgs.IsArgSet("-debug")) { | |||||
if (mapMultiArgs.count("-debug")) { | |||||
// Special-case: if -debug=0/-nodebug is set, turn off debugging | // Special-case: if -debug=0/-nodebug is set, turn off debugging | ||||
// messages | // messages | ||||
const std::vector<std::string> &categories = mapMultiArgs.at("-debug"); | const std::vector<std::string> &categories = gArgs.GetArgs("-debug"); | ||||
if (!(GetBoolArg("-nodebug", false) || | if (find(categories.begin(), categories.end(), std::string("0")) == | ||||
find(categories.begin(), categories.end(), std::string("0")) != | categories.end()) { | ||||
categories.end())) { | |||||
for (const auto &cat : categories) { | for (const auto &cat : categories) { | ||||
uint32_t flag; | uint32_t flag = 0; | ||||
if (!GetLogCategory(&flag, &cat)) { | if (!GetLogCategory(&flag, &cat)) { | ||||
InitWarning(strprintf( | InitWarning(strprintf( | ||||
_("Unsupported logging category %s.\n"), cat)); | _("Unsupported logging category %s.\n"), cat)); | ||||
} | } | ||||
logCategories |= flag; | logCategories |= flag; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | #endif | ||||
// Signal Bitcoin Cash support. | // Signal Bitcoin Cash support. | ||||
// TODO: remove some time after the hardfork when no longer needed | // TODO: remove some time after the hardfork when no longer needed | ||||
// to differentiate the network nodes. | // to differentiate the network nodes. | ||||
nLocalServices = ServiceFlags(nLocalServices | NODE_BITCOIN_CASH); | nLocalServices = ServiceFlags(nLocalServices | NODE_BITCOIN_CASH); | ||||
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); | nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); | ||||
if (mapMultiArgs.count("-bip9params")) { | if (gArgs.IsArgSet("-bip9params")) { | ||||
// Allow overriding BIP9 parameters for testing | // Allow overriding BIP9 parameters for testing | ||||
if (!chainparams.MineBlocksOnDemand()) { | if (!chainparams.MineBlocksOnDemand()) { | ||||
return InitError( | return InitError( | ||||
"BIP9 parameters may only be overridden on regtest."); | "BIP9 parameters may only be overridden on regtest."); | ||||
} | } | ||||
const std::vector<std::string> &deployments = | for (const std::string &strDeployment : gArgs.GetArgs("-bip9params")) { | ||||
mapMultiArgs.at("-bip9params"); | |||||
for (auto i : deployments) { | |||||
std::vector<std::string> vDeploymentParams; | std::vector<std::string> vDeploymentParams; | ||||
boost::split(vDeploymentParams, i, boost::is_any_of(":")); | boost::split(vDeploymentParams, strDeployment, | ||||
boost::is_any_of(":")); | |||||
if (vDeploymentParams.size() != 3) { | if (vDeploymentParams.size() != 3) { | ||||
return InitError("BIP9 parameters malformed, expecting " | return InitError("BIP9 parameters malformed, expecting " | ||||
"deployment:start:end"); | "deployment:start:end"); | ||||
} | } | ||||
int64_t nStartTime, nTimeout; | int64_t nStartTime, nTimeout; | ||||
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) { | if (!ParseInt64(vDeploymentParams[1], &nStartTime)) { | ||||
return InitError( | return InitError( | ||||
strprintf("Invalid nStartTime (%s)", vDeploymentParams[1])); | strprintf("Invalid nStartTime (%s)", vDeploymentParams[1])); | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | g_connman = std::unique_ptr<CConnman>( | ||||
new CConnman(config, GetRand(std::numeric_limits<uint64_t>::max()), | new CConnman(config, GetRand(std::numeric_limits<uint64_t>::max()), | ||||
GetRand(std::numeric_limits<uint64_t>::max()))); | GetRand(std::numeric_limits<uint64_t>::max()))); | ||||
CConnman &connman = *g_connman; | CConnman &connman = *g_connman; | ||||
peerLogic.reset(new PeerLogicValidation(&connman)); | peerLogic.reset(new PeerLogicValidation(&connman)); | ||||
RegisterValidationInterface(peerLogic.get()); | RegisterValidationInterface(peerLogic.get()); | ||||
RegisterNodeSignals(GetNodeSignals()); | RegisterNodeSignals(GetNodeSignals()); | ||||
if (mapMultiArgs.count("-onlynet")) { | if (gArgs.IsArgSet("-onlynet")) { | ||||
std::set<enum Network> nets; | std::set<enum Network> nets; | ||||
for (const std::string &snet : mapMultiArgs.at("-onlynet")) { | for (const std::string &snet : gArgs.GetArgs("-onlynet")) { | ||||
enum Network net = ParseNetwork(snet); | enum Network net = ParseNetwork(snet); | ||||
if (net == NET_UNROUTABLE) | if (net == NET_UNROUTABLE) | ||||
return InitError(strprintf( | return InitError(strprintf( | ||||
_("Unknown network specified in -onlynet: '%s'"), snet)); | _("Unknown network specified in -onlynet: '%s'"), snet)); | ||||
nets.insert(net); | nets.insert(net); | ||||
} | } | ||||
for (int n = 0; n < NET_MAX; n++) { | for (int n = 0; n < NET_MAX; n++) { | ||||
enum Network net = (enum Network)n; | enum Network net = (enum Network)n; | ||||
if (!nets.count(net)) SetLimited(net); | if (!nets.count(net)) SetLimited(net); | ||||
} | } | ||||
} | } | ||||
if (mapMultiArgs.count("-whitelist")) { | if (gArgs.IsArgSet("-whitelist")) { | ||||
for (const std::string &net : mapMultiArgs.at("-whitelist")) { | for (const std::string &net : gArgs.GetArgs("-whitelist")) { | ||||
CSubNet subnet; | CSubNet subnet; | ||||
LookupSubNet(net.c_str(), subnet); | LookupSubNet(net.c_str(), subnet); | ||||
if (!subnet.IsValid()) | if (!subnet.IsValid()) | ||||
return InitError(strprintf( | return InitError(strprintf( | ||||
_("Invalid netmask specified in -whitelist: '%s'"), net)); | _("Invalid netmask specified in -whitelist: '%s'"), net)); | ||||
connman.AddWhitelistedRange(subnet); | connman.AddWhitelistedRange(subnet); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | #endif | ||||
// see Step 2: parameter interactions for more information about these | // see Step 2: parameter interactions for more information about these | ||||
fListen = GetBoolArg("-listen", DEFAULT_LISTEN); | fListen = GetBoolArg("-listen", DEFAULT_LISTEN); | ||||
fDiscover = GetBoolArg("-discover", true); | fDiscover = GetBoolArg("-discover", true); | ||||
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); | fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); | ||||
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY); | fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY); | ||||
if (fListen) { | if (fListen) { | ||||
bool fBound = false; | bool fBound = false; | ||||
if (mapMultiArgs.count("-bind")) { | if (gArgs.IsArgSet("-bind")) { | ||||
for (const std::string &strBind : mapMultiArgs.at("-bind")) { | for (const std::string &strBind : gArgs.GetArgs("-bind")) { | ||||
CService addrBind; | CService addrBind; | ||||
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), | if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), | ||||
false)) { | false)) { | ||||
return InitError(ResolveErrMsg("bind", strBind)); | return InitError(ResolveErrMsg("bind", strBind)); | ||||
} | } | ||||
fBound |= | fBound |= | ||||
Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR)); | Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR)); | ||||
} | } | ||||
} | } | ||||
if (mapMultiArgs.count("-whitebind")) { | if (gArgs.IsArgSet("-whitebind")) { | ||||
for (const std::string &strBind : mapMultiArgs.at("-whitebind")) { | for (const std::string &strBind : gArgs.GetArgs("-whitebind")) { | ||||
CService addrBind; | CService addrBind; | ||||
if (!Lookup(strBind.c_str(), addrBind, 0, false)) { | if (!Lookup(strBind.c_str(), addrBind, 0, false)) { | ||||
return InitError(ResolveErrMsg("whitebind", strBind)); | return InitError(ResolveErrMsg("whitebind", strBind)); | ||||
} | } | ||||
if (addrBind.GetPort() == 0) { | if (addrBind.GetPort() == 0) { | ||||
return InitError(strprintf( | return InitError(strprintf( | ||||
_("Need to specify a port with -whitebind: '%s'"), | _("Need to specify a port with -whitebind: '%s'"), | ||||
strBind)); | strBind)); | ||||
} | } | ||||
fBound |= Bind(connman, addrBind, | fBound |= Bind(connman, addrBind, | ||||
(BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST)); | (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST)); | ||||
} | } | ||||
} | } | ||||
if (!mapMultiArgs.count("-bind") && !mapMultiArgs.count("-whitebind")) { | if (!gArgs.IsArgSet("-bind") && !gArgs.IsArgSet("-whitebind")) { | ||||
struct in_addr inaddr_any; | struct in_addr inaddr_any; | ||||
inaddr_any.s_addr = INADDR_ANY; | inaddr_any.s_addr = INADDR_ANY; | ||||
fBound |= | fBound |= | ||||
Bind(connman, CService(in6addr_any, GetListenPort()), BF_NONE); | Bind(connman, CService(in6addr_any, GetListenPort()), BF_NONE); | ||||
fBound |= Bind(connman, CService(inaddr_any, GetListenPort()), | fBound |= Bind(connman, CService(inaddr_any, GetListenPort()), | ||||
!fBound ? BF_REPORT_ERROR : BF_NONE); | !fBound ? BF_REPORT_ERROR : BF_NONE); | ||||
} | } | ||||
if (!fBound) { | if (!fBound) { | ||||
return InitError(_("Failed to listen on any port. Use -listen=0 if " | return InitError(_("Failed to listen on any port. Use -listen=0 if " | ||||
"you want this.")); | "you want this.")); | ||||
} | } | ||||
} | } | ||||
if (mapMultiArgs.count("-externalip")) { | if (gArgs.IsArgSet("-externalip")) { | ||||
for (const std::string &strAddr : mapMultiArgs.at("-externalip")) { | for (const std::string &strAddr : gArgs.GetArgs("-externalip")) { | ||||
CService addrLocal; | CService addrLocal; | ||||
if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), | if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), | ||||
fNameLookup) && | fNameLookup) && | ||||
addrLocal.IsValid()) { | addrLocal.IsValid()) { | ||||
AddLocal(addrLocal, LOCAL_MANUAL); | AddLocal(addrLocal, LOCAL_MANUAL); | ||||
} else { | } else { | ||||
return InitError(ResolveErrMsg("externalip", strAddr)); | return InitError(ResolveErrMsg("externalip", strAddr)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (mapMultiArgs.count("-seednode")) { | if (gArgs.IsArgSet("-seednode")) { | ||||
for (const std::string &strDest : mapMultiArgs.at("-seednode")) { | for (const std::string &strDest : gArgs.GetArgs("-seednode")) { | ||||
connman.AddOneShot(strDest); | connman.AddOneShot(strDest); | ||||
} | } | ||||
} | } | ||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
pzmqNotificationInterface = CZMQNotificationInterface::Create(); | pzmqNotificationInterface = CZMQNotificationInterface::Create(); | ||||
if (pzmqNotificationInterface) { | if (pzmqNotificationInterface) { | ||||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | #endif | ||||
// fHaveGenesis directly. | // fHaveGenesis directly. | ||||
// No locking, as this happens before any background thread is started. | // No locking, as this happens before any background thread is started. | ||||
if (chainActive.Tip() == nullptr) { | if (chainActive.Tip() == nullptr) { | ||||
uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); | uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); | ||||
} else { | } else { | ||||
fHaveGenesis = true; | fHaveGenesis = true; | ||||
} | } | ||||
if (IsArgSet("-blocknotify")) | if (IsArgSet("-blocknotify")) { | ||||
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); | uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); | ||||
} | |||||
std::vector<fs::path> vImportFiles; | std::vector<fs::path> vImportFiles; | ||||
if (mapMultiArgs.count("-loadblock")) { | if (gArgs.IsArgSet("-loadblock")) { | ||||
for (const std::string &strFile : mapMultiArgs.at("-loadblock")) { | for (const std::string &strFile : gArgs.GetArgs("-loadblock")) { | ||||
vImportFiles.push_back(strFile); | vImportFiles.push_back(strFile); | ||||
} | } | ||||
} | } | ||||
threadGroup.create_thread( | threadGroup.create_thread( | ||||
boost::bind(&ThreadImport, std::ref(config), vImportFiles)); | boost::bind(&ThreadImport, std::ref(config), vImportFiles)); | ||||
// Wait for genesis block to be processed | // Wait for genesis block to be processed | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |