fixed a few bugs in reputation items serialisation code and GUI display

This commit is contained in:
csoler 2015-10-08 23:02:34 -04:00
parent 3d21d99601
commit 8c6c9344fe
5 changed files with 31 additions and 26 deletions

View File

@ -95,7 +95,6 @@ std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
out << "GxsId: " << mGxsId << std::endl;
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
out << "mReputation: " << mReputation << std::endl;
out << "Opinions from neighbors: " << std::endl;
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
@ -148,7 +147,6 @@ uint32_t RsGxsReputationSetItem::serial_size() const
s += mGxsId.serial_size() ;
s += 4 ; // mOwnOpinion
s += 4 ; // mOwnOpinionTS
s += 4 ; // mReputation
s += 4 ; // mOpinions.size()
@ -197,7 +195,7 @@ bool RsGxsReputationConfigItem::serialise(void *data, uint32_t& pktsize) const
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
std::cerr << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl;
}
return ok;
@ -215,12 +213,18 @@ bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
ok &= mGxsId.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion);
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
ok &= setRawUInt32(data, tlvsize, &offset, mReputation);
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
{
ok &= it->first.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
}
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
}
return ok;
@ -247,7 +251,7 @@ bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl;
}
return ok;
@ -268,7 +272,7 @@ bool RsGxsReputationRequestItem::serialise(void *data, uint32_t& pktsize) const
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl;
}
return ok;
@ -310,7 +314,6 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mReputation);
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S);

View File

@ -90,7 +90,6 @@ public:
RsGxsId mGxsId;
uint32_t mOwnOpinion;
uint32_t mOwnOpinionTS;
uint32_t mReputation;
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
};

View File

@ -526,8 +526,7 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep
info.mOverallReputationScore = float(RsReputations::OPINION_NEUTRAL) ;
info.mAssessment = RsReputations::ASSESSMENT_OK ;
#ifdef DEBUG_REPUTATION
std::cerr << " no information present. Returning default" << std::endl;
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
std::cerr << " no information present. Returning default. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
#endif
}
else
@ -571,6 +570,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
/* find matching Reputation */
rit = mReputations.find(gxsid);
if (rit == mReputations.end())
{
mReputations[gxsid] = Reputation(gxsid);
@ -607,10 +607,11 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
mUpdated.insert(std::make_pair(now, gxsid));
mUpdatedReputations.insert(gxsid);
mReputationsUpdated = true;
// Switched to periodic save due to scale of data.
//IndicateConfigChanged();
IndicateConfigChanged();
return true;
}
@ -659,7 +660,6 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
item->mGxsId = rit->first;
item->mOwnOpinion = rit->second.mOwnOpinion;
item->mOwnOpinionTS = rit->second.mOwnOpinionTs;
item->mReputation = rit->second.mReputation;
std::map<RsPeerId, RsReputations::Opinion>::iterator oit;
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
@ -743,11 +743,11 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
// if dropping entries has changed the score -> must update.
int previous = item->mReputation;
if (previous != reputation.CalculateReputation(mAverageActiveFriends))
{
mUpdatedReputations.insert(gxsId);
}
float old_reputation = reputation.mReputation ;
if(old_reputation != reputation.CalculateReputation(mAverageActiveFriends))
mUpdatedReputations.insert(gxsId) ;
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
return true;
@ -891,9 +891,12 @@ void p3GxsReputation::debug_print()
std::cerr << "Reputations database: " << std::endl;
std::cerr << " Average number of peers: " << mAverageActiveFriends << std::endl;
time_t now = time(NULL) ;
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::endl;
std::cerr << " ID=" << it->first << ", own: " << it->second.mOwnOpinion << ", global_score: " << it->second.mReputation
<< ", last update: " << now - it->second.mOwnOpinionTs << std::endl;
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;

View File

@ -682,16 +682,16 @@ void IdDialog::insertIdDetails(uint32_t token)
ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore));
switch(data.mReputation.mOwnOpinion)
switch(info.mOwnOpinion)
{
case RsReputations::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ;
case RsReputations::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ;
case RsReputations::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ;
default:
std::cerr << "Unexpected value in own opinion: " << data.mReputation.mOwnOpinion << std::endl;
std::cerr << "Unexpected value in own opinion: " << info.mOwnOpinion << std::endl;
}
ui->neighborNodesOpinion_TF->setText(QString::number(data.mReputation.mPeerOpinion));
//ui->neighborNodesOpinion_TF->setText(QString::number(info.m));
}
void IdDialog::modifyReputation()

View File

@ -534,7 +534,7 @@ p, li { white-space: pre-wrap; }
</property>
<item>
<property name="text">
<string>Positive</string>
<string>Negative</string>
</property>
</item>
<item>
@ -544,7 +544,7 @@ p, li { white-space: pre-wrap; }
</item>
<item>
<property name="text">
<string>Negative</string>
<string>Positive</string>
</property>
</item>
</widget>