Changeset View
Changeset View
Standalone View
Standalone View
src/net.h
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24; | static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24; | ||||
/** Default for blocks only*/ | /** Default for blocks only*/ | ||||
static const bool DEFAULT_BLOCKSONLY = false; | static const bool DEFAULT_BLOCKSONLY = false; | ||||
static const bool DEFAULT_FORCEDNSSEED = false; | static const bool DEFAULT_FORCEDNSSEED = false; | ||||
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000; | static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000; | ||||
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000; | static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000; | ||||
static const ServiceFlags REQUIRED_SERVICES = ServiceFlags(NODE_NETWORK); | |||||
// Default 24-hour ban. | // Default 24-hour ban. | ||||
// NOTE: When adjusting this, update rpcnet:setban's help ("24h") | // NOTE: When adjusting this, update rpcnet:setban's help ("24h") | ||||
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; | static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; | ||||
typedef int64_t NodeId; | typedef int64_t NodeId; | ||||
struct AddedNodeInfo { | struct AddedNodeInfo { | ||||
std::string strAddedNode; | std::string strAddedNode; | ||||
Show All 24 Lines | enum NumConnections { | ||||
CONNECTIONS_NONE = 0, | CONNECTIONS_NONE = 0, | ||||
CONNECTIONS_IN = (1U << 0), | CONNECTIONS_IN = (1U << 0), | ||||
CONNECTIONS_OUT = (1U << 1), | CONNECTIONS_OUT = (1U << 1), | ||||
CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT), | CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT), | ||||
}; | }; | ||||
struct Options { | struct Options { | ||||
ServiceFlags nLocalServices = NODE_NONE; | ServiceFlags nLocalServices = NODE_NONE; | ||||
ServiceFlags nRelevantServices = NODE_NONE; | |||||
int nMaxConnections = 0; | int nMaxConnections = 0; | ||||
int nMaxOutbound = 0; | int nMaxOutbound = 0; | ||||
int nMaxAddnode = 0; | int nMaxAddnode = 0; | ||||
int nMaxFeeler = 0; | int nMaxFeeler = 0; | ||||
int nBestHeight = 0; | int nBestHeight = 0; | ||||
CClientUIInterface *uiInterface = nullptr; | CClientUIInterface *uiInterface = nullptr; | ||||
NetEventsInterface *m_msgproc = nullptr; | NetEventsInterface *m_msgproc = nullptr; | ||||
unsigned int nSendBufferMaxSize = 0; | unsigned int nSendBufferMaxSize = 0; | ||||
unsigned int nReceiveFloodSize = 0; | unsigned int nReceiveFloodSize = 0; | ||||
uint64_t nMaxOutboundTimeframe = 0; | uint64_t nMaxOutboundTimeframe = 0; | ||||
uint64_t nMaxOutboundLimit = 0; | uint64_t nMaxOutboundLimit = 0; | ||||
std::vector<std::string> vSeedNodes; | std::vector<std::string> vSeedNodes; | ||||
std::vector<CSubNet> vWhitelistedRange; | std::vector<CSubNet> vWhitelistedRange; | ||||
std::vector<CService> vBinds, vWhiteBinds; | std::vector<CService> vBinds, vWhiteBinds; | ||||
}; | }; | ||||
void Init(const Options &connOptions) { | void Init(const Options &connOptions) { | ||||
nLocalServices = connOptions.nLocalServices; | nLocalServices = connOptions.nLocalServices; | ||||
nRelevantServices = connOptions.nRelevantServices; | |||||
nMaxConnections = connOptions.nMaxConnections; | nMaxConnections = connOptions.nMaxConnections; | ||||
nMaxOutbound = | nMaxOutbound = | ||||
std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections); | std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections); | ||||
nMaxAddnode = connOptions.nMaxAddnode; | nMaxAddnode = connOptions.nMaxAddnode; | ||||
nMaxFeeler = connOptions.nMaxFeeler; | nMaxFeeler = connOptions.nMaxFeeler; | ||||
nBestHeight = connOptions.nBestHeight; | nBestHeight = connOptions.nBestHeight; | ||||
clientInterface = connOptions.uiInterface; | clientInterface = connOptions.uiInterface; | ||||
m_msgproc = connOptions.m_msgproc; | m_msgproc = connOptions.m_msgproc; | ||||
Show All 11 Lines | public: | ||||
void Stop(); | void Stop(); | ||||
void Interrupt(); | void Interrupt(); | ||||
bool GetNetworkActive() const { return fNetworkActive; }; | bool GetNetworkActive() const { return fNetworkActive; }; | ||||
void SetNetworkActive(bool active); | void SetNetworkActive(bool active); | ||||
bool OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, | bool OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, | ||||
CSemaphoreGrant *grantOutbound = nullptr, | CSemaphoreGrant *grantOutbound = nullptr, | ||||
const char *strDest = nullptr, | const char *strDest = nullptr, | ||||
bool fOneShot = false, bool fFeeler = false, | bool fOneShot = false, bool fFeeler = false, | ||||
bool fAddnode = false); | bool manual_connection = false); | ||||
bool CheckIncomingNonce(uint64_t nonce); | bool CheckIncomingNonce(uint64_t nonce); | ||||
bool ForNode(NodeId id, std::function<bool(CNode *pnode)> func); | bool ForNode(NodeId id, std::function<bool(CNode *pnode)> func); | ||||
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg); | void PushMessage(CNode *pnode, CSerializedNetMsg &&msg); | ||||
template <typename Callable> void ForEachNode(Callable &&func) { | template <typename Callable> void ForEachNode(Callable &&func) { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | private: | ||||
std::vector<CNode *> vNodes; | std::vector<CNode *> vNodes; | ||||
std::list<CNode *> vNodesDisconnected; | std::list<CNode *> vNodesDisconnected; | ||||
mutable CCriticalSection cs_vNodes; | mutable CCriticalSection cs_vNodes; | ||||
std::atomic<NodeId> nLastNodeId; | std::atomic<NodeId> nLastNodeId; | ||||
/** Services this instance offers */ | /** Services this instance offers */ | ||||
ServiceFlags nLocalServices; | ServiceFlags nLocalServices; | ||||
/** Services this instance cares about */ | |||||
ServiceFlags nRelevantServices; | |||||
CSemaphore *semOutbound; | CSemaphore *semOutbound; | ||||
CSemaphore *semAddnode; | CSemaphore *semAddnode; | ||||
int nMaxConnections; | int nMaxConnections; | ||||
int nMaxOutbound; | int nMaxOutbound; | ||||
int nMaxAddnode; | int nMaxAddnode; | ||||
int nMaxFeeler; | int nMaxFeeler; | ||||
std::atomic<int> nBestHeight; | std::atomic<int> nBestHeight; | ||||
CClientUIInterface *clientInterface; | CClientUIInterface *clientInterface; | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | public: | ||||
int64_t nLastSend; | int64_t nLastSend; | ||||
int64_t nLastRecv; | int64_t nLastRecv; | ||||
int64_t nTimeConnected; | int64_t nTimeConnected; | ||||
int64_t nTimeOffset; | int64_t nTimeOffset; | ||||
std::string addrName; | std::string addrName; | ||||
int nVersion; | int nVersion; | ||||
std::string cleanSubVer; | std::string cleanSubVer; | ||||
bool fInbound; | bool fInbound; | ||||
bool fAddnode; | bool m_manual_connection; | ||||
int nStartingHeight; | int nStartingHeight; | ||||
uint64_t nSendBytes; | uint64_t nSendBytes; | ||||
mapMsgCmdSize mapSendBytesPerMsgCmd; | mapMsgCmdSize mapSendBytesPerMsgCmd; | ||||
uint64_t nRecvBytes; | uint64_t nRecvBytes; | ||||
mapMsgCmdSize mapRecvBytesPerMsgCmd; | mapMsgCmdSize mapRecvBytesPerMsgCmd; | ||||
bool fWhitelisted; | bool fWhitelisted; | ||||
double dPingTime; | double dPingTime; | ||||
double dPingWait; | double dPingWait; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
/** Information about a peer */ | /** Information about a peer */ | ||||
class CNode { | class CNode { | ||||
friend class CConnman; | friend class CConnman; | ||||
public: | public: | ||||
// socket | // socket | ||||
std::atomic<ServiceFlags> nServices; | std::atomic<ServiceFlags> nServices; | ||||
// Services expected from a peer, otherwise it will be disconnected | |||||
ServiceFlags nServicesExpected; | |||||
SOCKET hSocket; | SOCKET hSocket; | ||||
// Total size of all vSendMsg entries. | // Total size of all vSendMsg entries. | ||||
size_t nSendSize; | size_t nSendSize; | ||||
// Offset inside the first vSendMsg already sent. | // Offset inside the first vSendMsg already sent. | ||||
size_t nSendOffset; | size_t nSendOffset; | ||||
uint64_t nSendBytes; | uint64_t nSendBytes; | ||||
std::deque<std::vector<uint8_t>> vSendMsg; | std::deque<std::vector<uint8_t>> vSendMsg; | ||||
CCriticalSection cs_vSend; | CCriticalSection cs_vSend; | ||||
Show All 27 Lines | public: | ||||
std::string strSubVer, cleanSubVer; | std::string strSubVer, cleanSubVer; | ||||
// Used for both cleanSubVer and strSubVer. | // Used for both cleanSubVer and strSubVer. | ||||
CCriticalSection cs_SubVer; | CCriticalSection cs_SubVer; | ||||
// This peer can bypass DoS banning. | // This peer can bypass DoS banning. | ||||
bool fWhitelisted; | bool fWhitelisted; | ||||
// If true this node is being used as a short lived feeler. | // If true this node is being used as a short lived feeler. | ||||
bool fFeeler; | bool fFeeler; | ||||
bool fOneShot; | bool fOneShot; | ||||
bool fAddnode; | bool m_manual_connection; | ||||
bool fClient; | bool fClient; | ||||
const bool fInbound; | const bool fInbound; | ||||
std::atomic_bool fSuccessfullyConnected; | std::atomic_bool fSuccessfullyConnected; | ||||
std::atomic_bool fDisconnect; | std::atomic_bool fDisconnect; | ||||
// We use fRelayTxes for two purposes - | // We use fRelayTxes for two purposes - | ||||
// a) it allows us to not relay tx invs before receiving the peer's version | // a) it allows us to not relay tx invs before receiving the peer's version | ||||
// message. | // message. | ||||
// b) the peer may tell us in its version message that we should not relay | // b) the peer may tell us in its version message that we should not relay | ||||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |