Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
net.h
Go to the documentation of this file.
209 void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool fOneShot = false, bool fFeeler = false, bool manual_connection = false, bool fConnectToMasternode = false, bool fMasternodeProbe = false);
227 bool ForNode(NodeId id, std::function<bool(const CNode* pnode)> cond, std::function<bool(CNode* pnode)> func);
228 bool ForNode(const CService& addr, std::function<bool(const CNode* pnode)> cond, std::function<bool(CNode* pnode)> func);
358 void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false);
359 void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false);
360 // This overload will not update node filters, so use it only for the cases when other messages will update related transaction data in filters
361 void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections = false);
367 void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
384 void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
385 void Ban(const CSubNet& subNet, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
412 void SetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash, const std::set<uint256>& proTxHashes);
416 std::set<NodeId> GetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash) const;
478 bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
490 bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
492 void SocketEventsEpoll(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
495 void SocketEventsPoll(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
497 void SocketEventsSelect(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
498 void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set, bool fOnlyPoll);
512 CNode* ConnectNode(CAddress addrConnect, const char *pszDest = nullptr, bool fCountFailure = false);
572 std::map<std::pair<Consensus::LLMQType, uint256>, std::set<uint256>> masternodeQuorumNodes; // protected by cs_vPendingMasternodes
622 std::unordered_map<NodeId, CNode*> mapNodesWithDataToSend GUARDED_BY(cs_mapNodesWithDataToSend);
645 bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
771 CNetMessage(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
946 // If true, we will send him all quorum related messages, even if he is not a member of our quorums
951 CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn = "", bool fInboundIn = false);
1109 inline std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
void ForEachNodeThen(const Condition &cond, Callable &&pre, CallableAfter &&post)
Definition: net.h:320
static const int MAX_OUTBOUND_CONNECTIONS
Maximum number of automatic outgoing nodes.
Definition: net.h:70
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:3863
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn="", bool fInboundIn=false)
Definition: net.cpp:3645
CNode * FindNode(const CNetAddr &ip, bool fExcludeDisconnecting=true)
Definition: net.cpp:330
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
Definition: net.cpp:316
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Maximum length of incoming protocol messages (no message over 3 MiB is currently acceptable).
Definition: net.h:66
void OpenMasternodeConnection(const CAddress &addrConnect, bool probe=false)
Definition: net.cpp:2697
Definition: net.h:221
Definition: util.h:110
Definition: net.h:150
static const uint64_t MAX_UPLOAD_TIMEFRAME
The default timeframe for -maxuploadtarget.
Definition: net.h:90
void SetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash, const std::set< uint256 > &proTxHashes)
Definition: net.cpp:3316
std::set< NodeId > GetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash) const
Definition: net.cpp:3344
void SetServices(const CService &addr, ServiceFlags nServices)
Definition: net.cpp:3262
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool &complete)
Definition: net.cpp:820
bool ForEachNodeContinueIf(const Condition &cond, Callable &&func) const
Definition: net.h:271
CNode & operator=(const CNode &)=delete
void insert(const std::vector< unsigned char > &vKey)
Definition: bloom.cpp:341
Definition: protocol.h:399
Definition: net.h:647
Definition: net.h:1099
Definition: net.h:678
uint64_t randrange(uint64_t range)
Generate a random integer in the range [0..range).
Definition: random.h:107
std::atomic< int64_t > m_next_send_inv_to_incoming
Definition: net.h:637
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:72
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3733
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target
Definition: net.cpp:3575
Definition: net.h:122
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:126
CSerializedNetMsg()=default
Definition: net.h:708
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
bool IsConnected(const CService &addr, std::function< bool(const CNode *pnode)> cond)
Definition: net.h:242
Definition: net.h:111
ListenSocket(SOCKET socket_, bool whitelisted_)
Definition: net.h:475
Definition: protocol.h:400
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:1026
std::thread threadOpenMasternodeConnections
Definition: net.h:629
static const int FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes or 120 seconds.
Definition: net.h:60
std::set< uint256 > GetMasternodeQuorums(Consensus::LLMQType llmqType)
Definition: net.cpp:3331
static const int TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:56
static constexpr const CFullyConnectedOnly FullyConnectedOnly
Definition: net.h:219
CNetMessage(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:771
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes
Definition: net.cpp:3543
void SetAddrLocal(const CService &addrLocalIn)
May not be called more than once.
Definition: net.cpp:741
void AddPendingProbeConnections(const std::set< uint256 > &proTxHashes)
Definition: net.cpp:3402
Definition: netaddress.h:105
bool ForEachNodeContinueIf(Callable &&func) const
Definition: net.h:282
bool contains(const std::vector< unsigned char > &vKey) const
Definition: bloom.cpp:378
void ForEachNodeThen(const Condition &cond, Callable &&pre, CallableAfter &&post) const
Definition: net.h:337
virtual bool SendMessages(CNode *pnode, std::atomic< bool > &interrupt)=0
Definition: net.h:145
bool IsMasternodeQuorumNode(const CNode *pnode)
Definition: net.cpp:3372
void RemoveMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: net.cpp:3366
void Ban(const CNetAddr &netAddr, const BanReason &reason, int64_t bantimeoffset=0, bool sinceUnixEpoch=false)
Definition: net.cpp:605
Definition: protocol.h:282
bool ForNode(NodeId id, std::function< bool(const CNode *pnode)> cond, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3795
Definition: net.h:717
uint64_t GetOutboundTargetBytesLeft()
response the bytes left in the current max outbound cycle
Definition: net.cpp:3607
void ForEachNode(const Condition &cond, Callable &&func) const
Definition: net.h:304
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:3728
uint64_t GetMaxOutboundTimeLeftInCycle()
response the time in second left in the current max outbound cycle
Definition: net.cpp:3561
bool InitBinds(const std::vector< CService > &binds, const std::vector< CService > &whiteBinds)
Definition: net.cpp:2940
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
void ThreadOpenMasternodeConnections()
Definition: net.cpp:2486
bool operator()(const CNode *pnode) const
Definition: net.h:214
void SocketEventsSelect(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set, bool fOnlyPoll)
Definition: net.cpp:1557
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:143
Definition: net.h:755
int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds)
Attempts to obfuscate tx time through exponentially distributed emitting.
Definition: net.cpp:3814
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached
Definition: net.cpp:3587
std::vector< std::string > m_specified_outgoing
Definition: net.h:172
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion=MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections=false)
Definition: net.cpp:3491
void ThreadOpenConnections(std::vector< std::string > connect)
Definition: net.cpp:2221
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:331
bool ForEachNodeContinueIf(const Condition &cond, Callable &&func)
Definition: net.h:254
void MaybeSetAddrName(const std::string &addrNameIn)
Sets the addrName only if it was not previously set.
Definition: net.cpp:729
std::atomic_bool m_try_another_outbound_peer
flag for deciding to connect to an extra outbound peer, in excess of nMaxOutbound This takes the plac...
Definition: net.h:635
virtual void FinalizeNode(NodeId id, bool &update_connection_time)=0
void AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:3272
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:86
std::atomic< int64_t > nTimeFirstMessageReceived
Definition: net.h:831
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
Definition: net.cpp:3858
void SetLimited(enum Network net, bool fLimited=true)
Make a particular network entirely off-limits (no automatic connects to it)
Definition: net.cpp:276
Definition: threadinterrupt.h:18
Definition: net.h:151
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:38
Definition: net.h:144
static const int INBOUND_EVICTION_PROTECTION_TIME
Eviction protection time for incoming connections.
Definition: net.h:74
bool AddPendingMasternode(const uint256 &proTxHash)
Definition: net.cpp:3305
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netaddress.h:33
CNode * ConnectNode(CAddress addrConnect, const char *pszDest=nullptr, bool fCountFailure=false)
Definition: net.cpp:412
Definition: net.h:154
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound=nullptr, const char *strDest=nullptr, bool fOneShot=false, bool fFeeler=false, bool manual_connection=false, bool fConnectToMasternode=false, bool fMasternodeProbe=false)
Definition: net.cpp:2628
static const unsigned int MAX_ADDR_TO_SEND
The maximum number of new addresses to accumulate before announcing.
Definition: net.h:64
void ReleaseNodeVector(const std::vector< CNode *> &vecNodes)
Definition: net.cpp:3850
Definition: protocol.h:409
Definition: net.h:213
Definition: net.h:679
bool AttemptToEvictConnection()
Try to find a connection to evict when the node is full.
Definition: net.cpp:1073
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:88
std::map< std::pair< Consensus::LLMQType, uint256 >, std::set< uint256 > > masternodeQuorumNodes
Definition: net.h:572
static const int MIN_PEER_PROTO_VERSION
disconnect from peers older than this proto version
Definition: version.h:23
static const unsigned int DEFAULT_MISBEHAVING_BANTIME
Definition: net.h:99
int64_t PoissonNextSend(int64_t now, int average_interval_seconds)
Return a timestamp in the future (in microseconds) for exponentially distributed events.
Definition: net.cpp:3825
Definition: net.h:149
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:348
Definition: net.h:471
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of strSubVer in version message.
Definition: net.h:68
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION, bool fAllowMasternodeConnections=false)
Definition: net.cpp:3482
Definition: net.h:680
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
bool HasMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: net.cpp:3325
bool IsMasternodeOrDisconnectRequested(const CService &addr)
Definition: net.cpp:3808
static const int PING_INTERVAL
Time between pings automatically sent out for latency probing and keepalive (in seconds).
Definition: net.h:54
SOCKET hSocket GUARDED_BY(cs_hSocket)
Definition: net.h:142
bool GenerateSelectSet(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1442
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1167
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:118
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
Definition: scheduler.h:37
virtual void InitializeNode(CNode *pnode)=0
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:180
static const unsigned int MAX_INV_SZ
The maximum number of entries in an 'inv' protocol message.
Definition: net.h:62
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:309
Definition: net.h:143
void SocketEvents(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set, bool fOnlyPoll)
Definition: net.cpp:1632
virtual bool ProcessMessages(CNode *pnode, std::atomic< bool > &interrupt)=0
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
Definition: net.h:676
int wakeupPipe[2]
a pipe which is added to select() calls to wakeup before the timeout
Definition: net.h:609
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
Definition: net.cpp:2752