MCPcopy Create free account
hub / github.com/LUX-Core/lux / ProcessMessage

Function ProcessMessage

src/main.cpp:6387–7226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6385}
6386
6387static bool ProcessMessage(CNode* pfrom, const string &strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams)
6388{
6389 if (fDebug) {
6390 LogPrintf("received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
6391 }
6392
6393 if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) {
6394 LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
6395 return true;
6396 }
6397
6398 //reject any message from not upgraded peer, which has already sent us their version, if current chain is after the hardfork
6399 if (pfrom->cleanSubVer != "" && GetMajorVersionFromVersion(pfrom->cleanSubVer) < CLIENT_VERSION_MAJOR && chainActive.Height() >= chainparams.SwitchPhi2Block()) {
6400 pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE);
6401 pfrom->fDisconnect = true;
6402 return false;
6403 }
6404
6405 if (strCommand == "version") {
6406 // Each connection can only send one version message
6407 if (pfrom->nVersion != 0) {
6408 pfrom->PushMessage("reject", strCommand, REJECT_DUPLICATE, string("Duplicate version message"));
6409 Misbehaving(pfrom->GetId(), 1);
6410 return false;
6411 }
6412
6413 int64_t nTime;
6414 CAddress addrMe;
6415 CAddress addrFrom;
6416 uint64_t nNonce = 1;
6417 uint64_t nServiceInt;
6418 vRecv >> pfrom->nVersion >> nServiceInt >> nTime >> addrMe;
6419 pfrom->nServices = ServiceFlags(nServiceInt);
6420 if (pfrom->nServicesExpected & ~pfrom->nServices)
6421 {
6422 LogPrint("net", "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->id, pfrom->nServices, pfrom->nServicesExpected);
6423 pfrom->PushMessage("reject", strCommand, REJECT_NONSTANDARD,
6424 strprintf("Expected to offer services %08x", pfrom->nServicesExpected));
6425 pfrom->fDisconnect = true;
6426 return false;
6427 }
6428 if (pfrom->nVersion < ActiveProtocol()) {
6429 // disconnect from peers older than this proto version
6430 LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
6431 pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
6432 strprintf("Version must be %d or greater", ActiveProtocol()));
6433 pfrom->fDisconnect = true;
6434 return false;
6435 }
6436
6437 if (pfrom->nVersion == 10300)
6438 pfrom->nVersion = 300;
6439 if (!vRecv.empty())
6440 vRecv >> addrFrom >> nNonce;
6441 if (!vRecv.empty()) {
6442 vRecv >> LIMITED_STRING(pfrom->strSubVer, 256);
6443 pfrom->cleanSubVer = SanitizeString(pfrom->strSubVer);
6444 }

Callers 1

ProcessMessagesFunction · 0.85

Calls 15

SanitizeStringFunction · 0.85
GetRandFunction · 0.85
atoiFunction · 0.85
MisbehavingFunction · 0.85
ServiceFlagsEnum · 0.85
LogPrintFunction · 0.85
ActiveProtocolFunction · 0.85
SeenLocalFunction · 0.85
UpdatePreferredDownloadFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
GetLocalAddressFunction · 0.85

Tested by

no test coverage detected