Bitcoin ABC  0.26.2
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 <addrdb.h>
11 #include <addrman.h>
12 #include <amount.h>
13 #include <avalanche/proofid.h>
15 #include <bloom.h>
16 #include <chainparams.h>
17 #include <compat.h>
18 #include <crypto/siphash.h>
19 #include <hash.h>
20 #include <i2p.h>
21 #include <net_permissions.h>
22 #include <netaddress.h>
23 #include <nodeid.h>
24 #include <protocol.h>
25 #include <pubkey.h>
26 #include <radix.h>
27 #include <random.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 <map>
40 #include <memory>
41 #include <thread>
42 #include <vector>
43 
44 class BanMan;
45 class Config;
46 class CNode;
47 class CScheduler;
48 struct bilingual_str;
49 
51 static const bool DEFAULT_WHITELISTRELAY = true;
53 static const bool DEFAULT_WHITELISTFORCERELAY = false;
54 
59 static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
61 static constexpr auto FEELER_INTERVAL = 2min;
63 static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
65 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
72 static const int MAX_ADDNODE_CONNECTIONS = 8;
74 static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
81 static const int MAX_FEELER_CONNECTIONS = 1;
83 static const bool DEFAULT_LISTEN = true;
85 #ifdef USE_UPNP
86 static const bool DEFAULT_UPNP = USE_UPNP;
87 #else
88 static const bool DEFAULT_UPNP = false;
89 #endif
95 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 4096;
97 static constexpr uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
99 static const bool DEFAULT_BLOCKSONLY = false;
101 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
102 
103 static const bool DEFAULT_FORCEDNSSEED = false;
104 static const bool DEFAULT_DNSSEED = true;
105 static const bool DEFAULT_FIXEDSEEDS = true;
106 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
107 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
108 
110 static constexpr std::chrono::minutes AVALANCHE_STATISTICS_REFRESH_PERIOD{10};
112 static constexpr std::chrono::minutes AVALANCHE_STATISTICS_TIME_CONSTANT{10};
118  1. - std::exp(-1. * AVALANCHE_STATISTICS_REFRESH_PERIOD.count() /
120 
122  std::string strAddedNode;
125  bool fInbound;
126 };
127 
128 struct CNodeStats;
129 class CClientUIInterface;
130 
132  CSerializedNetMsg() = default;
135  // No copying, only moves.
136  CSerializedNetMsg(const CSerializedNetMsg &msg) = delete;
138 
139  std::vector<uint8_t> data;
140  std::string m_type;
141 };
142 
143 const std::vector<std::string> CONNECTION_TYPE_DOC{
144  "outbound-full-relay (default automatic connections)",
145  "block-relay-only (does not relay transactions or addresses)",
146  "inbound (initiated by the peer)",
147  "manual (added via addnode RPC or -addnode/-connect configuration options)",
148  "addr-fetch (short-lived automatic connection for soliciting addresses)",
149  "feeler (short-lived automatic connection for testing addresses)"};
150 
156 enum class ConnectionType {
162  INBOUND,
163 
171 
178  MANUAL,
179 
196  FEELER,
197 
207  BLOCK_RELAY,
208 
215  ADDR_FETCH,
216 
222 };
223 
224 void Discover();
225 void StartMapPort();
226 void InterruptMapPort();
227 void StopMapPort();
228 uint16_t GetListenPort();
229 
230 enum {
231  // unknown
233  // address a local interface listens on
235  // address explicit bound to
237  // address reported by UPnP
239  // address explicitly specified (-externalip=)
241 
242  LOCAL_MAX
243 };
244 
245 bool IsPeerAddrLocalGood(CNode *pnode);
247 std::optional<CAddress> GetLocalAddrForPeer(CNode *pnode);
248 
253 void SetReachable(enum Network net, bool reachable);
255 bool IsReachable(enum Network net);
257 bool IsReachable(const CNetAddr &addr);
258 
259 bool AddLocal(const CService &addr, int nScore = LOCAL_NONE);
260 bool AddLocal(const CNetAddr &addr, int nScore = LOCAL_NONE);
261 void RemoveLocal(const CService &addr);
262 bool SeenLocal(const CService &addr);
263 bool IsLocal(const CService &addr);
264 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
265 CAddress GetLocalAddress(const CNetAddr *paddrPeer,
266  ServiceFlags nLocalServices);
267 
268 extern bool fDiscover;
269 extern bool fListen;
270 
272  int nScore;
273  uint16_t nPort;
274 };
275 
277 extern std::map<CNetAddr, LocalServiceInfo>
279 
280 extern const std::string NET_MESSAGE_COMMAND_OTHER;
281 // Command, total bytes
282 typedef std::map<std::string, uint64_t> mapMsgCmdSize;
283 
289 struct CNodeStats {
293  std::chrono::seconds m_last_send;
294  std::chrono::seconds m_last_recv;
295  std::chrono::seconds m_last_tx_time;
296  std::chrono::seconds m_last_proof_time;
297  std::chrono::seconds m_last_block_time;
298  std::chrono::seconds m_connected;
299  int64_t nTimeOffset;
300  std::string addrName;
301  int nVersion;
302  std::string cleanSubVer;
303  bool fInbound;
308  uint64_t nSendBytes;
310  uint64_t nRecvBytes;
314  std::chrono::microseconds m_last_ping_time;
315  std::chrono::microseconds m_min_ping_time;
317  // Our address, as reported by the peer
318  std::string addrLocal;
319  // Address of this peer
321  // Bind address of our side of the connection
323  // Network the peer connected through
325  uint32_t m_mapped_as;
326  std::string m_conn_type_string;
327  std::optional<double> m_availabilityScore;
328 };
329 
335 class CNetMessage {
336 public:
340  std::chrono::microseconds m_time{0};
341  bool m_valid_netmagic = false;
342  bool m_valid_header = false;
343  bool m_valid_checksum = false;
345  uint32_t m_message_size{0};
347  uint32_t m_raw_message_size{0};
348  std::string m_command;
349 
350  CNetMessage(CDataStream &&recv_in) : m_recv(std::move(recv_in)) {}
351 
352  void SetVersion(int nVersionIn) { m_recv.SetVersion(nVersionIn); }
353 };
354 
361 public:
362  // returns true if the current deserialization is complete
363  virtual bool Complete() const = 0;
364  // set the serialization context version
365  virtual void SetVersion(int version) = 0;
367  virtual int Read(const Config &config, Span<const uint8_t> &msg_bytes) = 0;
368  // decomposes a message from the context
369  virtual CNetMessage GetMessage(const Config &config,
370  std::chrono::microseconds time) = 0;
372 };
373 
375 private:
376  mutable CHash256 hasher;
378 
379  // Parsing header (false) or data (true)
380  bool in_data;
381  // Partially received header.
383  // Complete header.
385  // Received message data.
387  uint32_t nHdrPos;
388  uint32_t nDataPos;
389 
390  const uint256 &GetMessageHash() const;
391  int readHeader(const Config &config, Span<const uint8_t> msg_bytes);
392  int readData(Span<const uint8_t> msg_bytes);
393 
394  void Reset() {
395  vRecv.clear();
396  hdrbuf.clear();
397  hdrbuf.resize(24);
398  in_data = false;
399  nHdrPos = 0;
400  nDataPos = 0;
401  data_hash.SetNull();
402  hasher.Reset();
403  }
404 
405 public:
407  const CMessageHeader::MessageMagic &pchMessageStartIn, int nTypeIn,
408  int nVersionIn)
409  : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn),
410  vRecv(nTypeIn, nVersionIn) {
411  Reset();
412  }
413 
414  bool Complete() const override {
415  if (!in_data) {
416  return false;
417  }
418 
419  return (hdr.nMessageSize == nDataPos);
420  }
421 
422  void SetVersion(int nVersionIn) override {
423  hdrbuf.SetVersion(nVersionIn);
424  vRecv.SetVersion(nVersionIn);
425  }
426  int Read(const Config &config, Span<const uint8_t> &msg_bytes) override {
427  int ret = in_data ? readData(msg_bytes) : readHeader(config, msg_bytes);
428  if (ret < 0) {
429  Reset();
430  } else {
431  msg_bytes = msg_bytes.subspan(ret);
432  }
433  return ret;
434  }
435 
436  CNetMessage GetMessage(const Config &config,
437  std::chrono::microseconds time) override;
438 };
439 
444 public:
445  // prepare message for transport (header construction, error-correction
446  // computation, payload encryption, etc.)
447  virtual void prepareForTransport(const Config &config,
448  CSerializedNetMsg &msg,
449  std::vector<uint8_t> &header) = 0;
450  virtual ~TransportSerializer() {}
451 };
452 
454 public:
455  void prepareForTransport(const Config &config, CSerializedNetMsg &msg,
456  std::vector<uint8_t> &header) override;
457 };
458 
460 class CNode {
461  friend class CConnman;
462  friend struct ConnmanTestMsg;
463 
464 public:
465  std::unique_ptr<TransportDeserializer> m_deserializer;
466  std::unique_ptr<TransportSerializer> m_serializer;
467 
468  // socket
469  std::atomic<ServiceFlags> nServices{NODE_NONE};
471  // Total size of all vSendMsg entries.
472  size_t nSendSize{0};
473  // Offset inside the first vSendMsg already sent.
474  size_t nSendOffset{0};
475  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
476  std::deque<std::vector<uint8_t>> vSendMsg GUARDED_BY(cs_vSend);
480 
482  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
483  size_t nProcessQueueSize{0};
484 
486 
487  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
488 
489  std::atomic<std::chrono::seconds> m_last_send{0s};
490  std::atomic<std::chrono::seconds> m_last_recv{0s};
492  const std::chrono::seconds m_connected;
493  std::atomic<int64_t> nTimeOffset{0};
494  // Address of this peer
495  const CAddress addr;
496  // Bind address of our side of the connection
500  const bool m_inbound_onion;
501  std::atomic<int> nVersion{0};
502  // The nonce provided by the remote host.
503  uint64_t nRemoteHostNonce{0};
504  // The extra entropy provided by the remote host.
505  uint64_t nRemoteExtraEntropy{0};
511  std::string cleanSubVer GUARDED_BY(cs_SubVer){};
512  // This peer is preferred for eviction.
513  bool m_prefer_evict{false};
514  bool HasPermission(NetPermissionFlags permission) const {
515  return NetPermissions::HasFlag(m_permissionFlags, permission);
516  }
517  // This boolean is unusued in actual processing, only present for backward
518  // compatibility at RPC/QT level
519  bool m_legacyWhitelisted{false};
520  // set by version message
521  bool fClient{false};
522  // after BIP159, set by version message
523  bool m_limited_node{false};
524  std::atomic_bool fSuccessfullyConnected{false};
525  // Setting fDisconnect to true will cause the node to be disconnected the
526  // next time DisconnectNodes() runs
527  std::atomic_bool fDisconnect{false};
529  std::atomic<int> nRefCount{0};
530 
531  const uint64_t nKeyedNetGroup;
532  std::atomic_bool fPauseRecv{false};
533  std::atomic_bool fPauseSend{false};
534 
536  switch (m_conn_type) {
540  return true;
545  return false;
546  } // no default case, so the compiler can warn about missing cases
547 
548  assert(false);
549  }
550 
551  bool IsFullOutboundConn() const {
554  }
555 
556  bool IsManualConn() const { return m_conn_type == ConnectionType::MANUAL; }
557 
558  bool IsBlockOnlyConn() const {
560  }
561 
562  bool IsFeelerConn() const { return m_conn_type == ConnectionType::FEELER; }
563 
564  bool IsAddrFetchConn() const {
566  }
567 
568  bool IsInboundConn() const {
570  }
571 
574  }
575 
576  bool ExpectServicesFromConn() const {
577  switch (m_conn_type) {
581  return false;
586  return true;
587  } // no default case, so the compiler can warn about missing cases
588 
589  assert(false);
590  }
591 
604 
605 protected:
607  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
608 
609 public:
610  // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
611  std::atomic<bool> m_bip152_highbandwidth_to{false};
612  // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
613  std::atomic<bool> m_bip152_highbandwidth_from{false};
614 
615  struct TxRelay {
617  // We use fRelayTxes for two purposes -
618  // a) it allows us to not relay tx invs before receiving the peer's
619  // version message.
620  // b) the peer may tell us in its version message that we should not
621  // relay tx invs unless it loads a bloom filter.
622  bool fRelayTxes GUARDED_BY(cs_filter){false};
623  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter)
624  GUARDED_BY(cs_filter){nullptr};
625 
628  50000, 0.000001};
629  // Set of transaction ids we still have to announce.
630  // They are sorted by the mempool before relay, so the order is not
631  // important.
632  std::set<TxId> setInventoryTxToSend GUARDED_BY(cs_tx_inventory);
633  // Used for BIP35 mempool sending
634  bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
635  // Last time a "MEMPOOL" request was serviced.
636  std::atomic<std::chrono::seconds> m_last_mempool_req{0s};
637  std::chrono::microseconds nNextInvSend{0};
638 
640  // Minimum fee rate with which to filter inv's to this node
643  std::chrono::microseconds m_next_send_feefilter{0};
644  };
645 
646  // m_tx_relay == nullptr if we're not relaying transactions with this peer
647  const std::unique_ptr<TxRelay> m_tx_relay;
648 
649  struct ProofRelay {
651  std::set<avalanche::ProofId>
652  setInventoryProofToSend GUARDED_BY(cs_proof_inventory);
653  // Prevent sending proof invs if the peer already knows about them
655  10000, 0.000001};
656  std::chrono::microseconds nextInvSend{0};
657 
660  std::atomic<std::chrono::seconds> lastSharedProofsUpdate{0s};
661  std::atomic<bool> compactproofs_requested{false};
662  };
663 
664  // m_proof_relay == nullptr if we're not relaying proofs with this peer
665  const std::unique_ptr<ProofRelay> m_proof_relay;
666 
673  std::atomic<uint64_t> invCounters;
674 
676  std::atomic<double> availabilityScore;
677 
683 
684  public:
686 
688 
690  void invsPolled(uint32_t count);
691 
693  void invsVoted(uint32_t count);
694 
712 
713  double getAvailabilityScore() const;
714  };
715 
716  // m_avalanche_state == nullptr if we're not using avalanche with this peer
717  std::unique_ptr<AvalancheState> m_avalanche_state;
718 
719  // Store the next time we will consider a getavaaddr message from this peer
720  std::chrono::seconds m_nextGetAvaAddr{0};
721 
729  std::atomic<std::chrono::seconds> m_last_block_time{0s};
730 
737  std::atomic<std::chrono::seconds> m_last_tx_time{0s};
738 
745  std::atomic<std::chrono::seconds> m_last_proof_time{0s};
746 
748  std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
749 
754  std::atomic<std::chrono::microseconds> m_min_ping_time{
755  std::chrono::microseconds::max()};
756 
757  CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
758  const CAddress &addrIn, uint64_t nKeyedNetGroupIn,
759  uint64_t nLocalHostNonceIn, uint64_t nLocalExtraEntropyIn,
760  const CAddress &addrBindIn, const std::string &addrNameIn,
761  ConnectionType conn_type_in, bool inbound_onion);
762  ~CNode();
763  CNode(const CNode &) = delete;
764  CNode &operator=(const CNode &) = delete;
765 
770  void PongReceived(std::chrono::microseconds ping_time) {
771  m_last_ping_time = ping_time;
772  m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
773  }
774 
775 private:
776  const NodeId id;
777  const uint64_t nLocalHostNonce;
778  const uint64_t nLocalExtraEntropy;
781 
798 
800  // Used only by SocketHandler thread
801  std::list<CNetMessage> vRecvMsg;
802 
804  std::string addrName GUARDED_BY(cs_addrName);
805 
806  // Our address, as reported by the peer
809 
810 public:
811  NodeId GetId() const { return id; }
812 
813  uint64_t GetLocalNonce() const { return nLocalHostNonce; }
814  uint64_t GetLocalExtraEntropy() const { return nLocalExtraEntropy; }
815 
816  int GetRefCount() const {
817  assert(nRefCount >= 0);
818  return nRefCount;
819  }
820 
830  bool ReceiveMsgBytes(const Config &config, Span<const uint8_t> msg_bytes,
831  bool &complete);
832 
833  void SetCommonVersion(int greatest_common_version) {
835  m_greatest_common_version = greatest_common_version;
836  }
838 
839  CService GetAddrLocal() const;
841  void SetAddrLocal(const CService &addrLocalIn);
842 
844  nRefCount++;
845  return this;
846  }
847 
848  void Release() { nRefCount--; }
849 
850  void AddKnownTx(const TxId &txid) {
851  if (m_tx_relay != nullptr) {
852  LOCK(m_tx_relay->cs_tx_inventory);
853  m_tx_relay->filterInventoryKnown.insert(txid);
854  }
855  }
856 
857  void PushTxInventory(const TxId &txid) {
858  if (m_tx_relay == nullptr) {
859  return;
860  }
861  LOCK(m_tx_relay->cs_tx_inventory);
862  if (!m_tx_relay->filterInventoryKnown.contains(txid)) {
863  m_tx_relay->setInventoryTxToSend.insert(txid);
864  }
865  }
866 
867  void AddKnownProof(const avalanche::ProofId &proofid) {
868  if (m_proof_relay != nullptr) {
869  LOCK(m_proof_relay->cs_proof_inventory);
870  m_proof_relay->filterProofKnown.insert(proofid);
871  }
872  }
873 
874  void PushProofInventory(const avalanche::ProofId &proofid) {
875  if (m_proof_relay == nullptr) {
876  return;
877  }
878 
879  LOCK(m_proof_relay->cs_proof_inventory);
880  if (!m_proof_relay->filterProofKnown.contains(proofid)) {
881  m_proof_relay->setInventoryProofToSend.insert(proofid);
882  }
883  }
884 
885  void CloseSocketDisconnect();
886 
887  void copyStats(CNodeStats &stats);
888 
890 
891  std::string GetAddrName() const;
893  void MaybeSetAddrName(const std::string &addrNameIn);
894 
895  std::string ConnectionTypeAsString() const;
896 };
897 
902 public:
904  virtual void InitializeNode(const Config &config, CNode *pnode) = 0;
905 
907  virtual void FinalizeNode(const Config &config, const CNode &node,
908  bool &update_connection_time) = 0;
909 
919  virtual bool ProcessMessages(const Config &config, CNode *pnode,
920  std::atomic<bool> &interrupt) = 0;
921 
929  virtual bool SendMessages(const Config &config, CNode *pnode)
930  EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_sendProcessing) = 0;
931 
932 protected:
938  ~NetEventsInterface() = default;
939 };
940 
941 namespace {
942 struct CConnmanTest;
943 }
944 
945 class NetEventsInterface;
946 class CConnman {
947 public:
950  CONNECTIONS_IN = (1U << 0),
951  CONNECTIONS_OUT = (1U << 1),
953  };
954 
955  struct Options {
961  int nMaxAddnode = 0;
962  int nMaxFeeler = 0;
964  std::vector<NetEventsInterface *> m_msgproc;
965  BanMan *m_banman = nullptr;
966  unsigned int nSendBufferMaxSize = 0;
967  unsigned int nReceiveFloodSize = 0;
968  uint64_t nMaxOutboundLimit = 0;
970  std::vector<std::string> vSeedNodes;
971  std::vector<NetWhitelistPermissions> vWhitelistedRange;
972  std::vector<NetWhitebindPermissions> vWhiteBinds;
973  std::vector<CService> vBinds;
974  std::vector<CService> onion_binds;
976  std::vector<std::string> m_specified_outgoing;
977  std::vector<std::string> m_added_nodes;
979  };
980 
981  void Init(const Options &connOptions) {
982  nLocalServices = connOptions.nLocalServices;
983  nMaxConnections = connOptions.nMaxConnections;
985  nMaxAddnode = connOptions.nMaxAddnode;
986  nMaxFeeler = connOptions.nMaxFeeler;
987  {
988  // Lock cs_main to prevent a potential race with the peer validation
989  // logic thread.
990  LOCK(::cs_main);
992  std::min(connOptions.m_max_outbound_full_relay,
993  connOptions.nMaxConnections);
999  }
1000  clientInterface = connOptions.uiInterface;
1001  m_banman = connOptions.m_banman;
1002  m_msgproc = connOptions.m_msgproc;
1003  nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
1004  nReceiveFloodSize = connOptions.nReceiveFloodSize;
1006  std::chrono::seconds{connOptions.m_peer_connect_timeout};
1007  {
1009  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
1010  }
1011  vWhitelistedRange = connOptions.vWhitelistedRange;
1012  {
1014  vAddedNodes = connOptions.m_added_nodes;
1015  }
1016  m_onion_binds = connOptions.onion_binds;
1017  }
1018 
1019  CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1,
1020  bool network_active = true);
1021  ~CConnman();
1022 
1023  bool Start(CScheduler &scheduler, const Options &options);
1024 
1025  void StopThreads();
1026  void StopNodes();
1027  void Stop() {
1028  StopThreads();
1029  StopNodes();
1030  };
1031 
1032  void Interrupt();
1033  bool GetNetworkActive() const { return fNetworkActive; };
1035  void SetNetworkActive(bool active);
1036  void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure,
1037  CSemaphoreGrant *grantOutbound,
1038  const char *strDest, ConnectionType conn_type);
1039  bool CheckIncomingNonce(uint64_t nonce);
1040 
1041  bool ForNode(NodeId id, std::function<bool(CNode *pnode)> func);
1042 
1043  void PushMessage(CNode *pnode, CSerializedNetMsg &&msg);
1044 
1045  using NodeFn = std::function<void(CNode *)>;
1046  void ForEachNode(const NodeFn &func) {
1047  LOCK(cs_vNodes);
1048  for (auto &&node : vNodes) {
1049  if (NodeFullyConnected(node)) {
1050  func(node);
1051  }
1052  }
1053  };
1054 
1055  void ForEachNode(const NodeFn &func) const {
1056  LOCK(cs_vNodes);
1057  for (auto &&node : vNodes) {
1058  if (NodeFullyConnected(node)) {
1059  func(node);
1060  }
1061  }
1062  };
1063 
1064  // Addrman functions
1065  void SetServices(const CService &addr, ServiceFlags nServices);
1066  void MarkAddressGood(const CAddress &addr);
1067  bool AddNewAddresses(const std::vector<CAddress> &vAddr,
1068  const CAddress &addrFrom, int64_t nTimePenalty = 0);
1079  std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct,
1080  std::optional<Network> network);
1087  std::vector<CAddress> GetAddresses(CNode &requestor, size_t max_addresses,
1088  size_t max_pct);
1089 
1090  // This allows temporarily exceeding m_max_outbound_full_relay, with the
1091  // goal of finding a peer that is better than all our current peers.
1092  void SetTryNewOutboundPeer(bool flag);
1093  bool GetTryNewOutboundPeer();
1094 
1096  LogPrint(BCLog::NET, "net: enabling extra block-relay-only peers\n");
1098  }
1099 
1100  // Return the number of outbound peers we have in excess of our target (eg,
1101  // if we previously called SetTryNewOutboundPeer(true), and have since set
1102  // to false, we may have extra peers that we wish to disconnect). This may
1103  // return a value less than (num_outbound_connections - num_outbound_slots)
1104  // in cases where some outbound connections are not yet fully connected, or
1105  // not yet fully disconnected.
1107  // Count the number of block-relay-only peers we have over our limit.
1109 
1110  bool AddNode(const std::string &node);
1111  bool RemoveAddedNode(const std::string &node);
1112  std::vector<AddedNodeInfo> GetAddedNodeInfo();
1113 
1128  bool AddConnection(const std::string &address, ConnectionType conn_type);
1129 
1130  size_t GetNodeCount(NumConnections num);
1131  void GetNodeStats(std::vector<CNodeStats> &vstats);
1132  bool DisconnectNode(const std::string &node);
1133  bool DisconnectNode(const CSubNet &subnet);
1134  bool DisconnectNode(const CNetAddr &addr);
1135  bool DisconnectNode(NodeId id);
1136 
1144 
1145  uint64_t GetMaxOutboundTarget();
1146  std::chrono::seconds GetMaxOutboundTimeframe();
1147 
1151  bool OutboundTargetReached(bool historicalBlockServingLimit);
1152 
1155  uint64_t GetOutboundTargetBytesLeft();
1156 
1159  std::chrono::seconds GetMaxOutboundTimeLeftInCycle();
1160 
1161  uint64_t GetTotalBytesRecv();
1162  uint64_t GetTotalBytesSent();
1163 
1165  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
1166 
1167  unsigned int GetReceiveFloodSize() const;
1168 
1169  void WakeMessageHandler();
1170 
1176  std::chrono::microseconds
1177  PoissonNextSendInbound(std::chrono::microseconds now,
1178  std::chrono::seconds average_interval);
1179 
1180  void SetAsmap(std::vector<bool> asmap) {
1181  addrman.m_asmap = std::move(asmap);
1182  }
1183 
1188  bool ShouldRunInactivityChecks(const CNode &node,
1189  std::chrono::seconds now) const;
1190 
1191 private:
1192  struct ListenSocket {
1193  public:
1197  }
1198  ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
1199  : socket(socket_), m_permissions(permissions_) {}
1200 
1201  private:
1203  };
1204 
1205  bool BindListenPort(const CService &bindAddr, bilingual_str &strError,
1206  NetPermissionFlags permissions);
1207  bool Bind(const CService &addr, unsigned int flags,
1208  NetPermissionFlags permissions);
1209  bool InitBinds(const std::vector<CService> &binds,
1210  const std::vector<NetWhitebindPermissions> &whiteBinds,
1211  const std::vector<CService> &onion_binds);
1212 
1214  void AddAddrFetch(const std::string &strDest);
1215  void ProcessAddrFetch();
1216  void
1217  ThreadOpenConnections(std::vector<std::string> connect,
1218  std::function<void(const CAddress &, ConnectionType)>
1219  mockOpenConnection);
1220  void ThreadMessageHandler();
1221  void ThreadI2PAcceptIncoming();
1222  void AcceptConnection(const ListenSocket &hListenSocket);
1223 
1232  void CreateNodeFromAcceptedSocket(SOCKET hSocket,
1233  NetPermissionFlags permissionFlags,
1234  const CAddress &addr_bind,
1235  const CAddress &addr);
1236 
1237  void DisconnectNodes();
1240  bool InactivityCheck(const CNode &node) const;
1241  bool GenerateSelectSet(std::set<SOCKET> &recv_set,
1242  std::set<SOCKET> &send_set,
1243  std::set<SOCKET> &error_set);
1244  void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set,
1245  std::set<SOCKET> &error_set);
1246  void SocketHandler();
1247  void ThreadSocketHandler();
1248  void ThreadDNSAddressSeed();
1249 
1250  uint64_t CalculateKeyedNetGroup(const CAddress &ad) const;
1251 
1252  CNode *FindNode(const CNetAddr &ip);
1253  CNode *FindNode(const CSubNet &subNet);
1254  CNode *FindNode(const std::string &addrName);
1255  CNode *FindNode(const CService &addr);
1256 
1261  bool AlreadyConnectedToAddress(const CAddress &addr);
1262 
1263  bool AttemptToEvictConnection();
1264  CNode *ConnectNode(CAddress addrConnect, const char *pszDest,
1265  bool fCountFailure, ConnectionType conn_type);
1267  const CNetAddr &addr) const;
1268 
1269  void DeleteNode(CNode *pnode);
1270 
1271  NodeId GetNewNodeId();
1272 
1273  size_t SocketSendData(CNode &node) const
1274  EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1275  void DumpAddresses();
1276 
1277  // Network stats
1278  void RecordBytesRecv(uint64_t bytes);
1279  void RecordBytesSent(uint64_t bytes);
1280 
1284  std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1285 
1286  // Whether the node should be passed out in ForEach* callbacks
1287  static bool NodeFullyConnected(const CNode *pnode);
1288 
1289  const Config *config;
1290 
1291  // Network usage totals
1294  uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv){0};
1295  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent){0};
1296 
1297  // outbound limit & stats
1298  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent){0};
1299  std::chrono::seconds
1300  nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent){0};
1301  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
1302 
1303  // P2P timeout in seconds
1304  std::chrono::seconds m_peer_connect_timeout;
1305 
1306  // Whitelisted ranges. Any node connecting from these is automatically
1307  // whitelisted (as well as those connecting to whitelisted binds).
1308  std::vector<NetWhitelistPermissions> vWhitelistedRange;
1309 
1310  unsigned int nSendBufferMaxSize{0};
1311  unsigned int nReceiveFloodSize{0};
1312 
1313  std::vector<ListenSocket> vhListenSocket;
1314  std::atomic<bool> fNetworkActive{true};
1317  std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1319  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
1321  std::vector<CNode *> vNodes GUARDED_BY(cs_vNodes);
1322  std::list<CNode *> vNodesDisconnected;
1324  std::atomic<NodeId> nLastNodeId{0};
1325  unsigned int nPrevNodeCount{0};
1326 
1334  std::vector<CAddress> m_addrs_response_cache;
1335  std::chrono::microseconds m_cache_entry_expiration{0};
1336  };
1337 
1352  std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1353 
1367 
1368  std::unique_ptr<CSemaphore> semOutbound;
1369  std::unique_ptr<CSemaphore> semAddnode;
1371 
1372  // How many full-relay (tx, block, addr) outbound peers we want
1374 
1375  // How many block-relay only outbound peers we want
1376  // We do not relay tx or addr messages with these peers
1378 
1379  // How many avalanche enabled outbound peers we want
1381 
1387  // FIXME m_msgproc is a terrible name
1388  std::vector<NetEventsInterface *> m_msgproc;
1394 
1399  std::vector<CAddress> m_anchors;
1400 
1402  const uint64_t nSeed0, nSeed1;
1403 
1405  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1406 
1407  std::condition_variable condMsgProc;
1409  std::atomic<bool> flagInterruptMsgProc{false};
1410 
1418 
1423  std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1424 
1426  std::thread threadSocketHandler;
1431 
1437 
1443  std::atomic_bool m_start_extra_block_relay_peers{false};
1444 
1445  std::atomic<std::chrono::microseconds> m_next_send_inv_to_incoming{0us};
1446 
1451  std::vector<CService> m_onion_binds;
1452 
1453  friend struct ::CConnmanTest;
1454  friend struct ConnmanTestMsg;
1455 };
1456 
1461 std::chrono::microseconds
1462 PoissonNextSend(std::chrono::microseconds now,
1463  std::chrono::seconds average_interval);
1464 
1465 std::string getSubVersionEB(uint64_t MaxBlockSize);
1466 std::string userAgent(const Config &config);
1467 
1470  std::chrono::seconds m_connected;
1471  std::chrono::microseconds m_min_ping_time;
1472  std::chrono::seconds m_last_block_time;
1473  std::chrono::seconds m_last_proof_time;
1474  std::chrono::seconds m_last_tx_time;
1478  uint64_t nKeyedNetGroup;
1483 };
1484 
1492 [[nodiscard]] std::optional<NodeId>
1493 SelectNodeToEvict(std::vector<NodeEvictionCandidate> &&vEvictionCandidates);
1494 
1518  std::vector<NodeEvictionCandidate> &vEvictionCandidates);
1519 
1520 #endif // BITCOIN_NET_H
int flags
Definition: bitcoin-tx.cpp:533
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:91
#define Assume(val)
Assume is the identity function.
Definition: check.h:76
Definition: banman.h:58
Stochastical (IP) address manager.
Definition: addrman.h:191
std::vector< bool > m_asmap
Definition: addrman.h:370
A CService with information about it as peer.
Definition: protocol.h:445
Signals for UI communication.
Definition: ui_interface.h:24
Definition: net.h:946
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 vNodes member...
Definition: net.cpp:1299
std::condition_variable condMsgProc
Definition: net.h:1407
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1295
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1300
std::thread threadMessageHandler
Definition: net.h:1429
void ForEachNode(const NodeFn &func)
Definition: net.h:1046
void ThreadOpenAddedConnections()
Definition: net.cpp:2663
bool GetTryNewOutboundPeer()
Definition: net.cpp:2200
size_t SocketSendData(CNode &node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend)
Definition: net.cpp:823
void SocketHandler()
Definition: net.cpp:1779
void ForEachNode(const NodeFn &func) const
Definition: net.h:1055
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3704
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1426
bool InitBinds(const std::vector< CService > &binds, const std::vector< NetWhitebindPermissions > &whiteBinds, const std::vector< CService > &onion_binds)
Definition: net.cpp:3016
CNode * ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type)
Definition: net.cpp:389
void DeleteNode(CNode *pnode)
Definition: net.cpp:3296
bool AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:3321
bool AttemptToEvictConnection()
Try to find a connection to evict when the node is full.
Definition: net.cpp:1210
bool GetNetworkActive() const
Definition: net.h:1033
bool AlreadyConnectedToAddress(const CAddress &addr)
Determine whether we're already connected to a given address, in order to avoid initiating duplicate ...
Definition: net.cpp:357
int m_max_outbound
Definition: net.h:1384
void AddAddrFetch(const std::string &strDest)
Definition: net.cpp:134
RecursiveMutex cs_vNodes
Definition: net.h:1323
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:1366
size_t GetNodeCount(NumConnections num)
Definition: net.cpp:3417
void Stop()
Definition: net.h:1027
int m_max_outbound_block_relay
Definition: net.h:1377
void ProcessAddrFetch()
Definition: net.cpp:2182
std::thread threadI2PAcceptIncoming
Definition: net.h:1430
CAddrMan addrman
Definition: net.h:1316
void SetTryNewOutboundPeer(bool flag)
Definition: net.cpp:2204
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:1409
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:3584
uint64_t GetTotalBytesRecv()
Definition: net.cpp:3570
std::list< CNode * > vNodesDisconnected
Definition: net.h:1322
void SocketEvents(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1696
NodeId GetNewNodeId()
Definition: net.cpp:2990
std::vector< std::string > vAddedNodes GUARDED_BY(cs_vAddedNodes)
CThreadInterrupt interruptNet
This is signaled when network activity should cease.
Definition: net.h:1417
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:1369
std::atomic< NodeId > nLastNodeId
Definition: net.h:1324
void SetServices(const CService &addr, ServiceFlags nServices)
Definition: net.cpp:3313
std::atomic< std::chrono::microseconds > m_next_send_inv_to_incoming
Definition: net.h:1445
uint64_t GetOutboundTargetBytesLeft()
response the bytes left in the current max outbound cycle in case of no limit, it will always respons...
Definition: net.cpp:3559
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:3496
std::chrono::seconds GetMaxOutboundTimeLeftInCycle()
returns the time in second left in the current max outbound cycle in case of no limit,...
Definition: net.cpp:3520
bool fMsgProcWake GUARDED_BY(mutexMsgProc)
flag for waking the message processor.
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1393
void Interrupt()
Definition: net.cpp:3207
std::thread threadDNSAddressSeed
Definition: net.h:1425
void ThreadOpenConnections(std::vector< std::string > connect, std::function< void(const CAddress &, ConnectionType)> mockOpenConnection)
Definition: net.cpp:2246
void ThreadI2PAcceptIncoming()
Definition: net.cpp:2803
int GetExtraBlockRelayCount()
Definition: net.cpp:2232
const uint64_t nSeed1
Definition: net.h:1402
void StartExtraBlockRelayPeers()
Definition: net.h:1095
std::vector< CAddress > GetAddresses(size_t max_addresses, size_t max_pct, std::optional< Network > network)
Return all or many randomly selected addresses, optionally by network.
Definition: net.cpp:3326
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1399
RecursiveMutex m_addr_fetches_mutex
Definition: net.h:1318
friend struct ConnmanTestMsg
Definition: net.h:1454
unsigned int nPrevNodeCount
Definition: net.h:1325
void NotifyNumConnectionsChanged()
Definition: net.cpp:1532
ServiceFlags GetLocalServices() const
Used to convey which local services we are offering peers during node connection.
Definition: net.cpp:3580
bool DisconnectNode(const std::string &node)
Definition: net.cpp:3446
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1304
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:1436
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1298
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1313
std::vector< CAddress > GetCurrentBlockRelayOnlyConns() const
Return vector of current BLOCK_RELAY peers.
Definition: net.cpp:2594
CClientUIInterface * clientInterface
Definition: net.h:1386
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
Definition: net.cpp:3738
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:1368
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:1308
void ThreadSocketHandler()
Definition: net.cpp:1912
RecursiveMutex cs_totalBytesSent
Definition: net.h:1293
bool Bind(const CService &addr, unsigned int flags, NetPermissionFlags permissions)
Definition: net.cpp:2994
std::thread threadOpenConnections
Definition: net.h:1428
NumConnections
Definition: net.h:948
@ CONNECTIONS_IN
Definition: net.h:950
@ CONNECTIONS_NONE
Definition: net.h:949
@ CONNECTIONS_ALL
Definition: net.h:952
@ CONNECTIONS_OUT
Definition: net.h:951
bool InactivityCheck(const CNode &node) const
Return true if the peer is inactive and should be disconnected.
Definition: net.cpp:1551
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:317
void Init(const Options &connOptions)
Definition: net.h:981
int GetExtraFullOutboundCount()
Definition: net.cpp:2216
void MarkAddressGood(const CAddress &addr)
Definition: net.cpp:3317
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1402
unsigned int nReceiveFloodSize
Definition: net.h:1311
RecursiveMutex cs_totalBytesRecv
Definition: net.h:1292
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:3663
int nMaxConnections
Definition: net.h:1370
std::deque< std::string > m_addr_fetches GUARDED_BY(m_addr_fetches_mutex)
std::function< void(CNode *)> NodeFn
Definition: net.h:1045
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
Definition: net.h:1294
void WakeMessageHandler()
Definition: net.cpp:1920
void SetNetworkActive(bool active)
Definition: net.cpp:2969
uint64_t GetMaxOutboundTarget()
Definition: net.cpp:3511
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2695
void SetAsmap(std::vector< bool > asmap)
Definition: net.h:1180
std::vector< CNode * > vNodes GUARDED_BY(cs_vNodes)
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached.
Definition: net.cpp:3536
void AddWhitelistPermissionFlags(NetPermissionFlags &flags, const CNetAddr &addr) const
Definition: net.cpp:539
bool Start(CScheduler &scheduler, const Options &options)
Definition: net.cpp:3047
bool GenerateSelectSet(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1591
void ThreadDNSAddressSeed()
Definition: net.cpp:2036
void ThreadMessageHandler()
Definition: net.cpp:2742
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:3742
Mutex mutexMsgProc
Definition: net.h:1408
bool fAddressesInitialized
Definition: net.h:1315
uint64_t GetTotalBytesSent()
Definition: net.cpp:3575
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:3717
~CConnman()
Definition: net.cpp:3308
void StopThreads()
Definition: net.cpp:3230
RecursiveMutex cs_vAddedNodes
Definition: net.h:1320
std::thread threadOpenAddedConnections
Definition: net.h:1427
const Config * config
Definition: net.h:1289
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:362
int m_max_outbound_full_relay
Definition: net.h:1373
std::chrono::seconds GetMaxOutboundTimeframe()
Definition: net.cpp:3516
int nMaxAddnode
Definition: net.h:1382
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:3491
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:1546
std::vector< AddedNodeInfo > GetAddedNodeInfo()
Definition: net.cpp:2606
void GetNodeStats(std::vector< CNodeStats > &vstats)
Definition: net.cpp:3435
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3667
void StopNodes()
Definition: net.cpp:3251
bool GetUseAddrmanOutgoing() const
Definition: net.h:1034
unsigned int nSendBufferMaxSize
Definition: net.h:1310
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1423
bool m_use_addrman_outgoing
Definition: net.h:1385
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:1352
CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1, bool network_active=true)
Definition: net.cpp:2980
uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent)
std::atomic< bool > fNetworkActive
Definition: net.h:1314
std::atomic_bool m_start_extra_block_relay_peers
flag for initiating extra block-relay-only peer connections.
Definition: net.h:1443
void DisconnectNodes()
Definition: net.cpp:1474
void DumpAddresses()
Definition: net.cpp:2172
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:1451
bool AddNode(const std::string &node)
Definition: net.cpp:3393
int nMaxFeeler
Definition: net.h:1383
std::vector< NetEventsInterface * > m_msgproc
Definition: net.h:1388
std::thread threadSocketHandler
Definition: net.h:1426
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:3405
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1271
bool BindListenPort(const CService &bindAddr, bilingual_str &strError, NetPermissionFlags permissions)
Definition: net.cpp:2841
int m_max_avalanche_outbound
Definition: net.h:1380
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:23
CHash256 & Reset()
Definition: hash.h:42
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:120
Transport protocol agnostic message container.
Definition: net.h:335
CNetMessage(CDataStream &&recv_in)
Definition: net.h:350
uint32_t m_message_size
size of the payload
Definition: net.h:345
std::chrono::microseconds m_time
time of message receipt
Definition: net.h:340
CDataStream m_recv
received message data
Definition: net.h:338
void SetVersion(int nVersionIn)
Definition: net.h:352
uint32_t m_raw_message_size
used wire size of the message (including header/checksum)
Definition: net.h:347
std::string m_command
Definition: net.h:348
bool m_valid_checksum
Definition: net.h:343
bool m_valid_header
Definition: net.h:342
bool m_valid_netmagic
Definition: net.h:341
void invsPolled(uint32_t count)
The node was polled for count invs.
Definition: net.cpp:3588
std::atomic< uint64_t > invCounters
The inventories polled and voted couters since last score computation, stored as a pair of uint32_t w...
Definition: net.h:673
Mutex cs_statistics
Protect the sequence of operations required for updating the statistics.
Definition: net.h:682
void updateAvailabilityScore()
The availability score is calculated using an exponentially weighted average.
Definition: net.cpp:3596
double getAvailabilityScore() const
Definition: net.cpp:3610
std::atomic< double > availabilityScore
The last computed score.
Definition: net.h:676
void invsVoted(uint32_t count)
The node voted for count invs.
Definition: net.cpp:3592
CPubKey pubkey
Definition: net.h:685
Information about a peer.
Definition: net.h:460
RecursiveMutex cs_vProcessMsg
Definition: net.h:481
const CAddress addrBind
Definition: net.h:497
bool IsFeelerConn() const
Definition: net.h:562
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:492
bool ExpectServicesFromConn() const
Definition: net.h:576
bool m_prefer_evict
Definition: net.h:513
size_t nSendOffset
Definition: net.h:474
std::atomic< int > nVersion
Definition: net.h:501
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:487
bool IsInboundConn() const
Definition: net.h:568
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:514
std::atomic_bool fPauseRecv
Definition: net.h:532
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:535
NodeId GetId() const
Definition: net.h:811
bool IsManualConn() const
Definition: net.h:556
std::atomic< int64_t > nTimeOffset
Definition: net.h:493
RecursiveMutex cs_sendProcessing
Definition: net.h:485
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv)
std::string ConnectionTypeAsString() const
Definition: net.cpp:548
std::deque< std::vector< uint8_t > > vSendMsg GUARDED_BY(cs_vSend)
void SetCommonVersion(int greatest_common_version)
Definition: net.h:833
std::atomic< bool > m_bip152_highbandwidth_to
Definition: net.h:611
const std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:647
std::list< CNetMessage > vRecvMsg
Definition: net.h:801
size_t nProcessQueueSize
Definition: net.h:483
void SetAddrLocal(const CService &addrLocalIn)
May not be called more than once.
Definition: net.cpp:586
std::atomic< bool > m_bip152_highbandwidth_from
Definition: net.h:613
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:770
std::atomic_bool fSuccessfullyConnected
Definition: net.h:524
bool IsAddrFetchConn() const
Definition: net.h:564
uint64_t GetLocalNonce() const
Definition: net.h:813
size_t nSendSize
Definition: net.h:472
std::atomic< ServiceFlags > nServices
Definition: net.h:469
RecursiveMutex cs_SubVer
cleanSubVer is a sanitized string of the user agent byte array we read from the wire.
Definition: net.h:510
const CAddress addr
Definition: net.h:495
RecursiveMutex cs_addrLocal
Definition: net.h:808
CSemaphoreGrant grantOutbound
Definition: net.h:528
std::string GetAddrName() const
Definition: net.cpp:569
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:606
Mutex cs_hSocket
Definition: net.h:478
bool m_legacyWhitelisted
Definition: net.h:519
const uint64_t nKeyedNetGroup
Definition: net.h:531
friend struct ConnmanTestMsg
Definition: net.h:462
std::atomic< int > nRefCount
Definition: net.h:529
RecursiveMutex cs_addrName
Definition: net.h:803
std::atomic< int > m_greatest_common_version
Definition: net.h:780
bool IsBlockOnlyConn() const
Definition: net.h:558
void CloseSocketDisconnect()
Definition: net.cpp:530
const std::unique_ptr< ProofRelay > m_proof_relay
Definition: net.h:665
int GetCommonVersion() const
Definition: net.h:837
bool IsFullOutboundConn() const
Definition: net.h:551
uint64_t nRemoteHostNonce
Definition: net.h:503
std::unique_ptr< TransportSerializer > m_serializer
Definition: net.h:466
bool fClient
Definition: net.h:521
Mutex cs_vSend
Definition: net.h:477
std::atomic_bool fPauseSend
Definition: net.h:533
SOCKET hSocket GUARDED_BY(cs_hSocket)
std::chrono::seconds m_nextGetAvaAddr
Definition: net.h:720
uint64_t nRemoteExtraEntropy
Definition: net.h:505
int GetRefCount() const
Definition: net.h:816
uint64_t GetLocalExtraEntropy() const
Definition: net.h:814
std::list< CNetMessage > vProcessMsg GUARDED_BY(cs_vProcessMsg)
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:797
void PushProofInventory(const avalanche::ProofId &proofid)
Definition: net.h:874
void MaybeSetAddrName(const std::string &addrNameIn)
Sets the addrName only if it was not previously set.
Definition: net.cpp:574
void AddKnownTx(const TxId &txid)
Definition: net.h:850
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:465
std::unique_ptr< AvalancheState > m_avalanche_state
Definition: net.h:717
NetPermissionFlags m_permissionFlags
Definition: net.h:799
const ConnectionType m_conn_type
Definition: net.h:779
Network ConnectedThroughNetwork() const
Get network the peer connected through.
Definition: net.cpp:597
CService addrLocal GUARDED_BY(cs_addrLocal)
const uint64_t nLocalHostNonce
Definition: net.h:777
std::atomic< std::chrono::microseconds > m_last_ping_time
Last measured round-trip time.
Definition: net.h:748
void copyStats(CNodeStats &stats)
Definition: net.cpp:601
ServiceFlags GetLocalServices() const
Definition: net.h:889
std::string cleanSubVer GUARDED_BY(cs_SubVer)
Definition: net.h:511
const uint64_t nLocalExtraEntropy
Definition: net.h:778
CNode(const CNode &)=delete
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e.
Definition: net.h:500
std::atomic< std::chrono::microseconds > m_min_ping_time
Lowest measured round-trip time.
Definition: net.h:754
const NodeId id
Definition: net.h:776
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:745
Mutex cs_vRecv
Definition: net.h:479
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:729
~CNode()
Definition: net.cpp:3659
bool m_limited_node
Definition: net.h:523
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:475
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:665
void PushTxInventory(const TxId &txid)
Definition: net.h:857
std::atomic_bool fDisconnect
Definition: net.h:527
std::atomic< std::chrono::seconds > m_last_recv
Definition: net.h:490
void AddKnownProof(const avalanche::ProofId &proofid)
Definition: net.h:867
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:3616
CService GetAddrLocal() const
Definition: net.cpp:581
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:737
std::atomic< std::chrono::seconds > m_last_send
Definition: net.h:489
bool IsAvalancheOutboundConnection() const
Definition: net.h:572
void Release()
Definition: net.h:848
CNode & operator=(const CNode &)=delete
CNode * AddRef()
Definition: net.h:843
std::string addrName GUARDED_BY(cs_addrName)
An encapsulated public key.
Definition: pubkey.h:31
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:36
RAII-style semaphore lock.
Definition: sync.h:314
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:901
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, bool &update_connection_time)=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(const 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:360
virtual ~TransportDeserializer()
Definition: net.h:371
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:443
virtual void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header)=0
virtual ~TransportSerializer()
Definition: net.h:450
CNetMessage GetMessage(const Config &config, std::chrono::microseconds time) override
Definition: net.cpp:763
CDataStream vRecv
Definition: net.h:386
CMessageHeader hdr
Definition: net.h:384
const uint256 & GetMessageHash() const
Definition: net.cpp:754
uint32_t nDataPos
Definition: net.h:388
uint32_t nHdrPos
Definition: net.h:387
int Read(const Config &config, Span< const uint8_t > &msg_bytes) override
read and deserialize data, advances msg_bytes data pointer
Definition: net.h:426
void SetVersion(int nVersionIn) override
Definition: net.h:422
int readData(Span< const uint8_t > msg_bytes)
Definition: net.cpp:737
bool Complete() const override
Definition: net.h:414
int readHeader(const Config &config, Span< const uint8_t > msg_bytes)
Definition: net.cpp:704
CHash256 hasher
Definition: net.h:376
V1TransportDeserializer(const CMessageHeader::MessageMagic &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:406
CDataStream hdrbuf
Definition: net.h:382
uint256 data_hash
Definition: net.h:377
void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header) override
Definition: net.cpp:807
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:205
@ NET
Definition: logging.h:39
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:192
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:212
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.h:143
uint16_t GetListenPort()
Definition: net.cpp:139
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:95
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:312
void RemoveLocal(const CService &addr)
Definition: net.cpp:278
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:65
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:59
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:72
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:246
bool fDiscover
Definition: net.cpp:128
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:107
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:99
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:53
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:103
void StopMapPort()
Definition: net.cpp:2031
bool fListen
Definition: net.cpp:129
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:51
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:130
static constexpr uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:97
void StartMapPort()
Definition: net.cpp:2025
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
Definition: net.h:63
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:106
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:115
static const int DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS
Maximum number of avalanche enabled outgoing connections by default.
Definition: net.h:79
static const double AVALANCHE_STATISTICS_DECAY_FACTOR
Pre-computed decay factor for the avalanche statistics computation.
Definition: net.h:117
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:284
static const bool DEFAULT_FIXEDSEEDS
Definition: net.h:105
static constexpr std::chrono::minutes AVALANCHE_STATISTICS_TIME_CONSTANT
Time constant for the avalanche statistics computation.
Definition: net.h:112
static const bool DEFAULT_UPNP
-upnp default
Definition: net.h:88
ConnectionType
Different types of connections to a peer.
Definition: net.h:156
@ 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)
static constexpr std::chrono::minutes AVALANCHE_STATISTICS_REFRESH_PERIOD
Refresh period for the avalanche statistics computation.
Definition: net.h:110
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:282
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:3764
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:81
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:83
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:145
static constexpr auto FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes.
Definition: net.h:61
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:101
std::optional< NodeId > SelectNodeToEvict(std::vector< NodeEvictionCandidate > &&vEvictionCandidates)
Select an inbound peer to evict after filtering out (protecting) peers having distinct,...
Definition: net.cpp:1115
void ProtectEvictionCandidatesByRatio(std::vector< NodeEvictionCandidate > &vEvictionCandidates)
Protect desirable or disadvantaged inbound peers from eviction by ratio.
Definition: net.cpp:1020
void InterruptMapPort()
Definition: net.cpp:2028
std::optional< CAddress > GetLocalAddrForPeer(CNode *pnode)
Returns a local address that we should advertise to this peer.
Definition: net.cpp:218
static const bool DEFAULT_DNSSEED
Definition: net.h:104
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:70
@ LOCAL_NONE
Definition: net.h:232
@ LOCAL_MANUAL
Definition: net.h:240
@ LOCAL_MAX
Definition: net.h:242
@ LOCAL_UPNP
Definition: net.h:238
@ LOCAL_BIND
Definition: net.h:236
@ LOCAL_IF
Definition: net.h:234
std::string userAgent(const Config &config)
Definition: net.cpp:3778
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:74
void Discover()
Definition: net.cpp:2916
bool IsReachable(enum Network net)
Definition: net.cpp:292
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:302
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:3730
NetPermissionFlags
@ PF_NONE
Network
A network type.
Definition: netaddress.h:43
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:125
CService resolvedAddress
Definition: net.h:123
bool fConnected
Definition: net.h:124
std::string strAddedNode
Definition: net.h:122
Definition: amount.h:19
static constexpr Amount zero()
Definition: amount.h:42
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:1333
std::chrono::microseconds m_cache_entry_expiration
Definition: net.h:1335
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1334
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:1195
ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
Definition: net.h:1198
NetPermissionFlags m_permissions
Definition: net.h:1202
int m_max_outbound_block_relay
Definition: net.h:959
unsigned int nReceiveFloodSize
Definition: net.h:967
int m_max_outbound_full_relay
Definition: net.h:958
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:972
uint64_t nMaxOutboundLimit
Definition: net.h:968
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:971
CClientUIInterface * uiInterface
Definition: net.h:963
int m_max_avalanche_outbound
Definition: net.h:960
std::vector< CService > onion_binds
Definition: net.h:974
int nMaxFeeler
Definition: net.h:962
std::vector< std::string > m_specified_outgoing
Definition: net.h:976
int nMaxConnections
Definition: net.h:957
ServiceFlags nLocalServices
Definition: net.h:956
std::vector< std::string > m_added_nodes
Definition: net.h:977
int64_t m_peer_connect_timeout
Definition: net.h:969
std::vector< CService > vBinds
Definition: net.h:973
unsigned int nSendBufferMaxSize
Definition: net.h:966
bool m_i2p_accept_incoming
Definition: net.h:978
std::vector< std::string > vSeedNodes
Definition: net.h:970
BanMan * m_banman
Definition: net.h:965
bool m_use_addrman_outgoing
Definition: net.h:975
std::vector< NetEventsInterface * > m_msgproc
Definition: net.h:964
int nMaxAddnode
Definition: net.h:961
std::set< avalanche::ProofId > setInventoryProofToSend GUARDED_BY(cs_proof_inventory)
std::chrono::microseconds nextInvSend
Definition: net.h:656
CRollingBloomFilter filterProofKnown GUARDED_BY(cs_proof_inventory)
Definition: net.h:654
RecursiveMutex cs_proof_inventory
Definition: net.h:650
std::atomic< bool > compactproofs_requested
Definition: net.h:661
std::atomic< std::chrono::seconds > lastSharedProofsUpdate
Definition: net.h:660
RadixTree< const avalanche::Proof, avalanche::ProofRadixTreeAdapter > sharedProofs
Definition: net.h:659
CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory)
Definition: net.h:627
std::chrono::microseconds m_next_send_feefilter
Definition: net.h:643
std::chrono::microseconds nNextInvSend
Definition: net.h:637
RecursiveMutex cs_feeFilter
Definition: net.h:639
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:634
std::set< TxId > setInventoryTxToSend GUARDED_BY(cs_tx_inventory)
std::atomic< std::chrono::seconds > m_last_mempool_req
Definition: net.h:636
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:622
RecursiveMutex cs_filter
Definition: net.h:616
RecursiveMutex cs_tx_inventory
Definition: net.h:624
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter)
Definition: net.h:623
Amount lastSentFeeFilter
Definition: net.h:642
Amount minFeeFilter GUARDED_BY(cs_feeFilter)
Definition: net.h:641
POD that contains various stats about a node.
Definition: net.h:289
std::string addrLocal
Definition: net.h:318
CAddress addrBind
Definition: net.h:322
uint64_t nRecvBytes
Definition: net.h:310
bool m_manual_connection
Definition: net.h:304
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:309
bool fRelayTxes
Definition: net.h:292
std::chrono::microseconds m_last_ping_time
Definition: net.h:314
std::string addrName
Definition: net.h:300
uint32_t m_mapped_as
Definition: net.h:325
bool fInbound
Definition: net.h:303
uint64_t nSendBytes
Definition: net.h:308
std::chrono::seconds m_last_recv
Definition: net.h:294
std::optional< double > m_availabilityScore
Definition: net.h:327
std::chrono::seconds m_last_proof_time
Definition: net.h:296
std::chrono::seconds m_last_send
Definition: net.h:293
std::chrono::seconds m_last_tx_time
Definition: net.h:295
CAddress addr
Definition: net.h:320
std::string m_conn_type_string
Definition: net.h:326
bool m_legacyWhitelisted
Definition: net.h:313
std::chrono::microseconds m_min_ping_time
Definition: net.h:315
ServiceFlags nServices
Definition: net.h:291
int64_t nTimeOffset
Definition: net.h:299
std::chrono::seconds m_connected
Definition: net.h:298
bool m_bip152_highbandwidth_from
Definition: net.h:306
bool m_bip152_highbandwidth_to
Definition: net.h:305
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:311
int nVersion
Definition: net.h:301
std::chrono::seconds m_last_block_time
Definition: net.h:297
Network m_network
Definition: net.h:324
NodeId nodeid
Definition: net.h:290
NetPermissionFlags m_permissionFlags
Definition: net.h:312
std::string cleanSubVer
Definition: net.h:302
int m_starting_height
Definition: net.h:307
Amount minFeeFilter
Definition: net.h:316
CSerializedNetMsg(const CSerializedNetMsg &msg)=delete
std::vector< uint8_t > data
Definition: net.h:139
std::string m_type
Definition: net.h:140
CSerializedNetMsg & operator=(const CSerializedNetMsg &)=delete
CSerializedNetMsg()=default
CSerializedNetMsg(CSerializedNetMsg &&)=default
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
uint16_t nPort
Definition: net.h:273
int nScore
Definition: net.h:272
std::chrono::seconds m_last_tx_time
Definition: net.h:1474
Network m_network
Definition: net.h:1481
double availabilityScore
Definition: net.h:1482
std::chrono::seconds m_connected
Definition: net.h:1470
std::chrono::seconds m_last_block_time
Definition: net.h:1472
bool fRelevantServices
Definition: net.h:1475
std::chrono::microseconds m_min_ping_time
Definition: net.h:1471
std::chrono::seconds m_last_proof_time
Definition: net.h:1473
uint64_t nKeyedNetGroup
Definition: net.h:1478
A TxId is the identifier of a transaction.
Definition: txid.h:14
Bilingual messages:
Definition: translation.h:17
#define LOCK(cs)
Definition: sync.h:241
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