moved converted serialisation files into new directory rsitems/, leaving serialiser/ for the serialisation classes

This commit is contained in:
csoler 2017-04-18 21:11:37 +02:00
parent f8fc8b40e4
commit e2d9152b22
52 changed files with 58 additions and 598 deletions

View file

@ -0,0 +1,121 @@
/*
* libretroshare/src/serialiser: itempriorities.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2011-2011 by Cyril Soler
*
* 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 "csoler@users.sourceforge.net"
*
*/
#pragma once
#include <stdint.h>
// This file centralises QoS priorities for all transfer RsItems.
//
const uint8_t QOS_PRIORITY_UNKNOWN = 0 ;
const uint8_t QOS_PRIORITY_DEFAULT = 3 ;
const uint8_t QOS_PRIORITY_TOP = 9 ;
// Turtle traffic
//
const uint8_t QOS_PRIORITY_RS_TURTLE_OPEN_TUNNEL = 6 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_TUNNEL_OK = 6 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST = 6 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_CRC_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_CHUNK_CRC_REQUEST= 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_DATA = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_CRC = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_CHUNK_CRC = 5 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FILE_MAP = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_GENERIC_ITEM = 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_FORWARD_FILE_DATA= 3 ;
const uint8_t QOS_PRIORITY_RS_TURTLE_GENERIC_DATA = 5 ;
// File transfer
//
const uint8_t QOS_PRIORITY_RS_FILE_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_FILE_CRC_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_CHUNK_CRC_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_FILE_MAP_REQUEST = 5 ;
const uint8_t QOS_PRIORITY_RS_CACHE_REQUEST = 4 ;
const uint8_t QOS_PRIORITY_RS_FILE_DATA = 3 ;
const uint8_t QOS_PRIORITY_RS_FILE_CRC = 3 ;
const uint8_t QOS_PRIORITY_RS_CHUNK_CRC = 5 ;
const uint8_t QOS_PRIORITY_RS_FILE_MAP = 3 ;
const uint8_t QOS_PRIORITY_RS_CACHE_ITEM = 3 ;
// Discovery
//
const uint8_t QOS_PRIORITY_RS_DISC_HEART_BEAT = 8 ;
const uint8_t QOS_PRIORITY_RS_DISC_ASK_INFO = 2 ;
const uint8_t QOS_PRIORITY_RS_DISC_REPLY = 1 ;
const uint8_t QOS_PRIORITY_RS_DISC_VERSION = 1 ;
const uint8_t QOS_PRIORITY_RS_DISC_CONTACT = 2 ; // CONTACT and PGPLIST must have
const uint8_t QOS_PRIORITY_RS_DISC_PGP_LIST = 2 ; // same priority.
const uint8_t QOS_PRIORITY_RS_DISC_SERVICES = 2 ;
const uint8_t QOS_PRIORITY_RS_DISC_PGP_CERT = 1 ;
// File database
//
const uint8_t QOS_PRIORITY_RS_FAST_SYNC_REQUEST = 7 ;
const uint8_t QOS_PRIORITY_RS_SLOW_SYNC_REQUEST = 3 ;
// Heartbeat.
//
const uint8_t QOS_PRIORITY_RS_HEARTBEAT_PULSE = 8 ;
// Chat/Msgs
//
const uint8_t QOS_PRIORITY_RS_CHAT_ITEM = 7 ;
const uint8_t QOS_PRIORITY_RS_CHAT_AVATAR_ITEM = 2 ;
const uint8_t QOS_PRIORITY_RS_MSG_ITEM = 2 ; // depreciated.
const uint8_t QOS_PRIORITY_RS_MAIL_ITEM = 2 ; // new mail service
const uint8_t QOS_PRIORITY_RS_STATUS_ITEM = 2 ;
// RTT
//
const uint8_t QOS_PRIORITY_RS_RTT_PING = 9 ;
// BanList
//
const uint8_t QOS_PRIORITY_RS_BANLIST_ITEM = 2 ;
// Bandwidth Control.
//
const uint8_t QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM = 9 ;
// Dsdv Routing
//
const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ;
const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
// GXS
//
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;
// GXS Reputation.
const uint8_t QOS_PRIORITY_RS_GXSREPUTATION_ITEM = 2;
// Service Info / Control.
const uint8_t QOS_PRIORITY_RS_SERVICE_INFO_ITEM = 7;

View file

