Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/bitcoin.cpp
// Copyright (c) 2017-2020 The Bitcoin developers | // Copyright (c) 2017-2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <seeder/bitcoin.h> | #include <seeder/bitcoin.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <seeder/db.h> | #include <seeder/db.h> | ||||
#include <seeder/messagewriter.h> | #include <seeder/messagewriter.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/time.h> | |||||
#include <algorithm> | #include <algorithm> | ||||
#define BITCOIN_SEED_NONCE 0x0539a019ca550825ULL | #define BITCOIN_SEED_NONCE 0x0539a019ca550825ULL | ||||
void CSeederNode::Send() { | void CSeederNode::Send() { | ||||
if (sock == INVALID_SOCKET) { | if (sock == INVALID_SOCKET) { | ||||
return; | return; | ||||
Show All 32 Lines | PeerMessagingState CSeederNode::ProcessMessage(std::string strCommand, | ||||
} | } | ||||
if (strCommand == NetMsgType::VERACK) { | if (strCommand == NetMsgType::VERACK) { | ||||
vRecv.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | vRecv.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | ||||
// tfm::format(std::cout, "\n%s: version %i\n", ToString(you), | // tfm::format(std::cout, "\n%s: version %i\n", ToString(you), | ||||
// nVersion); | // nVersion); | ||||
if (vAddr) { | if (vAddr) { | ||||
MessageWriter::WriteMessage(vSend, NetMsgType::GETADDR); | MessageWriter::WriteMessage(vSend, NetMsgType::GETADDR); | ||||
doneAfter = time(nullptr) + GetTimeout(); | doneAfter = GetTime() + GetTimeout(); | ||||
} else { | } else { | ||||
doneAfter = time(nullptr) + 1; | doneAfter = GetTime() + 1; | ||||
} | } | ||||
return PeerMessagingState::AwaitingMessages; | return PeerMessagingState::AwaitingMessages; | ||||
} | } | ||||
if (strCommand == NetMsgType::ADDR && vAddr) { | if (strCommand == NetMsgType::ADDR && vAddr) { | ||||
std::vector<CAddress> vAddrNew; | std::vector<CAddress> vAddrNew; | ||||
recv >> vAddrNew; | recv >> vAddrNew; | ||||
// tfm::format(std::cout, "%s: got %i addresses\n", | // tfm::format(std::cout, "%s: got %i addresses\n", | ||||
// ToString(you), | // ToString(you), | ||||
// (int)vAddrNew.size()); | // (int)vAddrNew.size()); | ||||
int64_t now = time(nullptr); | int64_t now = GetTime(); | ||||
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) { | if (doneAfter == 0 || doneAfter > now + 1) { | ||||
doneAfter = now + 1; | doneAfter = now + 1; | ||||
} | } | ||||
} | } | ||||
while (it != vAddrNew.end()) { | while (it != vAddrNew.end()) { | ||||
CAddress &addr = *it; | CAddress &addr = *it; | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | bool CSeederNode::ProcessMessages() { | ||||
} while (1); | } while (1); | ||||
return false; | return false; | ||||
} | } | ||||
CSeederNode::CSeederNode(const CService &ip, std::vector<CAddress> *vAddrIn) | CSeederNode::CSeederNode(const CService &ip, std::vector<CAddress> *vAddrIn) | ||||
: sock(INVALID_SOCKET), vSend(SER_NETWORK, 0), vRecv(SER_NETWORK, 0), | : sock(INVALID_SOCKET), vSend(SER_NETWORK, 0), vRecv(SER_NETWORK, 0), | ||||
nHeaderStart(-1), nMessageStart(-1), nVersion(0), vAddr(vAddrIn), ban(0), | nHeaderStart(-1), nMessageStart(-1), nVersion(0), vAddr(vAddrIn), ban(0), | ||||
doneAfter(0), you(ip, ServiceFlags(NODE_NETWORK)) { | doneAfter(0), you(ip, ServiceFlags(NODE_NETWORK)) { | ||||
if (time(nullptr) > 1329696000) { | if (GetTime() > 1329696000) { | ||||
vSend.SetVersion(209); | vSend.SetVersion(209); | ||||
vRecv.SetVersion(209); | vRecv.SetVersion(209); | ||||
} | } | ||||
} | } | ||||
bool CSeederNode::Run() { | bool CSeederNode::Run() { | ||||
// FIXME: This logic is duplicated with CConnman::ConnectNode for no | // FIXME: This logic is duplicated with CConnman::ConnectNode for no | ||||
// good reason. | // good reason. | ||||
Show All 25 Lines | bool CSeederNode::Run() { | ||||
if (!connected) { | if (!connected) { | ||||
// tfm::format(std::cout, "Cannot connect to %s\n", | // tfm::format(std::cout, "Cannot connect to %s\n", | ||||
// ToString(you)); | // ToString(you)); | ||||
CloseSocket(sock); | CloseSocket(sock); | ||||
return false; | return false; | ||||
} | } | ||||
// Push version; | // Write version message | ||||
uint64_t nLocalServices = 0; | uint64_t nLocalServices = 0; | ||||
uint64_t nLocalNonce = BITCOIN_SEED_NONCE; | uint64_t nLocalNonce = BITCOIN_SEED_NONCE; | ||||
CService myService; | CService myService; | ||||
CAddress me(myService, ServiceFlags(NODE_NETWORK)); | CAddress me(myService, ServiceFlags(NODE_NETWORK)); | ||||
std::string ver = "/bitcoin-cash-seeder:0.15/"; | std::string ver = "/bitcoin-cash-seeder:0.15/"; | ||||
MessageWriter::WriteMessage(vSend, NetMsgType::VERSION, PROTOCOL_VERSION, | MessageWriter::WriteMessage(vSend, NetMsgType::VERSION, PROTOCOL_VERSION, | ||||
nLocalServices, time(nullptr), you, me, | nLocalServices, GetTime(), you, me, nLocalNonce, | ||||
nLocalNonce, ver, GetRequireHeight()); | ver, GetRequireHeight()); | ||||
Send(); | Send(); | ||||
bool res = true; | bool res = true; | ||||
int64_t now; | int64_t now; | ||||
while (now = time(nullptr), ban == 0 && | while (now = GetTime(), ban == 0 && (doneAfter == 0 || doneAfter > now) && | ||||
(doneAfter == 0 || doneAfter > now) && | |||||
sock != INVALID_SOCKET) { | sock != INVALID_SOCKET) { | ||||
char pchBuf[0x10000]; | char pchBuf[0x10000]; | ||||
fd_set fdsetRecv; | fd_set fdsetRecv; | ||||
fd_set fdsetError; | fd_set fdsetError; | ||||
FD_ZERO(&fdsetRecv); | FD_ZERO(&fdsetRecv); | ||||
FD_ZERO(&fdsetError); | FD_ZERO(&fdsetError); | ||||
FD_SET(sock, &fdsetRecv); | FD_SET(sock, &fdsetRecv); | ||||
FD_SET(sock, &fdsetError); | FD_SET(sock, &fdsetError); | ||||
struct timeval wa; | struct timeval wa; | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |