Bitcoin ABC  0.28.12
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  uint32_t nHeaderStart;
45  uint32_t nMessageStart;
46  int nVersion;
47  std::string strSubVer;
49  std::vector<CAddress> *vAddr;
50  int ban;
54 
55  std::chrono::seconds GetTimeout() { return you.IsTor() ? 120s : 30s; }
56 
57  void BeginMessage(const char *pszCommand);
58 
59  void AbortMessage();
60 
61  void EndMessage();
62 
63  void Send();
64 
65  void PushVersion();
66 
67  bool ProcessMessages();
68 
69 protected:
70  PeerMessagingState ProcessMessage(std::string strCommand,
71  CDataStream &recv);
72 
73 public:
74  CSeederNode(const CService &ip, std::vector<CAddress> *vAddrIn);
75 
76  bool Run();
77 
78  int GetBan() { return ban; }
79 
80  int GetClientVersion() { return nVersion; }
81 
82  std::string GetClientSubVersion() { return strSubVer; }
83 
85 
86  uint64_t GetServices() { return yourServices; }
87 };
88 
89 #endif // BITCOIN_SEEDER_BITCOIN_H
const CChainParams & Params()
Return the currently selected parameters.
uint16_t GetDefaultPort() const
Definition: chainparams.h:89
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:199
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:52
CSeederNode(const CService &ip, std::vector< CAddress > *vAddrIn)
Definition: bitcoin.cpp:188
CDataStream vSend
Definition: bitcoin.h:42
bool Run()
Definition: bitcoin.cpp:199
int nStartingHeight
Definition: bitcoin.h:48
int GetBan()
Definition: bitcoin.h:78
int nVersion
Definition: bitcoin.h:46
uint32_t nHeaderStart
Definition: bitcoin.h:44
std::string GetClientSubVersion()
Definition: bitcoin.h:82
std::vector< CAddress > * vAddr
Definition: bitcoin.h:49
ServiceFlags yourServices
Definition: bitcoin.h:53
bool ProcessMessages()
Definition: bitcoin.cpp:126
std::string strSubVer
Definition: bitcoin.h:47
PeerMessagingState ProcessMessage(std::string strCommand, CDataStream &recv)
Definition: bitcoin.cpp:38
int GetClientVersion()
Definition: bitcoin.h:80
void Send()
Definition: bitcoin.cpp:23
uint32_t nMessageStart
Definition: bitcoin.h:45
void PushVersion()
std::chrono::seconds GetTimeout()
Definition: bitcoin.h:55
void AbortMessage()
int GetStartingHeight()
Definition: bitcoin.h:84
int ban
Definition: bitcoin.h:50
uint64_t GetServices()
Definition: bitcoin.h:86
NodeSeconds doneAfter
Definition: bitcoin.h:51
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
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