mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 16:17:28 -04:00
Add RsReputations JSON API
This commit is contained in:
parent
ea7773f86d
commit
a6e8a27fc0
4 changed files with 162 additions and 38 deletions
|
@ -3,7 +3,8 @@
|
|||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2015 by Cyril Soler <retroshare.team@gmail.com> *
|
||||
* Copyright (C) 2015 Cyril Soler <retroshare.team@gmail.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
|
@ -23,6 +24,7 @@
|
|||
|
||||
#include "retroshare/rsids.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
|
||||
class RsReputations;
|
||||
|
||||
|
@ -33,8 +35,7 @@ class RsReputations;
|
|||
extern RsReputations* rsReputations;
|
||||
|
||||
|
||||
const float REPUTATION_THRESHOLD_DEFAULT = 1.0f;
|
||||
const float REPUTATION_THRESHOLD_ANTI_SPAM = 1.4f;
|
||||
constexpr float RS_REPUTATION_THRESHOLD_DEFAULT = 1.0f;
|
||||
|
||||
enum struct RsOpinion : uint8_t
|
||||
{
|
||||
|
@ -64,13 +65,14 @@ enum struct RsReputationLevel : uint8_t
|
|||
UNKNOWN = 0x05
|
||||
};
|
||||
|
||||
struct RsReputationInfo
|
||||
struct RsReputationInfo : RsSerializable
|
||||
{
|
||||
RsReputationInfo() :
|
||||
mOwnOpinion(RsOpinion::NEUTRAL), mFriendsPositiveVotes(0),
|
||||
mFriendsNegativeVotes(0),
|
||||
mFriendAverageScore(REPUTATION_THRESHOLD_DEFAULT),
|
||||
mFriendAverageScore(RS_REPUTATION_THRESHOLD_DEFAULT),
|
||||
mOverallReputationLevel(RsReputationLevel::NEUTRAL) {}
|
||||
virtual ~RsReputationInfo() {}
|
||||
|
||||
RsOpinion mOwnOpinion;
|
||||
|
||||
|
@ -81,6 +83,17 @@ struct RsReputationInfo
|
|||
|
||||
/// this should help clients in taking decisions
|
||||
RsReputationLevel mOverallReputationLevel;
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mOwnOpinion);
|
||||
RS_SERIAL_PROCESS(mFriendsPositiveVotes);
|
||||
RS_SERIAL_PROCESS(mFriendsNegativeVotes);
|
||||
RS_SERIAL_PROCESS(mFriendAverageScore);
|
||||
RS_SERIAL_PROCESS(mOverallReputationLevel);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -89,34 +102,143 @@ class RsReputations
|
|||
public:
|
||||
virtual ~RsReputations() {}
|
||||
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, RsOpinion op) = 0;
|
||||
virtual bool getOwnOpinion(const RsGxsId& key_id, RsOpinion& op) = 0;
|
||||
/**
|
||||
* @brief Set own opinion about the given identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @param[in] op Own opinion
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool setOwnOpinion(const RsGxsId& id, RsOpinion op) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get own opition about the given identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @param[out] op Own opinion
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getOwnOpinion(const RsGxsId& id, RsOpinion& op) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get reputation data of given identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @param[in] ownerNode Optiona PGP id of the signed identity, accept a null
|
||||
* (all zero/noninitialized) PGP id
|
||||
* @param[out] info storage for the information
|
||||
* @param[in] stamp if true, timestamo the information
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getReputationInfo(
|
||||
const RsGxsId& id, const RsPgpId& ownerNode, RsReputationInfo& info,
|
||||
bool stamp = true ) = 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 */
|
||||
RS_DEPRECATED
|
||||
virtual RsReputationLevel overallReputationLevel(
|
||||
const RsGxsId& id, uint32_t* identity_flags = nullptr) = 0;
|
||||
/**
|
||||
* @brief Get overall reputation level of given identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @return the calculated reputation level based on available information
|
||||
*/
|
||||
virtual RsReputationLevel overallReputationLevel(const RsGxsId& id) = 0;
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) = 0;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() = 0;
|
||||
/**
|
||||
* @brief Enable giving automatic positive opinion when flagging as contact
|
||||
* @jsonapi{development}
|
||||
* @param[in] b true to enable, false to disable
|
||||
*/
|
||||
virtual void setAutoPositiveOpinionForContacts(bool b) = 0;
|
||||
|
||||
virtual uint32_t thresholdForRemotelyNegativeReputation() = 0;
|
||||
virtual uint32_t thresholdForRemotelyPositiveReputation() = 0;
|
||||
/**
|
||||
* @brief check if giving automatic positive opinion when flagging as
|
||||
* contact is enbaled
|
||||
* @jsonapi{development}
|
||||
* @return true if enabled, false otherwise
|
||||
*/
|
||||
virtual bool autoPositiveOpinionForContacts() = 0;
|
||||
|
||||
/**
|
||||
* @brief Set threshold on remote reputation to consider it remotely
|
||||
* negative
|
||||
* @jsonapi{development}
|
||||
* @param[in] thresh Threshold value
|
||||
*/
|
||||
virtual void setThresholdForRemotelyNegativeReputation(uint32_t thresh) = 0;
|
||||
|
||||
/**
|
||||
* * @brief Get threshold on remote reputation to consider it remotely
|
||||
* negative
|
||||
* @jsonapi{development}
|
||||
* @return Threshold value
|
||||
*/
|
||||
virtual uint32_t thresholdForRemotelyNegativeReputation() = 0;
|
||||
|
||||
/**
|
||||
* @brief Set threshold on remote reputation to consider it remotely
|
||||
* positive
|
||||
* @jsonapi{development}
|
||||
* @param[in] thresh Threshold value
|
||||
*/
|
||||
virtual void setThresholdForRemotelyPositiveReputation(uint32_t thresh) = 0;
|
||||
|
||||
virtual void setRememberDeletedNodesThreshold(uint32_t days) = 0;
|
||||
virtual uint32_t rememberDeletedNodesThreshold() = 0;
|
||||
/**
|
||||
* @brief Get threshold on remote reputation to consider it remotely
|
||||
* negative
|
||||
* @jsonapi{development}
|
||||
* @return Threshold value
|
||||
*/
|
||||
virtual uint32_t thresholdForRemotelyPositiveReputation() = 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 */
|
||||
/**
|
||||
* @brief Get number of days to wait before deleting a banned identity from
|
||||
* local storage
|
||||
* @jsonapi{development}
|
||||
* @return number of days to wait, 0 means never delete
|
||||
*/
|
||||
virtual uint32_t rememberBannedIdThreshold() = 0;
|
||||
|
||||
/**
|
||||
* @brief Set number of days to wait before deleting a banned identity from
|
||||
* local storage
|
||||
* @jsonapi{development}
|
||||
* @param[in] days number of days to wait, 0 means never delete
|
||||
*/
|
||||
virtual void setRememberBannedIdThreshold(uint32_t days) = 0;
|
||||
|
||||
/**
|
||||
* @brief This method allow fast checking if a GXS identity is banned.
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity to check
|
||||
* @return true if identity is banned, false otherwise
|
||||
*/
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if automatic banning of all identities signed by the given
|
||||
* node is enabled
|
||||
* @jsonapi{development}
|
||||
* @param[in] id PGP id of the node
|
||||
* @return true if enabled, false otherwise
|
||||
*/
|
||||
virtual bool isNodeBanned(const RsPgpId& id) = 0;
|
||||
|
||||
/**
|
||||
* @brief Enable automatic banning of all identities signed by the given
|
||||
* node
|
||||
* @jsonapi{development}
|
||||
* @param[in] id PGP id of the node
|
||||
* @param[in] b true to enable, false to disable
|
||||
*/
|
||||
virtual void banNode(const RsPgpId& id, bool b) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* 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 ) = 0;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue