sorry this temporarily won't build, will fix tomorrow

using this as jump point to transfer dev'n to my laptop

nxs observer added
started to updated nxmMsg with original id and nxsItems with transaction ids
Added and netservice guts


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5201 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-06-07 20:43:12 +00:00
parent bf4c250e51
commit e4ecd898af
8 changed files with 507 additions and 67 deletions

View File

@ -1,9 +1,13 @@
#ifndef RSGENEXCHANGE_H
#define RSGENEXCHANGE_H
#include <queue>
#include "rsgxs.h"
#include "serialiser/rsnxsitems.h"
class RsGenExchange // : public RsGxsService
{

View File

@ -39,6 +39,9 @@
#include <map>
#include "serialiser/rsgxsitems.h"
#include "rsnxsobserver.h"
#include "rsnxs.h"
#include "rsgds.h"
#define GXS_STATUS_GRP_NOT_FOUND 1 /* request resulted in grp not found error */
#define GXS_STATUS_MSG_NOT_FOUND 2 /* request resulted in msg not found */
@ -105,16 +108,23 @@ public:
* - all data is received via call back \n
* - therefore interface to UI should not be based on being alerted to msg availability \n
*/
class RsGxsService
class RsGxsService : public RsNxsObserver
{
public:
RsGxsService(RsGxsSearchModule* mod);
RsGxsService(RsGeneralDataService* gds, RsNetworkExchangeService* ns);
virtual ~RsGxsService();
/***************** Group request receive API ********************/
/*!
* It is critical this service implements
* this function and returns a valid service id
* @return the service type of the Gxs Service
*/
virtual uint16_t getServiceType() const = 0;
/*!
* Request group, not intialising version member of RsGxsGrpId
* results in the latest version of groups being returned
@ -290,6 +300,7 @@ public:
/******************* Start: Configuration *************************/
/*!
* How long to keep subscribed groups
* @param length how long to keep group in seconds
@ -320,6 +331,8 @@ public:
*/
int requestSubscribeToGrp(const std::string& grpId, bool subscribe);
public:
/*!
* This called by event runner on status of subscription
* @param token the token to be redeemed
@ -370,29 +383,6 @@ public:
*/
int requestLocalSearch(RsGxsSearch* term);
// Remote Search...(2 hops ?)
/*!
*
* @param term This contains the search term
* @param hops how many hops from your immediate peer on the network for search
* @param delay lenght of time search should persist (if you are online search will be saved \n
* delay seconds, max is 2 days
* @return token to redeem search
*/
int requestRemoteSearchGrps(RsGxsSearch* term, uint32_t hops, uint32_t delay, bool immediate);
// Remote Search...(2 hops ?)
/*!
*
* @param term This contains the search term
* @param hops how many hops from your immediate peer on the network for search
* @param delay lenght of time search should persist (if you are online search will be saved \n
* delay seconds, max is 2 days
* @return token to redeem search
*/
int requestRemoteSearchMsgs(RsGxsSearch* term, uint32_t hops, uint32_t delay, bool immediate);
/*!
*
* @param token
@ -425,6 +415,33 @@ public:
*/
virtual void recieveRemoteSearchMsgs(int token, int errCode, std::list<RsGxsMsg*>& msgs) = 0;
/* the following are protected to prevent RsGxsNetService calling below
* and causing infinite recursion
*/
// Remote Search...(2 hops ?)
/*!
*
* @param term This contains the search term
* @param hops how many hops from your immediate peer on the network for search
* @param delay lenght of time search should persist (if you are online search will be saved \n
* delay seconds, max is 2 days
* @return token to redeem search
*/
int requestRemoteSearchGrps(RsGxsSearch* term, uint32_t hops, uint32_t delay, bool immediate);
// Remote Search...(2 hops ?)
/*!
*
* @param term This contains the search term
* @param hops how many hops from your immediate peer on the network for search
* @param delay lenght of time search should persist (if you are online search will be saved \n
* delay seconds, max is 2 days
* @return token to redeem search
*/
int requestRemoteSearchMsgs(RsGxsSearch* term, uint32_t hops, uint32_t delay, bool immediate);
/*!
* Note if parent group is not present this will be requested \n
* by the event runner
@ -432,14 +449,14 @@ public:
* @return token to be redeemed
* @see receiveMsg()
*/
virtual int requestRemoteMsg(std::list<RsGxsMsgId>& msgIds);
int requestRemoteMsg(std::list<RsGxsMsgId>& msgIds);
/*!
* @param grpIds the ids of the group being requested
* @return token to be redeemed
* @see receiveGrp()
*/
virtual int requestRemoteGrp(std::list<RsGxsGrpId>& grpIds);
int requestRemoteGrp(std::list<RsGxsGrpId>& grpIds);
/****************** End: Search from event runner ***************/

View File

@ -0,0 +1,99 @@
#include "rsgxsnetservice.h"
RsGxsNetService::RsGxsNetService(uint16_t servType,
RsGeneralDataService *gds, RsNxsObserver *nxsObs)
: mServType(servType), mDataStore(gds), mObserver(nxsObs)
{
}
void RsGxsNetService::tick(){
if(receivedItems())
recvNxsItemQueue();
}
void RsGxsNetService::recvNxsItemQueue(){
RsItem *item ;
while(NULL != (item=recvItem()))
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService Item:" << (void*)item << std::endl ;
#endif
// RsNxsItem needs dynamic_cast, since they have derived siblings.
//
RsNxsItem *ni = dynamic_cast<RsNxsItem*>(item) ;
if(ni != NULL)
{
if(ni->transactionNumber != 0){
// accumulate
if(handleTransactionContent(ci))
delete ni ;
continue ; // don't delete! It's handled by handleRecvChatMsgItem in some specific cases only.
}
switch(ni->PacketSubType())
{
case RS_PKT_SUBTYPE_NXS_SYNC_GRP: handleRecvSyncGroup (dynamic_cast<RsSyncGrp*>(ni)) ; break ;
case RS_PKT_SUBTYPE_NXS_SYNC_MSG: handleRecvSyncMessage (dynamic_cast<RsSyncGrpMsg*>(ni)) ; break ;
case RS_PKT_SUBTYPE_NXS_TRANS: handleRecvTransaction (dynamic_cast<RsNxsTransac*>(ni)) ; break;
default:
std::cerr << "Unhandled item subtype " << ni->PacketSubType() << " in RsGxsNetService: " << std::endl;
}
delete item ;
}
}
}
}
void RsGxsNetService::run(){
double timeDelta = 0.2;
while(isRunning()){
#ifndef WINDOWS_SYS
usleep((int) (timeDelta * 1000000));
#else
Sleep((int) (timeDelta * 1000));
#endif
processTransactions();
processCompleteTransactions();
processSyncRequests();
}
}
void RsGxsNetService::recvItem(){
}
/** NxsTransaction definition **/
NxsTransaction::NxsTransaction()
:mTransaction(NULL), mFlag(0), mTimestamp(0) {
}
NxsTransaction::~NxsTransaction(){
}

