28 #include <condition_variable> 31 #include <arpa/inet.h> 34 #include <boost/filesystem/path.hpp> 35 #include <boost/foreach.hpp> 36 #include <boost/signals2/signal.hpp> 163 bool ForNode(
const CService& addr, std::function<
bool(
const CNode* pnode)> cond, std::function<
bool(
CNode* pnode)> func);
165 template<
typename Callable>
171 template<
typename Callable>
177 template <
typename... Args>
186 template <
typename... Args>
192 template <
typename... Args>
198 template <
typename... Args>
204 template<
typename Condition,
typename Callable>
208 for (
auto&& node :
vNodes)
215 template<
typename Callable>
221 template<
typename Condition,
typename Callable>
225 for (
const auto& node :
vNodes)
232 template<
typename Callable>
238 template<
typename Condition,
typename Callable>
242 for (
auto&& node :
vNodes) {
248 template<
typename Callable>
254 template<
typename Condition,
typename Callable>
258 for (
auto&& node :
vNodes) {
264 template<
typename Callable>
270 template<
typename Condition,
typename Callable,
typename CallableAfter>
274 for (
auto&& node :
vNodes) {
281 template<
typename Callable,
typename CallableAfter>
287 template<
typename Condition,
typename Callable,
typename CallableAfter>
288 void ForEachNodeThen(
const Condition& cond, Callable&& pre, CallableAfter&& post)
const 291 for (
auto&& node :
vNodes) {
298 template<
typename Callable,
typename CallableAfter>
334 void Ban(
const CNetAddr& netAddr,
const BanReason& reason, int64_t bantimeoffset = 0,
bool sinceUnixEpoch =
false);
335 void Ban(
const CSubNet& subNet,
const BanReason& reason, int64_t bantimeoffset = 0,
bool sinceUnixEpoch =
false);
346 bool AddNode(
const std::string& node);
509 extern std::unique_ptr<CConnman>
g_connman;
510 void Discover(boost::thread_group& threadGroup);
522 while (first != last) {
523 if (!(*first))
return false;
574 extern std::map<CInv, CDataStream>
mapRelay;
588 extern std::map<CNetAddr, LocalServiceInfo>
mapLocalHost;
655 int readHeader(
const char *pch,
unsigned int nBytes);
656 int readData(
const char *pch,
unsigned int nBytes);
771 CNode(
NodeId id,
ServiceFlags nLocalServicesIn,
int nMyStartingHeightIn,
SOCKET hSocketIn,
const CAddress &addrIn,
const std::string &addrNameIn =
"",
bool fInboundIn =
false,
bool fNetworkNodeIn =
false);
809 bool ReceiveMsgBytes(
const char *pch,
unsigned int nBytes,
bool& complete);
916 #endif // BITCOIN_NET_H CCriticalSection cs_vAddedNodes
static const int MAX_OUTBOUND_CONNECTIONS
CNode * ConnectNode(CAddress addrConnect, const char *pszDest=NULL, bool fConnectToMasternode=false)
std::unique_ptr< CConnman > g_connman
void ForEachNode(const Condition &cond, Callable &&func) const
bool GetNetworkActive() const
void MarkAddressGood(const CAddress &addr)
int GetMyStartingHeight() const
static const size_t SETASKFOR_MAX_SZ
bool IsReachable(enum Network net)
CCriticalSection cs_vWhitelistedRange
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
CRollingBloomFilter addrKnown
void Ban(const CNetAddr &netAddr, const BanReason &reason, int64_t bantimeoffset=0, bool sinceUnixEpoch=false)
std::set< uint256 > setAskFor
unsigned int nSendBufferMaxSize
std::vector< CAddress > vAddrToSend
CRollingBloomFilter filterInventoryKnown
boost::signals2::signal< void(NodeId, bool &)> FinalizeNode
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=NULL)
void ThreadMessageHandler()
std::atomic_bool fPauseSend
void RelayTransaction(const CTransaction &tx)
void operator=(const CNode &)
boost::signals2::signal< void(CNode *, CConnman &)> InitializeNode
void PushMessageWithVersion(CNode *pnode, int nVersion, const std::string &sCommand, Args &&... args)
CClientUIInterface * clientInterface
std::vector< uint256 > vBlockHashesFromINV
ServiceFlags nLocalServices
std::vector< uint256 > vBlockHashesToAnnounce
CSemaphoreGrant grantMasternodeOutbound
static void callCleanup()
CCriticalSection cs_mapRelay
boost::signals2::signal< bool(CNode *, CConnman &, std::atomic< bool > &), CombinerAll > SendMessages
std::vector< unsigned char > GetKey() const
static const ServiceFlags REQUIRED_SERVICES
static const bool DEFAULT_FORCEDNSSEED
bool SeenLocal(const CService &addr)
uint64_t GetMaxOutboundTarget()
static std::vector< unsigned char > vchSecretKey
static constexpr const CFullyConnectedOnly FullyConnectedOnly
std::deque< std::string > vOneShots
std::thread threadSocketHandler
void SetBanned(const banmap_t &banmap)
void CloseSocketDisconnect()
CDataStream BeginMessage(CNode *node, int nVersion, int flags, const std::string &sCommand)
std::vector< ListenSocket > vhListenSocket
std::atomic_bool fPauseRecv
static const bool DEFAULT_LISTEN
void GetBanned(banmap_t &banmap)
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool &complete)
bool ForNode(NodeId id, std::function< bool(const CNode *pnode)> cond, std::function< bool(CNode *pnode)> func)
int64_t nNextLocalAddrSend
void DeleteNode(CNode *pnode)
void AdvertiseLocal(CNode *pnode)
void MapPort(bool fUseUPnP)
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION)
void EndMessage(CDataStream &strm)
static std::vector< unsigned char > CalculateKeyedNetGroup(CAddress &address)
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds)
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
size_t GetAddressCount() const
ServiceFlags nServicesExpected
CClientUIInterface * uiInterface
static const size_t MAPASKFOR_MAX_SZ
void AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
static const int FEELER_INTERVAL
uint64_t GetLocalNonce() const
uint64_t nMaxOutboundCycleStartTime
std::list< CNetMessage > vProcessMsg
void AddNewAddress(const CAddress &addr, const CAddress &addrFrom, int64_t nTimePenalty=0)
bool operator()(const CNode *) const
uint64_t nMaxOutboundLimit
static const int TIMEOUT_INTERVAL
CCriticalSection cs_vOneShots
uint64_t nMaxOutboundTotalBytesSentInCycle
static uint32_t insecure_rand(void)
CCriticalSection cs_vSend
int readData(const char *pch, unsigned int nBytes)
CCriticalSection cs_setBanned
void resize(size_type n, value_type c=0)
void ThreadOpenAddedConnections()
bool BannedSetIsDirty()
check is the banlist has unwritten changes
int GetBestHeight() const
bool ForEachNodeContinueIf(const Condition &cond, Callable &&func) const
uint64_t GetTotalBytesRecv()
unsigned int GetReceiveFloodSize() const
void copyStats(CNodeStats &stats)
std::list< CNode * > vNodesDisconnected
mapMsgCmdSize mapRecvBytesPerMsgCmd
unsigned int nReceiveFloodSize
void SerializeMany(Stream &s, int nType, int nVersion)
std::atomic_bool fSuccessfullyConnected
size_t GetNodeCount(NumConnections num)
std::vector< AddedNodeInfo > GetAddedNodeInfo()
void SetVersion(int nVersionIn)
uint64_t GetMaxOutboundTimeframe()
std::deque< CInv > vRecvGetData
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn="", bool fInboundIn=false, bool fNetworkNodeIn=false)
static const size_t DEFAULT_MAXRECEIVEBUFFER
bool Start(CScheduler &scheduler, std::string &strNodeError, Options options)
std::atomic< NodeId > nLastNodeId
std::atomic< int > nRecvVersion
void ReleaseNodeVector(const std::vector< CNode *> &vecNodes)
std::deque< std::pair< int64_t, CInv > > vRelayExpiration
void AddAddressKnown(const CAddress &addr)
std::map< CSubNet, CBanEntry > banmap_t
std::map< CInv, CDataStream > mapRelay
bool RemoveAddedNode(const std::string &node)
CCriticalSection cs_nRefCount
void AskFor(const CInv &inv)
void SetRecvVersion(int nVersionIn)
static bool NodeFullyConnected(const CNode *pnode)
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
void ForEachNodeThen(const Condition &cond, Callable &&pre, CallableAfter &&post)
bool CheckIncomingNonce(uint64_t nonce)
static int LogPrint(const char *category, const char *format)
uint64_t GetOutboundTargetBytesLeft()
response the bytes left in the current max outbound cycle
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
void GetNodeStats(std::vector< CNodeStats > &vstats)
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
CSemaphore * semMasternodeOutbound
bool IsPeerAddrLocalGood(CNode *pnode)
bool OpenNetworkConnection(const CAddress &addrConnect, CSemaphoreGrant *grantOutbound=NULL, const char *strDest=NULL, bool fOneShot=false, bool fFeeler=false)
std::vector< CSubNet > vWhitelistedRange
void RecordBytesSent(uint64_t bytes)
ListenSocket(SOCKET socket_, bool whitelisted_)
void ForEachNode(Callable &&func) const
static const int MAX_OUTBOUND_MASTERNODE_CONNECTIONS
bool ForEachNodeContinueIf(Callable &&func)
bool RemoveLocal(const CService &addr)
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached
void PushInventory(const CInv &inv)
std::thread threadDNSAddressSeed
void SetBestHeight(int height)
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
std::deque< CSerializeData > vSendMsg
unsigned int nReceiveFloodSize
ServiceFlags GetLocalServices() const
void SetLimited(enum Network net, bool fLimited=true)
std::vector< CNode * > CopyNodeVector()
void SetServices(const CService &addr, ServiceFlags nServices)
limitedmap< uint256, int64_t > mapAlreadyAskedFor
ServiceFlags nLocalServices
std::atomic< bool > flagInterruptMsgProc
ServiceFlags nLocalServices
std::set< uint256 > setKnown
CNetMessage(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
CThreadInterrupt interruptNet
std::string ToString() const
bool Unban(const CNetAddr &ip)
CCriticalSection cs_inventory
CCriticalSection cs_totalBytesSent
bool DisconnectNode(const std::string &node)
std::atomic< int64_t > nLastBlockTime
void AddWhitelistedRange(const CSubNet &subnet)
static const unsigned int MAX_ADDR_TO_SEND
void WakeMessageHandler()
std::thread threadOpenConnections
int GetSendVersion() const
static const size_t DEFAULT_MAXSENDBUFFER
std::condition_variable condMsgProc
bool fAddressesInitialized
mapMsgCmdSize mapSendBytesPerMsgCmd
bool operator()(I first, I last) const
bool ForEachNodeContinueIf(Callable &&func) const
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
void PushBlockHash(const uint256 &hash)
bool operator()(const CNode *pnode) const
uint64_t GetTotalBytesSent()
std::vector< CNode * > vNodes
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes
void AddInventoryKnown(const CInv &inv)
void ThreadMnbRequestConnections()
std::atomic< int64_t > nLastTXTime
std::map< std::string, uint64_t > mapMsgCmdSize
void ThreadSocketHandler()
static const int MIN_PEER_PROTO_VERSION
disconnect from peers older than this proto version
ServiceFlags GetLocalServices() const
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
std::vector< std::string > vAddedNodes
void AddressCurrentlyConnected(const CService &addr)
static const unsigned int DEFAULT_MISBEHAVING_BANTIME
CCriticalSection cs_filter
boost::signals2::signal< bool(CNode *, CConnman &, std::atomic< bool > &), CombinerAll > ProcessMessages
void Discover(boost::thread_group &threadGroup)
void ThreadDNSAddressSeed()
uint64_t GetMaxOutboundTimeLeftInCycle()
response the time in second left in the current max outbound cycle
unsigned int GetSendBufferSize() const
mapMsgCmdSize mapRecvBytesPerMsgCmd
bool IsBanned(CNetAddr ip)
std::thread threadMessageHandler
unsigned int nSendBufferMaxSize
CNode * FindNode(const CNetAddr &ip)
bool ForNode(const CService &addr, Callable &&func)
void PushBlockHashFromINV(const uint256 &hash)
static const unsigned int MAX_SUBVERSION_LENGTH
static const bool DEFAULT_UPNP
bool IsWhitelistedRange(const CNetAddr &addr)
static const bool DEFAULT_BLOCKSONLY
CSemaphoreGrant grantOutbound
void PushMessageWithVersionAndFlag(CNode *pnode, int nVersion, int flag, const std::string &sCommand, Args &&... args)
static const int PING_INTERVAL
bool ForEachNodeContinueIf(const Condition &cond, Callable &&func)
ServiceFlags nRelevantServices
std::multimap< int64_t, CInv > mapAskFor
CCriticalSection cs_vNodes
std::string strSubVersion
std::thread threadOpenAddedConnections
std::thread threadMnbRequestConnections
std::atomic< int > nBestHeight
static const int WARNING_INTERVAL
void AddOneShot(const std::string &strDest)
void AcceptConnection(const ListenSocket &hListenSocket)
bool AttemptToEvictConnection()
CCriticalSection cs_totalBytesRecv
std::vector< CAddress > GetAddresses()
void ThreadOpenConnections()
int readHeader(const char *pch, unsigned int nBytes)
static constexpr const CAllNodes AllNodes
void ForEachNode(Callable &&func)
void SetNetworkActive(bool active)
mapMsgCmdSize mapSendBytesPerMsgCmd
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
static const unsigned int MAX_INV_SZ
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
void ForEachNode(const Condition &cond, Callable &&func)
void PushAddress(const CAddress &addr)
CNodeSignals & GetNodeSignals()
bool IsLocal(const CService &addr)
void ForEachNodeThen(const Condition &cond, Callable &&pre, CallableAfter &&post) const
CCriticalSection cs_mapLocalHost
void SetSendVersion(int nVersionIn)
size_t SocketSendData(CNode *pnode)
ServiceFlags nRelevantServices
void RecordBytesRecv(uint64_t bytes)
void PushMessage(CNode *pnode, const std::string &sCommand, Args &&... args)
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target
std::atomic< int > nVersion
std::vector< CInv > vInventoryToSend
unsigned short GetListenPort()
bool IsLimited(enum Network net)
void PushMessageWithFlag(CNode *pnode, int flag, const std::string &sCommand, Args &&... args)
bool AddNode(const std::string &node)
std::vector< unsigned char > vchKeyedNetGroup
void SweepBanned()
clean unused entries (if bantime has expired)
uint64_t nMaxOutboundTimeframe
bool ForNode(NodeId id, Callable &&func)
std::list< CNetMessage > vRecvMsg
CCriticalSection cs_vProcessMsg