From 121133488c7893601255bf9507a0953e0c5639a7 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 16 Apr 2017 19:59:22 +0200 Subject: [PATCH] fixed bug in serialization for turtle --- libretroshare/src/chat/rschatitems.cc | 2 +- libretroshare/src/chat/rschatitems.h | 2 +- libretroshare/src/ft/ftserver.cc | 2 +- libretroshare/src/ft/ftserver.h | 3 ++- libretroshare/src/ft/ftturtlefiletransferitem.cc | 1 - libretroshare/src/serialiser/rsbanlistitems.cc | 2 +- libretroshare/src/serialiser/rsbanlistitems.h | 2 +- libretroshare/src/serialiser/rsbwctrlitems.cc | 2 +- libretroshare/src/serialiser/rsbwctrlitems.h | 2 +- libretroshare/src/serialiser/rsfiletransferitems.cc | 2 +- libretroshare/src/serialiser/rsfiletransferitems.h | 2 +- libretroshare/src/serialization/rsserializer.h | 2 +- libretroshare/src/turtle/rsturtleitem.cc | 4 ++-- libretroshare/src/turtle/rsturtleitem.h | 7 ++++--- libretroshare/src/turtle/turtleclientservice.h | 2 +- 15 files changed, 19 insertions(+), 18 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 88e7abe8a..23f4aab25 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -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 ; diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 7ec79ea44..7771a375f 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -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 ; }; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index b9c0c46c0..5b04f2828 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -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 ; diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index cda01eed6..23606b28e 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -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&) ; diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.cc b/libretroshare/src/ft/ftturtlefiletransferitem.cc index e8f1bc886..722991aef 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -606,7 +606,6 @@ void RsTurtleFileDataItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_offset,"chunk_offset") ; - RsTypeSerializer::serial_process(j,ctx,chunk_size,"chunk_size") ; RsTypeSerializer::TlvMemBlock_proxy prox(chunk_data,chunk_size) ; diff --git a/libretroshare/src/serialiser/rsbanlistitems.cc b/libretroshare/src/serialiser/rsbanlistitems.cc index a110ec00f..c28399e34 100644 --- a/libretroshare/src/serialiser/rsbanlistitems.cc +++ b/libretroshare/src/serialiser/rsbanlistitems.cc @@ -53,7 +53,7 @@ void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext RsTypeSerializer::serial_process (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 ; diff --git a/libretroshare/src/serialiser/rsbanlistitems.h b/libretroshare/src/serialiser/rsbanlistitems.h index cd5cb8cec..57263a356 100644 --- a/libretroshare/src/serialiser/rsbanlistitems.h +++ b/libretroshare/src/serialiser/rsbanlistitems.h @@ -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 ; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rsbwctrlitems.cc b/libretroshare/src/serialiser/rsbwctrlitems.cc index bd1f0341e..092b1d643 100644 --- a/libretroshare/src/serialiser/rsbwctrlitems.cc +++ b/libretroshare/src/serialiser/rsbwctrlitems.cc @@ -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 ; diff --git a/libretroshare/src/serialiser/rsbwctrlitems.h b/libretroshare/src/serialiser/rsbwctrlitems.h index 8b5cc8299..07907c709 100644 --- a/libretroshare/src/serialiser/rsbwctrlitems.h +++ b/libretroshare/src/serialiser/rsbwctrlitems.h @@ -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; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rsfiletransferitems.cc b/libretroshare/src/serialiser/rsfiletransferitems.cc index 0be0412b7..3eb7c1147 100644 --- a/libretroshare/src/serialiser/rsfiletransferitems.cc +++ b/libretroshare/src/serialiser/rsfiletransferitems.cc @@ -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 ; diff --git a/libretroshare/src/serialiser/rsfiletransferitems.h b/libretroshare/src/serialiser/rsfiletransferitems.h index 50b3c2a26..ae1835126 100644 --- a/libretroshare/src/serialiser/rsfiletransferitems.h +++ b/libretroshare/src/serialiser/rsfiletransferitems.h @@ -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 ; }; diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 9c6259cf9..d8ff50b14 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -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 ; } diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index 577d152a8..e5d064ef2 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -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 ; diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 22477668a..95594761b 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -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 diff --git a/libretroshare/src/turtle/turtleclientservice.h b/libretroshare/src/turtle/turtleclientservice.h index 6fa4dd629..7fa4d8b18 100644 --- a/libretroshare/src/turtle/turtleclientservice.h +++ b/libretroshare/src/turtle/turtleclientservice.h @@ -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 //