saved owner node ID in GXS reputation item

This commit is contained in:
csoler 2016-08-02 23:57:11 +02:00
parent 60cf2991d4
commit c4ef4d7743
3 changed files with 101 additions and 69 deletions

View File

@ -82,10 +82,10 @@ std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t inden
{
printRsItemBase(out, "RsReputationConfigItem", indent);
out << "mPeerId: " << mPeerId << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
out << "mPeerId: " << mPeerId << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
printRsItemEnd(out, "RsReputationConfigItem", indent);
return out;
}
@ -94,14 +94,15 @@ std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationSetItem", indent);
out << "GxsId: " << mGxsId << std::endl;
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
out << "GxsId: " << mGxsId << std::endl;
out << "Owner: " << mOwnerNodeId << std::endl;
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
out << "Opinions from neighbors: " << std::endl;
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
out << " " << it->first << ": " << it->second << std::endl;
out << " " << it->first << ": " << it->second << std::endl;
printRsItemEnd(out, "RsReputationSetItem", indent);
return out;
}
@ -109,12 +110,12 @@ std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t inden
{
printRsItemBase(out, "RsReputationUpdateItem", indent);
out << "from: " << PeerId() << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
out << "from: " << PeerId() << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
out << " " << it->first << ": " << it->second << std::endl;
out << " " << it->first << ": " << it->second << std::endl;
printRsItemEnd(out, "RsReputationUpdateItem", indent);
return out;
}
@ -122,8 +123,8 @@ std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t inde
{
printRsItemBase(out, "RsReputationRequestItem", indent);
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
printRsItemEnd(out, "RsReputationRequestItem", indent);
return out;
}
@ -142,18 +143,19 @@ uint32_t RsGxsReputationConfigItem::serial_size() const
uint32_t RsGxsReputationSetItem::serial_size() const
{
uint32_t s = 8; /* header */
s += mGxsId.serial_size() ;
uint32_t s = 8; /* header */
s += mGxsId.serial_size() ;
s += 4 ; // mOwnOpinion
s += 4 ; // mOwnOpinionTS
s += 4 ; // mIdentityFlags
s += mOwnerNodeId.serial_size() ;
s += 4 ; // mOpinions.size()
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
return s ;
return s ;
}
uint32_t RsGxsReputationUpdateItem::serial_size() const
@ -216,8 +218,10 @@ 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, mOpinions.size());
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
{
ok &= it->first.serialise(data,tlvsize,offset) ;
@ -315,30 +319,32 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_
/* add mandatory parts first */
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
item->mOwnerNodeId.clear(); // clears up, for backward compat.
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
item->mIdentityFlags = REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE; // special value that means please update me.
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
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);
ok &= pid.deserialise(data, tlvsize, offset) ;
ok &= getRawUInt32(data, tlvsize, &offset, &op);
if(ok)
item->mOpinions[pid] = op ;
item->mOpinions[pid] = op ;
}
if (offset != rssize || !ok)
{
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
delete item;
delete item;
return NULL ;
}
@ -357,7 +363,8 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S);
@ -455,12 +462,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_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_deprecated: return deserialiseReputationSetItem_deprecated(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;
return NULL;

View File

@ -32,11 +32,12 @@
#include "serialiser/rsserial.h"
#include "retroshare/rsgxsifacetypes.h"
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated 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 0x05
#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
/**************************************************************************/
class RsReputationItem: public RsItem
@ -68,33 +69,55 @@ public:
virtual void clear() {}
std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
RsPeerId mPeerId;
uint32_t mLatestUpdate; // timestamp they returned.
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,
// 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<RsPeerId, uint32_t> 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) {}
virtual ~RsGxsReputationSetItem() {}
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) const ;
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 bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
RsGxsId mGxsId;
uint32_t mOwnOpinion;
uint32_t mOwnOpinionTS;
uint32_t mIdentityFlags ;
RsPgpId mOwnerNodeId;
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
};
class RsGxsReputationUpdateItem: public RsReputationItem
{
public:
@ -145,11 +168,11 @@ public:
virtual RsItem * deserialise(void *data, uint32_t *size);
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 RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
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 RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
};
/**************************************************************************/

View File

@ -493,8 +493,8 @@ bool p3GxsReputation::processIncoming()
switch(item->PacketSubType())
{
default:
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
std::cerr << "p3GxsReputation::processingIncoming() Unknown Item";
std::cerr << std::endl;
itemOk = false;
@ -931,6 +931,7 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
item->mOwnOpinion = rit->second.mOwnOpinion;
item->mOwnOpinionTS = rit->second.mOwnOpinionTs;
item->mIdentityFlags = rit->second.mIdentityFlags;
item->mOwnerNodeId = rit->second.mOwnerNode;
std::map<RsPeerId, RsReputations::Opinion>::iterator oit;
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
@ -1069,6 +1070,7 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
reputation.mOwnOpinion = item->mOwnOpinion;
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
reputation.mOwnerNode = item->mOwnerNodeId;
// if dropping entries has changed the score -> must update.