fixed bug in serialization for turtle

This commit is contained in:
csoler 2017-04-16 19:59:22 +02:00
parent 636450f14d
commit 121133488c
15 changed files with 19 additions and 18 deletions

View File

@ -37,7 +37,7 @@
static const uint32_t RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE = 0x0001;
RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id)
RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
{
if(service_id != RS_SERVICE_TYPE_CHAT)
return NULL ;

View File

@ -332,6 +332,6 @@ class RsChatSerialiser: public RsSerializer
public:
RsChatSerialiser() :RsSerializer(RS_SERVICE_TYPE_CHAT) {}
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) ;
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ;
};

View File

@ -459,7 +459,7 @@ bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, Fi
return false;
}
RsItem *ftServer::create_item(uint16_t service,uint8_t item_type)
RsItem *ftServer::create_item(uint16_t service,uint8_t item_type) const
{
#ifdef SERVER_DEBUG
FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ;

View File

@ -97,7 +97,8 @@ public:
//
virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
virtual RsItem *create_item(uint16_t service,uint8_t item_type) ;
virtual RsItem *create_item(uint16_t service,uint8_t item_type) const ;
virtual RsSerializer *serializer() { return this ; }
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;

View File

@ -606,7 +606,6 @@ void RsTurtleFileDataItem::serial_process(SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_size,"chunk_size") ;
RsTypeSerializer::TlvMemBlock_proxy prox(chunk_data,chunk_size) ;

View File

@ -53,7 +53,7 @@ void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext
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)
RsItem *RsBanListSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
{
if(service_id != RS_SERVICE_TYPE_BANLIST)
return NULL ;

View File

@ -77,7 +77,7 @@ class RsBanListSerialiser: public RsSerializer
public:
RsBanListSerialiser() :RsSerializer(RS_SERVICE_TYPE_BANLIST) {}
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) ;
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ;
};
/**************************************************************************/

View File

@ -34,7 +34,7 @@
/*************************************************************************/
RsItem *RsBwCtrlSerialiser::create_item(uint16_t service, uint8_t item_sub_id)
RsItem *RsBwCtrlSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
{
if(service != RS_SERVICE_TYPE_BWCTRL)
return NULL ;

View File

@ -63,7 +63,7 @@ public:
RsBwCtrlSerialiser() :RsSerializer(RS_SERVICE_TYPE_BWCTRL) {}
virtual ~RsBwCtrlSerialiser() {}
RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */);
RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
};
/**************************************************************************/

View File

@ -137,7 +137,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const Compres
// Serializer //
//===================================================================================================//
RsItem *RsFileTransferSerialiser::create_item(uint16_t service_type,uint8_t item_type)
RsItem *RsFileTransferSerialiser::create_item(uint16_t service_type,uint8_t item_type) const
{
if(service_type != RS_SERVICE_TYPE_FILE_TRANSFER)
return NULL ;

View File

@ -183,7 +183,7 @@ class RsFileTransferSerialiser: public RsSerializer
virtual ~RsFileTransferSerialiser() {}
RsItem *create_item(uint16_t service_type,uint8_t item_type) ;
RsItem *create_item(uint16_t service_type,uint8_t item_type) const ;
};

View File

@ -17,7 +17,7 @@ class RsSerializer: public RsSerialType
/*! create_item
* should be overloaded to create the correct type of item depending on the data
*/
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */)
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const
{
return NULL ;
}

View File

@ -109,7 +109,7 @@ uint32_t RsTurtleGenericDataItem::serial_size() const
//
// ---------------------------------- Serialization ----------------------------------//
//
RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype)
RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
{
if (RS_SERVICE_TYPE_TURTLE != service)
{
@ -136,7 +136,7 @@ RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype)
RsItem *item = NULL ;
for(uint32_t i=0;i<_client_services.size();++i)
if((item = _client_services[i]->create_item(service,item_subtype)) != NULL)
if((_client_services[i]->serializer() != NULL) && (item = _client_services[i]->serializer()->create_item(service,item_subtype)) != NULL)
return item ;
std::cerr << "Unknown packet type in RsTurtle (not even handled by client services)!" << std::endl ;

View File

@ -23,11 +23,12 @@ const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ;
const uint8_t RS_TURTLE_SUBTYPE_GENERIC_DATA = 0x0a ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP = 0x10 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST = 0x11 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ;
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ;
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC = 0x14 ;
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST = 0x15 ;
// const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ; // unused
// const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ;
/***********************************************************************************/
/* Basic Turtle Item Class */
/***********************************************************************************/
@ -209,7 +210,7 @@ class RsTurtleSerialiser: public RsSerializer
public:
RsTurtleSerialiser() : RsSerializer(RS_SERVICE_TYPE_TURTLE) {}
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype);
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const;
// This is used by the turtle router to add services to its serialiser.
// Client services are only used for deserialising, since the serialisation is

View File

@ -76,7 +76,7 @@ class RsTurtleClientService
// services might only use the generic item already provided by the turtle
// router: RsTurtleGenericDataItem
virtual RsTurtleGenericTunnelItem *create_item(uint16_t service,uint8_t item_type) const { return NULL ; }
virtual RsSerializer *serializer() { return NULL ; }
// These methods are called by the turtle router to add/remove virtual peers when tunnels are created/deleted
//