 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
29 #include <arpa/inet.h>
32 #include <boost/signals2/signal.hpp>
45 static const int PING_INTERVAL = 2 * 60;
47 static const int TIMEOUT_INTERVAL = 20 * 60;
49 static const int FEELER_INTERVAL = 120;
51 static const unsigned int MAX_INV_SZ = 50000;
53 static const unsigned int MAX_LOCATOR_SZ = 101;
55 static const unsigned int MAX_ADDR_TO_SEND = 1000;
57 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024;
59 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
61 static const bool DEFAULT_LISTEN =
true;
64 static const bool DEFAULT_UPNP =
USE_UPNP;
66 static const bool DEFAULT_UPNP =
false;
69 static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
71 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
100 while (first != last) {
101 if (!(*first))
return false;
156 extern std::vector<CNode*>
vNodes;
158 extern std::map<CInv, CDataStream>
mapRelay;
178 extern std::map<CNetAddr, LocalServiceInfo>
mapLocalHost;
240 int readHeader(
const char* pch,
unsigned int nBytes);
241 int readData(
const char* pch,
unsigned int nBytes);
272 template <
typename Stream,
typename Operation>
293 return "node misbehaving";
295 return "manually added";
375 void Fuzz(
int nChance);
409 CNode(
SOCKET hSocketIn,
CAddress addrIn, std::string addrNameIn =
"",
bool fInboundIn =
false);
437 unsigned int total = 0;
439 total += msg.vRecv.size() + 24;
451 msg.SetVersion(nVersionIn);
504 void AskFor(
const CInv& inv,
bool fImmediateRetry =
false);
529 template <
typename T1>
542 template <
typename T1,
typename T2>
543 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2)
555 template <
typename T1,
typename T2,
typename T3>
556 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3)
568 template <
typename T1,
typename T2,
typename T3,
typename T4>
569 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4)
573 ssSend << a1 << a2 << a3 << a4;
581 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
582 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5)
586 ssSend << a1 << a2 << a3 << a4 << a5;
594 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
595 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6)
599 ssSend << a1 << a2 << a3 << a4 << a5 << a6;
607 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7>
608 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6,
const T7& a7)
612 ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7;
620 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8>
621 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6,
const T7& a7,
const T8& a8)
625 ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
633 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9>
634 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6,
const T7& a7,
const T8& a8,
const T9& a9)
638 ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
646 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
647 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6,
const T7& a7,
const T8& a8,
const T9& a9,
const T10& a10)
651 ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10;
659 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
typename T11>
660 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6,
const T7& a7,
const T8& a8,
const T9& a9,
const T10& a10,
const T11& a11)
664 ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10 << a11;
672 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
typename T11,
typename T12>
673 void PushMessage(
const char* pszCommand,
const T1& a1,
const T2& a2,
const T3& a3,
const T4& a4,
const T5& a5,
const T6& a6,
const T7& a7,
const T8& a8,
const T9& a9,
const T10& a10,
const T11& a11,
const T12& a12)
677 ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9 << a10 << a11 << a12;
688 if (type == strRequest)
return true;
697 if ((*it) == strRequest) {
712 void Subscribe(
unsigned int nChannel,
unsigned int nHops = 0);
735 static void Ban(
const CNetAddr &ip,
const BanReason &banReason, int64_t bantimeoffset = 0,
bool sinceUnixEpoch =
false);
736 static void Ban(
const CSubNet &subNet,
const BanReason &banReason, int64_t bantimeoffset = 0,
bool sinceUnixEpoch =
false);
808 #endif // BITCOIN_NET_H
int readData(const char *pch, unsigned int nBytes)
bool HasFulfilledRequest(std::string strRequest)
A combination of a network address (CNetAddr) and a (TCP) port.
CRollingBloomFilter filterInventoryKnown
bool Read(banmap_t &banSet)
CNode * FindNode(const CNetAddr &ip)
RecursiveMutex cs_inventory
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
static const int CURRENT_VERSION
std::vector< CNode * > vNodes
void insert(const std::vector< unsigned char > &vKey)
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8, const T9 &a9, const T10 &a10)
std::deque< CSerializeData > vSendMsg
static void SweepBanned()
clean unused entires (if bantime has expired)
static void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
bool DisconnectOldProtocol(int nVersionRequired, std::string strLastCommand="")
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
CRollingBloomFilter addrKnown
std::vector< std::string > vecRequestsFulfilled
unsigned int SendBufferSize()
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2)
boost::signals2::signal< void(NodeId)> FinalizeNode
#define EXCLUSIVE_LOCK_FUNCTION(...)
static uint64_t nTotalBytesRecv
#define UNLOCK_FUNCTION(...)
static uint64_t GetTotalBytesRecv()
static RecursiveMutex cs_vWhitelistedRange
unsigned int ReceiveFloodSize()
void AddInventoryKnown(const CInv &inv)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
static bool setBannedIsDirty
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
bool Write(const banmap_t &banSet)
STL-like map container that only keeps the N elements with the highest value.
RecursiveMutex cs_vAddedNodes
Information about a peer.
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
void PushInventory(const CInv &inv)
RecursiveMutex cs_mapRelay
bool fSuccessfullyConnected
void BeginMessage(const char *pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend)
void AbortMessage() UNLOCK_FUNCTION(cs_vSend)
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8, const T9 &a9)
std::vector< CInv > vInventoryToSend
int64_t nNextLocalAddrSend
void copyStats(CNodeStats &stats)
std::set< uint256 > setKnown
bool OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound=NULL, const char *strDest=NULL, bool fOneShot=false, bool fFeeler=false)
ServiceFlags
nServices flags
void CancelSubscribe(unsigned int nChannel)
static void Ban(const CNetAddr &ip, const BanReason &banReason, int64_t bantimeoffset=0, bool sinceUnixEpoch=false)
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
bool Write(const CAddrMan &addr)
void operator=(const CNode &)
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8)
std::vector< uint256 > vBlockRequested
std::atomic_bool fDisconnect
unsigned int GetTotalRecvSize()
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=NULL)
static RecursiveMutex cs_totalBytesRecv
bool contains(const std::vector< unsigned char > &vKey) const
ServiceFlags nLocalServices
void PushMessage(const char *pszCommand)
The basic transaction that is broadcasted on the network and contained in blocks.
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
int readHeader(const char *pch, unsigned int nBytes)
Access to the (IP) address database (peers.dat)
void FulfilledRequest(std::string strRequest)
static void SetBanned(const banmap_t &banmap)
RAII-style semaphore lock.
bool RemoveLocal(const CService &addr)
bool SeenLocal(const CService &addr)
vote for a local address
static void GetBanned(banmap_t &banmap)
static RecursiveMutex cs_totalBytesSent
void AddOneShot(std::string strDest)
static bool Unban(const CNetAddr &ip)
std::deque< CInv > vRecvGetData
limitedmap< CInv, int64_t > mapAlreadyAskedFor
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
bool IsLimited(enum Network net)
void PushMessage(const char *pszCommand, const T1 &a1)
static void RecordBytesRecv(uint64_t bytes)
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds)
Return a timestamp in the future (in microseconds) for exponentially distributed events.
bool IsSubscribed(unsigned int nChannel)
std::vector< AddedNodeInfo > GetAddedNodeInfo()
void MapPort(bool fUseUPnP)
bool DisconnectOldVersion(std::string strSubVer, int nHeight, std::string strLastCommand="")
RecursiveMutex cs_nLastNodeId
static banmap_t setBanned
void Subscribe(unsigned int nChannel, unsigned int nHops=0)
std::deque< CNetMessage > vRecvMsg
static void AddWhitelistedRange(const CSubNet &subnet)
std::map< CInv, CDataStream > mapRelay
static void RecordBytesSent(uint64_t bytes)
256-bit unsigned big integer.
void SetLimited(enum Network net, bool fLimited=true)
Make a particular network entirely off-limits (no automatic connects to it)
std::map< CSubNet, CBanEntry > banmap_t
void EndMessage() UNLOCK_FUNCTION(cs_vSend)
void AskFor(const CInv &inv, bool fImmediateRetry=false)
RecursiveMutex cs_mapLocalHost
Access to the banlist database (banlist.dat)
void RelayTransaction(const CTransaction &tx)
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
CSemaphoreGrant grantOutbound
boost::signals2::signal< bool(CNode *), CombinerAll > SendMessages
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
static void ClearBanned()
void SetRecvVersion(int nVersionIn)
CNetMessage(int nTypeIn, int nVersionIn)
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes)
static bool IsWhitelistedRange(const CNetAddr &ip)
ServiceFlags nServicesExpected
Stochastical (IP) address manager.
RecursiveMutex cs_sendProcessing
A CService with information about it as peer.
static uint64_t GetTotalBytesSent()
@ BanReasonNodeMisbehaving
std::string banReasonToString()
void SetVersion(int nVersionIn)
boost::signals2::signal< bool(CNode *), CombinerAll > ProcessMessages
CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn="", bool fInboundIn=false)
void CloseSocketDisconnect()
CAddress GetLocalAddress(const CNetAddr *paddrPeer=NULL)
void AdvertiseLocal(CNode *pnode)
static RecursiveMutex cs_setBanned
bool validateMasternodeIP(const std::string &addrStr)
void resize(size_type n, value_type c=0)
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3)
static uint64_t nTotalBytesSent
bool Read(CAddrMan &addr)
Double ended buffer combining vector and stream-like interfaces.
RecursiveMutex cs_vRecvMsg
bool operator()(I first, I last) const
std::vector< std::string > vAddedNodes
void StartNode(boost::thread_group &threadGroup, CScheduler &scheduler)
std::multimap< int64_t, CInv > mapAskFor
static bool IsBanned(CNetAddr ip)
void RelayTransactionLockReq(const CTransaction &tx, bool relayToAll=false)
boost::signals2::signal< void(NodeId, const CNode *)> InitializeNode
CBanEntry(int64_t nCreateTimeIn)
The block chain is a tree shaped structure starting with the genesis block at the root,...
void ClearFulfilledRequest(std::string strRequest)
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8, const T9 &a9, const T10 &a10, const T11 &a11)
void SocketSendData(CNode *pnode)
bool IsLocal(const CService &addr)
check whether a given address is potentially local
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
boost::signals2::signal< int()> GetHeight
static void callCleanup()
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
void AddressCurrentlyConnected(const CService &addr)
unsigned short GetListenPort()
uint64_t randrange(uint64_t range)
Generate a random integer in the range [0..range).
std::deque< std::pair< int64_t, CInv > > vRelayExpiration
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7)
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8, const T9 &a9, const T10 &a10, const T11 &a11, const T12 &a12)
std::vector< CAddress > vAddrToSend
static std::vector< CSubNet > vWhitelistedRange
void AddAddressKnown(const CAddress &addr)
std::vector< unsigned char > GetKey() const
bool IsPeerAddrLocalGood(CNode *pnode)
static bool BannedSetIsDirty()
check is the banlist has unwritten changes
CNodeSignals & GetNodeSignals()