From 291951b0317b5fc0de10a9d1305edf5c88c1d3a8 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 16 Jun 2012 15:08:36 -0700 Subject: [PATCH] Use SeedNodes when compute TrustedNodes scores. --- src/UniqueNodeList.cpp | 78 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/src/UniqueNodeList.cpp b/src/UniqueNodeList.cpp index c445593df4..fbee423211 100644 --- a/src/UniqueNodeList.cpp +++ b/src/UniqueNodeList.cpp @@ -197,22 +197,84 @@ void UniqueNodeList::scoreCompute() std::string strDomain = db->getStrBinary("Domain"); std::string strPublicKey = db->getStrBinary("PublicKey"); std::string strSource = db->getStrBinary("Source"); + int iScore = iSourceScore(static_cast(strSource[0])); + strIndex::iterator siOld = umPulicIdx.find(strPublicKey); + if (siOld == umPulicIdx.end()) + { + // New node + int iNode = vsnNodes.size(); + + umPulicIdx[strPublicKey] = iNode; + umDomainIdx[strDomain] = iNode; + + scoreNode snCurrent; + + snCurrent.strValidator = strPublicKey; + snCurrent.iScore = iScore; + snCurrent.iRoundSeed = snCurrent.iScore; + snCurrent.iRoundScore = 0; + snCurrent.iSeen = -1; + + vsnNodes.push_back(snCurrent); + } + else + { + scoreNode& snOld = vsnNodes[siOld->second]; + + if (snOld.iScore < iScore) + { + // Update old node + + snOld.iScore = iScore; + snOld.iRoundSeed = snOld.iScore; + } + } + } + } + } + + // For each entry in SeedNodes: + // - Add an entry in umPulicIdx, umDomainIdx, and vsnNodes. + { + ScopedLock sl(theApp->getWalletDB()->getDBLock()); + + SQL_FOREACH(db, "SELECT PublicKey,Source FROM SeedNodes;") + { + std::string strPublicKey = db->getStrBinary("PublicKey"); + std::string strSource = db->getStrBinary("Source"); + int iScore = iSourceScore(static_cast(strSource[0])); + strIndex::iterator siOld = umPulicIdx.find(strPublicKey); + + if (siOld == umPulicIdx.end()) + { + // New node int iNode = vsnNodes.size(); umPulicIdx[strPublicKey] = iNode; - umDomainIdx[strDomain] = iNode; scoreNode snCurrent; snCurrent.strValidator = strPublicKey; - snCurrent.iScore = iSourceScore(static_cast(strSource[0])); + snCurrent.iScore = iScore; snCurrent.iRoundSeed = snCurrent.iScore; snCurrent.iRoundScore = 0; snCurrent.iSeen = -1; vsnNodes.push_back(snCurrent); } + else + { + scoreNode& snOld = vsnNodes[siOld->second]; + + if (snOld.iScore < iScore) + { + // Update old node + + snOld.iScore = iScore; + snOld.iRoundSeed = snOld.iScore; + } + } } } @@ -227,8 +289,6 @@ void UniqueNodeList::scoreCompute() << std::endl; } - // XXX When we have a CAS do SeedNodes here. - // std::cerr << str(boost::format("vsnNodes.size=%d") % vsnNodes.size()) << std::endl; // Step through growing list of nodes adding each validation list. @@ -1203,22 +1263,22 @@ void UniqueNodeList::nodeAddDomain(std::string strDomain, validatorSource vsWhy, if (!bFound) { - sdCurrent.strDomain = strDomain; - sdCurrent.tpNext = boost::posix_time::second_clock::universal_time(); + sdCurrent.strDomain = strDomain; + sdCurrent.tpNext = boost::posix_time::second_clock::universal_time(); } // Promote source, if needed. if (!bFound || iSourceScore(vsWhy) >= iSourceScore(sdCurrent.vsSource)) { - sdCurrent.vsSource = vsWhy; - bChanged = true; + sdCurrent.vsSource = vsWhy; + sdCurrent.strComment = strComment; + bChanged = true; } if (vsManual == vsWhy) { // A manual add forces immediate scan. sdCurrent.tpNext = boost::posix_time::second_clock::universal_time(); - sdCurrent.strComment = strComment; bChanged = true; }