From d2f72145c4a40bdafce042607ec04d22c15dcc67 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Fri, 3 Jul 2020 21:39:14 -0400 Subject: [PATCH] Change logic for verified beacons This commit allows beacons that are already active to be pending and verified again, to be able to properly handle certain expiration and forced readvertisement cases. --- src/scraper/scraper.cpp | 80 +++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/src/scraper/scraper.cpp b/src/scraper/scraper.cpp index 77e4cf6577..26956f6854 100755 --- a/src/scraper/scraper.cpp +++ b/src/scraper/scraper.cpp @@ -2230,57 +2230,69 @@ bool ProcessProjectRacFileByCPID(const std::string& project, const fs::path& fil const std::string& cpid = ExtractXML(data, "", ""); - // If the CPID is active, then this is skipped and the CPID is included. - // If it is not active, then check if already verified. If so, then drop through - // and include. If not active and not already verified, then attempt - // to verify by matching the username to the "verification code" from the - // pending beacons. If this is matched then add to the incoming verified + // Attempt to verify pending beacons by matching the username to the + // "verification code" from the pending beacon with the same CPID. + // If this is matched then add to the incoming verified // map, but do not add CPID to the statistic (this go 'round). - if (Consensus.mBeaconMap.count(cpid) < 1) + + bool active = Consensus.mBeaconMap.count(cpid); + + bool already_verified = false; + for (const auto& entry : GlobalVerifiedBeaconsCopy.mVerifiedMap) { - // If not active, then check whether on passed in copy of the - // global verified beacons. - unsigned int already_verified = 0; - for (const auto& entry : GlobalVerifiedBeaconsCopy.mVerifiedMap) - { - if (entry.second.cpid == cpid) ++already_verified; - } + if (entry.second.cpid == cpid) already_verified = true; - if (!already_verified) - { - // Attempt to verify. + break; + } - const std::string username = ExtractXML(data, "", ""); + bool just_verified = false; + if (!already_verified) + { + // Attempt to verify. - // Base58-encoded beacon verification code sizes fall within: - if (username.size() < 26 || username.size() > 28) continue; + const std::string username = ExtractXML(data, "", ""); + // Base58-encoded beacon verification code sizes fall within: + if (username.size() >= 26 && username.size() <= 28) + { // The username has to be temporarily changed to a "verification code" that is // a base58 encoded version of the public key of the pending beacon, so that // it will match the mPendingMap entry. This is the crux of the user validation. const auto iter_pair = Consensus.mPendingMap.find(username); - if (iter_pair == Consensus.mPendingMap.end()) continue; - if (iter_pair->second.cpid != cpid) continue; - - // This copies the pending beacon entry into the local VerifiedBeacons map and updates - // the time entry. - IncomingVerifiedBeacons.mVerifiedMap[iter_pair->first] = iter_pair->second; + if (iter_pair != Consensus.mPendingMap.end() && iter_pair->second.cpid == cpid) + { + // This copies the pending beacon entry into the local VerifiedBeacons map and updates + // the time entry. + IncomingVerifiedBeacons.mVerifiedMap[iter_pair->first] = iter_pair->second; - _log(logattribute::INFO, "ProcessProjectRacFileByCPID", "Verified pending beacon for verification code " - + iter_pair->first + ", cpid " + iter_pair->second.cpid); + _log(logattribute::INFO, "ProcessProjectRacFileByCPID", "Verified pending beacon for verification code " + + iter_pair->first + ", cpid " + iter_pair->second.cpid); - IncomingVerifiedBeacons.timestamp = GetAdjustedTime(); + IncomingVerifiedBeacons.timestamp = GetAdjustedTime(); - // We do NOT want to add a just verified CPID to the statistics this iteration, - // because we may be halfway through processing the set of projects. Instead, add to the - // incoming verification map (above), which will be handled in the calling function once - // all of the projects are gone through. This will become a verified beacon the next time - // around. - continue; + just_verified = true; + } } } + // We do NOT want to add a just verified CPID to the statistics this iteration, if it was + // not already active, because we may be halfway through processing the set of projects. + // Instead, add to the incoming verification map (above), which will be handled in the + // calling function once all of the projects are gone through. This will become a verified + // beacon the next time around. This is potentially confusing... a truth table is in order... + + // active already verified just verified no stats (continue) + // false false false true (this is the initial beacon advertise case) + // false false true true + // false true false false + // false true true xxxxx invalid (just verified checks for already) + // true false false false + // true true false false + // true false true false + // true true true xxxxx invalid (just verified checks for already) + if (!active && !already_verified) continue; + // Only do this if team membership filtering is specified by network policy. if (REQUIRE_TEAM_WHITELIST_MEMBERSHIP) {