added last used TS in reputation items

This commit is contained in:
csoler 2017-01-08 11:10:33 +01:00
parent d631758e8c
commit 0dd3a318ed
2 changed files with 82 additions and 32 deletions

View File

@ -165,6 +165,7 @@ uint32_t RsGxsReputationSetItem::serial_size() const
s += 4 ; // mOwnOpinion s += 4 ; // mOwnOpinion
s += 4 ; // mOwnOpinionTS s += 4 ; // mOwnOpinionTS
s += 4 ; // mIdentityFlags s += 4 ; // mIdentityFlags
s += 4 ; // mLastUsedTS
s += mOwnerNodeId.serial_size() ; s += mOwnerNodeId.serial_size() ;
s += 4 ; // mOpinions.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, mOwnOpinion);
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS); ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ; ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ;
ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ;
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ; ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size()); ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
@ -421,13 +423,13 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_
return item; 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 offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data); uint32_t rssize = getRsItemSize(data);
bool ok = true ; bool ok = true ;
RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ;
/* add mandatory parts first */ /* add mandatory parts first */
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
@ -460,7 +462,46 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(
return item; 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) RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize)
{ {
uint32_t offset = 8; // skip the header uint32_t offset = 8; // skip the header
@ -533,12 +574,12 @@ RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
switch(getRsItemSubType(rstype)) switch(getRsItemSubType(rstype))
{ {
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize); 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_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_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_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (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_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
default: default:
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl; std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;

View File

@ -32,14 +32,16 @@
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvidset.h" #include "serialiser/rstlvidset.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include "retroshare/rsreputations.h"
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01 #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_SET_ITEM_deprecated2 0x02
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03 #define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04 #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_deprecated1 0x05
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x06 #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_BANNED_NODE_SET_ITEM 0x07
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x08
/**************************************************************************/ /**************************************************************************/
class RsReputationItem: public RsItem class RsReputationItem: public RsItem
@ -79,32 +81,38 @@ public:
uint32_t mLastQuery; // when we sent out. 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. // that is why it's commented out. Kept here in order to explains how the deserialisation works.
// //
// class RsGxsReputationSetItem_deprecated: public RsReputationItem class RsGxsReputationSetItem_deprecated3: public RsReputationItem
// { {
// public: public:
// RsGxsReputationSetItem_deprecated() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated) {} RsGxsReputationSetItem_deprecated3() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3) {}
//
// 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<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
// };
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<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
};
class RsGxsReputationSetItem: public RsReputationItem class RsGxsReputationSetItem: public RsReputationItem
{ {
public: 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 ~RsGxsReputationSetItem() {}
virtual void clear(); virtual void clear();
@ -116,11 +124,11 @@ public:
RsGxsId mGxsId; RsGxsId mGxsId;
uint32_t mOwnOpinion; uint32_t mOwnOpinion;
uint32_t mOwnOpinionTS; uint32_t mOwnOpinionTS;
uint32_t mIdentityFlags ; uint32_t mIdentityFlags;
uint32_t mLastUsedTS;
RsPgpId mOwnerNodeId; RsPgpId mOwnerNodeId;
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion. std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
}; };
class RsGxsReputationBannedNodeSetItem: public RsReputationItem class RsGxsReputationBannedNodeSetItem: public RsReputationItem
{ {
public: public:
@ -191,6 +199,7 @@ private:
static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size); static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size);
static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size); static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size);
static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (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 RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size); static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
static RsGxsReputationBannedNodeSetItem *deserialiseReputationBannedNodeSetItem (void *data, uint32_t size); static RsGxsReputationBannedNodeSetItem *deserialiseReputationBannedNodeSetItem (void *data, uint32_t size);