@ -0,0 +1,71 @@
/*
* libretroshare/src/serialiser: rsbanlist.cc
*
* RetroShare Serialiser.
*
* Copyright 2011 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 "serialiser/rsbaseserial.h"
#include "rsitems/rsbanlistitems.h"
#include "serialization/rstypeserializer.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
/*************************************************************************/
void RsBanListItem::clear()
{
peerList.TlvClear();
}
void RsBanListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ;
}
void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,type,"type") ;
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process<time_t> (j,ctx,update_time,"update_time") ;
RsTypeSerializer::serial_process (j,ctx,banned_peers,"banned_peers") ;
}
RsItem *RsBanListSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
{
if(service_id != RS_SERVICE_TYPE_BANLIST)
return NULL ;
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM: return new RsBanListConfigItem ;
case RS_PKT_SUBTYPE_BANLIST_ITEM: return new RsBanListItem ;
default:
std::cerr << "(EE) unknown item subtype " << (int)item_sub_id << " in RsBanListSerialiser::create_item()" << std::endl;
return NULL ;
}
}

View file

@ -0,0 +1,87 @@
#ifndef RS_BANLIST_ITEMS_H
#define RS_BANLIST_ITEMS_H
/*
* libretroshare/src/serialiser: rsbanlistitems.h
*
* RetroShare Serialiser.
*
* Copyright 2011 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 "rsitems/rsserviceids.h"
#include "serialiser/rstlvbanlist.h"
#include "serialization/rsserializer.h"
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM_deprecated 0x02
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x04
/**************************************************************************/
class RsBanListItem: public RsItem
{
public:
RsBanListItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_BANLIST_ITEM);
return;
}
virtual ~RsBanListItem(){}
virtual void clear();
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
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() { banned_peers.TlvClear() ; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
uint32_t type ;
RsPeerId peerId ;
time_t update_time ;
RsTlvBanList banned_peers;
};
class RsBanListSerialiser: public RsSerializer
{
public:
RsBanListSerialiser() :RsSerializer(RS_SERVICE_TYPE_BANLIST) {}
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ;
};
/**************************************************************************/
#endif /* RS_BANLIST_ITEMS_H */

View file

@ -0,0 +1,199 @@
/*
* libretroshare/src/serialiser: rsbwctrlitems.cc
*
* RetroShare Serialiser.
*
* Copyright 2012 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.1 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/rsbwctrlitems.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
/*************************************************************************/
RsItem *RsBwCtrlSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
{
if(service != RS_SERVICE_TYPE_BWCTRL)
return NULL ;
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM: return new RsBwCtrlAllowedItem();
default:
return NULL;
}
}
void RsBwCtrlAllowedItem::clear()
{
allowedBw = 0;
}
void RsBwCtrlAllowedItem::serial_process(SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ;
}
#ifdef TO_REMOVE
/* serialise the data to the buffer */
bool RsBwCtrlSerialiser::serialiseAllowed(RsBwCtrlAllowedItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeAllowed(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 << "RsBwCtrlSerialiser::serialiseRoute() Header: " << ok << std::endl;
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size Error! " << std::endl;
#endif
}
return ok;
}
RsBwCtrlAllowedItem *RsBwCtrlSerialiser::deserialiseAllowed(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_BWCTRL != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_BWCTRL_ALLOWED_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 */
RsBwCtrlAllowedItem *item = new RsBwCtrlAllowedItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw));
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsBwCtrlSerialiser::size(RsItem *i)
{
RsBwCtrlAllowedItem *dri;
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
{
return sizeAllowed(dri);
}
return 0;
}
bool RsBwCtrlSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
RsBwCtrlAllowedItem *dri;
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
{
return serialiseAllowed(dri, data, pktsize);
}
return false;
}
RsItem *RsBwCtrlSerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM:
return deserialiseAllowed(data, pktsize);
break;
default:
return NULL;
break;
}
}
/*************************************************************************/
#endif

View file

@ -0,0 +1,72 @@
#ifndef RS_BANDWIDTH_CONTROL_ITEMS_H
#define RS_BANDWIDTH_CONTROL_ITEMS_H
/*
* libretroshare/src/serialiser: rsbwctrlitems.h
*
* RetroShare Serialiser.
*
* Copyright 2012 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.1 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 "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialization/rsserializer.h"
#include "serialization/rstypeserializer.h"
#define RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM 0x01
/**************************************************************************/
class RsBwCtrlAllowedItem: public RsItem
{
public:
RsBwCtrlAllowedItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BWCTRL, RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM);
return;
}
virtual ~RsBwCtrlAllowedItem() {}
virtual void clear();
void serial_process(SerializeJob j,SerializeContext& ctx);
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
};
class RsBwCtrlSerialiser: public RsSerializer
{
public:
RsBwCtrlSerialiser() :RsSerializer(RS_SERVICE_TYPE_BWCTRL) {}
virtual ~RsBwCtrlSerialiser() {}
RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
};
/**************************************************************************/
#endif /* RS_BANDWIDTH_CONTROL_ITEMS_H */

