From 1a76bea6ffc7ed8302b52e34a0792b7d21f05cb0 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 11 Oct 2015 21:41:35 -0400 Subject: [PATCH] enabled bannign button in forums, and disable message passing for banned users --- libretroshare/src/gxs/rsgxsnetservice.cc | 20 +++++++++++++++---- libretroshare/src/retroshare/rsidentity.h | 13 +++++++----- libretroshare/src/retroshare/rsreputations.h | 4 ++-- libretroshare/src/services/p3gxsreputation.cc | 6 +++--- libretroshare/src/services/p3gxsreputation.h | 2 +- libretroshare/src/services/p3idservice.cc | 13 ++++++++---- retroshare-gui/src/gui/gxs/GxsIdDetails.cpp | 6 +++--- .../src/gui/gxs/GxsIdTreeWidgetItem.cpp | 2 +- .../gui/gxsforums/GxsForumThreadWidget.cpp | 4 ++-- 9 files changed, 45 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index c6503d3d4..14d09f3dc 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -1997,7 +1997,13 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr) std::cerr << ", no group meta found. Givign up." << std::endl; continue; } - + + if(rsReputations->isIdentityBanned(syncItem->authorId)) + { + std::cerr << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl; + continue ; + } + if(mReputations->haveReputation(syncItem->authorId) || noAuthor) { GixsReputation rep; @@ -2010,7 +2016,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr) // if author is required for this message, it will simply get dropped // at genexchange side of things - if(rsReputations->isIdentityOk(syncItem->authorId) && rep.score > (int)grpMeta->mReputationCutOff || noAuthor) + if(rep.score > (int)grpMeta->mReputationCutOff || noAuthor) { #ifdef NXS_NET_DEBUG std::cerr << ", passed! Adding message to req list." << std::endl; @@ -2211,7 +2217,13 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr) haveItem = true; latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs; } - + + if(rsReputations->isIdentityBanned(grpSyncItem->authorId)) + { + std::cerr << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl; + continue ; + } + if( (mGrpAutoSync && !haveItem) || latestVersion) { // determine if you need to check reputation @@ -2226,7 +2238,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr) GixsReputation rep; mReputations->getReputation(grpSyncItem->authorId, rep); - if(rep.score >= GIXS_CUT_OFF && rsReputations->isIdentityOk(grpSyncItem->authorId)) + if(rep.score >= GIXS_CUT_OFF) { addGroupItemToList(tr, grpId, transN, reqList); std::cerr << " reputation cut off: limit=" << GIXS_CUT_OFF << " value=" << rep.score << ": allowed." << std::endl; diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index b7e9856c1..d3ee14041 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -32,6 +32,7 @@ #include "retroshare/rstokenservice.h" #include "retroshare/rsgxsifacehelper.h" +#include "retroshare/rsreputations.h" #include "retroshare/rsids.h" #include "serialiser/rstlvimage.h" #include "retroshare/rsgxscommon.h" @@ -158,8 +159,7 @@ class RsIdentityDetails { public: RsIdentityDetails() - :mIsOwnId(false), mPgpLinked(false), mPgpKnown(false), - mReputation(), mLastUsageTS(0) { return; } + :mIsOwnId(false), mPgpLinked(false), mPgpKnown(false), mLastUsageTS(0) { return; } RsGxsId mId; @@ -175,9 +175,12 @@ public: // Recogn details. std::list mRecognTags; - // reputation details. - GxsReputation mReputation; - bool mBanned ; + // Cyril: Reputation details. At some point we might want to merge information + // between the two into a single global score. Since the old reputation system + // is not finished yet, I leave this in place. We should decide what to do with it. + + GxsReputation mReputation_oldSystem; // this is the old "mReputation" field, which apparently is not used. + RsReputations::ReputationInfo mReputation; // avatar RsGxsImage mAvatar ; diff --git a/libretroshare/src/retroshare/rsreputations.h b/libretroshare/src/retroshare/rsreputations.h index ee09458a8..433eb8368 100644 --- a/libretroshare/src/retroshare/rsreputations.h +++ b/libretroshare/src/retroshare/rsreputations.h @@ -48,9 +48,9 @@ public: virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) =0 ; // This one is a proxy designed to allow fast checking of a GXS id. - // it basically returns true if assessment is ASSESSMENT_OK + // it basically returns true if assessment is not ASSESSMENT_OK - virtual bool isIdentityOk(const RsGxsId& id) =0; + virtual bool isIdentityBanned(const RsGxsId& id) =0; }; // To access reputations from anywhere diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index fa53c5a8a..25c7d0cfa 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -550,16 +550,16 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, RsReputations::Rep return true ; } -bool p3GxsReputation::isIdentityOk(const RsGxsId &id) +bool p3GxsReputation::isIdentityBanned(const RsGxsId &id) { RsReputations::ReputationInfo info ; getReputationInfo(id,info) ; #ifdef DEBUG_REPUTATION - std::cerr << "isIdentityOk(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_OK) << " for GXS id " << id << std::endl; + std::cerr << "isIdentityBanned(): returning " << (info.mAssessment == RsReputations::ASSESSMENT_BAD) << " for GXS id " << id << std::endl; #endif - return info.mAssessment == RsReputations::ASSESSMENT_OK ; + return info.mAssessment == RsReputations::ASSESSMENT_BAD ; } bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::Opinion& opinion) diff --git a/libretroshare/src/services/p3gxsreputation.h b/libretroshare/src/services/p3gxsreputation.h index 82f954b4d..c5949dea1 100644 --- a/libretroshare/src/services/p3gxsreputation.h +++ b/libretroshare/src/services/p3gxsreputation.h @@ -90,7 +90,7 @@ class p3GxsReputation: public p3Service, public p3Config, public RsReputations / /***** Interface for RsReputations *****/ virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ; virtual bool getReputationInfo(const RsGxsId& id,ReputationInfo& info) ; - virtual bool isIdentityOk(const RsGxsId& id) ; + virtual bool isIdentityBanned(const RsGxsId& id) ; /***** overloaded from p3Service *****/ virtual int tick(); diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 8eaa08928..f8683729b 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -412,6 +412,8 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details) // one utf8 symbol can be at most 4 bytes long - would be better to measure real unicode length !!! if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4) details.mNickname = "[too long a name]" ; + + rsReputations->getReputationInfo(id,details.mReputation) ; return true; } @@ -421,6 +423,9 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details) { details = data.details; details.mLastUsageTS = locked_getLastUsageTS(id) ; + + rsReputations->getReputationInfo(id,details.mReputation) ; + return true; } } @@ -831,7 +836,7 @@ bool p3IdService::getReputation(const RsGxsId &id, GixsReputation &rep) if (mPublicKeyCache.fetch(id, data)) { rep.id = id; - rep.score = data.details.mReputation.mOverallScore; + rep.score = 0;//data.details.mReputation.mOverallScore; #ifdef DEBUG_IDS std::cerr << "p3IdService::getReputation() id: "; std::cerr << id.toStdString() << " score: " << @@ -1669,14 +1674,14 @@ void RsGxsIdCache::updateServiceString(std::string serviceString) } // copy over Reputation scores. - details.mReputation = ssdata.score.rep; + //details.mReputation = ssdata.score.rep; } else { details.mPgpKnown = false; details.mPgpId.clear(); - details.mReputation.updateIdScore(false, false); - details.mReputation.update(); + //details.mReputation.updateIdScore(false, false); + //details.mReputation.update(); } } diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index dc8667a84..400498823 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -878,7 +878,7 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, QLi QString GxsIdDetails::getName(const RsIdentityDetails &details) { - if(!rsReputations->isIdentityOk(details.mId)) + if(rsReputations->isIdentityBanned(details.mId)) return tr("[Banned]") ; QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE); @@ -897,7 +897,7 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details) QString comment; QString nickname ; - bool banned = !rsReputations->isIdentityOk(details.mId) ; + bool banned = rsReputations->isIdentityBanned(details.mId) ; if(details.mNickname.empty()) nickname = tr("[Unknown]") ; @@ -936,7 +936,7 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList &icon { QPixmap pix ; - if(!rsReputations->isIdentityOk(details.mId)) + if(rsReputations->isIdentityBanned(details.mId)) { icons.clear() ; icons.push_back(QIcon(IMAGE_BANNED)) ; diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index 2726a1376..4b933fd04 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -153,7 +153,7 @@ QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const QString t = RSTreeWidgetItem::data(column, role).toString(); QImage pix; - if(!rsReputations->isIdentityOk(mId)) + if(rsReputations->isIdentityBanned(mId)) pix = QImage(BANNED_IMAGE) ; else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG")) pix = GxsIdDetails::makeDefaultIcon(mId); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index a542fa87f..2bb84c485 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -901,7 +901,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum // is flagged with a bad reputation - bool redacted = !rsReputations->isIdentityOk(msg.mMeta.mAuthorId) ; + bool redacted = rsReputations->isIdentityBanned(msg.mMeta.mAuthorId) ; GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0)); item->moveToThread(ui->threadTreeWidget->thread()); @@ -1320,7 +1320,7 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg) return; } - bool redacted = !rsReputations->isIdentityOk(msg.mMeta.mAuthorId) ; + bool redacted = rsReputations->isIdentityBanned(msg.mMeta.mAuthorId) ; mStateHelper->setActive(mTokenTypeMessageData, true);