Dash Core  0.12.2.1
P2P Digital Currency
net.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_NET_H
7 #define BITCOIN_NET_H
8 
9 #include "addrdb.h"
10 #include "addrman.h"
11 #include "bloom.h"
12 #include "compat.h"
13 #include "limitedmap.h"
14 #include "netaddress.h"
15 #include "protocol.h"
16 #include "random.h"
17 #include "streams.h"
18 #include "sync.h"
19 #include "uint256.h"
20 #include "util.h"
21 #include "threadinterrupt.h"
22 
23 #include <atomic>
24 #include <deque>
25 #include <stdint.h>
26 #include <thread>
27 #include <memory>
28 #include <condition_variable>
29 
30 #ifndef WIN32
31 #include <arpa/inet.h>
32 #endif
33 
34 #include <boost/filesystem/path.hpp>
35 #include <boost/foreach.hpp>
36 #include <boost/signals2/signal.hpp>
37 
38 class CAddrMan;
39 class CScheduler;
40 class CNode;
41 
42 namespace boost {
43  class thread_group;
44 } // namespace boost
45 
47 static const int PING_INTERVAL = 2 * 60;
49 static const int TIMEOUT_INTERVAL = 20 * 60;
51 static const int WARNING_INTERVAL = 10 * 60;
53 static const int FEELER_INTERVAL = 120;
55 static const unsigned int MAX_INV_SZ = 50000;
57 static const unsigned int MAX_ADDR_TO_SEND = 1000;
59 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 3 * 1024 * 1024;
61 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
63 static const int MAX_OUTBOUND_CONNECTIONS = 8;
67 static const bool DEFAULT_LISTEN = true;
69 #ifdef USE_UPNP
70 static const bool DEFAULT_UPNP = USE_UPNP;
71 #else
72 static const bool DEFAULT_UPNP = false;
73 #endif
74 
75 static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
77 static const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ;
79 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
81 static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
83 static const bool DEFAULT_BLOCKSONLY = false;
84 
85 static const bool DEFAULT_FORCEDNSSEED = false;
86 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
87 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
88 
90 
91 // NOTE: When adjusting this, update rpcnet:setban's help ("24h")
92 static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban
93 
94 typedef int NodeId;
95 
97 {
98  std::string strAddedNode;
101  bool fInbound;
102 };
103 
104 class CTransaction;
105 class CNodeStats;
106 class CClientUIInterface;
107 
108 class CConnman
109 {
110 public:
111 
114  CONNECTIONS_IN = (1U << 0),
115  CONNECTIONS_OUT = (1U << 1),
117  };
118 
119  struct Options
120  {
124  int nMaxOutbound = 0;
125  int nMaxFeeler = 0;
126  int nBestHeight = 0;
128  unsigned int nSendBufferMaxSize = 0;
129  unsigned int nReceiveFloodSize = 0;
130  };
131  CConnman();
132  ~CConnman();
133  bool Start(CScheduler& scheduler, std::string& strNodeError, Options options);
134  void Stop();
135  void Interrupt();
136  bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
137  bool GetNetworkActive() const { return fNetworkActive; };
138  void SetNetworkActive(bool active);
139  bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
140  bool CheckIncomingNonce(uint64_t nonce);
141 
142  // fConnectToMasternode should be 'true' only if you want this node to allow to connect to itself
143  // and/or you want it to be disconnected on CMasternodeMan::ProcessMasternodeConnections()
144  // Unfortunately, can't make this method private like in Bitcoin,
145  // because it's used in many Dash-specific places (masternode, privatesend).
146  CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL, bool fConnectToMasternode = false);
147 
149  bool operator() (const CNode* pnode) const {
150  return NodeFullyConnected(pnode);
151  }
152  };
153 
154  constexpr static const CFullyConnectedOnly FullyConnectedOnly{};
155 
156  struct CAllNodes {
157  bool operator() (const CNode*) const {return true;}
158  };
159 
160  constexpr static const CAllNodes AllNodes{};
161 
162  bool ForNode(NodeId id, std::function<bool(const CNode* pnode)> cond, std::function<bool(CNode* pnode)> func);
163  bool ForNode(const CService& addr, std::function<bool(const CNode* pnode)> cond, std::function<bool(CNode* pnode)> func);
164 
165  template<typename Callable>
166  bool ForNode(const CService& addr, Callable&& func)
167  {
168  return ForNode(addr, FullyConnectedOnly, func);
169  }
170 
171  template<typename Callable>
172  bool ForNode(NodeId id, Callable&& func)
173  {
174  return ForNode(id, FullyConnectedOnly, func);
175  }
176 
177  template <typename... Args>
178  void PushMessageWithVersionAndFlag(CNode* pnode, int nVersion, int flag, const std::string& sCommand, Args&&... args)
179  {
180  auto msg(BeginMessage(pnode, nVersion, flag, sCommand));
181  ::SerializeMany(msg, msg.nType, msg.nVersion, std::forward<Args>(args)...);
182  EndMessage(msg);
183  PushMessage(pnode, msg, sCommand);
184  }
185 
186  template <typename... Args>
187  void PushMessageWithFlag(CNode* pnode, int flag, const std::string& sCommand, Args&&... args)
188  {
189  PushMessageWithVersionAndFlag(pnode, 0, flag, sCommand, std::forward<Args>(args)...);
190  }
191 
192  template <typename... Args>
193  void PushMessageWithVersion(CNode* pnode, int nVersion, const std::string& sCommand, Args&&... args)
194  {
195  PushMessageWithVersionAndFlag(pnode, nVersion, 0, sCommand, std::forward<Args>(args)...);
196  }
197 
198  template <typename... Args>
199  void PushMessage(CNode* pnode, const std::string& sCommand, Args&&... args)
200  {
201  PushMessageWithVersionAndFlag(pnode, 0, 0, sCommand, std::forward<Args>(args)...);
202  }
203 
204  template<typename Condition, typename Callable>
205  bool ForEachNodeContinueIf(const Condition& cond, Callable&& func)
206  {
207  LOCK(cs_vNodes);
208  for (auto&& node : vNodes)
209  if (cond(node))
210  if(!func(node))
211  return false;
212  return true;
213  };
214 
215  template<typename Callable>
216  bool ForEachNodeContinueIf(Callable&& func)
217  {
219  }
220 
221  template<typename Condition, typename Callable>
222  bool ForEachNodeContinueIf(const Condition& cond, Callable&& func) const
223  {
224  LOCK(cs_vNodes);
225  for (const auto& node : vNodes)
226  if (cond(node))
227  if(!func(node))
228  return false;
229  return true;
230  };
231 
232  template<typename Callable>
233  bool ForEachNodeContinueIf(Callable&& func) const
234  {
236  }
237 
238  template<typename Condition, typename Callable>
239  void ForEachNode(const Condition& cond, Callable&& func)
240  {
241  LOCK(cs_vNodes);
242  for (auto&& node : vNodes) {
243  if (cond(node))
244  func(node);
245  }
246  };
247 
248  template<typename Callable>
249  void ForEachNode(Callable&& func)
250  {
252  }
253 
254  template<typename Condition, typename Callable>
255  void ForEachNode(const Condition& cond, Callable&& func) const
256  {
257  LOCK(cs_vNodes);
258  for (auto&& node : vNodes) {
259  if (cond(node))
260  func(node);
261  }
262  };
263 
264  template<typename Callable>
265  void ForEachNode(Callable&& func) const
266  {
268  }
269 
270  template<typename Condition, typename Callable, typename CallableAfter>
271  void ForEachNodeThen(const Condition& cond, Callable&& pre, CallableAfter&& post)
272  {
273  LOCK(cs_vNodes);
274  for (auto&& node : vNodes) {
275  if (cond(node))
276  pre(node);
277  }
278  post();
279  };
280 
281  template<typename Callable, typename CallableAfter>
282  void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
283  {
285  }
286 
287  template<typename Condition, typename Callable, typename CallableAfter>
288  void ForEachNodeThen(const Condition& cond, Callable&& pre, CallableAfter&& post) const
289  {
290  LOCK(cs_vNodes);
291  for (auto&& node : vNodes) {
292  if (cond(node))
293  pre(node);
294  }
295  post();
296  };
297 
298  template<typename Callable, typename CallableAfter>
299  void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
300  {
302  }
303 
304  std::vector<CNode*> CopyNodeVector();
305  void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);
306 
307  void RelayTransaction(const CTransaction& tx);
308  void RelayTransaction(const CTransaction& tx, const CDataStream& ss);
309  void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
310 
311  // Addrman functions
312  size_t GetAddressCount() const;
313  void SetServices(const CService &addr, ServiceFlags nServices);
314  void MarkAddressGood(const CAddress& addr);
315  void AddNewAddress(const CAddress& addr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
316  void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
317  std::vector<CAddress> GetAddresses();
318  void AddressCurrentlyConnected(const CService& addr);
319 
320  // Denial-of-service detection/prevention
321  // The idea is to detect peers that are behaving
322  // badly and disconnect/ban them, but do it in a
323  // one-coding-mistake-won't-shatter-the-entire-network
324  // way.
325  // IMPORTANT: There should be nothing I can give a
326  // node that it will forward on that will make that
327  // node's peers drop it. If there is, an attacker
328  // can isolate a node and/or try to split the network.
329  // Dropping a node for sending stuff that is invalid
330  // now but might be valid in a later version is also
331  // dangerous, because it can cause a network split
332  // between nodes running old code and nodes running
333  // new code.
334  void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
335  void Ban(const CSubNet& subNet, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
336  void ClearBanned(); // needed for unit testing
337  bool IsBanned(CNetAddr ip);
338  bool IsBanned(CSubNet subnet);
339  bool Unban(const CNetAddr &ip);
340  bool Unban(const CSubNet &ip);
341  void GetBanned(banmap_t &banmap);
342  void SetBanned(const banmap_t &banmap);
343 
344  void AddOneShot(const std::string& strDest);
345 
346  bool AddNode(const std::string& node);
347  bool RemoveAddedNode(const std::string& node);
348  std::vector<AddedNodeInfo> GetAddedNodeInfo();
349 
350  size_t GetNodeCount(NumConnections num);
351  void GetNodeStats(std::vector<CNodeStats>& vstats);
352  bool DisconnectNode(const std::string& node);
353  bool DisconnectNode(NodeId id);
354 
355  unsigned int GetSendBufferSize() const;
356 
357  void AddWhitelistedRange(const CSubNet &subnet);
358 
360 
362  void SetMaxOutboundTarget(uint64_t limit);
363  uint64_t GetMaxOutboundTarget();
364 
366  void SetMaxOutboundTimeframe(uint64_t timeframe);
367  uint64_t GetMaxOutboundTimeframe();
368 
370  // if param historicalBlockServingLimit is set true, the function will
371  // response true if the limit for serving historical blocks has been reached
372  bool OutboundTargetReached(bool historicalBlockServingLimit);
373 
375  // in case of no limit, it will always response 0
376  uint64_t GetOutboundTargetBytesLeft();
377 
379  // in case of no limit, it will always response 0
381 
382  uint64_t GetTotalBytesRecv();
383  uint64_t GetTotalBytesSent();
384 
385  void SetBestHeight(int height);
386  int GetBestHeight() const;
387 
388 
389  unsigned int GetReceiveFloodSize() const;
390 private:
391  struct ListenSocket {
394 
395  ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
396  };
397 
399  void ProcessOneShot();
400  void ThreadOpenConnections();
401  void ThreadMessageHandler();
402  void AcceptConnection(const ListenSocket& hListenSocket);
403  void ThreadSocketHandler();
404  void ThreadDNSAddressSeed();
406 
407  void WakeMessageHandler();
408 
409  CNode* FindNode(const CNetAddr& ip);
410  CNode* FindNode(const CSubNet& subNet);
411  CNode* FindNode(const std::string& addrName);
412  CNode* FindNode(const CService& addr);
413 
415  bool IsWhitelistedRange(const CNetAddr &addr);
416 
417  void DeleteNode(CNode* pnode);
418 
420 
421  size_t SocketSendData(CNode *pnode);
423  bool BannedSetIsDirty();
425  void SetBannedSetDirty(bool dirty=true);
427  void SweepBanned();
428  void DumpAddresses();
429  void DumpData();
430  void DumpBanlist();
431 
432  CDataStream BeginMessage(CNode* node, int nVersion, int flags, const std::string& sCommand);
433  void PushMessage(CNode* pnode, CDataStream& strm, const std::string& sCommand);
434  void EndMessage(CDataStream& strm);
435 
436  // Network stats
437  void RecordBytesRecv(uint64_t bytes);
438  void RecordBytesSent(uint64_t bytes);
439 
440  // Whether the node should be passed out in ForEach* callbacks
441  static bool NodeFullyConnected(const CNode* pnode);
442 
443  // Network usage totals
446  uint64_t nTotalBytesRecv;
447  uint64_t nTotalBytesSent;
448 
449  // outbound limit & stats
454 
455  // Whitelisted ranges. Any node connecting from these is automatically
456  // whitelisted (as well as those connecting to whitelisted binds).
457  std::vector<CSubNet> vWhitelistedRange;
459 
460  unsigned int nSendBufferMaxSize;
461  unsigned int nReceiveFloodSize;
462 
463  std::vector<ListenSocket> vhListenSocket;
470  std::deque<std::string> vOneShots;
472  std::vector<std::string> vAddedNodes;
474  std::vector<CNode*> vNodes;
475  std::list<CNode*> vNodesDisconnected;
477  std::atomic<NodeId> nLastNodeId;
478 
481 
484 
490  std::atomic<int> nBestHeight;
492 
495 
496  std::condition_variable condMsgProc;
497  std::mutex mutexMsgProc;
498  std::atomic<bool> flagInterruptMsgProc;
499 
501 
502  std::thread threadDNSAddressSeed;
503  std::thread threadSocketHandler;
507  std::thread threadMessageHandler;
508 };
509 extern std::unique_ptr<CConnman> g_connman;
510 void Discover(boost::thread_group& threadGroup);
511 void MapPort(bool fUseUPnP);
512 unsigned short GetListenPort();
513 bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
514 
516 {
517  typedef bool result_type;
518 
519  template<typename I>
520  bool operator()(I first, I last) const
521  {
522  while (first != last) {
523  if (!(*first)) return false;
524  ++first;
525  }
526  return true;
527  }
528 };
529 
530 // Signals for message handling
532 {
533  boost::signals2::signal<bool (CNode*, CConnman&, std::atomic<bool>&), CombinerAll> ProcessMessages;
534  boost::signals2::signal<bool (CNode*, CConnman&, std::atomic<bool>&), CombinerAll> SendMessages;
535  boost::signals2::signal<void (CNode*, CConnman&)> InitializeNode;
536  boost::signals2::signal<void (NodeId, bool&)> FinalizeNode;
537 };
538 
539 
541 
542 
543 enum
544 {
545  LOCAL_NONE, // unknown
546  LOCAL_IF, // address a local interface listens on
547  LOCAL_BIND, // address explicit bound to
548  LOCAL_UPNP, // address reported by UPnP
549  LOCAL_MANUAL, // address explicitly specified (-externalip=)
550 
552 };
553 
554 bool IsPeerAddrLocalGood(CNode *pnode);
555 void AdvertiseLocal(CNode *pnode);
556 void SetLimited(enum Network net, bool fLimited = true);
557 bool IsLimited(enum Network net);
558 bool IsLimited(const CNetAddr& addr);
559 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
560 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
561 bool RemoveLocal(const CService& addr);
562 bool SeenLocal(const CService& addr);
563 bool IsLocal(const CService& addr);
564 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
565 bool IsReachable(enum Network net);
566 bool IsReachable(const CNetAddr &addr);
567 CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
568 
569 
570 extern bool fDiscover;
571 extern bool fListen;
572 extern bool fRelayTxes;
573 
574 extern std::map<CInv, CDataStream> mapRelay;
575 extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
578 
580 extern std::string strSubVersion;
581 
583  int nScore;
584  int nPort;
585 };
586 
588 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
589 typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
590 
592 {
593 public:
597  int64_t nLastSend;
598  int64_t nLastRecv;
599  int64_t nTimeConnected;
600  int64_t nTimeOffset;
601  std::string addrName;
602  int nVersion;
603  std::string cleanSubVer;
604  bool fInbound;
606  uint64_t nSendBytes;
608  uint64_t nRecvBytes;
611  double dPingTime;
612  double dPingWait;
613  double dMinPing;
614  std::string addrLocal;
616 };
617 
618 
619 
620 
621 class CNetMessage {
622 public:
623  bool in_data; // parsing header (false) or data (true)
624 
625  CDataStream hdrbuf; // partially received header
626  CMessageHeader hdr; // complete header
627  unsigned int nHdrPos;
628 
629  CDataStream vRecv; // received message data
630  unsigned int nDataPos;
631 
632  int64_t nTime; // time (in microseconds) of message receipt.
633 
634  CNetMessage(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
635  hdrbuf.resize(24);
636  in_data = false;
637  nHdrPos = 0;
638  nDataPos = 0;
639  nTime = 0;
640  }
641 
642  bool complete() const
643  {
644  if (!in_data)
645  return false;
646  return (hdr.nMessageSize == nDataPos);
647  }
648 
649  void SetVersion(int nVersionIn)
650  {
651  hdrbuf.SetVersion(nVersionIn);
652  vRecv.SetVersion(nVersionIn);
653  }
654 
655  int readHeader(const char *pch, unsigned int nBytes);
656  int readData(const char *pch, unsigned int nBytes);
657 };
658 
659 
661 class CNode
662 {
663  friend class CConnman;
664 public:
665  // socket
669  size_t nSendSize; // total size of all vSendMsg entries
670  size_t nSendOffset; // offset inside the first vSendMsg already sent
671  uint64_t nSendBytes;
672  std::deque<CSerializeData> vSendMsg;
674 
676  std::list<CNetMessage> vProcessMsg;
678 
679  std::deque<CInv> vRecvGetData;
680  uint64_t nRecvBytes;
681  std::atomic<int> nRecvVersion;
682 
683  int64_t nLastSend;
684  int64_t nLastRecv;
685  int64_t nTimeConnected;
686  int64_t nTimeOffset;
689  std::string addrName;
692  std::atomic<int> nVersion;
693  // strSubVer is whatever byte array we read from the wire. However, this field is intended
694  // to be printed out, displayed to humans in various forms and so on. So we sanitize it and
695  // store the sanitized version in cleanSubVer. The original should be used when dealing with
696  // the network or wire types and the cleaned string used when displayed or logged.
697  std::string strSubVer, cleanSubVer;
698  bool fWhitelisted; // This peer can bypass DoS banning.
699  bool fFeeler; // If true this node is being used as a short lived feeler.
700  bool fOneShot;
701  bool fClient;
702  bool fInbound;
704  std::atomic_bool fSuccessfullyConnected;
706  // We use fRelayTxes for two purposes -
707  // a) it allows us to not relay tx invs before receiving the peer's version message
708  // b) the peer may tell us in its version message that we should not relay tx invs
709  // unless it loads a bloom filter.
711  // If 'true' this node will be disconnected on CMasternodeMan::ProcessMasternodeConnections()
719 
720  std::atomic_bool fPauseRecv;
721  std::atomic_bool fPauseSend;
722 protected:
723 
726 
727 public:
730 
731  // flood relay
732  std::vector<CAddress> vAddrToSend;
734  bool fGetAddr;
735  std::set<uint256> setKnown;
736  int64_t nNextAddrSend;
738 
739  // inventory based relay
741  std::vector<CInv> vInventoryToSend;
743  std::set<uint256> setAskFor;
744  std::multimap<int64_t, CInv> mapAskFor;
745  int64_t nNextInvSend;
746  // Used for headers announcements - unfiltered blocks to relay
747  // Also protected by cs_inventory
748  std::vector<uint256> vBlockHashesToAnnounce;
749  // Blocks received by INV while headers chain was too far behind. These are used to delay GETHEADERS messages
750  // Also protected by cs_inventory
751  std::vector<uint256> vBlockHashesFromINV;
752 
753  // Block and TXN accept times
754  std::atomic<int64_t> nLastBlockTime;
755  std::atomic<int64_t> nLastTXTime;
756 
757  // Ping time measurement:
758  // The pong reply we're expecting, or 0 if no pong expected.
759  uint64_t nPingNonceSent;
760  // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
761  int64_t nPingUsecStart;
762  // Last measured round-trip time.
763  int64_t nPingUsecTime;
764  // Best measured round-trip time.
766  // Whether a ping is requested.
768 
769  std::vector<unsigned char> vchKeyedNetGroup;
770 
771  CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn = "", bool fInboundIn = false, bool fNetworkNodeIn = false);
772  ~CNode();
773 
774 private:
775  // Secret key for computing keyed net groups
776  static std::vector<unsigned char> vchSecretKey;
777 
779 
780  CNode(const CNode&);
781  void operator=(const CNode&);
782 
783  uint64_t nLocalHostNonce;
787  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
788 public:
789 
790  NodeId GetId() const {
791  return id;
792  }
793 
794  uint64_t GetLocalNonce() const {
795  return nLocalHostNonce;
796  }
797 
798  int GetMyStartingHeight() const {
799  return nMyStartingHeight;
800  }
801 
803  {
805  assert(nRefCount >= 0);
806  return nRefCount;
807  }
808 
809  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
810 
811  void SetRecvVersion(int nVersionIn)
812  {
813  nRecvVersion = nVersionIn;
814  }
816  {
817  return nRecvVersion;
818  }
819  void SetSendVersion(int nVersionIn);
820  int GetSendVersion() const;
821 
823  {
825  nRefCount++;
826  return this;
827  }
828 
829  void Release()
830  {
832  nRefCount--;
833  assert(nRefCount >= 0);
834  }
835 
836 
837 
839  {
841  }
842 
843  void PushAddress(const CAddress& addr)
844  {
845  // Known checking here is only to save space from duplicates.
846  // SendMessages will filter it again for knowns that were added
847  // after addresses were pushed.
848  if (addr.IsValid() && !addrKnown.contains(addr.GetKey())) {
849  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
851  } else {
852  vAddrToSend.push_back(addr);
853  }
854  }
855  }
856 
857 
858  void AddInventoryKnown(const CInv& inv)
859  {
860  {
863  }
864  }
865 
866  void PushInventory(const CInv& inv)
867  {
868  {
870  if (inv.type == MSG_TX && filterInventoryKnown.contains(inv.hash)) {
871  LogPrint("net", "PushInventory -- filtered inv: %s peer=%d\n", inv.ToString(), id);
872  return;
873  }
874  LogPrint("net", "PushInventory -- inv: %s peer=%d\n", inv.ToString(), id);
875  vInventoryToSend.push_back(inv);
876  }
877  }
878 
879  void PushBlockHash(const uint256 &hash)
880  {
882  vBlockHashesToAnnounce.push_back(hash);
883  }
884 
885  void PushBlockHashFromINV(const uint256 &hash)
886  {
888  vBlockHashesFromINV.push_back(hash);
889  }
890 
891  void AskFor(const CInv& inv);
892 
893  void CloseSocketDisconnect();
894 
895  void copyStats(CNodeStats &stats);
896 
898  {
899  return nLocalServices;
900  }
901 
902  static std::vector<unsigned char> CalculateKeyedNetGroup(CAddress& address);
903 };
904 
906 {
907 public:
908  static void callCleanup();
909 };
910 
911 
912 
914 int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds);
915 
916 #endif // BITCOIN_NET_H
CCriticalSection cs_vAddedNodes
Definition: net.h:473
static const int MAX_OUTBOUND_CONNECTIONS
Definition: net.h:63
double dPingTime
Definition: net.h:611
CNode * ConnectNode(CAddress addrConnect, const char *pszDest=NULL, bool fConnectToMasternode=false)
Definition: net.cpp:347
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:103
void ForEachNode(const Condition &cond, Callable &&func) const
Definition: net.h:255
bool GetNetworkActive() const
Definition: net.h:137
void MarkAddressGood(const CAddress &addr)
Definition: net.cpp:2385
int GetMyStartingHeight() const
Definition: net.h:798
CConnman()
Definition: net.cpp:2134
static const size_t SETASKFOR_MAX_SZ
Definition: net.h:77
void ProcessOneShot()
Definition: net.cpp:1602
banmap_t setBanned
Definition: net.h:465
bool IsReachable(enum Network net)
Definition: net.cpp:285
void SetVersion(int n)
Definition: streams.h:222
CCriticalSection cs_vWhitelistedRange
Definition: net.h:458
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Definition: net.h:59
CRollingBloomFilter addrKnown
Definition: net.h:733
void Ban(const CNetAddr &netAddr, const BanReason &reason, int64_t bantimeoffset=0, bool sinceUnixEpoch=false)
Definition: net.cpp:517
std::set< uint256 > setAskFor
Definition: net.h:743
unsigned int nSendBufferMaxSize
Definition: net.h:460
std::vector< CAddress > vAddrToSend
Definition: net.h:732
double dPingWait
Definition: net.h:612
~CConnman()
Definition: net.cpp:2369
CRollingBloomFilter filterInventoryKnown
Definition: net.h:740
ServiceFlags
Definition: protocol.h:253
void insert(const std::vector< unsigned char > &vKey)
Definition: bloom.cpp:232
bool fMsgProcWake
Definition: net.h:494
boost::signals2::signal< void(NodeId, bool &)> FinalizeNode
Definition: net.h:536
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=NULL)
Definition: net.cpp:106
std::string strSubVer
Definition: net.h:697
void ThreadMessageHandler()
Definition: net.cpp:1919
std::atomic_bool fPauseSend
Definition: net.h:721
BanReason
Definition: addrdb.h:19
bool fFeeler
Definition: net.h:699
void RelayTransaction(const CTransaction &tx)
Definition: net.cpp:2477
int nRefCount
Definition: net.h:717
void operator=(const CNode &)
boost::signals2::signal< void(CNode *, CConnman &)> InitializeNode
Definition: net.h:535
bool fListen
Definition: net.cpp:77
void PushMessageWithVersion(CNode *pnode, int nVersion, const std::string &sCommand, Args &&... args)
Definition: net.h:193
CClientUIInterface * clientInterface
Definition: net.h:491
std::vector< uint256 > vBlockHashesFromINV
Definition: net.h:751
ServiceFlags nLocalServices
Definition: net.h:784
std::vector< uint256 > vBlockHashesToAnnounce
Definition: net.h:748
Definition: init.h:14
CSemaphoreGrant grantMasternodeOutbound
Definition: net.h:714
int nMyStartingHeight
Definition: net.h:785
static void callCleanup()
Definition: net.cpp:2282
std::string addrName
Definition: net.h:601
CCriticalSection cs_mapRelay
Definition: net.cpp:87
CService resolvedAddress
Definition: net.h:99
boost::signals2::signal< bool(CNode *, CConnman &, std::atomic< bool > &), CombinerAll > SendMessages
Definition: net.h:534
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:544
static const ServiceFlags REQUIRED_SERVICES
Definition: net.h:89
bool fDisconnect
Definition: net.h:705
bool fConnected
Definition: net.h:100
~CNode()
Definition: net.cpp:2737
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:85
bool SeenLocal(const CService &addr)
Definition: net.cpp:265
uint64_t GetMaxOutboundTarget()
Definition: net.cpp:2568
static std::vector< unsigned char > vchSecretKey
Definition: net.h:776
void DumpBanlist()
Definition: net.cpp:442
CSemaphore * semOutbound
Definition: net.h:485
uint256 hash
Definition: protocol.h:339
static constexpr const CFullyConnectedOnly FullyConnectedOnly
Definition: net.h:154
std::deque< std::string > vOneShots
Definition: net.h:470
std::string addrLocal
Definition: net.h:614
bool fRelayTxes
Definition: net.cpp:78
std::thread threadSocketHandler
Definition: net.h:503
void SetBanned(const banmap_t &banmap)
Definition: net.cpp:578
void CloseSocketDisconnect()
Definition: net.cpp:462
std::mutex mutexMsgProc
Definition: net.h:497
int nMaxFeeler
Definition: net.h:489
CDataStream BeginMessage(CNode *node, int nVersion, int flags, const std::string &sCommand)
Definition: net.cpp:2817
std::vector< ListenSocket > vhListenSocket
Definition: net.h:463
std::atomic_bool fPauseRecv
Definition: net.h:720
bool contains(const std::vector< unsigned char > &vKey) const
Definition: bloom.cpp:252
static const bool DEFAULT_LISTEN
Definition: net.h:67
bool result_type
Definition: net.h:517
CAddress addr
Definition: net.h:688
void GetBanned(banmap_t &banmap)
Definition: net.cpp:572
bool IsValid() const
Definition: netaddress.cpp:186
int64_t nPingUsecTime
Definition: net.h:763
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool &complete)
Definition: net.cpp:677
Definition: net.h:108
bool ForNode(NodeId id, std::function< bool(const CNode *pnode)> cond, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:2879
u_int SOCKET
Definition: compat.h:52
int64_t nNextLocalAddrSend
Definition: net.h:737
int flags
Definition: dash-tx.cpp:326
NodeId id
Definition: net.h:718
void DumpData()
Definition: net.cpp:1596
bool in_data
Definition: net.h:623
void ClearBanned()
Definition: net.cpp:472
void DeleteNode(CNode *pnode)
Definition: net.cpp:2359
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:183
bool fNetworkNode
Definition: net.h:703
int64_t nLastSend
Definition: net.h:683
void DumpAddresses()
Definition: net.cpp:1585
void MapPort(bool fUseUPnP)
Definition: net.cpp:1511
int GetRecvVersion()
Definition: net.h:815
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION)
Definition: net.cpp:2528
void EndMessage(CDataStream &strm)
Definition: net.cpp:2822
int nMaxOutbound
Definition: net.h:488
static std::vector< unsigned char > CalculateKeyedNetGroup(CAddress &address)
Definition: net.cpp:2796
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds)
Definition: net.cpp:2892
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
Definition: net.cpp:80
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
Definition: net.cpp:1964
bool fInbound
Definition: net.h:101
size_t GetAddressCount() const
Definition: net.cpp:2375
ServiceFlags nServicesExpected
Definition: net.h:667
CClientUIInterface * uiInterface
Definition: net.h:127
static const size_t MAPASKFOR_MAX_SZ
Definition: net.h:75
void AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:2395
static const int FEELER_INTERVAL
Definition: net.h:53
uint64_t GetLocalNonce() const
Definition: net.h:794
uint64_t nMaxOutboundCycleStartTime
Definition: net.h:451
CBloomFilter * pfilter
Definition: net.h:716
std::list< CNetMessage > vProcessMsg
Definition: net.h:676
void AddNewAddress(const CAddress &addr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:2390
bool operator()(const CNode *) const
Definition: net.h:157
uint64_t nMaxOutboundLimit
Definition: net.h:452
static const int TIMEOUT_INTERVAL
Definition: net.h:49
CCriticalSection cs_vOneShots
Definition: net.h:471
uint64_t nMaxOutboundTotalBytesSentInCycle
Definition: net.h:450
static uint32_t insecure_rand(void)
Definition: random.h:42
CCriticalSection cs_vSend
Definition: net.h:673
int readData(const char *pch, unsigned int nBytes)
Definition: net.cpp:786
CCriticalSection cs_setBanned
Definition: net.h:466
void resize(size_type n, value_type c=0)
Definition: streams.h:124
void ThreadOpenAddedConnections()
Definition: net.cpp:1816
bool BannedSetIsDirty()
check is the banlist has unwritten changes
Definition: net.cpp:606
uint32_t nMessageSize
Definition: protocol.h:64
int GetBestHeight() const
Definition: net.cpp:2657
bool fClient
Definition: net.h:701
bool ForEachNodeContinueIf(const Condition &cond, Callable &&func) const
Definition: net.h:222
uint64_t GetTotalBytesRecv()
Definition: net.cpp:2635
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:2662
int64_t nTimeOffset
Definition: net.h:686
void copyStats(CNodeStats &stats)
Definition: net.cpp:635
std::list< CNode * > vNodesDisconnected
Definition: net.h:475
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:609
unsigned int nReceiveFloodSize
Definition: net.h:129
void SerializeMany(Stream &s, int nType, int nVersion)
Definition: serialize.h:988
bool fNetworkActive
Definition: net.h:464
std::atomic_bool fSuccessfullyConnected
Definition: net.h:704
size_t GetNodeCount(NumConnections num)
Definition: net.cpp:2429
std::vector< AddedNodeInfo > GetAddedNodeInfo()
Definition: net.cpp:1764
void SetVersion(int nVersionIn)
Definition: net.h:649
uint64_t GetMaxOutboundTimeframe()
Definition: net.cpp:2574
uint64_t nSendBytes
Definition: net.h:671
std::deque< CInv > vRecvGetData
Definition: net.h:679
std::string cleanSubVer
Definition: net.h:603
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn="", bool fInboundIn=false, bool fNetworkNodeIn=false)
Definition: net.cpp:2665
bool fPingQueued
Definition: net.h:767
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:86
void Release()
Definition: net.h:829
NodeId GetId() const
Definition: net.h:790
bool Start(CScheduler &scheduler, std::string &strNodeError, Options options)
Definition: net.cpp:2156
std::atomic< NodeId > nLastNodeId
Definition: net.h:477
uint64_t nTotalBytesRecv
Definition: net.h:446
std::atomic< int > nRecvVersion
Definition: net.h:681
void ReleaseNodeVector(const std::vector< CNode *> &vecNodes)
Definition: net.cpp:2908
std::deque< std::pair< int64_t, CInv > > vRelayExpiration
Definition: net.cpp:86
void AddAddressKnown(const CAddress &addr)
Definition: net.h:838
int nMaxConnections
Definition: net.h:487
std::map< CSubNet, CBanEntry > banmap_t
Definition: addrdb.h:78
#define USE_UPNP
Definition: dash-config.h:355
std::map< CInv, CDataStream > mapRelay
Definition: net.cpp:85
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:2417
CCriticalSection cs_nRefCount
Definition: net.h:778
void AskFor(const CInv &inv)
Definition: net.cpp:2745
void SetRecvVersion(int nVersionIn)
Definition: net.h:811
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:2791
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
Definition: net.cpp:612
bool fRelayTxes
Definition: net.h:710
void ForEachNodeThen(const Condition &cond, Callable &&pre, CallableAfter &&post)
Definition: net.h:271
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:337
CService addrLocal
Definition: net.h:690
NumConnections
Definition: clientmodel.h:34
Definition: net.h:661
Definition: net.h:551
static int LogPrint(const char *category, const char *format)
Definition: util.h:126
uint64_t GetOutboundTargetBytesLeft()
response the bytes left in the current max outbound cycle
Definition: net.cpp:2626
int64_t nTimeOffset
Definition: net.h:600
void Stop()
Definition: net.cpp:2306
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
void GetNodeStats(std::vector< CNodeStats > &vstats)
Definition: net.cpp:2443
#define LOCK(cs)
Definition: sync.h:168
NumConnections
Definition: net.h:112
int nStartingHeight
Definition: net.h:605
int nMaxOutbound
Definition: net.h:124
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:299
CSemaphore * semMasternodeOutbound
Definition: net.h:486
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:176
bool OpenNetworkConnection(const CAddress &addrConnect, CSemaphoreGrant *grantOutbound=NULL, const char *strDest=NULL, bool fOneShot=false, bool fFeeler=false)
Definition: net.cpp:1886
std::vector< CSubNet > vWhitelistedRange
Definition: net.h:457
int GetRefCount()
Definition: net.h:802
bool fWhitelisted
Definition: net.h:610
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:2541
ListenSocket(SOCKET socket_, bool whitelisted_)
Definition: net.h:395
bool fInbound
Definition: net.h:702
uint64_t nPingNonceSent
Definition: net.h:759
size_t nProcessQueueSize
Definition: net.h:677
CAddrMan addrman
Definition: net.h:469
Definition: net.h:546
void ForEachNode(Callable &&func) const
Definition: net.h:265
static const int MAX_OUTBOUND_MASTERNODE_CONNECTIONS
Definition: net.h:65
bool ForEachNodeContinueIf(Callable &&func)
Definition: net.h:216
std::string cleanSubVer
Definition: net.h:697
bool RemoveLocal(const CService &addr)
Definition: net.cpp:236
bool fInbound
Definition: net.h:604
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached
Definition: net.cpp:2606
CAddress addr
Definition: net.h:615
void PushInventory(const CInv &inv)
Definition: net.h:866
std::thread threadDNSAddressSeed
Definition: net.h:502
uint64_t nSendBytes
Definition: net.h:606
void SetBestHeight(int height)
Definition: net.cpp:2652
size_t nSendSize
Definition: net.h:669
Network
Definition: netaddress.h:19
bool fRelayTxes
Definition: net.h:596
bool fGetAddr
Definition: net.h:734
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
Definition: net.h:79
int nMaxFeeler
Definition: net.h:125
std::deque< CSerializeData > vSendMsg
Definition: net.h:672
bool fMasternode
Definition: net.h:712
unsigned int nReceiveFloodSize
Definition: net.h:461
ServiceFlags GetLocalServices() const
Definition: net.h:897
void SetLimited(enum Network net, bool fLimited=true)
Definition: net.cpp:245
std::vector< CNode * > CopyNodeVector()
Definition: net.cpp:2896
void SetServices(const CService &addr, ServiceFlags nServices)
Definition: net.cpp:2380
uint64_t nTotalBytesSent
Definition: net.h:447
limitedmap< uint256, int64_t > mapAlreadyAskedFor
ServiceFlags nLocalServices
Definition: net.h:121
int64_t nNextAddrSend
Definition: net.h:736
CDataStream hdrbuf
Definition: net.h:625
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:498
ServiceFlags nLocalServices
Definition: net.h:480
int64_t nPingUsecStart
Definition: net.h:761
CNode * AddRef()
Definition: net.h:822
SOCKET hSocket
Definition: net.h:668
std::set< uint256 > setKnown
Definition: net.h:735
int64_t nLastRecv
Definition: net.h:684
CNetMessage(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:634
uint64_t nRecvBytes
Definition: net.h:680
CThreadInterrupt interruptNet
Definition: net.h:500
std::string ToString() const
Definition: protocol.cpp:266
bool fWhitelisted
Definition: net.h:698
unsigned int nHdrPos
Definition: net.h:627
bool Unban(const CNetAddr &ip)
Definition: net.cpp:554
unsigned int nDataPos
Definition: net.h:630
CCriticalSection cs_inventory
Definition: net.h:742
CCriticalSection cs_totalBytesSent
Definition: net.h:445
bool DisconnectNode(const std::string &node)
Definition: net.cpp:2456
int64_t nMinPingUsecTime
Definition: net.h:765
uint256 hashContinue
Definition: net.h:728
std::atomic< int64_t > nLastBlockTime
Definition: net.h:754
void AddWhitelistedRange(const CSubNet &subnet)
Definition: net.cpp:628
static const unsigned int MAX_ADDR_TO_SEND
Definition: net.h:57
int64_t nLastRecv
Definition: net.h:598
void WakeMessageHandler()
Definition: net.cpp:1387
std::thread threadOpenConnections
Definition: net.h:505
double dMinPing
Definition: net.h:613
int GetSendVersion() const
Definition: net.cpp:742
int64_t nTimeConnected
Definition: net.h:599
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:87
std::condition_variable condMsgProc
Definition: net.h:496
int nScore
Definition: net.h:583
bool fAddressesInitialized
Definition: net.h:468
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:607
bool operator()(I first, I last) const
Definition: net.h:520
bool ForEachNodeContinueIf(Callable &&func) const
Definition: net.h:233
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
Definition: net.h:81
int nSendVersion
Definition: net.h:786
ServiceFlags nServices
Definition: net.h:595
void PushBlockHash(const uint256 &hash)
Definition: net.h:879
int nNumWarningsSkipped
Definition: net.h:691
bool operator()(const CNode *pnode) const
Definition: net.h:149
uint64_t GetTotalBytesSent()
Definition: net.cpp:2641
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:32
std::vector< CNode * > vNodes
Definition: net.h:474
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes
Definition: net.cpp:2558
void AddInventoryKnown(const CInv &inv)
Definition: net.h:858
std::string strAddedNode
Definition: net.h:98
void ThreadMnbRequestConnections()
Definition: net.cpp:1842
std::atomic< int64_t > nLastTXTime
Definition: net.h:755
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:589
void ThreadSocketHandler()
Definition: net.cpp:1109
static const int MIN_PEER_PROTO_VERSION
disconnect from peers older than this proto version
Definition: version.h:22
ServiceFlags GetLocalServices() const
Definition: net.cpp:2647
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:282
std::vector< std::string > vAddedNodes
Definition: net.h:472
void AddressCurrentlyConnected(const CService &addr)
static const unsigned int DEFAULT_MISBEHAVING_BANTIME
Definition: net.h:92
CCriticalSection cs_filter
Definition: net.h:715
boost::signals2::signal< bool(CNode *, CConnman &, std::atomic< bool > &), CombinerAll > ProcessMessages
Definition: net.h:533
int nVersion
Definition: net.h:602
int NodeId
Definition: net.h:94
void Discover(boost::thread_group &threadGroup)
Definition: net.cpp:2062
void ThreadDNSAddressSeed()
Definition: net.cpp:1522
uint64_t GetMaxOutboundTimeLeftInCycle()
response the time in second left in the current max outbound cycle
Definition: net.cpp:2580
int nStartingHeight
Definition: net.h:729
unsigned int GetSendBufferSize() const
Definition: net.cpp:2663
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:725
bool IsBanned(CNetAddr ip)
Definition: net.cpp:484
std::thread threadMessageHandler
Definition: net.h:507
unsigned int nSendBufferMaxSize
Definition: net.h:128
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:301
int64_t nLastSend
Definition: net.h:597
int type
Definition: protocol.h:338
bool ForNode(const CService &addr, Callable &&func)
Definition: net.h:166
void PushBlockHashFromINV(const uint256 &hash)
Definition: net.h:885
Definition: protocol.h:314
CMessageHeader hdr
Definition: net.h:626
static const unsigned int MAX_SUBVERSION_LENGTH
Definition: net.h:61
int nMaxConnections
Definition: net.h:123
static const bool DEFAULT_UPNP
Definition: net.h:72
bool IsWhitelistedRange(const CNetAddr &addr)
Definition: net.cpp:619
NodeId nodeid
Definition: net.h:594
static const bool DEFAULT_BLOCKSONLY
Definition: net.h:83
CSemaphoreGrant grantOutbound
Definition: net.h:713
void PushMessageWithVersionAndFlag(CNode *pnode, int nVersion, int flag, const std::string &sCommand, Args &&... args)
Definition: net.h:178
static const int PING_INTERVAL
Definition: net.h:47
bool ForEachNodeContinueIf(const Condition &cond, Callable &&func)
Definition: net.h:205
ServiceFlags nRelevantServices
Definition: net.h:122
std::multimap< int64_t, CInv > mapAskFor
Definition: net.h:744
int64_t nNextInvSend
Definition: net.h:745
void Interrupt()
Definition: net.cpp:2290
int64_t nLastWarningTime
Definition: net.h:687
CCriticalSection cs_vNodes
Definition: net.h:476
std::string addrName
Definition: net.h:689
std::string strSubVersion
Definition: net.cpp:83
std::thread threadOpenAddedConnections
Definition: net.h:504
std::thread threadMnbRequestConnections
Definition: net.h:506
int64_t nTime
Definition: net.h:632
std::atomic< int > nBestHeight
Definition: net.h:490
NodeId GetNewNodeId()
Definition: net.cpp:2151
static const int WARNING_INTERVAL
Definition: net.h:51
void AddOneShot(const std::string &strDest)
Definition: net.cpp:94
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1023
bool AttemptToEvictConnection()
Definition: net.cpp:924
CCriticalSection cs_totalBytesRecv
Definition: net.h:444
std::vector< CAddress > GetAddresses()
Definition: net.cpp:2400
bool fDiscover
Definition: net.cpp:76
void ThreadOpenConnections()
Definition: net.cpp:1620
int readHeader(const char *pch, unsigned int nBytes)
Definition: net.cpp:755
static constexpr const CAllNodes AllNodes
Definition: net.h:160
bool fOneShot
Definition: net.h:700
void ForEachNode(Callable &&func)
Definition: net.h:249
void SetNetworkActive(bool active)
Definition: net.cpp:2113
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:724
size_t nSendOffset
Definition: net.h:670
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:155
static const unsigned int MAX_INV_SZ
Definition: net.h:55
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:205
void ForEachNode(const Condition &cond, Callable &&func)
Definition: net.h:239
CDataStream vRecv
Definition: net.h:629
uint64_t nRecvBytes
Definition: net.h:608
void PushAddress(const CAddress &addr)
Definition: net.h:843
int64_t nTimeConnected
Definition: net.h:685
CNodeSignals & GetNodeSignals()
Definition: net.cpp:92
bool IsLocal(const CService &addr)
Definition: net.cpp:278
uint64_t nLocalHostNonce
Definition: net.h:783
void ForEachNodeThen(const Condition &cond, Callable &&pre, CallableAfter &&post) const
Definition: net.h:288
CCriticalSection cs_mapLocalHost
Definition: net.cpp:79
void SetSendVersion(int nVersionIn)
Definition: net.cpp:728
ServiceFlags nServices
Definition: net.h:666
size_t SocketSendData(CNode *pnode)
Definition: net.cpp:811
bool setBannedIsDirty
Definition: net.h:467
ServiceFlags nRelevantServices
Definition: net.h:483
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:2535
void PushMessage(CNode *pnode, const std::string &sCommand, Args &&... args)
Definition: net.h:199
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target
Definition: net.cpp:2594
std::atomic< int > nVersion
Definition: net.h:692
std::vector< CInv > vInventoryToSend
Definition: net.h:741
unsigned short GetListenPort()
Definition: net.cpp:100
bool IsLimited(enum Network net)
Definition: net.cpp:253
int nBestHeight
Definition: net.h:126
void PushMessageWithFlag(CNode *pnode, int flag, const std::string &sCommand, Args &&... args)
Definition: net.h:187
bool complete() const
Definition: net.h:642
bool AddNode(const std::string &node)
Definition: net.cpp:2405
std::vector< unsigned char > vchKeyedNetGroup
Definition: net.h:769
void SweepBanned()
clean unused entries (if bantime has expired)
Definition: net.cpp:585
uint64_t nMaxOutboundTimeframe
Definition: net.h:453
bool ForNode(NodeId id, Callable &&func)
Definition: net.h:172
std::list< CNetMessage > vRecvMsg
Definition: net.h:787
CCriticalSection cs_vProcessMsg
Definition: net.h:675