Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/bitcoin.cpp
// Copyright (c) 2017-2019 The Bitcoin developers | // Copyright (c) 2017-2019 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 <chain.h> | |||||
#include <chainparams.h> | |||||
#include <hash.h> | #include <hash.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <seeder/db.h> | #include <seeder/db.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | if (strCommand == "addr" && vAddr) { | ||||
if (vAddr->size() > 1000) { | if (vAddr->size() > 1000) { | ||||
doneAfter = 1; | doneAfter = 1; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
if (strCommand == NetMsgType::HEADERS) { | |||||
unsigned int nHeaders = ReadCompactSize(recv); | |||||
if (nHeaders == 0) { | |||||
// fprintf(stderr, | |||||
//"Peer (%s) did not find seeder checkpoint, bannded.\n", | |||||
// ToString(you).c_str()); | |||||
ban = 100000; | |||||
return true; | |||||
} | |||||
CBlockHeader header; | |||||
recv >> header; | |||||
/** | |||||
* If the node has this checkpoint then it will return the first 2000 | |||||
* block headers it knows that come after the checkpoint. This means | |||||
* the hashPrevBlock of the first header received should be the hash of | |||||
* the checkpoint if the node is following the correct chain. | |||||
*/ | |||||
if (networkParams->Checkpoints().mapCheckpoints.rbegin()->second == | |||||
header.hashPrevBlock) { | |||||
// fprintf(stderr, "Peer (%s) found seeder checkpoint.\n", | |||||
// ToString(you).c_str()); | |||||
return false; | |||||
} | |||||
/** | |||||
* Conversely, if hasPrevBlock is not the checkpoint, then the node is | |||||
* not following the correct chain and should be banned. | |||||
*/ | |||||
// fprintf(stderr, | |||||
//"Peer (%s) returned a header the does not come after the " | |||||
//"checkpoint and is therefore on the wrong chain, banned.\n", | |||||
// ToString(you).c_str()); | |||||
// This should probably be a longer lasting band in the future | |||||
ban = 100000; | |||||
return true; | |||||
} | |||||
return false; | return false; | ||||
} | } | ||||
bool CSeederNode::ProcessMessages() { | bool CSeederNode::ProcessMessages() { | ||||
if (vRecv.empty()) { | if (vRecv.empty()) { | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | do { | ||||
// strCommand.c_str()); | // strCommand.c_str()); | ||||
} 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 | NODE_BITCOIN_CASH)) { | doneAfter(0), you(ip, ServiceFlags(NODE_NETWORK | NODE_BITCOIN_CASH)), | ||||
networkParams(nullptr) { | |||||
if (time(nullptr) > 1329696000) { | if (time(nullptr) > 1329696000) { | ||||
vSend.SetVersion(209); | vSend.SetVersion(209); | ||||
vRecv.SetVersion(209); | vRecv.SetVersion(209); | ||||
} | } | ||||
std::string network = | |||||
fTestNet ? CBaseChainParams::TESTNET : CBaseChainParams::MAIN; | |||||
networkParams = CreateChainParams(network); | |||||
} | } | ||||
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. | ||||
bool connected = false; | bool connected = false; | ||||
proxyType proxy; | proxyType proxy; | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |