2012-06-07 16:43:12 -04:00
|
|
|
#ifndef RSGXSNETSERVICE_H
|
|
|
|
#define RSGXSNETSERVICE_H
|
|
|
|
|
2012-08-06 17:00:38 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/gxs: rsgxnetservice.h
|
|
|
|
*
|
|
|
|
* Access to rs network and synchronisation service implementation
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Christopher Evi-Parker
|
|
|
|
*
|
|
|
|
* 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-06-07 16:43:12 -04:00
|
|
|
#include <list>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include "rsnxs.h"
|
|
|
|
#include "rsgds.h"
|
|
|
|
#include "rsnxsobserver.h"
|
2012-07-05 17:26:14 -04:00
|
|
|
#include "pqi/p3linkmgr.h"
|
2012-06-07 16:43:12 -04:00
|
|
|
#include "serialiser/rsnxsitems.h"
|
2013-11-16 08:40:04 -05:00
|
|
|
#include "serialiser/rsgxsupdateitems.h"
|
2013-06-04 17:00:43 -04:00
|
|
|
#include "rsgxsnetutils.h"
|
2012-06-07 16:43:12 -04:00
|
|
|
#include "pqi/p3cfgmgr.h"
|
2013-06-04 17:00:43 -04:00
|
|
|
#include "rsgixs.h"
|
2014-04-18 17:58:14 -04:00
|
|
|
#include "util/rssharedptr.h"
|
2012-06-11 17:56:23 -04:00
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
/// keep track of transaction number
|
|
|
|
typedef std::map<uint32_t, NxsTransaction*> TransactionIdMap;
|
|
|
|
|
|
|
|
/// to keep track of peers active transactions
|
2014-03-17 16:56:06 -04:00
|
|
|
typedef std::map<RsPeerId, TransactionIdMap > TransactionsPeerMap;
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2014-04-27 09:14:07 -04:00
|
|
|
class PgpAuxUtils;
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2014-12-16 01:54:15 -05:00
|
|
|
class RsGroupNetworkStatsRecord
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsGroupNetworkStatsRecord() { max_visible_count= 0 ; }
|
|
|
|
|
|
|
|
std::set<RsPeerId> suppliers ;
|
|
|
|
uint32_t max_visible_count ;
|
|
|
|
};
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
/*!
|
2012-07-12 16:18:58 -04:00
|
|
|
* This class implements the RsNetWorkExchangeService
|
|
|
|
* using transactions to handle synchrnisation of Nxs items between
|
|
|
|
* peers in a network
|
2013-03-06 18:33:23 -05:00
|
|
|
* Transactions requires the maintenance of several states between peers
|
2012-07-12 16:18:58 -04:00
|
|
|
*
|
|
|
|
* Thus a data structure maintains: peers, and their active transactions
|
|
|
|
* Then for each transaction it needs to be noted if this is an outgoing or incoming transaction
|
|
|
|
* Outgoing transaction are in 3 different states:
|
|
|
|
* 1. START 2. INITIATED 3. SENDING 4. END
|
2013-03-06 18:33:23 -05:00
|
|
|
* Incoming transaction are in 3 different states
|
2012-07-12 16:18:58 -04:00
|
|
|
* 1. START 2. RECEIVING 3. END
|
2012-06-07 16:43:12 -04:00
|
|
|
*/
|
2012-07-05 17:26:14 -04:00
|
|
|
class RsGxsNetService : public RsNetworkExchangeService, public p3ThreadedService,
|
2012-06-07 16:43:12 -04:00
|
|
|
public p3Config
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
typedef RsSharedPtr<RsGxsNetService> pointer;
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
static const uint32_t FRAGMENT_SIZE;
|
2012-06-07 16:43:12 -04:00
|
|
|
/*!
|
|
|
|
* only one observer is allowed
|
|
|
|
* @param servType service type
|
|
|
|
* @param gds The data service which allows read access to a service/store
|
|
|
|
* @param nxsObs observer will be notified whenever new messages/grps
|
2013-06-04 17:00:43 -04:00
|
|
|
* @param nxsObs observer will be notified whenever new messages/grps
|
2012-06-07 16:43:12 -04:00
|
|
|
* arrive
|
|
|
|
*/
|
2014-03-21 23:53:44 -04:00
|
|
|
RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
2015-06-30 04:12:51 -04:00
|
|
|
RsNxsNetMgr *netMgr,
|
|
|
|
RsNxsObserver *nxsObs, // used to be = NULL.
|
|
|
|
const RsServiceInfo serviceInfo,
|
|
|
|
RsGixsReputation* reputations = NULL, RsGcxs* circles = NULL,
|
|
|
|
PgpAuxUtils *pgpUtils = NULL,
|
|
|
|
bool grpAutoSync = true, bool msgAutoSync = true);
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-07-12 16:18:58 -04:00
|
|
|
virtual ~RsGxsNetService();
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
virtual RsServiceInfo getServiceInfo() { return mServiceInfo; }
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Use this to set how far back synchronisation of messages should take place
|
|
|
|
* @param age the max age a sync item can to be allowed in a synchronisation
|
|
|
|
*/
|
2015-04-28 08:11:31 -04:00
|
|
|
// NOT IMPLEMENTED
|
2014-10-07 17:42:44 -04:00
|
|
|
virtual void setSyncAge(uint32_t age);
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* pauses synchronisation of subscribed groups and request for group id
|
|
|
|
* from peers
|
|
|
|
* @param enabled set to false to disable pause, and true otherwise
|
|
|
|
*/
|
2015-04-28 08:11:31 -04:00
|
|
|
// NOT IMPLEMENTED
|
2014-10-07 17:42:44 -04:00
|
|
|
virtual void pauseSynchronisation(bool enabled);
|
2012-06-07 16:43:12 -04: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
|
|
|
|
*/
|
2014-10-07 17:42:44 -04:00
|
|
|
virtual int requestMsg(const RsGxsGrpMsgIdPair& /* msgId */){ return 0;}
|
2012-06-07 16:43:12 -04: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-10-07 17:42:44 -04:00
|
|
|
virtual int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId);
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2014-10-05 15:14:05 -04:00
|
|
|
/*!
|
|
|
|
* share publish keys for the specified group with the peers in the specified list.
|
|
|
|
*/
|
|
|
|
|
2015-04-17 17:36:22 -04:00
|
|
|
virtual int sharePublishKey(const RsGxsGroupId& grpId,const std::set<RsPeerId>& peers) ;
|
2014-10-07 17:42:44 -04:00
|
|
|
|
2014-12-16 01:54:15 -05:00
|
|
|
/*!
|
|
|
|
* Returns statistics for the group networking activity: popularity (number of friends subscribers) and max_visible_msg_count,
|
|
|
|
* that is the max nnumber of messages reported by a friend.
|
|
|
|
*/
|
|
|
|
virtual bool getGroupNetworkStats(const RsGxsGroupId& id,RsGroupNetworkStats& stats) ;
|
2012-07-12 16:18:58 -04:00
|
|
|
|
2015-01-28 17:48:59 -05:00
|
|
|
/*!
|
|
|
|
* Used to inform the net service that we changed subscription status. That helps
|
|
|
|
* optimising data transfer when e.g. unsubsribed groups are updated less often, etc
|
|
|
|
*/
|
|
|
|
virtual void subscribeStatusChanged(const RsGxsGroupId& id,bool subscribed) ;
|
|
|
|
|
2014-10-05 15:14:05 -04:00
|
|
|
/* p3Config methods */
|
2012-07-12 16:18:58 -04:00
|
|
|
public:
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-07-12 16:18:58 -04:00
|
|
|
bool loadList(std::list<RsItem *>& load);
|
|
|
|
bool saveList(bool &cleanup, std::list<RsItem *>&);
|
|
|
|
RsSerialiser *setupSerialiser();
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* initiates synchronisation
|
|
|
|
*/
|
2012-06-11 17:56:23 -04:00
|
|
|
int tick();
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Processes transactions and job queue
|
|
|
|
*/
|
2015-05-22 16:54:38 -04:00
|
|
|
virtual void data_tick();
|
2012-06-07 16:43:12 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* called when
|
|
|
|
* items are deemed to be waiting in p3Service item queue
|
|
|
|
*/
|
|
|
|
void recvNxsItemQueue();
|
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
|
|
|
|
/** S: Transaction processing **/
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-11 17:56:23 -04:00
|
|
|
* These process transactions which are in a wait state
|
|
|
|
* Also moves transaction which have been completed to
|
|
|
|
* the completed transactions list
|
2012-06-07 16:43:12 -04:00
|
|
|
*/
|
2012-06-11 17:56:23 -04:00
|
|
|
void processTransactions();
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-11 17:56:23 -04:00
|
|
|
* Process completed transaction, which either simply
|
|
|
|
* retires a transaction or additionally generates a response
|
|
|
|
* to the completed transaction
|
2012-06-07 16:43:12 -04:00
|
|
|
*/
|
2012-06-11 17:56:23 -04:00
|
|
|
void processCompletedTransactions();
|
|
|
|
|
2012-07-14 13:59:54 -04:00
|
|
|
/*!
|
|
|
|
* Process transaction owned/started by user
|
|
|
|
* @param tr transaction to process, ownership stays with callee
|
|
|
|
*/
|
2012-07-15 08:38:20 -04:00
|
|
|
void locked_processCompletedOutgoingTrans(NxsTransaction* tr);
|
2012-07-14 13:59:54 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Process transactions started/owned by other peers
|
|
|
|
* @param tr transaction to process, ownership stays with callee
|
|
|
|
*/
|
2012-07-15 08:38:20 -04:00
|
|
|
void locked_processCompletedIncomingTrans(NxsTransaction* tr);
|
2012-07-14 13:59:54 -04:00
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-11 17:56:23 -04:00
|
|
|
* Process a transaction item, assumes a general lock
|
|
|
|
* @param item the transaction item to process
|
2014-07-05 08:29:40 -04:00
|
|
|
* @return false ownership of item left with callee
|
2012-06-07 16:43:12 -04:00
|
|
|
*/
|
2012-06-11 17:56:23 -04:00
|
|
|
bool locked_processTransac(RsNxsTransac* item);
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* This adds a transaction
|
|
|
|
* completeted transaction list
|
|
|
|
* If this is an outgoing transaction, transaction id is
|
|
|
|
* decrement
|
|
|
|
* @param trans transaction to add
|
|
|
|
*/
|
|
|
|
void locked_completeTransaction(NxsTransaction* trans);
|
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/*!
|
|
|
|
* This retrieves a unique transaction id that
|
|
|
|
* can be used in an outgoing transaction
|
|
|
|
*/
|
2012-07-15 08:38:20 -04:00
|
|
|
uint32_t locked_getTransactionId();
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/*!
|
|
|
|
* This attempts to push the transaction id counter back if you have
|
|
|
|
* active outgoing transactions in play
|
|
|
|
*/
|
2012-06-07 16:43:12 -04:00
|
|
|
bool attemptRecoverIds();
|
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/*!
|
|
|
|
* The cb listener is the owner of the grps
|
|
|
|
* @param grps
|
|
|
|
*/
|
2012-07-12 16:18:58 -04:00
|
|
|
//void notifyListenerGrps(std::list<RsNxsGrp*>& grps);
|
2012-06-11 17:56:23 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* The cb listener is the owner of the msgs
|
|
|
|
* @param msgs
|
|
|
|
*/
|
2012-07-12 16:18:58 -04:00
|
|
|
//void notifyListenerMsgs(std::list<RsNxsMsg*>& msgs);
|
2012-06-11 17:56:23 -04:00
|
|
|
|
|
|
|
/*!
|
2012-07-14 13:59:54 -04:00
|
|
|
* Generates new transaction to send msg requests based on list
|
|
|
|
* of msgs received from peer stored in passed transaction
|
2012-06-11 17:56:23 -04:00
|
|
|
* @param tr transaction responsible for generating msg request
|
|
|
|
*/
|
2012-09-04 18:32:52 -04:00
|
|
|
void locked_genReqMsgTransaction(NxsTransaction* tr);
|
2012-06-11 17:56:23 -04:00
|
|
|
|
|
|
|
/*!
|
2012-07-14 13:59:54 -04:00
|
|
|
* Generates new transaction to send grp requests based on list
|
|
|
|
* of grps received from peer stored in passed transaction
|
2012-06-11 17:56:23 -04:00
|
|
|
* @param tr transaction responsible for generating grp request
|
|
|
|
*/
|
2012-09-04 18:32:52 -04:00
|
|
|
void locked_genReqGrpTransaction(NxsTransaction* tr);
|
|
|
|
|
|
|
|
/*!
|
2014-04-26 19:48:33 -04:00
|
|
|
* This first checks if one can send a grpId based circles
|
|
|
|
* If it can send, then it call locked_genSendMsgsTransaction
|
2012-09-04 18:32:52 -04:00
|
|
|
* @param tr transaction responsible for generating grp request
|
2014-04-26 19:48:33 -04:00
|
|
|
* @see locked_genSendMsgsTransaction
|
2012-09-04 18:32:52 -04:00
|
|
|
*/
|
2014-04-26 19:48:33 -04:00
|
|
|
void locked_checkSendMsgsTransaction(NxsTransaction* tr);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Generates new transaction to send msg data based on list
|
|
|
|
* of grpids received from peer stored in passed transaction
|
|
|
|
* @param tr transaction responsible for generating grp request
|
|
|
|
*/
|
|
|
|
void locked_genSendMsgsTransaction(NxsTransaction* tr);
|
2012-09-04 18:32:52 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Generates new transaction to send grp data based on list
|
|
|
|
* of grps received from peer stored in passed transaction
|
|
|
|
* @param tr transaction responsible for generating grp request
|
|
|
|
*/
|
|
|
|
void locked_genSendGrpsTransaction(NxsTransaction* tr);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* convenience function to add a transaction to list
|
|
|
|
* @param tr transaction to add
|
|
|
|
*/
|
|
|
|
bool locked_addTransaction(NxsTransaction* tr);
|
|
|
|
|
|
|
|
void cleanTransactionItems(NxsTransaction* tr) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @param tr the transaction to check for timeout
|
|
|
|
* @return false if transaction has timed out, true otherwise
|
|
|
|
*/
|
|
|
|
bool locked_checkTransacTimedOut(NxsTransaction* tr);
|
|
|
|
|
|
|
|
/** E: Transaction processing **/
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/** S: item handlers **/
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/*!
|
|
|
|
* This attempts handles transaction items
|
|
|
|
* ownership of item is left with callee if this method returns false
|
|
|
|
* @param item transaction item to handle
|
|
|
|
* @return false if transaction could not be handled, ownership of item is left with callee
|
|
|
|
*/
|
|
|
|
bool handleTransaction(RsNxsItem* item);
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/*!
|
|
|
|
* Handles an nxs item for group synchronisation
|
2012-07-12 16:18:58 -04:00
|
|
|
* by startin a transaction and sending a list
|
|
|
|
* of groups held by user
|
|
|
|
* @param item contains grp sync info
|
2012-06-11 17:56:23 -04:00
|
|
|
*/
|
|
|
|
void handleRecvSyncGroup(RsNxsSyncGrp* item);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Handles an nxs item for msgs synchronisation
|
|
|
|
* @param item contaims msg sync info
|
|
|
|
*/
|
|
|
|
void handleRecvSyncMessage(RsNxsSyncMsg* item);
|
|
|
|
|
2014-10-05 15:14:05 -04:00
|
|
|
/*!
|
|
|
|
* Handles an nxs item for group publish key
|
|
|
|
* @param item contaims keys/grp info
|
|
|
|
*/
|
|
|
|
void handleRecvPublishKeys(RsNxsGroupPublishKeyItem*) ;
|
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
/** E: item handlers **/
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
void runVetting();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @param peerId The peer to vet to see if they can receive this groupid
|
|
|
|
* @param grpMeta this is the meta item to determine if it can be sent to given peer
|
|
|
|
* @param toVet groupid/peer to vet are stored here if their circle id is not cached
|
|
|
|
* @return false, if you cannot send to this peer, true otherwise
|
|
|
|
*/
|
2014-03-17 16:56:06 -04:00
|
|
|
bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet);
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId);
|
2013-06-04 17:00:43 -04:00
|
|
|
|
2014-05-01 14:50:07 -04:00
|
|
|
bool checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& meta);
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
void locked_createTransactionFromPending(MsgRespPending* grpPend);
|
|
|
|
void locked_createTransactionFromPending(GrpRespPending* msgPend);
|
|
|
|
void locked_createTransactionFromPending(GrpCircleIdRequestVetting* grpPend);
|
|
|
|
void locked_createTransactionFromPending(MsgCircleIdsRequestVetting* grpPend);
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
void locked_pushMsgTransactionFromList(std::list<RsNxsItem*>& reqList, const RsPeerId& peerId, const uint32_t& transN);
|
|
|
|
void locked_pushGrpTransactionFromList(std::list<RsNxsItem*>& reqList, const RsPeerId& peerId, const uint32_t& transN);
|
|
|
|
void locked_pushGrpRespFromList(std::list<RsNxsItem*>& respList, const RsPeerId& peer, const uint32_t& transN);
|
|
|
|
void locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const RsPeerId& sslId, const uint32_t& transN);
|
2012-07-12 16:18:58 -04:00
|
|
|
void syncWithPeers();
|
2013-06-04 17:00:43 -04:00
|
|
|
void addGroupItemToList(NxsTransaction*& tr,
|
2014-03-17 16:56:06 -04:00
|
|
|
const RsGxsGroupId& grpId, uint32_t& transN,
|
2013-06-04 17:00:43 -04:00
|
|
|
std::list<RsNxsItem*>& reqList);
|
|
|
|
|
2014-10-24 17:31:58 -04:00
|
|
|
//bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const RsPeerId& peerId);
|
2012-07-12 16:18:58 -04:00
|
|
|
|
2013-10-29 17:29:20 -04:00
|
|
|
void processExplicitGroupRequests();
|
2014-10-05 15:14:05 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
void locked_doMsgUpdateWork(const RsNxsTransac* nxsTrans, const RsGxsGroupId& grpId);
|
2013-10-29 17:29:20 -04:00
|
|
|
|
2013-11-23 18:39:55 -05:00
|
|
|
void updateServerSyncTS();
|
2015-12-13 18:22:04 -05:00
|
|
|
void updateClientSyncTS();
|
2013-11-23 18:39:55 -05:00
|
|
|
|
2013-11-25 17:28:17 -05:00
|
|
|
bool locked_CanReceiveUpdate(const RsNxsSyncGrp* item);
|
|
|
|
bool locked_CanReceiveUpdate(const RsNxsSyncMsg* item);
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
private:
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
typedef std::vector<RsNxsGrp*> GrpFragments;
|
|
|
|
typedef std::vector<RsNxsMsg*> MsgFragments;
|
|
|
|
|
2014-10-05 15:14:05 -04:00
|
|
|
/*!
|
|
|
|
* Loops over pending publish key orders.
|
|
|
|
*/
|
|
|
|
void sharePublishKeysPending() ;
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
/*!
|
|
|
|
* Fragment a message into individual fragments which are at most 150kb
|
|
|
|
* @param msg message to fragment
|
|
|
|
* @param msgFragments fragmented message
|
|
|
|
* @return false if fragmentation fails true otherwise
|
|
|
|
*/
|
|
|
|
bool fragmentMsg(RsNxsMsg& msg, MsgFragments& msgFragments) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Fragment a group into individual fragments which are at most 150kb
|
|
|
|
* @param grp group to fragment
|
|
|
|
* @param grpFragments fragmented group
|
|
|
|
* @return false if fragmentation fails true other wise
|
|
|
|
*/
|
|
|
|
bool fragmentGrp(RsNxsGrp& grp, GrpFragments& grpFragments) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Fragment a message into individual fragments which are at most 150kb
|
|
|
|
* @param msg message to fragment
|
|
|
|
* @param msgFragments fragmented message
|
|
|
|
* @return NULL if not possible to reconstruct message from fragment,
|
|
|
|
* pointer to defragments nxs message is possible
|
|
|
|
*/
|
|
|
|
RsNxsMsg* deFragmentMsg(MsgFragments& msgFragments) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Fragment a group into individual fragments which are at most 150kb
|
|
|
|
* @param grp group to fragment
|
|
|
|
* @param grpFragments fragmented group
|
|
|
|
* @return NULL if not possible to reconstruct group from fragment,
|
|
|
|
* pointer to defragments nxs group is possible
|
|
|
|
*/
|
|
|
|
RsNxsGrp* deFragmentGrp(GrpFragments& grpFragments) const;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Note that if all fragments for a message are not found then its fragments are dropped
|
|
|
|
* @param fragments message fragments which are not necessarily from the same message
|
|
|
|
* @param partFragments the partitioned fragments (into message ids)
|
|
|
|
*/
|
|
|
|
void collateMsgFragments(MsgFragments fragments, std::map<RsGxsMessageId, MsgFragments>& partFragments) const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Note that if all fragments for a group are not found then its fragments are dropped
|
|
|
|
* @param fragments group fragments which are not necessarily from the same group
|
|
|
|
* @param partFragments the partitioned fragments (into message ids)
|
|
|
|
*/
|
|
|
|
void collateGrpFragments(GrpFragments fragments, std::map<RsGxsGroupId, GrpFragments>& partFragments) const;
|
2015-01-30 15:46:58 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* stamp the group info from that particular peer at the given time.
|
|
|
|
*/
|
|
|
|
|
2015-01-31 13:06:37 -05:00
|
|
|
void locked_stampPeerGroupUpdateTime(const RsPeerId& pid,const RsGxsGroupId& grpId,time_t tm,uint32_t n_messages) ;
|
2015-01-30 15:46:58 -05:00
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
/*** transactions ***/
|
|
|
|
|
|
|
|
/// active transactions
|
2012-06-11 17:56:23 -04:00
|
|
|
TransactionsPeerMap mTransactions;
|
2012-06-07 16:43:12 -04:00
|
|
|
|
|
|
|
/// completed transactions
|
|
|
|
std::list<NxsTransaction*> mComplTransactions;
|
|
|
|
|
2012-07-12 16:18:58 -04:00
|
|
|
/// transaction id counter
|
2012-06-07 16:43:12 -04:00
|
|
|
uint32_t mTransactionN;
|
|
|
|
|
|
|
|
/*** transactions ***/
|
|
|
|
|
|
|
|
/*** synchronisation ***/
|
2012-06-11 17:56:23 -04:00
|
|
|
std::list<RsNxsSyncGrp*> mSyncGrp;
|
|
|
|
std::list<RsNxsSyncMsg*> mSyncMsg;
|
2012-06-07 16:43:12 -04:00
|
|
|
/*** synchronisation ***/
|
|
|
|
|
|
|
|
RsNxsObserver* mObserver;
|
|
|
|
RsGeneralDataService* mDataStore;
|
|
|
|
uint16_t mServType;
|
2012-07-14 13:59:54 -04:00
|
|
|
|
|
|
|
// how much time must elapse before a timeout failure
|
|
|
|
// for an active transaction
|
2012-06-11 17:56:23 -04:00
|
|
|
uint32_t mTransactionTimeOut;
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId mOwnId;
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
RsNxsNetMgr* mNetMgr;
|
|
|
|
|
2012-06-07 16:43:12 -04:00
|
|
|
/// for other members save transactions
|
|
|
|
RsMutex mNxsMutex;
|
|
|
|
|
2012-07-12 16:18:58 -04:00
|
|
|
uint32_t mSyncTs;
|
2014-10-05 15:14:05 -04:00
|
|
|
uint32_t mLastKeyPublishTs;
|
2012-09-04 18:32:52 -04:00
|
|
|
|
2012-07-12 16:18:58 -04:00
|
|
|
const uint32_t mSYNC_PERIOD;
|
2015-05-22 16:54:38 -04:00
|
|
|
int mUpdateCounter ;
|
2012-07-12 16:18:58 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
RsGcxs* mCircles;
|
|
|
|
RsGixsReputation* mReputations;
|
2014-04-27 09:14:07 -04:00
|
|
|
PgpAuxUtils *mPgpUtils;
|
2013-11-03 18:46:34 -05:00
|
|
|
bool mGrpAutoSync;
|
2015-06-30 04:12:51 -04:00
|
|
|
bool mAllowMsgSync;
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
// need to be verfied
|
|
|
|
std::vector<AuthorPending*> mPendingResp;
|
|
|
|
std::vector<GrpCircleVetting*> mPendingCircleVets;
|
2015-04-17 17:36:22 -04:00
|
|
|
std::map<RsGxsGroupId,std::set<RsPeerId> > mPendingPublishKeyRecipients ;
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, std::list<RsGxsGroupId> > mExplicitRequest;
|
2014-12-02 15:06:56 -05:00
|
|
|
std::map<RsPeerId, std::set<RsGxsGroupId> > mPartialMsgUpdates ;
|
2013-11-16 08:40:04 -05:00
|
|
|
|
|
|
|
// nxs sync optimisation
|
|
|
|
// can pull dynamically the latest timestamp for each message
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
typedef std::map<RsPeerId, RsGxsMsgUpdateItem*> ClientMsgMap;
|
|
|
|
typedef std::map<RsGxsGroupId, RsGxsServerMsgUpdateItem*> ServerMsgMap;
|
|
|
|
typedef std::map<RsPeerId, RsGxsGrpUpdateItem*> ClientGrpMap;
|
2013-11-16 08:40:04 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ClientMsgMap mClientMsgUpdateMap;
|
|
|
|
ServerMsgMap mServerMsgUpdateMap;
|
|
|
|
ClientGrpMap mClientGrpUpdateMap;
|
|
|
|
|
2014-12-16 01:54:15 -05:00
|
|
|
std::map<RsGxsGroupId,RsGroupNetworkStatsRecord> mGroupNetworkStats ;
|
2014-10-07 17:42:44 -04:00
|
|
|
|
2013-11-16 08:40:04 -05:00
|
|
|
RsGxsServerGrpUpdateItem* mGrpServerUpdateItem;
|
2014-03-21 23:53:44 -04:00
|
|
|
RsServiceInfo mServiceInfo;
|
2015-12-11 19:01:20 -05:00
|
|
|
|
|
|
|
void debugDump();
|
2012-06-07 16:43:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RSGXSNETSERVICE_H
|