View File

@ -0,0 +1,249 @@
#ifndef RSGXSNETSERVICE_H
#define RSGXSNETSERVICE_H
#include <list>
#include <queue>
#include "rsnxs.h"
#include "rsgds.h"
#include "rsnxsobserver.h"
#include "serialiser/rsnxsitems.h"
#include "pqi/p3cfgmgr.h"
/*!
* This represents a transaction made
* with the NxsNetService in all states
* of operation untill completion
*/
class NxsTransaction
{
public:
static const uint8_t FLAG_STATE_RECEIVING;
static const uint8_t FLAG_STATE_DONE;
static const uint8_t FLGA_STATE_COMPLETED;
NxsTransaction();
~NxsTransaction();
uint32_t mFlag; // current state of transaction
uint32_t mTimestamp;
/*!
* this contains who we
* c what peer this transaction involves.
* c The type of transaction
* c transaction id
* c timeout set for this transaction
* c and itemCount
*/
RsNxsTransac* mTransaction;
std::list<RsNxsItem*> mItems; // items received or sent
};
/// keep track of transaction number
typedef std::map<uint32_t, NxsTransaction*> TransactionIdMap;
/// to keep track of peers active transactions
typedef std::map<std::string, TransactionIdMap > TransactionsPeerMap;
/*!
*
*
*/
class RsGxsNetService : public RsNetworkExchangeService, public RsThread,
public p3Config
{
public:
/*!
* 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
* arrive
*/
RsGxsNetService(uint16_t servType, RsGeneralDataService* gds, RsNxsObserver* nxsObs = NULL);
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
*/
void setSyncAge(uint32_t age);
/*!
* Explicitly requests all the groups contained by a peer
* Circumvents polling of peers for message
* @param peerId id of peer
*/
void requestGroupsOfPeer(const std::string& peerId);
/*!
* get messages of a peer for a given group id, this circumvents the normal
* polling of peers for messages of given group id
* @param peerId Id of peer
* @param grpId id of group to request messages for
*/
void requestMessagesOfPeer(const std::string& peerId, const RsGroupId& grpId);
/*!
* subscribes the associated service to this group. This RsNetworktExchangeService
* now regularly polls all peers for new messages of this group
* @param grpId the id of the group to subscribe to
* @param subscribe set to true to subscribe or false to unsubscribe
*/
void subscribeToGroup(const RsGroupId& grpId, bool subscribe);
/*!
* 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
*/
int searchMsgs(RsGxsSearch* search, uint8_t hops = 1, bool retrieve = 0);
/*!
* Initiates a search of groups through the network which goes
* a given number of hosp deep into your friend's network
* @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
*/
int searchGrps(RsGxsSearch* search, uint8_t hops = 1, bool retrieve = 0);
/*!
* pauses synchronisation of subscribed groups and request for group id
* from peers
* @param enabled set to false to disable pause, and true otherwise
*/
void pauseSynchronisation(bool enabled);
/*!
* 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
*/
int requestMsg(const std::list<RsGxsMsgId>& msgId, uint8_t hops);
/*!
* 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
*/
int requestGrp(const std::list<RsGxsGrpId>& grpId, uint8_t hops);
public:
/*!
* initiates synchronisation
*/
void tick();
/*!
* Processes transactions and job queue
*/
void run();
private:
/*!
* called when
* items are deemed to be waiting in p3Service item queue
*/
void recvNxsItemQueue();
/*!
* Processes active tansaction map
*/
void processTransactions();
/*!
* Process completed transaction map
*/
void processCompleteTransactions();
/*!
* Processes synchronisation requests
*/
void processSyncRequests();
/*!
* This adds a transaction to
* @param
*/
void locked_addTransaction(NxsTransaction* trans);
/*!
* 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);
uint32_t getTransactionId();
bool attemptRecoverIds();
/** item handlers **/
void handleTransactionContent(RsNxsItem*);
void handleRecvSyncGroup(RsSyncGrp*);
void handleRecvSyncMessage(RsNxsItem*);
void handleRecvTransaction(RsNxsItem*);
/** item handlers **/
private:
/*** transactions ***/
/// active transactions
TransactionsPeerMap mInTransactions;
/// completed transactions
std::list<NxsTransaction*> mComplTransactions;
/// transaction id
uint32_t mTransactionN;
/*** transactions ***/
/*** synchronisation ***/
std::list<RsSyncGrp*> mSyncGrp;
std::list<RsSyncGrpMsg*> mSyncMsg;
/*** synchronisation ***/
RsNxsObserver* mObserver;
RsGeneralDataService* mDataStore;
uint16_t mServType;
/// for transaction members
RsMutex mTransMutex;
/// for other members save transactions
RsMutex mNxsMutex;
};
#endif // RSGXSNETSERVICE_H

