2007-11-15 23:45:00 -05:00
|
|
|
#ifndef RS_BASE_ITEMS_H
|
|
|
|
#define RS_BASE_ITEMS_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/serialiser: rsbaseitems.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>
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rstypes.h"
|
2007-11-15 23:45:00 -05:00
|
|
|
#include "serialiser/rsserial.h"
|
|
|
|
#include "serialiser/rstlvtypes.h"
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
const uint8_t RS_PKT_TYPE_FILE = 0x01;
|
|
|
|
const uint8_t RS_PKT_TYPE_CACHE = 0x02;
|
|
|
|
|
2010-07-25 15:04:31 -04:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_REQUEST = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_DATA = 0x02;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_TRANSFER = 0x03;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_CHUNK_MAP_REQUEST = 0x04;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_CHUNK_MAP = 0x05;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST = 0x06;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_CRC32_MAP = 0x07;
|
2012-03-15 15:55:43 -04:00
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_CHUNK_CRC_REQUEST = 0x08;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_FI_CHUNK_CRC = 0x09;
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_CACHE_ITEM = 0x01;
|
|
|
|
const uint8_t RS_PKT_SUBTYPE_CACHE_REQUEST = 0x02;
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
/**************************************************************************/
|
2007-12-11 19:54:42 -05:00
|
|
|
|
|
|
|
class RsFileRequest: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsFileRequest()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_FILE,
|
|
|
|
RS_PKT_SUBTYPE_FI_REQUEST)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_FILE_REQUEST) ;
|
|
|
|
}
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsFileRequest();
|
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
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
uint64_t fileoffset; /* start of data requested */
|
|
|
|
uint32_t chunksize; /* size of data requested */
|
2007-11-15 23:45:00 -05:00
|
|
|
RsTlvFileItem file; /* file information */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsFileData: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileData()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_FILE,
|
|
|
|
RS_PKT_SUBTYPE_FI_DATA)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_FILE_DATA) ;
|
|
|
|
}
|
2007-11-15 23:45:00 -05:00
|
|
|
virtual ~RsFileData();
|
|
|
|
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
|
|
|
RsTlvFileData fd;
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
2010-07-25 15:04:31 -04:00
|
|
|
class RsFileChunkMapRequest: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileChunkMapRequest()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CHUNK_MAP_REQUEST)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP_REQUEST) ;
|
|
|
|
}
|
2010-07-25 15:04:31 -04:00
|
|
|
virtual ~RsFileChunkMapRequest() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
|
|
|
bool is_client ; // is the request for a client, or a server ?
|
|
|
|
std::string hash ; // hash of the file for which we request the chunk map
|
|
|
|
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
class RsFileChunkMap: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileChunkMap()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CHUNK_MAP)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP) ;
|
|
|
|
}
|
2010-07-25 15:04:31 -04:00
|
|
|
virtual ~RsFileChunkMap() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
|
|
|
bool is_client ; // is the request for a client, or a server ?
|
|
|
|
std::string hash ; // hash of the file for which we request the chunk map
|
|
|
|
CompressedChunkMap compressed_map ; // Chunk map of the file.
|
|
|
|
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
};
|
2010-07-29 17:07:07 -04:00
|
|
|
|
|
|
|
class RsFileCRC32MapRequest: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileCRC32MapRequest()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CRC32_MAP_REQUEST)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC_REQUEST) ;
|
|
|
|
}
|
2010-07-29 17:07:07 -04:00
|
|
|
virtual ~RsFileCRC32MapRequest() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
|
|
|
std::string hash ; // hash of the file for which we request the chunk map
|
|
|
|
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
};
|
|
|
|
|
2012-03-15 15:55:43 -04:00
|
|
|
class RsFileSingleChunkCrcRequest: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileSingleChunkCrcRequest()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CHUNK_CRC_REQUEST)
|
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC_REQUEST) ;
|
|
|
|
}
|
|
|
|
virtual ~RsFileSingleChunkCrcRequest() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
|
|
|
std::string hash ; // hash of the file for which we request the crc
|
|
|
|
uint32_t chunk_number ; // chunk number
|
|
|
|
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-29 17:07:07 -04:00
|
|
|
class RsFileCRC32Map: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileCRC32Map()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CRC32_MAP)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_FILE_CRC) ;
|
|
|
|
}
|
2010-07-29 17:07:07 -04:00
|
|
|
virtual ~RsFileCRC32Map() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
|
|
|
std::string hash ; // hash of the file for which we request the chunk map
|
|
|
|
CRC32Map crc_map ; // CRC32 map of the file.
|
|
|
|
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
};
|
2012-03-15 15:55:43 -04:00
|
|
|
|
|
|
|
class RsFileSingleChunkCrc: public RsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsFileSingleChunkCrc()
|
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE, RS_PKT_TYPE_FILE, RS_PKT_SUBTYPE_FI_CHUNK_CRC)
|
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC) ;
|
|
|
|
}
|
|
|
|
virtual ~RsFileSingleChunkCrc() {}
|
|
|
|
virtual void clear() {}
|
|
|
|
|
|
|
|
std::string hash ; // hash of the file for which we request the chunk map
|
|
|
|
uint32_t chunk_number ;
|
|
|
|
Sha1CheckSum check_sum ; // CRC32 map of the file.
|
|
|
|
|
|
|
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|
|
|
};
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsFileItemSerialiser: public RsSerialType
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2010-07-25 15:04:31 -04:00
|
|
|
RsFileItemSerialiser()
|
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
|
|
|
RS_PKT_TYPE_FILE)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2010-07-25 15:04:31 -04:00
|
|
|
virtual ~RsFileItemSerialiser() { return; }
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2010-07-25 15:04:31 -04:00
|
|
|
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
|
|
|
|
2010-07-25 15:04:31 -04:00
|
|
|
private:
|
2007-12-11 19:54:42 -05:00
|
|
|
|
2010-07-25 15:04:31 -04:00
|
|
|
/* sub types */
|
|
|
|
virtual uint32_t sizeReq(RsFileRequest *);
|
|
|
|
virtual uint32_t sizeData(RsFileData *);
|
|
|
|
virtual uint32_t sizeChunkMapReq(RsFileChunkMapRequest *);
|
|
|
|
virtual uint32_t sizeChunkMap(RsFileChunkMap *);
|
2012-03-15 15:55:43 -04:00
|
|
|
virtual uint32_t sizeChunkCrcReq(RsFileSingleChunkCrcRequest *);
|
|
|
|
virtual uint32_t sizeChunkCrc(RsFileSingleChunkCrc *);
|
2010-07-29 17:07:07 -04:00
|
|
|
virtual uint32_t sizeCRC32MapReq(RsFileCRC32MapRequest *);
|
|
|
|
virtual uint32_t sizeCRC32Map(RsFileCRC32Map *);
|
2010-07-25 15:04:31 -04:00
|
|
|
|
|
|
|
virtual bool serialiseReq (RsFileRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual bool serialiseData (RsFileData *item, void *data, uint32_t *size);
|
|
|
|
virtual bool serialiseChunkMapReq(RsFileChunkMapRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual bool serialiseChunkMap(RsFileChunkMap *item, void *data, uint32_t *size);
|
2010-07-29 17:07:07 -04:00
|
|
|
virtual bool serialiseCRC32MapReq(RsFileCRC32MapRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual bool serialiseCRC32Map(RsFileCRC32Map *item, void *data, uint32_t *size);
|
2012-03-15 15:55:43 -04:00
|
|
|
virtual bool serialiseChunkCrcReq(RsFileSingleChunkCrcRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual bool serialiseChunkCrc(RsFileSingleChunkCrc *item, void *data, uint32_t *size);
|
2010-07-25 15:04:31 -04:00
|
|
|
|
|
|
|
virtual RsFileRequest *deserialiseReq(void *data, uint32_t *size);
|
2010-07-29 17:07:07 -04:00
|
|
|
virtual RsFileData *deserialiseData(void *data, uint32_t *size);
|
2010-07-25 15:04:31 -04:00
|
|
|
virtual RsFileChunkMapRequest *deserialiseChunkMapReq(void *data, uint32_t *size);
|
|
|
|
virtual RsFileChunkMap *deserialiseChunkMap(void *data, uint32_t *size);
|
2010-07-29 17:07:07 -04:00
|
|
|
virtual RsFileCRC32MapRequest *deserialiseCRC32MapReq(void *data, uint32_t *size);
|
|
|
|
virtual RsFileCRC32Map *deserialiseCRC32Map(void *data, uint32_t *size);
|
2012-03-15 15:55:43 -04:00
|
|
|
virtual RsFileSingleChunkCrcRequest *deserialiseChunkCrcReq(void *data, uint32_t *size);
|
|
|
|
virtual RsFileSingleChunkCrc *deserialiseChunkCrc(void *data, uint32_t *size);
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
class RsCacheRequest: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsCacheRequest()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE,
|
|
|
|
RS_PKT_SUBTYPE_CACHE_REQUEST)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_CACHE_REQUEST);
|
|
|
|
}
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsCacheRequest();
|
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
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
uint16_t cacheType;
|
|
|
|
uint16_t cacheSubId;
|
|
|
|
RsTlvFileItem file; /* file information */
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
class RsCacheItem: public RsItem
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsCacheItem()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE,
|
|
|
|
RS_PKT_SUBTYPE_CACHE_ITEM)
|
2011-09-04 16:01:30 -04:00
|
|
|
{
|
|
|
|
setPriorityLevel(QOS_PRIORITY_RS_CACHE_ITEM);
|
|
|
|
}
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsCacheItem();
|
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
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
uint16_t cacheType;
|
|
|
|
uint16_t cacheSubId;
|
|
|
|
RsTlvFileItem file; /* file information */
|
2007-11-15 23:45:00 -05:00
|
|
|
};
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsCacheItemSerialiser: public RsSerialType
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsCacheItemSerialiser()
|
2007-11-15 23:45:00 -05:00
|
|
|
:RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_BASE,
|
2007-12-11 19:54:42 -05:00
|
|
|
RS_PKT_TYPE_CACHE)
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual ~RsCacheItemSerialiser() { return; }
|
2007-11-15 23:45:00 -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);
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
private:
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/* sub types */
|
|
|
|
virtual uint32_t sizeReq(RsCacheRequest *);
|
|
|
|
virtual bool serialiseReq (RsCacheRequest *item, void *data, uint32_t *size);
|
|
|
|
virtual RsCacheRequest * deserialiseReq(void *data, uint32_t *size);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
virtual uint32_t sizeItem(RsCacheItem *);
|
|
|
|
virtual bool serialiseItem (RsCacheItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsCacheItem * deserialiseItem(void *data, uint32_t *size);
|
2007-11-15 23:45:00 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-12-11 19:54:42 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
class RsServiceSerialiser: public RsSerialType
|
2007-11-15 23:45:00 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-12-11 19:54:42 -05:00
|
|
|
RsServiceSerialiser()
|
|
|
|
:RsSerialType(RS_PKT_VERSION_SERVICE, 0, 0)
|
|
|
|
{ return; }
|
|
|
|
virtual ~RsServiceSerialiser()
|
2007-11-15 23:45:00 -05:00
|
|
|
{ return; }
|
|
|
|
|
|
|
|
virtual uint32_t size(RsItem *);
|
|
|
|
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
|
|
|
virtual RsItem * deserialise(void *data, uint32_t *size);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|