Repository: bitcoin/bitcoin
File: src/init.cpp (C++)

Code before:
     * be disabled when initialisation is finished.
     */
    if (args.GetBoolArg("-server", false)) {
        uiInterface.InitMessage_connect(SetRPCWarmupStatus);
        if (!AppInitServers(node))
            return InitError(_("Unable to start HTTP server. See debug log for details."));
    }

    // ********************************************************* Step 5: verify wallet database integrity
    for (const auto& client : node.chain_clients) {
        if (!client->verify()) {
            return false;
        }
    }

    // ********************************************************* Step 6: network initialization
    // Note that we absolutely cannot open any actual connections
    // until the very end ("start node") as the UTXO/block state
    // is not yet setup and may end up being set up twice if we
    // need to reindex later.

    fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
    fDiscover = args.GetBoolArg("-discover", true);

    PeerManager::Options peerman_opts{};
    ApplyArgsManOptions(args, peerman_opts);

    {
        // Read asmap file if configured and initialize
        // Netgroupman with or without it
        assert(!node.netgroupman);
        if (args.IsArgSet("-asmap") && !args.IsArgNegated("-asmap")) {
            fs::path asmap_path = args.GetPathArg("-asmap");
            if (asmap_path.empty()) {
                InitError(_("-asmap requires a file path. Use -asmap=<file>."));
                return false;
            }
            if (!asmap_path.is_absolute()) {
                asmap_path = args.GetDataDirNet() / asmap_path;
            }
            if (!fs::exists(asmap_path)) {
                InitError(strprintf(_("Could not find asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
                return false;
            }
            std::vector<std::byte> asmap{DecodeAsmap(asmap_path)};
            if (asmap.size() == 0) {
                InitError(strprintf(_("Could not parse asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
                return false;
            }
            const uint256 asmap_version = AsmapVersion(asmap);
            node.netgroupman = std::make_unique<NetGroupManager>(NetGroupManager::WithLoadedAsmap(std::move(asmap)));

Review comment (refactor):
meganit in 0b13a009d259adff3468ad5111295a80584ee51b "refactor: Use span instead of vector for data in util/asmap":
This comment should probably change in one of the later commits, like f5c8e41733fe91b6f7c66056a0a40c9b8ab86257 "init, net: Implement usage of binary-embedded asmap data".

Code after:
        g_reachable_nets.Remove(NET_CJDNS);
    }
    // Now g_reachable_nets.Contains(NET_CJDNS) is true if:
    // 1. -cjdnsreachable is given and
    // 2.1. -onlynet is not given or
    // 2.2. -onlynet=cjdns is given

    /* Start the RPC server already.  It will be started in "warmup" mode
     * and not really process calls already (but it will signify connections
     * that the server is there and will be ready later).  Warmup mode will
     * be disabled when initialisation is finished.
     */
    if (args.GetBoolArg("-server", false)) {
        uiInterface.InitMessage_connect(SetRPCWarmupStatus);
        if (!AppInitServers(node))
            return InitError(_("Unable to start HTTP server. See debug log for details."));
    }

    // ********************************************************* Step 5: verify wallet database integrity
    for (const auto& client : node.chain_clients) {
        if (!client->verify()) {
            return false;
        }
    }

    // ********************************************************* Step 6: network initialization
    // Note that we absolutely cannot open any actual connections
    // until the very end ("start node") as the UTXO/block state
    // is not yet setup and may end up being set up twice if we
    // need to reindex later.

    fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
    fDiscover = args.GetBoolArg("-discover", true);

    PeerManager::Options peerman_opts{};
    ApplyArgsManOptions(args, peerman_opts);

    {
        // Read asmap file if configured or embedded asmap data and initialize
        // Netgroupman with or without it
        assert(!node.netgroupman);
        if (args.IsArgSet("-asmap") && !args.IsArgNegated("-asmap")) {
            uint256 asmap_version{};
            if (!args.GetBoolArg("-asmap", false)) {
                fs::path asmap_path = args.GetPathArg("-asmap");
                if (!asmap_path.is_absolute()) {
                    asmap_path = args.GetDataDirNet() / asmap_path;
                }

                // If a specific path was passed with the asmap argument check if
                // the file actually exists in that location