View file

@ -0,0 +1,156 @@
/*
* libretroshare/src/serialiser: rsbaseitems.cc
*
* 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 "serialiser/rsbaseserial.h"
#include "serialiser/rstlvbase.h"
#include "rsitems/rsfiletransferitems.h"
#include "serialization/rstypeserializer.h"
/***
* #define RSSERIAL_DEBUG 1
* #define DEBUG_TRANSFERS 1
***/
#ifdef DEBUG_TRANSFERS
#include "util/rsprint.h"
#endif
#include <iostream>
void RsFileTransferDataRequestItem::clear()
{
file.TlvClear();
fileoffset = 0;
chunksize = 0;
}
void RsFileTransferDataItem::clear()
{
fd.TlvClear();
}
void RsFileTransferDataRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t> (j,ctx,fileoffset,"fileoffset") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunksize, "chunksize") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file, "file") ;
}
void RsFileTransferDataItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,fd,"fd") ;
}
void RsFileTransferChunkMapRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<bool> (j,ctx,is_client,"is_client") ;
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
}
void RsFileTransferChunkMapItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<bool> (j,ctx,is_client, "is_client") ;
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ;
}
void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
}
void RsFileTransferSingleChunkCrcItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ;
}
//===================================================================================================//
// CompressedChunkMap //
//===================================================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s)
{
return 4 + 4*s._map.size() ;
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s)
{
bool ok = true ;
ok &= setRawUInt32(data, size, &offset, s._map.size());
for(uint32_t i=0;i<s._map.size() && ok;++i)
ok &= setRawUInt32(data, size, &offset, s._map[i]);
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s)
{
uint32_t S =0;
bool ok = getRawUInt32(data, size, &offset, &S);
if(ok)
{
s._map.resize(S) ;
for(uint32_t i=0;i<S && ok;++i)
ok &= getRawUInt32(data, size, &offset, &(s._map[i]));
}
return ok;
}
template<> void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s)
{
std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl;
}
//===================================================================================================//
// Serializer //
//===================================================================================================//
RsItem *RsFileTransferSerialiser::create_item(uint16_t service_type,uint8_t item_type) const
{
if(service_type != RS_SERVICE_TYPE_FILE_TRANSFER)
return NULL ;
switch(item_type)
{
case RS_PKT_SUBTYPE_FT_DATA_REQUEST : return new RsFileTransferDataRequestItem();
case RS_PKT_SUBTYPE_FT_DATA : return new RsFileTransferDataItem();
case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST : return new RsFileTransferChunkMapRequestItem();
case RS_PKT_SUBTYPE_FT_CHUNK_MAP : return new RsFileTransferChunkMapItem();
case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST : return new RsFileTransferSingleChunkCrcRequestItem();
case RS_PKT_SUBTYPE_FT_CHUNK_CRC : return new RsFileTransferSingleChunkCrcItem() ;
default:
return NULL ;
}
}

View file

