mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
Merge pull request #1478 from G10h4ck/jsonapi
extend JSON API to identities, circles and reputation
This commit is contained in:
commit
f4e13975b0
@ -504,7 +504,7 @@ void IdentityHandler::handleGetIdentityDetails(Request& req, Response& resp)
|
||||
|
||||
resp.mDataStream << makeKeyValue("bannned_node", rsReputations->isNodeBanned(data.mPgpId));
|
||||
|
||||
RsReputations::ReputationInfo info;
|
||||
RsReputationInfo info;
|
||||
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId), data.mPgpId, info);
|
||||
resp.mDataStream << makeKeyValue("friends_positive_votes", info.mFriendsPositiveVotes);
|
||||
resp.mDataStream << makeKeyValue("friends_negative_votes", info.mFriendsNegativeVotes);
|
||||
@ -637,18 +637,12 @@ void IdentityHandler::handleSetOpinion(Request& req, Response& resp)
|
||||
int own_opinion;
|
||||
req.mStream << makeKeyValueReference("own_opinion", own_opinion);
|
||||
|
||||
RsReputations::Opinion opinion;
|
||||
RsOpinion opinion;
|
||||
switch(own_opinion)
|
||||
{
|
||||
case 0:
|
||||
opinion = RsReputations::OPINION_NEGATIVE;
|
||||
break;
|
||||
case 1: opinion =
|
||||
RsReputations::OPINION_NEUTRAL;
|
||||
break;
|
||||
case 2:
|
||||
opinion = RsReputations::OPINION_POSITIVE;
|
||||
break;
|
||||
case 0: opinion = RsOpinion::NEGATIVE; break;
|
||||
case 1: opinion = RsOpinion::NEUTRAL; break;
|
||||
case 2: opinion = RsOpinion::POSITIVE; break;
|
||||
default:
|
||||
resp.setFail();
|
||||
return;
|
||||
|
@ -136,7 +136,8 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(rsReputations->overallReputationLevel(cli->signature.keyId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( rsReputations->overallReputationLevel(cli->signature.keyId) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl;
|
||||
return false ;
|
||||
@ -677,9 +678,10 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
|
||||
#ifdef DEBUG_CHAT_LOBBIES
|
||||
std::cerr << "Received ChatLobbyEvent item of type " << (int)(item->event_type) << ", and string=" << item->string1 << std::endl;
|
||||
#endif
|
||||
rstime_t now = time(NULL) ;
|
||||
rstime_t now = time(nullptr);
|
||||
|
||||
if(rsReputations->overallReputationLevel(item->signature.keyId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( rsReputations->overallReputationLevel(item->signature.keyId) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl;
|
||||
return ;
|
||||
|
@ -2014,7 +2014,8 @@ bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item,const RsIden
|
||||
{
|
||||
try
|
||||
{
|
||||
if(rsReputations->overallReputationLevel(item->signature.keyId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( rsReputations->overallReputationLevel(item->signature.keyId) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl;
|
||||
return false ;
|
||||
|
@ -912,7 +912,8 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
|
||||
// now check reputation of the message author. The reputation will need to be at least as high as this value for the msg to validate.
|
||||
// At validation step, we accept all messages, except the ones signed by locally rejected identities.
|
||||
|
||||
if(details.mReputation.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( details.mReputation.mOverallReputationLevel ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::validateMsg(): message from " << metaData.mAuthorId << ", rejected because reputation level (" << details.mReputation.mOverallReputationLevel <<") indicate that you banned this ID." << std::endl;
|
||||
@ -1848,7 +1849,8 @@ uint32_t RsGenExchange::getDefaultSyncPeriod()
|
||||
}
|
||||
}
|
||||
|
||||
RsReputations::ReputationLevel RsGenExchange::minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_sign_flags)
|
||||
RsReputationLevel RsGenExchange::minReputationForForwardingMessages(
|
||||
uint32_t group_sign_flags, uint32_t identity_sign_flags )
|
||||
{
|
||||
return RsNetworkExchangeService::minReputationForForwardingMessages(group_sign_flags,identity_sign_flags);
|
||||
}
|
||||
|
@ -712,7 +712,8 @@ public:
|
||||
uint16_t serviceType() const { return mServType ; }
|
||||
uint32_t serviceFullType() const { return RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(mServType); }
|
||||
|
||||
virtual RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags);
|
||||
virtual RsReputationLevel minReputationForForwardingMessages(
|
||||
uint32_t group_sign_flags, uint32_t identity_flags );
|
||||
protected:
|
||||
|
||||
/** Notifications **/
|
||||
|
@ -178,25 +178,23 @@ public:
|
||||
uint32_t reputation_level ;
|
||||
};
|
||||
|
||||
class RsGixsReputation
|
||||
struct RsGixsReputation
|
||||
{
|
||||
public:
|
||||
// get Reputation.
|
||||
virtual RsReputations::ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL) = 0;
|
||||
virtual RsReputationLevel overallReputationLevel(
|
||||
const RsGxsId& id, uint32_t* identity_flags = nullptr ) = 0;
|
||||
virtual ~RsGixsReputation(){}
|
||||
};
|
||||
|
||||
/*** This Class pulls all the GXS Interfaces together ****/
|
||||
|
||||
class RsGxsIdExchange:
|
||||
public RsGenExchange,
|
||||
public RsGixs
|
||||
struct RsGxsIdExchange : RsGenExchange, RsGixs
|
||||
{
|
||||
public:
|
||||
RsGxsIdExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser, uint16_t mServType, uint32_t authenPolicy)
|
||||
:RsGenExchange(gds,ns,serviceSerialiser,mServType, this, authenPolicy) { return; }
|
||||
virtual ~RsGxsIdExchange() { return; }
|
||||
|
||||
RsGxsIdExchange(
|
||||
RsGeneralDataService* gds, RsNetworkExchangeService* ns,
|
||||
RsSerialType* serviceSerialiser, uint16_t mServType,
|
||||
uint32_t authenPolicy )
|
||||
: RsGenExchange(
|
||||
gds, ns, serviceSerialiser, mServType, this, authenPolicy ) {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -3034,7 +3034,8 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
// - if author is locally banned, do not download.
|
||||
// - if author is not locally banned, download, whatever friends' opinion might be.
|
||||
|
||||
if(mReputations->overallReputationLevel(syncItem->authorId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( mReputations->overallReputationLevel(syncItem->authorId) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_1
|
||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << ", Identity " << syncItem->authorId << " is banned. Not requesting message!" << std::endl;
|
||||
@ -3239,7 +3240,9 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
// FIXTESTS global variable rsReputations not available in unittests!
|
||||
|
||||
#warning csoler 2016-12-23: Update the code below to correctly send/recv dependign on reputation
|
||||
if(!grpSyncItem->authorId.isNull() && mReputations->overallReputationLevel(grpSyncItem->authorId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( !grpSyncItem->authorId.isNull() &&
|
||||
mReputations->overallReputationLevel(grpSyncItem->authorId) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " Identity " << grpSyncItem->authorId << " is banned. Not syncing group." << std::endl;
|
||||
|
@ -40,7 +40,8 @@ bool AuthorPending::expired() const
|
||||
bool AuthorPending::getAuthorRep(GixsReputation& rep, const RsGxsId& authorId, const RsPeerId& /*peerId*/)
|
||||
{
|
||||
rep.id = authorId ;
|
||||
rep.reputation_level = mRep->overallReputationLevel(authorId);
|
||||
rep.reputation_level =
|
||||
static_cast<uint32_t>(mRep->overallReputationLevel(authorId));
|
||||
|
||||
#warning csoler 2017-01-10: Can it happen that reputations do not have the info yet?
|
||||
return true ;
|
||||
|
@ -204,7 +204,10 @@ bool RsGxsIntegrityCheck::check()
|
||||
#ifdef DEBUG_GXSUTIL
|
||||
GXSUTIL_DEBUG() << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->grpId << std::endl;
|
||||
#endif
|
||||
if( rsReputations && rsReputations->overallReputationLevel(grp->metaData->mAuthorId ) > RsReputations::REPUTATION_LOCALLY_NEGATIVE )
|
||||
if( rsReputations &&
|
||||
rsReputations->overallReputationLevel(
|
||||
grp->metaData->mAuthorId ) >
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
used_gxs_ids.insert(std::make_pair(grp->metaData->mAuthorId, RsIdentityUsage(mGenExchangeClient->serviceType(), RsIdentityUsage::GROUP_AUTHOR_KEEP_ALIVE,grp->grpId)));
|
||||
}
|
||||
}
|
||||
@ -388,7 +391,10 @@ bool RsGxsIntegrityCheck::check()
|
||||
#ifdef DEBUG_GXSUTIL
|
||||
GXSUTIL_DEBUG() << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl;
|
||||
#endif
|
||||
if(rsReputations!=NULL && rsReputations->overallReputationLevel(msg->metaData->mAuthorId) > RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( rsReputations &&
|
||||
rsReputations->overallReputationLevel(
|
||||
msg->metaData->mAuthorId ) >
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
used_gxs_ids.insert(std::make_pair(msg->metaData->mAuthorId,RsIdentityUsage(mGenExchangeClient->serviceType(),RsIdentityUsage::MESSAGE_AUTHOR_KEEP_ALIVE,msg->metaData->mGroupId,msg->metaData->mMsgId))) ;
|
||||
}
|
||||
}
|
||||
|
@ -253,13 +253,14 @@ public:
|
||||
* \param identity_flags Flags of the identity
|
||||
* \return
|
||||
*/
|
||||
static RsReputations::ReputationLevel minReputationForRequestingMessages(uint32_t /* group_sign_flags */, uint32_t /* identity_flags */)
|
||||
static RsReputationLevel 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;
|
||||
return RsReputationLevel::REMOTELY_NEGATIVE;
|
||||
}
|
||||
static RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags, uint32_t identity_flags)
|
||||
static RsReputationLevel 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, O=neutral) :
|
||||
@ -277,20 +278,20 @@ public:
|
||||
//
|
||||
|
||||
if(identity_flags & RS_IDENTITY_FLAGS_PGP_KNOWN)
|
||||
return RsReputations::REPUTATION_NEUTRAL;
|
||||
return RsReputationLevel::NEUTRAL;
|
||||
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;
|
||||
return RsReputationLevel::REMOTELY_POSITIVE;
|
||||
else
|
||||
return RsReputations::REPUTATION_NEUTRAL;
|
||||
return RsReputationLevel::NEUTRAL;
|
||||
}
|
||||
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;
|
||||
return RsReputationLevel::REMOTELY_POSITIVE;
|
||||
else
|
||||
return RsReputations::REPUTATION_NEUTRAL;
|
||||
return RsReputationLevel::NEUTRAL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1256,31 +1256,38 @@ bool p3GxsTrans::acceptNewMessage(const RsGxsMsgMetaData *msgMeta,uint32_t msg_s
|
||||
uint32_t max_size = 0 ;
|
||||
uint32_t identity_flags = 0 ;
|
||||
|
||||
RsReputations::ReputationLevel rep_lev = rsReputations->overallReputationLevel(msgMeta->mAuthorId,&identity_flags);
|
||||
RsReputationLevel rep_lev =
|
||||
rsReputations->overallReputationLevel(
|
||||
msgMeta->mAuthorId, &identity_flags );
|
||||
|
||||
switch(rep_lev)
|
||||
{
|
||||
case RsReputations::REPUTATION_REMOTELY_NEGATIVE: max_count = GXSTRANS_MAX_COUNT_REMOTELY_NEGATIVE_DEFAULT;
|
||||
case RsReputationLevel::REMOTELY_NEGATIVE:
|
||||
max_count = GXSTRANS_MAX_COUNT_REMOTELY_NEGATIVE_DEFAULT;
|
||||
max_size = GXSTRANS_MAX_SIZE_REMOTELY_NEGATIVE_DEFAULT;
|
||||
break ;
|
||||
case RsReputations::REPUTATION_NEUTRAL: max_count = GXSTRANS_MAX_COUNT_NEUTRAL_DEFAULT;
|
||||
case RsReputationLevel::NEUTRAL:
|
||||
max_count = GXSTRANS_MAX_COUNT_NEUTRAL_DEFAULT;
|
||||
max_size = GXSTRANS_MAX_SIZE_NEUTRAL_DEFAULT;
|
||||
break;
|
||||
case RsReputations::REPUTATION_REMOTELY_POSITIVE: max_count = GXSTRANS_MAX_COUNT_REMOTELY_POSITIVE_DEFAULT;
|
||||
case RsReputationLevel::REMOTELY_POSITIVE:
|
||||
max_count = GXSTRANS_MAX_COUNT_REMOTELY_POSITIVE_DEFAULT;
|
||||
max_size = GXSTRANS_MAX_SIZE_REMOTELY_POSITIVE_DEFAULT;
|
||||
break;
|
||||
case RsReputations::REPUTATION_LOCALLY_POSITIVE: max_count = GXSTRANS_MAX_COUNT_LOCALLY_POSITIVE_DEFAULT;
|
||||
case RsReputationLevel::LOCALLY_POSITIVE:
|
||||
max_count = GXSTRANS_MAX_COUNT_LOCALLY_POSITIVE_DEFAULT;
|
||||
max_size = GXSTRANS_MAX_SIZE_LOCALLY_POSITIVE_DEFAULT;
|
||||
break;
|
||||
case RsReputationLevel::LOCALLY_NEGATIVE: // fallthrough
|
||||
default:
|
||||
case RsReputations::REPUTATION_LOCALLY_NEGATIVE: max_count = 0 ;
|
||||
max_count = 0;
|
||||
max_size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
bool pgp_linked = identity_flags & RS_IDENTITY_FLAGS_PGP_LINKED;
|
||||
|
||||
if(rep_lev <= RsReputations::REPUTATION_NEUTRAL && !pgp_linked)
|
||||
if(rep_lev <= RsReputationLevel::NEUTRAL && !pgp_linked)
|
||||
{
|
||||
max_count /= 10 ;
|
||||
max_size /= 10 ;
|
||||
|
@ -754,6 +754,7 @@ SOURCES += serialiser/rsserializable.cc \
|
||||
|
||||
# Identity Service
|
||||
HEADERS += retroshare/rsidentity.h \
|
||||
retroshare/rsreputations.h \
|
||||
gxs/rsgixs.h \
|
||||
services/p3idservice.h \
|
||||
rsitems/rsgxsiditems.h \
|
||||
|
@ -42,7 +42,7 @@ class RsGxsChannels;
|
||||
*/
|
||||
extern RsGxsChannels* rsGxsChannels;
|
||||
|
||||
// These should be in rsgxscommon.h
|
||||
|
||||
struct RsGxsChannelGroup : RsSerializable
|
||||
{
|
||||
RsGroupMetaData mMeta;
|
||||
|
@ -3,7 +3,8 @@
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -19,34 +20,31 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RETROSHARE_GXSCIRCLES_INTERFACE_H
|
||||
#define RETROSHARE_GXSCIRCLES_INTERFACE_H
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
//typedef std::string RsGxsCircleId;
|
||||
//typedef RsPgpId RsPgpId;
|
||||
//typedef std::string RsCircleInternalId;
|
||||
|
||||
#include "retroshare/rstokenservice.h"
|
||||
#include "retroshare/rsgxsifacehelper.h"
|
||||
|
||||
#include "retroshare/rsidentity.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsGxsCircles;
|
||||
|
||||
/**
|
||||
* Pointer to global instance of RsGxsCircles service implementation
|
||||
* @jsonapi{development}
|
||||
*/
|
||||
extern RsGxsCircles* rsGxsCircles;
|
||||
|
||||
typedef RsPgpId RsPgpId;
|
||||
|
||||
// TODO: convert to enum
|
||||
/// The meaning of the different circle types is:
|
||||
/// TODO: convert to enum
|
||||
static const uint32_t GXS_CIRCLE_TYPE_UNKNOWN = 0x0000 ; /// Used to detect uninizialized values.
|
||||
static const uint32_t GXS_CIRCLE_TYPE_PUBLIC = 0x0001 ; // not restricted to a circle
|
||||
static const uint32_t GXS_CIRCLE_TYPE_EXTERNAL = 0x0002 ; // restricted to an external circle, made of RsGxsId
|
||||
@ -62,47 +60,58 @@ static const uint32_t GXS_EXTERNAL_CIRCLE_FLAGS_ALLOWED = 0x0007 ;// user
|
||||
|
||||
static const uint32_t GXS_CIRCLE_FLAGS_IS_EXTERNAL = 0x0008 ;// user is allowed
|
||||
|
||||
/* Permissions is part of GroupMetaData */
|
||||
|
||||
class GxsPermissions
|
||||
struct RsGxsCircleGroup : RsSerializable
|
||||
{
|
||||
public:
|
||||
uint32_t mCircleType; // PUBLIC, EXTERNAL or YOUREYESONLY.
|
||||
RsGxsCircleId mCircleId; // If EXTERNAL, otherwise Blank.
|
||||
virtual ~RsGxsCircleGroup() {}
|
||||
|
||||
// BELOW IS NOT SERIALISED - BUT MUST BE STORED LOCALLY BY GXS. (If YOUREYESONLY)
|
||||
RsPeerId mOriginator;
|
||||
RsGxsCircleId mInternalCircle; // if Originator == ownId, otherwise blank.
|
||||
};
|
||||
|
||||
class RsGxsCircleGroup
|
||||
{
|
||||
public:
|
||||
RsGroupMetaData mMeta; // includes GxsPermissions, for control of group distribution.
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
std::set<RsPgpId> mLocalFriends;
|
||||
std::set<RsGxsId> mInvitedMembers;
|
||||
std::set<RsGxsCircleId> mSubCircles;
|
||||
#ifdef V07_NON_BACKWARD_COMPATIBLE_CHANGE_UNNAMED
|
||||
# error "Add description, and multiple owners/administrators to circles"
|
||||
// or better in general to GXS groups
|
||||
#endif
|
||||
|
||||
// Not Serialised.
|
||||
// Internally inside rsCircles, this will be turned into:
|
||||
// std::list<RsPeerId> mAllowedFriends;
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mLocalFriends);
|
||||
RS_SERIAL_PROCESS(mInvitedMembers);
|
||||
RS_SERIAL_PROCESS(mSubCircles);
|
||||
}
|
||||
};
|
||||
|
||||
class RsGxsCircleMsg
|
||||
struct RsGxsCircleMsg : RsSerializable
|
||||
{
|
||||
public:
|
||||
virtual ~RsGxsCircleMsg() {}
|
||||
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
// Signature by user signifying that they want to be part of the group.
|
||||
// maybe Phase 3.
|
||||
#ifndef V07_NON_BACKWARD_COMPATIBLE_CHANGE_UNNAMED
|
||||
/* This is horrible and should be changed into yet to be defined something
|
||||
* reasonable in next non retrocompatible version */
|
||||
std::string stuff;
|
||||
#endif
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(stuff);
|
||||
}
|
||||
};
|
||||
|
||||
class RsGxsCircleDetails
|
||||
struct RsGxsCircleDetails : RsSerializable
|
||||
{
|
||||
public:
|
||||
RsGxsCircleDetails() : mCircleType(GXS_CIRCLE_TYPE_EXTERNAL), mAmIAllowed(false) {}
|
||||
RsGxsCircleDetails() :
|
||||
mCircleType(GXS_CIRCLE_TYPE_EXTERNAL), mAmIAllowed(false) {}
|
||||
~RsGxsCircleDetails() {}
|
||||
|
||||
RsGxsCircleId mCircleId;
|
||||
std::string mCircleName;
|
||||
@ -110,12 +119,30 @@ class RsGxsCircleDetails
|
||||
uint32_t mCircleType;
|
||||
RsGxsCircleId mRestrictedCircleId;
|
||||
|
||||
bool mAmIAllowed ; // true when one of load GXS ids belong to the circle allowed list (admin list & subscribed list).
|
||||
/** true when one of load GXS ids belong to the circle allowed list (admin
|
||||
* list & subscribed list). */
|
||||
bool mAmIAllowed;
|
||||
|
||||
std::set<RsGxsId> mAllowedGxsIds; // This crosses admin list and subscribed list
|
||||
/// This crosses admin list and subscribed list
|
||||
std::set<RsGxsId> mAllowedGxsIds;
|
||||
std::set<RsPgpId> mAllowedNodes;
|
||||
|
||||
std::map<RsGxsId,uint32_t> mSubscriptionFlags ; // subscription flags for all ids
|
||||
/// subscription flags for all ids
|
||||
std::map<RsGxsId,uint32_t> mSubscriptionFlags;
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mCircleId);
|
||||
RS_SERIAL_PROCESS(mCircleName);
|
||||
RS_SERIAL_PROCESS(mCircleType);
|
||||
RS_SERIAL_PROCESS(mRestrictedCircleId);
|
||||
RS_SERIAL_PROCESS(mAmIAllowed);
|
||||
RS_SERIAL_PROCESS(mAllowedGxsIds);
|
||||
RS_SERIAL_PROCESS(mAllowedNodes);
|
||||
RS_SERIAL_PROCESS(mSubscriptionFlags);
|
||||
}
|
||||
};
|
||||
|
||||
class RsGxsCircles: public RsGxsIfaceHelper
|
||||
@ -125,27 +152,115 @@ public:
|
||||
RsGxsCircles(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsCircles() {}
|
||||
|
||||
/* External Interface (Cached stuff) */
|
||||
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details) = 0;
|
||||
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds) = 0;
|
||||
virtual bool getCirclePersonalIdList(std::list<RsGxsCircleId> &circleIds) = 0;
|
||||
/**
|
||||
* @brief Create new circle
|
||||
* @jsonapi{development}
|
||||
* @param[inout] cData input name and flags of the circle, storage for
|
||||
* generated circle data id etc.
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool createCircle(RsGxsCircleGroup& cData) = 0;
|
||||
|
||||
/* membership management for external circles */
|
||||
/**
|
||||
* @brief Edit own existing circle
|
||||
* @jsonapi{development}
|
||||
* @param[inout] cData Circle data with modifications, storage for data
|
||||
* updatedad during the operation.
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool editCircle(RsGxsCircleGroup& cData) = 0;
|
||||
|
||||
virtual bool requestCircleMembership(const RsGxsId& own_gxsid,const RsGxsCircleId& circle_id)=0 ;
|
||||
virtual bool cancelCircleMembership(const RsGxsId& own_gxsid,const RsGxsCircleId& circle_id)=0 ;
|
||||
/**
|
||||
* @brief Get circle details. Memory cached
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the circle
|
||||
* @param[out] details Storage for the circle details
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getCircleDetails(
|
||||
const RsGxsCircleId& id, RsGxsCircleDetails& details ) = 0;
|
||||
|
||||
/* standard load */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups) = 0;
|
||||
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsCircleMsg> &msgs) = 0;
|
||||
/**
|
||||
* @brief Get list of known external circles ids. Memory cached
|
||||
* @jsonapi{development}
|
||||
* @param[in] circleIds Storage for circles id list
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getCircleExternalIdList(
|
||||
std::list<RsGxsCircleId>& circleIds ) = 0;
|
||||
|
||||
/* make new group */
|
||||
/**
|
||||
* @brief Get circles summaries list.
|
||||
* @jsonapi{development}
|
||||
* @param[out] circles list where to store the circles summaries
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getCirclesSummaries(std::list<RsGroupMetaData>& circles) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get circles information
|
||||
* @jsonapi{development}
|
||||
* @param[in] circlesIds ids of the circles of which to get the informations
|
||||
* @param[out] circlesInfo storage for the circles informations
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getCirclesInfo(
|
||||
const std::list<RsGxsGroupId>& circlesIds,
|
||||
std::vector<RsGxsCircleGroup>& circlesInfo ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get circle requests
|
||||
* @jsonapi{development}
|
||||
* @param[in] circleId id of the circle of which the requests are requested
|
||||
* @param[out] requests storage for the circle requests
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getCircleRequests( const RsGxsGroupId& circleId,
|
||||
std::vector<RsGxsCircleMsg>& requests ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Invite identities to circle
|
||||
* @jsonapi{development}
|
||||
* @param[in] identities ids of the identities to invite
|
||||
* @param[in] circleId Id of the circle you own and want to invite ids in
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool inviteIdsToCircle( const std::set<RsGxsId>& identities,
|
||||
const RsGxsCircleId& circleId ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Request circle membership, or accept circle invitation
|
||||
* @jsonapi{development}
|
||||
* @param[in] ownGxsId Id of own identity to introduce to the circle
|
||||
* @param[in] circleId Id of the circle to which ask for inclusion
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool requestCircleMembership(
|
||||
const RsGxsId& ownGxsId, const RsGxsCircleId& circleId ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Leave given circle
|
||||
* @jsonapi{development}
|
||||
* @param[in] ownGxsId Own id to remove from the circle
|
||||
* @param[in] circleId Id of the circle to leave
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool cancelCircleMembership(
|
||||
const RsGxsId& ownGxsId, const RsGxsCircleId& circleId ) = 0;
|
||||
|
||||
RS_DEPRECATED_FOR("getCirclesSummaries getCirclesInfo")
|
||||
virtual bool getGroupData(
|
||||
const uint32_t& token, std::vector<RsGxsCircleGroup>& groups ) = 0;
|
||||
|
||||
RS_DEPRECATED_FOR(getCirclesRequests)
|
||||
virtual bool getMsgData(
|
||||
const uint32_t& token, std::vector<RsGxsCircleMsg>& msgs ) = 0;
|
||||
|
||||
/// make new group
|
||||
RS_DEPRECATED_FOR(createCircle)
|
||||
virtual void createGroup(uint32_t& token, RsGxsCircleGroup &group) = 0;
|
||||
|
||||
/* update an existing group */
|
||||
/// update an existing group
|
||||
RS_DEPRECATED_FOR("editCircle, inviteIdsToCircle")
|
||||
virtual void updateGroup(uint32_t &token, RsGxsCircleGroup &group) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -217,7 +217,8 @@ struct RsGxsIface
|
||||
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;
|
||||
virtual RsReputationLevel minReputationForForwardingMessages(
|
||||
uint32_t group_sign_flags,uint32_t identity_flags ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -228,7 +228,8 @@ struct RsGxsIfaceHelper
|
||||
mGxs.setSyncPeriod(grpId,age_in_secs);
|
||||
}
|
||||
|
||||
RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags)
|
||||
RsReputationLevel minReputationForForwardingMessages(
|
||||
uint32_t group_sign_flags, uint32_t identity_flags )
|
||||
{
|
||||
return mGxs.minReputationForForwardingMessages(group_sign_flags,identity_flags);
|
||||
}
|
||||
|
@ -90,7 +90,9 @@ struct RsGroupMetaData : RsSerializable
|
||||
rstime_t mLastPost; // Timestamp for last message. Not used yet.
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
std::string mServiceString; // Service Specific Free-Form extra storage.
|
||||
|
||||
/// Service Specific Free-Form local (non-synced) extra storage.
|
||||
std::string mServiceString;
|
||||
RsPeerId mOriginator;
|
||||
RsGxsCircleId mInternalCircle;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -20,12 +20,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RETROSHARE_IDENTITY_GUI_INTERFACE_H
|
||||
#define RETROSHARE_IDENTITY_GUI_INTERFACE_H
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include "retroshare/rstokenservice.h"
|
||||
#include "retroshare/rsgxsifacehelper.h"
|
||||
@ -37,8 +37,12 @@
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
struct RsIdentity;
|
||||
|
||||
/**
|
||||
* Pointer to global instance of RsIdentity service implementation
|
||||
* @jsonapi{development}
|
||||
*/
|
||||
extern RsIdentity* rsIdentity;
|
||||
|
||||
|
||||
@ -106,7 +110,7 @@ struct RsGxsIdGroup : RsSerializable
|
||||
{
|
||||
RsGxsIdGroup() :
|
||||
mLastUsageTS(0), mPgpKnown(false), mIsAContact(false) {}
|
||||
~RsGxsIdGroup() {}
|
||||
virtual ~RsGxsIdGroup() {}
|
||||
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
@ -144,18 +148,18 @@ struct RsGxsIdGroup : RsSerializable
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx );
|
||||
RsGenericSerializer::SerializeContext& ctx ) override;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &group);
|
||||
|
||||
// DATA TYPE FOR EXTERNAL INTERFACE.
|
||||
|
||||
class RsRecognTag
|
||||
struct RsRecognTag
|
||||
{
|
||||
public:
|
||||
RsRecognTag(uint16_t tc, uint16_t tt, bool v)
|
||||
:tag_class(tc), tag_type(tt), valid(v) { return; }
|
||||
RsRecognTag(uint16_t tc, uint16_t tt, bool v) :
|
||||
tag_class(tc), tag_type(tt), valid(v) {}
|
||||
|
||||
uint16_t tag_class;
|
||||
uint16_t tag_type;
|
||||
bool valid;
|
||||
@ -272,7 +276,7 @@ struct RsIdentityUsage : RsSerializable
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mServiceId);
|
||||
RS_SERIAL_PROCESS(mUsageCode);
|
||||
@ -311,7 +315,7 @@ struct RsIdentityDetails : RsSerializable
|
||||
* reputation system is not finished yet, I leave this in place. We should
|
||||
* decide what to do with it.
|
||||
*/
|
||||
RsReputations::ReputationInfo mReputation;
|
||||
RsReputationInfo mReputation;
|
||||
|
||||
RsGxsImage mAvatar;
|
||||
|
||||
@ -329,7 +333,7 @@ struct RsIdentityDetails : RsSerializable
|
||||
RS_SERIAL_PROCESS(mFlags);
|
||||
RS_SERIAL_PROCESS(mPgpId);
|
||||
//RS_SERIAL_PROCESS(mReputation);
|
||||
//RS_SERIAL_PROCESS(mAvatar);
|
||||
RS_SERIAL_PROCESS(mAvatar);
|
||||
RS_SERIAL_PROCESS(mPublishTS);
|
||||
RS_SERIAL_PROCESS(mLastUsageTS);
|
||||
RS_SERIAL_PROCESS(mUseCases);
|
||||
@ -338,73 +342,214 @@ struct RsIdentityDetails : RsSerializable
|
||||
|
||||
|
||||
|
||||
|
||||
/** The Main Interface Class for GXS people identities */
|
||||
struct RsIdentity : RsGxsIfaceHelper
|
||||
{
|
||||
explicit RsIdentity(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsIdentity() {}
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
/**
|
||||
* @brief Create a new identity
|
||||
* @jsonapi{development}
|
||||
* @param[out] id storage for the created identity Id
|
||||
* @param[in] name Name of the identity
|
||||
* @param[in] avatar Image associated to the identity
|
||||
* @param[in] pseudonimous true for unsigned identity, false otherwise
|
||||
* @param[in] pgpPassword password to unlock PGP to sign identity,
|
||||
* not implemented yet
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool createIdentity(
|
||||
RsGxsId& id,
|
||||
const std::string& name, const RsGxsImage& avatar = RsGxsImage(),
|
||||
bool pseudonimous = true, const std::string& pgpPassword = "" ) = 0;
|
||||
|
||||
// For Other Services....
|
||||
// It should be impossible for them to get a message which we don't have the identity.
|
||||
// Its a major error if we don't have the identity.
|
||||
/**
|
||||
* @brief Locally delete given identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool deleteIdentity(RsGxsId& id) = 0;
|
||||
|
||||
// We cache all identities, and provide alternative (instantaneous)
|
||||
// functions to extract info, rather than the standard Token system.
|
||||
/**
|
||||
* @brief Update identity data (name, avatar...)
|
||||
* @jsonapi{development}
|
||||
* @param[in] identityData updated identiy data
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool updateIdentity(RsGxsIdGroup& identityData) = 0;
|
||||
|
||||
//virtual bool getNickname(const RsGxsId &id, std::string &nickname) = 0;
|
||||
/**
|
||||
* @brief Get identity details, from the cache
|
||||
* @param[in] id Id of the identity
|
||||
* @param[out] details Storage for the identity details
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getIdDetails(const RsGxsId& id, RsIdentityDetails& details) = 0;
|
||||
|
||||
// Fills up list of all own ids. Returns false if ids are not yet loaded.
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds,bool only_signed_ids = false) = 0;
|
||||
virtual bool isOwnId(const RsGxsId& id) = 0;
|
||||
|
||||
//
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score) = 0;
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms) = 0;
|
||||
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
|
||||
virtual void setDeleteBannedNodesThreshold(uint32_t days) =0;
|
||||
virtual uint32_t deleteBannedNodesThreshold() =0;
|
||||
|
||||
virtual bool parseRecognTag(const RsGxsId &id, const std::string &nickname,
|
||||
const std::string &tag, RsRecognTagDetails &details) = 0;
|
||||
virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
||||
uint16_t tag_class, uint16_t tag_type, std::string &tag) = 0;
|
||||
|
||||
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) = 0 ;
|
||||
virtual bool isARegularContact(const RsGxsId& id) = 0 ;
|
||||
virtual uint32_t nbRegularContacts() =0;
|
||||
virtual void setAutoAddFriendIdsAsContact(bool b) =0;
|
||||
virtual bool autoAddFriendIdsAsContact() =0;
|
||||
|
||||
virtual bool serialiseIdentityToMemory( const RsGxsId& id,
|
||||
std::string& radix_string ) = 0;
|
||||
virtual bool deserialiseIdentityFromMemory( const std::string& radix_string,
|
||||
RsGxsId* id = nullptr ) = 0;
|
||||
|
||||
/*!
|
||||
* \brief overallReputationLevel
|
||||
* Returns the overall reputation level of the supplied identity. See rsreputations.h
|
||||
* \param id
|
||||
* \return
|
||||
/**
|
||||
* @brief Get last seen usage time of given identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @return timestamp of last seen usage
|
||||
*/
|
||||
virtual rstime_t getLastUsageTS(const RsGxsId& id) = 0;
|
||||
|
||||
// Specific RsIdentity Functions....
|
||||
/* Specific Service Data */
|
||||
/* We expose these initially for testing / GUI purposes.
|
||||
/**
|
||||
* @brief Get own signed ids
|
||||
* @jsonapi{development}
|
||||
* @param[out] ids storage for the ids
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getOwnSignedIds(std::vector<RsGxsId> ids) = 0;
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
|
||||
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups)=0;
|
||||
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
|
||||
/**
|
||||
* @brief Get own pseudonimous (unsigned) ids
|
||||
* @jsonapi{development}
|
||||
* @param[out] ids storage for the ids
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if an id is own
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id to check
|
||||
* @return true if the id is own, false otherwise
|
||||
*/
|
||||
virtual bool isOwnId(const RsGxsId& id) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get base64 representation of an identity
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @param[out] base64String storage for the identity base64
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool identityToBase64( const RsGxsId& id,
|
||||
std::string& base64String ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Import identity from base64 representation
|
||||
* @jsonapi{development}
|
||||
* @param[in] base64String base64 representation of the identity to import
|
||||
* @param[out] id storage for the identity id
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool identityFromBase64( const std::string& base64String,
|
||||
RsGxsId& id ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get identities summaries list.
|
||||
* @jsonapi{development}
|
||||
* @param[out] ids list where to store the identities
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getIdentitiesSummaries(std::list<RsGroupMetaData>& ids) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get identities information (name, avatar...).
|
||||
* Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[in] ids ids of the channels of which to get the informations
|
||||
* @param[out] idsInfo storage for the identities informations
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getIdentitiesInfo(
|
||||
const std::set<RsGxsId>& ids,
|
||||
std::vector<RsGxsIdGroup>& idsInfo ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if an identity is contact
|
||||
* @jsonapi{development}
|
||||
* @param[in] id Id of the identity
|
||||
* @return true if it is a conctact, false otherwise
|
||||
*/
|
||||
virtual bool isARegularContact(const RsGxsId& id) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set/unset identity as contact
|
||||
* @param[in] id Id of the identity
|
||||
* @param[in] isContact true to set, false to unset
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool setAsRegularContact(const RsGxsId& id, bool isContact) = 0;
|
||||
|
||||
/**
|
||||
* @brief Toggle automatic flagging signed by friends identity as contact
|
||||
* @jsonapi{development}
|
||||
* @param[in] enabled true to enable, false to disable
|
||||
*/
|
||||
virtual void setAutoAddFriendIdsAsContact(bool enabled) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if automatic signed by friend identity contact flagging is
|
||||
* enabled
|
||||
* @jsonapi{development}
|
||||
* @return true if enabled, false otherwise
|
||||
*/
|
||||
virtual bool autoAddFriendIdsAsContact() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get number of days after which delete a banned identities
|
||||
* @jsonapi{development}
|
||||
* @return number of days
|
||||
*/
|
||||
virtual uint32_t deleteBannedNodesThreshold() = 0;
|
||||
|
||||
/**
|
||||
* @brief Set number of days after which delete a banned identities
|
||||
* @jsonapi{development}
|
||||
* @param[in] days number of days
|
||||
*/
|
||||
virtual void setDeleteBannedNodesThreshold(uint32_t days) = 0;
|
||||
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool getGroupSerializedData(
|
||||
const uint32_t& token,
|
||||
std::map<RsGxsId,std::string>& serialized_groups ) = 0;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool parseRecognTag(
|
||||
const RsGxsId &id, const std::string& nickname,
|
||||
const std::string& tag, RsRecognTagDetails& details) = 0;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool getRecognTagRequest(
|
||||
const RsGxsId& id, const std::string& comment, uint16_t tag_class,
|
||||
uint16_t tag_type, std::string& tag) = 0;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual uint32_t nbRegularContacts() =0;
|
||||
|
||||
RS_DEPRECATED_FOR(identityToBase64)
|
||||
virtual bool serialiseIdentityToMemory( const RsGxsId& id,
|
||||
std::string& radix_string ) = 0;
|
||||
RS_DEPRECATED_FOR(identityFromBase64)
|
||||
virtual bool deserialiseIdentityFromMemory( const std::string& radix_string,
|
||||
RsGxsId* id = nullptr ) = 0;
|
||||
|
||||
/// Fills up list of all own ids. Returns false if ids are not yet loaded.
|
||||
RS_DEPRECATED_FOR("getOwnSignedIds getOwnPseudonimousIds")
|
||||
virtual bool getOwnIds( std::list<RsGxsId> &ownIds,
|
||||
bool only_signed_ids = false ) = 0;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms) = 0;
|
||||
|
||||
RS_DEPRECATED_FOR(RsReputations)
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score) = 0;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group) = 0;
|
||||
|
||||
RS_DEPRECATED_FOR("getIdentitiesSummaries getIdentitiesInfo")
|
||||
virtual bool getGroupData( const uint32_t& token,
|
||||
std::vector<RsGxsIdGroup>& groups) = 0;
|
||||
};
|
||||
|
||||
#endif // RETROSHARE_IDENTITY_GUI_INTERFACE_H
|
||||
|
@ -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 *
|
||||
@ -19,74 +20,225 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "retroshare/rsids.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
|
||||
class RsReputations
|
||||
class RsReputations;
|
||||
|
||||
/**
|
||||
* Pointer to global instance of RsReputations service implementation
|
||||
* @jsonapi{development}
|
||||
*/
|
||||
extern RsReputations* rsReputations;
|
||||
|
||||
|
||||
constexpr float RS_REPUTATION_THRESHOLD_DEFAULT = 1.0f;
|
||||
|
||||
enum struct RsOpinion : uint8_t
|
||||
{
|
||||
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 } ;
|
||||
|
||||
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
|
||||
NEGATIVE = 0,
|
||||
NEUTRAL = 1,
|
||||
POSITIVE = 2
|
||||
};
|
||||
|
||||
struct ReputationInfo
|
||||
enum struct RsReputationLevel : uint8_t
|
||||
{
|
||||
ReputationInfo() : mOwnOpinion(OPINION_NEUTRAL),mFriendsPositiveVotes(0),mFriendsNegativeVotes(0), mFriendAverageScore(REPUTATION_THRESHOLD_DEFAULT),mOverallReputationLevel(REPUTATION_NEUTRAL){}
|
||||
/// local opinion is negative
|
||||
LOCALLY_NEGATIVE = 0x00,
|
||||
|
||||
RsReputations::Opinion mOwnOpinion ;
|
||||
/// 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 : RsSerializable
|
||||
{
|
||||
RsReputationInfo() :
|
||||
mOwnOpinion(RsOpinion::NEUTRAL), mFriendsPositiveVotes(0),
|
||||
mFriendsNegativeVotes(0),
|
||||
mFriendAverageScore(RS_REPUTATION_THRESHOLD_DEFAULT),
|
||||
mOverallReputationLevel(RsReputationLevel::NEUTRAL) {}
|
||||
virtual ~RsReputationInfo() {}
|
||||
|
||||
RsOpinion mOwnOpinion;
|
||||
|
||||
uint32_t mFriendsPositiveVotes;
|
||||
uint32_t mFriendsNegativeVotes;
|
||||
|
||||
float mFriendAverageScore;
|
||||
|
||||
RsReputations::ReputationLevel mOverallReputationLevel; // this should help clients in taking decisions
|
||||
/// 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);
|
||||
}
|
||||
};
|
||||
|
||||
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 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
|
||||
class RsReputations
|
||||
{
|
||||
public:
|
||||
virtual ~RsReputations() {}
|
||||
|
||||
virtual ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL)=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;
|
||||
|
||||
// parameters
|
||||
/**
|
||||
* @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;
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) =0;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() =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;
|
||||
|
||||
virtual uint32_t thresholdForRemotelyNegativeReputation()=0;
|
||||
virtual uint32_t thresholdForRemotelyPositiveReputation()=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;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
virtual void banNode(const RsPgpId& id,bool b) =0;
|
||||
};
|
||||
|
||||
// To access reputations from anywhere
|
||||
//
|
||||
extern RsReputations *rsReputations ;
|
||||
/**
|
||||
* @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;
|
||||
};
|
||||
|
@ -100,7 +100,7 @@ class RsGxsReputationSetItem: public RsReputationItem
|
||||
public:
|
||||
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM)
|
||||
{
|
||||
mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
|
||||
mOwnOpinion = static_cast<uint32_t>(RsOpinion::NEUTRAL);
|
||||
mOwnOpinionTS = 0;
|
||||
mIdentityFlags = 0;
|
||||
mLastUsedTS = 0;
|
||||
|
@ -153,7 +153,118 @@ RsServiceInfo p3GxsCircles::getServiceInfo()
|
||||
GXS_CIRCLES_MIN_MINOR_VERSION);
|
||||
}
|
||||
|
||||
bool p3GxsCircles::createCircle(RsGxsCircleGroup& cData)
|
||||
{
|
||||
uint32_t token;
|
||||
createGroup(token, cData);
|
||||
|
||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!RsGenExchange::getPublishedGroupMeta(token, cData.mMeta))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting created"
|
||||
<< " group data." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsCircles::editCircle(RsGxsCircleGroup& cData)
|
||||
{
|
||||
uint32_t token;
|
||||
updateGroup(token, cData);
|
||||
|
||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!RsGenExchange::getPublishedGroupMeta(token, cData.mMeta))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated"
|
||||
<< " group data." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsCircles::getCirclesSummaries(std::list<RsGroupMetaData>& circles)
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
if( !requestGroupInfo(token, opts)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
return getGroupSummary(token, circles);
|
||||
}
|
||||
|
||||
bool p3GxsCircles::getCirclesInfo( const std::list<RsGxsGroupId>& circlesIds,
|
||||
std::vector<RsGxsCircleGroup>& circlesInfo )
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
if( !requestGroupInfo(token, opts, circlesIds)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
return getGroupData(token, circlesInfo);
|
||||
}
|
||||
|
||||
bool p3GxsCircles::getCircleRequests( const RsGxsGroupId& circleId,
|
||||
std::vector<RsGxsCircleMsg>& requests )
|
||||
{
|
||||
uint32_t token;
|
||||
std::list<RsGxsGroupId> grpIds { circleId };
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
|
||||
if( !requestMsgInfo(token, opts, grpIds) ||
|
||||
waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
|
||||
return getMsgData(token, requests);
|
||||
}
|
||||
|
||||
bool p3GxsCircles::inviteIdsToCircle( const std::set<RsGxsId>& identities,
|
||||
const RsGxsCircleId& circleId )
|
||||
{
|
||||
const std::list<RsGxsGroupId> circlesIds{ RsGxsGroupId(circleId) };
|
||||
std::vector<RsGxsCircleGroup> circlesInfo;
|
||||
|
||||
if(!getCirclesInfo(circlesIds, circlesInfo))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting group data."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circlesInfo.empty())
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Circle: "
|
||||
<< circleId.toStdString() << " not found!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsGxsCircleGroup& circleGrp = circlesInfo[0];
|
||||
|
||||
if(!(circleGrp.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Attempt to edit non-own "
|
||||
<< "circle: " << circleId.toStdString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
circleGrp.mInvitedMembers.insert(identities.begin(), identities.end());
|
||||
|
||||
return editCircle(circleGrp);
|
||||
}
|
||||
|
||||
uint32_t p3GxsCircles::circleAuthenPolicy()
|
||||
{
|
||||
@ -320,32 +431,6 @@ bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool p3GxsCircles:: getCirclePersonalIdList(std::list<RsGxsCircleId> &circleIds)
|
||||
{
|
||||
#ifdef DEBUG_CIRCLES
|
||||
std::cerr << "p3GxsCircles::getCircleIdList()";
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
if (circleIds.empty())
|
||||
{
|
||||
circleIds = mCirclePersonalIdList;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::list<RsGxsCircleId>::const_iterator it;
|
||||
for(it = mCirclePersonalIdList.begin(); it != mCirclePersonalIdList.begin(); ++it)
|
||||
{
|
||||
circleIds.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3GxsCircles:: getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds)
|
||||
{
|
||||
#ifdef DEBUG_CIRCLES
|
||||
|
@ -179,9 +179,30 @@ virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
/*********** External Interface ***************/
|
||||
|
||||
/// @see RsGxsCircles
|
||||
bool createCircle(RsGxsCircleGroup& cData) override;
|
||||
|
||||
/// @see RsGxsCircles
|
||||
bool editCircle(RsGxsCircleGroup& cData) override;
|
||||
|
||||
/// @see RsGxsCircles
|
||||
bool getCirclesSummaries(std::list<RsGroupMetaData>& circles) override;
|
||||
|
||||
/// @see RsGxsCircles
|
||||
bool getCirclesInfo(
|
||||
const std::list<RsGxsGroupId>& circlesIds,
|
||||
std::vector<RsGxsCircleGroup>& circlesInfo ) override;
|
||||
|
||||
/// @see RsGxsCircles
|
||||
bool getCircleRequests( const RsGxsGroupId& circleId,
|
||||
std::vector<RsGxsCircleMsg>& requests ) override;
|
||||
|
||||
/// @see RsGxsCircles
|
||||
bool inviteIdsToCircle( const std::set<RsGxsId>& identities,
|
||||
const RsGxsCircleId& circleId ) override;
|
||||
|
||||
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details);
|
||||
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds);
|
||||
virtual bool getCirclePersonalIdList(std::list<RsGxsCircleId> &circleIds);
|
||||
|
||||
virtual bool isLoaded(const RsGxsCircleId &circleId);
|
||||
virtual bool loadCircle(const RsGxsCircleId &circleId);
|
||||
@ -257,6 +278,8 @@ virtual RsServiceInfo getServiceInfo();
|
||||
// put a circle id into the external or personal circle id list
|
||||
// this function locks the mutex
|
||||
// if the id is already in the list, it will not be added again
|
||||
// G10h4ck: this is terrible, an std::set instead of a list should be used
|
||||
// to guarantee uniqueness
|
||||
void addCircleIdToList(const RsGxsCircleId& circleId, uint32_t circleType);
|
||||
|
||||
RsMutex mCircleMtx; /* Locked Below Here */
|
||||
|
@ -236,7 +236,7 @@ int p3GxsReputation::tick()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void p3GxsReputation::setNodeAutoPositiveOpinionForContacts(bool b)
|
||||
void p3GxsReputation::setAutoPositiveOpinionForContacts(bool b)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
@ -249,13 +249,13 @@ void p3GxsReputation::setNodeAutoPositiveOpinionForContacts(bool b)
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
}
|
||||
bool p3GxsReputation::nodeAutoPositiveOpinionForContacts()
|
||||
bool p3GxsReputation::autoPositiveOpinionForContacts()
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
return mAutoSetPositiveOptionToContacts ;
|
||||
}
|
||||
|
||||
void p3GxsReputation::setRememberDeletedNodesThreshold(uint32_t days)
|
||||
void p3GxsReputation::setRememberBannedIdThreshold(uint32_t days)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
@ -265,7 +265,7 @@ void p3GxsReputation::setRememberDeletedNodesThreshold(uint32_t days)
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
uint32_t p3GxsReputation::rememberDeletedNodesThreshold()
|
||||
uint32_t p3GxsReputation::rememberBannedIdThreshold()
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
@ -382,7 +382,10 @@ void p3GxsReputation::cleanup()
|
||||
{
|
||||
bool should_delete = false ;
|
||||
|
||||
if(it->second.mOwnOpinion == RsReputations::OPINION_NEGATIVE && mMaxPreventReloadBannedIds != 0 && it->second.mOwnOpinionTs + mMaxPreventReloadBannedIds < now)
|
||||
if( it->second.mOwnOpinion ==
|
||||
static_cast<int32_t>(RsOpinion::NEGATIVE) &&
|
||||
mMaxPreventReloadBannedIds != 0 &&
|
||||
it->second.mOwnOpinionTs + mMaxPreventReloadBannedIds < now )
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " ID " << it->first << ": own is negative for more than " << mMaxPreventReloadBannedIds/86400 << " days. Reseting it!" << std::endl;
|
||||
@ -392,7 +395,10 @@ void p3GxsReputation::cleanup()
|
||||
|
||||
// Delete slots with basically no information
|
||||
|
||||
if(it->second.mOpinions.empty() && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL && (it->second.mOwnerNode.isNull()))
|
||||
if( it->second.mOpinions.empty() &&
|
||||
it->second.mOwnOpinion ==
|
||||
static_cast<int32_t>(RsOpinion::NEUTRAL) &&
|
||||
it->second.mOwnerNode.isNull() )
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " ID " << it->first << ": own is neutral and no opinions from friends => remove entry" << std::endl;
|
||||
@ -461,23 +467,20 @@ void p3GxsReputation::cleanup()
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();++it)
|
||||
if(it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
|
||||
if( it->second.mOwnOpinion ==
|
||||
static_cast<int32_t>(RsOpinion::NEUTRAL) )
|
||||
should_set_to_positive_candidates.push_back(it->first) ;
|
||||
}
|
||||
|
||||
for(std::list<RsGxsId>::const_iterator it(should_set_to_positive_candidates.begin());it!=should_set_to_positive_candidates.end();++it)
|
||||
if(rsIdentity->isARegularContact(*it))
|
||||
setOwnOpinion(*it,RsReputations::OPINION_POSITIVE) ;
|
||||
setOwnOpinion(*it, RsOpinion::POSITIVE);
|
||||
}
|
||||
}
|
||||
|
||||
const float RsReputations::REPUTATION_THRESHOLD_ANTI_SPAM = 1.4f ;
|
||||
const float RsReputations::REPUTATION_THRESHOLD_DEFAULT = 1.0f ;
|
||||
|
||||
|
||||
static RsReputations::Opinion safe_convert_uint32t_to_opinion(uint32_t op)
|
||||
static RsOpinion safe_convert_uint32t_to_opinion(uint32_t op)
|
||||
{
|
||||
return RsReputations::Opinion(std::min((uint32_t)op,UPPER_LIMIT)) ;
|
||||
return RsOpinion(std::min( static_cast<uint32_t>(op), UPPER_LIMIT ));
|
||||
}
|
||||
/***** Implementation ******/
|
||||
|
||||
@ -631,13 +634,14 @@ bool p3GxsReputation::SendReputations(RsGxsReputationRequestItem *request)
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& about,RsReputations::Opinion op)
|
||||
void p3GxsReputation::locked_updateOpinion(
|
||||
const RsPeerId& from, const RsGxsId& about, RsOpinion op )
|
||||
{
|
||||
/* find matching Reputation */
|
||||
std::map<RsGxsId, Reputation>::iterator rit = mReputations.find(about);
|
||||
|
||||
RsReputations::Opinion new_opinion = safe_convert_uint32t_to_opinion(op);
|
||||
RsReputations::Opinion old_opinion = RsReputations::OPINION_NEUTRAL ; // default if not set
|
||||
RsOpinion new_opinion = op;
|
||||
RsOpinion old_opinion = RsOpinion::NEUTRAL ; // default if not set
|
||||
|
||||
bool updated = false ;
|
||||
|
||||
@ -658,9 +662,9 @@ void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& a
|
||||
std::cerr << " no preview record"<< std::endl;
|
||||
#endif
|
||||
|
||||
if(new_opinion != RsReputations::OPINION_NEUTRAL)
|
||||
if(new_opinion != RsOpinion::NEUTRAL)
|
||||
{
|
||||
mReputations[about] = Reputation(about);
|
||||
mReputations[about] = Reputation();
|
||||
rit = mReputations.find(about);
|
||||
}
|
||||
else
|
||||
@ -674,11 +678,11 @@ void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& a
|
||||
|
||||
Reputation& reputation = rit->second;
|
||||
|
||||
std::map<RsPeerId,RsReputations::Opinion>::iterator it2 = reputation.mOpinions.find(from) ;
|
||||
std::map<RsPeerId,RsOpinion>::iterator it2 = reputation.mOpinions.find(from) ;
|
||||
|
||||
if(it2 == reputation.mOpinions.end())
|
||||
{
|
||||
if(new_opinion != RsReputations::OPINION_NEUTRAL)
|
||||
if(new_opinion != RsOpinion::NEUTRAL)
|
||||
{
|
||||
reputation.mOpinions[from] = new_opinion; // filters potentially tweaked reputation score sent by friend
|
||||
updated = true ;
|
||||
@ -688,7 +692,7 @@ void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& a
|
||||
{
|
||||
old_opinion = it2->second ;
|
||||
|
||||
if(new_opinion == RsReputations::OPINION_NEUTRAL)
|
||||
if(new_opinion == RsOpinion::NEUTRAL)
|
||||
{
|
||||
reputation.mOpinions.erase(it2) ; // don't store when the opinion is neutral
|
||||
updated = true ;
|
||||
@ -700,7 +704,8 @@ void p3GxsReputation::locked_updateOpinion(const RsPeerId& from,const RsGxsId& a
|
||||
}
|
||||
}
|
||||
|
||||
if(reputation.mOpinions.empty() && reputation.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
|
||||
if( reputation.mOpinions.empty() &&
|
||||
reputation.mOwnOpinion == static_cast<int32_t>(RsOpinion::NEUTRAL) )
|
||||
{
|
||||
mReputations.erase(rit) ;
|
||||
#ifdef DEBUG_REPUTATION
|
||||
@ -766,9 +771,10 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,rstime_t latest_update)
|
||||
* Opinion
|
||||
****/
|
||||
|
||||
RsReputations::ReputationLevel p3GxsReputation::overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags)
|
||||
RsReputationLevel p3GxsReputation::overallReputationLevel(
|
||||
const RsGxsId& id, uint32_t* identity_flags )
|
||||
{
|
||||
ReputationInfo info ;
|
||||
RsReputationInfo info ;
|
||||
getReputationInfo(id,RsPgpId(),info) ;
|
||||
|
||||
RsPgpId owner_id ;
|
||||
@ -805,12 +811,14 @@ bool p3GxsReputation::getIdentityFlagsAndOwnerId(const RsGxsId& gxsid, uint32_t&
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputations::ReputationInfo& info, bool stamp)
|
||||
bool p3GxsReputation::getReputationInfo(
|
||||
const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputationInfo& info,
|
||||
bool stamp )
|
||||
{
|
||||
if(gxsid.isNull())
|
||||
return false ;
|
||||
|
||||
rstime_t now = time(NULL) ;
|
||||
rstime_t now = time(nullptr);
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
@ -822,8 +830,8 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
|
||||
if(it == mReputations.end())
|
||||
{
|
||||
info.mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
|
||||
info.mFriendAverageScore = REPUTATION_THRESHOLD_DEFAULT ;
|
||||
info.mOwnOpinion = RsOpinion::NEUTRAL ;
|
||||
info.mFriendAverageScore = RS_REPUTATION_THRESHOLD_DEFAULT ;
|
||||
info.mFriendsNegativeVotes = 0 ;
|
||||
info.mFriendsPositiveVotes = 0 ;
|
||||
|
||||
@ -833,7 +841,9 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
{
|
||||
Reputation& rep(it->second) ;
|
||||
|
||||
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
|
||||
info.mOwnOpinion =
|
||||
safe_convert_uint32t_to_opinion(
|
||||
static_cast<uint32_t>(rep.mOwnOpinion) );
|
||||
info.mFriendAverageScore = rep.mFriendAverage ;
|
||||
info.mFriendsNegativeVotes = rep.mFriendsNegative ;
|
||||
info.mFriendsPositiveVotes = rep.mFriendsPositive ;
|
||||
@ -853,18 +863,18 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
|
||||
// 0 - check for own opinion. If positive or negative, it decides on the result
|
||||
|
||||
if(info.mOwnOpinion == RsReputations::OPINION_NEGATIVE)
|
||||
if(info.mOwnOpinion == RsOpinion::NEGATIVE)
|
||||
{
|
||||
// own opinion is always read in priority
|
||||
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_LOCALLY_NEGATIVE ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::LOCALLY_NEGATIVE;
|
||||
return true ;
|
||||
}
|
||||
if(info.mOwnOpinion == RsReputations::OPINION_POSITIVE)
|
||||
if(info.mOwnOpinion == RsOpinion::POSITIVE)
|
||||
{
|
||||
// own opinion is always read in priority
|
||||
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_LOCALLY_POSITIVE ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::LOCALLY_POSITIVE;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -889,7 +899,7 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned (found in banned nodes list)." << std::endl;
|
||||
#endif
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_LOCALLY_NEGATIVE ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::LOCALLY_NEGATIVE;
|
||||
return true ;
|
||||
}
|
||||
// also check the proxy
|
||||
@ -899,17 +909,17 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned (found in proxy)." << std::endl;
|
||||
#endif
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_LOCALLY_NEGATIVE ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::LOCALLY_NEGATIVE;
|
||||
return true;
|
||||
}
|
||||
// 2 - now, our own opinion is neutral, which means we rely on what our friends tell
|
||||
|
||||
if(info.mFriendsPositiveVotes >= info.mFriendsNegativeVotes + mMinVotesForRemotelyPositive)
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_REMOTELY_POSITIVE ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::REMOTELY_POSITIVE;
|
||||
else if(info.mFriendsPositiveVotes + mMinVotesForRemotelyNegative <= info.mFriendsNegativeVotes)
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_REMOTELY_NEGATIVE ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::REMOTELY_NEGATIVE;
|
||||
else
|
||||
info.mOverallReputationLevel = RsReputations::REPUTATION_NEUTRAL ;
|
||||
info.mOverallReputationLevel = RsReputationLevel::NEUTRAL;
|
||||
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", owner node=" << owner_id << ", overall score=" << info.mAssessment << std::endl;
|
||||
@ -969,6 +979,10 @@ void p3GxsReputation::banNode(const RsPgpId& id,bool b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RsReputationLevel p3GxsReputation::overallReputationLevel(const RsGxsId& id)
|
||||
{ return overallReputationLevel(id, nullptr); }
|
||||
|
||||
bool p3GxsReputation::isNodeBanned(const RsPgpId& id)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
@ -978,7 +992,7 @@ bool p3GxsReputation::isNodeBanned(const RsPgpId& id)
|
||||
|
||||
bool p3GxsReputation::isIdentityBanned(const RsGxsId &id)
|
||||
{
|
||||
RsReputations::ReputationInfo info ;
|
||||
RsReputationInfo info;
|
||||
|
||||
if(!getReputationInfo(id,RsPgpId(),info))
|
||||
return false ;
|
||||
@ -986,10 +1000,11 @@ bool p3GxsReputation::isIdentityBanned(const RsGxsId &id)
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "isIdentityBanned(): returning " << (info.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE) << " for GXS id " << id << std::endl;
|
||||
#endif
|
||||
return info.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE ;
|
||||
return info.mOverallReputationLevel == RsReputationLevel::LOCALLY_NEGATIVE;
|
||||
}
|
||||
|
||||
bool p3GxsReputation::getOwnOpinion(const RsGxsId& gxsid, RsReputations::Opinion& opinion)
|
||||
bool p3GxsReputation::getOwnOpinion(
|
||||
const RsGxsId& gxsid, RsOpinion& opinion )
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "setOwnOpinion(): for GXS id " << gxsid << " to " << opinion << std::endl;
|
||||
@ -1000,19 +1015,21 @@ bool p3GxsReputation::getOwnOpinion(const RsGxsId& gxsid, RsReputations::Opinion
|
||||
return false ;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
RS_STACK_MUTEX(mReputationMtx);
|
||||
|
||||
std::map<RsGxsId, Reputation>::iterator rit = mReputations.find(gxsid);
|
||||
|
||||
if(rit != mReputations.end())
|
||||
opinion = RsReputations::Opinion(rit->second.mOwnOpinion) ;
|
||||
opinion = safe_convert_uint32t_to_opinion(
|
||||
static_cast<uint32_t>(rit->second.mOwnOpinion) );
|
||||
else
|
||||
opinion = RsReputations::OPINION_NEUTRAL ;
|
||||
opinion = RsOpinion::NEUTRAL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::Opinion& opinion)
|
||||
bool p3GxsReputation::setOwnOpinion(
|
||||
const RsGxsId& gxsid, RsOpinion opinion )
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "setOwnOpinion(): for GXS id " << gxsid << " to " << opinion << std::endl;
|
||||
@ -1023,7 +1040,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
|
||||
return false ;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
RS_STACK_MUTEX(mReputationMtx);
|
||||
|
||||
std::map<RsGxsId, Reputation>::iterator rit;
|
||||
|
||||
@ -1033,7 +1050,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
|
||||
if (rit == mReputations.end())
|
||||
{
|
||||
#warning csoler 2017-01-05: We should set the owner node id here.
|
||||
mReputations[gxsid] = Reputation(gxsid);
|
||||
mReputations[gxsid] = Reputation();
|
||||
rit = mReputations.find(gxsid);
|
||||
}
|
||||
|
||||
@ -1041,7 +1058,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
|
||||
Reputation &reputation = rit->second;
|
||||
if (reputation.mOwnOpinionTs != 0)
|
||||
{
|
||||
if (reputation.mOwnOpinion == opinion)
|
||||
if (reputation.mOwnOpinion == static_cast<int32_t>(opinion))
|
||||
{
|
||||
// if opinion is accurate, don't update.
|
||||
return false;
|
||||
@ -1060,8 +1077,8 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
|
||||
}
|
||||
}
|
||||
|
||||
rstime_t now = time(NULL);
|
||||
reputation.mOwnOpinion = opinion;
|
||||
rstime_t now = time(nullptr);
|
||||
reputation.mOwnOpinion = static_cast<int32_t>(opinion);
|
||||
reputation.mOwnOpinionTs = now;
|
||||
reputation.updateReputation();
|
||||
|
||||
@ -1126,7 +1143,7 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
||||
item->mOwnerNodeId = rit->second.mOwnerNode;
|
||||
item->mLastUsedTS = rit->second.mLastUsedTS;
|
||||
|
||||
std::map<RsPeerId, RsReputations::Opinion>::iterator oit;
|
||||
std::map<RsPeerId, RsOpinion>::iterator oit;
|
||||
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
|
||||
{
|
||||
// should be already limited.
|
||||
@ -1492,15 +1509,16 @@ void Reputation::updateReputation()
|
||||
// accounts for all friends. Neutral opinions count for 1-1=0
|
||||
// because the average is performed over only accessible peers (not the total number) we need to shift to 1
|
||||
|
||||
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
for( std::map<RsPeerId,RsOpinion>::const_iterator it(mOpinions.begin());
|
||||
it != mOpinions.end(); ++it )
|
||||
{
|
||||
if( it->second == RsReputations::OPINION_NEGATIVE)
|
||||
if( it->second == RsOpinion::NEGATIVE)
|
||||
++mFriendsNegative ;
|
||||
|
||||
if( it->second == RsReputations::OPINION_POSITIVE)
|
||||
if( it->second == RsOpinion::POSITIVE)
|
||||
++mFriendsPositive ;
|
||||
|
||||
friend_total += it->second - 1 ;
|
||||
friend_total += static_cast<int>(it->second) - 1;
|
||||
}
|
||||
|
||||
if(mOpinions.empty()) // includes the case of no friends!
|
||||
@ -1555,10 +1573,9 @@ void Reputation::updateReputation()
|
||||
|
||||
// now compute a bias for PGP-signed ids.
|
||||
|
||||
if(mOwnOpinion == RsReputations::OPINION_NEUTRAL)
|
||||
if(mOwnOpinion == static_cast<int32_t>(RsOpinion::NEUTRAL))
|
||||
mReputationScore = mFriendAverage;
|
||||
else
|
||||
mReputationScore = (float)mOwnOpinion ;
|
||||
else mReputationScore = static_cast<float>(mOwnOpinion);
|
||||
}
|
||||
|
||||
void p3GxsReputation::debug_print()
|
||||
@ -1570,16 +1587,19 @@ void p3GxsReputation::debug_print()
|
||||
std::map<RsGxsId,Reputation> rep_copy;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
RS_STACK_MUTEX(mReputationMtx);
|
||||
rep_copy = mReputations;
|
||||
}
|
||||
rstime_t now = time(NULL) ;
|
||||
|
||||
for(std::map<RsGxsId,Reputation>::const_iterator it(rep_copy.begin());it!=rep_copy.end();++it)
|
||||
rstime_t now = time(nullptr);
|
||||
|
||||
|
||||
for( std::map<RsGxsId,Reputation>::const_iterator it(rep_copy.begin());
|
||||
it != rep_copy.end(); ++it )
|
||||
{
|
||||
RsReputations::ReputationInfo info ;
|
||||
RsReputationInfo info;
|
||||
getReputationInfo(it->first, RsPgpId(), info, false);
|
||||
uint32_t lev = info.mOverallReputationLevel;
|
||||
uint32_t lev = static_cast<uint32_t>(info.mOverallReputationLevel);
|
||||
|
||||
std::cerr << " " << it->first << ": own: " << it->second.mOwnOpinion
|
||||
<< ", PGP id=" << it->second.mOwnerNode
|
||||
@ -1596,7 +1616,7 @@ std::map<RsGxsId,Reputation> rep_copy;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
RS_STACK_MUTEX(mReputationMtx);
|
||||
std::cerr << " Banned RS nodes by ID: " << std::endl;
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it)
|
||||
|
@ -64,15 +64,17 @@ struct BannedNodeInfo
|
||||
class Reputation
|
||||
{
|
||||
public:
|
||||
Reputation()
|
||||
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0),mFriendAverage(1.0f), mReputationScore(RsReputations::OPINION_NEUTRAL),mIdentityFlags(0){ }
|
||||
|
||||
Reputation(const RsGxsId& /*about*/)
|
||||
:mOwnOpinion(RsReputations::OPINION_NEUTRAL), mOwnOpinionTs(0),mFriendAverage(1.0f), mReputationScore(RsReputations::OPINION_NEUTRAL),mIdentityFlags(0){ }
|
||||
Reputation() :
|
||||
mOwnOpinion(static_cast<int32_t>(RsOpinion::NEUTRAL)), mOwnOpinionTs(0),
|
||||
mFriendAverage(1.0f),
|
||||
/* G10h4ck: TODO shouln't this be initialized with
|
||||
* RsReputation::NEUTRAL or UNKOWN? */
|
||||
mReputationScore(static_cast<float>(RsOpinion::NEUTRAL)),
|
||||
mIdentityFlags(0) {}
|
||||
|
||||
void updateReputation();
|
||||
|
||||
std::map<RsPeerId, RsReputations::Opinion> mOpinions;
|
||||
std::map<RsPeerId, RsOpinion> mOpinions;
|
||||
int32_t mOwnOpinion;
|
||||
rstime_t mOwnOpinionTs;
|
||||
|
||||
@ -91,11 +93,6 @@ public:
|
||||
|
||||
|
||||
//!The p3GxsReputation service.
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class p3GxsReputation: public p3Service, public p3Config, public RsGixsReputation, public RsReputations /* , public pqiMonitor */
|
||||
{
|
||||
public:
|
||||
@ -103,20 +100,26 @@ public:
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
/***** Interface for RsReputations *****/
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
|
||||
virtual bool getOwnOpinion(const RsGxsId& key_id, Opinion& op) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info,bool stamp=true) ;
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, RsOpinion op);
|
||||
virtual bool getOwnOpinion(const RsGxsId& key_id, RsOpinion& op) ;
|
||||
virtual bool getReputationInfo(
|
||||
const RsGxsId& id, const RsPgpId& ownerNode, RsReputationInfo& info,
|
||||
bool stamp = true );
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) ;
|
||||
|
||||
virtual bool isNodeBanned(const RsPgpId& id);
|
||||
virtual void banNode(const RsPgpId& id,bool b) ;
|
||||
virtual ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL);
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) ;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() ;
|
||||
RsReputationLevel overallReputationLevel(const RsGxsId& id) override;
|
||||
|
||||
virtual void setRememberDeletedNodesThreshold(uint32_t days) ;
|
||||
virtual uint32_t rememberDeletedNodesThreshold() ;
|
||||
virtual RsReputationLevel overallReputationLevel(
|
||||
const RsGxsId& id, uint32_t* identity_flags );
|
||||
|
||||
virtual void setAutoPositiveOpinionForContacts(bool b) ;
|
||||
virtual bool autoPositiveOpinionForContacts() ;
|
||||
|
||||
virtual void setRememberBannedIdThreshold(uint32_t days) ;
|
||||
virtual uint32_t rememberBannedIdThreshold() ;
|
||||
|
||||
uint32_t thresholdForRemotelyNegativeReputation();
|
||||
uint32_t thresholdForRemotelyPositiveReputation();
|
||||
@ -149,7 +152,8 @@ private:
|
||||
void updateBannedNodesProxy();
|
||||
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
|
||||
void locked_updateOpinion(
|
||||
const RsPeerId& from, const RsGxsId& about, RsOpinion op);
|
||||
bool loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet);
|
||||
#ifdef TO_REMOVE
|
||||
bool loadReputationSet_deprecated3(RsGxsReputationSetItem_deprecated3 *item, const std::set<RsPeerId> &peerSet);
|
||||
|
@ -21,6 +21,7 @@
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "services/p3idservice.h"
|
||||
#include "pgp/pgpauxutils.h"
|
||||
@ -207,6 +208,32 @@ void p3IdService::setNes(RsNetworkExchangeService *nes)
|
||||
mNes = nes;
|
||||
}
|
||||
|
||||
bool p3IdService::getIdentitiesInfo(
|
||||
const std::set<RsGxsId>& ids, std::vector<RsGxsIdGroup>& idsInfo )
|
||||
{
|
||||
uint32_t token;
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
|
||||
std::list<RsGxsGroupId> idsList;
|
||||
for (auto&& id : ids) idsList.push_back(RsGxsGroupId(id));
|
||||
|
||||
if( !requestGroupInfo(token, opts, idsList)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
return getGroupData(token, idsInfo);
|
||||
}
|
||||
|
||||
bool p3IdService::getIdentitiesSummaries(std::list<RsGroupMetaData>& ids)
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
if( !requestGroupInfo(token, opts)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
return getGroupSummary(token, ids);
|
||||
}
|
||||
|
||||
uint32_t p3IdService::idAuthenPolicy()
|
||||
{
|
||||
uint32_t policy = 0;
|
||||
@ -687,11 +714,12 @@ bool p3IdService::getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
|
||||
// This step is needed, because p3GxsReputation does not know all identities, and might not have any data for
|
||||
// the ones in the contact list. So we change them on demand.
|
||||
|
||||
if(is_a_contact && rsReputations->nodeAutoPositiveOpinionForContacts())
|
||||
if(is_a_contact && rsReputations->autoPositiveOpinionForContacts())
|
||||
{
|
||||
RsReputations::Opinion op ;
|
||||
if(rsReputations->getOwnOpinion(id,op) && op == RsReputations::OPINION_NEUTRAL)
|
||||
rsReputations->setOwnOpinion(id,RsReputations::OPINION_POSITIVE) ;
|
||||
RsOpinion op;
|
||||
if( rsReputations->getOwnOpinion(id,op) &&
|
||||
op == RsOpinion::NEUTRAL )
|
||||
rsReputations->setOwnOpinion(id, RsOpinion::POSITIVE);
|
||||
}
|
||||
|
||||
std::map<RsGxsId,keyTSInfo>::const_iterator it = mKeysTS.find(id) ;
|
||||
@ -727,6 +755,46 @@ bool p3IdService::isOwnId(const RsGxsId& id)
|
||||
|
||||
return std::find(mOwnIds.begin(),mOwnIds.end(),id) != mOwnIds.end() ;
|
||||
}
|
||||
|
||||
|
||||
bool p3IdService::getOwnSignedIds(std::vector<RsGxsId> ids)
|
||||
{
|
||||
ids.clear();
|
||||
|
||||
std::chrono::seconds maxWait(5);
|
||||
auto timeout = std::chrono::steady_clock::now() + maxWait;
|
||||
while( !ownIdsAreLoaded() && std::chrono::steady_clock::now() < timeout )
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
if(ownIdsAreLoaded())
|
||||
{
|
||||
RS_STACK_MUTEX(mIdMtx);
|
||||
ids.reserve(mOwnSignedIds.size());
|
||||
ids.insert(ids.end(), mOwnSignedIds.begin(), mOwnSignedIds.end());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3IdService::getOwnPseudonimousIds(std::vector<RsGxsId> ids)
|
||||
{
|
||||
ids.clear();
|
||||
std::vector<RsGxsId> signedV;
|
||||
|
||||
// this implicitely ensure ids are already loaded ;)
|
||||
if(!getOwnSignedIds(signedV)) return false;
|
||||
std::set<RsGxsId> signedS(signedV.begin(), signedV.end());
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mIdMtx);
|
||||
std::copy_if(mOwnIds.begin(), mOwnIds.end(), ids.end(),
|
||||
[&](const RsGxsId& id) {return !signedS.count(id);});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds,bool signed_only)
|
||||
{
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -742,6 +810,11 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds,bool signed_only)
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
bool p3IdService::identityToBase64( const RsGxsId& id,
|
||||
std::string& base64String )
|
||||
{ return serialiseIdentityToMemory(id, base64String); }
|
||||
|
||||
bool p3IdService::serialiseIdentityToMemory( const RsGxsId& id,
|
||||
std::string& radix_string )
|
||||
{
|
||||
@ -803,6 +876,10 @@ void p3IdService::handle_get_serialized_grp(uint32_t token)
|
||||
mSerialisedIdentities[RsGxsId(id)] = s ;
|
||||
}
|
||||
|
||||
bool p3IdService::identityFromBase64(
|
||||
const std::string& base64String, RsGxsId& id )
|
||||
{ return deserialiseIdentityFromMemory(base64String, &id); }
|
||||
|
||||
bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||
RsGxsId* id /* = nullptr */)
|
||||
{
|
||||
@ -826,6 +903,47 @@ bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::createIdentity(
|
||||
RsGxsId& id,
|
||||
const std::string& name, const RsGxsImage& avatar,
|
||||
bool pseudonimous, const std::string& pgpPassword)
|
||||
{
|
||||
if(!pgpPassword.empty())
|
||||
std::cerr<< __PRETTY_FUNCTION__ << " Warning! PGP Password handling "
|
||||
<< "not implemented yet!" << std::endl;
|
||||
|
||||
RsIdentityParameters params;
|
||||
params.isPgpLinked = !pseudonimous;
|
||||
params.nickname = name;
|
||||
params.mImage = avatar;
|
||||
|
||||
uint32_t token;
|
||||
if(!createIdentity(token, params))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error! Failed creating group."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsGroupMetaData meta;
|
||||
if(!RsGenExchange::getPublishedGroupMeta(token, meta))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated "
|
||||
<< " group data." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
id = RsGxsId(meta.mGroupId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
||||
{
|
||||
|
||||
@ -863,6 +981,26 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::updateIdentity(RsGxsIdGroup& identityData)
|
||||
{
|
||||
uint32_t token;
|
||||
if(!updateGroup(token, identityData))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failed updating group."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::updateIdentity(uint32_t& token, RsGxsIdGroup &group)
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
@ -876,6 +1014,27 @@ bool p3IdService::updateIdentity(uint32_t& token, RsGxsIdGroup &group)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3IdService::deleteIdentity(RsGxsId& id)
|
||||
{
|
||||
uint32_t token;
|
||||
RsGxsGroupId grouId = RsGxsGroupId(id);
|
||||
if(!deleteGroup(token, grouId))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! Failed deleting group."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::deleteIdentity(uint32_t& token, RsGxsIdGroup &group)
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
@ -883,7 +1042,7 @@ bool p3IdService::deleteIdentity(uint32_t& token, RsGxsIdGroup &group)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
deleteGroup(token, group);
|
||||
deleteGroup(token, group.mMeta.mGroupId);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1012,10 +1171,10 @@ bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers
|
||||
std::cerr << "p3IdService::requesting key " << id <<std::endl;
|
||||
#endif
|
||||
|
||||
RsReputations::ReputationInfo info ;
|
||||
RsReputationInfo info;
|
||||
rsReputations->getReputationInfo(id,RsPgpId(),info) ;
|
||||
|
||||
if(info.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( info.mOverallReputationLevel == RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
std::cerr << "(II) not requesting Key " << id << " because it has been banned." << std::endl;
|
||||
|
||||
@ -1796,16 +1955,16 @@ bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3IdService::deleteGroup(uint32_t& token, RsGxsIdGroup &group)
|
||||
bool p3IdService::deleteGroup(uint32_t& token, RsGxsGroupId& groupId)
|
||||
{
|
||||
RsGxsId id(group.mMeta.mGroupId);
|
||||
RsGxsId id(groupId);
|
||||
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::deleteGroup() Deleting RsGxsId: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsGenExchange::deleteGroup(token,group.mMeta.mGroupId);
|
||||
RsGenExchange::deleteGroup(token, groupId);
|
||||
|
||||
// if its in the cache - clear it.
|
||||
{
|
||||
|
@ -215,9 +215,8 @@ struct SerialisedIdentityStruct
|
||||
rstime_t mLastUsageTS;
|
||||
};
|
||||
|
||||
// Not sure exactly what should be inherited here?
|
||||
// Chris - please correct as necessary.
|
||||
|
||||
// We cache all identities, and provide alternative (instantaneous)
|
||||
// functions to extract info, rather than the horrible Token system.
|
||||
class p3IdService: public RsGxsIdExchange, public RsIdentity, public GxsTokenQueue, public RsTickEvent, public p3Config
|
||||
{
|
||||
public:
|
||||
@ -239,6 +238,13 @@ public:
|
||||
|
||||
/* Data Specific Interface */
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getIdentitiesInfo(const std::set<RsGxsId>& ids,
|
||||
std::vector<RsGxsIdGroup>& idsInfo ) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getIdentitiesSummaries(std::list<RsGroupMetaData>& ids) override;
|
||||
|
||||
// These are exposed via RsIdentity.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
||||
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups);
|
||||
@ -248,7 +254,7 @@ public:
|
||||
// These are local - and not exposed via RsIdentity.
|
||||
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool updateGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool deleteGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool deleteGroup(uint32_t& token, RsGxsGroupId& group);
|
||||
//virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
||||
|
||||
/**************** RsIdentity External Interface.
|
||||
@ -263,12 +269,28 @@ public:
|
||||
//virtual bool getNickname(const RsGxsId &id, std::string &nickname);
|
||||
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details);
|
||||
|
||||
//
|
||||
RS_DEPRECATED_FOR(RsReputations)
|
||||
virtual bool submitOpinion(uint32_t& token, const RsGxsId &id,
|
||||
bool absOpinion, int score);
|
||||
|
||||
/// @see RsIdentity
|
||||
virtual bool createIdentity(
|
||||
RsGxsId& id,
|
||||
const std::string& name, const RsGxsImage& avatar = RsGxsImage(),
|
||||
bool pseudonimous = true, const std::string& pgpPassword = "" ) override;
|
||||
|
||||
virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms);
|
||||
|
||||
/// @see RsIdentity
|
||||
bool updateIdentity(RsGxsIdGroup& identityData) override;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool updateIdentity(uint32_t& token, RsGxsIdGroup &group);
|
||||
|
||||
/// @see RsIdentity
|
||||
bool deleteIdentity(RsGxsId& id) override;
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool deleteIdentity(uint32_t& token, RsGxsIdGroup &group);
|
||||
|
||||
virtual void setDeleteBannedNodesThreshold(uint32_t days) ;
|
||||
@ -289,6 +311,12 @@ public:
|
||||
|
||||
/**************** RsGixs Implementation ***************/
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getOwnSignedIds(std::vector<RsGxsId> ids) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool getOwnPseudonimousIds(std::vector<RsGxsId> ids) override;
|
||||
|
||||
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false);
|
||||
|
||||
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
|
||||
@ -350,6 +378,15 @@ public:
|
||||
const RsIdentityUsage &use_info );
|
||||
virtual bool requestPrivateKey(const RsGxsId &id);
|
||||
|
||||
|
||||
/// @see RsIdentity
|
||||
bool identityToBase64( const RsGxsId& id,
|
||||
std::string& base64String ) override;
|
||||
|
||||
/// @see RsIdentity
|
||||
bool identityFromBase64( const std::string& base64String,
|
||||
RsGxsId& id ) override;
|
||||
|
||||
virtual bool serialiseIdentityToMemory(const RsGxsId& id,
|
||||
std::string& radix_string);
|
||||
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
|
||||
@ -600,6 +637,8 @@ private:
|
||||
rstime_t mLastConfigUpdate ;
|
||||
|
||||
bool mOwnIdsLoaded;
|
||||
bool ownIdsAreLoaded() { RS_STACK_MUTEX(mIdMtx); return mOwnIdsLoaded; }
|
||||
|
||||
bool mAutoAddFriendsIdentitiesAsContacts;
|
||||
uint32_t mMaxKeepKeysBanned ;
|
||||
};
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <cstdint>
|
||||
#endif
|
||||
#include <ctime> // Added for comfort of users of this util header
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
/**
|
||||
* Safer alternative to time_t.
|
||||
@ -47,7 +48,7 @@ namespace rstime {
|
||||
/*!
|
||||
* \brief This is a cross-system definition of usleep, which accepts any 32 bits number of micro-seconds.
|
||||
*/
|
||||
|
||||
RS_DEPRECATED_FOR("std::this_thread::sleep_for")
|
||||
int rs_usleep(uint32_t micro_seconds);
|
||||
|
||||
/* Use this class to measure and display time duration of a given environment:
|
||||
|
@ -285,7 +285,7 @@ void IdDetailsDialog::insertIdDetails(uint32_t token)
|
||||
|
||||
#endif
|
||||
|
||||
RsReputations::ReputationInfo info ;
|
||||
RsReputationInfo info;
|
||||
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),data.mPgpId,info) ;
|
||||
|
||||
#warning (csoler) Do we need to do this? This code is apparently not used.
|
||||
@ -304,21 +304,32 @@ void IdDetailsDialog::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 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 ;
|
||||
case RsReputationLevel::LOCALLY_POSITIVE:
|
||||
ui->overallOpinion_TF->setText(tr("Positive")); break;
|
||||
case RsReputationLevel::LOCALLY_NEGATIVE:
|
||||
ui->overallOpinion_TF->setText(tr("Negative (Banned by you)")); break;
|
||||
case RsReputationLevel::REMOTELY_POSITIVE:
|
||||
ui->overallOpinion_TF->setText(
|
||||
tr("Positive (according to your friends)"));
|
||||
break;
|
||||
case RsReputationLevel::REMOTELY_NEGATIVE:
|
||||
ui->overallOpinion_TF->setText(
|
||||
tr("Negative (according to your friends)"));
|
||||
break;
|
||||
case RsReputationLevel::NEUTRAL: // fallthrough
|
||||
default:
|
||||
case RsReputations::REPUTATION_NEUTRAL: ui->overallOpinion_TF->setText(tr("Neutral")) ; break ;
|
||||
ui->overallOpinion_TF->setText(tr("Neutral")); break;
|
||||
}
|
||||
|
||||
switch(info.mOwnOpinion)
|
||||
{
|
||||
case RsReputations::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ;
|
||||
case RsReputations::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ;
|
||||
case RsReputations::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ;
|
||||
case RsOpinion::NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break;
|
||||
case RsOpinion::NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break;
|
||||
case RsOpinion::POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break;
|
||||
default:
|
||||
std::cerr << "Unexpected value in own opinion: " << info.mOwnOpinion << std::endl;
|
||||
std::cerr << "Unexpected value in own opinion: "
|
||||
<< static_cast<uint32_t>(info.mOwnOpinion) << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,16 +342,16 @@ void IdDetailsDialog::modifyReputation()
|
||||
|
||||
RsGxsId id(ui->lineEdit_KeyId->text().toStdString());
|
||||
|
||||
RsReputations::Opinion op ;
|
||||
RsOpinion op;
|
||||
|
||||
switch(ui->ownOpinion_CB->currentIndex())
|
||||
{
|
||||
case 0: op = RsReputations::OPINION_NEGATIVE ; break ;
|
||||
case 1: op = RsReputations::OPINION_NEUTRAL ; break ;
|
||||
case 2: op = RsReputations::OPINION_POSITIVE ; break ;
|
||||
case 0: op = RsOpinion::NEGATIVE; break;
|
||||
case 1: op = RsOpinion::NEUTRAL ; break;
|
||||
case 2: op = RsOpinion::POSITIVE; break;
|
||||
default:
|
||||
std::cerr << "Wrong value from opinion combobox. Bug??" << std::endl;
|
||||
|
||||
break;
|
||||
}
|
||||
rsReputations->setOwnOpinion(id,op);
|
||||
|
||||
|
@ -344,7 +344,9 @@ IdDialog::IdDialog(QWidget *parent) :
|
||||
ui->idTreeWidget->setColumnWidth(RSID_COL_IDTYPE, 18 * fontWidth);
|
||||
ui->idTreeWidget->setColumnWidth(RSID_COL_VOTES, 2 * fontWidth);
|
||||
|
||||
ui->idTreeWidget->setItemDelegateForColumn(RSID_COL_VOTES,new ReputationItemDelegate(RsReputations::ReputationLevel(0xff))) ;
|
||||
ui->idTreeWidget->setItemDelegateForColumn(
|
||||
RSID_COL_VOTES,
|
||||
new ReputationItemDelegate(RsReputationLevel(0xff)));
|
||||
|
||||
/* Set header resize modes and initial section sizes */
|
||||
QHeaderView * idheader = ui->idTreeWidget->header();
|
||||
@ -1444,7 +1446,8 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
|
||||
RsIdentityDetails idd ;
|
||||
rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),idd) ;
|
||||
|
||||
bool isBanned = idd.mReputation.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE;
|
||||
bool isBanned = idd.mReputation.mOverallReputationLevel ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE;
|
||||
uint32_t item_flags = 0;
|
||||
|
||||
/* do filtering */
|
||||
@ -1514,8 +1517,12 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
|
||||
|
||||
item->setData(RSID_COL_KEYID, Qt::UserRole,QVariant(item_flags)) ;
|
||||
item->setTextAlignment(RSID_COL_VOTES, Qt::AlignRight | Qt::AlignVCenter);
|
||||
item->setData(RSID_COL_VOTES,Qt::DecorationRole, idd.mReputation.mOverallReputationLevel);
|
||||
item->setData(RSID_COL_VOTES,SortRole, idd.mReputation.mOverallReputationLevel);
|
||||
item->setData(
|
||||
RSID_COL_VOTES,Qt::DecorationRole,
|
||||
static_cast<uint32_t>(idd.mReputation.mOverallReputationLevel));
|
||||
item->setData(
|
||||
RSID_COL_VOTES,SortRole,
|
||||
static_cast<uint32_t>(idd.mReputation.mOverallReputationLevel));
|
||||
|
||||
if(isOwnId)
|
||||
{
|
||||
@ -1910,7 +1917,7 @@ void IdDialog::insertIdDetails(uint32_t token)
|
||||
|
||||
#endif
|
||||
|
||||
RsReputations::ReputationInfo info ;
|
||||
RsReputationInfo info;
|
||||
rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),data.mPgpId,info) ;
|
||||
|
||||
QString frep_string ;
|
||||
@ -1927,21 +1934,30 @@ 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 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 ;
|
||||
case RsReputationLevel::LOCALLY_POSITIVE:
|
||||
ui->overallOpinion_TF->setText(tr("Positive")); break;
|
||||
case RsReputationLevel::LOCALLY_NEGATIVE:
|
||||
ui->overallOpinion_TF->setText(tr("Negative (Banned by you)")); break;
|
||||
case RsReputationLevel::REMOTELY_POSITIVE:
|
||||
ui->overallOpinion_TF->setText(tr("Positive (according to your friends)"));
|
||||
break;
|
||||
case RsReputationLevel::REMOTELY_NEGATIVE:
|
||||
ui->overallOpinion_TF->setText(tr("Negative (according to your friends)"));
|
||||
break;
|
||||
case RsReputationLevel::NEUTRAL: // fallthrough
|
||||
default:
|
||||
case RsReputations::REPUTATION_NEUTRAL: ui->overallOpinion_TF->setText(tr("Neutral")) ; break ;
|
||||
ui->overallOpinion_TF->setText(tr("Neutral")) ; break ;
|
||||
}
|
||||
|
||||
switch(info.mOwnOpinion)
|
||||
{
|
||||
case RsReputations::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ;
|
||||
case RsReputations::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ;
|
||||
case RsReputations::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ;
|
||||
case RsOpinion::NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break;
|
||||
case RsOpinion::NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break;
|
||||
case RsOpinion::POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break;
|
||||
default:
|
||||
std::cerr << "Unexpected value in own opinion: " << info.mOwnOpinion << std::endl;
|
||||
std::cerr << "Unexpected value in own opinion: "
|
||||
<< static_cast<uint32_t>(info.mOwnOpinion) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
// now fill in usage cases
|
||||
@ -2061,16 +2077,16 @@ void IdDialog::modifyReputation()
|
||||
|
||||
RsGxsId id(ui->lineEdit_KeyId->text().toStdString());
|
||||
|
||||
RsReputations::Opinion op ;
|
||||
RsOpinion op;
|
||||
|
||||
switch(ui->ownOpinion_CB->currentIndex())
|
||||
{
|
||||
case 0: op = RsReputations::OPINION_NEGATIVE ; break ;
|
||||
case 1: op = RsReputations::OPINION_NEUTRAL ; break ;
|
||||
case 2: op = RsReputations::OPINION_POSITIVE ; break ;
|
||||
case 0: op = RsOpinion::NEGATIVE; break;
|
||||
case 1: op = RsOpinion::NEUTRAL ; break;
|
||||
case 2: op = RsOpinion::POSITIVE; break;
|
||||
default:
|
||||
std::cerr << "Wrong value from opinion combobox. Bug??" << std::endl;
|
||||
|
||||
break;
|
||||
}
|
||||
rsReputations->setOwnOpinion(id,op);
|
||||
|
||||
@ -2386,14 +2402,9 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
|
||||
|
||||
switch(det.mReputation.mOwnOpinion)
|
||||
{
|
||||
case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ;
|
||||
break ;
|
||||
|
||||
case RsReputations::OPINION_POSITIVE: ++n_positive_reputations ;
|
||||
break ;
|
||||
|
||||
case RsReputations::OPINION_NEUTRAL: ++n_neutral_reputations ;
|
||||
break ;
|
||||
case RsOpinion::NEGATIVE: ++n_negative_reputations; break;
|
||||
case RsOpinion::POSITIVE: ++n_positive_reputations; break;
|
||||
case RsOpinion::NEUTRAL: ++n_neutral_reputations; break;
|
||||
}
|
||||
|
||||
++n_selected_items;
|
||||
@ -2674,7 +2685,7 @@ void IdDialog::negativePerson()
|
||||
|
||||
std::string Id = item->text(RSID_COL_KEYID).toStdString();
|
||||
|
||||
rsReputations->setOwnOpinion(RsGxsId(Id),RsReputations::OPINION_NEGATIVE) ;
|
||||
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEGATIVE);
|
||||
}
|
||||
|
||||
requestIdDetails();
|
||||
@ -2690,7 +2701,7 @@ void IdDialog::neutralPerson()
|
||||
|
||||
std::string Id = item->text(RSID_COL_KEYID).toStdString();
|
||||
|
||||
rsReputations->setOwnOpinion(RsGxsId(Id),RsReputations::OPINION_NEUTRAL) ;
|
||||
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEUTRAL);
|
||||
}
|
||||
|
||||
requestIdDetails();
|
||||
@ -2705,7 +2716,7 @@ void IdDialog::positivePerson()
|
||||
|
||||
std::string Id = item->text(RSID_COL_KEYID).toStdString();
|
||||
|
||||
rsReputations->setOwnOpinion(RsGxsId(Id),RsReputations::OPINION_POSITIVE) ;
|
||||
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::POSITIVE);
|
||||
}
|
||||
|
||||
requestIdDetails();
|
||||
|
@ -300,9 +300,17 @@ void ChatLobbyDialog::initParticipantsContextMenu(QMenu *contextMnu, QList<RsGxs
|
||||
{
|
||||
distantChatAct->setEnabled(true);
|
||||
sendMessageAct->setEnabled(true);
|
||||
votePositiveAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_POSITIVE);
|
||||
voteNeutralAct->setEnabled((rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_POSITIVE) || (rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_NEGATIVE) );
|
||||
voteNegativeAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_NEGATIVE);
|
||||
votePositiveAct->setEnabled(
|
||||
rsReputations->overallReputationLevel(gxsid) !=
|
||||
RsReputationLevel::LOCALLY_POSITIVE );
|
||||
voteNeutralAct->setEnabled(
|
||||
( rsReputations->overallReputationLevel(gxsid) ==
|
||||
RsReputationLevel::LOCALLY_POSITIVE ) ||
|
||||
( rsReputations->overallReputationLevel(gxsid) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE ) );
|
||||
voteNegativeAct->setEnabled(
|
||||
rsReputations->overallReputationLevel(gxsid) !=
|
||||
RsReputationLevel::LOCALLY_NEGATIVE );
|
||||
muteAct->setEnabled(true);
|
||||
muteAct->setChecked(isParticipantMuted(gxsid));
|
||||
}
|
||||
@ -319,16 +327,15 @@ void ChatLobbyDialog::voteParticipant()
|
||||
|
||||
QList<RsGxsId> idList = act->data().value<QList<RsGxsId>>();
|
||||
|
||||
RsReputations::Opinion op = RsReputations::OPINION_NEUTRAL ;
|
||||
if (act == votePositiveAct)
|
||||
op = RsReputations::OPINION_POSITIVE;
|
||||
if (act == voteNegativeAct)
|
||||
op = RsReputations::OPINION_NEGATIVE;
|
||||
RsOpinion op = RsOpinion::NEUTRAL;
|
||||
if (act == votePositiveAct) op = RsOpinion::POSITIVE;
|
||||
if (act == voteNegativeAct) op = RsOpinion::NEGATIVE;
|
||||
|
||||
for (QList<RsGxsId>::iterator item = idList.begin(); item != idList.end(); ++item)
|
||||
{
|
||||
rsReputations->setOwnOpinion(*item, op);
|
||||
std::cerr << "Giving opinion to GXS id " << *item << " to " << op << std::endl;
|
||||
std::cerr << "Giving opinion to GXS id " << *item << " to "
|
||||
<< static_cast<uint32_t>(op) << std::endl;
|
||||
}
|
||||
|
||||
updateParticipantsList();
|
||||
|
@ -84,7 +84,8 @@ void ReputationItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||
if(icon_index > mMaxLevelToDisplay)
|
||||
return ;
|
||||
|
||||
QIcon icon = GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel(icon_index),0xff);
|
||||
QIcon icon = GxsIdDetails::getReputationIcon(
|
||||
RsReputationLevel(icon_index), 0xff );
|
||||
|
||||
QPixmap pix = icon.pixmap(r.size());
|
||||
|
||||
@ -937,7 +938,8 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, QLi
|
||||
|
||||
QString GxsIdDetails::getName(const RsIdentityDetails &details)
|
||||
{
|
||||
if(details.mReputation.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( details.mReputation.mOverallReputationLevel ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
return tr("[Banned]");
|
||||
|
||||
QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE);
|
||||
@ -956,7 +958,8 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details)
|
||||
QString comment;
|
||||
QString nickname ;
|
||||
|
||||
bool banned = (details.mReputation.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE);
|
||||
bool banned = ( details.mReputation.mOverallReputationLevel ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE );
|
||||
|
||||
if(details.mNickname.empty())
|
||||
nickname = tr("[Unknown]") ;
|
||||
@ -997,19 +1000,27 @@ QString nickname ;
|
||||
return comment;
|
||||
}
|
||||
|
||||
QIcon GxsIdDetails::getReputationIcon(RsReputations::ReputationLevel icon_index,uint32_t min_reputation)
|
||||
QIcon GxsIdDetails::getReputationIcon(
|
||||
RsReputationLevel icon_index, uint32_t min_reputation )
|
||||
{
|
||||
if( icon_index >= min_reputation ) return QIcon(REPUTATION_VOID) ;
|
||||
if( static_cast<uint32_t>(icon_index) >= min_reputation )
|
||||
return QIcon(REPUTATION_VOID);
|
||||
|
||||
switch(icon_index)
|
||||
{
|
||||
case RsReputations::REPUTATION_LOCALLY_NEGATIVE: return QIcon(REPUTATION_LOCALLY_NEGATIVE_ICON) ; break ;
|
||||
case RsReputations::REPUTATION_LOCALLY_POSITIVE: return QIcon(REPUTATION_LOCALLY_POSITIVE_ICON) ; break ;
|
||||
case RsReputations::REPUTATION_REMOTELY_POSITIVE: return QIcon(REPUTATION_REMOTELY_POSITIVE_ICON) ; break ;
|
||||
case RsReputations::REPUTATION_REMOTELY_NEGATIVE: return QIcon(REPUTATION_REMOTELY_NEGATIVE_ICON) ; break ;
|
||||
case RsReputations::REPUTATION_NEUTRAL: return QIcon(REPUTATION_NEUTRAL_ICON) ; break ;
|
||||
case RsReputationLevel::LOCALLY_NEGATIVE:
|
||||
return QIcon(REPUTATION_LOCALLY_NEGATIVE_ICON);
|
||||
case RsReputationLevel::LOCALLY_POSITIVE:
|
||||
return QIcon(REPUTATION_LOCALLY_POSITIVE_ICON);
|
||||
case RsReputationLevel::REMOTELY_POSITIVE:
|
||||
return QIcon(REPUTATION_REMOTELY_POSITIVE_ICON);
|
||||
case RsReputationLevel::REMOTELY_NEGATIVE:
|
||||
return QIcon(REPUTATION_REMOTELY_NEGATIVE_ICON);
|
||||
case RsReputationLevel::NEUTRAL:
|
||||
return QIcon(REPUTATION_NEUTRAL_ICON);
|
||||
default:
|
||||
std::cerr << "Asked for unidentified icon index " << icon_index << std::endl;
|
||||
std::cerr << "Asked for unidentified icon index "
|
||||
<< static_cast<uint32_t>(icon_index) << std::endl;
|
||||
return QIcon(); // dont draw anything
|
||||
}
|
||||
}
|
||||
@ -1018,7 +1029,8 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList<QIcon> &icon
|
||||
{
|
||||
QPixmap pix ;
|
||||
|
||||
if(details.mReputation.mOverallReputationLevel == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if( details.mReputation.mOverallReputationLevel ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
{
|
||||
icons.clear() ;
|
||||
icons.push_back(QIcon(IMAGE_BANNED)) ;
|
||||
|
@ -49,7 +49,8 @@ typedef void (*GxsIdDetailsCallbackFunction)(GxsIdDetailsType type, const RsIden
|
||||
class ReputationItemDelegate: public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
ReputationItemDelegate(RsReputations::ReputationLevel max_level_to_display) : mMaxLevelToDisplay(max_level_to_display) {}
|
||||
ReputationItemDelegate(RsReputationLevel max_level_to_display) :
|
||||
mMaxLevelToDisplay(static_cast<uint32_t>(max_level_to_display)) {}
|
||||
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
@ -96,7 +97,8 @@ public:
|
||||
static QString getNameForType(GxsIdDetailsType type, const RsIdentityDetails &details);
|
||||
|
||||
static QIcon getLoadingIcon(const RsGxsId &id);
|
||||
static QIcon getReputationIcon(RsReputations::ReputationLevel icon_index, uint32_t min_reputation);
|
||||
static QIcon getReputationIcon(
|
||||
RsReputationLevel icon_index, uint32_t min_reputation );
|
||||
|
||||
static void GenerateCombinedPixmap(QPixmap &pixmap, const QList<QIcon> &icons, int iconSize);
|
||||
|
||||
|
@ -156,19 +156,23 @@ QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const
|
||||
QString t = RSTreeWidgetItem::data(column, role).toString();
|
||||
QImage pix;
|
||||
|
||||
if(mId.isNull())
|
||||
return RSTreeWidgetItem::data(column, role);
|
||||
else if(rsReputations->overallReputationLevel(mId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if(mId.isNull()) return RSTreeWidgetItem::data(column, role);
|
||||
else if( rsReputations->overallReputationLevel(mId) ==
|
||||
RsReputationLevel::LOCALLY_NEGATIVE )
|
||||
pix = QImage(BANNED_IMAGE);
|
||||
else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG"))
|
||||
else if ( mAvatar.mSize == 0 ||
|
||||
!pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG") )
|
||||
pix = GxsIdDetails::makeDefaultIcon(mId);
|
||||
|
||||
int S = QFontMetricsF(font(column)).height();
|
||||
|
||||
QString embeddedImage;
|
||||
if (RsHtml::makeEmbeddedImage(pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, 8*S * 8*S)) {
|
||||
t = "<table><tr><td>" + embeddedImage + "</td><td>" + t + "</td></table>";
|
||||
}
|
||||
if ( RsHtml::makeEmbeddedImage(
|
||||
pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation ),
|
||||
embeddedImage, 8*S * 8*S ) )
|
||||
t = "<table><tr><td>" + embeddedImage + "</td><td>" + t
|
||||
+ "</td></table>";
|
||||
|
||||
return t;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
bool mIdFound;
|
||||
bool mBannedState ;
|
||||
bool mRetryWhenFailed;
|
||||
RsReputations::ReputationLevel mReputationLevel ;
|
||||
RsReputationLevel mReputationLevel;
|
||||
uint32_t mIconTypeMask;
|
||||
RsGxsImage mAvatar;
|
||||
};
|
||||
|
@ -824,19 +824,20 @@ void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,c
|
||||
void RsGxsForumModel::computeReputationLevel(uint32_t forum_sign_flags,ForumModelPostEntry& fentry)
|
||||
{
|
||||
uint32_t idflags =0;
|
||||
RsReputations::ReputationLevel reputation_level = rsReputations->overallReputationLevel(fentry.mAuthorId,&idflags) ;
|
||||
RsReputationLevel reputation_level =
|
||||
rsReputations->overallReputationLevel(fentry.mAuthorId, &idflags);
|
||||
bool redacted = false;
|
||||
|
||||
if(reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
if(reputation_level == RsReputationLevel::LOCALLY_NEGATIVE)
|
||||
fentry.mPostFlags |= ForumModelPostEntry::FLAG_POST_IS_REDACTED;
|
||||
else
|
||||
fentry.mPostFlags &= ~ForumModelPostEntry::FLAG_POST_IS_REDACTED;
|
||||
|
||||
// We use a specific item model for forums in order to handle the post pinning.
|
||||
|
||||
if(reputation_level == RsReputations::REPUTATION_UNKNOWN)
|
||||
if(reputation_level == RsReputationLevel::UNKNOWN)
|
||||
fentry.mReputationWarningLevel = 3 ;
|
||||
else if(reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
||||
else if(reputation_level == RsReputationLevel::LOCALLY_NEGATIVE)
|
||||
fentry.mReputationWarningLevel = 2 ;
|
||||
else if(reputation_level < rsGxsForums->minReputationForForwardingMessages(forum_sign_flags,idflags))
|
||||
fentry.mReputationWarningLevel = 1 ;
|
||||
@ -1301,7 +1302,7 @@ void RsGxsForumModel::debug_dump()
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsForumModel::setAuthorOpinion(const QModelIndex& indx,RsReputations::Opinion op)
|
||||
void RsGxsForumModel::setAuthorOpinion(const QModelIndex& indx, RsOpinion op)
|
||||
{
|
||||
if(!indx.isValid())
|
||||
return ;
|
||||
@ -1312,7 +1313,8 @@ void RsGxsForumModel::setAuthorOpinion(const QModelIndex& indx,RsReputations::Op
|
||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
|
||||
return ;
|
||||
|
||||
std::cerr << "Setting own opinion for author " << mPosts[entry].mAuthorId << " to " << op << std::endl;
|
||||
std::cerr << "Setting own opinion for author " << mPosts[entry].mAuthorId
|
||||
<< " to " << static_cast<uint32_t>(op) << std::endl;
|
||||
RsGxsId author_id = mPosts[entry].mAuthorId;
|
||||
|
||||
rsReputations->setOwnOpinion(author_id,op) ;
|
||||
|
@ -119,7 +119,7 @@ public:
|
||||
|
||||
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
|
||||
void setFilter(int column, const QStringList &strings, uint32_t &count) ;
|
||||
void setAuthorOpinion(const QModelIndex& indx,RsReputations::Opinion op);
|
||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
@ -770,17 +770,17 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
|
||||
|
||||
QAction *flagaspositiveAct = new QAction(QIcon(IMAGE_POSITIVE_OPINION), tr("Give positive opinion"), &contextMnu);
|
||||
flagaspositiveAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ;
|
||||
flagaspositiveAct->setData(RsReputations::OPINION_POSITIVE) ;
|
||||
flagaspositiveAct->setData(static_cast<uint32_t>(RsOpinion::POSITIVE));
|
||||
connect(flagaspositiveAct, SIGNAL(triggered()), this, SLOT(flagperson()));
|
||||
|
||||
QAction *flagasneutralAct = new QAction(QIcon(IMAGE_NEUTRAL_OPINION), tr("Give neutral opinion"), &contextMnu);
|
||||
flagasneutralAct->setToolTip(tr("Doing this, you trust your friends to decide to forward this message or not.")) ;
|
||||
flagasneutralAct->setData(RsReputations::OPINION_NEUTRAL) ;
|
||||
flagasneutralAct->setData(static_cast<uint32_t>(RsOpinion::NEUTRAL));
|
||||
connect(flagasneutralAct, SIGNAL(triggered()), this, SLOT(flagperson()));
|
||||
|
||||
QAction *flagasnegativeAct = new QAction(QIcon(IMAGE_NEGATIVE_OPINION), tr("Give negative opinion"), &contextMnu);
|
||||
flagasnegativeAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ;
|
||||
flagasnegativeAct->setData(RsReputations::OPINION_NEGATIVE) ;
|
||||
flagasnegativeAct->setData(static_cast<uint32_t>(RsOpinion::NEGATIVE));
|
||||
connect(flagasnegativeAct, SIGNAL(triggered()), this, SLOT(flagperson()));
|
||||
|
||||
QAction *newthreadAct = new QAction(QIcon(IMAGE_MESSAGE), tr("Start New Thread"), &contextMnu);
|
||||
@ -876,19 +876,19 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
|
||||
#endif
|
||||
contextMnu.addSeparator();
|
||||
|
||||
RsReputations::Opinion op ;
|
||||
RsOpinion op;
|
||||
|
||||
if(!rsIdentity->isOwnId(current_post.mAuthorId) && rsReputations->getOwnOpinion(current_post.mAuthorId,op))
|
||||
{
|
||||
QMenu *submenu1 = contextMnu.addMenu(tr("Author's reputation")) ;
|
||||
|
||||
if(op != RsReputations::OPINION_POSITIVE)
|
||||
if(op != RsOpinion::POSITIVE)
|
||||
submenu1->addAction(flagaspositiveAct);
|
||||
|
||||
if(op != RsReputations::OPINION_NEUTRAL)
|
||||
if(op != RsOpinion::NEUTRAL)
|
||||
submenu1->addAction(flagasneutralAct);
|
||||
|
||||
if(op != RsReputations::OPINION_NEGATIVE)
|
||||
if(op != RsOpinion::NEGATIVE)
|
||||
submenu1->addAction(flagasnegativeAct);
|
||||
}
|
||||
|
||||
@ -1294,8 +1294,10 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t overall_reputation = rsReputations->overallReputationLevel(msg.mMeta.mAuthorId) ;
|
||||
bool redacted = (overall_reputation == RsReputations::REPUTATION_LOCALLY_NEGATIVE) ;
|
||||
RsReputationLevel overall_reputation =
|
||||
rsReputations->overallReputationLevel(msg.mMeta.mAuthorId);
|
||||
bool redacted =
|
||||
(overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool setToReadOnActive = Settings->getForumMsgSetToReadOnActivate();
|
||||
@ -1621,9 +1623,12 @@ void GxsForumThreadWidget::flagperson()
|
||||
return;
|
||||
}
|
||||
|
||||
RsReputations::Opinion opinion = static_cast<RsReputations::Opinion>(qobject_cast<QAction*>(sender())->data().toUInt());
|
||||
RsOpinion opinion =
|
||||
static_cast<RsOpinion>(
|
||||
qobject_cast<QAction*>(sender())->data().toUInt() );
|
||||
|
||||
mThreadModel->setAuthorOpinion(mThreadProxyModel->mapToSource(getCurrentIndex()),opinion);
|
||||
mThreadModel->setAuthorOpinion(
|
||||
mThreadProxyModel->mapToSource(getCurrentIndex()), opinion );
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::replytoforummessage() { async_msg_action( &GxsForumThreadWidget::replyForumMessageData ); }
|
||||
|
@ -38,12 +38,12 @@ PeoplePage::PeoplePage(QWidget * parent, Qt::WindowFlags flags)
|
||||
connect(ui.autoAddFriendIdsAsContact_CB,SIGNAL(toggled(bool)),this,SLOT(updateAutoAddFriendIdsAsContact()));
|
||||
}
|
||||
|
||||
void PeoplePage::updateAutoPositiveOpinion() { rsReputations->setNodeAutoPositiveOpinionForContacts(ui.autoPositiveOpinion_CB->isChecked()) ; }
|
||||
void PeoplePage::updateAutoPositiveOpinion() { rsReputations->setAutoPositiveOpinionForContacts(ui.autoPositiveOpinion_CB->isChecked()) ; }
|
||||
|
||||
void PeoplePage::updateThresholdForRemotelyPositiveReputation() { rsReputations->setThresholdForRemotelyPositiveReputation(ui.thresholdForPositive_SB->value()); }
|
||||
void PeoplePage::updateThresholdForRemotelyNegativeReputation() { rsReputations->setThresholdForRemotelyNegativeReputation(ui.thresholdForNegative_SB->value()); }
|
||||
|
||||
void PeoplePage::updateRememberDeletedNodes() { rsReputations->setRememberDeletedNodesThreshold(ui.preventReloadingBannedIdentitiesFor_SB->value()); }
|
||||
void PeoplePage::updateRememberDeletedNodes() { rsReputations->setRememberBannedIdThreshold(ui.preventReloadingBannedIdentitiesFor_SB->value()); }
|
||||
void PeoplePage::updateDeleteBannedNodesThreshold() { rsIdentity->setDeleteBannedNodesThreshold(ui.deleteBannedIdentitiesAfter_SB->value());}
|
||||
void PeoplePage::updateAutoAddFriendIdsAsContact() { rsIdentity->setAutoAddFriendIdsAsContact(ui.autoAddFriendIdsAsContact_CB->isChecked()) ; }
|
||||
|
||||
@ -54,7 +54,7 @@ PeoplePage::~PeoplePage()
|
||||
/** Loads the settings for this page */
|
||||
void PeoplePage::load()
|
||||
{
|
||||
bool auto_positive_contacts = rsReputations->nodeAutoPositiveOpinionForContacts() ;
|
||||
bool auto_positive_contacts = rsReputations->autoPositiveOpinionForContacts() ;
|
||||
uint32_t threshold_for_positive = rsReputations->thresholdForRemotelyPositiveReputation();
|
||||
uint32_t threshold_for_negative = rsReputations->thresholdForRemotelyNegativeReputation();
|
||||
bool auto_add_friend_ids_as_contact = rsIdentity->autoAddFriendIdsAsContact();
|
||||
@ -64,5 +64,5 @@ void PeoplePage::load()
|
||||
whileBlocking(ui.thresholdForPositive_SB )->setValue(threshold_for_positive);
|
||||
whileBlocking(ui.thresholdForNegative_SB )->setValue(threshold_for_negative);
|
||||
whileBlocking(ui.deleteBannedIdentitiesAfter_SB )->setValue(rsIdentity->deleteBannedNodesThreshold());
|
||||
whileBlocking(ui.preventReloadingBannedIdentitiesFor_SB)->setValue(rsReputations->rememberDeletedNodesThreshold());
|
||||
whileBlocking(ui.preventReloadingBannedIdentitiesFor_SB)->setValue(rsReputations->rememberBannedIdThreshold());
|
||||
}
|
||||
|
@ -241,6 +241,7 @@ rs_v07_changes {
|
||||
DEFINES += V07_NON_BACKWARD_COMPATIBLE_CHANGE_001
|
||||
DEFINES += V07_NON_BACKWARD_COMPATIBLE_CHANGE_002
|
||||
DEFINES += V07_NON_BACKWARD_COMPATIBLE_CHANGE_003
|
||||
DEFINES += V07_NON_BACKWARD_COMPATIBLE_CHANGE_UNNAMED
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user