mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 17:09:34 -05:00
fixed some reputation sending bugs
This commit is contained in:
parent
8c6c9344fe
commit
bb7a8f2732
@ -109,7 +109,7 @@ std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t inden
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
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)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
@ -159,7 +159,7 @@ uint32_t RsGxsReputationUpdateItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += 4 ; // mLatestUpdate
|
||||
//s += 4 ; // mLatestUpdate
|
||||
s += 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;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||
//ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
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() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
|
||||
//ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S) ;
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
uint32_t mLatestUpdate;
|
||||
//uint32_t mLatestUpdate;
|
||||
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
||||
};
|
||||
|
||||
|
@ -39,16 +39,6 @@
|
||||
****/
|
||||
#define DEBUG_REPUTATION 1
|
||||
|
||||
|
||||
/* DEFINE INTERFACE POINTER! */
|
||||
//RsGxsReputation *rsGxsReputation = NULL;
|
||||
|
||||
static const int kMaximumPeerAge = 180; // half a year.
|
||||
static const int kMaximumSetSize = 100;
|
||||
|
||||
static const int ACTIVE_FRIENDS_UPDATE_PERIOD = 600 ; // 10 minutes
|
||||
static const int ACTIVE_FRIENDS_ONLINE_DELAY = 86400*7 ; // 1 week.
|
||||
|
||||
/************ IMPLEMENTATION NOTES *********************************
|
||||
*
|
||||
* p3GxsReputation shares opinions / reputations with peers.
|
||||
@ -135,20 +125,26 @@ static const int ACTIVE_FRIENDS_ONLINE_DELAY = 86400*7 ; // 1 week.
|
||||
* [X] Implement a system to allow not storing info when we don't have it
|
||||
*/
|
||||
|
||||
const uint32_t LOWER_LIMIT = 0;
|
||||
const uint32_t UPPER_LIMIT = 2;
|
||||
const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ;
|
||||
static const uint32_t LOWER_LIMIT = 0; // used to filter valid Opinion values from serialized data
|
||||
static const uint32_t UPPER_LIMIT = 2; // used to filter valid Opinion values from serialized data
|
||||
static const float REPUTATION_ASSESSMENT_THRESHOLD_X1 = 0.5f ; // reputation under which the peer gets killed
|
||||
static const int kMaximumPeerAge = 180; // half a year.
|
||||
static const int kMaximumSetSize = 100; // max set of updates to send at once.
|
||||
static const int ACTIVE_FRIENDS_UPDATE_PERIOD = 60;//600 ;// 10 minutes
|
||||
static const int ACTIVE_FRIENDS_ONLINE_DELAY = 86400*7 ; // 1 week.
|
||||
|
||||
|
||||
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
|
||||
:p3Service(), p3Config(),
|
||||
mReputationMtx("p3GxsReputation"), mLinkMgr(lm)
|
||||
{
|
||||
addSerialType(new RsGxsReputationSerialiser());
|
||||
addSerialType(new RsGxsReputationSerialiser());
|
||||
|
||||
mRequestTime = 0;
|
||||
mStoreTime = 0;
|
||||
mReputationsUpdated = false;
|
||||
mRequestTime = 0;
|
||||
mStoreTime = 0;
|
||||
mReputationsUpdated = false;
|
||||
mLastActiveFriendsUpdate = 0 ;
|
||||
mAverageActiveFriends = 0 ;
|
||||
}
|
||||
|
||||
const std::string GXS_REPUTATION_APP_NAME = "gxsreputation";
|
||||
@ -167,8 +163,6 @@ RsServiceInfo p3GxsReputation::getServiceInfo()
|
||||
GXS_REPUTATION_MIN_MINOR_VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int p3GxsReputation::tick()
|
||||
{
|
||||
processIncoming();
|
||||
@ -308,12 +302,13 @@ bool p3GxsReputation::SendReputations(RsGxsReputationRequestItem *request)
|
||||
int count = 0;
|
||||
int totalcount = 0;
|
||||
RsGxsReputationUpdateItem *pkt = new RsGxsReputationUpdateItem();
|
||||
|
||||
pkt->PeerId(peerId);
|
||||
for(;tit != mUpdated.end(); ++tit)
|
||||
{
|
||||
/* find */
|
||||
std::map<RsGxsId, Reputation>::iterator rit;
|
||||
rit = mReputations.find(tit->second);
|
||||
std::map<RsGxsId, Reputation>::iterator rit = mReputations.find(tit->second);
|
||||
|
||||
if (rit == mReputations.end())
|
||||
{
|
||||
std::cerr << "p3GxsReputation::SendReputations() ERROR Missing Reputation";
|
||||
@ -332,13 +327,14 @@ bool p3GxsReputation::SendReputations(RsGxsReputationRequestItem *request)
|
||||
|
||||
RsGxsId gxsId = rit->first;
|
||||
pkt->mOpinions[gxsId] = rit->second.mOwnOpinion;
|
||||
pkt->mLatestUpdate = rit->second.mOwnOpinionTs;
|
||||
if (pkt->mLatestUpdate == (uint32_t) now)
|
||||
{
|
||||
// if we could possibly get another Update at this point (same second).
|
||||
// then set Update back one second to ensure there are none missed.
|
||||
pkt->mLatestUpdate--;
|
||||
}
|
||||
|
||||
//pkt->mLatestUpdate = rit->second.mOwnOpinionTs;
|
||||
//if (pkt->mLatestUpdate == (uint32_t) now)
|
||||
//{
|
||||
// // if we could possibly get another Update at this point (same second).
|
||||
// // then set Update back one second to ensure there are none missed.
|
||||
// pkt->mLatestUpdate--;
|
||||
//}
|
||||
|
||||
count++;
|
||||
totalcount++;
|
||||
@ -349,6 +345,7 @@ bool p3GxsReputation::SendReputations(RsGxsReputationRequestItem *request)
|
||||
std::cerr << std::endl;
|
||||
|
||||
sendItem(pkt);
|
||||
|
||||
pkt = new RsGxsReputationUpdateItem();
|
||||
pkt->PeerId(peerId);
|
||||
count = 0;
|
||||
@ -477,16 +474,13 @@ bool p3GxsReputation::RecvReputations(RsGxsReputationUpdateItem *item)
|
||||
locked_updateOpinion(peerid,it->first,safe_convert_uint32t_to_opinion(it->second));
|
||||
}
|
||||
|
||||
|
||||
updateLatestUpdate(peerid, item->mLatestUpdate);
|
||||
|
||||
// now update all reputations of IDs for which some opinions have changed.
|
||||
updateLatestUpdate(peerid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid, time_t ts)
|
||||
bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
@ -497,11 +491,12 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid, time_t ts)
|
||||
mConfig[peerid] = ReputationConfig(peerid);
|
||||
it = mConfig.find(peerid) ;
|
||||
}
|
||||
it->second.mLatestUpdate = ts;
|
||||
it->second.mLatestUpdate = time(NULL);
|
||||
|
||||
mReputationsUpdated = true;
|
||||
// Switched to periodic save due to scale of data.
|
||||
//IndicateConfigChanged();
|
||||
|
||||
IndicateConfigChanged();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -758,7 +753,7 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
|
||||
* Send Requests.
|
||||
****/
|
||||
|
||||
const int kReputationRequestPeriod = 3600;
|
||||
const int kReputationRequestPeriod = 60; // 3600; // 1 hour
|
||||
const int kReputationStoreWait = 180; // 3 minutes.
|
||||
|
||||
int p3GxsReputation::sendPackets()
|
||||
@ -771,7 +766,7 @@ int p3GxsReputation::sendPackets()
|
||||
storeTime = mStoreTime;
|
||||
}
|
||||
|
||||
if (now - requestTime > kReputationRequestPeriod)
|
||||
if (now > requestTime + kReputationRequestPeriod)
|
||||
{
|
||||
sendReputationRequests();
|
||||
|
||||
@ -815,46 +810,41 @@ void p3GxsReputation::sendReputationRequests()
|
||||
|
||||
mLinkMgr->getOnlineList(idList);
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputation::sendReputationRequests()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* prepare packets */
|
||||
std::list<RsPeerId>::iterator it;
|
||||
for(it = idList.begin(); it != idList.end(); ++it)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputation::sendReputationRequest() To: " << *it;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
sendReputationRequest(*it);
|
||||
}
|
||||
}
|
||||
|
||||
int p3GxsReputation::sendReputationRequest(RsPeerId peerid)
|
||||
{
|
||||
std::cerr << "p3GxsReputation::sendReputationRequest(" << peerid << ")";
|
||||
std::cerr << std::endl;
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " p3GxsReputation::sendReputationRequest(" << peerid << ") " ;
|
||||
#endif
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
/* */
|
||||
RsGxsReputationRequestItem *requestItem =
|
||||
new RsGxsReputationRequestItem();
|
||||
|
||||
RsGxsReputationRequestItem *requestItem = new RsGxsReputationRequestItem();
|
||||
requestItem->PeerId(peerid);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
/* find the last timestamp we have */
|
||||
std::map<RsPeerId, ReputationConfig>::iterator it;
|
||||
it = mConfig.find(peerid);
|
||||
std::map<RsPeerId, ReputationConfig>::iterator it = mConfig.find(peerid);
|
||||
|
||||
if (it != mConfig.end())
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " lastUpdate = " << now - it->second.mLatestUpdate << " secs ago. Requesting only more recent." << std::endl;
|
||||
#endif
|
||||
requestItem->mLastUpdate = it->second.mLatestUpdate;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " lastUpdate = never. Requesting all!" << std::endl;
|
||||
#endif
|
||||
// get whole list.
|
||||
requestItem->mLastUpdate = 0;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations /
|
||||
|
||||
bool SendReputations(RsGxsReputationRequestItem *request);
|
||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||
bool updateLatestUpdate(RsPeerId peerid, time_t ts);
|
||||
bool updateLatestUpdate(RsPeerId peerid);
|
||||
void updateActiveFriends() ;
|
||||
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
|
Loading…
Reference in New Issue
Block a user