2014-02-19 06:08:37 -05:00
|
|
|
/*
|
|
|
|
* 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>
|
2015-10-12 17:21:17 -04:00
|
|
|
#include <time.h>
|
2014-02-19 06:08:37 -05:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
2015-10-06 00:11:18 -04:00
|
|
|
#include "serialiser/rsgxsreputationitems.h"
|
2014-02-19 06:08:37 -05:00
|
|
|
|
|
|
|
/***
|
|
|
|
#define RSSERIAL_DEBUG 1
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2015-10-25 22:54:56 -04:00
|
|
|
// re-defined here, in order to avoid cross-includes
|
|
|
|
#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100
|
|
|
|
|
2014-02-19 06:08:37 -05:00
|
|
|
/*************************************************************************/
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
bool RsReputationItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
tlvsize = serial_size() ;
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
if (pktsize < tlvsize)
|
|
|
|
return false; /* not enough space */
|
|
|
|
|
|
|
|
pktsize = tlvsize;
|
|
|
|
|
|
|
|
if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
|
|
|
|
{
|
|
|
|
std::cerr << "RsReputationItem::serialise_header(): ERROR. Not enough size!" << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
#ifdef RSSERIAL_DEBUG
|
|
|
|
std::cerr << "RsReputationItem::serialise() Header: " << ok << std::endl;
|
|
|
|
#endif
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
void RsGxsReputationSetItem::clear()
|
|
|
|
{
|
|
|
|
mOpinions.clear() ;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
void RsGxsReputationUpdateItem::clear()
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
mOpinions.clear() ;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
printRsItemBase(out, "RsReputationConfigItem", indent);
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2016-08-02 17:57:11 -04:00
|
|
|
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);
|
2014-02-19 06:08:37 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsReputationSetItem", indent);
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2016-08-02 17:57:11 -04:00
|
|
|
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;
|
2016-08-02 17:57:11 -04:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
2016-08-02 17:57:11 -04:00
|
|
|
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)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
printRsItemBase(out, "RsReputationUpdateItem", indent);
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2016-08-02 17:57:11 -04:00
|
|
|
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)
|
2016-08-02 17:57:11 -04:00
|
|
|
out << " " << it->first << ": " << it->second << std::endl;
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
printRsItemEnd(out, "RsReputationUpdateItem", indent);
|
|
|
|
return out;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
2015-10-06 00:11:18 -04:00
|
|
|
std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent)
|
|
|
|
{
|
|
|
|
printRsItemBase(out, "RsReputationRequestItem", indent);
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2016-08-02 17:57:11 -04:00
|
|
|
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
uint32_t RsGxsReputationConfigItem::serial_size() const
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
uint32_t s = 8; /* header */
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
s += mPeerId.serial_size() ; // PeerId
|
|
|
|
s += 4 ; // mLatestUpdate
|
|
|
|
s += 4 ; // mLastQuery
|
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsGxsReputationSetItem::serial_size() const
|
|
|
|
{
|
2016-08-02 17:57:11 -04:00
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
|
|
|
s += mGxsId.serial_size() ;
|
2015-10-06 00:11:18 -04:00
|
|
|
s += 4 ; // mOwnOpinion
|
|
|
|
s += 4 ; // mOwnOpinionTS
|
2015-10-25 23:45:33 -04:00
|
|
|
s += 4 ; // mIdentityFlags
|
2016-08-02 17:57:11 -04:00
|
|
|
s += mOwnerNodeId.serial_size() ;
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
s += 4 ; // mOpinions.size()
|
2016-08-02 17:57:11 -04:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
|
2016-08-02 17:57:11 -04:00
|
|
|
|
|
|
|
return s ;
|
2015-10-06 00:11:18 -04:00
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
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 ;
|
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
uint32_t RsGxsReputationRequestItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8; /* header */
|
|
|
|
|
|
|
|
s += 4 ; // mLastUpdate
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
return s;
|
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
/*************************************************************************/
|
2014-02-19 06:08:37 -05: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 ;
|
2014-02-19 06:08:37 -05:00
|
|
|
|
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);
|
2014-02-19 06:08:37 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-10-08 23:02:34 -04:00
|
|
|
std::cerr << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2015-10-25 22:54:56 -04:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
uint32_t tlvsize ;
|
|
|
|
uint32_t offset=0;
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
if(!serialise_header(data,pktsize,tlvsize,offset))
|
|
|
|
return false ;
|
2014-02-19 06:08:37 -05:00
|
|
|
|
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);
|
2015-10-25 22:54:56 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ;
|
2016-08-02 17:57:11 -04:00
|
|
|
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
|
|
|
|
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
|
|
|
|
2015-10-08 23:02:34 -04:00
|
|
|
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) ;
|
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
if (offset != tlvsize)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
ok = false;
|
2015-10-08 23:02:34 -04:00
|
|
|
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
|
|
|
|
{
|
|
|
|
uint32_t tlvsize ;
|
|
|
|
uint32_t offset=0;
|
2014-02-19 06:08:37 -05:00
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
if(!serialise_header(data,pktsize,tlvsize,offset))
|
|
|
|
return false ;
|
2014-02-19 06:08:37 -05:00
|
|
|
|
|
|
|
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) ;
|
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
ok = false;
|
2015-10-08 23:02:34 -04:00
|
|
|
std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
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)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
ok = false;
|
2015-10-08 23:02:34 -04:00
|
|
|
std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
return ok;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
2014-02-19 06:08:37 -05:00
|
|
|
|
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;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
2015-10-25 22:54:56 -04:00
|
|
|
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) ;
|
2016-08-02 17:57:11 -04:00
|
|
|
|
|
|
|
item->mOwnerNodeId.clear(); // clears up, for backward compat.
|
|
|
|
|
2015-10-25 22:54:56 -04:00
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
2016-08-02 17:57:11 -04:00
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
|
|
|
|
2015-10-25 22:54:56 -04:00
|
|
|
uint32_t S ;
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
2016-08-02 17:57:11 -04:00
|
|
|
|
2016-06-02 08:53:15 -04:00
|
|
|
for(uint32_t i = 0; ok && (i < S); ++i)
|
2015-10-25 22:54:56 -04:00
|
|
|
{
|
|
|
|
RsPeerId pid ;
|
|
|
|
uint32_t op ;
|
2016-08-02 17:57:11 -04:00
|
|
|
|
|
|
|
ok &= pid.deserialise(data, tlvsize, offset) ;
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
|
|
|
|
2015-10-25 22:54:56 -04:00
|
|
|
if(ok)
|
2016-08-02 17:57:11 -04:00
|
|
|
item->mOpinions[pid] = op ;
|
2015-10-25 22:54:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2016-08-02 17:57:11 -04:00
|
|
|
delete item;
|
2015-10-25 22:54:56 -04:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2015-10-06 00:11:18 -04:00
|
|
|
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
2015-10-06 00:11:18 -04:00
|
|
|
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);
|
2015-10-25 22:54:56 -04:00
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
2016-08-02 17:57:11 -04:00
|
|
|
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
|
|
|
|
|
2015-10-06 00:11:18 -04:00
|
|
|
uint32_t S ;
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
|
|
|
|
2016-06-02 08:53:15 -04:00
|
|
|
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;
|
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
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;
|
2014-02-19 06:08:37 -05:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
|
2014-02-19 06:08:37 -05:00
|
|
|
{
|
|
|
|
/* 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 */
|
|
|
|
}
|
2014-02-19 06:08:37 -05:00
|
|
|
|
|
|
|
switch(getRsItemSubType(rstype))
|
|
|
|
{
|
2016-08-02 17:57:11 -04:00
|
|
|
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);
|
|
|
|
|
2014-02-19 06:08:37 -05:00
|
|
|
default:
|
2015-10-06 00:11:18 -04:00
|
|
|
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
|
2014-02-19 06:08:37 -05:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|