Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/bitcoin.cpp
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | void CSeederNode::PushVersion() { | ||||
BeginMessage("version"); | BeginMessage("version"); | ||||
int nBestHeight = GetRequireHeight(); | int nBestHeight = GetRequireHeight(); | ||||
std::string ver = "/bitcoin-cash-seeder:0.15/"; | std::string ver = "/bitcoin-cash-seeder:0.15/"; | ||||
vSend << PROTOCOL_VERSION << nLocalServices << nTime << you << me | vSend << PROTOCOL_VERSION << nLocalServices << nTime << you << me | ||||
<< nLocalNonce << ver << nBestHeight; | << nLocalNonce << ver << nBestHeight; | ||||
EndMessage(); | EndMessage(); | ||||
} | } | ||||
void CSeederNode::GotVersion() { | void CSeederNode::CheckpointVerified() { | ||||
// fprintf(stdout, "\n%s: version %i\n", ToString(you).c_str(), | // fprintf(stdout, "\n%s: version %i\n", ToString(you).c_str(), | ||||
// nVersion); | // nVersion); | ||||
if (vAddr) { | if (vAddr) { | ||||
BeginMessage("getaddr"); | BeginMessage("getaddr"); | ||||
EndMessage(); | EndMessage(); | ||||
doneAfter = time(nullptr) + GetTimeout(); | doneAfter = time(nullptr) + GetTimeout(); | ||||
} else { | } else { | ||||
doneAfter = time(nullptr) + 1; | doneAfter = time(nullptr) + 1; | ||||
} | } | ||||
} | } | ||||
void CSeederNode::RequestBlocksAfterCheckpoint() { | |||||
// Create a getheaders message | |||||
BeginMessage("getheaders"); | |||||
// Locator hash; Seeder requests the headers after the latest checkpoint | |||||
uint256 seederCheckpoint = | |||||
Params().Checkpoints().mapCheckpoints.rbegin()->second; | |||||
std::vector<uint8_t> hashStop(32, 0); | |||||
uint8_t numberOfLocatorHashes = 1; | |||||
vSend << PROTOCOL_VERSION << numberOfLocatorHashes << seederCheckpoint | |||||
<< uint256(hashStop); | |||||
EndMessage(); | |||||
// Update socket timeout | |||||
doneAfter = time(nullptr) + GetTimeout(); | |||||
} | |||||
bool CSeederNode::ProcessMessage(std::string strCommand, CDataStream &recv) { | bool CSeederNode::ProcessMessage(std::string strCommand, CDataStream &recv) { | ||||
// fprintf(stdout, "%s: RECV %s\n", ToString(you).c_str(), | // fprintf(stdout, "%s: RECV %s\n", ToString(you).c_str(), | ||||
// strCommand.c_str()); | // strCommand.c_str()); | ||||
if (strCommand == "version") { | if (strCommand == "version") { | ||||
int64_t nTime; | int64_t nTime; | ||||
CAddress addrMe; | CAddress addrMe; | ||||
CAddress addrFrom; | CAddress addrFrom; | ||||
uint64_t nNonce = 1; | uint64_t nNonce = 1; | ||||
uint64_t nServiceInt; | uint64_t nServiceInt; | ||||
recv >> nVersion >> nServiceInt >> nTime >> addrMe; | recv >> nVersion >> nServiceInt >> nTime >> addrMe; | ||||
you.nServices = ServiceFlags(nServiceInt); | you.nServices = ServiceFlags(nServiceInt); | ||||
recv >> addrFrom >> nNonce; | recv >> addrFrom >> nNonce; | ||||
recv >> strSubVer; | recv >> strSubVer; | ||||
recv >> nStartingHeight; | recv >> nStartingHeight; | ||||
BeginMessage("verack"); | BeginMessage("verack"); | ||||
EndMessage(); | EndMessage(); | ||||
vSend.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | vSend.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | ||||
return false; | return false; | ||||
} | } | ||||
if (strCommand == "verack") { | if (strCommand == "verack") { | ||||
vRecv.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | vRecv.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | ||||
GotVersion(); | RequestBlocksAfterCheckpoint(); | ||||
return false; | return false; | ||||
} | } | ||||
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()); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::HEADERS) { | ||||
* block headers it knows that come after the checkpoint. This means | * block headers it knows that come after the checkpoint. This means | ||||
* the hashPrevBlock of the first header received should be the hash of | * the hashPrevBlock of the first header received should be the hash of | ||||
* the checkpoint if the node is following the correct chain. | * the checkpoint if the node is following the correct chain. | ||||
*/ | */ | ||||
if (Params().Checkpoints().mapCheckpoints.rbegin()->second == | if (Params().Checkpoints().mapCheckpoints.rbegin()->second == | ||||
header.hashPrevBlock) { | header.hashPrevBlock) { | ||||
// fprintf(stderr, "Peer (%s) found seeder checkpoint.\n", | // fprintf(stderr, "Peer (%s) found seeder checkpoint.\n", | ||||
// ToString(you).c_str()); | // ToString(you).c_str()); | ||||
CheckpointVerified(); | |||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Conversely, if hasPrevBlock is not the checkpoint, then the node is | * Conversely, if hasPrevBlock is not the checkpoint, then the node is | ||||
* not following the correct chain and should be banned. | * not following the correct chain and should be banned. | ||||
*/ | */ | ||||
// fprintf(stderr, | // fprintf(stderr, | ||||
▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines |