diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 25d4e52d8..b002638da 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1614,6 +1614,10 @@ uint32_t RsGenExchange::getDefaultSyncPeriod() } } +RsReputations::ReputationLevel RsGenExchange::minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_sign_flags) +{ + return RsNetworkExchangeService::minReputationForForwardingMessages(group_sign_flags,identity_sign_flags); +} uint32_t RsGenExchange::getSyncPeriod(const RsGxsGroupId& grpId) { RS_STACK_MUTEX(mGenMtx) ; diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index 0614ed2b1..95efbf2e1 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -658,6 +658,7 @@ public: uint16_t serviceType() const { return mServType ; } uint32_t serviceFullType() const { return ((uint32_t)mServType << 8) + (((uint32_t) RS_PKT_VERSION_SERVICE) << 24); } + virtual RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags); protected: /** Notifications **/ diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index a9c55eae0..f8fa8ecc2 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -4210,18 +4210,10 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_ if(canSendMsgIds(msgMetas, *grpMeta, peer, should_encrypt_to_this_circle_id)) { - RsReputations::ReputationLevel min_rep_for_anonymous ; - RsReputations::ReputationLevel min_rep_for_unknown_signed ; - - min_rep_for_anonymous = (grpMeta->mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG )?RsReputations::REPUTATION_REMOTELY_POSITIVE: RsReputations::REPUTATION_REMOTELY_NEGATIVE; - min_rep_for_unknown_signed = (grpMeta->mSignFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN)?RsReputations::REPUTATION_REMOTELY_POSITIVE: RsReputations::REPUTATION_REMOTELY_NEGATIVE; - for(std::vector::iterator vit = msgMetas.begin();vit != msgMetas.end(); ++vit) { RsGxsMsgMetaData* m = *vit; - // if anti-spam is enabled, do not send messages from authors with bad reputation - RsIdentityDetails details ; if(!rsIdentity->getIdDetails(m->mAuthorId,details)) @@ -4229,21 +4221,14 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_ std::cerr << /* GXSNETDEBUG_PG(item->PeerId(),item->grpId) << */ " not sending grp message ID " << (*vit)->mMsgId << ", because the identity of the author is not accessible (unknown/not cached)" << std::endl; continue ; } - if(!(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED) && details.mReputation.mOverallReputationLevel < min_rep_for_anonymous) - { -//#ifdef NXS_NET_DEBUG_0 - std::cerr << /* GXSNETDEBUG_PG(item->PeerId(),item->grpId) << */ " not sending item ID " << (*vit)->mMsgId << ", because the author is anonymous has reputation level " << details.mReputation.mOverallReputationLevel << std::endl; -//#endif - continue ; - } - if(!(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN) && details.mReputation.mOverallReputationLevel < min_rep_for_unknown_signed) - { -//#ifdef NXS_NET_DEBUG_0 - std::cerr << /* GXSNETDEBUG_PG(item->PeerId(),item->grpId) << */ " not sending item ID " << (*vit)->mMsgId << ", because the author is signed by unknown key, and has reputation level " << details.mReputation.mOverallReputationLevel << std::endl; -//#endif - continue ; - } + if(details.mReputation.mOverallReputationLevel < minReputationForForwardingMessages(grpMeta->mSignFlags, details.mFlags)) + { +//#ifdef NXS_NET_DEBUG_0 + std::cerr << /* GXSNETDEBUG_PG(item->PeerId(),item->grpId) << */ " not sending item ID " << (*vit)->mMsgId << ", because the author is flags " << std::hex << details.mFlags << std::dec << " and reputation level " << details.mReputation.mOverallReputationLevel << std::endl; +//#endif + continue ; + } // Check publish TS if(item->createdSinceTS > (*vit)->mPublishTs) diff --git a/libretroshare/src/gxs/rsnxs.h b/libretroshare/src/gxs/rsnxs.h index 0613560b0..995377ed3 100644 --- a/libretroshare/src/gxs/rsnxs.h +++ b/libretroshare/src/gxs/rsnxs.h @@ -34,6 +34,8 @@ #include #include "services/p3service.h" +#include "retroshare/rsreputations.h" +#include "retroshare/rsidentity.h" #include "rsgds.h" /*! @@ -159,6 +161,50 @@ public: * \return */ virtual bool stampMsgServerUpdateTS(const RsGxsGroupId& gid) =0; + + /*! + * \brief minReputationForForwardingMessages + * Encodes the policy for sending/requesting messages depending on anti-spam settings. + * + * \param group_sign_flags Sign flags from the group meta data + * \param identity_flags Flags of the identity + * \return + */ + static RsReputations::ReputationLevel minReputationForRequestingMessages(uint32_t /* group_sign_flags */, uint32_t /* identity_flags */) + { + // We always request messages, except if the author identity is locally banned. + + return RsReputations::REPUTATION_REMOTELY_NEGATIVE; + } + static RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags, uint32_t identity_flags) + { + // If anti-spam is enabled, do not send messages from authors with bad reputation. The policy is to only forward messages if the reputation of the author is at least + // equal to the minimal reputation in the table below (R=remotely, L=locally, P=positive, N=negative) : + // + // | Anonymous Signed Signed+Known + // -----------+----------------------------------------------------- + // NONE | RN RN RN + // GPG_AUTHED | RP RN RN + // GPG_KNOWN | RP RP RN + // + + if(identity_flags & RS_IDENTITY_FLAGS_PGP_KNOWN) + return RsReputations::REPUTATION_REMOTELY_NEGATIVE; + else if(identity_flags & RS_IDENTITY_FLAGS_PGP_LINKED) + { + if(group_sign_flags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) + return RsReputations::REPUTATION_REMOTELY_POSITIVE; + else + return RsReputations::REPUTATION_REMOTELY_NEGATIVE; + } + else + { + if( (group_sign_flags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN) || (group_sign_flags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)) + return RsReputations::REPUTATION_REMOTELY_POSITIVE; + else + return RsReputations::REPUTATION_REMOTELY_NEGATIVE; + } + } }; #endif // RSGNP_H diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index cf7ca26ef..e1835928e 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -61,37 +61,36 @@ std::ostream &operator<<(std::ostream &out, const RsGxsForumMsg &msg); class RsGxsForums: public RsGxsIfaceHelper { - public: +public: RsGxsForums(RsGxsIface *gxs) - :RsGxsIfaceHelper(gxs) { return; } -virtual ~RsGxsForums() { return; } + :RsGxsIfaceHelper(gxs) { return; } + virtual ~RsGxsForums() { return; } /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; -virtual bool getMsgData(const uint32_t &token, std::vector &msgs) = 0; -//Not currently used -//virtual bool getRelatedMessages(const uint32_t &token, std::vector &msgs) = 0; + virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; + virtual bool getMsgData(const uint32_t &token, std::vector &msgs) = 0; + //Not currently used + //virtual bool getRelatedMessages(const uint32_t &token, std::vector &msgs) = 0; - ////////////////////////////////////////////////////////////////////////////// -virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0; + ////////////////////////////////////////////////////////////////////////////// + virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0; -//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); -//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); + //virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); + //virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); -//virtual bool groupRestoreKeys(const std::string &groupId); -//virtual bool groupShareKeys(const std::string &groupId, std::list& peers); + //virtual bool groupRestoreKeys(const std::string &groupId); + //virtual bool groupShareKeys(const std::string &groupId, std::list& peers); -virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group) = 0; -virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0; - -/*! + virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group) = 0; + virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0; + /*! * To update forum group with new information * @param token the token used to check completion status of update * @param group group to be updated, groupId element must be set or will be rejected * @return false groupId not set, true if set and accepted (still check token for completion) */ -virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0; + virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0; }; diff --git a/libretroshare/src/retroshare/rsgxsiface.h b/libretroshare/src/retroshare/rsgxsiface.h index 8eb1ac6ae..3e2ae55ae 100644 --- a/libretroshare/src/retroshare/rsgxsiface.h +++ b/libretroshare/src/retroshare/rsgxsiface.h @@ -27,6 +27,7 @@ #ifndef RSGXSIFACE_H_ #define RSGXSIFACE_H_ +#include "retroshare/rsreputations.h" #include "retroshare/rsgxsservice.h" #include "gxs/rsgxsdata.h" #include "retroshare/rsgxsifacetypes.h" @@ -181,6 +182,8 @@ public: virtual uint32_t getDefaultSyncPeriod() = 0; virtual uint32_t getSyncPeriod(const RsGxsGroupId& grpId) = 0; virtual void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) = 0; + + virtual RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags)=0; }; diff --git a/libretroshare/src/retroshare/rsgxsifacehelper.h b/libretroshare/src/retroshare/rsgxsifacehelper.h index e23f1aeb1..fbe12570e 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -27,6 +27,7 @@ */ #include "retroshare/rsgxsiface.h" +#include "retroshare/rsreputations.h" #include "rsgxsflags.h" /*! @@ -236,6 +237,10 @@ public: mGxs->setSyncPeriod(grpId,age_in_secs); } + RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags) + { + return mGxs->minReputationForForwardingMessages(group_sign_flags,identity_flags); + } private: RsGxsIface* mGxs; diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 5dc948599..ef1841375 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -1857,9 +1857,9 @@ void IdDialog::insertIdDetails(uint32_t token) switch(info.mOverallReputationLevel) { case RsReputations::REPUTATION_LOCALLY_POSITIVE: ui->overallOpinion_TF->setText(tr("Positive")) ; break ; - case RsReputations::REPUTATION_LOCALLY_NEGATIVE: ui->overallOpinion_TF->setText(tr("Negative (Banned)")) ; break ; - case RsReputations::REPUTATION_REMOTELY_POSITIVE: ui->overallOpinion_TF->setText(tr("Positive, according to your friends")) ; break ; - case RsReputations::REPUTATION_REMOTELY_NEGATIVE: ui->overallOpinion_TF->setText(tr("Negative, according to your friends")) ; break ; + case RsReputations::REPUTATION_LOCALLY_NEGATIVE: ui->overallOpinion_TF->setText(tr("Negative (Banned by you)")) ; break ; + case RsReputations::REPUTATION_REMOTELY_POSITIVE: ui->overallOpinion_TF->setText(tr("Positive (according to your friends)")) ; break ; + case RsReputations::REPUTATION_REMOTELY_NEGATIVE: ui->overallOpinion_TF->setText(tr("Negative (according to your friends)")) ; break ; default: case RsReputations::REPUTATION_NEUTRAL: ui->overallOpinion_TF->setText(tr("Neutral")) ; break ; } diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index dff9e9607..7c115aecc 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "GxsForumThreadWidget.h" #include "ui_GxsForumThreadWidget.h" @@ -61,6 +62,9 @@ #define IMAGE_DOWNLOADALL ":/images/startall.png" #define IMAGE_COPYLINK ":/images/copyrslink.png" #define IMAGE_BIOHAZARD ":/icons/yellow_biohazard64.png" +#define IMAGE_WARNING_YELLOW ":/icons/warning_yellow_128.png" +#define IMAGE_WARNING_RED ":/icons/warning_red_128.png" +#define IMAGE_VOID ":/icons/void_128.png" #define IMAGE_POSITIVE_OPINION ":/icons/png/thumbs-up.png" #define IMAGE_NEUTRAL_OPINION ":/icons/png/thumbs-neutral.png" #define IMAGE_NEGATIVE_OPINION ":/icons/png/thumbs-down.png" @@ -92,6 +96,45 @@ #define ROLE_THREAD_COUNT 4 +class DistributionItemDelegate: public QStyledItemDelegate +{ +public: + DistributionItemDelegate() {} + + virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const + { + Q_ASSERT(index.isValid()); + + QStyleOptionViewItemV4 opt = option; + initStyleOption(&opt, index); + // disable default icon + opt.icon = QIcon(); + // draw default item + QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0); + + const QRect r = option.rect; + + QIcon icon ; + + // get pixmap + unsigned int warning_level = qvariant_cast(index.data(Qt::DecorationRole)); + + switch(warning_level) + { + default: + case 0: icon = QIcon(IMAGE_VOID); break; + case 1: icon = QIcon(IMAGE_WARNING_YELLOW); break; + case 2: icon = QIcon(IMAGE_WARNING_RED); break; + } + + QPixmap pix = icon.pixmap(r.size()); + + // draw pixmap at center of item + const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2); + painter->drawPixmap(r.topLeft() + p, pix); + } +}; + GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget *parent) : GxsMessageFrameWidget(rsGxsForums, parent), ui(new Ui::GxsForumThreadWidget) @@ -143,7 +186,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget mThreadCompareRole = new RSTreeWidgetItemCompareRole; mThreadCompareRole->setRole(COLUMN_THREAD_DATE, ROLE_THREAD_SORT); - ui->threadTreeWidget->setItemDelegateForColumn(COLUMN_THREAD_DISTRIBUTION,new ReputationItemDelegate(RsReputations::REPUTATION_NEUTRAL)) ; + ui->threadTreeWidget->setItemDelegateForColumn(COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ; connect(ui->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint))); connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint))); @@ -1018,9 +1061,18 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum // Early check for a message that should be hidden because its author // is flagged with a bad reputation - uint32_t reputation_level = rsIdentity->overallReputationLevel(msg.mMeta.mAuthorId) ; + RsIdentityDetails iddetails ; - bool redacted = (reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE) ; + RsReputations::ReputationLevel reputation_level = RsReputations::REPUTATION_NEUTRAL ; + bool redacted = false ; + + if(!rsIdentity->getIdDetails(msg.mMeta.mAuthorId,iddetails)) + std::cerr << "(WW) Cannot grab identity details for " << msg.mMeta.mAuthorId.toStdString() << std::endl; + else + { + reputation_level = iddetails.mReputation.mOverallReputationLevel ; + redacted = (reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE) ; + } GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_AVATAR ); item->moveToThread(ui->threadTreeWidget->thread()); @@ -1030,18 +1082,27 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum else item->setText(COLUMN_THREAD_TITLE, QString::fromUtf8(msg.mMeta.mMsgName.c_str())); - item->setData(COLUMN_THREAD_DISTRIBUTION,Qt::DecorationRole, reputation_level) ; - QString rep_tooltip_str ; - switch(reputation_level) + uint32_t rep_warning_level ; + + if(reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE) { - case RsReputations::REPUTATION_LOCALLY_NEGATIVE: rep_tooltip_str = tr("You have banned this ID. The message will not be\ndisplayed nor forwarded to your friends.") ; break; - case RsReputations::REPUTATION_REMOTELY_NEGATIVE: rep_tooltip_str = tr("You have not set an opinion for this person,\n and your friends vote negatively: Spam regulation \nprevents the message to be forwarded to your friends.") ; break; - case RsReputations::REPUTATION_NEUTRAL: rep_tooltip_str = tr("You have not set an opinion for this person,\n and neither have your friends: Spam regulation\nprevents the message to be forwarded to your friends.") ; break; - default: - rep_tooltip_str = tr("Message will be forwarded to your friends.") ; break; + rep_warning_level = 2 ; + rep_tooltip_str = tr("You have banned this ID. The message will not be\ndisplayed nor forwarded to your friends.") ; } + else if(reputation_level < rsGxsForums->minReputationForForwardingMessages(mForumGroup.mMeta.mSignFlags,iddetails.mFlags)) + { + rep_warning_level = 1 ; + rep_tooltip_str = tr("You have not set an opinion for this person,\n and your friends do not vote positively: Spam regulation \nprevents the message to be forwarded to your friends.") ; + } + else + { + rep_warning_level = 0 ; + rep_tooltip_str = tr("Message will be forwarded to your friends.") ; + } + item->setData(COLUMN_THREAD_DISTRIBUTION,Qt::ToolTipRole,rep_tooltip_str) ; + item->setData(COLUMN_THREAD_DISTRIBUTION,Qt::DecorationRole,rep_warning_level) ; //msg.mMeta.mChildTs Was not updated when received new child // so do it here. diff --git a/retroshare-gui/src/gui/icons.qrc b/retroshare-gui/src/gui/icons.qrc index 1a63b784d..8b57ae68a 100644 --- a/retroshare-gui/src/gui/icons.qrc +++ b/retroshare-gui/src/gui/icons.qrc @@ -216,6 +216,8 @@ icons/user-offline_64.png icons/user-online_64.png icons/void_128.png + icons/warning_red_128.png + icons/warning_yellow_128.png icons/yahoo.png icons/yandex.png icons/yellow_biohazard64.png diff --git a/retroshare-gui/src/gui/icons/warning_red_128.png b/retroshare-gui/src/gui/icons/warning_red_128.png new file mode 100644 index 000000000..3399fee0c Binary files /dev/null and b/retroshare-gui/src/gui/icons/warning_red_128.png differ diff --git a/retroshare-gui/src/gui/icons/warning_yellow_128.png b/retroshare-gui/src/gui/icons/warning_yellow_128.png new file mode 100644 index 000000000..0d809ce65 Binary files /dev/null and b/retroshare-gui/src/gui/icons/warning_yellow_128.png differ