mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 06:32:55 -04:00
almost done with load/save of BanLists. Changed the item format to include masked_bytes, and changed subitem types. Also disabled code from rsgxsreputationitems.cc wich was a copy of the code from rsbanlistitems.cc
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8316 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4ebc87b9c2
commit
20a2d42038
9 changed files with 376 additions and 68 deletions
|
@ -64,6 +64,15 @@ uint32_t RsBanListSerialiser::sizeList(RsBanListItem *item)
|
|||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsBanListSerialiser::sizeListConfig(RsBanListConfigItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += item->banned_peers.TlvSize();
|
||||
s += 8 ; // update time
|
||||
s += item->peerId.serial_size() ;
|
||||
|
||||
return s;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
|
@ -100,8 +109,95 @@ bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uin
|
|||
|
||||
return ok;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBanListSerialiser::serialiseListConfig(RsBanListConfigItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeListConfig(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBanListSerialiser::serialiseRoute() Header: " << ok << std::endl;
|
||||
std::cerr << "RsBanListSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->peerId.serialise(data, tlvsize, offset);
|
||||
ok &= setRawTimeT(data, tlvsize, &offset,item->update_time);
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->banned_peers.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBanListSerialiser::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;
|
||||
}
|
||||
RsBanListConfigItem *RsBanListSerialiser::deserialiseListConfig(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
@ -112,7 +208,7 @@ RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsiz
|
|||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_BANLIST_ITEM != getRsItemSubType(rstype)))
|
||||
(RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
@ -126,14 +222,17 @@ RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsiz
|
|||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsBanListItem *item = new RsBanListItem();
|
||||
RsBanListConfigItem *item = new RsBanListConfigItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->peerList.GetTlv(data, tlvsize, &offset);
|
||||
ok &= item->peerId.deserialise(data, tlvsize, offset);
|
||||
ok &= getRawTimeT(data, tlvsize, &offset,item->update_time);
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->banned_peers.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -156,23 +255,34 @@ RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsiz
|
|||
uint32_t RsBanListSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsBanListItem *dri;
|
||||
RsBanListConfigItem *drc;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
||||
{
|
||||
return sizeList(dri);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NULL != (drc = dynamic_cast<RsBanListConfigItem *>(i)))
|
||||
{
|
||||
return sizeListConfig(drc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsBanListSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsBanListItem *dri;
|
||||
RsBanListConfigItem *drc;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
||||
{
|
||||
return serialiseList(dri, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
if (NULL != (drc = dynamic_cast<RsBanListConfigItem *>(i)))
|
||||
{
|
||||
return serialiseListConfig(drc, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
|
@ -191,10 +301,28 @@ RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||
case RS_PKT_SUBTYPE_BANLIST_ITEM:
|
||||
return deserialiseList(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
case RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM:
|
||||
return deserialiseListConfig(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RsBanListConfigItem::clear()
|
||||
{
|
||||
banned_peers.TlvClear() ;
|
||||
}
|
||||
|
||||
std::ostream &RsBanListConfigItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsBanListConfigItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
banned_peers.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out, "RsBanListConfigItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x02
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -47,33 +49,51 @@ class RsBanListItem: public RsItem
|
|||
return;
|
||||
}
|
||||
|
||||
virtual ~RsBanListItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual ~RsBanListItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvBanList peerList;
|
||||
|
||||
};
|
||||
|
||||
class RsBanListConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsBanListConfigItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM) {}
|
||||
|
||||
virtual ~RsBanListConfigItem(){}
|
||||
virtual void clear();
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPeerId peerId ;
|
||||
time_t update_time ;
|
||||
RsTlvBanList banned_peers;
|
||||
};
|
||||
|
||||
class RsBanListSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsBanListSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST)
|
||||
{ return; }
|
||||
virtual ~RsBanListSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
public:
|
||||
RsBanListSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST)
|
||||
{ return; }
|
||||
virtual ~RsBanListSerialiser()
|
||||
{ return; }
|
||||
|
||||
private:
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeList(RsBanListItem *);
|
||||
virtual bool serialiseList (RsBanListItem *item, void *data, uint32_t *size);
|
||||
virtual RsBanListItem *deserialiseList(void *data, uint32_t *size);
|
||||
private:
|
||||
|
||||
virtual uint32_t sizeList(RsBanListItem *);
|
||||
virtual bool serialiseList (RsBanListItem *item, void *data, uint32_t *size);
|
||||
virtual RsBanListItem *deserialiseList(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeListConfig(RsBanListConfigItem *);
|
||||
virtual bool serialiseListConfig (RsBanListConfigItem *item, void *data, uint32_t *size);
|
||||
virtual RsBanListConfigItem *deserialiseListConfig(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef SUSPENDED
|
||||
RsBanListItem::~RsBanListItem()
|
||||
{
|
||||
return;
|
||||
|
@ -197,6 +198,7 @@ RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ uint32_t RsTlvBanListEntry::TlvSize() const
|
|||
s += 4; // level;
|
||||
s += 4; // reason;
|
||||
s += 4; // age;
|
||||
s += 1; // masked_bytes;
|
||||
|
||||
return s;
|
||||
|
||||
|
@ -79,7 +80,9 @@ bool RsTlvBanListEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) con
|
|||
ok &= setRawUInt32(data, tlvend, offset, level);
|
||||
ok &= setRawUInt32(data, tlvend, offset, reason);
|
||||
ok &= setRawUInt32(data, tlvend, offset, age);
|
||||
return ok;
|
||||
ok &= setRawUInt8(data, tlvend, offset, masked_bytes);
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
|
@ -110,7 +113,11 @@ bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|||
ok &= addr.GetTlv(data, tlvend, offset);
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(level));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(reason));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(age));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(age));
|
||||
|
||||
uint8_t tmp ;
|
||||
ok &= getRawUInt8(data, tlvend, offset, &(tmp));
|
||||
masked_bytes = tmp ;
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
|
@ -153,8 +160,13 @@ std::ostream &RsTlvBanListEntry::print(std::ostream &out, uint16_t indent) const
|
|||
out << "age:" << age;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvBanListEntry", indent);
|
||||
return out;
|
||||
printIndent(out, int_Indent);
|
||||
out << "masked bytes:" << masked_bytes;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvBanListEntry", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
|||
uint8_t masked_bytes ;
|
||||
};
|
||||
|
||||
|
||||
typedef t_RsTlvList<RsTlvBanListEntry,TLV_TYPE_BAN_LIST> RsTlvBanList;
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue