mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-16 18:07:11 -05:00
added code for all reputation items
This commit is contained in:
parent
7a7f4c99a3
commit
9f6bc0c3fc
@ -23,9 +23,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include "serialiser/rsbaseserial.h"
|
#include "serialiser/rsbaseserial.h"
|
||||||
#include "serialiser/rsbanlistitems.h"
|
#include "serialiser/rsgxsreputationitems.h"
|
||||||
#include "serialiser/rstlvbanlist.h"
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
#define RSSERIAL_DEBUG 1
|
#define RSSERIAL_DEBUG 1
|
||||||
@ -35,170 +35,392 @@
|
|||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#ifdef SUSPENDED
|
bool RsReputationItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const
|
||||||
RsBanListItem::~RsBanListItem()
|
|
||||||
{
|
{
|
||||||
return;
|
tlvsize = serial_size() ;
|
||||||
}
|
offset = 0;
|
||||||
|
|
||||||
void RsBanListItem::clear()
|
if (pktsize < tlvsize)
|
||||||
{
|
|
||||||
peerList.TlvClear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream &RsBanListItem::print(std::ostream &out, uint16_t indent)
|
|
||||||
{
|
|
||||||
printRsItemBase(out, "RsBanListItem", indent);
|
|
||||||
uint16_t int_Indent = indent + 2;
|
|
||||||
peerList.print(out, int_Indent);
|
|
||||||
|
|
||||||
printRsItemEnd(out, "RsBanListItem", indent);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t RsBanListSerialiser::sizeList(RsBanListItem *item)
|
|
||||||
{
|
|
||||||
uint32_t s = 8; /* header */
|
|
||||||
s += item->peerList.TlvSize();
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* serialise the data to the buffer */
|
|
||||||
bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uint32_t *pktsize)
|
|
||||||
{
|
|
||||||
uint32_t tlvsize = sizeList(item);
|
|
||||||
uint32_t offset = 0;
|
|
||||||
|
|
||||||
if (*pktsize < tlvsize)
|
|
||||||
return false; /* not enough space */
|
return false; /* not enough space */
|
||||||
|
|
||||||
*pktsize = tlvsize;
|
pktsize = tlvsize;
|
||||||
|
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
|
||||||
|
|
||||||
|
if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
|
||||||
|
{
|
||||||
|
std::cerr << "RsReputationItem::serialise_header(): ERROR. Not enough size!" << std::endl;
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
#ifdef RSSERIAL_DEBUG
|
#ifdef RSSERIAL_DEBUG
|
||||||
std::cerr << "RsDsdvSerialiser::serialiseRoute() Header: " << ok << std::endl;
|
std::cerr << "RsReputationItem::serialise() Header: " << ok << std::endl;
|
||||||
std::cerr << "RsDsdvSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* skip the header */
|
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
/* add mandatory parts first */
|
return true ;
|
||||||
ok &= item->peerList.SetTlv(data, tlvsize, &offset);
|
|
||||||
|
|
||||||
if (offset != tlvsize)
|
|
||||||
{
|
|
||||||
ok = false;
|
|
||||||
#ifdef RSSERIAL_DEBUG
|
|
||||||
std::cerr << "RsDsdvSerialiser::serialiseRoute() Size Error! " << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsize)
|
|
||||||
{
|
|
||||||
/* get the type and size */
|
|
||||||
uint32_t rstype = getRsItemId(data);
|
|
||||||
uint32_t tlvsize = getRsItemSize(data);
|
|
||||||
|
|
||||||
uint32_t offset = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
|
||||||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)) ||
|
|
||||||
(RS_PKT_SUBTYPE_BANLIST_ITEM != getRsItemSubType(rstype)))
|
|
||||||
{
|
|
||||||
return NULL; /* wrong type */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*pktsize < tlvsize) /* check size */
|
|
||||||
return NULL; /* not enough data */
|
|
||||||
|
|
||||||
/* set the packet length */
|
|
||||||
*pktsize = tlvsize;
|
|
||||||
|
|
||||||
bool ok = true;
|
|
||||||
|
|
||||||
/* ready to load */
|
|
||||||
RsBanListItem *item = new RsBanListItem();
|
|
||||||
item->clear();
|
|
||||||
|
|
||||||
/* skip the header */
|
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
/* add mandatory parts first */
|
|
||||||
ok &= item->peerList.GetTlv(data, tlvsize, &offset);
|
|
||||||
|
|
||||||
if (offset != tlvsize)
|
|
||||||
{
|
|
||||||
/* error */
|
|
||||||
delete item;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
delete item;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
uint32_t RsBanListSerialiser::size(RsItem *i)
|
void RsGxsReputationSetItem::clear()
|
||||||
{
|
{
|
||||||
RsBanListItem *dri;
|
mOpinions.clear() ;
|
||||||
|
|
||||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
|
||||||
{
|
|
||||||
return sizeList(dri);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsBanListSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
void RsGxsReputationUpdateItem::clear()
|
||||||
{
|
{
|
||||||
RsBanListItem *dri;
|
mOpinions.clear() ;
|
||||||
|
|
||||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
|
||||||
{
|
|
||||||
return serialiseList(dri, data, pktsize);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
/*************************************************************************/
|
||||||
|
/*************************************************************************/
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsReputationConfigItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsReputationSetItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
out << "GxsId: " << mGxsId << std::endl;
|
||||||
|
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
|
||||||
|
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
|
||||||
|
out << "mReputation: " << mReputation << 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;
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsReputationSetItem", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsReputationUpdateItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsReputationUpdateItem", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsReputationRequestItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
uint32_t RsGxsReputationConfigItem::serial_size() const
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
|
||||||
|
s += mPeerId.serial_size() ; // PeerId
|
||||||
|
s += 4 ; // mLatestUpdate
|
||||||
|
s += 4 ; // mLastQuery
|
||||||
|
|
||||||
|
return s ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RsGxsReputationSetItem::serial_size() const
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
|
||||||
|
s += mGxsId.serial_size() ;
|
||||||
|
s += 4 ; // mOwnOpinion
|
||||||
|
s += 4 ; // mOwnOpinionTS
|
||||||
|
s += 4 ; // mReputation
|
||||||
|
|
||||||
|
s += 4 ; // mOpinions.size()
|
||||||
|
|
||||||
|
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
|
||||||
|
|
||||||
|
return s ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RsGxsReputationUpdateItem::serial_size() const
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
|
||||||
|
s += 4 ; // mLatestUpdate
|
||||||
|
s += 4 ; // mOpinions.size();
|
||||||
|
|
||||||
|
s += (RsGxsId::serial_size() + 4) * mOpinions.size() ;
|
||||||
|
|
||||||
|
return s ;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RsGxsReputationRequestItem::serial_size() const
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
|
||||||
|
s += 4 ; // mLastUpdate
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
bool RsGxsReputationConfigItem::serialise(void *data, uint32_t& pktsize) const
|
||||||
|
{
|
||||||
|
uint32_t tlvsize ;
|
||||||
|
uint32_t offset=0;
|
||||||
|
|
||||||
|
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= mPeerId.serialise(data,tlvsize,offset) ;
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mLastQuery);
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||||
|
{
|
||||||
|
uint32_t tlvsize ;
|
||||||
|
uint32_t offset=0;
|
||||||
|
|
||||||
|
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= mGxsId.serialise(data,tlvsize,offset) ;
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion);
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mReputation);
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
|
||||||
|
{
|
||||||
|
uint32_t tlvsize ;
|
||||||
|
uint32_t offset=0;
|
||||||
|
|
||||||
|
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||||
|
|
||||||
|
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it)
|
||||||
|
{
|
||||||
|
ok &= it->first.serialise(data, tlvsize, offset) ;
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
/* serialise the data to the buffer */
|
||||||
|
bool RsGxsReputationRequestItem::serialise(void *data, uint32_t& pktsize) const
|
||||||
|
{
|
||||||
|
uint32_t tlvsize ;
|
||||||
|
uint32_t offset=0;
|
||||||
|
|
||||||
|
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, mLastUpdate);
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size)
|
||||||
|
{
|
||||||
|
uint32_t offset = 8; // skip the header
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
bool ok = true ;
|
||||||
|
|
||||||
|
RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem() ;
|
||||||
|
|
||||||
|
/* add mandatory parts first */
|
||||||
|
ok &= item->mPeerId.deserialise(data, size, offset) ;
|
||||||
|
ok &= getRawUInt32(data, size, &offset, &item->mLatestUpdate);
|
||||||
|
ok &= getRawUInt32(data, size, &offset, &item->mLastQuery);
|
||||||
|
|
||||||
|
if (offset != rssize || !ok)
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||||
|
delete item;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
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->mReputation);
|
||||||
|
|
||||||
|
uint32_t S ;
|
||||||
|
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||||
|
|
||||||
|
for(int 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
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
bool ok = true ;
|
||||||
|
|
||||||
|
RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ;
|
||||||
|
|
||||||
|
/* add mandatory parts first */
|
||||||
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
|
||||||
|
|
||||||
|
uint32_t S ;
|
||||||
|
ok &= getRawUInt32(data, tlvsize, &offset, &S) ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;ok && i<S;++i)
|
||||||
|
{
|
||||||
|
RsGxsId gid ;
|
||||||
|
uint32_t op ;
|
||||||
|
|
||||||
|
ok &= gid.deserialise(data, tlvsize, offset) ;
|
||||||
|
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||||
|
|
||||||
|
if(ok)
|
||||||
|
item->mOpinions[gid] = op ;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset != rssize || !ok)
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||||
|
delete item;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsGxsReputationRequestItem *RsGxsReputationSerialiser::deserialiseReputationRequestItem(void *data,uint32_t tlvsize)
|
||||||
|
{
|
||||||
|
uint32_t offset = 8; // skip the header
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
bool ok = true ;
|
||||||
|
|
||||||
|
RsGxsReputationRequestItem *item = new RsGxsReputationRequestItem() ;
|
||||||
|
|
||||||
|
/* add mandatory parts first */
|
||||||
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUpdate);
|
||||||
|
|
||||||
|
if (offset != rssize || !ok)
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||||
|
delete item;
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
|
RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||||
{
|
{
|
||||||
/* get the type and size */
|
/* get the type and size */
|
||||||
uint32_t rstype = getRsItemId(data);
|
uint32_t rstype = getRsItemId(data);
|
||||||
|
|
||||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_REPUTATION != getRsItemService(rstype)))
|
||||||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)))
|
{
|
||||||
{
|
std::cerr << "RsReputationSerialiser::deserialise(): wrong item type " << std::hex << rstype << std::dec << std::endl;
|
||||||
return NULL; /* wrong type */
|
return NULL; /* wrong type */
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(getRsItemSubType(rstype))
|
switch(getRsItemSubType(rstype))
|
||||||
{
|
{
|
||||||
case RS_PKT_SUBTYPE_BANLIST_ITEM:
|
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
|
||||||
return deserialiseList(data, pktsize);
|
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
|
||||||
break;
|
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:
|
default:
|
||||||
|
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,88 +32,95 @@
|
|||||||
#include "serialiser/rsserial.h"
|
#include "serialiser/rsserial.h"
|
||||||
#include "retroshare/rsgxsifacetypes.h"
|
#include "retroshare/rsgxsifacetypes.h"
|
||||||
|
|
||||||
#define RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM 0x01
|
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||||
#define RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM 0x02
|
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x02
|
||||||
#define RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM 0x03
|
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
|
||||||
#define RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM 0x04
|
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
class RsReputationItem: public RsItem
|
||||||
class RsGxsReputationConfigItem: public RsItem
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsReputationConfigItem()
|
RsReputationItem(uint8_t reputation_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_REPUTATION,reputation_subtype)
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
{
|
||||||
RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM)
|
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
||||||
{
|
}
|
||||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~RsGxsReputationConfigItem();
|
virtual ~RsReputationItem() {}
|
||||||
virtual void clear();
|
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
std::string mPeerId;
|
virtual bool serialise(void *data,uint32_t& size) const = 0 ;
|
||||||
|
virtual uint32_t serial_size() const = 0 ;
|
||||||
|
|
||||||
|
virtual void clear() = 0 ;
|
||||||
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RsGxsReputationConfigItem: public RsReputationItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsGxsReputationConfigItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM) {}
|
||||||
|
|
||||||
|
virtual ~RsGxsReputationConfigItem() {}
|
||||||
|
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 ;
|
||||||
|
|
||||||
|
RsPeerId mPeerId;
|
||||||
uint32_t mLatestUpdate; // timestamp they returned.
|
uint32_t mLatestUpdate; // timestamp they returned.
|
||||||
uint32_t mLastQuery; // when we sent out.
|
uint32_t mLastQuery; // when we sent out.
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGxsReputationSetItem: public RsItem
|
class RsGxsReputationSetItem: public RsReputationItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsReputationSetItem()
|
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) {}
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
|
||||||
RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM)
|
|
||||||
{
|
|
||||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~RsGxsReputationSetItem();
|
virtual ~RsGxsReputationSetItem();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
std::string mGxsId;
|
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||||
|
virtual uint32_t serial_size() const ;
|
||||||
|
|
||||||
|
RsGxsId mGxsId;
|
||||||
uint32_t mOwnOpinion;
|
uint32_t mOwnOpinion;
|
||||||
uint32_t mOwnOpinionTs;
|
uint32_t mOwnOpinionTS;
|
||||||
uint32_t mReputation;
|
uint32_t mReputation;
|
||||||
std::map<std::string, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGxsReputationUpdateItem: public RsItem
|
class RsGxsReputationUpdateItem: public RsReputationItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsReputationUpdateItem()
|
RsGxsReputationUpdateItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM) {}
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
|
||||||
RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM)
|
|
||||||
{
|
|
||||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~RsGxsReputationUpdateItem();
|
virtual ~RsGxsReputationUpdateItem();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||||
uint32_t mLatestUpdate;
|
virtual uint32_t serial_size() const ;
|
||||||
|
|
||||||
|
uint32_t mLatestUpdate;
|
||||||
|
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGxsReputationRequestItem: public RsItem
|
class RsGxsReputationRequestItem: public RsReputationItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsReputationRequestItem()
|
RsGxsReputationRequestItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM) {}
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION,
|
|
||||||
RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM)
|
|
||||||
{
|
|
||||||
setPriorityLevel(QOS_PRIORITY_RS_GXSREPUTATION_ITEM);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~RsGxsReputationRequestItem();
|
virtual ~RsGxsReputationRequestItem();
|
||||||
virtual void clear();
|
virtual void clear() {}
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
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 ;
|
||||||
|
|
||||||
uint32_t mLastUpdate;
|
uint32_t mLastUpdate;
|
||||||
};
|
};
|
||||||
@ -121,39 +128,26 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|||||||
|
|
||||||
class RsGxsReputationSerialiser: public RsSerialType
|
class RsGxsReputationSerialiser: public RsSerialType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsReputationSerialiser()
|
RsGxsReputationSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION){}
|
||||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION)
|
|
||||||
{ return; }
|
|
||||||
virtual ~RsGxsReputationSerialiser()
|
|
||||||
{ return; }
|
|
||||||
|
|
||||||
virtual uint32_t size(RsItem *);
|
|
||||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
||||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
private:
|
virtual ~RsGxsReputationSerialiser(){}
|
||||||
|
|
||||||
virtual uint32_t sizeConfig(RsGxsReputationConfigItem *);
|
|
||||||
virtual bool serialiseConfig(RsGxsReputationConfigItem *item, void *data, uint32_t *size);
|
|
||||||
virtual RsGxsReputationConfigItem *deserialiseConfig(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
|
|
||||||
virtual uint32_t sizeSet(RsGxsReputationSetItem *);
|
|
||||||
virtual bool serialiseSet(RsGxsReputationSetItem *item, void *data, uint32_t *size);
|
|
||||||
virtual RsGxsReputationSetItem *deserialiseSet(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
|
|
||||||
virtual uint32_t sizeUpdate(RsGxsReputationUpdateItem *);
|
|
||||||
virtual bool serialiseUpdate(RsGxsReputationUpdateItem *item, void *data, uint32_t *size);
|
|
||||||
virtual RsGxsReputationUpdateItem *deserialiseUpdate(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
|
|
||||||
virtual uint32_t sizeRequest(RsGxsReputationRequestItem *);
|
|
||||||
virtual bool serialiseRequest(RsGxsReputationRequestItem *item, void *data, uint32_t *size);
|
|
||||||
virtual RsGxsReputationRequestItem *deserialiseRequest(void *data, uint32_t *size);
|
|
||||||
|
|
||||||
|
virtual uint32_t size(RsItem *item)
|
||||||
|
{
|
||||||
|
return dynamic_cast<RsReputationItem*>(item)->serial_size() ;
|
||||||
|
}
|
||||||
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size)
|
||||||
|
{
|
||||||
|
return dynamic_cast<RsReputationItem*>(item)->serialise(data,*size) ;
|
||||||
|
}
|
||||||
|
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 RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
|
||||||
|
static RsGxsReputationRequestItem *deserialiseReputationRequestItem(void *data, uint32_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -184,14 +184,14 @@ bool p3GxsReputation::processIncoming()
|
|||||||
switch(item->PacketSubType())
|
switch(item->PacketSubType())
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case RS_PKT_SUBTYPE_GXSREPUTATION_CONFIG_ITEM:
|
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
|
||||||
case RS_PKT_SUBTYPE_GXSREPUTATION_SET_ITEM:
|
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
|
||||||
std::cerr << "p3GxsReputation::processingIncoming() Unknown Item";
|
std::cerr << "p3GxsReputation::processingIncoming() Unknown Item";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
itemOk = false;
|
itemOk = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_PKT_SUBTYPE_GXSREPUTATION_REQUEST_ITEM:
|
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM:
|
||||||
{
|
{
|
||||||
RsGxsReputationRequestItem *requestItem =
|
RsGxsReputationRequestItem *requestItem =
|
||||||
dynamic_cast<RsGxsReputationRequestItem *>(item);
|
dynamic_cast<RsGxsReputationRequestItem *>(item);
|
||||||
@ -206,7 +206,7 @@ bool p3GxsReputation::processIncoming()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_PKT_SUBTYPE_GXSREPUTATION_UPDATE_ITEM:
|
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM:
|
||||||
{
|
{
|
||||||
RsGxsReputationUpdateItem *updateItem =
|
RsGxsReputationUpdateItem *updateItem =
|
||||||
dynamic_cast<RsGxsReputationUpdateItem *>(item);
|
dynamic_cast<RsGxsReputationUpdateItem *>(item);
|
||||||
@ -465,7 +465,7 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem();
|
RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem();
|
||||||
item->mPeerId = it->first.toStdString();
|
item->mPeerId = it->first;
|
||||||
item->mLatestUpdate = it->second.mLatestUpdate;
|
item->mLatestUpdate = it->second.mLatestUpdate;
|
||||||
item->mLastQuery = it->second.mLastQuery;
|
item->mLastQuery = it->second.mLastQuery;
|
||||||
savelist.push_back(item);
|
savelist.push_back(item);
|
||||||
@ -476,16 +476,16 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
|||||||
for(rit = mReputations.begin(); rit != mReputations.end(); ++rit, count++)
|
for(rit = mReputations.begin(); rit != mReputations.end(); ++rit, count++)
|
||||||
{
|
{
|
||||||
RsGxsReputationSetItem *item = new RsGxsReputationSetItem();
|
RsGxsReputationSetItem *item = new RsGxsReputationSetItem();
|
||||||
item->mGxsId = rit->first.toStdString();
|
item->mGxsId = rit->first;
|
||||||
item->mOwnOpinion = ConvertToSerialised(rit->second.mOwnOpinion, false);
|
item->mOwnOpinion = ConvertToSerialised(rit->second.mOwnOpinion, false);
|
||||||
item->mOwnOpinionTs = rit->second.mOwnOpinionTs;
|
item->mOwnOpinionTS = rit->second.mOwnOpinionTs;
|
||||||
item->mReputation = ConvertToSerialised(rit->second.mReputation, false);
|
item->mReputation = ConvertToSerialised(rit->second.mReputation, false);
|
||||||
|
|
||||||
std::map<RsPeerId, int32_t>::iterator oit;
|
std::map<RsPeerId, int32_t>::iterator oit;
|
||||||
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
|
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
|
||||||
{
|
{
|
||||||
// should be already limited.
|
// should be already limited.
|
||||||
item->mOpinions[oit->first.toStdString()] = ConvertToSerialised(oit->second, false);
|
item->mOpinions[oit->first] = ConvertToSerialised(oit->second, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
savelist.push_back(item);
|
savelist.push_back(item);
|
||||||
@ -548,19 +548,17 @@ bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std:
|
|||||||
Reputation &reputation = mReputations[gxsId];
|
Reputation &reputation = mReputations[gxsId];
|
||||||
|
|
||||||
// install opinions.
|
// install opinions.
|
||||||
std::map<std::string, uint32_t>::const_iterator oit;
|
std::map<RsPeerId, uint32_t>::const_iterator oit;
|
||||||
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); ++oit)
|
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); ++oit)
|
||||||
{
|
{
|
||||||
// expensive ... but necessary.
|
// expensive ... but necessary.
|
||||||
RsPeerId peerId(oit->first);
|
RsPeerId peerId(oit->first);
|
||||||
if (peerSet.end() != peerSet.find(peerId))
|
if (peerSet.end() != peerSet.find(peerId))
|
||||||
{
|
|
||||||
reputation.mOpinions[peerId] = ConvertFromSerialised(oit->second, true);
|
reputation.mOpinions[peerId] = ConvertFromSerialised(oit->second, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reputation.mOwnOpinion = ConvertFromSerialised(item->mOwnOpinion, false);
|
reputation.mOwnOpinion = ConvertFromSerialised(item->mOwnOpinion, false);
|
||||||
reputation.mOwnOpinionTs = item->mOwnOpinionTs;
|
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
|
||||||
|
|
||||||
// if dropping entries has changed the score -> must update.
|
// if dropping entries has changed the score -> must update.
|
||||||
int previous = ConvertFromSerialised(item->mReputation, false);
|
int previous = ConvertFromSerialised(item->mReputation, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user