2012-01-11 23:01:29 +00:00
# ifndef RSGNP_H
# define RSGNP_H
2012-01-18 23:20:53 +00:00
/*
2012-08-06 21:00:38 +00:00
* libretroshare / src / gxs : rsnxs . h
2012-01-18 23:20:53 +00:00
*
2012-02-12 15:29:49 +00:00
* Network Exchange Service interface for RetroShare .
2012-01-18 23:20:53 +00:00
*
* Copyright 2011 - 2011 by Robert Fernie , Christopher Evi - Prker
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Library General Public License for more details .
*
* You should have received a copy of the GNU Library General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307
* USA .
*
* Please report all bugs and problems to " retroshare@lunamutt.com " .
*
*/
2012-01-15 13:07:31 +00:00
# include <set>
2012-01-18 23:20:53 +00:00
# include <string>
2012-01-16 21:52:22 +00:00
# include <time.h>
# include <stdlib.h>
2012-01-18 23:20:53 +00:00
# include <list>
# include <map>
2012-01-15 13:07:31 +00:00
2012-02-12 15:18:05 +00:00
# include "services/p3service.h"
2016-12-26 15:59:53 +01:00
# include "retroshare/rsreputations.h"
# include "retroshare/rsidentity.h"
2012-06-11 21:56:23 +00:00
# include "rsgds.h"
2012-01-19 23:32:27 +00:00
2012-01-11 23:01:29 +00:00
/*!
2012-01-18 23:20:53 +00:00
* Retroshare General Network Exchange Service : \ n
2012-01-19 23:32:27 +00:00
* Interface :
2012-02-12 15:18:05 +00:00
* - This provides a module to service peer ' s requests for GXS messages \ n
2012-01-19 23:32:27 +00:00
* and also request GXS messages from other peers . \ n
2012-02-12 15:18:05 +00:00
* - The general mode of operation is to sychronise all messages / grps between
* peers
*
* The interface is sparse as this service is mostly making the requests to other GXS components
*
* Groups :
2012-06-05 14:46:18 +00:00
* - As this is where exchanges occur between peers , this is also where group ' s relationships
2012-02-12 15:18:05 +00:00
* should get resolved as far as
* - Per implemented GXS there are a set of rules which will determine whether data is transferred
* between any set of groups
*
* 1 allow transfers to any group
* 2 transfers only between group
* - the also group matrix settings which is by default everyone can transfer to each other
2012-01-11 23:01:29 +00:00
*/
2012-07-05 21:26:14 +00:00
class RsNetworkExchangeService
2012-01-11 23:01:29 +00:00
{
public :
2012-01-15 13:07:31 +00:00
2012-07-12 20:18:58 +00:00
RsNetworkExchangeService ( ) { return ; }
2015-06-04 13:06:08 +00:00
virtual ~ RsNetworkExchangeService ( ) { }
2012-06-11 21:56:23 +00:00
2012-01-18 23:20:53 +00:00
/*!
2012-02-12 15:18:05 +00:00
* Use this to set how far back synchronisation of messages should take place
2016-12-04 23:26:48 +01:00
* @ param age in seconds the max age a sync / store item can to be allowed in a synchronisation
2012-01-18 23:20:53 +00:00
*/
2016-12-05 22:14:48 +01:00
virtual void setSyncAge ( const RsGxsGroupId & id , uint32_t age_in_secs ) = 0 ;
virtual void setKeepAge ( const RsGxsGroupId & id , uint32_t age_in_secs ) = 0 ;
virtual uint32_t getSyncAge ( const RsGxsGroupId & id ) = 0 ;
virtual uint32_t getKeepAge ( const RsGxsGroupId & id , uint32_t default_value ) = 0 ;
virtual uint32_t getDefaultSyncAge ( ) = 0 ;
2012-01-15 13:07:31 +00:00
2012-04-01 21:10:55 +00:00
/*!
* Initiates a search through the network
* This returns messages which contains the search terms set in RsGxsSearch
* @ param search contains search terms of requested from service
* @ param hops how far into friend tree for search
* @ return search token that can be redeemed later , implementation should indicate how this should be used
*/
2012-07-05 21:26:14 +00:00
//virtual int searchMsgs(RsGxsSearch* search, uint8_t hops = 1, bool retrieve = 0) = 0;
2012-04-01 21:10:55 +00:00
/*!
* Initiates a search of groups through the network which goes
2012-06-16 13:59:40 +00:00
* a given number of hops deep into your friend network
2012-04-01 21:10:55 +00:00
* @ param search contains search term requested from service
* @ param hops number of hops deep into peer network
* @ return search token that can be redeemed later
*/
2012-07-05 21:26:14 +00:00
//virtual int searchGrps(RsGxsSearch* search, uint8_t hops = 1, bool retrieve = 0) = 0;
2012-04-01 21:10:55 +00:00
/*!
* pauses synchronisation of subscribed groups and request for group id
* from peers
* @ param enabled set to false to disable pause , and true otherwise
*/
2012-07-12 20:18:58 +00:00
virtual void pauseSynchronisation ( bool enabled ) = 0 ;
2012-04-01 21:10:55 +00:00
/*!
* Request for this message is sent through to peers on your network
* and how many hops from them you ' ve indicated
* @ param msgId the messages to retrieve
* @ return request token to be redeemed
*/
2013-10-29 21:29:20 +00:00
virtual int requestMsg ( const RsGxsGrpMsgIdPair & msgId ) = 0 ;
2012-04-01 21:10:55 +00:00
/*!
* Request for this group is sent through to peers on your network
* and how many hops from them you ' ve indicated
* @ param enabled set to false to disable pause , and true otherwise
* @ return request token to be redeemed
*/
2014-03-17 20:56:06 +00:00
virtual int requestGrp ( const std : : list < RsGxsGroupId > & grpId , const RsPeerId & peerId ) = 0 ;
2012-04-01 21:10:55 +00:00
2014-12-16 06:54:15 +00:00
/*!
* returns some stats about this group related to the network visibility .
* For now , only one statistics :
* max_known_messages : max number of messages reported by a friend . This is used to display unsubscribed group content .
*/
virtual bool getGroupNetworkStats ( const RsGxsGroupId & grpId , RsGroupNetworkStats & stats ) = 0 ;
2012-04-01 21:10:55 +00:00
2015-01-28 22:48:59 +00:00
virtual void subscribeStatusChanged ( const RsGxsGroupId & id , bool subscribed ) = 0 ;
2014-10-05 19:14:05 +00:00
/*!
* Request for this group is sent through to peers on your network
* and how many hops from them you ' ve indicated
*/
2015-04-17 21:36:22 +00:00
virtual int sharePublishKey ( const RsGxsGroupId & grpId , const std : : set < RsPeerId > & peers ) = 0 ;
2014-10-05 19:14:05 +00:00
2015-12-17 23:08:02 -05:00
/*!
* \ brief rejectMessage
* Tells the network exchange service to not download this message again , at least for some time ( maybe 24 h or more )
* in order to avoid cluttering the network pipe with copied of this rejected message .
* \ param msgId
*/
virtual void rejectMessage ( const RsGxsMessageId & msgId ) = 0 ;
2016-03-21 23:21:26 -04:00
/*!
* \ brief getGroupServerUpdateTS
* Returns the server update time stamp for that group . This is used for synchronisation of TS between
* various network exchange services , suhc as channels / circles or forums / circles
* \ param gid group for that request
* \ param tm time stamp computed
* \ return false if the group is not found , true otherwise
*/
virtual bool getGroupServerUpdateTS ( const RsGxsGroupId & gid , time_t & grp_server_update_TS , time_t & msg_server_update_TS ) = 0 ;
2016-08-01 14:43:17 +02:00
/*!
* \ brief stampMsgServerUpdateTS
* Updates the msgServerUpdateMap structure to time ( NULL ) , so as to trigger sending msg lists to friends .
* This is needed when e . g . posting a new message to a group .
* \ param gid the group to stamp in msgServerUpdateMap
* \ return
*/
virtual bool stampMsgServerUpdateTS ( const RsGxsGroupId & gid ) = 0 ;
2016-12-26 15:59:53 +01:00
2017-01-19 23:59:26 +01:00
/*!
* \ brief removeGroups
* Removes time stamp information from the list of groups . This allows to re - sync them if suppliers are present .
* \ param groups list of groups to remove from the update maps
* \ return true if nothing bad happens .
*/
virtual bool removeGroups ( const std : : list < RsGxsGroupId > & groups ) = 0 ;
2016-12-26 15:59:53 +01:00
/*!
* \ brief minReputationForForwardingMessages
* Encodes the policy for sending / requesting messages depending on anti - spam settings .
*
* \ param group_sign_flags Sign flags from the group meta data
* \ param identity_flags Flags of the identity
* \ return
*/
static RsReputations : : ReputationLevel 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 ;
}
static RsReputations : : ReputationLevel 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
2016-12-29 21:54:50 +01:00
// equal to the minimal reputation in the table below (R=remotely, L=locally, P=positive, N=negative, O=neutral) :
2016-12-26 15:59:53 +01:00
//
2016-12-31 13:42:29 +01:00
//
// +----------------------------------------------------+
// | Identity flags |
// +----------------------------------------------------+
// | Anonymous Signed Signed+Known |
// +-------------+-----------+----------------------------------------------------+
// | |NONE | O O O |
// | Forum flags |GPG_AUTHED | RP O O |
// | |GPG_KNOWN | RP RP O |
// +-------------+-----------+----------------------------------------------------+
2016-12-26 15:59:53 +01:00
//
if ( identity_flags & RS_IDENTITY_FLAGS_PGP_KNOWN )
2016-12-29 21:54:50 +01:00
return RsReputations : : REPUTATION_NEUTRAL ;
2016-12-26 15:59:53 +01:00
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 ;
else
2016-12-29 21:54:50 +01:00
return RsReputations : : REPUTATION_NEUTRAL ;
2016-12-26 15:59:53 +01:00
}
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 ;
else
2016-12-29 21:54:50 +01:00
return RsReputations : : REPUTATION_NEUTRAL ;
2016-12-26 15:59:53 +01:00
}
}
2012-01-11 23:01:29 +00:00
} ;
# endif // RSGNP_H