improved type definition for GRouter item flags (simplified changed from PR~1697)

This commit is contained in:
csoler 2020-01-04 20:35:49 +01:00
parent e5d8600f25
commit 28ec7f5fb2
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
2 changed files with 44 additions and 24 deletions

View File

@ -108,7 +108,7 @@ void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,duplication_factor,"duplication_factor") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
RS_SERIAL_PROCESS(flags);
if(j == RsGenericSerializer::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more.
{
@ -128,7 +128,7 @@ void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob
void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t> (j,ctx,routing_id,"routing_id") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
RS_SERIAL_PROCESS(flags);
RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,service_id,"service_id") ;
RsTypeSerializer::serial_process (j,ctx,data_hash,"data_hash") ;
@ -269,3 +269,4 @@ RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const
return item ;
}
RsGRouterAbstractMsgItem::~RsGRouterAbstractMsgItem() = default;

View File

@ -27,7 +27,7 @@
#include "serialiser/rstlvkeys.h"
#include "rsitems/rsserviceids.h"
#include "retroshare/rstypes.h"
#include "retroshare/rsflags.h"
#include "retroshare/rsgrouter.h"
#include "groutermatrix.h"
@ -83,40 +83,59 @@ class RsGRouterNonCopyableObject
// and routing ID. Sub-items are responsible for providing the serialised data to be signed for
// both signing and checking.
class RsGRouterAbstractMsgItem: public RsGRouterItem
enum class RsGRouterItemFlags : uint32_t
{
public:
explicit RsGRouterAbstractMsgItem(uint8_t pkt_subtype) : RsGRouterItem(pkt_subtype), flags(0) {}
virtual ~RsGRouterAbstractMsgItem() {}
NONE = 0x0,
ENCRYPTED = 0x1,
SERVICE_UNKNOWN = 0x2
};
RS_REGISTER_ENUM_FLAGS_TYPE(RsGRouterItemFlags)
struct RsGRouterAbstractMsgItem: RsGRouterItem
{
explicit RsGRouterAbstractMsgItem(uint8_t pkt_subtype):
RsGRouterItem(pkt_subtype), flags(RsGRouterItemFlags::NONE) {}
GRouterMsgPropagationId routing_id ;
GRouterKeyId destination_key ;
GRouterServiceId service_id ;
RsTlvKeySignature signature ; // signs mid+destination_key+state
uint32_t flags ; // packet was delivered, not delivered, bounced, etc
/// packet was delivered, not delivered, bounced, etc
RsGRouterItemFlags flags;
~RsGRouterAbstractMsgItem();
};
class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRouterNonCopyableObject
class RsGRouterGenericDataItem:
public RsGRouterAbstractMsgItem, public RsGRouterNonCopyableObject
{
public:
RsGRouterGenericDataItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_DATA), data_size(0), data_bytes(NULL), duplication_factor(0) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
virtual ~RsGRouterGenericDataItem() { clear() ; }
public:
RsGRouterGenericDataItem():
RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_DATA),
data_size(0), data_bytes(nullptr), duplication_factor(0)
{ setPriorityLevel(QOS_PRIORITY_RS_GROUTER); }
virtual void clear()
{
free(data_bytes);
data_bytes=NULL;
}
virtual ~RsGRouterGenericDataItem() { clear(); }
virtual void clear()
{
free(data_bytes);
data_bytes = nullptr;
}
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx );
RsGRouterGenericDataItem *duplicate() const ;
RsGRouterGenericDataItem *duplicate() const;
// packet data
//
uint32_t data_size ;
uint8_t *data_bytes;
uint32_t duplication_factor ; // number of duplicates allowed. Should be capped at each de-serialise operation!
/// packet data
uint32_t data_size;
uint8_t* data_bytes;
/** number of duplicates allowed. Should be capped at each de-serialise
* operation! */
uint32_t duplication_factor;
};
class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem