made sure reputations are not stamped when requested for debugging/printing

This commit is contained in:
csoler 2017-01-10 23:05:00 +01:00
parent a810ae9a74
commit a7f0fff0f1
3 changed files with 30 additions and 9 deletions

View File

@ -61,7 +61,7 @@ public:
}; };
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0; virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info) =0; virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info,bool stamp=true) =0;
virtual ReputationLevel overallReputationLevel(const RsGxsId& id)=0; virtual ReputationLevel overallReputationLevel(const RsGxsId& id)=0;
// parameters // parameters

View File

@ -750,7 +750,7 @@ RsReputations::ReputationLevel p3GxsReputation::overallReputationLevel(const RsG
return info.mOverallReputationLevel ; return info.mOverallReputationLevel ;
} }
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputations::ReputationInfo& info) bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputations::ReputationInfo& info, bool stamp)
{ {
if(gxsid.isNull()) if(gxsid.isNull())
return false ; return false ;
@ -760,7 +760,7 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
#ifdef DEBUG_REPUTATION2 #ifdef DEBUG_REPUTATION2
std::cerr << "getReputationInfo() for " << gxsid << std::endl; std::cerr << "getReputationInfo() for " << gxsid << ", stamp = " << stamp << std::endl;
#endif #endif
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(gxsid) ; std::map<RsGxsId,Reputation>::iterator it = mReputations.find(gxsid) ;
RsPgpId owner_id ; RsPgpId owner_id ;
@ -787,7 +787,9 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
rep.mOwnerNode = ownerNode ; rep.mOwnerNode = ownerNode ;
owner_id = rep.mOwnerNode ; owner_id = rep.mOwnerNode ;
rep.mLastUsedTS = now ;
if(stamp)
rep.mLastUsedTS = now ;
mChanged = true ; mChanged = true ;
} }
@ -1274,7 +1276,7 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
} }
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
RsReputations::ReputationInfo info ; RsReputations::ReputationInfo info ;
getReputationInfo(item->mGxsId,item->mOwnerNodeId,info) ; getReputationInfo(item->mGxsId,item->mOwnerNodeId,info,false) ;
std::cerr << item->mGxsId << " : own: " << info.mOwnOpinion << ", owner node: " << item->mOwnerNodeId << ", level: " << info.mOverallReputationLevel << std::endl; std::cerr << item->mGxsId << " : own: " << info.mOwnOpinion << ", owner node: " << item->mOwnerNodeId << ", level: " << info.mOverallReputationLevel << std::endl;
#endif #endif
return true; return true;
@ -1468,19 +1470,38 @@ void p3GxsReputation::debug_print()
{ {
std::cerr << "Reputations database: " << std::endl; std::cerr << "Reputations database: " << std::endl;
std::cerr << " GXS ID data: " << std::endl; std::cerr << " GXS ID data: " << std::endl;
std::cerr << std::dec ;
std::map<RsGxsId,Reputation> rep_copy;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
rep_copy = mReputations ;
}
time_t now = time(NULL) ; time_t now = time(NULL) ;
for(std::map<RsGxsId,Reputation>::const_iterator it(mReputations.begin());it!=mReputations.end();++it) for(std::map<RsGxsId,Reputation>::const_iterator it(rep_copy.begin());it!=rep_copy.end();++it)
{ {
std::cerr << " " << it->first << ": own: " << it->second.mOwnOpinion << ", Friend average: " << it->second.mFriendAverage << ", global_score: " << it->second.mReputationScore RsReputations::ReputationInfo info ;
<< ", last own update: " << now - it->second.mOwnOpinionTs << " secs ago, last needed: " << now - it->second.mLastUsedTS << " secs ago." << std::endl; getReputationInfo(it->first,RsPgpId(),info,false) ;
uint32_t lev = info.mOverallReputationLevel;
std::cerr << " " << it->first << ": own: " << it->second.mOwnOpinion
<< ", PGP id=" << it->second.mOwnerNode
<< ", flags=" << std::setfill('0') << std::setw(4) << std::hex << it->second.mIdentityFlags << std::dec
<< ", Friend pos/neg: " << it->second.mFriendsPositive << "/" << it->second.mFriendsNegative
<< ", reputation lev: [" << lev
<< "], last own update: " << std::setfill(' ') << std::setw(10) << now - it->second.mOwnOpinionTs << " secs ago"
<< ", last needed: " << std::setfill(' ') << std::setw(10) << now - it->second.mLastUsedTS << " secs ago, "
<< std::endl;
#ifdef DEBUG_REPUTATION2 #ifdef DEBUG_REPUTATION2
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it2(it->second.mOpinions.begin());it2!=it->second.mOpinions.end();++it2) for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it2(it->second.mOpinions.begin());it2!=it->second.mOpinions.end();++it2)
std::cerr << " " << it2->first << ": " << it2->second << std::endl; std::cerr << " " << it2->first << ": " << it2->second << std::endl;
#endif #endif
} }
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
std::cerr << " Banned RS nodes by ID: " << std::endl; std::cerr << " Banned RS nodes by ID: " << std::endl;
for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it) for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it)

View File

@ -109,7 +109,7 @@ public:
/***** Interface for RsReputations *****/ /***** Interface for RsReputations *****/
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ; virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info) ; virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info,bool stamp=true) ;
virtual bool isIdentityBanned(const RsGxsId& id) ; virtual bool isIdentityBanned(const RsGxsId& id) ;
virtual bool isNodeBanned(const RsPgpId& id); virtual bool isNodeBanned(const RsPgpId& id);