Skip to content

Commit c97f70c

Browse files
committed
net_processing: move Peer definition to .cpp
1 parent e0f2e6d commit c97f70c

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

src/net_processing.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,61 @@ void EraseOrphansFor(NodeId peer);
169169

170170
// Internal stuff
171171
namespace {
172+
/**
173+
* Data structure for an individual peer. This struct is not protected by
174+
* cs_main since it does not contain validation-critical data.
175+
*
176+
* Memory is owned by shared pointers and this object is destructed when
177+
* the refcount drops to zero.
178+
*
179+
* Mutexes inside this struct must not be held when locking m_peer_mutex.
180+
*
181+
* TODO: move most members from CNodeState to this structure.
182+
* TODO: move remaining application-layer data members from CNode to this structure.
183+
*/
184+
struct Peer {
185+
/** Same id as the CNode object for this peer */
186+
const NodeId m_id{0};
187+
188+
/** Protects misbehavior data members */
189+
Mutex m_misbehavior_mutex;
190+
/** Accumulated misbehavior score for this peer */
191+
int m_misbehavior_score GUARDED_BY(m_misbehavior_mutex){0};
192+
/** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
193+
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false};
194+
195+
/** Protects block inventory data members */
196+
Mutex m_block_inv_mutex;
197+
/** List of blocks that we'll announce via an `inv` message.
198+
* There is no final sorting before sending, as they are always sent
199+
* immediately and in the order requested. */
200+
std::vector<uint256> m_blocks_for_inv_relay GUARDED_BY(m_block_inv_mutex);
201+
/** Unfiltered list of blocks that we'd like to announce via a `headers`
202+
* message. If we can't announce via a `headers` message, we'll fall back to
203+
* announcing via `inv`. */
204+
std::vector<uint256> m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex);
205+
/** The final block hash that we sent in an `inv` message to this peer.
206+
* When the peer requests this block, we send an `inv` message to trigger
207+
* the peer to request the next sequence of block hashes.
208+
* Most peers use headers-first syncing, which doesn't use this mechanism */
209+
uint256 m_continuation_block GUARDED_BY(m_block_inv_mutex) {};
210+
211+
/** This peer's reported block height when we connected */
212+
std::atomic<int> m_starting_height{-1};
213+
214+
/** Set of txids to reconsider once their parent transactions have been accepted **/
215+
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
216+
217+
/** Protects m_getdata_requests **/
218+
Mutex m_getdata_requests_mutex;
219+
/** Work queue of items requested by this peer **/
220+
std::deque<CInv> m_getdata_requests GUARDED_BY(m_getdata_requests_mutex);
221+
222+
explicit Peer(NodeId id) : m_id(id) {}
223+
};
224+
225+
using PeerRef = std::shared_ptr<Peer>;
226+
172227
class PeerManagerImpl final : public PeerManager
173228
{
174229
public:

src/net_processing.h

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -33,61 +33,6 @@ struct CNodeStateStats {
3333
std::vector<int> vHeightInFlight;
3434
};
3535

36-
/**
37-
* Data structure for an individual peer. This struct is not protected by
38-
* cs_main since it does not contain validation-critical data.
39-
*
40-
* Memory is owned by shared pointers and this object is destructed when
41-
* the refcount drops to zero.
42-
*
43-
* Mutexes inside this struct must not be held when locking m_peer_mutex.
44-
*
45-
* TODO: move most members from CNodeState to this structure.
46-
* TODO: move remaining application-layer data members from CNode to this structure.
47-
*/
48-
struct Peer {
49-
/** Same id as the CNode object for this peer */
50-
const NodeId m_id{0};
51-
52-
/** Protects misbehavior data members */
53-
Mutex m_misbehavior_mutex;
54-
/** Accumulated misbehavior score for this peer */
55-
int m_misbehavior_score GUARDED_BY(m_misbehavior_mutex){0};
56-
/** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
57-
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false};
58-
59-
/** Protects block inventory data members */
60-
Mutex m_block_inv_mutex;
61-
/** List of blocks that we'll announce via an `inv` message.
62-
* There is no final sorting before sending, as they are always sent
63-
* immediately and in the order requested. */
64-
std::vector<uint256> m_blocks_for_inv_relay GUARDED_BY(m_block_inv_mutex);
65-
/** Unfiltered list of blocks that we'd like to announce via a `headers`
66-
* message. If we can't announce via a `headers` message, we'll fall back to
67-
* announcing via `inv`. */
68-
std::vector<uint256> m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex);
69-
/** The final block hash that we sent in an `inv` message to this peer.
70-
* When the peer requests this block, we send an `inv` message to trigger
71-
* the peer to request the next sequence of block hashes.
72-
* Most peers use headers-first syncing, which doesn't use this mechanism */
73-
uint256 m_continuation_block GUARDED_BY(m_block_inv_mutex) {};
74-
75-
/** This peer's reported block height when we connected */
76-
std::atomic<int> m_starting_height{-1};
77-
78-
/** Set of txids to reconsider once their parent transactions have been accepted **/
79-
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
80-
81-
/** Protects m_getdata_requests **/
82-
Mutex m_getdata_requests_mutex;
83-
/** Work queue of items requested by this peer **/
84-
std::deque<CInv> m_getdata_requests GUARDED_BY(m_getdata_requests_mutex);
85-
86-
explicit Peer(NodeId id) : m_id(id) {}
87-
};
88-
89-
using PeerRef = std::shared_ptr<Peer>;
90-
9136
class PeerManager : public CValidationInterface, public NetEventsInterface
9237
{
9338
public:

0 commit comments

Comments
 (0)