Bitcoin
net.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <amount.h>
12 #include <bloom.h>
13 #include <compat.h>
14 #include <crypto/siphash.h>
15 #include <hash.h>
16 #include <limitedmap.h>
17 #include <netaddress.h>
18 #include <policy/feerate.h>
19 #include <protocol.h>
20 #include <random.h>
21 #include <streams.h>
22 #include <sync.h>
23 #include <uint256.h>
24 #include <threadinterrupt.h>
25 
26 #include <atomic>
27 #include <deque>
28 #include <stdint.h>
29 #include <thread>
30 #include <memory>
31 #include <condition_variable>
32 
33 #ifndef WIN32
34 #include <arpa/inet.h>
35 #endif
36 
37 
38 class CScheduler;
39 class CNode;
40 class BanMan;
41 
43 static const int PING_INTERVAL = 2 * 60;
45 static const int TIMEOUT_INTERVAL = 20 * 60;
47 static const int FEELER_INTERVAL = 120;
49 static const unsigned int MAX_INV_SZ = 50000;
51 static const unsigned int MAX_LOCATOR_SZ = 101;
53 static const unsigned int MAX_ADDR_TO_SEND = 1000;
55 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
57 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
59 static const int MAX_OUTBOUND_CONNECTIONS = 8;
61 static const int MAX_ADDNODE_CONNECTIONS = 8;
63 static const bool DEFAULT_LISTEN = true;
65 #ifdef USE_UPNP
66 static const bool DEFAULT_UPNP = USE_UPNP;
67 #else
68 static const bool DEFAULT_UPNP = false;
69 #endif
70 
71 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
75 static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
77 static const bool DEFAULT_BLOCKSONLY = false;
80 
81 static const bool DEFAULT_FORCEDNSSEED = false;
82 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
83 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
84 
85 typedef int64_t NodeId;
86 
88 {
89  std::string strAddedNode;
91  bool fConnected;
92  bool fInbound;
93 };
94 
95 class CNodeStats;
96 class CClientUIInterface;
97 
99 {
100  CSerializedNetMsg() = default;
103  // No copying, only moves.
104  CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
106 
107  std::vector<unsigned char> data;
108  std::string command;
109 };
110 
111 
112 class NetEventsInterface;
113 class CConnman
114 {
115 public:
116 
119  CONNECTIONS_IN = (1U << 0),
120  CONNECTIONS_OUT = (1U << 1),
122  };
123 
124  struct Options
125  {
128  int nMaxOutbound = 0;
129  int nMaxAddnode = 0;
130  int nMaxFeeler = 0;
131  int nBestHeight = 0;
134  BanMan* m_banman = nullptr;
135  unsigned int nSendBufferMaxSize = 0;
136  unsigned int nReceiveFloodSize = 0;
140  std::vector<std::string> vSeedNodes;
141  std::vector<CSubNet> vWhitelistedRange;
142  std::vector<CService> vBinds, vWhiteBinds;
144  std::vector<std::string> m_specified_outgoing;
145  std::vector<std::string> m_added_nodes;
146  };
147 
148  void Init(const Options& connOptions) {
149  nLocalServices = connOptions.nLocalServices;
150  nMaxConnections = connOptions.nMaxConnections;
151  nMaxOutbound = std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections);
153  nMaxAddnode = connOptions.nMaxAddnode;
154  nMaxFeeler = connOptions.nMaxFeeler;
155  nBestHeight = connOptions.nBestHeight;
156  clientInterface = connOptions.uiInterface;
157  m_banman = connOptions.m_banman;
158  m_msgproc = connOptions.m_msgproc;
160  nReceiveFloodSize = connOptions.nReceiveFloodSize;
162  {
164  nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
165  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
166  }
167  vWhitelistedRange = connOptions.vWhitelistedRange;
168  {
170  vAddedNodes = connOptions.m_added_nodes;
171  }
172  }
173 
174  CConnman(uint64_t seed0, uint64_t seed1);
175  ~CConnman();
176  bool Start(CScheduler& scheduler, const Options& options);
177 
178  // TODO: Remove NO_THREAD_SAFETY_ANALYSIS. Lock cs_vNodes before reading the variable vNodes.
179  //
180  // When removing NO_THREAD_SAFETY_ANALYSIS be aware of the following lock order requirements:
181  // * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
182  // which locks cs_vNodes.
183  // * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
184  // locks cs_vNodes.
185  //
186  // Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes.
188 
189  void Interrupt();
190  bool GetNetworkActive() const { return fNetworkActive; };
192  void SetNetworkActive(bool active);
193  void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool fOneShot = false, bool fFeeler = false, bool manual_connection = false);
194  bool CheckIncomingNonce(uint64_t nonce);
195 
196  bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
197 
198  void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
199 
200  template<typename Callable>
201  void ForEachNode(Callable&& func)
202  {
203  LOCK(cs_vNodes);
204  for (auto&& node : vNodes) {
205  if (NodeFullyConnected(node))
206  func(node);
207  }
208  };
209 
210  template<typename Callable>
211  void ForEachNode(Callable&& func) const
212  {
213  LOCK(cs_vNodes);
214  for (auto&& node : vNodes) {
215  if (NodeFullyConnected(node))
216  func(node);
217  }
218  };
219 
220  template<typename Callable, typename CallableAfter>
221  void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
222  {
223  LOCK(cs_vNodes);
224  for (auto&& node : vNodes) {
225  if (NodeFullyConnected(node))
226  pre(node);
227  }
228  post();
229  };
230 
231  template<typename Callable, typename CallableAfter>
232  void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
233  {
234  LOCK(cs_vNodes);
235  for (auto&& node : vNodes) {
236  if (NodeFullyConnected(node))
237  pre(node);
238  }
239  post();
240  };
241 
242  // Addrman functions
243  size_t GetAddressCount() const;
244  void SetServices(const CService &addr, ServiceFlags nServices);
245  void MarkAddressGood(const CAddress& addr);
246  void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
247  std::vector<CAddress> GetAddresses();
248 
249  // This allows temporarily exceeding nMaxOutbound, with the goal of finding
250  // a peer that is better than all our current peers.
251  void SetTryNewOutboundPeer(bool flag);
252  bool GetTryNewOutboundPeer();
253 
254  // Return the number of outbound peers we have in excess of our target (eg,
255  // if we previously called SetTryNewOutboundPeer(true), and have since set
256  // to false, we may have extra peers that we wish to disconnect). This may
257  // return a value less than (num_outbound_connections - num_outbound_slots)
258  // in cases where some outbound connections are not yet fully connected, or
259  // not yet fully disconnected.
260  int GetExtraOutboundCount();
261 
262  bool AddNode(const std::string& node);
263  bool RemoveAddedNode(const std::string& node);
264  std::vector<AddedNodeInfo> GetAddedNodeInfo();
265 
266  size_t GetNodeCount(NumConnections num);
267  void GetNodeStats(std::vector<CNodeStats>& vstats);
268  bool DisconnectNode(const std::string& node);
269  bool DisconnectNode(const CSubNet& subnet);
270  bool DisconnectNode(const CNetAddr& addr);
271  bool DisconnectNode(NodeId id);
272 
274 
276  void SetMaxOutboundTarget(uint64_t limit);
278 
280  void SetMaxOutboundTimeframe(uint64_t timeframe);
282 
286  bool OutboundTargetReached(bool historicalBlockServingLimit);
287 
291 
295 
298 
299  void SetBestHeight(int height);
300  int GetBestHeight() const;
301 
304 
305  unsigned int GetReceiveFloodSize() const;
306 
307  void WakeMessageHandler();
308 
313  int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
314 
315 private:
316  struct ListenSocket {
319 
320  ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
321  };
322 
323  bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
324  bool Bind(const CService &addr, unsigned int flags);
325  bool InitBinds(const std::vector<CService>& binds, const std::vector<CService>& whiteBinds);
327  void AddOneShot(const std::string& strDest);
328  void ProcessOneShot();
329  void ThreadOpenConnections(std::vector<std::string> connect);
330  void ThreadMessageHandler();
331  void AcceptConnection(const ListenSocket& hListenSocket);
332  void DisconnectNodes();
334  void InactivityCheck(CNode *pnode);
335  bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
336  void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
337  void SocketHandler();
338  void ThreadSocketHandler();
339  void ThreadDNSAddressSeed();
340 
341  uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
342 
343  CNode* FindNode(const CNetAddr& ip);
344  CNode* FindNode(const CSubNet& subNet);
345  CNode* FindNode(const std::string& addrName);
346  CNode* FindNode(const CService& addr);
347 
349  CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection);
350  bool IsWhitelistedRange(const CNetAddr &addr);
351 
352  void DeleteNode(CNode* pnode);
353 
355 
356  size_t SocketSendData(CNode *pnode) const;
357  void DumpAddresses();
358 
359  // Network stats
360  void RecordBytesRecv(uint64_t bytes);
361  void RecordBytesSent(uint64_t bytes);
362 
363  // Whether the node should be passed out in ForEach* callbacks
364  static bool NodeFullyConnected(const CNode* pnode);
365 
366  // Network usage totals
369  uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv);
370  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent);
371 
372  // outbound limit & stats
373  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
374  uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
375  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
376  uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
377 
378  // P2P timeout in seconds
380 
381  // Whitelisted ranges. Any node connecting from these is automatically
382  // whitelisted (as well as those connecting to whitelisted binds).
383  std::vector<CSubNet> vWhitelistedRange;
384 
385  unsigned int nSendBufferMaxSize{0};
386  unsigned int nReceiveFloodSize{0};
387 
388  std::vector<ListenSocket> vhListenSocket;
389  std::atomic<bool> fNetworkActive{true};
392  std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
394  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
396  std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
397  std::list<CNode*> vNodesDisconnected;
399  std::atomic<NodeId> nLastNodeId{0};
400  unsigned int nPrevNodeCount{0};
401 
404 
405  std::unique_ptr<CSemaphore> semOutbound;
406  std::unique_ptr<CSemaphore> semAddnode;
412  std::atomic<int> nBestHeight;
416 
419 
422 
423  std::condition_variable condMsgProc;
425  std::atomic<bool> flagInterruptMsgProc{false};
426 
428 
429  std::thread threadDNSAddressSeed;
430  std::thread threadSocketHandler;
433  std::thread threadMessageHandler;
434 
438  std::atomic_bool m_try_another_outbound_peer;
439 
440  std::atomic<int64_t> m_next_send_inv_to_incoming{0};
441 
442  friend struct CConnmanTest;
443 };
444 extern std::unique_ptr<CConnman> g_connman;
445 extern std::unique_ptr<BanMan> g_banman;
446 void Discover();
447 void StartMapPort();
448 void InterruptMapPort();
449 void StopMapPort();
450 unsigned short GetListenPort();
451 bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
452 
454 {
455  typedef bool result_type;
456 
457  template<typename I>
458  bool operator()(I first, I last) const
459  {
460  while (first != last) {
461  if (!(*first)) return false;
462  ++first;
463  }
464  return true;
465  }
466 };
467 
472 {
473 public:
474  virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
475  virtual bool SendMessages(CNode* pnode) = 0;
476  virtual void InitializeNode(CNode* pnode) = 0;
477  virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
478 
479 protected:
484  ~NetEventsInterface() = default;
485 };
486 
487 enum
488 {
489  LOCAL_NONE, // unknown
490  LOCAL_IF, // address a local interface listens on
491  LOCAL_BIND, // address explicit bound to
492  LOCAL_UPNP, // address reported by UPnP
493  LOCAL_MANUAL, // address explicitly specified (-externalip=)
494 
496 };
497 
498 bool IsPeerAddrLocalGood(CNode *pnode);
499 void AdvertiseLocal(CNode *pnode);
500 
505 void SetReachable(enum Network net, bool reachable);
507 bool IsReachable(enum Network net);
509 bool IsReachable(const CNetAddr& addr);
510 
511 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
512 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
513 void RemoveLocal(const CService& addr);
514 bool SeenLocal(const CService& addr);
515 bool IsLocal(const CService& addr);
516 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
518 
519 
520 extern bool fDiscover;
521 extern bool fListen;
522 extern bool g_relay_txes;
523 
525 extern std::string strSubVersion;
526 
528  int nScore;
529  int nPort;
530 };
531 
533 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost);
534 
535 extern const std::string NET_MESSAGE_COMMAND_OTHER;
536 typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
537 
539 {
540 public:
548  std::string addrName;
549  int nVersion;
550  std::string cleanSubVer;
551  bool fInbound;
559  double dPingTime;
560  double dPingWait;
561  double dMinPing;
563  // Our address, as reported by the peer
564  std::string addrLocal;
565  // Address of this peer
567  // Bind address of our side of the connection
569 };
570 
571 
572 
573 
574 class CNetMessage {
575 private:
576  mutable CHash256 hasher;
578 public:
579  bool in_data; // parsing header (false) or data (true)
580 
581  CDataStream hdrbuf; // partially received header
582  CMessageHeader hdr; // complete header
583  unsigned int nHdrPos;
584 
585  CDataStream vRecv; // received message data
586  unsigned int nDataPos;
587 
588  int64_t nTime; // time (in microseconds) of message receipt.
589 
590  CNetMessage(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
591  hdrbuf.resize(24);
592  in_data = false;
593  nHdrPos = 0;
594  nDataPos = 0;
595  nTime = 0;
596  }
597 
598  bool complete() const
599  {
600  if (!in_data)
601  return false;
602  return (hdr.nMessageSize == nDataPos);
603  }
604 
605  const uint256& GetMessageHash() const;
606 
607  void SetVersion(int nVersionIn)
608  {
609  hdrbuf.SetVersion(nVersionIn);
610  vRecv.SetVersion(nVersionIn);
611  }
612 
613  int readHeader(const char *pch, unsigned int nBytes);
614  int readData(const char *pch, unsigned int nBytes);
615 };
616 
617 
619 class CNode
620 {
621  friend class CConnman;
622 public:
623  // socket
624  std::atomic<ServiceFlags> nServices{NODE_NONE};
625  SOCKET hSocket GUARDED_BY(cs_hSocket);
626  size_t nSendSize{0}; // total size of all vSendMsg entries
627  size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
628  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
629  std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
633 
635  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
636  size_t nProcessQueueSize{0};
637 
639 
640  std::deque<CInv> vRecvGetData;
641  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
642  std::atomic<int> nRecvVersion{INIT_PROTO_VERSION};
643 
644  std::atomic<int64_t> nLastSend{0};
645  std::atomic<int64_t> nLastRecv{0};
647  std::atomic<int64_t> nTimeOffset{0};
648  // Address of this peer
649  const CAddress addr;
650  // Bind address of our side of the connection
652  std::atomic<int> nVersion{0};
658  std::string cleanSubVer GUARDED_BY(cs_SubVer){};
659  bool m_prefer_evict{false}; // This peer is preferred for eviction.
660  bool fWhitelisted{false}; // This peer can bypass DoS banning.
661  bool fFeeler{false}; // If true this node is being used as a short lived feeler.
662  bool fOneShot{false};
663  bool m_manual_connection{false};
664  bool fClient{false}; // set by version message
665  bool m_limited_node{false}; //after BIP159, set by version message
666  const bool fInbound;
667  std::atomic_bool fSuccessfullyConnected{false};
668  // Setting fDisconnect to true will cause the node to be disconnected the
669  // next time DisconnectNodes() runs
670  std::atomic_bool fDisconnect{false};
671  // We use fRelayTxes for two purposes -
672  // a) it allows us to not relay tx invs before receiving the peer's version message
673  // b) the peer may tell us in its version message that we should not relay tx invs
674  // unless it loads a bloom filter.
675  bool fRelayTxes GUARDED_BY(cs_filter){false};
676  bool fSentAddr{false};
679  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter);
680  std::atomic<int> nRefCount{0};
681 
683  std::atomic_bool fPauseRecv{false};
684  std::atomic_bool fPauseSend{false};
685 
686 protected:
688  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
689 
690 public:
692  std::atomic<int> nStartingHeight{-1};
693 
694  // flood relay
695  std::vector<CAddress> vAddrToSend;
697  bool fGetAddr{false};
698  std::set<uint256> setKnown;
700  int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
701 
702  // inventory based relay
703  CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_inventory);
704  // Set of transaction ids we still have to announce.
705  // They are sorted by the mempool before relay, so the order is not important.
706  std::set<uint256> setInventoryTxToSend;
707  // List of block ids we still have announce.
708  // There is no final sorting before sending, as they are always sent immediately
709  // and in the order requested.
710  std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory);
713  // Used for headers announcements - unfiltered blocks to relay
714  std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
715  // Used for BIP35 mempool sending
716  bool fSendMempool GUARDED_BY(cs_inventory){false};
717 
718  // Last time a "MEMPOOL" request was serviced.
719  std::atomic<int64_t> timeLastMempoolReq{0};
720 
721  // Block and TXN accept times
722  std::atomic<int64_t> nLastBlockTime{0};
723  std::atomic<int64_t> nLastTXTime{0};
724 
725  // Ping time measurement:
726  // The pong reply we're expecting, or 0 if no pong expected.
727  std::atomic<uint64_t> nPingNonceSent{0};
728  // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
729  std::atomic<int64_t> nPingUsecStart{0};
730  // Last measured round-trip time.
731  std::atomic<int64_t> nPingUsecTime{0};
732  // Best measured round-trip time.
733  std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
734  // Whether a ping is requested.
735  std::atomic<bool> fPingQueued{false};
736  // Minimum fee rate with which to filter inv's to this node
737  CAmount minFeeFilter GUARDED_BY(cs_feeFilter){0};
741 
742  std::set<uint256> orphan_work_set;
743 
744  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);
745  ~CNode();
746  CNode(const CNode&) = delete;
747  CNode& operator=(const CNode&) = delete;
748 
749 private:
750  const NodeId id;
752  // Services offered to this peer
754  const int nMyStartingHeight;
755  int nSendVersion{0};
756  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
757 
759  std::string addrName GUARDED_BY(cs_addrName);
760 
761  // Our address, as reported by the peer
762  CService addrLocal GUARDED_BY(cs_addrLocal);
764 public:
765 
766  NodeId GetId() const {
767  return id;
768  }
769 
771  return nLocalHostNonce;
772  }
773 
774  int GetMyStartingHeight() const {
775  return nMyStartingHeight;
776  }
777 
778  int GetRefCount() const
779  {
780  assert(nRefCount >= 0);
781  return nRefCount;
782  }
783 
784  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
785 
786  void SetRecvVersion(int nVersionIn)
787  {
788  nRecvVersion = nVersionIn;
789  }
790  int GetRecvVersion() const
791  {
792  return nRecvVersion;
793  }
794  void SetSendVersion(int nVersionIn);
795  int GetSendVersion() const;
796 
797  CService GetAddrLocal() const;
799  void SetAddrLocal(const CService& addrLocalIn);
800 
802  {
803  nRefCount++;
804  return this;
805  }
806 
807  void Release()
808  {
809  nRefCount--;
810  }
811 
812 
813 
814  void AddAddressKnown(const CAddress& _addr)
815  {
816  addrKnown.insert(_addr.GetKey());
817  }
818 
819  void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
820  {
821  // Known checking here is only to save space from duplicates.
822  // SendMessages will filter it again for knowns that were added
823  // after addresses were pushed.
824  if (_addr.IsValid() && !addrKnown.contains(_addr.GetKey())) {
825  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
826  vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
827  } else {
828  vAddrToSend.push_back(_addr);
829  }
830  }
831  }
832 
833 
834  void AddInventoryKnown(const CInv& inv)
835  {
836  {
838  filterInventoryKnown.insert(inv.hash);
839  }
840  }
841 
842  void PushInventory(const CInv& inv)
843  {
845  if (inv.type == MSG_TX) {
846  if (!filterInventoryKnown.contains(inv.hash)) {
847  setInventoryTxToSend.insert(inv.hash);
848  }
849  } else if (inv.type == MSG_BLOCK) {
850  vInventoryBlockToSend.push_back(inv.hash);
851  }
852  }
853 
854  void PushBlockHash(const uint256 &hash)
855  {
857  vBlockHashesToAnnounce.push_back(hash);
858  }
859 
860  void CloseSocketDisconnect();
861 
862  void copyStats(CNodeStats &stats);
863 
865  {
866  return nLocalServices;
867  }
868 
869  std::string GetAddrName() const;
871  void MaybeSetAddrName(const std::string& addrNameIn);
872 };
873 
874 
875 
876 
877 
879 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
880 
881 #endif // BITCOIN_NET_H
CCriticalSection cs_vAddedNodes
Definition: net.h:395
Definition: siphash.h:13
static const int MAX_OUTBOUND_CONNECTIONS
Definition: net.h:59
double dPingTime
Definition: net.h:559
bool m_manual_connection
Definition: net.h:552
std::atomic< int > nRefCount
Definition: net.h:680
bool m_prefer_evict
Definition: net.h:659
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:84
bool GetNetworkActive() const
Definition: net.h:190
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:628
Definition: protocol.h:325
void MarkAddressGood(const CAddress &addr)
Definition: net.cpp:2385
Definition: net.h:491
int GetMyStartingHeight() const
Definition: net.h:774
void ProcessOneShot()
Definition: net.cpp:1609
bool IsReachable(enum Network net)
Definition: net.cpp:250
void SetVersion(int n)
Definition: streams.h:396
const uint64_t nSeed0
Definition: net.h:418
Definition: net.h:453
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Definition: net.h:55
CRollingBloomFilter addrKnown
Definition: net.h:696
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing)
Definition: net.h:699
Definition: net.h:118
unsigned int nSendBufferMaxSize
Definition: net.h:385
std::vector< CAddress > vAddrToSend
Definition: net.h:695
double dPingWait
Definition: net.h:560
~CConnman()
Definition: net.cpp:2369
ServiceFlags
Definition: protocol.h:247
void insert(const std::vector< unsigned char > &vKey)
Definition: bloom.cpp:246
bool fMsgProcWake
Definition: net.h:421
static const uint64_t MAX_UPLOAD_TIMEFRAME
Definition: net.h:75
void ThreadMessageHandler()
Definition: net.cpp:1945
std::atomic_bool fPauseSend
Definition: net.h:684
bool fFeeler
Definition: net.h:661
int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds)
Definition: net.cpp:2705
CHash256 hasher
Definition: net.h:576
int64_t m_peer_connect_timeout
Definition: net.h:139
bool GetUseAddrmanOutgoing() const
Definition: net.h:191
bool fListen
Definition: net.cpp:81
std::set< uint256 > orphan_work_set
Definition: net.h:742
CClientUIInterface * clientInterface
Definition: net.h:413
const CAddress addr
Definition: net.h:649
std::string addrName
Definition: net.h:548
CService resolvedAddress
Definition: net.h:90
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:669
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:2655
bool fConnected
Definition: net.h:91
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:73
~CNode()
Definition: net.cpp:2645
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
int64_t m_peer_connect_timeout
Definition: net.h:379
std::vector< CService > vBinds
Definition: net.h:142
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:81
bool SeenLocal(const CService &addr)
Definition: net.cpp:262
uint64_t GetMaxOutboundTarget()
Definition: net.cpp:2519
Mutex mutexMsgProc
Definition: net.h:424
uint64_t nMaxOutboundTimeframe
Definition: net.h:137
std::atomic< int64_t > nLastRecv
Definition: net.h:645
bool whitelisted
Definition: net.h:318
void StartMapPort()
Definition: net.cpp:1503
void StopMapPort()
Definition: net.cpp:1511
const bool fInbound
Definition: net.h:666
Definition: protocol.h:371
uint256 hash
Definition: protocol.h:404
int GetRefCount() const
Definition: net.h:778
Definition: scheduler.h:37
std::string addrLocal
Definition: net.h:564
std::thread threadSocketHandler
Definition: net.h:430
#define USE_UPNP
Definition: bitcoin-config.h:432
Definition: netaddress.h:32
bool g_relay_txes
Definition: net.cpp:82
void CloseSocketDisconnect()
Definition: net.cpp:447
int nMaxFeeler
Definition: net.h:410
~NetEventsInterface()=default
std::vector< ListenSocket > vhListenSocket
Definition: net.h:388
std::atomic_bool fPauseRecv
Definition: net.h:683
uint256 data_hash
Definition: net.h:577
const CAddress addrBind
Definition: net.h:651
bool contains(const std::vector< unsigned char > &vKey) const
Definition: bloom.cpp:283
static const bool DEFAULT_LISTEN
Definition: net.h:63
bool result_type
Definition: net.h:455
std::atomic< int > nStartingHeight
Definition: net.h:692
static const int MAX_ADDNODE_CONNECTIONS
Definition: net.h:61
bool IsValid() const
Definition: netaddress.cpp:247
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool &complete)
Definition: net.cpp:555
Definition: net.h:113
bool in_data
Definition: net.h:579
void DeleteNode(CNode *pnode)
Definition: net.cpp:2358
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:177
void DumpAddresses()
Definition: net.cpp:1598
int nMaxOutbound
Definition: net.h:408
CConnman(uint64_t seed0, uint64_t seed1)
Definition: net.cpp:2132
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
Definition: net.cpp:1999
std::string command
Definition: net.h:108
bool InitBinds(const std::vector< CService > &binds, const std::vector< CService > &whiteBinds)
Definition: net.cpp:2159
bool fInbound
Definition: net.h:92
size_t GetAddressCount() const
Definition: net.cpp:2375
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:675
CClientUIInterface * uiInterface
Definition: net.h:132
Definition: protocol.h:372
void AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:2390
static CScheduler scheduler
Definition: init.cpp:178
Definition: net.h:98
CAddress addrBind
Definition: net.h:568
const ServiceFlags nLocalServices
Definition: net.h:753
static const int FEELER_INTERVAL
Definition: net.h:47
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:819
uint64_t GetLocalNonce() const
Definition: net.h:770
static const int TIMEOUT_INTERVAL
Definition: net.h:45
std::atomic< int64_t > m_next_send_inv_to_incoming
Definition: net.h:440
CCriticalSection cs_vOneShots
Definition: net.h:393
CSerializedNetMsg()=default
BanMan * m_banman
Definition: net.h:134
Definition: net.h:490
CCriticalSection cs_vSend
Definition: net.h:630
int readData(const char *pch, unsigned int nBytes)
Definition: net.cpp:664
std::atomic< int64_t > nPingUsecTime
Definition: net.h:731
void resize(size_type n, value_type c=0)
Definition: streams.h:296
void ThreadOpenAddedConnections()
Definition: net.cpp:1878
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:2615
uint32_t nMessageSize
Definition: protocol.h:59
int GetBestHeight() const
Definition: net.cpp:2608
std::vector< CService > vWhiteBinds
Definition: net.h:142
bool fClient
Definition: net.h:664
Definition: net.h:495
CAmount lastSentFeeFilter
Definition: net.h:739
uint64_t GetTotalBytesRecv()
Definition: net.cpp:2586
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:2613
void copyStats(CNodeStats &stats)
Definition: net.cpp:494
std::list< CNode * > vNodesDisconnected
Definition: net.h:397
Definition: net.h:87
Definition: threadinterrupt.h:20
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:557
unsigned int nReceiveFloodSize
Definition: net.h:136
Definition: banman.h:37
CService GetAddrLocal() const
Definition: net.cpp:478
std::atomic_bool fSuccessfullyConnected
Definition: net.h:667
const uint64_t nSeed1
Definition: net.h:418
int GetRecvVersion() const
Definition: net.h:790
static const unsigned int MAX_LOCATOR_SZ
Definition: net.h:51
Definition: net.h:124
size_t GetNodeCount(NumConnections num)
Definition: net.cpp:2423
std::vector< AddedNodeInfo > GetAddedNodeInfo()
Definition: net.cpp:1824
int64_t CAmount
Definition: amount.h:12
bool Bind(const CService &addr, unsigned int flags)
Definition: net.cpp:2146
void SetVersion(int nVersionIn)
Definition: net.h:607
int nMaxAddnode
Definition: net.h:409
uint64_t GetMaxOutboundTimeframe()
Definition: net.cpp:2525
std::deque< CInv > vRecvGetData
Definition: net.h:640
std::string cleanSubVer
Definition: net.h:550
CNode * ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection)
Definition: net.cpp:351
std::atomic< int64_t > nMinPingUsecTime
Definition: net.h:733
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:2726
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:82
void Release()
Definition: net.h:807
NodeId GetId() const
Definition: net.h:766
uint64_t randrange(uint64_t range) noexcept
Definition: random.h:165
std::atomic< NodeId > nLastNodeId
Definition: net.h:399
Definition: bloom.h:115
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
std::atomic< int > nRecvVersion
Definition: net.h:642
std::vector< unsigned char > data
Definition: net.h:107
int nMaxConnections
Definition: net.h:407
BanMan * m_banman
Definition: net.h:415
Definition: protocol.h:249
bool m_use_addrman_outgoing
Definition: net.h:411
void InterruptMapPort()
Definition: net.cpp:1507
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:2411
std::string GetAddrName() const
Definition: net.cpp:466
std::vector< CSubNet > vWhitelistedRange
Definition: net.h:141
void InactivityCheck(CNode *pnode)
Definition: net.cpp:1051
std::atomic_bool fDisconnect
Definition: net.h:670
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:100
void SetRecvVersion(int nVersionIn)
Definition: net.h:786
std::atomic< int64_t > nPingUsecStart
Definition: net.h:729
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:2650
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:325
NumConnections
Definition: clientmodel.h:36
Definition: net.h:619
std::atomic< ServiceFlags > nServices
Definition: net.h:624
std::atomic< uint64_t > nPingNonceSent
Definition: net.h:727
uint64_t GetOutboundTargetBytesLeft()
Definition: net.cpp:2577
int64_t nTimeOffset
Definition: net.h:547
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
CCriticalSection cs_vRecv
Definition: net.h:632
unsigned int nPrevNodeCount
Definition: net.h:400
CCriticalSection cs_addrLocal
Definition: net.h:763
const uint256 & GetMessageHash() const
Definition: net.cpp:681
void GetNodeStats(std::vector< CNodeStats > &vstats)
Definition: net.cpp:2439
std::atomic< bool > fNetworkActive
Definition: net.h:389
#define LOCK(cs)
Definition: sync.h:182
NumConnections
Definition: net.h:117
int nStartingHeight
Definition: net.h:553
int nMaxOutbound
Definition: net.h:128
void NotifyNumConnectionsChanged()
Definition: net.cpp:1037
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:232
std::atomic_bool m_try_another_outbound_peer
Definition: net.h:438
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:169
virtual void FinalizeNode(NodeId id, bool &update_connection_time)=0
void SetAddrLocal(const CService &addrLocalIn)
May not be called more than once.
Definition: net.cpp:483
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Definition: version.h:15
std::vector< CSubNet > vWhitelistedRange
Definition: net.h:383
unsigned long long uint64_t
Definition: stdint.h:22
Definition: net.h:471
bool fWhitelisted
Definition: net.h:558
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:2496
Definition: net.h:120
int nMaxAddnode
Definition: net.h:129
ListenSocket(SOCKET socket_, bool whitelisted_)
Definition: net.h:320
Definition: protocol.h:28
size_t nProcessQueueSize
Definition: net.h:636
Definition: net.h:527
CAddrMan addrman
Definition: net.h:391
void ForEachNode(Callable &&func) const
Definition: net.h:211
bool fSendMempool GUARDED_BY(cs_inventory)
Definition: net.h:716
bool fInbound
Definition: net.h:551
bool OutboundTargetReached(bool historicalBlockServingLimit)
Definition: net.cpp:2557
CAddress addr
Definition: net.h:566
SOCKET hSocket GUARDED_BY(cs_hSocket)
void PushInventory(const CInv &inv)
Definition: net.h:842
std::thread threadDNSAddressSeed
Definition: net.h:429
uint64_t nSendBytes
Definition: net.h:554
void SetBestHeight(int height)
Definition: net.cpp:2603
size_t nSendSize
Definition: net.h:626
std::vector< std::string > m_specified_outgoing
Definition: net.h:144
Network
Definition: netaddress.h:20
bool fRelayTxes
Definition: net.h:543
void AddAddressKnown(const CAddress &_addr)
Definition: net.h:814
bool fGetAddr
Definition: net.h:697
int64_t NodeId
Definition: net.h:85
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
Definition: net.h:71
int nMaxFeeler
Definition: net.h:130
Definition: streams.h:203
CCriticalSection cs_hSocket
Definition: net.h:631
void SocketHandler()
Definition: net.cpp:1248
Definition: sync.h:248
unsigned int nReceiveFloodSize
Definition: net.h:386
ServiceFlags GetLocalServices() const
Definition: net.h:864
void SetServices(const CService &addr, ServiceFlags nServices)
Definition: net.cpp:2380
std::unique_ptr< BanMan > g_banman
Definition: init.cpp:86
SOCKET socket
Definition: net.h:317
CCriticalSection cs_feeFilter
Definition: net.h:737
void ThreadOpenConnections(std::vector< std::string > connect)
Definition: net.cpp:1657
ServiceFlags nLocalServices
Definition: net.h:126
CNode & operator=(const CNode &)=delete
CDataStream hdrbuf
Definition: net.h:581
void Discover()
Definition: net.cpp:2068
const uint64_t nLocalHostNonce
Definition: net.h:751
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:425
ServiceFlags nLocalServices
Definition: net.h:403
uint64_t nMaxOutboundLimit
Definition: net.h:138
unsigned int SOCKET
Definition: compat.h:48
void Init(const Options &connOptions)
Definition: net.h:148
Definition: net.h:574
CNode * AddRef()
Definition: net.h:801
std::set< uint256 > setKnown
Definition: net.h:698
friend struct CConnmanTest
Definition: net.h:442
CAmount minFeeFilter GUARDED_BY(cs_feeFilter)
Definition: net.h:737
CNetMessage(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:590
Definition: net.h:121
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter)
int flags
Definition: bitcoin-tx.cpp:507
CThreadInterrupt interruptNet
Definition: net.h:427
bool fWhitelisted
Definition: net.h:660
void SetTryNewOutboundPeer(bool flag)
Definition: net.cpp:1631
NetEventsInterface * m_msgproc
Definition: net.h:414
unsigned int nHdrPos
Definition: net.h:583
std::string cleanSubVer GUARDED_BY(cs_SubVer)
Definition: net.h:658
unsigned int nDataPos
Definition: net.h:586
#define NO_THREAD_SAFETY_ANALYSIS
Definition: thread_annotations.h:57
Definition: netaddress.h:102
CCriticalSection cs_inventory
Definition: net.h:711
bool DisconnectNode(const std::string &node)
Definition: net.cpp:2450
CCriticalSection cs_totalBytesSent
Definition: net.h:368
Definition: uint256.h:121
void RemoveLocal(const CService &addr)
Definition: net.cpp:235
std::atomic< int64_t > nLastSend
Definition: net.h:644
uint256 hashContinue
Definition: net.h:691
std::atomic< int64_t > nLastBlockTime
Definition: net.h:722
int nPort
Definition: net.h:529
static const unsigned int MAX_ADDR_TO_SEND
Definition: net.h:53
virtual void InitializeNode(CNode *pnode)=0
int64_t nLastRecv
Definition: net.h:545
void MaybeSetAddrName(const std::string &addrNameIn)
Sets the addrName only if it was not previously set.
Definition: net.cpp:471
Definition: net.h:489
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound=nullptr, const char *strDest=nullptr, bool fOneShot=false, bool fFeeler=false, bool manual_connection=false)
Definition: net.cpp:1906
void WakeMessageHandler()
Definition: net.cpp:1381
std::thread threadOpenConnections
Definition: net.h:432
double dMinPing
Definition: net.h:561
int GetSendVersion() const
Definition: net.cpp:620
int64_t nTimeConnected
Definition: net.h:546
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:83
std::condition_variable condMsgProc
Definition: net.h:423
int nScore
Definition: net.h:528
bool fAddressesInitialized
Definition: net.h:390
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:555
virtual bool SendMessages(CNode *pnode)=0
ServiceFlags nLocalServices
Definition: init.cpp:882
bool operator()(I first, I last) const
Definition: net.h:458
NetEventsInterface * m_msgproc
Definition: net.h:133
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
Definition: net.h:73
int nSendVersion
Definition: net.h:755
int64_t nextSendTimeFeeFilter
Definition: net.h:740
ServiceFlags nServices
Definition: net.h:542
void PushBlockHash(const uint256 &hash)
Definition: net.h:854
uint64_t GetTotalBytesSent()
Definition: net.cpp:2592
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:38
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes
Definition: net.cpp:2513
void AddInventoryKnown(const CInv &inv)
Definition: net.h:834
std::string strAddedNode
Definition: net.h:89
std::atomic< int64_t > nLastTXTime
Definition: net.h:723
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:2692
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:536
void ThreadSocketHandler()
Definition: net.cpp:1371
ServiceFlags GetLocalServices() const
Definition: net.cpp:2598
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:221
std::atomic< bool > fPingQueued
Definition: net.h:735
CCriticalSection cs_filter
Definition: net.h:678
Definition: hash.h:22
Definition: net.h:316
int nVersion
Definition: net.h:549
void ThreadDNSAddressSeed()
Definition: net.cpp:1522
uint64_t GetMaxOutboundTimeLeftInCycle()
Definition: net.cpp:2531
bool GetTryNewOutboundPeer()
Definition: net.cpp:1626
int64_t PoissonNextSend(int64_t now, int average_interval_seconds)
Definition: net.cpp:2716
std::atomic< int64_t > timeLastMempoolReq
Definition: net.h:719
bool fSentAddr
Definition: net.h:676
std::thread threadMessageHandler
Definition: net.h:433
bool Start(CScheduler &scheduler, const Options &options)
Definition: net.cpp:2177
unsigned int nSendBufferMaxSize
Definition: net.h:135
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:281
int64_t nLastSend
Definition: net.h:544
int type
Definition: protocol.h:403
virtual bool ProcessMessages(CNode *pnode, std::atomic< bool > &interrupt)=0
Definition: protocol.h:382
Definition: netaddress.h:140
CMessageHeader hdr
Definition: net.h:582
static const unsigned int MAX_SUBVERSION_LENGTH
Definition: net.h:57
int nMaxConnections
Definition: net.h:127
static const bool DEFAULT_UPNP
Definition: net.h:68
std::vector< std::string > m_added_nodes
Definition: net.h:145
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
Definition: net.h:79
bool IsWhitelistedRange(const CNetAddr &addr)
Definition: net.cpp:458
NodeId nodeid
Definition: net.h:541
static const bool DEFAULT_BLOCKSONLY
Definition: net.h:77
Definition: random.h:98
CSemaphoreGrant grantOutbound
Definition: net.h:677
signed long long int64_t
Definition: stdint.h:18
const NodeId id
Definition: net.h:750
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Definition: net.cpp:2721
static const int PING_INTERVAL
Definition: net.h:43
int64_t nNextInvSend
Definition: net.h:712
void Interrupt()
Definition: net.cpp:2293
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:406
Definition: net.h:119
CCriticalSection cs_sendProcessing
Definition: net.h:638
std::atomic< int64_t > nTimeOffset
Definition: net.h:647
const uint64_t nKeyedNetGroup
Definition: net.h:682
CCriticalSection cs_vNodes
Definition: net.h:398
Definition: net.h:538
std::set< uint256 > setInventoryTxToSend
Definition: net.h:706
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:641
std::string strSubVersion
Definition: net.cpp:86
Definition: addrman.h:175
std::thread threadOpenAddedConnections
Definition: net.h:431
int64_t nTime
Definition: net.h:588
std::atomic< int > nBestHeight
Definition: net.h:412
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:405
bool m_use_addrman_outgoing
Definition: net.h:143
NodeId GetNewNodeId()
Definition: net.cpp:2140
void SetReachable(enum Network net, bool reachable)
Definition: net.cpp:242
void AddOneShot(const std::string &strDest)
Definition: net.cpp:88
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:889
bool m_manual_connection
Definition: net.h:663
bool AttemptToEvictConnection()
Definition: net.cpp:805
CCriticalSection cs_totalBytesRecv
Definition: net.h:367
std::vector< std::string > vSeedNodes
Definition: net.h:140
const int64_t nTimeConnected
Definition: net.h:646
const int nMyStartingHeight
Definition: net.h:754
std::vector< CAddress > GetAddresses()
Definition: net.cpp:2395
bool fDiscover
Definition: net.cpp:80
int GetExtraOutboundCount()
Definition: net.cpp:1643
int readHeader(const char *pch, unsigned int nBytes)
Definition: net.cpp:633
CCriticalSection cs_addrName
Definition: net.h:758
Definition: net.h:492
bool fOneShot
Definition: net.h:662
void ForEachNode(Callable &&func)
Definition: net.h:201
void Stop() NO_THREAD_SAFETY_ANALYSIS
Definition: net.cpp:2317
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing)
Definition: net.h:700
void SetNetworkActive(bool active)
Definition: net.cpp:2119
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:687
size_t nSendOffset
Definition: net.h:627
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:149
static const unsigned int MAX_INV_SZ
Definition: net.h:49
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:204
bool m_limited_node
Definition: net.h:665
CDataStream vRecv
Definition: net.h:585
uint64_t nRecvBytes
Definition: net.h:556
bool IsLocal(const CService &addr)
Definition: net.cpp:275
RecursiveMutex cs_SubVer
Definition: net.h:653
CCriticalSection cs_mapLocalHost
Definition: net.cpp:83
void SetSendVersion(int nVersionIn)
Definition: net.cpp:606
void SocketEvents(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1173
void DisconnectNodes()
Definition: net.cpp:975
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:2490
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target
Definition: net.cpp:2545
std::atomic< int > nVersion
Definition: net.h:652
unsigned short GetListenPort()
Definition: net.cpp:94
int nBestHeight
Definition: net.h:131
bool complete() const
Definition: net.h:598
bool AddNode(const std::string &node)
Definition: net.cpp:2400
size_t SocketSendData(CNode *pnode) const
Definition: net.cpp:689
Definition: net.h:493
bool GenerateSelectSet(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1084
std::list< CNetMessage > vRecvMsg
Definition: net.h:756
Definition: ui_interface.h:34
CAmount minFeeFilter
Definition: net.h:562
CCriticalSection cs_vProcessMsg
Definition: net.h:634