RetroShare/libretroshare/src/rsitems/rsgxsreputationitems.cc

630 lines
20 KiB
C++
Raw Normal View History

/*
* libretroshare/src/serialiser: rsbanlist.cc
*
* RetroShare Serialiser.
*
* Copyright 2011 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
2015-10-06 00:11:18 -04:00
#include <stdio.h>
#include <time.h>
#include "serialiser/rsbaseserial.h"
2017-04-22 15:36:39 -04:00
#include "rsitems/rsgxsreputationitems.h"
#include "serialization/rstypeserializer.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
2015-10-06 00:11:18 -04:00
/*************************************************************************/
void RsGxsReputationSetItem::clear()
{
mOpinions.clear() ;
}
2015-10-06 00:11:18 -04:00
void RsGxsReputationUpdateItem::clear()
{
2015-10-06 00:11:18 -04:00
mOpinions.clear() ;
}
void RsGxsReputationBannedNodeSetItem::clear()
{
mKnownIdentities.TlvClear();
}
void RsGxsReputationConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastQuery,"mLastQuery") ;
}
void RsGxsReputationBannedNodeSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,mLastActivityTS,"mLastActivityTS") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mKnownIdentities,"mKnownIdentities") ;
}
void RsGxsReputationSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinion,"mOwnOpinion") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinionTS,"mOwnOpinionTS") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mIdentityFlags,"mIdentityFlags") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUsedTS,"mLastUsedTS") ;
RsTypeSerializer::serial_process (j,ctx,mOwnerNodeId,"mOwnerNodeId") ;
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
}
void RsGxsReputationUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
}
void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ;
}
#ifdef TO_REMOVE
// re-defined here, in order to avoid cross-includes
#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100
2015-10-06 00:11:18 -04:00
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent)
{
2015-10-06 00:11:18 -04:00
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;
2015-10-06 00:11:18 -04:00
printRsItemEnd(out, "RsReputationConfigItem", indent);
return out;
}
2015-10-06 00:11:18 -04:00
std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationSetItem", indent);
out << "GxsId: " << mGxsId << std::endl;
out << "Owner: " << mOwnerNodeId << std::endl;
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
2015-10-06 00:11:18 -04:00
out << "Opinions from neighbors: " << std::endl;
2015-10-06 00:11:18 -04:00
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
out << " " << it->first << ": " << it->second << std::endl;
2015-10-06 00:11:18 -04:00
printRsItemEnd(out, "RsReputationSetItem", indent);
return out;
}
std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t indent)
{
2015-10-06 00:11:18 -04:00
printRsItemBase(out, "RsReputationUpdateItem", indent);
out << "from: " << PeerId() << std::endl;
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
2015-10-06 00:11:18 -04:00
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
out << " " << it->first << ": " << it->second << std::endl;
2015-10-06 00:11:18 -04:00
printRsItemEnd(out, "RsReputationUpdateItem", indent);
return out;
}
2015-10-06 00:11:18 -04:00
std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationRequestItem", indent);
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
2015-10-06 00:11:18 -04:00
printRsItemEnd(out, "RsReputationRequestItem", indent);
return out;
}
std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsReputationBannedNodeSetItem", indent);
out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl;
out << "PGP id: " << mPgpId << std::endl;
out << "Known ids: " << mKnownIdentities.ids.size() << std::endl;
printRsItemEnd(out, "RsReputationRequestItem", indent);
return out;
}
2015-10-06 00:11:18 -04:00
/*************************************************************************/
uint32_t RsGxsReputationConfigItem::serial_size() const
{
2015-10-06 00:11:18 -04:00
uint32_t s = 8; /* header */
2015-10-06 00:11:18 -04:00
s += mPeerId.serial_size() ; // PeerId
s += 4 ; // mLatestUpdate
s += 4 ; // mLastQuery
2015-10-06 00:11:18 -04:00
return s ;
}
uint32_t RsGxsReputationSetItem::serial_size() const
{
uint32_t s = 8; /* header */
s += mGxsId.serial_size() ;
2015-10-06 00:11:18 -04:00
s += 4 ; // mOwnOpinion
s += 4 ; // mOwnOpinionTS
s += 4 ; // mIdentityFlags
2017-01-08 05:10:33 -05:00
s += 4 ; // mLastUsedTS
s += mOwnerNodeId.serial_size() ;
2015-10-06 00:11:18 -04:00
s += 4 ; // mOpinions.size()
2015-10-06 00:11:18 -04:00
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
return s ;
2015-10-06 00:11:18 -04:00
}
uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const
{
uint32_t s = 8; /* header */
s += RsPgpId::serial_size() ; // mPgpId
s += 4 ; // mLastActivityTS;
s += mKnownIdentities.TlvSize(); // mKnownIdentities
return s ;
}
2015-10-06 00:11:18 -04:00
uint32_t RsGxsReputationUpdateItem::serial_size() const
{
uint32_t s = 8; /* header */
2015-10-09 17:51:10 -04:00
s += 4 ; // mLatestUpdate
2015-10-06 00:11:18 -04:00
s += 4 ; // mOpinions.size();
s += (RsGxsId::serial_size() + 4) * mOpinions.size() ;
return s ;
}
2015-10-06 00:11:18 -04:00
uint32_t RsGxsReputationRequestItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4 ; // mLastUpdate
2015-10-06 00:11:18 -04:00
return s;
}
2015-10-06 00:11:18 -04:00
/*************************************************************************/
2015-10-06 00:11:18 -04:00
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 ;
2015-10-06 00:11:18 -04:00
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 << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl;
}
return ok;
}
2015-10-06 00:11:18 -04:00
bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
{
2015-10-06 00:11:18 -04:00
uint32_t tlvsize ;
uint32_t offset=0;
2015-10-06 00:11:18 -04:00
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
2015-10-06 00:11:18 -04:00
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, mIdentityFlags) ;
2017-01-08 05:10:33 -05:00
ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ;
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) ;
ok &= setRawUInt32(data, tlvsize, &offset, it->second) ;
}
2015-10-06 00:11:18 -04:00
if (offset != tlvsize)
{
2015-10-06 00:11:18 -04:00
ok = false;
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
}
2015-10-06 00:11:18 -04:00
return ok;
}
bool RsGxsReputationBannedNodeSetItem::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 &= mPgpId.serialise(data, tlvsize, offset) ;
ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS);
ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
}
return ok;
}
2015-10-06 00:11:18 -04:00
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
{
uint32_t tlvsize ;
uint32_t offset=0;
2015-10-06 00:11:18 -04:00
if(!serialise_header(data,pktsize,tlvsize,offset))
return false ;
bool ok = true;
2015-10-06 00:11:18 -04:00
2015-10-09 17:51:10 -04:00
ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate);
2015-10-06 00:11:18 -04:00
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)
{
2015-10-06 00:11:18 -04:00
ok = false;
std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl;
}
2015-10-06 00:11:18 -04:00
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)
{
2015-10-06 00:11:18 -04:00
ok = false;
std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl;
}
2015-10-06 00:11:18 -04:00
return ok;
}
/*************************************************************************/
2015-10-06 00:11:18 -04:00
RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size)
{
2015-10-06 00:11:18 -04:00
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
2015-10-06 00:11:18 -04:00
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;
}
RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ;
/* add mandatory parts first */
ok &= item->mPgpId.deserialise(data, size, offset) ;
ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS);
ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ;
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_deprecated(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) ;
item->mOwnerNodeId.clear(); // clears up, for backward compat.
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
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);
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;
}
2017-01-08 05:10:33 -05:00
RsGxsReputationSetItem_deprecated3 *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated3(void *data,uint32_t tlvsize)
{
2015-10-06 00:11:18 -04:00
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
2017-01-08 05:10:33 -05:00
RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ;
2015-10-06 00:11:18 -04:00
/* 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 &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
2015-10-06 00:11:18 -04:00
uint32_t S ;
ok &= getRawUInt32(data, tlvsize, &offset, &S);
for(uint32_t i = 0; ok && (i < S); ++i)
2015-10-06 00:11:18 -04:00
{
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;
}
2017-01-08 05:10:33 -05:00
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 ;
}
2017-01-08 05:10:33 -05:00
return item;
}
2015-10-06 00:11:18 -04:00
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 */
2015-10-09 17:51:10 -04:00
ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate);
2015-10-06 00:11:18 -04:00
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;
}
2015-10-06 00:11:18 -04:00
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;
}
2015-10-06 00:11:18 -04:00
/*************************************************************************/
RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
2015-10-06 00:11:18 -04:00
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_REPUTATION != getRsItemService(rstype)))
{
std::cerr << "RsReputationSerialiser::deserialise(): wrong item type " << std::hex << rstype << std::dec << std::endl;
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
2017-01-08 05:10:33 -05:00
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:
2015-10-06 00:11:18 -04:00
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
return NULL;
break;
}
}
#endif
/*************************************************************************/
RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const
{
if(service != RS_SERVICE_GXS_TYPE_REPUTATION)
return NULL ;
switch(subtype)
{
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return new RsGxsReputationSetItem() ;
case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM : return new RsGxsReputationBannedNodeSetItem();
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return new RsGxsReputationUpdateItem();
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return new RsGxsReputationRequestItem() ;
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return new RsGxsReputationConfigItem () ;
default:
std::cerr << "(EE) RsGxsReputationSerialiser::create_item(): unhandled item type " << subtype << std::endl;
return NULL ;
}
}