1 // Copyright (c) 2022-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 5 #ifndef BITCOIN_NODE_CONNECTION_TYPES_H
6 #define BITCOIN_NODE_CONNECTION_TYPES_H
7 8 #include <cstdint>
9 #include <string>
10 11 /** Different types of connections to a peer. This enum encapsulates the
12 * information we have available at the time of opening or accepting the
13 * connection. Aside from INBOUND, all types are initiated by us.
14 *
15 * If adding or removing types, please update CONNECTION_TYPE_DOC in
16 * src/rpc/net.cpp and src/qt/rpcconsole.cpp, as well as the descriptions in
17 * src/qt/guiutil.cpp and src/bitcoin-cli.cpp::NetinfoRequestHandler. */
18 enum class ConnectionType {
19 /**
20 * Inbound connections are those initiated by a peer. This is the only
21 * property we know at the time of connection, until P2P messages are
22 * exchanged.
23 */
24 INBOUND,
25 26 /**
27 * These are the default connections that we use to connect with the
28 * network. There is no restriction on what is relayed; by default we relay
29 * blocks, addresses & transactions. We automatically attempt to open
30 * MAX_OUTBOUND_FULL_RELAY_CONNECTIONS using addresses from our AddrMan.
31 */
32 OUTBOUND_FULL_RELAY,
33 34 35 /**
36 * We open manual connections to addresses that users explicitly requested
37 * via the addnode RPC or the -addnode/-connect configuration options. Even if a
38 * manual connection is misbehaving, we do not automatically disconnect or
39 * add it to our discouragement filter.
40 */
41 MANUAL,
42 43 /**
44 * Feeler connections are short-lived connections made to check that a node
45 * is alive. They can be useful for:
46 * - test-before-evict: if one of the peers is considered for eviction from
47 * 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 more
50 * 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 */
58 FEELER,
59 60 /**
61 * We use block-relay-only connections to help prevent against partition
62 * attacks. By not relaying transactions or addresses, these connections
63 * are harder to detect by a third party, thus helping obfuscate the
64 * network topology. We automatically attempt to open
65 * MAX_BLOCK_RELAY_ONLY_ANCHORS using addresses from our anchors.dat. Then
66 * addresses from our AddrMan if MAX_BLOCK_RELAY_ONLY_CONNECTIONS
67 * isn't reached yet.
68 */
69 BLOCK_RELAY,
70 71 /**
72 * AddrFetch connections are short lived connections used to solicit
73 * addresses from peers. These are initiated to addresses submitted via the
74 * -seednode command line argument, or under certain conditions when the
75 * AddrMan is empty.
76 */
77 ADDR_FETCH,
78 79 /**
80 * Private broadcast connections are short-lived and only opened to
81 * privacy networks (Tor, I2P) for relaying privacy-sensitive data (like
82 * our own transactions) and closed afterwards.
83 */
84 PRIVATE_BROADCAST,
85 };
86 87 /** Convert ConnectionType enum to a string value */
88 std::string ConnectionTypeAsString(ConnectionType conn_type);
89 90 /** Transport layer version */
91 enum class TransportProtocolType : uint8_t {
92 DETECTING, //!< Peer could be v1 or v2
93 V1, //!< Unencrypted, plaintext protocol
94 V2, //!< BIP324 protocol
95 };
96 97 /** Convert TransportProtocolType enum to a string value */
98 std::string TransportTypeAsString(TransportProtocolType transport_type);
99 100 #endif // BITCOIN_NODE_CONNECTION_TYPES_H
101