BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
net.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 <hash.h>
15 #include <limitedmap.h>
16 #include <netaddress.h>
17 #include <policy/feerate.h>
18 #include <protocol.h>
19 #include <random.h>
20 #include <streams.h>
21 #include <sync.h>
22 #include <uint256.h>
23 #include <threadinterrupt.h>
24 
25 #include <atomic>
26 #include <deque>
27 #include <stdint.h>
28 #include <thread>
29 #include <memory>
30 #include <condition_variable>
31 
32 #ifndef WIN32
33 #include <arpa/inet.h>
34 #endif
35 
36 
37 class CScheduler;
38 class CNode;
39 
41 static const int PING_INTERVAL = 2 * 60;
43 static const int TIMEOUT_INTERVAL = 20 * 60;
45 static const int FEELER_INTERVAL = 120;
47 static const unsigned int MAX_INV_SZ = 50000;
49 static const unsigned int MAX_LOCATOR_SZ = 101;
51 static const unsigned int MAX_ADDR_TO_SEND = 1000;
53 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
55 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
57 static const int MAX_OUTBOUND_CONNECTIONS = 8;
59 static const int MAX_ADDNODE_CONNECTIONS = 8;
61 static const bool DEFAULT_LISTEN = true;
63 #ifdef USE_UPNP
64 static const bool DEFAULT_UPNP = USE_UPNP;
65 #else
66 static const bool DEFAULT_UPNP = false;
67 #endif
68 
69 static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
71 static const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ;
73 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
75 static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
77 static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
79 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 // NOTE: When adjusting this, update rpcnet:setban's help ("24h")
86 static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban
87 
88 typedef int64_t NodeId;
89 
91 {
92  std::string strAddedNode;
94  bool fConnected;
95  bool fInbound;
96 };
97 
98 class CNodeStats;
99 class CClientUIInterface;
100 
102 {
103  CSerializedNetMsg() = default;
106  // No copying, only moves.
107  CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
109 
110  std::vector<unsigned char> data;
111  std::string command;
112 };
113 
114 class NetEventsInterface;
115 class CConnman
116 {
117 public:
118 
121  CONNECTIONS_IN = (1U << 0),
122  CONNECTIONS_OUT = (1U << 1),
124  };
125 
126  struct Options
127  {
130  int nMaxOutbound = 0;
131  int nMaxAddnode = 0;
132  int nMaxFeeler = 0;
133  int nBestHeight = 0;
136  unsigned int nSendBufferMaxSize = 0;
137  unsigned int nReceiveFloodSize = 0;
138  uint64_t nMaxOutboundTimeframe = 0;
139  uint64_t nMaxOutboundLimit = 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_msgproc = connOptions.m_msgproc;
159  nReceiveFloodSize = connOptions.nReceiveFloodSize;
160  {
162  nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
163  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
164  }
165  vWhitelistedRange = connOptions.vWhitelistedRange;
166  {
168  vAddedNodes = connOptions.m_added_nodes;
169  }
170  }
171 
172  CConnman(uint64_t seed0, uint64_t seed1);
173  ~CConnman();
174  bool Start(CScheduler& scheduler, const Options& options);
175  void Stop();
176  void Interrupt();
177  bool GetNetworkActive() const { return fNetworkActive; };
179  void SetNetworkActive(bool active);
180  void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool fOneShot = false, bool fFeeler = false, bool manual_connection = false);
181  bool CheckIncomingNonce(uint64_t nonce);
182 
183  bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
184 
185  void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
186 
187  template<typename Callable>
188  void ForEachNode(Callable&& func)
189  {
190  LOCK(cs_vNodes);
191  for (auto&& node : vNodes) {
192  if (NodeFullyConnected(node))
193  func(node);
194  }
195  };
196 
197  template<typename Callable>
198  void ForEachNode(Callable&& func) const
199  {
200  LOCK(cs_vNodes);
201  for (auto&& node : vNodes) {
202  if (NodeFullyConnected(node))
203  func(node);
204  }
205  };
206 
207  template<typename Callable, typename CallableAfter>
208  void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
209  {
210  LOCK(cs_vNodes);
211  for (auto&& node : vNodes) {
212  if (NodeFullyConnected(node))
213  pre(node);
214  }
215  post();
216  };
217 
218  template<typename Callable, typename CallableAfter>
219  void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
220  {
221  LOCK(cs_vNodes);
222  for (auto&& node : vNodes) {
223  if (NodeFullyConnected(node))
224  pre(node);
225  }
226  post();
227  };
228 
229  // Addrman functions
230  size_t GetAddressCount() const;
231  void SetServices(const CService &addr, ServiceFlags nServices);
232  void MarkAddressGood(const CAddress& addr);
233  void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
234  std::vector<CAddress> GetAddresses();
235 
236  // Denial-of-service detection/prevention
237  // The idea is to detect peers that are behaving
238  // badly and disconnect/ban them, but do it in a
239  // one-coding-mistake-won't-shatter-the-entire-network
240  // way.
241  // IMPORTANT: There should be nothing I can give a
242  // node that it will forward on that will make that
243  // node's peers drop it. If there is, an attacker
244  // can isolate a node and/or try to split the network.
245  // Dropping a node for sending stuff that is invalid
246  // now but might be valid in a later version is also
247  // dangerous, because it can cause a network split
248  // between nodes running old code and nodes running
249  // new code.
250  void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
251  void Ban(const CSubNet& subNet, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
252  void ClearBanned(); // needed for unit testing
253  bool IsBanned(CNetAddr ip);
254  bool IsBanned(CSubNet subnet);
255  bool Unban(const CNetAddr &ip);
256  bool Unban(const CSubNet &ip);
257  void GetBanned(banmap_t &banmap);
258  void SetBanned(const banmap_t &banmap);
259 
260  // This allows temporarily exceeding nMaxOutbound, with the goal of finding
261  // a peer that is better than all our current peers.
262  void SetTryNewOutboundPeer(bool flag);
263  bool GetTryNewOutboundPeer();
264 
265  // Return the number of outbound peers we have in excess of our target (eg,
266  // if we previously called SetTryNewOutboundPeer(true), and have since set
267  // to false, we may have extra peers that we wish to disconnect). This may
268  // return a value less than (num_outbound_connections - num_outbound_slots)
269  // in cases where some outbound connections are not yet fully connected, or
270  // not yet fully disconnected.
271  int GetExtraOutboundCount();
272 
273  bool AddNode(const std::string& node);
274  bool RemoveAddedNode(const std::string& node);
275  std::vector<AddedNodeInfo> GetAddedNodeInfo();
276 
277  size_t GetNodeCount(NumConnections num);
278  void GetNodeStats(std::vector<CNodeStats>& vstats);
279  bool DisconnectNode(const std::string& node);
280  bool DisconnectNode(NodeId id);
281 
283 
285  void SetMaxOutboundTarget(uint64_t limit);
286  uint64_t GetMaxOutboundTarget();
287 
289  void SetMaxOutboundTimeframe(uint64_t timeframe);
290  uint64_t GetMaxOutboundTimeframe();
291 
293  // if param historicalBlockServingLimit is set true, the function will
294  // response true if the limit for serving historical blocks has been reached
295  bool OutboundTargetReached(bool historicalBlockServingLimit);
296 
298  // in case of no limit, it will always response 0
299  uint64_t GetOutboundTargetBytesLeft();
300 
302  // in case of no limit, it will always response 0
304 
305  uint64_t GetTotalBytesRecv();
306  uint64_t GetTotalBytesSent();
307 
308  void SetBestHeight(int height);
309  int GetBestHeight() const;
310 
312  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
313 
314  unsigned int GetReceiveFloodSize() const;
315 
316  void WakeMessageHandler();
317 
322  int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
323 
324 private:
325  struct ListenSocket {
328 
329  ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
330  };
331 
332  bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
333  bool Bind(const CService &addr, unsigned int flags);
334  bool InitBinds(const std::vector<CService>& binds, const std::vector<CService>& whiteBinds);
336  void AddOneShot(const std::string& strDest);
337  void ProcessOneShot();
338  void ThreadOpenConnections(std::vector<std::string> connect);
339  void ThreadMessageHandler();
340  void AcceptConnection(const ListenSocket& hListenSocket);
341  void DisconnectNodes();
343  void InactivityCheck(CNode *pnode);
344  void SocketHandler();
345  void ThreadSocketHandler();
346  void ThreadDNSAddressSeed();
347 
348  uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
349 
350  CNode* FindNode(const CNetAddr& ip);
351  CNode* FindNode(const CSubNet& subNet);
352  CNode* FindNode(const std::string& addrName);
353  CNode* FindNode(const CService& addr);
354 
356  CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection);
357  bool IsWhitelistedRange(const CNetAddr &addr);
358 
359  void DeleteNode(CNode* pnode);
360 
362 
363  size_t SocketSendData(CNode *pnode) const;
365  bool BannedSetIsDirty();
367  void SetBannedSetDirty(bool dirty=true);
369  void SweepBanned();
370  void DumpAddresses();
371  void DumpData();
372  void DumpBanlist();
373 
374  // Network stats
375  void RecordBytesRecv(uint64_t bytes);
376  void RecordBytesSent(uint64_t bytes);
377 
378  // Whether the node should be passed out in ForEach* callbacks
379  static bool NodeFullyConnected(const CNode* pnode);
380 
381  // Network usage totals
384  uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv);
385  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent);
386 
387  // outbound limit & stats
388  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
389  uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
390  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
391  uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
392 
393  // Whitelisted ranges. Any node connecting from these is automatically
394  // whitelisted (as well as those connecting to whitelisted binds).
395  std::vector<CSubNet> vWhitelistedRange;
396 
397  unsigned int nSendBufferMaxSize;
398  unsigned int nReceiveFloodSize;
399 
400  std::vector<ListenSocket> vhListenSocket;
401  std::atomic<bool> fNetworkActive;
407  std::deque<std::string> vOneShots;
409  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
411  std::vector<CNode*> vNodes;
412  std::list<CNode*> vNodesDisconnected;
414  std::atomic<NodeId> nLastNodeId;
415  unsigned int nPrevNodeCount;
416 
419 
420  std::unique_ptr<CSemaphore> semOutbound;
421  std::unique_ptr<CSemaphore> semAddnode;
427  std::atomic<int> nBestHeight;
430 
432  const uint64_t nSeed0, nSeed1;
433 
436 
437  std::condition_variable condMsgProc;
439  std::atomic<bool> flagInterruptMsgProc;
440 
442 
443  std::thread threadDNSAddressSeed;
444  std::thread threadSocketHandler;
447  std::thread threadMessageHandler;
448 
452  std::atomic_bool m_try_another_outbound_peer;
453 
454  std::atomic<int64_t> m_next_send_inv_to_incoming{0};
455 
456  friend struct CConnmanTest;
457 };
458 extern std::unique_ptr<CConnman> g_connman;
459 void Discover();
460 void StartMapPort();
461 void InterruptMapPort();
462 void StopMapPort();
463 unsigned short GetListenPort();
464 bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
465 
467 {
468  typedef bool result_type;
469 
470  template<typename I>
471  bool operator()(I first, I last) const
472  {
473  while (first != last) {
474  if (!(*first)) return false;
475  ++first;
476  }
477  return true;
478  }
479 };
480 
485 {
486 public:
487  virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
488  virtual bool SendMessages(CNode* pnode) = 0;
489  virtual void InitializeNode(CNode* pnode) = 0;
490  virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
491 
492 protected:
497  ~NetEventsInterface() = default;
498 };
499 
500 enum
501 {
502  LOCAL_NONE, // unknown
503  LOCAL_IF, // address a local interface listens on
504  LOCAL_BIND, // address explicit bound to
505  LOCAL_UPNP, // address reported by UPnP
506  LOCAL_MANUAL, // address explicitly specified (-externalip=)
507 
509 };
510 
511 bool IsPeerAddrLocalGood(CNode *pnode);
512 void AdvertiseLocal(CNode *pnode);
513 void SetLimited(enum Network net, bool fLimited = true);
514 bool IsLimited(enum Network net);
515 bool IsLimited(const CNetAddr& addr);
516 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
517 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
518 void RemoveLocal(const CService& addr);
519 bool SeenLocal(const CService& addr);
520 bool IsLocal(const CService& addr);
521 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
522 bool IsReachable(enum Network net);
523 bool IsReachable(const CNetAddr &addr);
524 CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
525 
526 
527 extern bool fDiscover;
528 extern bool fListen;
529 extern bool fRelayTxes;
530 
532 
534 extern std::string strSubVersion;
535 
537  int nScore;
538  int nPort;
539 };
540 
542 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
543 typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
544 
546 {
547 public:
551  int64_t nLastSend;
552  int64_t nLastRecv;
553  int64_t nTimeConnected;
554  int64_t nTimeOffset;
555  std::string addrName;
556  int nVersion;
557  std::string cleanSubVer;
558  bool fInbound;
561  uint64_t nSendBytes;
563  uint64_t nRecvBytes;
566  double dPingTime;
567  double dPingWait;
568  double dMinPing;
570  // Our address, as reported by the peer
571  std::string addrLocal;
572  // Address of this peer
574  // Bind address of our side of the connection
576 };
577 
578 
579 
580 
581 class CNetMessage {
582 private:
583  mutable CHash3 hasher;
585 public:
586  bool in_data; // parsing header (false) or data (true)
587 
588  CDataStream hdrbuf; // partially received header
589  CMessageHeader hdr; // complete header
590  unsigned int nHdrPos;
591 
592  CDataStream vRecv; // received message data
593  unsigned int nDataPos;
594 
595  int64_t nTime; // time (in microseconds) of message receipt.
596 
597  CNetMessage(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
598  hdrbuf.resize(24);
599  in_data = false;
600  nHdrPos = 0;
601  nDataPos = 0;
602  nTime = 0;
603  }
604 
605  bool complete() const
606  {
607  if (!in_data)
608  return false;
609  return (hdr.nMessageSize == nDataPos);
610  }
611 
612  const uint256& GetMessageHash() const;
613 
614  void SetVersion(int nVersionIn)
615  {
616  hdrbuf.SetVersion(nVersionIn);
617  vRecv.SetVersion(nVersionIn);
618  }
619 
620  int readHeader(const char *pch, unsigned int nBytes);
621  int readData(const char *pch, unsigned int nBytes);
622 };
623 
624 
626 class CNode
627 {
628  friend class CConnman;
629 public:
630  // socket
631  std::atomic<ServiceFlags> nServices;
633  size_t nSendSize; // total size of all vSendMsg entries
634  size_t nSendOffset; // offset inside the first vSendMsg already sent
635  uint64_t nSendBytes;
636  std::deque<std::vector<unsigned char>> vSendMsg;
640 
642  std::list<CNetMessage> vProcessMsg;
644 
646 
647  std::deque<CInv> vRecvGetData;
648  uint64_t nRecvBytes;
649  std::atomic<int> nRecvVersion;
650 
651  std::atomic<int64_t> nLastSend;
652  std::atomic<int64_t> nLastRecv;
653  const int64_t nTimeConnected;
654  std::atomic<int64_t> nTimeOffset;
655  // Address of this peer
656  const CAddress addr;
657  // Bind address of our side of the connection
659  std::atomic<int> nVersion;
660  // strSubVer is whatever byte array we read from the wire. However, this field is intended
661  // to be printed out, displayed to humans in various forms and so on. So we sanitize it and
662  // store the sanitized version in cleanSubVer. The original should be used when dealing with
663  // the network or wire types and the cleaned string used when displayed or logged.
664  std::string strSubVer, cleanSubVer;
665  CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer
666  bool fWhitelisted; // This peer can bypass DoS banning.
667  bool fFeeler; // If true this node is being used as a short lived feeler.
668  bool fOneShot;
670  bool fClient;
671  bool m_limited_node; //after BIP159
672  const bool fInbound;
673  std::atomic_bool fSuccessfullyConnected;
674  std::atomic_bool fDisconnect;
675  // We use fRelayTxes for two purposes -
676  // a) it allows us to not relay tx invs before receiving the peer's version message
677  // b) the peer may tell us in its version message that we should not relay tx invs
678  // unless it loads a bloom filter.
679  bool fRelayTxes; //protected by cs_filter
680  bool fSentAddr;
683  std::unique_ptr<CBloomFilter> pfilter;
684  std::atomic<int> nRefCount;
685 
686  const uint64_t nKeyedNetGroup;
687  std::atomic_bool fPauseRecv;
688  std::atomic_bool fPauseSend;
689 protected:
690 
693 
694 public:
696  std::atomic<int> nStartingHeight;
697 
698  // flood relay
699  std::vector<CAddress> vAddrToSend;
701  bool fGetAddr;
702  std::set<uint256> setKnown;
703  int64_t nNextAddrSend;
705 
706  // inventory based relay
708  // Set of transaction ids we still have to announce.
709  // They are sorted by the mempool before relay, so the order is not important.
710  std::set<uint256> setInventoryTxToSend;
711  // List of block ids we still have announce.
712  // There is no final sorting before sending, as they are always sent immediately
713  // and in the order requested.
714  std::vector<uint256> vInventoryBlockToSend;
716  std::set<uint256> setAskFor;
717  std::multimap<int64_t, CInv> mapAskFor;
718  int64_t nNextInvSend;
719  // Used for headers announcements - unfiltered blocks to relay
720  // Also protected by cs_inventory
721  std::vector<uint256> vBlockHashesToAnnounce;
722  // Used for BIP35 mempool sending, also protected by cs_inventory
724 
725  // Last time a "MEMPOOL" request was serviced.
726  std::atomic<int64_t> timeLastMempoolReq;
727 
728  // Block and TXN accept times
729  std::atomic<int64_t> nLastBlockTime;
730  std::atomic<int64_t> nLastTXTime;
731 
732  // Ping time measurement:
733  // The pong reply we're expecting, or 0 if no pong expected.
734  std::atomic<uint64_t> nPingNonceSent;
735  // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
736  std::atomic<int64_t> nPingUsecStart;
737  // Last measured round-trip time.
738  std::atomic<int64_t> nPingUsecTime;
739  // Best measured round-trip time.
740  std::atomic<int64_t> nMinPingUsecTime;
741  // Whether a ping is requested.
742  std::atomic<bool> fPingQueued;
743  // Minimum fee rate with which to filter inv's to this node
748 
749  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);
750  ~CNode();
751  CNode(const CNode&) = delete;
752  CNode& operator=(const CNode&) = delete;
753 
754 private:
755  const NodeId id;
756  const uint64_t nLocalHostNonce;
757  // Services offered to this peer
759  const int nMyStartingHeight;
761  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
762 
764  std::string addrName;
765 
766  // Our address, as reported by the peer
769 public:
770 
771  NodeId GetId() const {
772  return id;
773  }
774 
775  uint64_t GetLocalNonce() const {
776  return nLocalHostNonce;
777  }
778 
779  int GetMyStartingHeight() const {
780  return nMyStartingHeight;
781  }
782 
783  int GetRefCount() const
784  {
785  assert(nRefCount >= 0);
786  return nRefCount;
787  }
788 
789  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
790 
791  void SetRecvVersion(int nVersionIn)
792  {
793  nRecvVersion = nVersionIn;
794  }
795  int GetRecvVersion() const
796  {
797  return nRecvVersion;
798  }
799  void SetSendVersion(int nVersionIn);
800  int GetSendVersion() const;
801 
802  CService GetAddrLocal() const;
804  void SetAddrLocal(const CService& addrLocalIn);
805 
807  {
808  nRefCount++;
809  return this;
810  }
811 
812  void Release()
813  {
814  nRefCount--;
815  }
816 
817 
818 
819  void AddAddressKnown(const CAddress& _addr)
820  {
821  addrKnown.insert(_addr.GetKey());
822  }
823 
824  void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
825  {
826  // Known checking here is only to save space from duplicates.
827  // SendMessages will filter it again for knowns that were added
828  // after addresses were pushed.
829  if (_addr.IsValid() && !addrKnown.contains(_addr.GetKey())) {
830  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
831  vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
832  } else {
833  vAddrToSend.push_back(_addr);
834  }
835  }
836  }
837 
838 
839  void AddInventoryKnown(const CInv& inv)
840  {
841  {
844  }
845  }
846 
847  void PushInventory(const CInv& inv)
848  {
850  if (inv.type == MSG_TX) {
851  if (!filterInventoryKnown.contains(inv.hash)) {
852  setInventoryTxToSend.insert(inv.hash);
853  }
854  } else if (inv.type == MSG_BLOCK) {
855  vInventoryBlockToSend.push_back(inv.hash);
856  }
857  }
858 
859  void PushBlockHash(const uint256 &hash)
860  {
862  vBlockHashesToAnnounce.push_back(hash);
863  }
864 
865  void AskFor(const CInv& inv);
866 
867  void CloseSocketDisconnect();
868 
869  void copyStats(CNodeStats &stats);
870 
872  {
873  return nLocalServices;
874  }
875 
876  std::string GetAddrName() const;
878  void MaybeSetAddrName(const std::string& addrNameIn);
879 };
880 
881 
882 
883 
884 
886 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
887 
888 #endif // BITCOIN_NET_H
std::vector< CService > vBinds
Definition: net.h:142
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:439
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:2910
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:74
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:2722
int nMaxFeeler
Definition: net.h:425
bool BannedSetIsDirty()
check is the banlist has unwritten changes
Definition: net.cpp:637
std::vector< CSubNet > vWhitelistedRange
Definition: net.h:141
std::atomic< uint64_t > nPingNonceSent
Definition: net.h:734
uint256 data_hash
Definition: net.h:584
void SocketHandler()
Definition: net.cpp:1267
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
Definition: net.cpp:288
CCriticalSection cs_addrName
Definition: net.h:763
int nStartingHeight
Definition: net.h:560
std::atomic_bool fPauseSend
Definition: net.h:688
void ThreadOpenAddedConnections()
Definition: net.cpp:1974
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
Definition: net.cpp:643
int64_t nextSendTimeFeeFilter
Definition: net.h:747
int GetSendVersion() const
Definition: net.cpp:810
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:564
void SetBanned(const banmap_t &banmap)
Definition: net.cpp:602
std::atomic< bool > fNetworkActive
Definition: net.h:401
bool fMsgProcWake
flag for waking the message processor.
Definition: net.h:435
ServiceFlags
nServices flags
Definition: protocol.h:247
CCriticalSection cs_filter
Definition: net.h:682
BanReason
Definition: addrdb.h:19
int64_t nTimeOffset
Definition: net.h:554
std::string addrName
Definition: net.h:764
bool fListen
Definition: net.cpp:84
CConnman(uint64_t seed0, uint64_t seed1)
Definition: net.cpp:2228
STL-like map container that only keeps the N elements with the highest value.
Definition: limitedmap.h:13
size_t GetAddressCount() const
Definition: net.cpp:2501
std::atomic< int > nBestHeight
Definition: net.h:427
void WakeMessageHandler()
Definition: net.cpp:1477
void SetServices(const CService &addr, ServiceFlags nServices)
Definition: net.cpp:2506
void Interrupt()
Definition: net.cpp:2419
std::list< CNetMessage > vProcessMsg
Definition: net.h:642
Mutex mutexMsgProc
Definition: net.h:438
const uint64_t nKeyedNetGroup
Definition: net.h:686
void SweepBanned()
clean unused entries (if bantime has expired)
Definition: net.cpp:609
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:268
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool &complete)
Definition: net.cpp:744
CNode & operator=(const CNode &)=delete
int GetRecvVersion() const
Definition: net.h:795
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:691
void insert(const std::vector< unsigned char > &vKey)
Definition: bloom.cpp:245
void StartMapPort()
Definition: net.cpp:1599
void StopMapPort()
Definition: net.cpp:1607
std::vector< unsigned char > data
Definition: net.h:110
CHash3 hasher
Definition: net.h:583
inv message data
Definition: protocol.h:385
bool fRelayTxes
Definition: net.cpp:85
#define USE_UPNP
unsigned int nReceiveFloodSize
Definition: net.h:137
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:562
CClientUIInterface * uiInterface
Definition: net.h:134
void resize(size_type n, value_type c=0)
Definition: streams.h:314
std::vector< uint256 > vInventoryBlockToSend
Definition: net.h:714
CCriticalSection cs_hSocket
Definition: net.h:638
void AskFor(const CInv &inv)
Definition: net.cpp:2800
uint64_t randrange(uint64_t range)
Generate a random integer in the range [0..range).
Definition: random.h:104
ServiceFlags nServices
Definition: net.h:549
bool fSendMempool
Definition: net.h:723
CCriticalSection cs_SubVer
Definition: net.h:665
bool GetTryNewOutboundPeer()
Definition: net.cpp:1728
std::atomic< int64_t > m_next_send_inv_to_incoming
Definition: net.h:454
CCriticalSection cs_addrLocal
Definition: net.h:768
unsigned int nHdrPos
Definition: net.h:590
int nMaxAddnode
Definition: net.h:424
RAII-style semaphore lock.
Definition: sync.h:237
friend struct CConnmanTest
Definition: net.h:456
bool Unban(const CNetAddr &ip)
Definition: net.cpp:576
uint64_t GetMaxOutboundTarget()
Definition: net.cpp:2626
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:2839
std::unique_ptr< CBloomFilter > pfilter
Definition: net.h:683
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target
Definition: net.cpp:2652
std::string cleanSubVer
Definition: net.h:557
Interface for message handling.
Definition: net.h:484
void SetVersion(int nVersionIn)
Definition: net.h:614
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:115
void GetBanned(banmap_t &banmap)
Definition: net.cpp:594
NetEventsInterface * m_msgproc
Definition: net.h:429
std::atomic< int64_t > nPingUsecStart
Definition: net.h:736
CAmount minFeeFilter
Definition: net.h:569
void ClearBanned()
Definition: net.cpp:499
CCriticalSection cs_vNodes
Definition: net.h:413
int nMaxConnections
Definition: net.h:129
CSerializedNetMsg()=default
int64_t nTimeConnected
Definition: net.h:553
CCriticalSection cs_feeFilter
Definition: net.h:745
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:2002
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:182
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:221
CCriticalSection cs_vAddedNodes
Definition: net.h:410
void SetTryNewOutboundPeer(bool flag)
Definition: net.cpp:1733
uint32_t nMessageSize
Definition: protocol.h:59
ListenSocket(SOCKET socket_, bool whitelisted_)
Definition: net.h:329
CCriticalSection cs_inventory
Definition: net.h:715
uint64_t GetLocalNonce() const
Definition: net.h:775
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
Definition: net.cpp:87
CDataStream hdrbuf
Definition: net.h:588
std::set< uint256 > setInventoryTxToSend
Definition: net.h:710
void ThreadSocketHandler()
Definition: net.cpp:1467
std::vector< CAddress > vAddrToSend
Definition: net.h:699
std::vector< CService > vWhiteBinds
Definition: net.h:142
virtual bool SendMessages(CNode *pnode)=0
size_t GetNodeCount(NumConnections num)
Definition: net.cpp:2549
std::atomic< int > nStartingHeight
Definition: net.h:696
std::string cleanSubVer
Definition: net.h:664
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:824
void SetRecvVersion(int nVersionIn)
Definition: net.h:791
bool in_data
Definition: net.h:586
std::atomic< int64_t > timeLastMempoolReq
Definition: net.h:726
CAmount minFeeFilter
Definition: net.h:744
void AddOneShot(const std::string &strDest)
Definition: net.cpp:93
Signals for UI communication.
Definition: ui_interface.h:31
std::list< CNetMessage > vRecvMsg
Definition: net.h:761
CNetMessage(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:597
void NotifyNumConnectionsChanged()
Definition: net.cpp:1220
void PushInventory(const CInv &inv)
Definition: net.h:847
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes
Definition: net.cpp:2620
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:2603
CAddrMan addrman
Definition: net.h:406
std::atomic< ServiceFlags > nServices
Definition: net.h:631
void SetAddrLocal(const CService &addrLocalIn)
May not be called more than once.
Definition: net.cpp:675
int nSendVersion
Definition: net.h:760
int64_t nNextLocalAddrSend
Definition: net.h:704
std::deque< CInv > vRecvGetData
Definition: net.h:647
uint64_t GetMaxOutboundTimeframe()
Definition: net.cpp:2632
bool fConnected
Definition: net.h:94
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:2876
int GetRefCount() const
Definition: net.h:783
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:418
CDataStream vRecv
Definition: net.h:592
bool contains(const std::vector< unsigned char > &vKey) const
Definition: bloom.cpp:282
bool IsWhitelistedRange(const CNetAddr &addr)
Definition: net.cpp:650
bool IsValid() const
Definition: netaddress.cpp:188
bool DisconnectNode(const std::string &node)
Definition: net.cpp:2576
std::set< uint256 > setKnown
Definition: net.h:702
bool operator()(I first, I last) const
Definition: net.h:471
bool m_manual_connection
Definition: net.h:559
Stochastical (IP) address manager.
Definition: addrman.h:188
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
std::atomic< int64_t > nLastSend
Definition: net.h:651
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:2597
void DumpAddresses()
Definition: net.cpp:1694
bool fSentAddr
Definition: net.h:680
std::atomic< int64_t > nPingUsecTime
Definition: net.h:738
std::atomic< int64_t > nMinPingUsecTime
Definition: net.h:740
int GetMyStartingHeight() const
Definition: net.h:779
void Ban(const CNetAddr &netAddr, const BanReason &reason, int64_t bantimeoffset=0, bool sinceUnixEpoch=false)
Definition: net.cpp:539
ServiceFlags GetLocalServices() const
Definition: net.h:871
int nVersion
Definition: net.h:556
std::map< CSubNet, CBanEntry > banmap_t
Definition: addrdb.h:77
bool fClient
Definition: net.h:670
std::string strSubVer
Definition: net.h:664
void CloseSocketDisconnect()
Definition: net.cpp:488
void InterruptMapPort()
Definition: net.cpp:1603
uint64_t GetOutboundTargetBytesLeft()
response the bytes left in the current max outbound cycle
Definition: net.cpp:2684
void Release()
Definition: net.h:812
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:105
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:2834
unsigned int nPrevNodeCount
Definition: net.h:415
Definition: net.h:508
bool AddNode(const std::string &node)
Definition: net.cpp:2526
size_t nProcessQueueSize
Definition: net.h:643
std::condition_variable condMsgProc
Definition: net.h:437
bool result_type
Definition: net.h:468
CService GetAddrLocal() const
Definition: net.cpp:670
uint64_t GetMaxOutboundTimeLeftInCycle()
response the time in second left in the current max outbound cycle
Definition: net.cpp:2638
NumConnections
Definition: clientmodel.h:36
void InactivityCheck(CNode *pnode)
Definition: net.cpp:1234
std::atomic< int64_t > nLastRecv
Definition: net.h:652
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:432
bool fOneShot
Definition: net.h:668
bool InitBinds(const std::vector< CService > &binds, const std::vector< CService > &whiteBinds)
Definition: net.cpp:2263
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
std::thread threadOpenAddedConnections
Definition: net.h:445
#define LOCK(cs)
Definition: sync.h:181
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:302
std::vector< CNode * > vNodes
Definition: net.h:411
ServiceFlags GetLocalServices() const
Definition: net.cpp:2705
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:174
std::deque< std::string > vOneShots
Definition: net.h:407
NetEventsInterface * m_msgproc
Definition: net.h:135
int type
Definition: protocol.h:407
std::string strAddedNode
Definition: net.h:92
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:142
Fast randomness source.
Definition: random.h:45
const CAddress addrBind
Definition: net.h:658
std::vector< std::string > vSeedNodes
Definition: net.h:140
int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds)
Attempts to obfuscate tx time through exponentially distributed emitting.
Definition: net.cpp:2889
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached
Definition: net.cpp:2664
std::vector< std::string > m_specified_outgoing
Definition: net.h:144
void DumpData()
Definition: net.cpp:1705
std::vector< CAddress > GetAddresses()
Definition: net.cpp:2521
CRollingBloomFilter filterInventoryKnown
Definition: net.h:707
void DisconnectNodes()
Definition: net.cpp:1158
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:420
void ThreadOpenConnections(std::vector< std::string > connect)
Definition: net.cpp:1759
std::thread threadMessageHandler
Definition: net.h:447
CMessageHeader hdr
Definition: net.h:589
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:208
bool m_manual_connection
Definition: net.h:669
bool fInbound
Definition: net.h:558
void ProcessOneShot()
Definition: net.cpp:1711
~NetEventsInterface()=default
Protected destructor so that instances can only be deleted by derived classes.
uint64_t nSendBytes
Definition: net.h:635
A CService with information about it as peer.
Definition: protocol.h:328
bool Start(CScheduler &scheduler, const Options &options)
Definition: net.cpp:2281
uint64_t nRecvBytes
Definition: net.h:563
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:550
void MaybeSetAddrName(const std::string &addrNameIn)
Sets the addrName only if it was not previously set.
Definition: net.cpp:663
uint256 hash
Definition: protocol.h:408
uint64_t GetTotalBytesRecv()
Definition: net.cpp:2693
bool fInbound
Definition: net.h:95
double dPingTime
Definition: net.h:566
std::string addrName
Definition: net.h:555
int nMaxFeeler
Definition: net.h:132
Network
Definition: netaddress.h:20
std::vector< uint256 > vBlockHashesToAnnounce
Definition: net.h:721
std::atomic_bool m_try_another_outbound_peer
flag for deciding to connect to an extra outbound peer, in excess of nMaxOutbound This takes the plac...
Definition: net.h:452
int64_t NodeId
Definition: net.h:88
virtual void FinalizeNode(NodeId id, bool &update_connection_time)=0
Definition: net.h:115
void SetNetworkActive(bool active)
Definition: net.cpp:2215
void AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:2516
bool GetNetworkActive() const
Definition: net.h:177
NumConnections
Definition: net.h:119
bool fGetAddr
Definition: net.h:701
CClientUIInterface * clientInterface
Definition: net.h:428
uint64_t nRecvBytes
Definition: net.h:648
NodeId GetId() const
Definition: net.h:771
void GetNodeStats(std::vector< CNodeStats > &vstats)
Definition: net.cpp:2565
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
Definition: net.cpp:2905
uint64_t nSendBytes
Definition: net.h:561
int nMaxOutbound
Definition: net.h:130
size_t nSendOffset
Definition: net.h:634
std::atomic_bool fDisconnect
Definition: net.h:674
int nMaxConnections
Definition: net.h:422
void SetLimited(enum Network net, bool fLimited=true)
Make a particular network entirely off-limits (no automatic connects to it)
Definition: net.cpp:248
size_t nSendSize
Definition: net.h:633
void ForEachNode(Callable &&func)
Definition: net.h:188
limitedmap< uint256, int64_t > mapAlreadyAskedFor
CCriticalSection cs_vOneShots
Definition: net.h:408
CRollingBloomFilter addrKnown
Definition: net.h:700
bool IsBanned(CNetAddr ip)
Definition: net.cpp:511
void DumpBanlist()
Definition: net.cpp:468
void Discover()
Definition: net.cpp:2164
CCriticalSection cs_setBanned
Definition: net.h:403
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:2720
int readData(const char *pch, unsigned int nBytes)
Definition: net.cpp:854
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:38
~CNode()
Definition: net.cpp:2795
void DeleteNode(CNode *pnode)
Definition: net.cpp:2484
unsigned int SOCKET
Definition: compat.h:62
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:346
const CAddress addr
Definition: net.h:656
std::atomic< int > nRefCount
Definition: net.h:684
const int64_t nTimeConnected
Definition: net.h:653
int64_t nTime
Definition: net.h:595
uint64_t nMaxOutboundTimeframe
Definition: net.h:138
std::atomic< NodeId > nLastNodeId
Definition: net.h:414
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:2537
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netaddress.h:32
CCriticalSection cs_vRecv
Definition: net.h:639
std::list< CNode * > vNodesDisconnected
Definition: net.h:412
CService addrLocal
Definition: net.h:767
std::atomic< bool > fPingQueued
Definition: net.h:742
256-bit opaque blob.
Definition: uint256.h:122
void RemoveLocal(const CService &addr)
Definition: net.cpp:240
int GetBestHeight() const
Definition: net.cpp:2715
void AddInventoryKnown(const CInv &inv)
Definition: net.h:839
int nScore
Definition: net.h:537
bool Bind(const CService &addr, unsigned int flags)
Definition: net.cpp:2250
int nMaxAddnode
Definition: net.h:131
bool fFeeler
Definition: net.h:667
void ForEachNode(Callable &&func) const
Definition: net.h:198
std::atomic< int64_t > nLastTXTime
Definition: net.h:730
bool complete() const
Definition: net.h:605
CAddress addrBind
Definition: net.h:575
const bool fInbound
Definition: net.h:672
std::vector< CSubNet > vWhitelistedRange
Definition: net.h:395
~CConnman()
Definition: net.cpp:2495
CService resolvedAddress
Definition: net.h:93
std::thread threadOpenConnections
Definition: net.h:446
bool AttemptToEvictConnection()
Try to find a connection to evict when the node is full.
Definition: net.cpp:1003
CSemaphoreGrant grantOutbound
Definition: net.h:681
uint256 hashContinue
Definition: net.h:695
bool fWhitelisted
Definition: net.h:666
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:543
const NodeId id
Definition: net.h:755
bool setBannedIsDirty
Definition: net.h:404
NodeId GetNewNodeId()
Definition: net.cpp:2244
unsigned int nDataPos
Definition: net.h:593
std::string addrLocal
Definition: net.h:571
bool fAddressesInitialized
Definition: net.h:405
std::thread threadDNSAddressSeed
Definition: net.h:443
ServiceFlags nLocalServices
Definition: net.h:128
std::deque< std::vector< unsigned char > > vSendMsg
Definition: net.h:636
uint64_t nMaxOutboundLimit
Definition: net.h:139
size_t SocketSendData(CNode *pnode) const
Definition: net.cpp:888
std::vector< std::string > m_added_nodes
Definition: net.h:145
CCriticalSection cs_vProcessMsg
Definition: net.h:641
void SetSendVersion(int nVersionIn)
Definition: net.cpp:796
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:692
int64_t PoissonNextSend(int64_t now, int average_interval_seconds)
Return a timestamp in the future (in microseconds) for exponentially distributed events.
Definition: net.cpp:2900
std::vector< ListenSocket > vhListenSocket
Definition: net.h:400
void SetBestHeight(int height)
Definition: net.cpp:2710
double dMinPing
Definition: net.h:568
CAmount lastSentFeeFilter
Definition: net.h:746
std::atomic< int64_t > nTimeOffset
Definition: net.h:654
void PushBlockHash(const uint256 &hash)
Definition: net.h:859
std::string command
Definition: net.h:111
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:219
CCriticalSection cs_totalBytesSent
Definition: net.h:383
std::atomic_bool fSuccessfullyConnected
Definition: net.h:673
SipHash-2-4.
Definition: hash.h:247
void ThreadMessageHandler()
Definition: net.cpp:2041
SOCKET hSocket
Definition: net.h:632
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
std::atomic< int > nVersion
Definition: net.h:659
A hasher class for BSHA3&#39;s 256-bit hash (double SHA-3).
Definition: hash.h:22
bool fRelayTxes
Definition: net.h:679
int nMaxOutbound
Definition: net.h:423
unsigned int nSendBufferMaxSize
Definition: net.h:397
const uint64_t nLocalHostNonce
Definition: net.h:756
unsigned int nSendBufferMaxSize
Definition: net.h:136
int readHeader(const char *pch, unsigned int nBytes)
Definition: net.cpp:823
bool m_limited_node
Definition: net.h:671
const ServiceFlags nLocalServices
Definition: net.h:758
int GetExtraOutboundCount()
Definition: net.cpp:1745
banmap_t setBanned
Definition: net.h:402
int flags
Definition: bsha3-tx.cpp:509
uint64_t GetTotalBytesSent()
Definition: net.cpp:2699
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1077
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:89
CCriticalSection cs_sendProcessing
Definition: net.h:645
void MarkAddressGood(const CAddress &addr)
Definition: net.cpp:2511
Information about a peer.
Definition: net.h:626
std::thread threadSocketHandler
Definition: net.h:444
int64_t nNextInvSend
Definition: net.h:718
bool fWhitelisted
Definition: net.h:565
virtual void InitializeNode(CNode *pnode)=0
std::string GetAddrName() const
Definition: net.cpp:658
CCriticalSection cs_vSend
Definition: net.h:637
int64_t nNextAddrSend
Definition: net.h:703
CNode * ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection)
Definition: net.cpp:372
bool fDiscover
Definition: net.cpp:83
void SetVersion(int n)
Definition: streams.h:414
void AddAddressKnown(const CAddress &_addr)
Definition: net.h:819
void copyStats(CNodeStats &stats)
Definition: net.cpp:686
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
std::atomic_bool fPauseRecv
Definition: net.h:687
CNode * AddRef()
Definition: net.h:806
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:421
double dPingWait
Definition: net.h:567
void Init(const Options &connOptions)
Definition: net.h:148
CThreadInterrupt interruptNet
Definition: net.h:441
CCriticalSection cs_totalBytesRecv
Definition: net.h:382
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:153
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:209
const uint64_t nSeed1
Definition: net.h:432
void Stop()
Definition: net.cpp:2443
bool m_use_addrman_outgoing
Definition: net.h:143
std::atomic< int > nRecvVersion
Definition: net.h:649
std::atomic< int64_t > nLastBlockTime
Definition: net.h:729
Definition: net.h:503
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:281
std::multimap< int64_t, CInv > mapAskFor
Definition: net.h:717
CCriticalSection cs_mapLocalHost
Definition: net.cpp:86
bool GetUseAddrmanOutgoing() const
Definition: net.h:178
bool fRelayTxes
Definition: net.h:550
std::vector< AddedNodeInfo > GetAddedNodeInfo()
Definition: net.cpp:1920
int64_t nLastSend
Definition: net.h:551
const uint256 & GetMessageHash() const
Definition: net.cpp:871
unsigned short GetListenPort()
Definition: net.cpp:99
const int nMyStartingHeight
Definition: net.h:759
bool m_use_addrman_outgoing
Definition: net.h:426
bool IsLimited(enum Network net)
Definition: net.cpp:256
virtual bool ProcessMessages(CNode *pnode, std::atomic< bool > &interrupt)=0
int nBestHeight
Definition: net.h:133
NodeId nodeid
Definition: net.h:548
int64_t nLastRecv
Definition: net.h:552
std::set< uint256 > setAskFor
Definition: net.h:716
unsigned int nReceiveFloodSize
Definition: net.h:398
CAddress addr
Definition: net.h:573
Message header.
Definition: protocol.h:28
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
Definition: net.cpp:2095
void ThreadDNSAddressSeed()
Definition: net.cpp:1618