Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/bitcoin.cpp
Show First 20 Lines • Show All 87 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::GotChainParams() { | ||||
// 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::RequestChainParams() { | |||||
deadalnix: Function is called RequestChainPrams, doesn't request chain params. | |||||
// Create a getheaders message | |||||
BeginMessage("getheaders"); | |||||
// Locator hash | |||||
uint256 seederAssumeValid = | |||||
fTestNet ? ChainParamsConstants::TESTNET_DEFAULT_ASSUME_VALID | |||||
: ChainParamsConstants::MAINNET_DEFAULT_ASSUME_VALID; | |||||
deadalnixUnsubmitted Not Done Inline ActionsYou wouldn't have to do this is you actually used the chain params. deadalnix: You wouldn't have to do this is you actually used the chain params. | |||||
std::vector<uint8_t> hashStop(32, 0); | |||||
uint8_t numberOfLocatorHashes = 1; | |||||
vSend << PROTOCOL_VERSION << numberOfLocatorHashes << seederAssumeValid | |||||
<< uint256(hashStop); | |||||
EndMessage(); | |||||
// Update timeout | |||||
doneAfter = time(nullptr) + GetTimeout(); | |||||
deadalnixUnsubmitted Not Done Inline ActionsWhat does this do? deadalnix: What does this do? | |||||
nakihitoAuthorUnsubmitted Done Inline ActionsThis is the time out for the socket connection. nakihito: This is the time out for the socket connection. | |||||
} | |||||
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); | ||||
if (nVersion == 10300) nVersion = 300; | if (nVersion == 10300) nVersion = 300; | ||||
if (nVersion >= 106 && !recv.empty()) recv >> addrFrom >> nNonce; | if (nVersion >= 106 && !recv.empty()) recv >> addrFrom >> nNonce; | ||||
if (nVersion >= 106 && !recv.empty()) recv >> strSubVer; | if (nVersion >= 106 && !recv.empty()) recv >> strSubVer; | ||||
if (nVersion >= 209 && !recv.empty()) recv >> nStartingHeight; | if (nVersion >= 209 && !recv.empty()) recv >> nStartingHeight; | ||||
if (nVersion >= 209) { | if (nVersion >= 209) { | ||||
BeginMessage("verack"); | BeginMessage("verack"); | ||||
EndMessage(); | EndMessage(); | ||||
} | } | ||||
vSend.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | vSend.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | ||||
if (nVersion < 209) { | if (nVersion < 209) { | ||||
vRecv.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | vRecv.SetVersion(std::min(nVersion, PROTOCOL_VERSION)); | ||||
GotVersion(); | RequestChainParams(); | ||||
} | } | ||||
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(); | RequestChainParams(); | ||||
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 All 30 Lines | if (strCommand == NetMsgType::HEADERS) { | ||||
if (nHeaders == 0) { | if (nHeaders == 0) { | ||||
// fprintf(stderr, "Peer (%s) did not find seeder assume valid, | // fprintf(stderr, "Peer (%s) did not find seeder assume valid, | ||||
// banned.\n", ToString(you.c_str()); | // banned.\n", ToString(you.c_str()); | ||||
ban = 100000; | ban = 100000; | ||||
return false; | return false; | ||||
} | } | ||||
// fprintf(stderr, "Peer (%s) found seeder assume valid.\n", | // fprintf(stderr, "Peer (%s) found seeder assume valid.\n", | ||||
// ToString(you.c_str()); | // ToString(you.c_str()); | ||||
GotVersion(); | GotChainParams(); | ||||
return false; | return false; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool CSeederNode::ProcessMessages() { | bool CSeederNode::ProcessMessages() { | ||||
if (vRecv.empty()) { | if (vRecv.empty()) { | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |
Function is called RequestChainPrams, doesn't request chain params.