6 #if defined(HAVE_CONFIG_H)
24 #include <miniupnpc/miniupnpc.h>
25 #include <miniupnpc/miniwget.h>
26 #include <miniupnpc/upnpcommands.h>
27 #include <miniupnpc/upnperrors.h>
30 #include <boost/filesystem.hpp>
33 #define DUMP_ADDRESSES_INTERVAL 900
35 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
36 #define MSG_NOSIGNAL 0
40 using namespace boost;
91 vOneShots.push_back(strDest);
96 return (
unsigned short)(
GetArg(
"-port",
Params().GetDefaultPort()));
106 int nBestReachability = -1;
108 LOCK(cs_mapLocalHost);
109 for (map<CNetAddr, LocalServiceInfo>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++)
111 int nScore = (*it).second.nScore;
112 int nReachability = (*it).first.GetReachabilityFrom(paddrPeer);
113 if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
115 addr =
CService((*it).first, (*it).second.nPort);
116 nBestReachability = nReachability;
121 return nBestScore >= 0;
144 int nBytes = recv(hSocket, &c, 1, 0);
152 if (strLine.size() >= 9000)
155 else if (nBytes <= 0)
157 boost::this_thread::interruption_point();
169 if (!strLine.empty())
193 BOOST_FOREACH(
CNode* pnode, vNodes)
209 LOCK(cs_mapLocalHost);
230 LOCK(cs_mapLocalHost);
231 bool fAlready = mapLocalHost.count(addr) > 0;
233 if (!fAlready || nScore >= info.
nScore) {
234 info.
nScore = nScore + (fAlready ? 1 : 0);
255 LOCK(cs_mapLocalHost);
261 LOCK(cs_mapLocalHost);
274 LOCK(cs_mapLocalHost);
275 if (mapLocalHost.count(addr) == 0)
277 mapLocalHost[addr].nScore++;
288 LOCK(cs_mapLocalHost);
289 return mapLocalHost.count(addr) > 0;
295 LOCK(cs_mapLocalHost);
304 return error(
"GetMyExternalIP() : connection to %s failed", addrConnect.
ToString());
320 if (pszKeyword == NULL)
322 if (strLine.find(pszKeyword) != string::npos)
324 strLine = strLine.substr(strLine.find(pszKeyword) + strlen(pszKeyword));
329 if (strLine.find(
"<") != string::npos)
330 strLine = strLine.substr(0, strLine.find(
"<"));
331 strLine = strLine.substr(strspn(strLine.c_str(),
" \t\n\r"));
332 while (strLine.size() > 0 && isspace(strLine[strLine.size()-1]))
333 strLine.resize(strLine.size()-1);
343 return error(
"GetMyExternalIP() : connection closed");
350 const char* pszKeyword;
352 for (
int nLookup = 0; nLookup <= 1; nLookup++)
353 for (
int nHost = 1; nHost <= 1; nHost++)
361 addrConnect =
CService(
"91.198.22.70", 80);
365 CService addrIP(
"checkip.dyndns.org", 80,
true);
367 addrConnect = addrIP;
370 pszGet =
"GET / HTTP/1.1\r\n"
371 "Host: checkip.dyndns.org\r\n"
372 "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n"
373 "Connection: close\r\n"
376 pszKeyword =
"Address:";
416 BOOST_FOREACH(
CNode* pnode, vNodes)
425 BOOST_FOREACH(
CNode* pnode, vNodes)
434 BOOST_FOREACH(
CNode* pnode, vNodes)
442 if (pszDest == NULL) {
457 LogPrint(
"net",
"trying connection %s lastseen=%.1fhrs\n",
458 pszDest ? pszDest : addrConnect.
ToString(),
467 LogPrint(
"net",
"connected %s\n", pszDest ? pszDest : addrConnect.
ToString());
472 if (ioctlsocket(hSocket, FIONBIO, &nOne) ==
SOCKET_ERROR)
475 if (fcntl(hSocket, F_SETFL, O_NONBLOCK) ==
SOCKET_ERROR)
480 CNode* pnode =
new CNode(hSocket, addrConnect, pszDest ? pszDest :
"",
false);
485 vNodes.push_back(pnode);
502 LogPrint(
"net",
"disconnecting node %s\n", addrName);
513 if (
this == pnodeSync)
524 int nBestHeight = g_signals.
GetHeight().get_value_or(0);
531 LogPrint(
"net",
"send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n",
PROTOCOL_VERSION, nBestHeight, addrMe.
ToString(), addrYou.
ToString(), addr.ToString());
550 bool fResult =
false;
553 std::map<CNetAddr, int64_t>::iterator i = setBanned.find(ip);
554 if (i != setBanned.end())
556 int64_t t = (*i).second;
568 if (setBanned[addr] < banTime)
569 setBanned[addr] = banTime;
575 #define X(name) stats.name = name
578 stats.
nodeid = this->GetId();
598 int64_t nPingUsecWait = 0;
599 if ((0 != nPingNonceSent) && (0 != nPingUsecStart)) {
604 stats.
dPingTime = (((double)nPingUsecTime) / 1e6);
605 stats.
dPingWait = (((double)nPingUsecWait) / 1e6);
608 stats.
addrLocal = addrLocal.IsValid() ? addrLocal.ToString() :
"";
618 if (vRecvMsg.empty() ||
619 vRecvMsg.back().complete())
629 handled = msg.
readData(pch, nBytes);
644 unsigned int nRemaining = 24 - nHdrPos;
645 unsigned int nCopy = std::min(nRemaining, nBytes);
647 memcpy(&hdrbuf[nHdrPos], pch, nCopy);
658 catch (std::exception &e) {
668 vRecv.resize(hdr.nMessageSize);
675 unsigned int nRemaining = hdr.nMessageSize - nDataPos;
676 unsigned int nCopy = std::min(nRemaining, nBytes);
678 memcpy(&vRecv[nDataPos], pch, nCopy);
695 std::deque<CSerializeData>::iterator it = pnode->
vSendMsg.begin();
697 while (it != pnode->
vSendMsg.end()) {
740 unsigned int nPrevNodeCount = 0;
749 vector<CNode*> vNodesCopy =
vNodes;
750 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
756 vNodes.erase(
remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());
768 vNodesDisconnected.push_back(pnode);
775 BOOST_FOREACH(
CNode* pnode, vNodesDisconnectedCopy)
780 bool fDelete =
false;
796 vNodesDisconnected.remove(pnode);
802 if(vNodes.size() != nPrevNodeCount) {
803 nPrevNodeCount = vNodes.size();
811 struct timeval timeout;
813 timeout.tv_usec = 50000;
820 FD_ZERO(&fdsetError);
822 bool have_fds =
false;
824 BOOST_FOREACH(
SOCKET hListenSocket, vhListenSocket) {
825 FD_SET(hListenSocket, &fdsetRecv);
826 hSocketMax = max(hSocketMax, hListenSocket);
831 BOOST_FOREACH(
CNode* pnode, vNodes)
835 FD_SET(pnode->
hSocket, &fdsetError);
836 hSocketMax = max(hSocketMax, pnode->
hSocket);
856 if (lockSend && !pnode->
vSendMsg.empty()) {
857 FD_SET(pnode->
hSocket, &fdsetSend);
866 FD_SET(pnode->
hSocket, &fdsetRecv);
871 int nSelect = select(have_fds ? hSocketMax + 1 : 0,
872 &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
873 boost::this_thread::interruption_point();
881 for (
unsigned int i = 0; i <= hSocketMax; i++)
882 FD_SET(i, &fdsetRecv);
885 FD_ZERO(&fdsetError);
893 BOOST_FOREACH(
SOCKET hListenSocket, vhListenSocket)
894 if (hListenSocket !=
INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv))
896 struct sockaddr_storage sockaddr;
897 socklen_t len =
sizeof(sockaddr);
898 SOCKET hSocket = accept(hListenSocket, (
struct sockaddr*)&sockaddr, &len);
903 if (!addr.
SetSockAddr((
const struct sockaddr*)&sockaddr))
904 LogPrintf(
"Warning: Unknown socket family\n");
908 BOOST_FOREACH(
CNode* pnode, vNodes)
919 else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
931 CNode* pnode =
new CNode(hSocket, addr,
"",
true);
935 vNodes.push_back(pnode);
944 vector<CNode*> vNodesCopy;
948 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
951 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
953 boost::this_thread::interruption_point();
960 if (FD_ISSET(pnode->
hSocket, &fdsetRecv) || FD_ISSET(pnode->
hSocket, &fdsetError))
967 char pchBuf[0x10000];
968 int nBytes = recv(pnode->
hSocket, pchBuf,
sizeof(pchBuf), MSG_DONTWAIT);
977 else if (nBytes == 0)
1004 if (FD_ISSET(pnode->
hSocket, &fdsetSend))
1030 LogPrintf(
"socket inactivity timeout\n");
1037 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
1052 void ThreadMapPort()
1055 const char * multicastif = 0;
1056 const char * minissdpdpath = 0;
1057 struct UPNPDev * devlist = 0;
1060 #ifndef UPNPDISCOVER_SUCCESS
1062 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
1066 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
1069 struct UPNPUrls urls;
1070 struct IGDdatas
data;
1073 r = UPNP_GetValidIGD(devlist, &urls, &
data, lanaddr,
sizeof(lanaddr));
1077 char externalIPAddress[40];
1078 r = UPNP_GetExternalIPAddress(urls.controlURL,
data.first.servicetype, externalIPAddress);
1079 if(r != UPNPCOMMAND_SUCCESS)
1080 LogPrintf(
"UPnP: GetExternalIPAddress() returned %d\n", r);
1083 if(externalIPAddress[0])
1085 LogPrintf(
"UPnP: ExternalIPAddress = %s\n", externalIPAddress);
1089 LogPrintf(
"UPnP: GetExternalIPAddress failed.\n");
1097 #ifndef UPNPDISCOVER_SUCCESS
1099 r = UPNP_AddPortMapping(urls.controlURL,
data.first.servicetype,
1100 port.c_str(), port.c_str(), lanaddr, strDesc.c_str(),
"TCP", 0);
1103 r = UPNP_AddPortMapping(urls.controlURL,
data.first.servicetype,
1104 port.c_str(), port.c_str(), lanaddr, strDesc.c_str(),
"TCP", 0,
"0");
1107 if(r!=UPNPCOMMAND_SUCCESS)
1108 LogPrintf(
"AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
1109 port, port, lanaddr, r, strupnperror(r));
1111 LogPrintf(
"UPnP Port Mapping successful.\n");;
1116 catch (boost::thread_interrupted)
1118 r = UPNP_DeletePortMapping(urls.controlURL,
data.first.servicetype, port.c_str(),
"TCP", 0);
1119 LogPrintf(
"UPNP_DeletePortMapping() returned : %d\n", r);
1120 freeUPNPDevlist(devlist); devlist = 0;
1121 FreeUPNPUrls(&urls);
1125 LogPrintf(
"No valid UPnP IGDs found\n");
1126 freeUPNPDevlist(devlist); devlist = 0;
1128 FreeUPNPUrls(&urls);
1134 static boost::thread* upnp_thread = NULL;
1139 upnp_thread->interrupt();
1140 upnp_thread->join();
1143 upnp_thread =
new boost::thread(boost::bind(&
TraceThread<
void (*)()>,
"upnp", &ThreadMapPort));
1145 else if (upnp_thread) {
1146 upnp_thread->interrupt();
1147 upnp_thread->join();
1168 if ((addrman.
size() > 0) &&
1173 if (vNodes.size() >= 2) {
1174 LogPrintf(
"P2P peers available. Skipped DNS seeding.\n");
1182 LogPrintf(
"Loading addresses from DNS seeds (could take a while)\n");
1188 vector<CNetAddr> vIPs;
1189 vector<CAddress> vAdd;
1194 int nOneDay = 24*3600;
1197 vAdd.push_back(addr);
1205 LogPrintf(
"%d addresses found from DNS seeds\n", found);
1226 LogPrint(
"net",
"Flushed %d addresses to peers.dat %dms\n",
1235 if (vOneShots.empty())
1237 strDest = vOneShots.front();
1238 vOneShots.pop_front();
1253 for (int64_t nLoop = 0;; nLoop++)
1256 BOOST_FOREACH(
string strAddr,
mapMultiArgs[
"-connect"])
1260 for (
int i = 0; i < 10 && i < nLoop; i++)
1278 boost::this_thread::interruption_point();
1281 if (addrman.
size() == 0 && (
GetTime() - nStart > 60)) {
1282 static bool done =
false;
1284 LogPrintf(
"Adding fixed seed nodes as DNS doesn't seem to be available.\n");
1298 set<vector<unsigned char> > setConnected;
1301 BOOST_FOREACH(
CNode* pnode, vNodes) {
1332 if (nANow - addr.
nLastTry < 600 && nTries < 30)
1351 LOCK(cs_vAddedNodes);
1357 list<string> lAddresses(0);
1359 LOCK(cs_vAddedNodes);
1360 BOOST_FOREACH(
string& strAddNode, vAddedNodes)
1361 lAddresses.push_back(strAddNode);
1363 BOOST_FOREACH(
string& strAddNode, lAddresses) {
1373 for (
unsigned int i = 0;
true; i++)
1375 list<string> lAddresses(0);
1377 LOCK(cs_vAddedNodes);
1378 BOOST_FOREACH(
string& strAddNode, vAddedNodes)
1379 lAddresses.push_back(strAddNode);
1382 list<vector<CService> > lservAddressesToAdd(0);
1383 BOOST_FOREACH(
string& strAddNode, lAddresses)
1385 vector<CService> vservNode(0);
1388 lservAddressesToAdd.push_back(vservNode);
1390 LOCK(cs_setservAddNodeAddresses);
1391 BOOST_FOREACH(
CService& serv, vservNode)
1392 setservAddNodeAddresses.insert(serv);
1400 BOOST_FOREACH(
CNode* pnode, vNodes)
1401 for (list<vector<CService> >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++)
1402 BOOST_FOREACH(
CService& addrNode, *(it))
1403 if (pnode->
addr == addrNode)
1405 it = lservAddressesToAdd.erase(it);
1410 BOOST_FOREACH(vector<CService>& vserv, lservAddressesToAdd)
1426 boost::this_thread::interruption_point();
1430 FindNode(addrConnect.ToStringIPPort().c_str()))
1436 boost::this_thread::interruption_point();
1457 CNode *pnodeNewSync = NULL;
1458 int64_t nBestScore = 0;
1460 int nBestHeight = g_signals.
GetHeight().get_value_or(0);
1463 BOOST_FOREACH(
CNode* pnode, vNodes) {
1471 if (pnodeNewSync == NULL || nScore > nBestScore) {
1472 pnodeNewSync = pnode;
1473 nBestScore = nScore;
1480 pnodeSync = pnodeNewSync;
1489 bool fHaveSyncNode =
false;
1491 vector<CNode*> vNodesCopy;
1495 BOOST_FOREACH(
CNode* pnode, vNodesCopy) {
1497 if (pnode == pnodeSync)
1498 fHaveSyncNode =
true;
1506 CNode* pnodeTrickle = NULL;
1507 if (!vNodesCopy.empty())
1508 pnodeTrickle = vNodesCopy[
GetRand(vNodesCopy.size())];
1512 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
1534 boost::this_thread::interruption_point();
1542 boost::this_thread::interruption_point();
1547 BOOST_FOREACH(
CNode* pnode, vNodesCopy)
1567 struct sockaddr_storage sockaddr;
1568 socklen_t len =
sizeof(sockaddr);
1569 if (!addrBind.
GetSockAddr((
struct sockaddr*)&sockaddr, &len))
1571 strError =
strprintf(
"Error: bind address family for %s not supported", addrBind.
ToString());
1576 SOCKET hListenSocket = socket(((
struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
1586 setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (
void*)&nOne,
sizeof(
int));
1592 setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (
void*)&nOne,
sizeof(
int));
1598 if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) ==
SOCKET_ERROR)
1600 if (fcntl(hListenSocket, F_SETFL, O_NONBLOCK) ==
SOCKET_ERROR)
1613 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
const char*)&nOne,
sizeof(
int));
1615 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (
void*)&nOne,
sizeof(
int));
1619 int nProtLevel = 10 ;
1620 int nParameterId = 23 ;
1622 setsockopt(hListenSocket, IPPROTO_IPV6, nParameterId, (
const char*)&nProtLevel,
sizeof(
int));
1626 if (::bind(hListenSocket, (
struct sockaddr*)&sockaddr, len) ==
SOCKET_ERROR)
1630 strError =
strprintf(
_(
"Unable to bind to %s on this computer. Bitcoin Core is probably already running."), addrBind.
ToString());
1646 vhListenSocket.push_back(hListenSocket);
1661 char pszHostName[1000] =
"";
1662 if (gethostname(pszHostName,
sizeof(pszHostName)) !=
SOCKET_ERROR)
1664 vector<CNetAddr> vaddr;
1667 BOOST_FOREACH (
const CNetAddr &addr, vaddr)
1675 struct ifaddrs* myaddrs;
1676 if (getifaddrs(&myaddrs) == 0)
1678 for (
struct ifaddrs* ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next)
1680 if (ifa->ifa_addr == NULL)
continue;
1681 if ((ifa->ifa_flags & IFF_UP) == 0)
continue;
1682 if (strcmp(ifa->ifa_name,
"lo") == 0)
continue;
1683 if (strcmp(ifa->ifa_name,
"lo0") == 0)
continue;
1684 if (ifa->ifa_addr->sa_family == AF_INET)
1686 struct sockaddr_in* s4 = (
struct sockaddr_in*)(ifa->ifa_addr);
1691 else if (ifa->ifa_addr->sa_family == AF_INET6)
1693 struct sockaddr_in6* s6 = (
struct sockaddr_in6*)(ifa->ifa_addr);
1699 freeifaddrs(myaddrs);
1710 if (semOutbound == NULL) {
1712 int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
1716 if (pnodeLocalHost == NULL)
1757 semOutbound->
post();
1773 BOOST_FOREACH(
CNode* pnode, vNodes)
1776 BOOST_FOREACH(
SOCKET hListenSocket, vhListenSocket)
1782 BOOST_FOREACH(
CNode *pnode, vNodes)
1784 BOOST_FOREACH(
CNode *pnode, vNodesDisconnected)
1787 vNodesDisconnected.clear();
1791 pnodeLocalHost = NULL;
1821 while (!vRelayExpiration.empty() && vRelayExpiration.front().first <
GetTime())
1823 mapRelay.erase(vRelayExpiration.front().second);
1824 vRelayExpiration.pop_front();
1828 mapRelay.insert(std::make_pair(inv, ss));
1829 vRelayExpiration.push_back(std::make_pair(
GetTime() + 15 * 60, inv));
1832 BOOST_FOREACH(
CNode* pnode, vNodes)
1848 LOCK(cs_totalBytesRecv);
1849 nTotalBytesRecv += bytes;
1854 LOCK(cs_totalBytesSent);
1855 nTotalBytesSent += bytes;
1860 LOCK(cs_totalBytesRecv);
1861 return nTotalBytesRecv;
1866 LOCK(cs_totalBytesSent);
1867 return nTotalBytesSent;
1872 if (!fSuccessfullyConnected)
return;
1873 if (
GetRand(nChance) != 0)
return;
1879 if (!ssSend.empty()) {
1881 ssSend[pos] ^= (
unsigned char)(
GetRand(256));
1886 if (!ssSend.empty()) {
1888 ssSend.erase(ssSend.begin()+pos);
1896 ssSend.insert(ssSend.begin()+pos, ch);
1917 unsigned short randv = 0;
1918 RAND_bytes((
unsigned char *)&randv,
sizeof(randv));
1919 std::string tmpfn =
strprintf(
"peers.dat.%04x", randv);
1929 boost::filesystem::path pathTmp =
GetDataDir() / tmpfn;
1930 FILE *file = fopen(pathTmp.string().c_str(),
"wb");
1933 return error(
"%s : Failed to open file %s", __func__, pathTmp.string());
1939 catch (std::exception &e) {
1940 return error(
"%s : Serialize or I/O error - %s", __func__, e.what());
1947 return error(
"%s : Rename-into-place failed", __func__);
1955 FILE *file = fopen(pathAddr.string().c_str(),
"rb");
1958 return error(
"%s : Failed to open file %s", __func__, pathAddr.string());
1961 int fileSize = boost::filesystem::file_size(pathAddr);
1962 int dataSize = fileSize -
sizeof(
uint256);
1966 vector<unsigned char> vchData;
1967 vchData.resize(dataSize);
1972 filein.read((
char *)&vchData[0], dataSize);
1975 catch (std::exception &e) {
1976 return error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
1984 if (hashIn != hashTmp)
1985 return error(
"%s : Checksum mismatch, data corrupted", __func__);
1987 unsigned char pchMsgTmp[4];
1993 if (memcmp(pchMsgTmp,
Params().MessageStart(),
sizeof(pchMsgTmp)))
1994 return error(
"%s : Invalid network magic number", __func__);
1999 catch (std::exception &e) {
2000 return error(
"%s : Deserialize or I/O error - %s", __func__, e.what());
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
const vector< CDNSSeedData > & DNSSeeds() const
static bool vfReachable[NET_MAX]
static void ProcessOneShot()
CClientUIInterface uiInterface
void SetReachable(enum Network net, bool fFlag)
static int64_t NodeSyncScore(const CNode *pnode)
uint64_t GetRand(uint64_t nMax)
void Attempt(const CService &addr, int64_t nTime=GetAdjustedTime())
CNodeSignals & GetNodeSignals()
static uint64_t GetTotalBytesRecv()
void MoveTo(CSemaphoreGrant &grant)
Access to the (IP) address database (peers.dat)
bool GetLocal(CService &addr, const CNetAddr *paddrPeer)
void AddOneShot(string strDest)
static CNode * pnodeLocalHost
unsigned short GetPort() const
CCriticalSection cs_filter
bool AddLocal(const CService &addr, int nScore)
const_iterator begin() const
CNode * FindNode(const CNetAddr &ip)
#define TRY_LOCK(cs, name)
STL-like map container that only keeps the N elements with the highest value.
void SetIP(const CNetAddr &ip)
void FileCommit(FILE *fileout)
void MilliSleep(int64_t n)
std::string ToStringIP() const
static void ClearBanned()
bool GetMyExternalIP(CNetAddr &ipRet)
vector_type::size_type size_type
const std::string CLIENT_NAME
static const int CLIENT_VERSION
void ThreadOpenConnections()
void SetLimited(enum Network net, bool fLimited)
Make a particular network entirely off-limits (no automatic connects to it)
RAII-style semaphore lock.
limitedmap< CInv, int64_t > mapAlreadyAskedFor(MAX_INV_SZ)
static std::vector< SOCKET > vhListenSocket
bool ConnectSocketByName(CService &addr, SOCKET &hSocketRet, const char *pszDest, int portDefault, int nTimeout)
Double ended buffer combining vector and stream-like interfaces.
void ThreadDNSAddressSeed()
unsigned short GetListenPort()
CCriticalSection cs_inventory
bool SeenLocal(const CService &addr)
vote for a local address
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
bool Add(const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty=0)
vector< std::string > vAddedNodes
#define WSAGetLastError()
static void RecordBytesRecv(uint64_t bytes)
static list< CNode * > vNodesDisconnected
void PushInventory(const CInv &inv)
bool RecvLine(SOCKET hSocket, string &strLine)
std::deque< CInv > vRecvGetData
void ThreadSocketHandler()
Stochastical (IP) address manager.
static CSemaphore * semOutbound
CCriticalSection cs_nLastNodeId
CCriticalSection cs_vOneShots
std::deque< CNetMessage > vRecvMsg
unsigned int GetTotalRecvSize()
void CloseSocketDisconnect()
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
int64_t GetAdjustedTime()
bool Write(const CAddrMan &addr)
static deque< string > vOneShots
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
static int LogPrint(const char *category, const char *format)
int GetDefaultPort() const
static uint64_t nTotalBytesRecv
void AddressCurrentlyConnected(const CService &addr)
unsigned int ReceiveFloodSize()
static const int NOBLKS_VERSION_START
void ThreadMessageHandler()
CCriticalSection cs_mapLocalHost
A combination of a network address (CNetAddr) and a (TCP) port.
bool IsReachable(const CNetAddr &addr)
check whether a given address is in a network we can probably connect to
std::vector< char, zero_after_free_allocator< char > > CSerializeData
void TraceThread(const char *name, Callable func)
static bool error(const char *format)
bool IsProxy(const CNetAddr &addr)
#define THREAD_PRIORITY_BELOW_NORMAL
static CCriticalSection cs_totalBytesRecv
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes)
CCriticalSection cs_setservAddNodeAddresses
A CService with information about it as peer.
unsigned int SendBufferSize()
bool ConnectSocket(const CService &addrDest, SOCKET &hSocketRet, int nTimeout)
void RelayTransaction(const CTransaction &tx, const uint256 &hash)
bool fSuccessfullyConnected
std::string ToString() const
static const int NOBLKS_VERSION_END
bool OpenNetworkConnection(const CAddress &addrConnect, CSemaphoreGrant *grantOutbound=NULL, const char *strDest=NULL, bool fOneShot=false)
uint256 Hash(const T1 pbegin, const T1 pend)
static uint64_t GetTotalBytesSent()
boost::signals2::signal< bool(CNode *, bool)> SendMessages
static CCriticalSection cs_totalBytesSent
map< CNetAddr, LocalServiceInfo > mapLocalHost
CNode * ConnectNode(CAddress addrConnect, const char *pszDest)
#define DUMP_ADDRESSES_INTERVAL
boost::signals2::signal< bool(CNode *)> ProcessMessages
int readData(const char *pch, unsigned int nBytes)
CCriticalSection cs_vAddedNodes
void ThreadGetMyExternalIP()
void SetThreadPriority(int nPriority)
boost::signals2::signal< void(int newNumConnections)> NotifyNumConnectionsChanged
Number of network connections changed.
std::vector< unsigned char > GetGroup() const
boost::signals2::signal< int()> GetHeight
void SocketSendData(CNode *pnode)
static void StartSync(const vector< CNode * > &vNodes)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
static void RecordBytesSent(uint64_t bytes)
static void AdvertizeLocal()
bool BindListenPort(const CService &addrBind, string &strError)
CCriticalSection cs_mapRelay
bool IsRelevantAndUpdate(const CTransaction &tx, const uint256 &hash)
CCriticalSection cs_vRecvMsg
static const unsigned int MAX_SIZE
void reserve(size_type n)
const CChainParams & Params()
Return the currently selected parameters.
CSemaphoreGrant grantOutbound
void * memcpy(void *a, const void *b, size_t c)
static const int PROTOCOL_VERSION
static bool IsBanned(CNetAddr ip)
string FormatFullVersion()
static const int MAX_OUTBOUND_CONNECTIONS
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
static CCriticalSection cs_setBanned
CAddress Select(int nUnkBias=50)
static void Discover(boost::thread_group &threadGroup)
CAddress GetLocalAddress(const CNetAddr *paddrPeer)
static bool Ban(const CNetAddr &ip)
class CNetCleanup instance_of_cnetcleanup
int readHeader(const char *pch, unsigned int nBytes)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
bool GetMyExternalIP2(const CService &addrConnect, const char *pszGet, const char *pszKeyword, CNetAddr &ipRet)
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
deque< pair< int64_t, CInv > > vRelayExpiration
std::string ToString() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
Information about a peer.
bool LookupHost(const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
static const CCheckpointData data
set< CNetAddr > setservAddNodeAddresses
bool SetSockAddr(const struct sockaddr *paddr)
CCriticalSection cs_vSend
static uint64_t nTotalBytesSent
void Connected(const CService &addr, int64_t nTime=GetAdjustedTime())
void copyStats(CNodeStats &stats)
map< string, vector< string > > mapMultiArgs
static const unsigned int MAX_INV_SZ
The maximum number of entries in an 'inv' protocol message.
void LoopForever(const char *name, Callable func, int64_t msecs)
static bool vfLimited[NET_MAX]
void ThreadOpenAddedConnections()
CCriticalSection cs_vNodes
bool Read(CAddrMan &addr)
static std::map< CNetAddr, int64_t > setBanned
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
static CNodeSignals g_signals
bool IsLimited(enum Network net)
void StartNode(boost::thread_group &threadGroup)
map< string, string > mapArgs
map< CInv, CDataStream > mapRelay
bool IsLocal(const CService &addr)
check whether a given address is potentially local
std::deque< CSerializeData > vSendMsg
const_iterator end() const
void PushAddress(const CAddress &addr)
enum Network GetNetwork() const