Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/retroshare/rsreputations.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "retroshare/rsids.h"
#include "retroshare/rsgxsifacetypes.h"
#include "serialiser/rsserializable.h"
#include <vector>

class RsReputations;

Expand Down Expand Up @@ -97,6 +98,14 @@ struct RsReputationInfo : RsSerializable
virtual ~RsReputationInfo();
};

struct RsBannedIdentityInfo
{
RsGxsId mId;
rstime_t mOwnOpinionTs = 0;
rstime_t mLastUsedTS = 0;
bool mIsLocallyBanned = false;
};


class RsReputations
{
Expand Down Expand Up @@ -214,6 +223,15 @@ class RsReputations
*/
virtual bool isIdentityBanned(const RsGxsId& id) = 0;

/**
* @brief Get identities with locally or remotely negative reputation.
* @jsonapi{development}
* @param[out] identities storage for negative identities
* @return true on success, false otherwise
*/
virtual bool getLocallyBannedIdentities(
std::vector<RsBannedIdentityInfo>& identities ) = 0;

/**
* @brief Check if automatic banning of all identities signed by the given
* node is enabled
Expand Down
32 changes: 32 additions & 0 deletions src/services/p3gxsreputation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,38 @@ bool p3GxsReputation::isIdentityBanned(const RsGxsId &id)
return info.mOverallReputationLevel == RsReputationLevel::LOCALLY_NEGATIVE;
}

bool p3GxsReputation::getLocallyBannedIdentities(
std::vector<RsBannedIdentityInfo>& identities )
{
RS_STACK_MUTEX(mReputationMtx);

identities.clear();
identities.reserve(mReputations.size());

for(const auto& entry : mReputations)
{
const Reputation& rep(entry.second);
const bool locallyBanned =
rep.mOwnOpinion == static_cast<int32_t>(RsOpinion::NEGATIVE);
const bool remotelyNegative =
rep.mOwnOpinion == static_cast<int32_t>(RsOpinion::NEUTRAL)
&& rep.mFriendsPositive + mMinVotesForRemotelyNegative
<= rep.mFriendsNegative;

if(locallyBanned || remotelyNegative)
{
RsBannedIdentityInfo info;
info.mId = entry.first;
info.mOwnOpinionTs = rep.mOwnOpinionTs;
info.mLastUsedTS = rep.mLastUsedTS;
info.mIsLocallyBanned = locallyBanned;
identities.push_back(info);
}
}

return true;
}

bool p3GxsReputation::getOwnOpinion(
const RsGxsId& gxsid, RsOpinion& opinion )
{
Expand Down
2 changes: 2 additions & 0 deletions src/services/p3gxsreputation.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class p3GxsReputation: public p3Service, public p3Config, public RsGixsReputatio
const RsGxsId& id, const RsPgpId& ownerNode, RsReputationInfo& info,
bool stamp = true );
virtual bool isIdentityBanned(const RsGxsId& id) ;
virtual bool getLocallyBannedIdentities(
std::vector<RsBannedIdentityInfo>& identities ) override;

virtual bool isNodeBanned(const RsPgpId& id);
virtual void banNode(const RsPgpId& id,bool b) ;
Expand Down