Changeset View
Changeset View
Standalone View
Standalone View
src/net.h
Show First 20 Lines • Show All 631 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
/** Information about a peer */ | /** Information about a peer */ | ||||
class CNode { | class CNode { | ||||
friend class CConnman; | friend class CConnman; | ||||
public: | public: | ||||
// socket | // socket | ||||
std::atomic<ServiceFlags> nServices; | std::atomic<ServiceFlags> nServices{NODE_NONE}; | ||||
SOCKET hSocket GUARDED_BY(cs_hSocket); | SOCKET hSocket GUARDED_BY(cs_hSocket); | ||||
// Total size of all vSendMsg entries. | // Total size of all vSendMsg entries. | ||||
size_t nSendSize; | size_t nSendSize{0}; | ||||
// Offset inside the first vSendMsg already sent. | // Offset inside the first vSendMsg already sent. | ||||
size_t nSendOffset; | size_t nSendOffset{0}; | ||||
uint64_t nSendBytes GUARDED_BY(cs_vSend); | uint64_t nSendBytes GUARDED_BY(cs_vSend){0}; | ||||
std::deque<std::vector<uint8_t>> vSendMsg GUARDED_BY(cs_vSend); | std::deque<std::vector<uint8_t>> vSendMsg GUARDED_BY(cs_vSend); | ||||
CCriticalSection cs_vSend; | CCriticalSection cs_vSend; | ||||
CCriticalSection cs_hSocket; | CCriticalSection cs_hSocket; | ||||
CCriticalSection cs_vRecv; | CCriticalSection cs_vRecv; | ||||
CCriticalSection cs_vProcessMsg; | CCriticalSection cs_vProcessMsg; | ||||
std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg); | std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg); | ||||
size_t nProcessQueueSize; | size_t nProcessQueueSize{0}; | ||||
CCriticalSection cs_sendProcessing; | CCriticalSection cs_sendProcessing; | ||||
std::deque<CInv> vRecvGetData; | std::deque<CInv> vRecvGetData; | ||||
uint64_t nRecvBytes GUARDED_BY(cs_vRecv); | uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0}; | ||||
std::atomic<int> nRecvVersion; | std::atomic<int> nRecvVersion{INIT_PROTO_VERSION}; | ||||
std::atomic<int64_t> nLastSend; | std::atomic<int64_t> nLastSend{0}; | ||||
std::atomic<int64_t> nLastRecv; | std::atomic<int64_t> nLastRecv{0}; | ||||
const int64_t nTimeConnected; | const int64_t nTimeConnected; | ||||
std::atomic<int64_t> nTimeOffset; | std::atomic<int64_t> nTimeOffset{0}; | ||||
// Address of this peer | // Address of this peer | ||||
const CAddress addr; | const CAddress addr; | ||||
// Bind address of our side of the connection | // Bind address of our side of the connection | ||||
const CAddress addrBind; | const CAddress addrBind; | ||||
std::atomic<int> nVersion; | std::atomic<int> nVersion{0}; | ||||
// strSubVer is whatever byte array we read from the wire. However, this | // strSubVer is whatever byte array we read from the wire. However, this | ||||
// field is intended to be printed out, displayed to humans in various forms | // field is intended to be printed out, displayed to humans in various forms | ||||
// and so on. So we sanitize it and store the sanitized version in | // and so on. So we sanitize it and store the sanitized version in | ||||
// cleanSubVer. The original should be used when dealing with the network or | // cleanSubVer. The original should be used when dealing with the network or | ||||
// wire types and the cleaned string used when displayed or logged. | // wire types and the cleaned string used when displayed or logged. | ||||
std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer | std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer | ||||
GUARDED_BY(cs_SubVer); | GUARDED_BY(cs_SubVer); | ||||
// Used for both cleanSubVer and strSubVer. | // Used for both cleanSubVer and strSubVer. | ||||
CCriticalSection cs_SubVer; | CCriticalSection cs_SubVer; | ||||
// This peer can bypass DoS banning. | // This peer can bypass DoS banning. | ||||
bool fWhitelisted; | bool fWhitelisted{false}; | ||||
// If true this node is being used as a short lived feeler. | // If true this node is being used as a short lived feeler. | ||||
bool fFeeler; | bool fFeeler{false}; | ||||
bool fOneShot; | bool fOneShot{false}; | ||||
bool m_manual_connection; | bool m_manual_connection{false}; | ||||
bool fClient; | // set by version message | ||||
// after BIP159 | bool fClient{false}; | ||||
bool m_limited_node; | // after BIP159, set by version message | ||||
bool m_limited_node{false}; | |||||
const bool fInbound; | const bool fInbound; | ||||
std::atomic_bool fSuccessfullyConnected; | std::atomic_bool fSuccessfullyConnected{false}; | ||||
std::atomic_bool fDisconnect; | std::atomic_bool fDisconnect{false}; | ||||
// We use fRelayTxes for two purposes - | // We use fRelayTxes for two purposes - | ||||
// a) it allows us to not relay tx invs before receiving the peer's version | // a) it allows us to not relay tx invs before receiving the peer's version | ||||
// message. | // message. | ||||
// b) the peer may tell us in its version message that we should not relay | // b) the peer may tell us in its version message that we should not relay | ||||
// tx invs unless it loads a bloom filter. | // tx invs unless it loads a bloom filter. | ||||
bool fRelayTxes GUARDED_BY(cs_filter){false}; | |||||
bool fRelayTxes GUARDED_BY(cs_filter); | bool fSentAddr{false}; | ||||
bool fSentAddr; | |||||
CSemaphoreGrant grantOutbound; | CSemaphoreGrant grantOutbound; | ||||
mutable CCriticalSection cs_filter; | mutable CCriticalSection cs_filter; | ||||
std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter); | std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter); | ||||
std::atomic<int> nRefCount; | std::atomic<int> nRefCount{0}; | ||||
const uint64_t nKeyedNetGroup; | const uint64_t nKeyedNetGroup; | ||||
std::atomic_bool fPauseRecv; | std::atomic_bool fPauseRecv{false}; | ||||
std::atomic_bool fPauseSend; | std::atomic_bool fPauseSend{false}; | ||||
protected: | protected: | ||||
mapMsgCmdSize mapSendBytesPerMsgCmd; | mapMsgCmdSize mapSendBytesPerMsgCmd; | ||||
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); | mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); | ||||
public: | public: | ||||
uint256 hashContinue; | uint256 hashContinue; | ||||
std::atomic<int> nStartingHeight; | std::atomic<int> nStartingHeight{-1}; | ||||
// flood relay | // flood relay | ||||
std::vector<CAddress> vAddrToSend; | std::vector<CAddress> vAddrToSend; | ||||
CRollingBloomFilter addrKnown; | CRollingBloomFilter addrKnown; | ||||
bool fGetAddr; | bool fGetAddr{false}; | ||||
std::set<uint256> setKnown; | std::set<uint256> setKnown; | ||||
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing); | int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0}; | ||||
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing); | int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0}; | ||||
// Inventory based relay. | // Inventory based relay. | ||||
CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory); | CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory); | ||||
// Set of transaction ids we still have to announce. They are sorted by the | // Set of transaction ids we still have to announce. They are sorted by the | ||||
// mempool before relay, so the order is not important. | // mempool before relay, so the order is not important. | ||||
std::set<uint256> setInventoryTxToSend; | std::set<uint256> setInventoryTxToSend; | ||||
// List of block ids we still have announce. There is no final sorting | // List of block ids we still have announce. There is no final sorting | ||||
// before sending, as they are always sent immediately and in the order | // before sending, as they are always sent immediately and in the order | ||||
// requested. | // requested. | ||||
std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory); | std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory); | ||||
CCriticalSection cs_inventory; | CCriticalSection cs_inventory; | ||||
std::set<uint256> setAskFor; | std::set<uint256> setAskFor; | ||||
std::multimap<int64_t, CInv> mapAskFor; | std::multimap<int64_t, CInv> mapAskFor; | ||||
int64_t nNextInvSend; | int64_t nNextInvSend{0}; | ||||
// Used for headers announcements - unfiltered blocks to relay. | // Used for headers announcements - unfiltered blocks to relay. | ||||
std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory); | std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory); | ||||
// Used for BIP35 mempool sending. | // Used for BIP35 mempool sending. | ||||
bool fSendMempool GUARDED_BY(cs_inventory); | bool fSendMempool GUARDED_BY(cs_inventory){false}; | ||||
// Last time a "MEMPOOL" request was serviced. | // Last time a "MEMPOOL" request was serviced. | ||||
std::atomic<int64_t> timeLastMempoolReq; | std::atomic<int64_t> timeLastMempoolReq{0}; | ||||
// Block and TXN accept times | // Block and TXN accept times | ||||
std::atomic<int64_t> nLastBlockTime; | std::atomic<int64_t> nLastBlockTime{0}; | ||||
std::atomic<int64_t> nLastTXTime; | std::atomic<int64_t> nLastTXTime{0}; | ||||
// Ping time measurement: | // Ping time measurement: | ||||
// The pong reply we're expecting, or 0 if no pong expected. | // The pong reply we're expecting, or 0 if no pong expected. | ||||
std::atomic<uint64_t> nPingNonceSent; | std::atomic<uint64_t> nPingNonceSent{0}; | ||||
// Time (in usec) the last ping was sent, or 0 if no ping was ever sent. | // Time (in usec) the last ping was sent, or 0 if no ping was ever sent. | ||||
std::atomic<int64_t> nPingUsecStart; | std::atomic<int64_t> nPingUsecStart{0}; | ||||
// Last measured round-trip time. | // Last measured round-trip time. | ||||
std::atomic<int64_t> nPingUsecTime; | std::atomic<int64_t> nPingUsecTime{0}; | ||||
// Best measured round-trip time. | // Best measured round-trip time. | ||||
std::atomic<int64_t> nMinPingUsecTime; | std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()}; | ||||
// Whether a ping is requested. | // Whether a ping is requested. | ||||
std::atomic<bool> fPingQueued; | std::atomic<bool> fPingQueued{false}; | ||||
// Minimum fee rate with which to filter inv's to this node | // Minimum fee rate with which to filter inv's to this node | ||||
Amount minFeeFilter GUARDED_BY(cs_feeFilter); | Amount minFeeFilter GUARDED_BY(cs_feeFilter){Amount::zero()}; | ||||
CCriticalSection cs_feeFilter; | CCriticalSection cs_feeFilter; | ||||
Amount lastSentFeeFilter; | Amount lastSentFeeFilter{Amount::zero()}; | ||||
int64_t nextSendTimeFeeFilter; | int64_t nextSendTimeFeeFilter{0}; | ||||
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, | CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, | ||||
SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, | SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, | ||||
uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, | uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, | ||||
const std::string &addrNameIn = "", bool fInboundIn = false); | const std::string &addrNameIn = "", bool fInboundIn = false); | ||||
~CNode(); | ~CNode(); | ||||
CNode(const CNode &) = delete; | CNode(const CNode &) = delete; | ||||
CNode &operator=(const CNode &) = delete; | CNode &operator=(const CNode &) = delete; | ||||
private: | private: | ||||
const NodeId id; | const NodeId id; | ||||
const uint64_t nLocalHostNonce; | const uint64_t nLocalHostNonce; | ||||
// Services offered to this peer | // Services offered to this peer | ||||
const ServiceFlags nLocalServices; | const ServiceFlags nLocalServices; | ||||
const int nMyStartingHeight; | const int nMyStartingHeight; | ||||
int nSendVersion; | int nSendVersion{0}; | ||||
// Used only by SocketHandler thread. | // Used only by SocketHandler thread. | ||||
std::list<CNetMessage> vRecvMsg; | std::list<CNetMessage> vRecvMsg; | ||||
mutable CCriticalSection cs_addrName; | mutable CCriticalSection cs_addrName; | ||||
std::string addrName GUARDED_BY(cs_addrName); | std::string addrName GUARDED_BY(cs_addrName); | ||||
// Our address, as reported by the peer | // Our address, as reported by the peer | ||||
CService addrLocal GUARDED_BY(cs_addrLocal); | CService addrLocal GUARDED_BY(cs_addrLocal); | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |