Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
751if (can_listen_ipc) {752argsman.AddArg("-ipcbind=<address>", "Bind to Unix socket address and listen for incoming connections. Valid address values are \"unix\" to listen on the default path, <datadir>/node.sock, or \"unix:/custom/path\" to specify a custom path. Can be specified multiple times to listen on multiple paths. Default behavior is not to listen on any path. If relative paths are specified, they are interpreted relative to the network data directory. If paths include any parent directory components and the parent directories do not exist, they will be created. Enabling this gives local processes that can access the socket unauthenticated RPC access, so it's important to choose a path with secure permissions if customizing this.", ArgsManager::ALLOW_ANY, OptionsCategory::IPC);753}755#if HAVE_DECL_FORK756argsman.AddArg("-daemon", strprintf("Run in the background as a daemon and accept commands (default: %d)", DEFAULT_DAEMON), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);757argsman.AddArg("-daemonwait", strprintf("Wait for initialization to be finished before exiting. This implies -daemon (default: %d)", DEFAULT_DAEMONWAIT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);758#else759hidden_args.emplace_back("-daemon");760hidden_args.emplace_back("-daemonwait");761#endif763// Add the hidden options764argsman.AddHiddenArgs(hidden_args);765}767#if HAVE_SYSTEM768static void StartupNotify(const ArgsManager& args)769{770std::string cmd = args.GetArg("-startupnotify", "");771if (!cmd.empty()) {772std::thread t(runCommand, cmd);773t.detach(); // thread runs free774}775}776#endif778static bool AppInitServers(NodeContext& node)779{780const ArgsManager& args = *Assert(node.args);781if (!InitHTTPServer()) {782return false;783}784StartRPC();785node.rpc_interruption_point = RpcInterruptionPoint;786if (!StartHTTPRPC(&node))787return false;788if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(&node);789StartHTTPServer();790return true;791}793// Parameter interaction based on rules794void InitParameterInteraction(ArgsManager& args)795{796// when specifying an explicit binding address, you want to listen on it797// even when -connect or -proxy is specified798if (!args.GetArgs("-bind").empty()) {799if (args.SoftSetBoolArg("-listen", true))800LogInfo("parameter interaction: -bind set -> setting -listen=1\n");801}802if (!args.GetArgs("-whitebind").empty()) {803if (args.SoftSetBoolArg("-listen", true))804LogInfo("parameter interaction: -whitebind set -> setting -listen=1\n");805}807if (!args.GetArgs("-connect").empty() || args.IsArgNegated("-connect") || args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS) <= 0) {808// when only connecting to trusted nodes, do not seed via DNS, or listen by default809// do the same when connections are disabled810if (args.SoftSetBoolArg("-dnsseed", false))811LogInfo("parameter interaction: -connect or -maxconnections=0 set -> setting -dnsseed=0\n");812if (args.SoftSetBoolArg("-listen", false))813LogInfo("parameter interaction: -connect or -maxconnections=0 set -> setting -listen=0\n");814}816std::string proxy_arg = args.GetArg("-proxy", "");817if (proxy_arg != "" && proxy_arg != "0") {818// to protect privacy, do not listen by default if a default proxy server is specified819if (args.SoftSetBoolArg("-listen", false))820LogInfo("parameter interaction: -proxy set -> setting -listen=0\n");821// to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1822// to listen locally, so don't rely on this happening through -listen below.823if (args.SoftSetBoolArg("-natpmp", false)) {824LogInfo("parameter interaction: -proxy set -> setting -natpmp=0\n");825}826// to protect privacy, do not discover addresses by default827if (args.SoftSetBoolArg("-discover", false))828LogInfo("parameter interaction: -proxy set -> setting -discover=0\n");829}831if (!args.GetBoolArg("-listen", DEFAULT_LISTEN)) {832// do not map ports or try to retrieve public IP when not listening (pointless)833if (args.SoftSetBoolArg("-natpmp", false)) {834LogInfo("parameter interaction: -listen=0 -> setting -natpmp=0\n");835}836if (args.SoftSetBoolArg("-discover", false))837LogInfo("parameter interaction: -listen=0 -> setting -discover=0\n");838if (args.SoftSetBoolArg("-listenonion", false))839LogInfo("parameter interaction: -listen=0 -> setting -listenonion=0\n");840if (args.SoftSetBoolArg("-i2pacceptincoming", false)) {841LogInfo("parameter interaction: -listen=0 -> setting -i2pacceptincoming=0\n");842}843}845if (!args.GetArgs("-externalip").empty()) {846// if an explicit public IP is specified, do not try to find others847if (args.SoftSetBoolArg("-discover", false))848LogInfo("parameter interaction: -externalip set -> setting -discover=0\n");849}851if (args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {852// disable whitelistrelay in blocksonly mode853if (args.SoftSetBoolArg("-whitelistrelay", false))854LogInfo("parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n");855// Reduce default mempool size in blocksonly mode to avoid unexpected resource usage856if (args.SoftSetArg("-maxmempool", ToString(DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB)))857LogInfo("parameter interaction: -blocksonly=1 -> setting -maxmempool=%d\n", DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB);858}860// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.861if (args.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {862if (args.SoftSetBoolArg("-whitelistrelay", true))863LogInfo("parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n");864}865const auto onlynets = args.GetArgs("-onlynet");866if (!onlynets.empty()) {867bool clearnet_reachable = std::any_of(onlynets.begin(), onlynets.end(), [](const auto& net) {868const auto n = ParseNetwork(net);869return n == NET_IPV4 || n == NET_IPV6;870});871if (!clearnet_reachable && args.SoftSetBoolArg("-dnsseed", false)) {872LogInfo("parameter interaction: -onlynet excludes IPv4 and IPv6 -> setting -dnsseed=0\n");873}874}875}877/**878* Initialize global loggers.879*880* Note that this is called very early in the process lifetime, so you should be881* careful about what global state you rely on here.882*/883void InitLogging(const ArgsManager& args)884{885init::SetLoggingOptions(args);886init::LogPackageVersion();887}889namespace { // Variables internal to initialization process only891int num_p2p_max_connections;892int available_fds;893ServiceFlags g_local_services = ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);894int64_t peer_connect_timeout;895std::set<BlockFilterType> g_enabled_filter_types;897} // namespace899[[noreturn]] static void new_handler_terminate()900{901// Rather than throwing std::bad-alloc if allocation fails, terminate902// immediately to (try to) avoid chain corruption.903// Since logging may itself allocate memory, set the handler directly904// to terminate first.905std::set_new_handler(std::terminate);906LogError("Out of memory. Terminating.\n");908// The log was successful, terminate now.909std::terminate();910};912bool AppInitBasicSetup(const ArgsManager& args, std::atomic<int>& exit_status)913{914// ********************************************************* Step 1: setup915#ifdef _MSC_VER916// Turn off Microsoft heap dump noise917_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);918_CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0));919// Disable confusing "helpful" text message on abort, Ctrl-C920_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);921#endif922#ifdef WIN32923// Enable heap terminate-on-corruption924HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);925#endif926if (!SetupNetworking()) {927return InitError(Untranslated("Initializing networking failed."));928}930#ifndef WIN32931// Clean shutdown on SIGTERM932registerSignalHandler(SIGTERM, HandleSIGTERM);933registerSignalHandler(SIGINT, HandleSIGTERM);935// Reopen debug.log on SIGHUP936registerSignalHandler(SIGHUP, HandleSIGHUP);938// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly939signal(SIGPIPE, SIG_IGN);940#else941SetConsoleCtrlHandler(consoleCtrlHandler, true);942#endif944std::set_new_handler(new_handler_terminate);946return true;947}949bool AppInitParameterInteraction(const ArgsManager& args)950{951const CChainParams& chainparams = Params();952// ********************************************************* Step 2: parameter interactions954// also see: InitParameterInteraction()956// We removed checkpoints but keep the option to warn users who still have it in their config.957if (args.IsArgSet("-checkpoints")) {958InitWarning(_("Option '-checkpoints' is set but checkpoints were removed. This option has no effect."));959}960if (args.IsArgSet("-limitancestorsize")) {961InitWarning(_("Option '-limitancestorsize' is given but ancestor size limits have been replaced with cluster size limits (see -limitclustersize). This option has no effect."));962}963if (args.IsArgSet("-limitdescendantsize")) {964InitWarning(_("Option '-limitdescendantsize' is given but descendant size limits have been replaced with cluster size limits (see -limitclustersize). This option has no effect."));965}967// Error if network-specific options (-addnode, -connect, etc) are968// specified in default section of config file, but not overridden969// on the command line or in this chain's section of the config file.970ChainType chain = args.GetChainType();971if (chain == ChainType::SIGNET) {972LogInfo("Signet derived magic (message start): %s", HexStr(chainparams.MessageStart()));973}974bilingual_str errors;975for (const auto& arg : args.GetUnsuitableSectionOnlyArgs()) {976errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section."), arg, ChainTypeToString(chain), ChainTypeToString(chain)) + Untranslated("\n");977}979if (!errors.empty()) {980return InitError(errors);981}983// Testnet3 deprecation warning984if (chain == ChainType::TESTNET) {985LogInfo("Warning: Support for testnet3 is deprecated and will be removed in an upcoming release. Consider switching to testnet4.\n");986}988// Warn if unrecognized section name are present in the config file.989bilingual_str warnings;990for (const auto& section : args.GetUnrecognizedSections()) {991warnings += Untranslated(strprintf("%s:%i ", section.m_file, section.m_line)) + strprintf(_("Section [%s] is not recognized."), section.m_name) + Untranslated("\n");992}994if (!warnings.empty()) {995InitWarning(warnings);996}998if (!fs::is_directory(args.GetBlocksDirPath())) {999return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));1000}