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 
12 #include <cstdint>
13 #include <string>
14 #include <vector>
15 
16 static inline uint16_t GetDefaultPort() {
17  return Params().GetDefaultPort();
18 }
19 
20 // After the 1000th addr, the seeder will only add one more address per addr
21 // message.
22 static const unsigned int ADDR_SOFT_CAP = 1000;
23 
24 enum class PeerMessagingState {
26  Finished,
27 };
28 
29 class Sock;
30 
31 namespace {
32 class CSeederNodeTest;
33 }
34 
35 class CSeederNode {
36  friend class ::CSeederNodeTest;
37 
38 private:
39  std::unique_ptr<Sock> sock;
42  uint32_t nHeaderStart;
43  uint32_t nMessageStart;
44  int nVersion;
45  std::string strSubVer;
47  std::vector<CAddress> *vAddr;
48  int ban;
49  int64_t doneAfter;
51 
52  int GetTimeout() { return you.IsTor() ? 120 : 30; }
53 
54  void BeginMessage(const char *pszCommand);
55 
56  void AbortMessage();
57 
58  void EndMessage();
59 
60  void Send();
61 
62  void PushVersion();
63 
64  bool ProcessMessages();
65 
66 protected:
67  PeerMessagingState ProcessMessage(std::string strCommand,
68  CDataStream &recv);
69 
70 public:
71  CSeederNode(const CService &ip, std::vector<CAddress> *vAddrIn);
72 
73  bool Run();
74 
75  int GetBan() { return ban; }
76 
77  int GetClientVersion() { return nVersion; }
78 
79  std::string GetClientSubVersion() { return strSubVer; }
80 
82 
83  uint64_t GetServices() { return you.nServices; }
84 };
85 
86 #endif // BITCOIN_SEEDER_BITCOIN_H
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
Definition: protocol.h:445
ServiceFlags nServices
Definition: protocol.h:488
uint16_t GetDefaultPort() const
Definition: chainparams.h:89
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
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:41
CAddress you
Definition: bitcoin.h:50
CSeederNode(const CService &ip, std::vector< CAddress > *vAddrIn)
Definition: bitcoin.cpp:176
CDataStream vSend
Definition: bitcoin.h:40
bool Run()
Definition: bitcoin.cpp:186
int nStartingHeight
Definition: bitcoin.h:46
int GetBan()
Definition: bitcoin.h:75
int nVersion
Definition: bitcoin.h:44
uint32_t nHeaderStart
Definition: bitcoin.h:42
std::string GetClientSubVersion()
Definition: bitcoin.h:79
std::vector< CAddress > * vAddr
Definition: bitcoin.h:47
bool ProcessMessages()
Definition: bitcoin.cpp:115
std::string strSubVer
Definition: bitcoin.h:45
PeerMessagingState ProcessMessage(std::string strCommand, CDataStream &recv)
Definition: bitcoin.cpp:38
int GetClientVersion()
Definition: bitcoin.h:77
void Send()
Definition: bitcoin.cpp:23
uint32_t nMessageStart
Definition: bitcoin.h:43
int GetTimeout()
Definition: bitcoin.h:52
void PushVersion()
void AbortMessage()
int GetStartingHeight()
Definition: bitcoin.h:81
int ban
Definition: bitcoin.h:48
uint64_t GetServices()
Definition: bitcoin.h:83
void EndMessage()
std::unique_ptr< Sock > sock
Definition: bitcoin.h:39
int64_t doneAfter
Definition: bitcoin.h:49
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
PeerMessagingState
Definition: bitcoin.h:24
static const unsigned int ADDR_SOFT_CAP
Definition: bitcoin.h:22
static uint16_t GetDefaultPort()
Definition: bitcoin.h:16