View File

@ -56,7 +56,7 @@
* 2 transfers only between group
* - the also group matrix settings which is by default everyone can transfer to each other
*/
class RsNetworktExchangeService : public p3Service
class RsNetworkExchangeService : public p3Service
{
public:

View File

@ -0,0 +1,56 @@
#ifndef RSNXSOBSERVER_H
#define RSNXSOBSERVER_H
/*
* libretroshare/src/gxp: gxp.h
*
* Observer, interface for RetroShare.
*
* Copyright 2011-2011 by Robert Fernie, Evi-Parker Christopher
*
* 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".
*
*/
#include <set>
#include "serialiser/rsnxsitems.h"
class RsNxsObserver
{
public:
RsNxsObserver() {}
public:
/*!
* @param messages messages are deleted after function returns
*/
virtual void notifyNewMessages(std::set<RsNxsMsg*> messages);
/*!
* @param messages messages are deleted after function returns
*/
virtual void notifyNewGroups(std::set<RsNxsGrp*>& groups);
};
#endif // RSNXSOBSERVER_H

View File

@ -69,13 +69,13 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_SYNC_GRP:
case RS_PKT_SUBTYPE_NXS_SYNC_GRP:
return deserialSyncGrp(data, size);
case RS_PKT_SUBTYPE_SYNC_GRP_LIST:
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM:
return deserialSyncGrpList(data, size);
case RS_PKT_SUBTYPE_SYNC_MSG:
case RS_PKT_SUBTYPE_NXS_SYNC_MSG:
return deserialSyncGrpMsg(data, size);
case RS_PKT_SUBTYPE_SYNC_MSG_LIST:
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM:
return deserialSyncGrpMsgList(data, size);
case RS_PKT_SUBTYPE_NXS_GRP:
return deserialNxsGrp(data, size);
@ -175,6 +175,7 @@ bool RsNxsSerialiser::serialiseSynGrpMsgList(RsSyncGrpMsgList *item, void *data,
/* RsSyncGrpMsgList */
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
ok &= setRawUInt8(data, *size, &offset, item->flag);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
@ -279,7 +280,7 @@ bool RsNxsSerialiser::serialiseNxsGrp(RsNxsGrp *item, void *data, uint32_t *size
offset += 8;
// grp id
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->identity);
ok &= setRawUInt32(data, tlvsize, &offset, item->grpFlag);
@ -332,6 +333,7 @@ bool RsNxsSerialiser::serialiseSyncGrp(RsSyncGrp *item, void *data, uint32_t *si
/* skip the header */
offset += 8;
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
ok &= setRawUInt8(data, *size, &offset, item->flag);
ok &= setRawUInt32(data, *size, &offset, item->syncAge);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
@ -379,6 +381,7 @@ bool RsNxsSerialiser::serialiseNxsTrans(RsNxsTransac *item, void *data, uint32_t
/* skip the header */
offset += 8;
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
ok &= setRawUInt16(data, *size, &offset, item->transactFlag);
ok &= setRawUInt32(data, *size, &offset, item->nItems);
ok &= setRawUInt32(data, *size, &offset, item->timeout);
@ -430,6 +433,7 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
/* RsSyncGrpList */
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
ok &= setRawUInt8(data, *size, &offset, item->flag);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= item->adminSign.SetTlv(data, *size, &offset);
@ -476,6 +480,7 @@ bool RsNxsSerialiser::serialiseSyncGrpMsg(RsSyncGrpMsg *item, void *data, uint32
/* skip the header */
offset += 8;
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
ok &= setRawUInt8(data, *size, &offset, item->flag);
ok &= setRawUInt32(data, *size, &offset, item->syncAge);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
@ -546,6 +551,7 @@ RsNxsGrp* RsNxsSerialiser::deserialNxsGrp(void *data, uint32_t *size){
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->identity);
ok &= getRawUInt32(data, *size, &offset, &(item->grpFlag));
@ -618,6 +624,7 @@ RsNxsMsg* RsNxsSerialiser::deserialNxsMsg(void *data, uint32_t *size){
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->identity);
@ -664,7 +671,7 @@ RsSyncGrp* RsNxsSerialiser::deserialSyncGrp(void *data, uint32_t *size){
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(SERVICE_TYPE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_SYNC_GRP != getRsItemSubType(rstype)))
(RS_PKT_SUBTYPE_NXS_SYNC_GRP != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialSyncGrp() FAIL wrong type" << std::endl;
@ -689,6 +696,7 @@ RsSyncGrp* RsNxsSerialiser::deserialSyncGrp(void *data, uint32_t *size){
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= getRawUInt32(data, *size, &offset, &(item->syncAge));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
@ -730,7 +738,7 @@ RsSyncGrpList* RsNxsSerialiser::deserialSyncGrpList(void *data, uint32_t *size){
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(SERVICE_TYPE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_SYNC_GRP_LIST != getRsItemSubType(rstype)))
(RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialSyncGrpList() FAIL wrong type" << std::endl;
@ -755,6 +763,7 @@ RsSyncGrpList* RsNxsSerialiser::deserialSyncGrpList(void *data, uint32_t *size){
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= item->adminSign.GetTlv(data, *size, &offset);
@ -821,6 +830,7 @@ RsNxsTransac* RsNxsSerialiser::deserialNxsTrans(void *data, uint32_t *size){
RsNxsTransac* item = new RsNxsTransac(SERVICE_TYPE);
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag));
ok &= getRawUInt32(data, *size, &offset, &(item->nItems));
ok &= getRawUInt32(data, *size, &offset, &(item->timeout));
@ -889,6 +899,7 @@ RsSyncGrpMsgList* RsNxsSerialiser::deserialSyncGrpMsgList(void *data, uint32_t *
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
@ -959,6 +970,7 @@ RsSyncGrpMsg* RsNxsSerialiser::deserialSyncGrpMsg(void *data, uint32_t *size)
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= getRawUInt32(data, *size, &offset, &(item->syncAge));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash);
@ -1017,6 +1029,7 @@ uint32_t RsNxsSerialiser::sizeNxsGrp(RsNxsGrp *item)
{
uint32_t s = 8; // header size
s += 4; // transaction number
s += GetTlvStringSize(item->grpId);
s += GetTlvStringSize(item->identity);
s += 4; // grpFlag
@ -1034,6 +1047,7 @@ uint32_t RsNxsSerialiser::sizeSyncGrp(RsSyncGrp *item)
{
uint32_t s = 8; // header size
s += 4; // transaction number
s += 1; // flag
s += 4; // sync age
s += GetTlvStringSize(item->syncHash);
@ -1046,8 +1060,8 @@ uint32_t RsNxsSerialiser::sizeSyncGrpList(RsSyncGrpList *item)
{
uint32_t s = 8; // header size
s += 4; // transaction number
s += 1; // flag
s += GetTlvStringSize(item->grpId);
s += item->adminSign.TlvSize();
@ -1060,6 +1074,7 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsg(RsSyncGrpMsg *item)
uint32_t s = 8;
s += 4; // transaction number
s += 1; // flag
s += 4; // age
s += GetTlvStringSize(item->grpId);
@ -1073,6 +1088,7 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
{
uint32_t s = 8; // header size
s += 4; // transaction number
s += 1; // flag
s += GetTlvStringSize(item->grpId);
s += GetTlvStringSize(item->msgId);
@ -1084,6 +1100,8 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
uint32_t RsNxsSerialiser::sizeNxsTrans(RsNxsTransac *item){
uint32_t s = 8; // header size
s += 4; // transaction number
s += 2; // flag
s += 4; // nMsgs
s += 4; // timeout

View File

@ -36,11 +36,11 @@
#include "serialiser/rstlvkeys.h"
const uint8_t RS_PKT_SUBTYPE_SYNC_GRP = 0x0001;
const uint8_t RS_PKT_SUBTYPE_SYNC_GRP_LIST = 0x0002;
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_GRP = 0x0001;
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM = 0x0002;
const uint8_t RS_PKT_SUBTYPE_NXS_GRP = 0x0004;
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG = 0x0008;
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG_LIST = 0x0010;
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM = 0x0008;
const uint8_t RS_PKT_SUBTYPE_NXS_SYNC_MSG = 0x0010;
const uint8_t RS_PKT_SUBTYPE_NXS_MSG = 0x0020;
const uint8_t RS_PKT_SUBTYPE_NXS_TRANS = 0x0040;
@ -67,10 +67,12 @@ class RsNxsItem : public RsItem
public:
RsNxsItem(uint16_t servtype, uint8_t subtype)
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype) { return; }
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0) { return; }
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
uint32_t transactionNumber; // set to zero if this is not a transaction item
};
@ -79,14 +81,14 @@ public:
* Server may advise client peer to use sync file
* while serving his request. This results
*/
class RsSyncGrp : public RsNxsItem {
class RsNxsSyncGrp : public RsNxsItem {
public:
static const uint8_t FLAG_USE_SYNC_HASH;
static const uint8_t FLAG_ONLY_CURRENT; // only send most current version of grps / ignores sync hash
RsSyncGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP) { return;}
RsNxsSyncGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP) { return;}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
@ -112,12 +114,11 @@ public:
/** transaction **/
static const uint16_t FLAG_BEGIN_P1;
static const uint16_t FLAG_BEGIN_P2;
static const uint16_t FLAG_END_P1;
static const uint16_t FLAG_END_P2;
static const uint16_t FLAG_END_SUCCESS;
static const uint16_t FLAG_CANCEL;
static const uint16_t FLAG_FAIL_NUM;
static const uint16_t FLAG_FAIL_TIMEOUT;
static const uint16_t FLAG_FAIL_FULL;
static const uint16_t FLAG_END_FAIL_NUM;
static const uint16_t FLAG_END_FAIL_TIMEOUT;
static const uint16_t FLAG_END_FAIL_FULL;
/** transaction type **/
@ -144,7 +145,7 @@ public:
* Use to send to peer list of grps
* held by server peer
*/
class RsSyncGrpList : public RsNxsItem
class RsNxsSyncGrpItem : public RsNxsItem
{
public:
@ -153,8 +154,8 @@ public:
static const uint8_t FLAG_RESPONSE;
static const uint8_t FLAG_USE_SYNC_HASH;
RsSyncGrpList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; }
virtual ~RsSyncGrpList() { return; }
RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { return ; }
virtual ~RsNxsSyncGrpList() { return; }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
@ -198,14 +199,14 @@ public:
* Use to request list of msg held by peer
* for a given group
*/
class RsSyncGrpMsg : public RsNxsItem
class RsNxsSyncMsg : public RsNxsItem
{
public:
static const uint8_t FLAG_USE_SYNC_HASH;
RsSyncGrpMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_MSG) {return; }
RsNxsSyncMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG) {return; }
virtual void clear();
@ -221,15 +222,14 @@ public:
* Use to send list msgs for a group held by
* a peer
*/
class RsSyncGrpMsgList : public RsNxsItem
class RsNxsSyncMsgItem : public RsNxsItem
{
public:
static const uint8_t FLAG_REQUEST;
static const uint8_t FLAG_RESPONSE;
static const uint8_t FLAG_USE_SYNC_HASH;
RsSyncGrpMsgList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_MSG_LIST) { return; }
RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM) { return; }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
@ -237,7 +237,6 @@ public:
uint8_t flag; // response/req
std::string grpId;
std::string msgId;
RsTlvKeySignature idSign;
};
@ -250,8 +249,6 @@ class RsNxsMsg : public RsNxsItem
{
public:
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), msg(servtype) { return; }
@ -260,6 +257,7 @@ public:
std::string grpId; /// group id, forms part of version id
std::string msgId; /// msg id
std::string originalMsgId;
uint32_t msgFlag;
uint32_t timeStamp; /// UTC time create,
RsTlvBinaryData msg;
@ -360,7 +358,6 @@ public:
std::string msgId;
std::string grpId;
RsTlvKeySignature idSign;
RsTlvKeySignature deleteSign; // ( msgId + grpId + msg data ) sign //TODO: add warning not to place msgId+grpId in msg!
};
@ -396,15 +393,15 @@ private:
/* for RS_PKT_SUBTYPE_SYNC_GRP */
virtual uint32_t sizeSyncGrp(RsSyncGrp* item);
virtual bool serialiseSyncGrp(RsSyncGrp *item, void *data, uint32_t *size);
virtual RsSyncGrp* deserialSyncGrp(void *data, uint32_t *size);
virtual uint32_t sizeNxsSyncGrp(RsNxsSyncGrp* item);
virtual bool serialiseNxsSyncGrp(RsNxsSyncGrp *item, void *data, uint32_t *size);
virtual RsNxsSyncGrp* deserialNxsSyncGrp(void *data, uint32_t *size);
/* for RS_PKT_SUBTYPE_SYNC_GRP_LIST */
virtual uint32_t sizeSyncGrpList(RsSyncGrpList* item);
virtual bool serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint32_t *size);
virtual RsSyncGrpList* deserialSyncGrpList(void *data, uint32_t *size);
virtual uint32_t sizeSyncGrpList(RsNxsSyncGrpItem* item);
virtual bool serialiseNxsSyncGrpList(RsNxsSyncGrpItem *item, void *data, uint32_t *size);
virtual RsNxsSyncGrpItem* deserialNxsSyncGrpList(void *data, uint32_t *size);
/* for RS_PKT_SUBTYPE_NXS_GRP */