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) 2022-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#ifndef BITCOIN_NODE_CONNECTION_TYPES_H6#define BITCOIN_NODE_CONNECTION_TYPES_H8#include <cstdint>9#include <string>11/** Different types of connections to a peer. This enum encapsulates the12* information we have available at the time of opening or accepting the13* connection. Aside from INBOUND, all types are initiated by us.14*15* If adding or removing types, please update CONNECTION_TYPE_DOC in16* src/rpc/net.cpp and src/qt/rpcconsole.cpp, as well as the descriptions in17* src/qt/guiutil.cpp and src/bitcoin-cli.cpp::NetinfoRequestHandler. */18enum class ConnectionType {19/**20* Inbound connections are those initiated by a peer. This is the only21* property we know at the time of connection, until P2P messages are22* exchanged.23*/24INBOUND,26/**27* These are the default connections that we use to connect with the28* network. There is no restriction on what is relayed; by default we relay29* blocks, addresses & transactions. We automatically attempt to open30* MAX_OUTBOUND_FULL_RELAY_CONNECTIONS using addresses from our AddrMan.31*/32OUTBOUND_FULL_RELAY,35/**36* We open manual connections to addresses that users explicitly requested37* via the addnode RPC or the -addnode/-connect configuration options. Even if a38* manual connection is misbehaving, we do not automatically disconnect or39* add it to our discouragement filter.40*/41MANUAL,43/**44* Feeler connections are short-lived connections made to check that a node45* is alive. They can be useful for:46* - test-before-evict: if one of the peers is considered for eviction from47* our AddrMan because another peer is mapped to the same slot in the tried table,48* evict only if this longer-known peer is offline.49* - move node addresses from New to Tried table, so that we have more50* connectable addresses in our AddrMan.51* Note that in the literature ("Eclipse Attacks on Bitcoin’s Peer-to-Peer Network")52* only the latter feature is referred to as "feeler connections",53* although in our codebase feeler connections encompass test-before-evict as well.54* We make these connections approximately every FEELER_INTERVAL:55* first we resolve previously found collisions if they exist (test-before-evict),56* otherwise we connect to a node from the new table.57*/58FEELER,60/**61* We use block-relay-only connections to help prevent against partition62* attacks. By not relaying transactions or addresses, these connections63* are harder to detect by a third party, thus helping obfuscate the64* network topology. We automatically attempt to open65* MAX_BLOCK_RELAY_ONLY_ANCHORS using addresses from our anchors.dat. Then66* addresses from our AddrMan if MAX_BLOCK_RELAY_ONLY_CONNECTIONS67* isn't reached yet.68*/69BLOCK_RELAY,71/**72* AddrFetch connections are short lived connections used to solicit73* addresses from peers. These are initiated to addresses submitted via the74* -seednode command line argument, or under certain conditions when the75* AddrMan is empty.76*/77ADDR_FETCH,79/**80* Private broadcast connections are short-lived and only opened to81* privacy networks (Tor, I2P) for relaying privacy-sensitive data (like82* our own transactions) and closed afterwards.83*/84PRIVATE_BROADCAST,85};87/** Convert ConnectionType enum to a string value */88std::string ConnectionTypeAsString(ConnectionType conn_type);90/** Transport layer version */91enum class TransportProtocolType : uint8_t {92DETECTING, //!< Peer could be v1 or v293V1, //!< Unencrypted, plaintext protocol94V2, //!< BIP324 protocol95};97/** Convert TransportProtocolType enum to a string value */98std::string TransportTypeAsString(TransportProtocolType transport_type);100#endif // BITCOIN_NODE_CONNECTION_TYPES_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.