switched RsNxsItems to new serialization

This commit is contained in:
csoler 2017-04-27 14:16:57 +02:00
parent f6e59f7dee
commit 3c20a85335
3 changed files with 223 additions and 235 deletions

View File

@ -3500,10 +3500,10 @@ bool RsGxsNetService::encryptSingleNxsItem(RsNxsItem *item, const RsGxsCircleId&
#ifdef NXS_NET_DEBUG_7
GXSNETDEBUG_P_ (item->PeerId()) << " Encrypting..." << std::endl;
#endif
uint32_t size = item->serial_size() ;
uint32_t size = RsNxsSerialiser(mServType).size(item) ;
RsTemporaryMemory tempmem( size ) ;
if(!item->serialise(tempmem,size))
if(!RsNxsSerialiser(mServType).serialise(item,tempmem,&size))
{
std::cerr << " (EE) Cannot serialise item. Something went wrong." << std::endl;
status = RS_NXS_ITEM_ENCRYPTION_STATUS_SERIALISATION_ERROR ;
@ -3530,7 +3530,7 @@ bool RsGxsNetService::encryptSingleNxsItem(RsNxsItem *item, const RsGxsCircleId&
enc_item->transactionNumber = item->transactionNumber ;
enc_item->PeerId(item->PeerId()) ;
encrypted_item = enc_item ;
encrypted_item = enc_item ;
#ifdef NXS_NET_DEBUG_7
GXSNETDEBUG_P_(item->PeerId()) << " encrypted item of size " << encrypted_len << std::endl;
#endif

View File

@ -1,8 +1,9 @@
#include "rsnxsitems.h"
#include "rsbaseserial.h"
#include "util/rsprint.h"
#include <iomanip>
#include "serialization/rstypeserializer.h"
/***
* #define RSSERIAL_DEBUG 1
***/
@ -37,47 +38,181 @@ const uint16_t RsNxsTransacItem::FLAG_TYPE_GRPS = 0x1000;
const uint16_t RsNxsTransacItem::FLAG_TYPE_MSGS = 0x2000;
const uint16_t RsNxsTransacItem::FLAG_TYPE_ENCRYPTED_DATA = 0x4000;
RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size)
RsItem *RsNxsSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if(service_id != SERVICE_TYPE)
return NULL ;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(SERVICE_TYPE != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: return deserialNxsSyncGrpReqItem(data, size);
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM: return deserialNxsSyncGrpItem(data, size);
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: return deserialNxsSyncMsgReqItem(data, size);
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM: return deserialNxsSyncMsgItem(data, size);
case RS_PKT_SUBTYPE_NXS_GRP_ITEM: return deserialNxsGrpItem(data, size);
case RS_PKT_SUBTYPE_NXS_MSG_ITEM: return deserialNxsMsgItem(data, size);
case RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM: return deserialNxsTransacItem(data, size);
case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:return deserialNxsGroupPublishKeyItem(data, size);
case RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM: return deserialNxsSessionKeyItem(data, size);
case RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM: return deserialNxsEncryptedDataItem(data, size);
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: return deserialNxsSyncGrpStatsItem(data, size);
switch(item_subtype)
{
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: return new RsNxsSyncGrpReqItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM: return new RsNxsSyncGrpItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: return new RsNxsSyncMsgReqItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM: return new RsNxsSyncMsgItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_GRP_ITEM: return new RsNxsGrp(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_MSG_ITEM: return new RsNxsMsg(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM: return new RsNxsTransacItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:return new RsNxsGroupPublishKeyItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM: return new RsNxsEncryptedDataItem(SERVICE_TYPE) ;
case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: return new RsNxsSyncGrpStatsItem(SERVICE_TYPE) ;
default:
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialise() : data has no type"
<< std::endl;
#endif
return NULL;
}
}
}
}
void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ;
RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ;
}
void RsNxsMsg::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,pos ,"pos") ;
RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,msg ,"msg") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,meta ,"meta") ;
}
void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,pos ,"pos") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,grp ,"grp") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,meta ,"meta") ;
}
void RsNxsSyncGrpStatsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,request_type ,"request_type") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,number_of_posts,"number_of_posts") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,last_post_TS ,"last_post_TS") ;
}
void RsNxsSyncGrpReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,createdSince ,"createdSince") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
}
void RsNxsTransacItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,transactFlag ,"transactFlag") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,nItems ,"nItems") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
}
void RsNxsSyncGrpItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,publishTs ,"publishTs") ;
RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ;
}
void RsNxsSyncMsgReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,createdSinceTS ,"createdSinceTS") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ;
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
}
void RsNxsGroupPublishKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,private_key ,"private_key") ;
}
void RsNxsEncryptedDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,encrypted_data, "encrypted_data") ;
}
int RsNxsGrp::refcount = 0;
/** print and clear functions **/
int RsNxsMsg::refcount = 0;
void RsNxsMsg::clear()
{
msg.TlvClear();
meta.TlvClear();
}
void RsNxsGrp::clear()
{
grpId.clear();
grp.TlvClear();
meta.TlvClear();
}
void RsNxsSyncGrpReqItem::clear()
{
flag = 0;
createdSince = 0;
syncHash.clear();
updateTS = 0;
}
void RsNxsGroupPublishKeyItem::clear()
{
private_key.TlvClear();
}
void RsNxsSyncMsgReqItem::clear()
{
grpId.clear();
flag = 0;
createdSinceTS = 0;
syncHash.clear();
updateTS = 0;
}
void RsNxsSyncGrpItem::clear()
{
flag = 0;
publishTs = 0;
grpId.clear();
authorId.clear();
}
void RsNxsSyncMsgItem::clear()
{
flag = 0;
msgId.clear();
grpId.clear();
authorId.clear();
}
void RsNxsTransacItem::clear(){
transactFlag = 0;
nItems = 0;
updateTS = 0;
timestamp = 0;
transactionNumber = 0;
}
void RsNxsEncryptedDataItem::clear(){
encrypted_data.TlvClear() ;
}
#ifdef SUSPENDED_CODE_27042017
void RsNxsSessionKeyItem::clear()
{
for(std::map<RsGxsId,RsTlvBinaryData>::iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it)
it->second.TlvClear() ;
encrypted_session_keys.clear() ;
}
#endif
#ifdef TO_REMOVE
uint32_t RsNxsSerialiser::size(RsItem *item)
{
@ -165,7 +300,6 @@ bool RsNxsSyncMsgItem::serialise(void *data, uint32_t& size) const
return ok;
}
bool RsNxsMsg::serialise(void *data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
@ -231,7 +365,6 @@ bool RsNxsGrp::serialise(void *data, uint32_t& size) const
return ok;
}
bool RsNxsSyncGrpStatsItem::serialise(void *data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
@ -265,7 +398,6 @@ bool RsNxsSyncGrpStatsItem::serialise(void *data, uint32_t& size) const
return ok;
}
bool RsNxsSyncGrpReqItem::serialise(void *data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
@ -297,7 +429,6 @@ bool RsNxsSyncGrpReqItem::serialise(void *data, uint32_t& size) const
return ok;
}
bool RsNxsTransacItem::serialise(void *data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
@ -361,6 +492,7 @@ bool RsNxsSyncGrpItem::serialise(void *data, uint32_t& size) const
return ok;
}
bool RsNxsSyncMsgReqItem::serialise(void *data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
@ -1065,78 +1197,6 @@ uint32_t RsNxsSessionKeyItem::serial_size() const
}
int RsNxsGrp::refcount = 0;
/** print and clear functions **/
int RsNxsMsg::refcount = 0;
void RsNxsMsg::clear()
{
msg.TlvClear();
meta.TlvClear();
}
void RsNxsGrp::clear()
{
grpId.clear();
grp.TlvClear();
meta.TlvClear();
}
void RsNxsSyncGrpReqItem::clear()
{
flag = 0;
createdSince = 0;
syncHash.clear();
updateTS = 0;
}
void RsNxsGroupPublishKeyItem::clear()
{
private_key.TlvClear();
}
void RsNxsSyncMsgReqItem::clear()
{
grpId.clear();
flag = 0;
createdSinceTS = 0;
syncHash.clear();
updateTS = 0;
}
void RsNxsSyncGrpItem::clear()
{
flag = 0;
publishTs = 0;
grpId.clear();
authorId.clear();
}
void RsNxsSyncMsgItem::clear()
{
flag = 0;
msgId.clear();
grpId.clear();
authorId.clear();
}
void RsNxsTransacItem::clear(){
transactFlag = 0;
nItems = 0;
updateTS = 0;
timestamp = 0;
transactionNumber = 0;
}
void RsNxsEncryptedDataItem::clear(){
encrypted_data.TlvClear() ;
}
void RsNxsSessionKeyItem::clear()
{
for(std::map<RsGxsId,RsTlvBinaryData>::iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it)
it->second.TlvClear() ;
encrypted_session_keys.clear() ;
}
std::ostream& RsNxsSyncGrpReqItem::print(std::ostream &out, uint16_t indent)
{
@ -1347,3 +1407,4 @@ std::ostream& RsNxsEncryptedDataItem::print(std::ostream &out, uint16_t indent)
printRsItemEnd(out ,"RsNxsSessionKeyItem", indent);
return out;
}
#endif

