7 #if defined(HAVE_CONFIG_H) 38 #include <miniupnpc/miniupnpc.h> 39 #include <miniupnpc/miniwget.h> 40 #include <miniupnpc/upnpcommands.h> 41 #include <miniupnpc/upnperrors.h> 48 #define DUMP_ADDRESSES_INTERVAL 900 51 #define FEELER_SLEEP_WINDOW 1 53 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) 54 #define MSG_NOSIGNAL 0 60 #ifndef PROTECTION_LEVEL_UNRESTRICTED 61 #define PROTECTION_LEVEL_UNRESTRICTED 10 63 #ifndef IPV6_PROTECTION_LEVEL 64 #define IPV6_PROTECTION_LEVEL 23 102 return (
unsigned short)(
GetArg(
"-port",
Params().GetDefaultPort()));
112 int nBestReachability = -1;
117 int nScore = (*it).second.nScore;
118 int nReachability = (*it).first.GetReachabilityFrom(paddrPeer);
119 if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
121 addr =
CService((*it).first, (*it).second.nPort);
122 nBestReachability = nReachability;
127 return nBestScore >= 0;
131 static std::vector<CAddress>
convertSeed6(
const std::vector<SeedSpec6> &vSeedsIn)
137 const int64_t nOneWeek = 7*24*60*60;
138 std::vector<CAddress> vSeedsOut;
139 vSeedsOut.reserve(vSeedsIn.size());
140 for (std::vector<SeedSpec6>::const_iterator i(vSeedsIn.begin()); i != vSeedsIn.end(); ++i)
143 memcpy(&ip, i->addr,
sizeof(ip));
146 vSeedsOut.push_back(addr);
161 ret =
CAddress(addr, nLocalServices);
222 if (!fAlready || nScore >= info.
nScore) {
223 info.
nScore = nScore + (fAlready ? 1 : 0);
355 if (pszDest == NULL) {
358 if (
IsLocal(addrConnect) && !fConnectToMasternode)
377 LogPrint(
"net",
"trying connection %s lastseen=%.1fhrs\n",
378 pszDest ? pszDest : addrConnect.
ToString(),
383 bool proxyConnectionFailed =
false;
388 LogPrintf(
"Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
393 if (pszDest && addrConnect.
IsValid()) {
409 pnode->
addrName = std::string(pszDest);
423 if(fConnectToMasternode) {
433 }
else if (!proxyConnectionFailed) {
455 if (!bandb.
Write(banmap))
458 LogPrint(
"net",
"Flushed %d banned node ips/subnets to banlist.dat %dms\n",
467 LogPrint(
"net",
"disconnecting peer=%d\n",
id);
486 bool fResult =
false;
503 bool fResult =
false;
506 banmap_t::iterator i =
setBanned.find(subnet);
519 Ban(subNet, banReason, bantimeoffset, sinceUnixEpoch);
525 if (bantimeoffset <= 0)
528 sinceUnixEpoch =
false;
556 return Unban(subNet);
590 banmap_t::iterator it =
setBanned.begin();
599 LogPrint(
"net",
"%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.
ToString());
622 if (subnet.
Match(addr))
634 #define X(name) stats.name = name 662 int64_t nPingUsecWait = 0;
670 stats.
dPingWait = (((double)nPingUsecWait) / 1e6);
695 handled =
msg.readHeader(pch, nBytes);
697 handled =
msg.readData(pch, nBytes);
703 LogPrint(
"net",
"Oversized message from peer=%i, disconnecting\n",
GetId());
710 if (
msg.complete()) {
720 msg.nTime = nTimeMicros;
736 error(
"Send version already set for node: %i. Refusing to change from %i to %i",
id,
nSendVersion, nVersionIn);
758 unsigned int nRemaining = 24 -
nHdrPos;
759 unsigned int nCopy = std::min(nRemaining, nBytes);
772 catch (
const std::exception&) {
789 unsigned int nCopy = std::min(nRemaining, nBytes);
813 std::deque<CSerializeData>::iterator it = pnode->
vSendMsg.begin();
814 size_t nSentSize = 0;
816 while (it != pnode->
vSendMsg.end()) {
926 std::vector<NodeEvictionCandidate> vEvictionCandidates;
930 for(
size_t i = 0; i <
vNodes.size(); ++i) {
942 if (vEvictionCandidates.empty())
return false;
949 vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());
951 if (vEvictionCandidates.empty())
return false;
956 vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(8, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());
958 if (vEvictionCandidates.empty())
return false;
962 std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(),
CompareNodeTXTime);
963 vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());
965 if (vEvictionCandidates.empty())
return false;
970 vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());
972 if (vEvictionCandidates.empty())
return false;
977 vEvictionCandidates.erase(vEvictionCandidates.end() -
static_cast<int>(vEvictionCandidates.size() / 2), vEvictionCandidates.end());
979 if (vEvictionCandidates.empty())
return false;
983 std::vector<unsigned char> naMostConnections;
984 unsigned int nMostConnections = 0;
985 int64_t nMostConnectionsTime = 0;
986 std::map<std::vector<unsigned char>, std::vector<NodeEvictionCandidate> > mapAddrCounts;
987 for(
size_t i = 0; i < vEvictionCandidates.size(); ++i) {
989 mapAddrCounts[candidate.
vchNetGroup].push_back(candidate);
991 size_t groupsize = mapAddrCounts[candidate.
vchNetGroup].size();
993 if (groupsize > nMostConnections || (groupsize == nMostConnections && grouptime > nMostConnectionsTime)) {
994 nMostConnections = groupsize;
995 nMostConnectionsTime = grouptime;
1001 std::vector<NodeEvictionCandidate> vEvictionNodes = mapAddrCounts[naMostConnections];
1003 if(vEvictionNodes.empty()) {
1008 int nEvictionId = vEvictionNodes[0].id;
1011 for(
size_t i = 0; i <
vNodes.size(); ++i) {
1013 if(pnode->
id == nEvictionId) {
1024 struct sockaddr_storage sockaddr;
1025 socklen_t len =
sizeof(sockaddr);
1026 SOCKET hSocket = accept(hListenSocket.
socket, (
struct sockaddr*)&sockaddr, &len);
1032 if (!addr.
SetSockAddr((
const struct sockaddr*)&sockaddr))
1033 LogPrintf(
"Warning: Unknown socket family\n");
1052 LogPrintf(
"connection from %s dropped: not accepting new connections\n", addr.
ToString());
1059 LogPrintf(
"connection from %s dropped: non-selectable socket\n", addr.
ToString());
1068 setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (
const char*)&
set,
sizeof(
int));
1070 setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (
void*)&
set,
sizeof(
int));
1073 if (
IsBanned(addr) && !whitelisted)
1080 if (nInbound >= nMaxInbound)
1084 LogPrint(
"net",
"failed to find an eviction candidate - connection dropped (full)\n");
1092 LogPrintf(
"AcceptConnection -- masternode is not synced yet, skipping inbound connection attempt\n");
1111 unsigned int nPrevNodeCount = 0;
1120 std::vector<CNode*> vNodesCopy =
vNodes;
1121 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
1125 LogPrintf(
"ThreadSocketHandler -- removing node: peer=%d addr=%s nRefCount=%d fNetworkNode=%d fInbound=%d fMasternode=%d\n",
1150 BOOST_FOREACH(
CNode* pnode, vNodesDisconnectedCopy)
1155 bool fDelete =
false;
1176 vNodesSize =
vNodes.size();
1178 if(vNodesSize != nPrevNodeCount) {
1179 nPrevNodeCount = vNodesSize;
1187 struct timeval timeout;
1189 timeout.tv_usec = 50000;
1194 FD_ZERO(&fdsetRecv);
1195 FD_ZERO(&fdsetSend);
1196 FD_ZERO(&fdsetError);
1198 bool have_fds =
false;
1201 FD_SET(hListenSocket.
socket, &fdsetRecv);
1202 hSocketMax = std::max(hSocketMax, hListenSocket.
socket);
1212 FD_SET(pnode->
hSocket, &fdsetError);
1213 hSocketMax = std::max(hSocketMax, pnode->
hSocket);
1230 FD_SET(pnode->
hSocket, &fdsetSend);
1237 FD_SET(pnode->
hSocket, &fdsetRecv);
1242 int nSelect = select(have_fds ? hSocketMax + 1 : 0,
1243 &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
1253 for (
unsigned int i = 0; i <= hSocketMax; i++)
1254 FD_SET(i, &fdsetRecv);
1256 FD_ZERO(&fdsetSend);
1257 FD_ZERO(&fdsetError);
1277 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
1287 if (FD_ISSET(pnode->
hSocket, &fdsetRecv) || FD_ISSET(pnode->
hSocket, &fdsetError))
1292 char pchBuf[0x10000];
1293 int nBytes = recv(pnode->
hSocket, pchBuf,
sizeof(pchBuf), MSG_DONTWAIT);
1296 bool notify =
false;
1301 size_t nSizeAdded = 0;
1303 for (; it != pnode->
vRecvMsg.end(); ++it) {
1304 if (!it->complete())
1317 else if (nBytes == 0)
1321 LogPrint(
"net",
"socket closed\n");
1324 else if (nBytes < 0)
1344 if (FD_ISSET(pnode->
hSocket, &fdsetSend))
1402 void ThreadMapPort()
1405 const char * multicastif = 0;
1406 const char * minissdpdpath = 0;
1407 struct UPNPDev * devlist = 0;
1410 #ifndef UPNPDISCOVER_SUCCESS 1412 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
1413 #elif MINIUPNPC_API_VERSION < 14 1416 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &
error);
1420 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &
error);
1423 struct UPNPUrls urls;
1424 struct IGDdatas
data;
1427 r = UPNP_GetValidIGD(devlist, &urls, &
data, lanaddr,
sizeof(lanaddr));
1431 char externalIPAddress[40];
1432 r = UPNP_GetExternalIPAddress(urls.controlURL,
data.first.servicetype, externalIPAddress);
1433 if(r != UPNPCOMMAND_SUCCESS)
1434 LogPrintf(
"UPnP: GetExternalIPAddress() returned %d\n", r);
1437 if(externalIPAddress[0])
1440 if(
LookupHost(externalIPAddress, resolved,
false)) {
1446 LogPrintf(
"UPnP: GetExternalIPAddress failed.\n");
1454 #ifndef UPNPDISCOVER_SUCCESS 1456 r = UPNP_AddPortMapping(urls.controlURL,
data.first.servicetype,
1457 port.c_str(),
port.c_str(), lanaddr, strDesc.c_str(),
"TCP", 0);
1460 r = UPNP_AddPortMapping(urls.controlURL,
data.first.servicetype,
1461 port.c_str(),
port.c_str(), lanaddr, strDesc.c_str(),
"TCP", 0,
"0");
1464 if(r!=UPNPCOMMAND_SUCCESS)
1465 LogPrintf(
"AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
1466 port,
port, lanaddr, r, strupnperror(r));
1468 LogPrintf(
"UPnP Port Mapping successful.\n");
1473 catch (
const boost::thread_interrupted&)
1475 r = UPNP_DeletePortMapping(urls.controlURL,
data.first.servicetype,
port.c_str(),
"TCP", 0);
1476 LogPrintf(
"UPNP_DeletePortMapping() returned: %d\n", r);
1477 freeUPNPDevlist(devlist); devlist = 0;
1478 FreeUPNPUrls(&urls);
1482 LogPrintf(
"No valid UPnP IGDs found\n");
1483 freeUPNPDevlist(devlist); devlist = 0;
1485 FreeUPNPUrls(&urls);
1491 static boost::thread* upnp_thread = NULL;
1496 upnp_thread->interrupt();
1497 upnp_thread->join();
1500 upnp_thread =
new boost::thread(boost::bind(&
TraceThread<
void (*)()>,
"upnp", &ThreadMapPort));
1502 else if (upnp_thread) {
1503 upnp_thread->interrupt();
1504 upnp_thread->join();
1531 if (
vNodes.size() >= 2) {
1532 LogPrintf(
"P2P peers available. Skipped DNS seeding.\n");
1540 LogPrintf(
"Loading addresses from DNS seeds (could take a while)\n");
1546 std::vector<CNetAddr> vIPs;
1547 std::vector<CAddress> vAdd;
1550 BOOST_FOREACH(
const CNetAddr& ip, vIPs)
1552 int nOneDay = 24*3600;
1555 vAdd.push_back(addr);
1563 if (!vIPs.empty()) {
1565 Lookup(seed.
name.c_str(), seedSource, 0,
true);
1571 LogPrintf(
"%d addresses found from DNS seeds\n", found);
1592 LogPrint(
"net",
"Flushed %d addresses to peers.dat %dms\n",
1604 std::string strDest;
1625 for (int64_t nLoop = 0;; nLoop++)
1628 BOOST_FOREACH(
const std::string& strAddr,
mapMultiArgs[
"-connect"])
1632 for (
int i = 0; i < 10 && i < nLoop; i++)
1661 static bool done =
false;
1663 LogPrintf(
"Adding fixed seed nodes as DNS doesn't seem to be available.\n");
1679 std::set<std::vector<unsigned char> > setConnected;
1702 bool fFeeler =
false;
1705 if (nTime > nNextFeeler) {
1738 if (nANow - addr.
nLastTry < 600 && nTries < 30)
1756 LogPrint(
"net",
"Making feeler connection to %s\n", addrConnect.
ToString());
1766 std::vector<AddedNodeInfo> ret;
1768 std::list<std::string> lAddresses(0);
1772 BOOST_FOREACH(
const std::string& strAddNode,
vAddedNodes)
1773 lAddresses.push_back(strAddNode);
1778 std::map<CService, bool> mapConnected;
1779 std::map<std::string, std::pair<bool, CService>> mapConnectedByName;
1783 if (pnode->addr.IsValid()) {
1784 mapConnected[pnode->addr] = pnode->fInbound;
1786 if (!pnode->addrName.empty()) {
1787 mapConnectedByName[pnode->addrName] = std::make_pair(pnode->fInbound, static_cast<const CService&>(pnode->addr));
1792 BOOST_FOREACH(
const std::string& strAddNode, lAddresses) {
1796 auto it = mapConnected.find(service);
1797 if (it != mapConnected.end()) {
1798 ret.push_back(
AddedNodeInfo{strAddNode, service,
true, it->second});
1804 auto it = mapConnectedByName.find(strAddNode);
1805 if (it != mapConnectedByName.end()) {
1806 ret.push_back(
AddedNodeInfo{strAddNode, it->second.second,
true, it->second.first});
1823 for (
unsigned int i = 0;
true; i++)
1827 if (!info.fConnected) {
1858 if(
p.first ==
CService() ||
p.second.empty())
continue;
1870 std::vector<CInv> vToFetch;
1871 std::set<uint256>::iterator it =
p.second.begin();
1872 while(it !=
p.second.end()) {
1875 LogPrint(
"masternode",
"ThreadMnbRequestConnections -- asking for mnb %s from addr=%s\n", it->ToString(),
p.first.ToString());
1900 FindNode(addrConnect.ToStringIPPort()))
1902 }
else if (
FindNode(std::string(pszDest)))
1926 bool fMoreWork =
false;
1928 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
1935 fMoreWork |= (fMoreNodeWork && !pnode->
fPauseSend);
1953 condMsgProc.wait_until(lock, std::chrono::steady_clock::now() + std::chrono::milliseconds(100), [
this] {
return fMsgProcWake; });
1970 struct sockaddr_storage sockaddr;
1971 socklen_t len =
sizeof(sockaddr);
1972 if (!addrBind.
GetSockAddr((
struct sockaddr*)&sockaddr, &len))
1974 strError =
strprintf(
"Error: Bind address family for %s not supported", addrBind.
ToString());
1979 SOCKET hListenSocket = socket(((
struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
1988 strError =
"Error: Couldn't create a listenable socket for incoming connections";
1997 setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (
void*)&nOne,
sizeof(
int));
2001 setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (
void*)&nOne,
sizeof(
int));
2003 setsockopt(hListenSocket, IPPROTO_TCP, TCP_NODELAY, (
void*)&nOne,
sizeof(
int));
2005 setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (
const char*)&nOne,
sizeof(
int));
2006 setsockopt(hListenSocket, IPPROTO_TCP, TCP_NODELAY, (
const char*)&nOne,
sizeof(
int));
2021 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
const char*)&nOne,
sizeof(
int));
2023 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
void*)&nOne,
sizeof(
int));
2027 int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
2028 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (
const char*)&nProtLevel,
sizeof(
int));
2032 if (::bind(hListenSocket, (
struct sockaddr*)&sockaddr, len) ==
SOCKET_ERROR)
2036 strError =
strprintf(
_(
"Unable to bind to %s on this computer. Dash Core is probably already running."), addrBind.
ToString());
2069 char pszHostName[256] =
"";
2070 if (gethostname(pszHostName,
sizeof(pszHostName)) !=
SOCKET_ERROR)
2072 std::vector<CNetAddr> vaddr;
2075 BOOST_FOREACH (
const CNetAddr &addr, vaddr)
2084 struct ifaddrs* myaddrs;
2085 if (getifaddrs(&myaddrs) == 0)
2087 for (
struct ifaddrs* ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next)
2089 if (ifa->ifa_addr == NULL)
continue;
2090 if ((ifa->ifa_flags & IFF_UP) == 0)
continue;
2091 if (strcmp(ifa->ifa_name,
"lo") == 0)
continue;
2092 if (strcmp(ifa->ifa_name,
"lo0") == 0)
continue;
2093 if (ifa->ifa_addr->sa_family == AF_INET)
2095 struct sockaddr_in* s4 = (
struct sockaddr_in*)(ifa->ifa_addr);
2100 else if (ifa->ifa_addr->sa_family == AF_INET6)
2102 struct sockaddr_in6* s6 = (
struct sockaddr_in6*)(ifa->ifa_addr);
2108 freeifaddrs(myaddrs);
2116 LogPrint(
"net",
"SetNetworkActive: %s\n", active);
2153 return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
2187 LogPrintf(
"Invalid or missing peers.dat; recreating\n");
2197 if (bandb.
Read(banmap)) {
2202 LogPrint(
"net",
"Loaded %d banned node ips/subnets from banlist.dat %dms\n",
2205 LogPrintf(
"Invalid or missing banlist.dat; recreating\n");
2362 bool fUpdateConnectionTime =
false;
2364 if(fUpdateConnectionTime)
2421 if (strNode == *it) {
2436 for(std::vector<CNode*>::const_iterator it =
vNodes.begin(); it !=
vNodes.end(); ++it)
2447 vstats.reserve(
vNodes.size());
2448 for(std::vector<CNode*>::iterator it =
vNodes.begin(); it !=
vNodes.end(); ++it) {
2452 vstats.push_back(stats);
2460 pnode->fDisconnect =
true;
2469 if (
id == pnode->id) {
2470 pnode->fDisconnect =
true;
2487 ss << txLockRequest;
2499 CInv inv(nInv, hash);
2510 mapRelay.insert(std::make_pair(inv, ss));
2531 if(pnode->
nVersion >= minProtoVersion)
2564 if (limit > 0 && limit < recommendedMinimum)
2565 LogPrintf(
"Max outbound target is very small (%s bytes) and will be overshot. Recommended minimum is %s bytes.\n",
nMaxOutboundLimit, recommendedMinimum);
2591 return (cycleEndTime < now) ? 0 : cycleEndTime -
GetTime();
2612 if (historicalBlockServingLimit)
2654 nBestHeight.store(height, std::memory_order_release);
2659 return nBestHeight.load(std::memory_order_acquire);
2666 addrKnown(5000, 0.001),
2667 filterInventoryKnown(50000, 0.000001),
2734 LogPrint(
"net",
"Added connection peer=%d\n",
id);
2750 LogPrintf(
"CNode::AskFor -- WARNING: inventory message dropped: mapAskFor.size = %d, setAskFor.size = %d, MAPASKFOR_MAX_SZ = %d, SETASKFOR_MAX_SZ = %d, nSkipped = %d, peer=%d\n",
2766 int64_t nRequestTime;
2769 nRequestTime = it->second;
2777 static int64_t nLastTime;
2779 nNow = std::max(nNow, nLastTime);
2783 nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
2788 mapAskFor.insert(std::make_pair(nRequestTime, inv));
2803 std::vector<unsigned char> vchGroup;
2805 std::vector<unsigned char> vch(32);
2842 size_t nBytesSent = 0;
2848 bool optimisticSend(pnode->
vSendMsg.empty());
2859 if (optimisticSend ==
true)
2868 CNode* found =
nullptr;
2870 for (
auto&& pnode :
vNodes) {
2876 return found !=
nullptr && cond(found) && func(found);
2881 CNode* found =
nullptr;
2883 for (
auto&& pnode :
vNodes) {
2884 if(pnode->
id ==
id) {
2889 return found !=
nullptr && cond(found) && func(found);
2893 return nNow + (int64_t)(log1p(
GetRand(1ULL << 48) * -0.0000000000000035527136788 ) * average_interval_seconds * -1000000.0 + 0.5);
2898 std::vector<CNode*> vecNodesCopy;
2900 for(
size_t i = 0; i <
vNodes.size(); ++i) {
2903 vecNodesCopy.push_back(pnode);
2905 return vecNodesCopy;
2911 for(
size_t i = 0; i < vecNodes.size(); ++i) {
2912 CNode* pnode = vecNodes[i];
CCriticalSection cs_vAddedNodes
const std::vector< CDNSSeedData > & DNSSeeds() const
std::vector< CAddress > GetAddr()
Return a bunch of addresses, selected at random.
std::map< K, V >::const_iterator const_iterator
CNode * ConnectNode(CAddress addrConnect, const char *pszDest=NULL, bool fConnectToMasternode=false)
void MarkAddressGood(const CAddress &addr)
static const size_t SETASKFOR_MAX_SZ
CNodeSignals & GetNodeSignals()
CCriticalSection cs_vWhitelistedRange
bool GetLocal(CService &addr, const CNetAddr *paddrPeer)
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
CMasternodeSync masternodeSync
void Ban(const CNetAddr &netAddr, const BanReason &reason, int64_t bantimeoffset=0, bool sinceUnixEpoch=false)
static CNode * pnodeLocalHost
std::set< uint256 > setAskFor
unsigned int nSendBufferMaxSize
CRollingBloomFilter filterInventoryKnown
boost::signals2::signal< void(const std::string &message)> InitMessage
boost::signals2::signal< void(NodeId, bool &)> FinalizeNode
void ThreadMessageHandler()
std::atomic_bool fPauseSend
void RelayTransaction(const CTransaction &tx)
void SetThreadPriority(int nPriority)
bool AddLocal(const CService &addr, int nScore)
boost::signals2::signal< void(CNode *, CConnman &)> InitializeNode
void MilliSleep(int64_t n)
void MoveTo(CSemaphoreGrant &grant)
CClientUIInterface * clientInterface
ServiceFlags nLocalServices
#define TRY_LOCK(cs, name)
CSemaphoreGrant grantMasternodeOutbound
static void callCleanup()
boost::signals2::signal< bool(CNode *, CConnman &, std::atomic< bool > &), CombinerAll > SendMessages
static const ServiceFlags REQUIRED_SERVICES
static const bool DEFAULT_FORCEDNSSEED
unsigned int MaxBlockSize(bool fDIP0001Active)
uint64_t GetMaxOutboundTarget()
static bool CompareKeyedNetGroup(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
static std::vector< unsigned char > vchSecretKey
static constexpr const CFullyConnectedOnly FullyConnectedOnly
std::deque< std::string > vOneShots
std::string ToString() const
CService LookupNumeric(const char *pszName, int portDefault)
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
std::thread threadSocketHandler
void SetBanned(const banmap_t &banmap)
void CloseSocketDisconnect()
boost::signals2::signal< void(void)> BannedListChanged
CDataStream BeginMessage(CNode *node, int nVersion, int flags, const std::string &sCommand)
std::vector< ListenSocket > vhListenSocket
std::atomic_bool fPauseRecv
static void WriteLE32(unsigned char *ptr, uint32_t x)
#define FEELER_SLEEP_WINDOW
void SetLimited(enum Network net, bool fLimited)
static const int BIP0031_VERSION
BIP 0031, pong message, is enabled for all versions AFTER this one.
void GetBanned(banmap_t &banmap)
std::vector< unsigned char > vchNetGroup
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)
size_t size() const
Return the number of (unique) addresses in all tables.
int64_t nNextLocalAddrSend
const_iterator end() const
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
NodeEvictionCandidate(CNode *pnode)
void Good(const CService &addr, int64_t nTime=GetAdjustedTime())
Mark an entry as accessible.
void DeleteNode(CNode *pnode)
void RelayInv(CInv &inv, const int minProtoVersion=MIN_PEER_PROTO_VERSION)
unsigned short GetListenPort()
void EndMessage(CDataStream &strm)
static std::vector< unsigned char > CalculateKeyedNetGroup(CAddress &address)
bool SeenLocal(const CService &addr)
bool BindListenPort(const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
static bool CompareNodeBlockTime(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
std::string ToString(bool fUseGetnameinfo=true) const
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)
std::vector< unsigned char > GetGroup() const
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)
uint64_t nMaxOutboundLimit
static const int TIMEOUT_INTERVAL
bool Add(const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty=0)
Add a single address.
CCriticalSection cs_vOneShots
#define WSAGetLastError()
uint64_t nMaxOutboundTotalBytesSentInCycle
static bool CompareNodeTXTime(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
CCriticalSection cs_vSend
int readData(const char *pch, unsigned int nBytes)
bool Write(const banmap_t &banSet)
CCriticalSection cs_setBanned
void resize(size_type n, value_type c=0)
void ThreadOpenAddedConnections()
bool ConnectSocketByName(CService &addr, SOCKET &hSocketRet, const char *pszDest, int portDefault, int nTimeout, bool *outProxyConnectionFailed)
bool BannedSetIsDirty()
check is the banlist has unwritten changes
int GetBestHeight() const
void Finalize(unsigned char hash[OUTPUT_SIZE])
uint64_t GetTotalBytesRecv()
unsigned int GetReceiveFloodSize() const
void copyStats(CNodeStats &stats)
std::list< CNode * > vNodesDisconnected
int GetDefaultPort() const
void SetIP(const CNetAddr &ip)
unsigned int nReceiveFloodSize
void reserve(size_type n)
unsigned short GetPort() const
void scheduleEvery(Function f, int64_t deltaSeconds)
std::atomic_bool fSuccessfullyConnected
size_t GetNodeCount(NumConnections num)
bool SetSocketNonBlocking(SOCKET &hSocket, bool fNonBlocking)
std::vector< AddedNodeInfo > GetAddedNodeInfo()
std::map< CInv, CDataStream > mapRelay
uint64_t GetMaxOutboundTimeframe()
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, const std::string &addrNameIn="", bool fInboundIn=false, bool fNetworkNodeIn=false)
int64_t nLastTry
last try whatsoever by us (memory only)
CAddrInfo Select(bool newOnly=false)
bool Start(CScheduler &scheduler, std::string &strNodeError, Options options)
std::atomic< NodeId > nLastNodeId
std::atomic< int > nRecvVersion
void ReleaseNodeVector(const std::vector< CNode *> &vecNodes)
static bool IsSelectableSocket(SOCKET s)
std::map< CSubNet, CBanEntry > banmap_t
bool GetBoolArg(const std::string &strArg, bool fDefault)
bool RemoveAddedNode(const std::string &node)
void AskFor(const CInv &inv)
static bool NodeFullyConnected(const CNode *pnode)
int GetnScore(const CService &addr)
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
int64_t GetSystemTimeInSeconds()
std::string ToStringIPPort(bool fUseGetnameinfo=true) const
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
void GetNodeStats(std::vector< CNodeStats > &vstats)
const_iterator begin() 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)
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
bool ConnectSocket(const CService &addrDest, SOCKET &hSocketRet, int nTimeout, bool *outProxyConnectionFailed)
CCriticalSection cs_mapLocalHost
std::vector< CSubNet > vWhitelistedRange
void RecordBytesSent(uint64_t bytes)
void TraceThread(const char *name, Callable func)
std::vector< unsigned char > vchKeyedNetGroup
CClientUIInterface uiInterface
static bool error(const char *format)
std::map< CNetAddr, LocalServiceInfo > mapLocalHost
static const int MAX_OUTBOUND_MASTERNODE_CONNECTIONS
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached
const std::vector< std::string > & getAllNetMessageTypes()
void PushInventory(const CInv &inv)
std::thread threadDNSAddressSeed
boost::signals2::signal< void(int newNumConnections)> NotifyNumConnectionsChanged
std::atomic< bool > fDIP0001ActiveAtTip
void SetBestHeight(int height)
#define THREAD_PRIORITY_BELOW_NORMAL
uint256 Hash(const T1 pbegin, const T1 pend)
std::deque< pair< int64_t, CInv > > vRelayExpiration
std::deque< CSerializeData > vSendMsg
unsigned int nReceiveFloodSize
ServiceFlags GetLocalServices() const
std::string strSubVersion
std::vector< CNode * > CopyNodeVector()
void SetServices(const CService &addr, ServiceFlags nServices)
bool CloseSocket(SOCKET &hSocket)
#define DUMP_ADDRESSES_INTERVAL
ServiceFlags nLocalServices
std::string FormatFullVersion()
static const std::string NET_MESSAGE_COMMAND_OTHER
bool Read(banmap_t &banSet)
const CMessageHeader::MessageStartChars & MessageStart() const
void SetServices(const CService &addr, ServiceFlags nServices)
std::atomic< bool > flagInterruptMsgProc
ServiceFlags nLocalServices
V::value_type * begin_ptr(V &v)
bool SetSockAddr(const struct sockaddr *paddr)
bool Read(CAddrMan &addr)
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
bool IsReachable(enum Network net)
void AddWhitelistedRange(const CSubNet &subnet)
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds)
std::string ToString() const
CCriticalSection cs_mapRelay
void WakeMessageHandler()
std::thread threadOpenConnections
void Connected(const CService &addr, int64_t nTime=GetAdjustedTime())
Mark an entry as currently-connected-to.
int GetSendVersion() const
std::condition_variable condMsgProc
bool fAddressesInitialized
CSHA256 & Write(const unsigned char *data, size_t len)
static const unsigned int MAX_SIZE
static std::vector< CAddress > convertSeed6(const std::vector< SeedSpec6 > &vSeedsIn)
Convert the pnSeeds6 array into usable address objects.
bool RemoveLocal(const CService &addr)
const CChainParams & Params()
uint64_t GetTotalBytesSent()
std::vector< CNode * > vNodes
void * memcpy(void *a, const void *b, size_t c)
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes
void ThreadMnbRequestConnections()
std::atomic< int64_t > nLastTXTime
void ThreadSocketHandler()
static const int PROTOCOL_VERSION
const uint256 & GetHash() const
ServiceFlags GetLocalServices() const
std::vector< std::string > vAddedNodes
static const unsigned int DEFAULT_MISBEHAVING_BANTIME
CCriticalSection cs_filter
boost::signals2::signal< bool(CNode *, CConnman &, std::atomic< bool > &), CombinerAll > ProcessMessages
int64_t GetAdjustedTime()
void ThreadDNSAddressSeed()
uint64_t GetMaxOutboundTimeLeftInCycle()
response the time in second left in the current max outbound cycle
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes) ...
unsigned int GetSendBufferSize() const
mapMsgCmdSize mapRecvBytesPerMsgCmd
bool IsBanned(CNetAddr ip)
std::thread threadMessageHandler
unsigned int nSendBufferMaxSize
CNode * FindNode(const CNetAddr &ip)
void Discover(boost::thread_group &threadGroup)
void GetRandBytes(unsigned char *buf, int num)
bool IsWhitelistedRange(const CNetAddr &addr)
void InterruptSocks5(bool interrupt)
CSemaphoreGrant grantOutbound
class CNetCleanup instance_of_cnetcleanup
ServiceFlags nRelevantServices
bool HasTxLockRequest(const uint256 &txHash)
std::multimap< int64_t, CInv > mapAskFor
std::string GetArg(const std::string &strArg, const std::string &strDefault)
std::vector< char, zero_after_free_allocator< char > > CSerializeData
bool GetTxLockRequest(const uint256 &txHash, CTxLockRequest &txLockRequestRet)
CCriticalSection cs_vNodes
std::string NetworkErrorString(int err)
int64_t GetTime()
For unit testing.
std::pair< CService, std::set< uint256 > > PopScheduledMnbRequestConnection()
std::thread threadOpenAddedConnections
std::thread threadMnbRequestConnections
bool Write(const CAddrMan &addr)
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
std::atomic< int > nBestHeight
bool sleep_for(std::chrono::milliseconds rel_time)
static const int WARNING_INTERVAL
enum Network GetNetwork() const
void AddOneShot(const std::string &strDest)
void AcceptConnection(const ListenSocket &hListenSocket)
bool AttemptToEvictConnection()
CCriticalSection cs_totalBytesRecv
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
std::vector< CAddress > GetAddresses()
void ThreadOpenConnections()
int readHeader(const char *pch, unsigned int nBytes)
static constexpr const CAllNodes AllNodes
map< string, vector< string > > mapMultiArgs
bool Match(const CNetAddr &addr) const
void SetNetworkActive(bool active)
mapMsgCmdSize mapSendBytesPerMsgCmd
boost::signals2::signal< void(bool networkActive)> NotifyNetworkActiveChanged
static bool ReverseCompareNodeMinPingTime(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
static const unsigned int MAX_INV_SZ
limitedmap< uint256, int64_t > mapAlreadyAskedFor(MAX_INV_SZ)
void PushAddress(const CAddress &addr)
void Attempt(const CService &addr, int64_t nTime=GetAdjustedTime())
Mark an entry as connection attempted to.
static bool vfLimited[NET_MAX]
void SetSendVersion(int nVersionIn)
size_t SocketSendData(CNode *pnode)
ServiceFlags nRelevantServices
void AdvertiseLocal(CNode *pnode)
void RecordBytesRecv(uint64_t bytes)
static CDarksendBroadcastTx GetDSTX(const uint256 &hash)
void PushMessage(CNode *pnode, const std::string &sCommand, Args &&... args)
string SanitizeString(const string &str, int rule)
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target
static CNodeSignals g_signals
std::atomic< int > nVersion
bool IsLimited(enum Network net)
std::string _(const char *psz)
map< string, string > mapArgs
bool AddNode(const std::string &node)
bool IsLocal(const CService &addr)
std::vector< unsigned char > vchKeyedNetGroup
uint64_t GetRand(uint64_t nMax)
void SweepBanned()
clean unused entries (if bantime has expired)
uint64_t nMaxOutboundTimeframe
std::list< CNetMessage > vRecvMsg
static bool ReverseCompareNodeTimeConnected(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
CCriticalSection cs_vProcessMsg