Bitcoin ABC  0.26.3
P2P Digital Currency
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 // Copyright (c) 2017-2019 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_NET_H
8 #define BITCOIN_NET_H
9 
10 #include <avalanche/proofid.h>
12 #include <bloom.h>
13 #include <chainparams.h>
14 #include <compat.h>
15 #include <consensus/amount.h>
16 #include <crypto/siphash.h>
17 #include <hash.h>
18 #include <i2p.h>
19 #include <logging.h>
20 #include <net_permissions.h>
21 #include <netaddress.h>
22 #include <nodeid.h>
23 #include <protocol.h>
24 #include <pubkey.h>
25 #include <radix.h>
26 #include <random.h>
27 #include <span.h>
28 #include <streams.h>
29 #include <sync.h>
30 #include <threadinterrupt.h>
31 #include <uint256.h>
32 #include <util/check.h>
33 #include <validation.h> // For cs_main
34 
35 #include <atomic>
36 #include <condition_variable>
37 #include <cstdint>
38 #include <deque>
39 #include <list>
40 #include <map>
41 #include <memory>
42 #include <thread>
43 #include <vector>
44 
45 class AddrMan;
46 class BanMan;
47 class Config;
48 class CNode;
49 class CScheduler;
50 struct bilingual_str;
51 
53 static const bool DEFAULT_WHITELISTRELAY = true;
55 static const bool DEFAULT_WHITELISTFORCERELAY = false;
56 
61 static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
63 static constexpr auto FEELER_INTERVAL = 2min;
65 static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
67 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
74 static const int MAX_ADDNODE_CONNECTIONS = 8;
76 static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
83 static const int MAX_FEELER_CONNECTIONS = 1;
85 static const bool DEFAULT_LISTEN = true;
91 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 4096;
93 static constexpr uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
95 static const bool DEFAULT_BLOCKSONLY = false;
97 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
99 static const int NUM_FDS_MESSAGE_CAPTURE = 1;
100 
101 static const bool DEFAULT_FORCEDNSSEED = false;
102 static const bool DEFAULT_DNSSEED = true;
103 static const bool DEFAULT_FIXEDSEEDS = true;
104 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
105 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
106 
108  std::string strAddedNode;
111  bool fInbound;
112 };
113 
114 struct CNodeStats;
115 class CClientUIInterface;
116 
118  CSerializedNetMsg() = default;
121  // No copying, only moves.
122  CSerializedNetMsg(const CSerializedNetMsg &msg) = delete;
124 
125  std::vector<uint8_t> data;
126  std::string m_type;
127 };
128 
129 const std::vector<std::string> CONNECTION_TYPE_DOC{
130  "outbound-full-relay (default automatic connections)",
131  "block-relay-only (does not relay transactions or addresses)",
132  "inbound (initiated by the peer)",
133  "manual (added via addnode RPC or -addnode/-connect configuration options)",
134  "addr-fetch (short-lived automatic connection for soliciting addresses)",
135  "feeler (short-lived automatic connection for testing addresses)"};
136 
142 enum class ConnectionType {
148  INBOUND,
149 
157 
164  MANUAL,
165 
182  FEELER,
183 
193  BLOCK_RELAY,
194 
201  ADDR_FETCH,
202 
208 };
209 
211 std::string ConnectionTypeAsString(ConnectionType conn_type);
212 void Discover();
213 uint16_t GetListenPort();
214 
215 enum {
216  // unknown
218  // address a local interface listens on
220  // address explicit bound to
222  // address reported by UPnP or NAT-PMP
224  // address explicitly specified (-externalip=)
226 
227  LOCAL_MAX
228 };
229 
230 bool IsPeerAddrLocalGood(CNode *pnode);
232 std::optional<CAddress> GetLocalAddrForPeer(CNode *pnode);
233 
238 void SetReachable(enum Network net, bool reachable);
240 bool IsReachable(enum Network net);
242 bool IsReachable(const CNetAddr &addr);
243 
244 bool AddLocal(const CService &addr, int nScore = LOCAL_NONE);
245 bool AddLocal(const CNetAddr &addr, int nScore = LOCAL_NONE);
246 void RemoveLocal(const CService &addr);
247 bool SeenLocal(const CService &addr);
248 bool IsLocal(const CService &addr);
249 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
250 CAddress GetLocalAddress(const CNetAddr *paddrPeer,
251  ServiceFlags nLocalServices);
252 
253 extern bool fDiscover;
254 extern bool fListen;
255 
257  int nScore;
258  uint16_t nPort;
259 };
260 
262 extern std::map<CNetAddr, LocalServiceInfo>
264 
265 extern const std::string NET_MESSAGE_COMMAND_OTHER;
266 // Command, total bytes
267 typedef std::map<std::string, uint64_t> mapMsgCmdSize;
268 
274 struct CNodeStats {
278  std::chrono::seconds m_last_send;
279  std::chrono::seconds m_last_recv;
280  std::chrono::seconds m_last_tx_time;
281  std::chrono::seconds m_last_proof_time;
282  std::chrono::seconds m_last_block_time;
283  std::chrono::seconds m_connected;
284  int64_t nTimeOffset;
285  std::string m_addr_name;
286  int nVersion;
287  std::string cleanSubVer;
288  bool fInbound;
292  uint64_t nSendBytes;
294  uint64_t nRecvBytes;
297  std::chrono::microseconds m_last_ping_time;
298  std::chrono::microseconds m_min_ping_time;
300  // Our address, as reported by the peer
301  std::string addrLocal;
302  // Address of this peer
304  // Bind address of our side of the connection
306  // Network the peer connected through
308  uint32_t m_mapped_as;
310  std::optional<double> m_availabilityScore;
311 };
312 
318 class CNetMessage {
319 public:
323  std::chrono::microseconds m_time{0};
324  bool m_valid_netmagic = false;
325  bool m_valid_header = false;
326  bool m_valid_checksum = false;
328  uint32_t m_message_size{0};
330  uint32_t m_raw_message_size{0};
331  std::string m_command;
332 
333  CNetMessage(CDataStream &&recv_in) : m_recv(std::move(recv_in)) {}
334 
335  void SetVersion(int nVersionIn) { m_recv.SetVersion(nVersionIn); }
336 };
337 
344 public:
345  // returns true if the current deserialization is complete
346  virtual bool Complete() const = 0;
347  // set the serialization context version
348  virtual void SetVersion(int version) = 0;
350  virtual int Read(const Config &config, Span<const uint8_t> &msg_bytes) = 0;
351  // decomposes a message from the context
352  virtual CNetMessage GetMessage(const Config &config,
353  std::chrono::microseconds time) = 0;
355 };
356 
358 private:
359  mutable CHash256 hasher;
361 
362  // Parsing header (false) or data (true)
363  bool in_data;
364  // Partially received header.
366  // Complete header.
368  // Received message data.
370  uint32_t nHdrPos;
371  uint32_t nDataPos;
372 
373  const uint256 &GetMessageHash() const;
374  int readHeader(const Config &config, Span<const uint8_t> msg_bytes);
375  int readData(Span<const uint8_t> msg_bytes);
376 
377  void Reset() {
378  vRecv.clear();
379  hdrbuf.clear();
380  hdrbuf.resize(24);
381  in_data = false;
382  nHdrPos = 0;
383  nDataPos = 0;
384  data_hash.SetNull();
385  hasher.Reset();
386  }
387 
388 public:
390  const CMessageHeader::MessageMagic &pchMessageStartIn, int nTypeIn,
391  int nVersionIn)
392  : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn),
393  vRecv(nTypeIn, nVersionIn) {
394  Reset();
395  }
396 
397  bool Complete() const override {
398  if (!in_data) {
399  return false;
400  }
401 
402  return (hdr.nMessageSize == nDataPos);
403  }
404 
405  void SetVersion(int nVersionIn) override {
406  hdrbuf.SetVersion(nVersionIn);
407  vRecv.SetVersion(nVersionIn);
408  }
409  int Read(const Config &config, Span<const uint8_t> &msg_bytes) override {
410  int ret = in_data ? readData(msg_bytes) : readHeader(config, msg_bytes);
411  if (ret < 0) {
412  Reset();
413  } else {
414  msg_bytes = msg_bytes.subspan(ret);
415  }
416  return ret;
417  }
418 
419  CNetMessage GetMessage(const Config &config,
420  std::chrono::microseconds time) override;
421 };
422 
427 public:
428  // prepare message for transport (header construction, error-correction
429  // computation, payload encryption, etc.)
430  virtual void prepareForTransport(const Config &config,
431  CSerializedNetMsg &msg,
432  std::vector<uint8_t> &header) = 0;
433  virtual ~TransportSerializer() {}
434 };
435 
437 public:
438  void prepareForTransport(const Config &config, CSerializedNetMsg &msg,
439  std::vector<uint8_t> &header) override;
440 };
441 
443 class CNode {
444  friend class CConnman;
445  friend struct ConnmanTestMsg;
446 
447 public:
448  std::unique_ptr<TransportDeserializer> m_deserializer;
449  std::unique_ptr<TransportSerializer> m_serializer;
450 
451  // socket
452  std::atomic<ServiceFlags> nServices{NODE_NONE};
455  size_t nSendSize GUARDED_BY(cs_vSend){0};
457  size_t nSendOffset GUARDED_BY(cs_vSend){0};
458  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
459  std::deque<std::vector<uint8_t>> vSendMsg GUARDED_BY(cs_vSend);
463 
465  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
466  size_t nProcessQueueSize{0};
467 
469 
470  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
471 
472  std::atomic<std::chrono::seconds> m_last_send{0s};
473  std::atomic<std::chrono::seconds> m_last_recv{0s};
475  const std::chrono::seconds m_connected;
476  std::atomic<int64_t> nTimeOffset{0};
477  // Address of this peer
478  const CAddress addr;
479  // Bind address of our side of the connection
481  const std::string m_addr_name;
484  const bool m_inbound_onion;
485  std::atomic<int> nVersion{0};
486  // The nonce provided by the remote host.
487  uint64_t nRemoteHostNonce{0};
488  // The extra entropy provided by the remote host.
489  uint64_t nRemoteExtraEntropy{0};
495  std::string cleanSubVer GUARDED_BY(m_subver_mutex){};
496  // This peer is preferred for eviction.
497  bool m_prefer_evict{false};
498  bool HasPermission(NetPermissionFlags permission) const {
499  return NetPermissions::HasFlag(m_permissionFlags, permission);
500  }
501  // set by version message
502  bool fClient{false};
503  // after BIP159, set by version message
504  bool m_limited_node{false};
505  std::atomic_bool fSuccessfullyConnected{false};
506  // Setting fDisconnect to true will cause the node to be disconnected the
507  // next time DisconnectNodes() runs
508  std::atomic_bool fDisconnect{false};
510  std::atomic<int> nRefCount{0};
511 
512  const uint64_t nKeyedNetGroup;
513  std::atomic_bool fPauseRecv{false};
514  std::atomic_bool fPauseSend{false};
515 
517  switch (m_conn_type) {
521  return true;
526  return false;
527  } // no default case, so the compiler can warn about missing cases
528 
529  assert(false);
530  }
531 
532  bool IsFullOutboundConn() const {
535  }
536 
537  bool IsManualConn() const { return m_conn_type == ConnectionType::MANUAL; }
538 
539  bool IsBlockOnlyConn() const {
541  }
542 
543  bool IsFeelerConn() const { return m_conn_type == ConnectionType::FEELER; }
544 
545  bool IsAddrFetchConn() const {
547  }
548 
549  bool IsInboundConn() const {
551  }
552 
555  }
556 
557  bool ExpectServicesFromConn() const {
558  switch (m_conn_type) {
562  return false;
567  return true;
568  } // no default case, so the compiler can warn about missing cases
569 
570  assert(false);
571  }
572 
585 
586  // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
587  std::atomic<bool> m_bip152_highbandwidth_to{false};
588  // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
589  std::atomic<bool> m_bip152_highbandwidth_from{false};
590 
591  struct TxRelay {
593  // We use fRelayTxes for two purposes -
594  // a) it allows us to not relay tx invs before receiving the peer's
595  // version message.
596  // b) the peer may tell us in its version message that we should not
597  // relay tx invs unless it loads a bloom filter.
598  bool fRelayTxes GUARDED_BY(cs_filter){false};
599  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter)
600  GUARDED_BY(cs_filter){nullptr};
601 
604  50000, 0.000001};
605  // Set of transaction ids we still have to announce.
606  // They are sorted by the mempool before relay, so the order is not
607  // important.
608  std::set<TxId> setInventoryTxToSend GUARDED_BY(cs_tx_inventory);
609  // Used for BIP35 mempool sending
610  bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
611  // Last time a "MEMPOOL" request was serviced.
612  std::atomic<std::chrono::seconds> m_last_mempool_req{0s};
613  std::chrono::microseconds nNextInvSend{0};
614 
616  std::atomic<Amount> minFeeFilter{Amount::zero()};
618  std::chrono::microseconds m_next_send_feefilter{0};
619  };
620 
621  // m_tx_relay == nullptr if we're not relaying transactions with this peer
622  const std::unique_ptr<TxRelay> m_tx_relay;
623 
624  struct ProofRelay {
626  std::set<avalanche::ProofId>
627  setInventoryProofToSend GUARDED_BY(cs_proof_inventory);
628  // Prevent sending proof invs if the peer already knows about them
630  10000, 0.000001};
631  std::chrono::microseconds nextInvSend{0};
632 
635  std::atomic<std::chrono::seconds> lastSharedProofsUpdate{0s};
636  std::atomic<bool> compactproofs_requested{false};
637  };
638 
639  // m_proof_relay == nullptr if we're not relaying proofs with this peer
640  const std::unique_ptr<ProofRelay> m_proof_relay;
641 
642  // True if we know this peer is using Avalanche (at least polling)
643  std::atomic<bool> m_avalanche_enabled{false};
644 
646  // Pubkey used to verify signatures on Avalanche messages from this peer
647  std::optional<CPubKey> m_avalanche_pubkey GUARDED_BY(cs_avalanche_pubkey);
648 
650  void invsPolled(uint32_t count);
651 
653  void invsVoted(uint32_t count);
654 
671  void updateAvailabilityScore(double decayFactor);
672  double getAvailabilityScore() const;
673 
674  // Store the next time we will consider a getavaaddr message from this peer
675  std::chrono::seconds m_nextGetAvaAddr{0};
676 
684  std::atomic<std::chrono::seconds> m_last_block_time{0s};
685 
692  std::atomic<std::chrono::seconds> m_last_tx_time{0s};
693 
700  std::atomic<std::chrono::seconds> m_last_proof_time{0s};
701 
703  std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
704 
709  std::atomic<std::chrono::microseconds> m_min_ping_time{
710  std::chrono::microseconds::max()};
711 
712  CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
713  const CAddress &addrIn, uint64_t nKeyedNetGroupIn,
714  uint64_t nLocalHostNonceIn, uint64_t nLocalExtraEntropyIn,
715  const CAddress &addrBindIn, const std::string &addrNameIn,
716  ConnectionType conn_type_in, bool inbound_onion);
717  ~CNode();
718  CNode(const CNode &) = delete;
719  CNode &operator=(const CNode &) = delete;
720 
725  void PongReceived(std::chrono::microseconds ping_time) {
726  m_last_ping_time = ping_time;
727  m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
728  }
729 
730  NodeId GetId() const { return id; }
731 
732  uint64_t GetLocalNonce() const { return nLocalHostNonce; }
733  uint64_t GetLocalExtraEntropy() const { return nLocalExtraEntropy; }
734 
735  int GetRefCount() const {
736  assert(nRefCount >= 0);
737  return nRefCount;
738  }
739 
749  bool ReceiveMsgBytes(const Config &config, Span<const uint8_t> msg_bytes,
750  bool &complete);
751 
752  void SetCommonVersion(int greatest_common_version) {
754  m_greatest_common_version = greatest_common_version;
755  }
757 
758  CService GetAddrLocal() const;
760  void SetAddrLocal(const CService &addrLocalIn);
761 
763  nRefCount++;
764  return this;
765  }
766 
767  void Release() { nRefCount--; }
768 
769  void AddKnownTx(const TxId &txid) {
770  if (m_tx_relay != nullptr) {
771  LOCK(m_tx_relay->cs_tx_inventory);
772  m_tx_relay->filterInventoryKnown.insert(txid);
773  }
774  }
775 
776  void PushTxInventory(const TxId &txid) {
777  if (m_tx_relay == nullptr) {
778  return;
779  }
780  LOCK(m_tx_relay->cs_tx_inventory);
781  if (!m_tx_relay->filterInventoryKnown.contains(txid)) {
782  m_tx_relay->setInventoryTxToSend.insert(txid);
783  }
784  }
785 
786  void AddKnownProof(const avalanche::ProofId &proofid) {
787  if (m_proof_relay != nullptr) {
788  LOCK(m_proof_relay->cs_proof_inventory);
789  m_proof_relay->filterProofKnown.insert(proofid);
790  }
791  }
792 
793  void PushProofInventory(const avalanche::ProofId &proofid) {
794  if (m_proof_relay == nullptr) {
795  return;
796  }
797 
798  LOCK(m_proof_relay->cs_proof_inventory);
799  if (!m_proof_relay->filterProofKnown.contains(proofid)) {
800  m_proof_relay->setInventoryProofToSend.insert(proofid);
801  }
802  }
803 
804  void CloseSocketDisconnect();
805 
806  void copyStats(CNodeStats &stats);
807 
809 
810  std::string ConnectionTypeAsString() const {
812  }
813 
814 private:
815  const NodeId id;
816  const uint64_t nLocalHostNonce;
817  const uint64_t nLocalExtraEntropy;
820 
837 
839  // Used only by SocketHandler thread
840  std::list<CNetMessage> vRecvMsg;
841 
842  // Our address, as reported by the peer
845 
851  std::atomic<uint64_t> invCounters{0};
852 
854  std::atomic<double> availabilityScore{0.};
855 
856  mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
857  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
858 };
859 
864 public:
866  virtual void InitializeNode(const Config &config, CNode *pnode) = 0;
867 
869  virtual void FinalizeNode(const Config &config, const CNode &node) = 0;
870 
880  virtual bool ProcessMessages(const Config &config, CNode *pnode,
881  std::atomic<bool> &interrupt) = 0;
882 
890  virtual bool SendMessages(const Config &config, CNode *pnode)
891  EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_sendProcessing) = 0;
892 
893 protected:
899  ~NetEventsInterface() = default;
900 };
901 
902 namespace {
903 struct CConnmanTest;
904 }
905 
906 class NetEventsInterface;
907 class CConnman {
908 public:
911  CONNECTIONS_IN = (1U << 0),
912  CONNECTIONS_OUT = (1U << 1),
914  };
915 
916  struct Options {
922  int nMaxAddnode = 0;
923  int nMaxFeeler = 0;
925  std::vector<NetEventsInterface *> m_msgproc;
926  BanMan *m_banman = nullptr;
927  unsigned int nSendBufferMaxSize = 0;
928  unsigned int nReceiveFloodSize = 0;
929  uint64_t nMaxOutboundLimit = 0;
931  std::vector<std::string> vSeedNodes;
932  std::vector<NetWhitelistPermissions> vWhitelistedRange;
933  std::vector<NetWhitebindPermissions> vWhiteBinds;
934  std::vector<CService> vBinds;
935  std::vector<CService> onion_binds;
940  std::vector<std::string> m_specified_outgoing;
941  std::vector<std::string> m_added_nodes;
943  };
944 
945  void Init(const Options &connOptions) {
946  nLocalServices = connOptions.nLocalServices;
947  nMaxConnections = connOptions.nMaxConnections;
949  nMaxAddnode = connOptions.nMaxAddnode;
950  nMaxFeeler = connOptions.nMaxFeeler;
951  {
952  // Lock cs_main to prevent a potential race with the peer validation
953  // logic thread.
954  LOCK(::cs_main);
956  std::min(connOptions.m_max_outbound_full_relay,
957  connOptions.nMaxConnections);
963  }
964  m_client_interface = connOptions.uiInterface;
965  m_banman = connOptions.m_banman;
966  m_msgproc = connOptions.m_msgproc;
968  nReceiveFloodSize = connOptions.nReceiveFloodSize;
970  std::chrono::seconds{connOptions.m_peer_connect_timeout};
971  {
973  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
974  }
975  vWhitelistedRange = connOptions.vWhitelistedRange;
976  {
978  m_added_nodes = connOptions.m_added_nodes;
979  }
980  m_onion_binds = connOptions.onion_binds;
981  }
982 
983  CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1,
984  AddrMan &addrmanIn, bool network_active = true);
985  ~CConnman();
986 
987  bool Start(CScheduler &scheduler, const Options &options);
988 
989  void StopThreads();
990  void StopNodes();
991  void Stop() {
992  StopThreads();
993  StopNodes();
994  };
995 
996  void Interrupt();
997  bool GetNetworkActive() const { return fNetworkActive; };
999  void SetNetworkActive(bool active);
1000  void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure,
1001  CSemaphoreGrant *grantOutbound,
1002  const char *strDest, ConnectionType conn_type);
1003  bool CheckIncomingNonce(uint64_t nonce);
1004 
1005  bool ForNode(NodeId id, std::function<bool(CNode *pnode)> func);
1006 
1007  void PushMessage(CNode *pnode, CSerializedNetMsg &&msg);
1008 
1009  using NodeFn = std::function<void(CNode *)>;
1010  void ForEachNode(const NodeFn &func) {
1012  for (auto &&node : m_nodes) {
1013  if (NodeFullyConnected(node)) {
1014  func(node);
1015  }
1016  }
1017  };
1018 
1019  void ForEachNode(const NodeFn &func) const {
1021  for (auto &&node : m_nodes) {
1022  if (NodeFullyConnected(node)) {
1023  func(node);
1024  }
1025  }
1026  };
1027 
1028  // Addrman functions
1039  std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct,
1040  std::optional<Network> network) const;
1047  std::vector<CAddress> GetAddresses(CNode &requestor, size_t max_addresses,
1048  size_t max_pct);
1049 
1050  // This allows temporarily exceeding m_max_outbound_full_relay, with the
1051  // goal of finding a peer that is better than all our current peers.
1052  void SetTryNewOutboundPeer(bool flag);
1053  bool GetTryNewOutboundPeer() const;
1054 
1056  LogPrint(BCLog::NET, "net: enabling extra block-relay-only peers\n");
1058  }
1059 
1060  // Return the number of outbound peers we have in excess of our target (eg,
1061  // if we previously called SetTryNewOutboundPeer(true), and have since set
1062  // to false, we may have extra peers that we wish to disconnect). This may
1063  // return a value less than (num_outbound_connections - num_outbound_slots)
1064  // in cases where some outbound connections are not yet fully connected, or
1065  // not yet fully disconnected.
1066  int GetExtraFullOutboundCount() const;
1067  // Count the number of block-relay-only peers we have over our limit.
1068  int GetExtraBlockRelayCount() const;
1069 
1070  bool AddNode(const std::string &node);
1071  bool RemoveAddedNode(const std::string &node);
1072  std::vector<AddedNodeInfo> GetAddedNodeInfo() const;
1073 
1088  bool AddConnection(const std::string &address, ConnectionType conn_type);
1089 
1090  size_t GetNodeCount(NumConnections num) const;
1091  void GetNodeStats(std::vector<CNodeStats> &vstats) const;
1092  bool DisconnectNode(const std::string &node);
1093  bool DisconnectNode(const CSubNet &subnet);
1094  bool DisconnectNode(const CNetAddr &addr);
1095  bool DisconnectNode(NodeId id);
1096 
1104 
1105  uint64_t GetMaxOutboundTarget() const;
1106  std::chrono::seconds GetMaxOutboundTimeframe() const;
1107 
1111  bool OutboundTargetReached(bool historicalBlockServingLimit) const;
1112 
1115  uint64_t GetOutboundTargetBytesLeft() const;
1116 
1119  std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const;
1120 
1121  uint64_t GetTotalBytesRecv() const;
1122  uint64_t GetTotalBytesSent() const;
1123 
1125  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
1126 
1127  unsigned int GetReceiveFloodSize() const;
1128 
1129  void WakeMessageHandler();
1130 
1136  std::chrono::microseconds
1137  PoissonNextSendInbound(std::chrono::microseconds now,
1138  std::chrono::seconds average_interval);
1139 
1144  bool ShouldRunInactivityChecks(const CNode &node,
1145  std::chrono::seconds now) const;
1146 
1147 private:
1148  struct ListenSocket {
1149  public:
1153  }
1154  ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
1155  : socket(socket_), m_permissions(permissions_) {}
1156 
1157  private:
1159  };
1160 
1161  bool BindListenPort(const CService &bindAddr, bilingual_str &strError,
1162  NetPermissionFlags permissions);
1163  bool Bind(const CService &addr, unsigned int flags,
1164  NetPermissionFlags permissions);
1165  bool InitBinds(const Options &options);
1166 
1168  void AddAddrFetch(const std::string &strDest);
1169  void ProcessAddrFetch();
1170  void
1171  ThreadOpenConnections(std::vector<std::string> connect,
1172  std::function<void(const CAddress &, ConnectionType)>
1173  mockOpenConnection);
1174  void ThreadMessageHandler();
1175  void ThreadI2PAcceptIncoming();
1176  void AcceptConnection(const ListenSocket &hListenSocket);
1177 
1186  void CreateNodeFromAcceptedSocket(SOCKET hSocket,
1187  NetPermissionFlags permissionFlags,
1188  const CAddress &addr_bind,
1189  const CAddress &addr);
1190 
1191  void DisconnectNodes();
1194  bool InactivityCheck(const CNode &node) const;
1195  bool GenerateSelectSet(std::set<SOCKET> &recv_set,
1196  std::set<SOCKET> &send_set,
1197  std::set<SOCKET> &error_set);
1198  void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set,
1199  std::set<SOCKET> &error_set);
1200  void SocketHandler();
1201  void ThreadSocketHandler();
1202  void ThreadDNSAddressSeed();
1203 
1204  uint64_t CalculateKeyedNetGroup(const CAddress &ad) const;
1205 
1206  CNode *FindNode(const CNetAddr &ip);
1207  CNode *FindNode(const CSubNet &subNet);
1208  CNode *FindNode(const std::string &addrName);
1209  CNode *FindNode(const CService &addr);
1210 
1215  bool AlreadyConnectedToAddress(const CAddress &addr);
1216 
1217  bool AttemptToEvictConnection();
1218  CNode *ConnectNode(CAddress addrConnect, const char *pszDest,
1219  bool fCountFailure, ConnectionType conn_type);
1221  const CNetAddr &addr) const;
1222 
1223  void DeleteNode(CNode *pnode);
1224 
1225  NodeId GetNewNodeId();
1226 
1227  size_t SocketSendData(CNode &node) const
1228  EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1229  void DumpAddresses();
1230 
1231  // Network stats
1232  void RecordBytesRecv(uint64_t bytes);
1233  void RecordBytesSent(uint64_t bytes);
1234 
1238  std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1239 
1240  // Whether the node should be passed out in ForEach* callbacks
1241  static bool NodeFullyConnected(const CNode *pnode);
1242 
1243  const Config *config;
1244 
1245  // Network usage totals
1247  std::atomic<uint64_t> nTotalBytesRecv{0};
1248  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent){0};
1249 
1250  // outbound limit & stats
1251  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent){0};
1252  std::chrono::seconds
1253  nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent){0};
1254  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
1255 
1256  // P2P timeout in seconds
1257  std::chrono::seconds m_peer_connect_timeout;
1258 
1259  // Whitelisted ranges. Any node connecting from these is automatically
1260  // whitelisted (as well as those connecting to whitelisted binds).
1261  std::vector<NetWhitelistPermissions> vWhitelistedRange;
1262 
1263  unsigned int nSendBufferMaxSize{0};
1264  unsigned int nReceiveFloodSize{0};
1265 
1266  std::vector<ListenSocket> vhListenSocket;
1267  std::atomic<bool> fNetworkActive{true};
1270  std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1272  std::vector<std::string> m_added_nodes GUARDED_BY(m_added_nodes_mutex);
1274  std::vector<CNode *> m_nodes GUARDED_BY(m_nodes_mutex);
1275  std::list<CNode *> m_nodes_disconnected;
1277  std::atomic<NodeId> nLastNodeId{0};
1278  unsigned int nPrevNodeCount{0};
1279 
1287  std::vector<CAddress> m_addrs_response_cache;
1288  std::chrono::microseconds m_cache_entry_expiration{0};
1289  };
1290 
1305  std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1306 
1320 
1321  std::unique_ptr<CSemaphore> semOutbound;
1322  std::unique_ptr<CSemaphore> semAddnode;
1324 
1325  // How many full-relay (tx, block, addr) outbound peers we want
1327 
1328  // How many block-relay only outbound peers we want
1329  // We do not relay tx or addr messages with these peers
1331 
1332  // How many avalanche enabled outbound peers we want
1334 
1340  // FIXME m_msgproc is a terrible name
1341  std::vector<NetEventsInterface *> m_msgproc;
1347 
1352  std::vector<CAddress> m_anchors;
1353 
1355  const uint64_t nSeed0, nSeed1;
1356 
1358  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1359 
1360  std::condition_variable condMsgProc;
1362  std::atomic<bool> flagInterruptMsgProc{false};
1363 
1371 
1376  std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1377 
1379  std::thread threadSocketHandler;
1384 
1390 
1396  std::atomic_bool m_start_extra_block_relay_peers{false};
1397 
1398  std::atomic<std::chrono::microseconds> m_next_send_inv_to_incoming{0us};
1399 
1404  std::vector<CService> m_onion_binds;
1405 
1406  friend struct ::CConnmanTest;
1407  friend struct ConnmanTestMsg;
1408 };
1409 
1414 std::chrono::microseconds
1415 PoissonNextSend(std::chrono::microseconds now,
1416  std::chrono::seconds average_interval);
1417 
1418 std::string getSubVersionEB(uint64_t MaxBlockSize);
1419 std::string userAgent(const Config &config);
1420 
1422 void CaptureMessage(const CAddress &addr, const std::string &msg_type,
1423  const Span<const uint8_t> &data, bool is_incoming);
1424 
1427  std::chrono::seconds m_connected;
1428  std::chrono::microseconds m_min_ping_time;
1429  std::chrono::seconds m_last_block_time;
1430  std::chrono::seconds m_last_proof_time;
1431  std::chrono::seconds m_last_tx_time;
1435  uint64_t nKeyedNetGroup;
1440 };
1441 
1449 [[nodiscard]] std::optional<NodeId>
1450 SelectNodeToEvict(std::vector<NodeEvictionCandidate> &&vEvictionCandidates);
1451 
1475  std::vector<NodeEvictionCandidate> &vEvictionCandidates);
1476 
1477 #endif // BITCOIN_NET_H
int flags
Definition: bitcoin-tx.cpp:538
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:113
#define Assume(val)
Assume is the identity function.
Definition: check.h:85
Stochastic address manager.
Definition: addrman.h:68
Definition: banman.h:58
A CService with information about it as peer.
Definition: protocol.h:445
Signals for UI communication.
Definition: ui_interface.h:24
Definition: net.h:907
void CreateNodeFromAcceptedSocket(SOCKET hSocket, NetPermissionFlags permissionFlags, const CAddress &addr_bind, const CAddress &addr)
Create a CNode object from a socket that has just been accepted and add the node to the m_nodes membe...
Definition: net.cpp:1275
std::condition_variable condMsgProc
Definition: net.h:1360
size_t GetNodeCount(NumConnections num) const
Definition: net.cpp:3233
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1248
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1253
std::thread threadMessageHandler
Definition: net.h:1382
void ForEachNode(const NodeFn &func)
Definition: net.h:1010
std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const
returns the time in second left in the current max outbound cycle in case of no limit,...
Definition: net.cpp:3335
void ThreadOpenAddedConnections()
Definition: net.cpp:2514
bool OutboundTargetReached(bool historicalBlockServingLimit) const
check if the outbound target is reached.
Definition: net.cpp:3351
CClientUIInterface * m_client_interface
Definition: net.h:1339
size_t SocketSendData(CNode &node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend)
Definition: net.cpp:799
void SocketHandler()
Definition: net.cpp:1744
void ForEachNode(const NodeFn &func) const
Definition: net.h:1019
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3529
std::vector< AddedNodeInfo > GetAddedNodeInfo() const
Definition: net.cpp:2457
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1398
CNode * ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type)
Definition: net.cpp:384
void DeleteNode(CNode *pnode)
Definition: net.cpp:3129
bool AttemptToEvictConnection()
Try to find a connection to evict when the node is full.
Definition: net.cpp:1186
bool GetNetworkActive() const
Definition: net.h:997
bool AlreadyConnectedToAddress(const CAddress &addr)
Determine whether we're already connected to a given address, in order to avoid initiating duplicate ...
Definition: net.cpp:352
int m_max_outbound
Definition: net.h:1337
void AddAddrFetch(const std::string &strDest)
Definition: net.cpp:129
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:1319
bool GetTryNewOutboundPeer() const
Definition: net.cpp:2054
void Stop()
Definition: net.h:991
int m_max_outbound_block_relay
Definition: net.h:1330
void ProcessAddrFetch()
Definition: net.cpp:2036
std::thread threadI2PAcceptIncoming
Definition: net.h:1383
void SetTryNewOutboundPeer(bool flag)
Definition: net.cpp:2058
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:1362
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:3398
void SocketEvents(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1661
NodeId GetNewNodeId()
Definition: net.cpp:2851
CThreadInterrupt interruptNet
This is signaled when network activity should cease.
Definition: net.h:1370
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:1322
std::atomic< NodeId > nLastNodeId
Definition: net.h:1277
std::atomic< std::chrono::microseconds > m_next_send_inv_to_incoming
Definition: net.h:1398
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:3311
bool fMsgProcWake GUARDED_BY(mutexMsgProc)
flag for waking the message processor.
std::vector< std::string > m_added_nodes GUARDED_BY(m_added_nodes_mutex)
int GetExtraBlockRelayCount() const
Definition: net.cpp:2086
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1346
void Interrupt()
Definition: net.cpp:3040
uint64_t GetOutboundTargetBytesLeft() const
response the bytes left in the current max outbound cycle in case of no limit, it will always respons...
Definition: net.cpp:3374
std::thread threadDNSAddressSeed
Definition: net.h:1378
void ThreadOpenConnections(std::vector< std::string > connect, std::function< void(const CAddress &, ConnectionType)> mockOpenConnection)
Definition: net.cpp:2100
void ThreadI2PAcceptIncoming()
Definition: net.cpp:2660
const uint64_t nSeed1
Definition: net.h:1355
void StartExtraBlockRelayPeers()
Definition: net.h:1055
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1352
std::chrono::seconds GetMaxOutboundTimeframe() const
Definition: net.cpp:3331
friend struct ConnmanTestMsg
Definition: net.h:1407
unsigned int nPrevNodeCount
Definition: net.h:1278
void NotifyNumConnectionsChanged()
Definition: net.cpp:1497
ServiceFlags GetLocalServices() const
Used to convey which local services we are offering peers during node connection.
Definition: net.cpp:3394
bool DisconnectNode(const std::string &node)
Definition: net.cpp:3262
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1257
std::atomic_bool m_try_another_outbound_peer
flag for deciding to connect to an extra outbound peer, in excess of m_max_outbound_full_relay.
Definition: net.h:1389
bool InitBinds(const Options &options)
Definition: net.cpp:2877
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1251
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1266
std::vector< CAddress > GetCurrentBlockRelayOnlyConns() const
Return vector of current BLOCK_RELAY peers.
Definition: net.cpp:2445
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
Definition: net.cpp:3563
uint64_t GetMaxOutboundTarget() const
Definition: net.cpp:3326
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:1321
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:1261
void ThreadSocketHandler()
Definition: net.cpp:1875
RecursiveMutex cs_totalBytesSent
Definition: net.h:1246
bool Bind(const CService &addr, unsigned int flags, NetPermissionFlags permissions)
Definition: net.cpp:2855
std::thread threadOpenConnections
Definition: net.h:1381
NumConnections
Definition: net.h:909
@ CONNECTIONS_IN
Definition: net.h:911
@ CONNECTIONS_NONE
Definition: net.h:910
@ CONNECTIONS_ALL
Definition: net.h:913
@ CONNECTIONS_OUT
Definition: net.h:912
Mutex m_addr_fetches_mutex
Definition: net.h:1271
bool InactivityCheck(const CNode &node) const
Return true if the peer is inactive and should be disconnected.
Definition: net.cpp:1516
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:312
void Init(const Options &connOptions)
Definition: net.h:945
void GetNodeStats(std::vector< CNodeStats > &vstats) const
Definition: net.cpp:3251
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1355
unsigned int nReceiveFloodSize
Definition: net.h:1264
int GetExtraFullOutboundCount() const
Definition: net.cpp:2070
uint64_t GetTotalBytesRecv() const
Definition: net.cpp:3385
RecursiveMutex m_nodes_mutex
Definition: net.h:1276
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:3480
int nMaxConnections
Definition: net.h:1323
CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1, AddrMan &addrmanIn, bool network_active=true)
Definition: net.cpp:2840
std::vector< CAddress > GetAddresses(size_t max_addresses, size_t max_pct, std::optional< Network > network) const
Return all or many randomly selected addresses, optionally by network.
Definition: net.cpp:3143
std::deque< std::string > m_addr_fetches GUARDED_BY(m_addr_fetches_mutex)
std::function< void(CNode *)> NodeFn
Definition: net.h:1009
void WakeMessageHandler()
Definition: net.cpp:1883
void SetNetworkActive(bool active)
Definition: net.cpp:2826
std::list< CNode * > m_nodes_disconnected
Definition: net.h:1275
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2546
void AddWhitelistPermissionFlags(NetPermissionFlags &flags, const CNetAddr &addr) const
Definition: net.cpp:531
bool Start(CScheduler &scheduler, const Options &options)
Definition: net.cpp:2904
bool GenerateSelectSet(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1556
void ThreadDNSAddressSeed()
Definition: net.cpp:1891
AddrMan & addrman
Definition: net.h:1269
void ThreadMessageHandler()
Definition: net.cpp:2593
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:3567
Mutex mutexMsgProc
Definition: net.h:1361
bool fAddressesInitialized
Definition: net.h:1268
std::chrono::microseconds PoissonNextSendInbound(std::chrono::microseconds now, std::chrono::seconds average_interval)
Attempts to obfuscate tx time through exponentially distributed emitting.
Definition: net.cpp:3542
~CConnman()
Definition: net.cpp:3137
void StopThreads()
Definition: net.cpp:3063
std::thread threadOpenAddedConnections
Definition: net.h:1380
Mutex m_added_nodes_mutex
Definition: net.h:1273
std::vector< CNode * > m_nodes GUARDED_BY(m_nodes_mutex)
const Config * config
Definition: net.h:1243
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:357
int m_max_outbound_full_relay
Definition: net.h:1326
int nMaxAddnode
Definition: net.h:1335
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:3307
bool ShouldRunInactivityChecks(const CNode &node, std::chrono::seconds now) const
Return true if we should disconnect the peer for failing an inactivity check.
Definition: net.cpp:1511
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3484
void StopNodes()
Definition: net.cpp:3084
bool GetUseAddrmanOutgoing() const
Definition: net.h:998
unsigned int nSendBufferMaxSize
Definition: net.h:1263
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1376
bool m_use_addrman_outgoing
Definition: net.h:1338
std::map< uint64_t, CachedAddrResponse > m_addr_response_caches
Addr responses stored in different caches per (network, local socket) prevent cross-network node iden...
Definition: net.h:1305
uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent)
std::atomic< uint64_t > nTotalBytesRecv
Definition: net.h:1247
std::atomic< bool > fNetworkActive
Definition: net.h:1267
std::atomic_bool m_start_extra_block_relay_peers
flag for initiating extra block-relay-only peer connections.
Definition: net.h:1396
void DisconnectNodes()
Definition: net.cpp:1447
void DumpAddresses()
Definition: net.cpp:2027
std::vector< CService > m_onion_binds
A vector of -bind=<address>:<port>=onion arguments each of which is an address and port that are desi...
Definition: net.h:1404
bool AddNode(const std::string &node)
Definition: net.cpp:3209
int nMaxFeeler
Definition: net.h:1336
std::vector< NetEventsInterface * > m_msgproc
Definition: net.h:1341
std::thread threadSocketHandler
Definition: net.h:1379
uint64_t GetTotalBytesSent() const
Definition: net.cpp:3389
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:3221
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1247
bool BindListenPort(const CService &bindAddr, bilingual_str &strError, NetPermissionFlags permissions)
Definition: net.cpp:2698
int m_max_avalanche_outbound
Definition: net.h:1333
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
void SetVersion(int n)
Definition: streams.h:386
void resize(size_type n, value_type c=0)
Definition: streams.h:282
void clear()
Definition: streams.h:288
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:22
CHash256 & Reset()
Definition: hash.h:41
Message header.
Definition: protocol.h:37
uint32_t nMessageSize
Definition: protocol.h:74
std::array< uint8_t, MESSAGE_START_SIZE > MessageMagic
Definition: protocol.h:49
Network address.
Definition: netaddress.h:121
Transport protocol agnostic message container.
Definition: net.h:318
CNetMessage(CDataStream &&recv_in)
Definition: net.h:333
uint32_t m_message_size
size of the payload
Definition: net.h:328
std::chrono::microseconds m_time
time of message receipt
Definition: net.h:323
CDataStream m_recv
received message data
Definition: net.h:321
void SetVersion(int nVersionIn)
Definition: net.h:335
uint32_t m_raw_message_size
used wire size of the message (including header/checksum)
Definition: net.h:330
std::string m_command
Definition: net.h:331
bool m_valid_checksum
Definition: net.h:326
bool m_valid_header
Definition: net.h:325
bool m_valid_netmagic
Definition: net.h:324
Information about a peer.
Definition: net.h:443
RecursiveMutex cs_vProcessMsg
Definition: net.h:464
Mutex cs_avalanche_pubkey
Definition: net.h:645
const CAddress addrBind
Definition: net.h:480
bool IsFeelerConn() const
Definition: net.h:543
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend)
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:475
bool ExpectServicesFromConn() const
Definition: net.h:557
bool m_prefer_evict
Definition: net.h:497
std::atomic< int > nVersion
Definition: net.h:485
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:470
std::atomic< double > availabilityScore
The last computed score.
Definition: net.h:854
bool IsInboundConn() const
Definition: net.h:549
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:498
std::atomic_bool fPauseRecv
Definition: net.h:513
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:516
NodeId GetId() const
Definition: net.h:730
bool IsManualConn() const
Definition: net.h:537
std::atomic< int64_t > nTimeOffset
Definition: net.h:476
RecursiveMutex cs_sendProcessing
Definition: net.h:468
const std::string m_addr_name
Definition: net.h:481
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv)
std::string ConnectionTypeAsString() const
Definition: net.h:810
std::deque< std::vector< uint8_t > > vSendMsg GUARDED_BY(cs_vSend)
void SetCommonVersion(int greatest_common_version)
Definition: net.h:752
std::atomic< bool > m_bip152_highbandwidth_to
Definition: net.h:587
const std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:622
std::list< CNetMessage > vRecvMsg
Definition: net.h:840
size_t nProcessQueueSize
Definition: net.h:466
void SetAddrLocal(const CService &addrLocalIn)
May not be called more than once.
Definition: net.cpp:566
std::atomic< bool > m_bip152_highbandwidth_from
Definition: net.h:589
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:725
std::atomic_bool fSuccessfullyConnected
Definition: net.h:505
bool IsAddrFetchConn() const
Definition: net.h:545
uint64_t GetLocalNonce() const
Definition: net.h:732
std::atomic< ServiceFlags > nServices
Definition: net.h:452
const CAddress addr
Definition: net.h:478
RecursiveMutex cs_addrLocal
Definition: net.h:843
CSemaphoreGrant grantOutbound
Definition: net.h:509
Mutex cs_hSocket
Definition: net.h:461
const uint64_t nKeyedNetGroup
Definition: net.h:512
friend struct ConnmanTestMsg
Definition: net.h:445
std::atomic< int > nRefCount
Definition: net.h:510
std::atomic< int > m_greatest_common_version
Definition: net.h:819
bool IsBlockOnlyConn() const
Definition: net.h:539
void CloseSocketDisconnect()
Definition: net.cpp:522
const std::unique_ptr< ProofRelay > m_proof_relay
Definition: net.h:640
int GetCommonVersion() const
Definition: net.h:756
bool IsFullOutboundConn() const
Definition: net.h:532
uint64_t nRemoteHostNonce
Definition: net.h:487
std::unique_ptr< TransportSerializer > m_serializer
Definition: net.h:449
Mutex m_subver_mutex
cleanSubVer is a sanitized string of the user agent byte array we read from the wire.
Definition: net.h:494
bool fClient
Definition: net.h:502
Mutex cs_vSend
Definition: net.h:460
std::atomic_bool fPauseSend
Definition: net.h:514
SOCKET hSocket GUARDED_BY(cs_hSocket)
std::chrono::seconds m_nextGetAvaAddr
Definition: net.h:675
uint64_t nRemoteExtraEntropy
Definition: net.h:489
int GetRefCount() const
Definition: net.h:735
uint64_t GetLocalExtraEntropy() const
Definition: net.h:733
std::list< CNetMessage > vProcessMsg GUARDED_BY(cs_vProcessMsg)
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:836
void PushProofInventory(const avalanche::ProofId &proofid)
Definition: net.h:793
std::optional< CPubKey > m_avalanche_pubkey GUARDED_BY(cs_avalanche_pubkey)
void AddKnownTx(const TxId &txid)
Definition: net.h:769
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:448
double getAvailabilityScore() const
Definition: net.cpp:3425
size_t nSendOffset GUARDED_BY(cs_vSend)
Offset inside the first vSendMsg already sent.
Definition: net.h:457
NetPermissionFlags m_permissionFlags
Definition: net.h:838
const ConnectionType m_conn_type
Definition: net.h:818
Network ConnectedThroughNetwork() const
Get network the peer connected through.
Definition: net.cpp:577
CService addrLocal GUARDED_BY(cs_addrLocal)
const uint64_t nLocalHostNonce
Definition: net.h:816
std::atomic< std::chrono::microseconds > m_last_ping_time
Last measured round-trip time.
Definition: net.h:703
void updateAvailabilityScore(double decayFactor)
The availability score is calculated using an exponentially weighted average.
Definition: net.cpp:3410
size_t nSendSize GUARDED_BY(cs_vSend)
Total size of all vSendMsg entries.
Definition: net.h:455
void copyStats(CNodeStats &stats)
Definition: net.cpp:581
ServiceFlags GetLocalServices() const
Definition: net.h:808
const uint64_t nLocalExtraEntropy
Definition: net.h:817
void invsPolled(uint32_t count)
The node was polled for count invs.
Definition: net.cpp:3402
CNode(const CNode &)=delete
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e.
Definition: net.h:484
std::atomic< std::chrono::microseconds > m_min_ping_time
Lowest measured round-trip time.
Definition: net.h:709
const NodeId id
Definition: net.h:815
std::atomic< std::chrono::seconds > m_last_proof_time
UNIX epoch time of the last proof received from this peer that we had not yet seen (e....
Definition: net.h:700
Mutex cs_vRecv
Definition: net.h:462
std::atomic< bool > m_avalanche_enabled
Definition: net.h:643
std::atomic< std::chrono::seconds > m_last_block_time
UNIX epoch time of the last block received from this peer that we had not yet seen (e....
Definition: net.h:684
~CNode()
Definition: net.cpp:3476
bool m_limited_node
Definition: net.h:504
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:458
std::atomic< uint64_t > invCounters
The inventories polled and voted counters since last score computation, stored as a pair of uint32_t ...
Definition: net.h:851
bool ReceiveMsgBytes(const Config &config, Span< const uint8_t > msg_bytes, bool &complete)
Receive bytes from the buffer and deserialize them into messages.
Definition: net.cpp:641
void PushTxInventory(const TxId &txid)
Definition: net.h:776
std::atomic_bool fDisconnect
Definition: net.h:508
std::atomic< std::chrono::seconds > m_last_recv
Definition: net.h:473
void AddKnownProof(const avalanche::ProofId &proofid)
Definition: net.h:786
CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, uint64_t nLocalExtraEntropyIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
Definition: net.cpp:3431
CService GetAddrLocal() const
Definition: net.cpp:561
std::atomic< std::chrono::seconds > m_last_tx_time
UNIX epoch time of the last transaction received from this peer that we had not yet seen (e....
Definition: net.h:692
void invsVoted(uint32_t count)
The node voted for count invs.
Definition: net.cpp:3406
std::atomic< std::chrono::seconds > m_last_send
Definition: net.h:472
bool IsAvalancheOutboundConnection() const
Definition: net.h:553
void Release()
Definition: net.h:767
CNode & operator=(const CNode &)=delete
std::string cleanSubVer GUARDED_BY(m_subver_mutex)
Definition: net.h:495
CNode * AddRef()
Definition: net.h:762
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:119
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:41
RAII-style semaphore lock.
Definition: sync.h:316
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:544
SipHash-2-4.
Definition: siphash.h:13
A helper class for interruptible sleeps.
Definition: config.h:17
Interface for message handling.
Definition: net.h:863
virtual void InitializeNode(const Config &config, CNode *pnode)=0
Initialize a peer (setup state, queue any initial messages)
virtual bool SendMessages(const Config &config, CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode -> cs_sendProcessing)=0
Send queued protocol messages to a given node.
~NetEventsInterface()=default
Protected destructor so that instances can only be deleted by derived classes.
virtual void FinalizeNode(const Config &config, const CNode &node)=0
Handle removal of a peer (clear state)
virtual bool ProcessMessages(const Config &config, CNode *pnode, std::atomic< bool > &interrupt)=0
Process protocol messages received from a given node.
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:93
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
Definition: span.h:215
The TransportDeserializer takes care of holding and deserializing the network receive buffer.
Definition: net.h:343
virtual ~TransportDeserializer()
Definition: net.h:354
virtual bool Complete() const =0
virtual CNetMessage GetMessage(const Config &config, std::chrono::microseconds time)=0
virtual void SetVersion(int version)=0
virtual int Read(const Config &config, Span< const uint8_t > &msg_bytes)=0
read and deserialize data, advances msg_bytes data pointer
The TransportSerializer prepares messages for the network transport.
Definition: net.h:426
virtual void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header)=0
virtual ~TransportSerializer()
Definition: net.h:433
CNetMessage GetMessage(const Config &config, std::chrono::microseconds time) override
Definition: net.cpp:739
CDataStream vRecv
Definition: net.h:369
CMessageHeader hdr
Definition: net.h:367
const uint256 & GetMessageHash() const
Definition: net.cpp:730
uint32_t nDataPos
Definition: net.h:371
uint32_t nHdrPos
Definition: net.h:370
int Read(const Config &config, Span< const uint8_t > &msg_bytes) override
read and deserialize data, advances msg_bytes data pointer
Definition: net.h:409
void SetVersion(int nVersionIn) override
Definition: net.h:405
int readData(Span< const uint8_t > msg_bytes)
Definition: net.cpp:713
bool Complete() const override
Definition: net.h:397
int readHeader(const Config &config, Span< const uint8_t > msg_bytes)
Definition: net.cpp:680
CHash256 hasher
Definition: net.h:359
V1TransportDeserializer(const CMessageHeader::MessageMagic &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:389
CDataStream hdrbuf
Definition: net.h:365
uint256 data_hash
Definition: net.h:360
void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header) override
Definition: net.cpp:783
void SetNull()
Definition: uint256.h:39
256-bit opaque blob.
Definition: uint256.h:127
unsigned int SOCKET
Definition: compat.h:40
#define LogPrint(category,...)
Definition: logging.h:208
@ NET
Definition: logging.h:39
Definition: init.h:28
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:187
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:205
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.h:129
uint16_t GetListenPort()
Definition: net.cpp:134
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:91
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:307
void RemoveLocal(const CService &addr)
Definition: net.cpp:272
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:67
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:61
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:74
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:239
bool fDiscover
Definition: net.cpp:123
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:105
static const int NUM_FDS_MESSAGE_CAPTURE
Number of file descriptors required for message capture.
Definition: net.h:99
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:95
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:55
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:101
bool fListen
Definition: net.cpp:124
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:53
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:125
static constexpr uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:93
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
Definition: net.h:65
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:104
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:110
static const int DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS
Maximum number of avalanche enabled outgoing connections by default.
Definition: net.h:81
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:278
static const bool DEFAULT_FIXEDSEEDS
Definition: net.h:103
ConnectionType
Different types of connections to a peer.
Definition: net.h:142
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly inputted via the addnode RPC,...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
@ INBOUND
Inbound connections are those initiated by a peer.
@ AVALANCHE_OUTBOUND
Special case of connection to a full relay outbound with avalanche service enabled.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:267
std::string getSubVersionEB(uint64_t MaxBlockSize)
This function convert MaxBlockSize from byte to MB with a decimal precision one digit rounded down E....
Definition: net.cpp:3589
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:83
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:85
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:140
static constexpr auto FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes.
Definition: net.h:63
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:97
std::optional< NodeId > SelectNodeToEvict(std::vector< NodeEvictionCandidate > &&vEvictionCandidates)
Select an inbound peer to evict after filtering out (protecting) peers having distinct,...
Definition: net.cpp:1091
void ProtectEvictionCandidatesByRatio(std::vector< NodeEvictionCandidate > &vEvictionCandidates)
Protect desirable or disadvantaged inbound peers from eviction by ratio.
Definition: net.cpp:996
std::optional< CAddress > GetLocalAddrForPeer(CNode *pnode)
Returns a local address that we should advertise to this peer.
Definition: net.cpp:211
static const bool DEFAULT_DNSSEED
Definition: net.h:102
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:72
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
Definition: net.cpp:540
void CaptureMessage(const CAddress &addr, const std::string &msg_type, const Span< const uint8_t > &data, bool is_incoming)
Dump binary message to file, with timestamp.
Definition: net.cpp:3623
@ LOCAL_NONE
Definition: net.h:217
@ LOCAL_MAPPED
Definition: net.h:223
@ LOCAL_MANUAL
Definition: net.h:225
@ LOCAL_MAX
Definition: net.h:227
@ LOCAL_BIND
Definition: net.h:221
@ LOCAL_IF
Definition: net.h:219
std::string userAgent(const Config &config)
Definition: net.cpp:3603
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:76
void Discover()
Definition: net.cpp:2773
bool IsReachable(enum Network net)
Definition: net.cpp:286
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:296
std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
Return a timestamp in the future (in microseconds) for exponentially distributed events.
Definition: net.cpp:3555
NetPermissionFlags
Network
A network type.
Definition: netaddress.h:44
int64_t NodeId
Definition: nodeid.h:10
ServiceFlags
nServices flags.
Definition: protocol.h:338
@ NODE_NONE
Definition: protocol.h:341
bool fInbound
Definition: net.h:111
CService resolvedAddress
Definition: net.h:109
bool fConnected
Definition: net.h:110
std::string strAddedNode
Definition: net.h:108
Definition: amount.h:19
static constexpr Amount zero()
Definition: amount.h:32
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:1286
std::chrono::microseconds m_cache_entry_expiration
Definition: net.h:1288
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1287
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:1151
ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
Definition: net.h:1154
NetPermissionFlags m_permissions
Definition: net.h:1158
int m_max_outbound_block_relay
Definition: net.h:920
unsigned int nReceiveFloodSize
Definition: net.h:928
int m_max_outbound_full_relay
Definition: net.h:919
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:933
uint64_t nMaxOutboundLimit
Definition: net.h:929
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:932
CClientUIInterface * uiInterface
Definition: net.h:924
int m_max_avalanche_outbound
Definition: net.h:921
std::vector< CService > onion_binds
Definition: net.h:935
int nMaxFeeler
Definition: net.h:923
std::vector< std::string > m_specified_outgoing
Definition: net.h:940
int nMaxConnections
Definition: net.h:918
ServiceFlags nLocalServices
Definition: net.h:917
std::vector< std::string > m_added_nodes
Definition: net.h:941
int64_t m_peer_connect_timeout
Definition: net.h:930
std::vector< CService > vBinds
Definition: net.h:934
unsigned int nSendBufferMaxSize
Definition: net.h:927
bool m_i2p_accept_incoming
Definition: net.h:942
std::vector< std::string > vSeedNodes
Definition: net.h:931
BanMan * m_banman
Definition: net.h:926
bool m_use_addrman_outgoing
Definition: net.h:939
std::vector< NetEventsInterface * > m_msgproc
Definition: net.h:925
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
Definition: net.h:938
int nMaxAddnode
Definition: net.h:922
std::set< avalanche::ProofId > setInventoryProofToSend GUARDED_BY(cs_proof_inventory)
std::chrono::microseconds nextInvSend
Definition: net.h:631
CRollingBloomFilter filterProofKnown GUARDED_BY(cs_proof_inventory)
Definition: net.h:629
RecursiveMutex cs_proof_inventory
Definition: net.h:625
std::atomic< bool > compactproofs_requested
Definition: net.h:636
std::atomic< std::chrono::seconds > lastSharedProofsUpdate
Definition: net.h:635
RadixTree< const avalanche::Proof, avalanche::ProofRadixTreeAdapter > sharedProofs
Definition: net.h:634
CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory)
Definition: net.h:603
std::chrono::microseconds m_next_send_feefilter
Definition: net.h:618
std::chrono::microseconds nNextInvSend
Definition: net.h:613
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:610
std::set< TxId > setInventoryTxToSend GUARDED_BY(cs_tx_inventory)
std::atomic< std::chrono::seconds > m_last_mempool_req
Definition: net.h:612
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:598
RecursiveMutex cs_filter
Definition: net.h:592
RecursiveMutex cs_tx_inventory
Definition: net.h:600
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter)
Definition: net.h:599
Amount lastSentFeeFilter
Definition: net.h:617
std::atomic< Amount > minFeeFilter
Minimum fee rate with which to filter inv's to this node.
Definition: net.h:616
POD that contains various stats about a node.
Definition: net.h:274
std::string addrLocal
Definition: net.h:301
CAddress addrBind
Definition: net.h:305
uint64_t nRecvBytes
Definition: net.h:294
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:293
bool fRelayTxes
Definition: net.h:277
std::chrono::microseconds m_last_ping_time
Definition: net.h:297
uint32_t m_mapped_as
Definition: net.h:308
bool fInbound
Definition: net.h:288
uint64_t nSendBytes
Definition: net.h:292
std::chrono::seconds m_last_recv
Definition: net.h:279
std::optional< double > m_availabilityScore
Definition: net.h:310
std::chrono::seconds m_last_proof_time
Definition: net.h:281
ConnectionType m_conn_type
Definition: net.h:309
std::chrono::seconds m_last_send
Definition: net.h:278
std::chrono::seconds m_last_tx_time
Definition: net.h:280
CAddress addr
Definition: net.h:303
std::chrono::microseconds m_min_ping_time
Definition: net.h:298
ServiceFlags nServices
Definition: net.h:276
int64_t nTimeOffset
Definition: net.h:284
std::chrono::seconds m_connected
Definition: net.h:283
bool m_bip152_highbandwidth_from
Definition: net.h:290
bool m_bip152_highbandwidth_to
Definition: net.h:289
std::string m_addr_name
Definition: net.h:285
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:295
int nVersion
Definition: net.h:286
std::chrono::seconds m_last_block_time
Definition: net.h:282
Network m_network
Definition: net.h:307
NodeId nodeid
Definition: net.h:275
NetPermissionFlags m_permissionFlags
Definition: net.h:296
std::string cleanSubVer
Definition: net.h:287
int m_starting_height
Definition: net.h:291
Amount minFeeFilter
Definition: net.h:299
CSerializedNetMsg(const CSerializedNetMsg &msg)=delete
std::vector< uint8_t > data
Definition: net.h:125
std::string m_type
Definition: net.h:126
CSerializedNetMsg & operator=(const CSerializedNetMsg &)=delete
CSerializedNetMsg()=default
CSerializedNetMsg(CSerializedNetMsg &&)=default
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
uint16_t nPort
Definition: net.h:258
int nScore
Definition: net.h:257
std::chrono::seconds m_last_tx_time
Definition: net.h:1431
Network m_network
Definition: net.h:1438
double availabilityScore
Definition: net.h:1439
std::chrono::seconds m_connected
Definition: net.h:1427
std::chrono::seconds m_last_block_time
Definition: net.h:1429
bool fRelevantServices
Definition: net.h:1432
std::chrono::microseconds m_min_ping_time
Definition: net.h:1428
std::chrono::seconds m_last_proof_time
Definition: net.h:1430
uint64_t nKeyedNetGroup
Definition: net.h:1435
A TxId is the identifier of a transaction.
Definition: txid.h:14
Bilingual messages:
Definition: translation.h:17
#define LOCK(cs)
Definition: sync.h:243
static int count
Definition: tests.c:31
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
assert(!tx.IsCoinBase())
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Definition: version.h:14