mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 16:17:28 -04:00
Refactor RsReputations for compatibility with JSON API
This commit is contained in:
parent
598521d1ac
commit
ea7773f86d
20 changed files with 280 additions and 208 deletions
|
@ -19,74 +19,104 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "retroshare/rsids.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
class RsReputations;
|
||||
|
||||
/**
|
||||
* Pointer to global instance of RsReputations service implementation
|
||||
* @jsonapi{development}
|
||||
*/
|
||||
extern RsReputations* rsReputations;
|
||||
|
||||
|
||||
const float REPUTATION_THRESHOLD_DEFAULT = 1.0f;
|
||||
const float REPUTATION_THRESHOLD_ANTI_SPAM = 1.4f;
|
||||
|
||||
enum struct RsOpinion : uint8_t
|
||||
{
|
||||
NEGATIVE = 0,
|
||||
NEUTRAL = 1,
|
||||
POSITIVE = 2
|
||||
};
|
||||
|
||||
enum struct RsReputationLevel : uint8_t
|
||||
{
|
||||
/// local opinion is negative
|
||||
LOCALLY_NEGATIVE = 0x00,
|
||||
|
||||
/// local opinion is neutral and friends are positive in average
|
||||
REMOTELY_NEGATIVE = 0x01,
|
||||
|
||||
/// no reputation information
|
||||
NEUTRAL = 0x02,
|
||||
|
||||
/// local opinion is neutral and friends are positive in average
|
||||
REMOTELY_POSITIVE = 0x03,
|
||||
|
||||
/// local opinion is positive
|
||||
LOCALLY_POSITIVE = 0x04,
|
||||
|
||||
/// missing info
|
||||
UNKNOWN = 0x05
|
||||
};
|
||||
|
||||
struct RsReputationInfo
|
||||
{
|
||||
RsReputationInfo() :
|
||||
mOwnOpinion(RsOpinion::NEUTRAL), mFriendsPositiveVotes(0),
|
||||
mFriendsNegativeVotes(0),
|
||||
mFriendAverageScore(REPUTATION_THRESHOLD_DEFAULT),
|
||||
mOverallReputationLevel(RsReputationLevel::NEUTRAL) {}
|
||||
|
||||
RsOpinion mOwnOpinion;
|
||||
|
||||
uint32_t mFriendsPositiveVotes;
|
||||
uint32_t mFriendsNegativeVotes;
|
||||
|
||||
float mFriendAverageScore;
|
||||
|
||||
/// this should help clients in taking decisions
|
||||
RsReputationLevel mOverallReputationLevel;
|
||||
};
|
||||
|
||||
|
||||
class RsReputations
|
||||
{
|
||||
public:
|
||||
static const float REPUTATION_THRESHOLD_ANTI_SPAM;
|
||||
static const float REPUTATION_THRESHOLD_DEFAULT;
|
||||
|
||||
// This is the interface file for the reputation system
|
||||
//
|
||||
enum Opinion { OPINION_NEGATIVE = 0, OPINION_NEUTRAL = 1, OPINION_POSITIVE = 2 } ;
|
||||
virtual ~RsReputations() {}
|
||||
|
||||
enum ReputationLevel { REPUTATION_LOCALLY_NEGATIVE = 0x00, // local opinion is positive
|
||||
REPUTATION_REMOTELY_NEGATIVE = 0x01, // local opinion is neutral and friends are positive in average
|
||||
REPUTATION_NEUTRAL = 0x02, // no reputation information ;
|
||||
REPUTATION_REMOTELY_POSITIVE = 0x03, // local opinion is neutral and friends are negative in average
|
||||
REPUTATION_LOCALLY_POSITIVE = 0x04, // local opinion is negative
|
||||
REPUTATION_UNKNOWN = 0x05 // missing info
|
||||
};
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, RsOpinion op) = 0;
|
||||
virtual bool getOwnOpinion(const RsGxsId& key_id, RsOpinion& op) = 0;
|
||||
virtual bool getReputationInfo(
|
||||
const RsGxsId& id, const RsPgpId& ownerNode, RsReputationInfo& info,
|
||||
bool stamp = true ) = 0;
|
||||
|
||||
struct ReputationInfo
|
||||
{
|
||||
ReputationInfo() : mOwnOpinion(OPINION_NEUTRAL),mFriendsPositiveVotes(0),mFriendsNegativeVotes(0), mFriendAverageScore(REPUTATION_THRESHOLD_DEFAULT),mOverallReputationLevel(REPUTATION_NEUTRAL){}
|
||||
|
||||
RsReputations::Opinion mOwnOpinion ;
|
||||
/** This returns the reputation level and also the flags of the identity
|
||||
* service for that id. This is useful in order to get these flags without
|
||||
* relying on the async method of p3Identity */
|
||||
RS_DEPRECATED
|
||||
virtual RsReputationLevel overallReputationLevel(
|
||||
const RsGxsId& id, uint32_t* identity_flags = nullptr) = 0;
|
||||
|
||||
uint32_t mFriendsPositiveVotes ;
|
||||
uint32_t mFriendsNegativeVotes ;
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) = 0;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() = 0;
|
||||
|
||||
float mFriendAverageScore ;
|
||||
virtual uint32_t thresholdForRemotelyNegativeReputation() = 0;
|
||||
virtual uint32_t thresholdForRemotelyPositiveReputation() = 0;
|
||||
virtual void setThresholdForRemotelyNegativeReputation(uint32_t thresh) = 0;
|
||||
virtual void setThresholdForRemotelyPositiveReputation(uint32_t thresh) = 0;
|
||||
|
||||
RsReputations::ReputationLevel mOverallReputationLevel; // this should help clients in taking decisions
|
||||
};
|
||||
virtual void setRememberDeletedNodesThreshold(uint32_t days) = 0;
|
||||
virtual uint32_t rememberDeletedNodesThreshold() = 0;
|
||||
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
|
||||
virtual bool getOwnOpinion(const RsGxsId& key_id, Opinion& op) =0;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info,bool stamp=true) =0;
|
||||
/** This one is a proxy designed to allow fast checking of a GXS id.
|
||||
* It basically returns true if assessment is not ASSESSMENT_OK */
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) = 0;
|
||||
|
||||
// This returns the reputation level and also the flags of the identity service for that id. This is useful in order to get these flags without relying on the async method of p3Identity
|
||||
|
||||
virtual ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL)=0;
|
||||
|
||||
// parameters
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) =0;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() =0;
|
||||
|
||||
virtual uint32_t thresholdForRemotelyNegativeReputation()=0;
|
||||
virtual uint32_t thresholdForRemotelyPositiveReputation()=0;
|
||||
virtual void setThresholdForRemotelyNegativeReputation(uint32_t thresh)=0;
|
||||
virtual void setThresholdForRemotelyPositiveReputation(uint32_t thresh)=0;
|
||||
|
||||
virtual void setRememberDeletedNodesThreshold(uint32_t days) =0;
|
||||
virtual uint32_t rememberDeletedNodesThreshold() =0;
|
||||
|
||||
// This one is a proxy designed to allow fast checking of a GXS id.
|
||||
// it basically returns true if assessment is not ASSESSMENT_OK
|
||||
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) =0;
|
||||
|
||||
virtual bool isNodeBanned(const RsPgpId& id) =0;
|
||||
virtual void banNode(const RsPgpId& id,bool b) =0;
|
||||
virtual bool isNodeBanned(const RsPgpId& id) = 0;
|
||||
virtual void banNode(const RsPgpId& id, bool b) = 0;
|
||||
};
|
||||
|
||||
// To access reputations from anywhere
|
||||
//
|
||||
extern RsReputations *rsReputations ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue