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>
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
|
|
|
#include "serialiser/rstlvtypes.h"
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 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 */
|
|
|
|
std::string pid; /* Mandatory */
|
|
|
|
uint32_t netMode; /* Mandatory */
|
|
|
|
uint32_t visState; /* Mandatory */
|
|
|
|
uint32_t lastContact; /* Mandatory */
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
struct sockaddr_in localaddr; /* Mandatory */
|
|
|
|
struct sockaddr_in remoteaddr; /* Mandatory */
|
|
|
|
};
|
2007-11-15 23:45:00 -05: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:
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
//RsTlvPeerId peerid; /* Mandatory */
|
2007-11-15 23:45:00 -05:00
|
|
|
uint32_t cacheid; /* Mandatory */
|
|
|
|
|
|
|
|
std::string path; /* Mandatory */
|
|
|
|
std::string name; /* Mandatory */
|
|
|
|
std::string hash; /* 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);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
#define FT_STATE_FAILED 0
|
|
|
|
#define FT_STATE_OKAY 1
|
|
|
|
#define FT_STATE_WAITING 2
|
|
|
|
#define FT_STATE_DOWNLOADING 3
|
|
|
|
#define FT_STATE_COMPLETE 4
|
|
|
|
|
|
|
|
class RsFileTransfer: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileTransfer()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_FILE_CONFIG,
|
|
|
|
RS_PKT_SUBTYPE_DEFAULT)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsFileTransfer();
|
|
|
|
virtual void clear();
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
|
|
|
|
RsTlvFileItem file;
|
|
|
|
RsTlvPeerIdSet allPeerIds;
|
|
|
|
|
|
|
|
std::string cPeerId;
|
|
|
|
|
|
|
|
uint16_t state;
|
|
|
|
uint16_t in;
|
|
|
|
|
|
|
|
uint64_t transferred;
|
|
|
|
uint32_t crate;
|
|
|
|
uint32_t trate;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t lrate;
|
|
|
|
uint32_t ltransfer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsFileTransferSerialiser: public RsSerialType
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileTransferSerialiser()
|
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG,
|
|
|
|
RS_PKT_TYPE_FILE_CONFIG)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsFileTransferSerialiser() { return; }
|
|
|
|
|
|
|
|
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-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 */
|