Inside Bitcoin
Opening the selected file…
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-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <netaddress.h>6#include <netbase.h>8#include <string>9#include <type_traits>10#include <vector>12#ifndef BITCOIN_NET_PERMISSIONS_H13#define BITCOIN_NET_PERMISSIONS_H15struct bilingual_str;17extern const std::vector<std::string> NET_PERMISSIONS_DOC;19/** Default for -whitelistrelay. */20inline constexpr bool DEFAULT_WHITELISTRELAY = true;21/** Default for -whitelistforcerelay. */22inline constexpr bool DEFAULT_WHITELISTFORCERELAY = false;24enum class NetPermissionFlags : uint32_t {25None = 0,26// Can query bloomfilter even if -peerbloomfilters is false27BloomFilter = (1U << 1),28// Relay and accept transactions from this peer, even if -blocksonly is true29// This peer is also not subject to limits on how many transaction INVs are tracked30Relay = (1U << 3),31// Always relay transactions from this peer, even if already in mempool32// Keep parameter interaction: forcerelay implies relay33ForceRelay = (1U << 2) | Relay,34// Allow getheaders during IBD and block-download after maxuploadtarget limit35Download = (1U << 6),36// Can't be banned/disconnected/discouraged for misbehavior37NoBan = (1U << 4) | Download,38// Can query the mempool39Mempool = (1U << 5),40// Can request addrs without hitting a privacy-preserving cache, and send us41// unlimited amounts of addrs.42Addr = (1U << 7),44// True if the user did not specifically set fine-grained permissions with45// the -whitebind or -whitelist configuration options.46Implicit = (1U << 31),47All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr,48};49constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)50{51using t = std::underlying_type_t<NetPermissionFlags>;52return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b));53}55class NetPermissions56{57public:58NetPermissionFlags m_flags;59static std::vector<std::string> ToStrings(NetPermissionFlags flags);60static inline bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)61{62using t = std::underlying_type_t<NetPermissionFlags>;63return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(f);64}65static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f)66{67flags = flags | f;68}69//! ClearFlag is only called with `f` == NetPermissionFlags::Implicit.70//! If that should change in the future, be aware that ClearFlag should not71//! be called with a subflag of a multiflag, e.g. NetPermissionFlags::Relay72//! or NetPermissionFlags::Download, as that would leave `flags` in an73//! invalid state corresponding to none of the existing flags.74static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)75{76assert(f == NetPermissionFlags::Implicit);77using t = std::underlying_type_t<NetPermissionFlags>;78flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));79}80};82class NetWhitebindPermissions : public NetPermissions83{84public:85static bool TryParse(const std::string& str, NetWhitebindPermissions& output, bilingual_str& error);86CService m_service;87};89class NetWhitelistPermissions : public NetPermissions90{91public:92static bool TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error);93CSubNet m_subnet;94};96#endif // BITCOIN_NET_PERMISSIONS_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.