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.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_ADDRDB_H7#define BITCOIN_ADDRDB_H9#include <net_types.h>10#include <util/fs.h>11#include <util/result.h>13#include <memory>14#include <vector>16class ArgsManager;17class AddrMan;18class CAddress;19class DataStream;20class NetGroupManager;22/** Only used by tests. */23void ReadFromStream(AddrMan& addr, DataStream& ssPeers);25bool DumpPeerAddresses(const ArgsManager& args, const AddrMan& addr);27/** Access to the banlist database (banlist.json) */28class CBanDB29{30private:31/**32* JSON key under which the data is stored in the json database.33*/34static constexpr const char* JSON_KEY = "banned_nets";36const fs::path m_banlist_dat;37const fs::path m_banlist_json;38public:39explicit CBanDB(fs::path ban_list_path);40bool Write(const banmap_t& banSet);42/**43* Read the banlist from disk.44* @param[out] banSet The loaded list. Set if `true` is returned, otherwise it is left45* in an undefined state.46* @return true on success47*/48bool Read(banmap_t& banSet);49};51/** Returns an error string on failure */52util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args);54/**55* Dump the anchor IP address database (anchors.dat)56*57* Anchors are last known outgoing block-relay-only peers that are58* tried to re-connect to on startup.59*/60void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors);62/**63* Read the anchor IP address database (anchors.dat)64*65* Deleting anchors.dat is intentional as it avoids renewed peering to anchors after66* an unclean shutdown and thus potential exploitation of the anchor peer policy.67*/68std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path);70#endif // BITCOIN_ADDRDB_H