mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-26 01:31:30 -05:00
debugging of reputation system
This commit is contained in:
parent
bb7a8f2732
commit
ce96e88925
@ -109,7 +109,7 @@ std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t inden
|
|||||||
uint16_t int_Indent = indent + 2;
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
out << "from: " << PeerId() << std::endl;
|
out << "from: " << PeerId() << std::endl;
|
||||||
//out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||||
|
|
||||||
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||||
out << " " << it->first << ": " << it->second << std::endl;
|
out << " " << it->first << ": " << it->second << std::endl;
|
||||||
@ -159,7 +159,7 @@ uint32_t RsGxsReputationUpdateItem::serial_size() const
|
|||||||
{
|
{
|
||||||
uint32_t s = 8; /* header */
|
uint32_t s = 8; /* header */
|
||||||
|
|
||||||
//s += 4 ; // mLatestUpdate
|
s += 4 ; // mLatestUpdate
|
||||||
s += 4 ; // mOpinions.size();
|
s += 4 ; // mOpinions.size();
|
||||||
|
|
||||||
s += (RsGxsId::serial_size() + 4) * mOpinions.size() ;
|
s += (RsGxsId::serial_size() + 4) * mOpinions.size() ;
|
||||||
@ -239,7 +239,7 @@ bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
|
|||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
//ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||||
|
|
||||||
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it)
|
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it)
|
||||||
@ -349,7 +349,7 @@ RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdat
|
|||||||
RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ;
|
RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ;
|
||||||
|
|
||||||
/* add mandatory parts first */
|
/* add mandatory parts first */
|
||||||
//ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
|
||||||
|
|
||||||
uint32_t S ;
|
uint32_t S ;
|
||||||
ok &= getRawUInt32(data, tlvsize, &offset, &S) ;
|
ok &= getRawUInt32(data, tlvsize, &offset, &S) ;
|
||||||
|
@ -105,7 +105,7 @@ public:
|
|||||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||||
virtual uint32_t serial_size() const ;
|
virtual uint32_t serial_size() const ;
|
||||||
|
|
||||||
//uint32_t mLatestUpdate;
|
uint32_t mLatestUpdate;
|
||||||
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -206,16 +206,22 @@ void p3GxsReputation::updateActiveFriends()
|
|||||||
mLinkMgr->getFriendList(idList) ;
|
mLinkMgr->getFriendList(idList) ;
|
||||||
|
|
||||||
mAverageActiveFriends = 0 ;
|
mAverageActiveFriends = 0 ;
|
||||||
|
#ifdef DEBUG_REPUTATION
|
||||||
|
std::cerr << " counting recently online peers." << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
for(std::list<RsPeerId>::const_iterator it(idList.begin());it!=idList.end();++it)
|
for(std::list<RsPeerId>::const_iterator it(idList.begin());it!=idList.end();++it)
|
||||||
{
|
{
|
||||||
peerConnectState state ;
|
RsPeerDetails details ;
|
||||||
|
#ifdef DEBUG_REPUTATION
|
||||||
|
std::cerr << " " << *it << ": last seen " << now - details.lastConnect << " secs ago" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(mLinkMgr->getFriendNetStatus(*it, state) && now < state.lastavailable + ACTIVE_FRIENDS_ONLINE_DELAY)
|
if(rsPeers->getPeerDetails(*it, details) && now < details.lastConnect + ACTIVE_FRIENDS_ONLINE_DELAY)
|
||||||
++mAverageActiveFriends ;
|
++mAverageActiveFriends ;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_REPUTATION
|
#ifdef DEBUG_REPUTATION
|
||||||
std::cerr << "p3GxsReputation::updateActiveFriends(): new count: " << mAverageActiveFriends << std::endl;
|
std::cerr << " new count: " << mAverageActiveFriends << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -327,14 +333,14 @@ bool p3GxsReputation::SendReputations(RsGxsReputationRequestItem *request)
|
|||||||
|
|
||||||
RsGxsId gxsId = rit->first;
|
RsGxsId gxsId = rit->first;
|
||||||
pkt->mOpinions[gxsId] = rit->second.mOwnOpinion;
|
pkt->mOpinions[gxsId] = rit->second.mOwnOpinion;
|
||||||
|
pkt->mLatestUpdate = rit->second.mOwnOpinionTs;
|
||||||
|
|
||||||
//pkt->mLatestUpdate = rit->second.mOwnOpinionTs;
|
if (pkt->mLatestUpdate == (uint32_t) now)
|
||||||
//if (pkt->mLatestUpdate == (uint32_t) now)
|
{
|
||||||
//{
|
// if we could possibly get another Update at this point (same second).
|
||||||
// // if we could possibly get another Update at this point (same second).
|
// then set Update back one second to ensure there are none missed.
|
||||||
// // then set Update back one second to ensure there are none missed.
|
pkt->mLatestUpdate--;
|
||||||
// pkt->mLatestUpdate--;
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
totalcount++;
|
totalcount++;
|
||||||
@ -452,7 +458,7 @@ void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& a
|
|||||||
#ifdef DEBUG_REPUTATION
|
#ifdef DEBUG_REPUTATION
|
||||||
std::cerr << " reputation changed. re-calculating." << std::endl;
|
std::cerr << " reputation changed. re-calculating." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
reputation.CalculateReputation(mAverageActiveFriends) ;
|
reputation.updateReputation(mAverageActiveFriends) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updated)
|
if(updated)
|
||||||
@ -474,13 +480,13 @@ bool p3GxsReputation::RecvReputations(RsGxsReputationUpdateItem *item)
|
|||||||
locked_updateOpinion(peerid,it->first,safe_convert_uint32t_to_opinion(it->second));
|
locked_updateOpinion(peerid,it->first,safe_convert_uint32t_to_opinion(it->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLatestUpdate(peerid);
|
updateLatestUpdate(peerid,item->mLatestUpdate);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid)
|
bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||||
|
|
||||||
@ -491,7 +497,7 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid)
|
|||||||
mConfig[peerid] = ReputationConfig(peerid);
|
mConfig[peerid] = ReputationConfig(peerid);
|
||||||
it = mConfig.find(peerid) ;
|
it = mConfig.find(peerid) ;
|
||||||
}
|
}
|
||||||
it->second.mLatestUpdate = time(NULL);
|
it->second.mLatestUpdate = latest_update ;
|
||||||
|
|
||||||
mReputationsUpdated = true;
|
mReputationsUpdated = true;
|
||||||
// Switched to periodic save due to scale of data.
|
// Switched to periodic save due to scale of data.
|
||||||
@ -598,7 +604,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
|
|||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
reputation.mOwnOpinion = opinion;
|
reputation.mOwnOpinion = opinion;
|
||||||
reputation.mOwnOpinionTs = now;
|
reputation.mOwnOpinionTs = now;
|
||||||
reputation.CalculateReputation(mAverageActiveFriends);
|
reputation.updateReputation(mAverageActiveFriends);
|
||||||
|
|
||||||
mUpdated.insert(std::make_pair(now, gxsid));
|
mUpdated.insert(std::make_pair(now, gxsid));
|
||||||
mUpdatedReputations.insert(gxsid);
|
mUpdatedReputations.insert(gxsid);
|
||||||
@ -741,7 +747,7 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
|
|||||||
|
|
||||||
float old_reputation = reputation.mReputation ;
|
float old_reputation = reputation.mReputation ;
|
||||||
|
|
||||||
if(old_reputation != reputation.CalculateReputation(mAverageActiveFriends))
|
if(old_reputation != reputation.updateReputation(mAverageActiveFriends))
|
||||||
mUpdatedReputations.insert(gxsId) ;
|
mUpdatedReputations.insert(gxsId) ;
|
||||||
|
|
||||||
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
||||||
@ -854,7 +860,7 @@ int p3GxsReputation::sendReputationRequest(RsPeerId peerid)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Reputation::CalculateReputation(uint32_t average_active_friends)
|
float Reputation::updateReputation(uint32_t average_active_friends)
|
||||||
{
|
{
|
||||||
// the calculation of reputation makes the whole thing
|
// the calculation of reputation makes the whole thing
|
||||||
|
|
||||||
@ -868,12 +874,14 @@ float Reputation::CalculateReputation(uint32_t average_active_friends)
|
|||||||
friend_total += it->second - 1;
|
friend_total += it->second - 1;
|
||||||
|
|
||||||
if(mOpinions.empty()) // includes the case of no friends!
|
if(mOpinions.empty()) // includes the case of no friends!
|
||||||
return 1.0f;
|
mReputation = 1.0f;
|
||||||
else
|
else
|
||||||
return 1.0f + friend_total / float(std::max(average_active_friends,(uint32_t)mOpinions.size())) ;
|
mReputation = 1.0f + friend_total / float(std::max(average_active_friends,(uint32_t)mOpinions.size())) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return float(mOwnOpinion) ;
|
mReputation = (float)mOwnOpinion ;
|
||||||
|
|
||||||
|
return float(mOwnOpinion) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3GxsReputation::debug_print()
|
void p3GxsReputation::debug_print()
|
||||||
@ -886,7 +894,7 @@ void p3GxsReputation::debug_print()
|
|||||||
for(std::map<RsGxsId,Reputation>::const_iterator it(mReputations.begin());it!=mReputations.end();++it)
|
for(std::map<RsGxsId,Reputation>::const_iterator it(mReputations.begin());it!=mReputations.end();++it)
|
||||||
{
|
{
|
||||||
std::cerr << " ID=" << it->first << ", own: " << it->second.mOwnOpinion << ", global_score: " << it->second.mReputation
|
std::cerr << " ID=" << it->first << ", own: " << it->second.mOwnOpinion << ", global_score: " << it->second.mReputation
|
||||||
<< ", last update: " << now - it->second.mOwnOpinionTs << std::endl;
|
<< ", last own update: " << now - it->second.mOwnOpinionTs << " secs ago." << std::endl;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
Reputation(const RsGxsId& about)
|
Reputation(const RsGxsId& about)
|
||||||
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0), mReputation(RsReputations::OPINION_NEUTRAL) { }
|
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0), mReputation(RsReputations::OPINION_NEUTRAL) { }
|
||||||
|
|
||||||
float CalculateReputation(uint32_t average_active_friends);
|
float updateReputation(uint32_t average_active_friends);
|
||||||
|
|
||||||
std::map<RsPeerId, RsReputations::Opinion> mOpinions;
|
std::map<RsPeerId, RsReputations::Opinion> mOpinions;
|
||||||
int32_t mOwnOpinion;
|
int32_t mOwnOpinion;
|
||||||
@ -111,7 +111,7 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /
|
|||||||
|
|
||||||
bool SendReputations(RsGxsReputationRequestItem *request);
|
bool SendReputations(RsGxsReputationRequestItem *request);
|
||||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||||
bool updateLatestUpdate(RsPeerId peerid);
|
bool updateLatestUpdate(RsPeerId peerid, time_t latest_update);
|
||||||
void updateActiveFriends() ;
|
void updateActiveFriends() ;
|
||||||
|
|
||||||
// internal update of data. Takes care of cleaning empty boxes.
|
// internal update of data. Takes care of cleaning empty boxes.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user