mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
moved rsconfigitems and rshistoryitems to rsitems/
This commit is contained in:
parent
f7338d4a3d
commit
0d7df568b4
24 changed files with 35 additions and 29 deletions
267
libretroshare/src/rsitems/rsconfigitems.cc
Normal file
267
libretroshare/src/rsitems/rsconfigitems.cc
Normal file
|
@ -0,0 +1,267 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsconfigitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie, Chris Parker.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
***/
|
||||
|
||||
#define RSSERIAL_ERROR_DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsFileConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_FILE_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FILE_TRANSFER: return new RsFileTransfer() ;
|
||||
case RS_PKT_SUBTYPE_FILE_ITEM: return new RsFileConfigItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
void RsFileTransfer::clear()
|
||||
{
|
||||
|
||||
file.TlvClear();
|
||||
allPeerIds.TlvClear();
|
||||
cPeerId.clear() ;
|
||||
state = 0;
|
||||
in = false;
|
||||
transferred = 0;
|
||||
crate = 0;
|
||||
trate = 0;
|
||||
lrate = 0;
|
||||
ltransfer = 0;
|
||||
|
||||
}
|
||||
|
||||
void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,allPeerIds,"allPeerIds") ;
|
||||
|
||||
RsTypeSerializer::serial_process (j,ctx,cPeerId,"cPeerId") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,state,"state") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,in,"in") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,transferred,"transferred") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,crate,"crate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,trate,"trate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,lrate,"lrate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,ltransfer,"ltransfer") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunk_strategy,"chunk_strategy") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ;
|
||||
}
|
||||
|
||||
void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,parent_groups,"parent_groups") ;
|
||||
}
|
||||
|
||||
RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_GENERAL_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_KEY_VALUE: return new RsConfigKeyValueSet();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsConfigKeyValueSet::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,tlvkvs,"tlvkvs") ;
|
||||
}
|
||||
|
||||
RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_PEER_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_PEER_NET: return new RsPeerNetItem();
|
||||
case RS_PKT_SUBTYPE_PEER_STUN: return new RsPeerStunItem();
|
||||
case RS_PKT_SUBTYPE_NODE_GROUP: return new RsNodeGroupItem() ;
|
||||
case RS_PKT_SUBTYPE_PEER_PERMISSIONS: return new RsPeerServicePermissionItem();
|
||||
case RS_PKT_SUBTYPE_PEER_BANDLIMITS: return new RsPeerBandwidthLimitsItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsPeerNetItem::clear()
|
||||
{
|
||||
peerId.clear();
|
||||
pgpId.clear();
|
||||
location.clear();
|
||||
netMode = 0;
|
||||
vs_disc = 0;
|
||||
vs_dht = 0;
|
||||
lastContact = 0;
|
||||
|
||||
localAddrV4.TlvClear();
|
||||
extAddrV4.TlvClear();
|
||||
localAddrV6.TlvClear();
|
||||
extAddrV6.TlvClear();
|
||||
|
||||
dyndns.clear();
|
||||
|
||||
localAddrList.TlvClear();
|
||||
extAddrList.TlvClear();
|
||||
|
||||
domain_addr.clear();
|
||||
domain_port = 0;
|
||||
}
|
||||
void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION,location,"location") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,netMode,"netMode") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_disc,"vs_disc") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_dht,"vs_dht") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lastContact,"lastContact") ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV4,"localAddrV4") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrV4,"extAddrV4") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV6,"localAddrV6") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrV6,"extAddrV6") ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DYNDNS,dyndns,"dyndns") ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrList,"localAddrList") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrList,"extAddrList") ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DOMADDR,domain_addr,"domain_addr") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,domain_port,"domain_port") ;
|
||||
}
|
||||
|
||||
void RsPeerBandwidthLimitsItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peers,"peers") ;
|
||||
}
|
||||
|
||||
void RsPeerStunItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& s)
|
||||
{
|
||||
return 4+4 ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const PeerBandwidthLimits& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
ok = ok && setRawUInt32(data,size,&offset,s.max_up_rate_kbs);
|
||||
ok = ok && setRawUInt32(data,size,&offset,s.max_dl_rate_kbs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,PeerBandwidthLimits& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
ok = ok && getRawUInt32(data,size,&offset,&s.max_up_rate_kbs);
|
||||
ok = ok && getRawUInt32(data,size,&offset,&s.max_dl_rate_kbs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const PeerBandwidthLimits& s)
|
||||
{
|
||||
std::cerr << " [Peer BW limit] " << s.max_up_rate_kbs << " / " << s.max_dl_rate_kbs << std::endl;
|
||||
}
|
||||
|
||||
RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
|
||||
{
|
||||
id = g.id ;
|
||||
name = g.name ;
|
||||
flag = g.flag ;
|
||||
pgpList.ids = g.peerIds;
|
||||
}
|
||||
|
||||
void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"dummy field 0") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,id,"id") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,name,"name") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flag,"flag") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpList,"pgpList") ;
|
||||
}
|
||||
|
||||
void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
// We need to hack this because of backward compatibility. The correct way to do it would be:
|
||||
//
|
||||
// RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ;
|
||||
// RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ;
|
||||
|
||||
if(j == RsItem::DESERIALIZE)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"pgp_ids.size()") ;
|
||||
|
||||
pgp_ids.resize(v) ;
|
||||
service_flags.resize(v) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t s = pgp_ids.size();
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s,"pgp_ids.size()") ;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<pgp_ids.size();++i)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,pgp_ids[i],"pgp_ids[i]") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,service_flags[i],"service_flags[i]") ;
|
||||
}
|
||||
}
|
||||
|
376
libretroshare/src/rsitems/rsconfigitems.h
Normal file
376
libretroshare/src/rsitems/rsconfigitems.h
Normal file
|
@ -0,0 +1,376 @@
|
|||
#ifndef RS_CONFIG_ITEMS_SERIALISER_H
|
||||
#define RS_CONFIG_ITEMS_SERIALISER_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsconfigitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvkeyvalue.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
|
||||
class RsGroupInfo;
|
||||
|
||||
const uint8_t RS_PKT_TYPE_GENERAL_CONFIG = 0x01;
|
||||
const uint8_t RS_PKT_TYPE_PEER_CONFIG = 0x02;
|
||||
const uint8_t RS_PKT_TYPE_CACHE_CONFIG = 0x03;
|
||||
const uint8_t RS_PKT_TYPE_FILE_CONFIG = 0x04;
|
||||
const uint8_t RS_PKT_TYPE_PLUGIN_CONFIG = 0x05;
|
||||
const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
|
||||
|
||||
/* GENERAL CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
|
||||
|
||||
/* PEER CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP_deprecated = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
|
||||
|
||||
/* FILE CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM_deprecated = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsPeerNetItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerNetItem()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_PEER_CONFIG,
|
||||
RS_PKT_SUBTYPE_PEER_NET) {}
|
||||
|
||||
virtual ~RsPeerNetItem(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
/* networking information */
|
||||
RsPeerId peerId; /* Mandatory */
|
||||
RsPgpId pgpId; /* Mandatory */
|
||||
std::string location; /* Mandatory */
|
||||
uint32_t netMode; /* Mandatory */
|
||||
uint16_t vs_disc; /* Mandatory */
|
||||
uint16_t vs_dht; /* Mandatory */
|
||||
uint32_t lastContact; /* Mandatory */
|
||||
|
||||
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||
|
||||
std::string dyndns;
|
||||
|
||||
RsTlvIpAddrSet localAddrList;
|
||||
RsTlvIpAddrSet extAddrList;
|
||||
|
||||
// for proxy connection.
|
||||
std::string domain_addr;
|
||||
uint16_t domain_port;
|
||||
};
|
||||
|
||||
// This item should be merged with the next item, but that is not backward compatible.
|
||||
class RsPeerServicePermissionItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerServicePermissionItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_PERMISSIONS) {}
|
||||
virtual ~RsPeerServicePermissionItem() {}
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
pgp_ids.clear() ;
|
||||
service_flags.clear() ;
|
||||
}
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
|
||||
/* Mandatory */
|
||||
std::vector<RsPgpId> pgp_ids ;
|
||||
std::vector<ServicePermissionFlags> service_flags ;
|
||||
};
|
||||
class RsPeerBandwidthLimitsItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerBandwidthLimitsItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_BANDLIMITS) {}
|
||||
virtual ~RsPeerBandwidthLimitsItem() {}
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
peers.clear() ;
|
||||
}
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
/* Mandatory */
|
||||
std::map<RsPgpId,PeerBandwidthLimits> peers ;
|
||||
};
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
class RsPeerGroupItem_deprecated : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerGroupItem_deprecated();
|
||||
virtual ~RsPeerGroupItem_deprecated();
|
||||
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
/* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
void set(RsGroupInfo &groupInfo);
|
||||
/* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
void get(RsGroupInfo &groupInfo);
|
||||
|
||||
/* Mandatory */
|
||||
std::string id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsNodeGroupItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsNodeGroupItem(): RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP){}
|
||||
virtual ~RsNodeGroupItem() {}
|
||||
|
||||
virtual void clear() { pgpList.TlvClear();}
|
||||
|
||||
explicit RsNodeGroupItem(const RsGroupInfo&) ;
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
// /* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void set(RsGroupInfo &groupInfo);
|
||||
// /* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void get(RsGroupInfo &groupInfo);
|
||||
|
||||
/* Mandatory */
|
||||
RsNodeGroupId id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
|
||||
class RsPeerStunItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerStunItem()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_PEER_CONFIG,
|
||||
RS_PKT_SUBTYPE_PEER_STUN) {}
|
||||
virtual ~RsPeerStunItem(){}
|
||||
virtual void clear() { stunList.TlvClear() ;}
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
RsTlvPeerIdSet stunList; /* Mandatory */
|
||||
};
|
||||
|
||||
class RsPeerConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsPeerConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PEER_CONFIG) {}
|
||||
|
||||
virtual ~RsPeerConfigSerialiser(){}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
class RsCacheConfig: public RsItem
|
||||
{
|
||||
public:
|
||||
RsCacheConfig()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_CACHE_CONFIG,
|
||||
RS_PKT_SUBTYPE_DEFAULT)
|
||||
{ return; }
|
||||
virtual ~RsCacheConfig();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPeerId pid; /* Mandatory */
|
||||
uint16_t cachetypeid; /* Mandatory */
|
||||
uint16_t cachesubid; /* Mandatory */
|
||||
|
||||
std::string path; /* Mandatory */
|
||||
std::string name; /* Mandatory */
|
||||
RsFileHash hash; /* Mandatory */
|
||||
uint64_t size; /* Mandatory */
|
||||
|
||||
uint32_t recvd; /* Mandatory */
|
||||
};
|
||||
|
||||
|
||||
class RsCacheConfigSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsCacheConfigSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_CACHE_CONFIG)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsCacheConfigSerialiser();
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransfer: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileTransfer() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_TRANSFER)
|
||||
{
|
||||
state = 0;
|
||||
in = 0;
|
||||
transferred = 0;
|
||||
crate = 0;
|
||||
trate = 0;
|
||||
lrate = 0;
|
||||
ltransfer = 0;
|
||||
flags = 0;
|
||||
chunk_strategy = 0;
|
||||
}
|
||||
virtual ~RsFileTransfer(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
RsTlvFileItem file;
|
||||
RsTlvPeerIdSet allPeerIds;
|
||||
|
||||
RsPeerId cPeerId;
|
||||
|
||||
uint16_t state;
|
||||
uint16_t in;
|
||||
|
||||
uint64_t transferred;
|
||||
uint32_t crate;
|
||||
uint32_t trate;
|
||||
|
||||
uint32_t lrate;
|
||||
uint32_t ltransfer;
|
||||
|
||||
// chunk information
|
||||
uint32_t flags ;
|
||||
uint32_t chunk_strategy ; // strategy flags for chunks
|
||||
CompressedChunkMap compressed_chunk_map ; // chunk availability (bitwise)
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/* Used by ft / extralist / configdirs / anyone who wants a basic file */
|
||||
class RsFileConfigItem_deprecated: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem_deprecated()
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
||||
RS_PKT_TYPE_FILE_CONFIG,
|
||||
RS_PKT_SUBTYPE_FILE_ITEM_deprecated)
|
||||
{}
|
||||
virtual ~RsFileConfigItem_deprecated() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
std::list<std::string> parent_groups ;
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsFileConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_ITEM) {}
|
||||
virtual ~RsFileConfigItem() {}
|
||||
virtual void clear() { parent_groups.TlvClear(); }
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
RsTlvNodeGroupIdSet parent_groups ;
|
||||
};
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsFileConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG) { }
|
||||
virtual ~RsFileConfigSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
/* Config items that are used generally */
|
||||
|
||||
class RsConfigKeyValueSet: public RsItem
|
||||
{
|
||||
public:
|
||||
RsConfigKeyValueSet() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG, RS_PKT_SUBTYPE_KEY_VALUE) {}
|
||||
virtual ~RsConfigKeyValueSet(){}
|
||||
virtual void clear() { tlvkvs.TlvClear();}
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
RsTlvKeyValueSet tlvkvs;
|
||||
};
|
||||
|
||||
|
||||
class RsGeneralConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsGeneralConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG) {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_CONFIG_ITEMS_SERIALISER_H */
|
294
libretroshare/src/rsitems/rshistoryitems.cc
Normal file
294
libretroshare/src/rsitems/rshistoryitems.cc
Normal file
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 by Thunder.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsitems/rshistoryitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void RsHistoryMsgItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
uint16_t version=0;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,version,"version") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,chatPeerId,"chatPeerId") ;
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,incoming,"incoming") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,peerName,"peerName") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message") ;
|
||||
}
|
||||
|
||||
RsItem *RsHistorySerialiser::create_item(uint8_t serial_class,uint8_t serial_type) const
|
||||
{
|
||||
if(serial_class != RS_PKT_CLASS_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
if(serial_type == RS_PKT_SUBTYPE_DEFAULT)
|
||||
return new RsHistoryMsgItem();
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG, RS_PKT_SUBTYPE_DEFAULT)
|
||||
{
|
||||
incoming = false;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
msgId = 0;
|
||||
saveToDisc = true;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
|
||||
/*************************************************************************/
|
||||
RsHistoryMsgItem::~RsHistoryMsgItem()
|
||||
{
|
||||
}
|
||||
|
||||
void RsHistoryMsgItem::clear()
|
||||
{
|
||||
incoming = false;
|
||||
peerId.clear();
|
||||
peerName.clear();
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
message.clear();
|
||||
msgId = 0;
|
||||
saveToDisc = true;
|
||||
}
|
||||
|
||||
std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsHistoryMsgItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "chatPeerid: " << chatPeerId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "incoming: " << (incoming ? "1" : "0") << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerId: " << peerId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerName: " << peerName << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "sendTime: " << sendTime << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "recvTime: " << recvTime << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_message(message.begin(), message.end());
|
||||
out << "message: " << cnv_message << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsHistoryMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
RsHistorySerialiser::~RsHistorySerialiser()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 2; /* version */
|
||||
s += item->chatPeerId.serial_size();
|
||||
s += 1; /* incoming */
|
||||
s += item->peerId.serial_size();
|
||||
s += GetTlvStringSize(item->peerName);
|
||||
s += 4; /* sendTime */
|
||||
s += 4; /* recvTime */
|
||||
s += GetTlvStringSize(item->message);
|
||||
|
||||
return s;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeHistoryMsgItem(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 << "RsHistorySerialiser::serialiseItem() Header: " << ok << std::endl;
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, 0); // version
|
||||
ok &= item->chatPeerId.serialise(data, tlvsize, offset) ;
|
||||
uint8_t dummy = item->incoming ? 1 : 0;
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, dummy);
|
||||
ok &= item->peerId.serialise(data, tlvsize, offset) ;
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->message);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsHistoryMsgItem *item = new RsHistoryMsgItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
uint16_t version = 0;
|
||||
ok &= getRawUInt16(data, rssize, &offset, &version);
|
||||
ok &= item->chatPeerId.deserialise(data, rssize, offset) ;
|
||||
uint8_t dummy;
|
||||
ok &= getRawUInt8(data, rssize, &offset, &dummy);
|
||||
item->incoming = (dummy == 1);
|
||||
ok &= item->peerId.deserialise(data, rssize, offset) ;
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime));
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsHistorySerialiser::size(RsItem *item)
|
||||
{
|
||||
RsHistoryMsgItem* hi;
|
||||
|
||||
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
|
||||
{
|
||||
return sizeHistoryMsgItem(hi);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsHistorySerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsHistoryMsgItem* hi;
|
||||
|
||||
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
|
||||
{
|
||||
return serialiseHistoryMsgItem(hi, data, pktsize);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DEFAULT:
|
||||
return deserialiseHistoryMsgItem(data, pktsize);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#endif
|
73
libretroshare/src/rsitems/rshistoryitems.h
Normal file
73
libretroshare/src/rsitems/rshistoryitems.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
#ifndef RS_HISTORY_ITEMS_H
|
||||
#define RS_HISTORY_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Thunder.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsHistoryMsgItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsHistoryMsgItem();
|
||||
virtual ~RsHistoryMsgItem() {}
|
||||
virtual void clear() {}
|
||||
|
||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
RsPeerId chatPeerId; // empty for global chat
|
||||
bool incoming;
|
||||
RsPeerId peerId;
|
||||
std::string peerName;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::string message;
|
||||
|
||||
/* not serialised */
|
||||
uint32_t msgId;
|
||||
bool saveToDisc;
|
||||
};
|
||||
|
||||
class RsHistorySerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsHistorySerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) {}
|
||||
virtual ~RsHistorySerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t service,uint8_t type) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_HISTORY_ITEMS_H */
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue