9 #if defined(HAVE_CONFIG_H)
34 #include <miniupnpc/miniupnpc.h>
35 #include <miniupnpc/upnpcommands.h>
36 #include <miniupnpc/upnperrors.h>
39 #include <boost/thread.hpp>
44 #define DUMP_ADDRESSES_INTERVAL 900
47 #define FEELER_SLEEP_WINDOW 1
49 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
50 #define MSG_NOSIGNAL 0
54 const int MAX_OUTBOUND_CONNECTIONS = 16;
55 const int MAX_FEELER_CONNECTIONS = 1;
61 ListenSocket(
SOCKET socket,
bool whitelisted) : socket(socket), whitelisted(whitelisted) {}
76 static bool vfLimited[
NET_MAX] = {};
77 static CNode *pnodeLocalHost = NULL;
79 static std::vector <ListenSocket> vhListenSocket;
92 static std::deque<std::string> vOneShots;
111 vOneShots.push_back(strDest);
115 return (
unsigned short) (
GetArg(
"-port",
Params().GetDefaultPort()));
124 int nBestReachability = -1;
128 int nScore = (*it).second.nScore;
129 int nReachability = (*it).first.GetReachabilityFrom(paddrPeer);
130 if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) {
131 addr =
CService((*it).first, (*it).second.nPort);
132 nBestReachability = nReachability;
137 return nBestScore >= 0;
141 static std::vector<CAddress> convertSeed6(
const std::vector<SeedSpec6>& vSeedsIn)
147 const int64_t nOneWeek = 7 * 24 * 60 * 60;
148 std::vector<CAddress> vSeedsOut;
149 vSeedsOut.reserve(vSeedsIn.size());
150 for (std::vector<SeedSpec6>::const_iterator i(vSeedsIn.begin()); i != vSeedsIn.end(); ++i) {
152 memcpy(&ip, i->addr,
sizeof(ip));
155 vSeedsOut.push_back(addr);
224 if (!fAlready || nScore >= info.
nScore) {
225 info.
nScore = nScore + (fAlready ? 1 : 0);
249 vfLimited[net] = fLimited;
254 return vfLimited[net];
282 return !vfLimited[net];
335 if (pnode->
addr == addr)
344 if (pszDest == NULL) {
358 pszDest ? pszDest : addrConnect.
ToString(),
363 bool proxyConnectionFailed =
false;
365 &proxyConnectionFailed) :
367 if (!IsSelectableSocket(hSocket)) {
368 LogPrintf(
"Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
376 CNode *pnode =
new CNode(hSocket, addrConnect, pszDest ? pszDest :
"",
false);
388 }
else if (!proxyConnectionFailed) {
397 static void DumpBanlist()
410 if (!bandb.
Write(banmap))
433 LogPrintf(
"%s : peer=%d using obsolete version %i; disconnecting\n", __func__,
id,
nVersion);
452 LogPrintf(
"%s : peer=%d using unsupported version %i; disconnecting\n", __func__,
id,
strSubVer);
470 LogPrint(
BCLog::NET,
"send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION,
473 LogPrint(
BCLog::NET,
"send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight,
495 bool fResult =
false;
509 bool fResult =
false;
512 banmap_t::iterator i =
setBanned.find(subnet);
524 Ban(subNet, banReason, bantimeoffset, sinceUnixEpoch);
530 if (bantimeoffset <= 0) {
531 bantimeoffset =
GetArg(
"-bantime", 60 * 60 * 24);
532 sinceUnixEpoch =
false;
558 return Unban(subNet);
586 bool notifyUI =
false;
589 banmap_t::iterator it =
setBanned.begin();
627 if (subnet.Match(
addr))
639 #define X(name) stats.name = name
664 int64_t nPingUsecWait = 0;
671 stats.
dPingWait = (((double) nPingUsecWait) / 1e6);
694 handled = msg.
readData(pch, nBytes);
718 unsigned int nRemaining = 24 -
nHdrPos;
719 unsigned int nCopy = std::min(nRemaining, nBytes);
731 }
catch (
const std::exception &) {
747 unsigned int nCopy = std::min(nRemaining, nBytes);
763 std::deque<CSerializeData>::iterator it = pnode->
vSendMsg.begin();
765 while (it != pnode->
vSendMsg.end()) {
804 static std::list<CNode*> vNodesDisconnected;
836 std::vector<unsigned char> vchGroupA, vchGroupB;
838 std::vector<unsigned char> vchA(32), vchB(32);
841 vchGroupB =
b.addr.GetGroup();
864 static bool AttemptToEvictConnection(
bool fPreferNewConnection) {
865 std::vector<NodeEvictionCandidate> vEvictionCandidates;
870 if (node->fWhitelisted)
874 if (node->fDisconnect)
877 vEvictionCandidates.push_back(candidate);
881 if (vEvictionCandidates.empty())
return false;
888 std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), comparerNetGroupKeyed);
889 vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4,
static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());
891 if (vEvictionCandidates.empty())
return false;
895 std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeMinPingTime);
896 vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(8,
static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());
898 if (vEvictionCandidates.empty())
return false;
902 std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
903 vEvictionCandidates.erase(vEvictionCandidates.end() -
static_cast<int>(vEvictionCandidates.size() / 2), vEvictionCandidates.end());
905 if (vEvictionCandidates.empty())
return false;
909 std::vector<unsigned char> naMostConnections;
910 unsigned int nMostConnections = 0;
911 int64_t nMostConnectionsTime = 0;
912 std::map<std::vector<unsigned char>, std::vector<NodeEvictionCandidate> > mapAddrCounts;
914 mapAddrCounts[node.addr.GetGroup()].push_back(node);
915 int64_t grouptime = mapAddrCounts[node.addr.GetGroup()][0].nTimeConnected;
916 size_t groupsize = mapAddrCounts[node.addr.GetGroup()].size();
918 if (groupsize > nMostConnections || (groupsize == nMostConnections && grouptime > nMostConnectionsTime)) {
919 nMostConnections = groupsize;
920 nMostConnectionsTime = grouptime;
921 naMostConnections = node.addr.GetGroup();
926 vEvictionCandidates = mapAddrCounts[naMostConnections];
929 if (vEvictionCandidates.size() <= 1)
931 if (!fPreferNewConnection)
935 NodeId evicted = vEvictionCandidates.front().id;
937 for(std::vector<CNode*>::const_iterator it(
vNodes.begin()); it !=
vNodes.end(); ++it) {
938 if ((*it)->GetId() == evicted) {
939 (*it)->fDisconnect =
true;
946 static void AcceptConnection(
const ListenSocket& hListenSocket) {
947 struct sockaddr_storage sockaddr;
948 socklen_t len =
sizeof(sockaddr);
949 SOCKET hSocket = accept(hListenSocket.socket, (
struct sockaddr*)&sockaddr, &len);
952 int nMaxInbound =
nMaxConnections - (MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS);
955 if (!addr.
SetSockAddr((
const struct sockaddr*)&sockaddr))
956 LogPrintf(
"Warning: Unknown socket family\n");
973 if (!IsSelectableSocket(hSocket)) {
974 LogPrintf(
"connection from %s dropped: non-selectable socket\n", addr.
ToString());
986 if (!AttemptToEvictConnection(whitelisted)) {
988 LogPrint(
BCLog::NET,
"failed to find an eviction candidate - connection dropped (full)\n");
994 CNode* pnode =
new CNode(hSocket, addr,
"",
true);
1007 unsigned int nPrevNodeCount = 0;
1015 std::vector<CNode*> vNodesCopy =
vNodes;
1016 for (
CNode * pnode : vNodesCopy)
1033 vNodesDisconnected.push_back(pnode);
1039 std::list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected;
1040 for (
CNode * pnode : vNodesDisconnectedCopy)
1044 bool fDelete =
false;
1057 vNodesDisconnected.remove(pnode);
1066 vNodesSize =
vNodes.size();
1068 if (vNodesSize != nPrevNodeCount) {
1069 nPrevNodeCount = vNodesSize;
1076 struct timeval timeout;
1078 timeout.tv_usec = 50000;
1083 FD_ZERO(&fdsetRecv);
1084 FD_ZERO(&fdsetSend);
1085 FD_ZERO(&fdsetError);
1087 bool have_fds =
false;
1089 for (
const ListenSocket &hListenSocket : vhListenSocket) {
1090 FD_SET(hListenSocket.socket, &fdsetRecv);
1091 hSocketMax = std::max(hSocketMax, hListenSocket.socket);
1101 FD_SET(pnode->
hSocket, &fdsetError);
1102 hSocketMax = std::max(hSocketMax, pnode->
hSocket);
1123 FD_SET(pnode->
hSocket, &fdsetSend);
1129 if (lockRecv && (pnode->
vRecvMsg.empty() || !pnode->
vRecvMsg.front().complete() ||
1131 FD_SET(pnode->
hSocket, &fdsetRecv);
1136 int nSelect = select(have_fds ? hSocketMax + 1 : 0,
1137 &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
1138 boost::this_thread::interruption_point();
1144 for (
unsigned int i = 0; i <= hSocketMax; i++)
1145 FD_SET(i, &fdsetRecv);
1147 FD_ZERO(&fdsetSend);
1148 FD_ZERO(&fdsetError);
1155 for (
const ListenSocket &hListenSocket : vhListenSocket) {
1156 if (hListenSocket.socket !=
INVALID_SOCKET && FD_ISSET(hListenSocket.socket, &fdsetRecv)) {
1157 AcceptConnection(hListenSocket);
1164 std::vector<CNode*> vNodesCopy;
1168 for (
CNode * pnode : vNodesCopy)
1171 for (
CNode * pnode : vNodesCopy)
1173 boost::this_thread::interruption_point();
1180 if (FD_ISSET(pnode->
hSocket, &fdsetRecv) || FD_ISSET(pnode->
hSocket, &fdsetError)) {
1185 char pchBuf[0x10000];
1186 int nBytes = recv(pnode->
hSocket, pchBuf,
sizeof(pchBuf), MSG_DONTWAIT);
1193 }
else if (nBytes == 0) {
1198 }
else if (nBytes < 0) {
1217 if (FD_ISSET(pnode->
hSocket, &fdsetSend)) {
1231 }
else if (nTime - pnode->
nLastSend > TIMEOUT_INTERVAL) {
1235 (pnode->
nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90 * 60)) {
1247 for (
CNode * pnode : vNodesCopy)
1255 void ThreadMapPort()
1258 const char* multicastif = 0;
1259 const char* minissdpdpath = 0;
1260 struct UPNPDev* devlist = 0;
1263 #ifndef UPNPDISCOVER_SUCCESS
1265 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
1266 #elif MINIUPNPC_API_VERSION < 14
1269 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &
error);
1273 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &
error);
1276 struct UPNPUrls urls;
1277 struct IGDdatas data;
1280 r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr,
sizeof(lanaddr));
1283 char externalIPAddress[40];
1284 r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
1285 if (
r != UPNPCOMMAND_SUCCESS)
1286 LogPrintf(
"UPnP: GetExternalIPAddress() returned %d\n",
r);
1288 if (externalIPAddress[0]) {
1290 if (
LookupHost(externalIPAddress, resolved,
false)) {
1295 LogPrintf(
"UPnP: GetExternalIPAddress failed.\n");
1303 #ifndef UPNPDISCOVER_SUCCESS
1305 r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
1306 port.c_str(), port.c_str(), lanaddr, strDesc.c_str(),
"TCP", 0);
1309 r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
1310 port.c_str(), port.c_str(), lanaddr, strDesc.c_str(),
"TCP", 0,
"0");
1313 if (
r != UPNPCOMMAND_SUCCESS)
1314 LogPrintf(
"AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
1315 port, port, lanaddr,
r, strupnperror(
r));
1317 LogPrintf(
"UPnP Port Mapping successful.\n");
1322 }
catch (
const boost::thread_interrupted&) {
1323 r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(),
"TCP", 0);
1324 LogPrintf(
"UPNP_DeletePortMapping() returned : %d\n",
r);
1325 freeUPNPDevlist(devlist);
1327 FreeUPNPUrls(&urls);
1331 LogPrintf(
"No valid UPnP IGDs found\n");
1332 freeUPNPDevlist(devlist);
1335 FreeUPNPUrls(&urls);
1341 static boost::thread* upnp_thread = NULL;
1345 upnp_thread->interrupt();
1346 upnp_thread->join();
1349 upnp_thread =
new boost::thread(boost::bind(&
TraceThread<
void (*)()>,
"upnp", &ThreadMapPort));
1350 }
else if (upnp_thread) {
1351 upnp_thread->interrupt();
1352 upnp_thread->join();
1374 return strprintf(
"x%x.%s", *requiredServiceBits, data.
host);
1384 if (
vNodes.size() >= 3) {
1385 LogPrintf(
"P2P peers available. Skipped DNS seeding.\n");
1393 LogPrintf(
"Loading addresses from DNS seeds (could take a while)\n");
1399 std::vector<CNetAddr> vIPs;
1400 std::vector<CAddress> vAdd;
1402 if (
LookupHost(GetDNSHost(seed, &requiredServiceBits).c_str(), vIPs, 0,
true)) {
1405 int nOneDay = 24 * 3600;
1409 vAdd.push_back(addr);
1417 if (!vIPs.empty()) {
1419 Lookup(seed.name.c_str(), seedSource, 0,
true);
1425 LogPrintf(
"%d addresses found from DNS seeds\n", found);
1444 void static ProcessOneShot() {
1445 std::string strDest;
1448 if (vOneShots.empty())
1450 strDest = vOneShots.front();
1451 vOneShots.pop_front();
1464 for (int64_t nLoop = 0;; nLoop++) {
1469 for (
int i = 0; i < 10 && i < nLoop; i++) {
1481 int64_t nNextFeeler =
PoissonNextSend(nStart * 1000 * 1000, FEELER_INTERVAL);
1488 boost::this_thread::interruption_point();
1492 static bool done =
false;
1494 LogPrintf(
"Adding fixed seed nodes as DNS doesn't seem to be available.\n");
1510 std::set<std::vector<unsigned char> > setConnected;
1534 bool fFeeler =
false;
1535 if (nOutbound >= MAX_OUTBOUND_CONNECTIONS) {
1537 if (nTime > nNextFeeler) {
1565 if ((addr.
nServices & REQUIRED_SERVICES) != REQUIRED_SERVICES)
1569 if (nANow - addr.
nLastTry < 600 && nTries < 30)
1573 if (addr.
GetPort() !=
Params().GetDefaultPort() && nTries < 50)
1595 std::vector<AddedNodeInfo> ret;
1597 std::list<std::string> lAddresses(0);
1602 lAddresses.push_back(strAddNode);
1607 std::map<CService, bool> mapConnected;
1608 std::map<std::string, std::pair<bool, CService> > mapConnectedByName;
1621 for (std::string& strAddNode : lAddresses) {
1625 auto it = mapConnected.find(service);
1626 if (it != mapConnected.end()) {
1627 ret.push_back(
AddedNodeInfo{strAddNode, service,
true, it->second});
1633 auto it = mapConnectedByName.find(strAddNode);
1634 if (it != mapConnectedByName.end()) {
1635 ret.push_back(
AddedNodeInfo{strAddNode, it->second.second,
true, it->second.first});
1652 for (
unsigned int i = 0;
true; i++) {
1655 if (!info.fConnected) {
1675 boost::this_thread::interruption_point();
1679 FindNode(addrConnect.ToStringIPPort()))
1685 boost::this_thread::interruption_point();
1701 boost::mutex condition_mutex;
1702 boost::unique_lock<boost::mutex> lock(condition_mutex);
1706 std::vector<CNode*> vNodesCopy;
1710 for (
CNode * pnode : vNodesCopy)
1717 for (
CNode * pnode : vNodesCopy)
1736 boost::this_thread::interruption_point();
1742 boost::this_thread::interruption_point();
1747 for (
CNode * pnode : vNodesCopy)
1753 boost::posix_time::milliseconds(100));
1762 struct sockaddr_storage sockaddr;
1763 socklen_t len =
sizeof(sockaddr);
1764 if (!addrBind.
GetSockAddr((
struct sockaddr *) &sockaddr, &len)) {
1765 strError =
strprintf(
"Error: Bind address family for %s not supported", addrBind.
ToString());
1770 SOCKET hListenSocket = socket(((
struct sockaddr *) &sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
1772 strError =
strprintf(
"Error: Couldn't open socket for incoming connections (socket returned error %s)",
1777 if (!IsSelectableSocket(hListenSocket)) {
1778 strError =
"Error: Couldn't create a listenable socket for incoming connections";
1787 setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (
void*)&nOne,
sizeof(
int));
1791 setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (
void *) &nOne,
sizeof(
int));
1796 strError =
strprintf(
"BindListenPort: Setting listening socket to non-blocking failed, error %s\n",
1807 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
const char*)&nOne,
sizeof(
int));
1809 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
void*)&nOne,
sizeof(
int));
1813 int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
1814 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (
const char*)&nProtLevel,
sizeof(
int));
1818 if (::bind(hListenSocket, (
struct sockaddr *) &sockaddr, len) ==
SOCKET_ERROR) {
1821 strError =
strprintf(
_(
"Unable to bind to %s on this computer. PRCY is probably already running."),
1824 strError =
strprintf(
_(
"Unable to bind to %s on this computer (bind returned error %s)"),
1833 if (listen(hListenSocket, SOMAXCONN) ==
SOCKET_ERROR) {
1834 strError =
strprintf(
_(
"Error: Listening for incoming connections failed (listen returned error %s)"),
1841 vhListenSocket.push_back(ListenSocket(hListenSocket, fWhitelisted));
1849 void static Discover(boost::thread_group &threadGroup) {
1855 char pszHostName[256] =
"";
1856 if (gethostname(pszHostName,
sizeof(pszHostName)) !=
SOCKET_ERROR) {
1857 std::vector<CNetAddr> vaddr;
1858 if (
LookupHost(pszHostName, vaddr, 0,
true)) {
1859 for (
const CNetAddr& addr : vaddr) {
1867 struct ifaddrs *myaddrs;
1868 if (getifaddrs(&myaddrs) == 0) {
1869 for (
struct ifaddrs *ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
1870 if (ifa->ifa_addr == NULL)
continue;
1871 if ((ifa->ifa_flags & IFF_UP) == 0)
continue;
1872 if (strcmp(ifa->ifa_name,
"lo") == 0)
continue;
1873 if (strcmp(ifa->ifa_name,
"lo0") == 0)
continue;
1874 if (ifa->ifa_addr->sa_family == AF_INET) {
1875 struct sockaddr_in *s4 = (
struct sockaddr_in *) (ifa->ifa_addr);
1879 }
else if (ifa->ifa_addr->sa_family == AF_INET6) {
1880 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) (ifa->ifa_addr);
1886 freeifaddrs(myaddrs);
1901 LogPrintf(
"Invalid or missing peers.dat; recreating\n");
1911 if (bandb.
Read(banmap)) {
1919 LogPrintf(
"Invalid or missing banlist.dat; recreating\n");
1929 if (semOutbound == NULL) {
1931 int nMaxOutbound = std::min((MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS),
nMaxConnections);
1935 if (pnodeLocalHost == NULL) {
1941 Discover(threadGroup);
1976 for (
int i = 0; i < (MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS); i++)
1977 semOutbound->
post();
1996 for (ListenSocket & hListenSocket : vhListenSocket)
2004 for (
CNode * pnode : vNodesDisconnected)
2007 vNodesDisconnected.clear();
2008 vhListenSocket.clear();
2011 delete pnodeLocalHost;
2012 pnodeLocalHost = NULL;
2046 mapRelay.insert(std::make_pair(inv, ss));
2109 if (
GetRand(nChance) != 0)
return;
2130 char ch = (char)
GetRand(256);
2150 unsigned short randv = 0;
2152 std::string tmpfn =
strprintf(
"peers.dat.%04x", randv);
2166 return error(
"%s : Failed to open file %s", __func__,
pathAddr.string());
2171 }
catch (
const std::exception& e) {
2172 return error(
"%s : Serialize or I/O error - %s", __func__, e.what());
2185 return error(
"%s : Failed to open file %s", __func__,
pathAddr.string());
2188 uint64_t fileSize = fs::file_size(
pathAddr);
2189 uint64_t dataSize = fileSize -
sizeof(
uint256);
2191 if (fileSize >=
sizeof(
uint256))
2192 dataSize = fileSize -
sizeof(
uint256);
2194 return error(
"%s : Failed to open file %s", __func__,
pathAddr.string());
2196 std::vector<unsigned char> vchData;
2197 vchData.resize(dataSize);
2202 filein.
read((
char *) &vchData[0], dataSize);
2204 }
catch (
const std::exception& e) {
2205 return error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
2213 if (hashIn != hashTmp)
2214 return error(
"%s : Checksum mismatch, data corrupted", __func__);
2216 return Read(addr, ssPeers);
2221 unsigned char pchMsgTmp[4];
2227 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
2228 return error(
"%s : Invalid network magic number", __func__);
2232 }
catch (
const std::exception& e) {
2235 return error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
2247 addrKnown(5000, 0.001),
2248 filterInventoryKnown(50000, 0.000001)
2317 if (
mapAskFor.size() > MAPASKFOR_MAX_SZ)
2321 int64_t nRequestTime;
2324 nRequestTime = it->second;
2333 static int64_t nLastTime;
2335 nNow = std::max(nNow, nLastTime);
2339 nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
2340 if (fImmediateRetry)
2341 nRequestTime = nNow;
2343 nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
2348 mapAskFor.insert(std::make_pair(nRequestTime, inv));
2353 assert(ssSend.size() == 0);
2375 if (
mapArgs.count(
"-fuzzmessagestest"))
2389 unsigned int nChecksum = 0;
2390 memcpy(&nChecksum, &hash,
sizeof(nChecksum));
2417 unsigned short randv = 0;
2419 std::string tmpfn =
strprintf(
"banlist.dat.%04x", randv);
2423 ssBanlist << banSet;
2431 return error(
"%s: Failed to open file %s", __func__, pathTmp.string());
2434 fileout << ssBanlist;
2436 catch (
const std::exception& e) {
2437 return error(
"%s: Serialize or I/O error - %s", __func__, e.what());
2443 return error(
"%s: Rename-into-place failed", __func__);
2452 return error(
"%s: Failed to open file %s", __func__,
pathBanlist.string());
2455 uint64_t dataSize = 0;
2457 if (fileSize >=
sizeof(
uint256))
2458 dataSize = fileSize -
sizeof(
uint256);
2459 std::vector<unsigned char> vchData;
2460 vchData.resize(dataSize);
2464 filein.
read((
char *) &vchData[0], dataSize);
2467 catch (
const std::exception& e) {
2468 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
2474 if (hashIn != hashTmp)
2475 return error(
"%s: Checksum mismatch, data corrupted", __func__);
2476 unsigned char pchMsgTmp[4];
2481 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
2482 return error(
"%s: Invalid network magic number", __func__);
2484 ssBanlist >> banSet;
2486 catch (
const std::exception& e) {
2487 return error(
"%s: Deserialize or I/O error - %s", __func__, e.what());
2496 if (
LookupHost(addrStr.c_str(), resolved,
false)) {
2504 return nNow + (int64_t)(log1p(
GetRand(1ULL << 48) * -0.0000000000000035527136788 ) * average_interval_seconds * -1000000.0 + 0.5);