Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/bitcoin.cpp
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | bool CSeederNode::ProcessMessage(std::string strCommand, CDataStream &recv) { | ||||
if (strCommand == "addr" && vAddr) { | if (strCommand == "addr" && vAddr) { | ||||
std::vector<CAddress> vAddrNew; | std::vector<CAddress> vAddrNew; | ||||
recv >> vAddrNew; | recv >> vAddrNew; | ||||
// fprintf(stdout, "%s: got %i addresses\n", ToString(you).c_str(), | // fprintf(stdout, "%s: got %i addresses\n", ToString(you).c_str(), | ||||
// (int)vAddrNew.size()); | // (int)vAddrNew.size()); | ||||
int64_t now = time(nullptr); | int64_t now = time(nullptr); | ||||
std::vector<CAddress>::iterator it = vAddrNew.begin(); | std::vector<CAddress>::iterator it = vAddrNew.begin(); | ||||
if (vAddrNew.size() > 1) { | if (vAddrNew.size() > 1) { | ||||
if (doneAfter == 0 || doneAfter > now + 1) doneAfter = now + 1; | if (doneAfter == 0 || doneAfter > now + 1) { | ||||
doneAfter = now + 1; | |||||
} | |||||
} | } | ||||
while (it != vAddrNew.end()) { | while (it != vAddrNew.end()) { | ||||
CAddress &addr = *it; | CAddress &addr = *it; | ||||
// fprintf(stdout, "%s: got address %s\n", | // fprintf(stdout, "%s: got address %s\n", | ||||
// ToString(you).c_str(), | // ToString(you).c_str(), | ||||
// addr.ToString().c_str(), (int)(vAddr->size())); | // addr.ToString().c_str(), (int)(vAddr->size())); | ||||
it++; | it++; | ||||
if (addr.nTime <= 100000000 || addr.nTime > now + 600) { | if (addr.nTime <= 100000000 || addr.nTime > now + 600) { | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | while (now = time(nullptr), ban == 0 && | ||||
wa.tv_sec = doneAfter - now; | wa.tv_sec = doneAfter - now; | ||||
wa.tv_usec = 0; | wa.tv_usec = 0; | ||||
} else { | } else { | ||||
wa.tv_sec = GetTimeout(); | wa.tv_sec = GetTimeout(); | ||||
wa.tv_usec = 0; | wa.tv_usec = 0; | ||||
} | } | ||||
int ret = select(sock + 1, &fdsetRecv, nullptr, &fdsetError, &wa); | int ret = select(sock + 1, &fdsetRecv, nullptr, &fdsetError, &wa); | ||||
if (ret != 1) { | if (ret != 1) { | ||||
if (!doneAfter) res = false; | if (!doneAfter) { | ||||
res = false; | |||||
} | |||||
break; | break; | ||||
} | } | ||||
int nBytes = recv(sock, pchBuf, sizeof(pchBuf), 0); | int nBytes = recv(sock, pchBuf, sizeof(pchBuf), 0); | ||||
int nPos = vRecv.size(); | int nPos = vRecv.size(); | ||||
if (nBytes > 0) { | if (nBytes > 0) { | ||||
vRecv.resize(nPos + nBytes); | vRecv.resize(nPos + nBytes); | ||||
memcpy(&vRecv[nPos], pchBuf, nBytes); | memcpy(&vRecv[nPos], pchBuf, nBytes); | ||||
} else if (nBytes == 0) { | } else if (nBytes == 0) { | ||||
// fprintf(stdout, "%s: BAD (connection closed prematurely)\n", | // fprintf(stdout, "%s: BAD (connection closed prematurely)\n", | ||||
// ToString(you).c_str()); | // ToString(you).c_str()); | ||||
res = false; | res = false; | ||||
break; | break; | ||||
} else { | } else { | ||||
// fprintf(stdout, "%s: BAD (connection error)\n", | // fprintf(stdout, "%s: BAD (connection error)\n", | ||||
// ToString(you).c_str()); | // ToString(you).c_str()); | ||||
res = false; | res = false; | ||||
break; | break; | ||||
} | } | ||||
ProcessMessages(); | ProcessMessages(); | ||||
Send(); | Send(); | ||||
} | } | ||||
if (sock == INVALID_SOCKET) res = false; | if (sock == INVALID_SOCKET) { | ||||
res = false; | |||||
} | |||||
close(sock); | close(sock); | ||||
sock = INVALID_SOCKET; | sock = INVALID_SOCKET; | ||||
return (ban == 0) && res; | return (ban == 0) && res; | ||||
} | } | ||||
bool TestNode(const CService &cip, int &ban, int &clientV, | bool TestNode(const CService &cip, int &ban, int &clientV, | ||||
std::string &clientSV, int &blocks, | std::string &clientSV, int &blocks, | ||||
std::vector<CAddress> *vAddr) { | std::vector<CAddress> *vAddr) { | ||||
Show All 19 Lines |