Changeset View
Changeset View
Standalone View
Standalone View
src/net.h
Show First 20 Lines • Show All 397 Lines • ▼ Show 20 Lines | private: | ||||
// whitelisted (as well as those connecting to whitelisted binds). | // whitelisted (as well as those connecting to whitelisted binds). | ||||
std::vector<CSubNet> vWhitelistedRange; | std::vector<CSubNet> vWhitelistedRange; | ||||
unsigned int nSendBufferMaxSize; | unsigned int nSendBufferMaxSize; | ||||
unsigned int nReceiveFloodSize; | unsigned int nReceiveFloodSize; | ||||
std::vector<ListenSocket> vhListenSocket; | std::vector<ListenSocket> vhListenSocket; | ||||
std::atomic<bool> fNetworkActive; | std::atomic<bool> fNetworkActive; | ||||
banmap_t setBanned; | banmap_t setBanned GUARDED_BY(cs_setBanned); | ||||
CCriticalSection cs_setBanned; | CCriticalSection cs_setBanned; | ||||
bool setBannedIsDirty; | bool setBannedIsDirty GUARDED_BY(cs_setBanned); | ||||
bool fAddressesInitialized; | bool fAddressesInitialized; | ||||
CAddrMan addrman; | CAddrMan addrman; | ||||
std::deque<std::string> vOneShots; | std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots); | ||||
CCriticalSection cs_vOneShots; | CCriticalSection cs_vOneShots; | ||||
std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes); | std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes); | ||||
CCriticalSection cs_vAddedNodes; | CCriticalSection cs_vAddedNodes; | ||||
std::vector<CNode *> vNodes; | std::vector<CNode *> vNodes; | ||||
std::list<CNode *> vNodesDisconnected; | std::list<CNode *> vNodesDisconnected; | ||||
mutable CCriticalSection cs_vNodes; | mutable CCriticalSection cs_vNodes; | ||||
std::atomic<NodeId> nLastNodeId; | std::atomic<NodeId> nLastNodeId; | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
extern limitedmap<uint256, int64_t> mapAlreadyAskedFor; | extern limitedmap<uint256, int64_t> mapAlreadyAskedFor; | ||||
struct LocalServiceInfo { | struct LocalServiceInfo { | ||||
int nScore; | int nScore; | ||||
int nPort; | int nPort; | ||||
}; | }; | ||||
extern CCriticalSection cs_mapLocalHost; | extern CCriticalSection cs_mapLocalHost; | ||||
extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost; | extern std::map<CNetAddr, LocalServiceInfo> | ||||
mapLocalHost GUARDED_BY(cs_mapLocalHost); | |||||
// Command, total bytes | // Command, total bytes | ||||
typedef std::map<std::string, uint64_t> mapMsgCmdSize; | typedef std::map<std::string, uint64_t> mapMsgCmdSize; | ||||
/** | /** | ||||
* POD that contains various stats about a node. | * POD that contains various stats about a node. | ||||
* Usually constructed from CConman::GetNodeStats. Stats are filled from the | * Usually constructed from CConman::GetNodeStats. Stats are filled from the | ||||
* node using CNode::copyStats. | * node using CNode::copyStats. | ||||
▲ Show 20 Lines • Show All 83 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; | ||||
SOCKET 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; | ||||
// Offset inside the first vSendMsg already sent. | // Offset inside the first vSendMsg already sent. | ||||
size_t nSendOffset; | size_t nSendOffset; | ||||
uint64_t nSendBytes; | uint64_t nSendBytes GUARDED_BY(cs_vSend); | ||||
std::deque<std::vector<uint8_t>> vSendMsg; | 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; | std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg); | ||||
size_t nProcessQueueSize; | size_t nProcessQueueSize; | ||||
CCriticalSection cs_sendProcessing; | CCriticalSection cs_sendProcessing; | ||||
std::deque<CInv> vRecvGetData; | std::deque<CInv> vRecvGetData; | ||||
uint64_t nRecvBytes; | uint64_t nRecvBytes GUARDED_BY(cs_vRecv); | ||||
std::atomic<int> nRecvVersion; | std::atomic<int> nRecvVersion; | ||||
std::atomic<int64_t> nLastSend; | std::atomic<int64_t> nLastSend; | ||||
std::atomic<int64_t> nLastRecv; | std::atomic<int64_t> nLastRecv; | ||||
const int64_t nTimeConnected; | const int64_t nTimeConnected; | ||||
std::atomic<int64_t> nTimeOffset; | std::atomic<int64_t> nTimeOffset; | ||||
// 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; | ||||
// 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, cleanSubVer; | std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer | ||||
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; | ||||
// 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; | ||||
bool fOneShot; | bool fOneShot; | ||||
bool m_manual_connection; | bool m_manual_connection; | ||||
Show All 9 Lines | public: | ||||
// 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. | ||||
// protected by cs_filter | // protected by cs_filter | ||||
bool fRelayTxes; | bool fRelayTxes; | ||||
bool fSentAddr; | bool fSentAddr; | ||||
CSemaphoreGrant grantOutbound; | CSemaphoreGrant grantOutbound; | ||||
CCriticalSection cs_filter; | CCriticalSection cs_filter; | ||||
std::unique_ptr<CBloomFilter> pfilter; | std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter); | ||||
std::atomic<int> nRefCount; | std::atomic<int> nRefCount; | ||||
const uint64_t nKeyedNetGroup; | const uint64_t nKeyedNetGroup; | ||||
std::atomic_bool fPauseRecv; | std::atomic_bool fPauseRecv; | ||||
std::atomic_bool fPauseSend; | std::atomic_bool fPauseSend; | ||||
protected: | protected: | ||||
mapMsgCmdSize mapSendBytesPerMsgCmd; | mapMsgCmdSize mapSendBytesPerMsgCmd; | ||||
mapMsgCmdSize mapRecvBytesPerMsgCmd; | mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); | ||||
public: | public: | ||||
uint256 hashContinue; | uint256 hashContinue; | ||||
std::atomic<int> nStartingHeight; | std::atomic<int> nStartingHeight; | ||||
// flood relay | // flood relay | ||||
std::vector<CAddress> vAddrToSend; | std::vector<CAddress> vAddrToSend; | ||||
CRollingBloomFilter addrKnown; | CRollingBloomFilter addrKnown; | ||||
bool fGetAddr; | bool fGetAddr; | ||||
std::set<uint256> setKnown; | std::set<uint256> setKnown; | ||||
int64_t nNextAddrSend; | int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing); | ||||
int64_t nNextLocalAddrSend; | int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing); | ||||
// Inventory based relay. | // Inventory based relay. | ||||
CRollingBloomFilter filterInventoryKnown; | 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; | 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; | ||||
// Used for headers announcements - unfiltered blocks to relay. Also | // Used for headers announcements - unfiltered blocks to relay. Also | ||||
// protected by cs_inventory. | // protected by cs_inventory. | ||||
std::vector<uint256> vBlockHashesToAnnounce; | std::vector<uint256> vBlockHashesToAnnounce; | ||||
// Used for BIP35 mempool sending, also protected by cs_inventory. | // Used for BIP35 mempool sending, also protected by cs_inventory. | ||||
Show All 13 Lines | public: | ||||
std::atomic<int64_t> nPingUsecStart; | std::atomic<int64_t> nPingUsecStart; | ||||
// Last measured round-trip time. | // Last measured round-trip time. | ||||
std::atomic<int64_t> nPingUsecTime; | std::atomic<int64_t> nPingUsecTime; | ||||
// Best measured round-trip time. | // Best measured round-trip time. | ||||
std::atomic<int64_t> nMinPingUsecTime; | std::atomic<int64_t> nMinPingUsecTime; | ||||
// Whether a ping is requested. | // Whether a ping is requested. | ||||
std::atomic<bool> fPingQueued; | std::atomic<bool> fPingQueued; | ||||
// 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; | Amount minFeeFilter GUARDED_BY(cs_feeFilter); | ||||
CCriticalSection cs_feeFilter; | CCriticalSection cs_feeFilter; | ||||
Amount lastSentFeeFilter; | Amount lastSentFeeFilter; | ||||
int64_t nextSendTimeFeeFilter; | int64_t nextSendTimeFeeFilter; | ||||
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; | ||||
// 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; | std::string addrName GUARDED_BY(cs_addrName); | ||||
// Our address, as reported by the peer | // Our address, as reported by the peer | ||||
CService addrLocal; | CService addrLocal GUARDED_BY(cs_addrLocal); | ||||
mutable CCriticalSection cs_addrLocal; | mutable CCriticalSection cs_addrLocal; | ||||
public: | public: | ||||
NodeId GetId() const { return id; } | NodeId GetId() const { return id; } | ||||
uint64_t GetLocalNonce() const { return nLocalHostNonce; } | uint64_t GetLocalNonce() const { return nLocalHostNonce; } | ||||
int GetMyStartingHeight() const { return nMyStartingHeight; } | int GetMyStartingHeight() const { return nMyStartingHeight; } | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |