2007-11-15 23:45:00 -05:00
|
|
|
#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>
|
2009-12-10 17:55:27 -05:00
|
|
|
#include <vector>
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rstypes.h"
|
2007-12-11 19:54:42 -05:00
|
|
|
#include "serialiser/rsserial.h"
|
2014-03-29 11:34:37 -04:00
|
|
|
|
|
|
|
#include "serialiser/rstlvidset.h"
|
|
|
|
#include "serialiser/rstlvfileitem.h"
|
|
|
|
#include "serialiser/rstlvkeyvalue.h"
|
|
|
|
#include "serialiser/rstlvaddrs.h"
|
|
|
|
|
2010-09-22 18:37:57 -04:00
|
|
|
class RsGroupInfo;
|
|
|
|
|
2008-01-25 02:52:46 -05:00
|
|
|
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;
|
2011-07-05 16:29:07 -04:00
|
|
|
const uint8_t RS_PKT_TYPE_PLUGIN_CONFIG = 0x05;
|
2011-09-29 05:20:09 -04:00
|
|
|
const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
|
2008-01-25 02:52:46 -05:00
|
|
|
|
|
|
|
/* GENERAL CONFIG SUBTYPES */
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* PEER CONFIG SUBTYPES */
|
2012-12-01 14:22:22 -05:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
|
2013-09-13 10:35:19 -04:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
|
2012-12-01 14:22:22 -05:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP = 0x04;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-11-15 15:00:29 -05:00
|
|
|
/* FILE CONFIG SUBTYPES */
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x02;
|
|
|
|
|
2007-11-15 23:45:00 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
class RsPeerNetItem: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-02-07 11:18:34 -05:00
|
|
|
RsPeerNetItem()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_PEER_CONFIG,
|
2008-02-07 11:18:34 -05:00
|
|
|
RS_PKT_SUBTYPE_PEER_NET)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2008-02-07 11:18:34 -05:00
|
|
|
virtual ~RsPeerNetItem();
|
2007-11-15 23:45:00 -05:00
|
|
|
virtual void clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* networking information */
|
2014-04-01 04:00:20 -04:00
|
|
|
RsPeerId peerId; /* Mandatory */
|
|
|
|
RsPgpId pgpId; /* Mandatory */
|
|
|
|
std::string location; /* Mandatory */
|
2010-01-13 16:22:52 -05:00
|
|
|
uint32_t netMode; /* Mandatory */
|
2013-09-28 04:09:59 -04:00
|
|
|
uint16_t vs_disc; /* Mandatory */
|
|
|
|
uint16_t vs_dht; /* Mandatory */
|
2008-02-07 11:18:34 -05:00
|
|
|
uint32_t lastContact; /* Mandatory */
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2013-09-28 04:09:59 -04:00
|
|
|
RsTlvIpAddress localAddrV4; /* Mandatory */
|
|
|
|
RsTlvIpAddress extAddrV4; /* Mandatory */
|
|
|
|
RsTlvIpAddress localAddrV6; /* Mandatory */
|
|
|
|
RsTlvIpAddress extAddrV6; /* Mandatory */
|
|
|
|
|
2010-04-22 14:49:08 -04:00
|
|
|
std::string dyndns;
|
2009-11-11 11:43:51 -05:00
|
|
|
|
2010-07-04 06:17:37 -04:00
|
|
|
RsTlvIpAddrSet localAddrList;
|
|
|
|
RsTlvIpAddrSet extAddrList;
|
2013-09-03 09:35:39 -04:00
|
|
|
|
|
|
|
// for proxy connection.
|
|
|
|
std::string domain_addr;
|
|
|
|
uint16_t domain_port;
|
2008-02-07 11:18:34 -05:00
|
|
|
};
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2012-12-01 14:22:22 -05:00
|
|
|
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() ;
|
|
|
|
}
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
/* Mandatory */
|
2014-03-17 16:56:06 -04:00
|
|
|
std::vector<RsPgpId> pgp_ids ;
|
2012-12-01 14:22:22 -05:00
|
|
|
std::vector<ServicePermissionFlags> service_flags ;
|
|
|
|
};
|
2014-04-01 04:00:20 -04:00
|
|
|
|
|
|
|
|
2010-09-22 18:37:57 -04:00
|
|
|
class RsPeerGroupItem : public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsPeerGroupItem();
|
|
|
|
virtual ~RsPeerGroupItem();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-04-01 04:00:20 -04:00
|
|
|
RsTlvPgpIdSet pgpList;
|
2010-09-22 18:37:57 -04:00
|
|
|
};
|
|
|
|
|
2010-07-04 06:17:37 -04:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
class RsPeerStunItem: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsPeerStunItem()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_PEER_CONFIG,
|
|
|
|
RS_PKT_SUBTYPE_PEER_STUN)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsPeerStunItem();
|
|
|
|
virtual void clear();
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
RsTlvPeerIdSet stunList; /* Mandatory */
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class RsPeerConfigSerialiser: public RsSerialType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsPeerConfigSerialiser()
|
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_PEER_CONFIG)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
virtual ~RsPeerConfigSerialiser();
|
|
|
|
|
|
|
|
virtual uint32_t size(RsItem *);
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
private:
|
|
|
|
|
2010-07-04 06:17:37 -04:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
virtual uint32_t sizeNet(RsPeerNetItem *);
|
|
|
|
virtual bool serialiseNet (RsPeerNetItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsPeerNetItem *deserialiseNet(void *data, uint32_t *size);
|
|
|
|
|
|
|
|
virtual uint32_t sizeStun(RsPeerStunItem *);
|
|
|
|
virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size);
|
|
|
|
|
2010-09-22 18:37:57 -04:00
|
|
|
virtual uint32_t sizeGroup(RsPeerGroupItem *);
|
|
|
|
virtual bool serialiseGroup (RsPeerGroupItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsPeerGroupItem * deserialiseGroup(void *data, uint32_t *size);
|
|
|
|
|
2012-12-01 14:22:22 -05:00
|
|
|
virtual uint32_t sizePermissions(RsPeerServicePermissionItem *);
|
|
|
|
virtual bool serialisePermissions (RsPeerServicePermissionItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsPeerServicePermissionItem * deserialisePermissions(void *data, uint32_t *size);
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-11-15 23:45:00 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsCacheConfig: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsCacheConfig()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE_CONFIG,
|
|
|
|
RS_PKT_SUBTYPE_DEFAULT)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
|
|
|
virtual ~RsCacheConfig();
|
|
|
|
virtual void clear();
|
2007-12-11 19:54:42 -05:00
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId pid; /* Mandatory */
|
2008-02-09 07:47:45 -05:00
|
|
|
uint16_t cachetypeid; /* Mandatory */
|
|
|
|
uint16_t cachesubid; /* Mandatory */
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
std::string path; /* Mandatory */
|
|
|
|
std::string name; /* Mandatory */
|
2014-03-17 16:56:06 -04:00
|
|
|
RsFileHash hash; /* Mandatory */
|
2008-02-09 07:47:45 -05:00
|
|
|
uint64_t size; /* Mandatory */
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
class RsFileTransfer: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
2009-12-10 17:55:27 -05:00
|
|
|
RsFileTransfer() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_TRANSFER)
|
|
|
|
{
|
2012-05-07 10:54:46 -04:00
|
|
|
state = 0;
|
|
|
|
in = 0;
|
|
|
|
transferred = 0;
|
|
|
|
crate = 0;
|
|
|
|
trate = 0;
|
|
|
|
lrate = 0;
|
|
|
|
ltransfer = 0;
|
|
|
|
flags = 0;
|
|
|
|
chunk_strategy = 0;
|
2009-12-10 17:55:27 -05:00
|
|
|
}
|
|
|
|
virtual ~RsFileTransfer();
|
|
|
|
virtual void clear();
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
RsTlvFileItem file;
|
|
|
|
RsTlvPeerIdSet allPeerIds;
|
|
|
|
|
2014-04-01 04:00:20 -04:00
|
|
|
RsPeerId cPeerId;
|
2009-12-10 17:55:27 -05:00
|
|
|
|
|
|
|
uint16_t state;
|
|
|
|
uint16_t in;
|
|
|
|
|
|
|
|
uint64_t transferred;
|
|
|
|
uint32_t crate;
|
|
|
|
uint32_t trate;
|
|
|
|
|
|
|
|
uint32_t lrate;
|
|
|
|
uint32_t ltransfer;
|
|
|
|
|
|
|
|
// chunk information
|
2010-01-22 18:23:37 -05:00
|
|
|
uint32_t flags ;
|
2009-12-10 17:55:27 -05:00
|
|
|
uint32_t chunk_strategy ; // strategy flags for chunks
|
2010-01-11 11:00:42 -05:00
|
|
|
CompressedChunkMap compressed_chunk_map ; // chunk availability (bitwise)
|
2007-12-11 19:54:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-11-15 15:00:29 -05:00
|
|
|
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
|
|
|
|
|
|
|
|
/* Used by ft / extralist / configdirs / anyone who wants a basic file */
|
|
|
|
class RsFileConfigItem: public RsItem
|
2007-12-11 19:54:42 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-11-15 15:00:29 -05:00
|
|
|
RsFileConfigItem()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_FILE_CONFIG,
|
|
|
|
RS_PKT_SUBTYPE_FILE_ITEM)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsFileConfigItem();
|
|
|
|
virtual void clear();
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
RsTlvFileItem file;
|
|
|
|
uint32_t flags;
|
2012-11-03 11:25:25 -04:00
|
|
|
std::list<std::string> parent_groups ;
|
2008-11-15 15:00:29 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsFileConfigSerialiser: public RsSerialType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileConfigSerialiser()
|
2007-12-11 19:54:42 -05:00
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_FILE_CONFIG)
|
|
|
|
{ return; }
|
2008-11-15 15:00:29 -05:00
|
|
|
virtual ~RsFileConfigSerialiser() { return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
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 uint32_t sizeTransfer(RsFileTransfer *);
|
|
|
|
virtual bool serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *size);
|
|
|
|
virtual RsFileTransfer * deserialiseTransfer(void *data, uint32_t *size);
|
|
|
|
|
2008-11-15 15:00:29 -05:00
|
|
|
virtual uint32_t sizeFileItem(RsFileConfigItem *);
|
|
|
|
virtual bool serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsFileConfigItem * deserialiseFileItem(void *data, uint32_t *size);
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-01-25 02:52:46 -05:00
|
|
|
/* 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)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsConfigKeyValueSet();
|
|
|
|
virtual void clear();
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
RsTlvKeyValueSet tlvkvs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RsGeneralConfigSerialiser: public RsSerialType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsGeneralConfigSerialiser()
|
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_GENERAL_CONFIG)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
virtual ~RsGeneralConfigSerialiser();
|
|
|
|
|
|
|
|
virtual uint32_t size(RsItem *);
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t sizeKeyValueSet(RsConfigKeyValueSet *item);
|
|
|
|
bool serialiseKeyValueSet(RsConfigKeyValueSet *item, void *data, uint32_t *pktsize);
|
|
|
|
RsConfigKeyValueSet *deserialiseKeyValueSet(void *data, uint32_t *pktsize);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-11-15 23:45:00 -05:00
|
|
|
#endif /* RS_CONFIG_ITEMS_SERIALISER_H */
|