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