Bitcoin ABC  0.26.3
P2P Digital Currency
bitcoin.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2019 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_SEEDER_BITCOIN_H
6 #define BITCOIN_SEEDER_BITCOIN_H
7 
8 #include <chainparams.h>
9 #include <protocol.h>
10 #include <streams.h>
11 #include <util/time.h>
12 
13 #include <chrono>
14 #include <cstdint>
15 #include <string>
16 #include <vector>
17 
18 static inline uint16_t GetDefaultPort() {
19  return Params().GetDefaultPort();
20 }
21 
22 // After the 1000th addr, the seeder will only add one more address per addr
23 // message.
24 static const unsigned int ADDR_SOFT_CAP = 1000;
25 
26 enum class PeerMessagingState {
28  Finished,
29 };
30 
31 class Sock;
32 
33 namespace {
34 class CSeederNodeTest;
35 }
36 
37 class CSeederNode {
38  friend class ::CSeederNodeTest;
39 
40 private:
41  std::unique_ptr<Sock> sock;
44  int nVersion{0};
45  std::string strSubVer;
47  std::vector<CAddress> *vAddr;
48  int ban{0};
52 
53  std::chrono::seconds GetTimeout() { return you.IsTor() ? 120s : 30s; }
54 
55  void BeginMessage(const char *pszCommand);
56 
57  void AbortMessage();
58 
59  void EndMessage();
60 
61  void Send();
62 
63  void PushVersion();
64 
65  bool ProcessMessages();
66 
67 protected:
68  PeerMessagingState ProcessMessage(std::string strCommand,
69  CDataStream &recv);
70 
71 public:
72  CSeederNode(const CService &ip, std::vector<CAddress> *vAddrIn);
73 
74  bool Run();
75 
76  int GetBan() { return ban; }
77 
78  int GetClientVersion() { return nVersion; }
79 
80  std::string GetClientSubVersion() { return strSubVer; }
81 
83 
84  uint64_t GetServices() { return yourServices; }
85 };
86 
87 #endif // BITCOIN_SEEDER_BITCOIN_H
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
uint16_t GetDefaultPort() const
Definition: chainparams.h:95
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:177
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:435
void BeginMessage(const char *pszCommand)
CDataStream vRecv
Definition: bitcoin.h:43
CService you
Definition: bitcoin.h:50
CSeederNode(const CService &ip, std::vector< CAddress > *vAddrIn)
Definition: bitcoin.cpp:227
CDataStream vSend
Definition: bitcoin.h:42
bool Run()
Definition: bitcoin.cpp:235
int nStartingHeight
Definition: bitcoin.h:46
int GetBan()
Definition: bitcoin.h:76
int nVersion
Definition: bitcoin.h:44
std::string GetClientSubVersion()
Definition: bitcoin.h:80
std::vector< CAddress > * vAddr
Definition: bitcoin.h:47
ServiceFlags yourServices
Definition: bitcoin.h:51
bool ProcessMessages()
Definition: bitcoin.cpp:165
std::string strSubVer
Definition: bitcoin.h:45
PeerMessagingState ProcessMessage(std::string strCommand, CDataStream &recv)
Definition: bitcoin.cpp:41
int GetClientVersion()
Definition: bitcoin.h:78
void Send()
Definition: bitcoin.cpp:26
void PushVersion()
std::chrono::seconds GetTimeout()
Definition: bitcoin.h:53
void AbortMessage()
int GetStartingHeight()
Definition: bitcoin.h:82
int ban
Definition: bitcoin.h:48
uint64_t GetServices()
Definition: bitcoin.h:84
NodeSeconds doneAfter
Definition: bitcoin.h:49
void EndMessage()
std::unique_ptr< Sock > sock
Definition: bitcoin.h:41
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:545
RAII helper class that manages a socket.
Definition: sock.h:26
ServiceFlags
nServices flags.
Definition: protocol.h:335
@ NODE_NETWORK
Definition: protocol.h:342
PeerMessagingState
Definition: bitcoin.h:26
static const unsigned int ADDR_SOFT_CAP
Definition: bitcoin.h:24
static uint16_t GetDefaultPort()
Definition: bitcoin.h:18
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
Definition: time.h:25