Skip to content

Commit c741d74

Browse files
theunidergoegge
authored andcommitted
[net] Move ConnectionType to its own file
1 parent a3c2707 commit c741d74

File tree

5 files changed

+111
-92
lines changed

5 files changed

+111
-92
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ BITCOIN_CORE_H = \
139139
compat/cpuid.h \
140140
compat/endian.h \
141141
compressor.h \
142+
node/connection_types.h \
142143
consensus/consensus.h \
143144
consensus/tx_check.h \
144145
consensus/tx_verify.h \
@@ -368,6 +369,7 @@ libbitcoin_node_a_SOURCES = \
368369
node/caches.cpp \
369370
node/chainstate.cpp \
370371
node/coin.cpp \
372+
node/connection_types.cpp \
371373
node/context.cpp \
372374
node/interfaces.cpp \
373375
node/miner.cpp \

src/net.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -576,26 +576,6 @@ void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNet
576576
}
577577
}
578578

579-
std::string ConnectionTypeAsString(ConnectionType conn_type)
580-
{
581-
switch (conn_type) {
582-
case ConnectionType::INBOUND:
583-
return "inbound";
584-
case ConnectionType::MANUAL:
585-
return "manual";
586-
case ConnectionType::FEELER:
587-
return "feeler";
588-
case ConnectionType::OUTBOUND_FULL_RELAY:
589-
return "outbound-full-relay";
590-
case ConnectionType::BLOCK_RELAY:
591-
return "block-relay-only";
592-
case ConnectionType::ADDR_FETCH:
593-
return "addr-fetch";
594-
} // no default case, so the compiler can warn about missing cases
595-
596-
assert(false);
597-
}
598-
599579
CService CNode::GetAddrLocal() const
600580
{
601581
AssertLockNotHeld(m_addr_local_mutex);

src/net.h

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <chainparams.h>
1010
#include <common/bloom.h>
1111
#include <compat.h>
12+
#include <node/connection_types.h>
1213
#include <consensus/amount.h>
1314
#include <crypto/siphash.h>
1415
#include <hash.h>
@@ -121,78 +122,6 @@ struct CSerializedNetMsg {
121122
std::string m_type;
122123
};
123124

124-
/** Different types of connections to a peer. This enum encapsulates the
125-
* information we have available at the time of opening or accepting the
126-
* connection. Aside from INBOUND, all types are initiated by us.
127-
*
128-
* If adding or removing types, please update CONNECTION_TYPE_DOC in
129-
* src/rpc/net.cpp and src/qt/rpcconsole.cpp, as well as the descriptions in
130-
* src/qt/guiutil.cpp and src/bitcoin-cli.cpp::NetinfoRequestHandler. */
131-
enum class ConnectionType {
132-
/**
133-
* Inbound connections are those initiated by a peer. This is the only
134-
* property we know at the time of connection, until P2P messages are
135-
* exchanged.
136-
*/
137-
INBOUND,
138-
139-
/**
140-
* These are the default connections that we use to connect with the
141-
* network. There is no restriction on what is relayed; by default we relay
142-
* blocks, addresses & transactions. We automatically attempt to open
143-
* MAX_OUTBOUND_FULL_RELAY_CONNECTIONS using addresses from our AddrMan.
144-
*/
145-
OUTBOUND_FULL_RELAY,
146-
147-
148-
/**
149-
* We open manual connections to addresses that users explicitly requested
150-
* via the addnode RPC or the -addnode/-connect configuration options. Even if a
151-
* manual connection is misbehaving, we do not automatically disconnect or
152-
* add it to our discouragement filter.
153-
*/
154-
MANUAL,
155-
156-
/**
157-
* Feeler connections are short-lived connections made to check that a node
158-
* is alive. They can be useful for:
159-
* - test-before-evict: if one of the peers is considered for eviction from
160-
* our AddrMan because another peer is mapped to the same slot in the tried table,
161-
* evict only if this longer-known peer is offline.
162-
* - move node addresses from New to Tried table, so that we have more
163-
* connectable addresses in our AddrMan.
164-
* Note that in the literature ("Eclipse Attacks on Bitcoin’s Peer-to-Peer Network")
165-
* only the latter feature is referred to as "feeler connections",
166-
* although in our codebase feeler connections encompass test-before-evict as well.
167-
* We make these connections approximately every FEELER_INTERVAL:
168-
* first we resolve previously found collisions if they exist (test-before-evict),
169-
* otherwise we connect to a node from the new table.
170-
*/
171-
FEELER,
172-
173-
/**
174-
* We use block-relay-only connections to help prevent against partition
175-
* attacks. By not relaying transactions or addresses, these connections
176-
* are harder to detect by a third party, thus helping obfuscate the
177-
* network topology. We automatically attempt to open
178-
* MAX_BLOCK_RELAY_ONLY_ANCHORS using addresses from our anchors.dat. Then
179-
* addresses from our AddrMan if MAX_BLOCK_RELAY_ONLY_CONNECTIONS
180-
* isn't reached yet.
181-
*/
182-
BLOCK_RELAY,
183-
184-
/**
185-
* AddrFetch connections are short lived connections used to solicit
186-
* addresses from peers. These are initiated to addresses submitted via the
187-
* -seednode command line argument, or under certain conditions when the
188-
* AddrMan is empty.
189-
*/
190-
ADDR_FETCH,
191-
};
192-
193-
/** Convert ConnectionType enum to a string value */
194-
std::string ConnectionTypeAsString(ConnectionType conn_type);
195-
196125
/**
197126
* Look up IP addresses from all interfaces on the machine and add them to the
198127
* list of local addresses to self-advertise.

src/node/connection_types.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2022 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+
#include <node/connection_types.h>
6+
#include <cassert>
7+
8+
std::string ConnectionTypeAsString(ConnectionType conn_type)
9+
{
10+
switch (conn_type) {
11+
case ConnectionType::INBOUND:
12+
return "inbound";
13+
case ConnectionType::MANUAL:
14+
return "manual";
15+
case ConnectionType::FEELER:
16+
return "feeler";
17+
case ConnectionType::OUTBOUND_FULL_RELAY:
18+
return "outbound-full-relay";
19+
case ConnectionType::BLOCK_RELAY:
20+
return "block-relay-only";
21+
case ConnectionType::ADDR_FETCH:
22+
return "addr-fetch";
23+
} // no default case, so the compiler can warn about missing cases
24+
25+
assert(false);
26+
}

src/node/connection_types.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) 2022 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 <string>
9+
10+
/** Different types of connections to a peer. This enum encapsulates the
11+
* information we have available at the time of opening or accepting the
12+
* connection. Aside from INBOUND, all types are initiated by us.
13+
*
14+
* If adding or removing types, please update CONNECTION_TYPE_DOC in
15+
* src/rpc/net.cpp and src/qt/rpcconsole.cpp, as well as the descriptions in
16+
* src/qt/guiutil.cpp and src/bitcoin-cli.cpp::NetinfoRequestHandler. */
17+
enum class ConnectionType {
18+
/**
19+
* Inbound connections are those initiated by a peer. This is the only
20+
* property we know at the time of connection, until P2P messages are
21+
* exchanged.
22+
*/
23+
INBOUND,
24+
25+
/**
26+
* These are the default connections that we use to connect with the
27+
* network. There is no restriction on what is relayed; by default we relay
28+
* blocks, addresses & transactions. We automatically attempt to open
29+
* MAX_OUTBOUND_FULL_RELAY_CONNECTIONS using addresses from our AddrMan.
30+
*/
31+
OUTBOUND_FULL_RELAY,
32+
33+
34+
/**
35+
* We open manual connections to addresses that users explicitly requested
36+
* via the addnode RPC or the -addnode/-connect configuration options. Even if a
37+
* manual connection is misbehaving, we do not automatically disconnect or
38+
* add it to our discouragement filter.
39+
*/
40+
MANUAL,
41+
42+
/**
43+
* Feeler connections are short-lived connections made to check that a node
44+
* is alive. They can be useful for:
45+
* - test-before-evict: if one of the peers is considered for eviction from
46+
* our AddrMan because another peer is mapped to the same slot in the tried table,
47+
* evict only if this longer-known peer is offline.
48+
* - move node addresses from New to Tried table, so that we have more
49+
* connectable addresses in our AddrMan.
50+
* Note that in the literature ("Eclipse Attacks on Bitcoin’s Peer-to-Peer Network")
51+
* only the latter feature is referred to as "feeler connections",
52+
* although in our codebase feeler connections encompass test-before-evict as well.
53+
* We make these connections approximately every FEELER_INTERVAL:
54+
* first we resolve previously found collisions if they exist (test-before-evict),
55+
* otherwise we connect to a node from the new table.
56+
*/
57+
FEELER,
58+
59+
/**
60+
* We use block-relay-only connections to help prevent against partition
61+
* attacks. By not relaying transactions or addresses, these connections
62+
* are harder to detect by a third party, thus helping obfuscate the
63+
* network topology. We automatically attempt to open
64+
* MAX_BLOCK_RELAY_ONLY_ANCHORS using addresses from our anchors.dat. Then
65+
* addresses from our AddrMan if MAX_BLOCK_RELAY_ONLY_CONNECTIONS
66+
* isn't reached yet.
67+
*/
68+
BLOCK_RELAY,
69+
70+
/**
71+
* AddrFetch connections are short lived connections used to solicit
72+
* addresses from peers. These are initiated to addresses submitted via the
73+
* -seednode command line argument, or under certain conditions when the
74+
* AddrMan is empty.
75+
*/
76+
ADDR_FETCH,
77+
};
78+
79+
/** Convert ConnectionType enum to a string value */
80+
std::string ConnectionTypeAsString(ConnectionType conn_type);
81+
82+
#endif // BITCOIN_NODE_CONNECTION_TYPES_H

0 commit comments

Comments
 (0)