diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index a3df21c82..302465414 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -108,7 +108,7 @@ void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; RsTypeSerializer::serial_process(j,ctx,duplication_factor,"duplication_factor") ; - RsTypeSerializer::serial_process(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 (j,ctx,routing_id,"routing_id") ; - RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; + RS_SERIAL_PROCESS(flags); RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ; RsTypeSerializer::serial_process (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; diff --git a/libretroshare/src/grouter/grouteritems.h b/libretroshare/src/grouter/grouteritems.h index baf7c0576..14957ab87 100644 --- a/libretroshare/src/grouter/grouteritems.h +++ b/libretroshare/src/grouter/grouteritems.h @@ -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