View File

@ -72,20 +72,13 @@ class RsNxsItem : public RsItem
{
public:
RsNxsItem(uint16_t servtype, uint8_t subtype)
: RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
RsNxsItem(uint16_t servtype, uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0)
{
setPriorityLevel(QOS_PRIORITY_RS_GXS_NET);
return;
}
virtual ~RsNxsItem(){}
virtual bool serialise(void *data,uint32_t& size) const = 0 ;
virtual uint32_t serial_size() const = 0 ;
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
bool serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const;
uint32_t transactionNumber; // set to zero if this is not a transaction item
};
@ -103,14 +96,11 @@ 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
RsNxsSyncGrpReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM) { clear(); return;}
RsNxsSyncGrpReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM) { clear();}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint8_t flag; // advises whether to use sync hash
uint32_t createdSince; // how far back to sync data
uint32_t updateTS; // time of last group update
@ -127,14 +117,12 @@ public:
RsNxsSyncGrpStatsItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM) {}
virtual void clear() {}
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const ;
static const uint8_t GROUP_INFO_TYPE_REQUEST = 0x01;
static const uint8_t GROUP_INFO_TYPE_RESPONSE = 0x02;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t request_type; // used to determine the type of request
RsGxsGroupId grpId; // id of the group
uint32_t number_of_posts; // number of posts in that group
@ -149,14 +137,12 @@ public:
class RsNxsGroupPublishKeyItem : public RsNxsItem
{
public:
RsNxsGroupPublishKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM) { clear(); return;}
RsNxsGroupPublishKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM) { clear(); }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGxsGroupId grpId ;
RsTlvPrivateRSAKey private_key ;
};
@ -194,14 +180,12 @@ public:
static const uint16_t FLAG_TYPE_MSGS;
static const uint16_t FLAG_TYPE_ENCRYPTED_DATA;
RsNxsTransacItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM) { clear(); return; }
virtual ~RsNxsTransacItem() { return ; }
RsNxsTransacItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM) { clear(); }
virtual ~RsNxsTransacItem() {}
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const ;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint16_t transactFlag;
uint32_t nItems;
@ -224,18 +208,14 @@ public:
static const uint8_t FLAG_RESPONSE;
static const uint8_t FLAG_USE_SYNC_HASH;
RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { clear(); return ; }
virtual ~RsNxsSyncGrpItem() { return; }
RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { clear();}
virtual ~RsNxsSyncGrpItem() {}
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint8_t flag; // request or response
uint32_t publishTs; // to compare to Ts of receiving peer's grp of same id
/// grpId of grp held by sending peer
@ -244,6 +224,7 @@ public:
};
#ifdef SUSPENDED_CODE_27042017
/*!
* Use to send to peer list of grps
* held by server peer
@ -256,17 +237,14 @@ public:
RsNxsSessionKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM) { clear(); }
virtual ~RsNxsSessionKeyItem() {}
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
/// Session key encrypted for the whole group
///
uint8_t iv[EVP_MAX_IV_LENGTH] ; // initialisation vector
std::map<RsGxsId, RsTlvBinaryData> encrypted_session_keys; // encrypted session keys
};
#endif
/*!
* Use to send to peer list of grps
* held by server peer
@ -282,12 +260,9 @@ public:
clear();
}
virtual ~RsNxsEncryptedDataItem() {}
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
/// grpId of grp held by sending peer
///
@ -306,20 +281,14 @@ class RsNxsGrp : public RsNxsItem
public:
RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_ITEM), grp(servtype), meta(servtype),
metaData(NULL) { clear();
//std::cout << "\nGrp refcount++ : " << ++refcount << std::endl;
return; }
virtual ~RsNxsGrp() { if(metaData) delete metaData;
//std::cout << "\nGrp refcount-- : " << --refcount << std::endl;
}
metaData(NULL) { clear();}
virtual ~RsNxsGrp() { if(metaData) delete metaData; }
RsNxsGrp* clone() const;
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGxsGroupId grpId; /// group Id, needed to complete version Id (ncvi)
static int refcount;
@ -354,13 +323,11 @@ public:
#endif
static const uint8_t FLAG_USE_HASHED_GROUP_ID;
RsNxsSyncMsgReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM) { clear(); return; }
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
RsNxsSyncMsgReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM) { clear(); }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGxsGroupId grpId;
uint8_t flag;
@ -380,13 +347,11 @@ public:
static const uint8_t FLAG_REQUEST;
static const uint8_t FLAG_RESPONSE;
static const uint8_t FLAG_USE_SYNC_HASH;
RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM) { clear(); return; }
RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM) { clear(); }
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint8_t flag; // response/req
RsGxsGroupId grpId;
@ -405,24 +370,12 @@ class RsNxsMsg : public RsNxsItem
public:
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG_ITEM), meta(servtype), msg(servtype),
metaData(NULL) {
// std::cout << "\nrefcount++ : " << ++refcount << std::endl;
clear(); return;
}
virtual ~RsNxsMsg()
{
//std::cout << "\nrefcount-- : " << --refcount << std::endl;
if(metaData){
//std::cout << "\ndeleted\n";
delete metaData;
}
}
metaData(NULL) { clear(); }
virtual ~RsNxsMsg() { if(metaData) delete metaData; }
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint8_t pos; /// used for splitting up msg
uint8_t count; /// number of split up messages
@ -453,14 +406,11 @@ class RsNxsSearchReqItem : public RsNxsItem
{
public:
RsNxsSearchReqItem(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_EXT_SEARCH_REQ), serviceSearchItem(servtype) { return; }
virtual ~RsNxsSearchReqItem() { return;}
RsNxsSearchReqItem(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_EXT_SEARCH_REQ), serviceSearchItem(servtype) {}
virtual ~RsNxsSearchReqItem() {}
virtual void clear() {}
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
virtual void clear() { return;}
virtual std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint8_t nHops; /// how many peers to jump to
uint32_t token; // search token
@ -477,13 +427,11 @@ class RsNxsSearchResultMsgItem
{
public:
RsNxsSearchResultMsgItem() : context(0) { return;}
RsNxsSearchResultMsgItem() : context(0) {}
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
void clear() {}
std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t token; // search token to be redeemed
RsTlvBinaryData context; // used by client service
@ -504,14 +452,11 @@ public:
RsNxsSearchResultGrpItem();
virtual bool serialise(void *data,uint32_t& size) const;
virtual uint32_t serial_size() const;
void clear() {}
std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; }
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t token; // search token to be redeemed
RsTlvBinaryData context; // used by client service
std::string grpId;
@ -547,34 +492,16 @@ public:
#endif
class RsNxsSerialiser : public RsSerialType
class RsNxsSerialiser : public RsServiceSerializer
{
public:
RsNxsSerialiser(uint16_t servtype) :
RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) { return; }
RsNxsSerialiser(uint16_t servtype) : RsServiceSerializer(servtype), SERVICE_TYPE(servtype) {}
virtual ~RsNxsSerialiser() {}
virtual ~RsNxsSerialiser() { return; }
virtual uint32_t size(RsItem *item);
virtual bool serialise(RsItem *item, void *data, uint32_t *size);
virtual RsItem* deserialise(void *data, uint32_t *size);
private:
RsNxsSyncGrpReqItem *deserialNxsSyncGrpReqItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP */
RsNxsSyncGrpItem *deserialNxsSyncGrpItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP_ITEM */
RsNxsSyncMsgReqItem *deserialNxsSyncMsgReqItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_MSG */
RsNxsSyncMsgItem *deserialNxsSyncMsgItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_MSG_ITEM */
RsNxsGrp *deserialNxsGrpItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_GRP */
RsNxsMsg *deserialNxsMsgItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_MSG */
RsNxsTransacItem *deserialNxsTransacItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_TRANS */
RsNxsGroupPublishKeyItem *deserialNxsGroupPublishKeyItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY */
RsNxsSessionKeyItem *deserialNxsSessionKeyItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM */
RsNxsEncryptedDataItem *deserialNxsEncryptedDataItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM */
RsNxsSyncGrpStatsItem *deserialNxsSyncGrpStatsItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM */
bool checkItemHeader(void *data, uint32_t *size, uint8_t subservice_type);
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
protected:
const uint16_t SERVICE_TYPE;
};