@ -0,0 +1,191 @@
#pragma once
/*
* 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>
#include "retroshare/rstypes.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvfileitem.h"
#include "rsitems/rsserviceids.h"
#include "serialization/rsserializer.h"
const uint8_t RS_PKT_SUBTYPE_FT_DATA_REQUEST = 0x01;
const uint8_t RS_PKT_SUBTYPE_FT_DATA = 0x02;
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST = 0x04;
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_MAP = 0x05;
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST = 0x08;
const uint8_t RS_PKT_SUBTYPE_FT_CHUNK_CRC = 0x09;
const uint8_t RS_PKT_SUBTYPE_FT_CACHE_ITEM = 0x0A;
const uint8_t RS_PKT_SUBTYPE_FT_CACHE_REQUEST = 0x0B;
//const uint8_t RS_PKT_SUBTYPE_FT_TRANSFER = 0x03;
//const uint8_t RS_PKT_SUBTYPE_FT_CRC32_MAP_REQUEST = 0x06;
//const uint8_t RS_PKT_SUBTYPE_FT_CRC32_MAP = 0x07;
/**************************************************************************/
class RsFileTransferItem: public RsItem
{
public:
RsFileTransferItem(uint8_t ft_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_FILE_TRANSFER,ft_subtype) {}
virtual ~RsFileTransferItem() {}
virtual void clear() = 0 ;
};
class RsFileTransferDataRequestItem: public RsFileTransferItem
{
public:
RsFileTransferDataRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_DATA_REQUEST)
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_REQUEST) ;
}
virtual ~RsFileTransferDataRequestItem() {}
virtual void clear();
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
// Private data part.
//
uint64_t fileoffset; /* start of data requested */
uint32_t chunksize; /* size of data requested */
RsTlvFileItem file; /* file information */
};
/**************************************************************************/
class RsFileTransferDataItem: public RsFileTransferItem
{
public:
RsFileTransferDataItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_DATA)
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_DATA) ;
}
virtual ~RsFileTransferDataItem() { clear() ; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
virtual void clear();
// Private data part.
//
RsTlvFileData fd;
};
class RsFileTransferChunkMapRequestItem: public RsFileTransferItem
{
public:
RsFileTransferChunkMapRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST)
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP_REQUEST) ;
}
virtual ~RsFileTransferChunkMapRequestItem() {}
virtual void clear() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
// Private data part.
//
bool is_client ; // is the request for a client, or a server ?
RsFileHash hash ; // hash of the file for which we request the chunk map
};
class RsFileTransferChunkMapItem: public RsFileTransferItem
{
public:
RsFileTransferChunkMapItem()
:RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_MAP)
{
setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP) ;
}
virtual ~RsFileTransferChunkMapItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
virtual void clear() {}
// Private data part.
//
bool is_client ; // is the request for a client, or a server ?
RsFileHash hash ; // hash of the file for which we request the chunk map
CompressedChunkMap compressed_map ; // Chunk map of the file.
};
class RsFileTransferSingleChunkCrcRequestItem: public RsFileTransferItem
{
public:
RsFileTransferSingleChunkCrcRequestItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST)
{
setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC_REQUEST) ;
}
virtual ~RsFileTransferSingleChunkCrcRequestItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
virtual void clear() {}
// Private data part.
//
RsFileHash hash ; // hash of the file for which we request the crc
uint32_t chunk_number ; // chunk number
};
class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem
{
public:
RsFileTransferSingleChunkCrcItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CHUNK_CRC)
{
setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC) ;
}
virtual ~RsFileTransferSingleChunkCrcItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
virtual void clear() {}
// Private data part.
//
RsFileHash hash ; // hash of the file for which we request the chunk map
uint32_t chunk_number ;
Sha1CheckSum check_sum ; // CRC32 map of the file.
};
/**************************************************************************/
class RsFileTransferSerialiser: public RsSerializer
{
public:
RsFileTransferSerialiser(): RsSerializer(RS_SERVICE_TYPE_FILE_TRANSFER) {}
virtual ~RsFileTransferSerialiser() {}
RsItem *create_item(uint16_t service_type,uint8_t item_type) const ;
};
/**************************************************************************/

View file

