mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
net_processing: move Peer definition to .cpp
This commit is contained in:
parent
e0f2e6d2df
commit
c97f70c861
@ -169,6 +169,61 @@ void EraseOrphansFor(NodeId peer);
|
|||||||
|
|
||||||
// Internal stuff
|
// Internal stuff
|
||||||
namespace {
|
namespace {
|
||||||
|
/**
|
||||||
|
* Data structure for an individual peer. This struct is not protected by
|
||||||
|
* cs_main since it does not contain validation-critical data.
|
||||||
|
*
|
||||||
|
* Memory is owned by shared pointers and this object is destructed when
|
||||||
|
* the refcount drops to zero.
|
||||||
|
*
|
||||||
|
* Mutexes inside this struct must not be held when locking m_peer_mutex.
|
||||||
|
*
|
||||||
|
* TODO: move most members from CNodeState to this structure.
|
||||||
|
* TODO: move remaining application-layer data members from CNode to this structure.
|
||||||
|
*/
|
||||||
|
struct Peer {
|
||||||
|
/** Same id as the CNode object for this peer */
|
||||||
|
const NodeId m_id{0};
|
||||||
|
|
||||||
|
/** Protects misbehavior data members */
|
||||||
|
Mutex m_misbehavior_mutex;
|
||||||
|
/** Accumulated misbehavior score for this peer */
|
||||||
|
int m_misbehavior_score GUARDED_BY(m_misbehavior_mutex){0};
|
||||||
|
/** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
|
||||||
|
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false};
|
||||||
|
|
||||||
|
/** Protects block inventory data members */
|
||||||
|
Mutex m_block_inv_mutex;
|
||||||
|
/** List of blocks that we'll announce via an `inv` message.
|
||||||
|
* There is no final sorting before sending, as they are always sent
|
||||||
|
* immediately and in the order requested. */
|
||||||
|
std::vector<uint256> m_blocks_for_inv_relay GUARDED_BY(m_block_inv_mutex);
|
||||||
|
/** Unfiltered list of blocks that we'd like to announce via a `headers`
|
||||||
|
* message. If we can't announce via a `headers` message, we'll fall back to
|
||||||
|
* announcing via `inv`. */
|
||||||
|
std::vector<uint256> m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex);
|
||||||
|
/** The final block hash that we sent in an `inv` message to this peer.
|
||||||
|
* When the peer requests this block, we send an `inv` message to trigger
|
||||||
|
* the peer to request the next sequence of block hashes.
|
||||||
|
* Most peers use headers-first syncing, which doesn't use this mechanism */
|
||||||
|
uint256 m_continuation_block GUARDED_BY(m_block_inv_mutex) {};
|
||||||
|
|
||||||
|
/** This peer's reported block height when we connected */
|
||||||
|
std::atomic<int> m_starting_height{-1};
|
||||||
|
|
||||||
|
/** Set of txids to reconsider once their parent transactions have been accepted **/
|
||||||
|
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
|
||||||
|
|
||||||
|
/** Protects m_getdata_requests **/
|
||||||
|
Mutex m_getdata_requests_mutex;
|
||||||
|
/** Work queue of items requested by this peer **/
|
||||||
|
std::deque<CInv> m_getdata_requests GUARDED_BY(m_getdata_requests_mutex);
|
||||||
|
|
||||||
|
explicit Peer(NodeId id) : m_id(id) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
using PeerRef = std::shared_ptr<Peer>;
|
||||||
|
|
||||||
class PeerManagerImpl final : public PeerManager
|
class PeerManagerImpl final : public PeerManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -33,61 +33,6 @@ struct CNodeStateStats {
|
|||||||
std::vector<int> vHeightInFlight;
|
std::vector<int> vHeightInFlight;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Data structure for an individual peer. This struct is not protected by
|
|
||||||
* cs_main since it does not contain validation-critical data.
|
|
||||||
*
|
|
||||||
* Memory is owned by shared pointers and this object is destructed when
|
|
||||||
* the refcount drops to zero.
|
|
||||||
*
|
|
||||||
* Mutexes inside this struct must not be held when locking m_peer_mutex.
|
|
||||||
*
|
|
||||||
* TODO: move most members from CNodeState to this structure.
|
|
||||||
* TODO: move remaining application-layer data members from CNode to this structure.
|
|
||||||
*/
|
|
||||||
struct Peer {
|
|
||||||
/** Same id as the CNode object for this peer */
|
|
||||||
const NodeId m_id{0};
|
|
||||||
|
|
||||||
/** Protects misbehavior data members */
|
|
||||||
Mutex m_misbehavior_mutex;
|
|
||||||
/** Accumulated misbehavior score for this peer */
|
|
||||||
int m_misbehavior_score GUARDED_BY(m_misbehavior_mutex){0};
|
|
||||||
/** Whether this peer should be disconnected and marked as discouraged (unless it has the noban permission). */
|
|
||||||
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false};
|
|
||||||
|
|
||||||
/** Protects block inventory data members */
|
|
||||||
Mutex m_block_inv_mutex;
|
|
||||||
/** List of blocks that we'll announce via an `inv` message.
|
|
||||||
* There is no final sorting before sending, as they are always sent
|
|
||||||
* immediately and in the order requested. */
|
|
||||||
std::vector<uint256> m_blocks_for_inv_relay GUARDED_BY(m_block_inv_mutex);
|
|
||||||
/** Unfiltered list of blocks that we'd like to announce via a `headers`
|
|
||||||
* message. If we can't announce via a `headers` message, we'll fall back to
|
|
||||||
* announcing via `inv`. */
|
|
||||||
std::vector<uint256> m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex);
|
|
||||||
/** The final block hash that we sent in an `inv` message to this peer.
|
|
||||||
* When the peer requests this block, we send an `inv` message to trigger
|
|
||||||
* the peer to request the next sequence of block hashes.
|
|
||||||
* Most peers use headers-first syncing, which doesn't use this mechanism */
|
|
||||||
uint256 m_continuation_block GUARDED_BY(m_block_inv_mutex) {};
|
|
||||||
|
|
||||||
/** This peer's reported block height when we connected */
|
|
||||||
std::atomic<int> m_starting_height{-1};
|
|
||||||
|
|
||||||
/** Set of txids to reconsider once their parent transactions have been accepted **/
|
|
||||||
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
|
|
||||||
|
|
||||||
/** Protects m_getdata_requests **/
|
|
||||||
Mutex m_getdata_requests_mutex;
|
|
||||||
/** Work queue of items requested by this peer **/
|
|
||||||
std::deque<CInv> m_getdata_requests GUARDED_BY(m_getdata_requests_mutex);
|
|
||||||
|
|
||||||
explicit Peer(NodeId id) : m_id(id) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
using PeerRef = std::shared_ptr<Peer>;
|
|
||||||
|
|
||||||
class PeerManager : public CValidationInterface, public NetEventsInterface
|
class PeerManager : public CValidationInterface, public NetEventsInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user