diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.cc b/libretroshare/src/serialiser/rsgxsreputationitems.cc index 7a7c9e7f8..5701cc756 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.cc +++ b/libretroshare/src/serialiser/rsgxsreputationitems.cc @@ -165,6 +165,7 @@ uint32_t RsGxsReputationSetItem::serial_size() const s += 4 ; // mOwnOpinion s += 4 ; // mOwnOpinionTS s += 4 ; // mIdentityFlags + s += 4 ; // mLastUsedTS s += mOwnerNodeId.serial_size() ; s += 4 ; // mOpinions.size() @@ -245,6 +246,7 @@ bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion); ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS); ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ; + ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ; ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ; ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size()); @@ -421,13 +423,13 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_ return item; } -RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize) +RsGxsReputationSetItem_deprecated3 *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated3(void *data,uint32_t tlvsize) { uint32_t offset = 8; // skip the header uint32_t rssize = getRsItemSize(data); bool ok = true ; - RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; + RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ; /* add mandatory parts first */ ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; @@ -460,7 +462,46 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem( return item; } +RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize) +{ + uint32_t offset = 8; // skip the header + uint32_t rssize = getRsItemSize(data); + bool ok = true ; + RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; + + /* add mandatory parts first */ + ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; + ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); + ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); + ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); + ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUsedTS); + ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ; + + uint32_t S ; + ok &= getRawUInt32(data, tlvsize, &offset, &S); + + for(uint32_t i = 0; ok && (i < S); ++i) + { + RsPeerId pid ; + uint32_t op ; + + ok &= pid.deserialise(data, tlvsize, offset) ; + ok &= getRawUInt32(data, tlvsize, &offset, &op); + + if(ok) + item->mOpinions[pid] = op ; + } + + if (offset != rssize || !ok) + { + std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; + delete item; + return NULL ; + } + + return item; +} RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize) { uint32_t offset = 8; // skip the header @@ -533,12 +574,12 @@ RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize) switch(getRsItemSubType(rstype)) { - case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated : return deserialiseReputationSetItem_deprecated(data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem(data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize); + case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize); + case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3: return deserialiseReputationSetItem_deprecated3(data, *pktsize); + case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem (data, *pktsize); + case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize); + case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize); + case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize); default: std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl; diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.h b/libretroshare/src/serialiser/rsgxsreputationitems.h index 4bf55e0d8..c7321f74b 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.h +++ b/libretroshare/src/serialiser/rsgxsreputationitems.h @@ -32,14 +32,16 @@ #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" #include "retroshare/rsgxsifacetypes.h" +#include "retroshare/rsreputations.h" #define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01 #define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02 #define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03 #define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04 -#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated 0x05 -#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x06 +#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated1 0x05 +#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3 0x06 #define RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM 0x07 +#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x08 /**************************************************************************/ class RsReputationItem: public RsItem @@ -79,32 +81,38 @@ public: uint32_t mLastQuery; // when we sent out. }; -// This class should disappear. Deprecated since Aug 1, 2016. The class definition is actually not needed, +// This class should disappear. Deprecated since Jan 7, 2017. The class definition is actually not needed, // that is why it's commented out. Kept here in order to explains how the deserialisation works. // -// class RsGxsReputationSetItem_deprecated: public RsReputationItem -// { -// public: -// RsGxsReputationSetItem_deprecated() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated) {} -// -// virtual ~RsGxsReputationSetItem_deprecated() {} -// virtual void clear() {} -// std::ostream &print(std::ostream &out, uint16_t indent = 0) { return out;} -// -// virtual bool serialise(void *data,uint32_t& size) const { std::cerr << "(EE) serialise attempt for a deprecated reputation item. This should not happen" << std::endl; return false ; } -// virtual uint32_t serial_size() const ; -// -// RsGxsId mGxsId; -// uint32_t mOwnOpinion; -// uint32_t mOwnOpinionTS; -// uint32_t mIdentityFlags; -// std::map mOpinions; // RsPeerId -> Opinion. -// }; +class RsGxsReputationSetItem_deprecated3: public RsReputationItem +{ +public: + RsGxsReputationSetItem_deprecated3() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3) {} + virtual ~RsGxsReputationSetItem_deprecated3() {} + virtual void clear() {} + std::ostream &print(std::ostream &out, uint16_t indent = 0) { return out;} + + virtual bool serialise(void *data,uint32_t& size) const { return false ;} + virtual uint32_t serial_size() const { return 0;} + + RsGxsId mGxsId; + uint32_t mOwnOpinion; + uint32_t mOwnOpinionTS; + uint32_t mIdentityFlags ; + RsPgpId mOwnerNodeId; + std::map mOpinions; // RsPeerId -> Opinion. +}; class RsGxsReputationSetItem: public RsReputationItem { public: - RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) {} + RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) + { + mOwnOpinion = RsReputations::OPINION_NEUTRAL ; + mOwnOpinionTS = 0; + mIdentityFlags = 0; + mLastUsedTS = 0; + } virtual ~RsGxsReputationSetItem() {} virtual void clear(); @@ -116,11 +124,11 @@ public: RsGxsId mGxsId; uint32_t mOwnOpinion; uint32_t mOwnOpinionTS; - uint32_t mIdentityFlags ; + uint32_t mIdentityFlags; + uint32_t mLastUsedTS; RsPgpId mOwnerNodeId; std::map mOpinions; // RsPeerId -> Opinion. }; - class RsGxsReputationBannedNodeSetItem: public RsReputationItem { public: @@ -191,6 +199,7 @@ private: static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size); static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size); static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (void *data, uint32_t size); + static RsGxsReputationSetItem_deprecated3 *deserialiseReputationSetItem_deprecated3 (void *data, uint32_t size); static RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size); static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size); static RsGxsReputationBannedNodeSetItem *deserialiseReputationBannedNodeSetItem (void *data, uint32_t size);