@ -0,0 +1,161 @@
#ifndef RS_SERVICE_IDS_H
#define RS_SERVICE_IDS_H
/*
* libretroshare/src/serialiser: rsserviceids.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 <inttypes.h>
/* Single place for Cache/Service Ids (uint16_t)
* to 64K of them....
*
* Some Services/Caches are only msgs or caches...
* but they need to be combined so that the messages/caches
* can easily be aligned.
*
*/
/* These are Cache Only */
const uint16_t RS_SERVICE_TYPE_FILE_INDEX = 0x0001;
/* These are Services only */
const uint16_t RS_SERVICE_TYPE_DISC = 0x0011;
const uint16_t RS_SERVICE_TYPE_CHAT = 0x0012;
const uint16_t RS_SERVICE_TYPE_MSG = 0x0013;
const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014;
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016;
const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
const uint16_t RS_SERVICE_TYPE_GROUTER = 0x0018;
const uint16_t RS_SERVICE_TYPE_FILE_DATABASE = 0x0019;
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0020;
/* Bandwidth Control */
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0x0021;
// New Mail Service (replace old Msg Service)
const uint16_t RS_SERVICE_TYPE_MAIL = 0x0022;
const uint16_t RS_SERVICE_TYPE_DIRECT_MAIL = 0x0023;
const uint16_t RS_SERVICE_TYPE_DISTANT_MAIL = 0x0024;
const uint16_t RS_SERVICE_TYPE_GWEMAIL_MAIL = 0x0025;
const uint16_t RS_SERVICE_TYPE_SERVICE_CONTROL= 0x0026;
const uint16_t RS_SERVICE_TYPE_DISTANT_CHAT = 0x0027;
const uint16_t RS_SERVICE_TYPE_GXS_TUNNEL = 0x0028;
// Non essential services.
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
const uint16_t RS_SERVICE_TYPE_STATUS = 0x0102;
/* New Cache Services */
/* Rs Network Exchange Service */
const uint16_t RS_SERVICE_TYPE_NXS = 0x0200;
const uint16_t RS_SERVICE_GXS_TYPE_GXSID = 0x0211;
const uint16_t RS_SERVICE_GXS_TYPE_PHOTO = 0x0212;
const uint16_t RS_SERVICE_GXS_TYPE_WIKI = 0x0213;
const uint16_t RS_SERVICE_GXS_TYPE_WIRE = 0x0214;
const uint16_t RS_SERVICE_GXS_TYPE_FORUMS = 0x0215;
const uint16_t RS_SERVICE_GXS_TYPE_POSTED = 0x0216;
const uint16_t RS_SERVICE_GXS_TYPE_CHANNELS = 0x0217;
const uint16_t RS_SERVICE_GXS_TYPE_GXSCIRCLE = 0x0218;
// not gxs, but used with identities.
const uint16_t RS_SERVICE_GXS_TYPE_REPUTATION = 0x0219;
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0x0220;
// Experimental Services.
/* DSDV Testing at the moment - Service Only */
const uint16_t RS_SERVICE_TYPE_DSDV = 0x1010;
/* Latency RTT Measurements */
const uint16_t RS_SERVICE_TYPE_RTT = 0x1011;
/***************** IDS ALLOCATED FOR PLUGINS ******************/
// 2000+
const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_ID = 0x2001;
const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_ID = 0x2002;
const uint16_t RS_SERVICE_TYPE_PLUGIN_FEEDREADER = 0x2003;
// Reserved for packet slicing probes.
const uint16_t RS_SERVICE_TYPE_PACKET_SLICING_PROBE = 0xAABB;
// Nabu's services.
const uint16_t RS_SERVICE_TYPE_PLUGIN_FIDO_GW = 0xF1D0;
const uint16_t RS_SERVICE_TYPE_PLUGIN_ZERORESERVE = 0xBEEF;
/****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/
/*
* If you are planning on making a new service....
* Test it out with an ID in the range from 0xf000 - 0xffff
* And Change the ID everytime you make significant changes to the
* data structures...
*
* eg.
* const uint16_t RS_SERVICE_TYPE_DISTRIB_O1 = 0xf110; // First Revision.
* const uint16_t RS_SERVICE_TYPE_DISTRIB_O2 = 0xf111; // Second Revision.
* const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf112; // Final Revision.
*
* This minimises the chances of your new serialisers messing with
* other existing, older, or proposed services.
*
* ONLY MOVE your Id once the service has been finalised.
*
*/
/*! for Qblog service (Cache Only) */
//const uint16_t RS_SERVICE_TYPE_QBLOG = 0xf010;
/* TEST VOIP - Service only */
// NOT SURE WHATS HAPPENING WITH THIS ONE?
// SHOULD BE DEFINED IN PLUGIN SECTION!
//const uint16_t RS_SERVICE_TYPE_VOIP = 0xf011;
/* Proxy - Service only */
//const uint16_t RS_SERVICE_TYPE_PROXY = 0xf030;
/* Games/External Apps - Service Only */
//const uint16_t RS_SERVICE_TYPE_GAME_LAUNCHER = 0xf200;
//const uint16_t RS_SERVICE_TYPE_PORT = 0xf201;
/* Example Games (NOT USED YET!) */
/* Board Games */
//const uint16_t RS_SERVICE_TYPE_GAME_QTCHESS = 0xf211;
//const uint16_t RS_SERVICE_TYPE_GAME_QGO = 0xf212;
/* Card Games */
//const uint16_t RS_SERVICE_TYPE_GAME_BIGTWO = 0xf213;
//const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf214;
/***************** IDS ALLOCATED FOR PLUGINS ******************/
//const uint16_t RS_SERVICE_TYPE_PLUGIN_ARADO_TEST_ID1 = 0xf401;
//const uint16_t RS_SERVICE_TYPE_PLUGIN_QCHESS_TEST_ID1 = 0xf402;
// test
//const uint16_t RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM = 0xf403;
#endif /* RS_SERVICE_IDS_H */