From 657857dca14c7389e501761e7a213d0f46e0eb94 Mon Sep 17 00:00:00 2001 From: retrop00h Date: Fri, 24 Apr 2026 17:18:16 +0300 Subject: [PATCH] showbanlist_lib --- src/retroshare/rsreputations.h | 18 ++++++++++++++++++ src/services/p3gxsreputation.cc | 32 ++++++++++++++++++++++++++++++++ src/services/p3gxsreputation.h | 2 ++ 3 files changed, 52 insertions(+) diff --git a/src/retroshare/rsreputations.h b/src/retroshare/rsreputations.h index b8426e6423..9117ff665b 100644 --- a/src/retroshare/rsreputations.h +++ b/src/retroshare/rsreputations.h @@ -25,6 +25,7 @@ #include "retroshare/rsids.h" #include "retroshare/rsgxsifacetypes.h" #include "serialiser/rsserializable.h" +#include class RsReputations; @@ -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 { @@ -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& identities ) = 0; + /** * @brief Check if automatic banning of all identities signed by the given * node is enabled diff --git a/src/services/p3gxsreputation.cc b/src/services/p3gxsreputation.cc index 4b7383a936..ca4eae64e8 100644 --- a/src/services/p3gxsreputation.cc +++ b/src/services/p3gxsreputation.cc @@ -1003,6 +1003,38 @@ bool p3GxsReputation::isIdentityBanned(const RsGxsId &id) return info.mOverallReputationLevel == RsReputationLevel::LOCALLY_NEGATIVE; } +bool p3GxsReputation::getLocallyBannedIdentities( + std::vector& 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(RsOpinion::NEGATIVE); + const bool remotelyNegative = + rep.mOwnOpinion == static_cast(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 ) { diff --git a/src/services/p3gxsreputation.h b/src/services/p3gxsreputation.h index 2045e6f057..c3ec431cae 100644 --- a/src/services/p3gxsreputation.h +++ b/src/services/p3gxsreputation.h @@ -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& identities ) override; virtual bool isNodeBanned(const RsPgpId& id); virtual void banNode(const RsPgpId& id,bool b) ;