Bitcoin ABC  0.24.7
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 namespace {
30 class CSeederNodeTest;
31 }
32 
33 class CSeederNode {
34  friend class ::CSeederNodeTest;
35 
36 private:
40  uint32_t nHeaderStart;
41  uint32_t nMessageStart;
42  int nVersion;
43  std::string strSubVer;
45  std::vector<CAddress> *vAddr;
46  int ban;
47  int64_t doneAfter;
49 
50  int GetTimeout() { return you.IsTor() ? 120 : 30; }
51 
52  void BeginMessage(const char *pszCommand);
53 
54  void AbortMessage();
55 
56  void EndMessage();
57 
58  void Send();
59 
60  void PushVersion();
61 
62  bool ProcessMessages();
63 
64 protected:
65  PeerMessagingState ProcessMessage(std::string strCommand,
66  CDataStream &recv);
67 
68 public:
69  CSeederNode(const CService &ip, std::vector<CAddress> *vAddrIn);
70 
71  bool Run();
72 
73  int GetBan() { return ban; }
74 
75  int GetClientVersion() { return nVersion; }
76 
77  std::string GetClientSubVersion() { return strSubVer; }
78 
80 
81  uint64_t GetServices() { return you.nServices; }
82 };
83 
84 #endif // BITCOIN_SEEDER_BITCOIN_H
CSeederNode::PushVersion
void PushVersion()
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:514
CSeederNode::AbortMessage
void AbortMessage()
PeerMessagingState::AwaitingMessages
@ AwaitingMessages
CSeederNode::ban
int ban
Definition: bitcoin.h:46
streams.h
CSeederNode::nStartingHeight
int nStartingHeight
Definition: bitcoin.h:44
CSeederNode::sock
SOCKET sock
Definition: bitcoin.h:37
CAddress::nServices
ServiceFlags nServices
Definition: protocol.h:464
CSeederNode::vRecv
CDataStream vRecv
Definition: bitcoin.h:39
chainparams.h
CSeederNode::you
CAddress you
Definition: bitcoin.h:48
CSeederNode::GetStartingHeight
int GetStartingHeight()
Definition: bitcoin.h:79
CSeederNode::vSend
CDataStream vSend
Definition: bitcoin.h:38
CSeederNode::Run
bool Run()
Definition: bitcoin.cpp:186
CSeederNode::Send
void Send()
Definition: bitcoin.cpp:22
CSeederNode::GetBan
int GetBan()
Definition: bitcoin.h:73
ADDR_SOFT_CAP
static const unsigned int ADDR_SOFT_CAP
Definition: bitcoin.h:22
CSeederNode::GetTimeout
int GetTimeout()
Definition: bitcoin.h:50
CSeederNode::ProcessMessage
PeerMessagingState ProcessMessage(std::string strCommand, CDataStream &recv)
Definition: bitcoin.cpp:38
CSeederNode::GetClientSubVersion
std::string GetClientSubVersion()
Definition: bitcoin.h:77
PeerMessagingState::Finished
@ Finished
PeerMessagingState
PeerMessagingState
Definition: bitcoin.h:24
CChainParams::GetDefaultPort
int GetDefaultPort() const
Definition: chainparams.h:62
CSeederNode::nHeaderStart
uint32_t nHeaderStart
Definition: bitcoin.h:40
CSeederNode::nVersion
int nVersion
Definition: bitcoin.h:42
CAddress
A CService with information about it as peer.
Definition: protocol.h:421
CSeederNode::EndMessage
void EndMessage()
CSeederNode::ProcessMessages
bool ProcessMessages()
Definition: bitcoin.cpp:115
CSeederNode::doneAfter
int64_t doneAfter
Definition: bitcoin.h:47
CSeederNode::vAddr
std::vector< CAddress > * vAddr
Definition: bitcoin.h:45
GetDefaultPort
static uint16_t GetDefaultPort()
Definition: bitcoin.h:16
CNetAddr::IsTor
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:394
CSeederNode
Definition: bitcoin.h:33
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:508
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
CSeederNode::nMessageStart
uint32_t nMessageStart
Definition: bitcoin.h:41
CSeederNode::strSubVer
std::string strSubVer
Definition: bitcoin.h:43
CSeederNode::GetServices
uint64_t GetServices()
Definition: bitcoin.h:81
CSeederNode::CSeederNode
CSeederNode(const CService &ip, std::vector< CAddress > *vAddrIn)
Definition: bitcoin.cpp:176
CSeederNode::BeginMessage
void BeginMessage(const char *pszCommand)
CSeederNode::GetClientVersion
int GetClientVersion()
Definition: bitcoin.h:75
SOCKET
unsigned int SOCKET
Definition: compat.h:44