From 8c6c9344fe4db50096ccdd6e6d23eda4016a14a3 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 8 Oct 2015 23:02:34 -0400 Subject: [PATCH] fixed a few bugs in reputation items serialisation code and GUI display --- .../src/serialiser/rsgxsreputationitems.cc | 19 +++++++------ .../src/serialiser/rsgxsreputationitems.h | 1 - libretroshare/src/services/p3gxsreputation.cc | 27 ++++++++++--------- retroshare-gui/src/gui/Identity/IdDialog.cpp | 6 ++--- retroshare-gui/src/gui/Identity/IdDialog.ui | 4 +-- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.cc b/libretroshare/src/serialiser/rsgxsreputationitems.cc index 90f10e433..876d055f7 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.cc +++ b/libretroshare/src/serialiser/rsgxsreputationitems.cc @@ -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::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::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); diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.h b/libretroshare/src/serialiser/rsgxsreputationitems.h index ca6d8f9a3..16b90847c 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.h +++ b/libretroshare/src/serialiser/rsgxsreputationitems.h @@ -90,7 +90,6 @@ public: RsGxsId mGxsId; uint32_t mOwnOpinion; uint32_t mOwnOpinionTS; - uint32_t mReputation; std::map mOpinions; // RsPeerId -> Opinion. }; diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index 29b1dcf8f..b69f4fcd0 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -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 &savelist) item->mGxsId = rit->first; item->mOwnOpinion = rit->second.mOwnOpinion; item->mOwnOpinionTS = rit->second.mOwnOpinionTs; - item->mReputation = rit->second.mReputation; std::map::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,12 +891,15 @@ 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::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::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; } } diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 1443c4f61..afdd3ceec 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -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() diff --git a/retroshare-gui/src/gui/Identity/IdDialog.ui b/retroshare-gui/src/gui/Identity/IdDialog.ui index 789dd66f6..06462cca3 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.ui +++ b/retroshare-gui/src/gui/Identity/IdDialog.ui @@ -534,7 +534,7 @@ p, li { white-space: pre-wrap; } - Positive + Negative @@ -544,7 +544,7 @@ p, li { white-space: pre-wrap; } - Negative + Positive