From 4f24b95b163ddc0c276c5ea308e477affbf2f54b Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Mar 2017 21:28:28 +0100 Subject: [PATCH 001/106] added new serialization code test example --- .../src/serialization/serial_test.cc | 78 +++++ libretroshare/src/serialization/serializer.h | 299 ++++++++++++++++++ 2 files changed, 377 insertions(+) create mode 100644 libretroshare/src/serialization/serial_test.cc create mode 100644 libretroshare/src/serialization/serializer.h diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc new file mode 100644 index 000000000..a0409aaed --- /dev/null +++ b/libretroshare/src/serialization/serial_test.cc @@ -0,0 +1,78 @@ +// COMPILE_LINE: g++ -g serial_test.cc -I.. -o serial_test ../lib/libretroshare.a -lssl -lcrypto -lstdc++ -lpthread +// +// + +#include "serializer.h" +#include "util/rsmemory.h" +#include "util/rsprint.h" +#include "serialiser/rsserial.h" + +static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff; +static const uint8_t RS_ITEM_SUBTYPE_TEST1 = 0x01 ; + +class RsTestItem: public RsSerializable +{ + public: + RsTestItem() : RsSerializable(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) {} + + virtual void serial_process(RsSerializable::SerializeJob j, SerializeContext& ctx) + { + RsTypeSerializer ().serial_process(j,ctx,ts) ; + RsTypeSerializer().serial_process(j,ctx,str) ; + } + + // derived from RsItem + // + virtual void clear() {} + virtual std::ostream& print(std::ostream&,uint16_t indent) {} + + + private: + std::string str ; + uint64_t ts ; +}; + +class RsTestSerializer: public RsSerializer +{ + public: + + virtual RsSerializable *create_item(uint16_t service,uint8_t subtype) + { + switch(subtype) + { + case RS_ITEM_SUBTYPE_TEST1: return new RsTestItem(); + + default: + return NULL ; + } + } +}; + +int main(int argc,char *argv[]) +{ + try + { + RsTestItem t1 ; + + uint32_t size = RsTestSerializer().size_item(&t1); + + std::cerr << "t1.serial_size() = " << size << std::endl; + + RsTemporaryMemory mem1(size); + + RsTestSerializer().serialize_item(&t1,mem1,mem1.size()) ; + + RsSerializable *t2 = RsTestSerializer().deserialize_item(mem1,mem1.size()) ; + + std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; + + return 0; + } + catch(std::exception& e) + { + std::cerr << "Exception caught: " << e.what() << std::endl; + return 1; + } +} + + diff --git a/libretroshare/src/serialization/serializer.h b/libretroshare/src/serialization/serializer.h new file mode 100644 index 000000000..65ce10269 --- /dev/null +++ b/libretroshare/src/serialization/serializer.h @@ -0,0 +1,299 @@ +#pragma once + +#include +#include +#include +#include +#include "arpa/inet.h" +#include "serialiser/rsserial.h" + +class RsItem ; + +class SerializeContext; + +class RsSerializable: public RsItem +{ +public: + typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; + + RsSerializable(uint8_t version,uint16_t service,uint8_t id) + : RsItem(version,service,id) + { + } + + /** + * @brief serialize this object to the given buffer + * @param Job to do: serialise or deserialize. + * @param data Chunk of memory were to dump the serialized data + * @param size Size of memory chunk + * @param offset Readed to determine at witch offset start writing data, + * written to inform caller were written data ends, the updated value + * is usually passed by the caller to serialize of another + * RsSerializable so it can write on the same chunk of memory just + * after where this RsSerializable has been serialized. + * @return true if serialization successed, false otherwise + */ + + virtual void serial_process(SerializeJob j,SerializeContext& ctx) = 0; +}; + +class SerializeContext +{ + public: + + SerializeContext(uint8_t *data,uint32_t size) + : mData(data),mSize(size),mOffset(0),mOk(true) {} + + unsigned char *mData ; + uint32_t mSize ; + uint32_t mOffset ; + bool mOk ; +}; +template T ntoh(T t) +{ + if(sizeof(T) == 4) return ntohl(t) ; + if(sizeof(T) == 2) return ntohs(t) ; + + std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in ntoh<>" << std::endl; + return t; +} +template T hton(T t) +{ + if(sizeof(T) == 4) return htonl(t) ; + if(sizeof(T) == 2) return htons(t) ; + + std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in hton<>" << std::endl; + return t; +} + +template class RsTypeSerializerBase +{ + public: + void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,T& member) + { + switch(j) + { + case RsSerializable::SIZE_ESTIMATE: ctx.mSize += serial_size(member) ; + break ; + + case RsSerializable::DESERIALIZE: deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + break ; + + case RsSerializable::SERIALIZE: serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + break ; + + default: + throw std::runtime_error("Unknown serial job") ; + } + } + + protected: + virtual bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const T& member)const=0; + virtual bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member) const=0; + virtual uint32_t serial_size(const T& /* member */)const=0; +}; + +/// Templates to generate RsSerializer for standard integral types +template class t_SerializerNType : public RsTypeSerializerBase +{ +protected: + bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const N& member)const + { + if (size <= offset || size - offset < SIZE) + return false; + + N tmp = hton(member); + memcpy(data+offset, &tmp, SIZE); + offset += SIZE; + return true; + } + bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, N& member)const + { + if (size <= offset || size - offset < SIZE) + return false; + + N tmp ; + memcpy(&tmp, data+offset, SIZE); + member = ntoh(tmp); + offset += SIZE; + return true; + } + + inline uint32_t serial_size(const N& /* member */)const + { + return SIZE; + } +}; + +template class RsTypeSerializer +{ +// public: +// virtual void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,const T& member)=0; +// +// protected: +// virtual bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const T& member)const=0; +// virtual bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member)=0; +// virtual uint32_t serial_size(const T& /* member */)const=0; +}; + +template<> class RsTypeSerializer : public t_SerializerNType{}; +template<> class RsTypeSerializer : public t_SerializerNType{}; +template<> class RsTypeSerializer : public t_SerializerNType{}; +template<> class RsTypeSerializer : public t_SerializerNType{}; +template<> class RsTypeSerializer : public t_SerializerNType{}; + +/// Serializer for non negative float +template<> class RsTypeSerializer : public RsTypeSerializerBase +{ +protected: + bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const float& f)const + { + uint32_t sz = serial_size(f); + if ( !data || size <= offset || size - offset < sz ) + return false; + + const float tmp = f; + if(tmp < 0.0f) + { + std::cerr << "(EE) Cannot serialise invalid negative float value " + << tmp << " in " << __PRETTY_FUNCTION__ << std::endl; + return false; + } + + /* This serialisation is quite accurate. The max relative error is approx. + * 0.01% and most of the time less than 1e-05% The error is well distributed + * over numbers also. */ + uint32_t n; + if(tmp < 1e-7) n = (~(uint32_t)0); + else n = ((uint32_t)( (1.0f/(1.0f+tmp) * (~(uint32_t)0)))); + n = hton(n); + memcpy(data+offset, &n, sz); + offset += sz; + return true; + } + + bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f)const + { + uint32_t sz = serial_size(f); + if ( !data || size <= offset || + size - offset < sz ) + return false; + + uint32_t n; + memcpy(&n, data+offset, sz); + n = ntoh(n); + f = 1.0f/ ( n/(float)(~(uint32_t)0)) - 1.0f; + return true; + } + inline uint32_t serial_size(const float&)const { return 4; } +}; + +/// Serializer for std::string +template<> class RsTypeSerializer : public RsTypeSerializerBase +{ + protected: + bool serialize(uint8_t data[], uint32_t size, uint32_t &offset,const std::string& s)const + { + if ( !data || size <= offset || size - offset < serial_size(s)) + return false; + + uint32_t charsLen = s.length(); + uint32_t netLen = hton(charsLen); + memcpy(data+offset, &netLen, 4); offset += 4; + memcpy(data+offset, s.c_str(), charsLen); offset += charsLen; + return true; + } + bool deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,std::string& s)const + { + if ( !data || size <= offset || size - offset < 4 ) return false; + uint32_t charsLen; + memcpy(&charsLen, data+offset, 4); offset += 4; + charsLen = ntoh(charsLen); + + if ( size <= offset || size - offset < charsLen ) return false; + s.clear(); + s.insert(0, (char*)data+offset, charsLen); + offset += charsLen; + return true; + } + inline uint32_t serial_size(const std::string& s)const + { + return s.length() + 4; + } +}; + + + +class RsSerializer +{ + public: + /*! create_item + * should be overloaded to create the correct type of item depending on the data + */ + virtual RsSerializable *create_item(uint16_t service, uint8_t item_sub_id) + { + return NULL ; + } + + RsSerializable *deserialize_item(const uint8_t *data,uint32_t size) + { + uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; + + RsSerializable *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; + + if(!item) + { + std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + return NULL ; + } + + SerializeContext ctx(const_cast(data),size); + item->serial_process(RsSerializable::DESERIALIZE, ctx) ; + + if(ctx.mOk) + return item ; + + delete item ; + return NULL ; + } + + bool serialize_item(const RsSerializable *item,uint8_t *const data,uint32_t size) + { + SerializeContext ctx(data,0); + + uint32_t tlvsize = size_item(item) ; + + if(tlvsize > size) + throw std::runtime_error("Cannot serialise: not enough room.") ; + + if(!setRsItemHeader(data, tlvsize, const_cast(item)->PacketId(), tlvsize)) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; + return false ; + } + ctx.mOffset = 8; + ctx.mSize = tlvsize; + + const_cast(item)->serial_process(RsSerializable::SERIALIZE,ctx) ; + + if(ctx.mSize != ctx.mOffset) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; + return false ; + } + return true ; + } + + uint32_t size_item(const RsSerializable *item) + { + SerializeContext ctx(NULL,0); + + ctx.mSize = 8 ; // header size + const_cast(item)->serial_process(RsSerializable::SIZE_ESTIMATE, ctx) ; + + return ctx.mSize ; + } +}; + + + From 369621f4a40c77aae7fb0d1aed2e30ada0b6dad1 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 20 Mar 2017 23:31:04 +0100 Subject: [PATCH 002/106] simplified new serialization prototype --- .../src/serialization/serial_test.cc | 74 ++++++++++- libretroshare/src/serialization/serializer.h | 117 +++++++++++------- 2 files changed, 144 insertions(+), 47 deletions(-) diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index a0409aaed..08c53b6db 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -2,6 +2,8 @@ // // +#include + #include "serializer.h" #include "util/rsmemory.h" #include "util/rsprint.h" @@ -10,18 +12,79 @@ static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff; static const uint8_t RS_ITEM_SUBTYPE_TEST1 = 0x01 ; +// Template serialization of RsTypeSerialiser::serial_process() for unknown/new types +// +// +template<> uint32_t RsTypeSerializer::serial_size(const std::set& s) +{ + return s.size() * 4 + 4 ; +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const std::set& member) +{ + uint32_t tlvsize = serial_size(member) ; + bool ok = true ; + uint32_t offset_save = offset ; + + if(tlvsize + offset >= size) + return false ; + + ok = ok && RsTypeSerializer::serialize(data,size,offset,member.size()) ; + + for(std::set::const_iterator it(member.begin());it!=member.end();++it) + ok = ok && RsTypeSerializer::serialize(data,size,offset,*it) ; + + if(!ok) + { + std::cerr << "(EE) Cannot serialize std::set" << std::endl; + offset = offset_save ; // return the data in the same condition + } + return ok ; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, std::set& member) +{ + bool ok = true ; + uint32_t n = 0 ; + uint32_t offset_save = offset ; + member.clear(); + + ok = ok && RsTypeSerializer::deserialize(data,size,offset,n); + + for(uint32_t i=0;i" << std::endl; + offset = offset_save ; // return the data in the same condition + } + return ok; +} + +// New item class. This class needs to define: +// - a serial_process method that tells which members to serialize +// - overload the clear() and print() methods of RsItem +// class RsTestItem: public RsSerializable { public: RsTestItem() : RsSerializable(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) {} + // Derived from RsSerializable + // virtual void serial_process(RsSerializable::SerializeJob j, SerializeContext& ctx) { - RsTypeSerializer ().serial_process(j,ctx,ts) ; - RsTypeSerializer().serial_process(j,ctx,str) ; + RsTypeSerializer::serial_process(j,ctx,ts ) ; + RsTypeSerializer::serial_process(j,ctx,str) ; + RsTypeSerializer::serial_process(j,ctx,int_set ) ; } - // derived from RsItem + // Derived from RsItem // virtual void clear() {} virtual std::ostream& print(std::ostream&,uint16_t indent) {} @@ -30,8 +93,13 @@ class RsTestItem: public RsSerializable private: std::string str ; uint64_t ts ; + std::set int_set ; }; +// New user-defined serializer class. +// The only required member is the create_item() method, which creates the correct RsSerializable +// that corresponds to a specific (service,subtype) couple. +// class RsTestSerializer: public RsSerializer { public: diff --git a/libretroshare/src/serialization/serializer.h b/libretroshare/src/serialization/serializer.h index 65ce10269..462206c42 100644 --- a/libretroshare/src/serialization/serializer.h +++ b/libretroshare/src/serialization/serializer.h @@ -51,6 +51,7 @@ class SerializeContext }; template T ntoh(T t) { + if(sizeof(T) == 8) return t; if(sizeof(T) == 4) return ntohl(t) ; if(sizeof(T) == 2) return ntohs(t) ; @@ -59,6 +60,7 @@ template T ntoh(T t) } template T hton(T t) { + if(sizeof(T) == 8) return t; if(sizeof(T) == 4) return htonl(t) ; if(sizeof(T) == 2) return htons(t) ; @@ -66,10 +68,11 @@ template T hton(T t) return t; } -template class RsTypeSerializerBase +class RsTypeSerializer { public: - void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,T& member) + template + static void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,T& member) { switch(j) { @@ -88,16 +91,22 @@ template class RsTypeSerializerBase } protected: - virtual bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const T& member)const=0; - virtual bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member) const=0; - virtual uint32_t serial_size(const T& /* member */)const=0; + template + static bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const T& member); + + template + static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); + + template + static uint32_t serial_size(const T& /* member */); }; /// Templates to generate RsSerializer for standard integral types -template class t_SerializerNType : public RsTypeSerializerBase +// +template class t_SerializerNType { -protected: - bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const N& member)const +public: + static bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const N& member) { if (size <= offset || size - offset < SIZE) return false; @@ -107,7 +116,7 @@ protected: offset += SIZE; return true; } - bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, N& member)const + static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, N& member) { if (size <= offset || size - offset < SIZE) return false; @@ -119,34 +128,56 @@ protected: return true; } - inline uint32_t serial_size(const N& /* member */)const + static uint32_t serial_size(const N& /* member */) { return SIZE; } }; -template class RsTypeSerializer -{ -// public: -// virtual void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,const T& member)=0; +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) +{ + return t_SerializerNType::serialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) +{ + return t_SerializerNType::serialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint64_t& member) +{ + return t_SerializerNType::serialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member) +{ + return t_SerializerNType::deserialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) +{ + return t_SerializerNType::deserialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint64_t& member) +{ + return t_SerializerNType::deserialize(data,size,offset,member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& member) +{ + return t_SerializerNType::serial_size(member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint32_t& member) +{ + return t_SerializerNType::serial_size(member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint64_t& member) +{ + return t_SerializerNType::serial_size(member); +} +//// Float // -// protected: -// virtual bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const T& member)const=0; -// virtual bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member)=0; -// virtual uint32_t serial_size(const T& /* member */)const=0; -}; +template<> + uint32_t RsTypeSerializer::serial_size(const float&){ return 4; } -template<> class RsTypeSerializer : public t_SerializerNType{}; -template<> class RsTypeSerializer : public t_SerializerNType{}; -template<> class RsTypeSerializer : public t_SerializerNType{}; -template<> class RsTypeSerializer : public t_SerializerNType{}; -template<> class RsTypeSerializer : public t_SerializerNType{}; -/// Serializer for non negative float -template<> class RsTypeSerializer : public RsTypeSerializerBase -{ -protected: - bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const float& f)const +template<> +bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const float& f) { uint32_t sz = serial_size(f); if ( !data || size <= offset || size - offset < sz ) @@ -172,7 +203,14 @@ protected: return true; } - bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f)const +template<> uint32_t RsTypeSerializer::serial_size(const std::string& s) +{ + return s.length() + 4; +} + + +template<> + bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f) { uint32_t sz = serial_size(f); if ( !data || size <= offset || @@ -185,14 +223,11 @@ protected: f = 1.0f/ ( n/(float)(~(uint32_t)0)) - 1.0f; return true; } - inline uint32_t serial_size(const float&)const { return 4; } -}; + /// Serializer for std::string -template<> class RsTypeSerializer : public RsTypeSerializerBase -{ - protected: - bool serialize(uint8_t data[], uint32_t size, uint32_t &offset,const std::string& s)const + template<> + bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const std::string& s) { if ( !data || size <= offset || size - offset < serial_size(s)) return false; @@ -203,7 +238,8 @@ template<> class RsTypeSerializer : public RsTypeSerializerBase + bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,std::string& s) { if ( !data || size <= offset || size - offset < 4 ) return false; uint32_t charsLen; @@ -216,13 +252,6 @@ template<> class RsTypeSerializer : public RsTypeSerializerBase Date: Sat, 25 Mar 2017 19:01:32 +0100 Subject: [PATCH 003/106] polished serialisation prototype --- .../src/serialization/rsserializable.h | 35 ++ .../src/serialization/rsserializer.h | 97 ++++++ .../src/serialization/rstypeserializer.h | 195 +++++++++++ .../src/serialization/serial_test.cc | 54 ++- libretroshare/src/serialization/serializer.h | 328 ------------------ 5 files changed, 371 insertions(+), 338 deletions(-) create mode 100644 libretroshare/src/serialization/rsserializable.h create mode 100644 libretroshare/src/serialization/rsserializer.h create mode 100644 libretroshare/src/serialization/rstypeserializer.h delete mode 100644 libretroshare/src/serialization/serializer.h diff --git a/libretroshare/src/serialization/rsserializable.h b/libretroshare/src/serialization/rsserializable.h new file mode 100644 index 000000000..3351e0147 --- /dev/null +++ b/libretroshare/src/serialization/rsserializable.h @@ -0,0 +1,35 @@ +#pragma once + +#include "serialiser/rsserial.h" + +class RsItem ; +class SerializeContext; + +#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " + +class RsSerializable: public RsItem +{ +public: + typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; + + RsSerializable(uint8_t version,uint16_t service,uint8_t id) + : RsItem(version,service,id) + { + } + + /** + * @brief serialize this object to the given buffer + * @param Job to do: serialise or deserialize. + * @param data Chunk of memory were to dump the serialized data + * @param size Size of memory chunk + * @param offset Readed to determine at witch offset start writing data, + * written to inform caller were written data ends, the updated value + * is usually passed by the caller to serialize of another + * RsSerializable so it can write on the same chunk of memory just + * after where this RsSerializable has been serialized. + * @return true if serialization successed, false otherwise + */ + + virtual void serial_process(SerializeJob j,SerializeContext& ctx) = 0; +}; + diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h new file mode 100644 index 000000000..706ee3be4 --- /dev/null +++ b/libretroshare/src/serialization/rsserializer.h @@ -0,0 +1,97 @@ +#pragma once + +#include +#include +#include +#include + +#include "rsserializable.h" + +class SerializeContext +{ + public: + + SerializeContext(uint8_t *data,uint32_t size) + : mData(data),mSize(size),mOffset(0),mOk(true) {} + + unsigned char *mData ; + uint32_t mSize ; + uint32_t mOffset ; + bool mOk ; +}; + +class RsSerializer +{ + public: + /*! create_item + * should be overloaded to create the correct type of item depending on the data + */ + virtual RsSerializable *create_item(uint16_t service, uint8_t item_sub_id) + { + return NULL ; + } + + RsSerializable *deserialize_item(const uint8_t *data,uint32_t size) + { + uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; + + RsSerializable *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; + + if(!item) + { + std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + return NULL ; + } + + SerializeContext ctx(const_cast(data),size); + ctx.mOffset = 8 ; + + item->serial_process(RsSerializable::DESERIALIZE, ctx) ; + + if(ctx.mOk) + return item ; + + delete item ; + return NULL ; + } + + bool serialize_item(const RsSerializable *item,uint8_t *const data,uint32_t size) + { + SerializeContext ctx(data,0); + + uint32_t tlvsize = size_item(item) ; + + if(tlvsize > size) + throw std::runtime_error("Cannot serialise: not enough room.") ; + + if(!setRsItemHeader(data, tlvsize, const_cast(item)->PacketId(), tlvsize)) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; + return false ; + } + ctx.mOffset = 8; + ctx.mSize = tlvsize; + + const_cast(item)->serial_process(RsSerializable::SERIALIZE,ctx) ; + + if(ctx.mSize != ctx.mOffset) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; + return false ; + } + return true ; + } + + uint32_t size_item(const RsSerializable *item) + { + SerializeContext ctx(NULL,0); + + ctx.mSize = 8 ; // header size + const_cast(item)->serial_process(RsSerializable::SIZE_ESTIMATE, ctx) ; + + return ctx.mSize ; + } +}; + + + diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h new file mode 100644 index 000000000..a713832b3 --- /dev/null +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -0,0 +1,195 @@ +#include "serialiser/rstlvbase.h" + +template T ntoh(T t) +{ + if(sizeof(T) == 8) return t; + if(sizeof(T) == 4) return ntohl(t) ; + if(sizeof(T) == 2) return ntohs(t) ; + + std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in ntoh<>" << std::endl; + return t; +} +template T hton(T t) +{ + if(sizeof(T) == 8) return t; + if(sizeof(T) == 4) return htonl(t) ; + if(sizeof(T) == 2) return htons(t) ; + + std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in hton<>" << std::endl; + return t; +} + +class RsTypeSerializer +{ + public: + template + static void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,T& member) + { + switch(j) + { + case RsSerializable::SIZE_ESTIMATE: ctx.mSize += serial_size(member) ; + break ; + + case RsSerializable::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + break ; + + case RsSerializable::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + break ; + + default: + ctx.mOk = false ; + throw std::runtime_error("Unknown serial job") ; + } + } + + protected: + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); + template static uint32_t serial_size(const T& /* member */); +}; + +/// Templates to generate RsSerializer for standard integral types +// +template class t_SerializerNType +{ +public: + static bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const N& member) + { + if (size <= offset || size < SIZE + offset) + { + SERIALIZE_ERROR() << ": not enough room. SIZE+offset=" << SIZE+offset << " and size is only " << size << std::endl; + return false; + } + + N tmp = hton(member); + memcpy(data+offset, &tmp, SIZE); + offset += SIZE; + return true; + } + static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, N& member) + { + if (size <= offset || size < offset + SIZE) + { + SERIALIZE_ERROR() << ": not enough room. SIZE+offset=" << SIZE+offset << " and size is only " << size << std::endl; + return false; + } + + N tmp ; + memcpy(&tmp, data+offset, SIZE); + member = ntoh(tmp); + offset += SIZE; + return true; + } + + static uint32_t serial_size(const N& /* member */) + { + return SIZE; + } +}; + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) +{ + return t_SerializerNType::serialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) +{ + return t_SerializerNType::serialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint64_t& member) +{ + return t_SerializerNType::serialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member) +{ + return t_SerializerNType::deserialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) +{ + return t_SerializerNType::deserialize(data,size,offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint64_t& member) +{ + return t_SerializerNType::deserialize(data,size,offset,member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& member) +{ + return t_SerializerNType::serial_size(member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint32_t& member) +{ + return t_SerializerNType::serial_size(member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint64_t& member) +{ + return t_SerializerNType::serial_size(member); +} +//// Float +// +template<> uint32_t RsTypeSerializer::serial_size(const float&){ return 4; } + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t& offset, const float& f) +{ + uint32_t sz = serial_size(f); + + if ( !data || size <= offset || size < sz + offset ) + { + SERIALIZE_ERROR() << ": not enough room. SIZE+offset=" << sz+offset << " and size is only " << size << std::endl; + return false; + } + + const float tmp = f; + if(tmp < 0.0f) + { + SERIALIZE_ERROR() << "Cannot serialise invalid negative float value " << tmp << std::endl; + return false; + } + + /* This serialisation is quite accurate. The max relative error is approx. + * 0.01% and most of the time less than 1e-05% The error is well distributed + * over numbers also. */ + + uint32_t n; + if(tmp < 1e-7) n = (~(uint32_t)0); + else n = ((uint32_t)( (1.0f/(1.0f+tmp) * (~(uint32_t)0)))); + n = hton(n); + memcpy(data+offset, &n, sz); + offset += sz; + return true; +} + + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f) +{ + uint32_t sz = serial_size(f); + + if ( !data || size <= offset || size < offset + sz ) + { + SERIALIZE_ERROR() << "Cannot deserialise float value. Not enough room. size=" << size << ", offset=" << offset << std::endl; + return false; + } + + uint32_t n; + memcpy(&n, data+offset, sz); + n = ntoh(n); + f = 1.0f/ ( n/(float)(~(uint32_t)0)) - 1.0f; + return true; +} + +typedef std::pair TlvString; + +/// Serializer for std::string +template<> uint32_t RsTypeSerializer::serial_size(const TlvString& s) +{ + return GetTlvStringSize(s.first) ; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const TlvString& s) +{ + return SetTlvString(data,size,&offset,s.second,s.first) ; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,TlvString& s) +{ + return GetTlvString((void*)data,size,&offset,s.second,s.first) ; +} + diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index 08c53b6db..9b5745b4b 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -4,16 +4,18 @@ #include -#include "serializer.h" #include "util/rsmemory.h" #include "util/rsprint.h" #include "serialiser/rsserial.h" +#include "serializer.h" +#include "rstypeserializer.h" + static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff; static const uint8_t RS_ITEM_SUBTYPE_TEST1 = 0x01 ; // Template serialization of RsTypeSerialiser::serial_process() for unknown/new types -// +// Here we do it for std::set as an example. // template<> uint32_t RsTypeSerializer::serial_size(const std::set& s) { @@ -25,13 +27,16 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint3 bool ok = true ; uint32_t offset_save = offset ; - if(tlvsize + offset >= size) + if(tlvsize + offset > size) + { + std::cerr << "RsTypeSerializer::serialize: error. tlvsize+offset > size, where tlvsize=" << tlvsize << ", offset=" << offset << ", size=" << size << std::endl; return false ; + } - ok = ok && RsTypeSerializer::serialize(data,size,offset,member.size()) ; + ok = ok && RsTypeSerializer::serialize(data,size,offset,member.size()) ; for(std::set::const_iterator it(member.begin());it!=member.end();++it) - ok = ok && RsTypeSerializer::serialize(data,size,offset,*it) ; + ok = ok && RsTypeSerializer::serialize(data,size,offset,*it) ; if(!ok) { @@ -50,7 +55,7 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz ok = ok && RsTypeSerializer::deserialize(data,size,offset,n); - for(uint32_t i=0;i bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz class RsTestItem: public RsSerializable { public: - RsTestItem() : RsSerializable(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) {} + RsTestItem() : RsSerializable(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) + { + str = "test string"; + ts = time(NULL) ; + + int_set.insert(lrand48()) ; + int_set.insert(lrand48()) ; + int_set.insert(lrand48()) ; + } // Derived from RsSerializable // virtual void serial_process(RsSerializable::SerializeJob j, SerializeContext& ctx) { + TlvString tt(str,TLV_TYPE_STR_DESCR) ; + RsTypeSerializer::serial_process(j,ctx,ts ) ; - RsTypeSerializer::serial_process(j,ctx,str) ; + RsTypeSerializer::serial_process(j,ctx,tt ) ; RsTypeSerializer::serial_process(j,ctx,int_set ) ; } @@ -89,11 +104,12 @@ class RsTestItem: public RsSerializable virtual void clear() {} virtual std::ostream& print(std::ostream&,uint16_t indent) {} - private: std::string str ; uint64_t ts ; std::set int_set ; + + friend int main(int argc,char *argv[]); }; // New user-defined serializer class. @@ -116,6 +132,12 @@ class RsTestSerializer: public RsSerializer } }; +// Methods to check the equality of items. +// +void check(const std::string& s1,const std::string& s2) { assert(s1 == s2) ; } +void check(const uint64_t& s1,const uint64_t& s2) { assert(s1 == s2) ; } +void check(const std::set& s1,const std::set& s2) { assert(s1 == s2) ; } + int main(int argc,char *argv[]) { try @@ -126,13 +148,25 @@ int main(int argc,char *argv[]) std::cerr << "t1.serial_size() = " << size << std::endl; + // Allocate some memory to serialise to + // RsTemporaryMemory mem1(size); RsTestSerializer().serialize_item(&t1,mem1,mem1.size()) ; + std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; + + // Now deserialise into a new item + // RsSerializable *t2 = RsTestSerializer().deserialize_item(mem1,mem1.size()) ; - std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; + // make sure t1 is equal to t2 + // + check(t1.str,dynamic_cast(t2)->str) ; + check(t1.ts,dynamic_cast(t2)->ts) ; + check(t1.int_set,dynamic_cast(t2)->int_set) ; + + delete t2; return 0; } diff --git a/libretroshare/src/serialization/serializer.h b/libretroshare/src/serialization/serializer.h deleted file mode 100644 index 462206c42..000000000 --- a/libretroshare/src/serialization/serializer.h +++ /dev/null @@ -1,328 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include "arpa/inet.h" -#include "serialiser/rsserial.h" - -class RsItem ; - -class SerializeContext; - -class RsSerializable: public RsItem -{ -public: - typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; - - RsSerializable(uint8_t version,uint16_t service,uint8_t id) - : RsItem(version,service,id) - { - } - - /** - * @brief serialize this object to the given buffer - * @param Job to do: serialise or deserialize. - * @param data Chunk of memory were to dump the serialized data - * @param size Size of memory chunk - * @param offset Readed to determine at witch offset start writing data, - * written to inform caller were written data ends, the updated value - * is usually passed by the caller to serialize of another - * RsSerializable so it can write on the same chunk of memory just - * after where this RsSerializable has been serialized. - * @return true if serialization successed, false otherwise - */ - - virtual void serial_process(SerializeJob j,SerializeContext& ctx) = 0; -}; - -class SerializeContext -{ - public: - - SerializeContext(uint8_t *data,uint32_t size) - : mData(data),mSize(size),mOffset(0),mOk(true) {} - - unsigned char *mData ; - uint32_t mSize ; - uint32_t mOffset ; - bool mOk ; -}; -template T ntoh(T t) -{ - if(sizeof(T) == 8) return t; - if(sizeof(T) == 4) return ntohl(t) ; - if(sizeof(T) == 2) return ntohs(t) ; - - std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in ntoh<>" << std::endl; - return t; -} -template T hton(T t) -{ - if(sizeof(T) == 8) return t; - if(sizeof(T) == 4) return htonl(t) ; - if(sizeof(T) == 2) return htons(t) ; - - std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in hton<>" << std::endl; - return t; -} - -class RsTypeSerializer -{ - public: - template - static void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,T& member) - { - switch(j) - { - case RsSerializable::SIZE_ESTIMATE: ctx.mSize += serial_size(member) ; - break ; - - case RsSerializable::DESERIALIZE: deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; - break ; - - case RsSerializable::SERIALIZE: serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; - break ; - - default: - throw std::runtime_error("Unknown serial job") ; - } - } - - protected: - template - static bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const T& member); - - template - static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); - - template - static uint32_t serial_size(const T& /* member */); -}; - -/// Templates to generate RsSerializer for standard integral types -// -template class t_SerializerNType -{ -public: - static bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const N& member) - { - if (size <= offset || size - offset < SIZE) - return false; - - N tmp = hton(member); - memcpy(data+offset, &tmp, SIZE); - offset += SIZE; - return true; - } - static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, N& member) - { - if (size <= offset || size - offset < SIZE) - return false; - - N tmp ; - memcpy(&tmp, data+offset, SIZE); - member = ntoh(tmp); - offset += SIZE; - return true; - } - - static uint32_t serial_size(const N& /* member */) - { - return SIZE; - } -}; - -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) -{ - return t_SerializerNType::serialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) -{ - return t_SerializerNType::serialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint64_t& member) -{ - return t_SerializerNType::serialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member) -{ - return t_SerializerNType::deserialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) -{ - return t_SerializerNType::deserialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint64_t& member) -{ - return t_SerializerNType::deserialize(data,size,offset,member); -} -template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& member) -{ - return t_SerializerNType::serial_size(member); -} -template<> uint32_t RsTypeSerializer::serial_size(const uint32_t& member) -{ - return t_SerializerNType::serial_size(member); -} -template<> uint32_t RsTypeSerializer::serial_size(const uint64_t& member) -{ - return t_SerializerNType::serial_size(member); -} -//// Float -// -template<> - uint32_t RsTypeSerializer::serial_size(const float&){ return 4; } - - -template<> -bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const float& f) - { - uint32_t sz = serial_size(f); - if ( !data || size <= offset || size - offset < sz ) - return false; - - const float tmp = f; - if(tmp < 0.0f) - { - std::cerr << "(EE) Cannot serialise invalid negative float value " - << tmp << " in " << __PRETTY_FUNCTION__ << std::endl; - return false; - } - - /* This serialisation is quite accurate. The max relative error is approx. - * 0.01% and most of the time less than 1e-05% The error is well distributed - * over numbers also. */ - uint32_t n; - if(tmp < 1e-7) n = (~(uint32_t)0); - else n = ((uint32_t)( (1.0f/(1.0f+tmp) * (~(uint32_t)0)))); - n = hton(n); - memcpy(data+offset, &n, sz); - offset += sz; - return true; - } - -template<> uint32_t RsTypeSerializer::serial_size(const std::string& s) -{ - return s.length() + 4; -} - - -template<> - bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f) - { - uint32_t sz = serial_size(f); - if ( !data || size <= offset || - size - offset < sz ) - return false; - - uint32_t n; - memcpy(&n, data+offset, sz); - n = ntoh(n); - f = 1.0f/ ( n/(float)(~(uint32_t)0)) - 1.0f; - return true; - } - - -/// Serializer for std::string - template<> - bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const std::string& s) - { - if ( !data || size <= offset || size - offset < serial_size(s)) - return false; - - uint32_t charsLen = s.length(); - uint32_t netLen = hton(charsLen); - memcpy(data+offset, &netLen, 4); offset += 4; - memcpy(data+offset, s.c_str(), charsLen); offset += charsLen; - return true; - } -template<> - bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,std::string& s) - { - if ( !data || size <= offset || size - offset < 4 ) return false; - uint32_t charsLen; - memcpy(&charsLen, data+offset, 4); offset += 4; - charsLen = ntoh(charsLen); - - if ( size <= offset || size - offset < charsLen ) return false; - s.clear(); - s.insert(0, (char*)data+offset, charsLen); - offset += charsLen; - return true; - } - -class RsSerializer -{ - public: - /*! create_item - * should be overloaded to create the correct type of item depending on the data - */ - virtual RsSerializable *create_item(uint16_t service, uint8_t item_sub_id) - { - return NULL ; - } - - RsSerializable *deserialize_item(const uint8_t *data,uint32_t size) - { - uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; - - RsSerializable *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; - - if(!item) - { - std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; - return NULL ; - } - - SerializeContext ctx(const_cast(data),size); - item->serial_process(RsSerializable::DESERIALIZE, ctx) ; - - if(ctx.mOk) - return item ; - - delete item ; - return NULL ; - } - - bool serialize_item(const RsSerializable *item,uint8_t *const data,uint32_t size) - { - SerializeContext ctx(data,0); - - uint32_t tlvsize = size_item(item) ; - - if(tlvsize > size) - throw std::runtime_error("Cannot serialise: not enough room.") ; - - if(!setRsItemHeader(data, tlvsize, const_cast(item)->PacketId(), tlvsize)) - { - std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; - return false ; - } - ctx.mOffset = 8; - ctx.mSize = tlvsize; - - const_cast(item)->serial_process(RsSerializable::SERIALIZE,ctx) ; - - if(ctx.mSize != ctx.mOffset) - { - std::cerr << "RsSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; - return false ; - } - return true ; - } - - uint32_t size_item(const RsSerializable *item) - { - SerializeContext ctx(NULL,0); - - ctx.mSize = 8 ; // header size - const_cast(item)->serial_process(RsSerializable::SIZE_ESTIMATE, ctx) ; - - return ctx.mSize ; - } -}; - - - From b52071d0c9e63477e2a60a701a6a73c235d74bf4 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 1 Apr 2017 18:05:53 +0200 Subject: [PATCH 004/106] removed RsSerializable and merged it into RsItem --- libretroshare/src/serialiser/rsserial.h | 19 ++++++++++++- .../src/serialization/rsserializer.h | 28 +++++++++++-------- .../src/serialization/rstypeserializer.h | 8 +++--- .../src/serialization/serial_test.cc | 21 +++++++------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index bb8b84d8c..ad735abe5 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -70,6 +70,7 @@ const uint8_t RS_PKT_CLASS_CONFIG = 0x02; const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */ +class SerializeContext ; class RsItem: public RsMemoryManagement::SmallObject { @@ -105,7 +106,23 @@ class RsItem: public RsMemoryManagement::SmallObject void setPacketService(uint16_t service); inline uint8_t priority_level() const { return _priority_level ;} - inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} + inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} + + /** + * @brief serialize this object to the given buffer + * @param Job to do: serialise or deserialize. + * @param data Chunk of memory were to dump the serialized data + * @param size Size of memory chunk + * @param offset Readed to determine at witch offset start writing data, + * written to inform caller were written data ends, the updated value + * is usually passed by the caller to serialize of another + * RsSerializable so it can write on the same chunk of memory just + * after where this RsSerializable has been serialized. + * @return true if serialization successed, false otherwise + */ + typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; + + virtual void serial_process(SerializeJob j,SerializeContext& ctx) = 0; private: uint32_t type; diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 706ee3be4..e7725b955 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -5,7 +5,9 @@ #include #include -#include "rsserializable.h" +#include "serialiser/rsserial.h" + +#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " class SerializeContext { @@ -20,22 +22,24 @@ class SerializeContext bool mOk ; }; -class RsSerializer +class RsSerializer: public RsSerialType { public: + RsSerializer(uint16_t service_id) : RsSerialType(service_id) {} + /*! create_item * should be overloaded to create the correct type of item depending on the data */ - virtual RsSerializable *create_item(uint16_t service, uint8_t item_sub_id) + virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) { return NULL ; } - RsSerializable *deserialize_item(const uint8_t *data,uint32_t size) + RsItem *deserialise(const uint8_t *data,uint32_t size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; - RsSerializable *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; + RsItem *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; if(!item) { @@ -46,7 +50,7 @@ class RsSerializer SerializeContext ctx(const_cast(data),size); ctx.mOffset = 8 ; - item->serial_process(RsSerializable::DESERIALIZE, ctx) ; + item->serial_process(RsItem::DESERIALIZE, ctx) ; if(ctx.mOk) return item ; @@ -55,16 +59,16 @@ class RsSerializer return NULL ; } - bool serialize_item(const RsSerializable *item,uint8_t *const data,uint32_t size) + bool serialise(RsItem *item,uint8_t *const data,uint32_t size) { SerializeContext ctx(data,0); - uint32_t tlvsize = size_item(item) ; + uint32_t tlvsize = this->size(item) ; if(tlvsize > size) throw std::runtime_error("Cannot serialise: not enough room.") ; - if(!setRsItemHeader(data, tlvsize, const_cast(item)->PacketId(), tlvsize)) + if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize)) { std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; return false ; @@ -72,7 +76,7 @@ class RsSerializer ctx.mOffset = 8; ctx.mSize = tlvsize; - const_cast(item)->serial_process(RsSerializable::SERIALIZE,ctx) ; + item->serial_process(RsItem::SERIALIZE,ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -82,12 +86,12 @@ class RsSerializer return true ; } - uint32_t size_item(const RsSerializable *item) + uint32_t size(RsItem *item) { SerializeContext ctx(NULL,0); ctx.mSize = 8 ; // header size - const_cast(item)->serial_process(RsSerializable::SIZE_ESTIMATE, ctx) ; + item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; return ctx.mSize ; } diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index a713832b3..4661ecc61 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -23,17 +23,17 @@ class RsTypeSerializer { public: template - static void serial_process(RsSerializable::SerializeJob j,SerializeContext& ctx,T& member) + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member) { switch(j) { - case RsSerializable::SIZE_ESTIMATE: ctx.mSize += serial_size(member) ; + case RsItem::SIZE_ESTIMATE: ctx.mSize += serial_size(member) ; break ; - case RsSerializable::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; - case RsSerializable::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; default: diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index 9b5745b4b..f1698ad0c 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -8,7 +8,7 @@ #include "util/rsprint.h" #include "serialiser/rsserial.h" -#include "serializer.h" +#include "rsserializer.h" #include "rstypeserializer.h" static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff; @@ -75,10 +75,10 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz // - a serial_process method that tells which members to serialize // - overload the clear() and print() methods of RsItem // -class RsTestItem: public RsSerializable +class RsTestItem: public RsItem { public: - RsTestItem() : RsSerializable(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) + RsTestItem() : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) { str = "test string"; ts = time(NULL) ; @@ -88,9 +88,9 @@ class RsTestItem: public RsSerializable int_set.insert(lrand48()) ; } - // Derived from RsSerializable + // Derived from RsItem // - virtual void serial_process(RsSerializable::SerializeJob j, SerializeContext& ctx) + virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx) { TlvString tt(str,TLV_TYPE_STR_DESCR) ; @@ -113,14 +113,15 @@ class RsTestItem: public RsSerializable }; // New user-defined serializer class. -// The only required member is the create_item() method, which creates the correct RsSerializable +// The only required member is the create_item() method, which creates the correct RsItem // that corresponds to a specific (service,subtype) couple. // class RsTestSerializer: public RsSerializer { public: + RsTestSerializer() : RsSerializer(RS_SERVICE_TYPE_TEST) {} - virtual RsSerializable *create_item(uint16_t service,uint8_t subtype) + virtual RsItem *create_item(uint8_t subtype) { switch(subtype) { @@ -144,7 +145,7 @@ int main(int argc,char *argv[]) { RsTestItem t1 ; - uint32_t size = RsTestSerializer().size_item(&t1); + uint32_t size = RsTestSerializer().size(&t1); std::cerr << "t1.serial_size() = " << size << std::endl; @@ -152,13 +153,13 @@ int main(int argc,char *argv[]) // RsTemporaryMemory mem1(size); - RsTestSerializer().serialize_item(&t1,mem1,mem1.size()) ; + RsTestSerializer().serialise(&t1,mem1,mem1.size()) ; std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; // Now deserialise into a new item // - RsSerializable *t2 = RsTestSerializer().deserialize_item(mem1,mem1.size()) ; + RsItem *t2 = RsTestSerializer().deserialise(mem1,mem1.size()) ; // make sure t1 is equal to t2 // From ddbe2ef9a19b374c9350ea0476fe86c535f90f1a Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 2 Apr 2017 14:48:17 +0200 Subject: [PATCH 005/106] created .cc files for serialization --- libretroshare/src/libretroshare.pro | 7 + libretroshare/src/serialiser/rsserial.h | 5 +- .../src/serialization/rsserializable.h | 35 ---- .../src/serialization/rsserializer.cc | 67 +++++++ .../src/serialization/rsserializer.h | 63 +------ .../src/serialization/rstypeserializer.h | 164 +----------------- 6 files changed, 82 insertions(+), 259 deletions(-) delete mode 100644 libretroshare/src/serialization/rsserializable.h create mode 100644 libretroshare/src/serialization/rsserializer.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 551fbf335..1b437282c 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -771,6 +771,13 @@ HEADERS += gxstunnel/p3gxstunnel.h \ SOURCES += gxstunnel/p3gxstunnel.cc \ gxstunnel/rsgxstunnelitems.cc +# new serialization code +HEADERS += serialization/rsserializer.h \ + serialization/rstypeserializer.h + +SOURCES += serialization/rsserializer.cc \ + serialization/rstypeserializer.cc + # Identity Service HEADERS += retroshare/rsidentity.h \ gxs/rsgixs.h \ diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index ad735abe5..2b4aa304d 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -122,7 +122,10 @@ class RsItem: public RsMemoryManagement::SmallObject */ typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; - virtual void serial_process(SerializeJob j,SerializeContext& ctx) = 0; + virtual void serial_process(SerializeJob j,SerializeContext& ctx) + { + std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! " << std::endl; + } private: uint32_t type; diff --git a/libretroshare/src/serialization/rsserializable.h b/libretroshare/src/serialization/rsserializable.h deleted file mode 100644 index 3351e0147..000000000 --- a/libretroshare/src/serialization/rsserializable.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "serialiser/rsserial.h" - -class RsItem ; -class SerializeContext; - -#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " - -class RsSerializable: public RsItem -{ -public: - typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; - - RsSerializable(uint8_t version,uint16_t service,uint8_t id) - : RsItem(version,service,id) - { - } - - /** - * @brief serialize this object to the given buffer - * @param Job to do: serialise or deserialize. - * @param data Chunk of memory were to dump the serialized data - * @param size Size of memory chunk - * @param offset Readed to determine at witch offset start writing data, - * written to inform caller were written data ends, the updated value - * is usually passed by the caller to serialize of another - * RsSerializable so it can write on the same chunk of memory just - * after where this RsSerializable has been serialized. - * @return true if serialization successed, false otherwise - */ - - virtual void serial_process(SerializeJob j,SerializeContext& ctx) = 0; -}; - diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc new file mode 100644 index 000000000..cf8976fc1 --- /dev/null +++ b/libretroshare/src/serialization/rsserializer.cc @@ -0,0 +1,67 @@ +#pragma once + +#include "serialization/rsserializer.h" + +RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) +{ + uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; + + RsItem *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; + + if(!item) + { + std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + return NULL ; + } + + SerializeContext ctx(const_cast(data),size); + ctx.mOffset = 8 ; + + item->serial_process(RsItem::DESERIALIZE, ctx) ; + + if(ctx.mOk) + return item ; + + delete item ; + return NULL ; +} + +bool RsSerializer::serialise(RsItem *item,uint8_t *const data,uint32_t size) +{ + SerializeContext ctx(data,0); + + uint32_t tlvsize = this->size(item) ; + + if(tlvsize > size) + throw std::runtime_error("Cannot serialise: not enough room.") ; + + if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize)) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; + return false ; + } + ctx.mOffset = 8; + ctx.mSize = tlvsize; + + item->serial_process(RsItem::SERIALIZE,ctx) ; + + if(ctx.mSize != ctx.mOffset) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; + return false ; + } + return true ; +} + +uint32_t RsSerializer::size(RsItem *item) +{ + SerializeContext ctx(NULL,0); + + ctx.mSize = 8 ; // header size + item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; + + return ctx.mSize ; +} + + + diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index e7725b955..102bc4dce 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -35,66 +35,9 @@ class RsSerializer: public RsSerialType return NULL ; } - RsItem *deserialise(const uint8_t *data,uint32_t size) - { - uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; - - RsItem *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; - - if(!item) - { - std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; - return NULL ; - } - - SerializeContext ctx(const_cast(data),size); - ctx.mOffset = 8 ; - - item->serial_process(RsItem::DESERIALIZE, ctx) ; - - if(ctx.mOk) - return item ; - - delete item ; - return NULL ; - } - - bool serialise(RsItem *item,uint8_t *const data,uint32_t size) - { - SerializeContext ctx(data,0); - - uint32_t tlvsize = this->size(item) ; - - if(tlvsize > size) - throw std::runtime_error("Cannot serialise: not enough room.") ; - - if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize)) - { - std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; - return false ; - } - ctx.mOffset = 8; - ctx.mSize = tlvsize; - - item->serial_process(RsItem::SERIALIZE,ctx) ; - - if(ctx.mSize != ctx.mOffset) - { - std::cerr << "RsSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; - return false ; - } - return true ; - } - - uint32_t size(RsItem *item) - { - SerializeContext ctx(NULL,0); - - ctx.mSize = 8 ; // header size - item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; - - return ctx.mSize ; - } + RsItem *deserialise(const uint8_t *data,uint32_t size) ; + bool serialise(RsItem *item,uint8_t *const data,uint32_t size) ; + uint32_t size(RsItem *item) ; }; diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 4661ecc61..5c49d928c 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -1,24 +1,6 @@ +#include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" -template T ntoh(T t) -{ - if(sizeof(T) == 8) return t; - if(sizeof(T) == 4) return ntohl(t) ; - if(sizeof(T) == 2) return ntohs(t) ; - - std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in ntoh<>" << std::endl; - return t; -} -template T hton(T t) -{ - if(sizeof(T) == 8) return t; - if(sizeof(T) == 4) return htonl(t) ; - if(sizeof(T) == 2) return htons(t) ; - - std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in hton<>" << std::endl; - return t; -} - class RsTypeSerializer { public: @@ -48,148 +30,4 @@ class RsTypeSerializer template static uint32_t serial_size(const T& /* member */); }; -/// Templates to generate RsSerializer for standard integral types -// -template class t_SerializerNType -{ -public: - static bool serialize(uint8_t data[], uint32_t size, uint32_t &offset, const N& member) - { - if (size <= offset || size < SIZE + offset) - { - SERIALIZE_ERROR() << ": not enough room. SIZE+offset=" << SIZE+offset << " and size is only " << size << std::endl; - return false; - } - - N tmp = hton(member); - memcpy(data+offset, &tmp, SIZE); - offset += SIZE; - return true; - } - static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, N& member) - { - if (size <= offset || size < offset + SIZE) - { - SERIALIZE_ERROR() << ": not enough room. SIZE+offset=" << SIZE+offset << " and size is only " << size << std::endl; - return false; - } - - N tmp ; - memcpy(&tmp, data+offset, SIZE); - member = ntoh(tmp); - offset += SIZE; - return true; - } - - static uint32_t serial_size(const N& /* member */) - { - return SIZE; - } -}; - -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) -{ - return t_SerializerNType::serialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) -{ - return t_SerializerNType::serialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint64_t& member) -{ - return t_SerializerNType::serialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member) -{ - return t_SerializerNType::deserialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) -{ - return t_SerializerNType::deserialize(data,size,offset,member); -} -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint64_t& member) -{ - return t_SerializerNType::deserialize(data,size,offset,member); -} -template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& member) -{ - return t_SerializerNType::serial_size(member); -} -template<> uint32_t RsTypeSerializer::serial_size(const uint32_t& member) -{ - return t_SerializerNType::serial_size(member); -} -template<> uint32_t RsTypeSerializer::serial_size(const uint64_t& member) -{ - return t_SerializerNType::serial_size(member); -} -//// Float -// -template<> uint32_t RsTypeSerializer::serial_size(const float&){ return 4; } - -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t& offset, const float& f) -{ - uint32_t sz = serial_size(f); - - if ( !data || size <= offset || size < sz + offset ) - { - SERIALIZE_ERROR() << ": not enough room. SIZE+offset=" << sz+offset << " and size is only " << size << std::endl; - return false; - } - - const float tmp = f; - if(tmp < 0.0f) - { - SERIALIZE_ERROR() << "Cannot serialise invalid negative float value " << tmp << std::endl; - return false; - } - - /* This serialisation is quite accurate. The max relative error is approx. - * 0.01% and most of the time less than 1e-05% The error is well distributed - * over numbers also. */ - - uint32_t n; - if(tmp < 1e-7) n = (~(uint32_t)0); - else n = ((uint32_t)( (1.0f/(1.0f+tmp) * (~(uint32_t)0)))); - n = hton(n); - memcpy(data+offset, &n, sz); - offset += sz; - return true; -} - - -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f) -{ - uint32_t sz = serial_size(f); - - if ( !data || size <= offset || size < offset + sz ) - { - SERIALIZE_ERROR() << "Cannot deserialise float value. Not enough room. size=" << size << ", offset=" << offset << std::endl; - return false; - } - - uint32_t n; - memcpy(&n, data+offset, sz); - n = ntoh(n); - f = 1.0f/ ( n/(float)(~(uint32_t)0)) - 1.0f; - return true; -} - -typedef std::pair TlvString; - -/// Serializer for std::string -template<> uint32_t RsTypeSerializer::serial_size(const TlvString& s) -{ - return GetTlvStringSize(s.first) ; -} - -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const TlvString& s) -{ - return SetTlvString(data,size,&offset,s.second,s.first) ; -} - -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,TlvString& s) -{ - return GetTlvString((void*)data,size,&offset,s.second,s.first) ; -} From 75a3cf0f3b9e0cdd746311d30b6d0cdb2c6a7312 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 2 Apr 2017 15:04:03 +0200 Subject: [PATCH 006/106] fixed compilation in new serialization test code --- libretroshare/src/serialization/rsserializer.cc | 2 ++ libretroshare/src/serialization/rstypeserializer.h | 8 ++++++-- libretroshare/src/serialization/serial_test.cc | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index cf8976fc1..e12878b1d 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -1,5 +1,6 @@ #pragma once +#include "util/rsprint.h" #include "serialization/rsserializer.h" RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) @@ -11,6 +12,7 @@ RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) if(!item) { std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + std::cerr << "(EE) Data is: " << RsUtil::BinToHex(data,std::min(50u,size)) << ((size>50)?"...":"") << std::endl; return NULL ; } diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 5c49d928c..25c4d45b2 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -4,8 +4,12 @@ class RsTypeSerializer { public: - template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member) + // This type should be used to pass a parameter to drive the serialisation if needed. + + typedef std::pair TlvString; + + template + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member) { switch(j) { diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index f1698ad0c..24822284e 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -92,7 +92,7 @@ class RsTestItem: public RsItem // virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx) { - TlvString tt(str,TLV_TYPE_STR_DESCR) ; + RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_DESCR) ; RsTypeSerializer::serial_process(j,ctx,ts ) ; RsTypeSerializer::serial_process(j,ctx,tt ) ; @@ -121,8 +121,11 @@ class RsTestSerializer: public RsSerializer public: RsTestSerializer() : RsSerializer(RS_SERVICE_TYPE_TEST) {} - virtual RsItem *create_item(uint8_t subtype) + virtual RsItem *create_item(uint16_t service_id,uint8_t subtype) { + if(service_id != RS_SERVICE_TYPE_TEST) + return NULL ; + switch(subtype) { case RS_ITEM_SUBTYPE_TEST1: return new RsTestItem(); From 059dfcff47956dd9182f378a377414fec05bb640 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Apr 2017 14:00:17 +0200 Subject: [PATCH 007/106] added hability to print in the serialization process --- libretroshare/src/serialiser/rsserial.h | 2 +- .../src/serialization/rsserializer.cc | 8 ++++++++ .../src/serialization/rstypeserializer.h | 6 +++++- .../src/serialization/serial_test.cc | 20 ++++++++++++++----- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 2b4aa304d..0abc63af6 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -120,7 +120,7 @@ class RsItem: public RsMemoryManagement::SmallObject * after where this RsSerializable has been serialized. * @return true if serialization successed, false otherwise */ - typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03} SerializeJob ; + typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ; virtual void serial_process(SerializeJob j,SerializeContext& ctx) { diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index e12878b1d..f7926f8e2 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -65,5 +65,13 @@ uint32_t RsSerializer::size(RsItem *item) return ctx.mSize ; } +void RsSerializer::print(RsItem *item) +{ + SerializeContext ctx(NULL,0); + + std::cerr << "***** RsItem class: \"" << typeid(*item).name() << "\" *****" << std::endl; + item->serial_process(RsItem::PRINT, ctx) ; + std::cerr << "******************************" << std::endl; +} diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 25c4d45b2..37c1f9dc7 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -9,7 +9,7 @@ class RsTypeSerializer typedef std::pair TlvString; template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member) + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) { switch(j) { @@ -22,6 +22,9 @@ class RsTypeSerializer case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; + case RsItem::PRINT: + print_data(member_name,member); + break; default: ctx.mOk = false ; throw std::runtime_error("Unknown serial job") ; @@ -32,6 +35,7 @@ class RsTypeSerializer template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); template static uint32_t serial_size(const T& /* member */); + template static void print_data(const std::string& name,const T& /* member */); }; diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index 24822284e..786fd1d88 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -11,6 +11,8 @@ #include "rsserializer.h" #include "rstypeserializer.h" +#define GET_VARIABLE_NAME(str) #str + static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff; static const uint8_t RS_ITEM_SUBTYPE_TEST1 = 0x01 ; @@ -71,6 +73,11 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz return ok; } +template<> void RsTypeSerializer::print_data(const std::string& s,const std::set& set) +{ + std::cerr << " [set] " << s << " : set of size " << set.size() << std::endl; +} + // New item class. This class needs to define: // - a serial_process method that tells which members to serialize // - overload the clear() and print() methods of RsItem @@ -94,15 +101,15 @@ class RsTestItem: public RsItem { RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_DESCR) ; - RsTypeSerializer::serial_process(j,ctx,ts ) ; - RsTypeSerializer::serial_process(j,ctx,tt ) ; - RsTypeSerializer::serial_process(j,ctx,int_set ) ; + RsTypeSerializer::serial_process(j,ctx,ts ,GET_VARIABLE_NAME(ts) ) ; + RsTypeSerializer::serial_process(j,ctx,tt ,GET_VARIABLE_NAME(str) ) ; + RsTypeSerializer::serial_process(j,ctx,int_set,GET_VARIABLE_NAME(int_set) ) ; } - // Derived from RsItem + // Derived from RsItem, because they are pure virtuals. Normally print() should disappear soon. // virtual void clear() {} - virtual std::ostream& print(std::ostream&,uint16_t indent) {} + virtual std::ostream& print(std::ostream&,uint16_t) {} private: std::string str ; @@ -156,6 +163,9 @@ int main(int argc,char *argv[]) // RsTemporaryMemory mem1(size); + std::cerr << "Item to be serialized:" << std::endl; + + RsTestSerializer().print(&t1) ; RsTestSerializer().serialise(&t1,mem1,mem1.size()) ; std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; From f7e396856e0e044bc1e35bced8f0e9de6f6c48e3 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Apr 2017 14:01:33 +0200 Subject: [PATCH 008/106] added hability to print in the serialization process --- libretroshare/src/serialization/rsserializer.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 102bc4dce..ea20845b7 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -35,9 +35,13 @@ class RsSerializer: public RsSerialType return NULL ; } + // The following functions *should not* be overloaded. + // They are kept public in order to allow them to be called if needed. + RsItem *deserialise(const uint8_t *data,uint32_t size) ; bool serialise(RsItem *item,uint8_t *const data,uint32_t size) ; uint32_t size(RsItem *item) ; + void print(RsItem *item) ; }; From 32ce9aea3a2990425c62305731480998d793b50b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Apr 2017 15:33:59 +0200 Subject: [PATCH 009/106] started converting rschatitems to new serialization --- libretroshare/src/chat/distantchat.cc | 2 +- libretroshare/src/chat/rschatitems.cc | 139 ++++++++++++------ libretroshare/src/chat/rschatitems.h | 33 ++--- .../src/serialization/rsserializer.cc | 4 +- .../src/serialization/rstypeserializer.h | 2 +- 5 files changed, 106 insertions(+), 74 deletions(-) diff --git a/libretroshare/src/chat/distantchat.cc b/libretroshare/src/chat/distantchat.cc index 70fb88d8c..3f0e26b83 100644 --- a/libretroshare/src/chat/distantchat.cc +++ b/libretroshare/src/chat/distantchat.cc @@ -218,7 +218,7 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu contact.from_id = tinfo.source_gxs_id ; } - RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ; + RsItem *item = RsChatSerialiser().deserialise(data,data_size) ; if(item != NULL) { diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 90cf78fa6..3e2bd7d5a 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -29,10 +29,13 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" +#include "serialization/rstypeserializer.h" + #include "chat/rschatitems.h" //#define CHAT_DEBUG 1 +#ifdef TO_BE_REMOVED std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsChatMsgItem", indent); @@ -220,57 +223,44 @@ std::ostream& RsChatAvatarItem::print(std::ostream &out, uint16_t indent) return out; } -RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) +#endif + +RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) { - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); + if(service_id != RS_SERVICE_TYPE_CHAT) + return NULL ; -#ifdef CHAT_DEBUG - std::cerr << "deserializing packet..."<< std::endl ; -#endif - // look what we have... - if (*pktsize < rssize) /* check size */ + switch(item_sub_id) { -#ifdef CHAT_DEBUG - std::cerr << "chat deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - /* ready to load */ - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_CHAT != getRsItemService(rstype))) - { -#ifdef CHAT_DEBUG - std::cerr << "chat deserialisation: wrong type !" << std::endl ; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG: return new RsPrivateChatDistantInviteConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: return new RsChatLobbyEventItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ; + case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ; + case RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG: return new RsPrivateChatDistantInviteConfigItem() ; + case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ; + case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT:return new RsChatLobbyEventItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST:return new RsChatLobbyListRequestItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem() ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem() ; default: std::cerr << "Unknown packet type in chat!" << std::endl ; return NULL ; } } +void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_MSG) ; + + RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; + RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; + RsTypeSerializer::serial_process(j,ctx,tt,"message") ; +} + +#ifdef TO_BE_REMOVED uint32_t RsChatMsgItem::serial_size() { uint32_t s = 8; /* header */ @@ -423,6 +413,7 @@ uint32_t RsChatLobbyConfigItem::serial_size() return s; } +#endif /*************************************************************************/ @@ -435,6 +426,7 @@ RsChatAvatarItem::~RsChatAvatarItem() } } +#ifdef TO_BE_REMOVED /* serialise the data to the buffer */ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) { @@ -481,21 +473,40 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) #endif return ok ; } +#endif -bool RsChatLobbyBouncingObject::serialise_to_memory(void *data,uint32_t tlvsize,uint32_t& offset,bool include_signature) +bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature) { - bool ok = true ; + TlvString tt(nick,TLV_TYPE_STR_NAME) ; - ok &= setRawUInt64(data, tlvsize, &offset, lobby_id); - ok &= setRawUInt64(data, tlvsize, &offset, msg_id); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, nick); + RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; + RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; + RsTypeSerializer::serial_process(j,ctx,tt ,"nick") ; if(include_signature) - ok &= signature.SetTlv(data, tlvsize, &offset); + RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; - return ok ; + return true ; } +void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsChatMsgItem::serial_process(j,ctx) ; + + if(j == RsItem::SERIALIZE) + { + SerializeContext ctx2 ; + serial_process(RsItem::SIZE_ESTIMATE,ctx2); + + setRsItemHeader(ctx.mData, ctx.mSize, PacketId(), ctx2.mOffset); // correct header! + } + + RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; + + ctx.mOk &= RsChatLobbyBouncingObject::serialise_to_memory(j,ctx,true) ; +} + +#ifdef TO_BE_REMOVED /* serialise the data to the buffer */ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) { @@ -528,6 +539,8 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) #endif return ok ; } +#endif + /* serialise the data to the buffer */ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize) { @@ -562,7 +575,12 @@ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize) return ok ; } +void RsChatLobbyListRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + // nothing to do. This is an empty item. +} +#ifdef TO_BE_REMOVED bool RsChatLobbyListRequestItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -575,6 +593,27 @@ bool RsChatLobbyListRequestItem::serialise(void *data, uint32_t& pktsize) pktsize = tlvsize ; return ok ; } +#endif + +template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info) +{ + RsTypeSerializer::serial_process(info.id) ; + + TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ; + TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ; + + RsTypeSerializer::serial_process(info.name) ; + RsTypeSerializer::serial_process(info.topic) ; + RsTypeSerializer::serial_process(info.count) ; + RsTypeSerializer::serial_process(info.flags.toUInt32()) ; +} + +void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; +} + +#ifdef TO_BE_REMOVED bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -604,6 +643,8 @@ bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize) } return ok ; } +#endif + bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 13b42c18f..2ce127196 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -27,6 +27,7 @@ #include "openssl/bn.h" #include "retroshare/rstypes.h" +#include "serialization/rsserializer.h" #include "serialiser/rstlvkeys.h" #include "serialiser/rsserviceids.h" #include "serialiser/rsserial.h" @@ -90,11 +91,9 @@ class RsChatItem: public RsItem } virtual ~RsChatItem() {} - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; + virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) {} // derived from RsItem, but should be removed - virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor + virtual void clear() {} }; /*! @@ -107,14 +106,14 @@ public: RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT) {} RsChatMsgItem(uint8_t subtype) :RsChatItem(subtype) {} - RsChatMsgItem(void *data,uint32_t size,uint8_t subtype = RS_PKT_SUBTYPE_DEFAULT) ; // deserialization + //RsChatMsgItem() {} virtual ~RsChatMsgItem() {} - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + // derived from RsItem + + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void clear() {} uint32_t chatFlags; uint32_t sendTime; @@ -150,7 +149,7 @@ protected: // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. uint32_t serialized_size(bool include_signature) ; - bool serialise_to_memory(void *data,uint32_t tlvsize,uint32_t& offset,bool include_signature) ; + bool serialise_to_memory(RsItem::SerializeJob j, SerializeContext &ctx, bool include_signature) ; bool deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) ; }; @@ -413,19 +412,11 @@ class RsChatDHPublicKeyItem: public RsChatItem const RsChatDHPublicKeyItem& operator=(const RsChatDHPublicKeyItem&) { return *this ;} }; -class RsChatSerialiser: public RsSerialType +class RsChatSerialiser: public RsSerializer { public: - RsChatSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_CHAT) {} + RsChatSerialiser() :RsSerializer(RS_SERVICE_TYPE_CHAT) {} - virtual uint32_t size (RsItem *item) - { - return static_cast(item)->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - return static_cast(item)->serialise(data,*size) ; - } - virtual RsItem *deserialise (void *data, uint32_t *size) ; + virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) ; }; diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index f7926f8e2..b17785038 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -59,10 +59,10 @@ uint32_t RsSerializer::size(RsItem *item) { SerializeContext ctx(NULL,0); - ctx.mSize = 8 ; // header size + ctx.mOffset = 8 ; // header size item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; - return ctx.mSize ; + return ctx.mOffset ; } void RsSerializer::print(RsItem *item) diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 37c1f9dc7..1e4d5b20b 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -13,7 +13,7 @@ class RsTypeSerializer { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mSize += serial_size(member) ; + case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; break ; case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; From f2fa70e39562a0d80d85df0abf7ab52ad7f4472a Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Apr 2017 16:37:57 +0200 Subject: [PATCH 010/106] progress in converting Chat items to new serialization model --- libretroshare/src/chat/distantchat.cc | 8 +- libretroshare/src/chat/distributedchat.cc | 2 +- libretroshare/src/chat/rschatitems.cc | 91 ++++++++++++-- libretroshare/src/chat/rschatitems.h | 113 ++++-------------- .../src/serialization/rsserializer.h | 13 -- .../src/serialization/rstypeserializer.h | 25 ++++ 6 files changed, 136 insertions(+), 116 deletions(-) diff --git a/libretroshare/src/chat/distantchat.cc b/libretroshare/src/chat/distantchat.cc index 3f0e26b83..576e97efe 100644 --- a/libretroshare/src/chat/distantchat.cc +++ b/libretroshare/src/chat/distantchat.cc @@ -89,10 +89,10 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item) std::cerr << "p3ChatService::handleOutgoingItem(): sending to " << item->PeerId() << ": interpreted as a distant chat virtual peer id." << std::endl; #endif - uint32_t size = item->serial_size() ; + uint32_t size = RsChatSerialiser().size(item) ; RsTemporaryMemory mem(size) ; - if(!item->serialise(mem,size)) + if(!RsChatSerialiser().serialise(item,mem,size)) { std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl; return false; @@ -149,10 +149,10 @@ bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id,const RsGxsTun // we do not use handleOutGoingItem() because there's no distant chat contact, as the chat is refused. - uint32_t size = item->serial_size() ; + uint32_t size = RsChatSerialiser().size(item) ; RsTemporaryMemory mem(size) ; - if(!item->serialise(mem,size)) + if(!RsChatSerialiser().serialise(item,mem,size)) { std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl; return false; diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index 05312e1a9..52c9e6ffb 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -415,7 +415,7 @@ void DistributedChatService::checkSizeAndSendLobbyMessage(RsChatItem *msg) // static const uint32_t MAX_ITEM_SIZE = 32000 ; - if(msg->serial_size() > MAX_ITEM_SIZE) + if(RsChatSerialiser().size(msg) > MAX_ITEM_SIZE) { std::cerr << "(EE) Chat item exceeds maximum serial size. It will be dropped." << std::endl; delete msg ; diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 3e2bd7d5a..aa0a19cda 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -234,7 +234,6 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) { case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ; case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ; - case RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG: return new RsPrivateChatDistantInviteConfigItem() ; case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ; case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ; case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ; @@ -253,7 +252,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_MSG) ; + RsTypeSerializer::TlvString tt(message,TLV_TYPE_STR_MSG) ; RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; @@ -475,9 +474,9 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) } #endif -bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature) +void RsChatLobbyBouncingObject::serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature) { - TlvString tt(nick,TLV_TYPE_STR_NAME) ; + RsTypeSerializer::TlvString tt(nick,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; @@ -485,8 +484,6 @@ bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,Seria if(include_signature) RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; - - return true ; } void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) @@ -495,7 +492,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& if(j == RsItem::SERIALIZE) { - SerializeContext ctx2 ; + SerializeContext ctx2(NULL,0) ; serial_process(RsItem::SIZE_ESTIMATE,ctx2); setRsItemHeader(ctx.mData, ctx.mSize, PacketId(), ctx2.mOffset); // correct header! @@ -503,7 +500,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; - ctx.mOk &= RsChatLobbyBouncingObject::serialise_to_memory(j,ctx,true) ; + RsChatLobbyBouncingObject::serial_process_special(j,ctx,true) ; } #ifdef TO_BE_REMOVED @@ -561,7 +558,7 @@ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize) // The signature is at the end of the serialised data, so that the signed data is *before* the signature. - ok &= RsChatLobbyBouncingObject::serialise_to_memory(data,tlvsize,offset,false) ; + ok &= RsChatLobbyBouncingObject::serial_process_special(data,tlvsize,offset,false) ; /* add mandatory parts first */ if (offset != tlvsize) @@ -706,6 +703,12 @@ bool RsChatLobbyEventItem::serialise_signed_part(void *data, uint32_t& pktsize) return ok ; } +void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; +} + +#ifdef TO_BE_REMOVED bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -730,6 +733,14 @@ bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize) pktsize = tlvsize ; return ok ; } +#endif + +void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,challenge_code,"challenge_code") ; +} + +#ifdef TO_BE_REMOVED bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -754,7 +765,19 @@ bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize) pktsize = tlvsize ; return ok ; } +#endif +void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; + + TlvString s(message,TLV_TYPE_STR_NAME) ; + + RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; + RsTypeSerializer::serial_process(j,ctx,lobby_flags.toUInt32(),"lobby_flags") ; +} + +#ifdef TO_BE_REMOVED bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -781,7 +804,22 @@ bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) pktsize = tlvsize ; return ok ; } +#endif +void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + uint32_t x=0 ; + TlvString s(message,TLV_TYPE_STR_MSG) ; + + RsTypeSerializer::serial_process(j,ctx,x,"place holder value") ; + RsTypeSerializer::serial_process (j,ctx,configPeerId,"configPeerId") ; + RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatFlags") ; + RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; + RsTypeSerializer::serial_process (j,ctx,s,"message") ; + RsTypeSerializer::serial_process(j,ctx,recvTime,"recvTime") ; +} + +#ifdef TO_BE_REMOVED bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -821,6 +859,7 @@ bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize) return ok; } + bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -863,6 +902,18 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi return ok; } +#endif + +void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; + + RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ; + + RsTypeSerializer::serial_process(j,ctx,tt,"status_string") ; +} + +#ifdef TO_BE_REMOVED bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -901,7 +952,14 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) return ok; } +#endif +void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,RsTypeSerializer::BinaryDataBlock(data,image_size)) ; +} + +#ifdef TO_BE_REMOVED bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -942,6 +1000,15 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize) return ok; } +#endif + +void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; + RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; +} + +#ifdef TO_BE_REMOVED bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -1067,6 +1134,7 @@ RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t) if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; } +#endif bool RsChatLobbyBouncingObject::deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) { @@ -1103,6 +1171,8 @@ RsChatLobbyEventItem::RsChatLobbyEventItem(void *data,uint32_t /*size*/) if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; } + +#ifdef TO_BE_REMOVED RsChatLobbyUnsubscribeItem::RsChatLobbyUnsubscribeItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) { @@ -1246,6 +1316,7 @@ RsChatLobbyConfigItem::RsChatLobbyConfigItem(void *data,uint32_t /*size*/) if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; } +#endif /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags) @@ -1270,6 +1341,7 @@ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci) ci->recvTime = recvTime; } +#ifdef TO_BE_REMOVED RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) { @@ -1319,4 +1391,5 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) std::cerr << "Unknown error while deserializing." << std::endl ; } +#endif diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 2ce127196..3b04b995c 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -79,7 +79,7 @@ const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1A ; typedef uint64_t ChatLobbyId ; typedef uint64_t ChatLobbyMsgId ; -typedef std::string ChatLobbyNickName ; +typedef std::string ChatLobbyNickName ; typedef uint64_t DistantChatDHSessionId ; class RsChatItem: public RsItem @@ -91,7 +91,7 @@ class RsChatItem: public RsItem } virtual ~RsChatItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) {} // derived from RsItem, but should be removed + virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) { return out; } // derived from RsItem, but should be removed virtual void clear() {} }; @@ -136,7 +136,6 @@ public: RsTlvKeySignature signature ; virtual RsChatLobbyBouncingObject *duplicate() const = 0 ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); // returns the size in bytes of the data chunk to sign. @@ -148,9 +147,7 @@ protected: // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - uint32_t serialized_size(bool include_signature) ; - bool serialise_to_memory(RsItem::SerializeJob j, SerializeContext &ctx, bool include_signature) ; - bool deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) ; + void serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature); }; class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject @@ -158,14 +155,10 @@ class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject public: RsChatLobbyMsgItem() :RsChatMsgItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG) {} - RsChatLobbyMsgItem(void *data,uint32_t size) ; // deserialization /// TODO!!! - virtual ~RsChatLobbyMsgItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; virtual uint32_t signed_serial_size() ; virtual bool serialise_signed_part(void *data,uint32_t& size) ;// Isn't it better that items can serialize themselves ? @@ -177,17 +170,14 @@ class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject { public: RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {} - RsChatLobbyEventItem(void *data,uint32_t size) ; // deserialization /// TODO!!! virtual ~RsChatLobbyEventItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } // - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); virtual uint32_t signed_serial_size() ; - virtual bool serialise_signed_part(void *data,uint32_t& size) ; + virtual bool serialise_signed_part(void *data,uint32_t& size) ; // members. // @@ -200,13 +190,9 @@ class RsChatLobbyListRequestItem: public RsChatItem { public: RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {} - RsChatLobbyListRequestItem(void *data,uint32_t size) ; virtual ~RsChatLobbyListRequestItem() {} - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); }; struct VisibleChatLobbyInfo @@ -222,13 +208,9 @@ class RsChatLobbyListItem: public RsChatItem { public: RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {} - RsChatLobbyListItem(void *data,uint32_t size) ; virtual ~RsChatLobbyListItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); std::vector lobbies ; }; @@ -237,48 +219,38 @@ class RsChatLobbyUnsubscribeItem: public RsChatItem { public: RsChatLobbyUnsubscribeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) {} - RsChatLobbyUnsubscribeItem(void *data,uint32_t size) ; // deserialization virtual ~RsChatLobbyUnsubscribeItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); uint64_t lobby_id ; - - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor }; class RsChatLobbyConnectChallengeItem: public RsChatItem { public: RsChatLobbyConnectChallengeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) {} - RsChatLobbyConnectChallengeItem(void *data,uint32_t size) ; // deserialization virtual ~RsChatLobbyConnectChallengeItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); uint64_t challenge_code ; - - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor }; class RsChatLobbyInviteItem: public RsChatItem { public: RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {} - RsChatLobbyInviteItem(void *data,uint32_t size) ; // deserialization - virtual ~RsChatLobbyInviteItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); ChatLobbyId lobby_id ; std::string lobby_name ; std::string lobby_topic ; ChatLobbyFlags lobby_flags ; - - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor }; /*! @@ -289,14 +261,11 @@ class RsPrivateChatMsgConfigItem: public RsChatItem { public: RsPrivateChatMsgConfigItem() :RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG) {} - RsPrivateChatMsgConfigItem(void *data,uint32_t size) ; // deserialization virtual ~RsPrivateChatMsgConfigItem() {} virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags); @@ -310,43 +279,19 @@ class RsPrivateChatMsgConfigItem: public RsChatItem std::string message; uint32_t recvTime; }; -class RsPrivateChatDistantInviteConfigItem: public RsChatItem -{ - public: - RsPrivateChatDistantInviteConfigItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG) {} - RsPrivateChatDistantInviteConfigItem(void *data,uint32_t size) ; // deserialization - - virtual ~RsPrivateChatDistantInviteConfigItem() {} - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor - - unsigned char aes_key[16] ; - RsFileHash hash ; - std::string encrypted_radix64_string ; - RsPgpId destination_pgp_id ; - uint32_t time_of_validity ; - uint32_t last_hit_time ; - uint32_t flags ; -}; class RsChatLobbyConfigItem: public RsChatItem { public: - RsChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG) { lobby_Id = 0; } - RsChatLobbyConfigItem(void *data,uint32_t size) ; // deserialization + RsChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG) { lobby_Id = 0; } - virtual ~RsChatLobbyConfigItem() {} + virtual ~RsChatLobbyConfigItem() {} - virtual void clear() { lobby_Id = 0; } - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual void clear() { lobby_Id = 0; } - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); - uint64_t lobby_Id; - uint32_t flags ; + uint64_t lobby_Id; + uint32_t flags ; }; // This class contains activity info for the sending peer: active, idle, typing, etc. @@ -355,13 +300,10 @@ class RsChatStatusItem: public RsChatItem { public: RsChatStatusItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) {} - RsChatStatusItem(void *data,uint32_t size) ; // deserialization virtual ~RsChatStatusItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); uint32_t flags ; std::string status_string; @@ -373,13 +315,9 @@ class RsChatAvatarItem: public RsChatItem { public: RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;} - RsChatAvatarItem(void *data,uint32_t size) ; // deserialization virtual ~RsChatAvatarItem() ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); uint32_t image_size ; // size of data in bytes unsigned char *image_data ; // image @@ -392,13 +330,10 @@ class RsChatDHPublicKeyItem: public RsChatItem { public: RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;} - RsChatDHPublicKeyItem(void *data,uint32_t size) ; // deserialization virtual ~RsChatDHPublicKeyItem() { BN_free(public_key) ; } - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); // Private data to DH public key item // diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index ea20845b7..8c5539088 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -9,19 +9,6 @@ #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " -class SerializeContext -{ - public: - - SerializeContext(uint8_t *data,uint32_t size) - : mData(data),mSize(size),mOffset(0),mOk(true) {} - - unsigned char *mData ; - uint32_t mSize ; - uint32_t mOffset ; - bool mOk ; -}; - class RsSerializer: public RsSerialType { public: diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 1e4d5b20b..49505fc78 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -1,6 +1,22 @@ +#pragma once + #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" +class SerializeContext +{ + public: + + SerializeContext(uint8_t *data,uint32_t size) + : mData(data),mSize(size),mOffset(0),mOk(true) {} + + unsigned char *mData ; + uint32_t mSize ; + uint32_t mOffset ; + bool mOk ; +}; + + class RsTypeSerializer { public: @@ -8,6 +24,15 @@ class RsTypeSerializer typedef std::pair TlvString; + class BinaryDataBlock_ref + { + public: + BinaryDataBlock_ref(unsigned char *& _mem,uint32_t& _size) : mem(&_mem),size(&_size){} + + unsigned char **mem ; + uint32_t *size ; + }; + template static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) { From 9438d606096063d10650cfedee49a2712f38bc9a Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Apr 2017 22:53:50 +0200 Subject: [PATCH 011/106] progress in converting Chat items to new serialization model --- libretroshare/src/chat/distributedchat.cc | 10 +- libretroshare/src/chat/rschatitems.cc | 91 ++++++++++++++----- libretroshare/src/chat/rschatitems.h | 25 ++--- .../src/serialization/rstypeserializer.h | 11 ++- 4 files changed, 92 insertions(+), 45 deletions(-) diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index 52c9e6ffb..4d1207f8f 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -222,7 +222,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id)); - uint32_t size = obj->signed_serial_size() ; + uint32_t size = obj->serial_size_no_signature() ; RsTemporaryMemory memory(size) ; #ifdef DEBUG_CHAT_LOBBIES @@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const std::cerr << " signature id: " << obj->signature.keyId << std::endl; #endif - if(!obj->serialise_signed_part(memory,size)) + if(!obj->serialize_no_signature(memory,size)) { std::cerr << " (EE) Cannot serialise message item. " << std::endl; return false ; @@ -239,7 +239,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const uint32_t error_status ; RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ; - if(!mGixs->validateData(memory,obj->signed_serial_size(),obj->signature,false,use_info,error_status)) + if(!mGixs->validateData(memory,obj->serial_size_no_signature(),obj->signature,false,use_info,error_status)) { bool res = false ; @@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId& // now sign the object, if the lobby expects it - uint32_t size = item.signed_serial_size() ; + uint32_t size = item.serial_size_no_signature() ; RsTemporaryMemory memory(size) ; - if(!item.serialise_signed_part(memory,size)) + if(!item.serialize_no_signature(memory,size)) { std::cerr << "(EE) Cannot sign message item. " << std::endl; return false ; diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index aa0a19cda..165dc94de 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -35,6 +35,8 @@ //#define CHAT_DEBUG 1 +static const uint32_t RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE = 0x0001; + #ifdef TO_BE_REMOVED std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) { @@ -474,7 +476,7 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) } #endif -void RsChatLobbyBouncingObject::serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature) +void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::TlvString tt(nick,TLV_TYPE_STR_NAME) ; @@ -482,7 +484,7 @@ void RsChatLobbyBouncingObject::serial_process_special(RsItem::SerializeJob j,Se RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; RsTypeSerializer::serial_process(j,ctx,tt ,"nick") ; - if(include_signature) + if(!(ctx.mFlags & RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE)) RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } @@ -490,17 +492,9 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& { RsChatMsgItem::serial_process(j,ctx) ; - if(j == RsItem::SERIALIZE) - { - SerializeContext ctx2(NULL,0) ; - serial_process(RsItem::SIZE_ESTIMATE,ctx2); - - setRsItemHeader(ctx.mData, ctx.mSize, PacketId(), ctx2.mOffset); // correct header! - } - RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; - RsChatLobbyBouncingObject::serial_process_special(j,ctx,true) ; + RsChatLobbyBouncingObject::serial_process(j,ctx) ; } #ifdef TO_BE_REMOVED @@ -536,7 +530,6 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) #endif return ok ; } -#endif /* serialise the data to the buffer */ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize) @@ -571,6 +564,7 @@ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize) #endif return ok ; } +#endif void RsChatLobbyListRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { @@ -592,17 +586,17 @@ bool RsChatLobbyListRequestItem::serialise(void *data, uint32_t& pktsize) } #endif -template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info) +template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info) { RsTypeSerializer::serial_process(info.id) ; TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ; TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(info.name) ; - RsTypeSerializer::serial_process(info.topic) ; - RsTypeSerializer::serial_process(info.count) ; - RsTypeSerializer::serial_process(info.flags.toUInt32()) ; + RsTypeSerializer::serial_process(j,ctx,info.name,"info.name") ; + RsTypeSerializer::serial_process(j,ctx,info.topic,"info.topic") ; + RsTypeSerializer::serial_process(j,ctx,info.count,"info.count") ; + RsTypeSerializer::serial_process(j,ctx,info.flags.toUInt32(),"info.flags") ; } void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) @@ -642,6 +636,18 @@ bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize) } #endif +void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::TlvString tt(string1,TLV_TYPE_STR_NAME) ; + + RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; + RsTypeSerializer::serial_process (j,ctx,string1,"string1") ; + RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; + + RsChatLobbyBouncingObject::serial_process(j,ctx,!(ctx.mFlags & RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE)); +} + +#ifdef TO_BE_REMOVED bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -702,6 +708,7 @@ bool RsChatLobbyEventItem::serialise_signed_part(void *data, uint32_t& pktsize) #endif return ok ; } +#endif void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { @@ -771,7 +778,7 @@ void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeConte { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; - TlvString s(message,TLV_TYPE_STR_NAME) ; + RsTypeSerializer::TlvString s(lobby_name,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; RsTypeSerializer::serial_process(j,ctx,lobby_flags.toUInt32(),"lobby_flags") ; @@ -809,7 +816,7 @@ bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { uint32_t x=0 ; - TlvString s(message,TLV_TYPE_STR_MSG) ; + RsTypeSerializer::TlvString s(message,TLV_TYPE_STR_MSG) ; RsTypeSerializer::serial_process(j,ctx,x,"place holder value") ; RsTypeSerializer::serial_process (j,ctx,configPeerId,"configPeerId") ; @@ -956,7 +963,7 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,RsTypeSerializer::BinaryDataBlock(data,image_size)) ; + RsTypeSerializer::serial_process(j,ctx,RsTypeSerializer::BinaryDataBlock_ref(image_data,image_size)) ; } #ifdef TO_BE_REMOVED @@ -1004,7 +1011,7 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize) void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; + RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; } @@ -1134,7 +1141,6 @@ RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t) if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; } -#endif bool RsChatLobbyBouncingObject::deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) { @@ -1172,7 +1178,6 @@ RsChatLobbyEventItem::RsChatLobbyEventItem(void *data,uint32_t /*size*/) std::cerr << "Unknown error while deserializing." << std::endl ; } -#ifdef TO_BE_REMOVED RsChatLobbyUnsubscribeItem::RsChatLobbyUnsubscribeItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) { @@ -1393,3 +1398,43 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) #endif +uint32_t RsChatLobbyBouncingObject::serial_size_no_signature() const +{ + SerializeContext ctx(NULL,0); + + ctx.mOffset = 8; + ctx.mFlags = RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE ; + + const_cast(this)->serial_process(RsItem::SERIALIZE,ctx) ; + + return ctx.mOffset ; +} + +bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t size) const +{ + SerializeContext ctx(data,0); + + uint32_t tlvsize = serial_size_no_signature() ; + + if(tlvsize > size) + throw std::runtime_error("Cannot serialise: not enough room.") ; + + if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; + return false ; + } + ctx.mOffset = 8; + ctx.mSize = tlvsize; + ctx.mFlags = RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE ; + + const_cast(this)->serial_process(RsItem::SERIALIZE,ctx) ; + + if(ctx.mSize != ctx.mOffset) + { + std::cerr << "RsChatSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; + return false ; + } + return true ; +} + diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 3b04b995c..5cdee927e 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -137,17 +137,17 @@ public: virtual RsChatLobbyBouncingObject *duplicate() const = 0 ; - // returns the size in bytes of the data chunk to sign. - - virtual uint32_t signed_serial_size() =0; - virtual bool serialise_signed_part(void *data,uint32_t& size) = 0; + uint32_t serial_size_no_signature() const ; + bool serialize_no_signature(uint8_t *data,uint32_t size) const ; protected: // The functions below handle the serialisation of data that is specific to the bouncing object level. // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - void serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + + virtual uint32_t PacketId() const= 0; }; class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject @@ -160,10 +160,10 @@ public: void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; - virtual uint32_t signed_serial_size() ; - virtual bool serialise_signed_part(void *data,uint32_t& size) ;// Isn't it better that items can serialize themselves ? - ChatLobbyMsgId parent_msg_id ; // Used for threaded chat. + +protected: + virtual uint32_t PacketId() const { return RsChatMsgItem::PacketId() ; } }; class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject @@ -176,14 +176,14 @@ class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject // void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); - virtual uint32_t signed_serial_size() ; - virtual bool serialise_signed_part(void *data,uint32_t& size) ; - // members. // uint8_t event_type ; // used for defining the type of event. std::string string1; // used for any string uint32_t sendTime; // used to check for old looping messages + +protected: + virtual uint32_t PacketId() const { return RsChatItem::PacketId() ; } }; class RsChatLobbyListRequestItem: public RsChatItem @@ -243,7 +243,7 @@ class RsChatLobbyInviteItem: public RsChatItem { public: RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {} - virtual ~RsChatLobbyInviteItem() {} + virtual ~RsChatLobbyInviteItem() {} void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); @@ -279,6 +279,7 @@ class RsPrivateChatMsgConfigItem: public RsChatItem std::string message; uint32_t recvTime; }; + class RsChatLobbyConfigItem: public RsChatItem { public: diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 49505fc78..348d18375 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -8,12 +8,13 @@ class SerializeContext public: SerializeContext(uint8_t *data,uint32_t size) - : mData(data),mSize(size),mOffset(0),mOk(true) {} + : mData(data),mSize(size),mOffset(0),mOk(true),mFlags(0) {} unsigned char *mData ; uint32_t mSize ; uint32_t mOffset ; bool mOk ; + uint32_t mFlags ; }; @@ -57,10 +58,10 @@ class RsTypeSerializer } protected: - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); - template static uint32_t serial_size(const T& /* member */); - template static void print_data(const std::string& name,const T& /* member */); + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); + template static uint32_t serial_size(const T& /* member */); + template static void print_data(const std::string& name,const T& /* member */); }; From 48688eae3f2a04a024e83bc25597683902f4870d Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 10:27:12 +0200 Subject: [PATCH 012/106] progress in converting chat items to new serialization --- libretroshare/src/chat/rschatitems.cc | 26 +++--- libretroshare/src/chat/rschatitems.h | 2 +- .../src/serialization/rsserializer.cc | 1 + .../src/serialization/rstypeserializer.h | 84 ++++++++++++++++--- 4 files changed, 88 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 165dc94de..41291515e 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -476,7 +476,7 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) } #endif -void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx, bool include_signature) { RsTypeSerializer::TlvString tt(nick,TLV_TYPE_STR_NAME) ; @@ -484,7 +484,7 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j,SerializeC RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; RsTypeSerializer::serial_process(j,ctx,tt ,"nick") ; - if(!(ctx.mFlags & RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE)) + if(include_signature) RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } @@ -494,7 +494,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; - RsChatLobbyBouncingObject::serial_process(j,ctx) ; + RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; } #ifdef TO_BE_REMOVED @@ -586,9 +586,9 @@ bool RsChatLobbyListRequestItem::serialise(void *data, uint32_t& pktsize) } #endif -template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info) +template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) { - RsTypeSerializer::serial_process(info.id) ; + RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ; TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ; @@ -596,12 +596,12 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ RsTypeSerializer::serial_process(j,ctx,info.name,"info.name") ; RsTypeSerializer::serial_process(j,ctx,info.topic,"info.topic") ; RsTypeSerializer::serial_process(j,ctx,info.count,"info.count") ; - RsTypeSerializer::serial_process(j,ctx,info.flags.toUInt32(),"info.flags") ; + RsTypeSerializer::serial_process(j,ctx,info.flags,"info.flags") ; } void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; + RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; } #ifdef TO_BE_REMOVED @@ -644,7 +644,7 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex RsTypeSerializer::serial_process (j,ctx,string1,"string1") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; - RsChatLobbyBouncingObject::serial_process(j,ctx,!(ctx.mFlags & RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE)); + RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; } #ifdef TO_BE_REMOVED @@ -781,7 +781,7 @@ void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeConte RsTypeSerializer::TlvString s(lobby_name,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; - RsTypeSerializer::serial_process(j,ctx,lobby_flags.toUInt32(),"lobby_flags") ; + RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; } #ifdef TO_BE_REMOVED @@ -963,7 +963,7 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,RsTypeSerializer::BinaryDataBlock_ref(image_data,image_size)) ; + RsTypeSerializer::serial_process(j,ctx,RsTypeSerializer::block_ref(image_data,image_size),"image data") ; } #ifdef TO_BE_REMOVED @@ -1403,9 +1403,8 @@ uint32_t RsChatLobbyBouncingObject::serial_size_no_signature() const SerializeContext ctx(NULL,0); ctx.mOffset = 8; - ctx.mFlags = RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE ; - const_cast(this)->serial_process(RsItem::SERIALIZE,ctx) ; + const_cast(this)->serial_process(RsItem::SERIALIZE,ctx,false) ; return ctx.mOffset ; } @@ -1426,9 +1425,8 @@ bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t si } ctx.mOffset = 8; ctx.mSize = tlvsize; - ctx.mFlags = RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE ; - const_cast(this)->serial_process(RsItem::SERIALIZE,ctx) ; + const_cast(this)->serial_process(RsItem::SERIALIZE,ctx,false) ; if(ctx.mSize != ctx.mOffset) { diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 5cdee927e..2440722dd 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -145,7 +145,7 @@ protected: // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature); virtual uint32_t PacketId() const= 0; }; diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index b17785038..745dc3521 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -2,6 +2,7 @@ #include "util/rsprint.h" #include "serialization/rsserializer.h" +#include "serialization/rstypeserializer.h" RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) { diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 348d18375..15bb8c696 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" @@ -8,31 +10,39 @@ class SerializeContext public: SerializeContext(uint8_t *data,uint32_t size) - : mData(data),mSize(size),mOffset(0),mOk(true),mFlags(0) {} + : mData(data),mSize(size),mOffset(0),mOk(true) {} unsigned char *mData ; uint32_t mSize ; uint32_t mOffset ; bool mOk ; - uint32_t mFlags ; }; class RsTypeSerializer { +protected: + class BinaryDataBlock_ref + { + public: + BinaryDataBlock_ref(unsigned char *_mem,uint32_t& _size) : mem(_mem),size(_size){} + + // This allows to pass Temporary objects as modifiable. This is valid only because all members of this class + // are pointers and references. + + BinaryDataBlock_ref& modifiable() const { return *const_cast(this) ; } + + unsigned char *& mem ; + uint32_t& size ; + }; + + public: // This type should be used to pass a parameter to drive the serialisation if needed. typedef std::pair TlvString; - class BinaryDataBlock_ref - { - public: - BinaryDataBlock_ref(unsigned char *& _mem,uint32_t& _size) : mem(&_mem),size(&_size){} - - unsigned char **mem ; - uint32_t *size ; - }; + static BinaryDataBlock_ref& block_ref(unsigned char *mem,uint32_t& size) { return BinaryDataBlock_ref(mem,size).modifiable() ; } template static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) @@ -57,11 +67,65 @@ class RsTypeSerializer } } + // Arrays of stuff + + template + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::vector& v,const std::string& member_name) + { + switch(j) + { + case RsItem::SIZE_ESTIMATE: + { + ctx.mOffset += 4 ; + for(uint32_t i=0;i static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); template static uint32_t serial_size(const T& /* member */); template static void print_data(const std::string& name,const T& /* member */); + + }; From 5b3e488b423cb8e0aae0f50af6b510fd5d4125ea Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 16:53:20 +0200 Subject: [PATCH 013/106] fixed compilation --- libretroshare/src/chat/rschatitems.cc | 16 ++-- libretroshare/src/retroshare/rsids.h | 2 +- libretroshare/src/serialiser/rsserial.h | 2 +- .../src/serialization/rsserializer.h | 2 +- .../src/serialization/rstypeserializer.h | 79 +++++++++++++++++-- .../src/serialization/serial_test.cc | 10 ++- 6 files changed, 91 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 41291515e..9865ca411 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -593,10 +593,10 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ; TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,info.name,"info.name") ; - RsTypeSerializer::serial_process(j,ctx,info.topic,"info.topic") ; + RsTypeSerializer::serial_process(j,ctx,tt1,"info.name") ; + RsTypeSerializer::serial_process(j,ctx,tt2,"info.topic") ; RsTypeSerializer::serial_process(j,ctx,info.count,"info.count") ; - RsTypeSerializer::serial_process(j,ctx,info.flags,"info.flags") ; + RsTypeSerializer::serial_process(j,ctx,info.flags,"info.flags") ; } void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) @@ -641,8 +641,8 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex RsTypeSerializer::TlvString tt(string1,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; - RsTypeSerializer::serial_process (j,ctx,string1,"string1") ; - RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; + RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ; + RsTypeSerializer::serial_process(j,ctx,sendTime ,"sendTime") ; RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; } @@ -781,7 +781,7 @@ void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeConte RsTypeSerializer::TlvString s(lobby_name,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; - RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; + RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; } #ifdef TO_BE_REMOVED @@ -913,7 +913,7 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; + RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ; @@ -1012,7 +1012,7 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize) void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; - RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; + RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; } #ifdef TO_BE_REMOVED diff --git a/libretroshare/src/retroshare/rsids.h b/libretroshare/src/retroshare/rsids.h index db842ab21..a412f0cf2 100644 --- a/libretroshare/src/retroshare/rsids.h +++ b/libretroshare/src/retroshare/rsids.h @@ -120,7 +120,7 @@ template c offset += SIZE_IN_BYTES ; return true ; } - bool deserialise(void *data,uint32_t pktsize,uint32_t& offset) + bool deserialise(const void *data,uint32_t pktsize,uint32_t& offset) { if(offset + SIZE_IN_BYTES > pktsize) return false ; diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 0abc63af6..722eec9ec 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -122,7 +122,7 @@ class RsItem: public RsMemoryManagement::SmallObject */ typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ; - virtual void serial_process(SerializeJob j,SerializeContext& ctx) + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) { std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! " << std::endl; } diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 8c5539088..f5f815d52 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 */) { return NULL ; } diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 15bb8c696..2bb269ef6 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -1,10 +1,11 @@ #pragma once -#include - #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" +#include "retroshare/rsflags.h" +#include "retroshare/rsids.h" + class SerializeContext { public: @@ -44,6 +45,10 @@ protected: static BinaryDataBlock_ref& block_ref(unsigned char *mem,uint32_t& size) { return BinaryDataBlock_ref(mem,size).modifiable() ; } + //=================================================================================================// + // Generic types // + //=================================================================================================// + template static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) { @@ -67,7 +72,9 @@ protected: } } - // Arrays of stuff + //=================================================================================================// + // std::vector // + //=================================================================================================// template static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::vector& v,const std::string& member_name) @@ -106,7 +113,7 @@ protected: if(v.empty()) std::cerr << " Empty array"<< std::endl; else - std::cerr << " Array of \"" << typeid(v[0]).name() << "\"" << " with " << v.size() << " elements:"; + std::cerr << " Array of " << v.size() << " elements:" << std::endl; for(uint32_t i=0;i types // + //=================================================================================================// + + template + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,t_RsFlags32& v,const std::string& member_name) + { + switch(j) + { + case RsItem::SIZE_ESTIMATE: ctx.mOffset += 4 ; + break ; + + case RsItem::DESERIALIZE: + { + uint32_t n=0 ; + deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; + v = t_RsFlags32(n) ; + } + break ; + + case RsItem::SERIALIZE: + { + uint32_t n=v.toUInt32() ; + serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; + } + break ; + + case RsItem::PRINT: + std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl; + break ; + } + + } protected: template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); @@ -125,7 +165,36 @@ protected: template static uint32_t serial_size(const T& /* member */); template static void print_data(const std::string& name,const T& /* member */); - + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member); + template static uint32_t serial_size(const t_RsGenericIdType& /* member */); + template static void print_data(const std::string& name,const t_RsGenericIdType& /* member */); }; +//=================================================================================================// +// t_RsGenericId<> // +//=================================================================================================// +template +bool RsTypeSerializer::serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType& member) +{ + return (*const_cast *>(&member)).serialise(data,size,offset) ; +} + +template +bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member) +{ + return member.deserialise(data,size,offset) ; +} + +template +uint32_t RsTypeSerializer::serial_size(const t_RsGenericIdType& member) +{ + return member.serial_size(); +} + +template +void RsTypeSerializer::print_data(const std::string& name,const t_RsGenericIdType& member) +{ + std::cerr << " [RsGenericId<" << std::hex << UNIQUE_IDENTIFIER << ">] : " << member << std::endl; +} diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index 786fd1d88..67770ad87 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -3,6 +3,7 @@ // #include +#include #include "util/rsmemory.h" #include "util/rsprint.h" @@ -90,9 +91,9 @@ class RsTestItem: public RsItem str = "test string"; ts = time(NULL) ; - int_set.insert(lrand48()) ; - int_set.insert(lrand48()) ; - int_set.insert(lrand48()) ; + int_set.push_back(lrand48()) ; + int_set.push_back(lrand48()) ; + int_set.push_back(lrand48()) ; } // Derived from RsItem @@ -114,7 +115,7 @@ class RsTestItem: public RsItem private: std::string str ; uint64_t ts ; - std::set int_set ; + std::vector int_set ; friend int main(int argc,char *argv[]); }; @@ -148,6 +149,7 @@ class RsTestSerializer: public RsSerializer void check(const std::string& s1,const std::string& s2) { assert(s1 == s2) ; } void check(const uint64_t& s1,const uint64_t& s2) { assert(s1 == s2) ; } void check(const std::set& s1,const std::set& s2) { assert(s1 == s2) ; } +void check(const std::vector& s1,const std::vector& s2) { assert(s1 == s2) ; } int main(int argc,char *argv[]) { From a941136c0457975c477c398a2dbb16c67f216caf Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 18:09:45 +0200 Subject: [PATCH 014/106] fixed a few bugs in new serialization --- libretroshare/src/chat/distantchat.cc | 6 +++--- libretroshare/src/serialiser/rsserial.cc | 1 + libretroshare/src/serialization/rsserializer.cc | 14 ++++++-------- libretroshare/src/serialization/rsserializer.h | 9 ++++----- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/chat/distantchat.cc b/libretroshare/src/chat/distantchat.cc index 576e97efe..8bb8b8d17 100644 --- a/libretroshare/src/chat/distantchat.cc +++ b/libretroshare/src/chat/distantchat.cc @@ -92,7 +92,7 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item) uint32_t size = RsChatSerialiser().size(item) ; RsTemporaryMemory mem(size) ; - if(!RsChatSerialiser().serialise(item,mem,size)) + if(!RsChatSerialiser().serialise(item,mem,&size)) { std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl; return false; @@ -152,7 +152,7 @@ bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id,const RsGxsTun uint32_t size = RsChatSerialiser().size(item) ; RsTemporaryMemory mem(size) ; - if(!RsChatSerialiser().serialise(item,mem,size)) + if(!RsChatSerialiser().serialise(item,mem,&size)) { std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl; return false; @@ -218,7 +218,7 @@ void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tu contact.from_id = tinfo.source_gxs_id ; } - RsItem *item = RsChatSerialiser().deserialise(data,data_size) ; + RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ; if(item != NULL) { diff --git a/libretroshare/src/serialiser/rsserial.cc b/libretroshare/src/serialiser/rsserial.cc index 549bdc42c..8624b5304 100644 --- a/libretroshare/src/serialiser/rsserial.cc +++ b/libretroshare/src/serialiser/rsserial.cc @@ -219,6 +219,7 @@ uint32_t RsSerialType::size(RsItem *) bool RsSerialType::serialise(RsItem */*item*/, void */*data*/, uint32_t */*size*/) { + std::cerr << "(EE) Empty method called for missing serialize() method in serializer class " << typeid(this).name() << std::endl; #ifdef RSSERIAL_DEBUG std::cerr << "RsSerialType::serialise()" << std::endl; #endif diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 745dc3521..4cf03d133 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -1,10 +1,8 @@ -#pragma once - #include "util/rsprint.h" #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" -RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) +RsItem *RsSerializer::deserialise(void *data, uint32_t *size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; @@ -13,11 +11,11 @@ RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) if(!item) { std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; - std::cerr << "(EE) Data is: " << RsUtil::BinToHex(data,std::min(50u,size)) << ((size>50)?"...":"") << std::endl; + std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl; return NULL ; } - SerializeContext ctx(const_cast(data),size); + SerializeContext ctx(const_cast(static_cast(data)),*size); ctx.mOffset = 8 ; item->serial_process(RsItem::DESERIALIZE, ctx) ; @@ -29,13 +27,13 @@ RsItem *RsSerializer::deserialise(const uint8_t *data,uint32_t size) return NULL ; } -bool RsSerializer::serialise(RsItem *item,uint8_t *const data,uint32_t size) +bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size) { - SerializeContext ctx(data,0); + SerializeContext ctx(static_cast(data),0); uint32_t tlvsize = this->size(item) ; - if(tlvsize > size) + if(tlvsize > *size) throw std::runtime_error("Cannot serialise: not enough room.") ; if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize)) diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index f5f815d52..9c6259cf9 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -12,7 +12,7 @@ class RsSerializer: public RsSerialType { public: - RsSerializer(uint16_t service_id) : RsSerialType(service_id) {} + RsSerializer(uint16_t service_id) : RsSerialType(RS_PKT_VERSION_SERVICE,service_id) {} /*! create_item * should be overloaded to create the correct type of item depending on the data @@ -22,11 +22,10 @@ class RsSerializer: public RsSerialType return NULL ; } - // The following functions *should not* be overloaded. - // They are kept public in order to allow them to be called if needed. + // The following functions overload RsSerialType. They *should not* need to be further overloaded. - RsItem *deserialise(const uint8_t *data,uint32_t size) ; - bool serialise(RsItem *item,uint8_t *const data,uint32_t size) ; + RsItem *deserialise(void *data,uint32_t *size) ; + bool serialise(RsItem *item,void *data,uint32_t *size) ; uint32_t size(RsItem *item) ; void print(RsItem *item) ; }; From 6b4fdb42ae7a23250357d771f9cf28d581ea3058 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 18:25:54 +0200 Subject: [PATCH 015/106] fixed bug in serialization --- libretroshare/src/chat/rschatitems.cc | 20 ++++++++++-------- .../src/serialization/rstypeserializer.h | 21 ++----------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 9865ca411..ef4908252 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -254,7 +254,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::TlvString tt(message,TLV_TYPE_STR_MSG) ; + RsTypeSerializer::TlvString_proxy tt(message,TLV_TYPE_STR_MSG) ; RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; @@ -478,7 +478,7 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx, bool include_signature) { - RsTypeSerializer::TlvString tt(nick,TLV_TYPE_STR_NAME) ; + RsTypeSerializer::TlvString_proxy tt(nick,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; @@ -590,8 +590,8 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ { RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; - TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ; - TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ; + TlvString_proxy tt1(info.name ,TLV_TYPE_STR_NAME) ; + TlvString_proxy tt2(info.topic,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,tt1,"info.name") ; RsTypeSerializer::serial_process(j,ctx,tt2,"info.topic") ; @@ -638,7 +638,7 @@ bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize) void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::TlvString tt(string1,TLV_TYPE_STR_NAME) ; + RsTypeSerializer::TlvString_proxy tt(string1,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ; @@ -778,7 +778,7 @@ void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeConte { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; - RsTypeSerializer::TlvString s(lobby_name,TLV_TYPE_STR_NAME) ; + RsTypeSerializer::TlvString_proxy s(lobby_name,TLV_TYPE_STR_NAME) ; RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; @@ -816,7 +816,7 @@ bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { uint32_t x=0 ; - RsTypeSerializer::TlvString s(message,TLV_TYPE_STR_MSG) ; + RsTypeSerializer::TlvString_proxy s(message,TLV_TYPE_STR_MSG) ; RsTypeSerializer::serial_process(j,ctx,x,"place holder value") ; RsTypeSerializer::serial_process (j,ctx,configPeerId,"configPeerId") ; @@ -915,7 +915,7 @@ void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& c { RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; - RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ; + RsTypeSerializer::TlvString_proxy tt(status_string,TLV_TYPE_STR_MSG) ; RsTypeSerializer::serial_process(j,ctx,tt,"status_string") ; } @@ -963,7 +963,9 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,RsTypeSerializer::block_ref(image_data,image_size),"image data") ; + RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ; + + RsTypeSerializer::serial_process(j,ctx,b,"image data") ; } #ifdef TO_BE_REMOVED diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 2bb269ef6..f82365f82 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -22,28 +22,11 @@ class SerializeContext class RsTypeSerializer { -protected: - class BinaryDataBlock_ref - { - public: - BinaryDataBlock_ref(unsigned char *_mem,uint32_t& _size) : mem(_mem),size(_size){} - - // This allows to pass Temporary objects as modifiable. This is valid only because all members of this class - // are pointers and references. - - BinaryDataBlock_ref& modifiable() const { return *const_cast(this) ; } - - unsigned char *& mem ; - uint32_t& size ; - }; - - public: // This type should be used to pass a parameter to drive the serialisation if needed. - typedef std::pair TlvString; - - static BinaryDataBlock_ref& block_ref(unsigned char *mem,uint32_t& size) { return BinaryDataBlock_ref(mem,size).modifiable() ; } + typedef std::pair TlvString_proxy; + typedef std::pair TlvMemBlock_proxy; //=================================================================================================// // Generic types // From 03c31ceaccfe1812ea32765fa55cc573c6544159 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 18:27:29 +0200 Subject: [PATCH 016/106] fixed serialization test example --- libretroshare/src/serialization/serial_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc index 67770ad87..a8d89a25f 100644 --- a/libretroshare/src/serialization/serial_test.cc +++ b/libretroshare/src/serialization/serial_test.cc @@ -100,7 +100,7 @@ class RsTestItem: public RsItem // virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx) { - RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_DESCR) ; + RsTypeSerializer::TlvString_proxy tt(str,TLV_TYPE_STR_DESCR) ; RsTypeSerializer::serial_process(j,ctx,ts ,GET_VARIABLE_NAME(ts) ) ; RsTypeSerializer::serial_process(j,ctx,tt ,GET_VARIABLE_NAME(str) ) ; @@ -168,13 +168,13 @@ int main(int argc,char *argv[]) std::cerr << "Item to be serialized:" << std::endl; RsTestSerializer().print(&t1) ; - RsTestSerializer().serialise(&t1,mem1,mem1.size()) ; + RsTestSerializer().serialise(&t1,mem1,&size); std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; // Now deserialise into a new item // - RsItem *t2 = RsTestSerializer().deserialise(mem1,mem1.size()) ; + RsItem *t2 = RsTestSerializer().deserialise(mem1,&size); // make sure t1 is equal to t2 // From ae9d0b2ab48c7d0778385d680de728d104bb8762 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 20:49:32 +0200 Subject: [PATCH 017/106] fixed a few bugs in chat serialization --- libretroshare/src/chat/distributedchat.cc | 10 +++---- libretroshare/src/chat/rschatitems.cc | 28 +++++++++++++------ libretroshare/src/chat/rschatitems.h | 33 ++++++++++++----------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index 4d1207f8f..c83ddde8e 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -222,7 +222,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id)); - uint32_t size = obj->serial_size_no_signature() ; + uint32_t size = obj->serial_size_for_signature() ; RsTemporaryMemory memory(size) ; #ifdef DEBUG_CHAT_LOBBIES @@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const std::cerr << " signature id: " << obj->signature.keyId << std::endl; #endif - if(!obj->serialize_no_signature(memory,size)) + if(!obj->serialize_for_signature(memory,size)) { std::cerr << " (EE) Cannot serialise message item. " << std::endl; return false ; @@ -239,7 +239,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const uint32_t error_status ; RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ; - if(!mGixs->validateData(memory,obj->serial_size_no_signature(),obj->signature,false,use_info,error_status)) + if(!mGixs->validateData(memory,obj->serial_size_for_signature(),obj->signature,false,use_info,error_status)) { bool res = false ; @@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId& // now sign the object, if the lobby expects it - uint32_t size = item.serial_size_no_signature() ; + uint32_t size = item.serial_size_for_signature() ; RsTemporaryMemory memory(size) ; - if(!item.serialize_no_signature(memory,size)) + if(!item.serialize_for_signature(memory,size)) { std::cerr << "(EE) Cannot sign message item. " << std::endl; return false ; diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index ef4908252..e6a405c0c 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -491,12 +491,15 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsChatMsgItem::serial_process(j,ctx) ; - RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; - RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; } - +void RsChatLobbyMsgItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsChatMsgItem::serial_process(j,ctx) ; + RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; + RsChatLobbyBouncingObject::serial_process(j,ctx,false) ; +} #ifdef TO_BE_REMOVED /* serialise the data to the buffer */ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) @@ -646,7 +649,16 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; } +void RsChatLobbyEventItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::TlvString_proxy tt(string1,TLV_TYPE_STR_NAME) ; + RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; + RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ; + RsTypeSerializer::serial_process(j,ctx,sendTime ,"sendTime") ; + + RsChatLobbyBouncingObject::serial_process(j,ctx,false) ; +} #ifdef TO_BE_REMOVED bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize) { @@ -1400,22 +1412,22 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) #endif -uint32_t RsChatLobbyBouncingObject::serial_size_no_signature() const +uint32_t RsChatLobbyBouncingObject::serial_size_for_signature() const { SerializeContext ctx(NULL,0); ctx.mOffset = 8; - const_cast(this)->serial_process(RsItem::SERIALIZE,ctx,false) ; + const_cast(this)->serial_process_for_signature(RsItem::SIZE_ESTIMATE,ctx) ; return ctx.mOffset ; } -bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t size) const +bool RsChatLobbyBouncingObject::serialize_for_signature(uint8_t *data,uint32_t size) const { SerializeContext ctx(data,0); - uint32_t tlvsize = serial_size_no_signature() ; + uint32_t tlvsize = serial_size_for_signature() ; if(tlvsize > size) throw std::runtime_error("Cannot serialise: not enough room.") ; @@ -1428,7 +1440,7 @@ bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t si ctx.mOffset = 8; ctx.mSize = tlvsize; - const_cast(this)->serial_process(RsItem::SERIALIZE,ctx,false) ; + const_cast(this)->serial_process_for_signature(RsItem::SERIALIZE,ctx) ; if(ctx.mSize != ctx.mOffset) { diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 2440722dd..974dda91d 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -137,15 +137,16 @@ public: virtual RsChatLobbyBouncingObject *duplicate() const = 0 ; - uint32_t serial_size_no_signature() const ; - bool serialize_no_signature(uint8_t *data,uint32_t size) const ; + uint32_t serial_size_for_signature() const ; + bool serialize_for_signature(uint8_t *data,uint32_t size) const ; protected: // The functions below handle the serialisation of data that is specific to the bouncing object level. // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature); + virtual void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature); + virtual void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)=0; virtual uint32_t PacketId() const= 0; }; @@ -159,6 +160,7 @@ public: virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; + void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand ChatLobbyMsgId parent_msg_id ; // Used for threaded chat. @@ -168,22 +170,23 @@ protected: class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject { - public: - RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {} +public: + RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {} - virtual ~RsChatLobbyEventItem() {} - virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } - // - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual ~RsChatLobbyEventItem() {} + virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } + // + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand - // members. - // - uint8_t event_type ; // used for defining the type of event. - std::string string1; // used for any string - uint32_t sendTime; // used to check for old looping messages + // members. + // + uint8_t event_type ; // used for defining the type of event. + std::string string1; // used for any string + uint32_t sendTime; // used to check for old looping messages protected: - virtual uint32_t PacketId() const { return RsChatItem::PacketId() ; } + virtual uint32_t PacketId() const { return RsChatItem::PacketId() ; } }; class RsChatLobbyListRequestItem: public RsChatItem From 8b773885fddb0a48c843effa1cbe326a34349c67 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 21:02:17 +0200 Subject: [PATCH 018/106] removed all chat serialization code --- libretroshare/src/chat/rschatitems.cc | 1189 ------------------------- libretroshare/src/chat/rschatitems.h | 24 - 2 files changed, 1213 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index e6a405c0c..f7edf5601 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -37,196 +37,6 @@ static const uint32_t RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE = 0x0001; -#ifdef TO_BE_REMOVED -std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatMsgItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "QblogMs " << chatFlags << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << " (" << time(NULL)-sendTime << " secs ago)" << std::endl; - - printIndent(out, int_Indent); - - std::string cnv_message(message.begin(), message.end()); - out << "msg: " << cnv_message << std::endl; - - printRsItemEnd(out, "RsChatMsgItem", indent); - return out; -} - -std::ostream& RsChatLobbyListItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatLobbyListItem", indent); - - for(uint32_t i=0;i void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) { RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; @@ -607,38 +130,6 @@ void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize ; - - uint32_t offset = 8 ; - ok &= setRawUInt32(data, tlvsize, &offset, lobbies.size()); - - for(uint32_t i=0;i(j,ctx,lobby_id,"lobby_id") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - uint32_t offset = 8 ; - - ok &= setRawUInt64(data, tlvsize, &offset, lobby_id); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - pktsize = tlvsize ; - return ok ; -} -#endif - void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,challenge_code,"challenge_code") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - uint32_t offset = 8 ; - - ok &= setRawUInt64(data, tlvsize, &offset, challenge_code); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - pktsize = tlvsize ; - return ok ; -} -#endif - void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; - RsTypeSerializer::TlvString_proxy s(lobby_name,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - uint32_t offset = 8 ; - - ok &= setRawUInt64(data, tlvsize, &offset, lobby_id); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, lobby_name); - ok &= setRawUInt32(data, tlvsize, &offset, lobby_flags.toUInt32()); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - pktsize = tlvsize ; - return ok ; -} -#endif - void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { uint32_t x=0 ; @@ -838,505 +181,25 @@ void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,Serialize RsTypeSerializer::serial_process(j,ctx,recvTime,"recvTime") ; } -#ifdef TO_BE_REMOVED -bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, 0); - ok &= configPeerId.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, chatFlags); - ok &= setRawUInt32(data, tlvsize, &offset, configFlags); - ok &= setRawUInt32(data, tlvsize, &offset, sendTime); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message); - ok &= setRawUInt32(data, tlvsize, &offset, recvTime); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} - -bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= hash.serialise(data, tlvsize, offset) ; - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LINK, encrypted_radix64_string); - ok &= destination_pgp_id.serialise(data, tlvsize, offset); - - memcpy(&((unsigned char *)data)[offset],aes_key,16) ; - offset += 16 ; - - ok &= setRawUInt32(data, tlvsize, &offset, time_of_validity); - ok &= setRawUInt32(data, tlvsize, &offset, last_hit_time); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} -#endif - void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; - RsTypeSerializer::TlvString_proxy tt(status_string,TLV_TYPE_STR_MSG) ; - RsTypeSerializer::serial_process(j,ctx,tt,"status_string") ; } -#ifdef TO_BE_REMOVED -bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser serialising chat status item." << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= SetTlvString(data, tlvsize, &offset,TLV_TYPE_STR_MSG, status_string); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - - return ok; -} -#endif - void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ; - RsTypeSerializer::serial_process(j,ctx,b,"image data") ; } -#ifdef TO_BE_REMOVED -bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser serialising chat avatar item." << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset,image_size); - - memcpy((void*)( (unsigned char *)data + offset),image_data,image_size) ; - offset += image_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - - return ok; -} -#endif - void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatLobbyConfigItem::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatLobbyConfigItem::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, lobby_Id); - ok &= setRawUInt32(data, tlvsize, &offset, flags ); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatLobbyConfigItem::serialise() Size Error! " << std::endl; - } - - return ok; -} - -RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype) - : RsChatItem(subtype) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - -#ifdef CHAT_DEBUG - std::cerr << "Received packet result: " ; - for(int i=0;i<20;++i) - std::cerr << (int)((uint8_t*)data)[i] << " " ; - std::cerr << std::endl ; -#endif - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &chatFlags); - ok &= getRawUInt32(data, rssize, &offset, &sendTime); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, message); - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat msg item." << std::endl ; -#endif - if (getRsItemSubType(getRsItemId(data)) == RS_PKT_SUBTYPE_DEFAULT && offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} - -RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/) - : RsChatMsgItem(data,0,RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG) -{ - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - uint32_t offset = RsChatMsgItem::serial_size() ; - - ok &= getRawUInt64(data, rssize, &offset, &parent_msg_id); - - ok &= RsChatLobbyBouncingObject::deserialise_from_memory(data,rssize,offset) ; - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat lobby msg item." << std::endl ; -#endif - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} -RsChatLobbyListRequestItem::RsChatLobbyListRequestItem(void *data,uint32_t) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) -{ - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - uint32_t offset = 8; // skip the header - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} -RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) -{ - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - uint32_t offset = 8; // skip the header - - uint32_t n=0 ; - ok &= getRawUInt32(data, rssize, &offset, &n); - - lobbies.resize(n) ; - - for(uint32_t i=0;irecvTime = recvTime; } -#ifdef TO_BE_REMOVED -RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat status item." << std::endl ; -#endif - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &flags); - ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string); - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} - -RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat status item." << std::endl ; -#endif - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset,&image_size); - - // ensure invalid image length does not overflow data - if( (offset + image_size) <= rssize){ - image_data = new unsigned char[image_size] ; - memcpy(image_data,(void*)((unsigned char*)data+offset),image_size) ; - offset += image_size ; - }else{ - ok = false; - std::cerr << "offset+image_size exceeds rssize" << std::endl; - } - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} - -#endif - uint32_t RsChatLobbyBouncingObject::serial_size_for_signature() const { SerializeContext ctx(NULL,0); diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 974dda91d..7ec79ea44 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -327,30 +327,6 @@ class RsChatAvatarItem: public RsChatItem unsigned char *image_data ; // image }; -// This class contains the public Diffie-Hellman parameters to be sent -// when performing a DH agreement over a distant chat tunnel. -// -class RsChatDHPublicKeyItem: public RsChatItem -{ - public: - RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;} - - virtual ~RsChatDHPublicKeyItem() { BN_free(public_key) ; } - - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); - - // Private data to DH public key item - // - BIGNUM *public_key ; - - RsTlvKeySignature signature ; // signs the public key in a row. - RsTlvPublicRSAKey gxs_key ; // public key of the signer - - private: - RsChatDHPublicKeyItem(const RsChatDHPublicKeyItem&) : RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {} // make the object non copy-able - const RsChatDHPublicKeyItem& operator=(const RsChatDHPublicKeyItem&) { return *this ;} -}; - class RsChatSerialiser: public RsSerializer { public: From 691ed8de08ae779531df638cfed874c5ea37ba99 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Apr 2017 20:34:02 +0200 Subject: [PATCH 019/106] added new template for std::string with type id --- libretroshare/src/chat/rschatitems.cc | 50 +++++++------------ .../src/serialization/rstypeserializer.h | 33 +++++++++++- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index f7edf5601..a430b1119 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -64,11 +64,9 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::TlvString_proxy tt(message,TLV_TYPE_STR_MSG) ; - RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; - RsTypeSerializer::serial_process(j,ctx,tt,"message") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,message,"message") ; } /*************************************************************************/ @@ -84,11 +82,9 @@ RsChatAvatarItem::~RsChatAvatarItem() void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx, bool include_signature) { - RsTypeSerializer::TlvString_proxy tt(nick,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; - RsTypeSerializer::serial_process(j,ctx,tt ,"nick") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,nick,"nick") ; if(include_signature) RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; @@ -116,13 +112,10 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ { RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; - TlvString_proxy tt1(info.name ,TLV_TYPE_STR_NAME) ; - TlvString_proxy tt2(info.topic,TLV_TYPE_STR_NAME) ; - - RsTypeSerializer::serial_process(j,ctx,tt1,"info.name") ; - RsTypeSerializer::serial_process(j,ctx,tt2,"info.topic") ; - RsTypeSerializer::serial_process(j,ctx,info.count,"info.count") ; - RsTypeSerializer::serial_process(j,ctx,info.flags,"info.flags") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,info.name, "info.name") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,info.topic,"info.topic") ; + RsTypeSerializer::serial_process(j,ctx, info.count,"info.count") ; + RsTypeSerializer::serial_process (j,ctx, info.flags,"info.flags") ; } void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) @@ -132,20 +125,16 @@ void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::TlvString_proxy tt(string1,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; - RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; RsTypeSerializer::serial_process(j,ctx,sendTime ,"sendTime") ; RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; } void RsChatLobbyEventItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::TlvString_proxy tt(string1,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; - RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; RsTypeSerializer::serial_process(j,ctx,sendTime ,"sendTime") ; RsChatLobbyBouncingObject::serial_process(j,ctx,false) ; @@ -162,30 +151,27 @@ void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,Seri void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; - RsTypeSerializer::TlvString_proxy s(lobby_name,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; - RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; + RsTypeSerializer::serial_process(j,ctx, lobby_id, "lobby_id") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ; + RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ; } void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { uint32_t x=0 ; - RsTypeSerializer::TlvString_proxy s(message,TLV_TYPE_STR_MSG) ; - RsTypeSerializer::serial_process(j,ctx,x,"place holder value") ; - RsTypeSerializer::serial_process (j,ctx,configPeerId,"configPeerId") ; - RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatFlags") ; - RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; - RsTypeSerializer::serial_process (j,ctx,s,"message") ; - RsTypeSerializer::serial_process(j,ctx,recvTime,"recvTime") ; + RsTypeSerializer::serial_process(j,ctx, x, "place holder value") ; + RsTypeSerializer::serial_process (j,ctx, configPeerId,"configPeerId") ; + RsTypeSerializer::serial_process(j,ctx, chatFlags, "chatFlags") ; + RsTypeSerializer::serial_process(j,ctx, sendTime, "sendTime") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message, "message") ; + RsTypeSerializer::serial_process(j,ctx, recvTime, "recvTime") ; } void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; - RsTypeSerializer::TlvString_proxy tt(status_string,TLV_TYPE_STR_MSG) ; - RsTypeSerializer::serial_process(j,ctx,tt,"status_string") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,status_string,"status_string") ; } void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index f82365f82..878ec3e6b 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -25,7 +25,6 @@ class RsTypeSerializer public: // This type should be used to pass a parameter to drive the serialisation if needed. - typedef std::pair TlvString_proxy; typedef std::pair TlvMemBlock_proxy; //=================================================================================================// @@ -55,6 +54,33 @@ class RsTypeSerializer } } + //=================================================================================================// + // Generic types + type_id // + //=================================================================================================// + + template + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) + { + switch(j) + { + case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; + break ; + + case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; + break ; + + case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; + break ; + + case RsItem::PRINT: + print_data(member_name,type_id,member); + break; + default: + ctx.mOk = false ; + throw std::runtime_error("Unknown serial job") ; + } + } + //=================================================================================================// // std::vector // //=================================================================================================// @@ -148,6 +174,11 @@ class RsTypeSerializer template static uint32_t serial_size(const T& /* member */); template static void print_data(const std::string& name,const T& /* member */); + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, uint16_t type_id,const T& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset,uint16_t type_id, T& member); + template static uint32_t serial_size(uint16_t type_id,const T& /* member */); + template static void print_data(const std::string& name,uint16_t type_id,const T& /* member */); + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType& member); template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member); template static uint32_t serial_size(const t_RsGenericIdType& /* member */); From 731e20d0a3ed023f845dc618fea21c391411edb6 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Apr 2017 22:09:56 +0200 Subject: [PATCH 020/106] switch BanListItem classes to new serialization system --- .../src/serialiser/rsbanlistitems.cc | 299 ++---------------- libretroshare/src/serialiser/rsbanlistitems.h | 44 +-- libretroshare/src/serialiser/rsbaseserial.cc | 23 +- libretroshare/src/serialiser/rsbaseserial.h | 14 +- libretroshare/src/serialiser/rsserial.h | 7 +- .../src/serialization/rstypeserializer.h | 36 ++- 6 files changed, 93 insertions(+), 330 deletions(-) diff --git a/libretroshare/src/serialiser/rsbanlistitems.cc b/libretroshare/src/serialiser/rsbanlistitems.cc index b22c16d2b..a110ec00f 100644 --- a/libretroshare/src/serialiser/rsbanlistitems.cc +++ b/libretroshare/src/serialiser/rsbanlistitems.cc @@ -25,7 +25,8 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rsbanlistitems.h" -#include "serialiser/rstlvbanlist.h" + +#include "serialization/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 @@ -35,300 +36,36 @@ /*************************************************************************/ -RsBanListItem::~RsBanListItem() -{ - return; -} - void RsBanListItem::clear() { peerList.TlvClear(); } -std::ostream &RsBanListItem::print(std::ostream &out, uint16_t indent) +void RsBanListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - printRsItemBase(out, "RsBanListItem", indent); - uint16_t int_Indent = indent + 2; - peerList.print(out, int_Indent); - - printRsItemEnd(out, "RsBanListItem", indent); - return out; + RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ; } - -uint32_t RsBanListSerialiser::sizeList(RsBanListItem *item) +void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - uint32_t s = 8; /* header */ - s += item->peerList.TlvSize(); - - return s; + RsTypeSerializer::serial_process(j,ctx,type,"type") ; + RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; + RsTypeSerializer::serial_process (j,ctx,update_time,"update_time") ; + RsTypeSerializer::serial_process (j,ctx,banned_peers,"banned_peers") ; } - -uint32_t RsBanListSerialiser::sizeListConfig(RsBanListConfigItem *item) +RsItem *RsBanListSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) { - uint32_t s = 8; /* header */ - s += 4 ; // type - s += item->banned_peers.TlvSize(); - s += 8 ; // update time - s += item->peerId.serial_size() ; + if(service_id != RS_SERVICE_TYPE_BANLIST) + return NULL ; - return s; -} -/* serialise the data to the buffer */ -bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeList(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 << "RsDsdvSerialiser::serialiseRoute() Header: " << ok << std::endl; - std::cerr << "RsDsdvSerialiser::serialiseRoute() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->peerList.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDsdvSerialiser::serialiseRoute() Size Error! " << std::endl; -#endif - } - - return ok; -} -/* serialise the data to the buffer */ -bool RsBanListSerialiser::serialiseListConfig(RsBanListConfigItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeListConfig(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 << "RsBanListSerialiser::serialiseRoute() Header: " << ok << std::endl; - std::cerr << "RsBanListSerialiser::serialiseRoute() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset,item->type); - ok &= item->peerId.serialise(data, tlvsize, offset); - ok &= setRawTimeT(data, tlvsize, &offset,item->update_time); - - /* add mandatory parts first */ - ok &= item->banned_peers.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) + switch(item_sub_id) { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsBanListSerialiser::serialiseRoute() Size Error! " << std::endl; -#endif - } - - return ok; -} -RsBanListItem *RsBanListSerialiser::deserialiseList(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_BANLIST != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_BANLIST_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 */ - RsBanListItem *item = new RsBanListItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->peerList.GetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} -RsBanListConfigItem *RsBanListSerialiser::deserialiseListConfig(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_BANLIST != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_BANLIST_CONFIG_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 */ - RsBanListConfigItem *item = new RsBanListConfigItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - ok &= getRawUInt32(data, tlvsize, &offset,&item->type); - ok &= item->peerId.deserialise(data, tlvsize, offset); - ok &= getRawTimeT(data, tlvsize, &offset,item->update_time); - - /* add mandatory parts first */ - ok &= item->banned_peers.GetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -uint32_t RsBanListSerialiser::size(RsItem *i) -{ - RsBanListItem *dri; - RsBanListConfigItem *drc; - - if (NULL != (dri = dynamic_cast(i))) - { - return sizeList(dri); - } - - if (NULL != (drc = dynamic_cast(i))) - { - return sizeListConfig(drc); - } - return 0; -} - -bool RsBanListSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsBanListItem *dri; - RsBanListConfigItem *drc; - - if (NULL != (dri = dynamic_cast(i))) - { - return serialiseList(dri, data, pktsize); - } - if (NULL != (drc = dynamic_cast(i))) - { - return serialiseListConfig(drc, data, pktsize); - } - return false; -} - -RsItem *RsBanListSerialiser::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_BANLIST != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_BANLIST_ITEM: - return deserialiseList(data, pktsize); - break; - case RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM: - return deserialiseListConfig(data, pktsize); - break; - default: - return NULL; - break; + 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 ; } } -void RsBanListConfigItem::clear() -{ - banned_peers.TlvClear() ; -} - -std::ostream &RsBanListConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsBanListConfigItem", indent); - uint16_t int_Indent = indent + 2; - banned_peers.print(out, int_Indent); - - printRsItemEnd(out, "RsBanListConfigItem", indent); - return out; -} - -/*************************************************************************/ - - diff --git a/libretroshare/src/serialiser/rsbanlistitems.h b/libretroshare/src/serialiser/rsbanlistitems.h index 372f71a5d..cd5cb8cec 100644 --- a/libretroshare/src/serialiser/rsbanlistitems.h +++ b/libretroshare/src/serialiser/rsbanlistitems.h @@ -29,12 +29,12 @@ #include #include "serialiser/rsserviceids.h" -#include "serialiser/rsserial.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_deprecated 0x02 +#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03 #define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x04 /**************************************************************************/ @@ -42,17 +42,15 @@ class RsBanListItem: public RsItem { public: - RsBanListItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, - RS_PKT_SUBTYPE_BANLIST_ITEM) + 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 ~RsBanListItem(){} virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); RsTlvBanList peerList; }; @@ -64,40 +62,22 @@ public: :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM) {} virtual ~RsBanListConfigItem(){} - virtual void clear(); + virtual void clear() { banned_peers.TlvClear() ; } - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); uint32_t type ; RsPeerId peerId ; - time_t update_time ; + time_t update_time ; RsTlvBanList banned_peers; }; -class RsBanListSerialiser: public RsSerialType +class RsBanListSerialiser: public RsSerializer { public: - RsBanListSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST) - { return; } - virtual ~RsBanListSerialiser() - { 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 sizeList(RsBanListItem *); - virtual bool serialiseList (RsBanListItem *item, void *data, uint32_t *size); - virtual RsBanListItem *deserialiseList(void *data, uint32_t *size); - - virtual uint32_t sizeListConfig(RsBanListConfigItem *); - virtual bool serialiseListConfig (RsBanListConfigItem *item, void *data, uint32_t *size); - virtual RsBanListConfigItem *deserialiseListConfig(void *data, uint32_t *size); - + RsBanListSerialiser() :RsSerializer(RS_SERVICE_TYPE_BANLIST) {} + virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) ; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rsbaseserial.cc b/libretroshare/src/serialiser/rsbaseserial.cc index 2ef67cd5b..44bd249d1 100644 --- a/libretroshare/src/serialiser/rsbaseserial.cc +++ b/libretroshare/src/serialiser/rsbaseserial.cc @@ -35,7 +35,7 @@ /* UInt8 get/set */ -bool getRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t *out) +bool getRawUInt8(const void *data, uint32_t size, uint32_t *offset, uint8_t *out) { /* first check there is space */ if (size < *offset + 1) @@ -71,7 +71,7 @@ bool setRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t in) } /* UInt16 get/set */ -bool getRawUInt16(void *data, uint32_t size, uint32_t *offset, uint16_t *out) +bool getRawUInt16(const void *data, uint32_t size, uint32_t *offset, uint16_t *out) { /* first check there is space */ if (size < *offset + 2) @@ -113,7 +113,7 @@ bool setRawUInt16(void *data, uint32_t size, uint32_t *offset, uint16_t in) /* UInt32 get/set */ -bool getRawUInt32(void *data, uint32_t size, uint32_t *offset, uint32_t *out) +bool getRawUInt32(const void *data, uint32_t size, uint32_t *offset, uint32_t *out) { /* first check there is space */ if (size < *offset + 4) @@ -155,7 +155,7 @@ bool setRawUInt32(void *data, uint32_t size, uint32_t *offset, uint32_t in) /* UInt64 get/set */ -bool getRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t *out) +bool getRawUInt64(const void *data, uint32_t size, uint32_t *offset, uint64_t *out) { /* first check there is space */ if (size < *offset + 8) @@ -195,7 +195,7 @@ bool setRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t in) return true; } -bool getRawUFloat32(void *data,uint32_t size,uint32_t *offset,float& f) +bool getRawUFloat32(const void *data, uint32_t size, uint32_t *offset, float& f) { uint32_t n ; if(!getRawUInt32(data, size, offset, &n) ) @@ -208,6 +208,13 @@ bool getRawUFloat32(void *data,uint32_t size,uint32_t *offset,float& f) bool setRawUFloat32(void *data,uint32_t size,uint32_t *offset,float f) { + uint32_t sz = 4; + + if ( !data || size <= *offset || size < sz + *offset ) + { + std::cerr << "(EE) not enough room. SIZE+offset=" << sz+*offset << " and size is only " << size << std::endl; + return false; + } if(f < 0.0f) { std::cerr << "(EE) Cannot serialise invalid negative float value " << f << " in " << __PRETTY_FUNCTION__ << std::endl; @@ -229,7 +236,7 @@ uint32_t getRawStringSize(const std::string &outStr) return outStr.length() + 4; } -bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr) +bool getRawString(const void *data, uint32_t size, uint32_t *offset, std::string &outStr) { #warning Gio: "I had to change this. It seems like a bug to not clear the string. Should make sure it's not introducing any side effect." outStr.clear(); @@ -284,7 +291,7 @@ bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string return true; } -bool getRawTimeT(void *data,uint32_t size,uint32_t *offset,time_t& t) +bool getRawTimeT(const void *data,uint32_t size,uint32_t *offset,time_t& t) { uint64_t T ; bool res = getRawUInt64(data,size,offset,&T) ; @@ -292,7 +299,7 @@ bool getRawTimeT(void *data,uint32_t size,uint32_t *offset,time_t& t) return res ; } -bool setRawTimeT(void *data,uint32_t size,uint32_t *offset,const time_t& t) +bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const time_t& t) { return setRawUInt64(data,size,offset,t) ; } diff --git a/libretroshare/src/serialiser/rsbaseserial.h b/libretroshare/src/serialiser/rsbaseserial.h index 25e0f57cc..650fc9e6d 100644 --- a/libretroshare/src/serialiser/rsbaseserial.h +++ b/libretroshare/src/serialiser/rsbaseserial.h @@ -48,27 +48,27 @@ * ******************************************************************/ -bool getRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t *out); +bool getRawUInt8(const void *data, uint32_t size, uint32_t *offset, uint8_t *out); bool setRawUInt8(void *data, uint32_t size, uint32_t *offset, uint8_t in); -bool getRawUInt16(void *data, uint32_t size, uint32_t *offset, uint16_t *out); +bool getRawUInt16(const void *data, uint32_t size, uint32_t *offset, uint16_t *out); bool setRawUInt16(void *data, uint32_t size, uint32_t *offset, uint16_t in); -bool getRawUInt32(void *data, uint32_t size, uint32_t *offset, uint32_t *out); +bool getRawUInt32(const void *data, uint32_t size, uint32_t *offset, uint32_t *out); bool setRawUInt32(void *data, uint32_t size, uint32_t *offset, uint32_t in); -bool getRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t *out); +bool getRawUInt64(const void *data, uint32_t size, uint32_t *offset, uint64_t *out); bool setRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t in); -bool getRawUFloat32(void *data, uint32_t size, uint32_t *offset, float& out); +bool getRawUFloat32(const void *data, uint32_t size, uint32_t *offset, float& out); bool setRawUFloat32(void *data, uint32_t size, uint32_t *offset, float in); uint32_t getRawStringSize(const std::string &outStr); -bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr); +bool getRawString(const void *data, uint32_t size, uint32_t *offset, std::string &outStr); bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string &inStr); +bool getRawTimeT(const void *data, uint32_t size, uint32_t *offset, time_t& outStr); bool setRawTimeT(void *data, uint32_t size, uint32_t *offset, const time_t& inStr); -bool getRawTimeT(void *data, uint32_t size, uint32_t *offset, time_t& outStr); #endif diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 722eec9ec..21e0fcec7 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -84,7 +84,12 @@ class RsItem: public RsMemoryManagement::SmallObject virtual ~RsItem(); virtual void clear() = 0; - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0; + virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) + { + std::cerr << "(EE) RsItem::print() called by an item using new serialization classes, but not derived! " << std::endl; +#warning This method should normally call serial_process(PRINT,ctx) + return out; + } void print_string(std::string &out, uint16_t indent = 0); /* source / destination id */ diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 878ec3e6b..349689c0b 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -2,6 +2,7 @@ #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" +#include "serialiser/rstlvlist.h" #include "retroshare/rsflags.h" #include "retroshare/rsids.h" @@ -183,6 +184,11 @@ class RsTypeSerializer template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member); template static uint32_t serial_size(const t_RsGenericIdType& /* member */); template static void print_data(const std::string& name,const t_RsGenericIdType& /* member */); + + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsTlvList& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsTlvList& member); + template static uint32_t serial_size(const t_RsTlvList& /* member */); + template static void print_data(const std::string& name,const t_RsTlvList& /* member */); }; //=================================================================================================// @@ -208,7 +214,35 @@ uint32_t RsTypeSerializer::serial_size(const t_RsGenericIdType -void RsTypeSerializer::print_data(const std::string& name,const t_RsGenericIdType& member) +void RsTypeSerializer::print_data(const std::string& /* name */,const t_RsGenericIdType& member) { std::cerr << " [RsGenericId<" << std::hex << UNIQUE_IDENTIFIER << ">] : " << member << std::endl; } + +//=================================================================================================// +// t_RsTlvList<> // +//=================================================================================================// + +template +bool RsTypeSerializer::serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsTlvList& member) +{ + return (*const_cast *>(&member)).SetTlv(data,size,&offset) ; +} + +template +bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsTlvList& member) +{ + return member.GetTlv(const_cast(data),size,&offset) ; +} + +template +uint32_t RsTypeSerializer::serial_size(const t_RsTlvList& member) +{ + return member.TlvSize(); +} + +template +void RsTypeSerializer::print_data(const std::string& /* name */,const t_RsTlvList& member) +{ + std::cerr << " [t_RsTlvString<" << std::hex << TLV_TYPE << ">] : size=" << member.mList.size() << std::endl; +} From 80e8769ed7cfe068533695ebab52bf9e92574f6d Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 11 Apr 2017 21:37:35 +0200 Subject: [PATCH 021/106] added missign file and converted BW control items --- libretroshare/src/serialiser/rsbwctrlitems.cc | 34 +-- libretroshare/src/serialiser/rsbwctrlitems.h | 44 ++- .../src/serialization/rstypeserializer.cc | 254 ++++++++++++++++++ 3 files changed, 284 insertions(+), 48 deletions(-) create mode 100644 libretroshare/src/serialization/rstypeserializer.cc diff --git a/libretroshare/src/serialiser/rsbwctrlitems.cc b/libretroshare/src/serialiser/rsbwctrlitems.cc index fbd314bb2..bd1f0341e 100644 --- a/libretroshare/src/serialiser/rsbwctrlitems.cc +++ b/libretroshare/src/serialiser/rsbwctrlitems.cc @@ -34,9 +34,17 @@ /*************************************************************************/ -RsBwCtrlAllowedItem::~RsBwCtrlAllowedItem() +RsItem *RsBwCtrlSerialiser::create_item(uint16_t service, uint8_t item_sub_id) { - return; + 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() @@ -44,27 +52,12 @@ void RsBwCtrlAllowedItem::clear() allowedBw = 0; } -std::ostream &RsBwCtrlAllowedItem::print(std::ostream &out, uint16_t indent) +void RsBwCtrlAllowedItem::serial_process(SerializeJob j,SerializeContext& ctx) { - printRsItemBase(out, "RsBwCtrlAllowedItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "AllowedBw: " << allowedBw; - out << std::endl; - - printRsItemEnd(out, "RsBwCtrlAllowedItem", indent); - return out; -} - - -uint32_t RsBwCtrlSerialiser::sizeAllowed(RsBwCtrlAllowedItem * /*item*/) -{ - uint32_t s = 8; /* header */ - s += GetTlvUInt32Size(); - - return s; + RsTypeSerializer::serial_process(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) { @@ -200,6 +193,7 @@ RsItem *RsBwCtrlSerialiser::deserialise(void *data, uint32_t *pktsize) } /*************************************************************************/ +#endif diff --git a/libretroshare/src/serialiser/rsbwctrlitems.h b/libretroshare/src/serialiser/rsbwctrlitems.h index c1679c9c9..8b5cc8299 100644 --- a/libretroshare/src/serialiser/rsbwctrlitems.h +++ b/libretroshare/src/serialiser/rsbwctrlitems.h @@ -32,50 +32,38 @@ #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) - { +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; + return; } -virtual ~RsBwCtrlAllowedItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsBwCtrlAllowedItem() {} + virtual void clear(); - uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; + void serial_process(SerializeJob j,SerializeContext& ctx); + uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; }; -class RsBwCtrlSerialiser: public RsSerialType +class RsBwCtrlSerialiser: public RsSerializer { - public: - RsBwCtrlSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BWCTRL) - { return; } -virtual ~RsBwCtrlSerialiser() - { 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 sizeAllowed(RsBwCtrlAllowedItem *); -virtual bool serialiseAllowed (RsBwCtrlAllowedItem *item, void *data, uint32_t *size); -virtual RsBwCtrlAllowedItem *deserialiseAllowed(void *data, uint32_t *size); - +public: + RsBwCtrlSerialiser() :RsSerializer(RS_SERVICE_TYPE_BWCTRL) {} + virtual ~RsBwCtrlSerialiser() {} + RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */); }; /**************************************************************************/ diff --git a/libretroshare/src/serialization/rstypeserializer.cc b/libretroshare/src/serialization/rstypeserializer.cc new file mode 100644 index 000000000..fc9563fe6 --- /dev/null +++ b/libretroshare/src/serialization/rstypeserializer.cc @@ -0,0 +1,254 @@ +#include "serialization/rsserializer.h" +#include "serialization/rstypeserializer.h" + +#include "serialiser/rsbaseserial.h" +#include "serialiser/rstlvkeys.h" + +#include "util/rsprint.h" + +#include + +static const uint32_t MAX_SERIALIZED_ARRAY_SIZE = 500 ; + +#ifdef REMOVE +template T ntoh(T t) +{ + if(sizeof(T) == 8) return t; + if(sizeof(T) == 4) return ntohl(t) ; + if(sizeof(T) == 2) return ntohs(t) ; + if(sizeof(T) == 1) return t ; + + std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in ntoh<>" << std::endl; + return t; +} +template T hton(T t) +{ + if(sizeof(T) == 8) return t; + if(sizeof(T) == 4) return htonl(t) ; + if(sizeof(T) == 2) return htons(t) ; + if(sizeof(T) == 1) return t ; + + std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in hton<>" << std::endl; + return t; +} +#endif + +//=================================================================================================// +// Integer types // +//=================================================================================================// + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) +{ + return setRawUInt8(data,size,&offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) +{ + return setRawUInt32(data,size,&offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint64_t& member) +{ + return setRawUInt64(data,size,&offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const time_t& member) +{ + return setRawTimeT(data,size,&offset,member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member) +{ + return getRawUInt8(data,size,&offset,&member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) +{ + return getRawUInt32(data,size,&offset,&member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint64_t& member) +{ + return getRawUInt64(data,size,&offset,&member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, time_t& member) +{ + return getRawTimeT(data,size,&offset,member); +} +template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& /* member*/) +{ + return 1; +} +template<> uint32_t RsTypeSerializer::serial_size(const uint32_t& /* member*/) +{ + return 4; +} +template<> uint32_t RsTypeSerializer::serial_size(const uint64_t& /* member*/) +{ + return 8; +} +template<> uint32_t RsTypeSerializer::serial_size(const time_t& /* member*/) +{ + return 8; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, const uint8_t & V) +{ + std::cerr << " [uint8_t ] " << n << ": " << V << std::endl; +} +template<> void RsTypeSerializer::print_data(const std::string& n, const uint16_t& V) +{ + std::cerr << " [uint16_t ] " << n << ": " << V << std::endl; +} +template<> void RsTypeSerializer::print_data(const std::string& n, const uint32_t& V) +{ + std::cerr << " [uint32_t ] " << n << ": " << V << std::endl; +} +template<> void RsTypeSerializer::print_data(const std::string& n, const uint64_t& V) +{ + std::cerr << " [uint64_t ] " << n << ": " << V << std::endl; +} +template<> void RsTypeSerializer::print_data(const std::string& n, const time_t& V) +{ + std::cerr << " [time_t ] " << n << ": " << V << " (" << time(NULL)-V << " secs ago)" << std::endl; +} + + +//=================================================================================================// +// FLoats // +//=================================================================================================// + +template<> uint32_t RsTypeSerializer::serial_size(const float&){ return 4; } + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t& offset, const float& f) +{ + return setRawUFloat32(data,size,&offset,f) ; +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, float& f) +{ + return getRawUFloat32(data,size,&offset,f) ; +} +template<> void RsTypeSerializer::print_data(const std::string& n, const float& V) +{ + std::cerr << " [float ] " << n << ": " << V << std::endl; +} + + +//=================================================================================================// +// TlvString with subtype // +//=================================================================================================// + +template<> uint32_t RsTypeSerializer::serial_size(uint16_t /* type_subtype */,const std::string& s) +{ + return GetTlvStringSize(s) ; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,uint16_t type_substring,const std::string& s) +{ + return SetTlvString(data,size,&offset,type_substring,s) ; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,uint16_t type_substring,std::string& s) +{ + return GetTlvString((void*)data,size,&offset,type_substring,s) ; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, uint16_t type_substring,const std::string& V) +{ + std::cerr << " [TlvString ] " << n << ": type=" << std::hex < uint32_t RsTypeSerializer::serial_size(uint16_t /* type_subtype */,const uint32_t& s) +{ + return GetTlvUInt32Size() ; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,uint16_t sub_type,const uint32_t& s) +{ + return SetTlvUInt32(data,size,&offset,sub_type,s) ; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,uint16_t sub_type,uint32_t& s) +{ + return GetTlvUInt32((void*)data,size,&offset,sub_type,&s) ; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, uint16_t sub_type,const uint32_t& V) +{ + std::cerr << " [TlvUInt32 ] " << n << ": type=" << std::hex < void RsTypeSerializer::print_data(const std::string& n, const std::string& V) +{ + std::cerr << " [std::string] " << n << ": " << V << std::endl; +} + +//=================================================================================================// +// Binary blocks // +//=================================================================================================// + +template<> uint32_t RsTypeSerializer::serial_size(const RsTypeSerializer::TlvMemBlock_proxy& r) { return 4 + r.second ; } + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,RsTypeSerializer::TlvMemBlock_proxy& r) +{ + uint32_t saved_offset = offset ; + + bool ok = deserialize(data,size,offset,r.second) ; + + r.first = (uint8_t*)rs_malloc(r.second) ; + + ok = ok && NULL != r.first; + + memcpy(r.first,&data[offset],r.second) ; + + if(!ok) + offset = saved_offset ; + + return ok; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const RsTypeSerializer::TlvMemBlock_proxy& r) +{ + uint32_t saved_offset = offset ; + + bool ok = serialize(data,size,offset,r.second) ; + + memcpy(&data[offset],r.first,r.second) ; + + if(!ok) + offset = saved_offset ; + + return ok; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, const RsTypeSerializer::TlvMemBlock_proxy& s) +{ + std::cerr << " [Binary data] " << n << ", length=" << s.second << " data=" << RsUtil::BinToHex(s.first,std::min(50u,s.second)) << ((s.second>50)?"...":"") << std::endl; +} + +//=================================================================================================// +// Signatures // +//=================================================================================================// + +template<> uint32_t RsTypeSerializer::serial_size(const RsTlvKeySignature& s) +{ + return s.TlvSize() ; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const RsTlvKeySignature& s) +{ + return s.SetTlv(data,size,&offset) ; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,RsTlvKeySignature& s) +{ + return s.GetTlv((void*)data,size,&offset) ; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, const RsTlvKeySignature& s) +{ + std::cerr << " [Signature] " << n << " : key_id=" << s.keyId << ", length=" << s.signData.bin_len << std::endl; +} From 3453a3e57dcddcd514a1be031cfd37a76a993790 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 11 Apr 2017 23:05:27 +0200 Subject: [PATCH 022/106] switched FileTransfer items to new serialization --- libretroshare/src/chat/rschatitems.cc | 2 +- .../src/serialiser/rsfiletransferitems.cc | 765 ++---------------- .../src/serialiser/rsfiletransferitems.h | 103 +-- libretroshare/src/serialiser/rstlvfileitem.h | 2 +- .../src/serialization/rstypeserializer.cc | 60 +- 5 files changed, 110 insertions(+), 822 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index a430b1119..88e7abe8a 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -87,7 +87,7 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,nick,"nick") ; if(include_signature) - RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; + RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) diff --git a/libretroshare/src/serialiser/rsfiletransferitems.cc b/libretroshare/src/serialiser/rsfiletransferitems.cc index 0caabc2f8..0be0412b7 100644 --- a/libretroshare/src/serialiser/rsfiletransferitems.cc +++ b/libretroshare/src/serialiser/rsfiletransferitems.cc @@ -28,6 +28,8 @@ #include "serialiser/rstlvbase.h" #include "serialiser/rsfiletransferitems.h" +#include "serialization/rstypeserializer.h" + /*** * #define RSSERIAL_DEBUG 1 * #define DEBUG_TRANSFERS 1 @@ -40,758 +42,115 @@ #include -/**********************************************************************************************/ -/* SERIALISER STUFF */ -/**********************************************************************************************/ - -RsFileTransferItem *RsFileTransferSerialiser::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_FILE_TRANSFER != getRsItemService(rstype)) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_FT_CACHE_ITEM: return deserialise_RsFileTransferCacheItem(data, *pktsize); - case RS_PKT_SUBTYPE_FT_DATA_REQUEST: return deserialise_RsFileTransferDataRequestItem(data, *pktsize); - case RS_PKT_SUBTYPE_FT_DATA: return deserialise_RsFileTransferDataItem(data, *pktsize); - case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST: return deserialise_RsFileTransferChunkMapRequestItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_FT_CHUNK_MAP: return deserialise_RsFileTransferChunkMapItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: return deserialise_RsFileTransferSingleChunkCrcRequestItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_FT_CHUNK_CRC: return deserialise_RsFileTransferSingleChunkCrcItem(data,*pktsize) ; - default: - std::cerr << "RsFileTransferSerialiser::deserialise(): Could not de-serialise item. SubPacket id = " << std::hex << getRsItemSubType(rstype) << " id = " << rstype << std::dec << std::endl; - return NULL; - } - return NULL; -} - -/**********************************************************************************************/ -/* OUTPUTS */ -/**********************************************************************************************/ - -std::ostream& RsFileTransferCacheItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferCacheItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "CacheId: " << cacheType << "/" << cacheSubId << std::endl; - file.print(out, int_Indent); - printRsItemEnd(out, "RsFileTransferCacheItem", indent); - return out; -} -std::ostream& RsFileTransferDataRequestItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferDataRequestItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "FileOffset: " << fileoffset; - out << " ChunkSize: " << chunksize << std::endl; - file.print(out, int_Indent); - printRsItemEnd(out, "RsFileTransferDataRequestItem", indent); - return out; -} -std::ostream& RsFileTransferChunkMapItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferChunkMapItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); out << "PeerId: " << PeerId() << std::endl ; - printIndent(out, int_Indent); out << " hash: " << hash << std::endl ; - printIndent(out, int_Indent); out << "chunks: " << std::hex << compressed_map._map[0] << std::dec << "..." << std::endl ; - printRsItemEnd(out, "RsFileTransferChunkMapItem", indent); - return out; -} -std::ostream& RsFileTransferChunkMapRequestItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferChunkMapRequestItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); out << "PeerId: " << PeerId() << std::endl ; - printIndent(out, int_Indent); out << " hash: " << hash << std::endl ; - printRsItemEnd(out, "RsFileTransferChunkMapRequestItem", indent); - return out; -} -std::ostream& RsFileTransferSingleChunkCrcRequestItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferSingleChunkCrcRequestItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); out << "PeerId: " << PeerId() << std::endl ; - printIndent(out, int_Indent); out << " hash: " << hash << std::endl ; - printIndent(out, int_Indent); out << " chunk: " << chunk_number << "..." << std::endl ; - printRsItemEnd(out, "RsFileTransferSingleChunkCrcRequestItem", indent); - return out; -} -std::ostream& RsFileTransferSingleChunkCrcItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferSingleChunkCrcItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); out << "PeerId: " << PeerId() << std::endl ; - printIndent(out, int_Indent); out << " hash: " << hash << std::endl ; - printIndent(out, int_Indent); out << " chunk: " << chunk_number << "..." << std::endl ; - printIndent(out, int_Indent); out << " sha1: " << check_sum.toStdString() << "..." << std::endl ; - printRsItemEnd(out, "RsFileTransferSingleChunkCrcItem", indent); - return out; -} -std::ostream& RsFileTransferDataItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransferDataItem", indent); - uint16_t int_Indent = indent + 2; - fd.print(out, int_Indent); - printRsItemEnd(out, "RsFileTransferDataItem", indent); - return out; -} - -/**********************************************************************************************/ -/* SERIAL SIZE */ -/**********************************************************************************************/ - -uint32_t RsFileTransferDataRequestItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 8; /* offset */ - s += 4; /* chunksize */ - s += file.TlvSize(); - - return s; -} -uint32_t RsFileTransferCacheItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 4; /* type/subid */ - s += file.TlvSize(); - - return s; -} -uint32_t RsFileTransferDataItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += fd.TlvSize(); - - return s; -} -uint32_t RsFileTransferChunkMapRequestItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 1 ; // is_client - s += hash.serial_size() ; // hash - - return s; -} -uint32_t RsFileTransferChunkMapItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += 1 ; // is_client - s += hash.serial_size() ; // hash - s += 4 ; // compressed map size - s += 4 * compressed_map._map.size() ; // compressed chunk map - - return s; -} -uint32_t RsFileTransferSingleChunkCrcItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += hash.serial_size() ; // hash - s += 4 ; // chunk number - s += check_sum.serial_size() ; // sha1 - - return s; -} -uint32_t RsFileTransferSingleChunkCrcRequestItem::serial_size() -{ - uint32_t s = 8; /* header */ - s += hash.serial_size() ; // hash - s += 4 ; // chunk number - - return s; -} - -/*************************************************************************/ - void RsFileTransferDataRequestItem::clear() { file.TlvClear(); fileoffset = 0; chunksize = 0; } -void RsFileTransferCacheItem::clear() -{ - cacheType = 0; - cacheSubId = 0; - file.TlvClear(); -} void RsFileTransferDataItem::clear() { fd.TlvClear(); } -/**********************************************************************************************/ -/* SERIALISATION */ -/**********************************************************************************************/ - -bool RsFileTransferItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) +void RsFileTransferDataRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; + RsTypeSerializer::serial_process (j,ctx,fileoffset,"fileoffset") ; + RsTypeSerializer::serial_process (j,ctx,chunksize, "chunksize") ; + RsTypeSerializer::serial_process(j,ctx,file, "file") ; } -/* serialise the data to the buffer */ -bool RsFileTransferChunkMapRequestItem::serialise(void *data, uint32_t& pktsize) +void RsFileTransferDataItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt8(data, tlvsize, &offset, is_client); - ok &= hash.serialise(data, tlvsize, offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl; - } - - return ok; -} -bool RsFileTransferSingleChunkCrcRequestItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= hash.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, chunk_number) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl; - } - - return ok; -} -bool RsFileTransferSingleChunkCrcItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= hash.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, chunk_number) ; - - ok &= check_sum.serialise(data,tlvsize,offset) ; - - //ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[0]) ; - //ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[1]) ; - //ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[2]) ; - //ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[3]) ; - //ok &= setRawUInt32(data, tlvsize, &offset, check_sum.fourbytes[4]) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl; - } - - return ok; -} -bool RsFileTransferChunkMapItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt8(data, tlvsize, &offset, is_client); - ok &= hash.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, compressed_map._map.size()); - - for(uint32_t i=0;i(j,ctx,fd,"fd") ; } -/* serialise the data to the buffer */ -bool RsFileTransferDataItem::serialise(void *data, uint32_t& pktsize) +void RsFileTransferChunkMapRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= fd.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsFileItemSerialiser::serialiseData() Size Error! " << std::endl; - } - -#ifdef DEBUG_TRANSFERS - std::cerr << "RsFileItemSerialiser::serialiseData() at: " << RsUtil::AccurateTimeString() << std::endl; - print(std::cerr, 10); -#endif - - return ok; + RsTypeSerializer::serial_process (j,ctx,is_client,"is_client") ; + RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; } -/* serialise the data to the buffer */ -bool RsFileTransferDataRequestItem::serialise(void *data, uint32_t& pktsize) +void RsFileTransferChunkMapItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, fileoffset); - ok &= setRawUInt32(data, tlvsize, &offset, chunksize); - ok &= file.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsFileTransferDataRequestItem::serialise() Size Error! " << std::endl; - } - - /*** Debugging Transfer rates. - * print timestamp, and file details so we can workout packet lags. - ***/ - -#ifdef DEBUG_TRANSFERS - std::cerr << "RsFileTransferDataRequestItem::serialise() at: " << RsUtil::AccurateTimeString() << std::endl; - print(std::cerr, 10); -#endif - - return ok; + RsTypeSerializer::serial_process (j,ctx,is_client, "is_client") ; + RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; + RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ; } -/* serialise the data to the buffer */ -bool RsFileTransferCacheItem::serialise(void *data, uint32_t& pktsize) +void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt16(data, tlvsize, &offset, cacheType); - ok &= setRawUInt16(data, tlvsize, &offset, cacheSubId); - ok &= file.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseItem() Size Error! " << std::endl; -#endif - } - - return ok; + RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; + RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; } -/**********************************************************************************************/ -/* DESERIALISATION */ -/**********************************************************************************************/ - -RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferCacheItem(void *data, uint32_t pktsize) +void RsFileTransferSingleChunkCrcItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if(RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_CACHE_ITEM != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferCacheItem(): wong subtype!" << std::endl; - return NULL; /* wrong type */ - } - - if (pktsize < rssize) /* check size */ - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferCacheItem(): size inconsistency!" << std::endl; - return NULL; /* not enough data */ - } - - bool ok = true; - - /* ready to load */ - RsFileTransferCacheItem *item = new RsFileTransferCacheItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt16(data, rssize, &offset, &(item->cacheType)); - ok &= getRawUInt16(data, rssize, &offset, &(item->cacheSubId)); - ok &= item->file.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; + RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; + RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; + RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ; } -RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferChunkMapRequestItem(void *data, uint32_t pktsize) +//===================================================================================================// +// CompressedChunkMap // +//===================================================================================================// + +template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if(RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferChunkMapRequestItem(): wong subtype!" << std::endl; - return NULL; /* wrong type */ - } - - if (pktsize < rssize) /* check size */ - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferChunkMapRequestItem(): size inconsistency!" << std::endl; - return NULL; /* not enough data */ - } - - bool ok = true; - - /* ready to load */ - RsFileTransferChunkMapRequestItem *item = new RsFileTransferChunkMapRequestItem(); - item->clear(); - - /* skip the header */ - offset += 8; - uint8_t tmp ; - ok &= getRawUInt8(data, rssize, &offset, &tmp); item->is_client = tmp; - ok &= item->hash.deserialise(data, rssize, offset) ; // File hash - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; + return 4 + 4*s._map.size() ; } -RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferDataItem(void *data, uint32_t pktsize) +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); + bool ok = true ; - uint32_t offset = 0; + ok &= setRawUInt32(data, size, &offset, s._map.size()); - if(RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_DATA != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferDataItem(): wong subtype!" << std::endl; - return NULL; /* wrong type */ - } + for(uint32_t i=0;iclear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->fd.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - -#ifdef DEBUG_TRANSFERS - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferDataItem() at: " << RsUtil::AccurateTimeString() << std::endl; - item->print(std::cerr, 10); -#endif - - return item; + return ok; } - -RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferDataRequestItem(void *data, uint32_t pktsize) +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if (RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_DATA_REQUEST != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferDataRequestItem(): wrong subtype!" << std::endl; - return NULL; /* wrong type */ - } - - if (pktsize < rssize) /* check size */ - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferDataRequestItem(): size inconsistency!" << std::endl; - return NULL; /* not enough data */ - } - - RsFileTransferDataRequestItem *item = new RsFileTransferDataRequestItem() ; - - bool ok = true; - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt64(data, rssize, &offset, &item->fileoffset); - ok &= getRawUInt32(data, rssize, &offset, &item->chunksize); - ok &= item->file.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - /*** Debugging Transfer rates. - * print timestamp, and file details so we can workout packet lags. - ***/ - -#ifdef DEBUG_TRANSFERS - std::cerr << "RsFileItemSerialiser::deserialise_RsFileTransferDataRequestItem() at: " << RsUtil::AccurateTimeString() << std::endl; - item->print(std::cerr, 10); -#endif - - return item; -} -RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferChunkMapItem(void *data, uint32_t pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if (RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_CHUNK_MAP != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferChunkMapItem(): wrong subtype!" << std::endl; - return NULL; /* wrong type */ - } - - if (pktsize < rssize) /* check size */ - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferChunkMapItem(): size inconsistency!" << std::endl; - return NULL; /* not enough data */ - } - - bool ok = true; - - /* ready to load */ - RsFileTransferChunkMapItem *item = new RsFileTransferChunkMapItem(); - item->clear(); - - /* skip the header */ - offset += 8; - uint8_t tmp ; - ok &= getRawUInt8(data, rssize, &offset, &tmp); item->is_client = tmp; - ok &= item->hash.deserialise(data, rssize, offset) ; // File hash - uint32_t size =0; - ok &= getRawUInt32(data, rssize, &offset, &size); + uint32_t S =0; + bool ok = getRawUInt32(data, size, &offset, &S); if(ok) { - item->compressed_map._map.resize(size) ; + s._map.resize(S) ; - for(uint32_t i=0;icompressed_map._map[i])); + for(uint32_t i=0;i void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if (RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferSingleChunkCrcRequestItem(): wrong subtype!" << std::endl; - return NULL; /* wrong type */ - } - - if (pktsize < rssize) /* check size */ - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferSingleChunkCrcRequestItem(): size inconsistency!" << std::endl; - return NULL; /* not enough data */ - } - - bool ok = true; - - /* ready to load */ - RsFileTransferSingleChunkCrcRequestItem *item = new RsFileTransferSingleChunkCrcRequestItem(); - item->clear(); - - /* skip the header */ - offset += 8; - ok &= item->hash.deserialise(data, rssize, offset) ; - ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_number)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; + std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl; } -RsFileTransferItem *RsFileTransferSerialiser::deserialise_RsFileTransferSingleChunkCrcItem(void *data, uint32_t pktsize) + +//===================================================================================================// +// Serializer // +//===================================================================================================// + +RsItem *RsFileTransferSerialiser::create_item(uint16_t service_type,uint8_t item_type) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); + if(service_type != RS_SERVICE_TYPE_FILE_TRANSFER) + return NULL ; - uint32_t offset = 0; - - if (RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_FILE_TRANSFER != getRsItemType(rstype) || RS_PKT_SUBTYPE_FT_CHUNK_CRC != getRsItemSubType(rstype)) - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferSingleChunkCrcItem(): wrong subtype!" << std::endl; - return NULL; /* wrong type */ - } - - if (pktsize < rssize) /* check size */ - { - std::cerr << "RsFileTransferSerialiser::deserialise_RsFileTransferSingleChunkCrcItem(): size inconsistency!" << std::endl; - return NULL; /* not enough data */ - } - - bool ok = true; - - /* ready to load */ - RsFileTransferSingleChunkCrcItem *item = new RsFileTransferSingleChunkCrcItem(); - item->clear(); - - /* skip the header */ - offset += 8; - ok &= item->hash.deserialise(data, rssize, offset) ; - ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_number)); - ok &= item->check_sum.deserialise(data,rssize,offset) ; - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; + 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 ; + } } -/*************************************************************************/ diff --git a/libretroshare/src/serialiser/rsfiletransferitems.h b/libretroshare/src/serialiser/rsfiletransferitems.h index fa989861d..50b3c2a26 100644 --- a/libretroshare/src/serialiser/rsfiletransferitems.h +++ b/libretroshare/src/serialiser/rsfiletransferitems.h @@ -29,10 +29,10 @@ #include "retroshare/rstypes.h" #include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvfileitem.h" #include "serialiser/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; @@ -53,20 +53,11 @@ const uint8_t RS_PKT_SUBTYPE_FT_CACHE_REQUEST = 0x0B; class RsFileTransferItem: public RsItem { public: - RsFileTransferItem(uint8_t ft_subtype) - : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_FILE_TRANSFER,ft_subtype) - {} + RsFileTransferItem(uint8_t ft_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_FILE_TRANSFER,ft_subtype) {} virtual ~RsFileTransferItem() {} - virtual bool serialise(void *data,uint32_t& size) = 0 ; - virtual uint32_t serial_size() = 0 ; - - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0; virtual void clear() = 0 ; - - protected: - bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) ; }; class RsFileTransferDataRequestItem: public RsFileTransferItem @@ -77,13 +68,9 @@ class RsFileTransferDataRequestItem: public RsFileTransferItem setPriorityLevel(QOS_PRIORITY_RS_FILE_REQUEST) ; } virtual ~RsFileTransferDataRequestItem() {} - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); // Private data part. // @@ -103,11 +90,9 @@ class RsFileTransferDataItem: public RsFileTransferItem } virtual ~RsFileTransferDataItem() { clear() ; } - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - virtual void clear(); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual void clear(); // Private data part. // @@ -122,10 +107,9 @@ class RsFileTransferChunkMapRequestItem: public RsFileTransferItem setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP_REQUEST) ; } virtual ~RsFileTransferChunkMapRequestItem() {} - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); // Private data part. // @@ -142,11 +126,9 @@ class RsFileTransferChunkMapItem: public RsFileTransferItem setPriorityLevel(QOS_PRIORITY_RS_FILE_MAP) ; } virtual ~RsFileTransferChunkMapItem() {} - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void clear() {} // Private data part. // @@ -163,11 +145,9 @@ class RsFileTransferSingleChunkCrcRequestItem: public RsFileTransferItem setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC_REQUEST) ; } virtual ~RsFileTransferSingleChunkCrcRequestItem() {} - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void clear() {} // Private data part. // @@ -183,11 +163,9 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC) ; } virtual ~RsFileTransferSingleChunkCrcItem() {} - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void clear() {} // Private data part. // @@ -196,65 +174,16 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem Sha1CheckSum check_sum ; // CRC32 map of the file. }; -class RsFileTransferCacheItem: public RsFileTransferItem -{ - public: - RsFileTransferCacheItem() :RsFileTransferItem(RS_PKT_SUBTYPE_FT_CACHE_ITEM) - { - setPriorityLevel(QOS_PRIORITY_RS_CACHE_ITEM); - } - - virtual ~RsFileTransferCacheItem(){ clear() ; } - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - // private part. - // - uint16_t cacheType; - uint16_t cacheSubId; - RsTlvFileItem file; /* file information */ -}; - - /**************************************************************************/ -class RsFileTransferSerialiser: public RsSerialType +class RsFileTransferSerialiser: public RsSerializer { public: - RsFileTransferSerialiser(): RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_FILE_TRANSFER) {} + RsFileTransferSerialiser(): RsSerializer(RS_SERVICE_TYPE_FILE_TRANSFER) {} virtual ~RsFileTransferSerialiser() {} - virtual uint32_t size(RsItem *item) - { - RsFileTransferItem *ftitem = dynamic_cast(item); - if (!ftitem) - { - return 0; - } - return ftitem->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - RsFileTransferItem *ftitem = dynamic_cast(item); - if (!ftitem) - { - return false; - } - return ftitem->serialise(data,*size) ; - } - virtual RsFileTransferItem *deserialise(void *data, uint32_t *size); - - private: - RsFileTransferItem *deserialise_RsFileTransferCacheItem(void *data, uint32_t pktsize); - RsFileTransferItem *deserialise_RsFileTransferChunkMapRequestItem(void *data, uint32_t pktsize); - RsFileTransferItem *deserialise_RsFileTransferChunkMapItem(void *data, uint32_t pktsize); - RsFileTransferItem *deserialise_RsFileTransferDataRequestItem(void *data, uint32_t pktsize); - RsFileTransferItem *deserialise_RsFileTransferDataItem(void *data, uint32_t pktsize); - RsFileTransferItem *deserialise_RsFileTransferSingleChunkCrcItem(void *data, uint32_t pktsize); - RsFileTransferItem *deserialise_RsFileTransferSingleChunkCrcRequestItem(void *data, uint32_t pktsize); + RsItem *create_item(uint16_t service_type,uint8_t item_type) ; }; diff --git a/libretroshare/src/serialiser/rstlvfileitem.h b/libretroshare/src/serialiser/rstlvfileitem.h index 62745b658..1a474e60c 100644 --- a/libretroshare/src/serialiser/rstlvfileitem.h +++ b/libretroshare/src/serialiser/rstlvfileitem.h @@ -42,7 +42,7 @@ virtual ~RsTlvFileItem() { return; } virtual uint32_t TlvSize() const; virtual void TlvClear(); virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const; -virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); +virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); virtual std::ostream &print(std::ostream &out, uint16_t indent) const; uint64_t filesize; /// Mandatory: size of file to be downloaded diff --git a/libretroshare/src/serialization/rstypeserializer.cc b/libretroshare/src/serialization/rstypeserializer.cc index fc9563fe6..5a8def1bd 100644 --- a/libretroshare/src/serialization/rstypeserializer.cc +++ b/libretroshare/src/serialization/rstypeserializer.cc @@ -10,34 +10,15 @@ static const uint32_t MAX_SERIALIZED_ARRAY_SIZE = 500 ; -#ifdef REMOVE -template T ntoh(T t) -{ - if(sizeof(T) == 8) return t; - if(sizeof(T) == 4) return ntohl(t) ; - if(sizeof(T) == 2) return ntohs(t) ; - if(sizeof(T) == 1) return t ; - - std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in ntoh<>" << std::endl; - return t; -} -template T hton(T t) -{ - if(sizeof(T) == 8) return t; - if(sizeof(T) == 4) return htonl(t) ; - if(sizeof(T) == 2) return htons(t) ; - if(sizeof(T) == 1) return t ; - - std::cerr << "(EE) unhandled type of size " << sizeof(T) << " in hton<>" << std::endl; - return t; -} -#endif - //=================================================================================================// // Integer types // //=================================================================================================// -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const bool& member) +{ + return setRawUInt8(data,size,&offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint8_t& member) { return setRawUInt8(data,size,&offset,member); } @@ -53,6 +34,14 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint3 { return setRawTimeT(data,size,&offset,member); } + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, bool& member) +{ + uint8_t m ; + bool ok = getRawUInt8(data,size,&offset,&m); + member = m ; + return ok; +} template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint8_t& member) { return getRawUInt8(data,size,&offset,&member); @@ -69,6 +58,11 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz { return getRawTimeT(data,size,&offset,member); } + +template<> uint32_t RsTypeSerializer::serial_size(const bool& /* member*/) +{ + return 1; +} template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& /* member*/) { return 1; @@ -86,6 +80,10 @@ template<> uint32_t RsTypeSerializer::serial_size(const time_t& /* member*/) return 8; } +template<> void RsTypeSerializer::print_data(const std::string& n, const bool & V) +{ + std::cerr << " [bool ] " << n << ": " << V << std::endl; +} template<> void RsTypeSerializer::print_data(const std::string& n, const uint8_t & V) { std::cerr << " [uint8_t ] " << n << ": " << V << std::endl; @@ -230,25 +228,27 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsTypeS } //=================================================================================================// -// Signatures // +// TlvItems // //=================================================================================================// -template<> uint32_t RsTypeSerializer::serial_size(const RsTlvKeySignature& s) +template<> uint32_t RsTypeSerializer::serial_size(const RsTlvItem& s) { return s.TlvSize() ; } -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const RsTlvKeySignature& s) +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const RsTlvItem& s) { return s.SetTlv(data,size,&offset) ; } -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,RsTlvKeySignature& s) +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,RsTlvItem& s) { return s.GetTlv((void*)data,size,&offset) ; } -template<> void RsTypeSerializer::print_data(const std::string& n, const RsTlvKeySignature& s) +template<> void RsTypeSerializer::print_data(const std::string& n, const RsTlvItem& s) { - std::cerr << " [Signature] " << n << " : key_id=" << s.keyId << ", length=" << s.signData.bin_len << std::endl; + // can we call TlvPrint inside this? + + std::cerr << " [" << typeid(s).name() << "] " << n << std::endl; } From 636450f14dcaf3bd934f659daa320f9b30491702 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 15 Apr 2017 18:46:44 +0200 Subject: [PATCH 023/106] moved turtle and FT to new serialization --- libretroshare/src/ft/ftserver.cc | 32 +-- libretroshare/src/ft/ftserver.h | 4 +- .../src/ft/ftturtlefiletransferitem.cc | 50 ++++ .../src/ft/ftturtlefiletransferitem.h | 49 ++-- libretroshare/src/serialiser/rstlvbase.cc | 4 +- libretroshare/src/serialiser/rstlvbase.h | 2 +- .../src/serialization/rstypeserializer.cc | 18 +- .../src/serialization/rstypeserializer.h | 59 ++++- libretroshare/src/turtle/p3turtle.cc | 20 +- libretroshare/src/turtle/rsturtleitem.cc | 247 +++++++++++++++--- libretroshare/src/turtle/rsturtleitem.h | 91 +++---- .../src/turtle/turtleclientservice.h | 4 +- 12 files changed, 419 insertions(+), 161 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index caab409e8..b9c0c46c0 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -64,7 +64,7 @@ static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priorit /* Setup */ ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc) - : p3Service(), + : p3Service(),RsSerializer(RS_SERVICE_TYPE_TURTLE), // should be FT, but this is for backward compatibility mPeerMgr(pm), mServiceCtrl(sc), mFileDatabase(NULL), mFtController(NULL), mFtExtra(NULL), @@ -459,14 +459,12 @@ bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, Fi return false; } -RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) const +RsItem *ftServer::create_item(uint16_t service,uint8_t item_type) { - uint32_t rstype = getRsItemId(data); - #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ; #endif - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) + if (RS_SERVICE_TYPE_TURTLE != service) { FTSERVER_ERROR() << " Wrong type !!" << std::endl ; return NULL; /* wrong type */ @@ -474,14 +472,14 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c try { - switch(getRsItemSubType(rstype)) + switch(item_type) { - case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(data,size) ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(); + case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(); + case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(); + case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(); + case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(); + case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(); default: return NULL ; @@ -1189,7 +1187,8 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; #endif - uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; + uint32_t item_serialized_size = size(clear_item) ; + uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + item_serialized_size + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; #ifdef SERVER_DEBUG FTSERVER_DEBUG() << " clear part size : " << clear_item->serial_size() << std::endl; @@ -1204,7 +1203,7 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas return false ; uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; - uint32_t edata_size = clear_item->serial_size() ; + uint32_t edata_size = item_serialized_size; uint32_t offset = 0; edata[0] = 0xae ; @@ -1227,7 +1226,8 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas offset += ENCRYPTED_FT_EDATA_SIZE ; uint32_t ser_size = (uint32_t)((int)total_data_size - (int)offset); - clear_item->serialize(&edata[offset], ser_size); + + serialise(clear_item,&edata[offset], &ser_size); #ifdef SERVER_DEBUG FTSERVER_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; @@ -1331,7 +1331,7 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH return false ; } - decrypted_item = deserialiseItem(&edata[clear_item_offset],edata_size) ; + decrypted_item = dynamic_cast(deserialise(&edata[clear_item_offset],&edata_size)) ; if(decrypted_item == NULL) return false ; diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index d52c539d0..cda01eed6 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -68,7 +68,7 @@ class p3PeerMgr; class p3ServiceControl; class p3FileDatabase; -class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTurtleClientService +class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTurtleClientService, public RsSerializer { public: @@ -97,7 +97,7 @@ 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 RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ; + virtual RsItem *create_item(uint16_t service,uint8_t item_type) ; 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 b4ce91623..e8f1bc886 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -30,6 +30,9 @@ #include #include +#include + +#ifdef TO_REMOVE uint32_t RsTurtleFileRequestItem::serial_size() const { uint32_t s = 0 ; @@ -101,6 +104,15 @@ uint32_t RsTurtleChunkCrcRequestItem::serial_size() const return s ; } +#endif + +void RsTurtleFileMapRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; + RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; +} + +#ifdef TO_REMOVE bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); @@ -134,6 +146,7 @@ bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) const return ok; } + bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); @@ -563,3 +576,40 @@ std::ostream& RsTurtleChunkCrcItem::print(std::ostream& o, uint16_t) return o ; } +#endif + +void RsTurtleFileMapItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; + RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; + RsTypeSerializer::serial_process (j,ctx,compressed_map._map,"map") ; +} +void RsTurtleChunkCrcRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; + RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; +} +void RsTurtleChunkCrcItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; + RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; + RsTypeSerializer::serial_process (j,ctx,check_sum,"check_sum") ; +} + +void RsTurtleFileRequestItem::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") ; +} +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) ; + + RsTypeSerializer::serial_process(j,ctx,prox,"chunk_data") ; +} + diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.h b/libretroshare/src/ft/ftturtlefiletransferitem.h index 8a886918e..fd8aada93 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.h +++ b/libretroshare/src/ft/ftturtlefiletransferitem.h @@ -34,7 +34,6 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem { public: RsTurtleFileRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_REQUEST);} - RsTurtleFileRequestItem(void *data,uint32_t size) ; // deserialization virtual bool shouldStampTunnel() const { return false ; } virtual Direction travelingDirection() const { return DIRECTION_SERVER ; } @@ -42,51 +41,50 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem uint64_t chunk_offset ; uint32_t chunk_size ; - virtual std::ostream& print(std::ostream& o, uint16_t) ; + void clear() {} protected: - virtual bool serialize(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem { public: RsTurtleFileDataItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_DATA) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_DATA) ;} - ~RsTurtleFileDataItem() ; - RsTurtleFileDataItem(void *data,uint32_t size) ; // deserialization + ~RsTurtleFileDataItem() { clear() ; } virtual bool shouldStampTunnel() const { return true ; } virtual Direction travelingDirection() const { return DIRECTION_CLIENT ; } + void clear() + { + free(chunk_data); + chunk_data = NULL ; + chunk_size = 0 ; + chunk_offset = 0 ; + } + uint64_t chunk_offset ; // offset in the file uint32_t chunk_size ; // size of the file chunk void *chunk_data ; // actual data. - virtual std::ostream& print(std::ostream& o, uint16_t) ; - - virtual bool serialize(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem { public: RsTurtleFileMapRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST) ;} - RsTurtleFileMapRequestItem(void *data,uint32_t size) ; // deserialization virtual bool shouldStampTunnel() const { return false ; } - virtual std::ostream& print(std::ostream& o, uint16_t) ; - - virtual bool serialize(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + void clear() {} + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem { public: RsTurtleFileMapItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP) ;} - RsTurtleFileMapItem(void *data,uint32_t size) ; // deserialization virtual bool shouldStampTunnel() const { return false ; } @@ -94,34 +92,28 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem // by default, we suppose the peer has all the chunks. This info will thus be and-ed // with the default file map for this source. - virtual std::ostream& print(std::ostream& o, uint16_t) ; - - virtual bool serialize(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + void clear() { compressed_map._map.clear() ;} + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem { public: RsTurtleChunkCrcRequestItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST) { setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC_REQUEST);} - RsTurtleChunkCrcRequestItem(void *data,uint32_t size) ; // deserialization virtual bool shouldStampTunnel() const { return false ; } virtual Direction travelingDirection() const { return DIRECTION_SERVER ; } uint32_t chunk_number ; // id of the chunk to CRC. - virtual std::ostream& print(std::ostream& o, uint16_t) ; - - virtual bool serialize(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + void clear() {} + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem { public: RsTurtleChunkCrcItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC) { setPriorityLevel(QOS_PRIORITY_RS_CHUNK_CRC);} - RsTurtleChunkCrcItem(void *data,uint32_t size) ; // deserialization virtual bool shouldStampTunnel() const { return true ; } virtual Direction travelingDirection() const { return DIRECTION_CLIENT ; } @@ -129,7 +121,6 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem uint32_t chunk_number ; Sha1CheckSum check_sum ; - virtual std::ostream& print(std::ostream& o, uint16_t) ; - virtual bool serialize(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + void clear() { check_sum.clear() ;} + void serial_process(SerializeJob j,SerializeContext& ctx); }; diff --git a/libretroshare/src/serialiser/rstlvbase.cc b/libretroshare/src/serialiser/rstlvbase.cc index afc29a99e..f92dae4d9 100644 --- a/libretroshare/src/serialiser/rstlvbase.cc +++ b/libretroshare/src/serialiser/rstlvbase.cc @@ -32,7 +32,7 @@ //********************* // A facility func -inline void* right_shift_void_pointer(void* p, uint32_t len) { +inline void* right_shift_void_pointer(const void* p, uint32_t len) { return (void*)( (uint8_t*)p + len); } @@ -550,7 +550,7 @@ static bool find_decoded_string(const std::string& in,const std::string& suspici } //tested -bool GetTlvString(void *data, uint32_t size, uint32_t *offset, +bool GetTlvString(const void *data, uint32_t size, uint32_t *offset, uint16_t type, std::string &in) { if (!data) diff --git a/libretroshare/src/serialiser/rstlvbase.h b/libretroshare/src/serialiser/rstlvbase.h index f33a7d8ee..3f6ac1102 100644 --- a/libretroshare/src/serialiser/rstlvbase.h +++ b/libretroshare/src/serialiser/rstlvbase.h @@ -275,7 +275,7 @@ uint32_t GetTlvUInt64Size(); bool SetTlvString(void *data, uint32_t size, uint32_t *offset, uint16_t type, std::string out); -bool GetTlvString(void *data, uint32_t size, uint32_t *offset, uint16_t type, std::string &in); +bool GetTlvString(const void *data, uint32_t size, uint32_t *offset, uint16_t type, std::string &in); uint32_t GetTlvStringSize(const std::string &in); #ifdef REMOVED_CODE diff --git a/libretroshare/src/serialization/rstypeserializer.cc b/libretroshare/src/serialization/rstypeserializer.cc index 5a8def1bd..2c68d2c0c 100644 --- a/libretroshare/src/serialization/rstypeserializer.cc +++ b/libretroshare/src/serialization/rstypeserializer.cc @@ -22,7 +22,11 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint3 { return setRawUInt8(data,size,&offset,member); } -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint16_t& member) +{ + return setRawUInt16(data,size,&offset,member); +} +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const uint32_t& member) { return setRawUInt32(data,size,&offset,member); } @@ -46,7 +50,11 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t siz { return getRawUInt8(data,size,&offset,&member); } -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint16_t& member) +{ + return getRawUInt16(data,size,&offset,&member); +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, uint32_t& member) { return getRawUInt32(data,size,&offset,&member); } @@ -67,6 +75,10 @@ template<> uint32_t RsTypeSerializer::serial_size(const uint8_t& /* member*/) { return 1; } +template<> uint32_t RsTypeSerializer::serial_size(const uint16_t& /* member*/) +{ + return 2; +} template<> uint32_t RsTypeSerializer::serial_size(const uint32_t& /* member*/) { return 4; @@ -224,7 +236,7 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_ template<> void RsTypeSerializer::print_data(const std::string& n, const RsTypeSerializer::TlvMemBlock_proxy& s) { - std::cerr << " [Binary data] " << n << ", length=" << s.second << " data=" << RsUtil::BinToHex(s.first,std::min(50u,s.second)) << ((s.second>50)?"...":"") << std::endl; + std::cerr << " [Binary data] " << n << ", length=" << s.second << " data=" << RsUtil::BinToHex((uint8_t*)s.first,std::min(50u,s.second)) << ((s.second>50)?"...":"") << std::endl; } //=================================================================================================// diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 349689c0b..403219ecb 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -26,7 +26,11 @@ class RsTypeSerializer public: // This type should be used to pass a parameter to drive the serialisation if needed. - typedef std::pair TlvMemBlock_proxy; + struct TlvMemBlock_proxy: public std::pair + { + TlvMemBlock_proxy(void *& p,uint32_t& s) : std::pair(p,s) {} + TlvMemBlock_proxy(uint8_t*& p,uint32_t& s) : std::pair(*(void**)&p,s) {} + }; //=================================================================================================// // Generic types // @@ -135,6 +139,59 @@ class RsTypeSerializer break; } } + + //=================================================================================================// + // std::list // + //=================================================================================================// + + template + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::list& v,const std::string& member_name) + { + switch(j) + { + case RsItem::SIZE_ESTIMATE: + { + ctx.mOffset += 4 ; + for(typename std::list::iterator it(v.begin());it!=v.end();++it) + serial_process(j,ctx,*it ,member_name) ; + } + break ; + + case RsItem::DESERIALIZE: + { uint32_t n=0 ; + serial_process(j,ctx,n,"temporary size") ; + + for(uint32_t i=0;i(j,ctx,tmp,member_name) ; + v.push_back(tmp); + } + } + break ; + + case RsItem::SERIALIZE: + { + uint32_t n=v.size(); + serial_process(j,ctx,n,"temporary size") ; + for(typename std::list::iterator it(v.begin());it!=v.end();++it) + serial_process(j,ctx,*it ,member_name) ; + } + break ; + + case RsItem::PRINT: + { + if(v.empty()) + std::cerr << " Empty list"<< std::endl; + else + std::cerr << " List of " << v.size() << " elements:" << std::endl; + } + break; + default: + break; + } + } + //=================================================================================================// // t_RsFlags32<> types // //=================================================================================================// diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 997fe0e7e..1cfbc2cbd 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -852,12 +852,14 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item) item->print(std::cerr,0) ; #endif - if(item->serial_size() > TURTLE_MAX_SEARCH_REQ_ACCEPTED_SERIAL_SIZE) + uint32_t item_size = RsTurtleSerialiser().size(item); + + if(item_size > TURTLE_MAX_SEARCH_REQ_ACCEPTED_SERIAL_SIZE) { #ifdef P3TURTLE_DEBUG std::cerr << " Dropping, because the serial size exceeds the accepted limit." << std::endl ; #endif - std::cerr << " Caught a turtle search item with arbitrary large size from " << item->PeerId() << " of size " << item->serial_size() << " and depth " << item->depth << ". This is not allowed => dropping." << std::endl; + std::cerr << " Caught a turtle search item with arbitrary large size from " << item->PeerId() << " of size " << item_size << " and depth " << item->depth << ". This is not allowed => dropping." << std::endl; return ; } @@ -1074,7 +1076,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item) if(item->shouldStampTunnel()) tunnel.time_stamp = time(NULL) ; - tunnel.transfered_bytes += static_cast(item)->serial_size() ; + tunnel.transfered_bytes += RsTurtleSerialiser().size(item); if(item->PeerId() == tunnel.local_dst) item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; @@ -1100,7 +1102,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item) #endif item->PeerId(tunnel.local_src) ; - _traffic_info_buffer.unknown_updn_Bps += static_cast(item)->serial_size() ; + _traffic_info_buffer.unknown_updn_Bps += RsTurtleSerialiser().size(item) ; // This has been disabled for compilation reasons. Not sure we actually need it. // @@ -1118,7 +1120,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item) #endif item->PeerId(tunnel.local_dst) ; - _traffic_info_buffer.unknown_updn_Bps += static_cast(item)->serial_size() ; + _traffic_info_buffer.unknown_updn_Bps += RsTurtleSerialiser().size(item); sendItem(item) ; return ; @@ -1126,7 +1128,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item) // item is for us. Use the locked region to record the data. - _traffic_info_buffer.data_dn_Bps += item->serial_size() ; + _traffic_info_buffer.data_dn_Bps += RsTurtleSerialiser().size(item); } // The packet was not forwarded, so it is for us. Let's treat it. @@ -1246,7 +1248,7 @@ void p3turtle::sendTurtleData(const RsPeerId& virtual_peer_id,RsTurtleGenericTun item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever. - uint32_t ss = item->serial_size() ; + uint32_t ss = RsTurtleSerialiser().size(item); if(item->shouldStampTunnel()) tunnel.time_stamp = time(NULL) ; @@ -1380,7 +1382,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) { RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ - _traffic_info_buffer.tr_dn_Bps += static_cast(item)->serial_size() ; + _traffic_info_buffer.tr_dn_Bps += RsTurtleSerialiser().size(item); float distance_to_maximum = std::min(100.0f,_traffic_info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ; float corrected_distance = pow(distance_to_maximum,DISTANCE_SQUEEZING_POWER) ; @@ -1572,7 +1574,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item) { RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ - _traffic_info_buffer.tr_up_Bps += static_cast(fwd_item)->serial_size() ; + _traffic_info_buffer.tr_up_Bps += RsTurtleSerialiser().size(fwd_item); } sendItem(fwd_item) ; diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index c1965deee..577d152a8 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -6,6 +6,8 @@ #include "rsturtleitem.h" #include "turtleclientservice.h" +#include "serialization/rstypeserializer.h" + //#define P3TURTLE_DEBUG // -----------------------------------------------------------------------------------// // -------------------------------- Serialization. --------------------------------- // @@ -16,6 +18,7 @@ // ---------------------------------- Packet sizes -----------------------------------// // +#ifdef TO_REMOVE uint32_t RsTurtleStringSearchRequestItem::serial_size() const { uint32_t s = 0 ; @@ -102,19 +105,13 @@ uint32_t RsTurtleGenericDataItem::serial_size() const return s ; } +#endif // // ---------------------------------- Serialization ----------------------------------// // -RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size) +RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) { - // look what we have... - - /* get the type */ - uint32_t rstype = getRsItemId(data); -#ifdef P3TURTLE_DEBUG - std::cerr << "p3turtle: deserialising packet: " << std::endl ; -#endif - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) + if (RS_SERVICE_TYPE_TURTLE != service) { #ifdef P3TURTLE_DEBUG std::cerr << " Wrong type !!" << std::endl ; @@ -122,43 +119,38 @@ RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size) return NULL; /* wrong type */ } -#ifndef WINDOWS_SYS - try + switch(getRsItemSubType(item_subtype)) { -#endif - switch(getRsItemSubType(rstype)) - { - case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST : return new RsTurtleStringSearchRequestItem(data,*size) ; - case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST : return new RsTurtleRegExpSearchRequestItem(data,*size) ; - case RS_TURTLE_SUBTYPE_SEARCH_RESULT : return new RsTurtleSearchResultItem(data,*size) ; - case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem(data,*size) ; - case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem(data,*size) ; - case RS_TURTLE_SUBTYPE_GENERIC_DATA : return new RsTurtleGenericDataItem(data,*size) ; - - default: - break ; - } - // now try all client services - // - RsItem *item = NULL ; + case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST : return new RsTurtleStringSearchRequestItem(); + case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST : return new RsTurtleRegExpSearchRequestItem(); + case RS_TURTLE_SUBTYPE_SEARCH_RESULT : return new RsTurtleSearchResultItem(); + case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem(); + case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem(); + case RS_TURTLE_SUBTYPE_GENERIC_DATA : return new RsTurtleGenericDataItem(); - for(uint32_t i=0;i<_client_services.size();++i) - if((item = _client_services[i]->deserialiseItem(data,*size)) != NULL) - return item ; - - std::cerr << "Unknown packet type in RsTurtle (not even handled by client services)!" << std::endl ; - return NULL ; -#ifndef WINDOWS_SYS + default: + break ; } - catch(std::exception& e) - { - std::cerr << "Exception raised: " << e.what() << std::endl ; - return NULL ; - } -#endif + // now try all client services + // + RsItem *item = NULL ; + for(uint32_t i=0;i<_client_services.size();++i) + if((item = _client_services[i]->create_item(service,item_subtype)) != NULL) + return item ; + + std::cerr << "Unknown packet type in RsTurtle (not even handled by client services)!" << std::endl ; + return NULL ; } +void RsTurtleStringSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ; + RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; + RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; +} + +#ifdef TO_REMOVE bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); @@ -242,7 +234,95 @@ bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) co return ok; } +#endif +void RsTurtleRegExpSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; + RsTypeSerializer::serial_process(j,ctx,depth,"depth") ; + RsTypeSerializer::serial_process(j,ctx,expr,"expr") ; +} + +template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r) +{ + uint32_t s = 0 ; + + s += 4 ; // number of strings + + for(unsigned int i=0;i bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,RsRegularExpression::LinearizedExpression& expr) +{ + uint32_t saved_offset = offset ; + + uint32_t n =0 ; + bool ok = true ; + + ok &= getRawUInt32(data,size,&offset,&n) ; + + if(ok) expr._tokens.resize(n) ; + + for(uint32_t i=0;i bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const RsRegularExpression::LinearizedExpression& expr) +{ + uint32_t saved_offset = offset ; + + bool ok = true ; + + ok &= setRawUInt32(data,size,&offset,expr._tokens.size()) ; + + for(unsigned int i=0;i void RsTypeSerializer::print_data(const std::string& n, const RsRegularExpression::LinearizedExpression& expr) +{ + std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl; +} + + +#ifdef TO_REMOVE RsTurtleStringSearchRequestItem::RsTurtleStringSearchRequestItem(void *data,uint32_t pktsize) : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) { @@ -309,6 +389,62 @@ RsTurtleRegExpSearchRequestItem::RsTurtleRegExpSearchRequestItem(void *data,uint throw std::runtime_error("Unknown error while deserializing.") ; #endif } +#endif + +void RsTurtleSearchResultItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; + RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; + RsTypeSerializer::serial_process (j,ctx,result ,"result") ; +} + +template<> uint32_t RsTypeSerializer::serial_size(const TurtleFileInfo& i) +{ + uint32_t s = 0 ; + + s += 8 ; // size + s += i.hash.SIZE_IN_BYTES ; + s += GetTlvStringSize(i.name) ; + + return s; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,TurtleFileInfo& i) +{ + uint32_t saved_offset = offset ; + bool ok = true ; + + ok &= getRawUInt64(data, size, &offset, &i.size); // file size + ok &= i.hash.deserialise(data, size, offset); // file hash + ok &= GetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // file name + + if(!ok) + offset = saved_offset ; + + return ok; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const TurtleFileInfo& i) +{ + uint32_t saved_offset = offset ; + bool ok = true ; + + ok &= setRawUInt64(data, size, &offset, i.size); // file size + ok &= i.hash.serialise(data, size, offset); // file hash + ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // file name + + if(!ok) + offset = saved_offset ; + + return ok; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleFileInfo& i) +{ + std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl; +} + +#ifdef TO_REMOVE bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) const { @@ -394,7 +530,17 @@ RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize) throw std::runtime_error("Unknown error while deserializing.") ; #endif } +#endif +void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ; + RsTypeSerializer::serial_process(j,ctx,request_id ,"request_id") ; + RsTypeSerializer::serial_process(j,ctx,partial_tunnel_id,"partial_tunnel_id") ; + RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; +} + +#ifdef TO_REMOVE bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); @@ -460,7 +606,15 @@ RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize) throw std::runtime_error("RsTurtleOpenTunnelItem::() unknown error while deserializing.") ; #endif } +#endif +void RsTurtleTunnelOkItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; + RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; +} + +#ifdef TO_REMOVE bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); @@ -522,7 +676,18 @@ RsTurtleTunnelOkItem::RsTurtleTunnelOkItem(void *data,uint32_t pktsize) throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ; #endif } +#endif +void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; + + RsTypeSerializer::TlvMemBlock_proxy prox(data_bytes,data_size) ; + + RsTypeSerializer::serial_process(j,ctx,prox,"data bytes") ; +} + +#ifdef TO_REMOVE RsTurtleGenericDataItem::RsTurtleGenericDataItem(void *data,uint32_t pktsize) : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_GENERIC_DATA) { @@ -604,6 +769,7 @@ bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) const return ok; } + // -----------------------------------------------------------------------------------// // ------------------------------------- IO --------------------------------------- // // -----------------------------------------------------------------------------------// @@ -681,3 +847,4 @@ std::ostream& RsTurtleGenericDataItem::print(std::ostream& o, uint16_t) return o ; } +#endif diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 5b15f7781..22477668a 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -9,6 +9,8 @@ #include "serialiser/rsserviceids.h" #include "turtle/turtletypes.h" +#include "serialization/rsserializer.h" + const uint8_t RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST = 0x01 ; const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ; const uint8_t RS_TURTLE_SUBTYPE_OPEN_TUNNEL = 0x03 ; @@ -17,14 +19,14 @@ const uint8_t RS_TURTLE_SUBTYPE_CLOSE_TUNNEL = 0x05 ; const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_CLOSED = 0x06 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_REQUEST = 0x07 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_DATA = 0x08 ; -const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ; +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_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 ; /***********************************************************************************/ /* Basic Turtle Item Class */ @@ -34,11 +36,6 @@ class RsTurtleItem: public RsItem { public: RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {} - - virtual bool serialize(void *data,uint32_t& size) const = 0 ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor - - virtual void clear() {} }; /***********************************************************************************/ @@ -50,29 +47,26 @@ class RsTurtleSearchResultItem: public RsTurtleItem { public: RsTurtleSearchResultItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_RESULT), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ;} - RsTurtleSearchResultItem(void *data,uint32_t size) ; // deserialization TurtleSearchRequestId request_id ; // Randomly generated request id. - uint16_t depth ; // The depth of a search result is obfuscated in this way: - // If the actual depth is 1, this field will be 1. - // If the actual depth is > 1, this field is a larger arbitrary integer. - + uint16_t depth ; // The depth of a search result is obfuscated in this way: + // If the actual depth is 1, this field will be 1. + // If the actual depth is > 1, this field is a larger arbitrary integer. std::list result ; - virtual std::ostream& print(std::ostream& o, uint16_t) ; - + void clear() { result.clear() ; } protected: - virtual bool serialize(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + void serial_process(SerializeJob j,SerializeContext& ctx); + }; class RsTurtleSearchRequestItem: public RsTurtleItem { public: RsTurtleSearchRequestItem(uint32_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST) ;} + virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods - virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods virtual void performLocalSearch(std::list&) const = 0 ; // abstracts the search method uint32_t request_id ; // randomly generated request id. @@ -83,34 +77,31 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem { public: RsTurtleStringSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {} - RsTurtleStringSearchRequestItem(void *data,uint32_t size) ; std::string match_string ; // string to match virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; } virtual void performLocalSearch(std::list&) const ; - virtual std::ostream& print(std::ostream& o, uint16_t) ; + void clear() { match_string.clear() ; } + protected: - virtual bool serialize(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem { public: RsTurtleRegExpSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {} - RsTurtleRegExpSearchRequestItem(void *data,uint32_t size) ; RsRegularExpression::LinearizedExpression expr ; // Reg Exp in linearised mode virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; } virtual void performLocalSearch(std::list&) const ; - virtual std::ostream& print(std::ostream& o, uint16_t) ; + void clear() { expr = RsRegularExpression::LinearizedExpression(); } protected: - virtual bool serialize(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + void serial_process(SerializeJob j,SerializeContext& ctx); }; /***********************************************************************************/ @@ -121,34 +112,28 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem { public: RsTurtleOpenTunnelItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_OPEN_TUNNEL), request_id(0), partial_tunnel_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_OPEN_TUNNEL) ;} - RsTurtleOpenTunnelItem(void *data,uint32_t size) ; // deserialization TurtleFileHash file_hash ; // hash to match uint32_t request_id ; // randomly generated request id. uint32_t partial_tunnel_id ; // uncomplete tunnel id. Will be completed at destination. uint16_t depth ; // Used for limiting search depth. - virtual std::ostream& print(std::ostream& o, uint16_t) ; - + void clear() { file_hash.clear() ;} protected: - virtual bool serialize(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + void serial_process(SerializeJob j,SerializeContext& ctx); }; class RsTurtleTunnelOkItem: public RsTurtleItem { public: RsTurtleTunnelOkItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_OK), tunnel_id(0), request_id(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_TUNNEL_OK) ;} - RsTurtleTunnelOkItem(void *data,uint32_t size) ; // deserialization uint32_t tunnel_id ; // id of the tunnel. Should be identical for a tunnel between two same peers for the same hash. uint32_t request_id ; // randomly generated request id corresponding to the intial request. - virtual std::ostream& print(std::ostream& o, uint16_t) ; - + void clear() {} protected: - virtual bool serialize(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + void serial_process(SerializeJob j,SerializeContext& ctx); }; /***********************************************************************************/ @@ -198,8 +183,6 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem { public: RsTurtleGenericDataItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_GENERIC_DATA), data_size(0), data_bytes(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_REQUEST);} - RsTurtleGenericDataItem(void *data,uint32_t size) ; // deserialization - virtual ~RsTurtleGenericDataItem() { if(data_bytes != NULL) free(data_bytes) ; } virtual bool shouldStampTunnel() const { return true ; } @@ -207,30 +190,26 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem uint32_t data_size ; void *data_bytes ; - virtual std::ostream& print(std::ostream& o, uint16_t) ; + void clear() + { + free(data_bytes) ; + data_bytes = NULL ; + data_size = 0; + } protected: - virtual bool serialize(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + void serial_process(SerializeJob j,SerializeContext& ctx); }; /***********************************************************************************/ /* Turtle Serialiser class */ /***********************************************************************************/ -class RsTurtleSerialiser: public RsSerialType +class RsTurtleSerialiser: public RsSerializer { public: - RsTurtleSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_TURTLE) {} + RsTurtleSerialiser() : RsSerializer(RS_SERVICE_TYPE_TURTLE) {} - virtual uint32_t size (RsItem *item) - { - return dynamic_cast(item)->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - return dynamic_cast(item)->serialize(data,*size) ; - } - virtual RsItem *deserialise (void *data, uint32_t *size) ; + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype); // 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 033d5e046..6fa4dd629 100644 --- a/libretroshare/src/turtle/turtleclientservice.h +++ b/libretroshare/src/turtle/turtleclientservice.h @@ -71,12 +71,12 @@ class RsTurtleClientService std::cerr << "!!!!!! Received Data from turtle router, but the client service is not handling it !!!!!!!!!!" << std::endl ; } - // Method for deserialising specific items of the client service. The + // Method for creating specific items of the client service. The // method has a default behavior of not doing anything, since most client // services might only use the generic item already provided by the turtle // router: RsTurtleGenericDataItem - virtual RsTurtleGenericTunnelItem *deserialiseItem(void */*data*/, uint32_t /*size*/) const { return NULL ; } + virtual RsTurtleGenericTunnelItem *create_item(uint16_t service,uint8_t item_type) const { return NULL ; } // These methods are called by the turtle router to add/remove virtual peers when tunnels are created/deleted // From 121133488c7893601255bf9507a0953e0c5639a7 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 16 Apr 2017 19:59:22 +0200 Subject: [PATCH 024/106] 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 // From 2ca46ec636bef771616be789a538739199a4637f Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 16 Apr 2017 20:11:54 +0200 Subject: [PATCH 025/106] fixed bug in serialization of data chunks --- libretroshare/src/serialization/rstypeserializer.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libretroshare/src/serialization/rstypeserializer.cc b/libretroshare/src/serialization/rstypeserializer.cc index 2c68d2c0c..64ba46f68 100644 --- a/libretroshare/src/serialization/rstypeserializer.cc +++ b/libretroshare/src/serialization/rstypeserializer.cc @@ -213,6 +213,7 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size ok = ok && NULL != r.first; memcpy(r.first,&data[offset],r.second) ; + offset += r.second ; if(!ok) offset = saved_offset ; @@ -227,6 +228,7 @@ template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_ bool ok = serialize(data,size,offset,r.second) ; memcpy(&data[offset],r.first,r.second) ; + offset += r.second ; if(!ok) offset = saved_offset ; From f8fc8b40e4a26c6556a394abd664fffa21e4eb7d Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 16 Apr 2017 20:16:59 +0200 Subject: [PATCH 026/106] removed old code in turtle serialiser --- .../src/serialization/rsserializer.cc | 8 +- libretroshare/src/turtle/rsturtleitem.cc | 633 ------------------ 2 files changed, 7 insertions(+), 634 deletions(-) diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 4cf03d133..13b4435fd 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -20,6 +20,12 @@ RsItem *RsSerializer::deserialise(void *data, uint32_t *size) item->serial_process(RsItem::DESERIALIZE, ctx) ; + if(ctx.mSize != ctx.mOffset) + { + std::cerr << "RsSerializer::deserialise(): ERROR. offset does not match expected size!" << std::endl; + delete item ; + return NULL ; + } if(ctx.mOk) return item ; @@ -48,7 +54,7 @@ bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size) if(ctx.mSize != ctx.mOffset) { - std::cerr << "RsSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; + std::cerr << "RsSerializer::serialise(): ERROR. offset does not match expected size!" << std::endl; return false ; } return true ; diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index e5d064ef2..4d5f1a2fa 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -14,101 +14,6 @@ // -----------------------------------------------------------------------------------// // -// -// ---------------------------------- Packet sizes -----------------------------------// -// - -#ifdef TO_REMOVE -uint32_t RsTurtleStringSearchRequestItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // request_id - s += 2 ; // depth - s += GetTlvStringSize(match_string) ; // match_string - - return s ; -} -uint32_t RsTurtleRegExpSearchRequestItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // request_id - s += 2 ; // depth - - s += 4 ; // number of strings - - for(unsigned int i=0;i::const_iterator it(result.begin());it!=result.end();++it) - { - s += 8 ; // file size - s += it->hash.serial_size(); // file hash - s += GetTlvStringSize(it->name) ; // file name - } - - return s ; -} - -uint32_t RsTurtleOpenTunnelItem::serial_size()const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += file_hash.serial_size() ; // file hash - s += 4 ; // tunnel request id - s += 4 ; // partial tunnel id - s += 2 ; // depth - - return s ; -} - -uint32_t RsTurtleTunnelOkItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 4 ; // tunnel request id - - return s ; -} - -uint32_t RsTurtleGenericDataItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 4 ; // data size - s += data_size ; // data - - return s ; -} -#endif -// -// ---------------------------------- Serialization ----------------------------------// -// RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) const { if (RS_SERVICE_TYPE_TURTLE != service) @@ -150,92 +55,6 @@ void RsTurtleStringSearchRequestItem::serial_process(SerializeJob j,SerializeCon RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; } -#ifdef TO_REMOVE -bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, match_string); - ok &= setRawUInt32(data, tlvsize, &offset, request_id); - ok &= setRawUInt16(data, tlvsize, &offset, depth); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - -#ifdef P3TURTLE_DEBUG - std::cerr << "RsTurtleSerialiser::serialising RegExp search packet (size=" << tlvsize << ")" << std::endl; -#endif - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, request_id); - ok &= setRawUInt16(data, tlvsize, &offset, depth); - - // now serialize the regexp - ok &= setRawUInt32(data,tlvsize,&offset,expr._tokens.size()) ; - - for(unsigned int i=0;i(j,ctx,request_id,"request_id") ; @@ -321,76 +140,6 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegul std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl; } - -#ifdef TO_REMOVE -RsTurtleStringSearchRequestItem::RsTurtleStringSearchRequestItem(void *data,uint32_t pktsize) - : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) -{ -#ifdef P3TURTLE_DEBUG - std::cerr << " deserializibg packet. type = search request (string)" << std::endl ; -#endif - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE, match_string); // file hash - ok &= getRawUInt32(data, pktsize, &offset, &request_id); - ok &= getRawUInt16(data, pktsize, &offset, &depth); - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (offset != rssize) - throw std::runtime_error("Size error while deserializing.") ; - if (!ok) - throw std::runtime_error("Unknown error while deserializing.") ; -#endif -} - -RsTurtleRegExpSearchRequestItem::RsTurtleRegExpSearchRequestItem(void *data,uint32_t pktsize) - : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) -{ -#ifdef P3TURTLE_DEBUG - std::cerr << " deserializibg packet. type = search request (regexp)" << std::endl ; -#endif - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - ok &= getRawUInt32(data, pktsize, &offset, &request_id); - ok &= getRawUInt16(data, pktsize, &offset, &depth); - - // now serialize the regexp - uint32_t n =0 ; - ok &= getRawUInt32(data,pktsize,&offset,&n) ; - - if(ok) expr._tokens.resize(n) ; - - for(uint32_t i=0;i(j,ctx,request_id,"request_id") ; @@ -444,94 +193,6 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleF std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl; } -#ifdef TO_REMOVE - -bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, request_id); - ok &= setRawUInt16(data, tlvsize, &offset, depth); - ok &= setRawUInt32(data, tlvsize, &offset, result.size()); - - for(std::list::const_iterator it(result.begin());it!=result.end();++it) - { - ok &= setRawUInt64(data, tlvsize, &offset, it->size); // file size - ok &= it->hash.serialise(data, tlvsize, offset); // file hash - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, it->name); // file name - } - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize) - : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_RESULT) -{ - setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ; -#ifdef P3TURTLE_DEBUG - std::cerr << " type = search result" << std::endl ; -#endif - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - - /* add mandatory parts first */ - - bool ok = true ; - uint32_t s ; - ok &= getRawUInt32(data, pktsize, &offset, &request_id); - ok &= getRawUInt16(data, pktsize, &offset, &depth); - ok &= getRawUInt32(data, pktsize, &offset, &s) ; -#ifdef P3TURTLE_DEBUG - std::cerr << " request_id=" << request_id << ", depth=" << depth << ", s=" << s << std::endl ; -#endif - - result.clear() ; - - for(int i=0;i<(int)s;++i) - { - TurtleFileInfo f ; - - ok &= getRawUInt64(data, pktsize, &offset, &(f.size)); // file size - ok &= f.hash.deserialise(data, pktsize, offset); // file hash - ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_NAME, f.name); // file name - - result.push_back(f) ; - } - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (offset != rssize) - throw std::runtime_error("Size error while deserializing.") ; - if (!ok) - throw std::runtime_error("Unknown error while deserializing.") ; -#endif -} -#endif - void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ; @@ -540,144 +201,12 @@ void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; } -#ifdef TO_REMOVE -bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= file_hash.serialise(data, tlvsize, offset); // file hash - ok &= setRawUInt32(data, tlvsize, &offset, request_id); - ok &= setRawUInt32(data, tlvsize, &offset, partial_tunnel_id); - ok &= setRawUInt16(data, tlvsize, &offset, depth); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsTurtleOpenTunnelItem::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize) - : RsTurtleItem(RS_TURTLE_SUBTYPE_OPEN_TUNNEL) -{ - setPriorityLevel(QOS_PRIORITY_RS_TURTLE_OPEN_TUNNEL) ; -#ifdef P3TURTLE_DEBUG - std::cerr << " type = open tunnel" << std::endl ; -#endif - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - - /* add mandatory parts first */ - - bool ok = true ; - ok &= file_hash.deserialise(data, pktsize, offset); // file hash - ok &= getRawUInt32(data, pktsize, &offset, &request_id); - ok &= getRawUInt32(data, pktsize, &offset, &partial_tunnel_id) ; - ok &= getRawUInt16(data, pktsize, &offset, &depth); -#ifdef P3TURTLE_DEBUG - std::cerr << " request_id=" << (void*)request_id << ", partial_id=" << (void*)partial_tunnel_id << ", depth=" << depth << ", hash=" << file_hash << std::endl ; -#endif - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (offset != rssize) - throw std::runtime_error("RsTurtleOpenTunnelItem::() error while deserializing.") ; - if (!ok) - throw std::runtime_error("RsTurtleOpenTunnelItem::() unknown error while deserializing.") ; -#endif -} -#endif - void RsTurtleTunnelOkItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; } -#ifdef TO_REMOVE -bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id); - ok &= setRawUInt32(data, tlvsize, &offset, request_id); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsTurtleTunnelOkItem::RsTurtleTunnelOkItem(void *data,uint32_t pktsize) - : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_OK) -{ - setPriorityLevel(QOS_PRIORITY_RS_TURTLE_TUNNEL_OK) ; -#ifdef P3TURTLE_DEBUG - std::cerr << " type = tunnel ok" << std::endl ; -#endif - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - - /* add mandatory parts first */ - - bool ok = true ; - ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ; - ok &= getRawUInt32(data, pktsize, &offset, &request_id); -#ifdef P3TURTLE_DEBUG - std::cerr << " request_id=" << (void*)request_id << ", tunnel_id=" << (void*)tunnel_id << std::endl ; -#endif - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (offset != rssize) - throw std::runtime_error("RsTurtleTunnelOkItem::() error while deserializing.") ; - if (!ok) - throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ; -#endif -} -#endif - void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; @@ -686,165 +215,3 @@ void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ct RsTypeSerializer::serial_process(j,ctx,prox,"data bytes") ; } - -#ifdef TO_REMOVE -RsTurtleGenericDataItem::RsTurtleGenericDataItem(void *data,uint32_t pktsize) - : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_GENERIC_DATA) -{ - setPriorityLevel(QOS_PRIORITY_RS_TURTLE_GENERIC_DATA) ; -#ifdef P3TURTLE_DEBUG - std::cerr << " type = tunnel ok" << std::endl ; -#endif - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - - if(rssize > pktsize) - throw std::runtime_error("RsTurtleTunnelOkItem::() wrong rssize (exceeds pktsize).") ; - - /* add mandatory parts first */ - - bool ok = true ; - - ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ; - ok &= getRawUInt32(data, pktsize, &offset, &data_size); -#ifdef P3TURTLE_DEBUG - std::cerr << " request_id=" << (void*)request_id << ", tunnel_id=" << (void*)tunnel_id << std::endl ; -#endif - - if(data_size > rssize || rssize - data_size < offset) - throw std::runtime_error("RsTurtleTunnelOkItem::() wrong data_size (exceeds rssize).") ; - - data_bytes = rs_malloc(data_size) ; - - if(data_bytes != NULL) - { - memcpy(data_bytes,(void *)((uint8_t *)data+offset),data_size) ; - offset += data_size ; - } - else - offset = 0 ; // generate an error - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (offset != rssize) - throw std::runtime_error("RsTurtleTunnelOkItem::() error while deserializing.") ; - if (!ok) - throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ; -#endif -} - -bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id); - ok &= setRawUInt32(data, tlvsize, &offset, data_size); - - memcpy((void *)((uint8_t *)data+offset),data_bytes,data_size) ; - offset += data_size ; - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -// -----------------------------------------------------------------------------------// -// ------------------------------------- IO --------------------------------------- // -// -----------------------------------------------------------------------------------// -// -std::ostream& RsTurtleStringSearchRequestItem::print(std::ostream& o, uint16_t) -{ - o << "Search request (string):" << std::endl ; - o << " direct origin: \"" << PeerId() << "\"" << std::endl ; - o << " match string: \"" << match_string << "\"" << std::endl ; - o << " Req. Id: " << std::hex << request_id << std::dec << std::endl ; - o << " Depth : " << depth << std::endl ; - - return o ; -} -std::ostream& RsTurtleRegExpSearchRequestItem::print(std::ostream& o, uint16_t) -{ - o << "Search request (regexp):" << std::endl ; - o << " direct origin: \"" << PeerId() << "\"" << std::endl ; - o << " Req. Id: " << std::hex << request_id << std::dec << std::endl ; - o << " Depth : " << depth << std::endl ; - o << " RegExp: " << std::endl ; - o << " Toks: " ; for(unsigned int i=0;i::const_iterator it(result.begin());it!=result.end();++it) - o << " " << it->hash << " " << it->size << " " << it->name << std::endl ; - - return o ; -} - -std::ostream& RsTurtleOpenTunnelItem::print(std::ostream& o, uint16_t) -{ - o << "Open Tunnel:" << std::endl ; - - o << " Peer id : " << PeerId() << std::endl ; - o << " Partial tId: " << std::hex << partial_tunnel_id << std::dec << std::endl ; - o << " Req. Id : " << std::hex << request_id << std::dec << std::endl ; - o << " Depth : " << depth << std::endl ; - o << " Hash : " << file_hash << std::endl ; - - return o ; -} - -std::ostream& RsTurtleTunnelOkItem::print(std::ostream& o, uint16_t) -{ - o << "Tunnel Ok:" << std::endl ; - - o << " Peer id : " << PeerId() << std::endl ; - o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ; - o << " Req. Id : " << std::hex << request_id << std::dec << std::endl ; - - return o ; -} - -std::ostream& RsTurtleGenericDataItem::print(std::ostream& o, uint16_t) -{ - o << "Generic Data item:" << std::endl ; - - o << " Peer id : " << PeerId() << std::endl ; - o << " data size : " << data_size << std::endl ; - o << " data bytes: " << std::hex << (void*)data_bytes << std::dec << std::endl ; - - return o ; -} -#endif From e2d9152b226bc003d9c1d64d54ea7e9e96609f10 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 18 Apr 2017 21:11:37 +0200 Subject: [PATCH 027/106] moved converted serialisation files into new directory rsitems/, leaving serialiser/ for the serialisation classes --- libretroshare/src/chat/rschatitems.h | 2 +- libretroshare/src/file_sharing/p3filelists.cc | 2 +- .../src/file_sharing/rsfilelistitems.h | 2 +- libretroshare/src/ft/ftserver.cc | 4 +- .../src/ft/ftturtlefiletransferitem.cc | 542 +----------------- libretroshare/src/grouter/grouteritems.h | 2 +- .../src/gxstunnel/rsgxstunnelitems.h | 2 +- libretroshare/src/libretroshare.pro | 16 +- libretroshare/src/pqi/p3servicecontrol.cc | 2 +- .../{serialiser => rsitems}/itempriorities.h | 0 .../{serialiser => rsitems}/rsbanlistitems.cc | 2 +- .../{serialiser => rsitems}/rsbanlistitems.h | 2 +- .../{serialiser => rsitems}/rsbwctrlitems.cc | 2 +- .../{serialiser => rsitems}/rsbwctrlitems.h | 2 +- .../rsfiletransferitems.cc | 2 +- .../rsfiletransferitems.h | 2 +- .../{serialiser => rsitems}/rsserviceids.h | 0 .../src/serialiser/rsdiscovery2items.cc | 2 +- .../src/serialiser/rsdiscovery2items.h | 2 +- libretroshare/src/serialiser/rsdsdvitems.h | 2 +- .../src/serialiser/rsgxschannelitems.h | 2 +- .../src/serialiser/rsgxscircleitems.h | 2 +- .../src/serialiser/rsgxscommentitems.h | 2 +- .../src/serialiser/rsgxsforumitems.h | 2 +- libretroshare/src/serialiser/rsgxsiditems.h | 2 +- libretroshare/src/serialiser/rsgxsitems.h | 2 +- .../src/serialiser/rsgxsrecognitems.h | 2 +- .../src/serialiser/rsgxsreputationitems.h | 2 +- .../src/serialiser/rsgxsupdateitems.h | 2 +- .../src/serialiser/rsheartbeatitems.cc | 2 +- .../src/serialiser/rsheartbeatitems.h | 2 +- libretroshare/src/serialiser/rshistoryitems.h | 2 +- libretroshare/src/serialiser/rsmsgitems.h | 2 +- libretroshare/src/serialiser/rsnxsitems.h | 2 +- libretroshare/src/serialiser/rsphotoitems.h | 2 +- libretroshare/src/serialiser/rsposteditems.h | 2 +- libretroshare/src/serialiser/rsrttitems.h | 2 +- libretroshare/src/serialiser/rsserial.h | 2 +- .../src/serialiser/rsserviceinfoitems.h | 2 +- libretroshare/src/serialiser/rsstatusitems.h | 2 +- libretroshare/src/serialiser/rswikiitems.h | 2 +- libretroshare/src/serialiser/rswireitems.h | 2 +- libretroshare/src/services/p3banlist.cc | 2 +- libretroshare/src/services/p3banlist.h | 2 +- libretroshare/src/services/p3bwctrl.cc | 2 +- libretroshare/src/services/p3bwctrl.h | 2 +- libretroshare/src/services/p3serviceinfo.cc | 2 +- libretroshare/src/turtle/rsturtleitem.h | 2 +- plugins/FeedReader/FeedReaderPlugin.h | 2 +- .../FeedReader/services/rsFeedReaderItems.h | 2 +- plugins/VOIP/services/rsVOIPItems.h | 2 +- .../services/gxs/rsgxstestitems.h | 2 +- 52 files changed, 58 insertions(+), 598 deletions(-) rename libretroshare/src/{serialiser => rsitems}/itempriorities.h (100%) rename libretroshare/src/{serialiser => rsitems}/rsbanlistitems.cc (98%) rename libretroshare/src/{serialiser => rsitems}/rsbanlistitems.h (98%) rename libretroshare/src/{serialiser => rsitems}/rsbwctrlitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsbwctrlitems.h (98%) rename libretroshare/src/{serialiser => rsitems}/rsfiletransferitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsfiletransferitems.h (99%) rename libretroshare/src/{serialiser => rsitems}/rsserviceids.h (100%) diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 7771a375f..456ffe5b6 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -29,7 +29,7 @@ #include "retroshare/rstypes.h" #include "serialization/rsserializer.h" #include "serialiser/rstlvkeys.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 2c30b6813..492c37f67 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -22,7 +22,7 @@ * Please report all bugs and problems to "retroshare.project@gmail.com". * */ -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "file_sharing/p3filelists.h" #include "file_sharing/directory_storage.h" diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 8c1d466e1..d56827527 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -27,7 +27,7 @@ #include #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 5b04f2828..9dcc139d4 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -49,8 +49,8 @@ const int ftserverzone = 29539; #include "pqi/pqi.h" #include "pqi/p3linkmgr.h" -#include "serialiser/rsfiletransferitems.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsfiletransferitems.h" +#include "rsitems/rsserviceids.h" /*** * #define SERVER_DEBUG 1 diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.cc b/libretroshare/src/ft/ftturtlefiletransferitem.cc index 722991aef..5c343b7fa 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -27,557 +27,17 @@ #include #include -#include +#include #include #include -#ifdef TO_REMOVE -uint32_t RsTurtleFileRequestItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 8 ; // file offset - s += 4 ; // chunk size - - return s ; -} - -uint32_t RsTurtleFileDataItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 8 ; // file offset - s += 4 ; // chunk size - s += chunk_size ; // actual data size. - - return s ; -} - -uint32_t RsTurtleFileMapRequestItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 4 ; // direction - - return s ; -} - -uint32_t RsTurtleFileMapItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 4 ; // direction - s += 4 ; // compressed_map.size() - - s += 4 * compressed_map._map.size() ; - - return s ; -} - -uint32_t RsTurtleChunkCrcItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 4 ; // chunk number - s += check_sum.serial_size() ; // check_sum - - return s ; -} -uint32_t RsTurtleChunkCrcRequestItem::serial_size() const -{ - uint32_t s = 0 ; - - s += 8 ; // header - s += 4 ; // tunnel id - s += 4 ; // chunk number - - return s ; -} -#endif - void RsTurtleFileMapRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; } -#ifdef TO_REMOVE -bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id); - ok &= setRawUInt32(data, tlvsize, &offset, direction); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - - -bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id); - ok &= setRawUInt32(data, tlvsize, &offset, direction); - ok &= setRawUInt32(data, tlvsize, &offset, compressed_map._map.size()); - - for(uint32_t i=0;i pktsize) - ok = false ; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ; - ok &= getRawUInt64(data, pktsize, &offset, &chunk_offset); - ok &= getRawUInt32(data, pktsize, &offset, &chunk_size); - - if(chunk_size > rssize || rssize - chunk_size < offset) - throw std::runtime_error("RsTurtleFileDataItem::() error while deserializing.") ; - - chunk_data = (void*)rs_malloc(chunk_size) ; - - if(chunk_data == NULL) - throw std::runtime_error("RsTurtleFileDataItem::() cannot allocate memory.") ; - - memcpy(chunk_data,(void*)((unsigned char*)data+offset),chunk_size) ; - - offset += chunk_size ; - -#ifdef P3TURTLE_DEBUG - std::cerr << " tunnel_id=" << (void*)tunnel_id << ", chunk_offset=" << chunk_offset << ", chunk_size=" << chunk_size << std::endl ; -#endif - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (offset != rssize) - throw std::runtime_error("RsTurtleFileDataItem::() error while deserializing.") ; - if (!ok) - throw std::runtime_error("RsTurtleFileDataItem::() unknown error while deserializing.") ; -#endif -} - -bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize) const -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id) ; - ok &= setRawUInt64(data, tlvsize, &offset, chunk_offset); - ok &= setRawUInt32(data, tlvsize, &offset, chunk_size); - - memcpy((void*)((unsigned char*)data+offset),chunk_data,chunk_size) ; - offset += chunk_size ; - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} -std::ostream& RsTurtleFileRequestItem::print(std::ostream& o, uint16_t) -{ - o << "File request item:" << std::endl ; - - o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ; - o << " offset : " << chunk_offset << std::endl ; - o << " chunk size: " << chunk_size << std::endl ; - - return o ; -} - -std::ostream& RsTurtleFileDataItem::print(std::ostream& o, uint16_t) -{ - o << "File request item:" << std::endl ; - - o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ; - o << " offset : " << chunk_offset << std::endl ; - o << " chunk size: " << chunk_size << std::endl ; - o << " data : " << std::hex << chunk_data << std::dec << std::endl ; - - return o ; -} - -std::ostream& RsTurtleFileMapItem::print(std::ostream& o, uint16_t) -{ - o << "File map item:" << std::endl ; - - o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ; - o << " direction : " << direction << std::endl ; - o << " map : " ; - - for(uint32_t i=0;i(j,ctx,tunnel_id,"tunnel_id") ; diff --git a/libretroshare/src/grouter/grouteritems.h b/libretroshare/src/grouter/grouteritems.h index a0c3dd9e7..af78866c0 100644 --- a/libretroshare/src/grouter/grouteritems.h +++ b/libretroshare/src/grouter/grouteritems.h @@ -29,7 +29,7 @@ #include "serialiser/rsserial.h" #include "serialiser/rstlvkeys.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "retroshare/rstypes.h" #include "retroshare/rsgrouter.h" diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.h b/libretroshare/src/gxstunnel/rsgxstunnelitems.h index c23a8b9a1..ad049a753 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.h +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.h @@ -29,7 +29,7 @@ #include "retroshare/rstypes.h" #include "serialiser/rstlvkeys.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 1b437282c..2d7a966e9 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -452,15 +452,15 @@ HEADERS += grouter/groutercache.h \ grouter/groutertypes.h \ grouter/rsgrouterclient.h -HEADERS += serialiser/itempriorities.h \ +HEADERS += rsitems/itempriorities.h \ serialiser/rsbaseserial.h \ - serialiser/rsfiletransferitems.h \ + rsitems/rsfiletransferitems.h \ serialiser/rsserviceserialiser.h \ serialiser/rsconfigitems.h \ serialiser/rshistoryitems.h \ serialiser/rsmsgitems.h \ serialiser/rsserial.h \ - serialiser/rsserviceids.h \ + rsitems/rsserviceids.h \ serialiser/rsserviceitems.h \ serialiser/rsstatusitems.h \ serialiser/rstlvaddrs.h \ @@ -479,8 +479,8 @@ HEADERS += serialiser/itempriorities.h \ serialiser/rstlvlist.h \ serialiser/rstlvmaps.h \ serialiser/rstlvbanlist.h \ - serialiser/rsbanlistitems.h \ - serialiser/rsbwctrlitems.h \ + rsitems/rsbanlistitems.h \ + rsitems/rsbwctrlitems.h \ serialiser/rsdiscovery2items.h \ serialiser/rsheartbeatitems.h \ serialiser/rsrttitems.h \ @@ -608,7 +608,7 @@ SOURCES += plugins/pluginmanager.cc \ serialiser/rspluginitems.cc SOURCES += serialiser/rsbaseserial.cc \ - serialiser/rsfiletransferitems.cc \ + rsitems/rsfiletransferitems.cc \ serialiser/rsserviceserialiser.cc \ serialiser/rsconfigitems.cc \ serialiser/rshistoryitems.cc \ @@ -627,8 +627,8 @@ SOURCES += serialiser/rsbaseserial.cc \ serialiser/rstlvkeyvalue.cc \ serialiser/rstlvgenericparam.cc \ serialiser/rstlvbanlist.cc \ - serialiser/rsbanlistitems.cc \ - serialiser/rsbwctrlitems.cc \ + rsitems/rsbanlistitems.cc \ + rsitems/rsbwctrlitems.cc \ serialiser/rsdiscovery2items.cc \ serialiser/rsheartbeatitems.cc \ serialiser/rsrttitems.cc \ diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index a397a4e1c..f22cc44c0 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -26,7 +26,7 @@ #include #include "p3servicecontrol.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rsbaseserial.h" #include "pqi/p3cfgmgr.h" diff --git a/libretroshare/src/serialiser/itempriorities.h b/libretroshare/src/rsitems/itempriorities.h similarity index 100% rename from libretroshare/src/serialiser/itempriorities.h rename to libretroshare/src/rsitems/itempriorities.h diff --git a/libretroshare/src/serialiser/rsbanlistitems.cc b/libretroshare/src/rsitems/rsbanlistitems.cc similarity index 98% rename from libretroshare/src/serialiser/rsbanlistitems.cc rename to libretroshare/src/rsitems/rsbanlistitems.cc index c28399e34..d597abcfd 100644 --- a/libretroshare/src/serialiser/rsbanlistitems.cc +++ b/libretroshare/src/rsitems/rsbanlistitems.cc @@ -24,7 +24,7 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsbanlistitems.h" +#include "rsitems/rsbanlistitems.h" #include "serialization/rstypeserializer.h" diff --git a/libretroshare/src/serialiser/rsbanlistitems.h b/libretroshare/src/rsitems/rsbanlistitems.h similarity index 98% rename from libretroshare/src/serialiser/rsbanlistitems.h rename to libretroshare/src/rsitems/rsbanlistitems.h index 57263a356..cc3f96eeb 100644 --- a/libretroshare/src/serialiser/rsbanlistitems.h +++ b/libretroshare/src/rsitems/rsbanlistitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rstlvbanlist.h" #include "serialization/rsserializer.h" diff --git a/libretroshare/src/serialiser/rsbwctrlitems.cc b/libretroshare/src/rsitems/rsbwctrlitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsbwctrlitems.cc rename to libretroshare/src/rsitems/rsbwctrlitems.cc index 092b1d643..747dbbbda 100644 --- a/libretroshare/src/serialiser/rsbwctrlitems.cc +++ b/libretroshare/src/rsitems/rsbwctrlitems.cc @@ -24,7 +24,7 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsbwctrlitems.h" +#include "rsitems/rsbwctrlitems.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/serialiser/rsbwctrlitems.h b/libretroshare/src/rsitems/rsbwctrlitems.h similarity index 98% rename from libretroshare/src/serialiser/rsbwctrlitems.h rename to libretroshare/src/rsitems/rsbwctrlitems.h index 07907c709..e9262cd5b 100644 --- a/libretroshare/src/serialiser/rsbwctrlitems.h +++ b/libretroshare/src/rsitems/rsbwctrlitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" diff --git a/libretroshare/src/serialiser/rsfiletransferitems.cc b/libretroshare/src/rsitems/rsfiletransferitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsfiletransferitems.cc rename to libretroshare/src/rsitems/rsfiletransferitems.cc index 3eb7c1147..acdadaff2 100644 --- a/libretroshare/src/serialiser/rsfiletransferitems.cc +++ b/libretroshare/src/rsitems/rsfiletransferitems.cc @@ -26,7 +26,7 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" -#include "serialiser/rsfiletransferitems.h" +#include "rsitems/rsfiletransferitems.h" #include "serialization/rstypeserializer.h" diff --git a/libretroshare/src/serialiser/rsfiletransferitems.h b/libretroshare/src/rsitems/rsfiletransferitems.h similarity index 99% rename from libretroshare/src/serialiser/rsfiletransferitems.h rename to libretroshare/src/rsitems/rsfiletransferitems.h index ae1835126..5cfed03b9 100644 --- a/libretroshare/src/serialiser/rsfiletransferitems.h +++ b/libretroshare/src/rsitems/rsfiletransferitems.h @@ -30,7 +30,7 @@ #include "retroshare/rstypes.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvfileitem.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialization/rsserializer.h" diff --git a/libretroshare/src/serialiser/rsserviceids.h b/libretroshare/src/rsitems/rsserviceids.h similarity index 100% rename from libretroshare/src/serialiser/rsserviceids.h rename to libretroshare/src/rsitems/rsserviceids.h diff --git a/libretroshare/src/serialiser/rsdiscovery2items.cc b/libretroshare/src/serialiser/rsdiscovery2items.cc index 611a7e80a..90b4313b3 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.cc +++ b/libretroshare/src/serialiser/rsdiscovery2items.cc @@ -29,7 +29,7 @@ #if 0 -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsdiscovery2items.h b/libretroshare/src/serialiser/rsdiscovery2items.h index dad0d0fb5..26bbf1f22 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.h +++ b/libretroshare/src/serialiser/rsdiscovery2items.h @@ -31,7 +31,7 @@ #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" #include "serialiser/rstlvaddrs.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01; const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02; diff --git a/libretroshare/src/serialiser/rsdsdvitems.h b/libretroshare/src/serialiser/rsdsdvitems.h index efafa1f4b..fd03be486 100644 --- a/libretroshare/src/serialiser/rsdsdvitems.h +++ b/libretroshare/src/serialiser/rsdsdvitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvbinary.h" diff --git a/libretroshare/src/serialiser/rsgxschannelitems.h b/libretroshare/src/serialiser/rsgxschannelitems.h index f7386b93d..9a937e581 100644 --- a/libretroshare/src/serialiser/rsgxschannelitems.h +++ b/libretroshare/src/serialiser/rsgxschannelitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" #include "serialiser/rstlvfileitem.h" diff --git a/libretroshare/src/serialiser/rsgxscircleitems.h b/libretroshare/src/serialiser/rsgxscircleitems.h index 4ae4e7109..84316b133 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.h +++ b/libretroshare/src/serialiser/rsgxscircleitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvitem.h" #include "serialiser/rstlvstring.h" diff --git a/libretroshare/src/serialiser/rsgxscommentitems.h b/libretroshare/src/serialiser/rsgxscommentitems.h index 6f5d1bddd..2ccd6d5d8 100644 --- a/libretroshare/src/serialiser/rsgxscommentitems.h +++ b/libretroshare/src/serialiser/rsgxscommentitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsgxsforumitems.h b/libretroshare/src/serialiser/rsgxsforumitems.h index f4bce076d..97f6dd89b 100644 --- a/libretroshare/src/serialiser/rsgxsforumitems.h +++ b/libretroshare/src/serialiser/rsgxsforumitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsgxsiditems.h b/libretroshare/src/serialiser/rsgxsiditems.h index 483916055..39ca6882a 100644 --- a/libretroshare/src/serialiser/rsgxsiditems.h +++ b/libretroshare/src/serialiser/rsgxsiditems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "rsgxsitems.h" diff --git a/libretroshare/src/serialiser/rsgxsitems.h b/libretroshare/src/serialiser/rsgxsitems.h index 4e46a39a4..ed6d3124d 100644 --- a/libretroshare/src/serialiser/rsgxsitems.h +++ b/libretroshare/src/serialiser/rsgxsitems.h @@ -26,7 +26,7 @@ * */ -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" //#include "serialiser/rstlvkeys.h" diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.h b/libretroshare/src/serialiser/rsgxsrecognitems.h index a8aad7c31..6d0ea0ae6 100644 --- a/libretroshare/src/serialiser/rsgxsrecognitems.h +++ b/libretroshare/src/serialiser/rsgxsrecognitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvkeys.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.h b/libretroshare/src/serialiser/rsgxsreputationitems.h index 0fdc40ee2..9d5383343 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.h +++ b/libretroshare/src/serialiser/rsgxsreputationitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" #include "retroshare/rsgxsifacetypes.h" diff --git a/libretroshare/src/serialiser/rsgxsupdateitems.h b/libretroshare/src/serialiser/rsgxsupdateitems.h index b7d6f324c..7d6c89907 100644 --- a/libretroshare/src/serialiser/rsgxsupdateitems.h +++ b/libretroshare/src/serialiser/rsgxsupdateitems.h @@ -30,7 +30,7 @@ #if 0 #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsheartbeatitems.cc b/libretroshare/src/serialiser/rsheartbeatitems.cc index 55f1e844a..0151525a2 100644 --- a/libretroshare/src/serialiser/rsheartbeatitems.cc +++ b/libretroshare/src/serialiser/rsheartbeatitems.cc @@ -25,7 +25,7 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsheartbeatitems.h" /*** diff --git a/libretroshare/src/serialiser/rsheartbeatitems.h b/libretroshare/src/serialiser/rsheartbeatitems.h index cfabae2ee..5660ba373 100644 --- a/libretroshare/src/serialiser/rsheartbeatitems.h +++ b/libretroshare/src/serialiser/rsheartbeatitems.h @@ -29,7 +29,7 @@ #define RS_HEARTBEAT_ITEMS_H #include "serialiser/rsserial.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01; diff --git a/libretroshare/src/serialiser/rshistoryitems.h b/libretroshare/src/serialiser/rshistoryitems.h index 039bf095f..72f186561 100644 --- a/libretroshare/src/serialiser/rshistoryitems.h +++ b/libretroshare/src/serialiser/rshistoryitems.h @@ -26,7 +26,7 @@ * */ -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "retroshare/rstypes.h" diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 1a7e84cd0..0d44aa501 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -30,7 +30,7 @@ #include "retroshare/rstypes.h" #include "serialiser/rstlvkeys.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/serialiser/rsnxsitems.h b/libretroshare/src/serialiser/rsnxsitems.h index 88f0ca914..259c560a6 100644 --- a/libretroshare/src/serialiser/rsnxsitems.h +++ b/libretroshare/src/serialiser/rsnxsitems.h @@ -30,7 +30,7 @@ #include #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" diff --git a/libretroshare/src/serialiser/rsphotoitems.h b/libretroshare/src/serialiser/rsphotoitems.h index 40fa8b32b..a935472e6 100644 --- a/libretroshare/src/serialiser/rsphotoitems.h +++ b/libretroshare/src/serialiser/rsphotoitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "rsgxsitems.h" diff --git a/libretroshare/src/serialiser/rsposteditems.h b/libretroshare/src/serialiser/rsposteditems.h index 6fa08f203..a303f0d33 100644 --- a/libretroshare/src/serialiser/rsposteditems.h +++ b/libretroshare/src/serialiser/rsposteditems.h @@ -1,7 +1,7 @@ #ifndef RSPOSTEDITEMS_H #define RSPOSTEDITEMS_H -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsrttitems.h b/libretroshare/src/serialiser/rsrttitems.h index 2ebbbb51b..11a6b8889 100644 --- a/libretroshare/src/serialiser/rsrttitems.h +++ b/libretroshare/src/serialiser/rsrttitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 21e0fcec7..ffa9bb855 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -60,7 +60,7 @@ ******************************************************************/ #include -#include "itempriorities.h" +#include "rsitems/itempriorities.h" const uint8_t RS_PKT_VERSION1 = 0x01; const uint8_t RS_PKT_VERSION_SERVICE = 0x02; diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.h b/libretroshare/src/serialiser/rsserviceinfoitems.h index 295ca4f6b..76b451cce 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.h +++ b/libretroshare/src/serialiser/rsserviceinfoitems.h @@ -30,7 +30,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvgenericmap.h" diff --git a/libretroshare/src/serialiser/rsstatusitems.h b/libretroshare/src/serialiser/rsstatusitems.h index 8677c2be0..c6cc0c8b2 100644 --- a/libretroshare/src/serialiser/rsstatusitems.h +++ b/libretroshare/src/serialiser/rsstatusitems.h @@ -26,7 +26,7 @@ * */ -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rswikiitems.h b/libretroshare/src/serialiser/rswikiitems.h index e45eab729..4247f9d3b 100644 --- a/libretroshare/src/serialiser/rswikiitems.h +++ b/libretroshare/src/serialiser/rswikiitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rswireitems.h b/libretroshare/src/serialiser/rswireitems.h index 72d1732a6..77258707a 100644 --- a/libretroshare/src/serialiser/rswireitems.h +++ b/libretroshare/src/serialiser/rswireitems.h @@ -28,7 +28,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/services/p3banlist.cc b/libretroshare/src/services/p3banlist.cc index 157cc23f8..bf72ea815 100644 --- a/libretroshare/src/services/p3banlist.cc +++ b/libretroshare/src/services/p3banlist.cc @@ -30,7 +30,7 @@ #include "util/rsnet.h" #include "services/p3banlist.h" -#include "serialiser/rsbanlistitems.h" +#include "rsitems/rsbanlistitems.h" #include "serialiser/rsconfigitems.h" #include "retroshare/rsdht.h" #include "retroshare/rsbanlist.h" diff --git a/libretroshare/src/services/p3banlist.h b/libretroshare/src/services/p3banlist.h index 87bb7104a..7cdc983a5 100644 --- a/libretroshare/src/services/p3banlist.h +++ b/libretroshare/src/services/p3banlist.h @@ -31,7 +31,7 @@ #include #include -#include "serialiser/rsbanlistitems.h" +#include "rsitems/rsbanlistitems.h" #include "services/p3service.h" #include "retroshare/rsbanlist.h" diff --git a/libretroshare/src/services/p3bwctrl.cc b/libretroshare/src/services/p3bwctrl.cc index 1cf4da87f..aa9106e47 100644 --- a/libretroshare/src/services/p3bwctrl.cc +++ b/libretroshare/src/services/p3bwctrl.cc @@ -30,7 +30,7 @@ #include "util/rsnet.h" #include "services/p3bwctrl.h" -#include "serialiser/rsbwctrlitems.h" +#include "rsitems/rsbwctrlitems.h" #include diff --git a/libretroshare/src/services/p3bwctrl.h b/libretroshare/src/services/p3bwctrl.h index 94c746aa8..9e80bb188 100644 --- a/libretroshare/src/services/p3bwctrl.h +++ b/libretroshare/src/services/p3bwctrl.h @@ -31,7 +31,7 @@ #include #include -#include "serialiser/rsbwctrlitems.h" +#include "rsitems/rsbwctrlitems.h" #include "services/p3service.h" #include "pqi/pqiservicemonitor.h" #include "retroshare/rsconfig.h" // for datatypes. diff --git a/libretroshare/src/services/p3serviceinfo.cc b/libretroshare/src/services/p3serviceinfo.cc index 0965914e0..0782016a1 100644 --- a/libretroshare/src/services/p3serviceinfo.cc +++ b/libretroshare/src/services/p3serviceinfo.cc @@ -29,7 +29,7 @@ #include "util/rsnet.h" #include "services/p3serviceinfo.h" -#include "serialiser/rsbanlistitems.h" +#include "rsitems/rsbanlistitems.h" #include diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 95594761b..0249cce22 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -6,7 +6,7 @@ #include "retroshare/rsturtle.h" #include "retroshare/rsexpr.h" #include "retroshare/rstypes.h" -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "turtle/turtletypes.h" #include "serialization/rsserializer.h" diff --git a/plugins/FeedReader/FeedReaderPlugin.h b/plugins/FeedReader/FeedReaderPlugin.h index 9a27d9243..12b45db20 100644 --- a/plugins/FeedReader/FeedReaderPlugin.h +++ b/plugins/FeedReader/FeedReaderPlugin.h @@ -21,7 +21,7 @@ #pragma once -#include +#include #include #include #include "services/p3FeedReader.h" diff --git a/plugins/FeedReader/services/rsFeedReaderItems.h b/plugins/FeedReader/services/rsFeedReaderItems.h index 14f6d0e6e..da4e4fa72 100644 --- a/plugins/FeedReader/services/rsFeedReaderItems.h +++ b/plugins/FeedReader/services/rsFeedReaderItems.h @@ -22,7 +22,7 @@ #ifndef RS_FEEDREADER_ITEMS_H #define RS_FEEDREADER_ITEMS_H -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvstring.h" diff --git a/plugins/VOIP/services/rsVOIPItems.h b/plugins/VOIP/services/rsVOIPItems.h index 7d083fde5..a685f9ef6 100644 --- a/plugins/VOIP/services/rsVOIPItems.h +++ b/plugins/VOIP/services/rsVOIPItems.h @@ -48,7 +48,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" /**************************************************************************/ diff --git a/tests/unittests/libretroshare/services/gxs/rsgxstestitems.h b/tests/unittests/libretroshare/services/gxs/rsgxstestitems.h index 8a367cfc3..78379436f 100644 --- a/tests/unittests/libretroshare/services/gxs/rsgxstestitems.h +++ b/tests/unittests/libretroshare/services/gxs/rsgxstestitems.h @@ -27,7 +27,7 @@ #include -#include "serialiser/rsserviceids.h" +#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rsgxsitems.h" From 782c02744f96e34fad0beeef939fc1f744b86426 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Apr 2017 16:00:01 +0200 Subject: [PATCH 028/106] added names for turtle sub items --- libretroshare/src/turtle/p3turtle.cc | 17 +++++++++++++++++ libretroshare/src/turtle/p3turtle.h | 2 ++ libretroshare/src/turtle/rsturtleitem.h | 4 ---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 997fe0e7e..4064a7a3e 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -144,6 +144,23 @@ RsServiceInfo p3turtle::getServiceInfo() TURTLE_MIN_MINOR_VERSION); } +void p3turtle::getItemNames(std::map& names) const +{ + names.clear(); + + names[RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST ] = "Search request"; + names[RS_TURTLE_SUBTYPE_SEARCH_RESULT ] = "Search result"; + names[RS_TURTLE_SUBTYPE_OPEN_TUNNEL ] = "Tunnel request"; + names[RS_TURTLE_SUBTYPE_TUNNEL_OK ] = "Tunnel response"; + names[RS_TURTLE_SUBTYPE_FILE_REQUEST ] = "Data request"; + names[RS_TURTLE_SUBTYPE_FILE_DATA ] = "Data chunk"; + names[RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST ] = "RegExp search"; + names[RS_TURTLE_SUBTYPE_GENERIC_DATA ] = "Generic data"; + names[RS_TURTLE_SUBTYPE_FILE_MAP ] = "Chunk map"; + names[RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST ] = "Chunk map request"; + names[RS_TURTLE_SUBTYPE_CHUNK_CRC ] = "Chunk CRC"; + names[RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST ] = "Chunk CRC request"; +} void p3turtle::setEnabled(bool b) { diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index d9d51456b..36324f941 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -293,6 +293,8 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config /// virtual int tick(); + virtual void getItemNames(std::map& names) const; + /************* from p3Config *******************/ virtual RsSerialiser *setupSerialiser() ; virtual bool saveList(bool& cleanup, std::list&) ; diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 5b15f7781..bbe587396 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -13,16 +13,12 @@ const uint8_t RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST = 0x01 ; const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ; const uint8_t RS_TURTLE_SUBTYPE_OPEN_TUNNEL = 0x03 ; const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_OK = 0x04 ; -const uint8_t RS_TURTLE_SUBTYPE_CLOSE_TUNNEL = 0x05 ; -const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_CLOSED = 0x06 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_REQUEST = 0x07 ; const uint8_t RS_TURTLE_SUBTYPE_FILE_DATA = 0x08 ; 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 ; From 311f257090ab6027e629357c6927d5f4e7e29ecb Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Apr 2017 21:10:55 +0200 Subject: [PATCH 029/106] converted GxsReputationItems to new serialization --- .../src/serialiser/rsgxsreputationitems.cc | 91 +++++++++++++------ .../src/serialiser/rsgxsreputationitems.h | 65 ++++--------- .../src/serialization/rstypeserializer.h | 71 +++++++++++++++ libretroshare/src/services/p3gxsreputation.cc | 5 +- libretroshare/src/services/p3gxsreputation.h | 2 + 5 files changed, 156 insertions(+), 78 deletions(-) diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.cc b/libretroshare/src/serialiser/rsgxsreputationitems.cc index 5701cc756..e5240d91d 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.cc +++ b/libretroshare/src/serialiser/rsgxsreputationitems.cc @@ -28,40 +28,14 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rsgxsreputationitems.h" +#include "serialization/rstypeserializer.h" + /*** #define RSSERIAL_DEBUG 1 ***/ #include -// re-defined here, in order to avoid cross-includes -#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100 - -/*************************************************************************/ - -bool RsReputationItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsReputationItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsReputationItem::serialise() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; -} - /*************************************************************************/ void RsGxsReputationSetItem::clear() @@ -79,6 +53,45 @@ void RsGxsReputationBannedNodeSetItem::clear() mKnownIdentities.TlvClear(); } +void RsGxsReputationConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ; + RsTypeSerializer::serial_process(j,ctx,mLatestUpdate,"mLatestUpdate") ; + RsTypeSerializer::serial_process(j,ctx,mLastQuery,"mLastQuery") ; +} + +void RsGxsReputationBannedNodeSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ; + RsTypeSerializer::serial_process (j,ctx,mLastActivityTS,"mLastActivityTS") ; + RsTypeSerializer::serial_process(j,ctx,mKnownIdentities,"mKnownIdentities") ; +} + +void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ; + RsTypeSerializer::serial_process(j,ctx,mOwnOpinion,"mOwnOpinion") ; + RsTypeSerializer::serial_process(j,ctx,mOwnOpinionTS,"mOwnOpinionTS") ; + RsTypeSerializer::serial_process(j,ctx,mIdentityFlags,"mIdentityFlags") ; + RsTypeSerializer::serial_process(j,ctx,mLastUsedTS,"mLastUsedTS") ; + RsTypeSerializer::serial_process (j,ctx,mOwnerNodeId,"mOwnerNodeId") ; + RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; +} + +void RsGxsReputationUpdateItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mLatestUpdate,"mLatestUpdate") ; + RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; +} +void RsGxsReputationRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mLastUpdate,"mLastUpdate") ; +} + +#ifdef TO_REMOVE +// re-defined here, in order to avoid cross-includes +#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100 + /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ @@ -360,6 +373,7 @@ RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfi return item; } + RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size) { uint32_t offset = 8; // skip the header @@ -382,6 +396,8 @@ RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputati return item; } + + RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize) { uint32_t offset = 8; // skip the header @@ -502,6 +518,7 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem( return item; } + RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize) { uint32_t offset = 8; // skip the header @@ -559,6 +576,7 @@ RsGxsReputationRequestItem *RsGxsReputationSerialiser::deserialiseReputationRequ return item; } + /*************************************************************************/ RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize) @@ -587,8 +605,25 @@ RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize) break; } } +#endif /*************************************************************************/ +RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const +{ + if(service != RS_SERVICE_GXS_TYPE_REPUTATION) + return NULL ; + switch(subtype) + { + case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return new RsGxsReputationSetItem() ; + case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM : return new RsGxsReputationBannedNodeSetItem(); + case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return new RsGxsReputationUpdateItem(); + case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return new RsGxsReputationRequestItem() ; + case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return new RsGxsReputationConfigItem () ; + default: + std::cerr << "(EE) RsGxsReputationSerialiser::create_item(): unhandled item type " << subtype << std::endl; + return NULL ; + } +} diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.h b/libretroshare/src/serialiser/rsgxsreputationitems.h index 9d5383343..cc3f64a78 100644 --- a/libretroshare/src/serialiser/rsgxsreputationitems.h +++ b/libretroshare/src/serialiser/rsgxsreputationitems.h @@ -34,6 +34,8 @@ #include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsreputations.h" +#include "serialization/rsserializer.h" + #define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01 #define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02 #define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03 @@ -53,15 +55,7 @@ class RsReputationItem: public RsItem } virtual ~RsReputationItem() {} - - virtual bool serialise(void *data,uint32_t& size) const = 0 ; - virtual uint32_t serial_size() const = 0 ; - virtual void clear() = 0 ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0; - - protected: - bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) const; }; class RsGxsReputationConfigItem: public RsReputationItem @@ -71,16 +65,15 @@ public: virtual ~RsGxsReputationConfigItem() {} virtual void clear() {} - std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; - + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + RsPeerId mPeerId; uint32_t mLatestUpdate; // timestamp they returned. uint32_t mLastQuery; // when we sent out. }; +#ifdef TO_REMOVE // This class should disappear. Deprecated since Jan 7, 2017. The class definition is actually not needed, // that is why it's commented out. Kept here in order to explains how the deserialisation works. // @@ -91,10 +84,8 @@ public: virtual ~RsGxsReputationSetItem_deprecated3() {} virtual void clear() {} - std::ostream &print(std::ostream &out, uint16_t /*indent*/ = 0) { return out;} - virtual bool serialise(void */*data*/,uint32_t& /*size*/) const { return false ;} - virtual uint32_t serial_size() const { return 0;} + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; RsGxsId mGxsId; uint32_t mOwnOpinion; @@ -103,6 +94,8 @@ public: RsPgpId mOwnerNodeId; std::map mOpinions; // RsPeerId -> Opinion. }; +#endif + class RsGxsReputationSetItem: public RsReputationItem { public: @@ -116,10 +109,8 @@ public: virtual ~RsGxsReputationSetItem() {} virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; RsGxsId mGxsId; uint32_t mOwnOpinion; @@ -136,10 +127,8 @@ public: virtual ~RsGxsReputationBannedNodeSetItem() {} virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; RsPgpId mPgpId ; uint32_t mLastActivityTS ; @@ -153,12 +142,10 @@ public: virtual ~RsGxsReputationUpdateItem() {} virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; - uint32_t mLatestUpdate; + uint32_t mLatestUpdate; std::map mOpinions; // GxsId -> Opinion. }; @@ -169,40 +156,20 @@ public: virtual ~RsGxsReputationRequestItem() {} virtual void clear() {} - std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; uint32_t mLastUpdate; }; -class RsGxsReputationSerialiser: public RsSerialType +class RsGxsReputationSerialiser: public RsSerializer { public: - RsGxsReputationSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION){} - + RsGxsReputationSerialiser() :RsSerializer(RS_SERVICE_GXS_TYPE_REPUTATION){} virtual ~RsGxsReputationSerialiser(){} - virtual uint32_t size(RsItem *item) - { - return dynamic_cast(item)->serial_size() ; - } - virtual bool serialise (RsItem *item, void *data, uint32_t *size) - { - return dynamic_cast(item)->serialise(data,*size) ; - } - virtual RsItem * deserialise(void *data, uint32_t *size); - -private: - static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size); - static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size); - static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (void *data, uint32_t size); - static RsGxsReputationSetItem_deprecated3 *deserialiseReputationSetItem_deprecated3 (void *data, uint32_t size); - static RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size); - static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size); - static RsGxsReputationBannedNodeSetItem *deserialiseReputationBannedNodeSetItem (void *data, uint32_t size); + virtual RsItem *create_item(uint16_t service,uint8_t item_type) const; }; /**************************************************************************/ diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 403219ecb..1899a26fe 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -85,6 +85,77 @@ class RsTypeSerializer throw std::runtime_error("Unknown serial job") ; } } + //=================================================================================================// + // std::map // + //=================================================================================================// + + template + static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::map& v,const std::string& member_name) + { + switch(j) + { + case RsItem::SIZE_ESTIMATE: + { + ctx.mOffset += 4 ; + for(typename std::map::iterator it(v.begin());it!=v.end();++it) + { + ctx.mOffset += serial_size(it->first) ; + ctx.mOffset += serial_size(it->second) ; + } + } + break ; + + case RsItem::DESERIALIZE: + { + uint32_t n=0 ; + ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; + + for(uint32_t i=0;i(ctx.mData,ctx.mSize,ctx.mOffset,n) ; + + for(typename std::map::iterator it(v.begin());it!=v.end();++it) + { + ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,it->first) ; + ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,it->second) ; + } + } + break ; + + case RsItem::PRINT: + { + if(v.empty()) + std::cerr << " Empty map"<< std::endl; + else + std::cerr << " std::map of " << v.size() << " elements:" << std::endl; + + for(typename std::map::iterator it(v.begin());it!=v.end();++it) + { + std::cerr << " " ; + + print_data("first",it->first) ; + print_data("second",it->second) ; + } + } + break; + default: + break; + } + } //=================================================================================================// // std::vector // diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index 45fd95898..cf956c0d8 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -1210,6 +1210,7 @@ bool p3GxsReputation::loadList(std::list& loadList) if (set) loadReputationSet(set, peerSet); +#ifdef TO_REMOVE RsGxsReputationSetItem_deprecated3 *set2 = dynamic_cast(*it); if(set2) @@ -1217,6 +1218,7 @@ bool p3GxsReputation::loadList(std::list& loadList) std::cerr << "(II) reading and converting old format ReputationSetItem." << std::endl; loadReputationSet_deprecated3(set2, peerSet); } +#endif RsGxsReputationBannedNodeSetItem *itm2 = dynamic_cast(*it) ; @@ -1274,6 +1276,7 @@ bool p3GxsReputation::loadList(std::list& loadList) loadList.clear() ; return true; } +#ifdef TO_REMOVE bool p3GxsReputation::loadReputationSet_deprecated3(RsGxsReputationSetItem_deprecated3 *item, const std::set &peerSet) { { @@ -1324,7 +1327,7 @@ bool p3GxsReputation::loadReputationSet_deprecated3(RsGxsReputationSetItem_depre #endif return true; } - +#endif bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std::set &peerSet) { diff --git a/libretroshare/src/services/p3gxsreputation.h b/libretroshare/src/services/p3gxsreputation.h index baabdaa43..fdfd8ac54 100644 --- a/libretroshare/src/services/p3gxsreputation.h +++ b/libretroshare/src/services/p3gxsreputation.h @@ -156,7 +156,9 @@ private: // internal update of data. Takes care of cleaning empty boxes. void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op); bool loadReputationSet(RsGxsReputationSetItem *item, const std::set &peerSet); +#ifdef TO_REMOVE bool loadReputationSet_deprecated3(RsGxsReputationSetItem_deprecated3 *item, const std::set &peerSet); +#endif int sendPackets(); void cleanup(); void sendReputationRequests(); From bef6db4b4362d49f38893c522cc72b7bb9b6bfa5 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Apr 2017 21:32:57 +0200 Subject: [PATCH 030/106] moved files --- libretroshare/src/{serialiser => rsitems}/rsgxsreputationitems.cc | 0 libretroshare/src/{serialiser => rsitems}/rsgxsreputationitems.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsgxsreputationitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxsreputationitems.h (100%) diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsgxsreputationitems.cc rename to libretroshare/src/rsitems/rsgxsreputationitems.cc diff --git a/libretroshare/src/serialiser/rsgxsreputationitems.h b/libretroshare/src/rsitems/rsgxsreputationitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxsreputationitems.h rename to libretroshare/src/rsitems/rsgxsreputationitems.h From 2e7127077dab71675431e9826e494cff1cfc396d Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Apr 2017 21:36:39 +0200 Subject: [PATCH 031/106] fixed previous file move --- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/rsitems/rsgxsreputationitems.cc | 2 +- libretroshare/src/services/p3gxsreputation.cc | 2 +- libretroshare/src/services/p3gxsreputation.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 2d7a966e9..16aba6778 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -784,12 +784,12 @@ HEADERS += retroshare/rsidentity.h \ services/p3idservice.h \ serialiser/rsgxsiditems.h \ services/p3gxsreputation.h \ - serialiser/rsgxsreputationitems.h \ + rsitems/rsgxsreputationitems.h \ SOURCES += services/p3idservice.cc \ serialiser/rsgxsiditems.cc \ services/p3gxsreputation.cc \ - serialiser/rsgxsreputationitems.cc \ + rsitems/rsgxsreputationitems.cc \ # GxsCircles Service HEADERS += services/p3gxscircles.h \ diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc index e5240d91d..11e267654 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.cc +++ b/libretroshare/src/rsitems/rsgxsreputationitems.cc @@ -26,7 +26,7 @@ #include #include #include "serialiser/rsbaseserial.h" -#include "serialiser/rsgxsreputationitems.h" +#include "rsitems/rsgxsreputationitems.h" #include "serialization/rstypeserializer.h" diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index cf956c0d8..609382444 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -29,7 +29,7 @@ #include "retroshare/rspeers.h" #include "services/p3gxsreputation.h" -#include "serialiser/rsgxsreputationitems.h" +#include "rsitems/rsgxsreputationitems.h" #include "serialiser/rsconfigitems.h" #include diff --git a/libretroshare/src/services/p3gxsreputation.h b/libretroshare/src/services/p3gxsreputation.h index fdfd8ac54..06ff7415b 100644 --- a/libretroshare/src/services/p3gxsreputation.h +++ b/libretroshare/src/services/p3gxsreputation.h @@ -36,7 +36,7 @@ static const uint32_t REPUTATION_IDENTITY_FLAG_UP_TO_DATE = 0x0100; // This static const uint32_t REPUTATION_IDENTITY_FLAG_PGP_LINKED = 0x0001; static const uint32_t REPUTATION_IDENTITY_FLAG_PGP_KNOWN = 0x0002; -#include "serialiser/rsgxsreputationitems.h" +#include "rsitems/rsgxsreputationitems.h" #include "retroshare/rsidentity.h" #include "retroshare/rsreputations.h" From 9d9ff567bbe4611b36bc0bd46537c9a70b5e2303 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 23 Apr 2017 19:02:12 +0200 Subject: [PATCH 032/106] switched discovery2items to new serialization --- .../src/serialiser/rsdiscovery2items.cc | 179 ++++++++++++------ .../src/serialiser/rsdiscovery2items.h | 84 +++----- 2 files changed, 149 insertions(+), 114 deletions(-) diff --git a/libretroshare/src/serialiser/rsdiscovery2items.cc b/libretroshare/src/serialiser/rsdiscovery2items.cc index 90b4313b3..8cd94f9d9 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.cc +++ b/libretroshare/src/serialiser/rsdiscovery2items.cc @@ -27,6 +27,8 @@ #include "serialiser/rsdiscovery2items.h" #include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" + #if 0 #include "rsitems/rsserviceids.h" @@ -44,6 +46,121 @@ #include +RsItem *RsDiscSerialiser::create_item(uint16_t service,uint8_t item_subtype) const +{ + if(service != RS_SERVICE_TYPE_DISC) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_DISC_PGP_LIST : return new RsDiscPgpListItem() ; //= 0x01; + case RS_PKT_SUBTYPE_DISC_PGP_CERT : return new RsDiscPgpCertItem() ; //= 0x02; + case RS_PKT_SUBTYPE_DISC_CONTACT_deprecated : return NULL ; //= 0x03; +#if 0 + case RS_PKT_SUBTYPE_DISC_SERVICES : return new RsDiscServicesItem(); //= 0x04; +#endif + case RS_PKT_SUBTYPE_DISC_CONTACT : return new RsDiscContactItem(); //= 0x05; + default: + return NULL ; + } +} + +/*************************************************************************/ + +void RsDiscPgpListItem::clear() +{ + mode = DISC_PGP_LIST_MODE_NONE; + pgpIdSet.TlvClear(); +} + +void RsDiscPgpListItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mode,"mode") ; + RsTypeSerializer::serial_process(j,ctx,pgpIdSet,"pgpIdSet") ; +} + +void RsDiscPgpCertItem::clear() +{ + pgpId.clear(); + pgpCert.clear(); +} + + +void RsDiscPgpCertItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; +} + +void RsDiscContactItem::clear() +{ + pgpId.clear(); + sslId.clear(); + + location.clear(); + version.clear(); + + netMode = 0; + vs_disc = 0; + vs_dht = 0; + lastContact = 0; + + isHidden = false; + hiddenAddr.clear(); + hiddenPort = 0; + + localAddrV4.TlvClear(); + extAddrV4.TlvClear(); + localAddrV6.TlvClear(); + extAddrV6.TlvClear(); + + + dyndns.clear(); + + localAddrList.TlvClear(); + extAddrList.TlvClear(); +} + +void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,pgpId,"pgpId"); + RsTypeSerializer::serial_process (j,ctx,sslId,"sslId"); + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_LOCATION,location,"location"); + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VERSION,version,"version"); + RsTypeSerializer::serial_process(j,ctx,netMode,"netMode"); + RsTypeSerializer::serial_process(j,ctx,vs_disc,"vs_disc"); + RsTypeSerializer::serial_process(j,ctx,vs_dht,"vs_dht"); + RsTypeSerializer::serial_process(j,ctx,lastContact,"lastContact"); + + // This is a hack. Normally we should have to different item types, in order to avoid this nonesense. + + if( (j == RsItem::DESERIALIZE && GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR) || isHidden) + { + isHidden = true ; + + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DOMADDR,hiddenAddr,"hiddenAddr"); + RsTypeSerializer::serial_process(j,ctx,hiddenPort,"hiddenPort"); + } + else + { + isHidden = false ; + + RsTypeSerializer::serial_process(j,ctx,localAddrV4,"localAddrV4"); + RsTypeSerializer::serial_process(j,ctx, extAddrV4,"extAddrV4"); + RsTypeSerializer::serial_process(j,ctx,localAddrV6,"localAddrV6"); + RsTypeSerializer::serial_process(j,ctx, extAddrV6,"extAddrV6"); + RsTypeSerializer::serial_process(j,ctx,currentConnectAddress,"currentConnectAddress"); + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DYNDNS,dyndns,"dyndns"); + RsTypeSerializer::serial_process (j,ctx,localAddrList,"localAddrList"); + RsTypeSerializer::serial_process (j,ctx, extAddrList,"extAddrList"); + } +} + +/*************************************************************************/ + + + +#ifdef TO_REMOVE /*************************************************************************/ uint32_t RsDiscSerialiser::size(RsItem *i) @@ -138,20 +255,6 @@ RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize) } return NULL; } - -/*************************************************************************/ - -RsDiscPgpListItem::~RsDiscPgpListItem() -{ - return; -} - -void RsDiscPgpListItem::clear() -{ - mode = DISC_PGP_LIST_MODE_NONE; - pgpIdSet.TlvClear(); -} - std::ostream &RsDiscPgpListItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsDiscPgpListItem", indent); @@ -173,7 +276,6 @@ uint32_t RsDiscSerialiser::sizePgpList(RsDiscPgpListItem *item) s += item->pgpIdSet.TlvSize(); return s; } - /* serialise the data to the buffer */ bool RsDiscSerialiser::serialisePgpList(RsDiscPgpListItem *item, void *data, uint32_t *pktsize) { @@ -273,6 +375,7 @@ RsDiscPgpListItem *RsDiscSerialiser::deserialisePgpList(void *data, uint32_t *pk return item; } +#endif /*************************************************************************/ /*************************************************************************/ @@ -410,22 +513,11 @@ RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(void *data, uint32_t * return item; } -#endif - - -/*************************************************************************/ - RsDiscPgpCertItem::~RsDiscPgpCertItem() { return; } -void RsDiscPgpCertItem::clear() -{ - pgpId.clear(); - pgpCert.clear(); -} - std::ostream &RsDiscPgpCertItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsDiscPgpCertItem", indent); @@ -448,7 +540,6 @@ uint32_t RsDiscSerialiser::sizePgpCert(RsDiscPgpCertItem *item) s += GetTlvStringSize(item->pgpCert); return s; } - /* serialise the data to the buffer */ bool RsDiscSerialiser::serialisePgpCert(RsDiscPgpCertItem *item, void *data, uint32_t *pktsize) { @@ -557,35 +648,6 @@ RsDiscContactItem::~RsDiscContactItem() return; } -void RsDiscContactItem::clear() -{ - pgpId.clear(); - sslId.clear(); - - location.clear(); - version.clear(); - - netMode = 0; - vs_disc = 0; - vs_dht = 0; - lastContact = 0; - - isHidden = false; - hiddenAddr.clear(); - hiddenPort = 0; - - localAddrV4.TlvClear(); - extAddrV4.TlvClear(); - localAddrV6.TlvClear(); - extAddrV6.TlvClear(); - - - dyndns.clear(); - - localAddrList.TlvClear(); - extAddrList.TlvClear(); -} - std::ostream &RsDiscContactItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsDiscContact", indent); @@ -657,7 +719,6 @@ std::ostream &RsDiscContactItem::print(std::ostream &out, uint16_t indent) return out; } - uint32_t RsDiscSerialiser::sizeContact(RsDiscContactItem *item) { uint32_t s = 8; /* header */ @@ -893,6 +954,4 @@ RsDiscContactItem *RsDiscSerialiser::deserialiseContact(void *data, uint32_t *pk return item; } - -/*************************************************************************/ - +#endif diff --git a/libretroshare/src/serialiser/rsdiscovery2items.h b/libretroshare/src/serialiser/rsdiscovery2items.h index 26bbf1f22..fc1a944cb 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.h +++ b/libretroshare/src/serialiser/rsdiscovery2items.h @@ -33,6 +33,8 @@ #include "serialiser/rstlvaddrs.h" #include "rsitems/rsserviceids.h" +#include "serialization/rsserializer.h" + const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01; const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02; const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT_deprecated = 0x03; @@ -52,18 +54,18 @@ class RsDiscItem: public RsItem class RsDiscPgpListItem: public RsDiscItem { - public: +public: - RsDiscPgpListItem() - :RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_LIST) - { + RsDiscPgpListItem() + :RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_LIST) + { setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_LIST); } -virtual ~RsDiscPgpListItem(); + virtual ~RsDiscPgpListItem(){} -virtual void clear(); -virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear(); + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); uint32_t mode; RsTlvPgpIdSet pgpIdSet; @@ -73,18 +75,18 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); class RsDiscPgpCertItem: public RsDiscItem { - public: +public: - RsDiscPgpCertItem() - :RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_CERT) - { + RsDiscPgpCertItem() + :RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_CERT) + { setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); } -virtual ~RsDiscPgpCertItem(); + virtual ~RsDiscPgpCertItem(){} -virtual void clear(); -virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear(); + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); RsPgpId pgpId; std::string pgpCert; @@ -93,30 +95,30 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); class RsDiscContactItem: public RsDiscItem { - public: +public: RsDiscContactItem() - :RsDiscItem(RS_PKT_SUBTYPE_DISC_CONTACT) - { - setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT); + :RsDiscItem(RS_PKT_SUBTYPE_DISC_CONTACT) + { + setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT); } -virtual ~RsDiscContactItem(); + virtual ~RsDiscContactItem() {} -virtual void clear(); -virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear(); + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); RsPgpId pgpId; RsPeerId sslId; // COMMON - std::string location; + std::string location; std::string version; uint32_t netMode; /* Mandatory */ uint16_t vs_disc; /* Mandatory */ uint16_t vs_dht; /* Mandatory */ - uint32_t lastContact; + uint32_t lastContact; bool isHidden; /* not serialised */ @@ -126,7 +128,7 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); // STANDARD. - RsTlvIpAddress currentConnectAddress ; // used to check! + RsTlvIpAddress currentConnectAddress ; // used to check! RsTlvIpAddress localAddrV4; /* Mandatory */ RsTlvIpAddress extAddrV4; /* Mandatory */ @@ -164,40 +166,14 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); #endif -class RsDiscSerialiser: public RsSerialType +class RsDiscSerialiser: public RsSerializer { public: - RsDiscSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC) - { return; } + RsDiscSerialiser() :RsSerializer(RS_SERVICE_TYPE_DISC) {} -virtual ~RsDiscSerialiser() { 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 sizePgpList(RsDiscPgpListItem *); -virtual bool serialisePgpList(RsDiscPgpListItem *item, void *data, uint32_t *size); -virtual RsDiscPgpListItem *deserialisePgpList(void *data, uint32_t *size); - -virtual uint32_t sizePgpCert(RsDiscPgpCertItem *); -virtual bool serialisePgpCert(RsDiscPgpCertItem *item, void *data, uint32_t *size); -virtual RsDiscPgpCertItem *deserialisePgpCert(void *data, uint32_t *size); - -virtual uint32_t sizeContact(RsDiscContactItem *); -virtual bool serialiseContact(RsDiscContactItem *item, void *data, uint32_t *size); -virtual RsDiscContactItem *deserialiseContact(void *data, uint32_t *size); - -#if 0 -virtual uint32_t sizeServices(RsDiscServicesItem *); -virtual bool serialiseServices(RsDiscServicesItem *item, void *data, uint32_t *size); -virtual RsDiscServicesItem *deserialiseServices(void *data, uint32_t *size); - -#endif + virtual ~RsDiscSerialiser() {} + RsItem *create_item(uint16_t service,uint8_t item_subtype) const ; }; From 63b4b3a1f785a119b717a5c50280053967407141 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 23 Apr 2017 19:07:26 +0200 Subject: [PATCH 033/106] moved discovery2 items to rsitems/ --- libretroshare/src/libretroshare.pro | 4 ++-- .../src/{serialiser => rsitems}/rsdiscovery2items.cc | 2 +- libretroshare/src/{serialiser => rsitems}/rsdiscovery2items.h | 0 libretroshare/src/services/p3discovery2.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsdiscovery2items.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsdiscovery2items.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 16aba6778..15ab467b3 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -481,7 +481,7 @@ HEADERS += rsitems/itempriorities.h \ serialiser/rstlvbanlist.h \ rsitems/rsbanlistitems.h \ rsitems/rsbwctrlitems.h \ - serialiser/rsdiscovery2items.h \ + rsitems/rsdiscovery2items.h \ serialiser/rsheartbeatitems.h \ serialiser/rsrttitems.h \ serialiser/rsgxsrecognitems.h \ @@ -629,7 +629,7 @@ SOURCES += serialiser/rsbaseserial.cc \ serialiser/rstlvbanlist.cc \ rsitems/rsbanlistitems.cc \ rsitems/rsbwctrlitems.cc \ - serialiser/rsdiscovery2items.cc \ + rsitems/rsdiscovery2items.cc \ serialiser/rsheartbeatitems.cc \ serialiser/rsrttitems.cc \ serialiser/rsgxsrecognitems.cc \ diff --git a/libretroshare/src/serialiser/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc similarity index 99% rename from libretroshare/src/serialiser/rsdiscovery2items.cc rename to libretroshare/src/rsitems/rsdiscovery2items.cc index 8cd94f9d9..e1e939ffa 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -24,7 +24,7 @@ * */ -#include "serialiser/rsdiscovery2items.h" +#include "rsitems/rsdiscovery2items.h" #include "serialiser/rsbaseserial.h" #include "serialization/rstypeserializer.h" diff --git a/libretroshare/src/serialiser/rsdiscovery2items.h b/libretroshare/src/rsitems/rsdiscovery2items.h similarity index 100% rename from libretroshare/src/serialiser/rsdiscovery2items.h rename to libretroshare/src/rsitems/rsdiscovery2items.h diff --git a/libretroshare/src/services/p3discovery2.h b/libretroshare/src/services/p3discovery2.h index 2d063ee77..79ac13135 100644 --- a/libretroshare/src/services/p3discovery2.h +++ b/libretroshare/src/services/p3discovery2.h @@ -35,7 +35,7 @@ #include "pqi/p3netmgr.h" #include "pqi/pqiservicemonitor.h" -#include "serialiser/rsdiscovery2items.h" +#include "rsitems/rsdiscovery2items.h" #include "services/p3service.h" #include "pqi/authgpg.h" From 31c07f4dfd6db51fec429b332be5e87fbb11f219 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 23 Apr 2017 22:40:26 +0200 Subject: [PATCH 034/106] converted RsMsgItems to new serialization. Added format and flag members to RsSerialiser and used the later to handle signature and config serialization techniques --- libretroshare/src/chat/distributedchat.cc | 10 +- libretroshare/src/chat/rschatitems.cc | 59 +------ libretroshare/src/chat/rschatitems.h | 11 +- libretroshare/src/retroshare/rsflags.h | 9 +- libretroshare/src/serialiser/rsmsgitems.cc | 162 ++++++++++++++---- libretroshare/src/serialiser/rsmsgitems.h | 82 ++------- .../src/serialization/rsserializer.cc | 12 +- .../src/serialization/rsserializer.h | 21 ++- .../src/serialization/rstypeserializer.h | 11 +- libretroshare/src/services/p3msgservice.cc | 8 +- 10 files changed, 202 insertions(+), 183 deletions(-) diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index c83ddde8e..f79b71a18 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -222,7 +222,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id)); - uint32_t size = obj->serial_size_for_signature() ; + uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size((RsItem*)obj) ; RsTemporaryMemory memory(size) ; #ifdef DEBUG_CHAT_LOBBIES @@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const std::cerr << " signature id: " << obj->signature.keyId << std::endl; #endif - if(!obj->serialize_for_signature(memory,size)) + if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise((RsItem*)obj,memory,&size)) { std::cerr << " (EE) Cannot serialise message item. " << std::endl; return false ; @@ -239,7 +239,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const uint32_t error_status ; RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ; - if(!mGixs->validateData(memory,obj->serial_size_for_signature(),obj->signature,false,use_info,error_status)) + if(!mGixs->validateData(memory,size,obj->signature,false,use_info,error_status)) { bool res = false ; @@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId& // now sign the object, if the lobby expects it - uint32_t size = item.serial_size_for_signature() ; + uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size((RsItem*)&item) ; RsTemporaryMemory memory(size) ; - if(!item.serialize_for_signature(memory,size)) + if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise((RsItem*)&item,memory,&size)) { std::cerr << "(EE) Cannot sign message item. " << std::endl; return false ; diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 23f4aab25..75d90e0a4 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -80,13 +80,13 @@ RsChatAvatarItem::~RsChatAvatarItem() } } -void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx, bool include_signature) +void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,nick,"nick") ; - if(include_signature) + if(!(ctx.mFlags & RsSerializer::SERIALIZATION_FLAG_SIGNATURE)) RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } @@ -94,13 +94,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& { RsChatMsgItem::serial_process(j,ctx) ; RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; - RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; -} -void RsChatLobbyMsgItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) -{ - RsChatMsgItem::serial_process(j,ctx) ; - RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; - RsChatLobbyBouncingObject::serial_process(j,ctx,false) ; + RsChatLobbyBouncingObject::serial_process(j,ctx) ; } void RsChatLobbyListRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) @@ -129,15 +123,7 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; RsTypeSerializer::serial_process(j,ctx,sendTime ,"sendTime") ; - RsChatLobbyBouncingObject::serial_process(j,ctx,true) ; -} -void RsChatLobbyEventItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; - RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; - RsTypeSerializer::serial_process(j,ctx,sendTime ,"sendTime") ; - - RsChatLobbyBouncingObject::serial_process(j,ctx,false) ; + RsChatLobbyBouncingObject::serial_process(j,ctx) ; } void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { @@ -209,41 +195,4 @@ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci) ci->recvTime = recvTime; } -uint32_t RsChatLobbyBouncingObject::serial_size_for_signature() const -{ - SerializeContext ctx(NULL,0); - - ctx.mOffset = 8; - - const_cast(this)->serial_process_for_signature(RsItem::SIZE_ESTIMATE,ctx) ; - - return ctx.mOffset ; -} - -bool RsChatLobbyBouncingObject::serialize_for_signature(uint8_t *data,uint32_t size) const -{ - SerializeContext ctx(data,0); - - uint32_t tlvsize = serial_size_for_signature() ; - - if(tlvsize > size) - throw std::runtime_error("Cannot serialise: not enough room.") ; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; - return false ; - } - ctx.mOffset = 8; - ctx.mSize = tlvsize; - - const_cast(this)->serial_process_for_signature(RsItem::SERIALIZE,ctx) ; - - if(ctx.mSize != ctx.mOffset) - { - std::cerr << "RsChatSerializer::serialise_item(): ERROR. offset does not match expected size!" << std::endl; - return false ; - } - return true ; -} diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 456ffe5b6..b357f0873 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -137,16 +137,12 @@ public: virtual RsChatLobbyBouncingObject *duplicate() const = 0 ; - uint32_t serial_size_for_signature() const ; - bool serialize_for_signature(uint8_t *data,uint32_t size) const ; - protected: // The functions below handle the serialisation of data that is specific to the bouncing object level. // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - virtual void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature); - virtual void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)=0; + virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx); virtual uint32_t PacketId() const= 0; }; @@ -160,7 +156,6 @@ public: virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; - void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand ChatLobbyMsgId parent_msg_id ; // Used for threaded chat. @@ -177,7 +172,6 @@ public: virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } // void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); - void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand // members. // @@ -330,7 +324,8 @@ class RsChatAvatarItem: public RsChatItem class RsChatSerialiser: public RsSerializer { public: - RsChatSerialiser() :RsSerializer(RS_SERVICE_TYPE_CHAT) {} + RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) + :RsSerializer(RS_SERVICE_TYPE_CHAT,SerializeContext::FORMAT_BINARY,flags) {} virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ; }; diff --git a/libretroshare/src/retroshare/rsflags.h b/libretroshare/src/retroshare/rsflags.h index 500ed42d4..548b1641b 100644 --- a/libretroshare/src/retroshare/rsflags.h +++ b/libretroshare/src/retroshare/rsflags.h @@ -59,11 +59,12 @@ template class t_RsFlags32 uint32_t _bits ; }; -#define FLAGS_TAG_TRANSFER_REQS 0x4228af +#define FLAGS_TAG_TRANSFER_REQS 0x4228af #define FLAGS_TAG_FILE_STORAGE 0x184738 -#define FLAGS_TAG_FILE_SEARCH 0xf29ba5 +#define FLAGS_TAG_FILE_SEARCH 0xf29ba5 #define FLAGS_TAG_SERVICE_PERM 0x380912 #define FLAGS_TAG_SERVICE_CHAT 0x839042 +#define FLAGS_TAG_SERIALIZER 0xa0338d // Flags for requesting transfers, ask for turtle, cache, speed, etc. // @@ -85,3 +86,7 @@ typedef t_RsFlags32 ServicePermissionFlags ; // typedef t_RsFlags32 ChatLobbyFlags ; +// Flags for serializer +// +typedef t_RsFlags32 SerializationFlags ; + diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 69c1028ee..9fc3d7e40 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -30,12 +30,35 @@ #include "serialiser/rsmsgitems.h" #include "serialiser/rstlvbase.h" +#include "serialization/rstypeserializer.h" + /*** #define RSSERIAL_DEBUG 1 ***/ #include + +RsItem *RsMsgSerialiser::create_item(uint16_t service,uint8_t type) const +{ + if(service != RS_SERVICE_TYPE_MSG) + return NULL ; + + switch(type) + { + case RS_PKT_SUBTYPE_DEFAULT : return new RsMsgItem() ; //= 0x01; + case RS_PKT_SUBTYPE_MSG_TAG_TYPE : return new RsMsgTagType() ; //= 0x03; + case RS_PKT_SUBTYPE_MSG_TAGS : return new RsMsgTags() ; //= 0x04; + case RS_PKT_SUBTYPE_MSG_SRC_TAG : return new RsMsgSrcId(); //= 0x05; + case RS_PKT_SUBTYPE_MSG_PARENT_TAG : return new RsMsgParentId() ; //= 0x06; + case RS_PKT_SUBTYPE_MSG_INVITE : return new RsPublicMsgInviteConfigItem(); //= 0x07; + case RS_PKT_SUBTYPE_MSG_GROUTER_MAP : return new RsMsgGRouterMap(); //= 0x08; + case RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP : return new RsMsgDistantMessagesHashMap();//= 0x09; + default: + return NULL ; + } +} + void RsMsgItem::clear() { msgId = 0; @@ -56,6 +79,107 @@ void RsMsgItem::clear() attachment.TlvClear(); } +void RsPublicMsgInviteConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ; + RsTypeSerializer::serial_process(j,ctx,(uint32_t&)time_stamp,"time_stamp") ; +} +void RsMsgTagType::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ; + RsTypeSerializer::serial_process(j,ctx,rgb_color,"rgb_color") ; + RsTypeSerializer::serial_process(j,ctx,tagId,"tagId") ; +} + +void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; + +#warning this is not the correct way to serialise here. We should directly call serial_process >() but for backward compatibility, we cannot + + if(j == RsItem::DESERIALIZE) + while(ctx.mOffset < ctx.mSize) + { + uint32_t n ; + RsTypeSerializer::serial_process(j,ctx,n,"tagIds element") ; + tagIds.push_back(n) ; + } + else + for(std::list::iterator it(tagIds.begin());it!=tagIds.end();++it) + RsTypeSerializer::serial_process(j,ctx,*it,"tagIds element") ; +} + +void RsMsgSrcId::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; + RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ; +} + +void RsMsgGRouterMap::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ; +} + +void RsMsgGRouterMap::clear() +{ + ongoing_msgs.clear() ; + + return; +} + +void RsMsgDistantMessagesHashMap::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ; +} + +void RsMsgParentId::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; + RsTypeSerializer::serial_process(j,ctx,msgParentId,"msgParentId") ; +} + +void RsMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,msgFlags,"msgFlags"); + RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime"); + RsTypeSerializer::serial_process(j,ctx,recvTime,"recvTime"); + + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_SUBJECT,subject,"subject"); + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message"); + + RsTypeSerializer::serial_process(j,ctx,rspeerid_msgto,"rspeerid_msgto"); + RsTypeSerializer::serial_process(j,ctx,rspeerid_msgcc,"rspeerid_msgcc"); + RsTypeSerializer::serial_process(j,ctx,rspeerid_msgbcc,"rspeerid_msgbcc"); + + RsTypeSerializer::serial_process(j,ctx,rsgxsid_msgto,"rsgxsid_msgto"); + RsTypeSerializer::serial_process(j,ctx,rsgxsid_msgcc,"rsgxsid_msgcc"); + RsTypeSerializer::serial_process(j,ctx,rsgxsid_msgbcc,"rsgxsid_msgbcc"); + + RsTypeSerializer::serial_process(j,ctx,attachment,"attachment"); + + if(ctx.mFlags & RsSerializer::SERIALIZATION_FLAG_CONFIG) + RsTypeSerializer::serial_process(j,ctx,msgId,"msgId"); +} + +void RsMsgTagType::clear() +{ + text.clear(); + tagId = 0; + rgb_color = 0; +} + +void RsPublicMsgInviteConfigItem::clear() +{ + hash.clear() ; + time_stamp = 0 ; +} +void RsMsgTags::clear() +{ + msgId = 0; + tagIds.clear(); +} + +#ifdef TO_REMOVE std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsMsgItem", indent); @@ -100,19 +224,6 @@ std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out, "RsMsgItem", indent); return out; } - -void RsMsgTagType::clear() -{ - text.clear(); - tagId = 0; - rgb_color = 0; -} - -void RsPublicMsgInviteConfigItem::clear() -{ - hash.clear() ; - time_stamp = 0 ; -} std::ostream& RsPublicMsgInviteConfigItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsPublicMsgInviteConfigItem", indent); @@ -128,12 +239,6 @@ std::ostream& RsPublicMsgInviteConfigItem::print(std::ostream &out, uint16_t ind return out; } -void RsMsgTags::clear() -{ - msgId = 0; - tagIds.clear(); -} - std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsMsgTagType", indent); @@ -346,7 +451,6 @@ uint32_t RsMsgTagType::serial_size(bool) return s; } - bool RsPublicMsgInviteConfigItem::serialise(void *data, uint32_t& pktsize,bool config) { uint32_t tlvsize = serial_size(config) ; @@ -382,8 +486,6 @@ bool RsPublicMsgInviteConfigItem::serialise(void *data, uint32_t& pktsize,bool c return ok; } - - bool RsMsgTagType::serialise(void *data, uint32_t& pktsize,bool config) { uint32_t tlvsize = serial_size( config) ; @@ -536,7 +638,6 @@ uint32_t RsMsgTags::serial_size(bool) return s; } - bool RsMsgTags::serialise(void *data, uint32_t& pktsize,bool config) { uint32_t tlvsize = serial_size( config) ; @@ -672,8 +773,6 @@ uint32_t RsMsgSrcId::serial_size(bool) return s; } - - bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config) { uint32_t tlvsize = serial_size(config) ; @@ -777,14 +876,6 @@ std::ostream& RsMsgGRouterMap::print(std::ostream& out, uint16_t indent) return out; } - -void RsMsgGRouterMap::clear() -{ - ongoing_msgs.clear() ; - - return; -} - uint32_t RsMsgGRouterMap::serial_size(bool) { uint32_t s = 8; /* header */ @@ -933,7 +1024,6 @@ uint32_t RsMsgDistantMessagesHashMap::serial_size(bool) return s; } - bool RsMsgDistantMessagesHashMap::serialise(void *data, uint32_t& pktsize,bool config) { uint32_t tlvsize = serial_size(config) ; @@ -1073,7 +1163,6 @@ uint32_t RsMsgParentId::serial_size(bool) return s; } - bool RsMsgParentId::serialise(void *data, uint32_t& pktsize,bool config) { uint32_t tlvsize = serial_size( config) ; @@ -1198,3 +1287,6 @@ RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize) /*************************************************************************/ +#endif + + diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 0d44aa501..5eb94e5b4 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -90,10 +90,6 @@ class RsMessageItem: public RsItem virtual ~RsMessageItem() {} virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; - - virtual bool serialise(void *data,uint32_t& size,bool config) = 0 ; - virtual uint32_t serial_size(bool config) = 0 ; }; @@ -105,10 +101,7 @@ class RsMsgItem: public RsMessageItem virtual ~RsMsgItem() {} virtual void clear(); - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; - - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); // ----------- Specific fields ------------- // @@ -137,10 +130,7 @@ class RsMsgTagType : public RsMessageItem public: RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsMsgTagType() {} virtual void clear(); @@ -158,10 +148,7 @@ public: RsMsgTags() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {} - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; - - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsMsgTags() {} virtual void clear(); @@ -177,13 +164,10 @@ class RsMsgSrcId : public RsMessageItem public: RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {} - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsMsgSrcId() {} - virtual void clear(); + virtual void clear(){} // ----------- Specific fields ------------- // // @@ -196,10 +180,7 @@ class RsPublicMsgInviteConfigItem : public RsMessageItem public: RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {} - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; - - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsPublicMsgInviteConfigItem() {} virtual void clear(); @@ -215,10 +196,7 @@ class RsMsgGRouterMap : public RsMessageItem public: RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {} - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsMsgGRouterMap() {} virtual void clear(); @@ -232,13 +210,10 @@ class RsMsgDistantMessagesHashMap : public RsMessageItem public: RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {} - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsMsgDistantMessagesHashMap() {} - virtual void clear(); + virtual void clear() { hash_map.clear() ;} // ----------- Specific fields ------------- // // @@ -249,13 +224,10 @@ class RsMsgParentId : public RsMessageItem public: RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {} - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size,bool config) ; - virtual uint32_t serial_size(bool config) ; + virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual ~RsMsgParentId() {} - virtual void clear(); + virtual void clear(){} // ----------- Specific fields ------------- // // @@ -263,39 +235,15 @@ class RsMsgParentId : public RsMessageItem uint32_t msgParentId; }; -class RsMsgSerialiser: public RsSerialType +class RsMsgSerialiser: public RsSerializer { public: - RsMsgSerialiser(bool bConfiguration = false) - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG), m_bConfiguration (bConfiguration) {} - - RsMsgSerialiser(uint16_t type) - :RsSerialType(RS_PKT_VERSION_SERVICE, type), m_bConfiguration (false) {} + RsMsgSerialiser(SerializationFlags flags) + :RsSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){} virtual ~RsMsgSerialiser() {} - virtual uint32_t size(RsItem *item) - { - return dynamic_cast(item)->serial_size(m_bConfiguration) ; - } - virtual bool serialise (RsItem *item, void *data, uint32_t *size) - { - return dynamic_cast(item)->serialise(data,*size,m_bConfiguration) ; - } - virtual RsItem * deserialise(void *data, uint32_t *size); - - private: - - virtual RsMsgItem *deserialiseMsgItem(void *data, uint32_t *size); - virtual RsMsgTagType *deserialiseTagItem(void *data, uint32_t *size); - virtual RsMsgTags *deserialiseMsgTagItem(void *data, uint32_t *size); - virtual RsMsgSrcId *deserialiseMsgSrcIdItem(void *data, uint32_t *size); - virtual RsMsgParentId *deserialiseMsgParentIdItem(void *data, uint32_t *size); - virtual RsPublicMsgInviteConfigItem *deserialisePublicMsgInviteConfigItem(void *data, uint32_t *size); - virtual RsMsgGRouterMap *deserialiseMsgGRouterMap(void *data, uint32_t *size); - virtual RsMsgDistantMessagesHashMap *deserialiseMsgDistantMessageHashMap(void *data, uint32_t *size); - - bool m_bConfiguration; // is set to true for saving configuration (enables serialising msgId) + virtual RsItem *create_item(uint16_t service,uint8_t type) const ; }; /**************************************************************************/ diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 13b4435fd..85a7a9430 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -2,6 +2,10 @@ #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" +const SerializationFlags RsSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); +const SerializationFlags RsSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); +const SerializationFlags RsSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 ); + RsItem *RsSerializer::deserialise(void *data, uint32_t *size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; @@ -15,7 +19,7 @@ RsItem *RsSerializer::deserialise(void *data, uint32_t *size) return NULL ; } - SerializeContext ctx(const_cast(static_cast(data)),*size); + SerializeContext ctx(const_cast(static_cast(data)),*size,mFormat,mFlags); ctx.mOffset = 8 ; item->serial_process(RsItem::DESERIALIZE, ctx) ; @@ -35,7 +39,7 @@ RsItem *RsSerializer::deserialise(void *data, uint32_t *size) bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size) { - SerializeContext ctx(static_cast(data),0); + SerializeContext ctx(static_cast(data),0,mFormat,mFlags); uint32_t tlvsize = this->size(item) ; @@ -62,7 +66,7 @@ bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size) uint32_t RsSerializer::size(RsItem *item) { - SerializeContext ctx(NULL,0); + SerializeContext ctx(NULL,0,mFormat,mFlags); ctx.mOffset = 8 ; // header size item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; @@ -72,7 +76,7 @@ uint32_t RsSerializer::size(RsItem *item) void RsSerializer::print(RsItem *item) { - SerializeContext ctx(NULL,0); + SerializeContext ctx(NULL,0,mFormat,mFlags); std::cerr << "***** RsItem class: \"" << typeid(*item).name() << "\" *****" << std::endl; item->serial_process(RsItem::PRINT, ctx) ; diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index d8ff50b14..db765e36b 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -6,13 +6,28 @@ #include #include "serialiser/rsserial.h" +#include "serialization/rstypeserializer.h" #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " class RsSerializer: public RsSerialType { public: - RsSerializer(uint16_t service_id) : RsSerialType(RS_PKT_VERSION_SERVICE,service_id) {} + // These are convenience flags to be used by the items when processing the data. The names of the flags + // are not very important. What matters is that the serial_process() method of each item correctly + // deals with the data when it sees the flags, if the serialiser sets them. By default the flags are not + // set and shouldn't be handled. + // When deriving a new serializer, the user can set his own flags, using compatible values + + static const SerializationFlags SERIALIZATION_FLAG_NONE ; // 0x0000 + static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001 + static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002 + + RsSerializer(uint16_t service_id, + SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, + SerializationFlags flags = SERIALIZATION_FLAG_NONE) + + : RsSerialType(RS_PKT_VERSION_SERVICE,service_id),mFormat(format),mFlags(flags) {} /*! create_item * should be overloaded to create the correct type of item depending on the data @@ -28,6 +43,10 @@ class RsSerializer: public RsSerialType bool serialise(RsItem *item,void *data,uint32_t *size) ; uint32_t size(RsItem *item) ; void print(RsItem *item) ; + +private: + SerializeContext::SerializationFormat mFormat ; + SerializationFlags mFlags ; }; diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 1899a26fe..0693331b1 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -11,13 +11,20 @@ class SerializeContext { public: - SerializeContext(uint8_t *data,uint32_t size) - : mData(data),mSize(size),mOffset(0),mOk(true) {} + enum SerializationFormat { + FORMAT_BINARY = 0x01 , + FORMAT_JSON = 0x02 + }; + + SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags) + : mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {} unsigned char *mData ; uint32_t mSize ; uint32_t mOffset ; bool mOk ; + SerializationFormat mFormat ; + SerializationFlags mFlags ; }; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 8781e245b..44c244023 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -86,7 +86,7 @@ static const uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400 ; // ke p3MsgService::p3MsgService(p3ServiceControl *sc, p3IdService *id_serv) :p3Service(), p3Config(), mIdService(id_serv), mServiceCtrl(sc), mMsgMtx("p3MsgService"), mMsgUniqueId(0) { - _serialiser = new RsMsgSerialiser(); // this serialiser is used for services. It's not the same than the one returned by setupSerialiser(). We need both!! + _serialiser = new RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_NONE); // this serialiser is used for services. It's not the same than the one returned by setupSerialiser(). We need both!! addSerialType(_serialiser); mMsgUniqueId = 1 ; // MsgIds are not transmitted, but only used locally as a storage index. As such, thay do not need to be different @@ -519,7 +519,7 @@ RsSerialiser* p3MsgService::setupSerialiser() // this serialiser is used for con { RsSerialiser *rss = new RsSerialiser ; - rss->addSerialType(new RsMsgSerialiser(true)); + rss->addSerialType(new RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_CONFIG)); rss->addSerialType(new RsGeneralConfigSerialiser()); return rss; @@ -2024,10 +2024,10 @@ void p3MsgService::sendDistantMsgItem(RsMsgItem *msgitem) // The item is serialized and turned into a generic turtle item. Use use the explicit serialiser to make sure that the msgId is not included - uint32_t msg_serialized_rssize = msgitem->serial_size(false) ; + uint32_t msg_serialized_rssize = RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_NONE).size(msgitem) ; RsTemporaryMemory msg_serialized_data(msg_serialized_rssize) ; - if(!msgitem->serialise(msg_serialized_data,msg_serialized_rssize,false)) + if(!RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_NONE).serialise(msgitem,msg_serialized_data,&msg_serialized_rssize)) { std::cerr << "(EE) p3MsgService::sendTurtleData(): Serialization error." << std::endl; return ; From 91b04098b64419bcdc038799899d1f45abb10311 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 10:11:24 +0200 Subject: [PATCH 035/106] fixed two memory bugs in serialization code --- libretroshare/src/chat/rschatitems.cc | 2 +- libretroshare/src/rsitems/rsdiscovery2items.cc | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 75d90e0a4..e30c401c1 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -75,7 +75,7 @@ RsChatAvatarItem::~RsChatAvatarItem() { if(image_data != NULL) { - delete[] image_data ; + free(image_data) ; image_data = NULL ; } } diff --git a/libretroshare/src/rsitems/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc index e1e939ffa..687f32f21 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -134,17 +134,16 @@ void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) // This is a hack. Normally we should have to different item types, in order to avoid this nonesense. - if( (j == RsItem::DESERIALIZE && GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR) || isHidden) - { - isHidden = true ; + if(j == RsItem::DESERIALIZE) + isHidden = ( GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR); + if(isHidden) + { RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DOMADDR,hiddenAddr,"hiddenAddr"); RsTypeSerializer::serial_process(j,ctx,hiddenPort,"hiddenPort"); } else { - isHidden = false ; - RsTypeSerializer::serial_process(j,ctx,localAddrV4,"localAddrV4"); RsTypeSerializer::serial_process(j,ctx, extAddrV4,"extAddrV4"); RsTypeSerializer::serial_process(j,ctx,localAddrV6,"localAddrV6"); From 08867945f34be33bca05ed835c42d80441ece435 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 10:29:57 +0200 Subject: [PATCH 036/106] fixed bug caused by wrong cast in lobby msg signature validation --- libretroshare/src/chat/distributedchat.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index f79b71a18..79c41b2f2 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -222,7 +222,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id)); - uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size((RsItem*)obj) ; + uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast(obj)) ; RsTemporaryMemory memory(size) ; #ifdef DEBUG_CHAT_LOBBIES @@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const std::cerr << " signature id: " << obj->signature.keyId << std::endl; #endif - if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise((RsItem*)obj,memory,&size)) + if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast(obj),memory,&size)) { std::cerr << " (EE) Cannot serialise message item. " << std::endl; return false ; @@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId& // now sign the object, if the lobby expects it - uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size((RsItem*)&item) ; + uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast(&item)) ; RsTemporaryMemory memory(size) ; - if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise((RsItem*)&item,memory,&size)) + if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast(&item),memory,&size)) { std::cerr << "(EE) Cannot sign message item. " << std::endl; return false ; From fc82b2083322f07940453e4a8407602a6142e034 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 10:36:22 +0200 Subject: [PATCH 037/106] removed old serialization code in msgs --- .../src/rsitems/rsdiscovery2items.cc | 663 ---------- libretroshare/src/serialiser/rsmsgitems.cc | 1111 ----------------- 2 files changed, 1774 deletions(-) diff --git a/libretroshare/src/rsitems/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc index 687f32f21..8e4175a9e 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -156,228 +156,6 @@ void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) } /*************************************************************************/ - - - -#ifdef TO_REMOVE -/*************************************************************************/ - -uint32_t RsDiscSerialiser::size(RsItem *i) -{ - RsDiscPgpListItem *pgplist; - RsDiscPgpCertItem *pgpcert; - RsDiscContactItem *contact; - //RsDiscServicesItem *services; - - if (NULL != (pgplist = dynamic_cast(i))) - { - return sizePgpList(pgplist); - } - else if (NULL != (pgpcert = dynamic_cast(i))) - { - return sizePgpCert(pgpcert); - } - else if (NULL != (contact = dynamic_cast(i))) - { - return sizeContact(contact); - } -#if 0 - else if (NULL != (services = dynamic_cast(i))) - { - return sizeServices(services); - } -#endif - return 0; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsDiscPgpListItem *pgplist; - RsDiscPgpCertItem *pgpcert; - RsDiscContactItem *contact; - //RsDiscServicesItem *services; - - if (NULL != (pgplist = dynamic_cast(i))) - { - return serialisePgpList(pgplist, data, pktsize); - } - else if (NULL != (pgpcert = dynamic_cast(i))) - { - return serialisePgpCert(pgpcert, data, pktsize); - } - else if (NULL != (contact = dynamic_cast(i))) - { - return serialiseContact(contact, data, pktsize); - } -#if 0 - else if (NULL != (services = dynamic_cast(i))) - { - return serialiseServices(services, data, pktsize); - } -#endif - - return false; -} - -RsItem *RsDiscSerialiser::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_DISC != getRsItemService(rstype))) - { - std::cerr << "RsDiscSerialiser::deserialise() Wrong Type" << std::endl; - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DISC_PGP_LIST: - return deserialisePgpList(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_PGP_CERT: - return deserialisePgpCert(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_CONTACT: - return deserialiseContact(data, pktsize); - break; -#if 0 - case RS_PKT_SUBTYPE_DISC_SERVICES: - return deserialiseServices(data, pktsize); - break; -#endif - default: - return NULL; - break; - } - return NULL; -} -std::ostream &RsDiscPgpListItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscPgpListItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "mode: " << mode << std::endl; - pgpIdSet.print(out, int_Indent); - - printRsItemEnd(out, "RsDiscPgpList", indent); - return out; -} - - -uint32_t RsDiscSerialiser::sizePgpList(RsDiscPgpListItem *item) -{ - uint32_t s = 8; /* header */ - s += 4; /* mode */ - s += item->pgpIdSet.TlvSize(); - return s; -} -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialisePgpList(RsDiscPgpListItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizePgpList(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 << "RsDiscSerialiser::serialisePgpList() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialisePgpList() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mode); - ok &= item->pgpIdSet.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialisePgpList() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsDiscPgpListItem *RsDiscSerialiser::deserialisePgpList(void *data, uint32_t *pktsize) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_PGP_LIST != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() Not Enough Space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscPgpListItem *item = new RsDiscPgpListItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->mode)); - ok &= item->pgpIdSet.GetTlv(data, rssize, &offset); - - if (offset != rssize) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpList() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif - -/*************************************************************************/ -/*************************************************************************/ #if 0 RsDiscServicesItem::~RsDiscServicesItem() @@ -512,445 +290,4 @@ RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(void *data, uint32_t * return item; } -RsDiscPgpCertItem::~RsDiscPgpCertItem() -{ - return; -} - -std::ostream &RsDiscPgpCertItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscPgpCertItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "pgpId: " << pgpId << std::endl; - printIndent(out, int_Indent); - out << "pgpCert: " << pgpCert << std::endl; - - printRsItemEnd(out, "RsDiscPgpCert", indent); - return out; -} - - -uint32_t RsDiscSerialiser::sizePgpCert(RsDiscPgpCertItem *item) -{ - uint32_t s = 8; /* header */ - s += item->pgpId.serial_size(); - s += GetTlvStringSize(item->pgpCert); - return s; -} -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialisePgpCert(RsDiscPgpCertItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizePgpCert(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 << "RsDiscSerialiser::serialisePgpCert() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialisePgpCert() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->pgpId.serialise(data, tlvsize, offset) ; - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert); - - if (offset != tlvsize) { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialisePgpCert() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsDiscPgpCertItem *RsDiscSerialiser::deserialisePgpCert(void *data, uint32_t *pktsize) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_PGP_CERT != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() Not Enough Space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscPgpCertItem *item = new RsDiscPgpCertItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->pgpId.deserialise(data, rssize, offset) ; - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert); - - if (offset != rssize) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialisePgpCert() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - - -RsDiscContactItem::~RsDiscContactItem() -{ - return; -} - -std::ostream &RsDiscContactItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscContact", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "pgpId: " << pgpId << std::endl; - - printIndent(out, int_Indent); - out << "sslId: " << sslId << std::endl; - - printIndent(out, int_Indent); - out << "location: " << location << std::endl; - - printIndent(out, int_Indent); - out << "version: " << version << std::endl; - - printIndent(out, int_Indent); - out << "netMode: " << netMode << std::endl; - - printIndent(out, int_Indent); - out << "vs_disc: " << vs_disc << std::endl; - - printIndent(out, int_Indent); - out << "vs_dht: " << vs_dht << std::endl; - - printIndent(out, int_Indent); - out << "lastContact: " << lastContact << std::endl; - - if (isHidden) - { - printIndent(out, int_Indent); - out << "hiddenAddr: " << hiddenAddr << std::endl; - - printIndent(out, int_Indent); - out << "hiddenPort: " << hiddenPort << std::endl; - } - else - { - printIndent(out, int_Indent); - out << "localAddrV4: " << std::endl; - localAddrV4.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrV4: " << std::endl; - extAddrV4.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "localAddrV6: " << std::endl; - localAddrV6.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrV6: " << std::endl; - extAddrV6.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "DynDNS: " << dyndns << std::endl; - - printIndent(out, int_Indent); - out << "localAddrList: " << std::endl; - localAddrList.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrList: " << std::endl; - extAddrList.print(out, int_Indent); - } - - printRsItemEnd(out, "RsDiscContact", indent); - return out; -} - -uint32_t RsDiscSerialiser::sizeContact(RsDiscContactItem *item) -{ - uint32_t s = 8; /* header */ - s += item->pgpId.serial_size(); - s += item->sslId.serial_size(); - - s += GetTlvStringSize(item->location); - s += GetTlvStringSize(item->version); - - s += 4; // netMode - s += 2; // vs_disc - s += 2; // vs_dht - s += 4; // last contact - - if (item->isHidden) - { - s += GetTlvStringSize(item->hiddenAddr); - s += 2; /* hidden port */ - } - else - { - s += item->localAddrV4.TlvSize(); /* localaddr */ - s += item->extAddrV4.TlvSize(); /* remoteaddr */ - - s += item->currentConnectAddress.TlvSize() ; - - s += item->localAddrV6.TlvSize(); /* localaddr */ - s += item->extAddrV6.TlvSize(); /* remoteaddr */ - - s += GetTlvStringSize(item->dyndns); - - //add the size of the ip list - s += item->localAddrList.TlvSize(); - s += item->extAddrList.TlvSize(); - } - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeContact() Total Size: " << s << std::endl; -#endif - - return s; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialiseContact(RsDiscContactItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeContact(item); - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() tlvsize: " << tlvsize; - std::cerr << std::endl; -#endif - - if (*pktsize < tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() ERROR not enough space" << std::endl; - std::cerr << "RsDiscSerialiser::serialiseContact() ERROR *pktsize: " << *pktsize << " tlvsize: " << tlvsize; - std::cerr << std::endl; -#endif - return false; /* not enough space */ - } - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseContact() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->pgpId.serialise(data, tlvsize, offset) ; - ok &= item->sslId.serialise(data, tlvsize, offset) ; - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version); - - ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); - ok &= setRawUInt16(data, tlvsize, &offset, item->vs_disc); - ok &= setRawUInt16(data, tlvsize, &offset, item->vs_dht); - ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */ - - if (item->isHidden) - { - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DOMADDR, item->hiddenAddr); - ok &= setRawUInt16(data, tlvsize, &offset, item->hiddenPort); - } - else - { - ok &= item->localAddrV4.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrV4.SetTlv(data, tlvsize, &offset); - ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); - - ok &= item->currentConnectAddress.SetTlv(data, tlvsize, &offset); - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); - - ok &= item->localAddrList.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrList.SetTlv(data, tlvsize, &offset); - } - - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseContact() Size Error: " << tlvsize << " != " << offset << std::endl; -#endif - } - - return ok; -} - -RsDiscContactItem *RsDiscSerialiser::deserialiseContact(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() Pkt Type: " << std::hex << rstype << std::dec; - std::cerr << "RsDiscSerialiser::deserialiseContact() Pkt Size: " << rssize << std::endl; -#endif - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_CONTACT != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() Not enough space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscContactItem *item = new RsDiscContactItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->pgpId.deserialise(data, rssize, offset) ; - ok &= item->sslId.deserialise(data, rssize, offset) ; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version); - - ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */ - ok &= getRawUInt16(data, rssize, &offset, &(item->vs_disc)); /* Mandatory */ - ok &= getRawUInt16(data, rssize, &offset, &(item->vs_dht)); /* Mandatory */ - ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); - - if (rssize < offset + TLV_HEADER_SIZE) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() missized" << std::endl; -#endif - /* no extra */ - delete item; - return NULL; - } - - uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[offset]) ); - - if (tlvtype == TLV_TYPE_STR_DOMADDR) - { - item->isHidden = true; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DOMADDR, item->hiddenAddr); - ok &= getRawUInt16(data, rssize, &offset, &(item->hiddenPort)); /* Mandatory */ - - } - else - { - item->isHidden = false; - - ok &= item->localAddrV4.GetTlv(data, rssize, &offset); - ok &= item->extAddrV4.GetTlv(data, rssize, &offset); - ok &= item->localAddrV6.GetTlv(data, rssize, &offset); - ok &= item->extAddrV6.GetTlv(data, rssize, &offset); - - ok &= item->currentConnectAddress.GetTlv(data, rssize, &offset); - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); - ok &= item->localAddrList.GetTlv(data, rssize, &offset); - ok &= item->extAddrList.GetTlv(data, rssize, &offset); - } - - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseContact() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} #endif diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 9fc3d7e40..6dee2f2be 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -179,1114 +179,3 @@ void RsMsgTags::clear() tagIds.clear(); } -#ifdef TO_REMOVE -std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "msgId (not serialised): " << msgId << std::endl; - printIndent(out, int_Indent); - out << "msgFlags: " << msgFlags << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << std::endl; - printIndent(out, int_Indent); - out << "recvTime: " << recvTime << std::endl; - - printIndent(out, int_Indent); - out << "Message To: " << std::endl; - rspeerid_msgto.print(out, int_Indent); - rsgxsid_msgto.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "Message CC: " << std::endl; - rspeerid_msgcc.print(out, int_Indent); - rsgxsid_msgcc.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "Message BCC: " << std::endl; - rspeerid_msgbcc.print(out, int_Indent); - rsgxsid_msgbcc.print(out, int_Indent); - - printIndent(out, int_Indent); - std::string cnv_subject(subject.begin(), subject.end()); - out << "subject: " << cnv_subject << std::endl; - - printIndent(out, int_Indent); - std::string cnv_message(message.begin(), message.end()); - out << "msg: " << cnv_message << std::endl; - - printIndent(out, int_Indent); - out << "Attachment: " << std::endl; - attachment.print(out, int_Indent); - - printRsItemEnd(out, "RsMsgItem", indent); - return out; -} -std::ostream& RsPublicMsgInviteConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPublicMsgInviteConfigItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "hash : " << hash << std::endl; - - printIndent(out, int_Indent); - out << "timt : " << time_stamp << std::endl; - - printRsItemEnd(out, "RsPublicMsgInviteConfigItem", indent); - - return out; -} -std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgTagType", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "rgb_color : " << rgb_color << std::endl; - - - printIndent(out, int_Indent); - out << "text: " << text << std::endl; - - printIndent(out, int_Indent); - out << "tagId: " << tagId << std::endl; - - printRsItemEnd(out, "RsMsgTagTypeItem", indent); - - return out; -} - -std::ostream& RsMsgTags::print(std::ostream &out, uint16_t indent) -{ - - printRsItemBase(out, "RsMsgTagsItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "msgId : " << msgId << std::endl; - - std::list::iterator it; - - for(it=tagIds.begin(); it != tagIds.end(); ++it) - { - printIndent(out, int_Indent); - out << "tagId : " << *it << std::endl; - } - - printRsItemEnd(out, "RsMsgTags", indent); - - return out; -} - -uint32_t RsMsgItem::serial_size(bool m_bConfiguration) -{ - uint32_t s = 8; /* header */ - s += 4; /* msgFlags */ - s += 4; /* sendTime */ - s += 4; /* recvTime */ - - s += GetTlvStringSize(subject); - s += GetTlvStringSize(message); - - s += rspeerid_msgto.TlvSize(); - s += rspeerid_msgcc.TlvSize(); - s += rspeerid_msgbcc.TlvSize(); - - s += rsgxsid_msgto.TlvSize(); - s += rsgxsid_msgcc.TlvSize(); - s += rsgxsid_msgbcc.TlvSize(); - - s += attachment.TlvSize(); - - if (m_bConfiguration) { - // serialise msgId too - s += 4; - } - - return s; -} - -/* serialise the data to the buffer */ -bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, msgFlags); - ok &= setRawUInt32(data, tlvsize, &offset, sendTime); - ok &= setRawUInt32(data, tlvsize, &offset, recvTime); - - ok &= SetTlvString(data,tlvsize,&offset,TLV_TYPE_STR_SUBJECT,subject); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message); - - ok &= rspeerid_msgto.SetTlv(data, tlvsize, &offset); - ok &= rspeerid_msgcc.SetTlv(data, tlvsize, &offset); - ok &= rspeerid_msgbcc.SetTlv(data, tlvsize, &offset); - - ok &= rsgxsid_msgto.SetTlv(data, tlvsize, &offset); - ok &= rsgxsid_msgcc.SetTlv(data, tlvsize, &offset); - ok &= rsgxsid_msgbcc.SetTlv(data, tlvsize, &offset); - - ok &= attachment.SetTlv(data, tlvsize, &offset); - - if (config) // serialise msgId too - ok &= setRawUInt32(data, tlvsize, &offset, msgId); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgItem *item = new RsMsgItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->msgFlags)); - ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime)); - ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime)); - - ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_SUBJECT,item->subject); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message); - - ok &= item->rspeerid_msgto.GetTlv(data, rssize, &offset); - ok &= item->rspeerid_msgcc.GetTlv(data, rssize, &offset); - ok &= item->rspeerid_msgbcc.GetTlv(data, rssize, &offset); - ok &= item->rsgxsid_msgto.GetTlv(data, rssize, &offset); - ok &= item->rsgxsid_msgcc.GetTlv(data, rssize, &offset); - ok &= item->rsgxsid_msgbcc.GetTlv(data, rssize, &offset); - - ok &= item->attachment.GetTlv(data, rssize, &offset); - - if (m_bConfiguration) { - // deserialise msgId too - // ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - getRawUInt32(data, rssize, &offset, &(item->msgId)); //use this line for backward compatibility - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} -uint32_t RsPublicMsgInviteConfigItem::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += GetTlvStringSize(hash); - s += 4; /* time_stamp */ - - return s; -} - -uint32_t RsMsgTagType::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += GetTlvStringSize(text); - s += 4; /* color */ - s += 4; /* tag id */ - - return s; -} -bool RsPublicMsgInviteConfigItem::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size(config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_HASH_SHA1, hash); - ok &= setRawUInt32(data,tlvsize,&offset, time_stamp); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; - } - - return ok; -} -bool RsMsgTagType::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_NAME, text); - ok &= setRawUInt32(data, tlvsize, &offset, rgb_color); - ok &= setRawUInt32(data, tlvsize, &offset, tagId); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; - } - - return ok; -} -RsPublicMsgInviteConfigItem* RsMsgSerialiser::deserialisePublicMsgInviteConfigItem(void *data,uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_INVITE != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsPublicMsgInviteConfigItem *item = new RsPublicMsgInviteConfigItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_HASH_SHA1,item->hash); - - uint32_t ts ; - ok &= getRawUInt32(data, rssize, &offset, &ts) ; - item->time_stamp = ts ; - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - -RsMsgTagType* RsMsgSerialiser::deserialiseTagItem(void *data,uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_TAG_TYPE != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgTagType *item = new RsMsgTagType(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_NAME,item->text); - ok &= getRawUInt32(data, rssize, &offset, &(item->rgb_color)); - ok &= getRawUInt32(data, rssize, &offset, &(item->tagId)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -uint32_t RsMsgTags::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; /* msgId */ - s += tagIds.size() * 4; /* tagIds */ - - return s; -} -bool RsMsgTags::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data,tlvsize,&offset, msgId); - - std::list::iterator mit = tagIds.begin(); - for(;mit != tagIds.end(); ++mit) - ok &= setRawUInt32(data, tlvsize, &offset, *mit); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(void* data, uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_TAGS != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgTags *item = new RsMsgTags(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &item->msgId); - - uint32_t tagId; - while (offset != rssize) - { - tagId = 0; - - ok &= getRawUInt32(data, rssize, &offset, &tagId); - - item->tagIds.push_back(tagId); - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - -/************************************** Message SrcId **********************/ - -std::ostream& RsMsgSrcId::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgSrcIdItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "msgId : " << msgId << std::endl; - - printIndent(out, int_Indent); - out << "SrcId: " << srcId << std::endl; - - - printRsItemEnd(out, "RsMsgItem", indent); - - return out; -} - -void RsMsgSrcId::clear() -{ - msgId = 0; - srcId.clear(); - - return; -} - -uint32_t RsMsgSrcId::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; - s += srcId.serial_size() ; - - return s; -} -bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size(config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, msgId); - ok &= srcId.serialise(data, tlvsize, offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(void* data, uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_SRC_TAG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgSrcId *item = new RsMsgSrcId(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - ok &= item->srcId.deserialise(data, rssize, offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/************************* end of definition of msgSrcId serialisation functions ************************/ - -std::ostream& RsMsgGRouterMap::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgGRouterMap", indent); - uint16_t int_Indent = indent + 2; - - for(std::map::const_iterator it(ongoing_msgs.begin());it!=ongoing_msgs.end();++it) - { - printIndent(out, int_Indent); - out << " " << std::hex << it->first << std::dec << " : " << it->second << std::endl; - } - - printRsItemEnd(out, "RsMsgGRouterMap", indent); - - return out; -} -uint32_t RsMsgGRouterMap::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; // number of entries - s += (8+4)*ongoing_msgs.size(); // entries - - return s; -} - -bool RsMsgGRouterMap::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, ongoing_msgs.size()); - - for(std::map::const_iterator it=ongoing_msgs.begin();ok && it!=ongoing_msgs.end();++it) - { - ok &= setRawUInt64(data, tlvsize, &offset, it->first); - ok &= setRawUInt32(data, tlvsize, &offset, it->second); - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgGRouterMap() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgGRouterMap* RsMsgSerialiser::deserialiseMsgGRouterMap(void* data, uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_GROUTER_MAP != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgGRouterMap *item = new RsMsgGRouterMap(); - item->clear(); - - /* skip the header */ - offset += 8; - - uint32_t s=0 ; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - for(uint32_t i=0;iongoing_msgs.insert(std::make_pair(routing_id,mid)) ; - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/************************* end of definition of msgGRouterMap serialisation functions ************************/ - -/************************* definition of msgDistantMessageMap serialisation functions ************************/ - -std::ostream& RsMsgDistantMessagesHashMap::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgDistantMessagesHashMap", indent); - uint16_t int_Indent = indent + 2; - - for(std::map::const_iterator it(hash_map.begin());it!=hash_map.end();++it) - { - printIndent(out, int_Indent); - out << " " << std::hex << it->first << std::dec << " : " << it->second << std::endl; - } - - printRsItemEnd(out, "RsMsgDistantMessagesHashMap", indent); - - return out; -} - -void RsMsgDistantMessagesHashMap::clear() -{ - hash_map.clear() ; - - return; -} - -uint32_t RsMsgDistantMessagesHashMap::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; // number of entries - s += (Sha1CheckSum::SIZE_IN_BYTES+4)*hash_map.size(); // entries - - return s; -} -bool RsMsgDistantMessagesHashMap::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size(config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, hash_map.size()); - - for(std::map::const_iterator it=hash_map.begin();ok && it!=hash_map.end();++it) - { - ok &= it->first.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, it->second); - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgDistantMessagesHashMap() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgDistantMessagesHashMap* RsMsgSerialiser::deserialiseMsgDistantMessageHashMap(void* data, uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgDistantMessagesHashMap *item = new RsMsgDistantMessagesHashMap(); - item->clear(); - - /* skip the header */ - offset += 8; - - uint32_t s=0 ; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - for(uint32_t i=0;ihash_map.insert(std::make_pair(s,tm)) ; - } - - if (offset != rssize) - { - /* error */ - std::cerr << "(EE) size error in packet deserialisation: p3MsgItem, subtype " << getRsItemSubType(rstype) << ". offset=" << offset << " != rssize=" << rssize << std::endl; - delete item; - return NULL; - } - - if (!ok) - { - std::cerr << "(EE) size error in packet deserialisation: p3MsgItem, subtype " << getRsItemSubType(rstype) << std::endl; - delete item; - return NULL; - } - - return item; -} -/************************************** Message ParentId **********************/ - -std::ostream& RsMsgParentId::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsMsgParentIdItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "msgId : " << msgId << std::endl; - - printIndent(out, int_Indent); - out << "msgParentId: " << msgParentId << std::endl; - - - printRsItemEnd(out, "RsMsgParentId", indent); - - return out; -} - -void RsMsgParentId::clear() -{ - msgId = 0; - msgParentId = 0; - - return; -} - -uint32_t RsMsgParentId::serial_size(bool) -{ - uint32_t s = 8; /* header */ - - s += 4; // srcId - s += 4; // msgParentId - - return s; -} -bool RsMsgParentId::serialise(void *data, uint32_t& pktsize,bool config) -{ - uint32_t tlvsize = serial_size( config) ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl; - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, msgId); - ok &= setRawUInt32(data, tlvsize, &offset, msgParentId); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size Error! " << std::endl; - } - - return ok; -} - -RsMsgParentId* RsMsgSerialiser::deserialiseMsgParentIdItem(void* data, uint32_t* pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_MSG_PARENT_TAG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsMsgParentId *item = new RsMsgParentId(); - item->clear(); - - /* skip the header */ - offset += 8; - - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->msgId)); - ok &= getRawUInt32(data, rssize, &offset, &(item->msgParentId)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/************************* end of definition of msgParentId serialisation functions ************************/ - -RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::deserialise()" << std::endl; -#endif - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_MSG != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DEFAULT: return deserialiseMsgItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_SRC_TAG: return deserialiseMsgSrcIdItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_PARENT_TAG: return deserialiseMsgParentIdItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_TAG_TYPE: return deserialiseTagItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_INVITE: return deserialisePublicMsgInviteConfigItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_TAGS: return deserialiseMsgTagItem(data, pktsize); - case RS_PKT_SUBTYPE_MSG_GROUTER_MAP: return deserialiseMsgGRouterMap(data, pktsize); - case RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP: return deserialiseMsgDistantMessageHashMap(data, pktsize); - default: - return NULL; - break; - } - - return NULL; -} - - -/*************************************************************************/ - -#endif - - From 5071c4bc7f30b43afe342a116217c547410291d6 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 11:00:57 +0200 Subject: [PATCH 038/106] moved msgitems to rsitems/ --- libretroshare/src/{serialiser => rsitems}/rsmsgitems.cc | 0 libretroshare/src/{serialiser => rsitems}/rsmsgitems.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsmsgitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsmsgitems.h (100%) diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/rsitems/rsmsgitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsmsgitems.cc rename to libretroshare/src/rsitems/rsmsgitems.cc diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/rsitems/rsmsgitems.h similarity index 100% rename from libretroshare/src/serialiser/rsmsgitems.h rename to libretroshare/src/rsitems/rsmsgitems.h From f6aaee73827e8767c7c518c15d2de3fabc8416db Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 11:01:45 +0200 Subject: [PATCH 039/106] converted RTT items to new serialization --- libretroshare/src/chat/distantchat.cc | 18 ++++---- libretroshare/src/chat/p3chatservice.h | 2 +- libretroshare/src/libretroshare.pro | 4 +- libretroshare/src/pqi/p3historymgr.cc | 2 +- libretroshare/src/rsitems/rsmsgitems.cc | 3 +- libretroshare/src/serialiser/rsrttitems.cc | 28 +++++++++++++ libretroshare/src/serialiser/rsrttitems.h | 42 +++++++------------ libretroshare/src/serialiser/rsserial.cc | 2 +- .../src/serialization/rsserializer.h | 9 ++-- libretroshare/src/services/p3msgservice.h | 2 +- 10 files changed, 65 insertions(+), 47 deletions(-) diff --git a/libretroshare/src/chat/distantchat.cc b/libretroshare/src/chat/distantchat.cc index 8bb8b8d17..7345aa274 100644 --- a/libretroshare/src/chat/distantchat.cc +++ b/libretroshare/src/chat/distantchat.cc @@ -35,17 +35,17 @@ #include "util/rsmemory.h" #include "util/rsprint.h" -#include +#include "rsitems/rsmsgitems.h" -#include -#include -#include +#include "retroshare/rsmsgs.h" +#include "retroshare/rsidentity.h" +#include "retroshare/rsiface.h" -#include -#include -#include -#include -#include +#include "rsserver/p3face.h" +#include "services/p3idservice.h" +#include "gxs/gxssecurity.h" +#include "turtle/p3turtle.h" +#include "retroshare/rsids.h" #include "distantchat.h" //#define DEBUG_DISTANT_CHAT diff --git a/libretroshare/src/chat/p3chatservice.h b/libretroshare/src/chat/p3chatservice.h index 3096309b0..482a61c6e 100644 --- a/libretroshare/src/chat/p3chatservice.h +++ b/libretroshare/src/chat/p3chatservice.h @@ -31,7 +31,7 @@ #include #include -#include "serialiser/rsmsgitems.h" +#include "rsitems/rsmsgitems.h" #include "services/p3service.h" #include "pqi/pqiservicemonitor.h" #include "chat/distantchat.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 15ab467b3..4d94f4c71 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -458,7 +458,7 @@ HEADERS += rsitems/itempriorities.h \ serialiser/rsserviceserialiser.h \ serialiser/rsconfigitems.h \ serialiser/rshistoryitems.h \ - serialiser/rsmsgitems.h \ + rsitems/rsmsgitems.h \ serialiser/rsserial.h \ rsitems/rsserviceids.h \ serialiser/rsserviceitems.h \ @@ -612,7 +612,7 @@ SOURCES += serialiser/rsbaseserial.cc \ serialiser/rsserviceserialiser.cc \ serialiser/rsconfigitems.cc \ serialiser/rshistoryitems.cc \ - serialiser/rsmsgitems.cc \ + rsitems/rsmsgitems.cc \ serialiser/rsserial.cc \ serialiser/rsstatusitems.cc \ serialiser/rstlvaddrs.cc \ diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index d190a903b..5739ff94a 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -30,7 +30,7 @@ #include "serialiser/rsconfigitems.h" #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" -#include "serialiser/rsmsgitems.h" +#include "rsitems/rsmsgitems.h" #include "rsserver/p3face.h" #include "util/rsstring.h" diff --git a/libretroshare/src/rsitems/rsmsgitems.cc b/libretroshare/src/rsitems/rsmsgitems.cc index 6dee2f2be..7405f37e0 100644 --- a/libretroshare/src/rsitems/rsmsgitems.cc +++ b/libretroshare/src/rsitems/rsmsgitems.cc @@ -27,9 +27,10 @@ #include #include #include "serialiser/rsbaseserial.h" -#include "serialiser/rsmsgitems.h" #include "serialiser/rstlvbase.h" +#include "rsitems/rsmsgitems.h" + #include "serialization/rstypeserializer.h" /*** diff --git a/libretroshare/src/serialiser/rsrttitems.cc b/libretroshare/src/serialiser/rsrttitems.cc index 8f5c136e7..5965f1068 100644 --- a/libretroshare/src/serialiser/rsrttitems.cc +++ b/libretroshare/src/serialiser/rsrttitems.cc @@ -36,7 +36,34 @@ /*************************************************************************/ +RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const +{ + if(service != RS_SERVICE_TYPE_RTT) + return NULL ; + switch(type) + { + case RS_PKT_SUBTYPE_RTT_PING: return new RsRttPingItem() ; //= 0x01; + case RS_PKT_SUBTYPE_RTT_PONG: return new RsRttPongItem() ; // = 0x02; + default: + return NULL ; + } +} + +void RsRttPingItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; + RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; +} + +void RsRttPongItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; + RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; + RsTypeSerializer::serial_process(j,ctx,mPongTS,"mPongTS") ; +} + +#ifdef TO_REMOVE RsRttPingItem::~RsRttPingItem() { return; @@ -370,4 +397,5 @@ RsItem* RsRttSerialiser::deserialise(void *data, uint32_t *pktsize) /*************************************************************************/ +#endif diff --git a/libretroshare/src/serialiser/rsrttitems.h b/libretroshare/src/serialiser/rsrttitems.h index 11a6b8889..cad02062e 100644 --- a/libretroshare/src/serialiser/rsrttitems.h +++ b/libretroshare/src/serialiser/rsrttitems.h @@ -31,6 +31,8 @@ #include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" +#include "serialization/rsserializer.h" + /**************************************************************************/ const uint8_t RS_PKT_SUBTYPE_RTT_PING = 0x01; @@ -39,12 +41,11 @@ const uint8_t RS_PKT_SUBTYPE_RTT_PONG = 0x02; class RsRttItem: public RsItem { public: - RsRttItem(uint8_t chat_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_RTT,chat_subtype) + RsRttItem(uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_RTT,subtype) { setPriorityLevel(QOS_PRIORITY_RS_RTT_PING) ;} // should be refined later. virtual ~RsRttItem() {}; virtual void clear() {}; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; }; class RsRttPingItem: public RsRttItem @@ -52,9 +53,10 @@ class RsRttPingItem: public RsRttItem public: RsRttPingItem() :RsRttItem(RS_PKT_SUBTYPE_RTT_PING) {} - virtual ~RsRttPingItem(); - virtual void clear(); - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual ~RsRttPingItem(){} + virtual void clear(){} + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; @@ -65,9 +67,10 @@ class RsRttPongItem: public RsRttItem public: RsRttPongItem() :RsRttItem(RS_PKT_SUBTYPE_RTT_PONG) {} - virtual ~RsRttPongItem(); - virtual void clear(); - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual ~RsRttPongItem(){} + virtual void clear(){} + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; @@ -75,29 +78,14 @@ class RsRttPongItem: public RsRttItem }; -class RsRttSerialiser: public RsSerialType +class RsRttSerialiser: public RsSerializer { public: - RsRttSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_RTT) - { return; } + RsRttSerialiser() :RsSerializer(RS_SERVICE_TYPE_RTT) {} -virtual ~RsRttSerialiser() { return; } + virtual ~RsRttSerialiser(){} -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 sizeRttPingItem(RsRttPingItem *); -virtual bool serialiseRttPingItem (RsRttPingItem *item, void *data, uint32_t *size); -virtual RsRttPingItem *deserialiseRttPingItem(void *data, uint32_t *size); - -virtual uint32_t sizeRttPongItem(RsRttPongItem *); -virtual bool serialiseRttPongItem (RsRttPongItem *item, void *data, uint32_t *size); -virtual RsRttPongItem *deserialiseRttPongItem(void *data, uint32_t *size); - + virtual RsItem *create_item(uint16_t service,uint8_t type) const; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rsserial.cc b/libretroshare/src/serialiser/rsserial.cc index 8624b5304..30fed530e 100644 --- a/libretroshare/src/serialiser/rsserial.cc +++ b/libretroshare/src/serialiser/rsserial.cc @@ -438,7 +438,7 @@ RsItem * RsSerialiser::deserialise(void *data, uint32_t *size) uint32_t failedtype = getRsItemId(data); std::cerr << "RsSerialiser::deserialise() FAILED PACKET Size: "; std::cerr << getRsItemSize(data) << " ID: "; - std::cerr << std::hex << failedtype << std::dec; + std::cerr << std::hex << failedtype << std::endl; std::cerr << "RsSerialiser::deserialise() FAILED PACKET: "; std::cerr << " Version: " << std::hex << (uint32_t) getRsItemVersion(failedtype) << std::dec; std::cerr << " Class: " << std::hex << (uint32_t) getRsItemClass(failedtype) << std::dec; diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index db765e36b..6670a377b 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -32,10 +32,11 @@ 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 */) const - { - return NULL ; - } + virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const=0; + // { + // std::cerr << "(EE) Serializer does not overload create_item(). This is probably an error."<< std::endl; + // return NULL ; + // } // The following functions overload RsSerialType. They *should not* need to be further overloaded. diff --git a/libretroshare/src/services/p3msgservice.h b/libretroshare/src/services/p3msgservice.h index a36486514..2b7370d06 100644 --- a/libretroshare/src/services/p3msgservice.h +++ b/libretroshare/src/services/p3msgservice.h @@ -40,7 +40,7 @@ #include "pqi/p3cfgmgr.h" #include "services/p3service.h" -#include "serialiser/rsmsgitems.h" +#include "rsitems/rsmsgitems.h" #include "util/rsthreads.h" #include "retroshare/rsgxsifacetypes.h" From 26e95416d14430c8230ddde4b5fd8357e998f213 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 11:06:51 +0200 Subject: [PATCH 040/106] moved RTT items to rsitems/ --- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/{serialiser => rsitems}/rsrttitems.cc | 4 +--- libretroshare/src/{serialiser => rsitems}/rsrttitems.h | 0 libretroshare/src/serialization/rsserializer.h | 4 ---- libretroshare/src/services/p3rtt.cc | 2 +- libretroshare/src/services/p3rtt.h | 2 +- 6 files changed, 5 insertions(+), 11 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsrttitems.cc (98%) rename libretroshare/src/{serialiser => rsitems}/rsrttitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 4d94f4c71..e6f1a4ef4 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -483,7 +483,7 @@ HEADERS += rsitems/itempriorities.h \ rsitems/rsbwctrlitems.h \ rsitems/rsdiscovery2items.h \ serialiser/rsheartbeatitems.h \ - serialiser/rsrttitems.h \ + rsitems/rsrttitems.h \ serialiser/rsgxsrecognitems.h \ serialiser/rsgxsupdateitems.h \ serialiser/rsserviceinfoitems.h \ @@ -631,7 +631,7 @@ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsbwctrlitems.cc \ rsitems/rsdiscovery2items.cc \ serialiser/rsheartbeatitems.cc \ - serialiser/rsrttitems.cc \ + rsitems/rsrttitems.cc \ serialiser/rsgxsrecognitems.cc \ serialiser/rsgxsupdateitems.cc \ serialiser/rsserviceinfoitems.cc \ diff --git a/libretroshare/src/serialiser/rsrttitems.cc b/libretroshare/src/rsitems/rsrttitems.cc similarity index 98% rename from libretroshare/src/serialiser/rsrttitems.cc rename to libretroshare/src/rsitems/rsrttitems.cc index 5965f1068..ce2423dd4 100644 --- a/libretroshare/src/serialiser/rsrttitems.cc +++ b/libretroshare/src/rsitems/rsrttitems.cc @@ -24,9 +24,7 @@ * */ -#include "serialiser/rsbaseserial.h" -#include "serialiser/rsrttitems.h" -//#include "serialiser/rstlvbase.h" +#include "rsitems/rsrttitems.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/serialiser/rsrttitems.h b/libretroshare/src/rsitems/rsrttitems.h similarity index 100% rename from libretroshare/src/serialiser/rsrttitems.h rename to libretroshare/src/rsitems/rsrttitems.h diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 6670a377b..92f409361 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -33,10 +33,6 @@ class RsSerializer: public RsSerialType * 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 */) const=0; - // { - // std::cerr << "(EE) Serializer does not overload create_item(). This is probably an error."<< std::endl; - // return NULL ; - // } // The following functions overload RsSerialType. They *should not* need to be further overloaded. diff --git a/libretroshare/src/services/p3rtt.cc b/libretroshare/src/services/p3rtt.cc index 987467b77..8d4b2700b 100644 --- a/libretroshare/src/services/p3rtt.cc +++ b/libretroshare/src/services/p3rtt.cc @@ -32,7 +32,7 @@ #include "pqi/p3linkmgr.h" #include "services/p3rtt.h" -#include "serialiser/rsrttitems.h" +#include "rsitems/rsrttitems.h" #include diff --git a/libretroshare/src/services/p3rtt.h b/libretroshare/src/services/p3rtt.h index 9b881fba8..8714e2e02 100644 --- a/libretroshare/src/services/p3rtt.h +++ b/libretroshare/src/services/p3rtt.h @@ -30,7 +30,7 @@ #include #include -#include "serialiser/rsrttitems.h" +#include "rsitems/rsrttitems.h" #include "services/p3service.h" #include "retroshare/rsrtt.h" From 976a80a7af810f8f9583df617dd2e34200c61773 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 13:30:18 +0200 Subject: [PATCH 041/106] switch rsfilelistitems to new serialization --- .../src/file_sharing/rsfilelistitems.cc | 45 ++++++++++++++++--- .../src/file_sharing/rsfilelistitems.h | 34 ++++---------- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index 800f2f3d8..254d89edd 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -26,6 +26,41 @@ #include "file_sharing/rsfilelistitems.h" +void RsFileListsSyncRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; + RsTypeSerializer::serial_process(j,ctx,flags ,"flags") ; + RsTypeSerializer::serial_process(j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ; + RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; +} +void RsFileListsSyncResponseItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; + RsTypeSerializer::serial_process (j,ctx,checksum,"checksum") ; + RsTypeSerializer::serial_process (j,ctx,flags ,"flags") ; + RsTypeSerializer::serial_process (j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ; + RsTypeSerializer::serial_process (j,ctx,request_id,"request_id") ; + RsTypeSerializer::serial_process(j,ctx,directory_content_data,"directory_content_data") ; +} + +RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const +{ + if(service != RS_SERVICE_TYPE_FILE_DATABASE) + return NULL ; + + switch(type) + { + case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: return new RsFileListsSyncRequestItem(); + case RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM: return new RsFileListsSyncResponseItem(); + default: + return NULL ; + } +} +void RsFileListsSyncResponseItem::clear() +{ + directory_content_data.TlvClear(); +} +#ifdef TO_REMOVE RsItem* RsFileListsSerialiser::deserialise(void *data, uint32_t *size) { #ifdef RSSERIAL_DEBUG @@ -325,13 +360,7 @@ uint32_t RsFileListsSyncResponseItem::serial_size()const return s; } -void RsFileListsSyncRequestItem::clear() -{ -} -void RsFileListsSyncResponseItem::clear() -{ - directory_content_data.TlvClear(); -} + std::ostream& RsFileListsSyncRequestItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsFileListsSyncReqItem", indent); @@ -363,3 +392,5 @@ std::ostream& RsFileListsSyncResponseItem::print(std::ostream &out, uint16_t ind return out; } + +#endif diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index d56827527..fd9a928d5 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -34,6 +34,8 @@ #include "serialiser/rstlvkeys.h" #include "gxs/rsgxsdata.h" +#include "serialization/rsserializer.h" + // These items have "flag type" numbers, but this is not used. const uint8_t RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM = 0x01; @@ -54,12 +56,7 @@ public: } virtual ~RsFileListsItem(){} - virtual bool serialise(void *data,uint32_t& size) const = 0 ; - virtual uint32_t serial_size() const = 0 ; virtual void clear() = 0; - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0; - - bool serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const; static const uint32_t FLAGS_SYNC_REQUEST = 0x0001 ; static const uint32_t FLAGS_SYNC_RESPONSE = 0x0002 ; @@ -79,12 +76,10 @@ public: RsFileListsSyncRequestItem() : RsFileListsItem(RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM) {} - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + virtual void clear(){} + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const ; - RsFileHash entry_hash ; // hash of the directory to sync uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc. uint32_t last_known_recurs_modf_TS; // time of last modification, computed over all files+directories below. @@ -98,10 +93,8 @@ public: RsFileListsSyncResponseItem() : RsFileListsItem(RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM) {} virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsFileHash entry_hash ; // hash of the directory to sync RsFileHash checksum ; // checksum of the bindary data, for checking @@ -112,24 +105,15 @@ public: RsTlvBinaryData directory_content_data ; // encoded binary data. This allows to vary the encoding format, in a way that is transparent to the serialiser. }; -class RsFileListsSerialiser : public RsSerialType +class RsFileListsSerialiser : public RsSerializer { public: - RsFileListsSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_FILE_DATABASE) {} + RsFileListsSerialiser() : RsSerializer(RS_SERVICE_TYPE_FILE_DATABASE) {} virtual ~RsFileListsSerialiser() {} - virtual uint32_t size(RsItem *item); - virtual bool serialise(RsItem *item, void *data, uint32_t *size); - virtual RsItem* deserialise(void *data, uint32_t *size); - -private: - RsFileListsSyncRequestItem *deserialFileListsSyncRequestItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP */ - RsFileListsSyncResponseItem *deserialFileListsSyncResponseItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP */ -// RsFileListsSyncResponseItem *deserialFileListsConfigItem (void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP */ - - bool checkItemHeader(void *data, uint32_t *size, uint8_t subservice_type); + virtual RsItem *create_item(uint16_t service,uint8_t type) const ; }; From dc2df071a57c14314614c35e8b01de97e6e289e6 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 14:14:34 +0200 Subject: [PATCH 042/106] renamed RsSerializer into RsServiceSerializer --- libretroshare/src/chat/distributedchat.cc | 8 +- libretroshare/src/chat/rschatitems.cc | 2 +- libretroshare/src/chat/rschatitems.h | 4 +- .../src/file_sharing/rsfilelistitems.cc | 334 ------------------ .../src/file_sharing/rsfilelistitems.h | 4 +- libretroshare/src/ft/ftserver.cc | 2 +- libretroshare/src/ft/ftserver.h | 4 +- libretroshare/src/rsitems/rsbanlistitems.h | 4 +- libretroshare/src/rsitems/rsbwctrlitems.h | 4 +- libretroshare/src/rsitems/rsdiscovery2items.h | 4 +- .../src/rsitems/rsfiletransferitems.h | 4 +- .../src/rsitems/rsgxsreputationitems.h | 4 +- libretroshare/src/rsitems/rsmsgitems.cc | 2 +- libretroshare/src/rsitems/rsmsgitems.h | 4 +- libretroshare/src/rsitems/rsrttitems.h | 4 +- .../src/serialization/rsserializer.cc | 14 +- .../src/serialization/rsserializer.h | 4 +- libretroshare/src/services/p3msgservice.cc | 8 +- libretroshare/src/turtle/rsturtleitem.h | 4 +- .../src/turtle/turtleclientservice.h | 2 +- 20 files changed, 43 insertions(+), 377 deletions(-) diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index 79c41b2f2..696ce3058 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -222,7 +222,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id)); - uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast(obj)) ; + uint32_t size = RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast(obj)) ; RsTemporaryMemory memory(size) ; #ifdef DEBUG_CHAT_LOBBIES @@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const std::cerr << " signature id: " << obj->signature.keyId << std::endl; #endif - if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast(obj),memory,&size)) + if(!RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast(obj),memory,&size)) { std::cerr << " (EE) Cannot serialise message item. " << std::endl; return false ; @@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId& // now sign the object, if the lobby expects it - uint32_t size = RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast(&item)) ; + uint32_t size = RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast(&item)) ; RsTemporaryMemory memory(size) ; - if(!RsChatSerialiser(RsSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast(&item),memory,&size)) + if(!RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast(&item),memory,&size)) { std::cerr << "(EE) Cannot sign message item. " << std::endl; return false ; diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index e30c401c1..7aa0dd4f3 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -86,7 +86,7 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,nick,"nick") ; - if(!(ctx.mFlags & RsSerializer::SERIALIZATION_FLAG_SIGNATURE)) + if(!(ctx.mFlags & RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE)) RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index b357f0873..1766dbfec 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -321,11 +321,11 @@ class RsChatAvatarItem: public RsChatItem unsigned char *image_data ; // image }; -class RsChatSerialiser: public RsSerializer +class RsChatSerialiser: public RsServiceSerializer { public: RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) - :RsSerializer(RS_SERVICE_TYPE_CHAT,SerializeContext::FORMAT_BINARY,flags) {} + :RsServiceSerializer(RS_SERVICE_TYPE_CHAT,SerializeContext::FORMAT_BINARY,flags) {} virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ; }; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index 254d89edd..85a94488f 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -60,337 +60,3 @@ void RsFileListsSyncResponseItem::clear() { directory_content_data.TlvClear(); } -#ifdef TO_REMOVE -RsItem* RsFileListsSerialiser::deserialise(void *data, uint32_t *size) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (getRsItemService(rstype) != RS_SERVICE_TYPE_FILE_DATABASE)) - return NULL; /* wrong type */ - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM: return deserialFileListsSyncRequestItem(data, size); - case RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM: return deserialFileListsSyncResponseItem(data, size); -// case RS_PKT_SUBTYPE_FILELISTS_CONFIG_ITEM: return deserialFileListsConfigItem (data, size); - - default: - { - std::cerr << "(WW) RsFileListsSerialiser::deserialise() : unhandled item type " << getRsItemSubType(rstype) << std::endl; - return NULL; - - } - } -} - -uint32_t RsFileListsSerialiser::size(RsItem *item) -{ - RsFileListsItem *flst_item = dynamic_cast(item) ; - - if(flst_item != NULL) - return flst_item->serial_size() ; - else - { - std::cerr << "RsFileListsSerialiser::serialise(): Not an RsFileListsItem!" << std::endl; - return 0; - } -} - -bool RsFileListsSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsFileListsItem *flst_item = dynamic_cast(item) ; - - if(flst_item != NULL) - return flst_item->serialise(data,*size) ; - else - { - std::cerr << "RsFileListsSerialiser::serialise(): Not an RsFileListsItem!" << std::endl; - return 0; - } -} - -bool RsFileListsItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; -} - -bool RsFileListsSyncRequestItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::serialiseFileListsSyncReqItem()" << std::endl; -#endif - - /* RsFileListsSyncMsgItem */ - - ok &= entry_hash.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, flags ); - ok &= setRawUInt32(data, size, &offset, last_known_recurs_modf_TS); - ok &= setRawUInt64(data, size, &offset, request_id); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsFileListsSyncResponseItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::serialiseFileListsSyncReqItem()" << std::endl; -#endif - - /* RsFileListsSyncMsgItem */ - - ok &= entry_hash.serialise(data, size, offset); - ok &= checksum.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, flags ); - ok &= setRawUInt32(data, size, &offset, last_known_recurs_modf_TS); - ok &= setRawUInt64(data, size, &offset, request_id); - ok &= directory_content_data.SetTlv(data,size,&offset) ; - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl; - } -#endif - - return ok; -} - -//============================================================================================================================// -// Deserialisation // -//============================================================================================================================// - -//RsFileListsConfigItem* RsFileListsSerialiser::deserialFileListsConfigItem(void *data, uint32_t *size) -//{ -// NOT_IMPLEMENTED(); -// -// return NULL ; -//} - -RsFileListsSyncRequestItem* RsFileListsSerialiser::deserialFileListsSyncRequestItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_FILELISTS_SYNC_REQ_ITEM); - uint32_t offset = 8; - - RsFileListsSyncRequestItem* item = new RsFileListsSyncRequestItem(); - - ok &= item->entry_hash.deserialise(data, *size, offset); - ok &= getRawUInt32(data, *size, &offset, &item->flags); - ok &= getRawUInt32(data, *size, &offset, &item->last_known_recurs_modf_TS); - ok &= getRawUInt64(data, *size, &offset, &item->request_id); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::deserialNxsGrp() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::deserialNxsGrp() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsFileListsSyncResponseItem* RsFileListsSerialiser::deserialFileListsSyncResponseItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_FILELISTS_SYNC_RSP_ITEM); - uint32_t offset = 8; - - RsFileListsSyncResponseItem* item = new RsFileListsSyncResponseItem(); - - /* - uint32_t entry_index ; // index of the directory to sync - uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc. - uint32_t last_known_recurs_modf_TS; // time of last modification, computed over all files+directories below. - uint64_t request_id; // use to determine if changes that have occured since last hash - */ - - ok &= item->entry_hash.deserialise(data, *size, offset); - ok &= item->checksum.deserialise(data, *size, offset); - ok &= getRawUInt32(data, *size, &offset, &item->flags); - ok &= getRawUInt32(data, *size, &offset, &item->last_known_recurs_modf_TS); - ok &= getRawUInt64(data, *size, &offset, &item->request_id); - - ok &= item->directory_content_data.GetTlv(data,*size,&offset) ; - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::deserialNxsGrp() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::deserialNxsGrp() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -bool RsFileListsSerialiser::checkItemHeader(void *data,uint32_t *size,uint8_t subservice_type) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::checkItemHeader()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_FILE_DATABASE != getRsItemService(rstype)) || (subservice_type != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::checkItemHeader() FAIL wrong type" << std::endl; -#endif - return false; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileListsSerialiser::checkItemHeader() FAIL wrong size" << std::endl; -#endif - return false; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - return true ; -} - -//============================================================================================================================// -// Sizes // -//============================================================================================================================// - -uint32_t RsFileListsSyncRequestItem::serial_size()const -{ - - uint32_t s = 8; //header size - - s += RsFileHash::serial_size(); // entry hash - s += 4; // flags - s += 4; // last_known_recurs_modf_TS - s += 8; // request_id - - return s; -} - -uint32_t RsFileListsSyncResponseItem::serial_size()const -{ - - uint32_t s = 8; //header size - - s += RsFileHash::serial_size(); // entry hash - s += RsFileHash::serial_size(); // checksum - s += 4; // flags - s += 4; // last_known_recurs_modf_TS - s += 8; // request_id - s += directory_content_data.TlvSize(); - - return s; -} - - -std::ostream& RsFileListsSyncRequestItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileListsSyncReqItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); out << "Entry hash: " << entry_hash << std::endl; - printIndent(out , int_Indent); out << "Flags: " << (uint32_t) flags << std::endl; - printIndent(out , int_Indent); out << "Last modf TS: " << last_known_recurs_modf_TS << std::endl; - printIndent(out , int_Indent); out << "request id: " << std::hex << request_id << std::dec << std::endl; - - printRsItemEnd(out ,"RsFileListsSyncReqItem", indent); - - return out; -} - -std::ostream& RsFileListsSyncResponseItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileListsSyncDirItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); out << "Entry hash: " << entry_hash << std::endl; - printIndent(out , int_Indent); out << "Checksum : " << checksum << std::endl; - printIndent(out , int_Indent); out << "Flags: " << (uint32_t) flags << std::endl; - printIndent(out , int_Indent); out << "Last modf TS: " << last_known_recurs_modf_TS << std::endl; - printIndent(out , int_Indent); out << "request id: " << std::hex << request_id << std::dec << std::endl; - printIndent(out , int_Indent); out << "Data size: " << directory_content_data.bin_len << std::endl; - - printRsItemEnd(out ,"RsFileListsSyncDirItem", indent); - - return out; -} - -#endif diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index fd9a928d5..391d3dd88 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -105,11 +105,11 @@ public: RsTlvBinaryData directory_content_data ; // encoded binary data. This allows to vary the encoding format, in a way that is transparent to the serialiser. }; -class RsFileListsSerialiser : public RsSerializer +class RsFileListsSerialiser : public RsServiceSerializer { public: - RsFileListsSerialiser() : RsSerializer(RS_SERVICE_TYPE_FILE_DATABASE) {} + RsFileListsSerialiser() : RsServiceSerializer(RS_SERVICE_TYPE_FILE_DATABASE) {} virtual ~RsFileListsSerialiser() {} diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 9dcc139d4..15a44f34f 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -64,7 +64,7 @@ static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priorit /* Setup */ ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc) - : p3Service(),RsSerializer(RS_SERVICE_TYPE_TURTLE), // should be FT, but this is for backward compatibility + : p3Service(),RsServiceSerializer(RS_SERVICE_TYPE_TURTLE), // should be FT, but this is for backward compatibility mPeerMgr(pm), mServiceCtrl(sc), mFileDatabase(NULL), mFtController(NULL), mFtExtra(NULL), diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 23606b28e..5ad4824b5 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -68,7 +68,7 @@ class p3PeerMgr; class p3ServiceControl; class p3FileDatabase; -class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTurtleClientService, public RsSerializer +class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTurtleClientService, public RsServiceSerializer { public: @@ -98,7 +98,7 @@ 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) const ; - virtual RsSerializer *serializer() { return this ; } + virtual RsServiceSerializer *serializer() { return this ; } void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ; diff --git a/libretroshare/src/rsitems/rsbanlistitems.h b/libretroshare/src/rsitems/rsbanlistitems.h index cc3f96eeb..3fce37956 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.h +++ b/libretroshare/src/rsitems/rsbanlistitems.h @@ -72,10 +72,10 @@ public: RsTlvBanList banned_peers; }; -class RsBanListSerialiser: public RsSerializer +class RsBanListSerialiser: public RsServiceSerializer { public: - RsBanListSerialiser() :RsSerializer(RS_SERVICE_TYPE_BANLIST) {} + RsBanListSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_BANLIST) {} virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ; }; diff --git a/libretroshare/src/rsitems/rsbwctrlitems.h b/libretroshare/src/rsitems/rsbwctrlitems.h index e9262cd5b..e21410b39 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.h +++ b/libretroshare/src/rsitems/rsbwctrlitems.h @@ -57,10 +57,10 @@ public: }; -class RsBwCtrlSerialiser: public RsSerializer +class RsBwCtrlSerialiser: public RsServiceSerializer { public: - RsBwCtrlSerialiser() :RsSerializer(RS_SERVICE_TYPE_BWCTRL) {} + RsBwCtrlSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_BWCTRL) {} virtual ~RsBwCtrlSerialiser() {} RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const; diff --git a/libretroshare/src/rsitems/rsdiscovery2items.h b/libretroshare/src/rsitems/rsdiscovery2items.h index fc1a944cb..7610d534f 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.h +++ b/libretroshare/src/rsitems/rsdiscovery2items.h @@ -166,10 +166,10 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); #endif -class RsDiscSerialiser: public RsSerializer +class RsDiscSerialiser: public RsServiceSerializer { public: - RsDiscSerialiser() :RsSerializer(RS_SERVICE_TYPE_DISC) {} + RsDiscSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_DISC) {} virtual ~RsDiscSerialiser() {} diff --git a/libretroshare/src/rsitems/rsfiletransferitems.h b/libretroshare/src/rsitems/rsfiletransferitems.h index 5cfed03b9..b51e74d53 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.h +++ b/libretroshare/src/rsitems/rsfiletransferitems.h @@ -176,10 +176,10 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem /**************************************************************************/ -class RsFileTransferSerialiser: public RsSerializer +class RsFileTransferSerialiser: public RsServiceSerializer { public: - RsFileTransferSerialiser(): RsSerializer(RS_SERVICE_TYPE_FILE_TRANSFER) {} + RsFileTransferSerialiser(): RsServiceSerializer(RS_SERVICE_TYPE_FILE_TRANSFER) {} virtual ~RsFileTransferSerialiser() {} diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.h b/libretroshare/src/rsitems/rsgxsreputationitems.h index cc3f64a78..1f30a5d65 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.h +++ b/libretroshare/src/rsitems/rsgxsreputationitems.h @@ -163,10 +163,10 @@ public: }; -class RsGxsReputationSerialiser: public RsSerializer +class RsGxsReputationSerialiser: public RsServiceSerializer { public: - RsGxsReputationSerialiser() :RsSerializer(RS_SERVICE_GXS_TYPE_REPUTATION){} + RsGxsReputationSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_REPUTATION){} virtual ~RsGxsReputationSerialiser(){} virtual RsItem *create_item(uint16_t service,uint8_t item_type) const; diff --git a/libretroshare/src/rsitems/rsmsgitems.cc b/libretroshare/src/rsitems/rsmsgitems.cc index 7405f37e0..8fd2f2c55 100644 --- a/libretroshare/src/rsitems/rsmsgitems.cc +++ b/libretroshare/src/rsitems/rsmsgitems.cc @@ -158,7 +158,7 @@ void RsMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,attachment,"attachment"); - if(ctx.mFlags & RsSerializer::SERIALIZATION_FLAG_CONFIG) + if(ctx.mFlags & RsServiceSerializer::SERIALIZATION_FLAG_CONFIG) RsTypeSerializer::serial_process(j,ctx,msgId,"msgId"); } diff --git a/libretroshare/src/rsitems/rsmsgitems.h b/libretroshare/src/rsitems/rsmsgitems.h index 5eb94e5b4..f0916352b 100644 --- a/libretroshare/src/rsitems/rsmsgitems.h +++ b/libretroshare/src/rsitems/rsmsgitems.h @@ -235,11 +235,11 @@ class RsMsgParentId : public RsMessageItem uint32_t msgParentId; }; -class RsMsgSerialiser: public RsSerializer +class RsMsgSerialiser: public RsServiceSerializer { public: RsMsgSerialiser(SerializationFlags flags) - :RsSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){} + :RsServiceSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){} virtual ~RsMsgSerialiser() {} diff --git a/libretroshare/src/rsitems/rsrttitems.h b/libretroshare/src/rsitems/rsrttitems.h index cad02062e..b3e5bdec2 100644 --- a/libretroshare/src/rsitems/rsrttitems.h +++ b/libretroshare/src/rsitems/rsrttitems.h @@ -78,10 +78,10 @@ class RsRttPongItem: public RsRttItem }; -class RsRttSerialiser: public RsSerializer +class RsRttSerialiser: public RsServiceSerializer { public: - RsRttSerialiser() :RsSerializer(RS_SERVICE_TYPE_RTT) {} + RsRttSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_RTT) {} virtual ~RsRttSerialiser(){} diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 85a7a9430..0a468abf5 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -2,11 +2,11 @@ #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" -const SerializationFlags RsSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); -const SerializationFlags RsSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); -const SerializationFlags RsSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 ); +const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); +const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); +const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 ); -RsItem *RsSerializer::deserialise(void *data, uint32_t *size) +RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; @@ -37,7 +37,7 @@ RsItem *RsSerializer::deserialise(void *data, uint32_t *size) return NULL ; } -bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size) +bool RsServiceSerializer::serialise(RsItem *item,void *data,uint32_t *size) { SerializeContext ctx(static_cast(data),0,mFormat,mFlags); @@ -64,7 +64,7 @@ bool RsSerializer::serialise(RsItem *item,void *data,uint32_t *size) return true ; } -uint32_t RsSerializer::size(RsItem *item) +uint32_t RsServiceSerializer::size(RsItem *item) { SerializeContext ctx(NULL,0,mFormat,mFlags); @@ -74,7 +74,7 @@ uint32_t RsSerializer::size(RsItem *item) return ctx.mOffset ; } -void RsSerializer::print(RsItem *item) +void RsServiceSerializer::print(RsItem *item) { SerializeContext ctx(NULL,0,mFormat,mFlags); diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 92f409361..60860b426 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -10,7 +10,7 @@ #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " -class RsSerializer: public RsSerialType +class RsServiceSerializer: public RsSerialType { public: // These are convenience flags to be used by the items when processing the data. The names of the flags @@ -23,7 +23,7 @@ class RsSerializer: public RsSerialType static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001 static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002 - RsSerializer(uint16_t service_id, + RsServiceSerializer(uint16_t service_id, SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, SerializationFlags flags = SERIALIZATION_FLAG_NONE) diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 44c244023..a3aacfc7b 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -86,7 +86,7 @@ static const uint32_t RS_MSG_DISTANT_MESSAGE_HASH_KEEP_TIME = 2*30*86400 ; // ke p3MsgService::p3MsgService(p3ServiceControl *sc, p3IdService *id_serv) :p3Service(), p3Config(), mIdService(id_serv), mServiceCtrl(sc), mMsgMtx("p3MsgService"), mMsgUniqueId(0) { - _serialiser = new RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_NONE); // this serialiser is used for services. It's not the same than the one returned by setupSerialiser(). We need both!! + _serialiser = new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE); // this serialiser is used for services. It's not the same than the one returned by setupSerialiser(). We need both!! addSerialType(_serialiser); mMsgUniqueId = 1 ; // MsgIds are not transmitted, but only used locally as a storage index. As such, thay do not need to be different @@ -519,7 +519,7 @@ RsSerialiser* p3MsgService::setupSerialiser() // this serialiser is used for con { RsSerialiser *rss = new RsSerialiser ; - rss->addSerialType(new RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_CONFIG)); + rss->addSerialType(new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_CONFIG)); rss->addSerialType(new RsGeneralConfigSerialiser()); return rss; @@ -2024,10 +2024,10 @@ void p3MsgService::sendDistantMsgItem(RsMsgItem *msgitem) // The item is serialized and turned into a generic turtle item. Use use the explicit serialiser to make sure that the msgId is not included - uint32_t msg_serialized_rssize = RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_NONE).size(msgitem) ; + uint32_t msg_serialized_rssize = RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE).size(msgitem) ; RsTemporaryMemory msg_serialized_data(msg_serialized_rssize) ; - if(!RsMsgSerialiser(RsSerializer::SERIALIZATION_FLAG_NONE).serialise(msgitem,msg_serialized_data,&msg_serialized_rssize)) + if(!RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE).serialise(msgitem,msg_serialized_data,&msg_serialized_rssize)) { std::cerr << "(EE) p3MsgService::sendTurtleData(): Serialization error." << std::endl; return ; diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 0249cce22..9bc3fc4bf 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -205,10 +205,10 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem /* Turtle Serialiser class */ /***********************************************************************************/ -class RsTurtleSerialiser: public RsSerializer +class RsTurtleSerialiser: public RsServiceSerializer { public: - RsTurtleSerialiser() : RsSerializer(RS_SERVICE_TYPE_TURTLE) {} + RsTurtleSerialiser() : RsServiceSerializer(RS_SERVICE_TYPE_TURTLE) {} virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const; diff --git a/libretroshare/src/turtle/turtleclientservice.h b/libretroshare/src/turtle/turtleclientservice.h index 7fa4d8b18..d9552c662 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 RsSerializer *serializer() { return NULL ; } + virtual RsServiceSerializer *serializer() { return NULL ; } // These methods are called by the turtle router to add/remove virtual peers when tunnels are created/deleted // From 8ae6541ceb4daea26e77ea7b2b41934980ca3893 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 17:10:01 +0200 Subject: [PATCH 043/106] added two new classes for config/service serialisers and a base generic serialiser class --- .../src/serialization/rsserializer.cc | 14 ++--- .../src/serialization/rsserializer.h | 52 +++++++++++++++---- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 0a468abf5..9f14ee91e 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -2,11 +2,11 @@ #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" -const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); -const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); -const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 ); +const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); +const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); +const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 ); -RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) +RsItem *RsGenericSerializer::deserialise(void *data, uint32_t *size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; @@ -37,7 +37,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) return NULL ; } -bool RsServiceSerializer::serialise(RsItem *item,void *data,uint32_t *size) +bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size) { SerializeContext ctx(static_cast(data),0,mFormat,mFlags); @@ -64,7 +64,7 @@ bool RsServiceSerializer::serialise(RsItem *item,void *data,uint32_t *size) return true ; } -uint32_t RsServiceSerializer::size(RsItem *item) +uint32_t RsGenericSerializer::size(RsItem *item) { SerializeContext ctx(NULL,0,mFormat,mFlags); @@ -74,7 +74,7 @@ uint32_t RsServiceSerializer::size(RsItem *item) return ctx.mOffset ; } -void RsServiceSerializer::print(RsItem *item) +void RsGenericSerializer::print(RsItem *item) { SerializeContext ctx(NULL,0,mFormat,mFlags); diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 60860b426..33e643215 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -10,9 +10,11 @@ #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " -class RsServiceSerializer: public RsSerialType +class RsGenericSerializer: public RsSerialType { - public: +public: + + // These are convenience flags to be used by the items when processing the data. The names of the flags // are not very important. What matters is that the serial_process() method of each item correctly // deals with the data when it sees the flags, if the serialiser sets them. By default the flags are not @@ -23,13 +25,7 @@ class RsServiceSerializer: public RsSerialType static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001 static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002 - RsServiceSerializer(uint16_t service_id, - SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, - SerializationFlags flags = SERIALIZATION_FLAG_NONE) - - : RsSerialType(RS_PKT_VERSION_SERVICE,service_id),mFormat(format),mFlags(flags) {} - - /*! create_item + /*! 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 */) const=0; @@ -41,10 +37,48 @@ class RsServiceSerializer: public RsSerialType uint32_t size(RsItem *item) ; void print(RsItem *item) ; +protected: + RsGenericSerializer(uint8_t serial_class, + uint8_t serial_type, + SerializeContext::SerializationFormat format, + SerializationFlags flags ) + : RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags) + {} + + RsGenericSerializer(uint16_t service, + SerializeContext::SerializationFormat format, + SerializationFlags flags ) + : RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags) + {} + private: SerializeContext::SerializationFormat mFormat ; SerializationFlags mFlags ; + +}; + +class RsServiceSerializer: public RsGenericSerializer +{ +public: + RsServiceSerializer(uint16_t service_id, + SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, + SerializationFlags flags = SERIALIZATION_FLAG_NONE) + + : RsGenericSerializer(service_id,format,flags) {} +}; + +class RsConfigSerializer: public RsGenericSerializer +{ +public: + RsConfigSerializer(uint8_t config_class, + uint8_t config_type, + SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, + SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE) + + : RsGenericSerializer(config_class,config_type,format,flags) {} }; + + From af4fcf767902c19ff3cd2d4cbef5f60ac9157b7d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 17:33:30 +0200 Subject: [PATCH 044/106] switched rshistoryitems to new serialization --- .../src/serialiser/rshistoryitems.cc | 35 ++++++++++++++++--- libretroshare/src/serialiser/rshistoryitems.h | 24 ++++++------- .../src/serialization/rsserializer.cc | 31 +++++++++++++++- .../src/serialization/rsserializer.h | 22 ++++++++---- 4 files changed, 85 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/serialiser/rshistoryitems.cc b/libretroshare/src/serialiser/rshistoryitems.cc index 2ecbf591b..6c05e9afb 100644 --- a/libretroshare/src/serialiser/rshistoryitems.cc +++ b/libretroshare/src/serialiser/rshistoryitems.cc @@ -34,7 +34,31 @@ #include -/*************************************************************************/ +void RsHistoryMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + uint16_t version=0; + + RsTypeSerializer::serial_process(j,ctx,version,"version") ; + RsTypeSerializer::serial_process (j,ctx,chatPeerId,"chatPeerId") ; + RsTypeSerializer::serial_process (j,ctx,incoming,"incoming") ; + RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,peerName,"peerName") ; + RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; + RsTypeSerializer::serial_process(j,ctx,recvTime,"recvTime") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message") ; +} + +RsItem *RsHistorySerialiser::create_item(uint8_t serial_class,uint8_t serial_type) const +{ + if(serial_class != RS_PKT_CLASS_CONFIG) + return NULL ; + + if(serial_type == RS_PKT_SUBTYPE_DEFAULT) + return new RsHistoryMsgItem(); + + return NULL ; +} + RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG, RS_PKT_SUBTYPE_DEFAULT) { @@ -45,6 +69,9 @@ RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONF saveToDisc = true; } +#ifdef TO_REMOVE + +/*************************************************************************/ RsHistoryMsgItem::~RsHistoryMsgItem() { } @@ -92,9 +119,6 @@ std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent) return out; } -RsHistorySerialiser::RsHistorySerialiser() : RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) -{ -} RsHistorySerialiser::~RsHistorySerialiser() { @@ -114,7 +138,6 @@ uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item) return s; } - /* serialise the data to the buffer */ bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize) { @@ -266,3 +289,5 @@ RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize) } /*************************************************************************/ + +#endif diff --git a/libretroshare/src/serialiser/rshistoryitems.h b/libretroshare/src/serialiser/rshistoryitems.h index 72f186561..ffc5b571c 100644 --- a/libretroshare/src/serialiser/rshistoryitems.h +++ b/libretroshare/src/serialiser/rshistoryitems.h @@ -28,18 +28,21 @@ #include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" +#include "serialiser/rsconfigitems.h" #include "retroshare/rstypes.h" +#include "serialization/rsserializer.h" + /**************************************************************************/ class RsHistoryMsgItem: public RsItem { public: RsHistoryMsgItem(); - virtual ~RsHistoryMsgItem(); + virtual ~RsHistoryMsgItem() {} + virtual void clear() {} - virtual void clear(); - std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsPeerId chatPeerId; // empty for global chat bool incoming; @@ -54,20 +57,13 @@ public: bool saveToDisc; }; -class RsHistorySerialiser: public RsSerialType +class RsHistorySerialiser: public RsConfigSerializer { public: - RsHistorySerialiser(); - virtual ~RsHistorySerialiser(); - - virtual uint32_t size(RsItem*); - virtual bool serialise(RsItem* item, void* data, uint32_t* size); - virtual RsItem* deserialise(void* data, uint32_t* size); + RsHistorySerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) {} + virtual ~RsHistorySerialiser() {} -private: - virtual uint32_t sizeHistoryMsgItem(RsHistoryMsgItem*); - virtual bool serialiseHistoryMsgItem (RsHistoryMsgItem* item, void* data, uint32_t* size); - virtual RsHistoryMsgItem* deserialiseHistoryMsgItem(void* data, uint32_t* size); + virtual RsItem *create_item(uint8_t service,uint8_t type) const ; }; /**************************************************************************/ diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 9f14ee91e..ab47e9429 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -6,7 +6,7 @@ const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0 const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 ); -RsItem *RsGenericSerializer::deserialise(void *data, uint32_t *size) +RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; @@ -36,7 +36,36 @@ RsItem *RsGenericSerializer::deserialise(void *data, uint32_t *size) delete item ; return NULL ; } +RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size) +{ + uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; + RsItem *item = create_item(getRsItemClass(rstype),getRsItemSubType(rstype)) ; + + if(!item) + { + std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl; + return NULL ; + } + + SerializeContext ctx(const_cast(static_cast(data)),*size,mFormat,mFlags); + ctx.mOffset = 8 ; + + item->serial_process(RsItem::DESERIALIZE, ctx) ; + + if(ctx.mSize != ctx.mOffset) + { + std::cerr << "RsSerializer::deserialise(): ERROR. offset does not match expected size!" << std::endl; + delete item ; + return NULL ; + } + if(ctx.mOk) + return item ; + + delete item ; + return NULL ; +} bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size) { SerializeContext ctx(static_cast(data),0,mFormat,mFlags); diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 33e643215..3285becf9 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -25,14 +25,9 @@ public: static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001 static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002 - /*! 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 */) const=0; - // The following functions overload RsSerialType. They *should not* need to be further overloaded. - RsItem *deserialise(void *data,uint32_t *size) ; + RsItem *deserialise(void *data,uint32_t *size) =0; bool serialise(RsItem *item,void *data,uint32_t *size) ; uint32_t size(RsItem *item) ; void print(RsItem *item) ; @@ -51,7 +46,6 @@ protected: : RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags) {} -private: SerializeContext::SerializationFormat mFormat ; SerializationFlags mFlags ; @@ -65,6 +59,13 @@ public: SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsGenericSerializer(service_id,format,flags) {} + + /*! 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 */) const=0; + + RsItem *deserialise(void *data,uint32_t *size) ; }; class RsConfigSerializer: public RsGenericSerializer @@ -76,6 +77,13 @@ public: SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE) : RsGenericSerializer(config_class,config_type,format,flags) {} + + /*! create_item + * should be overloaded to create the correct type of item depending on the data + */ + virtual RsItem *create_item(uint8_t /* class */, uint8_t /* item_type */) const=0; + + RsItem *deserialise(void *data,uint32_t *size) ; }; From fcabe6359f7667b18e23844056f4d6dbf9464b51 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 18:51:51 +0200 Subject: [PATCH 045/106] switch RsConfigItems to new serialization --- libretroshare/src/ft/ftextralist.cc | 5 +- libretroshare/src/pqi/p3peermgr.cc | 3 +- libretroshare/src/serialiser/rsconfigitems.cc | 278 ++++++++++++++---- libretroshare/src/serialiser/rsconfigitems.h | 185 ++++-------- 4 files changed, 297 insertions(+), 174 deletions(-) diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index e63a5f1a8..8538a46a9 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -396,7 +396,8 @@ bool ftExtraList::saveList(bool &cleanup, std::list& sList) std::map::const_iterator it; for(it = mFiles.begin(); it != mFiles.end(); ++it) { - RsFileConfigItem_deprecated *fi = new RsFileConfigItem_deprecated(); + RsFileConfigItem *fi = new RsFileConfigItem(); + fi->file.path = (it->second).info.path; fi->file.name = (it->second).info.fname; fi->file.hash = (it->second).info.hash; @@ -429,7 +430,7 @@ bool ftExtraList::loadList(std::list& load) for(it = load.begin(); it != load.end(); ++it) { - RsFileConfigItem_deprecated *fi = dynamic_cast(*it); + RsFileConfigItem *fi = dynamic_cast(*it); if (!fi) { delete (*it); diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 97e738a40..d26c4a950 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2294,7 +2294,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) continue; } - +#ifdef TO_REMOVE RsPeerGroupItem_deprecated *gitem = dynamic_cast(*it) ; if (gitem) @@ -2331,6 +2331,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) continue; } +#endif RsNodeGroupItem *gitem2 = dynamic_cast(*it) ; diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 9b94d454d..0c603ed3a 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -40,6 +40,37 @@ /*************************************************************************/ +RsItem *RsFileConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const +{ + if(item_class != RS_PKT_CLASS_CONFIG) + return NULL ; + + switch(item_type) + { + case RS_PKT_SUBTYPE_FILE_TRANSFER: return new RsFileTransfer() ; + case RS_PKT_SUBTYPE_FILE_ITEM: return new RsFileConfigItem() ; + default: + return NULL ; + } +} +void RsFileTransfer::clear() +{ + + file.TlvClear(); + allPeerIds.TlvClear(); + cPeerId.clear() ; + state = 0; + in = false; + transferred = 0; + crate = 0; + trate = 0; + lrate = 0; + ltransfer = 0; + +} + + +#ifdef TO_REMOVE uint32_t RsFileConfigSerialiser::size(RsItem *i) { RsFileTransfer *rft; @@ -110,22 +141,6 @@ RsFileTransfer::~RsFileTransfer() return; } -void RsFileTransfer::clear() -{ - - file.TlvClear(); - allPeerIds.TlvClear(); - cPeerId.clear() ; - state = 0; - in = false; - transferred = 0; - crate = 0; - trate = 0; - lrate = 0; - ltransfer = 0; - -} - std::ostream &RsFileTransfer::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsFileTransfer", indent); @@ -231,7 +246,31 @@ uint32_t RsFileConfigSerialiser::sizeTransfer(RsFileTransfer *item) return s; } +#endif +void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,file,"file") ; + RsTypeSerializer::serial_process(j,ctx,allPeerIds,"allPeerIds") ; + + RsTypeSerializer::serial_process (j,ctx,cPeerId,"cPeerId") ; + + RsTypeSerializer::serial_process (j,ctx,state,"state") ; + RsTypeSerializer::serial_process (j,ctx,in,"in") ; + + RsTypeSerializer::serial_process (j,ctx,transferred,"transferred") ; + + RsTypeSerializer::serial_process (j,ctx,crate,"crate") ; + RsTypeSerializer::serial_process (j,ctx,trate,"trate") ; + RsTypeSerializer::serial_process (j,ctx,lrate,"lrate") ; + RsTypeSerializer::serial_process (j,ctx,ltransfer,"ltransfer") ; + + RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; + RsTypeSerializer::serial_process (j,ctx,chunk_strategy,"chunk_strategy") ; + RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ; +} + +#ifdef TO_REMOVE bool RsFileConfigSerialiser::serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *pktsize) { uint32_t tlvsize = sizeTransfer(item); @@ -374,7 +413,16 @@ uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item) return s; } +#endif +void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,file,"file") ; + RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; + RsTypeSerializer::serial_process(j,ctx,parent_groups,"parent_groups") ; +} + +#ifdef TO_REMOVE bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *pktsize) { uint32_t tlvsize = sizeFileItem(item); @@ -540,6 +588,22 @@ RsGeneralConfigSerialiser::~RsGeneralConfigSerialiser() return; } +#endif + +RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const +{ + if(item_class != RS_PKT_TYPE_GENERAL_CONFIG) + return NULL ; + + switch(item_type) + { + case RS_PKT_SUBTYPE_KEY_VALUE: return new RsConfigKeyValueSet(); + default: + return NULL ; + } +} + +#ifdef TO_REMOVE uint32_t RsGeneralConfigSerialiser::size(RsItem *i) { RsConfigKeyValueSet *kvs; @@ -632,7 +696,14 @@ uint32_t RsGeneralConfigSerialiser::sizeKeyValueSet(RsConfigKeyValueSet *item return s; } +#endif +void RsConfigKeyValueSet::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,tlvkvs,"tlvkvs") ; +} + +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsGeneralConfigSerialiser::serialiseKeyValueSet(RsConfigKeyValueSet *item, void *data, uint32_t *pktsize) { @@ -745,7 +816,49 @@ RsPeerConfigSerialiser::~RsPeerConfigSerialiser() { return; } +#endif +RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const +{ + if(item_class != RS_PKT_TYPE_PEER_CONFIG) + return NULL ; + + switch(item_type) + { + case RS_PKT_SUBTYPE_PEER_NET: return new RsPeerNetItem(); + case RS_PKT_SUBTYPE_PEER_STUN: return new RsPeerStunItem(); + case RS_PKT_SUBTYPE_NODE_GROUP: return new RsNodeGroupItem() ; + case RS_PKT_SUBTYPE_PEER_PERMISSIONS: return new RsPeerServicePermissionItem(); + case RS_PKT_SUBTYPE_PEER_BANDLIMITS: return new RsPeerBandwidthLimitsItem(); + default: + return NULL ; + } +} + +void RsPeerNetItem::clear() +{ + peerId.clear(); + pgpId.clear(); + location.clear(); + netMode = 0; + vs_disc = 0; + vs_dht = 0; + lastContact = 0; + + localAddrV4.TlvClear(); + extAddrV4.TlvClear(); + localAddrV6.TlvClear(); + extAddrV6.TlvClear(); + + dyndns.clear(); + + localAddrList.TlvClear(); + extAddrList.TlvClear(); + + domain_addr.clear(); + domain_port = 0; +} +#ifdef TO_REMOVE uint32_t RsPeerConfigSerialiser::size(RsItem *i) { RsPeerStunItem *psi; @@ -855,29 +968,7 @@ RsPeerNetItem::~RsPeerNetItem() return; } -void RsPeerNetItem::clear() -{ - peerId.clear(); - pgpId.clear(); - location.clear(); - netMode = 0; - vs_disc = 0; - vs_dht = 0; - lastContact = 0; - localAddrV4.TlvClear(); - extAddrV4.TlvClear(); - localAddrV6.TlvClear(); - extAddrV6.TlvClear(); - - dyndns.clear(); - - localAddrList.TlvClear(); - extAddrList.TlvClear(); - - domain_addr.clear(); - domain_port = 0; -} std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent) { @@ -963,7 +1054,34 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i) return s; } +#endif +void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ; + RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION,location,"location") ; + + RsTypeSerializer::serial_process(j,ctx,netMode,"netMode") ; + RsTypeSerializer::serial_process(j,ctx,vs_disc,"vs_disc") ; + RsTypeSerializer::serial_process(j,ctx,vs_dht,"vs_dht") ; + RsTypeSerializer::serial_process(j,ctx,lastContact,"lastContact") ; + + RsTypeSerializer::serial_process(j,ctx,localAddrV4,"localAddrV4") ; + RsTypeSerializer::serial_process(j,ctx,extAddrV4,"extAddrV4") ; + RsTypeSerializer::serial_process(j,ctx,localAddrV6,"localAddrV6") ; + RsTypeSerializer::serial_process(j,ctx,extAddrV6,"extAddrV6") ; + + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DYNDNS,dyndns,"dyndns") ; + + RsTypeSerializer::serial_process(j,ctx,localAddrList,"localAddrList") ; + RsTypeSerializer::serial_process(j,ctx,extAddrList,"extAddrList") ; + + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DOMADDR,domain_addr,"domain_addr") ; + RsTypeSerializer::serial_process(j,ctx,domain_port,"domain_port") ; +} + +#ifdef TO_REMOVE bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint32_t *size) { uint32_t tlvsize = RsPeerConfigSerialiser::sizeNet(item); @@ -1119,7 +1237,14 @@ uint32_t RsPeerConfigSerialiser::sizePeerBandwidthLimits(RsPeerBandwidthLimitsIt return s; } +#endif +void RsPeerBandwidthLimitsItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,peers,"peers") ; +} + +#ifdef TO_REMOVE bool RsPeerConfigSerialiser::serialisePeerBandwidthLimits(RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size) { uint32_t tlvsize = RsPeerConfigSerialiser::sizePeerBandwidthLimits(item); @@ -1296,7 +1421,50 @@ uint32_t RsPeerConfigSerialiser::sizeStun(RsPeerStunItem *i) return s; } +#endif +void RsPeerStunItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,stunList,"stunList") ; +} + +template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& s) +{ + return 4+4 ; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const PeerBandwidthLimits& s) +{ + bool ok = true ; + ok = ok && setRawUInt32(data,size,&offset,s.max_up_rate_kbs); + ok = ok && setRawUInt32(data,size,&offset,s.max_dl_rate_kbs); + return ok; +} + +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,PeerBandwidthLimits& s) +{ + bool ok = true ; + ok = ok && getRawUInt32(data,size,&offset,&s.max_up_rate_kbs); + ok = ok && getRawUInt32(data,size,&offset,&s.max_dl_rate_kbs); + return ok; +} + +template<> void RsTypeSerializer::print_data(const std::string& n, const PeerBandwidthLimits& s) +{ + std::cerr << " [Peer BW limit] " << s.max_up_rate_kbs << " / " << s.max_dl_rate_kbs << std::endl; +} + +RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g) + :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP) +{ + id = g.id ; + name = g.name ; + flag = g.flag ; + pgpList.ids = g.peerIds; +} + + +#ifdef TO_REMOVE bool RsPeerConfigSerialiser::serialiseStun(RsPeerStunItem *item, void *data, uint32_t *size) { uint32_t tlvsize = RsPeerConfigSerialiser::sizeStun(item); @@ -1382,18 +1550,6 @@ RsPeerStunItem *RsPeerConfigSerialiser::deserialiseStun(void *data, uint32_t *si } /*************************************************************************/ -RsNodeGroupItem::RsNodeGroupItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP) -{ -} - -RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g) - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP) -{ - id = g.id ; - name = g.name ; - flag = g.flag ; - pgpList.ids = g.peerIds; -} void RsNodeGroupItem::clear() { @@ -1531,6 +1687,20 @@ uint32_t RsPeerConfigSerialiser::sizeGroup(RsNodeGroupItem *i) return s; } +#endif + +void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + uint32_t v=0 ; + + RsTypeSerializer::serial_process(j,ctx,v,"dummy field 0") ; + RsTypeSerializer::serial_process (j,ctx,id,"id") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,name,"name") ; + RsTypeSerializer::serial_process(j,ctx,flag,"flag") ; + RsTypeSerializer::serial_process(j,ctx,pgpList,"pgpList") ; +} + +#ifdef TO_REMOVE bool RsPeerConfigSerialiser::serialiseGroup(RsNodeGroupItem *item, void *data, uint32_t *size) { uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item); @@ -1650,7 +1820,14 @@ uint32_t RsPeerConfigSerialiser::sizePermissions(RsPeerServicePermissionItem *i) return s; } +#endif +void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ; +} + +#ifdef TO_REMOVE bool RsPeerConfigSerialiser::serialisePermissions(RsPeerServicePermissionItem *item, void *data, uint32_t *size) { uint32_t tlvsize = RsPeerConfigSerialiser::sizePermissions(item); @@ -1932,6 +2109,7 @@ RsItem *RsCacheConfigSerialiser::deserialise(void *data, uint32_t *size) } +#endif diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 3d3d50a97..84b5a176f 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -37,6 +37,8 @@ #include "serialiser/rstlvkeyvalue.h" #include "serialiser/rstlvaddrs.h" +#include "serialization/rsserializer.h" + class RsGroupInfo; const uint8_t RS_PKT_TYPE_GENERAL_CONFIG = 0x01; @@ -68,21 +70,22 @@ const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03; class RsPeerNetItem: public RsItem { - public: - RsPeerNetItem() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_PEER_CONFIG, - RS_PKT_SUBTYPE_PEER_NET) - { return; } -virtual ~RsPeerNetItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); +public: + RsPeerNetItem() + :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, + RS_PKT_TYPE_PEER_CONFIG, + RS_PKT_SUBTYPE_PEER_NET) {} + + virtual ~RsPeerNetItem(){} + virtual void clear(); + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); /* networking information */ RsPeerId peerId; /* Mandatory */ - RsPgpId pgpId; /* Mandatory */ - std::string location; /* Mandatory */ - uint32_t netMode; /* Mandatory */ + RsPgpId pgpId; /* Mandatory */ + std::string location; /* Mandatory */ + uint32_t netMode; /* Mandatory */ uint16_t vs_disc; /* Mandatory */ uint16_t vs_dht; /* Mandatory */ uint32_t lastContact; /* Mandatory */ @@ -92,14 +95,14 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0); RsTlvIpAddress localAddrV6; /* Mandatory */ RsTlvIpAddress extAddrV6; /* Mandatory */ - std::string dyndns; + std::string dyndns; RsTlvIpAddrSet localAddrList; RsTlvIpAddrSet extAddrList; // for proxy connection. std::string domain_addr; - uint16_t domain_port; + uint16_t domain_port; }; // This item should be merged with the next item, but that is not backward compatible. @@ -114,7 +117,8 @@ class RsPeerServicePermissionItem : public RsItem pgp_ids.clear() ; service_flags.clear() ; } - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(SerializeJob j,SerializeContext& ctx); + /* Mandatory */ std::vector pgp_ids ; @@ -130,12 +134,13 @@ class RsPeerBandwidthLimitsItem : public RsItem { peers.clear() ; } - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(SerializeJob j,SerializeContext& ctx); /* Mandatory */ std::map peers ; }; +#ifdef TO_REMOVE class RsPeerGroupItem_deprecated : public RsItem { public: @@ -157,18 +162,20 @@ public: RsTlvPgpIdSet pgpList; }; +#endif class RsNodeGroupItem: public RsItem { public: - RsNodeGroupItem(); + RsNodeGroupItem(): RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP){} virtual ~RsNodeGroupItem() {} - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear() { pgpList.TlvClear();} explicit RsNodeGroupItem(const RsGroupInfo&) ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); + // /* set data from RsGroupInfo to RsPeerGroupItem */ // void set(RsGroupInfo &groupInfo); // /* get data from RsGroupInfo to RsPeerGroupItem */ @@ -184,63 +191,32 @@ public: 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); +public: + RsPeerStunItem() + :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, + RS_PKT_TYPE_PEER_CONFIG, + RS_PKT_SUBTYPE_PEER_STUN) {} + virtual ~RsPeerStunItem(){} + virtual void clear() { stunList.TlvClear() ;} + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsTlvPeerIdSet stunList; /* Mandatory */ }; -class RsPeerConfigSerialiser: public RsSerialType +class RsPeerConfigSerialiser: public RsConfigSerializer { public: - RsPeerConfigSerialiser() - :RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_PEER_CONFIG) - { return; } + RsPeerConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PEER_CONFIG) {} -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); + virtual ~RsPeerConfigSerialiser(){} - 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); - -virtual uint32_t sizeGroup(RsNodeGroupItem *); -virtual bool serialiseGroup (RsNodeGroupItem *item, void *data, uint32_t *size); -virtual RsNodeGroupItem *deserialiseGroup(void *data, uint32_t *size); -virtual RsPeerGroupItem_deprecated * deserialiseGroup_deprecated(void *data, uint32_t *size); - -virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *); -virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size); -virtual RsPeerBandwidthLimitsItem *deserialisePeerBandwidthLimits(void *data, uint32_t *size); - -virtual uint32_t sizePermissions(RsPeerServicePermissionItem *); -virtual bool serialisePermissions (RsPeerServicePermissionItem *item, void *data, uint32_t *size); -virtual RsPeerServicePermissionItem * deserialisePermissions(void *data, uint32_t *size); + virtual RsItem *create_item(uint8_t item_class,uint8_t item_type) const ; }; -/**************************************************************************/ -/**************************************************************************/ - /**************************************************************************/ +#ifdef TO_REMOVE class RsCacheConfig: public RsItem { public: @@ -281,6 +257,7 @@ virtual bool serialise (RsItem *item, void *data, uint32_t *size); virtual RsItem * deserialise(void *data, uint32_t *size); }; +#endif /**************************************************************************/ @@ -299,14 +276,15 @@ class RsFileTransfer: public RsItem flags = 0; chunk_strategy = 0; } - virtual ~RsFileTransfer(); + virtual ~RsFileTransfer(){} virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsTlvFileItem file; RsTlvPeerIdSet allPeerIds; - RsPeerId cPeerId; + RsPeerId cPeerId; uint16_t state; uint16_t in; @@ -328,6 +306,7 @@ class RsFileTransfer: public RsItem const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001; +#ifdef TO_REMOVE /* Used by ft / extralist / configdirs / anyone who wants a basic file */ class RsFileConfigItem_deprecated: public RsItem { @@ -345,18 +324,16 @@ public: uint32_t flags; std::list parent_groups ; }; +#endif class RsFileConfigItem: public RsItem { public: - RsFileConfigItem() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_FILE_CONFIG, - RS_PKT_SUBTYPE_FILE_ITEM) - {} + RsFileConfigItem() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_ITEM) {} virtual ~RsFileConfigItem() {} - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear() { parent_groups.TlvClear(); } + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsTlvFileItem file; uint32_t flags; @@ -364,31 +341,13 @@ public: }; /**************************************************************************/ -class RsFileConfigSerialiser: public RsSerialType +class RsFileConfigSerialiser: public RsConfigSerializer { public: - RsFileConfigSerialiser() - :RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_FILE_CONFIG) - { return; } -virtual ~RsFileConfigSerialiser() { return; } + RsFileConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG) { } + virtual ~RsFileConfigSerialiser() {} -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); - -virtual RsFileConfigItem_deprecated * deserialiseFileItem_deprecated(void *data, uint32_t *size); - -virtual uint32_t sizeFileItem(RsFileConfigItem *); -virtual bool serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *size); -virtual RsFileConfigItem *deserialiseFileItem(void *data, uint32_t *size); - + virtual RsItem *create_item(uint8_t item_class,uint8_t item_type) const ; }; /**************************************************************************/ @@ -397,39 +356,23 @@ virtual RsFileConfigItem *deserialiseFileItem(void *data, uint32_t *size); 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); +public: + RsConfigKeyValueSet() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG, RS_PKT_SUBTYPE_KEY_VALUE) {} + virtual ~RsConfigKeyValueSet(){} + virtual void clear() { tlvkvs.TlvClear();} + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsTlvKeyValueSet tlvkvs; }; -class RsGeneralConfigSerialiser: public RsSerialType +class RsGeneralConfigSerialiser: public RsConfigSerializer { 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); + RsGeneralConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG) {} + virtual RsItem *create_item(uint8_t item_class,uint8_t item_type) const ; }; #endif /* RS_CONFIG_ITEMS_SERIALISER_H */ From 43b3b877822960dde58f33f8e52013be694d77f4 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 22:36:03 +0200 Subject: [PATCH 046/106] fixed a few bugs in config items --- libretroshare/src/serialiser/rsconfigitems.cc | 43 ++++++++++++++----- libretroshare/src/serialiser/rsconfigitems.h | 8 ++-- .../src/serialization/rsserializer.cc | 8 ++-- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 0c603ed3a..61b888f2c 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -40,12 +40,12 @@ /*************************************************************************/ -RsItem *RsFileConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const +RsItem *RsFileConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const { - if(item_class != RS_PKT_CLASS_CONFIG) + if(item_type != RS_PKT_TYPE_FILE_CONFIG) return NULL ; - switch(item_type) + switch(item_subtype) { case RS_PKT_SUBTYPE_FILE_TRANSFER: return new RsFileTransfer() ; case RS_PKT_SUBTYPE_FILE_ITEM: return new RsFileConfigItem() ; @@ -590,12 +590,12 @@ RsGeneralConfigSerialiser::~RsGeneralConfigSerialiser() #endif -RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const +RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const { - if(item_class != RS_PKT_TYPE_GENERAL_CONFIG) + if(item_type != RS_PKT_TYPE_GENERAL_CONFIG) return NULL ; - switch(item_type) + switch(item_subtype) { case RS_PKT_SUBTYPE_KEY_VALUE: return new RsConfigKeyValueSet(); default: @@ -818,12 +818,12 @@ RsPeerConfigSerialiser::~RsPeerConfigSerialiser() } #endif -RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const +RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const { - if(item_class != RS_PKT_TYPE_PEER_CONFIG) + if(item_type != RS_PKT_TYPE_PEER_CONFIG) return NULL ; - switch(item_type) + switch(item_subtype) { case RS_PKT_SUBTYPE_PEER_NET: return new RsPeerNetItem(); case RS_PKT_SUBTYPE_PEER_STUN: return new RsPeerStunItem(); @@ -1824,7 +1824,30 @@ uint32_t RsPeerConfigSerialiser::sizePermissions(RsPeerServicePermissionItem *i) void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx) { - RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ; + // We need to hack this because of backward compatibility. The correct way to do it would be: + // + // RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ; + // RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ; + + if(j == RsItem::DESERIALIZE) + { + uint32_t v=0 ; + RsTypeSerializer::serial_process(j,ctx,v,"pgp_ids.size()") ; + + pgp_ids.resize(v) ; + service_flags.resize(v) ; + } + else + { + uint32_t s = pgp_ids.size(); + RsTypeSerializer::serial_process(j,ctx,s,"pgp_ids.size()") ; + } + + for(uint32_t i=0;i + #include "util/rsprint.h" #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" @@ -14,7 +16,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) if(!item) { - std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << getRsItemSubType(rstype) << std::dec << std::endl; std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl; return NULL ; } @@ -40,11 +42,11 @@ RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size) { uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; - RsItem *item = create_item(getRsItemClass(rstype),getRsItemSubType(rstype)) ; + RsItem *item = create_item(getRsItemType(rstype),getRsItemSubType(rstype)) ; if(!item) { - std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl; + std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << getRsItemSubType(rstype) << std::dec << std::endl; std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl; return NULL ; } From f7338d4a3de73f6f68339a0b0c0fc345dc38d1f4 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 22:39:05 +0200 Subject: [PATCH 047/106] removed old code --- libretroshare/src/serialiser/rsconfigitems.cc | 1871 ----------------- 1 file changed, 1871 deletions(-) diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index 61b888f2c..856294ca3 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -69,185 +69,6 @@ void RsFileTransfer::clear() } - -#ifdef TO_REMOVE -uint32_t RsFileConfigSerialiser::size(RsItem *i) -{ - RsFileTransfer *rft; - RsFileConfigItem *rfj; - - if (NULL != (rft = dynamic_cast(i))) - { - return sizeTransfer(rft); - } - if (NULL != (rfj = dynamic_cast(i))) - { - return sizeFileItem(rfj); - } - return 0; -} - -/* serialise the data to the buffer */ -bool RsFileConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsFileTransfer *rft; - RsFileConfigItem *rfj; - - if (NULL != (rft = dynamic_cast(i))) - { - return serialiseTransfer(rft, data, pktsize); - } - if (NULL != (rfj = dynamic_cast(i))) - { - return serialiseFileItem(rfj, data, pktsize); - } - return false; -} - -RsItem *RsFileConfigSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_FILE_TRANSFER: - return deserialiseTransfer(data, pktsize); - break; - case RS_PKT_SUBTYPE_FILE_ITEM_deprecated: - return deserialiseFileItem_deprecated(data, pktsize); - break; - case RS_PKT_SUBTYPE_FILE_ITEM: - return deserialiseFileItem(data, pktsize); - break; - default: - return NULL; - break; - } - return NULL; -} - -/*************************************************************************/ - -RsFileTransfer::~RsFileTransfer() -{ - return; -} - -std::ostream &RsFileTransfer::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileTransfer", indent); - uint16_t int_Indent = indent + 2; - file.print(out, int_Indent); - allPeerIds.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "cPeerId: " << cPeerId << std::endl; - - printIndent(out, int_Indent); - out << "State: " << state << std::endl; - printIndent(out, int_Indent); - out << "In/Out: " << in << std::endl; - - printIndent(out, int_Indent); - out << "Transferred: " << transferred << std::endl; - - printIndent(out, int_Indent); - out << "crate: " << crate << std::endl; - printIndent(out, int_Indent); - out << "trate: " << trate << std::endl; - printIndent(out, int_Indent); - out << "lrate: " << lrate << std::endl; - printIndent(out, int_Indent); - out << "ltransfer: " << ltransfer << std::endl; - - printRsItemEnd(out, "RsFileTransfer", indent); - return out; - -} - -/*************************************************************************/ -/*************************************************************************/ - -void RsFileConfigItem_deprecated::clear() -{ - file.TlvClear(); - flags = 0; - parent_groups.clear() ; -} - -void RsFileConfigItem::clear() -{ - file.TlvClear(); - flags = 0; - parent_groups.TlvClear() ; -} -std::ostream &RsFileConfigItem_deprecated::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileConfigItem", indent); - uint16_t int_Indent = indent + 2; - file.print(out, int_Indent); - - printIndent(out, int_Indent); out << "flags: " << flags << std::endl; - printIndent(out, int_Indent); out << "groups:" ; - - for(std::list::const_iterator it(parent_groups.begin());it!=parent_groups.end();++it) - out << (*it) << " " ; - out << std::endl; - - printRsItemEnd(out, "RsFileConfigItem", indent); - return out; -} - -std::ostream &RsFileConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsFileConfigItem", indent); - uint16_t int_Indent = indent + 2; - file.print(out, int_Indent); - - printIndent(out, int_Indent); out << "flags: " << flags << std::endl; - printIndent(out, int_Indent); out << "groups:" ; - - for(std::set::const_iterator it(parent_groups.ids.begin());it!=parent_groups.ids.end();++it) - out << (*it) << " " ; - out << std::endl; - - printRsItemEnd(out, "RsFileConfigItem", indent); - return out; -} -/*************************************************************************/ -/*************************************************************************/ - - -uint32_t RsFileConfigSerialiser::sizeTransfer(RsFileTransfer *item) -{ - uint32_t s = 8; /* header */ - s += item->file.TlvSize(); - s += item->allPeerIds.TlvSize(); - s += RsPeerId::SIZE_IN_BYTES; - s += 2; /* state */ - s += 2; /* in/out */ - s += 8; /* transferred */ - s += 4; /* crate */ - s += 4; /* trate */ - s += 4; /* lrate */ - s += 4; /* ltransfer */ - s += 4; // chunk_strategy - s += 4; // flags - s += 4; // chunk map size - s += 4*item->compressed_chunk_map._map.size(); // compressed_chunk_map - - return s; -} -#endif - void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,file,"file") ; @@ -270,151 +91,6 @@ void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ; } -#ifdef TO_REMOVE -bool RsFileConfigSerialiser::serialiseTransfer(RsFileTransfer *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeTransfer(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 << "RsFileConfigSerialiser::serialiseTransfer() Header: " << ok << std::endl; - std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->file.SetTlv(data, tlvsize, &offset); - ok &= item->allPeerIds.SetTlv(data, tlvsize, &offset); - - ok &= item->cPeerId.serialise(data, tlvsize, offset) ; - - ok &= setRawUInt16(data, tlvsize, &offset, item->state); - ok &= setRawUInt16(data, tlvsize, &offset, item->in); - - ok &= setRawUInt64(data, tlvsize, &offset, item->transferred); - - ok &= setRawUInt32(data, tlvsize, &offset, item->crate); - ok &= setRawUInt32(data, tlvsize, &offset, item->trate); - ok &= setRawUInt32(data, tlvsize, &offset, item->lrate); - ok &= setRawUInt32(data, tlvsize, &offset, item->ltransfer); - - ok &= setRawUInt32(data, tlvsize, &offset, item->flags); - ok &= setRawUInt32(data, tlvsize, &offset, item->chunk_strategy); - ok &= setRawUInt32(data, tlvsize, &offset, item->compressed_chunk_map._map.size()); - - for(uint32_t i=0;icompressed_chunk_map._map.size();++i) - ok &= setRawUInt32(data, tlvsize, &offset, item->compressed_chunk_map._map[i]); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsFileTransfer *RsFileConfigSerialiser::deserialiseTransfer(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_FILE_TRANSFER != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsFileTransfer *item = new RsFileTransfer(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->file.GetTlv(data, rssize, &offset); - ok &= item->allPeerIds.GetTlv(data, rssize, &offset); - - ok &= item->cPeerId.deserialise(data, rssize, offset) ; - - /* data */ - ok &= getRawUInt16(data, rssize, &offset, &(item->state)); - ok &= getRawUInt16(data, rssize, &offset, &(item->in)); - ok &= getRawUInt64(data, rssize, &offset, &(item->transferred)); - ok &= getRawUInt32(data, rssize, &offset, &(item->crate)); - ok &= getRawUInt32(data, rssize, &offset, &(item->trate)); - ok &= getRawUInt32(data, rssize, &offset, &(item->lrate)); - ok &= getRawUInt32(data, rssize, &offset, &(item->ltransfer)); - - ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); - ok &= getRawUInt32(data, rssize, &offset, &(item->chunk_strategy)); - uint32_t map_size = 0 ; - ok &= getRawUInt32(data, rssize, &offset, &map_size); - - item->compressed_chunk_map._map.resize(map_size) ; - for(uint32_t i=0;icompressed_chunk_map._map[i])); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ -/*************************************************************************/ - - -uint32_t RsFileConfigSerialiser::sizeFileItem(RsFileConfigItem *item) -{ - uint32_t s = 8; /* header */ - s += item->file.TlvSize(); - s += 4; // flags - - s += item->parent_groups.TlvSize() ; - - return s; -} -#endif - void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,file,"file") ; @@ -422,174 +98,6 @@ void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,parent_groups,"parent_groups") ; } -#ifdef TO_REMOVE -bool RsFileConfigSerialiser::serialiseFileItem(RsFileConfigItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeFileItem(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 << "RsFileConfigSerialiser::serialiseFileItem() Header: " << ok << std::endl; - std::cerr << "RsFileConfigSerialiser::serialiseFileItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->file.SetTlv(data, tlvsize, &offset); - ok &= setRawUInt32(data, tlvsize, &offset, item->flags); - ok &= item->parent_groups.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsFileConfigSerialiser::serialiseFileItem() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsFileConfigItem_deprecated *RsFileConfigSerialiser::deserialiseFileItem_deprecated(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_FILE_ITEM_deprecated != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsFileConfigItem_deprecated *item = new RsFileConfigItem_deprecated(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->file.GetTlv(data, rssize, &offset); - ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); - - while(offset < rssize) - { - std::string tmp ; - if(GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, tmp)) - item->parent_groups.push_back(tmp) ; - else - break ; - } - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} -RsFileConfigItem *RsFileConfigSerialiser::deserialiseFileItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_FILE_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_FILE_ITEM != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsFileConfigItem *item = new RsFileConfigItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->file.GetTlv(data, rssize, &offset); - ok &= getRawUInt32(data, rssize, &offset, &(item->flags)); - ok &= item->parent_groups.GetTlv(data, rssize, &offset) ; - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - - - -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ - -RsGeneralConfigSerialiser::~RsGeneralConfigSerialiser() -{ - return; -} - -#endif - RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const { if(item_type != RS_PKT_TYPE_GENERAL_CONFIG) @@ -603,221 +111,11 @@ RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_su } } -#ifdef TO_REMOVE -uint32_t RsGeneralConfigSerialiser::size(RsItem *i) -{ - RsConfigKeyValueSet *kvs; - - if (NULL != (kvs = dynamic_cast(i))) - { - return sizeKeyValueSet(kvs); - } - else if (NULL != (kvs = dynamic_cast(i))) - { - return sizeKeyValueSet(kvs); - } - - return 0; -} - -/* serialise the data to the buffer */ -bool RsGeneralConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsConfigKeyValueSet *kvs; - - /* do reply first - as it is derived from Item */ - if (NULL != (kvs = dynamic_cast(i))) - { - return serialiseKeyValueSet(kvs, data, pktsize); - } - else if (NULL != (kvs = dynamic_cast(i))) - { - return serialiseKeyValueSet(kvs, data, pktsize); - } - - return false; -} - -RsItem *RsGeneralConfigSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_GENERAL_CONFIG != getRsItemType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsGeneralConfigSerialiser::deserialise() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_KEY_VALUE: - return deserialiseKeyValueSet(data, pktsize); - break; - default: - return NULL; - break; - } - return NULL; -} - -/*************************************************************************/ - -RsConfigKeyValueSet::~RsConfigKeyValueSet() -{ - return; -} - -void RsConfigKeyValueSet::clear() -{ - tlvkvs.pairs.clear(); -} - -std::ostream &RsConfigKeyValueSet::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsConfigKeyValueSet", indent); - uint16_t int_Indent = indent + 2; - - tlvkvs.print(out, int_Indent); - - printRsItemEnd(out, "RsConfigKeyValueSet", indent); - return out; -} - - -uint32_t RsGeneralConfigSerialiser::sizeKeyValueSet(RsConfigKeyValueSet *item) -{ - uint32_t s = 8; /* header */ - s += item->tlvkvs.TlvSize(); - - return s; -} -#endif - void RsConfigKeyValueSet::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tlvkvs,"tlvkvs") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGeneralConfigSerialiser::serialiseKeyValueSet(RsConfigKeyValueSet *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeKeyValueSet(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 << "RsGeneralConfigSerialiser::serialiseKeyValueSet() Header: " << ok << std::endl; - std::cerr << "RsGeneralConfigSerialiser::serialiseKeyValueSet() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->tlvkvs.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsGeneralConfigSerialiser::serialiseKeyValueSet() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsConfigKeyValueSet *RsGeneralConfigSerialiser::deserialiseKeyValueSet(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_GENERAL_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_KEY_VALUE != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() Not Enough Space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsConfigKeyValueSet *item = new RsConfigKeyValueSet(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->tlvkvs.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsGeneralConfigSerialiser::deserialiseKeyValueSet() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ - -RsPeerConfigSerialiser::~RsPeerConfigSerialiser() -{ - return; -} -#endif - RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const { if(item_type != RS_PKT_TYPE_PEER_CONFIG) @@ -858,204 +156,6 @@ void RsPeerNetItem::clear() domain_addr.clear(); domain_port = 0; } -#ifdef TO_REMOVE -uint32_t RsPeerConfigSerialiser::size(RsItem *i) -{ - RsPeerStunItem *psi; - RsPeerNetItem *pni; - RsNodeGroupItem *pgi; - RsPeerServicePermissionItem *pri; - RsPeerBandwidthLimitsItem *pblitem; - - if (NULL != (pni = dynamic_cast(i))) - { - return sizeNet(pni); - } - else if (NULL != (psi = dynamic_cast(i))) - { - return sizeStun(psi); - } - else if (NULL != (pgi = dynamic_cast(i))) - { - return sizeGroup(pgi); - } - else if (NULL != (pri = dynamic_cast(i))) - { - return sizePermissions(pri); - } - else if (NULL != (pblitem = dynamic_cast(i))) - { - return sizePeerBandwidthLimits(pblitem); - } - - return 0; -} - -/* serialise the data to the buffer */ -bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsPeerNetItem *pni; - RsPeerStunItem *psi; - RsNodeGroupItem *pgi; - RsPeerServicePermissionItem *pri; - RsPeerBandwidthLimitsItem *pblitem; - - if (NULL != (pni = dynamic_cast(i))) - { - return serialiseNet(pni, data, pktsize); - } - else if (NULL != (psi = dynamic_cast(i))) - { - return serialiseStun(psi, data, pktsize); - } - else if (NULL != (pgi = dynamic_cast(i))) - { - return serialiseGroup(pgi, data, pktsize); - } - else if (NULL != (pri = dynamic_cast(i))) - { - return serialisePermissions(pri, data, pktsize); - } - else if (NULL != (pblitem = dynamic_cast(i))) - { - return serialisePeerBandwidthLimits(pblitem, data, pktsize); - } - - return false; -} - -RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialise() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_PEER_NET: - return deserialiseNet(data, pktsize); - case RS_PKT_SUBTYPE_PEER_STUN: - return deserialiseStun(data, pktsize); - case RS_PKT_SUBTYPE_PEER_GROUP_deprecated: - return deserialiseGroup_deprecated(data, pktsize); - case RS_PKT_SUBTYPE_NODE_GROUP: - return deserialiseGroup(data, pktsize); - case RS_PKT_SUBTYPE_PEER_PERMISSIONS: - return deserialisePermissions(data, pktsize); - case RS_PKT_SUBTYPE_PEER_BANDLIMITS: - return deserialisePeerBandwidthLimits(data, pktsize); - default: - return NULL; - } - return NULL; -} - - - -/****************************************************************************/ - -RsPeerNetItem::~RsPeerNetItem() -{ - return; -} - - - -std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPeerNetItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "PeerId: " << peerId.toStdString() << std::endl; - - printIndent(out, int_Indent); - out << "PgpId: " << pgpId.toStdString() << std::endl; - - printIndent(out, int_Indent); - out << "location: " << location << std::endl; - - printIndent(out, int_Indent); - out << "netMode: " << netMode << std::endl; - - printIndent(out, int_Indent); - out << "vs_disc: " << vs_disc << std::endl; - - printIndent(out, int_Indent); - out << "vs_dht: " << vs_dht << std::endl; - - printIndent(out, int_Indent); - out << "lastContact: " << lastContact << std::endl; - - printIndent(out, int_Indent); - out << "localAddrV4: " << std::endl; - localAddrV4.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrV4: " << std::endl; - extAddrV4.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "localAddrV6: " << std::endl; - localAddrV6.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "extAddrV6: " << std::endl; - extAddrV6.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "DynDNS: " << dyndns << std::endl; - - localAddrList.print(out, int_Indent); - extAddrList.print(out, int_Indent); - - printIndent(out, int_Indent); - out << "DomainAddr: " << domain_addr; - out << ":" << domain_port << std::endl; - printRsItemEnd(out, "RsPeerNetItem", indent); - return out; -} - -/*************************************************************************/ - -uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i) -{ - uint32_t s = 8; /* header */ - s += RsPeerId::SIZE_IN_BYTES; - s += RsPgpId::SIZE_IN_BYTES; - s += GetTlvStringSize(i->location); - s += 4; /* netMode */ - s += 2; /* vs_disc */ - s += 2; /* vs_dht */ - s += 4; /* lastContact */ - - s += i->localAddrV4.TlvSize(); /* localaddr */ - s += i->extAddrV4.TlvSize(); /* remoteaddr */ - s += i->localAddrV6.TlvSize(); /* localaddr */ - s += i->extAddrV6.TlvSize(); /* remoteaddr */ - - s += GetTlvStringSize(i->dyndns); - - //add the size of the ip list - s += i->localAddrList.TlvSize(); - s += i->extAddrList.TlvSize(); - - s += GetTlvStringSize(i->domain_addr); - s += 2; /* domain_port */ - - return s; -} -#endif - void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ; @@ -1081,348 +181,11 @@ void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,domain_port,"domain_port") ; } -#ifdef TO_REMOVE -bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint32_t *size) -{ - uint32_t tlvsize = RsPeerConfigSerialiser::sizeNet(item); - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() tlvsize: " << tlvsize << std::endl; -#endif - - if(*size < tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() ERROR not enough space" << std::endl; -#endif - return false; /* not enough space */ - } - - *size = tlvsize; - - bool ok = true; - - // serialise header - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header: " << ok << std::endl; - std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header test: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->peerId.serialise(data, tlvsize, offset); - ok &= item->pgpId.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* Mandatory */ - ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); /* Mandatory */ - ok &= setRawUInt16(data, tlvsize, &offset, item->vs_disc); /* Mandatory */ - ok &= setRawUInt16(data, tlvsize, &offset, item->vs_dht); /* Mandatory */ - ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */ - ok &= item->localAddrV4.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrV4.SetTlv(data, tlvsize, &offset); - ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); - - ok &= item->localAddrList.SetTlv(data, tlvsize, &offset); - ok &= item->extAddrList.SetTlv(data, tlvsize, &offset); - - // New for V0.6. - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DOMADDR, item->domain_addr); - ok &= setRawUInt16(data, tlvsize, &offset, item->domain_port); /* Mandatory */ - - if(offset != tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() Size Error! " << std::endl; -#endif - ok = false; - } - - return ok; - -} - -RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() rssize: " << rssize << std::endl; -#endif - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_PEER_NET != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR not enough data" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsPeerNetItem *item = new RsPeerNetItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->peerId.deserialise(data, rssize, offset); - ok &= item->pgpId.deserialise(data, rssize, offset); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* Mandatory */ - ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */ - ok &= getRawUInt16(data, rssize, &offset, &(item->vs_disc)); /* Mandatory */ - ok &= getRawUInt16(data, rssize, &offset, &(item->vs_dht)); /* Mandatory */ - ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); /* Mandatory */ - - ok &= item->localAddrV4.GetTlv(data, rssize, &offset); - ok &= item->extAddrV4.GetTlv(data, rssize, &offset); - ok &= item->localAddrV6.GetTlv(data, rssize, &offset); - ok &= item->extAddrV6.GetTlv(data, rssize, &offset); - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); - ok &= item->localAddrList.GetTlv(data, rssize, &offset); - ok &= item->extAddrList.GetTlv(data, rssize, &offset); - - // New for V0.6. - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DOMADDR, item->domain_addr); - ok &= getRawUInt16(data, rssize, &offset, &(item->domain_port)); /* Mandatory */ - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - return item; -} - -/****************************************************************************/ - -uint32_t RsPeerConfigSerialiser::sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *i) -{ - uint32_t s = 8; /* header */ - s += 4; // number of elements - s += i->peers.size() * (4 + 4 + RsPgpId::SIZE_IN_BYTES) ; - - return s; -} -#endif - void RsPeerBandwidthLimitsItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peers,"peers") ; } -#ifdef TO_REMOVE -bool RsPeerConfigSerialiser::serialisePeerBandwidthLimits(RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size) -{ - uint32_t tlvsize = RsPeerConfigSerialiser::sizePeerBandwidthLimits(item); - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() tlvsize: " << tlvsize << std::endl; -#endif - - if(*size < tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() ERROR not enough space" << std::endl; -#endif - return false; /* not enough space */ - } - - *size = tlvsize; - - bool ok = true; - - // serialise header - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header: " << ok << std::endl; - std::cerr << "RsPeerConfigSerialiser::serialiseNet() Header test: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= setRawUInt32(data, tlvsize, &offset, item->peers.size()); /* Mandatory */ - - for(std::map::const_iterator it(item->peers.begin());it!=item->peers.end();++it) - { - ok &= it->first.serialise(data,tlvsize,offset); - - ok &= setRawUInt32(data, tlvsize, &offset, it->second.max_up_rate_kbs); /* Mandatory */ - ok &= setRawUInt32(data, tlvsize, &offset, it->second.max_dl_rate_kbs); /* Mandatory */ - } - - if(offset != tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseNet() Size Error! " << std::endl; -#endif - ok = false; - } - - return ok; - -} - -RsPeerBandwidthLimitsItem *RsPeerConfigSerialiser::deserialisePeerBandwidthLimits(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() rssize: " << rssize << std::endl; -#endif - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_PEER_BANDLIMITS != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR not enough data" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsPeerBandwidthLimitsItem *item = new RsPeerBandwidthLimitsItem(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint32_t n ; - ok &= getRawUInt32(data, rssize, &offset, &n) ; - - for(uint32_t i=0;ipeers[pgpid] = p ; - } - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::deserialiseNet() ERROR size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - return item; -} - -std::ostream &RsPeerBandwidthLimitsItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPeerBandwidthLimitsItem", indent); - uint16_t int_Indent = indent + 2; - - for(std::map::const_iterator it(peers.begin());it!=peers.end();++it) - { - printIndent(out, int_Indent); - out << it->first << " : " << it->second.max_up_rate_kbs << " (up) " << it->second.max_dl_rate_kbs << " (dn)" << std::endl; - } - - printRsItemEnd(out, "RsPeerStunItem", indent); - return out; -} - - - -/****************************************************************************/ - -RsPeerStunItem::~RsPeerStunItem() -{ - return; -} - -void RsPeerStunItem::clear() -{ - stunList.TlvClear(); -} - -std::ostream &RsPeerStunItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPeerStunItem", indent); - uint16_t int_Indent = indent + 2; - - stunList.printHex(out, int_Indent); - - printRsItemEnd(out, "RsPeerStunItem", indent); - return out; -} - -/*************************************************************************/ - -uint32_t RsPeerConfigSerialiser::sizeStun(RsPeerStunItem *i) -{ - uint32_t s = 8; /* header */ - s += i->stunList.TlvSize(); /* stunList */ - - return s; - -} -#endif - void RsPeerStunItem::serial_process(SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,stunList,"stunList") ; @@ -1463,232 +226,6 @@ RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g) pgpList.ids = g.peerIds; } - -#ifdef TO_REMOVE -bool RsPeerConfigSerialiser::serialiseStun(RsPeerStunItem *item, void *data, uint32_t *size) -{ - uint32_t tlvsize = RsPeerConfigSerialiser::sizeStun(item); - uint32_t offset = 0; - - if(*size < tlvsize) - return false; /* not enough space */ - - *size = tlvsize; - - bool ok = true; - - // serialise header - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseStun() Header: " << ok << std::endl; - std::cerr << "RsPeerConfigSerialiser::serialiseStun() Header: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->stunList.SetTlv(data, tlvsize, &offset); /* Mandatory */ - - if(offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseStun() Size Error! " << std::endl; -#endif - } - - return ok; - -} - -RsPeerStunItem *RsPeerConfigSerialiser::deserialiseStun(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_PEER_STUN != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsPeerStunItem *item = new RsPeerStunItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= item->stunList.GetTlv(data, rssize, &offset); /* Mandatory */ - - if (offset != rssize) - { - - /* error */ - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -void RsNodeGroupItem::clear() -{ - id.clear(); - name.clear(); - flag = 0; - pgpList.ids.clear(); -} - -std::ostream &RsNodeGroupItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNodeGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "groupId: " << id << std::endl; - - printIndent(out, int_Indent); - out << "groupName: " << name << std::endl; - - printIndent(out, int_Indent); - out << "groupFlag: " << flag << std::endl; - - std::set::iterator it; - for (it = pgpList.ids.begin(); it != pgpList.ids.end(); ++it) { - printIndent(out, int_Indent); - out << "peerId: " << it->toStdString() << std::endl; - } - - printRsItemEnd(out, "RsNodeGroupItem", indent); - return out; -} - -/*************************************************************************/ -/* DEPRECATED CODE. SHOULD BE REMOVED WHEN EVERYONE USES THE NEW CLASS */ -/*************************************************************************/ - -RsPeerGroupItem_deprecated::RsPeerGroupItem_deprecated() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_GROUP_deprecated) -{ -} - -RsPeerGroupItem_deprecated::~RsPeerGroupItem_deprecated() -{ -} - -void RsPeerGroupItem_deprecated::clear() -{ - id.clear(); - name.clear(); - flag = 0; - pgpList.ids.clear(); -} - -std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPeerGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "groupId: " << id << std::endl; - - printIndent(out, int_Indent); - out << "groupName: " << name << std::endl; - - printIndent(out, int_Indent); - out << "groupFlag: " << flag << std::endl; - - std::set::iterator it; - for (it = pgpList.ids.begin(); it != pgpList.ids.end(); ++it) { - printIndent(out, int_Indent); - out << "peerId: " << it->toStdString() << std::endl; - } - - printRsItemEnd(out, "RsPeerGroupItem", indent); - return out; -} - -RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup_deprecated(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint32_t version; - ok &= getRawUInt32(data, rssize, &offset, &version); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); - ok &= item->pgpList.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - return item; -} -/*************************************************************************/ - -uint32_t RsPeerConfigSerialiser::sizeGroup(RsNodeGroupItem *i) -{ - uint32_t s = 8; /* header */ - s += 4; /* version */ - s += RsNodeGroupId::serial_size(); - s += GetTlvStringSize(i->name); - s += 4; /* flag */ - s += i->pgpList.TlvSize(); - return s; -} - -#endif - void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) { uint32_t v=0 ; @@ -1700,128 +237,6 @@ void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,pgpList,"pgpList") ; } -#ifdef TO_REMOVE -bool RsPeerConfigSerialiser::serialiseGroup(RsNodeGroupItem *item, void *data, uint32_t *size) -{ - uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item); - uint32_t offset = 0; - - if(*size < tlvsize) - return false; /* not enough space */ - - *size = tlvsize; - - bool ok = true; - - // serialise header - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Header: " << ok << std::endl; - std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Header: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, 0); - ok &= item->id.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= setRawUInt32(data, tlvsize, &offset, item->flag); - ok &= item->pgpList.SetTlv(data, tlvsize, &offset); - - if(offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsNodeGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_NODE_GROUP != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsNodeGroupItem *item = new RsNodeGroupItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint32_t version; - ok &= getRawUInt32(data, rssize, &offset, &version); - ok &= item->id.deserialise(data, rssize, offset); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); - ok &= item->pgpList.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - return item; -} - -/**************************************************************/ - -std::ostream& RsPeerServicePermissionItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsPeerServicePermissionItem", indent); - uint16_t int_Indent = indent + 2; - - for(uint32_t i=0;ipgp_ids.size();++j) - { - s += RsPgpId::SIZE_IN_BYTES ;//GetTlvStringSize(i->pgp_ids[j]) ; - s += 4; /* flag */ - } - - return s; -} -#endif - void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx) { // We need to hack this because of backward compatibility. The correct way to do it would be: @@ -1850,289 +265,3 @@ void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext } } -#ifdef TO_REMOVE -bool RsPeerConfigSerialiser::serialisePermissions(RsPeerServicePermissionItem *item, void *data, uint32_t *size) -{ - uint32_t tlvsize = RsPeerConfigSerialiser::sizePermissions(item); - uint32_t offset = 0; - - if(*size < tlvsize) - return false; /* not enough space */ - - *size = tlvsize; - - bool ok = true; - - // serialise header - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Header: " << ok << std::endl; - std::cerr << "RsPeerConfigSerialiser::serialiseGroup() Header: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->pgp_ids.size()); - - for(uint32_t i=0;ipgp_ids.size();++i) - { - ok &= item->pgp_ids[i].serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, item->service_flags[i].toUInt32()); - } - - if(offset != tlvsize) - { - ok = false; - std::cerr << "(EE) Item size ERROR in RsPeerServicePermissionItem!" << std::endl; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsPeerConfigSerialiser::serialisePermissions() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsPeerServicePermissionItem *RsPeerConfigSerialiser::deserialisePermissions(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_PEER_PERMISSIONS != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsPeerServicePermissionItem *item = new RsPeerServicePermissionItem ; - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint32_t s; - ok &= getRawUInt32(data, rssize, &offset, &s); - item->pgp_ids.resize(s) ; - item->service_flags.resize(s) ; - - for(uint32_t i=0;ipgp_ids[i].deserialise(data, rssize, offset) ; - ok &= getRawUInt32(data, rssize, &offset, &flags); - - item->service_flags[i] = ServicePermissionFlags(flags) ; - } - - if (offset != rssize) - { - /* error */ - std::cerr << "(EE) Item size ERROR in RsPeerServicePermissionItem!" << std::endl; - delete item; - return NULL; - } - - return item; -} - - - -/****************************************************************************/ - - -RsCacheConfig::~RsCacheConfig() -{ - return; -} - -void RsCacheConfig::clear() -{ - pid.clear(); - cachetypeid = 0; - cachesubid = 0; - path = ""; - name = ""; - hash.clear() ; - size = 0; - recvd = 0; - -} - -std::ostream &RsCacheConfig::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsCacheConfig", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); //indent - out << "pid: " << pid << std::endl; // display value of peerid - - printIndent(out, int_Indent); //indent - out << "cacheid: " << cachetypeid << ":" << cachesubid << std::endl; // display value of cacheid - - printIndent(out, int_Indent); - out << "path: " << path << std::endl; // display value of path - - printIndent(out, int_Indent); - out << "name: " << name << std::endl; // display value of name - - printIndent(out, int_Indent); - out << "hash: " << hash << std::endl; // display value of hash - - printIndent(out, int_Indent); - out << "size: " << size << std::endl; // display value of size - - printIndent(out, int_Indent); - out << "recvd: " << recvd << std::endl; // display value of recvd - - printRsItemEnd(out, "RsCacheConfig", indent); // end of 'WRITE' check - return out; -} - -/**************************************************************************/ - - -RsCacheConfigSerialiser::~RsCacheConfigSerialiser() -{ - return; -} - -uint32_t RsCacheConfigSerialiser::size(RsItem *i) -{ - RsCacheConfig *item = (RsCacheConfig *) i; - - uint32_t s = 8; // to store calculated size, initiailize with size of header - - - s += item->pid.serial_size(); - s += 2; /* cachetypeid */ - s += 2; /* cachesubid */ - s += GetTlvStringSize(item->path); - s += GetTlvStringSize(item->name); - s += item->hash.serial_size(); - s += 8; /* size */ - s += 4; /* recvd */ - - return s; -} - -bool RsCacheConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *size) -{ - RsCacheConfig *item = (RsCacheConfig *) i; - uint32_t tlvsize = RsCacheConfigSerialiser::size(item); - uint32_t offset = 0; - - if(*size < tlvsize) - return false; /* not enough space */ - - *size = tlvsize; - - bool ok = true; - - ok &=setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsCacheConfigSerialiser::serialise() Header: " << ok << std::endl; - std::cerr << "RsCacheConfigSerialiser::serialise() Size: " << size << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add the mandatory parts first */ - - ok &= item->pid.serialise(data, tlvsize, offset) ; - ok &= setRawUInt16(data, tlvsize, &offset, item->cachetypeid); - ok &= setRawUInt16(data, tlvsize, &offset, item->cachesubid); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PATH, item->path); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= item->hash.serialise(data, tlvsize, offset) ; - ok &= setRawUInt64(data, tlvsize, &offset, item->size); - ok &= setRawUInt32(data, tlvsize, &offset, item->recvd); - - if (offset !=tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsConfigSerialiser::serialisertransfer() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsItem *RsCacheConfigSerialiser::deserialise(void *data, uint32_t *size) -{/* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset; - offset = 0; - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_CACHE_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - /* ready to load */ - RsCacheConfig *item = new RsCacheConfig(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - - ok &= item->pid.deserialise(data, rssize, offset) ; - ok &= getRawUInt16(data, rssize, &offset, &(item->cachetypeid)); - ok &= getRawUInt16(data, rssize, &offset, &(item->cachesubid)); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PATH, item->path); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); - ok &= item->hash.deserialise(data, rssize, offset) ; - ok &= getRawUInt64(data, rssize, &offset, &(item->size)); - ok &= getRawUInt32(data, rssize, &offset, &(item->recvd)); - - - if (offset != rssize) - { - - /* error */ - delete item; - return NULL; - } - - return item; -} - - -#endif - - - From 0d7df568b49601d80dfa01946d1971a803cb43cc Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 Apr 2017 22:47:08 +0200 Subject: [PATCH 048/106] moved rsconfigitems and rshistoryitems to rsitems/ --- libretroshare/src/chat/p3chatservice.cc | 2 +- libretroshare/src/dht/p3bitdht_relay.cc | 2 +- libretroshare/src/ft/ftcontroller.cc | 2 +- libretroshare/src/ft/ftcontroller.h | 2 +- libretroshare/src/ft/ftextralist.cc | 2 +- libretroshare/src/grouter/p3grouter.cc | 2 +- libretroshare/src/libretroshare.pro | 8 ++++---- libretroshare/src/pqi/authgpg.cc | 2 +- libretroshare/src/pqi/authssl.cc | 2 +- libretroshare/src/pqi/p3cfgmgr.cc | 2 +- libretroshare/src/pqi/p3historymgr.cc | 4 ++-- libretroshare/src/pqi/p3historymgr.h | 2 +- libretroshare/src/pqi/p3linkmgr.cc | 3 ++- libretroshare/src/pqi/p3netmgr.cc | 3 ++- libretroshare/src/pqi/p3peermgr.cc | 2 +- .../src/{serialiser => rsitems}/rsconfigitems.cc | 2 +- libretroshare/src/{serialiser => rsitems}/rsconfigitems.h | 0 .../src/{serialiser => rsitems}/rshistoryitems.cc | 5 +++-- .../src/{serialiser => rsitems}/rshistoryitems.h | 2 +- libretroshare/src/serialiser/rspluginitems.h | 2 +- libretroshare/src/services/p3banlist.cc | 5 +++-- libretroshare/src/services/p3gxsreputation.cc | 3 ++- libretroshare/src/services/p3idservice.cc | 2 +- libretroshare/src/services/p3msgservice.cc | 3 ++- 24 files changed, 35 insertions(+), 29 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsconfigitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsconfigitems.h (100%) rename libretroshare/src/{serialiser => rsitems}/rshistoryitems.cc (95%) rename libretroshare/src/{serialiser => rsitems}/rshistoryitems.h (94%) diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index eb421ac31..453ec7df1 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -42,7 +42,7 @@ #include "services/p3idservice.h" #include "chat/p3chatservice.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" /**** * #define CHAT_DEBUG 1 diff --git a/libretroshare/src/dht/p3bitdht_relay.cc b/libretroshare/src/dht/p3bitdht_relay.cc index d71f3e7c5..d846e7691 100644 --- a/libretroshare/src/dht/p3bitdht_relay.cc +++ b/libretroshare/src/dht/p3bitdht_relay.cc @@ -29,7 +29,7 @@ #include "tcponudp/udprelay.h" #include "bitdht/bdstddht.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" /*********************************************************************************************** diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 13bafa5f0..fad8642fa 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -60,7 +60,7 @@ #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include #include /* for (u)sleep() */ #include diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 6f41c3dc8..edeb8d82f 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -53,7 +53,7 @@ class p3ServiceControl; #include "pqi/p3cfgmgr.h" #include "retroshare/rsfiles.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index 8538a46a9..7548d421c 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -30,7 +30,7 @@ #include #include #include "ft/ftextralist.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "util/rsdir.h" #include #include /* for (u)sleep() */ diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 5f2b6e7d0..f14af4412 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -186,7 +186,7 @@ #include "util/rsrandom.h" #include "util/rsprint.h" #include "util/rsmemory.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "services/p3idservice.h" #include "turtle/p3turtle.h" #include "gxs/rsgixs.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index e6f1a4ef4..8a633c1a7 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -456,8 +456,8 @@ HEADERS += rsitems/itempriorities.h \ serialiser/rsbaseserial.h \ rsitems/rsfiletransferitems.h \ serialiser/rsserviceserialiser.h \ - serialiser/rsconfigitems.h \ - serialiser/rshistoryitems.h \ + rsitems/rsconfigitems.h \ + rsitems/rshistoryitems.h \ rsitems/rsmsgitems.h \ serialiser/rsserial.h \ rsitems/rsserviceids.h \ @@ -610,8 +610,8 @@ SOURCES += plugins/pluginmanager.cc \ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsfiletransferitems.cc \ serialiser/rsserviceserialiser.cc \ - serialiser/rsconfigitems.cc \ - serialiser/rshistoryitems.cc \ + rsitems/rsconfigitems.cc \ + rsitems/rshistoryitems.cc \ rsitems/rsmsgitems.cc \ serialiser/rsserial.cc \ serialiser/rsstatusitems.cc \ diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 38756476c..1e20d6b85 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -41,7 +41,7 @@ #include #include #include -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #define LIMIT_CERTIFICATE_SIZE 1 #define MAX_CERTIFICATE_SIZE 10000 diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 4191e0b4f..ccc176908 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -37,7 +37,7 @@ #include "pqinetwork.h" #include "authgpg.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "util/rsdir.h" #include "util/rsstring.h" diff --git a/libretroshare/src/pqi/p3cfgmgr.cc b/libretroshare/src/pqi/p3cfgmgr.cc index 5f9934d57..3266f68d4 100644 --- a/libretroshare/src/pqi/p3cfgmgr.cc +++ b/libretroshare/src/pqi/p3cfgmgr.cc @@ -35,7 +35,7 @@ #include #include "util/rsstring.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" /* #define CONFIG_DEBUG 1 diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index 5739ff94a..72a2640ec 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -26,8 +26,8 @@ #include #include "p3historymgr.h" -#include "serialiser/rshistoryitems.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rshistoryitems.h" +#include "rsitems/rsconfigitems.h" #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" #include "rsitems/rsmsgitems.h" diff --git a/libretroshare/src/pqi/p3historymgr.h b/libretroshare/src/pqi/p3historymgr.h index 98d7b6eed..3f3c9a6f1 100644 --- a/libretroshare/src/pqi/p3historymgr.h +++ b/libretroshare/src/pqi/p3historymgr.h @@ -29,7 +29,7 @@ #include #include -#include "serialiser/rshistoryitems.h" +#include "rsitems/rshistoryitems.h" #include "retroshare/rshistory.h" #include "pqi/p3cfgmgr.h" diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 26a27dc45..39424a21b 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -41,7 +41,8 @@ #include "util/rsprint.h" #include "util/rsdebug.h" #include "util/rsstring.h" -#include "serialiser/rsconfigitems.h" + +#include "rsitems/rsconfigitems.h" #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index 1cbabb75c..acfa32852 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -42,7 +42,8 @@ struct RsLog::logInfo p3netmgrzoneInfo = {RsLog::Default, "p3netmgr"}; #define p3netmgrzone &p3netmgrzoneInfo -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" + #include "retroshare/rsiface.h" #include "retroshare/rsconfig.h" #include "retroshare/rsbanlist.h" diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index d26c4a950..5ae948d86 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -42,7 +42,7 @@ #include "util/rsstring.h" #include "util/rsdebug.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "retroshare/rsiface.h" // Needed for rsicontrol (should remove this dependancy) #include "retroshare/rspeers.h" // Needed for Group Parameters. diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/rsitems/rsconfigitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsconfigitems.cc rename to libretroshare/src/rsitems/rsconfigitems.cc index 856294ca3..4ba94a8bf 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/rsitems/rsconfigitems.cc @@ -25,7 +25,7 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "retroshare/rspeers.h" // Needed for RsGroupInfo. /*** diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/rsitems/rsconfigitems.h similarity index 100% rename from libretroshare/src/serialiser/rsconfigitems.h rename to libretroshare/src/rsitems/rsconfigitems.h diff --git a/libretroshare/src/serialiser/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc similarity index 95% rename from libretroshare/src/serialiser/rshistoryitems.cc rename to libretroshare/src/rsitems/rshistoryitems.cc index 6c05e9afb..eb50bf15e 100644 --- a/libretroshare/src/serialiser/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -23,10 +23,11 @@ * */ -#include "serialiser/rshistoryitems.h" +#include "rsitems/rshistoryitems.h" +#include "rsitems/rsconfigitems.h" + #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" -#include "serialiser/rsconfigitems.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/serialiser/rshistoryitems.h b/libretroshare/src/rsitems/rshistoryitems.h similarity index 94% rename from libretroshare/src/serialiser/rshistoryitems.h rename to libretroshare/src/rsitems/rshistoryitems.h index ffc5b571c..27a387f60 100644 --- a/libretroshare/src/serialiser/rshistoryitems.h +++ b/libretroshare/src/rsitems/rshistoryitems.h @@ -28,7 +28,7 @@ #include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "retroshare/rstypes.h" #include "serialization/rsserializer.h" diff --git a/libretroshare/src/serialiser/rspluginitems.h b/libretroshare/src/serialiser/rspluginitems.h index ed2bda137..02b64fc54 100644 --- a/libretroshare/src/serialiser/rspluginitems.h +++ b/libretroshare/src/serialiser/rspluginitems.h @@ -27,7 +27,7 @@ #pragma once #include "serialiser/rsserial.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "serialiser/rsbaseserial.h" #if 0 diff --git a/libretroshare/src/services/p3banlist.cc b/libretroshare/src/services/p3banlist.cc index bf72ea815..800fe697c 100644 --- a/libretroshare/src/services/p3banlist.cc +++ b/libretroshare/src/services/p3banlist.cc @@ -30,11 +30,12 @@ #include "util/rsnet.h" #include "services/p3banlist.h" -#include "rsitems/rsbanlistitems.h" -#include "serialiser/rsconfigitems.h" #include "retroshare/rsdht.h" #include "retroshare/rsbanlist.h" +#include "rsitems/rsbanlistitems.h" +#include "rsitems/rsconfigitems.h" + #include #include diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index 609382444..d2ad1b9da 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -29,8 +29,9 @@ #include "retroshare/rspeers.h" #include "services/p3gxsreputation.h" + #include "rsitems/rsgxsreputationitems.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 53b922327..c173dba8a 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -28,7 +28,7 @@ #include "services/p3idservice.h" #include "pgp/pgpauxutils.h" #include "serialiser/rsgxsiditems.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "retroshare/rsgxsflags.h" #include "util/rsrandom.h" #include "util/rsstring.h" diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index a3aacfc7b..29fad5319 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -41,7 +41,8 @@ #include "pgp/pgpkeyutil.h" #include "rsserver/p3face.h" -#include "serialiser/rsconfigitems.h" + +#include "rsitems/rsconfigitems.h" #include "grouter/p3grouter.h" #include "grouter/groutertypes.h" From 9e246c9670a23be77af01b18a8e1870a799ef0d0 Mon Sep 17 00:00:00 2001 From: Phenom Date: Tue, 25 Apr 2017 18:39:30 +0200 Subject: [PATCH 049/106] Add warning about relays bandwidth. --- retroshare-gui/src/gui/settings/RelayPage.cpp | 4 +- retroshare-gui/src/gui/settings/RelayPage.ui | 98 +++++++++++-------- retroshare-gui/src/gui/settings/ServerPage.ui | 17 +++- 3 files changed, 77 insertions(+), 42 deletions(-) diff --git a/retroshare-gui/src/gui/settings/RelayPage.cpp b/retroshare-gui/src/gui/settings/RelayPage.cpp index d26550c8b..2927d2ea5 100644 --- a/retroshare-gui/src/gui/settings/RelayPage.cpp +++ b/retroshare-gui/src/gui/settings/RelayPage.cpp @@ -209,7 +209,7 @@ void RelayPage::updateEnabled() if (ui.enableCheckBox->isChecked()) { - ui.groupBox->setEnabled(true); + ui.relayOptionGBox->setEnabled(true); if (ui.serverCheckBox->isChecked()) { std::cerr << "RelayPage::updateEnabled() Both Enabled" << std::endl; @@ -224,7 +224,7 @@ void RelayPage::updateEnabled() else { std::cerr << "RelayPage::updateEnabled() Both Disabled" << std::endl; - ui.groupBox->setEnabled(false); + ui.relayOptionGBox->setEnabled(false); ui.serverGroupBox->setEnabled(false); } diff --git a/retroshare-gui/src/gui/settings/RelayPage.ui b/retroshare-gui/src/gui/settings/RelayPage.ui index f753b0c49..d5df50626 100644 --- a/retroshare-gui/src/gui/settings/RelayPage.ui +++ b/retroshare-gui/src/gui/settings/RelayPage.ui @@ -10,9 +10,9 @@ 546 - + - + @@ -21,7 +21,7 @@ - + Qt::Horizontal @@ -41,7 +41,7 @@ - + Qt::Horizontal @@ -56,14 +56,14 @@ - + true Relay options - + 0 @@ -80,7 +80,7 @@ 0 - + Qt::Horizontal @@ -93,14 +93,14 @@ - + Number - + Qt::Horizontal @@ -113,28 +113,28 @@ - + Bandwidth per link - + Qt::Vertical - + Total Bandwidth - + Friends @@ -154,7 +154,7 @@ - + x @@ -184,7 +184,7 @@ - + Friends of Friends @@ -198,7 +198,7 @@ - + x @@ -228,7 +228,7 @@ - + General @@ -242,7 +242,7 @@ - + x @@ -272,12 +272,19 @@ - + Qt::Horizontal + + + + Total: + + + @@ -288,15 +295,8 @@ - - - - Total: - - - - + Qt::Horizontal @@ -318,6 +318,26 @@ + + + + + 0 + 0 + + + + border: 1px solid #DCDC41; + border-radius: 6px; + background: #FFFFD7; + background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FFFFD7, stop:1 #FFFFB2); + + + + Warning: This bandwidth adds up to the max bandwidth. + + + @@ -326,7 +346,17 @@ Relay Server Setup - + + + + + HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH + + + + + + @@ -347,16 +377,6 @@ - - - - HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH - - - - - - @@ -377,7 +397,7 @@ - + Qt::Vertical diff --git a/retroshare-gui/src/gui/settings/ServerPage.ui b/retroshare-gui/src/gui/settings/ServerPage.ui index a0f16a62b..921e5b7df 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -26,7 +26,7 @@ - 2 + 0 @@ -418,6 +418,21 @@ + + + + border: 1px solid #DCDC41; + border-radius: 6px; + background: #FFFFD7; + background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FFFFD7, stop:1 #FFFFB2); + + + + WARNING: +These values don't take into account the Relays. + + + From 77e809ea4b9f4a9e6e7b3cc36b016a163ecc1f74 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 25 Apr 2017 21:21:46 +0200 Subject: [PATCH 050/106] switched GRouter to new serialization --- libretroshare/src/grouter/grouteritems.cc | 262 +++++++++++++++--- libretroshare/src/grouter/grouteritems.h | 161 +++-------- libretroshare/src/grouter/p3grouter.cc | 67 +++-- libretroshare/src/pqi/pqistore.cc | 2 +- libretroshare/src/serialiser/rsserial.h | 2 +- .../src/serialization/rsserializer.cc | 43 ++- .../src/serialization/rsserializer.h | 1 + 7 files changed, 343 insertions(+), 195 deletions(-) diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index 3f500d615..c48dbc134 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -1,65 +1,71 @@ +#include "util/rsprint.h" #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" #include "grouteritems.h" -/**********************************************************************************************/ -/* SERIALISATION */ -/**********************************************************************************************/ - -bool RsGRouterItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; -} - /**********************************************************************************************/ /* SERIALISER STUFF */ /**********************************************************************************************/ -RsItem *RsGRouterSerialiser::deserialise(void *data, uint32_t *pktsize) +RsItem *RsGRouterSerialiser::create_item(uint16_t service_id,uint8_t subtype) const { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if(RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_GROUTER != getRsItemService(rstype)) - { + if(RS_SERVICE_TYPE_GROUTER != service_id) return NULL; /* wrong type */ - } - switch(getRsItemSubType(rstype)) + switch(subtype) { - case RS_PKT_SUBTYPE_GROUTER_DATA: return deserialise_RsGRouterGenericDataItem (data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: return deserialise_RsGRouterTransactionChunkItem(data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return deserialise_RsGRouterTransactionAcknItem (data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT: return deserialise_RsGRouterSignedReceiptItem (data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return deserialise_RsGRouterMatrixCluesItem (data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK: return deserialise_RsGRouterMatrixTrackItem (data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST: return deserialise_RsGRouterMatrixFriendListItem(data, *pktsize); - case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return deserialise_RsGRouterRoutingInfoItem (data, *pktsize); + case RS_PKT_SUBTYPE_GROUTER_DATA: return new RsGRouterGenericDataItem (); + case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: return new RsGRouterTransactionChunkItem(); + case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return new RsGRouterTransactionAcknItem (); + case RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT: return new RsGRouterSignedReceiptItem (); + case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return new RsGRouterMatrixCluesItem (); + case RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK: return new RsGRouterMatrixTrackItem (); + case RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST: return new RsGRouterMatrixFriendListItem(); + case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return new RsGRouterRoutingInfoItem (); default: - std::cerr << "RsGRouterSerialiser::deserialise(): Could not de-serialise item. SubPacket id = " << std::hex << getRsItemSubType(rstype) << " id = " << rstype << std::dec << std::endl; return NULL; } - return NULL; } + +void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; + RsTypeSerializer::serial_process(j,ctx,chunk_start ,"chunk_start") ; + RsTypeSerializer::serial_process(j,ctx,chunk_size ,"chunk_size") ; + RsTypeSerializer::serial_process(j,ctx,total_size ,"total_size") ; + + // Hack for backward compatibility (the chunk size is not directly next to the chunk data) + + if(j == RsItem::DESERIALIZE) + { + if(chunk_size > ctx.mSize || ctx.mOffset > ctx.mSize - chunk_size) // better than if(chunk_size + offset > size) + { + std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl; + ctx.mOk = false ; + return ; + } + if( NULL == (chunk_data = (uint8_t*)rs_malloc(chunk_size))) + { + ctx.mOk = false ; + return ; + } + + memcpy(chunk_data,&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_size) ; + ctx.mOffset += chunk_size ; + } + else if(j== RsItem::SERIALIZE) + { + memcpy(&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_data,chunk_size) ; + ctx.mOffset += chunk_size ; + } + else if(j== RsItem::SIZE_ESTIMATE) + ctx.mOffset += chunk_size ; + else + std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl; + +} +#ifdef TO_REMOVE RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionChunkItem(void *data, uint32_t tlvsize) const { uint32_t offset = 8; // skip the header @@ -104,6 +110,14 @@ RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransac return item; } +#endif + +void RsGRouterTransactionAcknItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; +} + +#ifdef TO_REMOVE RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionAcknItem(void *data, uint32_t tlvsize) const { uint32_t offset = 8; // skip the header @@ -124,6 +138,41 @@ RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransact return item; } +#endif + +void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,routing_id,"routing_id") ; + RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ; + RsTypeSerializer::serial_process(j,ctx,service_id,"service_id") ; + + RsTypeSerializer::TlvMemBlock_proxy prox(data_bytes,data_size) ; + + RsTypeSerializer::serial_process(j,ctx,prox,"data") ; + + if(ctx.mFlags & RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE) + return ; + + RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; + RsTypeSerializer::serial_process(j,ctx,duplication_factor,"duplication_factor") ; + RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; + + if(j == RsItem::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. + { + if(duplication_factor < 1) + { + duplication_factor = 1 ; + std::cerr << "(II) correcting GRouter item duplication factor from 0 to 1, to ensure backward compat." << std::endl; + } + if(duplication_factor > GROUTER_MAX_DUPLICATION_FACTOR) + { + std::cerr << "(WW) correcting GRouter item duplication factor of " << duplication_factor << ". This is very unexpected." << std::endl; + duplication_factor = GROUTER_MAX_DUPLICATION_FACTOR ; + } + } +} + +#ifdef TO_REMOVE RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const { uint32_t offset = 8; // skip the header @@ -191,7 +240,23 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI return item; } +#endif +void RsGRouterSignedReceiptItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,routing_id,"routing_id") ; + RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; + RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ; + RsTypeSerializer::serial_process (j,ctx,service_id,"service_id") ; + RsTypeSerializer::serial_process (j,ctx,data_hash,"data_hash") ; + + if(ctx.mFlags & RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE) + return ; + + RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; +} + +#ifdef TO_REMOVE RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedReceiptItem(void *data, uint32_t pktsize) const { uint32_t offset = 8; // skip the header @@ -216,7 +281,76 @@ RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedRece return item; } +#endif +void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; + RsTypeSerializer::serial_process(j,ctx,data_status,"data_status") ; + RsTypeSerializer::serial_process(j,ctx,tunnel_status,"tunnel_status") ; + RsTypeSerializer::serial_process (j,ctx,received_time_TS,"received_time_TS") ; + RsTypeSerializer::serial_process (j,ctx,last_sent_TS,"last_sent_TS") ; + + RsTypeSerializer::serial_process (j,ctx,last_tunnel_request_TS,"last_tunnel_request_TS") ; + RsTypeSerializer::serial_process(j,ctx,sending_attempts,"sending_attempts") ; + + RsTypeSerializer::serial_process(j,ctx,client_id,"client_id") ; + RsTypeSerializer::serial_process (j,ctx,item_hash,"item_hash") ; + RsTypeSerializer::serial_process (j,ctx,tunnel_hash,"tunnel_hash") ; + RsTypeSerializer::serial_process(j,ctx,routing_flags,"routing_flags") ; + + RsTypeSerializer::serial_process(j,ctx,incoming_routes,"incoming_routes") ; + + // Hack for backward compatibility. Normally we should need a single commandline to serialise/deserialise a single item here. + // But the full item is serialised, so we need the header. + + if(j == RsItem::DESERIALIZE) + { + data_item = new RsGRouterGenericDataItem() ; + + ctx.mOffset += 8 ; + data_item->serial_process(j,ctx) ; + + if(ctx.mOffset < ctx.mSize) + { + receipt_item = new RsGRouterSignedReceiptItem(); + + ctx.mOffset += 8 ; + receipt_item->serial_process(j,ctx) ; + } + else + receipt_item = NULL ; + } + else if(j == RsItem::SERIALIZE) + { + uint32_t remaining_size = ctx.mSize - ctx.mOffset; + ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size) ; + ctx.mOffset += RsGRouterSerialiser().size(data_item) ; + + if(receipt_item != NULL) + { + remaining_size = ctx.mSize - ctx.mOffset; + ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size); + ctx.mOffset += RsGRouterSerialiser().size(data_item) ; + } + } + else if(j == RsItem::PRINT) + { + std::cerr << " [Serialized data] " << std::endl; + + if(receipt_item != NULL) + std::cerr << " [Receipt item ]" << std::endl; + } + else if(j == RsItem::SIZE_ESTIMATE) + { + ctx.mOffset += RsGRouterSerialiser().size(data_item) ; + + if(receipt_item != NULL) + ctx.mOffset += RsGRouterSerialiser().size(receipt_item) ; + } +} + +#ifdef TO_REMOVE RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *data, uint32_t pktsize) const { uint32_t offset = 8; // skip the header @@ -274,6 +408,14 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI return item; } +#endif + +void RsGRouterMatrixFriendListItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ; +} + +#ifdef TO_REMOVE RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(void *data, uint32_t pktsize) const { uint32_t offset = 8; // skip the header @@ -299,7 +441,16 @@ RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixF return item; } +#endif +void RsGRouterMatrixTrackItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ; + RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ; + RsTypeSerializer::serial_process(j,ctx,time_stamp,"time_stamp") ; +} + +#ifdef TO_REMOVE RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackItem(void *data, uint32_t pktsize) const { uint32_t offset = 8; // skip the header @@ -321,6 +472,22 @@ RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackI return item; } +#endif + +void RsGRouterMatrixCluesItem::serial_process(SerializeJob j,SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ; + RsTypeSerializer::serial_process(j,ctx,clues,"clues") ; +} + +template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name) +{ + RsTypeSerializer::serial_process(j,ctx,s.friend_id,name+":friend_id") ; + RsTypeSerializer::serial_process (j,ctx,s.weight,name+":weight") ; + RsTypeSerializer::serial_process (j,ctx,s.time_stamp,name+":time_stamp") ; +} + +#ifdef TO_REMOVE RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const { uint32_t offset = 8; // skip the header @@ -356,6 +523,8 @@ RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesI return item; } +#endif + RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const { RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ; @@ -393,6 +562,8 @@ RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const return item ; } + +#ifdef TO_REMOVE uint32_t RsGRouterGenericDataItem::serial_size() const { uint32_t s = 8 ; // header @@ -896,3 +1067,4 @@ std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t) return o ; } +#endif diff --git a/libretroshare/src/grouter/grouteritems.h b/libretroshare/src/grouter/grouteritems.h index af78866c0..7c69d4718 100644 --- a/libretroshare/src/grouter/grouteritems.h +++ b/libretroshare/src/grouter/grouteritems.h @@ -63,14 +63,7 @@ class RsGRouterItem: public RsItem virtual ~RsGRouterItem() {} - virtual bool serialise(void *data,uint32_t& size) const = 0 ; - virtual uint32_t serial_size() const = 0 ; - virtual void clear() = 0 ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0; - - protected: - bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) const; }; /***********************************************************************************/ @@ -100,14 +93,11 @@ public: RsGRouterAbstractMsgItem(uint8_t pkt_subtype) : RsGRouterItem(pkt_subtype) {} virtual ~RsGRouterAbstractMsgItem() {} - virtual uint32_t signed_data_size() const = 0 ; - virtual bool serialise_signed_data(void *data,uint32_t size) const = 0 ; - GRouterMsgPropagationId routing_id ; GRouterKeyId destination_key ; GRouterServiceId service_id ; RsTlvKeySignature signature ; // signs mid+destination_key+state - uint32_t flags ; // packet was delivered, not delivered, bounced, etc + uint32_t flags ; // packet was delivered, not delivered, bounced, etc }; class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRouterNonCopyableObject @@ -116,15 +106,13 @@ class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRoute RsGRouterGenericDataItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_DATA) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } virtual ~RsGRouterGenericDataItem() { clear() ; } - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; - virtual void clear() { free(data_bytes); data_bytes=NULL; } - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; + + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsGRouterGenericDataItem *duplicate() const ; @@ -132,35 +120,23 @@ class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRoute // uint32_t data_size ; uint8_t *data_bytes; - uint32_t duplication_factor ; // number of duplicates allowed. Should be capped at each de-serialise operation! - - // utility methods for signing data - virtual uint32_t signed_data_size() const ; - virtual bool serialise_signed_data(void *data, uint32_t size) const ; }; class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem { public: RsGRouterSignedReceiptItem() : RsGRouterAbstractMsgItem(RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } - virtual ~RsGRouterSignedReceiptItem() {} - - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual ~RsGRouterSignedReceiptItem() {} virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); RsGRouterSignedReceiptItem *duplicate() const ; // packet data // - Sha1CheckSum data_hash ; // avoids an attacker to re-use a given signed receipt. This is the hash of the enceypted data. - - // utility methods for signing data - virtual uint32_t signed_data_size() const ; - virtual bool serialise_signed_data(void *data, uint32_t size) const ; + Sha1CheckSum data_hash ; // avoids an attacker to re-use a given signed receipt. This is the hash of the enceypted data. }; // Low-level data items @@ -170,62 +146,55 @@ class RsGRouterTransactionItem: public RsGRouterItem public: RsGRouterTransactionItem(uint8_t pkt_subtype) : RsGRouterItem(pkt_subtype) {} - virtual ~RsGRouterTransactionItem() {} + virtual ~RsGRouterTransactionItem() {} - virtual bool serialise(void *data,uint32_t& size) const =0; - virtual uint32_t serial_size() const =0; virtual void clear() =0; - virtual RsGRouterTransactionItem *duplicate() const = 0 ; + virtual RsGRouterTransactionItem *duplicate() const = 0 ; }; class RsGRouterTransactionChunkItem: public RsGRouterTransactionItem, public RsGRouterNonCopyableObject { - public: - RsGRouterTransactionChunkItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } +public: + RsGRouterTransactionChunkItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } - virtual ~RsGRouterTransactionChunkItem() { free(chunk_data) ; } + virtual ~RsGRouterTransactionChunkItem() { free(chunk_data) ; } - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void clear() {} + virtual void serial_process(SerializeJob j,SerializeContext& ctx); - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; + virtual RsGRouterTransactionItem *duplicate() const + { + RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem ; + *item = *this ; // copy all fields + item->chunk_data = (uint8_t*)rs_malloc(chunk_size) ; // deep copy memory chunk - virtual RsGRouterTransactionItem *duplicate() const - { - RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem ; - *item = *this ; // copy all fields - item->chunk_data = (uint8_t*)rs_malloc(chunk_size) ; // deep copy memory chunk - - if(item->chunk_data == NULL) - return NULL ; - - memcpy(item->chunk_data,chunk_data,chunk_size) ; - return item ; - } + if(item->chunk_data == NULL) + return NULL ; - GRouterMsgPropagationId propagation_id ; - uint32_t chunk_start ; - uint32_t chunk_size ; - uint32_t total_size ; - uint8_t *chunk_data ; + memcpy(item->chunk_data,chunk_data,chunk_size) ; + return item ; + } + + GRouterMsgPropagationId propagation_id ; + uint32_t chunk_start ; + uint32_t chunk_size ; + uint32_t total_size ; + uint8_t *chunk_data ; }; class RsGRouterTransactionAcknItem: public RsGRouterTransactionItem { - public: - RsGRouterTransactionAcknItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } - virtual ~RsGRouterTransactionAcknItem() {} +public: + RsGRouterTransactionAcknItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } + virtual ~RsGRouterTransactionAcknItem() {} - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; + virtual void clear() {} - virtual RsGRouterTransactionItem *duplicate() const { return new RsGRouterTransactionAcknItem(*this) ; } + virtual RsGRouterTransactionItem *duplicate() const { return new RsGRouterTransactionAcknItem(*this) ; } - GRouterMsgPropagationId propagation_id ; + GRouterMsgPropagationId propagation_id ; }; // Items for saving the routing matrix information. @@ -236,11 +205,8 @@ class RsGRouterMatrixCluesItem: public RsGRouterItem RsGRouterMatrixCluesItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); // packet data // @@ -254,17 +220,15 @@ class RsGRouterMatrixTrackItem: public RsGRouterItem RsGRouterMatrixTrackItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; // packet data // RsGxsMessageId message_id ; - RsPeerId provider_id ; - time_t time_stamp ; + RsPeerId provider_id ; + time_t time_stamp ; }; class RsGRouterMatrixFriendListItem: public RsGRouterItem { @@ -272,11 +236,8 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem RsGRouterMatrixFriendListItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; - - virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void clear() {} // packet data // @@ -291,8 +252,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, virtual ~RsGRouterRoutingInfoItem() { clear() ; } - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void clear() { @@ -302,47 +262,18 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, data_item = NULL ; receipt_item = NULL ; } - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ; }; /***********************************************************************************/ /* Serialisation */ /***********************************************************************************/ -class RsGRouterSerialiser: public RsSerialType +class RsGRouterSerialiser: public RsServiceSerializer { public: - RsGRouterSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GROUTER) {} + RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,SerializeContext::FORMAT_BINARY,flags) {} - virtual uint32_t size (RsItem *item) - { - RsGRouterItem *gitem = dynamic_cast(item); - if (!gitem) - { - return 0; - } - return gitem->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - RsGRouterItem *gitem = dynamic_cast(item); - if (!gitem) - { - return false; - } - return gitem->serialise(data,*size) ; - } - virtual RsItem *deserialise (void *data, uint32_t *size) ; - -private: - RsGRouterGenericDataItem *deserialise_RsGRouterGenericDataItem(void *data,uint32_t size) const ; - RsGRouterTransactionChunkItem *deserialise_RsGRouterTransactionChunkItem(void *data,uint32_t size) const ; - RsGRouterTransactionAcknItem *deserialise_RsGRouterTransactionAcknItem(void *data,uint32_t size) const ; - RsGRouterSignedReceiptItem *deserialise_RsGRouterSignedReceiptItem(void *data,uint32_t size) const ; - RsGRouterMatrixCluesItem *deserialise_RsGRouterMatrixCluesItem(void *data,uint32_t size) const ; - RsGRouterMatrixTrackItem *deserialise_RsGRouterMatrixTrackItem(void *data,uint32_t size) const ; - RsGRouterMatrixFriendListItem *deserialise_RsGRouterMatrixFriendListItem(void *data,uint32_t size) const ; - RsGRouterRoutingInfoItem *deserialise_RsGRouterRoutingInfoItem(void *data,uint32_t size) const ; + virtual RsItem *create_item(uint16_t service,uint8_t subtype) const ; }; diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index f14af4412..998f7e636 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -1263,13 +1263,13 @@ bool p3GRouter::locked_sendTransactionData(const RsPeerId& pid,const RsGRouterTr #ifdef GROUTER_DEBUG std::cerr << " sending to tunnel vpid " << pid << std::endl; #endif - uint32_t turtle_data_size = trans_item.serial_size() ; + uint32_t turtle_data_size = RsGRouterSerialiser().size(const_cast(&trans_item)) ; uint8_t *turtle_data = (uint8_t*)rs_malloc(turtle_data_size) ; if(turtle_data == NULL) return false ; - if(!trans_item.serialise(turtle_data,turtle_data_size)) + if(!RsGRouterSerialiser().serialise(const_cast(&trans_item),turtle_data,&turtle_data_size)) { std::cerr << " ERROR: cannot serialise RsGRouterTransactionChunkItem." << std::endl; @@ -1428,7 +1428,7 @@ bool p3GRouter::sliceDataItem(RsGRouterAbstractMsgItem *item,std::listprint(std::cerr, 2) ; #endif - uint32_t size = item->serial_size(); + uint32_t size = RsGRouterSerialiser().size(item); RsTemporaryMemory data(size) ; // data will be freed on return, whatever the route taken. @@ -1438,7 +1438,7 @@ bool p3GRouter::sliceDataItem(RsGRouterAbstractMsgItem *item,std::listserialise(data,size)) + if(!RsGRouterSerialiser().serialise(item,data,&size)) { std::cerr << " ERROR: cannot serialise." << std::endl; throw ; @@ -1617,12 +1617,15 @@ void p3GRouter::handleIncomingReceiptItem(RsGRouterSignedReceiptItem *receipt_it Sha1CheckSum p3GRouter::computeDataItemHash(RsGRouterGenericDataItem *data_item) { - uint32_t total_size = data_item->signed_data_size() + data_item->signature.TlvSize() ; + RsGRouterSerialiser signature_serializer(RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE | RsGenericSerializer::SERIALIZATION_FLAG_SKIP_HEADER); + + uint32_t signed_data_size = signature_serializer.size(data_item); + uint32_t total_size = signed_data_size + data_item->signature.TlvSize() ; RsTemporaryMemory mem(total_size) ; uint32_t offset = 0 ; - data_item->serialise_signed_data(mem,total_size) ; - offset += data_item->signed_data_size() ; + signature_serializer.serialise(data_item,mem,&total_size) ; + offset += signed_data_size ; data_item->signature.SetTlv(mem, total_size,&offset) ; @@ -1948,28 +1951,45 @@ bool p3GRouter::signDataItem(RsGRouterAbstractMsgItem *item,const RsGxsId& signi { try { -#ifdef GROUTER_DEBUG +//#ifdef GROUTER_DEBUG std::cerr << "p3GRouter::signDataItem()" << std::endl; std::cerr << " Key ID = " << signing_id << std::endl; std::cerr << " Getting key material..." << std::endl; -#endif - uint32_t data_size = item->signed_data_size() ; - RsTemporaryMemory data(data_size) ; +//#endif + RsGRouterSerialiser signature_serializer(RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE | RsGenericSerializer::SERIALIZATION_FLAG_SKIP_HEADER) ; + uint32_t data_size = signature_serializer.size(item) ; + RsTemporaryMemory data(data_size) ; if(data == NULL) throw std::runtime_error("Cannot allocate memory for signing data.") ; - if(!item->serialise_signed_data(data,data_size)) + if(!signature_serializer.serialise(item,data,&data_size)) throw std::runtime_error("Cannot serialise signed data.") ; - uint32_t error_status ; + uint32_t error_status ; - if(!mGixs->signData(data,data_size,signing_id,item->signature,error_status)) - throw std::runtime_error("Cannot sign for id " + signing_id.toStdString() + ". Signature call failed.") ; + std::cerr << "GRouter::signing data" << std::endl; + std::cerr << " size: " << data_size << std::endl; + std::cerr << " data: " << RsUtil::BinToHex(data,data_size) << std::endl; -#ifdef GROUTER_DEBUG + if(!mGixs->signData(data,data_size,signing_id,item->signature,error_status)) + throw std::runtime_error("Cannot sign for id " + signing_id.toStdString() + ". Signature call failed.") ; + +//#ifdef GROUTER_DEBUG std::cerr << "Created signature for data hash: " << RsDirUtil::sha1sum(data,data_size) << " and key id=" << signing_id << std::endl; -#endif +//#endif + // Check signature + RsIdentityUsage::UsageCode info; + uint32_t error; + + if(verifySignedDataItem(item,info,error)) + std::cerr << "Signature checks." << std::endl; + else + { + std::cerr << "(EE) Cannot verify own signed item. Something's wrong." << std::endl; + return false ; + } + return true ; } catch(std::exception& e) @@ -1989,15 +2009,16 @@ bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item,const RsIden std::cerr << "(WW) received global router message from banned identity " << item->signature.keyId << ". Rejecting the message." << std::endl; return false ; } + RsGRouterSerialiser signature_serializer(RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE | RsGenericSerializer::SERIALIZATION_FLAG_SKIP_HEADER); - uint32_t data_size = item->signed_data_size() ; - RsTemporaryMemory data(data_size) ; + uint32_t data_size = signature_serializer.size(item) ; + RsTemporaryMemory data(data_size) ; - if(data == NULL) - throw std::runtime_error("Cannot allocate data.") ; + if(data == NULL) + throw std::runtime_error("Cannot allocate data.") ; - if(!item->serialise_signed_data(data,data_size)) - throw std::runtime_error("Cannot serialise signed data.") ; + if(!signature_serializer.serialise(item,data,&data_size)) + throw std::runtime_error("Cannot serialise signed data.") ; RsIdentityUsage use(RS_SERVICE_TYPE_GROUTER,info) ; diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index ca6d23820..4a962cf29 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -524,7 +524,7 @@ int pqiSSLstore::readPkt(RsItem **item_out) int extralen = getRsItemSize(block) - blen; int totallen = extralen+blen; - if(totallen > 1024*1024) + if(totallen > 1024*1024 || totallen((const void*)data)) ; RsItem *item = create_item(getRsItemService(rstype),getRsItemSubType(rstype)) ; if(!item) { - std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << getRsItemSubType(rstype) << std::dec << std::endl; + std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << (int)getRsItemSubType(rstype) << std::dec << std::endl; std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl; return NULL ; } @@ -40,13 +47,19 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) } RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size) { + if(mFlags & SERIALIZATION_FLAG_SKIP_HEADER) + { + std::cerr << "(EE) Cannot deserialise item with flags SERIALIZATION_FLAG_SKIP_HEADER. Check your code!" << std::endl; + return NULL ; + } + uint32_t rstype = getRsItemId(const_cast((const void*)data)) ; RsItem *item = create_item(getRsItemType(rstype),getRsItemSubType(rstype)) ; if(!item) { - std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << getRsItemSubType(rstype) << std::dec << std::endl; + std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << (int)getRsItemSubType(rstype) << std::dec << std::endl; std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl; return NULL ; } @@ -77,12 +90,19 @@ bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size) if(tlvsize > *size) throw std::runtime_error("Cannot serialise: not enough room.") ; - if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize)) + + if(mFlags & SERIALIZATION_FLAG_SKIP_HEADER) + ctx.mOffset = 0; + else { - std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; - return false ; + if(!setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize)) + { + std::cerr << "RsSerializer::serialise_item(): ERROR. Not enough size!" << std::endl; + return false ; + } + ctx.mOffset = 8; } - ctx.mOffset = 8; + ctx.mSize = tlvsize; item->serial_process(RsItem::SERIALIZE,ctx) ; @@ -99,7 +119,10 @@ uint32_t RsGenericSerializer::size(RsItem *item) { SerializeContext ctx(NULL,0,mFormat,mFlags); - ctx.mOffset = 8 ; // header size + if(mFlags & SERIALIZATION_FLAG_SKIP_HEADER) + ctx.mOffset = 0; + else + ctx.mOffset = 8 ; // header size item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; return ctx.mOffset ; diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 3285becf9..700b690f5 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -24,6 +24,7 @@ public: static const SerializationFlags SERIALIZATION_FLAG_NONE ; // 0x0000 static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001 static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002 + static const SerializationFlags SERIALIZATION_FLAG_SKIP_HEADER ; // 0x0004 // The following functions overload RsSerialType. They *should not* need to be further overloaded. From 9c610a736da2f1caefcaead5762af23ccdb24e01 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 11:40:46 +0200 Subject: [PATCH 051/106] cleaned the hierarchy of serialization classes --- libretroshare/src/chat/rschatitems.cc | 28 +++--- libretroshare/src/chat/rschatitems.h | 30 +++--- .../src/file_sharing/rsfilelistitems.cc | 6 +- .../src/file_sharing/rsfilelistitems.h | 5 +- .../src/ft/ftturtlefiletransferitem.cc | 12 +-- .../src/ft/ftturtlefiletransferitem.h | 12 +-- libretroshare/src/grouter/grouteritems.cc | 40 ++++---- libretroshare/src/grouter/grouteritems.h | 18 ++-- .../src/gxstunnel/rsgxstunnelitems.h | 5 +- libretroshare/src/libretroshare.pro | 3 +- libretroshare/src/pqi/p3servicecontrol.cc | 1 + libretroshare/src/pqi/pqi.h | 3 +- libretroshare/src/pqi/pqiqos.cc | 4 + libretroshare/src/pqi/pqistore.cc | 1 + libretroshare/src/rsitems/rsbanlistitems.cc | 4 +- libretroshare/src/rsitems/rsbanlistitems.h | 6 +- libretroshare/src/rsitems/rsbwctrlitems.cc | 2 +- libretroshare/src/rsitems/rsbwctrlitems.h | 6 +- libretroshare/src/rsitems/rsconfigitems.cc | 19 ++-- libretroshare/src/rsitems/rsconfigitems.h | 18 ++-- .../src/rsitems/rsdiscovery2items.cc | 8 +- libretroshare/src/rsitems/rsdiscovery2items.h | 8 +- .../src/rsitems/rsfiletransferitems.cc | 12 +-- .../src/rsitems/rsfiletransferitems.h | 14 +-- .../src/rsitems/rsgxsreputationitems.cc | 10 +- .../src/rsitems/rsgxsreputationitems.h | 13 ++- libretroshare/src/rsitems/rshistoryitems.cc | 4 +- libretroshare/src/rsitems/rshistoryitems.h | 2 +- libretroshare/src/rsitems/rsitem.h | 90 ++++++++++++++++++ libretroshare/src/rsitems/rsmsgitems.cc | 18 ++-- libretroshare/src/rsitems/rsmsgitems.h | 18 ++-- libretroshare/src/rsitems/rsrttitems.cc | 6 +- libretroshare/src/rsitems/rsrttitems.h | 6 +- libretroshare/src/serialiser/rsgxsitems.h | 1 + .../src/serialiser/rsgxsrecognitems.h | 3 + .../src/serialiser/rsheartbeatitems.h | 2 + libretroshare/src/serialiser/rsnxsitems.h | 1 + libretroshare/src/serialiser/rsserial.cc | 5 +- libretroshare/src/serialiser/rsserial.h | 94 +------------------ .../src/serialiser/rsserviceinfoitems.h | 3 + .../src/serialiser/rsserviceserialiser.cc | 1 + libretroshare/src/serialiser/rsstatusitems.h | 3 +- .../src/serialization/rsserializer.cc | 12 ++- .../src/serialization/rsserializer.h | 35 +++++-- .../src/serialization/rstypeserializer.h | 84 +++++++---------- libretroshare/src/services/p3service.cc | 2 + libretroshare/src/turtle/rsturtleitem.cc | 12 +-- libretroshare/src/turtle/rsturtleitem.h | 18 ++-- 48 files changed, 382 insertions(+), 326 deletions(-) create mode 100644 libretroshare/src/rsitems/rsitem.h diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 7aa0dd4f3..06bb063a7 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -62,7 +62,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) c } } -void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; @@ -80,7 +80,7 @@ RsChatAvatarItem::~RsChatAvatarItem() } } -void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx) +void RsChatLobbyBouncingObject::serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; @@ -90,19 +90,19 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } -void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsChatMsgItem::serial_process(j,ctx) ; RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; RsChatLobbyBouncingObject::serial_process(j,ctx) ; } -void RsChatLobbyListRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyListRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { // nothing to do. This is an empty item. } -template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) +template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) { RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; @@ -112,12 +112,12 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ RsTypeSerializer::serial_process (j,ctx, info.flags,"info.flags") ; } -void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; } -void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyEventItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; @@ -125,24 +125,24 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex RsChatLobbyBouncingObject::serial_process(j,ctx) ; } -void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyUnsubscribeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; } -void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyConnectChallengeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,challenge_code,"challenge_code") ; } -void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyInviteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx, lobby_id, "lobby_id") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ; RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ; } -void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsPrivateChatMsgConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { uint32_t x=0 ; @@ -154,19 +154,19 @@ void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,Serialize RsTypeSerializer::serial_process(j,ctx, recvTime, "recvTime") ; } -void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,status_string,"status_string") ; } -void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatAvatarItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ; RsTypeSerializer::serial_process(j,ctx,b,"image data") ; } -void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 1766dbfec..06de87c7f 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -30,6 +30,8 @@ #include "serialization/rsserializer.h" #include "serialiser/rstlvkeys.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" +#include "rsitems/rsitem.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" @@ -112,7 +114,7 @@ public: // derived from RsItem - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} uint32_t chatFlags; @@ -142,7 +144,7 @@ protected: // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual uint32_t PacketId() const= 0; }; @@ -155,7 +157,7 @@ public: virtual ~RsChatLobbyMsgItem() {} virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); ChatLobbyMsgId parent_msg_id ; // Used for threaded chat. @@ -171,7 +173,7 @@ public: virtual ~RsChatLobbyEventItem() {} virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } // - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // members. // @@ -189,7 +191,7 @@ class RsChatLobbyListRequestItem: public RsChatItem RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {} virtual ~RsChatLobbyListRequestItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; struct VisibleChatLobbyInfo @@ -207,7 +209,7 @@ class RsChatLobbyListItem: public RsChatItem RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {} virtual ~RsChatLobbyListItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); std::vector lobbies ; }; @@ -219,7 +221,7 @@ class RsChatLobbyUnsubscribeItem: public RsChatItem virtual ~RsChatLobbyUnsubscribeItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t lobby_id ; }; @@ -231,7 +233,7 @@ class RsChatLobbyConnectChallengeItem: public RsChatItem virtual ~RsChatLobbyConnectChallengeItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t challenge_code ; }; @@ -242,7 +244,7 @@ class RsChatLobbyInviteItem: public RsChatItem RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {} virtual ~RsChatLobbyInviteItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); ChatLobbyId lobby_id ; std::string lobby_name ; @@ -262,7 +264,7 @@ class RsPrivateChatMsgConfigItem: public RsChatItem virtual ~RsPrivateChatMsgConfigItem() {} virtual void clear() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags); @@ -286,7 +288,7 @@ public: virtual void clear() { lobby_Id = 0; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t lobby_Id; uint32_t flags ; @@ -301,7 +303,7 @@ class RsChatStatusItem: public RsChatItem virtual ~RsChatStatusItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t flags ; std::string status_string; @@ -315,7 +317,7 @@ class RsChatAvatarItem: public RsChatItem RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;} virtual ~RsChatAvatarItem() ; - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t image_size ; // size of data in bytes unsigned char *image_data ; // image @@ -325,7 +327,7 @@ class RsChatSerialiser: public RsServiceSerializer { public: RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) - :RsServiceSerializer(RS_SERVICE_TYPE_CHAT,SerializeContext::FORMAT_BINARY,flags) {} + :RsServiceSerializer(RS_SERVICE_TYPE_CHAT,RsGenericSerializer::FORMAT_BINARY,flags) {} virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ; }; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index 85a94488f..6934f29d2 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -24,16 +24,18 @@ */ #include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" + #include "file_sharing/rsfilelistitems.h" -void RsFileListsSyncRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileListsSyncRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; RsTypeSerializer::serial_process(j,ctx,flags ,"flags") ; RsTypeSerializer::serial_process(j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; } -void RsFileListsSyncResponseItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileListsSyncResponseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; RsTypeSerializer::serial_process (j,ctx,checksum,"checksum") ; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 391d3dd88..8e45ef251 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -28,6 +28,7 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" @@ -78,7 +79,7 @@ public: virtual void clear(){} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsFileHash entry_hash ; // hash of the directory to sync uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc. @@ -94,7 +95,7 @@ public: virtual void clear(); - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsFileHash entry_hash ; // hash of the directory to sync RsFileHash checksum ; // checksum of the bindary data, for checking diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.cc b/libretroshare/src/ft/ftturtlefiletransferitem.cc index 5c343b7fa..3009fb87c 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -32,37 +32,37 @@ #include -void RsTurtleFileMapRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; } -void RsTurtleFileMapItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; RsTypeSerializer::serial_process (j,ctx,compressed_map._map,"map") ; } -void RsTurtleChunkCrcRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; } -void RsTurtleChunkCrcItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; RsTypeSerializer::serial_process (j,ctx,check_sum,"check_sum") ; } -void RsTurtleFileRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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") ; } -void RsTurtleFileDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_offset,"chunk_offset") ; diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.h b/libretroshare/src/ft/ftturtlefiletransferitem.h index fd8aada93..ce4a25217 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.h +++ b/libretroshare/src/ft/ftturtlefiletransferitem.h @@ -43,7 +43,7 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem void clear() {} protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem @@ -67,7 +67,7 @@ class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem uint32_t chunk_size ; // size of the file chunk void *chunk_data ; // actual data. - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem @@ -78,7 +78,7 @@ class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem virtual bool shouldStampTunnel() const { return false ; } void clear() {} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem @@ -93,7 +93,7 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem // with the default file map for this source. void clear() { compressed_map._map.clear() ;} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem @@ -107,7 +107,7 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem uint32_t chunk_number ; // id of the chunk to CRC. void clear() {} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem @@ -122,5 +122,5 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem Sha1CheckSum check_sum ; void clear() { check_sum.clear() ;} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index c48dbc134..48da81548 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -3,6 +3,8 @@ #include "serialiser/rstlvbase.h" #include "grouteritems.h" +#include "serialization/rstypeserializer.h" + /**********************************************************************************************/ /* SERIALISER STUFF */ /**********************************************************************************************/ @@ -28,7 +30,7 @@ RsItem *RsGRouterSerialiser::create_item(uint16_t service_id,uint8_t subtype) co } } -void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterTransactionChunkItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_start ,"chunk_start") ; @@ -37,7 +39,7 @@ void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeConte // Hack for backward compatibility (the chunk size is not directly next to the chunk data) - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) { if(chunk_size > ctx.mSize || ctx.mOffset > ctx.mSize - chunk_size) // better than if(chunk_size + offset > size) { @@ -54,12 +56,12 @@ void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeConte memcpy(chunk_data,&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_size) ; ctx.mOffset += chunk_size ; } - else if(j== RsItem::SERIALIZE) + else if(j== RsGenericSerializer::SERIALIZE) { memcpy(&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_data,chunk_size) ; ctx.mOffset += chunk_size ; } - else if(j== RsItem::SIZE_ESTIMATE) + else if(j== RsGenericSerializer::SIZE_ESTIMATE) ctx.mOffset += chunk_size ; else std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl; @@ -112,7 +114,7 @@ RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransac } #endif -void RsGRouterTransactionAcknItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterTransactionAcknItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; } @@ -140,7 +142,7 @@ RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransact } #endif -void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,routing_id,"routing_id") ; RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ; @@ -157,7 +159,7 @@ void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& c RsTypeSerializer::serial_process(j,ctx,duplication_factor,"duplication_factor") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; - if(j == RsItem::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. + if(j == RsGenericSerializer::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. { if(duplication_factor < 1) { @@ -242,7 +244,7 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI } #endif -void RsGRouterSignedReceiptItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,routing_id,"routing_id") ; RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; @@ -283,7 +285,7 @@ RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedRece } #endif -void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process(j,ctx,data_status,"data_status") ; @@ -304,7 +306,7 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c // Hack for backward compatibility. Normally we should need a single commandline to serialise/deserialise a single item here. // But the full item is serialised, so we need the header. - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) { data_item = new RsGRouterGenericDataItem() ; @@ -321,7 +323,7 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c else receipt_item = NULL ; } - else if(j == RsItem::SERIALIZE) + else if(j == RsGenericSerializer::SERIALIZE) { uint32_t remaining_size = ctx.mSize - ctx.mOffset; ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size) ; @@ -330,18 +332,18 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c if(receipt_item != NULL) { remaining_size = ctx.mSize - ctx.mOffset; - ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size); - ctx.mOffset += RsGRouterSerialiser().size(data_item) ; + ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(receipt_item,ctx.mData,&remaining_size); + ctx.mOffset += RsGRouterSerialiser().size(receipt_item) ; } } - else if(j == RsItem::PRINT) + else if(j == RsGenericSerializer::PRINT) { std::cerr << " [Serialized data] " << std::endl; if(receipt_item != NULL) std::cerr << " [Receipt item ]" << std::endl; } - else if(j == RsItem::SIZE_ESTIMATE) + else if(j == RsGenericSerializer::SIZE_ESTIMATE) { ctx.mOffset += RsGRouterSerialiser().size(data_item) ; @@ -410,7 +412,7 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI } #endif -void RsGRouterMatrixFriendListItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterMatrixFriendListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ; } @@ -443,7 +445,7 @@ RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixF } #endif -void RsGRouterMatrixTrackItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ; RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ; @@ -474,13 +476,13 @@ RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackI } #endif -void RsGRouterMatrixCluesItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ; RsTypeSerializer::serial_process(j,ctx,clues,"clues") ; } -template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name) +template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name) { RsTypeSerializer::serial_process(j,ctx,s.friend_id,name+":friend_id") ; RsTypeSerializer::serial_process (j,ctx,s.weight,name+":weight") ; diff --git a/libretroshare/src/grouter/grouteritems.h b/libretroshare/src/grouter/grouteritems.h index 7c69d4718..505f35361 100644 --- a/libretroshare/src/grouter/grouteritems.h +++ b/libretroshare/src/grouter/grouteritems.h @@ -112,7 +112,7 @@ class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRoute data_bytes=NULL; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGRouterGenericDataItem *duplicate() const ; @@ -130,7 +130,7 @@ class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem virtual ~RsGRouterSignedReceiptItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGRouterSignedReceiptItem *duplicate() const ; @@ -161,7 +161,7 @@ public: virtual ~RsGRouterTransactionChunkItem() { free(chunk_data) ; } virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual RsGRouterTransactionItem *duplicate() const { @@ -188,7 +188,7 @@ public: RsGRouterTransactionAcknItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } virtual ~RsGRouterTransactionAcknItem() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} @@ -206,7 +206,7 @@ class RsGRouterMatrixCluesItem: public RsGRouterItem { setPriorityLevel(0) ; } // this item is never sent through the network virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // packet data // @@ -220,7 +220,7 @@ class RsGRouterMatrixTrackItem: public RsGRouterItem RsGRouterMatrixTrackItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} @@ -236,7 +236,7 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem RsGRouterMatrixFriendListItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // packet data @@ -252,7 +252,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, virtual ~RsGRouterRoutingInfoItem() { clear() ; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() { @@ -271,7 +271,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, class RsGRouterSerialiser: public RsServiceSerializer { public: - RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,SerializeContext::FORMAT_BINARY,flags) {} + RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,RsGenericSerializer::FORMAT_BINARY,flags) {} virtual RsItem *create_item(uint16_t service,uint8_t subtype) const ; }; diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.h b/libretroshare/src/gxstunnel/rsgxstunnelitems.h index ad049a753..4da26da0e 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.h +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.h @@ -27,9 +27,12 @@ #include +#include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" +#include "rsitems/rsitem.h" + #include "retroshare/rstypes.h" #include "serialiser/rstlvkeys.h" -#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 8a633c1a7..287e6a4d7 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -452,7 +452,8 @@ HEADERS += grouter/groutercache.h \ grouter/groutertypes.h \ grouter/rsgrouterclient.h -HEADERS += rsitems/itempriorities.h \ +HEADERS += rsitems/rsitem.h \ + rsitems/itempriorities.h \ serialiser/rsbaseserial.h \ rsitems/rsfiletransferitems.h \ serialiser/rsserviceserialiser.h \ diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index f22cc44c0..0b3b1514e 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -27,6 +27,7 @@ #include "p3servicecontrol.h" #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" #include "serialiser/rsserial.h" #include "serialiser/rsbaseserial.h" #include "pqi/p3cfgmgr.h" diff --git a/libretroshare/src/pqi/pqi.h b/libretroshare/src/pqi/pqi.h index a7aa5854c..07cf00f9d 100644 --- a/libretroshare/src/pqi/pqi.h +++ b/libretroshare/src/pqi/pqi.h @@ -27,8 +27,7 @@ #ifndef PQI_TOP_HEADER #define PQI_TOP_HEADER -#include "serialiser/rsserial.h" - +#include "rsitems/rsitem.h" class P3Interface { diff --git a/libretroshare/src/pqi/pqiqos.cc b/libretroshare/src/pqi/pqiqos.cc index b2472c0b7..9fc62aa8c 100644 --- a/libretroshare/src/pqi/pqiqos.cc +++ b/libretroshare/src/pqi/pqiqos.cc @@ -11,7 +11,9 @@ const uint32_t pqiQoS::MAX_PACKET_COUNTER_VALUE = (1 << 24) ; pqiQoS::pqiQoS(uint32_t nb_levels,float alpha) : _item_queues(nb_levels),_alpha(alpha) { +#ifdef DEBUG assert(pow(alpha,nb_levels) < 1e+20) ; +#endif float c = 1.0f ; float inc = alpha ; @@ -110,7 +112,9 @@ void *pqiQoS::out_rsItem(uint32_t max_slice_size, uint32_t& size, bool& starts, if(last >= 0) { +#ifdef DEBUG assert(_nb_items > 0) ; +#endif // now chop a slice of this item diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index 4a962cf29..23201541a 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -40,6 +40,7 @@ * */ +#include "rsitems/rsitem.h" #include "pqi/pqistore.h" #include "serialiser/rsserial.h" #include diff --git a/libretroshare/src/rsitems/rsbanlistitems.cc b/libretroshare/src/rsitems/rsbanlistitems.cc index d597abcfd..85acfb96c 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.cc +++ b/libretroshare/src/rsitems/rsbanlistitems.cc @@ -41,12 +41,12 @@ void RsBanListItem::clear() peerList.TlvClear(); } -void RsBanListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsBanListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ; } -void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsBanListConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,type,"type") ; RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; diff --git a/libretroshare/src/rsitems/rsbanlistitems.h b/libretroshare/src/rsitems/rsbanlistitems.h index 3fce37956..836fe1b7e 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.h +++ b/libretroshare/src/rsitems/rsbanlistitems.h @@ -29,6 +29,8 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" #include "serialiser/rstlvbanlist.h" #include "serialization/rsserializer.h" @@ -50,7 +52,7 @@ class RsBanListItem: public RsItem virtual ~RsBanListItem(){} virtual void clear(); - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvBanList peerList; }; @@ -64,7 +66,7 @@ public: virtual ~RsBanListConfigItem(){} virtual void clear() { banned_peers.TlvClear() ; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t type ; RsPeerId peerId ; diff --git a/libretroshare/src/rsitems/rsbwctrlitems.cc b/libretroshare/src/rsitems/rsbwctrlitems.cc index 747dbbbda..45c23d2c8 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.cc +++ b/libretroshare/src/rsitems/rsbwctrlitems.cc @@ -52,7 +52,7 @@ void RsBwCtrlAllowedItem::clear() allowedBw = 0; } -void RsBwCtrlAllowedItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ; } diff --git a/libretroshare/src/rsitems/rsbwctrlitems.h b/libretroshare/src/rsitems/rsbwctrlitems.h index e21410b39..570e0d87b 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.h +++ b/libretroshare/src/rsitems/rsbwctrlitems.h @@ -28,9 +28,9 @@ #include +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -#include "serialiser/rstlvbase.h" +#include "rsitems/itempriorities.h" #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" @@ -51,7 +51,7 @@ public: virtual ~RsBwCtrlAllowedItem() {} virtual void clear(); - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; }; diff --git a/libretroshare/src/rsitems/rsconfigitems.cc b/libretroshare/src/rsitems/rsconfigitems.cc index 4ba94a8bf..743e35871 100644 --- a/libretroshare/src/rsitems/rsconfigitems.cc +++ b/libretroshare/src/rsitems/rsconfigitems.cc @@ -28,6 +28,7 @@ #include "rsitems/rsconfigitems.h" #include "retroshare/rspeers.h" // Needed for RsGroupInfo. +#include "serialization/rstypeserializer.h" /*** * #define RSSERIAL_DEBUG 1 * #define RSSERIAL_ERROR_DEBUG 1 @@ -69,7 +70,7 @@ void RsFileTransfer::clear() } -void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,file,"file") ; RsTypeSerializer::serial_process(j,ctx,allPeerIds,"allPeerIds") ; @@ -91,7 +92,7 @@ void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ; } -void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,file,"file") ; RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; @@ -111,7 +112,7 @@ RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_su } } -void RsConfigKeyValueSet::serial_process(SerializeJob j,SerializeContext& ctx) +void RsConfigKeyValueSet::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tlvkvs,"tlvkvs") ; } @@ -156,7 +157,7 @@ void RsPeerNetItem::clear() domain_addr.clear(); domain_port = 0; } -void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerNetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; @@ -181,12 +182,12 @@ void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,domain_port,"domain_port") ; } -void RsPeerBandwidthLimitsItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerBandwidthLimitsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peers,"peers") ; } -void RsPeerStunItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,stunList,"stunList") ; } @@ -226,7 +227,7 @@ RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g) pgpList.ids = g.peerIds; } -void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsNodeGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { uint32_t v=0 ; @@ -237,14 +238,14 @@ void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,pgpList,"pgpList") ; } -void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerServicePermissionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { // We need to hack this because of backward compatibility. The correct way to do it would be: // // RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ; // RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ; - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) { uint32_t v=0 ; RsTypeSerializer::serial_process(j,ctx,v,"pgp_ids.size()") ; diff --git a/libretroshare/src/rsitems/rsconfigitems.h b/libretroshare/src/rsitems/rsconfigitems.h index 6ac90c212..bc4b9e824 100644 --- a/libretroshare/src/rsitems/rsconfigitems.h +++ b/libretroshare/src/rsitems/rsconfigitems.h @@ -29,6 +29,8 @@ #include #include +#include "rsitems/rsitem.h" + #include "retroshare/rstypes.h" #include "serialiser/rsserial.h" @@ -77,7 +79,7 @@ public: virtual ~RsPeerNetItem(){} virtual void clear(); - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* networking information */ RsPeerId peerId; /* Mandatory */ @@ -115,7 +117,7 @@ class RsPeerServicePermissionItem : public RsItem pgp_ids.clear() ; service_flags.clear() ; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* Mandatory */ @@ -132,7 +134,7 @@ class RsPeerBandwidthLimitsItem : public RsItem { peers.clear() ; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* Mandatory */ std::map peers ; @@ -172,7 +174,7 @@ public: explicit RsNodeGroupItem(const RsGroupInfo&) ; - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // /* set data from RsGroupInfo to RsPeerGroupItem */ // void set(RsGroupInfo &groupInfo); @@ -197,7 +199,7 @@ public: virtual ~RsPeerStunItem(){} virtual void clear() { stunList.TlvClear() ;} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvPeerIdSet stunList; /* Mandatory */ }; @@ -277,7 +279,7 @@ class RsFileTransfer: public RsItem virtual ~RsFileTransfer(){} virtual void clear(); - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvFileItem file; RsTlvPeerIdSet allPeerIds; @@ -331,7 +333,7 @@ public: virtual ~RsFileConfigItem() {} virtual void clear() { parent_groups.TlvClear(); } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvFileItem file; uint32_t flags; @@ -359,7 +361,7 @@ public: virtual ~RsConfigKeyValueSet(){} virtual void clear() { tlvkvs.TlvClear();} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvKeyValueSet tlvkvs; }; diff --git a/libretroshare/src/rsitems/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc index 8e4175a9e..f9f19270c 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -73,7 +73,7 @@ void RsDiscPgpListItem::clear() pgpIdSet.TlvClear(); } -void RsDiscPgpListItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsDiscPgpListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mode,"mode") ; RsTypeSerializer::serial_process(j,ctx,pgpIdSet,"pgpIdSet") ; @@ -86,7 +86,7 @@ void RsDiscPgpCertItem::clear() } -void RsDiscPgpCertItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; @@ -121,7 +121,7 @@ void RsDiscContactItem::clear() extAddrList.TlvClear(); } -void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsDiscContactItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,pgpId,"pgpId"); RsTypeSerializer::serial_process (j,ctx,sslId,"sslId"); @@ -134,7 +134,7 @@ void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) // This is a hack. Normally we should have to different item types, in order to avoid this nonesense. - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) isHidden = ( GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR); if(isHidden) diff --git a/libretroshare/src/rsitems/rsdiscovery2items.h b/libretroshare/src/rsitems/rsdiscovery2items.h index 7610d534f..ce30a2928 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.h +++ b/libretroshare/src/rsitems/rsdiscovery2items.h @@ -32,6 +32,8 @@ #include "serialiser/rstlvidset.h" #include "serialiser/rstlvaddrs.h" #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" #include "serialization/rsserializer.h" @@ -65,7 +67,7 @@ public: virtual ~RsDiscPgpListItem(){} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); uint32_t mode; RsTlvPgpIdSet pgpIdSet; @@ -86,7 +88,7 @@ public: virtual ~RsDiscPgpCertItem(){} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); RsPgpId pgpId; std::string pgpCert; @@ -106,7 +108,7 @@ public: virtual ~RsDiscContactItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); RsPgpId pgpId; RsPeerId sslId; diff --git a/libretroshare/src/rsitems/rsfiletransferitems.cc b/libretroshare/src/rsitems/rsfiletransferitems.cc index acdadaff2..cd0ea088d 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.cc +++ b/libretroshare/src/rsitems/rsfiletransferitems.cc @@ -53,38 +53,38 @@ void RsFileTransferDataItem::clear() fd.TlvClear(); } -void RsFileTransferDataRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferDataRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,fileoffset,"fileoffset") ; RsTypeSerializer::serial_process (j,ctx,chunksize, "chunksize") ; RsTypeSerializer::serial_process(j,ctx,file, "file") ; } -void RsFileTransferDataItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,fd,"fd") ; } -void RsFileTransferChunkMapRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferChunkMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,is_client,"is_client") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; } -void RsFileTransferChunkMapItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferChunkMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (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) +void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; } -void RsFileTransferSingleChunkCrcItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; diff --git a/libretroshare/src/rsitems/rsfiletransferitems.h b/libretroshare/src/rsitems/rsfiletransferitems.h index b51e74d53..b0ab0972a 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.h +++ b/libretroshare/src/rsitems/rsfiletransferitems.h @@ -30,7 +30,9 @@ #include "retroshare/rstypes.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvfileitem.h" +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialization/rsserializer.h" @@ -70,7 +72,7 @@ class RsFileTransferDataRequestItem: public RsFileTransferItem virtual ~RsFileTransferDataRequestItem() {} virtual void clear(); - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // Private data part. // @@ -90,7 +92,7 @@ class RsFileTransferDataItem: public RsFileTransferItem } virtual ~RsFileTransferDataItem() { clear() ; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear(); @@ -109,7 +111,7 @@ class RsFileTransferChunkMapRequestItem: public RsFileTransferItem virtual ~RsFileTransferChunkMapRequestItem() {} virtual void clear() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // Private data part. // @@ -127,7 +129,7 @@ class RsFileTransferChunkMapItem: public RsFileTransferItem } virtual ~RsFileTransferChunkMapItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // Private data part. @@ -146,7 +148,7 @@ class RsFileTransferSingleChunkCrcRequestItem: public RsFileTransferItem } virtual ~RsFileTransferSingleChunkCrcRequestItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // Private data part. @@ -164,7 +166,7 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem } virtual ~RsFileTransferSingleChunkCrcItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // Private data part. diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc index 11e267654..1a50bf9dc 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.cc +++ b/libretroshare/src/rsitems/rsgxsreputationitems.cc @@ -53,21 +53,21 @@ void RsGxsReputationBannedNodeSetItem::clear() mKnownIdentities.TlvClear(); } -void RsGxsReputationConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ; RsTypeSerializer::serial_process(j,ctx,mLatestUpdate,"mLatestUpdate") ; RsTypeSerializer::serial_process(j,ctx,mLastQuery,"mLastQuery") ; } -void RsGxsReputationBannedNodeSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationBannedNodeSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ; RsTypeSerializer::serial_process (j,ctx,mLastActivityTS,"mLastActivityTS") ; RsTypeSerializer::serial_process(j,ctx,mKnownIdentities,"mKnownIdentities") ; } -void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ; RsTypeSerializer::serial_process(j,ctx,mOwnOpinion,"mOwnOpinion") ; @@ -78,12 +78,12 @@ void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeCont RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; } -void RsGxsReputationUpdateItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mLatestUpdate,"mLatestUpdate") ; RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; } -void RsGxsReputationRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mLastUpdate,"mLastUpdate") ; } diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.h b/libretroshare/src/rsitems/rsgxsreputationitems.h index 1f30a5d65..7c841bd4e 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.h +++ b/libretroshare/src/rsitems/rsgxsreputationitems.h @@ -29,6 +29,9 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" #include "retroshare/rsgxsifacetypes.h" @@ -66,7 +69,7 @@ public: virtual ~RsGxsReputationConfigItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; RsPeerId mPeerId; uint32_t mLatestUpdate; // timestamp they returned. @@ -110,7 +113,7 @@ public: virtual ~RsGxsReputationSetItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; RsGxsId mGxsId; uint32_t mOwnOpinion; @@ -128,7 +131,7 @@ public: virtual ~RsGxsReputationBannedNodeSetItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; RsPgpId mPgpId ; uint32_t mLastActivityTS ; @@ -143,7 +146,7 @@ public: virtual ~RsGxsReputationUpdateItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; uint32_t mLatestUpdate; std::map mOpinions; // GxsId -> Opinion. @@ -157,7 +160,7 @@ public: virtual ~RsGxsReputationRequestItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; uint32_t mLastUpdate; }; diff --git a/libretroshare/src/rsitems/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc index eb50bf15e..38f2f0254 100644 --- a/libretroshare/src/rsitems/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -29,13 +29,15 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" +#include "serialization/rstypeserializer.h" + /*** #define RSSERIAL_DEBUG 1 ***/ #include -void RsHistoryMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { uint16_t version=0; diff --git a/libretroshare/src/rsitems/rshistoryitems.h b/libretroshare/src/rsitems/rshistoryitems.h index 27a387f60..56d12e559 100644 --- a/libretroshare/src/rsitems/rshistoryitems.h +++ b/libretroshare/src/rsitems/rshistoryitems.h @@ -42,7 +42,7 @@ public: virtual ~RsHistoryMsgItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPeerId chatPeerId; // empty for global chat bool incoming; diff --git a/libretroshare/src/rsitems/rsitem.h b/libretroshare/src/rsitems/rsitem.h new file mode 100644 index 000000000..f7f6dae54 --- /dev/null +++ b/libretroshare/src/rsitems/rsitem.h @@ -0,0 +1,90 @@ +#pragma once + +#include "util/smallobject.h" +#include "retroshare/rstypes.h" +#include "serialization/rsserializer.h" + +class RsItem: public RsMemoryManagement::SmallObject +{ + public: + RsItem(uint32_t t); + RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype); +#ifdef DO_STATISTICS + void *operator new(size_t s) ; + void operator delete(void *,size_t s) ; +#endif + + virtual ~RsItem(); + virtual void clear() = 0; + + virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0) + { + RsGenericSerializer::SerializeContext ctx(NULL,0,RsGenericSerializer::FORMAT_BINARY,RsGenericSerializer::SERIALIZATION_FLAG_NONE); + serial_process(RsGenericSerializer::PRINT,ctx) ; + return out; + } + + void print_string(std::string &out, uint16_t indent = 0); + + /* source / destination id */ + const RsPeerId& PeerId() const { return peerId; } + void PeerId(const RsPeerId& id) { peerId = id; } + + /* complete id */ + uint32_t PacketId() const; + + /* id parts */ + uint8_t PacketVersion(); + uint8_t PacketClass(); + uint8_t PacketType(); + uint8_t PacketSubType() const; + + /* For Service Packets */ + RsItem(uint8_t ver, uint16_t service, uint8_t subtype); + uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */ + void setPacketService(uint16_t service); + + inline uint8_t priority_level() const { return _priority_level ;} + inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} + + /** + * @brief serialize this object to the given buffer + * @param Job to do: serialise or deserialize. + * @param data Chunk of memory were to dump the serialized data + * @param size Size of memory chunk + * @param offset Readed to determine at witch offset start writing data, + * written to inform caller were written data ends, the updated value + * is usually passed by the caller to serialize of another + * RsSerializable so it can write on the same chunk of memory just + * after where this RsSerializable has been serialized. + * @return true if serialization successed, false otherwise + */ + + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) + { + std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! Class is " << typeid(*this).name() << std::endl; + } + + protected: + uint32_t type; + RsPeerId peerId; + uint8_t _priority_level ; +}; + +class RsRawItem: public RsItem +{ +public: + RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size) + { data = rs_malloc(len); } + virtual ~RsRawItem() { free(data); } + + uint32_t getRawLength() { return len; } + void * getRawData() { return data; } + + virtual void clear() {} + virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + +private: + void *data; + uint32_t len; +}; diff --git a/libretroshare/src/rsitems/rsmsgitems.cc b/libretroshare/src/rsitems/rsmsgitems.cc index 8fd2f2c55..20c98ad1b 100644 --- a/libretroshare/src/rsitems/rsmsgitems.cc +++ b/libretroshare/src/rsitems/rsmsgitems.cc @@ -80,25 +80,25 @@ void RsMsgItem::clear() attachment.TlvClear(); } -void RsPublicMsgInviteConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPublicMsgInviteConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ; RsTypeSerializer::serial_process(j,ctx,(uint32_t&)time_stamp,"time_stamp") ; } -void RsMsgTagType::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgTagType::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ; RsTypeSerializer::serial_process(j,ctx,rgb_color,"rgb_color") ; RsTypeSerializer::serial_process(j,ctx,tagId,"tagId") ; } -void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgTags::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; #warning this is not the correct way to serialise here. We should directly call serial_process >() but for backward compatibility, we cannot - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) while(ctx.mOffset < ctx.mSize) { uint32_t n ; @@ -110,13 +110,13 @@ void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,*it,"tagIds element") ; } -void RsMsgSrcId::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgSrcId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ; } -void RsMsgGRouterMap::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgGRouterMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ; } @@ -128,18 +128,18 @@ void RsMsgGRouterMap::clear() return; } -void RsMsgDistantMessagesHashMap::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgDistantMessagesHashMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ; } -void RsMsgParentId::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgParentId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process(j,ctx,msgParentId,"msgParentId") ; } -void RsMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgFlags,"msgFlags"); RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime"); diff --git a/libretroshare/src/rsitems/rsmsgitems.h b/libretroshare/src/rsitems/rsmsgitems.h index f0916352b..527c43fdf 100644 --- a/libretroshare/src/rsitems/rsmsgitems.h +++ b/libretroshare/src/rsitems/rsmsgitems.h @@ -101,7 +101,7 @@ class RsMsgItem: public RsMessageItem virtual ~RsMsgItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); // ----------- Specific fields ------------- // @@ -130,7 +130,7 @@ class RsMsgTagType : public RsMessageItem public: RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgTagType() {} virtual void clear(); @@ -148,7 +148,7 @@ public: RsMsgTags() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgTags() {} virtual void clear(); @@ -164,7 +164,7 @@ class RsMsgSrcId : public RsMessageItem public: RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgSrcId() {} virtual void clear(){} @@ -180,7 +180,7 @@ class RsPublicMsgInviteConfigItem : public RsMessageItem public: RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsPublicMsgInviteConfigItem() {} virtual void clear(); @@ -196,7 +196,7 @@ class RsMsgGRouterMap : public RsMessageItem public: RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgGRouterMap() {} virtual void clear(); @@ -210,7 +210,7 @@ class RsMsgDistantMessagesHashMap : public RsMessageItem public: RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgDistantMessagesHashMap() {} virtual void clear() { hash_map.clear() ;} @@ -224,7 +224,7 @@ class RsMsgParentId : public RsMessageItem public: RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgParentId() {} virtual void clear(){} @@ -239,7 +239,7 @@ class RsMsgSerialiser: public RsServiceSerializer { public: RsMsgSerialiser(SerializationFlags flags) - :RsServiceSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){} + :RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){} virtual ~RsMsgSerialiser() {} diff --git a/libretroshare/src/rsitems/rsrttitems.cc b/libretroshare/src/rsitems/rsrttitems.cc index ce2423dd4..2ab7292e5 100644 --- a/libretroshare/src/rsitems/rsrttitems.cc +++ b/libretroshare/src/rsitems/rsrttitems.cc @@ -32,6 +32,8 @@ #include +#include "serialization/rstypeserializer.h" + /*************************************************************************/ RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const @@ -48,13 +50,13 @@ RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const } } -void RsRttPingItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsRttPingItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; } -void RsRttPongItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; diff --git a/libretroshare/src/rsitems/rsrttitems.h b/libretroshare/src/rsitems/rsrttitems.h index b3e5bdec2..8f635c3b9 100644 --- a/libretroshare/src/rsitems/rsrttitems.h +++ b/libretroshare/src/rsitems/rsrttitems.h @@ -28,7 +28,9 @@ #include +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" #include "serialization/rsserializer.h" @@ -56,7 +58,7 @@ class RsRttPingItem: public RsRttItem virtual ~RsRttPingItem(){} virtual void clear(){} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; @@ -70,7 +72,7 @@ class RsRttPongItem: public RsRttItem virtual ~RsRttPongItem(){} virtual void clear(){} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; diff --git a/libretroshare/src/serialiser/rsgxsitems.h b/libretroshare/src/serialiser/rsgxsitems.h index ed6d3124d..74942d807 100644 --- a/libretroshare/src/serialiser/rsgxsitems.h +++ b/libretroshare/src/serialiser/rsgxsitems.h @@ -26,6 +26,7 @@ * */ +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.h b/libretroshare/src/serialiser/rsgxsrecognitems.h index 6d0ea0ae6..aab0e3974 100644 --- a/libretroshare/src/serialiser/rsgxsrecognitems.h +++ b/libretroshare/src/serialiser/rsgxsrecognitems.h @@ -28,7 +28,10 @@ #include +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvkeys.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/serialiser/rsheartbeatitems.h b/libretroshare/src/serialiser/rsheartbeatitems.h index 5660ba373..3a9e6e95f 100644 --- a/libretroshare/src/serialiser/rsheartbeatitems.h +++ b/libretroshare/src/serialiser/rsheartbeatitems.h @@ -30,6 +30,8 @@ #include "serialiser/rsserial.h" #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01; diff --git a/libretroshare/src/serialiser/rsnxsitems.h b/libretroshare/src/serialiser/rsnxsitems.h index 259c560a6..2f4886507 100644 --- a/libretroshare/src/serialiser/rsnxsitems.h +++ b/libretroshare/src/serialiser/rsnxsitems.h @@ -31,6 +31,7 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" diff --git a/libretroshare/src/serialiser/rsserial.cc b/libretroshare/src/serialiser/rsserial.cc index 30fed530e..1436f92fa 100644 --- a/libretroshare/src/serialiser/rsserial.cc +++ b/libretroshare/src/serialiser/rsserial.cc @@ -25,11 +25,14 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsserial.h" + #include "util/rsthreads.h" #include "util/rsstring.h" #include "util/rsprint.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include #include #include diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 511eec1c3..248c0a3bc 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -34,9 +34,6 @@ #include #include -#include "util/rsmemory.h" -#include "retroshare/rstypes.h" - /******************************************************************* * This is the Top-Level serialiser/deserialise, * @@ -59,9 +56,6 @@ * 8 bits: SubType ******************************************************************/ -#include -#include "rsitems/itempriorities.h" - const uint8_t RS_PKT_VERSION1 = 0x01; const uint8_t RS_PKT_VERSION_SERVICE = 0x02; @@ -70,74 +64,7 @@ const uint8_t RS_PKT_CLASS_CONFIG = 0x02; const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */ -class SerializeContext ; - -class RsItem: public RsMemoryManagement::SmallObject -{ - public: - RsItem(uint32_t t); - RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype); -#ifdef DO_STATISTICS - void *operator new(size_t s) ; - void operator delete(void *,size_t s) ; -#endif - - virtual ~RsItem(); - virtual void clear() = 0; - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) - { - std::cerr << "(EE) RsItem::print() called by an item using new serialization classes, but not derived! " << std::endl; -#warning This method should normally call serial_process(PRINT,ctx) - return out; - } - void print_string(std::string &out, uint16_t indent = 0); - - /* source / destination id */ - const RsPeerId& PeerId() const { return peerId; } - void PeerId(const RsPeerId& id) { peerId = id; } - - /* complete id */ - uint32_t PacketId() const; - - /* id parts */ - uint8_t PacketVersion(); - uint8_t PacketClass(); - uint8_t PacketType(); - uint8_t PacketSubType() const; - - /* For Service Packets */ - RsItem(uint8_t ver, uint16_t service, uint8_t subtype); - uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */ - void setPacketService(uint16_t service); - - inline uint8_t priority_level() const { return _priority_level ;} - inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} - - /** - * @brief serialize this object to the given buffer - * @param Job to do: serialise or deserialize. - * @param data Chunk of memory were to dump the serialized data - * @param size Size of memory chunk - * @param offset Readed to determine at witch offset start writing data, - * written to inform caller were written data ends, the updated value - * is usually passed by the caller to serialize of another - * RsSerializable so it can write on the same chunk of memory just - * after where this RsSerializable has been serialized. - * @return true if serialization successed, false otherwise - */ - typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ; - - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) - { - std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! " << std::endl; - } - - protected: - uint32_t type; - RsPeerId peerId; - uint8_t _priority_level ; -}; - +class RsItem ; class RsSerialType { @@ -201,23 +128,4 @@ std::ostream &printRsItemEnd(std::ostream &o, std::string n, uint16_t i); std::ostream &printIndent(std::ostream &out, uint16_t indent); /* Wrapper class for data that is serialised somewhere else */ -class RsRawItem: public RsItem -{ -public: - RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size) - { data = rs_malloc(len); } - virtual ~RsRawItem() { free(data); } - - uint32_t getRawLength() { return len; } - void * getRawData() { return data; } - - virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - -private: - void *data; - uint32_t len; -}; - - #endif /* RS_BASE_SERIALISER_H */ diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.h b/libretroshare/src/serialiser/rsserviceinfoitems.h index 76b451cce..b4c9beabe 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.h +++ b/libretroshare/src/serialiser/rsserviceinfoitems.h @@ -31,6 +31,9 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvgenericmap.h" diff --git a/libretroshare/src/serialiser/rsserviceserialiser.cc b/libretroshare/src/serialiser/rsserviceserialiser.cc index d99d03de1..0c953fec3 100644 --- a/libretroshare/src/serialiser/rsserviceserialiser.cc +++ b/libretroshare/src/serialiser/rsserviceserialiser.cc @@ -23,6 +23,7 @@ * */ +#include "rsitems/rsitem.h" #include "rsserviceserialiser.h" uint32_t RsServiceSerialiser::size(RsItem *i) diff --git a/libretroshare/src/serialiser/rsstatusitems.h b/libretroshare/src/serialiser/rsstatusitems.h index c6cc0c8b2..8ea99e04c 100644 --- a/libretroshare/src/serialiser/rsstatusitems.h +++ b/libretroshare/src/serialiser/rsstatusitems.h @@ -27,7 +27,8 @@ */ #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" +#include "rsitems/itempriorities.h" +#include "rsitems/rsitem.h" /**************************************************************************/ diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 3ab5770aa..f9619e839 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -1,5 +1,7 @@ #include +#include "rsitems/rsitem.h" + #include "util/rsprint.h" #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" @@ -31,7 +33,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) SerializeContext ctx(const_cast(static_cast(data)),*size,mFormat,mFlags); ctx.mOffset = 8 ; - item->serial_process(RsItem::DESERIALIZE, ctx) ; + item->serial_process(RsGenericSerializer::DESERIALIZE, ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -67,7 +69,7 @@ RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size) SerializeContext ctx(const_cast(static_cast(data)),*size,mFormat,mFlags); ctx.mOffset = 8 ; - item->serial_process(RsItem::DESERIALIZE, ctx) ; + item->serial_process(DESERIALIZE, ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -105,7 +107,7 @@ bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size) ctx.mSize = tlvsize; - item->serial_process(RsItem::SERIALIZE,ctx) ; + item->serial_process(RsGenericSerializer::SERIALIZE,ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -123,7 +125,7 @@ uint32_t RsGenericSerializer::size(RsItem *item) ctx.mOffset = 0; else ctx.mOffset = 8 ; // header size - item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; + item->serial_process(SIZE_ESTIMATE, ctx) ; return ctx.mOffset ; } @@ -133,7 +135,7 @@ void RsGenericSerializer::print(RsItem *item) SerializeContext ctx(NULL,0,mFormat,mFlags); std::cerr << "***** RsItem class: \"" << typeid(*item).name() << "\" *****" << std::endl; - item->serial_process(RsItem::PRINT, ctx) ; + item->serial_process(PRINT, ctx) ; std::cerr << "******************************" << std::endl; } diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 700b690f5..2bea8d23f 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -5,15 +5,34 @@ #include #include +#include "retroshare/rsflags.h" #include "serialiser/rsserial.h" -#include "serialization/rstypeserializer.h" + +class RsItem ; #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " class RsGenericSerializer: public RsSerialType { public: + typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ; + typedef enum { FORMAT_BINARY = 0x01, FORMAT_JSON = 0x02 } SerializationFormat ; + class SerializeContext + { + public: + + + SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags) + : mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {} + + unsigned char *mData ; + uint32_t mSize ; + uint32_t mOffset ; + bool mOk ; + SerializationFormat mFormat ; + SerializationFlags mFlags ; + }; // These are convenience flags to be used by the items when processing the data. The names of the flags // are not very important. What matters is that the serial_process() method of each item correctly @@ -36,18 +55,18 @@ public: protected: RsGenericSerializer(uint8_t serial_class, uint8_t serial_type, - SerializeContext::SerializationFormat format, + SerializationFormat format, SerializationFlags flags ) : RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags) {} RsGenericSerializer(uint16_t service, - SerializeContext::SerializationFormat format, + SerializationFormat format, SerializationFlags flags ) : RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags) {} - SerializeContext::SerializationFormat mFormat ; + SerializationFormat mFormat ; SerializationFlags mFlags ; }; @@ -56,8 +75,8 @@ class RsServiceSerializer: public RsGenericSerializer { public: RsServiceSerializer(uint16_t service_id, - SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, - SerializationFlags flags = SERIALIZATION_FLAG_NONE) + SerializationFormat format = FORMAT_BINARY, + SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsGenericSerializer(service_id,format,flags) {} @@ -74,8 +93,8 @@ class RsConfigSerializer: public RsGenericSerializer public: RsConfigSerializer(uint8_t config_class, uint8_t config_type, - SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, - SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE) + SerializationFormat format = FORMAT_BINARY, + SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsGenericSerializer(config_class,config_type,format,flags) {} diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 0693331b1..31da447f4 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -7,25 +7,7 @@ #include "retroshare/rsflags.h" #include "retroshare/rsids.h" -class SerializeContext -{ - public: - - enum SerializationFormat { - FORMAT_BINARY = 0x01 , - FORMAT_JSON = 0x02 - }; - - SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags) - : mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {} - - unsigned char *mData ; - uint32_t mSize ; - uint32_t mOffset ; - bool mOk ; - SerializationFormat mFormat ; - SerializationFlags mFlags ; -}; +#include "serialization/rsserializer.h" class RsTypeSerializer @@ -44,20 +26,20 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,T& member,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; break ; - case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; - case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: print_data(member_name,member); break; default: @@ -71,20 +53,20 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; break ; - case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; + case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; break ; - case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; + case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: print_data(member_name,type_id,member); break; default: @@ -97,11 +79,11 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::map& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::map& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: + case RsGenericSerializer::SIZE_ESTIMATE: { ctx.mOffset += 4 ; for(typename std::map::iterator it(v.begin());it!=v.end();++it) @@ -112,7 +94,7 @@ class RsTypeSerializer } break ; - case RsItem::DESERIALIZE: + case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; @@ -130,7 +112,7 @@ class RsTypeSerializer } break ; - case RsItem::SERIALIZE: + case RsGenericSerializer::SERIALIZE: { uint32_t n=v.size(); ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; @@ -143,12 +125,12 @@ class RsTypeSerializer } break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: { if(v.empty()) - std::cerr << " Empty map"<< std::endl; + std::cerr << " Empty map \"" << member_name << "\"" << std::endl; else - std::cerr << " std::map of " << v.size() << " elements:" << std::endl; + std::cerr << " std::map of " << v.size() << " elements: \"" << member_name << "\"" << std::endl; for(typename std::map::iterator it(v.begin());it!=v.end();++it) { @@ -169,11 +151,11 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::vector& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::vector& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: + case RsGenericSerializer::SIZE_ESTIMATE: { ctx.mOffset += 4 ; for(uint32_t i=0;i - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::list& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::list& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: + case RsGenericSerializer::SIZE_ESTIMATE: { ctx.mOffset += 4 ; for(typename std::list::iterator it(v.begin());it!=v.end();++it) @@ -235,7 +217,7 @@ class RsTypeSerializer } break ; - case RsItem::DESERIALIZE: + case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; serial_process(j,ctx,n,"temporary size") ; @@ -248,7 +230,7 @@ class RsTypeSerializer } break ; - case RsItem::SERIALIZE: + case RsGenericSerializer::SERIALIZE: { uint32_t n=v.size(); serial_process(j,ctx,n,"temporary size") ; @@ -257,7 +239,7 @@ class RsTypeSerializer } break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: { if(v.empty()) std::cerr << " Empty list"<< std::endl; @@ -275,14 +257,14 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,t_RsFlags32& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,t_RsFlags32& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mOffset += 4 ; + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += 4 ; break ; - case RsItem::DESERIALIZE: + case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; @@ -290,14 +272,14 @@ class RsTypeSerializer } break ; - case RsItem::SERIALIZE: + case RsGenericSerializer::SERIALIZE: { uint32_t n=v.toUInt32() ; serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; } break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl; break ; } diff --git a/libretroshare/src/services/p3service.cc b/libretroshare/src/services/p3service.cc index 469247905..bb15831d7 100644 --- a/libretroshare/src/services/p3service.cc +++ b/libretroshare/src/services/p3service.cc @@ -23,6 +23,8 @@ * */ +#include "rsitems/itempriorities.h" + #include "pqi/pqi.h" #include "util/rsstring.h" #include "services/p3service.h" diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index 4d5f1a2fa..2455c98e5 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -48,14 +48,14 @@ RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) c return NULL ; } -void RsTurtleStringSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleStringSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; } -void RsTurtleRegExpSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleRegExpSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process(j,ctx,depth,"depth") ; @@ -140,7 +140,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegul std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl; } -void RsTurtleSearchResultItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; @@ -193,7 +193,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleF std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl; } -void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ; RsTypeSerializer::serial_process(j,ctx,request_id ,"request_id") ; @@ -201,13 +201,13 @@ void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; } -void RsTurtleTunnelOkItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleTunnelOkItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; } -void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 9bc3fc4bf..8a8a1e49c 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -1,12 +1,16 @@ #pragma once +#include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rsbaseserial.h" + #include "retroshare/rsturtle.h" #include "retroshare/rsexpr.h" #include "retroshare/rstypes.h" -#include "rsitems/rsserviceids.h" #include "turtle/turtletypes.h" #include "serialization/rsserializer.h" @@ -58,7 +62,7 @@ class RsTurtleSearchResultItem: public RsTurtleItem void clear() { result.clear() ; } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; @@ -87,7 +91,7 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem void clear() { match_string.clear() ; } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem @@ -102,7 +106,7 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem void clear() { expr = RsRegularExpression::LinearizedExpression(); } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; /***********************************************************************************/ @@ -121,7 +125,7 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem void clear() { file_hash.clear() ;} protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleTunnelOkItem: public RsTurtleItem @@ -134,7 +138,7 @@ class RsTurtleTunnelOkItem: public RsTurtleItem void clear() {} protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; /***********************************************************************************/ @@ -198,7 +202,7 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem data_size = 0; } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; /***********************************************************************************/ From fb34fa19c02e417397f1b9984be3037eff02d091 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 13:44:09 +0200 Subject: [PATCH 052/106] switch GxsComment item to new serialization --- .../src/serialiser/rsgxscommentitems.cc | 32 +++++++++++++ .../src/serialiser/rsgxscommentitems.h | 46 ++++++------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/libretroshare/src/serialiser/rsgxscommentitems.cc b/libretroshare/src/serialiser/rsgxscommentitems.cc index 11832701e..4f655cc13 100644 --- a/libretroshare/src/serialiser/rsgxscommentitems.cc +++ b/libretroshare/src/serialiser/rsgxscommentitems.cc @@ -28,9 +28,25 @@ #include "rsgxscommentitems.h" #include "serialiser/rstlvbase.h" #include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" //#define GXSCOMMENT_DEBUG 1 +RsItem *RsGxsCommentSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const +{ + if(service_id != getRsItemService(PacketId())) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM: return new RsGxsCommentItem(getRsItemService(PacketId())) ; + case RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM: return new RsGxsVoteItem(getRsItemService(PacketId())); + default: + return NULL ; + } +} + +#ifdef TO_REMOVE uint32_t RsGxsCommentSerialiser::size(RsItem *item) { @@ -152,7 +168,15 @@ uint32_t RsGxsCommentSerialiser::sizeGxsCommentItem(RsGxsCommentItem *item) return s; } +#endif + +void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ; +} + +#ifdef TO_REMOVE bool RsGxsCommentSerialiser::serialiseGxsCommentItem(RsGxsCommentItem *item, void *data, uint32_t *size) { @@ -297,7 +321,14 @@ uint32_t RsGxsCommentSerialiser::sizeGxsVoteItem(RsGxsVoteItem */*item*/) return s; } +#endif +void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ; +} + +#ifdef TO_REMOVE bool RsGxsCommentSerialiser::serialiseGxsVoteItem(RsGxsVoteItem *item, void *data, uint32_t *size) { @@ -414,3 +445,4 @@ RsGxsVoteItem* RsGxsCommentSerialiser::deserialiseGxsVoteItem(void *data, uint32 /*****************************************************************************************/ /*****************************************************************************************/ +#endif diff --git a/libretroshare/src/serialiser/rsgxscommentitems.h b/libretroshare/src/serialiser/rsgxscommentitems.h index 2ccd6d5d8..37171ce94 100644 --- a/libretroshare/src/serialiser/rsgxscommentitems.h +++ b/libretroshare/src/serialiser/rsgxscommentitems.h @@ -43,54 +43,36 @@ class RsGxsCommentItem : public RsGxsMsgItem { public: - RsGxsCommentItem(uint16_t service_type): RsGxsMsgItem(service_type, - RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM) {return; } - virtual ~RsGxsCommentItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsCommentItem(uint16_t service_type): RsGxsMsgItem(service_type, RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM) {} + virtual ~RsGxsCommentItem() {} + void clear(){} + + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); RsGxsComment mMsg; }; - class RsGxsVoteItem : public RsGxsMsgItem { public: - RsGxsVoteItem(uint16_t service_type): RsGxsMsgItem(service_type, - RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM) {return; } - virtual ~RsGxsVoteItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsVoteItem(uint16_t service_type): RsGxsMsgItem(service_type, RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM) {} + virtual ~RsGxsVoteItem() {} + void clear(){} + + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); RsGxsVote mMsg; }; - -class RsGxsCommentSerialiser : public RsSerialType +class RsGxsCommentSerialiser : public RsServiceSerializer { public: - RsGxsCommentSerialiser(uint16_t service_type) - :RsSerialType(RS_PKT_VERSION_SERVICE, service_type) - { return; } - virtual ~RsGxsCommentSerialiser() { return; } - - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsCommentItem(RsGxsCommentItem *item); - bool serialiseGxsCommentItem (RsGxsCommentItem *item, void *data, uint32_t *size); - RsGxsCommentItem * deserialiseGxsCommentItem(void *data, uint32_t *size); - - - uint32_t sizeGxsVoteItem(RsGxsVoteItem *item); - bool serialiseGxsVoteItem (RsGxsVoteItem *item, void *data, uint32_t *size); - RsGxsVoteItem * deserialiseGxsVoteItem(void *data, uint32_t *size); + RsGxsCommentSerialiser(uint16_t service_type) :RsServiceSerializer(service_type) {} + virtual ~RsGxsCommentSerialiser() {} + RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; }; #endif /* RS_GXS_COMMENT_ITEMS_H */ From c0d8735251a3f2c25191bc461ed60f587c286818 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 14:17:38 +0200 Subject: [PATCH 053/106] switched RsGxsIdItems to new serialization --- libretroshare/src/serialiser/rsgxsiditems.cc | 70 ++++++++++++++----- libretroshare/src/serialiser/rsgxsiditems.h | 49 ++----------- .../src/serialization/rstypeserializer.h | 52 ++++++++++++++ 3 files changed, 110 insertions(+), 61 deletions(-) diff --git a/libretroshare/src/serialiser/rsgxsiditems.cc b/libretroshare/src/serialiser/rsgxsiditems.cc index f5019b7f4..2daa65a49 100644 --- a/libretroshare/src/serialiser/rsgxsiditems.cc +++ b/libretroshare/src/serialiser/rsgxsiditems.cc @@ -31,8 +31,36 @@ #include "serialiser/rstlvstring.h" #include "util/rsstring.h" +#include "serialization/rstypeserializer.h" + #define GXSID_DEBUG 1 +RsItem *RsGxsIdSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const +{ + if(service_id != RS_SERVICE_GXS_TYPE_GXSID) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM : return new RsGxsIdGroupItem (); + case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return new RsGxsIdLocalInfoItem() ; + default: + return NULL ; + } +} +void RsGxsIdLocalInfoItem::clear() +{ + mTimeStamps.clear() ; +} +void RsGxsIdGroupItem::clear() +{ + mPgpIdHash.clear(); + mPgpIdSign.clear(); + + mRecognTags.clear(); + mImage.TlvClear(); +} +#ifdef TO_REMOVE RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size) { /* get the type and size */ @@ -84,18 +112,8 @@ bool RsGxsIdItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsiz /*****************************************************************************************/ -void RsGxsIdLocalInfoItem::clear() -{ - mTimeStamps.clear() ; -} -void RsGxsIdGroupItem::clear() -{ - mPgpIdHash.clear(); - mPgpIdSign.clear(); - mRecognTags.clear(); - mImage.TlvClear(); -} + uint32_t RsGxsIdLocalInfoItem::serial_size() { uint32_t s = 8 ; // header @@ -160,8 +178,15 @@ uint32_t RsGxsIdGroupItem::serial_size() return s; } +#endif +void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ; + RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ; +} +#ifdef TO_REMOVE bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size) { uint32_t tlvsize,offset=0; @@ -199,7 +224,20 @@ bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size) return ok; } +#endif +void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_SIGN,mPgpIdSign,"mPgpIdSign") ; + + RsTlvStringSetRef rset(TLV_TYPE_RECOGNSET,mRecognTags) ; + + RsTypeSerializer::serial_process(j,ctx,rset,"mRecognTags") ; + RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; +} + +#ifdef TO_REMOVE bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size) { uint32_t tlvsize,offset=0; @@ -234,7 +272,7 @@ bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size) return ok; } - +#endif bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage) { @@ -275,6 +313,8 @@ bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage) } return true ; } + +#ifdef TO_REMOVE RsGxsIdGroupItem* RsGxsIdSerialiser::deserialise_GxsIdGroupItem(void *data, uint32_t *size) { /* get the type and size */ @@ -427,6 +467,7 @@ RsGxsIdLocalInfoItem *RsGxsIdSerialiser::deserialise_GxsIdLocalInfoItem(void *da return item; } +#endif /*****************************************************************************************/ @@ -692,8 +733,3 @@ RsGxsIdCommentItem* RsGxsIdSerialiser::deserialise_GxsIdCommentItem(void *data, } #endif - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - diff --git a/libretroshare/src/serialiser/rsgxsiditems.h b/libretroshare/src/serialiser/rsgxsiditems.h index 39ca6882a..19802a9a1 100644 --- a/libretroshare/src/serialiser/rsgxsiditems.h +++ b/libretroshare/src/serialiser/rsgxsiditems.h @@ -45,14 +45,6 @@ class RsGxsIdItem: public RsGxsGrpItem { public: RsGxsIdItem(uint8_t item_subtype) : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSID,item_subtype) {} - - virtual bool serialise(void *data,uint32_t& size) = 0 ; - virtual uint32_t serial_size() = 0 ; - - virtual void clear() = 0 ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0; - - bool serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) ; }; class RsGxsIdGroupItem : public RsGxsIdItem @@ -62,11 +54,8 @@ public: RsGxsIdGroupItem(): RsGxsIdItem(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) {} virtual ~RsGxsIdGroupItem() {} + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; bool fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage); bool toGxsIdGroup(RsGxsIdGroup &group, bool moveImage); @@ -91,10 +80,8 @@ public: virtual ~RsGxsIdLocalInfoItem() {} virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); std::map mTimeStamps ; std::set mContacts ; @@ -133,39 +120,13 @@ public: }; #endif -class RsGxsIdSerialiser : public RsSerialType +class RsGxsIdSerialiser : public RsServiceSerializer { public: - RsGxsIdSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_GXSID) {} + RsGxsIdSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_GXSID) {} virtual ~RsGxsIdSerialiser() {} - virtual uint32_t size (RsItem *item) - { - RsGxsIdItem *idItem = dynamic_cast(item); - if (!idItem) - { - return 0; - } - return idItem->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - RsGxsIdItem *idItem = dynamic_cast(item); - if (!idItem) - { - return false; - } - return idItem->serialise(data,*size) ; - } - virtual RsItem *deserialise (void *data, uint32_t *size) ; - -private: -#if 0 - static RsGxsIdOpinionItem *deserialise_GxsIdOpinionItem(void *data, uint32_t *size); - static RsGxsIdCommentItem *deserialise_GxsIdCommentItem(void *data, uint32_t *size); -#endif - static RsGxsIdGroupItem *deserialise_GxsIdGroupItem(void *data, uint32_t *size); - static RsGxsIdLocalInfoItem *deserialise_GxsIdLocalInfoItem(void *data, uint32_t *size); + virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; }; #endif /* RS_GXS_IDENTITY_ITEMS_H */ diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 31da447f4..5ff9f4944 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -199,6 +199,58 @@ class RsTypeSerializer break; } } + //=================================================================================================// + // std::set // + //=================================================================================================// + + template + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::set& v,const std::string& member_name) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + { + ctx.mOffset += 4 ; + for(typename std::set::iterator it(v.begin());it!=v.end();++it) + serial_process(j,ctx,const_cast(*it) ,member_name) ; + } + break ; + + case RsGenericSerializer::DESERIALIZE: + { uint32_t n=0 ; + serial_process(j,ctx,n,"temporary size") ; + + for(uint32_t i=0;i(j,ctx,tmp,member_name) ; + v.insert(tmp); + } + } + break ; + + case RsGenericSerializer::SERIALIZE: + { + uint32_t n=v.size(); + serial_process(j,ctx,n,"temporary size") ; + for(typename std::set::iterator it(v.begin());it!=v.end();++it) + serial_process(j,ctx,const_cast(*it) ,member_name) ; + } + break ; + + case RsGenericSerializer::PRINT: + { + if(v.empty()) + std::cerr << " Empty set"<< std::endl; + else + std::cerr << " Set of " << v.size() << " elements:" << std::endl; + } + break; + default: + break; + } + } + //=================================================================================================// // std::list // From 97d0df0737f522bf7511bb6b616b17efeae646ec Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 14:19:34 +0200 Subject: [PATCH 054/106] added comment about serialization hack --- libretroshare/src/serialization/rstypeserializer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 5ff9f4944..3da545df8 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -212,7 +212,7 @@ class RsTypeSerializer { ctx.mOffset += 4 ; for(typename std::set::iterator it(v.begin());it!=v.end();++it) - serial_process(j,ctx,const_cast(*it) ,member_name) ; + serial_process(j,ctx,const_cast(*it) ,member_name) ; // the const cast here is a hack to avoid serial_process to instantiate serialise(const T&) } break ; @@ -234,7 +234,7 @@ class RsTypeSerializer uint32_t n=v.size(); serial_process(j,ctx,n,"temporary size") ; for(typename std::set::iterator it(v.begin());it!=v.end();++it) - serial_process(j,ctx,const_cast(*it) ,member_name) ; + serial_process(j,ctx,const_cast(*it) ,member_name) ; // the const cast here is a hack to avoid serial_process to instantiate serialise(const T&) } break ; From 508a2e2864aaa6bcd848d7dc54d6016c947c6cfb Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 14:28:25 +0200 Subject: [PATCH 055/106] moved gxs comment and Id items to rsitems/ --- libretroshare/src/gxs/rsgds.h | 2 +- libretroshare/src/gxs/rsgxsdata.h | 25 +++++++++---------- libretroshare/src/libretroshare.pro | 12 ++++----- .../rsgxscommentitems.cc | 0 .../rsgxscommentitems.h | 0 .../{serialiser => rsitems}/rsgxsiditems.cc | 0 .../{serialiser => rsitems}/rsgxsiditems.h | 0 .../src/{serialiser => rsitems}/rsgxsitems.cc | 0 .../src/{serialiser => rsitems}/rsgxsitems.h | 0 .../src/serialiser/rsgxschannelitems.h | 8 +++--- .../src/serialiser/rsgxscircleitems.h | 4 +-- .../src/serialiser/rsgxsforumitems.h | 4 +-- libretroshare/src/serialiser/rsposteditems.h | 7 ++---- libretroshare/src/services/p3gxscommon.cc | 2 +- libretroshare/src/services/p3idservice.cc | 2 +- libretroshare/src/services/p3idservice.h | 2 +- libretroshare/src/services/p3postbase.cc | 2 +- 17 files changed, 31 insertions(+), 39 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsgxscommentitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxscommentitems.h (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxsiditems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxsiditems.h (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxsitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxsitems.h (100%) diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index c56b47c12..5a82337fe 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -32,7 +32,7 @@ #include "inttypes.h" -#include "serialiser/rsgxsitems.h" +#include "rsitems/rsgxsitems.h" #include "serialiser/rsnxsitems.h" #include "gxs/rsgxsdata.h" #include "rsgxs.h" diff --git a/libretroshare/src/gxs/rsgxsdata.h b/libretroshare/src/gxs/rsgxsdata.h index 21fbe1445..6e85193dc 100644 --- a/libretroshare/src/gxs/rsgxsdata.h +++ b/libretroshare/src/gxs/rsgxsdata.h @@ -29,10 +29,9 @@ #include #include - -#include "serialiser/rsserial.h" #include "serialiser/rstlvkeys.h" -#include "serialiser/rsgxsitems.h" + +#include "rsitems/rsgxsitems.h" class RsGroupMetaData; class RsMsgMetaData; @@ -56,22 +55,22 @@ public: void clear(); void operator =(const RsGroupMetaData& rMeta); - //Sort data in same order than serialiser and deserializer + //Sort data in same order than serialiser and deserializer RsGxsGroupId mGroupId; RsGxsGroupId mOrigGrpId; - RsGxsGroupId mParentGrpId; + RsGxsGroupId mParentGrpId; std::string mGroupName; uint32_t mGroupFlags; // GXS_SERV::FLAG_PRIVACY_RESTRICTED | GXS_SERV::FLAG_PRIVACY_PRIVATE | GXS_SERV::FLAG_PRIVACY_PUBLIC uint32_t mPublishTs; - uint32_t mCircleType; - uint32_t mAuthenFlags; + uint32_t mCircleType; + uint32_t mAuthenFlags; RsGxsId mAuthorId; - std::string mServiceString; + std::string mServiceString; RsGxsCircleId mCircleId; RsTlvKeySignatureSet signSet; RsTlvSecurityKeySet keys; - uint32_t mSignFlags; + uint32_t mSignFlags; // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. @@ -103,9 +102,9 @@ public: void clear(); void operator =(const RsMsgMetaData& rMeta); - static int refcount; - - //Sort data in same order than serialiser and deserializer + static int refcount; + + //Sort data in same order than serialiser and deserializer RsGxsGroupId mGroupId; RsGxsMessageId mMsgId; RsGxsMessageId mThreadId; @@ -121,7 +120,7 @@ public: // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. // normally READ / UNREAD flags. LOCAL Data. - std::string mServiceString; + std::string mServiceString; uint32_t mMsgStatus; uint32_t mMsgSize; time_t mChildTs; diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 287e6a4d7..aa2aecf9e 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -735,7 +735,7 @@ HEADERS += serialiser/rsnxsitems.h \ retroshare/rstokenservice.h \ gxs/rsgxsdataaccess.h \ retroshare/rsgxsservice.h \ - serialiser/rsgxsitems.h \ + rsitems/rsgxsitems.h \ util/retrodb.h \ util/rsdbbind.h \ gxs/rsgxsutil.h \ @@ -753,7 +753,7 @@ SOURCES += serialiser/rsnxsitems.cc \ gxs/rsgenexchange.cc \ gxs/rsgxsnetservice.cc \ gxs/rsgxsdata.cc \ - serialiser/rsgxsitems.cc \ + rsitems/rsgxsitems.cc \ gxs/rsgxsdataaccess.cc \ util/retrodb.cc \ util/contentvalue.cc \ @@ -783,12 +783,12 @@ SOURCES += serialization/rsserializer.cc \ HEADERS += retroshare/rsidentity.h \ gxs/rsgixs.h \ services/p3idservice.h \ - serialiser/rsgxsiditems.h \ + rsitems/rsgxsiditems.h \ services/p3gxsreputation.h \ rsitems/rsgxsreputationitems.h \ SOURCES += services/p3idservice.cc \ - serialiser/rsgxsiditems.cc \ + rsitems/rsgxsiditems.cc \ services/p3gxsreputation.cc \ rsitems/rsgxsreputationitems.cc \ @@ -812,12 +812,12 @@ SOURCES += services/p3gxsforums.cc \ HEADERS += retroshare/rsgxschannels.h \ services/p3gxschannels.h \ services/p3gxscommon.h \ - serialiser/rsgxscommentitems.h \ + rsitems/rsgxscommentitems.h \ serialiser/rsgxschannelitems.h \ SOURCES += services/p3gxschannels.cc \ services/p3gxscommon.cc \ - serialiser/rsgxscommentitems.cc \ + rsitems/rsgxscommentitems.cc \ serialiser/rsgxschannelitems.cc \ wikipoos { diff --git a/libretroshare/src/serialiser/rsgxscommentitems.cc b/libretroshare/src/rsitems/rsgxscommentitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsgxscommentitems.cc rename to libretroshare/src/rsitems/rsgxscommentitems.cc diff --git a/libretroshare/src/serialiser/rsgxscommentitems.h b/libretroshare/src/rsitems/rsgxscommentitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxscommentitems.h rename to libretroshare/src/rsitems/rsgxscommentitems.h diff --git a/libretroshare/src/serialiser/rsgxsiditems.cc b/libretroshare/src/rsitems/rsgxsiditems.cc similarity index 100% rename from libretroshare/src/serialiser/rsgxsiditems.cc rename to libretroshare/src/rsitems/rsgxsiditems.cc diff --git a/libretroshare/src/serialiser/rsgxsiditems.h b/libretroshare/src/rsitems/rsgxsiditems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxsiditems.h rename to libretroshare/src/rsitems/rsgxsiditems.h diff --git a/libretroshare/src/serialiser/rsgxsitems.cc b/libretroshare/src/rsitems/rsgxsitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsgxsitems.cc rename to libretroshare/src/rsitems/rsgxsitems.cc diff --git a/libretroshare/src/serialiser/rsgxsitems.h b/libretroshare/src/rsitems/rsgxsitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxsitems.h rename to libretroshare/src/rsitems/rsgxsitems.h diff --git a/libretroshare/src/serialiser/rsgxschannelitems.h b/libretroshare/src/serialiser/rsgxschannelitems.h index 9a937e581..51939d576 100644 --- a/libretroshare/src/serialiser/rsgxschannelitems.h +++ b/libretroshare/src/serialiser/rsgxschannelitems.h @@ -29,14 +29,12 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" +#include "rsitems/rsgxscommentitems.h" +#include "rsitems/rsgxsitems.h" + #include "serialiser/rstlvfileitem.h" #include "serialiser/rstlvimage.h" -#include "serialiser/rsgxscommentitems.h" - -#include "rsgxsitems.h" #include "retroshare/rsgxschannels.h" #include "util/rsdir.h" diff --git a/libretroshare/src/serialiser/rsgxscircleitems.h b/libretroshare/src/serialiser/rsgxscircleitems.h index 84316b133..ba28f2782 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.h +++ b/libretroshare/src/serialiser/rsgxscircleitems.h @@ -29,12 +29,12 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" + #include "serialiser/rstlvitem.h" #include "serialiser/rstlvstring.h" #include "serialiser/rstlvidset.h" -#include "rsgxsitems.h" +#include "rsitems/rsgxsitems.h" #include "retroshare/rsgxscircles.h" const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02; diff --git a/libretroshare/src/serialiser/rsgxsforumitems.h b/libretroshare/src/serialiser/rsgxsforumitems.h index 97f6dd89b..22fae7e63 100644 --- a/libretroshare/src/serialiser/rsgxsforumitems.h +++ b/libretroshare/src/serialiser/rsgxsforumitems.h @@ -29,10 +29,8 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" +#include "rsitems/rsgxsitems.h" -#include "rsgxsitems.h" #include "retroshare/rsgxsforums.h" const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02; diff --git a/libretroshare/src/serialiser/rsposteditems.h b/libretroshare/src/serialiser/rsposteditems.h index a303f0d33..e78dfafe1 100644 --- a/libretroshare/src/serialiser/rsposteditems.h +++ b/libretroshare/src/serialiser/rsposteditems.h @@ -2,12 +2,9 @@ #define RSPOSTEDITEMS_H #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" +#include "rsitems/rsgxscommentitems.h" +#include "rsitems/rsgxsitems.h" -#include "serialiser/rsgxscommentitems.h" - -#include "rsgxsitems.h" #include "retroshare/rsposted.h" const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02; diff --git a/libretroshare/src/services/p3gxscommon.cc b/libretroshare/src/services/p3gxscommon.cc index ad97f1eca..822c19cdf 100644 --- a/libretroshare/src/services/p3gxscommon.cc +++ b/libretroshare/src/services/p3gxscommon.cc @@ -25,7 +25,7 @@ #include "retroshare/rsgxscommon.h" #include "services/p3gxscommon.h" -#include "serialiser/rsgxscommentitems.h" +#include "rsitems/rsgxscommentitems.h" #include "util/rsstring.h" #include diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index c173dba8a..37c609373 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -27,7 +27,7 @@ #include "services/p3idservice.h" #include "pgp/pgpauxutils.h" -#include "serialiser/rsgxsiditems.h" +#include "rsitems/rsgxsiditems.h" #include "rsitems/rsconfigitems.h" #include "retroshare/rsgxsflags.h" #include "util/rsrandom.h" diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index addff0d1b..caf29ee73 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -32,7 +32,7 @@ #include "gxs/rsgixs.h" // Internal Interfaces. #include "gxs/gxstokenqueue.h" -#include "serialiser/rsgxsiditems.h" +#include "rsitems/rsgxsiditems.h" #include #include diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index cb3c43fc1..077104db0 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -30,7 +30,7 @@ #include #include "services/p3postbase.h" -#include "serialiser/rsgxscommentitems.h" +#include "rsitems/rsgxscommentitems.h" #include "rsserver/p3face.h" #include "retroshare/rsnotify.h" From c31396a010883c4d98a80bcabf37e1536e48e534 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 14:31:15 +0200 Subject: [PATCH 056/106] moved dsdv code to unused directory --- libretroshare/src/libretroshare.pro | 14 +++++++------- libretroshare/src/{services => unused}/p3dsdv.cc | 0 libretroshare/src/{services => unused}/p3dsdv.h | 0 libretroshare/src/{retroshare => unused}/rsdsdv.h | 0 .../src/{serialiser => unused}/rsdsdvitems.cc | 0 .../src/{serialiser => unused}/rsdsdvitems.h | 0 6 files changed, 7 insertions(+), 7 deletions(-) rename libretroshare/src/{services => unused}/p3dsdv.cc (100%) rename libretroshare/src/{services => unused}/p3dsdv.h (100%) rename libretroshare/src/{retroshare => unused}/rsdsdv.h (100%) rename libretroshare/src/{serialiser => unused}/rsdsdvitems.cc (100%) rename libretroshare/src/{serialiser => unused}/rsdsdvitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index aa2aecf9e..781228027 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -61,14 +61,14 @@ file_lists { dsdv { DEFINES *= SERVICES_DSDV -HEADERS += services/p3dsdv.h \ - serialiser/rstlvdsdv.h \ - serialiser/rsdsdvitems.h \ - retroshare/rsdsdv.h +HEADERS += unused/p3dsdv.h \ + unused/rstlvdsdv.h \ + unused/rsdsdvitems.h \ + unused/rsdsdv.h -SOURCES *= serialiser/rstlvdsdv.cc \ - serialiser/rsdsdvitems.cc \ - services/p3dsdv.cc +SOURCES *= unused/rstlvdsdv.cc \ + unused/rsdsdvitems.cc \ + unused/p3dsdv.cc } bitdht { diff --git a/libretroshare/src/services/p3dsdv.cc b/libretroshare/src/unused/p3dsdv.cc similarity index 100% rename from libretroshare/src/services/p3dsdv.cc rename to libretroshare/src/unused/p3dsdv.cc diff --git a/libretroshare/src/services/p3dsdv.h b/libretroshare/src/unused/p3dsdv.h similarity index 100% rename from libretroshare/src/services/p3dsdv.h rename to libretroshare/src/unused/p3dsdv.h diff --git a/libretroshare/src/retroshare/rsdsdv.h b/libretroshare/src/unused/rsdsdv.h similarity index 100% rename from libretroshare/src/retroshare/rsdsdv.h rename to libretroshare/src/unused/rsdsdv.h diff --git a/libretroshare/src/serialiser/rsdsdvitems.cc b/libretroshare/src/unused/rsdsdvitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsdsdvitems.cc rename to libretroshare/src/unused/rsdsdvitems.cc diff --git a/libretroshare/src/serialiser/rsdsdvitems.h b/libretroshare/src/unused/rsdsdvitems.h similarity index 100% rename from libretroshare/src/serialiser/rsdsdvitems.h rename to libretroshare/src/unused/rsdsdvitems.h From 8f97647246ec30080436a8c8fb8d30743dd97895 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 15:43:00 +0200 Subject: [PATCH 057/106] fixed bug in RsGxsId deserialization --- libretroshare/src/gxs/rsgenexchange.cc | 3 ++- libretroshare/src/rsitems/rsgxsiditems.cc | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index a334f7e3d..c59da85de 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1323,7 +1323,8 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector 0) - std::cerr << "(EE) RsGenExchange::getGroupData() Item type is probably not handled. Data is: " << RsUtil::BinToHex((unsigned char*)data.bin_data,std::min(50u,data.bin_len)) << ((data.bin_len>50)?"...":"") << std::endl; + //std::cerr << "(EE) RsGenExchange::getGroupData() Item type is probably not handled. Data is: " << RsUtil::BinToHex((unsigned char*)data.bin_data,std::min(50u,data.bin_len)) << ((data.bin_len>50)?"...":"") << std::endl; + std::cerr << "(EE) RsGenExchange::getGroupData() Item type is probably not handled. Data is: " << RsUtil::BinToHex((unsigned char*)data.bin_data,data.bin_len) << std::endl; delete *lit; } diff --git a/libretroshare/src/rsitems/rsgxsiditems.cc b/libretroshare/src/rsitems/rsgxsiditems.cc index 2daa65a49..cb5ed324e 100644 --- a/libretroshare/src/rsitems/rsgxsiditems.cc +++ b/libretroshare/src/rsitems/rsgxsiditems.cc @@ -234,6 +234,12 @@ void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene RsTlvStringSetRef rset(TLV_TYPE_RECOGNSET,mRecognTags) ; RsTypeSerializer::serial_process(j,ctx,rset,"mRecognTags") ; + + // image is optional + + if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize) + return ; + RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; } From 77c2e6da8c80d1f762264bc86a753c5f897b4a64 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 18:14:10 +0200 Subject: [PATCH 058/106] improved error handlign in pqistore --- libretroshare/src/pqi/pqistore.cc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index 23201541a..7372529b1 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -310,24 +310,25 @@ int pqistore::readPkt(RsItem **item_out) } // workout how much more to read. - int extralen = getRsItemSize(block) - blen; - int totallen = extralen+blen; - - // make sure that totallen is not a crazy number. If so, we drop the entire stream that might be corrupted. - - if(totallen > 1024*1024) + int blocklength = getRsItemSize(block); + + // make sure that blocklength is not a crazy number. If so, we drop the entire stream that might be corrupted. + + if(blocklength < blen || blocklength > 1024*1024*10) { - std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << totallen <<", which exceeds the allowed limit (1MB)" << std::endl ; + std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << blocklength <<", which is either too small, or exceeds the safety limit (10 MB)" << std::endl ; free(block) ; bStopReading=true; return 0 ; } - void *tmp = realloc(block, totallen); + int extralen = blocklength - blen; + + void *tmp = realloc(block, blocklength); if (tmp == NULL) { free(block); - std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << totallen << std::endl ; + std::cerr << "pqistore: ERROR: trying to realloc memory for packet of length" << blocklength << std::endl ; std::cerr << "Have you got enought memory?" << std::endl ; bStopReading=true; return 0 ; @@ -522,17 +523,18 @@ int pqiSSLstore::readPkt(RsItem **item_out) } // workout how much more to read. - int extralen = getRsItemSize(block) - blen; - int totallen = extralen+blen; + int blocklength = getRsItemSize(block); - if(totallen > 1024*1024 || totallen 1024*1024*10) { free(block); - std::cerr << "pqiSSLstore: ERROR: trying to realloc memory for packet of length" << totallen << ", that exceeds the limit of 1MB" << std::endl ; + std::cerr << "pqiSSLstore: ERROR: block length has invalid value " << blocklength << " (either too small, or exceeds the safety limit of 10 MB)" << std::endl ; bStopReading=true; return 0 ; } - void *tmp = realloc(block, totallen); + int extralen = blocklength - blen; + + void *tmp = realloc(block, blocklength); if (tmp == NULL) { From 69729ad7d2f6c9f049221627953fdd780f0fa1b9 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 18:55:23 +0200 Subject: [PATCH 059/106] switch Channel items to new serialization --- libretroshare/src/rsitems/rsgxscommentitems.h | 2 +- .../src/serialiser/rsgxschannelitems.cc | 78 ++++++++++++++----- .../src/serialiser/rsgxschannelitems.h | 46 ++++------- 3 files changed, 74 insertions(+), 52 deletions(-) diff --git a/libretroshare/src/rsitems/rsgxscommentitems.h b/libretroshare/src/rsitems/rsgxscommentitems.h index 37171ce94..dcb89e2de 100644 --- a/libretroshare/src/rsitems/rsgxscommentitems.h +++ b/libretroshare/src/rsitems/rsgxscommentitems.h @@ -72,7 +72,7 @@ public: RsGxsCommentSerialiser(uint16_t service_type) :RsServiceSerializer(service_type) {} virtual ~RsGxsCommentSerialiser() {} - RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; + virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; }; #endif /* RS_GXS_COMMENT_ITEMS_H */ diff --git a/libretroshare/src/serialiser/rsgxschannelitems.cc b/libretroshare/src/serialiser/rsgxschannelitems.cc index bad8a0a98..f540fffd7 100644 --- a/libretroshare/src/serialiser/rsgxschannelitems.cc +++ b/libretroshare/src/serialiser/rsgxschannelitems.cc @@ -29,9 +29,25 @@ #include "serialiser/rstlvbase.h" #include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" + //#define GXSCHANNEL_DEBUG 1 +RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const +{ + if(service_id != RS_SERVICE_GXS_TYPE_CHANNELS) + return NULL ; + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM: return new RsGxsChannelGroupItem() ; + case RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM: return new RsGxsChannelPostItem(); + default: + return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ; + } +} + +#ifdef TO_REMOVE uint32_t RsGxsChannelSerialiser::size(RsItem *item) { #ifdef GXSCHANNEL_DEBUG @@ -113,19 +129,6 @@ RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size) return NULL; } - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsChannelGroupItem::clear() -{ - mDescription.clear(); - mImage.TlvClear(); -} - std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsChannelGroupItem", indent); @@ -141,6 +144,19 @@ std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent) return out; } +#endif + +/*****************************************************************************************/ +/*****************************************************************************************/ +/*****************************************************************************************/ + + +void RsGxsChannelGroupItem::clear() +{ + mDescription.clear(); + mImage.TlvClear(); +} + bool RsGxsChannelGroupItem::fromChannelGroup(RsGxsChannelGroup &group, bool moveImage) @@ -181,6 +197,7 @@ bool RsGxsChannelGroupItem::toChannelGroup(RsGxsChannelGroup &group, bool moveIm return true; } +#ifdef TO_REMOVE uint32_t RsGxsChannelSerialiser::sizeGxsChannelGroupItem(RsGxsChannelGroupItem *item) { @@ -191,7 +208,15 @@ uint32_t RsGxsChannelSerialiser::sizeGxsChannelGroupItem(RsGxsChannelGroupItem * return s; } +#endif +void RsGxsChannelGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DESCR,mDescription,"mDescription") ; + RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; +} + +#ifdef TO_REMOVE bool RsGxsChannelSerialiser::serialiseGxsChannelGroupItem(RsGxsChannelGroupItem *item, void *data, uint32_t *size) { @@ -312,14 +337,6 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo /*****************************************************************************************/ /*****************************************************************************************/ - -void RsGxsChannelPostItem::clear() -{ - mMsg.clear(); - mAttachment.TlvClear(); - mThumbnail.TlvClear(); -} - std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsChannelPostItem", indent); @@ -337,6 +354,7 @@ std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent) printRsItemEnd(out ,"RsGxsChannelPostItem", indent); return out; } +#endif bool RsGxsChannelPostItem::fromChannelPost(RsGxsChannelPost &post, bool moveImage) @@ -402,6 +420,14 @@ bool RsGxsChannelPostItem::toChannelPost(RsGxsChannelPost &post, bool moveImage) return true; } +void RsGxsChannelPostItem::clear() +{ + mMsg.clear(); + mAttachment.TlvClear(); + mThumbnail.TlvClear(); +} + +#ifdef TO_REMOVE uint32_t RsGxsChannelSerialiser::sizeGxsChannelPostItem(RsGxsChannelPostItem *item) { @@ -413,7 +439,16 @@ uint32_t RsGxsChannelSerialiser::sizeGxsChannelPostItem(RsGxsChannelPostItem *it return s; } +#endif +void RsGxsChannelPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,mMsg,"mMsg") ; + RsTypeSerializer::serial_process(j,ctx,mAttachment,"mAttachment") ; + RsTypeSerializer::serial_process(j,ctx,mThumbnail,"mThumbnail") ; +} + +#ifdef TO_REMOVE bool RsGxsChannelSerialiser::serialiseGxsChannelPostItem(RsGxsChannelPostItem *item, void *data, uint32_t *size) { @@ -533,4 +568,5 @@ RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ +#endif diff --git a/libretroshare/src/serialiser/rsgxschannelitems.h b/libretroshare/src/serialiser/rsgxschannelitems.h index 51939d576..b4caf5197 100644 --- a/libretroshare/src/serialiser/rsgxschannelitems.h +++ b/libretroshare/src/serialiser/rsgxschannelitems.h @@ -37,22 +37,23 @@ #include "retroshare/rsgxschannels.h" +#include "serialization/rsserializer.h" + #include "util/rsdir.h" const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM = 0x02; -const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03; +const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03; class RsGxsChannelGroupItem : public RsGxsGrpItem { - public: - RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_CHANNELS, - RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM) { return;} - virtual ~RsGxsChannelGroupItem() { return;} + RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_CHANNELS, RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM) {} + virtual ~RsGxsChannelGroupItem() {} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // use conversion functions to transform: bool fromChannelGroup(RsGxsChannelGroup &group, bool moveImage); @@ -66,11 +67,11 @@ class RsGxsChannelPostItem : public RsGxsMsgItem { public: - RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_CHANNELS, - RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM) {return; } - virtual ~RsGxsChannelPostItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_CHANNELS, RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM) {} + virtual ~RsGxsChannelPostItem() {} + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // Slightly unusual structure. // use conversion functions to transform: @@ -87,25 +88,10 @@ class RsGxsChannelSerialiser : public RsGxsCommentSerialiser { public: - RsGxsChannelSerialiser() - :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_CHANNELS) - { return; } - virtual ~RsGxsChannelSerialiser() { return; } - - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsChannelGroupItem(RsGxsChannelGroupItem *item); - bool serialiseGxsChannelGroupItem (RsGxsChannelGroupItem *item, void *data, uint32_t *size); - RsGxsChannelGroupItem * deserialiseGxsChannelGroupItem(void *data, uint32_t *size); - - uint32_t sizeGxsChannelPostItem(RsGxsChannelPostItem *item); - bool serialiseGxsChannelPostItem (RsGxsChannelPostItem *item, void *data, uint32_t *size); - RsGxsChannelPostItem * deserialiseGxsChannelPostItem(void *data, uint32_t *size); + RsGxsChannelSerialiser() :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_CHANNELS) {} + virtual ~RsGxsChannelSerialiser() {} + virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; }; #endif /* RS_GXS_CHANNEL_ITEMS_H */ From db645239cbb9c90733c4a95f89c44fe18a354378 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 20:15:54 +0200 Subject: [PATCH 060/106] moved rsgxschannel items to rsitems --- libretroshare/src/libretroshare.pro | 4 +- .../src/rsitems/rsgxschannelitems.cc | 173 ++++++ .../rsgxschannelitems.h | 0 libretroshare/src/rsitems/rsgxscommentitems.h | 3 +- libretroshare/src/rsitems/rsgxsitems.h | 4 +- .../src/serialiser/rsgxschannelitems.cc | 572 ------------------ 6 files changed, 177 insertions(+), 579 deletions(-) create mode 100644 libretroshare/src/rsitems/rsgxschannelitems.cc rename libretroshare/src/{serialiser => rsitems}/rsgxschannelitems.h (100%) delete mode 100644 libretroshare/src/serialiser/rsgxschannelitems.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 781228027..d13df8213 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -813,12 +813,12 @@ HEADERS += retroshare/rsgxschannels.h \ services/p3gxschannels.h \ services/p3gxscommon.h \ rsitems/rsgxscommentitems.h \ - serialiser/rsgxschannelitems.h \ + rsitems/rsgxschannelitems.h \ SOURCES += services/p3gxschannels.cc \ services/p3gxscommon.cc \ rsitems/rsgxscommentitems.cc \ - serialiser/rsgxschannelitems.cc \ + rsitems/rsgxschannelitems.cc \ wikipoos { # Wiki Service diff --git a/libretroshare/src/rsitems/rsgxschannelitems.cc b/libretroshare/src/rsitems/rsgxschannelitems.cc new file mode 100644 index 000000000..789357b4c --- /dev/null +++ b/libretroshare/src/rsitems/rsgxschannelitems.cc @@ -0,0 +1,173 @@ +/* + * libretroshare/src/serialiser: rsgxschannelitems.cc + * + * RetroShare C++ Interface. + * + * Copyright 2012-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 + +#include "rsgxschannelitems.h" +#include "serialiser/rstlvbase.h" +#include "serialiser/rsbaseserial.h" + +#include "serialization/rstypeserializer.h" + +RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const +{ + if(service_id != RS_SERVICE_GXS_TYPE_CHANNELS) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM: return new RsGxsChannelGroupItem() ; + case RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM: return new RsGxsChannelPostItem(); + default: + return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ; + } +} + +void RsGxsChannelGroupItem::clear() +{ + mDescription.clear(); + mImage.TlvClear(); +} + +bool RsGxsChannelGroupItem::fromChannelGroup(RsGxsChannelGroup &group, bool moveImage) +{ + clear(); + meta = group.mMeta; + mDescription = group.mDescription; + + if (moveImage) + { + mImage.binData.bin_data = group.mImage.mData; + mImage.binData.bin_len = group.mImage.mSize; + group.mImage.shallowClear(); + } + else + { + mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize); + } + return true; +} + + + +bool RsGxsChannelGroupItem::toChannelGroup(RsGxsChannelGroup &group, bool moveImage) +{ + group.mMeta = meta; + group.mDescription = mDescription; + if (moveImage) + { + group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len); + // mImage doesn't have a ShallowClear at the moment! + mImage.binData.TlvShallowClear(); + } + else + { + group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len); + } + return true; +} + +void RsGxsChannelGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DESCR,mDescription,"mDescription") ; + RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; +} + +bool RsGxsChannelPostItem::fromChannelPost(RsGxsChannelPost &post, bool moveImage) +{ + clear(); + meta = post.mMeta; + mMsg = post.mMsg; + + if (moveImage) + { + mThumbnail.binData.bin_data = post.mThumbnail.mData; + mThumbnail.binData.bin_len = post.mThumbnail.mSize; + post.mThumbnail.shallowClear(); + } + else + { + mThumbnail.binData.setBinData(post.mThumbnail.mData, post.mThumbnail.mSize); + } + + std::list::iterator fit; + for(fit = post.mFiles.begin(); fit != post.mFiles.end(); ++fit) + { + RsTlvFileItem fi; + fi.name = fit->mName; + fi.filesize = fit->mSize; + fi.hash = fit->mHash; + mAttachment.items.push_back(fi); + } + return true; +} + + + +bool RsGxsChannelPostItem::toChannelPost(RsGxsChannelPost &post, bool moveImage) +{ + post.mMeta = meta; + post.mMsg = mMsg; + if (moveImage) + { + post.mThumbnail.take((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len); + // mThumbnail doesn't have a ShallowClear at the moment! + mThumbnail.binData.TlvShallowClear(); + } + else + { + post.mThumbnail.copy((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len); + } + + post.mCount = 0; + post.mSize = 0; + std::list::iterator fit; + for(fit = mAttachment.items.begin(); fit != mAttachment.items.end(); ++fit) + { + RsGxsFile fi; + fi.mName = RsDirUtil::getTopDir(fit->name); + fi.mSize = fit->filesize; + fi.mHash = fit->hash; + + post.mFiles.push_back(fi); + post.mCount++; + post.mSize += fi.mSize; + } + return true; +} + +void RsGxsChannelPostItem::clear() +{ + mMsg.clear(); + mAttachment.TlvClear(); + mThumbnail.TlvClear(); +} + +void RsGxsChannelPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,mMsg,"mMsg") ; + RsTypeSerializer::serial_process(j,ctx,mAttachment,"mAttachment") ; + RsTypeSerializer::serial_process(j,ctx,mThumbnail,"mThumbnail") ; +} diff --git a/libretroshare/src/serialiser/rsgxschannelitems.h b/libretroshare/src/rsitems/rsgxschannelitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxschannelitems.h rename to libretroshare/src/rsitems/rsgxschannelitems.h diff --git a/libretroshare/src/rsitems/rsgxscommentitems.h b/libretroshare/src/rsitems/rsgxscommentitems.h index dcb89e2de..ec5d6ae2c 100644 --- a/libretroshare/src/rsitems/rsgxscommentitems.h +++ b/libretroshare/src/rsitems/rsgxscommentitems.h @@ -29,8 +29,6 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" #include "rsgxsitems.h" @@ -52,6 +50,7 @@ public: RsGxsComment mMsg; }; + class RsGxsVoteItem : public RsGxsMsgItem { public: diff --git a/libretroshare/src/rsitems/rsgxsitems.h b/libretroshare/src/rsitems/rsgxsitems.h index 74942d807..026cbca08 100644 --- a/libretroshare/src/rsitems/rsgxsitems.h +++ b/libretroshare/src/rsitems/rsgxsitems.h @@ -28,9 +28,7 @@ #include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" -//#include "serialiser/rstlvkeys.h" + #include "retroshare/rsgxsifacetypes.h" std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta); diff --git a/libretroshare/src/serialiser/rsgxschannelitems.cc b/libretroshare/src/serialiser/rsgxschannelitems.cc deleted file mode 100644 index f540fffd7..000000000 --- a/libretroshare/src/serialiser/rsgxschannelitems.cc +++ /dev/null @@ -1,572 +0,0 @@ -/* - * libretroshare/src/serialiser: rsgxschannelitems.cc - * - * RetroShare C++ Interface. - * - * Copyright 2012-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 - -#include "rsgxschannelitems.h" -#include "serialiser/rstlvbase.h" -#include "serialiser/rsbaseserial.h" - -#include "serialization/rstypeserializer.h" - -//#define GXSCHANNEL_DEBUG 1 - -RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const -{ - if(service_id != RS_SERVICE_GXS_TYPE_CHANNELS) - return NULL ; - - switch(item_subtype) - { - case RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM: return new RsGxsChannelGroupItem() ; - case RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM: return new RsGxsChannelPostItem(); - default: - return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ; - } -} - -#ifdef TO_REMOVE -uint32_t RsGxsChannelSerialiser::size(RsItem *item) -{ -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::size()" << std::endl; -#endif - - RsGxsChannelGroupItem* grp_item = NULL; - RsGxsChannelPostItem* op_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsChannelGroupItem(grp_item); - } - else if((op_item = dynamic_cast(item)) != NULL) - { - return sizeGxsChannelPostItem(op_item); - } - else - { - return RsGxsCommentSerialiser::size(item); - } - return 0; -} - -bool RsGxsChannelSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialise()" << std::endl; -#endif - - RsGxsChannelGroupItem* grp_item = NULL; - RsGxsChannelPostItem* op_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsChannelGroupItem(grp_item, data, size); - } - else if((op_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsChannelPostItem(op_item, data, size); - } - else - { - return RsGxsCommentSerialiser::serialise(item, data, size); - } -} - -RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_CHANNELS != getRsItemService(rstype))) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialise() ERROR Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM: - return deserialiseGxsChannelGroupItem(data, size); - break; - case RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM: - return deserialiseGxsChannelPostItem(data, size); - break; - default: - return RsGxsCommentSerialiser::deserialise(data, size); - break; - } - return NULL; -} - -std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsChannelGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << mDescription << std::endl; - - out << "Image: " << std::endl; - mImage.print(out, int_Indent); - - printRsItemEnd(out ,"RsGxsChannelGroupItem", indent); - return out; -} - -#endif - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsChannelGroupItem::clear() -{ - mDescription.clear(); - mImage.TlvClear(); -} - - - -bool RsGxsChannelGroupItem::fromChannelGroup(RsGxsChannelGroup &group, bool moveImage) -{ - clear(); - meta = group.mMeta; - mDescription = group.mDescription; - - if (moveImage) - { - mImage.binData.bin_data = group.mImage.mData; - mImage.binData.bin_len = group.mImage.mSize; - group.mImage.shallowClear(); - } - else - { - mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize); - } - return true; -} - - - -bool RsGxsChannelGroupItem::toChannelGroup(RsGxsChannelGroup &group, bool moveImage) -{ - group.mMeta = meta; - group.mDescription = mDescription; - if (moveImage) - { - group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len); - // mImage doesn't have a ShallowClear at the moment! - mImage.binData.TlvShallowClear(); - } - else - { - group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len); - } - return true; -} - -#ifdef TO_REMOVE - -uint32_t RsGxsChannelSerialiser::sizeGxsChannelGroupItem(RsGxsChannelGroupItem *item) -{ - uint32_t s = 8; // header - - s += GetTlvStringSize(item->mDescription); - s += item->mImage.TlvSize(); - - return s; -} -#endif - -void RsGxsChannelGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DESCR,mDescription,"mDescription") ; - RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; -} - -#ifdef TO_REMOVE -bool RsGxsChannelSerialiser::serialiseGxsChannelGroupItem(RsGxsChannelGroupItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsChannelGroupItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem() Size too small" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsChannelGroupItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->mDescription); - item->mImage.SetTlv(data, tlvsize, &offset); - - if(offset != tlvsize) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSCHANNEL_DEBUG - if (!ok) - { - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(void *data, uint32_t *size) -{ - -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_CHANNELS != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsChannelGroupItem* item = new RsGxsChannelGroupItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->mDescription); - item->mImage.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsChannelPostItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Msg: " << mMsg << std::endl; - - out << "Attachment: " << std::endl; - mAttachment.print(out, int_Indent); - - out << "Thumbnail: " << std::endl; - mThumbnail.print(out, int_Indent); - - printRsItemEnd(out ,"RsGxsChannelPostItem", indent); - return out; -} -#endif - - -bool RsGxsChannelPostItem::fromChannelPost(RsGxsChannelPost &post, bool moveImage) -{ - clear(); - meta = post.mMeta; - mMsg = post.mMsg; - - if (moveImage) - { - mThumbnail.binData.bin_data = post.mThumbnail.mData; - mThumbnail.binData.bin_len = post.mThumbnail.mSize; - post.mThumbnail.shallowClear(); - } - else - { - mThumbnail.binData.setBinData(post.mThumbnail.mData, post.mThumbnail.mSize); - } - - std::list::iterator fit; - for(fit = post.mFiles.begin(); fit != post.mFiles.end(); ++fit) - { - RsTlvFileItem fi; - fi.name = fit->mName; - fi.filesize = fit->mSize; - fi.hash = fit->mHash; - mAttachment.items.push_back(fi); - } - return true; -} - - - -bool RsGxsChannelPostItem::toChannelPost(RsGxsChannelPost &post, bool moveImage) -{ - post.mMeta = meta; - post.mMsg = mMsg; - if (moveImage) - { - post.mThumbnail.take((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len); - // mThumbnail doesn't have a ShallowClear at the moment! - mThumbnail.binData.TlvShallowClear(); - } - else - { - post.mThumbnail.copy((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len); - } - - post.mCount = 0; - post.mSize = 0; - std::list::iterator fit; - for(fit = mAttachment.items.begin(); fit != mAttachment.items.end(); ++fit) - { - RsGxsFile fi; - fi.mName = RsDirUtil::getTopDir(fit->name); - fi.mSize = fit->filesize; - fi.mHash = fit->hash; - - post.mFiles.push_back(fi); - post.mCount++; - post.mSize += fi.mSize; - } - return true; -} - -void RsGxsChannelPostItem::clear() -{ - mMsg.clear(); - mAttachment.TlvClear(); - mThumbnail.TlvClear(); -} - -#ifdef TO_REMOVE - -uint32_t RsGxsChannelSerialiser::sizeGxsChannelPostItem(RsGxsChannelPostItem *item) -{ - uint32_t s = 8; // header - - s += GetTlvStringSize(item->mMsg); // mMsg. - s += item->mAttachment.TlvSize(); - s += item->mThumbnail.TlvSize(); - - return s; -} -#endif - -void RsGxsChannelPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,mMsg,"mMsg") ; - RsTypeSerializer::serial_process(j,ctx,mAttachment,"mAttachment") ; - RsTypeSerializer::serial_process(j,ctx,mThumbnail,"mThumbnail") ; -} - -#ifdef TO_REMOVE -bool RsGxsChannelSerialiser::serialiseGxsChannelPostItem(RsGxsChannelPostItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelPostItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsChannelPostItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelPostItem() ERROR space too small" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsChannelPostItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->mMsg); - item->mAttachment.SetTlv(data, tlvsize, &offset); - item->mThumbnail.SetTlv(data, tlvsize, &offset); - - if(offset != tlvsize) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelPostItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSCHANNEL_DEBUG - if (!ok) - { - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void *data, uint32_t *size) -{ - -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelPostItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_CHANNELS != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelPostItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelPostItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsChannelPostItem* item = new RsGxsChannelPostItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->mMsg); - item->mAttachment.GetTlv(data, rssize, &offset); - item->mThumbnail.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelPostItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSCHANNEL_DEBUG - std::cerr << "RsGxsChannelSerialiser::deserialiseGxsChannelPostItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ -#endif - From 559137d05b534070b0dfbaee42fedef26d5acc28 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 20:57:28 +0200 Subject: [PATCH 061/106] switched gxscircleitems to new serialization --- libretroshare/src/rsitems/rsgxsitems.h | 1 - .../src/serialiser/rsgxscircleitems.cc | 164 +++++++++++------- .../src/serialiser/rsgxscircleitems.h | 59 ++----- libretroshare/src/services/p3gxschannels.cc | 2 +- 4 files changed, 118 insertions(+), 108 deletions(-) diff --git a/libretroshare/src/rsitems/rsgxsitems.h b/libretroshare/src/rsitems/rsgxsitems.h index 026cbca08..3e7bd814c 100644 --- a/libretroshare/src/rsitems/rsgxsitems.h +++ b/libretroshare/src/rsitems/rsgxsitems.h @@ -34,7 +34,6 @@ std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta); std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta); - class RsGxsGrpItem : public RsItem { diff --git a/libretroshare/src/serialiser/rsgxscircleitems.cc b/libretroshare/src/serialiser/rsgxscircleitems.cc index c9cce891e..ae3dc6d69 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.cc +++ b/libretroshare/src/serialiser/rsgxscircleitems.cc @@ -26,11 +26,104 @@ #include #include "rsgxscircleitems.h" -#include "serialiser/rstlvbase.h" -#include "serialiser/rsbaseserial.h" + +#include "serialization/rstypeserializer.h" //#define CIRCLE_DEBUG 1 +RsItem *RsGxsCircleSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_GXS_TYPE_GXSCIRCLE) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM: return new RsGxsCircleGroupItem(); + case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM: return new RsGxsCircleMsgItem(); + case RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM: return new RsGxsCircleSubscriptionRequestItem(); + default: + return NULL ; + } +} + +void RsGxsCircleSubscriptionRequestItem::clear() +{ + time_stamp = 0 ; + time_out = 0 ; + subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN; +} + +void RsGxsCircleMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,msg.stuff,"msg.stuff") ; +} + +void RsGxsCircleSubscriptionRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,time_stamp,"time_stamp") ; + RsTypeSerializer::serial_process(j,ctx,time_out ,"time_out") ; + RsTypeSerializer::serial_process (j,ctx,subscription_type ,"subscription_type") ; +} + +void RsGxsCircleGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,pgpIdSet,"pgpIdSet") ; + RsTypeSerializer::serial_process(j,ctx,gxsIdSet,"gxsIdSet") ; + RsTypeSerializer::serial_process(j,ctx,subCircleSet,"subCircleSet") ; +} + +void RsGxsCircleMsgItem::clear() +{ + msg.stuff.clear(); +} + +void RsGxsCircleGroupItem::clear() +{ + pgpIdSet.TlvClear(); + gxsIdSet.TlvClear(); + subCircleSet.TlvClear(); +} + +bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group) +{ + clear(); + + meta = group.mMeta; + + // Enforce the local rules. + if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) + { + pgpIdSet.ids = group.mLocalFriends; + } + else + { + gxsIdSet.ids = group.mInvitedMembers; + } + + subCircleSet.ids = group.mSubCircles; + return true; +} + +bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const +{ + group.mMeta = meta; + + // Enforce the local rules. + if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) + { + group.mLocalFriends = pgpIdSet.ids; + } + else + { + group.mInvitedMembers = gxsIdSet.ids; + } + + group.mSubCircles = subCircleSet.ids; + return true; +} + + +#ifdef TO_REMOVE uint32_t RsGxsCircleSerialiser::size(RsItem *item) { RsGxsCircleGroupItem* grp_item = NULL; @@ -115,14 +208,6 @@ RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size) /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ - -void RsGxsCircleSubscriptionRequestItem::clear() -{ - time_stamp = 0 ; - time_out = 0 ; - subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN; -} - std::ostream& RsGxsCircleSubscriptionRequestItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsCircleSubscriptionRequestItem", indent); @@ -135,51 +220,6 @@ std::ostream& RsGxsCircleSubscriptionRequestItem::print(std::ostream& out, uint1 return out; } -void RsGxsCircleGroupItem::clear() -{ - pgpIdSet.TlvClear(); - gxsIdSet.TlvClear(); - subCircleSet.TlvClear(); -} - -bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group) -{ - clear(); - - meta = group.mMeta; - - // Enforce the local rules. - if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) - { - pgpIdSet.ids = group.mLocalFriends; - } - else - { - gxsIdSet.ids = group.mInvitedMembers; - } - - subCircleSet.ids = group.mSubCircles; - return true; -} - -bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const -{ - group.mMeta = meta; - - // Enforce the local rules. - if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) - { - group.mLocalFriends = pgpIdSet.ids; - } - else - { - group.mInvitedMembers = gxsIdSet.ids; - } - - group.mSubCircles = subCircleSet.ids; - return true; -} - std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent) { @@ -275,7 +315,6 @@ bool RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem(RsGxsCircl return ok; } - bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size) { @@ -324,8 +363,7 @@ bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *it #endif return ok; - } - +} RsGxsCircleSubscriptionRequestItem *RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem(void *data, uint32_t *size) { @@ -463,13 +501,6 @@ RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ - - -void RsGxsCircleMsgItem::clear() -{ - msg.stuff.clear(); -} - std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsCircleMsgItem", indent); @@ -494,6 +525,7 @@ uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item) return s; } + bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size) { @@ -610,4 +642,4 @@ RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *dat /*****************************************************************************************/ /*****************************************************************************************/ /*****************************************************************************************/ - +#endif diff --git a/libretroshare/src/serialiser/rsgxscircleitems.h b/libretroshare/src/serialiser/rsgxscircleitems.h index ba28f2782..5734b34cd 100644 --- a/libretroshare/src/serialiser/rsgxscircleitems.h +++ b/libretroshare/src/serialiser/rsgxscircleitems.h @@ -52,18 +52,12 @@ class RsGxsCircleGroupItem : public RsGxsGrpItem public: - RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, - RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) -#if 0 - pgpIdSet(GXSCIRCLE_PGPIDSET), - gxsIdSet(GXSCIRCLE_GXSIDSET), - subCircleSet(GXSCIRCLE_SUBCIRCLESET) -#endif - { return;} - virtual ~RsGxsCircleGroupItem() { return;} + RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) {} + virtual ~RsGxsCircleGroupItem() {} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); bool convertFrom(const RsGxsCircleGroup &group); bool convertTo(RsGxsCircleGroup &group) const; @@ -78,11 +72,12 @@ class RsGxsCircleMsgItem : public RsGxsMsgItem { public: - RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, - RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; } - virtual ~RsGxsCircleMsgItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSCIRCLE, RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {} + virtual ~RsGxsCircleMsgItem() {} + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsGxsCircleMsg msg; }; @@ -94,7 +89,6 @@ public: virtual ~RsGxsCircleSubscriptionRequestItem() {} void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); enum { SUBSCRIPTION_REQUEST_UNKNOWN = 0x00, @@ -102,37 +96,22 @@ public: SUBSCRIPTION_REQUEST_UNSUBSCRIBE = 0x02 }; - time_t time_stamp ; - time_t time_out ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + + uint32_t time_stamp ; + uint32_t time_out ; uint8_t subscription_type ; }; -class RsGxsCircleSerialiser : public RsSerialType +class RsGxsCircleSerialiser : public RsServiceSerializer { public: RsGxsCircleSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_GXSCIRCLE) - { return; } - virtual ~RsGxsCircleSerialiser() { return; } + :RsServiceSerializer(RS_SERVICE_GXS_TYPE_GXSCIRCLE) {} + virtual ~RsGxsCircleSerialiser() {} - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsCircleSubscriptionRequestItem(RsGxsCircleSubscriptionRequestItem *item); - bool serialiseGxsCircleSubscriptionRequestItem (RsGxsCircleSubscriptionRequestItem *item, void *data, uint32_t *size); - RsGxsCircleSubscriptionRequestItem * deserialiseGxsCircleSubscriptionRequestItem(void *data, uint32_t *size); - - uint32_t sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item); - bool serialiseGxsCircleGroupItem (RsGxsCircleGroupItem *item, void *data, uint32_t *size); - RsGxsCircleGroupItem * deserialiseGxsCircleGroupItem(void *data, uint32_t *size); - - uint32_t sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item); - bool serialiseGxsCircleMsgItem (RsGxsCircleMsgItem *item, void *data, uint32_t *size); - RsGxsCircleMsgItem * deserialiseGxsCircleMsgItem(void *data, uint32_t *size); + virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const; }; #endif /* RS_GXSCIRCLE_ITEMS_H */ diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 6410bd396..6805bb0ab 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -24,7 +24,7 @@ */ #include "services/p3gxschannels.h" -#include "serialiser/rsgxschannelitems.h" +#include "rsitems/rsgxschannelitems.h" #include "util/radix64.h" #include "util/rsmemory.h" From f50670f77376e93357c7a3a139e0ceed89d5a83e Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 20:59:59 +0200 Subject: [PATCH 062/106] moved circle items to rsitems/ --- libretroshare/src/libretroshare.pro | 4 +- libretroshare/src/rsitems/rsgxscircleitems.cc | 124 ++++ .../rsgxscircleitems.h | 0 .../src/serialiser/rsgxscircleitems.cc | 645 ------------------ libretroshare/src/services/p3gxscircles.cc | 3 +- 5 files changed, 128 insertions(+), 648 deletions(-) create mode 100644 libretroshare/src/rsitems/rsgxscircleitems.cc rename libretroshare/src/{serialiser => rsitems}/rsgxscircleitems.h (100%) delete mode 100644 libretroshare/src/serialiser/rsgxscircleitems.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index d13df8213..43a0eb6dd 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -794,11 +794,11 @@ SOURCES += services/p3idservice.cc \ # GxsCircles Service HEADERS += services/p3gxscircles.h \ - serialiser/rsgxscircleitems.h \ + rsitems/rsgxscircleitems.h \ retroshare/rsgxscircles.h \ SOURCES += services/p3gxscircles.cc \ - serialiser/rsgxscircleitems.cc \ + rsitems/rsgxscircleitems.cc \ # GxsForums Service HEADERS += retroshare/rsgxsforums.h \ diff --git a/libretroshare/src/rsitems/rsgxscircleitems.cc b/libretroshare/src/rsitems/rsgxscircleitems.cc new file mode 100644 index 000000000..a5937b5ab --- /dev/null +++ b/libretroshare/src/rsitems/rsgxscircleitems.cc @@ -0,0 +1,124 @@ +/* + * libretroshare/src/serialiser: rswikiitems.cc + * + * RetroShare C++ Interface. + * + * Copyright 2012-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 + +#include "rsgxscircleitems.h" + +#include "serialization/rstypeserializer.h" + +//#define CIRCLE_DEBUG 1 + +RsItem *RsGxsCircleSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_GXS_TYPE_GXSCIRCLE) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM: return new RsGxsCircleGroupItem(); + case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM: return new RsGxsCircleMsgItem(); + case RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM: return new RsGxsCircleSubscriptionRequestItem(); + default: + return NULL ; + } +} + +void RsGxsCircleSubscriptionRequestItem::clear() +{ + time_stamp = 0 ; + time_out = 0 ; + subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN; +} + +void RsGxsCircleMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,msg.stuff,"msg.stuff") ; +} + +void RsGxsCircleSubscriptionRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,time_stamp,"time_stamp") ; + RsTypeSerializer::serial_process(j,ctx,time_out ,"time_out") ; + RsTypeSerializer::serial_process (j,ctx,subscription_type ,"subscription_type") ; +} + +void RsGxsCircleGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,pgpIdSet,"pgpIdSet") ; + RsTypeSerializer::serial_process(j,ctx,gxsIdSet,"gxsIdSet") ; + RsTypeSerializer::serial_process(j,ctx,subCircleSet,"subCircleSet") ; +} + +void RsGxsCircleMsgItem::clear() +{ + msg.stuff.clear(); +} + +void RsGxsCircleGroupItem::clear() +{ + pgpIdSet.TlvClear(); + gxsIdSet.TlvClear(); + subCircleSet.TlvClear(); +} + +bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group) +{ + clear(); + + meta = group.mMeta; + + // Enforce the local rules. + if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) + { + pgpIdSet.ids = group.mLocalFriends; + } + else + { + gxsIdSet.ids = group.mInvitedMembers; + } + + subCircleSet.ids = group.mSubCircles; + return true; +} + +bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const +{ + group.mMeta = meta; + + // Enforce the local rules. + if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) + { + group.mLocalFriends = pgpIdSet.ids; + } + else + { + group.mInvitedMembers = gxsIdSet.ids; + } + + group.mSubCircles = subCircleSet.ids; + return true; +} + diff --git a/libretroshare/src/serialiser/rsgxscircleitems.h b/libretroshare/src/rsitems/rsgxscircleitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxscircleitems.h rename to libretroshare/src/rsitems/rsgxscircleitems.h diff --git a/libretroshare/src/serialiser/rsgxscircleitems.cc b/libretroshare/src/serialiser/rsgxscircleitems.cc deleted file mode 100644 index ae3dc6d69..000000000 --- a/libretroshare/src/serialiser/rsgxscircleitems.cc +++ /dev/null @@ -1,645 +0,0 @@ -/* - * libretroshare/src/serialiser: rswikiitems.cc - * - * RetroShare C++ Interface. - * - * Copyright 2012-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 - -#include "rsgxscircleitems.h" - -#include "serialization/rstypeserializer.h" - -//#define CIRCLE_DEBUG 1 - -RsItem *RsGxsCircleSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const -{ - if(service != RS_SERVICE_GXS_TYPE_GXSCIRCLE) - return NULL ; - - switch(item_sub_id) - { - case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM: return new RsGxsCircleGroupItem(); - case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM: return new RsGxsCircleMsgItem(); - case RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM: return new RsGxsCircleSubscriptionRequestItem(); - default: - return NULL ; - } -} - -void RsGxsCircleSubscriptionRequestItem::clear() -{ - time_stamp = 0 ; - time_out = 0 ; - subscription_type = SUBSCRIPTION_REQUEST_UNKNOWN; -} - -void RsGxsCircleMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,msg.stuff,"msg.stuff") ; -} - -void RsGxsCircleSubscriptionRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,time_stamp,"time_stamp") ; - RsTypeSerializer::serial_process(j,ctx,time_out ,"time_out") ; - RsTypeSerializer::serial_process (j,ctx,subscription_type ,"subscription_type") ; -} - -void RsGxsCircleGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,pgpIdSet,"pgpIdSet") ; - RsTypeSerializer::serial_process(j,ctx,gxsIdSet,"gxsIdSet") ; - RsTypeSerializer::serial_process(j,ctx,subCircleSet,"subCircleSet") ; -} - -void RsGxsCircleMsgItem::clear() -{ - msg.stuff.clear(); -} - -void RsGxsCircleGroupItem::clear() -{ - pgpIdSet.TlvClear(); - gxsIdSet.TlvClear(); - subCircleSet.TlvClear(); -} - -bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group) -{ - clear(); - - meta = group.mMeta; - - // Enforce the local rules. - if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) - { - pgpIdSet.ids = group.mLocalFriends; - } - else - { - gxsIdSet.ids = group.mInvitedMembers; - } - - subCircleSet.ids = group.mSubCircles; - return true; -} - -bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const -{ - group.mMeta = meta; - - // Enforce the local rules. - if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) - { - group.mLocalFriends = pgpIdSet.ids; - } - else - { - group.mInvitedMembers = gxsIdSet.ids; - } - - group.mSubCircles = subCircleSet.ids; - return true; -} - - -#ifdef TO_REMOVE -uint32_t RsGxsCircleSerialiser::size(RsItem *item) -{ - RsGxsCircleGroupItem* grp_item = NULL; - RsGxsCircleMsgItem* snap_item = NULL; - RsGxsCircleSubscriptionRequestItem* subr_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsCircleGroupItem(grp_item); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return sizeGxsCircleMsgItem(snap_item); - } - else if((subr_item = dynamic_cast(item)) != NULL) - { - return sizeGxsCircleSubscriptionRequestItem(subr_item); - } - else - return 0 ; -} - -bool RsGxsCircleSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsGxsCircleGroupItem* grp_item = NULL; - RsGxsCircleMsgItem* snap_item = NULL; - RsGxsCircleSubscriptionRequestItem* subr_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsCircleGroupItem(grp_item, data, size); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsCircleMsgItem(snap_item, data, size); - } - else if((subr_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsCircleSubscriptionRequestItem(subr_item, data, size); - } - return false; -} - -RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM: - return deserialiseGxsCircleGroupItem(data, size); - break; - case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM: - return deserialiseGxsCircleMsgItem(data, size); - break; - case RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM: - return deserialiseGxsCircleSubscriptionRequestItem(data, size); - break; - default: -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ -std::ostream& RsGxsCircleSubscriptionRequestItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsCircleSubscriptionRequestItem", indent); - - printRsItemBase(out, "time stmp: ", indent); out << time_stamp ; - printRsItemBase(out, "time out : ", indent); out << time_out ; - printRsItemBase(out, "Subs type: ", indent); out << subscription_type ; - - printRsItemEnd(out ,"RsGxsCircleSubscriptionRequestItem", indent); - return out; -} - - -std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsCircleGroupItem", indent); - uint16_t int_Indent = indent + 2; - - if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL) - { - printRsItemBase(out, "Local Circle: PGP Ids:", indent); - pgpIdSet.print(out, int_Indent); - printRsItemBase(out, "GXS Ids (should be empty):", indent); - gxsIdSet.print(out, int_Indent); - } - else - { - printRsItemBase(out, "External Circle: GXS Ids", indent); - gxsIdSet.print(out, int_Indent); - printRsItemBase(out, "PGP Ids (should be empty):", indent); - pgpIdSet.print(out, int_Indent); - } - - subCircleSet.print(out, int_Indent); - printRsItemEnd(out ,"RsGxsCircleGroupItem", indent); - return out; -} - -uint32_t RsGxsCircleSerialiser::sizeGxsCircleSubscriptionRequestItem(RsGxsCircleSubscriptionRequestItem * /* item */) -{ - uint32_t s=8 ; // header - - s += 4 ; // time_stamp serialised as uint32_t; - s += 4 ; // time_out serialised as uint32_t; - s += 1 ; // subscription_type ; - - return s ; -} - -uint32_t RsGxsCircleSerialiser::sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item) -{ - uint32_t s = 8; // header - - s += item->pgpIdSet.TlvSize(); - s += item->gxsIdSet.TlvSize(); - s += item->subCircleSet.TlvSize(); - - return s; -} - -bool RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem(RsGxsCircleSubscriptionRequestItem *item, void *data, uint32_t *size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsCircleSubscriptionRequestItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsCircleGroupItem */ - ok &= setRawUInt32(data,tlvsize,&offset,item->time_stamp) ; - ok &= setRawUInt32(data,tlvsize,&offset,item->time_out) ; - ok &= setRawUInt8(data,tlvsize,&offset,item->subscription_type) ; - - if(offset != tlvsize) - { - //#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem() FAIL Size Error! " << std::endl; - //#endif - ok = false; - } - - //#ifdef CIRCLE_DEBUG - if (!ok) - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleSubscriptionRequestItem() NOK" << std::endl; - //#endif - - return ok; -} -bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsCircleGroupItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsCircleGroupItem */ - ok &= item->pgpIdSet.SetTlv(data, tlvsize, &offset); - ok &= item->gxsIdSet.SetTlv(data, tlvsize, &offset); - ok &= item->subCircleSet.SetTlv(data, tlvsize, &offset); - - if(offset != tlvsize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef CIRCLE_DEBUG - if (!ok) - { - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() NOK" << std::endl; - } -#endif - - return ok; -} -RsGxsCircleSubscriptionRequestItem *RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem(void *data, uint32_t *size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCIRCLE_SUBSCRIPTION_REQUEST_ITEM != getRsItemSubType(rstype))) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsCircleSubscriptionRequestItem* item = new RsGxsCircleSubscriptionRequestItem(); - /* skip the header */ - offset += 8; - - uint32_t tmp ; - ok &= getRawUInt32(data,rssize,&offset,&tmp) ; item->time_stamp = tmp ; - ok &= getRawUInt32(data,rssize,&offset,&tmp) ; item->time_out = tmp ; - ok &= getRawUInt8(data,rssize,&offset,&item->subscription_type) ; - - if (offset != rssize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleSubscriptionRequestItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void *data, uint32_t *size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsCircleGroupItem* item = new RsGxsCircleGroupItem(); - /* skip the header */ - offset += 8; - - ok &= item->pgpIdSet.GetTlv(data, rssize, &offset); - ok &= item->gxsIdSet.GetTlv(data, rssize, &offset); - ok &= item->subCircleSet.GetTlv(data, rssize, &offset); - - if (offset != rssize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ -std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsCircleMsgItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Stuff: " << msg.stuff << std::endl; - - printRsItemEnd(out ,"RsGxsCircleMsgItem", indent); - return out; -} - - -uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item) -{ - - const RsGxsCircleMsg &msg = item->msg; - uint32_t s = 8; // header - - s += GetTlvStringSize(msg.stuff); - - return s; -} - - -bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsCircleMsgItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsCircleMsgItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->msg.stuff); - - if(offset != tlvsize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef CIRCLE_DEBUG - if (!ok) - { - std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *data, uint32_t *size) -{ - -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSCIRCLE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype))) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsCircleMsgItem* item = new RsGxsCircleMsgItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->msg.stuff); - - if (offset != rssize) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef CIRCLE_DEBUG - std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ -#endif diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index cf731fcd8..0daa3d24e 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -23,8 +23,9 @@ * */ +#include "rsitems/rsgxscircleitems.h" + #include "services/p3gxscircles.h" -#include "serialiser/rsgxscircleitems.h" #include "retroshare/rsgxsflags.h" #include "util/rsrandom.h" #include "util/rsdir.h" From 449a4209d9b97b37fae4e3c5f7cedb432c2f5b0e Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 11:56:56 +0200 Subject: [PATCH 063/106] dwitched gxsforum items to new serialization --- libretroshare/src/rsitems/rsgxsitems.h | 1 - .../src/serialiser/rsgxsforumitems.cc | 366 +----------------- .../src/serialiser/rsgxsforumitems.h | 48 +-- 3 files changed, 32 insertions(+), 383 deletions(-) diff --git a/libretroshare/src/rsitems/rsgxsitems.h b/libretroshare/src/rsitems/rsgxsitems.h index 3e7bd814c..fa461a0e8 100644 --- a/libretroshare/src/rsitems/rsgxsitems.h +++ b/libretroshare/src/rsitems/rsgxsitems.h @@ -43,7 +43,6 @@ public: : RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; } virtual ~RsGxsGrpItem(){} - RsGroupMetaData meta; }; diff --git a/libretroshare/src/serialiser/rsgxsforumitems.cc b/libretroshare/src/serialiser/rsgxsforumitems.cc index 731584b38..462f4fcf6 100644 --- a/libretroshare/src/serialiser/rsgxsforumitems.cc +++ b/libretroshare/src/serialiser/rsgxsforumitems.cc @@ -26,376 +26,42 @@ #include #include "rsgxsforumitems.h" -#include "serialiser/rstlvbase.h" -#include "serialiser/rsbaseserial.h" + +#include "serialization/rstypeserializer.h" //#define GXSFORUM_DEBUG 1 -uint32_t RsGxsForumSerialiser::size(RsItem *item) +RsItem *RsGxsForumSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const { - RsGxsForumGroupItem* grp_item = NULL; - RsGxsForumMsgItem* op_item = NULL; + if(service_id != RS_SERVICE_GXS_TYPE_FORUMS) + return NULL ; - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsForumGroupItem(grp_item); - } - else if((op_item = dynamic_cast(item)) != NULL) - { - return sizeGxsForumMsgItem(op_item); - } - std::cerr << "RsGxsForumSerialiser::size() ERROR invalid item" << std::endl; - return 0; + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM: return new RsGxsForumGroupItem(); + case RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM: return new RsGxsForumMsgItem(); + default: + return NULL ; + } } - -bool RsGxsForumSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsGxsForumGroupItem* grp_item = NULL; - RsGxsForumMsgItem* op_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsForumGroupItem(grp_item, data, size); - } - else if((op_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsForumMsgItem(op_item, data, size); - } - std::cerr << "RsGxsForumSerialiser::serialise() ERROR invalid item" << std::endl; - return false; -} - -RsItem* RsGxsForumSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_FORUMS != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM: - return deserialiseGxsForumGroupItem(data, size); - break; - case RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM: - return deserialiseGxsForumMsgItem(data, size); - break; - default: -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - void RsGxsForumGroupItem::clear() { mGroup.mDescription.clear(); } -std::ostream& RsGxsForumGroupItem::print(std::ostream& out, uint16_t indent) +void RsGxsForumGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - printRsItemBase(out, "RsGxsForumGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << mGroup.mDescription << std::endl; - - printRsItemEnd(out ,"RsGxsForumGroupItem", indent); - return out; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,mGroup.mDescription,"mGroup.Description"); } - - -uint32_t RsGxsForumSerialiser::sizeGxsForumGroupItem(RsGxsForumGroupItem *item) -{ - - const RsGxsForumGroup& group = item->mGroup; - uint32_t s = 8; // header - - s += GetTlvStringSize(group.mDescription); - - return s; -} - -bool RsGxsForumSerialiser::serialiseGxsForumGroupItem(RsGxsForumGroupItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsForumGroupItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() Size too small" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsForumGroupItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->mGroup.mDescription); - - if(offset != tlvsize) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSFORUM_DEBUG - if (!ok) - { - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsForumGroupItem* RsGxsForumSerialiser::deserialiseGxsForumGroupItem(void *data, uint32_t *size) -{ - -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_FORUMS != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsForumGroupItem* item = new RsGxsForumGroupItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->mGroup.mDescription); - - if (offset != rssize) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - void RsGxsForumMsgItem::clear() { mMsg.mMsg.clear(); } -std::ostream& RsGxsForumMsgItem::print(std::ostream& out, uint16_t indent) +void RsGxsForumMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - printRsItemBase(out, "RsGxsForumMsgItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Msg: " << mMsg.mMsg << std::endl; - - printRsItemEnd(out ,"RsGxsForumMsgItem", indent); - return out; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,mMsg.mMsg,"mGroup.Description"); } -uint32_t RsGxsForumSerialiser::sizeGxsForumMsgItem(RsGxsForumMsgItem *item) -{ - - const RsGxsForumMsg& msg = item->mMsg; - uint32_t s = 8; // header - - s += GetTlvStringSize(msg.mMsg); // mMsg. - - return s; -} - -bool RsGxsForumSerialiser::serialiseGxsForumMsgItem(RsGxsForumMsgItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsForumMsgItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsForumMsgItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->mMsg.mMsg); - - if(offset != tlvsize) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumMsgItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSFORUM_DEBUG - if (!ok) - { - std::cerr << "RsGxsForumSerialiser::serialiseGxsForumGroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsForumMsgItem* RsGxsForumSerialiser::deserialiseGxsForumMsgItem(void *data, uint32_t *size) -{ - -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_FORUMS != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsForumMsgItem* item = new RsGxsForumMsgItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->mMsg.mMsg); - - if (offset != rssize) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSFORUM_DEBUG - std::cerr << "RsGxsForumSerialiser::deserialiseGxsForumMsgItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ diff --git a/libretroshare/src/serialiser/rsgxsforumitems.h b/libretroshare/src/serialiser/rsgxsforumitems.h index 22fae7e63..8e8d2bc24 100644 --- a/libretroshare/src/serialiser/rsgxsforumitems.h +++ b/libretroshare/src/serialiser/rsgxsforumitems.h @@ -31,9 +31,11 @@ #include "rsitems/rsserviceids.h" #include "rsitems/rsgxsitems.h" +#include "serialization/rsserializer.h" + #include "retroshare/rsgxsforums.h" -const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02; +const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02; const uint8_t RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM = 0x03; class RsGxsForumGroupItem : public RsGxsGrpItem @@ -41,13 +43,11 @@ class RsGxsForumGroupItem : public RsGxsGrpItem public: - RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_FORUMS, - RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) { return;} - virtual ~RsGxsForumGroupItem() { return;} - - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_FORUMS, RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) {} + virtual ~RsGxsForumGroupItem() {} + void clear(); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGxsForumGroup mGroup; }; @@ -56,38 +56,22 @@ class RsGxsForumMsgItem : public RsGxsMsgItem { public: - RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_FORUMS, - RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {return; } - virtual ~RsGxsForumMsgItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_FORUMS, RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {} + virtual ~RsGxsForumMsgItem() {} + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGxsForumMsg mMsg; }; -class RsGxsForumSerialiser : public RsSerialType +class RsGxsForumSerialiser : public RsServiceSerializer { public: + RsGxsForumSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_FORUMS) {} + virtual ~RsGxsForumSerialiser() {} - RsGxsForumSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_FORUMS) - { return; } - virtual ~RsGxsForumSerialiser() { return; } - - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsForumGroupItem(RsGxsForumGroupItem *item); - bool serialiseGxsForumGroupItem (RsGxsForumGroupItem *item, void *data, uint32_t *size); - RsGxsForumGroupItem * deserialiseGxsForumGroupItem(void *data, uint32_t *size); - - uint32_t sizeGxsForumMsgItem(RsGxsForumMsgItem *item); - bool serialiseGxsForumMsgItem (RsGxsForumMsgItem *item, void *data, uint32_t *size); - RsGxsForumMsgItem * deserialiseGxsForumMsgItem(void *data, uint32_t *size); - + virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; }; #endif /* RS_GXS_FORUM_ITEMS_H */ From f6e59f7dee865be575020792cd4d464b168e73c5 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 11:59:18 +0200 Subject: [PATCH 064/106] moved gxsforumitems to rsitems/ --- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/{serialiser => rsitems}/rsgxsforumitems.cc | 0 libretroshare/src/{serialiser => rsitems}/rsgxsforumitems.h | 0 libretroshare/src/services/p3gxsforums.cc | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsgxsforumitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsgxsforumitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 43a0eb6dd..4d2e75c7c 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -803,10 +803,10 @@ SOURCES += services/p3gxscircles.cc \ # GxsForums Service HEADERS += retroshare/rsgxsforums.h \ services/p3gxsforums.h \ - serialiser/rsgxsforumitems.h + rsitems/rsgxsforumitems.h SOURCES += services/p3gxsforums.cc \ - serialiser/rsgxsforumitems.cc \ + rsitems/rsgxsforumitems.cc \ # GxsChannels Service HEADERS += retroshare/rsgxschannels.h \ diff --git a/libretroshare/src/serialiser/rsgxsforumitems.cc b/libretroshare/src/rsitems/rsgxsforumitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsgxsforumitems.cc rename to libretroshare/src/rsitems/rsgxsforumitems.cc diff --git a/libretroshare/src/serialiser/rsgxsforumitems.h b/libretroshare/src/rsitems/rsgxsforumitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxsforumitems.h rename to libretroshare/src/rsitems/rsgxsforumitems.h diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 29c7ed6c7..72ad9ad46 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -24,7 +24,7 @@ */ #include "services/p3gxsforums.h" -#include "serialiser/rsgxsforumitems.h" +#include "rsitems/rsgxsforumitems.h" #include From 3c20a85335d88c2351175e4dafbf68db83b1dd9d Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 14:16:57 +0200 Subject: [PATCH 065/106] switched RsNxsItems to new serialization --- libretroshare/src/gxs/rsgxsnetservice.cc | 6 +- libretroshare/src/serialiser/rsnxsitems.cc | 283 +++++++++++++-------- libretroshare/src/serialiser/rsnxsitems.h | 169 ++++-------- 3 files changed, 223 insertions(+), 235 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 259d01135..1811f2658 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -3500,10 +3500,10 @@ bool RsGxsNetService::encryptSingleNxsItem(RsNxsItem *item, const RsGxsCircleId& #ifdef NXS_NET_DEBUG_7 GXSNETDEBUG_P_ (item->PeerId()) << " Encrypting..." << std::endl; #endif - uint32_t size = item->serial_size() ; + uint32_t size = RsNxsSerialiser(mServType).size(item) ; RsTemporaryMemory tempmem( size ) ; - if(!item->serialise(tempmem,size)) + if(!RsNxsSerialiser(mServType).serialise(item,tempmem,&size)) { std::cerr << " (EE) Cannot serialise item. Something went wrong." << std::endl; status = RS_NXS_ITEM_ENCRYPTION_STATUS_SERIALISATION_ERROR ; @@ -3530,7 +3530,7 @@ bool RsGxsNetService::encryptSingleNxsItem(RsNxsItem *item, const RsGxsCircleId& enc_item->transactionNumber = item->transactionNumber ; enc_item->PeerId(item->PeerId()) ; - encrypted_item = enc_item ; + encrypted_item = enc_item ; #ifdef NXS_NET_DEBUG_7 GXSNETDEBUG_P_(item->PeerId()) << " encrypted item of size " << encrypted_len << std::endl; #endif diff --git a/libretroshare/src/serialiser/rsnxsitems.cc b/libretroshare/src/serialiser/rsnxsitems.cc index d17002ca9..bfea43843 100644 --- a/libretroshare/src/serialiser/rsnxsitems.cc +++ b/libretroshare/src/serialiser/rsnxsitems.cc @@ -1,8 +1,9 @@ #include "rsnxsitems.h" -#include "rsbaseserial.h" #include "util/rsprint.h" #include +#include "serialization/rstypeserializer.h" + /*** * #define RSSERIAL_DEBUG 1 ***/ @@ -37,47 +38,181 @@ const uint16_t RsNxsTransacItem::FLAG_TYPE_GRPS = 0x1000; const uint16_t RsNxsTransacItem::FLAG_TYPE_MSGS = 0x2000; const uint16_t RsNxsTransacItem::FLAG_TYPE_ENCRYPTED_DATA = 0x4000; -RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) +RsItem *RsNxsSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); + if(service_id != SERVICE_TYPE) + return NULL ; - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (SERVICE_TYPE != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: return deserialNxsSyncGrpReqItem(data, size); - case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM: return deserialNxsSyncGrpItem(data, size); - case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: return deserialNxsSyncMsgReqItem(data, size); - case RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM: return deserialNxsSyncMsgItem(data, size); - case RS_PKT_SUBTYPE_NXS_GRP_ITEM: return deserialNxsGrpItem(data, size); - case RS_PKT_SUBTYPE_NXS_MSG_ITEM: return deserialNxsMsgItem(data, size); - case RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM: return deserialNxsTransacItem(data, size); - case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:return deserialNxsGroupPublishKeyItem(data, size); - case RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM: return deserialNxsSessionKeyItem(data, size); - case RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM: return deserialNxsEncryptedDataItem(data, size); - case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: return deserialNxsSyncGrpStatsItem(data, size); + switch(item_subtype) + { + case RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM: return new RsNxsSyncGrpReqItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM: return new RsNxsSyncGrpItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM: return new RsNxsSyncMsgReqItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM: return new RsNxsSyncMsgItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_GRP_ITEM: return new RsNxsGrp(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_MSG_ITEM: return new RsNxsMsg(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM: return new RsNxsTransacItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM:return new RsNxsGroupPublishKeyItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM: return new RsNxsEncryptedDataItem(SERVICE_TYPE) ; + case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM: return new RsNxsSyncGrpStatsItem(SERVICE_TYPE) ; default: - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialise() : data has no type" - << std::endl; -#endif return NULL; - - } - } + } } +void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process (j,ctx,flag ,"flag") ; + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ; + RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ; +} +void RsNxsMsg::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process (j,ctx,pos ,"pos") ; + RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ; + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process(j,ctx,msg ,"msg") ; + RsTypeSerializer::serial_process(j,ctx,meta ,"meta") ; +} +void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process (j,ctx,pos ,"pos") ; + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process(j,ctx,grp ,"grp") ; + RsTypeSerializer::serial_process(j,ctx,meta ,"meta") ; +} + +void RsNxsSyncGrpStatsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,request_type ,"request_type") ; + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process (j,ctx,number_of_posts,"number_of_posts") ; + RsTypeSerializer::serial_process (j,ctx,last_post_TS ,"last_post_TS") ; +} + +void RsNxsSyncGrpReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process (j,ctx,flag ,"flag") ; + RsTypeSerializer::serial_process(j,ctx,createdSince ,"createdSince") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ; + RsTypeSerializer::serial_process(j,ctx,updateTS ,"updateTS") ; +} + +void RsNxsTransacItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process(j,ctx,transactFlag ,"transactFlag") ; + RsTypeSerializer::serial_process(j,ctx,nItems ,"nItems") ; + RsTypeSerializer::serial_process(j,ctx,updateTS ,"updateTS") ; +} +void RsNxsSyncGrpItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process (j,ctx,flag ,"flag") ; + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process(j,ctx,publishTs ,"publishTs") ; + RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ; +} +void RsNxsSyncMsgReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process (j,ctx,flag ,"flag") ; + RsTypeSerializer::serial_process(j,ctx,createdSinceTS ,"createdSinceTS") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ; + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process(j,ctx,updateTS ,"updateTS") ; +} +void RsNxsGroupPublishKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; + RsTypeSerializer::serial_process(j,ctx,private_key ,"private_key") ; +} +void RsNxsEncryptedDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,transactionNumber,"transactionNumber") ; + RsTypeSerializer::serial_process(j,ctx,encrypted_data, "encrypted_data") ; +} + +int RsNxsGrp::refcount = 0; +/** print and clear functions **/ +int RsNxsMsg::refcount = 0; +void RsNxsMsg::clear() +{ + + msg.TlvClear(); + meta.TlvClear(); +} + +void RsNxsGrp::clear() +{ + grpId.clear(); + grp.TlvClear(); + meta.TlvClear(); +} + +void RsNxsSyncGrpReqItem::clear() +{ + flag = 0; + createdSince = 0; + syncHash.clear(); + updateTS = 0; +} +void RsNxsGroupPublishKeyItem::clear() +{ + private_key.TlvClear(); +} +void RsNxsSyncMsgReqItem::clear() +{ + grpId.clear(); + flag = 0; + createdSinceTS = 0; + syncHash.clear(); + updateTS = 0; +} +void RsNxsSyncGrpItem::clear() +{ + flag = 0; + publishTs = 0; + grpId.clear(); + authorId.clear(); +} + +void RsNxsSyncMsgItem::clear() +{ + flag = 0; + msgId.clear(); + grpId.clear(); + authorId.clear(); +} + +void RsNxsTransacItem::clear(){ + transactFlag = 0; + nItems = 0; + updateTS = 0; + timestamp = 0; + transactionNumber = 0; +} +void RsNxsEncryptedDataItem::clear(){ + encrypted_data.TlvClear() ; +} + +#ifdef SUSPENDED_CODE_27042017 +void RsNxsSessionKeyItem::clear() +{ + for(std::map::iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) + it->second.TlvClear() ; + + encrypted_session_keys.clear() ; +} +#endif + +#ifdef TO_REMOVE uint32_t RsNxsSerialiser::size(RsItem *item) { @@ -165,7 +300,6 @@ bool RsNxsSyncMsgItem::serialise(void *data, uint32_t& size) const return ok; } - bool RsNxsMsg::serialise(void *data, uint32_t& size) const { uint32_t tlvsize,offset=0; @@ -231,7 +365,6 @@ bool RsNxsGrp::serialise(void *data, uint32_t& size) const return ok; } - bool RsNxsSyncGrpStatsItem::serialise(void *data, uint32_t& size) const { uint32_t tlvsize,offset=0; @@ -265,7 +398,6 @@ bool RsNxsSyncGrpStatsItem::serialise(void *data, uint32_t& size) const return ok; } - bool RsNxsSyncGrpReqItem::serialise(void *data, uint32_t& size) const { uint32_t tlvsize,offset=0; @@ -297,7 +429,6 @@ bool RsNxsSyncGrpReqItem::serialise(void *data, uint32_t& size) const return ok; } - bool RsNxsTransacItem::serialise(void *data, uint32_t& size) const { uint32_t tlvsize,offset=0; @@ -361,6 +492,7 @@ bool RsNxsSyncGrpItem::serialise(void *data, uint32_t& size) const return ok; } + bool RsNxsSyncMsgReqItem::serialise(void *data, uint32_t& size) const { uint32_t tlvsize,offset=0; @@ -1065,78 +1197,6 @@ uint32_t RsNxsSessionKeyItem::serial_size() const } - - -int RsNxsGrp::refcount = 0; -/** print and clear functions **/ -int RsNxsMsg::refcount = 0; -void RsNxsMsg::clear() -{ - - msg.TlvClear(); - meta.TlvClear(); -} - -void RsNxsGrp::clear() -{ - grpId.clear(); - grp.TlvClear(); - meta.TlvClear(); -} - -void RsNxsSyncGrpReqItem::clear() -{ - flag = 0; - createdSince = 0; - syncHash.clear(); - updateTS = 0; -} -void RsNxsGroupPublishKeyItem::clear() -{ - private_key.TlvClear(); -} -void RsNxsSyncMsgReqItem::clear() -{ - grpId.clear(); - flag = 0; - createdSinceTS = 0; - syncHash.clear(); - updateTS = 0; -} -void RsNxsSyncGrpItem::clear() -{ - flag = 0; - publishTs = 0; - grpId.clear(); - authorId.clear(); -} - -void RsNxsSyncMsgItem::clear() -{ - flag = 0; - msgId.clear(); - grpId.clear(); - authorId.clear(); -} - -void RsNxsTransacItem::clear(){ - transactFlag = 0; - nItems = 0; - updateTS = 0; - timestamp = 0; - transactionNumber = 0; -} -void RsNxsEncryptedDataItem::clear(){ - encrypted_data.TlvClear() ; -} -void RsNxsSessionKeyItem::clear() -{ - for(std::map::iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - it->second.TlvClear() ; - - encrypted_session_keys.clear() ; -} - std::ostream& RsNxsSyncGrpReqItem::print(std::ostream &out, uint16_t indent) { @@ -1347,3 +1407,4 @@ std::ostream& RsNxsEncryptedDataItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out ,"RsNxsSessionKeyItem", indent); return out; } +#endif diff --git a/libretroshare/src/serialiser/rsnxsitems.h b/libretroshare/src/serialiser/rsnxsitems.h index 2f4886507..10eb1d835 100644 --- a/libretroshare/src/serialiser/rsnxsitems.h +++ b/libretroshare/src/serialiser/rsnxsitems.h @@ -72,20 +72,13 @@ class RsNxsItem : public RsItem { public: - RsNxsItem(uint16_t servtype, uint8_t subtype) - : RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0) + RsNxsItem(uint16_t servtype, uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, servtype, subtype), transactionNumber(0) { setPriorityLevel(QOS_PRIORITY_RS_GXS_NET); return; } virtual ~RsNxsItem(){} - - virtual bool serialise(void *data,uint32_t& size) const = 0 ; - virtual uint32_t serial_size() const = 0 ; virtual void clear() = 0; - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0; - - bool serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const; uint32_t transactionNumber; // set to zero if this is not a transaction item }; @@ -103,14 +96,11 @@ public: static const uint8_t FLAG_USE_SYNC_HASH; static const uint8_t FLAG_ONLY_CURRENT; // only send most current version of grps / ignores sync hash - RsNxsSyncGrpReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM) { clear(); return;} - + RsNxsSyncGrpReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM) { clear();} virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const ; - + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + uint8_t flag; // advises whether to use sync hash uint32_t createdSince; // how far back to sync data uint32_t updateTS; // time of last group update @@ -127,14 +117,12 @@ public: RsNxsSyncGrpStatsItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM) {} virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent); - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const ; - static const uint8_t GROUP_INFO_TYPE_REQUEST = 0x01; static const uint8_t GROUP_INFO_TYPE_RESPONSE = 0x02; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + uint32_t request_type; // used to determine the type of request RsGxsGroupId grpId; // id of the group uint32_t number_of_posts; // number of posts in that group @@ -149,14 +137,12 @@ public: class RsNxsGroupPublishKeyItem : public RsNxsItem { public: - RsNxsGroupPublishKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM) { clear(); return;} + RsNxsGroupPublishKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM) { clear(); } virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsGxsGroupId grpId ; RsTlvPrivateRSAKey private_key ; }; @@ -194,14 +180,12 @@ public: static const uint16_t FLAG_TYPE_MSGS; static const uint16_t FLAG_TYPE_ENCRYPTED_DATA; - RsNxsTransacItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM) { clear(); return; } - virtual ~RsNxsTransacItem() { return ; } + RsNxsTransacItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM) { clear(); } + virtual ~RsNxsTransacItem() {} - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const ; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint16_t transactFlag; uint32_t nItems; @@ -224,18 +208,14 @@ public: static const uint8_t FLAG_RESPONSE; static const uint8_t FLAG_USE_SYNC_HASH; - RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { clear(); return ; } - virtual ~RsNxsSyncGrpItem() { return; } + RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { clear();} + virtual ~RsNxsSyncGrpItem() {} - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint8_t flag; // request or response - uint32_t publishTs; // to compare to Ts of receiving peer's grp of same id /// grpId of grp held by sending peer @@ -244,6 +224,7 @@ public: }; +#ifdef SUSPENDED_CODE_27042017 /*! * Use to send to peer list of grps * held by server peer @@ -256,17 +237,14 @@ public: RsNxsSessionKeyItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM) { clear(); } virtual ~RsNxsSessionKeyItem() {} - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); /// Session key encrypted for the whole group /// uint8_t iv[EVP_MAX_IV_LENGTH] ; // initialisation vector std::map encrypted_session_keys; // encrypted session keys }; +#endif /*! * Use to send to peer list of grps * held by server peer @@ -282,12 +260,9 @@ public: clear(); } virtual ~RsNxsEncryptedDataItem() {} - - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /// grpId of grp held by sending peer /// @@ -306,20 +281,14 @@ class RsNxsGrp : public RsNxsItem public: RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP_ITEM), grp(servtype), meta(servtype), - metaData(NULL) { clear(); - //std::cout << "\nGrp refcount++ : " << ++refcount << std::endl; - return; } - virtual ~RsNxsGrp() { if(metaData) delete metaData; - //std::cout << "\nGrp refcount-- : " << --refcount << std::endl; - } + metaData(NULL) { clear();} + virtual ~RsNxsGrp() { if(metaData) delete metaData; } RsNxsGrp* clone() const; - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGxsGroupId grpId; /// group Id, needed to complete version Id (ncvi) static int refcount; @@ -354,13 +323,11 @@ public: #endif static const uint8_t FLAG_USE_HASHED_GROUP_ID; - RsNxsSyncMsgReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM) { clear(); return; } - - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; + RsNxsSyncMsgReqItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM) { clear(); } virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGxsGroupId grpId; uint8_t flag; @@ -380,13 +347,11 @@ public: static const uint8_t FLAG_REQUEST; static const uint8_t FLAG_RESPONSE; static const uint8_t FLAG_USE_SYNC_HASH; - RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM) { clear(); return; } + RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM) { clear(); } - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint8_t flag; // response/req RsGxsGroupId grpId; @@ -405,24 +370,12 @@ class RsNxsMsg : public RsNxsItem public: RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG_ITEM), meta(servtype), msg(servtype), - metaData(NULL) { - // std::cout << "\nrefcount++ : " << ++refcount << std::endl; - clear(); return; - } - virtual ~RsNxsMsg() - { - //std::cout << "\nrefcount-- : " << --refcount << std::endl; - if(metaData){ - //std::cout << "\ndeleted\n"; - delete metaData; - } - } + metaData(NULL) { clear(); } + virtual ~RsNxsMsg() { if(metaData) delete metaData; } - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint8_t pos; /// used for splitting up msg uint8_t count; /// number of split up messages @@ -453,14 +406,11 @@ class RsNxsSearchReqItem : public RsNxsItem { public: - RsNxsSearchReqItem(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_EXT_SEARCH_REQ), serviceSearchItem(servtype) { return; } - virtual ~RsNxsSearchReqItem() { return;} + RsNxsSearchReqItem(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_EXT_SEARCH_REQ), serviceSearchItem(servtype) {} + virtual ~RsNxsSearchReqItem() {} + virtual void clear() {} - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - - virtual void clear() { return;} - virtual std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; } + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint8_t nHops; /// how many peers to jump to uint32_t token; // search token @@ -477,13 +427,11 @@ class RsNxsSearchResultMsgItem { public: - RsNxsSearchResultMsgItem() : context(0) { return;} + RsNxsSearchResultMsgItem() : context(0) {} - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - void clear() {} - std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; } + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t token; // search token to be redeemed RsTlvBinaryData context; // used by client service @@ -504,14 +452,11 @@ public: RsNxsSearchResultGrpItem(); - virtual bool serialise(void *data,uint32_t& size) const; - virtual uint32_t serial_size() const; - void clear() {} - std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out; } + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t token; // search token to be redeemed - RsTlvBinaryData context; // used by client service std::string grpId; @@ -547,34 +492,16 @@ public: #endif -class RsNxsSerialiser : public RsSerialType +class RsNxsSerialiser : public RsServiceSerializer { public: - RsNxsSerialiser(uint16_t servtype) : - RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) { return; } + RsNxsSerialiser(uint16_t servtype) : RsServiceSerializer(servtype), SERVICE_TYPE(servtype) {} + virtual ~RsNxsSerialiser() {} - virtual ~RsNxsSerialiser() { return; } - virtual uint32_t size(RsItem *item); - virtual bool serialise(RsItem *item, void *data, uint32_t *size); - virtual RsItem* deserialise(void *data, uint32_t *size); - -private: - RsNxsSyncGrpReqItem *deserialNxsSyncGrpReqItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP */ - RsNxsSyncGrpItem *deserialNxsSyncGrpItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_GRP_ITEM */ - RsNxsSyncMsgReqItem *deserialNxsSyncMsgReqItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_MSG */ - RsNxsSyncMsgItem *deserialNxsSyncMsgItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_SYNC_MSG_ITEM */ - RsNxsGrp *deserialNxsGrpItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_GRP */ - RsNxsMsg *deserialNxsMsgItem(void *data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_MSG */ - RsNxsTransacItem *deserialNxsTransacItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_TRANS */ - RsNxsGroupPublishKeyItem *deserialNxsGroupPublishKeyItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY */ - RsNxsSessionKeyItem *deserialNxsSessionKeyItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM */ - RsNxsEncryptedDataItem *deserialNxsEncryptedDataItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM */ - RsNxsSyncGrpStatsItem *deserialNxsSyncGrpStatsItem(void* data, uint32_t *size); /* RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM */ - - bool checkItemHeader(void *data, uint32_t *size, uint8_t subservice_type); - + virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; +protected: const uint16_t SERVICE_TYPE; }; From 22f6d150dfd59135038abe3c6528f87159a1e6dd Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 14:21:46 +0200 Subject: [PATCH 066/106] moved rsnxsitems.cc to rsitems/ --- libretroshare/src/gxs/gxssecurity.h | 3 ++- libretroshare/src/gxs/rsgds.h | 2 +- libretroshare/src/gxs/rsgenexchange.h | 2 +- libretroshare/src/gxs/rsgxsnetservice.h | 2 +- libretroshare/src/gxs/rsgxsnetutils.h | 2 +- libretroshare/src/gxs/rsgxsutil.h | 2 +- libretroshare/src/gxs/rsnxsobserver.h | 2 +- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/{serialiser => rsitems}/rsnxsitems.cc | 0 libretroshare/src/{serialiser => rsitems}/rsnxsitems.h | 0 10 files changed, 10 insertions(+), 9 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsnxsitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rsnxsitems.h (100%) diff --git a/libretroshare/src/gxs/gxssecurity.h b/libretroshare/src/gxs/gxssecurity.h index b19f81302..047094688 100644 --- a/libretroshare/src/gxs/gxssecurity.h +++ b/libretroshare/src/gxs/gxssecurity.h @@ -28,7 +28,8 @@ */ #include "serialiser/rstlvkeys.h" -#include "serialiser/rsnxsitems.h" + +#include "rsitems/rsnxsitems.h" #include #include diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index 5a82337fe..303d411b8 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -33,7 +33,7 @@ #include "inttypes.h" #include "rsitems/rsgxsitems.h" -#include "serialiser/rsnxsitems.h" +#include "rsitems/rsnxsitems.h" #include "gxs/rsgxsdata.h" #include "rsgxs.h" #include "util/contentvalue.h" diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index 21ea4365c..8ebd40bd7 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -36,7 +36,7 @@ #include "rsgxsdataaccess.h" #include "rsnxsobserver.h" #include "retroshare/rsgxsservice.h" -#include "serialiser/rsnxsitems.h" +#include "rsitems/rsnxsitems.h" #include "rsgxsutil.h" template diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index b14d55058..883649e57 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -33,7 +33,7 @@ #include "rsgds.h" #include "rsnxsobserver.h" #include "pqi/p3linkmgr.h" -#include "serialiser/rsnxsitems.h" +#include "rsitems/rsnxsitems.h" #include "serialiser/rsgxsupdateitems.h" #include "rsgxsnetutils.h" #include "pqi/p3cfgmgr.h" diff --git a/libretroshare/src/gxs/rsgxsnetutils.h b/libretroshare/src/gxs/rsgxsnetutils.h index df82cb2b3..aae2be9f8 100644 --- a/libretroshare/src/gxs/rsgxsnetutils.h +++ b/libretroshare/src/gxs/rsgxsnetutils.h @@ -28,7 +28,7 @@ #include #include "retroshare/rsgxsifacetypes.h" -#include "serialiser/rsnxsitems.h" +#include "rsitems/rsnxsitems.h" #include "rsgixs.h" class p3ServiceControl; diff --git a/libretroshare/src/gxs/rsgxsutil.h b/libretroshare/src/gxs/rsgxsutil.h index a47b981d3..ea94fedcb 100644 --- a/libretroshare/src/gxs/rsgxsutil.h +++ b/libretroshare/src/gxs/rsgxsutil.h @@ -27,7 +27,7 @@ #define GXSUTIL_H_ #include -#include "serialiser/rsnxsitems.h" +#include "rsitems/rsnxsitems.h" #include "rsgds.h" class RsGixs ; diff --git a/libretroshare/src/gxs/rsnxsobserver.h b/libretroshare/src/gxs/rsnxsobserver.h index 2b25fc950..087842ef0 100644 --- a/libretroshare/src/gxs/rsnxsobserver.h +++ b/libretroshare/src/gxs/rsnxsobserver.h @@ -27,7 +27,7 @@ */ #include -#include "serialiser/rsnxsitems.h" +#include "rsitems/rsnxsitems.h" class RsNxsObserver diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 4d2e75c7c..1c047a75b 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -722,7 +722,7 @@ SOURCES += zeroconf/p3zcnatassist.cc \ DEFINES *= SQLITE_HAS_CODEC DEFINES *= GXS_ENABLE_SYNC_MSGS -HEADERS += serialiser/rsnxsitems.h \ +HEADERS += rsitems/rsnxsitems.h \ gxs/rsgds.h \ gxs/rsgxs.h \ gxs/rsdataservice.h \ @@ -748,7 +748,7 @@ HEADERS += serialiser/rsnxsitems.h \ gxs/rsgxsrequesttypes.h -SOURCES += serialiser/rsnxsitems.cc \ +SOURCES += rsitems/rsnxsitems.cc \ gxs/rsdataservice.cc \ gxs/rsgenexchange.cc \ gxs/rsgxsnetservice.cc \ diff --git a/libretroshare/src/serialiser/rsnxsitems.cc b/libretroshare/src/rsitems/rsnxsitems.cc similarity index 100% rename from libretroshare/src/serialiser/rsnxsitems.cc rename to libretroshare/src/rsitems/rsnxsitems.cc diff --git a/libretroshare/src/serialiser/rsnxsitems.h b/libretroshare/src/rsitems/rsnxsitems.h similarity index 100% rename from libretroshare/src/serialiser/rsnxsitems.h rename to libretroshare/src/rsitems/rsnxsitems.h From 35ecc196777e5007066ec65bbc17061a26a752f0 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 14:41:31 +0200 Subject: [PATCH 067/106] switched rsposteditems to new serialization --- libretroshare/src/serialiser/rsposteditems.cc | 358 +----------------- libretroshare/src/serialiser/rsposteditems.h | 37 +- libretroshare/src/services/p3posted.cc | 1 + 3 files changed, 27 insertions(+), 369 deletions(-) diff --git a/libretroshare/src/serialiser/rsposteditems.cc b/libretroshare/src/serialiser/rsposteditems.cc index e5f8a666e..628a1a1ee 100644 --- a/libretroshare/src/serialiser/rsposteditems.cc +++ b/libretroshare/src/serialiser/rsposteditems.cc @@ -25,365 +25,39 @@ */ #include "serialiser/rsposteditems.h" -#include "rsbaseserial.h" -#include "rstlvbase.h" +#include "serialization/rstypeserializer.h" - -uint32_t RsGxsPostedSerialiser::size(RsItem *item) +void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::size()" << std::endl; -#endif - - RsGxsPostedGroupItem* pgItem = NULL; - RsGxsPostedPostItem* ppItem = NULL; - - if ((pgItem = dynamic_cast(item)) != NULL) - { - return sizeGxsPostedGroupItem(pgItem); - } - else if ((ppItem = dynamic_cast(item)) != NULL) - { - return sizeGxsPostedPostItem(ppItem); - } - else - { - return RsGxsCommentSerialiser::size(item); - } + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LINK,mPost.mLink,"mPost.mLink") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG ,mPost.mNotes,"mPost.mNotes") ; } -bool RsGxsPostedSerialiser::serialise(RsItem *item, void *data, uint32_t *size) +void RsGxsPostedGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::serialise()" << std::endl; -#endif - - RsGxsPostedPostItem* ppItem = NULL; - RsGxsPostedGroupItem* pgItem = NULL; - - if ((pgItem = dynamic_cast(item)) != NULL) - { - return serialiseGxsPostedGroupItem(pgItem, data, size); - } - else if ((ppItem = dynamic_cast(item)) != NULL) - { - return serialiseGxsPostedPostItem(ppItem, data, size); - } - else - { - return RsGxsCommentSerialiser::serialise(item, data, size); - } + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,mGroup.mDescription,"mGroup.mDescription") ; } -RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size) +RsItem *RsGxsPostedSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const { -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); + if(service_id != RS_SERVICE_GXS_TYPE_POSTED) + return NULL ; - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_POSTED != getRsItemService(rstype))) - { - std::cerr << "RsGxsPostedSerialiser::deserialise() ERROR Wrong Type"; - std::cerr << std::endl; - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_POSTED_GRP_ITEM: - return deserialiseGxsPostedGroupItem(data, size); - break; - case RS_PKT_SUBTYPE_POSTED_POST_ITEM: - return deserialiseGxsPostedPostItem(data, size); - break; - default: - return RsGxsCommentSerialiser::deserialise(data, size); - break; - } + switch(item_subtype) + { + case RS_PKT_SUBTYPE_POSTED_GRP_ITEM: return new RsGxsPostedGroupItem() ; + case RS_PKT_SUBTYPE_POSTED_POST_ITEM: return new RsGxsPostedPostItem() ; + default: + return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ; + } } -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - void RsGxsPostedPostItem::clear() { mPost.mLink.clear(); mPost.mNotes.clear(); } - -std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsPostedPostItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Link: " << mPost.mLink << std::endl; - printIndent(out, int_Indent); - out << "Notes: " << mPost.mNotes << std::endl; - - printRsItemEnd(out ,"RsGxsPostedPostItem", indent); - return out; -} - -uint32_t RsGxsPostedSerialiser::sizeGxsPostedPostItem(RsGxsPostedPostItem* item) -{ - RsPostedPost& p = item->mPost; - - uint32_t s = 8; - - s += GetTlvStringSize(p.mLink); - s += GetTlvStringSize(p.mNotes); - - return s; -} - -bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size) -{ - -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsPostedPostItem(item); - uint32_t offset = 0; - - if(*size < tlvsize){ - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() Size too small" << std::endl; - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* RsPostedPost */ - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LINK, item->mPost.mLink); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->mPost.mNotes); - - if(offset != tlvsize) - { - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl; - ok = false; - } - -#ifdef POSTED_DEBUG - if (!ok) - { - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl; - } -#endif - - return ok; -} - - - - -RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size) -{ - -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_POSTED != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype))) - { - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl; - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl; - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsPostedPostItem* item = new RsGxsPostedPostItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LINK, item->mPost.mLink); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->mPost.mNotes); - - if (offset != rssize) - { - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl; - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - void RsGxsPostedGroupItem::clear() { mGroup.mDescription.clear(); - return; } - -std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsPostedGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << mGroup.mDescription << std::endl; - - printRsItemEnd(out ,"RsGxsPostedGroupItem", indent); - return out; -} - - -uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item) -{ - RsPostedGroup& g = item->mGroup; - uint32_t s = 8; // header - - s += GetTlvStringSize(g.mDescription); - - return s; -} - -bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size) -{ - -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsPostedGroupItem(item); - uint32_t offset = 0; - - if(*size < tlvsize){ -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* PostedGroupItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->mGroup.mDescription); - - - if(offset != tlvsize) - { -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef POSTED_DEBUG - if (!ok) - { - std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl; - } -#endif - - return ok; -} -RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void *data, uint32_t *size) -{ - -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_POSTED != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_POSTED_GRP_ITEM != getRsItemSubType(rstype))) - { - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl; - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl; - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->mGroup.mDescription); - - if (offset != rssize) - { - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl; - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef POSTED_DEBUG - std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - diff --git a/libretroshare/src/serialiser/rsposteditems.h b/libretroshare/src/serialiser/rsposteditems.h index e78dfafe1..b78835451 100644 --- a/libretroshare/src/serialiser/rsposteditems.h +++ b/libretroshare/src/serialiser/rsposteditems.h @@ -7,18 +7,17 @@ #include "retroshare/rsposted.h" -const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02; +const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02; const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03; class RsGxsPostedGroupItem : public RsGxsGrpItem { public: - RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_POSTED, - RS_PKT_SUBTYPE_POSTED_GRP_ITEM) { return; } - virtual ~RsGxsPostedGroupItem() { return; } + RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_POSTED, RS_PKT_SUBTYPE_POSTED_GRP_ITEM) {} + virtual ~RsGxsPostedGroupItem() {} void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPostedGroup mGroup; }; @@ -26,40 +25,24 @@ public: class RsGxsPostedPostItem : public RsGxsMsgItem { public: - RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXS_TYPE_POSTED, - RS_PKT_SUBTYPE_POSTED_POST_ITEM) {return ; } - virtual ~RsGxsPostedPostItem() { return; } + RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXS_TYPE_POSTED, RS_PKT_SUBTYPE_POSTED_POST_ITEM) {} + virtual ~RsGxsPostedPostItem() {} void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPostedPost mPost; }; class RsGxsPostedSerialiser : public RsGxsCommentSerialiser { - public: - RsGxsPostedSerialiser() - :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_POSTED) - { return; } + RsGxsPostedSerialiser() :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_POSTED) {} - virtual ~RsGxsPostedSerialiser() { return; } + virtual ~RsGxsPostedSerialiser() {} - uint32_t size(RsItem *item); - bool serialise(RsItem *item, void *data, uint32_t *size); - RsItem* deserialise(void *data, uint32_t *size); - -private: - - uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item); - bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size); - RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size); - - uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item); - bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size); - RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size); + virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ; }; diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index b231149d5..1fe9dde3f 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -156,6 +156,7 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector &msg std::cerr << "Not a PostedPostItem neither a RsGxsCommentItem" << " PacketService=" << std::hex << (int)msg->PacketService() << std::dec << " PacketSubType=" << std::hex << (int)msg->PacketSubType() << std::dec + << " type name =" << typeid(*msg).name() << " , deleting!" << std::endl; delete *vit; } From 349d14b354645cc33a0f44bb2671e658e91f732e Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 14:44:41 +0200 Subject: [PATCH 068/106] moved rsposteditems to rsitems/ --- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/{serialiser => rsitems}/rsposteditems.cc | 2 +- libretroshare/src/{serialiser => rsitems}/rsposteditems.h | 0 libretroshare/src/services/p3posted.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsposteditems.cc (95%) rename libretroshare/src/{serialiser => rsitems}/rsposteditems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 1c047a75b..a86b8b9e4 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -844,11 +844,11 @@ gxsthewire { HEADERS += services/p3postbase.h \ services/p3posted.h \ retroshare/rsposted.h \ - serialiser/rsposteditems.h + rsitems/rsposteditems.h SOURCES += services/p3postbase.cc \ services/p3posted.cc \ - serialiser/rsposteditems.cc + rsitems/rsposteditems.cc gxsphotoshare { #Photo Service diff --git a/libretroshare/src/serialiser/rsposteditems.cc b/libretroshare/src/rsitems/rsposteditems.cc similarity index 95% rename from libretroshare/src/serialiser/rsposteditems.cc rename to libretroshare/src/rsitems/rsposteditems.cc index 628a1a1ee..652abed05 100644 --- a/libretroshare/src/serialiser/rsposteditems.cc +++ b/libretroshare/src/rsitems/rsposteditems.cc @@ -24,7 +24,7 @@ * */ -#include "serialiser/rsposteditems.h" +#include "rsitems/rsposteditems.h" #include "serialization/rstypeserializer.h" void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) diff --git a/libretroshare/src/serialiser/rsposteditems.h b/libretroshare/src/rsitems/rsposteditems.h similarity index 100% rename from libretroshare/src/serialiser/rsposteditems.h rename to libretroshare/src/rsitems/rsposteditems.h diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 1fe9dde3f..b3ad80ddf 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -24,7 +24,7 @@ */ #include "services/p3posted.h" -#include "serialiser/rsposteditems.h" +#include "rsitems/rsposteditems.h" #include From 19b4fb892c73e6db57cff5f71bfdd66fde152e4b Mon Sep 17 00:00:00 2001 From: Phenom Date: Thu, 27 Apr 2017 16:42:25 +0200 Subject: [PATCH 069/106] Add Friend Time Offset news feed. --- libretroshare/src/retroshare/rsnotify.h | 17 ++--- libretroshare/src/retroshare/rsrtt.h | 3 +- libretroshare/src/services/p3rtt.cc | 32 ++++++++- libretroshare/src/services/p3rtt.h | 2 + retroshare-gui/src/gui/NewsFeed.cpp | 37 ++++++++-- retroshare-gui/src/gui/NewsFeed.h | 3 +- retroshare-gui/src/gui/feeds/PeerItem.cpp | 29 +++++++- retroshare-gui/src/gui/feeds/PeerItem.h | 3 + retroshare-gui/src/gui/feeds/PeerItem.ui | 88 ++++++++++++++++------- 9 files changed, 172 insertions(+), 42 deletions(-) diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index fd09218bd..7ca7385ee 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -78,15 +78,16 @@ const uint32_t RS_FEED_TYPE_SECURITY = 0x0800; const uint32_t RS_FEED_TYPE_POSTED = 0x1000; const uint32_t RS_FEED_TYPE_SECURITY_IP = 0x2000; -const uint32_t RS_FEED_ITEM_PEER_CONNECT = RS_FEED_TYPE_PEER | 0x0001; -const uint32_t RS_FEED_ITEM_PEER_DISCONNECT = RS_FEED_TYPE_PEER | 0x0002; -const uint32_t RS_FEED_ITEM_PEER_HELLO = RS_FEED_TYPE_PEER | 0x0003; -const uint32_t RS_FEED_ITEM_PEER_NEW = RS_FEED_TYPE_PEER | 0x0004; +const uint32_t RS_FEED_ITEM_PEER_CONNECT = RS_FEED_TYPE_PEER | 0x0001; +const uint32_t RS_FEED_ITEM_PEER_DISCONNECT = RS_FEED_TYPE_PEER | 0x0002; +const uint32_t RS_FEED_ITEM_PEER_HELLO = RS_FEED_TYPE_PEER | 0x0003; +const uint32_t RS_FEED_ITEM_PEER_NEW = RS_FEED_TYPE_PEER | 0x0004; +const uint32_t RS_FEED_ITEM_PEER_OFFSET = RS_FEED_TYPE_PEER | 0x0005; -const uint32_t RS_FEED_ITEM_SEC_CONNECT_ATTEMPT = RS_FEED_TYPE_SECURITY | 0x0001; -const uint32_t RS_FEED_ITEM_SEC_AUTH_DENIED = RS_FEED_TYPE_SECURITY | 0x0002; -const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_IN = RS_FEED_TYPE_SECURITY | 0x0003; -const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_OUT = RS_FEED_TYPE_SECURITY | 0x0004; +const uint32_t RS_FEED_ITEM_SEC_CONNECT_ATTEMPT = RS_FEED_TYPE_SECURITY | 0x0001; +const uint32_t RS_FEED_ITEM_SEC_AUTH_DENIED = RS_FEED_TYPE_SECURITY | 0x0002; +const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_IN = RS_FEED_TYPE_SECURITY | 0x0003; +const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_OUT = RS_FEED_TYPE_SECURITY | 0x0004; const uint32_t RS_FEED_ITEM_SEC_WRONG_SIGNATURE = RS_FEED_TYPE_SECURITY | 0x0005; const uint32_t RS_FEED_ITEM_SEC_BAD_CERTIFICATE = RS_FEED_TYPE_SECURITY | 0x0006; const uint32_t RS_FEED_ITEM_SEC_INTERNAL_ERROR = RS_FEED_TYPE_SECURITY | 0x0007; diff --git a/libretroshare/src/retroshare/rsrtt.h b/libretroshare/src/retroshare/rsrtt.h index aba776a17..6d9422562 100644 --- a/libretroshare/src/retroshare/rsrtt.h +++ b/libretroshare/src/retroshare/rsrtt.h @@ -2,7 +2,7 @@ #define RETROSHARE_RTT_INTERFACE_H /* - * libretroshare/src/retroshare: rsrtt.h + * libretroshare/src/retroshare: rsrtt.h * * RetroShare C++ Interface. * @@ -58,6 +58,7 @@ class RsRtt virtual ~RsRtt() { return; } virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list &results) = 0; +virtual double getMeanOffset(const RsPeerId& id) = 0; }; diff --git a/libretroshare/src/services/p3rtt.cc b/libretroshare/src/services/p3rtt.cc index 987467b77..250cea007 100644 --- a/libretroshare/src/services/p3rtt.cc +++ b/libretroshare/src/services/p3rtt.cc @@ -30,11 +30,13 @@ #include "pqi/pqibin.h" #include "pqi/pqistore.h" #include "pqi/p3linkmgr.h" +#include "rsserver/p3face.h" #include "services/p3rtt.h" #include "serialiser/rsrttitems.h" #include +#include /**** * #define DEBUG_RTT 1 @@ -358,7 +360,26 @@ int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double recv_ts, peerInfo->mPongResults.pop_front(); } - /* should do calculations */ + //Wait at least 20 pongs before compute mean time offset + if(peerInfo->mPongResults.size() > 20) + { + double mean = 0; + for(std::list::const_iterator prIt = peerInfo->mPongResults.begin(), end = peerInfo->mPongResults.end(); prIt != end; ++ prIt) + { + mean += prIt->mOffset; + } + peerInfo->mCurrentMeanOffset = mean / peerInfo->mPongResults.size(); + if(fabs(peerInfo->mCurrentMeanOffset) > 120) + { + p3Notify *notify = RsServer::notify(); + if (notify) + { + //notify->AddPopupMessage(RS_POPUP_OFFSET, eerInfo->mId.toStdString(),"", "Time Offset: "); + notify->AddFeedItem(RS_FEED_ITEM_PEER_OFFSET, peerInfo->mId.toStdString()); + } + std::cerr << "(WW) Peer:" << peerInfo->mId << " get time offset more than two minutes with you!!!" << std::endl; + } + } return 1; } @@ -379,7 +400,16 @@ uint32_t p3rtt::getPongResults(const RsPeerId& id, int n, std::listmCurrentMeanOffset; + else + return 0; +} RttPeerInfo *p3rtt::locked_GetPeerInfo(const RsPeerId& id) { diff --git a/libretroshare/src/services/p3rtt.h b/libretroshare/src/services/p3rtt.h index 9b881fba8..fdf6ef01c 100644 --- a/libretroshare/src/services/p3rtt.h +++ b/libretroshare/src/services/p3rtt.h @@ -46,6 +46,7 @@ class RttPeerInfo double mCurrentPingTS; double mCurrentPingCounter; bool mCurrentPongRecvd; + double mCurrentMeanOffset; uint32_t mLostPongs; uint32_t mSentPings; @@ -69,6 +70,7 @@ virtual RsServiceInfo getServiceInfo(); /***** overloaded from rsRtt *****/ virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list &results); +virtual double getMeanOffset(const RsPeerId &id); /***** overloaded from p3Service *****/ diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index a3351d335..fc42faf7f 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -217,13 +217,17 @@ void NewsFeed::updateDisplay() if (flags & RS_FEED_TYPE_PEER) addFeedItemPeerDisconnect(fi); break; + case RS_FEED_ITEM_PEER_HELLO: + if (flags & RS_FEED_TYPE_PEER) + addFeedItemPeerHello(fi); + break; case RS_FEED_ITEM_PEER_NEW: if (flags & RS_FEED_TYPE_PEER) addFeedItemPeerNew(fi); break; - case RS_FEED_ITEM_PEER_HELLO: + case RS_FEED_ITEM_PEER_OFFSET: if (flags & RS_FEED_TYPE_PEER) - addFeedItemPeerHello(fi); + addFeedItemPeerOffset(fi); break; case RS_FEED_ITEM_SEC_CONNECT_ATTEMPT: @@ -412,8 +416,9 @@ void NewsFeed::testFeeds(uint notifyFlags) instance->addFeedItemPeerConnect(fi); instance->addFeedItemPeerDisconnect(fi); - instance->addFeedItemPeerNew(fi); instance->addFeedItemPeerHello(fi); + instance->addFeedItemPeerNew(fi); + instance->addFeedItemPeerOffset(fi); break; case RS_FEED_TYPE_SECURITY: @@ -906,6 +911,7 @@ struct AddFeedItemIfUniqueData AddFeedItemIfUniqueData(FeedItem *feedItem, int type, const RsPeerId &sslId, const std::string& ipAddr, const std::string& ipAddrReported) : mType(type), mSslId(sslId), mIpAddr(ipAddr), mIpAddrReported(ipAddrReported) { + mPeerItem = dynamic_cast(feedItem); mSecItem = dynamic_cast(feedItem); mSecurityIpItem = dynamic_cast(feedItem); } @@ -914,6 +920,7 @@ struct AddFeedItemIfUniqueData const RsPeerId &mSslId; const std::string& mIpAddr; const std::string& mIpAddrReported; + PeerItem *mPeerItem; SecurityItem *mSecItem; SecurityIpItem *mSecurityIpItem; }; @@ -925,6 +932,14 @@ static bool addFeedItemIfUniqueCallback(FeedItem *feedItem, void *data) return false; } + if (findData->mPeerItem) { + PeerItem *peerItem = dynamic_cast(feedItem); + if (peerItem && peerItem->isSame(findData->mSslId, findData->mType)) { + return true; + } + return false; + } + if (findData->mSecItem) { SecurityItem *secitem = dynamic_cast(feedItem); if (secitem && secitem->isSame(findData->mSslId, findData->mType)) { @@ -955,7 +970,7 @@ void NewsFeed::addFeedItemIfUnique(FeedItem *item, int itemType, const RsPeerId return; } - ui->feedWidget->removeFeedItem(item); + ui->feedWidget->removeFeedItem(feedItem); } addFeedItem(item); @@ -1017,6 +1032,20 @@ void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi) #endif } +void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi) +{ + /* make new widget */ + PeerItem *pi = new PeerItem(this, NEWSFEED_PEERLIST, RsPeerId(fi.mId1), PEER_TYPE_OFFSET, false); + + /* add to layout */ + addFeedItemIfUnique(pi, PEER_TYPE_OFFSET, RsPeerId(fi.mId1), "", "", false); + +#ifdef NEWS_DEBUG + std::cerr << "NewsFeed::addFeedItemPeerOffset()"; + std::cerr << std::endl; +#endif +} + void NewsFeed::addFeedItemSecurityConnectAttempt(const RsFeedItem &fi) { /* make new widget */ diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index b49779b2b..28b8dabaa 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -87,8 +87,9 @@ private: void addFeedItemPeerConnect(const RsFeedItem &fi); void addFeedItemPeerDisconnect(const RsFeedItem &fi); - void addFeedItemPeerNew(const RsFeedItem &fi); void addFeedItemPeerHello(const RsFeedItem &fi); + void addFeedItemPeerNew(const RsFeedItem &fi); + void addFeedItemPeerOffset(const RsFeedItem &fi); void addFeedItemSecurityConnectAttempt(const RsFeedItem &fi); void addFeedItemSecurityAuthDenied(const RsFeedItem &fi); diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 62e92e5c1..3eddd5718 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -34,6 +34,7 @@ #include #include +#include /***** * #define DEBUG_ITEM 1 @@ -68,6 +69,16 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, } +bool PeerItem::isSame(const RsPeerId &peerId, uint32_t type) +{ + if ((mPeerId == peerId) && (mType == type)) + { + return true; + } + return false; +} + + void PeerItem::updateItemStatic() { if (!rsPeers) @@ -95,6 +106,9 @@ void PeerItem::updateItemStatic() case PEER_TYPE_NEW_FOF: title = tr("Friend of Friend"); break; + case PEER_TYPE_OFFSET: + title = tr("Friend Time Offset"); + break; default: title = tr("Peer"); break; @@ -111,8 +125,14 @@ void PeerItem::updateItemStatic() /* expanded Info */ nameLabel->setText(QString::fromUtf8(details.name.c_str())); - idLabel->setText(QString::fromStdString(details.id.toStdString())); + idLabel->setText(QString::fromStdString(details.id.toStdString())); locLabel->setText(QString::fromUtf8(details.location.c_str())); + + if (rsRtt) + { + double offset = rsRtt->getMeanOffset(RsPeerId(mPeerId)); + offsetLabel->setText(QString::number(offset,'f',2).append(" s")); + } } else { @@ -187,6 +207,13 @@ void PeerItem::updateItem() { sendmsgButton->setEnabled(false); } + + if (rsRtt) + { + double offset = rsRtt->getMeanOffset(RsPeerId(mPeerId)); + offsetLabel->setText(QString::number(offset,'f',2).append(" s")); + } + } /* slow Tick */ diff --git a/retroshare-gui/src/gui/feeds/PeerItem.h b/retroshare-gui/src/gui/feeds/PeerItem.h index 6f8f9a85d..9bccaeb1c 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.h +++ b/retroshare-gui/src/gui/feeds/PeerItem.h @@ -30,6 +30,7 @@ const uint32_t PEER_TYPE_STD = 0x0001; const uint32_t PEER_TYPE_CONNECT = 0x0002; const uint32_t PEER_TYPE_HELLO = 0x0003; /* failed Connect Attempt */ const uint32_t PEER_TYPE_NEW_FOF = 0x0004; /* new Friend of Friend */ +const uint32_t PEER_TYPE_OFFSET = 0x0005; /* received time offset */ class FeedHolder; @@ -43,6 +44,8 @@ public: void updateItemStatic(); + bool isSame(const RsPeerId &peerId, uint32_t type); + protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/feeds/PeerItem.ui b/retroshare-gui/src/gui/feeds/PeerItem.ui index 49eb48937..dc37abc28 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.ui +++ b/retroshare-gui/src/gui/feeds/PeerItem.ui @@ -7,11 +7,20 @@ 0 0 476 - 247 + 250 - - + + + 1 + + + 1 + + + 1 + + 1 @@ -95,13 +104,13 @@ QFrame::Sunken - + 0 - + 0 @@ -128,7 +137,7 @@ - + @@ -165,9 +174,9 @@ - + - + Qt::Horizontal @@ -204,9 +213,9 @@ - + - + Qt::Horizontal @@ -317,13 +326,13 @@ - + - + - + - + 75 @@ -336,7 +345,7 @@ - + 75 @@ -349,7 +358,7 @@ - + 0 @@ -368,7 +377,7 @@ - + 75 @@ -381,7 +390,7 @@ - + 75 @@ -394,7 +403,7 @@ - + 75 @@ -407,7 +416,7 @@ - + 0 @@ -426,10 +435,30 @@ + + + + + 0 + 0 + + + + + 75 + true + true + + + + Time offset: + + + - + @@ -509,6 +538,13 @@ + + + + TextLabel + + + @@ -531,17 +567,17 @@ + + StyledLabel + QLabel +
gui/common/StyledLabel.h
+
AvatarWidget QLabel
gui/common/AvatarWidget.h
1
- - StyledLabel - QLabel -
gui/common/StyledLabel.h
-
From 8a9edb2905d57601e52fb9353a68bad3be3552f7 Mon Sep 17 00:00:00 2001 From: Phenom Date: Thu, 27 Apr 2017 17:03:53 +0200 Subject: [PATCH 070/106] Create a Gxs Identity by default. --- retroshare-gui/src/gui/GenCertDialog.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/GenCertDialog.cpp b/retroshare-gui/src/gui/GenCertDialog.cpp index c65c08b89..11bd8f7dd 100644 --- a/retroshare-gui/src/gui/GenCertDialog.cpp +++ b/retroshare-gui/src/gui/GenCertDialog.cpp @@ -22,6 +22,7 @@ #include "GenCertDialog.h" #include +#include #include #include #include @@ -269,9 +270,6 @@ void GenCertDialog::setupState() //ui.no_gpg_key_label->setText(tr("Welcome to Retroshare. Before you can proceed you need to create a profile and associate a node with it. To do so please fill out this form.\nAlternatively you can import a (previously exported) profile. Just uncheck \"Create a new profile\"")); //no_gpg_key_label->setVisible(false); - ui.nickname_label->setVisible(adv_state) ; - ui.nickname_input->setVisible(adv_state) ; - ui.name_label->setVisible(true); ui.name_input->setVisible(generate_new); @@ -421,7 +419,15 @@ void GenCertDialog::genPerson() RsPgpId PGPId; bool isHiddenLoc = false; - mGXSNickname = ui.nickname_input->text(); + if(ui.nickname_input->isVisible()) + { + mGXSNickname = ui.nickname_input->text(); + } + else + { + mGXSNickname = ui.node_input->text(); + } + if (!mGXSNickname.isEmpty()) { if (mGXSNickname.size() < RSID_MINIMUM_NICKNAME_SIZE) From 9adbab32816a5ce1c4a205fb835fb27e8f673073 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 21:10:22 +0200 Subject: [PATCH 071/106] switched heartbeatitems to new serialization --- libretroshare/src/libretroshare.pro | 3 +- .../src/serialiser/rsheartbeatitems.cc | 7 ++-- .../src/serialiser/rsheartbeatitems.h | 34 ++++++++----------- libretroshare/src/services/p3heartbeat.cc | 2 +- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index a86b8b9e4..de265a388 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -483,7 +483,7 @@ HEADERS += rsitems/rsitem.h \ rsitems/rsbanlistitems.h \ rsitems/rsbwctrlitems.h \ rsitems/rsdiscovery2items.h \ - serialiser/rsheartbeatitems.h \ + rsitems/rsheartbeatitems.h \ rsitems/rsrttitems.h \ serialiser/rsgxsrecognitems.h \ serialiser/rsgxsupdateitems.h \ @@ -631,7 +631,6 @@ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsbanlistitems.cc \ rsitems/rsbwctrlitems.cc \ rsitems/rsdiscovery2items.cc \ - serialiser/rsheartbeatitems.cc \ rsitems/rsrttitems.cc \ serialiser/rsgxsrecognitems.cc \ serialiser/rsgxsupdateitems.cc \ diff --git a/libretroshare/src/serialiser/rsheartbeatitems.cc b/libretroshare/src/serialiser/rsheartbeatitems.cc index 0151525a2..f3a1db0c0 100644 --- a/libretroshare/src/serialiser/rsheartbeatitems.cc +++ b/libretroshare/src/serialiser/rsheartbeatitems.cc @@ -24,6 +24,7 @@ * */ +#ifdef TO_REMOVE #include "serialiser/rsbaseserial.h" #include "rsitems/rsserviceids.h" #include "serialiser/rsheartbeatitems.h" @@ -91,10 +92,6 @@ RsItem *RsHeartbeatSerialiser::deserialise(void *data, uint32_t *pktsize) /*************************************************************************/ -void RsHeartbeatItem::clear() -{ -} - std::ostream &RsHeartbeatItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsHeartbeatItem", indent); @@ -204,3 +201,5 @@ RsHeartbeatItem *RsHeartbeatSerialiser::deserialiseHeartbeat(void *data, uint32_ /*************************************************************************/ + +#endif diff --git a/libretroshare/src/serialiser/rsheartbeatitems.h b/libretroshare/src/serialiser/rsheartbeatitems.h index 3a9e6e95f..87d480b3e 100644 --- a/libretroshare/src/serialiser/rsheartbeatitems.h +++ b/libretroshare/src/serialiser/rsheartbeatitems.h @@ -28,9 +28,8 @@ #ifndef RS_HEARTBEAT_ITEMS_H #define RS_HEARTBEAT_ITEMS_H -#include "serialiser/rsserial.h" -#include "rsitems/rsserviceids.h" #include "rsitems/rsitem.h" +#include "rsitems/rsserviceids.h" #include "rsitems/itempriorities.h" const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01; @@ -43,30 +42,25 @@ public: setPriorityLevel(QOS_PRIORITY_RS_HEARTBEAT_PULSE) ; } virtual ~RsHeartbeatItem() {} + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) {} - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void clear(){} }; -class RsHeartbeatSerialiser: public RsSerialType +class RsHeartbeatSerialiser: public RsServiceSerializer { - public: - RsHeartbeatSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_HEARTBEAT) - { return; } +public: + RsHeartbeatSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_HEARTBEAT) {} -virtual ~RsHeartbeatSerialiser() { 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 sizeHeartbeat(RsHeartbeatItem *); -virtual bool serialiseHeartbeat(RsHeartbeatItem *item, void *data, uint32_t *size); -virtual RsHeartbeatItem *deserialiseHeartbeat(void *data, uint32_t *size); + virtual ~RsHeartbeatSerialiser() {} + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const + { + if(service == RS_SERVICE_TYPE_HEARTBEAT && item_subtype == RS_PKT_SUBTYPE_HEARTBEAT_PULSE) + return new RsHeartbeatItem() ; + else + return NULL ; + } }; diff --git a/libretroshare/src/services/p3heartbeat.cc b/libretroshare/src/services/p3heartbeat.cc index 40a510165..498a88cfa 100644 --- a/libretroshare/src/services/p3heartbeat.cc +++ b/libretroshare/src/services/p3heartbeat.cc @@ -26,7 +26,7 @@ #include #include "services/p3heartbeat.h" -#include "serialiser/rsheartbeatitems.h" +#include "rsitems/rsheartbeatitems.h" #include "pqi/p3servicecontrol.h" #include "pqi/pqipersongrp.h" From 07a93be1b2de5500a95857401c12e30763d00a10 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 21:11:10 +0200 Subject: [PATCH 072/106] moved heartbeatitem.h to rsitems/ --- .../rsheartbeatitems.h | 0 .../src/serialiser/rsheartbeatitems.cc | 205 ------------------ 2 files changed, 205 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsheartbeatitems.h (100%) delete mode 100644 libretroshare/src/serialiser/rsheartbeatitems.cc diff --git a/libretroshare/src/serialiser/rsheartbeatitems.h b/libretroshare/src/rsitems/rsheartbeatitems.h similarity index 100% rename from libretroshare/src/serialiser/rsheartbeatitems.h rename to libretroshare/src/rsitems/rsheartbeatitems.h diff --git a/libretroshare/src/serialiser/rsheartbeatitems.cc b/libretroshare/src/serialiser/rsheartbeatitems.cc deleted file mode 100644 index f3a1db0c0..000000000 --- a/libretroshare/src/serialiser/rsheartbeatitems.cc +++ /dev/null @@ -1,205 +0,0 @@ - -/* - * libretroshare/src/serialiser: rsheartbeatitems.cc - * - * RetroShare Serialiser. - * - * Copyright 2013-2013 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". - * - */ - -#ifdef TO_REMOVE -#include "serialiser/rsbaseserial.h" -#include "rsitems/rsserviceids.h" -#include "serialiser/rsheartbeatitems.h" - -/*** - * #define HEART_DEBUG 1 - ***/ - -#define HEART_DEBUG 1 - -#include - -/*************************************************************************/ - -uint32_t RsHeartbeatSerialiser::size(RsItem *i) -{ - RsHeartbeatItem *beat; - - if (NULL != (beat = dynamic_cast(i))) - { - return sizeHeartbeat(beat); - } - return 0; -} - -/* serialise the data to the buffer */ -bool RsHeartbeatSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsHeartbeatItem *beat; - - if (NULL != (beat = dynamic_cast(i))) - { - return serialiseHeartbeat(beat, data, pktsize); - } - return false; -} - -RsItem *RsHeartbeatSerialiser::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_HEARTBEAT != getRsItemService(rstype))) - { - -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::deserialise() Wrong Type" << std::endl; -#endif - return NULL; - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_HEARTBEAT_PULSE: - return deserialiseHeartbeat(data, pktsize); - break; - default: - return NULL; - break; - } - return NULL; -} - -/*************************************************************************/ - - -std::ostream &RsHeartbeatItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsHeartbeatItem", indent); - printRsItemEnd(out, "RsHeartbeatItem", indent); - return out; -} - -uint32_t RsHeartbeatSerialiser::sizeHeartbeat(RsHeartbeatItem */*item*/) -{ - uint32_t s = 8; /* header */ - return s; -} - -/* serialise the data to the buffer */ -bool RsHeartbeatSerialiser::serialiseHeartbeat(RsHeartbeatItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeHeartbeat(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - { -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::serialiseHeartbeat() Not enough space" << std::endl; -#endif - return false; /* not enough space */ - } - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize); - - /* skip the header */ - offset += 8; - - if (offset != tlvsize) - { -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::serialiseHeartbeat() size error" << std::endl; -#endif - ok = false; - } - - return ok; -} - -RsHeartbeatItem *RsHeartbeatSerialiser::deserialiseHeartbeat(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_HEARTBEAT != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_HEARTBEAT_PULSE != getRsItemSubType(rstype))) - { -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() size error" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsHeartbeatItem *item = new RsHeartbeatItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - if (offset != rssize) - { -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() size error2" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef HEART_DEBUG - std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - -#endif From 87018edeb2907fc2ed6172bc707785984411697e Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 21:20:30 +0200 Subject: [PATCH 073/106] switched rsstatusitem to new serializer --- libretroshare/src/serialiser/rsstatusitems.cc | 3 ++ libretroshare/src/serialiser/rsstatusitems.h | 49 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/serialiser/rsstatusitems.cc b/libretroshare/src/serialiser/rsstatusitems.cc index e39c4f56c..d41d8c7ba 100644 --- a/libretroshare/src/serialiser/rsstatusitems.cc +++ b/libretroshare/src/serialiser/rsstatusitems.cc @@ -23,6 +23,7 @@ * */ +#ifdef TO_REMOVE #include "serialiser/rsstatusitems.h" #include "serialiser/rsbaseserial.h" @@ -173,3 +174,5 @@ RsItem *RsStatusSerialiser::deserialise(void *data, uint32_t *pktsize) } /*************************************************************************/ + +#endif diff --git a/libretroshare/src/serialiser/rsstatusitems.h b/libretroshare/src/serialiser/rsstatusitems.h index 8ea99e04c..8c0316a9b 100644 --- a/libretroshare/src/serialiser/rsstatusitems.h +++ b/libretroshare/src/serialiser/rsstatusitems.h @@ -30,49 +30,46 @@ #include "rsitems/itempriorities.h" #include "rsitems/rsitem.h" +#include "serialization/rstypeserializer.h" + /**************************************************************************/ class RsStatusItem: public RsItem { - public: - RsStatusItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_STATUS, - RS_PKT_SUBTYPE_DEFAULT) +public: + RsStatusItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_STATUS, RS_PKT_SUBTYPE_DEFAULT) { setPriorityLevel(QOS_PRIORITY_RS_STATUS_ITEM); } -virtual ~RsStatusItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsStatusItem() {} + virtual void clear() {} + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) + { + RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; + RsTypeSerializer::serial_process(j,ctx,status ,"status") ; + } uint32_t sendTime; - uint32_t status; /* not serialised */ uint32_t recvTime; }; -class RsStatusSerialiser: public RsSerialType +class RsStatusSerialiser: public RsServiceSerializer { - public: - RsStatusSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_STATUS) - { return; } -virtual ~RsStatusSerialiser() - { 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 sizeItem(RsStatusItem *); -virtual bool serialiseItem (RsStatusItem *item, void *data, uint32_t *size); -virtual RsStatusItem *deserialiseItem(void *data, uint32_t *size); - +public: + RsStatusSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_STATUS) {} + virtual ~RsStatusSerialiser() {} + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const + { + if(service == RS_SERVICE_TYPE_STATUS && item_subtype == RS_PKT_SUBTYPE_DEFAULT) + return new RsStatusItem(); + else + return NULL ; + } }; /**************************************************************************/ From 5995e508c567f4e28f35c5d29e8fa2e81d5371be Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Apr 2017 21:24:27 +0200 Subject: [PATCH 074/106] moved rsstatusitem.h to rsitems/ --- libretroshare/src/libretroshare.pro | 3 +- .../{serialiser => rsitems}/rsstatusitems.h | 0 libretroshare/src/serialiser/rsstatusitems.cc | 178 ------------------ libretroshare/src/services/p3statusservice.cc | 2 +- libretroshare/src/services/p3statusservice.h | 2 +- 5 files changed, 3 insertions(+), 182 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsstatusitems.h (100%) delete mode 100644 libretroshare/src/serialiser/rsstatusitems.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index de265a388..455ad9d33 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -463,7 +463,7 @@ HEADERS += rsitems/rsitem.h \ serialiser/rsserial.h \ rsitems/rsserviceids.h \ serialiser/rsserviceitems.h \ - serialiser/rsstatusitems.h \ + rsitems/rsstatusitems.h \ serialiser/rstlvaddrs.h \ serialiser/rstlvbase.h \ serialiser/rstlvitem.h \ @@ -615,7 +615,6 @@ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rshistoryitems.cc \ rsitems/rsmsgitems.cc \ serialiser/rsserial.cc \ - serialiser/rsstatusitems.cc \ serialiser/rstlvaddrs.cc \ serialiser/rstlvbase.cc \ serialiser/rstlvitem.cc \ diff --git a/libretroshare/src/serialiser/rsstatusitems.h b/libretroshare/src/rsitems/rsstatusitems.h similarity index 100% rename from libretroshare/src/serialiser/rsstatusitems.h rename to libretroshare/src/rsitems/rsstatusitems.h diff --git a/libretroshare/src/serialiser/rsstatusitems.cc b/libretroshare/src/serialiser/rsstatusitems.cc deleted file mode 100644 index d41d8c7ba..000000000 --- a/libretroshare/src/serialiser/rsstatusitems.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* - * libretroshare/src/serialiser: rsstatusitems.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-2008 by Vinny Do. - * - * 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". - * - */ - -#ifdef TO_REMOVE -#include "serialiser/rsstatusitems.h" -#include "serialiser/rsbaseserial.h" - -/*** -#define RSSERIAL_DEBUG 1 -***/ - -#include - -/*************************************************************************/ - -RsStatusItem::~RsStatusItem() -{ - return; -} - -void RsStatusItem::clear() -{ - sendTime = 0; - status = 0; -} - -std::ostream &RsStatusItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsStatusItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << std::endl; - - printIndent(out, int_Indent); - out << "status: " << status << std::endl; - - printRsItemEnd(out, "RsStatusItem", indent); - return out; -} - -uint32_t RsStatusSerialiser::sizeItem(RsStatusItem */*item*/) -{ - uint32_t s = 8; /* header */ - s += 4; /* sendTime */ - s += 4; /* status */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsStatusSerialiser::serialiseItem(RsStatusItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeItem(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 << "RsStatusSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsStatusSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime); - ok &= setRawUInt32(data, tlvsize, &offset, item->status); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsStatusSerialiser::serialiseItem() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsStatusItem *RsStatusSerialiser::deserialiseItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_STATUS != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsStatusItem *item = new RsStatusItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime)); - ok &= getRawUInt32(data, rssize, &offset, &(item->status)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -uint32_t RsStatusSerialiser::size(RsItem *item) -{ - return sizeItem((RsStatusItem *) item); -} - -bool RsStatusSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize) -{ - return serialiseItem((RsStatusItem *) item, data, pktsize); -} - -RsItem *RsStatusSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - return deserialiseItem(data, pktsize); -} - -/*************************************************************************/ - -#endif diff --git a/libretroshare/src/services/p3statusservice.cc b/libretroshare/src/services/p3statusservice.cc index c80740462..54184f4db 100644 --- a/libretroshare/src/services/p3statusservice.cc +++ b/libretroshare/src/services/p3statusservice.cc @@ -24,7 +24,7 @@ */ #include "services/p3statusservice.h" -#include "serialiser/rsstatusitems.h" +#include "rsitems/rsstatusitems.h" #include "rsserver/p3face.h" #include "retroshare/rsiface.h" diff --git a/libretroshare/src/services/p3statusservice.h b/libretroshare/src/services/p3statusservice.h index 16395976e..c4f730b0d 100644 --- a/libretroshare/src/services/p3statusservice.h +++ b/libretroshare/src/services/p3statusservice.h @@ -29,7 +29,7 @@ #include #include -#include "serialiser/rsstatusitems.h" +#include "rsitems/rsstatusitems.h" #include "retroshare/rsstatus.h" #include "services/p3service.h" #include "pqi/p3cfgmgr.h" From 2e6766569d4e7f4f07503f88174d8163a0a97c30 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 16:26:59 +0200 Subject: [PATCH 075/106] switched MsgUpdate items to new serialization --- .../src/serialiser/rsgxsupdateitems.cc | 660 ++---------------- .../src/serialiser/rsgxsupdateitems.h | 75 +- .../src/serialization/rstypeserializer.h | 20 +- 3 files changed, 71 insertions(+), 684 deletions(-) diff --git a/libretroshare/src/serialiser/rsgxsupdateitems.cc b/libretroshare/src/serialiser/rsgxsupdateitems.cc index 0074b23c9..f0a7912b3 100644 --- a/libretroshare/src/serialiser/rsgxsupdateitems.cc +++ b/libretroshare/src/serialiser/rsgxsupdateitems.cc @@ -23,9 +23,32 @@ * */ +#include "serialization/rstypeserializer.h" + #include "rsgxsupdateitems.h" #include "rsbaseserial.h" +/**********************************************************************************************/ +/* SERIALIZER */ +/**********************************************************************************************/ + +RsItem* RsGxsUpdateSerialiser::create_item(uint16_t service,uint8_t item_subtype) const +{ + if(service != SERVICE_TYPE) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return new RsGxsMsgUpdateItem(SERVICE_TYPE); + case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return new RsGxsGrpUpdateItem(SERVICE_TYPE); + case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return new RsGxsServerGrpUpdateItem(SERVICE_TYPE); + case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return new RsGxsServerMsgUpdateItem(SERVICE_TYPE); + case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return new RsGxsGrpConfigItem(SERVICE_TYPE); + default: + return NULL ; + } +} + /**********************************************************************************************/ /* CLEAR */ /**********************************************************************************************/ @@ -53,642 +76,63 @@ void RsGxsServerGrpUpdateItem::clear() grpUpdateTS = 0; } - - /**********************************************************************************************/ -/* PRINT */ +/* SERIALISER */ /**********************************************************************************************/ -std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent) +void RsGxsGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - RsPeerId peerId; - std::map msgUpdateTS; - - printRsItemBase(out, "RsGxsMsgUpdateItem", indent); - uint16_t int_Indent = indent + 2; - out << "peerId: " << peerId << std::endl; - printIndent(out, int_Indent); - - std::map::const_iterator cit = msgUpdateInfos.begin(); - out << "msgUpdateTS map:" << std::endl; - int_Indent += 2; - for(; cit != msgUpdateInfos.end(); ++cit) - { - out << "grpId: " << cit->first << std::endl; - printIndent(out, int_Indent); - out << "Msg time stamp: " << cit->second.time_stamp << std::endl; - printIndent(out, int_Indent); - out << "posts available: " << cit->second.message_count << std::endl; - printIndent(out, int_Indent); - } - - return out; -} -std::ostream& RsGxsGrpUpdateItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsGrpUpdateItem", indent); - uint16_t int_Indent = indent + 2; - out << "peerId: " << peerID << std::endl; - printIndent(out, int_Indent); - out << "grpUpdateTS: " << grpUpdateTS << std::endl; - printIndent(out, int_Indent); - return out ; + RsTypeSerializer::serial_process (j,ctx,peerID,"peerID"); + RsTypeSerializer::serial_process(j,ctx,grpUpdateTS,"grpUpdateTS"); } -std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent) +void RsGxsServerGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - printRsItemBase(out, "RsGxsServerMsgUpdateItem", indent); - uint16_t int_Indent = indent + 2; - out << "grpId: " << grpId << std::endl; - printIndent(out, int_Indent); - out << "msgUpdateTS: " << msgUpdateTS << std::endl; - printIndent(out, int_Indent); - return out; + RsTypeSerializer::serial_process(j,ctx,grpUpdateTS,"grpUpdateTS"); } - -std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent) +void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - printRsItemBase(out, "RsGxsServerGrpUpdateItem", indent); - uint16_t int_Indent = indent + 2; - out << "grpUpdateTS: " << grpUpdateTS << std::endl; - printIndent(out, int_Indent); - - return out; + RsTypeSerializer::serial_process(j,ctx,peerID,"peerID"); + RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos"); } -/**********************************************************************************************/ -/* SERIALISER */ -/**********************************************************************************************/ - -bool RsGxsNetServiceItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info) { - tlvsize = serial_size() ; - offset = 0; + bool ok = true ; - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; -} -RsItem* RsGxsUpdateSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype))) - return NULL; /* wrong type */ - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return deserialGxsMsgUpdate(data, size); - case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return deserialGxsGrpUpddate(data, size); - case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return deserialGxsServerGrpUpddate(data, size); - case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return deserialGxsServerMsgUpdate(data, size); - case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return deserialGxsGrpConfig(data, size); - - default: - { -# ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialise() : data has no type" - << std::endl; -# endif - return NULL; - - } - } -} - -/**********************************************************************************************/ -/* SERIAL_SIZE() */ -/**********************************************************************************************/ - - -uint32_t RsGxsGrpUpdateItem::serial_size() const -{ - uint32_t s = 8; // header size - s += peerID.serial_size(); - s += 4; // mUpdateTS - return s; -} - -uint32_t RsGxsServerGrpUpdateItem::serial_size() const -{ - uint32_t s = 8; // header size - s += 4; // time stamp - return s; -} - -uint32_t RsGxsMsgUpdateItem::serial_size() const -{ - uint32_t s = 8; // header size - s += peerID.serial_size() ;//GetTlvStringSize(item->peerId); - - s += msgUpdateInfos.size() * (4 + 4 + RsGxsGroupId::serial_size()); - s += 4; // number of map items - - return s; -} - -uint32_t RsGxsServerMsgUpdateItem::serial_size() const -{ - uint32_t s = 8; // header size - s += grpId.serial_size(); - s += 4; // grp TS - - return s; -} -uint32_t RsGxsGrpConfigItem::serial_size() const -{ - uint32_t s = 8; // header size - s += grpId.serial_size(); - s += 4; // msg_keep_delay - s += 4; // msg_send_delay - s += 4; // msg_req_delay - - return s; -} - -/**********************************************************************************************/ -/* SERIALISE() */ -/**********************************************************************************************/ - -bool RsGxsGrpUpdateItem::serialise(void* data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= peerID.serialise(data, size, offset) ; - ok &= setRawUInt32(data, size, &offset, grpUpdateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() FAIL Size Error! " << std::endl; -#endif - ok = false; - } + ok = ok && setRawUInt32(data,size,&offset,info.time_stamp); + ok = ok && setRawUInt32(data,size,&offset,info.message_count); return ok; } - -bool RsGxsServerGrpUpdateItem::serialise(void* data, uint32_t& size) const +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info) { - uint32_t tlvsize,offset=0; - bool ok = true; + bool ok = true ; - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* RsGxsServerGrpUpdateItem */ - - ok &= setRawUInt32(data, size, &offset, grpUpdateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() FAIL Size Error! " << std::endl; -#endif - ok = false; - } + ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp); + ok = ok && getRawUInt32(data,size,&offset,&info.message_count); return ok; } -bool RsGxsMsgUpdateItem::serialise(void* data, uint32_t& size) const +template<> uint32_t RsTypeSerializer::serial_size(const RsGxsMsgUpdateItem::MsgUpdateInfo& /* info */) { return 8; } + +template<> void RsTypeSerializer::print_data(const std::string& name,const RsGxsMsgUpdateItem::MsgUpdateInfo& info) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= peerID.serialise(data, size, offset) ; - - std::map::const_iterator cit(msgUpdateInfos.begin()); - - uint32_t numItems = msgUpdateInfos.size(); - ok &= setRawUInt32(data, size, &offset, numItems); - - for(; cit != msgUpdateInfos.end(); ++cit) - { - ok &= cit->first.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, cit->second.time_stamp); - ok &= setRawUInt32(data, size, &offset, cit->second.message_count); - } - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - - return ok; + std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl; } -bool RsGxsServerMsgUpdateItem::serialise( void* data, uint32_t& size) const +void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= grpId.serialise(data, size, offset) ; - ok &= setRawUInt32(data, size, &offset, msgUpdateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - - return ok; + RsTypeSerializer::serial_process (j,ctx,grpId,"grpId"); + RsTypeSerializer::serial_process(j,ctx,msgUpdateTS,"msgUpdateTS"); } - -bool RsGxsGrpConfigItem::serialise( void* data, uint32_t& size) const +void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= grpId.serialise(data, size, offset) ; - ok &= setRawUInt32(data, size, &offset, msg_keep_delay); - ok &= setRawUInt32(data, size, &offset, msg_send_delay); - ok &= setRawUInt32(data, size, &offset, msg_req_delay); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - - return ok; + RsTypeSerializer::serial_process (j,ctx,grpId,"grpId") ; + RsTypeSerializer::serial_process(j,ctx,msg_keep_delay,"msg_keep_delay") ; + RsTypeSerializer::serial_process(j,ctx,msg_send_delay,"msg_send_delay") ; + RsTypeSerializer::serial_process(j,ctx,msg_req_delay,"msg_req_delay") ; } -/**********************************************************************************************/ -/* DESERIALISE() */ -/**********************************************************************************************/ - -RsGxsGrpConfigItem* RsGxsUpdateSerialiser::deserialGxsGrpConfig(void* data, uint32_t* size) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_GRP_CONFIG != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsGrpConfigItem* item = new RsGxsGrpConfigItem(getRsItemService(rstype)); - - /* skip the header */ - offset += 8; - - ok &= item->grpId.deserialise(data, *size, offset) ; - ok &= getRawUInt32(data, *size, &offset, &(item->msg_keep_delay)); - ok &= getRawUInt32(data, *size, &offset, &(item->msg_send_delay)); - ok &= getRawUInt32(data, *size, &offset, &(item->msg_req_delay)); - - if (offset != rssize) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxxGrpUpdate() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data, uint32_t* size) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (SERVICE_TYPE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXS_GRP_UPDATE != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsGrpUpdateItem* item = new RsGxsGrpUpdateItem(getRsItemService(rstype)); - - /* skip the header */ - offset += 8; - - ok &= item->peerID.deserialise(data, *size, offset) ; - ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS)); - - if (offset != rssize) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxxGrpUpdate() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(void* data, uint32_t* size) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsServerGrpUpdateItem* item = new RsGxsServerGrpUpdateItem(getRsItemService(rstype)); - - /* skip the header */ - offset += 8; - - ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS)); - - if (offset != rssize) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data, uint32_t* size) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_MSG_UPDATE != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsMsgUpdateItem* item = new RsGxsMsgUpdateItem(getRsItemService(rstype)); - - /* skip the header */ - offset += 8; - - ok &= item->peerID.deserialise(data, *size, offset) ; - uint32_t numUpdateItems; - ok &= getRawUInt32(data, *size, &offset, &(numUpdateItems)); - std::map& msgUpdateInfos = item->msgUpdateInfos; - RsGxsGroupId pId; - - RsGxsMsgUpdateItem::MsgUpdateInfo info ; - - for(uint32_t i = 0; i < numUpdateItems; i++) - { - ok &= pId.deserialise(data, *size, offset); - - if(!ok) - break; - - ok &= getRawUInt32(data, *size, &offset, &(info.time_stamp)); - ok &= getRawUInt32(data, *size, &offset, &(info.message_count)); - - if(!ok) - break; - - msgUpdateInfos.insert(std::make_pair(pId, info)); - } - - if (offset != rssize) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsGxsServerMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate(void* data, uint32_t* size) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsServerMsgUpdateItem* item = new RsGxsServerMsgUpdateItem(getRsItemService(rstype)); - - /* skip the header */ - offset += 8; - - ok &= item->grpId.deserialise(data, *size, offset) ; - ok &= getRawUInt32(data, *size, &offset, &(item->msgUpdateTS)); - - if (offset != rssize) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - diff --git a/libretroshare/src/serialiser/rsgxsupdateitems.h b/libretroshare/src/serialiser/rsgxsupdateitems.h index 7d6c89907..8ea020fe5 100644 --- a/libretroshare/src/serialiser/rsgxsupdateitems.h +++ b/libretroshare/src/serialiser/rsgxsupdateitems.h @@ -55,15 +55,7 @@ public: RsGxsNetServiceItem(uint16_t serv_type,uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, serv_type, subtype) {} virtual ~RsGxsNetServiceItem() {} - - virtual bool serialise(void *data,uint32_t& size) const = 0 ; - virtual uint32_t serial_size() const = 0 ; - virtual void clear() = 0 ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0; - -protected: - bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) const; }; class RsGxsGrpConfig @@ -96,10 +88,7 @@ public: virtual ~RsGxsGrpConfigItem() {} virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out;} - - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGxsGroupId grpId ; }; @@ -121,10 +110,7 @@ public: virtual ~RsGxsGrpUpdateItem() {} virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPeerId peerID; }; @@ -145,11 +131,8 @@ public: virtual ~RsGxsServerGrpUpdateItem() {} - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void clear(); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsGxsMsgUpdate @@ -175,10 +158,7 @@ public: virtual ~RsGxsMsgUpdateItem() {} virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPeerId peerID; }; @@ -199,58 +179,21 @@ public: virtual ~RsGxsServerMsgUpdateItem() {} virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); - - virtual bool serialise(void *data,uint32_t& size) const ; - virtual uint32_t serial_size() const ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGxsGroupId grpId; }; -class RsGxsUpdateSerialiser : public RsSerialType +class RsGxsUpdateSerialiser : public RsServiceSerializer { public: - RsGxsUpdateSerialiser(uint16_t servtype) : RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) {} + RsGxsUpdateSerialiser(uint16_t servtype) : RsServiceSerializer(servtype), SERVICE_TYPE(servtype) {} virtual ~RsGxsUpdateSerialiser() {} - virtual uint32_t size(RsItem *item) - { - RsGxsNetServiceItem *gitem = dynamic_cast(item); - - if (!gitem) - { - std::cerr << "(EE) trying to serialise/size an item that is not a RsGxsNetServiceItem!" << std::endl; - return 0; - } - - return gitem->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - RsGxsNetServiceItem *gitem = dynamic_cast(item); - - if (!gitem) - { - std::cerr << "(EE) trying to serialise an item that is not a RsGxsNetServiceItem!" << std::endl; - return false; - } - - return gitem->serialise(data,*size) ; - } - - virtual RsItem* deserialise(void *data, uint32_t *size); - -private: - RsGxsGrpConfigItem *deserialGxsGrpConfig(void *data, uint32_t *size); - RsGxsServerMsgUpdateItem *deserialGxsServerMsgUpdate(void *data, uint32_t *size); - RsGxsMsgUpdateItem *deserialGxsMsgUpdate(void *data, uint32_t *size); - RsGxsServerGrpUpdateItem *deserialGxsServerGrpUpddate(void *data, uint32_t *size); - RsGxsGrpUpdateItem *deserialGxsGrpUpddate(void *data, uint32_t *size); - - bool checkItemHeader(void *data, uint32_t *size, uint16_t service_type,uint8_t subservice_type); + virtual RsItem* create_item(uint16_t service,uint8_t item_subtype) const ; const uint16_t SERVICE_TYPE; }; diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 3da545df8..3ed0e9c16 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -88,8 +88,8 @@ class RsTypeSerializer ctx.mOffset += 4 ; for(typename std::map::iterator it(v.begin());it!=v.end();++it) { - ctx.mOffset += serial_size(it->first) ; - ctx.mOffset += serial_size(it->second) ; + serial_process(j,ctx,const_cast(it->first),"map::*it->first") ; + serial_process(j,ctx,const_cast(it->second),"map::*it->second") ; } } break ; @@ -97,15 +97,15 @@ class RsTypeSerializer case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; - ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; + serial_process(j,ctx,n,"temporary size"); for(uint32_t i=0;ifirst") ; + serial_process(j,ctx,u,"map::*it->second") ; v[t] = u ; } @@ -115,12 +115,12 @@ class RsTypeSerializer case RsGenericSerializer::SERIALIZE: { uint32_t n=v.size(); - ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; + serial_process(j,ctx,n,"temporary size"); for(typename std::map::iterator it(v.begin());it!=v.end();++it) { - ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,it->first) ; - ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,it->second) ; + serial_process(j,ctx,const_cast(it->first),"map::*it->first") ; + serial_process(j,ctx,const_cast(it->second),"map::*it->second") ; } } break ; @@ -136,8 +136,8 @@ class RsTypeSerializer { std::cerr << " " ; - print_data("first",it->first) ; - print_data("second",it->second) ; + serial_process(j,ctx,const_cast(it->first),"map::*it->first") ; + serial_process(j,ctx,const_cast(it->second),"map::*it->second") ; } } break; From 45eaf27deb3bcf51e6d722f432fffa8fca30fe36 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 16:30:33 +0200 Subject: [PATCH 076/106] moved rsgxsupdateitems to rsitems/ --- libretroshare/src/gxs/rsgxsnetservice.h | 2 +- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/{serialiser => rsitems}/rsgxsupdateitems.cc | 2 +- libretroshare/src/{serialiser => rsitems}/rsgxsupdateitems.h | 0 4 files changed, 4 insertions(+), 4 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsgxsupdateitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsgxsupdateitems.h (100%) diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index 883649e57..b74e53998 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -34,7 +34,7 @@ #include "rsnxsobserver.h" #include "pqi/p3linkmgr.h" #include "rsitems/rsnxsitems.h" -#include "serialiser/rsgxsupdateitems.h" +#include "rsitems/rsgxsupdateitems.h" #include "rsgxsnetutils.h" #include "pqi/p3cfgmgr.h" #include "rsgixs.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 455ad9d33..ca5a07442 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -486,7 +486,7 @@ HEADERS += rsitems/rsitem.h \ rsitems/rsheartbeatitems.h \ rsitems/rsrttitems.h \ serialiser/rsgxsrecognitems.h \ - serialiser/rsgxsupdateitems.h \ + rsitems/rsgxsupdateitems.h \ serialiser/rsserviceinfoitems.h \ HEADERS += services/p3msgservice.h \ @@ -632,7 +632,7 @@ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsdiscovery2items.cc \ rsitems/rsrttitems.cc \ serialiser/rsgxsrecognitems.cc \ - serialiser/rsgxsupdateitems.cc \ + rsitems/rsgxsupdateitems.cc \ serialiser/rsserviceinfoitems.cc \ SOURCES += services/p3msgservice.cc \ diff --git a/libretroshare/src/serialiser/rsgxsupdateitems.cc b/libretroshare/src/rsitems/rsgxsupdateitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsgxsupdateitems.cc rename to libretroshare/src/rsitems/rsgxsupdateitems.cc index f0a7912b3..259cd1b4a 100644 --- a/libretroshare/src/serialiser/rsgxsupdateitems.cc +++ b/libretroshare/src/rsitems/rsgxsupdateitems.cc @@ -24,9 +24,9 @@ */ #include "serialization/rstypeserializer.h" +#include "serialiser/rsbaseserial.h" #include "rsgxsupdateitems.h" -#include "rsbaseserial.h" /**********************************************************************************************/ /* SERIALIZER */ diff --git a/libretroshare/src/serialiser/rsgxsupdateitems.h b/libretroshare/src/rsitems/rsgxsupdateitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxsupdateitems.h rename to libretroshare/src/rsitems/rsgxsupdateitems.h From d32a8caf0650bb5686e35fea80983eec838acf81 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 16:39:54 +0200 Subject: [PATCH 077/106] switched PluginItems to new serialization --- libretroshare/src/serialiser/rsphotoitems.h | 4 +- libretroshare/src/serialiser/rspluginitems.cc | 3 ++ libretroshare/src/serialiser/rspluginitems.h | 48 ++++++++----------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/libretroshare/src/serialiser/rsphotoitems.h b/libretroshare/src/serialiser/rsphotoitems.h index a935472e6..814ea52bc 100644 --- a/libretroshare/src/serialiser/rsphotoitems.h +++ b/libretroshare/src/serialiser/rsphotoitems.h @@ -34,8 +34,8 @@ #include "rsgxsitems.h" #include "retroshare/rsphoto.h" -const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02; -const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03; +const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02; +const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03; const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04; class RsGxsPhotoAlbumItem : public RsGxsGrpItem diff --git a/libretroshare/src/serialiser/rspluginitems.cc b/libretroshare/src/serialiser/rspluginitems.cc index d671d1a1c..f09046d9f 100644 --- a/libretroshare/src/serialiser/rspluginitems.cc +++ b/libretroshare/src/serialiser/rspluginitems.cc @@ -1,5 +1,6 @@ #include "rspluginitems.h" +#ifdef TO_REMOVE #ifndef WINDOWS_SYS #include #endif @@ -130,3 +131,5 @@ std::ostream& RsPluginHashSetItem::print(std::ostream& o, uint16_t) } + +#endif diff --git a/libretroshare/src/serialiser/rspluginitems.h b/libretroshare/src/serialiser/rspluginitems.h index 02b64fc54..d21533c68 100644 --- a/libretroshare/src/serialiser/rspluginitems.h +++ b/libretroshare/src/serialiser/rspluginitems.h @@ -26,14 +26,10 @@ #pragma once -#include "serialiser/rsserial.h" +#include "rsitems/rsitem.h" #include "rsitems/rsconfigitems.h" -#include "serialiser/rsbaseserial.h" -#if 0 -#include "serialiser/rstlvbase.h" -#include "serialiser/rstlvtypes.h" -#endif +#include "serialization/rstypeserializer.h" const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ; @@ -43,41 +39,35 @@ class RsPluginItem: public RsItem RsPluginItem(uint8_t plugin_item_subtype): RsItem(RS_PKT_VERSION1,RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PLUGIN_CONFIG,plugin_item_subtype) {} virtual ~RsPluginItem() {} - virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ? - virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor - virtual void clear() {} }; -class RsPluginSerialiser: public RsSerialType -{ - public: - RsPluginSerialiser() : RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PLUGIN_CONFIG) {} - - virtual uint32_t size (RsItem *item) - { - return dynamic_cast(item)->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - return dynamic_cast(item)->serialise(data,*size) ; - } - virtual RsItem *deserialise (void *data, uint32_t *size) ; -}; - class RsPluginHashSetItem: public RsPluginItem { public: RsPluginHashSetItem() : RsPluginItem(RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET) {} RsPluginHashSetItem(void *data,uint32_t size) ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) + { + RsTypeSerializer::serial_process(j,ctx,hashes,"hashes"); + } + RsTlvHashSet hashes ; +}; - virtual std::ostream& print(std::ostream& o, uint16_t) ; +class RsPluginSerialiser: public RsConfigSerializer +{ + public: + RsPluginSerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PLUGIN_CONFIG) {} - protected: - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual RsItem *create_item(uint8_t class_type, uint8_t item_type) const + { + if(class_type == RS_PKT_TYPE_PLUGIN_CONFIG && item_type == RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET) + return new RsPluginHashSetItem() ; + + return NULL ; + } }; From c33c34b17527081b15abcbd6d9622f4ccfa6643e Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 16:44:04 +0200 Subject: [PATCH 078/106] moved rspluginitems to rsitems/ --- libretroshare/src/libretroshare.pro | 5 +- libretroshare/src/plugins/pluginmanager.cc | 5 +- .../{serialiser => rsitems}/rspluginitems.h | 0 libretroshare/src/serialiser/rspluginitems.cc | 135 ------------------ 4 files changed, 4 insertions(+), 141 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rspluginitems.h (100%) delete mode 100644 libretroshare/src/serialiser/rspluginitems.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index ca5a07442..2b7a1b96f 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -143,7 +143,7 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \ HEADERS += plugins/pluginmanager.h \ plugins/dlfcn_win32.h \ - serialiser/rspluginitems.h \ + rsitems/rspluginitems.h \ util/rsinitedptr.h HEADERS += $$PUBLIC_HEADERS @@ -605,8 +605,7 @@ SOURCES += grouter/p3grouter.cc \ grouter/groutermatrix.cc SOURCES += plugins/pluginmanager.cc \ - plugins/dlfcn_win32.cc \ - serialiser/rspluginitems.cc + plugins/dlfcn_win32.cc SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsfiletransferitems.cc \ diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index 431b6c2f8..bbc1761fb 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -9,8 +9,7 @@ #include #endif -#include - +#include #include #include @@ -34,7 +33,7 @@ std::string RsPluginManager::_plugin_entry_symbol = "RETROSHARE_PLUGIN_provide" ; std::string RsPluginManager::_plugin_revision_symbol = "RETROSHARE_PLUGIN_revision" ; -std::string RsPluginManager::_plugin_API_symbol = "RETROSHARE_PLUGIN_api" ; +std::string RsPluginManager::_plugin_API_symbol = "RETROSHARE_PLUGIN_api" ; std::string RsPluginManager::_local_cache_dir ; std::string RsPluginManager::_remote_cache_dir ; diff --git a/libretroshare/src/serialiser/rspluginitems.h b/libretroshare/src/rsitems/rspluginitems.h similarity index 100% rename from libretroshare/src/serialiser/rspluginitems.h rename to libretroshare/src/rsitems/rspluginitems.h diff --git a/libretroshare/src/serialiser/rspluginitems.cc b/libretroshare/src/serialiser/rspluginitems.cc deleted file mode 100644 index f09046d9f..000000000 --- a/libretroshare/src/serialiser/rspluginitems.cc +++ /dev/null @@ -1,135 +0,0 @@ -#include "rspluginitems.h" - -#ifdef TO_REMOVE -#ifndef WINDOWS_SYS -#include -#endif - -bool RsPluginHashSetItem::serialise(void *data,uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size(); - uint32_t offset = 0; - -#ifdef P3TURTLE_DEBUG - std::cerr << "RsPluginSerialiser::serialising HashSet packet (size=" << tlvsize << ")" << std::endl; -#endif - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - - ok &= hashes.SetTlv(data,tlvsize,&offset) ; - - if (offset != tlvsize) - { - ok = false; -#ifdef P3TURTLE_DEBUG - std::cerr << "RsPluginHashSetItem::serialise() Size Error! (offset=" << offset << ", tlvsize=" << tlvsize << ")" << std::endl; -#endif - } - - return ok ; -} - -RsPluginHashSetItem::RsPluginHashSetItem(void *data,uint32_t size) - : RsPluginItem(RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - hashes.ids.clear() ; - - ok &= hashes.GetTlv(data,size,&offset) ; - - if (offset != rssize) - { -#ifdef TLV_DEBUG - std::cerr << "RsTlvPeerIdSet::GetTlv() Warning extra bytes at end of item"; - std::cerr << std::endl; -#endif - ok = false ; - } - -#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs). - UNREFERENCED_LOCAL_VARIABLE(rssize); -#else - if (!ok) - throw std::runtime_error("Unknown error while deserializing.") ; -#endif - -} - -RsItem *RsPluginSerialiser::deserialise(void *data, uint32_t *size) -{ - // look what we have... - - /* get the type */ - uint32_t rstype = getRsItemId(data); -#ifdef P3TURTLE_DEBUG - std::cerr << "p3turtle: deserialising packet: " << std::endl ; -#endif - if ( (RS_PKT_VERSION1 != getRsItemVersion(rstype)) - || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) - || (RS_PKT_TYPE_PLUGIN_CONFIG != getRsItemType(rstype))) - { -#ifdef P3TURTLE_DEBUG - std::cerr << " Wrong type !!" << std::endl ; -#endif - return NULL; /* wrong type */ - } - -#ifndef WINDOWS_SYS - try - { -#endif - switch(getRsItemSubType(rstype)) - { - case RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET : return new RsPluginHashSetItem(data,*size) ; - - default: - std::cerr << "Unknown packet type in RsPluginSerialiser. Type = " << rstype << std::endl; - return NULL ; - } -#ifndef WINDOWS_SYS - } - catch(std::exception& e) - { - std::cerr << "Exception raised: " << e.what() << std::endl ; - return NULL ; - } -#endif -} - -uint32_t RsPluginHashSetItem::serial_size() -{ - uint32_t size = 8 ; - - size += hashes.TlvSize() ; - - return size ; -} - -std::ostream& RsPluginHashSetItem::print(std::ostream& o, uint16_t) -{ - o << "Item type: RsPluginHashSetItem" << std::endl; - o << " Hash list: " << std::endl; - - for(std::set::const_iterator it(hashes.ids.begin());it!=hashes.ids.end();++it) - o << " " << *it << std::endl; - - return o ; -} - - - -#endif From 2d19783296276c1e99f14c420f1c6af97050c403 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 17:44:45 +0200 Subject: [PATCH 079/106] switched serviceinfo items to new serialization --- .../src/serialiser/rsserviceinfoitems.cc | 51 +++++++++-------- .../src/serialiser/rsserviceinfoitems.h | 57 +++++-------------- .../src/serialiser/rstlvgenericmap.inl | 1 + 3 files changed, 43 insertions(+), 66 deletions(-) diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.cc b/libretroshare/src/serialiser/rsserviceinfoitems.cc index 8efc0eb87..a538273de 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.cc +++ b/libretroshare/src/serialiser/rsserviceinfoitems.cc @@ -25,6 +25,7 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rsserviceinfoitems.h" +#include "serialization/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 @@ -35,8 +36,7 @@ /*************************************************************************/ /***** RsServiceInfo ****/ -template<> -std::ostream &RsTlvParamRef::print(std::ostream &out, uint16_t /*indent*/) const +template<> std::ostream& RsTlvParamRef::print(std::ostream &out, uint16_t /*indent*/) const { out << "RsServiceInfo: " << mParam.mServiceType << " name " << mParam.mServiceName; out << std::endl; @@ -138,38 +138,19 @@ template class RsTlvParamRef; /*************************************************************************/ -RsServiceInfoListItem::~RsServiceInfoListItem() -{ - return; -} - void RsServiceInfoListItem::clear() { mServiceInfo.clear(); } -std::ostream &RsServiceInfoListItem::print(std::ostream &out, uint16_t indent) +void RsServiceInfoListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - printRsItemBase(out, "RsServiceInfoListItem", indent); - uint16_t int_Indent = indent + 2; RsTlvServiceInfoMapRef map(mServiceInfo); - map.print(out, int_Indent); - out << std::endl; - printRsItemEnd(out, "RsServiceInfoListItem", indent); - return out; -} - - -uint32_t RsServiceInfoSerialiser::sizeInfo(RsServiceInfoListItem *item) -{ - uint32_t s = 8; /* header */ - RsTlvServiceInfoMapRef map(item->mServiceInfo); - s += map.TlvSize(); - - return s; + RsTypeSerializer::serial_process(j,ctx,map,"map") ; } +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsServiceInfoSerialiser::serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *pktsize) { @@ -291,7 +272,14 @@ uint32_t RsServiceInfoSerialiser::sizePermissions(RsServiceInfoPermissionsIte return s; } +#endif +void RsServiceInfoPermissionsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,allowedBw,"allowedBw") ; +} + +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsServiceInfoSerialiser::serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *pktsize) { @@ -440,6 +428,21 @@ RsItem *RsServiceInfoSerialiser::deserialise(void *data, uint32_t *pktsize) } /*************************************************************************/ +#endif + +RsItem *RsServiceInfoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_TYPE_SERVICEINFO) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_SERVICELIST_ITEM: return new RsServiceInfoListItem() ; + case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM: return new RsServiceInfoPermissionsItem() ; + default: + return NULL ; + } +} diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.h b/libretroshare/src/serialiser/rsserviceinfoitems.h index b4c9beabe..04a524331 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.h +++ b/libretroshare/src/serialiser/rsserviceinfoitems.h @@ -34,8 +34,6 @@ #include "rsitems/rsitem.h" #include "rsitems/itempriorities.h" -#include "serialiser/rsserial.h" -#include "serialiser/rstlvbase.h" #include "serialiser/rstlvgenericmap.h" #include "retroshare/rsservicecontrol.h" @@ -63,72 +61,47 @@ public: } }; - - class RsServiceInfoListItem: public RsItem { public: - RsServiceInfoListItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, - RS_PKT_SUBTYPE_SERVICELIST_ITEM) + RsServiceInfoListItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, RS_PKT_SUBTYPE_SERVICELIST_ITEM) { setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM); return; } -virtual ~RsServiceInfoListItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsServiceInfoListItem(){} + virtual void clear(); - std::map mServiceInfo; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + + std::map mServiceInfo; }; - class RsServiceInfoPermissionsItem: public RsItem { public: - RsServiceInfoPermissionsItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, - RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM) + RsServiceInfoPermissionsItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM) { setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM); return; } -virtual ~RsServiceInfoPermissionsItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsServiceInfoPermissionsItem(){} + virtual void clear(){} + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; - }; - -class RsServiceInfoSerialiser: public RsSerialType +class RsServiceInfoSerialiser: public RsServiceSerializer { public: - RsServiceInfoSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO) - { return; } -virtual ~RsServiceInfoSerialiser() - { return; } + RsServiceInfoSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_SERVICEINFO) {} + virtual ~RsServiceInfoSerialiser() {} -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 sizeInfo(RsServiceInfoListItem *); -virtual bool serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *size); -virtual RsServiceInfoListItem *deserialiseInfo(void *data, uint32_t *size); - - -virtual uint32_t sizePermissions(RsServiceInfoPermissionsItem *); -virtual bool serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *size); -virtual RsServiceInfoPermissionsItem *deserialisePermissions(void *data, uint32_t *size); - - + virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rstlvgenericmap.inl b/libretroshare/src/serialiser/rstlvgenericmap.inl index 87e0d8b04..540ee5d2e 100644 --- a/libretroshare/src/serialiser/rstlvgenericmap.inl +++ b/libretroshare/src/serialiser/rstlvgenericmap.inl @@ -24,6 +24,7 @@ * */ +#include "serialiser/rstlvbase.h" // Must be different - as this is inline in headers. //#define TLV_GENERICMAP_DEBUG 1 From 22e2416f3ea50460a9f944a14ac1e2b5b29f8be3 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 17:47:41 +0200 Subject: [PATCH 080/106] moved rsserviceinfo items to rsitems/ --- libretroshare/src/libretroshare.pro | 4 ++-- .../src/{serialiser => rsitems}/rsserviceinfoitems.cc | 2 +- .../src/{serialiser => rsitems}/rsserviceinfoitems.h | 0 libretroshare/src/services/p3serviceinfo.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsserviceinfoitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsserviceinfoitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 2b7a1b96f..a72b2d246 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -487,7 +487,7 @@ HEADERS += rsitems/rsitem.h \ rsitems/rsrttitems.h \ serialiser/rsgxsrecognitems.h \ rsitems/rsgxsupdateitems.h \ - serialiser/rsserviceinfoitems.h \ + rsitems/rsserviceinfoitems.h \ HEADERS += services/p3msgservice.h \ services/p3service.h \ @@ -632,7 +632,7 @@ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsrttitems.cc \ serialiser/rsgxsrecognitems.cc \ rsitems/rsgxsupdateitems.cc \ - serialiser/rsserviceinfoitems.cc \ + rsitems/rsserviceinfoitems.cc \ SOURCES += services/p3msgservice.cc \ services/p3service.cc \ diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.cc b/libretroshare/src/rsitems/rsserviceinfoitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsserviceinfoitems.cc rename to libretroshare/src/rsitems/rsserviceinfoitems.cc index a538273de..e09160db8 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.cc +++ b/libretroshare/src/rsitems/rsserviceinfoitems.cc @@ -24,8 +24,8 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsserviceinfoitems.h" #include "serialization/rstypeserializer.h" +#include "rsitems/rsserviceinfoitems.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.h b/libretroshare/src/rsitems/rsserviceinfoitems.h similarity index 100% rename from libretroshare/src/serialiser/rsserviceinfoitems.h rename to libretroshare/src/rsitems/rsserviceinfoitems.h diff --git a/libretroshare/src/services/p3serviceinfo.h b/libretroshare/src/services/p3serviceinfo.h index 4d776e44e..210731af1 100644 --- a/libretroshare/src/services/p3serviceinfo.h +++ b/libretroshare/src/services/p3serviceinfo.h @@ -36,7 +36,7 @@ #include "services/p3service.h" -#include "serialiser/rsserviceinfoitems.h" +#include "rsitems/rsserviceinfoitems.h" //!The ServiceInfo service. /** From d3c960e4e7a97d2b21188bee462573249988bd8f Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 17:48:54 +0200 Subject: [PATCH 081/106] removed old code --- .../src/rsitems/rsserviceinfoitems.cc | 345 ++---------------- 1 file changed, 35 insertions(+), 310 deletions(-) diff --git a/libretroshare/src/rsitems/rsserviceinfoitems.cc b/libretroshare/src/rsitems/rsserviceinfoitems.cc index e09160db8..35ba6d02d 100644 --- a/libretroshare/src/rsitems/rsserviceinfoitems.cc +++ b/libretroshare/src/rsitems/rsserviceinfoitems.cc @@ -35,6 +35,41 @@ /*************************************************************************/ /***** RsServiceInfo ****/ +/*************************************************************************/ + +void RsServiceInfoListItem::clear() +{ + mServiceInfo.clear(); +} + +void RsServiceInfoListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTlvServiceInfoMapRef map(mServiceInfo); + + RsTypeSerializer::serial_process(j,ctx,map,"map") ; +} + +void RsServiceInfoPermissionsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,allowedBw,"allowedBw") ; +} + +RsItem *RsServiceInfoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_TYPE_SERVICEINFO) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_SERVICELIST_ITEM: return new RsServiceInfoListItem() ; + case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM: return new RsServiceInfoPermissionsItem() ; + default: + return NULL ; + } +} + + + template<> std::ostream& RsTlvParamRef::print(std::ostream &out, uint16_t /*indent*/) const { @@ -136,313 +171,3 @@ bool RsTlvParamRef::GetTlv(void *data, uint32_t size, uint32_t *o template class RsTlvParamRef; -/*************************************************************************/ - -void RsServiceInfoListItem::clear() -{ - mServiceInfo.clear(); -} - -void RsServiceInfoListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTlvServiceInfoMapRef map(mServiceInfo); - - RsTypeSerializer::serial_process(j,ctx,map,"map") ; -} - -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsServiceInfoSerialiser::serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeInfo(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 << "RsServiceInfoSerialiser::serialiseInfo() Header: " << ok << std::endl; - std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - RsTlvServiceInfoMapRef map(item->mServiceInfo); - ok &= map.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Size Error! " << std::endl; -#endif - } - return ok; -} - -RsServiceInfoListItem *RsServiceInfoSerialiser::deserialiseInfo(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_SERVICEINFO != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_SERVICELIST_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 */ - RsServiceInfoListItem *item = new RsServiceInfoListItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - RsTlvServiceInfoMapRef map(item->mServiceInfo); - ok &= map.GetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ -/*************************************************************************/ - -RsServiceInfoPermissionsItem::~RsServiceInfoPermissionsItem() -{ - return; -} - -void RsServiceInfoPermissionsItem::clear() -{ - allowedBw = 0; -} - -std::ostream &RsServiceInfoPermissionsItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsServiceInfoPermissionsItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "AllowedBw: " << allowedBw; - out << std::endl; - - printRsItemEnd(out, "RsServiceInfoPermissionsItem", indent); - return out; -} - - -uint32_t RsServiceInfoSerialiser::sizePermissions(RsServiceInfoPermissionsItem * /*item*/) -{ - uint32_t s = 8; /* header */ - s += GetTlvUInt32Size(); - - return s; -} -#endif - -void RsServiceInfoPermissionsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,allowedBw,"allowedBw") ; -} - -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsServiceInfoSerialiser::serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizePermissions(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 << "RsServiceInfoSerialiser::serialisePermissions() Header: " << ok << std::endl; - std::cerr << "RsServiceInfoSerialiser::serialisePermissions() 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 << "RsServiceInfoSerialiser::serialisePermissions() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsServiceInfoPermissionsItem *RsServiceInfoSerialiser::deserialisePermissions(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_SERVICEINFO != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_SERVICEPERMISSIONS_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 */ - RsServiceInfoPermissionsItem *item = new RsServiceInfoPermissionsItem(); - 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 RsServiceInfoSerialiser::size(RsItem *i) -{ - RsServiceInfoListItem *sli; - RsServiceInfoPermissionsItem *spi; - - if (NULL != (sli = dynamic_cast(i))) - { - return sizeInfo(sli); - } - if (NULL != (spi = dynamic_cast(i))) - { - return sizePermissions(spi); - } - return 0; -} - -bool RsServiceInfoSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsServiceInfoListItem *sli; - RsServiceInfoPermissionsItem *spi; - - if (NULL != (sli = dynamic_cast(i))) - { - return serialiseInfo(sli, data, pktsize); - } - if (NULL != (spi = dynamic_cast(i))) - { - return serialisePermissions(spi, data, pktsize); - } - return false; -} - -RsItem *RsServiceInfoSerialiser::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_SERVICEINFO != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_SERVICELIST_ITEM: - return deserialiseInfo(data, pktsize); - break; - case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM: - return deserialisePermissions(data, pktsize); - break; - default: - return NULL; - break; - } -} - -/*************************************************************************/ -#endif - -RsItem *RsServiceInfoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const -{ - if(service != RS_SERVICE_TYPE_SERVICEINFO) - return NULL ; - - switch(item_sub_id) - { - case RS_PKT_SUBTYPE_SERVICELIST_ITEM: return new RsServiceInfoListItem() ; - case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM: return new RsServiceInfoPermissionsItem() ; - default: - return NULL ; - } -} - - - From 634efb6142d7ccb14a13178a9e03d61cc89a56bb Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 18:42:11 +0200 Subject: [PATCH 082/106] switched rsphotoitems to new serialization --- .../src/retroshare/rsgxsifacetypes.h | 1 + libretroshare/src/serialiser/rsphotoitems.cc | 87 ++++++++++++++++--- libretroshare/src/serialiser/rsphotoitems.h | 56 +++++------- libretroshare/src/serialiser/rstlvbinary.cc | 84 ++++++++++++++++++ libretroshare/src/serialiser/rstlvbinary.h | 19 ++++ 5 files changed, 200 insertions(+), 47 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 6fd907898..0b1682327 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -14,6 +14,7 @@ #include #include +#include typedef GXSGroupId RsGxsGroupId; typedef Sha1CheckSum RsGxsMessageId; diff --git a/libretroshare/src/serialiser/rsphotoitems.cc b/libretroshare/src/serialiser/rsphotoitems.cc index 3ff10cf8e..6971793d1 100644 --- a/libretroshare/src/serialiser/rsphotoitems.cc +++ b/libretroshare/src/serialiser/rsphotoitems.cc @@ -33,6 +33,22 @@ #define GXS_PHOTO_SERIAL_DEBUG +virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_GXS_TYPE_PHOTO) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM: return new RsGxsPhotoCommentItem() ; + case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: return new RsGxsPhotoAlbumItem() ; + case RS_PKT_SUBTYPE_PHOTO_ITEM: return new RsGxsPhotoPhotoItem() ; + default: + return NULL ; + } +} + +#ifdef TO_REMOVE uint32_t RsGxsPhotoSerialiser::size(RsItem* item) { RsGxsPhotoPhotoItem* ppItem = NULL; @@ -161,7 +177,27 @@ uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem return s; } +#endif +void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CAPTION, album.mCaption, "mCaption"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CATEGORY, album.mCategory, "mCategory"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR, album.mDescription, "mDescription"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG, album.mHashTags, "mHashTags"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG, album.mOther, "mOther"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PATH, album.mPhotoPath, "mPhotoPath"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME, album.mPhotographer, "mPhotographer"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DATE, album.mWhen, "mWhen"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LOCATION, album.mWhere, "mWhere"); + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PIC_TYPE, album.mThumbnail.type,"mThumbnail.type"); + + RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO, album.mThumbnail.data,album.mThumbnail.size); + + RsTypeSerializer::serial_process(j,ctx,b,"thumbnail binary data") ; +} + +#ifdef TO_REMOVE bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data, uint32_t* size) { @@ -326,7 +362,25 @@ uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item) return s; } +#endif +void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CAPTION, photo.mCaption); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CATEGORY, photo.mCategory); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DESCR, photo.mDescription); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_HASH_TAG, photo.mHashTags); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_MSG, photo.mOther); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_AUTH, photo.mPhotographer); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_DATE, photo.mWhen); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_LOCATION, photo.mWhere); + RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_PIC_TYPE, photo.mThumbnail.type); + + RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO,photo.mThumbnail.data, photo.mThumbnail.size); + RsTypeSerializer::serial_process(j,ctx, b, "mThumbnail") ; +} + +#ifdef TO_REMOVE bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data, uint32_t* size) { @@ -468,8 +522,15 @@ RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* da return item; } +#endif +void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"mComment"); + RsTypeSerializer::serial_process(j,ctx,comment.mCommentFlag,"mCommentFlag"); +} +#ifdef TO_REMOVE bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size) { @@ -586,6 +647,7 @@ RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem( return item; } +#endif void RsGxsPhotoAlbumItem::clear() { @@ -607,6 +669,7 @@ void RsGxsPhotoCommentItem::clear() comment.mCommentFlag = 0; } +#ifdef TO_REMOVE std::ostream& RsGxsPhotoCommentItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsPhotoCommentItem", indent); @@ -628,6 +691,19 @@ std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent) return out; } +std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent) +{ + printRsItemBase(out, "RsGxsPhotoPhotoItem", indent); + uint16_t int_Indent = indent + 2; + + + printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent); + return out; +} + + +#endif + void RsGxsPhotoPhotoItem::clear() { photo.mCaption.clear(); @@ -640,14 +716,3 @@ void RsGxsPhotoPhotoItem::clear() photo.mWhere.clear(); photo.mThumbnail.deleteImage(); } - -std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsPhotoPhotoItem", indent); - uint16_t int_Indent = indent + 2; - - - printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent); - return out; -} - diff --git a/libretroshare/src/serialiser/rsphotoitems.h b/libretroshare/src/serialiser/rsphotoitems.h index 814ea52bc..cbaf29700 100644 --- a/libretroshare/src/serialiser/rsphotoitems.h +++ b/libretroshare/src/serialiser/rsphotoitems.h @@ -29,9 +29,11 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" +#include "rsitems/rsgxsitems.h" + +#include "serialiser/rsserial.h" +#include "serialization/rsserializer.h" -#include "rsgxsitems.h" #include "retroshare/rsphoto.h" const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02; @@ -50,6 +52,7 @@ public: void clear(); std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPhotoAlbum album; }; @@ -58,11 +61,12 @@ class RsGxsPhotoPhotoItem : public RsGxsMsgItem { public: - RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, - RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; } - virtual ~RsGxsPhotoPhotoItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {} + virtual ~RsGxsPhotoPhotoItem() {} + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsPhotoPhoto photo; }; @@ -70,43 +74,23 @@ class RsGxsPhotoCommentItem : public RsGxsMsgItem { public: - RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, - RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; } - virtual ~RsGxsPhotoCommentItem() { return; } + RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) {} + virtual ~RsGxsPhotoCommentItem() {} void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsPhotoComment comment; - - }; -class RsGxsPhotoSerialiser : public RsSerialType +class RsGxsPhotoSerialiser : public RsServiceSerializer { public: - RsGxsPhotoSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_PHOTO) - { return; } - virtual ~RsGxsPhotoSerialiser() { return; } - - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem *item); - bool serialiseGxsPhotoAlbumItem (RsGxsPhotoAlbumItem *item, void *data, uint32_t *size); - RsGxsPhotoAlbumItem * deserialiseGxsPhotoAlbumItem(void *data, uint32_t *size); - - uint32_t sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem *item); - bool serialiseGxsPhotoPhotoItem (RsGxsPhotoPhotoItem *item, void *data, uint32_t *size); - RsGxsPhotoPhotoItem * deserialiseGxsPhotoPhotoItem(void *data, uint32_t *size); - - uint32_t sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item); - bool serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size); - RsGxsPhotoCommentItem * deserialiseGxsPhotoCommentItem(void *data, uint32_t *size); + RsGxsPhotoSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_PHOTO) {} + virtual ~RsGxsPhotoSerialiser() {} + virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const; }; #endif /* RSPHOTOV2ITEMS_H_ */ diff --git a/libretroshare/src/serialiser/rstlvbinary.cc b/libretroshare/src/serialiser/rstlvbinary.cc index 5b601a234..258da0d9a 100644 --- a/libretroshare/src/serialiser/rstlvbinary.cc +++ b/libretroshare/src/serialiser/rstlvbinary.cc @@ -218,5 +218,89 @@ std::ostream &RsTlvBinaryData::print(std::ostream &out, uint16_t indent) const } +bool RsTlvBinaryDataRef::SetTlv(void *data, uint32_t size, uint32_t *offset) const +{ + /* must check sizes */ + uint32_t tlvsize = TlvSize(); + uint32_t tlvend = *offset + tlvsize; + if (size < tlvend) + return false; /* not enough space */ + bool ok = true; + + /* start at data[offset] */ + ok &= SetTlvBase(data, tlvend, offset, tlvtype, tlvsize); + + /* add mandatory data */ + + // Warning: this is actually not an error if bin_len=0, as it does not + // corrupt the packet structure. We thus still return true in this case. + // + if (mDataRef != NULL && mSizeRef > 0) + { + memcpy(&(((uint8_t *) data)[*offset]), mDataRef, mSizeRef); + *offset += mSizeRef; + } + return ok; +} +bool RsTlvBinaryDataRef::GetTlv(void *data, uint32_t size, uint32_t *offset) +{ + if (size < *offset + TLV_HEADER_SIZE) + { + return false; /* not enough space to get the header */ + } + + uint16_t tlvtype_in = GetTlvType( &(((uint8_t *) data)[*offset]) ); + uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) ); + uint32_t tlvend = *offset + tlvsize; + + if (size < tlvend) /* check size */ + return false; /* not enough space */ + + if (tlvsize < TLV_HEADER_SIZE) + return false; /* bad tlv size */ + + if (tlvtype != tlvtype_in) /* check type */ + return false; + + /* skip the header */ + (*offset) += TLV_HEADER_SIZE; + + mDataRef = (uint8_t*)rs_malloc(tlvsize - TLV_HEADER_SIZE) ; + + if(mDataRef == NULL) + return false ; + + mSizeRef = tlvsize - TLV_HEADER_SIZE; + + memcpy(mDataRef,&(((uint8_t *) data)[*offset]), tlvsize - TLV_HEADER_SIZE); + *offset += mSizeRef; + + /*************************************************************************** + * NB: extra components could be added (for future expansion of the type). + * or be present (if this code is reading an extended version). + * + * We must chew up the extra characters to conform with TLV specifications + ***************************************************************************/ + if (*offset != tlvend) + { +#ifdef TLV_DEBUG + std::cerr << "RsTlvBinaryData::GetTlv() Warning extra bytes at end of item"; + std::cerr << std::endl; +#endif + *offset = tlvend; + } + + return true; +} + +uint32_t RsTlvBinaryDataRef::TlvSize() const +{ + uint32_t s = TLV_HEADER_SIZE; /* header */ + + if (mDataRef != NULL) + s += mSizeRef; // len is the size of data + + return s; +} diff --git a/libretroshare/src/serialiser/rstlvbinary.h b/libretroshare/src/serialiser/rstlvbinary.h index addac7f46..49a5d00f3 100644 --- a/libretroshare/src/serialiser/rstlvbinary.h +++ b/libretroshare/src/serialiser/rstlvbinary.h @@ -64,4 +64,23 @@ public: void *bin_data; /// mandatory }; +// This class is mainly used for on-the-fly serialization + +class RsTlvBinaryDataRef: public RsTlvItem +{ +public: + RsTlvBinaryDataRef(uint16_t type,uint8_t *& data_ref,uint32_t& size_ref) : mDataRef(data_ref),mSizeRef(size_ref),tlvtype(type) {} + virtual ~RsTlvBinaryDataRef() {} + + virtual uint32_t TlvSize() const; + virtual void TlvClear(){} + virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const; + virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); + + uint8_t *& mDataRef ; + uint32_t & mSizeRef ; + uint16_t tlvtype ; +}; + + From 688813fbf58a22bee997a09c2a9146a045803ec1 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 18:51:35 +0200 Subject: [PATCH 083/106] moved photo items to rsitems/ --- libretroshare/src/libretroshare.pro | 4 +-- libretroshare/src/retroshare/rsphoto.h | 2 +- .../{serialiser => rsitems}/rsphotoitems.cc | 8 +++--- .../{serialiser => rsitems}/rsphotoitems.h | 0 libretroshare/src/serialiser/rstlvbinary.cc | 28 +++++++++++++++++++ libretroshare/src/serialiser/rstlvbinary.h | 2 ++ libretroshare/src/services/p3photoservice.cc | 2 +- 7 files changed, 38 insertions(+), 8 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsphotoitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsphotoitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index a72b2d246..60fad8f7b 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -851,10 +851,10 @@ gxsphotoshare { #Photo Service HEADERS += services/p3photoservice.h \ retroshare/rsphoto.h \ - serialiser/rsphotoitems.h \ + rsitems/rsphotoitems.h \ SOURCES += services/p3photoservice.cc \ - serialiser/rsphotoitems.cc \ + rsitems/rsphotoitems.cc \ } diff --git a/libretroshare/src/retroshare/rsphoto.h b/libretroshare/src/retroshare/rsphoto.h index 7d3c1ae09..5a27a491b 100644 --- a/libretroshare/src/retroshare/rsphoto.h +++ b/libretroshare/src/retroshare/rsphoto.h @@ -52,7 +52,7 @@ class RsPhotoThumbnail // Holds Thumbnail image. uint8_t *data; - int size; + uint32_t size; std::string type; }; diff --git a/libretroshare/src/serialiser/rsphotoitems.cc b/libretroshare/src/rsitems/rsphotoitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsphotoitems.cc rename to libretroshare/src/rsitems/rsphotoitems.cc index 6971793d1..e2f3c279a 100644 --- a/libretroshare/src/serialiser/rsphotoitems.cc +++ b/libretroshare/src/rsitems/rsphotoitems.cc @@ -25,15 +25,15 @@ #include -#include "serialiser/rsphotoitems.h" -#include "serialiser/rstlvbase.h" +#include "rsitems/rsphotoitems.h" + #include "serialiser/rstlvbinary.h" -#include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" #define GXS_PHOTO_SERIAL_DEBUG -virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const +RsItem *RsGxsPhotoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const { if(service != RS_SERVICE_GXS_TYPE_PHOTO) return NULL ; diff --git a/libretroshare/src/serialiser/rsphotoitems.h b/libretroshare/src/rsitems/rsphotoitems.h similarity index 100% rename from libretroshare/src/serialiser/rsphotoitems.h rename to libretroshare/src/rsitems/rsphotoitems.h diff --git a/libretroshare/src/serialiser/rstlvbinary.cc b/libretroshare/src/serialiser/rstlvbinary.cc index 258da0d9a..7eaa58ae2 100644 --- a/libretroshare/src/serialiser/rstlvbinary.cc +++ b/libretroshare/src/serialiser/rstlvbinary.cc @@ -188,6 +188,34 @@ bool RsTlvBinaryData::GetTlv(void *data, uint32_t size, uint32_t *offset) return ok; } +std::ostream &RsTlvBinaryDataRef::print(std::ostream &out, uint16_t indent) const +{ + uint16_t int_Indent = indent + 2; + + uint32_t i; + std::ostringstream sout; + printIndent(sout, indent); + sout << "RsTlvBinaryData: Type: " << tlvtype << " Size: " << mSizeRef; + sout << std::hex; + + for(i = 0; i < mSizeRef; i++) + { + if (i % 16 == 0) + { + sout << std::endl; + printIndent(sout, int_Indent); + } + sout << std::setw(2) << std::setfill('0') + << (int) (((unsigned char *) mDataRef)[i]) << ":"; + } + + sout << std::endl; + out << sout.str(); + + printEnd(out, "RsTlvBinaryData", indent); + return out; + +} std::ostream &RsTlvBinaryData::print(std::ostream &out, uint16_t indent) const { diff --git a/libretroshare/src/serialiser/rstlvbinary.h b/libretroshare/src/serialiser/rstlvbinary.h index 49a5d00f3..a22269e0f 100644 --- a/libretroshare/src/serialiser/rstlvbinary.h +++ b/libretroshare/src/serialiser/rstlvbinary.h @@ -72,6 +72,8 @@ public: RsTlvBinaryDataRef(uint16_t type,uint8_t *& data_ref,uint32_t& size_ref) : mDataRef(data_ref),mSizeRef(size_ref),tlvtype(type) {} virtual ~RsTlvBinaryDataRef() {} + virtual std::ostream &print(std::ostream &out, uint16_t indent) const; + virtual uint32_t TlvSize() const; virtual void TlvClear(){} virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const; diff --git a/libretroshare/src/services/p3photoservice.cc b/libretroshare/src/services/p3photoservice.cc index 759f5ad18..519f10c68 100644 --- a/libretroshare/src/services/p3photoservice.cc +++ b/libretroshare/src/services/p3photoservice.cc @@ -1,5 +1,5 @@ #include "p3photoservice.h" -#include "serialiser/rsphotoitems.h" +#include "rsitems/rsphotoitems.h" #include "retroshare/rsgxsflags.h" RsPhoto *rsPhoto = NULL; From 8341c683885caa032c9d0a1d0392aa5dffa2318b Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 18:54:07 +0200 Subject: [PATCH 084/106] removed old code --- libretroshare/src/rsitems/rsphotoitems.cc | 598 ---------------------- 1 file changed, 598 deletions(-) diff --git a/libretroshare/src/rsitems/rsphotoitems.cc b/libretroshare/src/rsitems/rsphotoitems.cc index e2f3c279a..9c2f217d9 100644 --- a/libretroshare/src/rsitems/rsphotoitems.cc +++ b/libretroshare/src/rsitems/rsphotoitems.cc @@ -48,137 +48,6 @@ RsItem *RsGxsPhotoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) } } -#ifdef TO_REMOVE -uint32_t RsGxsPhotoSerialiser::size(RsItem* item) -{ - RsGxsPhotoPhotoItem* ppItem = NULL; - RsGxsPhotoAlbumItem* paItem = NULL; - RsGxsPhotoCommentItem* cItem = NULL; - - if((ppItem = dynamic_cast(item)) != NULL) - { - return sizeGxsPhotoPhotoItem(ppItem); - } - else if((paItem = dynamic_cast(item)) != NULL) - { - return sizeGxsPhotoAlbumItem(paItem); - } - else if((cItem = dynamic_cast(item)) != NULL) - { - return sizeGxsPhotoCommentItem(cItem); - } - else - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - -#endif - return NULL; - } - -} - -bool RsGxsPhotoSerialiser::serialise(RsItem* item, void* data, uint32_t* size) -{ - - RsGxsPhotoPhotoItem* ppItem = NULL; - RsGxsPhotoAlbumItem* paItem = NULL; - RsGxsPhotoCommentItem* cItem = NULL; - - if((ppItem = dynamic_cast(item)) != NULL) - { - return serialiseGxsPhotoPhotoItem(ppItem, data, size); - } - else if((paItem = dynamic_cast(item)) != NULL) - { - return serialiseGxsPhotoAlbumItem(paItem, data, size); - }else if((cItem = dynamic_cast(item)) != NULL) - { - return serialiseGxsPhotoCommentItem(cItem, data, size); - } - else - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - -#endif - return false; - } - -} - -RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: - return deserialiseGxsPhotoPhotoItem(data, size); - case RS_PKT_SUBTYPE_PHOTO_ITEM: - return deserialiseGxsPhotoAlbumItem(data, size); - case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM: - return deserialiseGxsPhotoCommentItem(data, size); - default: - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialise(): subtype could not be dealt with" - << std::endl; -#endif - break; - } - } - return NULL; -} - -uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item) -{ - - const RsPhotoAlbum& album = item->album; - uint32_t s = 8; // header - - s += GetTlvStringSize(album.mCaption); - s += GetTlvStringSize(album.mCategory); - s += GetTlvStringSize(album.mDescription); - s += GetTlvStringSize(album.mHashTags); - s += GetTlvStringSize(album.mOther); - s += GetTlvStringSize(album.mPhotoPath); - s += GetTlvStringSize(album.mPhotographer); - s += GetTlvStringSize(album.mWhen); - s += GetTlvStringSize(album.mWhere); - - RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent - b.setBinData(album.mThumbnail.data, album.mThumbnail.size); - s += GetTlvStringSize(album.mThumbnail.type); - s += b.TlvSize(); - - return s; -} - -uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoCommentItem(RsGxsPhotoCommentItem *item) -{ - - const RsPhotoComment& comment = item->comment; - uint32_t s = 8; // header - - s += GetTlvStringSize(comment.mComment); - s += 4; // mflags - - return s; - -} -#endif - void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CAPTION, album.mCaption, "mCaption"); @@ -196,174 +65,6 @@ void RsGxsPhotoAlbumItem::serial_process(RsGenericSerializer::SerializeJob j,RsG RsTypeSerializer::serial_process(j,ctx,b,"thumbnail binary data") ; } - -#ifdef TO_REMOVE -bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item, void* data, - uint32_t* size) -{ - -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsPhotoAlbumItem(item); - uint32_t offset = 0; - - if(*size < tlvsize){ -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsPhotoAlbumItem */ - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CAPTION, item->album.mCaption); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CATEGORY, item->album.mCategory); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->album.mDescription); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->album.mHashTags); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->album.mOther); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PATH, item->album.mPhotoPath); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->album.mPhotographer); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DATE, item->album.mWhen); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->album.mWhere); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PIC_TYPE, item->album.mThumbnail.type); - RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent - b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size); - ok &= b.SetTlv(data, tlvsize, &offset); - - if(offset != tlvsize) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXS_PHOTO_SERIAL_DEBUG - if (!ok) - { - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem() NOK" << std::endl; - } -#endif - - return ok; -} - -RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* data, - uint32_t* size) -{ - - -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsPhotoAlbumItem* item = new RsGxsPhotoAlbumItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CAPTION, item->album.mCaption); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CATEGORY, item->album.mCategory); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->album.mDescription); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->album.mHashTags); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->album.mOther); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PATH, item->album.mPhotoPath); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->album.mPhotographer); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DATE, item->album.mWhen); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->album.mWhere); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PIC_TYPE, item->album.mThumbnail.type); - - RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent - ok &= b.GetTlv(data, rssize, &offset); - item->album.mThumbnail.data = (uint8_t*)b.bin_data; - item->album.mThumbnail.size = b.bin_len; - b.TlvShallowClear(); - - if (offset != rssize) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -uint32_t RsGxsPhotoSerialiser::sizeGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item) -{ - - const RsPhotoPhoto& photo = item->photo; - - uint32_t s = 8; // header size - s += GetTlvStringSize(photo.mCaption); - s += GetTlvStringSize(photo.mCategory); - s += GetTlvStringSize(photo.mDescription); - s += GetTlvStringSize(photo.mHashTags); - s += GetTlvStringSize(photo.mOther); - s += GetTlvStringSize(photo.mPhotographer); - s += GetTlvStringSize(photo.mWhen); - s += GetTlvStringSize(photo.mWhere); - - RsTlvBinaryData b(item->PacketService()); // TODO, need something more persisitent - b.setBinData(photo.mThumbnail.data, photo.mThumbnail.size); - s += GetTlvStringSize(photo.mThumbnail.type); - s += b.TlvSize(); - - return s; -} -#endif - void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx, TLV_TYPE_STR_CAPTION, photo.mCaption); @@ -379,276 +80,12 @@ void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsG RsTlvBinaryDataRef b(RS_SERVICE_GXS_TYPE_PHOTO,photo.mThumbnail.data, photo.mThumbnail.size); RsTypeSerializer::serial_process(j,ctx, b, "mThumbnail") ; } - -#ifdef TO_REMOVE -bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item, void* data, - uint32_t* size) -{ - - -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsPhotoPhotoItem(item); - uint32_t offset = 0; - - if(*size < tlvsize){ -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsPhotoAlbumItem */ - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CAPTION, item->photo.mCaption); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CATEGORY, item->photo.mCategory); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->photo.mDescription); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->photo.mHashTags); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->photo.mOther); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PIC_AUTH, item->photo.mPhotographer); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DATE, item->photo.mWhen); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->photo.mWhere); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PIC_TYPE, item->photo.mThumbnail.type); - RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent - b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size); - ok &= b.SetTlv(data, tlvsize, &offset); - - if(offset != tlvsize) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXS_PHOTO_SERIAL_DEBUG - if (!ok) - { - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem() NOK" << std::endl; - } -#endif - - return ok; -} - -RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* data, - uint32_t* size) -{ - - -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsPhotoPhotoItem* item = new RsGxsPhotoPhotoItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CAPTION, item->photo.mCaption); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CATEGORY, item->photo.mCategory); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->photo.mDescription); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->photo.mHashTags); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->photo.mOther); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PIC_AUTH, item->photo.mPhotographer); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DATE, item->photo.mWhen); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->photo.mWhere); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PIC_TYPE, item->photo.mThumbnail.type); - - RsTlvBinaryData b(RS_SERVICE_GXS_TYPE_PHOTO); // TODO, need something more persisitent - ok &= b.GetTlv(data, rssize, &offset); - item->photo.mThumbnail.data = (uint8_t*)(b.bin_data); - item->photo.mThumbnail.size = b.bin_len; - b.TlvShallowClear(); - - if (offset != rssize) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif - void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"mComment"); RsTypeSerializer::serial_process(j,ctx,comment.mCommentFlag,"mCommentFlag"); } -#ifdef TO_REMOVE -bool RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem (RsGxsPhotoCommentItem *item, void *data, uint32_t *size) -{ - - -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsPhotoCommentItem(item); - uint32_t offset = 0; - - if(*size < tlvsize){ -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsPhotoAlbumItem */ - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - ok &= setRawUInt32(data, tlvsize, &offset, item->comment.mCommentFlag); - - if(offset != tlvsize) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXS_PHOTO_SERIAL_DEBUG - if (!ok) - { - std::cerr << "RsGxsPhotoSerialiser::serialiseGxsPhotoCommentItem() NOK" << std::endl; - } -#endif - - return ok; -} - -RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem(void *data, uint32_t *size) -{ - - -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_PHOTO != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsPhotoCommentItem* item = new RsGxsPhotoCommentItem(); - - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - ok &= getRawUInt32(data, rssize, &offset, &(item->comment.mCommentFlag)); - - if (offset != rssize) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXS_PHOTO_SERIAL_DEBUG - std::cerr << "RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -#endif - void RsGxsPhotoAlbumItem::clear() { album.mCaption.clear(); @@ -669,41 +106,6 @@ void RsGxsPhotoCommentItem::clear() comment.mCommentFlag = 0; } -#ifdef TO_REMOVE -std::ostream& RsGxsPhotoCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsPhotoCommentItem", indent); - uint16_t int_Indent = indent + 2; - - - printRsItemEnd(out ,"RsGxsPhotoCommentItem", indent); - return out; -} - -std::ostream& RsGxsPhotoAlbumItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsPhotoAlbumItem", indent); - uint16_t int_Indent = indent + 2; - - out << album << std::endl; - - printRsItemEnd(out ,"RsGxsPhotoAlbumItem", indent); - return out; -} - -std::ostream& RsGxsPhotoPhotoItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsPhotoPhotoItem", indent); - uint16_t int_Indent = indent + 2; - - - printRsItemEnd(out ,"RsGxsPhotoPhotoItem", indent); - return out; -} - - -#endif - void RsGxsPhotoPhotoItem::clear() { photo.mCaption.clear(); From 23492698d4c38595045e6270136fbd3eec7b6112 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 23:28:56 +0200 Subject: [PATCH 085/106] switch rsrecognitems to new serialization --- .../src/serialiser/rsgxsrecognitems.cc | 64 ++++++++++++++- .../src/serialiser/rsgxsrecognitems.h | 82 +++++++------------ 2 files changed, 89 insertions(+), 57 deletions(-) diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.cc b/libretroshare/src/serialiser/rsgxsrecognitems.cc index 11317ad3c..a95cf8f60 100644 --- a/libretroshare/src/serialiser/rsgxsrecognitems.cc +++ b/libretroshare/src/serialiser/rsgxsrecognitems.cc @@ -25,6 +25,7 @@ #include "serialiser/rsgxsrecognitems.h" #include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 @@ -34,9 +35,19 @@ /*************************************************************************/ -RsGxsRecognReqItem::~RsGxsRecognReqItem() +RsItem *RsGxsRecognSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const { - return; + if(service != RS_SERVICE_TYPE_GXS_RECOGN) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_RECOGN_REQ: return new RsGxsRecognReqItem(); + case RS_PKT_SUBTYPE_RECOGN_SIGNER: return new RsGxsRecognSignerItem(); + case RS_PKT_SUBTYPE_RECOGN_TAG: return new RsGxsRecognTagItem(); + default: + return NULL ; + } } void RsGxsRecognReqItem::clear() @@ -53,6 +64,12 @@ void RsGxsRecognReqItem::clear() sign.TlvClear(); } +#ifdef TO_REMOVE +RsGxsRecognReqItem::~RsGxsRecognReqItem() +{ + return; +} + std::ostream &RsGxsRecognReqItem::print(std::ostream &out, uint16_t indent) { @@ -104,6 +121,21 @@ uint32_t RsGxsRecognSerialiser::sizeReq(RsGxsRecognReqItem *item) return s; } +#endif + +void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,issued_at ,"issued_at") ; + RsTypeSerializer::serial_process (j,ctx,period ,"period") ; + RsTypeSerializer::serial_process (j,ctx,tag_class ,"tag_class") ; + RsTypeSerializer::serial_process (j,ctx,tag_type ,"tag_type") ; + RsTypeSerializer::serial_process (j,ctx,identity ,"identity") ; + RsTypeSerializer::serial_process (j,ctx,1,nickname ,"nickname") ; + RsTypeSerializer::serial_process (j,ctx,1,comment ,"comment") ; + RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; +} + +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsGxsRecognSerialiser::serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *pktsize) { @@ -217,6 +249,7 @@ RsGxsRecognTagItem::~RsGxsRecognTagItem() { return; } +#endif void RsGxsRecognTagItem::clear() { @@ -232,6 +265,7 @@ void RsGxsRecognTagItem::clear() sign.TlvClear(); } +#ifdef TO_REMOVE std::ostream &RsGxsRecognTagItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsGxsRecognTagItem", indent); @@ -279,7 +313,20 @@ uint32_t RsGxsRecognSerialiser::sizeTag(RsGxsRecognTagItem *item) return s; } +#endif +void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,valid_from ,"valid_from") ; + RsTypeSerializer::serial_process (j,ctx,valid_to ,"valid_to") ; + RsTypeSerializer::serial_process (j,ctx,tag_class ,"tag_class") ; + RsTypeSerializer::serial_process (j,ctx,tag_type ,"tag_type") ; + RsTypeSerializer::serial_process (j,ctx,identity ,"identity"); + RsTypeSerializer::serial_process (j,ctx,1,nickname ,"nickname") ; + RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; +} + +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsGxsRecognSerialiser::serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *pktsize) { @@ -393,6 +440,7 @@ RsGxsRecognSignerItem::~RsGxsRecognSignerItem() { return; } +#endif void RsGxsRecognSignerItem::clear() { @@ -401,6 +449,7 @@ void RsGxsRecognSignerItem::clear() sign.TlvClear(); } +#ifdef TO_REMOVE std::ostream &RsGxsRecognSignerItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsGxsRecognSignerItem", indent); @@ -435,7 +484,16 @@ uint32_t RsGxsRecognSerialiser::sizeSigner(RsGxsRecognSignerItem *item) return s; } +#endif +void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,signing_classes ,"signing_classes") ; + RsTypeSerializer::serial_process(j,ctx,key ,"key"); + RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; +} + +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsGxsRecognSerialiser::serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *pktsize) { @@ -604,6 +662,6 @@ RsItem *RsGxsRecognSerialiser::deserialise(void *data, uint32_t *pktsize) } /*************************************************************************/ - +#endif diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.h b/libretroshare/src/serialiser/rsgxsrecognitems.h index aab0e3974..e072477ce 100644 --- a/libretroshare/src/serialiser/rsgxsrecognitems.h +++ b/libretroshare/src/serialiser/rsgxsrecognitems.h @@ -32,7 +32,6 @@ #include "rsitems/rsserviceids.h" #include "rsitems/itempriorities.h" -#include "serialiser/rsserial.h" #include "serialiser/rstlvkeys.h" #include "serialiser/rstlvidset.h" @@ -46,25 +45,23 @@ /**************************************************************************/ -#define RS_PKT_SUBTYPE_RECOGN_REQ 0x01 -#define RS_PKT_SUBTYPE_RECOGN_TAG 0x02 -#define RS_PKT_SUBTYPE_RECOGN_SIGNER 0x03 +#define RS_PKT_SUBTYPE_RECOGN_REQ 0x01 +#define RS_PKT_SUBTYPE_RECOGN_TAG 0x02 +#define RS_PKT_SUBTYPE_RECOGN_SIGNER 0x03 class RsGxsRecognReqItem: public RsItem { - public: - RsGxsRecognReqItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, - RS_PKT_SUBTYPE_RECOGN_REQ) - { +public: + RsGxsRecognReqItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, RS_PKT_SUBTYPE_RECOGN_REQ) + { setPriorityLevel(QOS_PRIORITY_DEFAULT); - return; + return; } -virtual ~RsGxsRecognReqItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsGxsRecognReqItem(){} + virtual void clear(); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t issued_at; uint32_t period; @@ -82,16 +79,15 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0); class RsGxsRecognTagItem: public RsItem { public: - RsGxsRecognTagItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, - RS_PKT_SUBTYPE_RECOGN_TAG) + RsGxsRecognTagItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, RS_PKT_SUBTYPE_RECOGN_TAG) { setPriorityLevel(QOS_PRIORITY_DEFAULT); return; } -virtual ~RsGxsRecognTagItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsGxsRecognTagItem(){} + virtual void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t valid_from; uint32_t valid_to; @@ -107,52 +103,30 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0); class RsGxsRecognSignerItem: public RsItem { - public: - RsGxsRecognSignerItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, - RS_PKT_SUBTYPE_RECOGN_SIGNER) - { +public: + RsGxsRecognSignerItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN, RS_PKT_SUBTYPE_RECOGN_SIGNER) + { setPriorityLevel(QOS_PRIORITY_DEFAULT); - return; + return; } -virtual ~RsGxsRecognSignerItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsGxsRecognSignerItem(){} + virtual void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvServiceIdSet signing_classes; - RsTlvPublicRSAKey key; // has from->to, and flags. + RsTlvPublicRSAKey key; // has from->to, and flags. RsTlvKeySignature sign; }; -class RsGxsRecognSerialiser: public RsSerialType +class RsGxsRecognSerialiser: public RsServiceSerializer { public: - RsGxsRecognSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_RECOGN) - { return; } -virtual ~RsGxsRecognSerialiser() - { 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 sizeReq(RsGxsRecognReqItem *); -virtual bool serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *size); -virtual RsGxsRecognReqItem *deserialiseReq(void *data, uint32_t *size); - -virtual uint32_t sizeTag(RsGxsRecognTagItem *); -virtual bool serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *size); -virtual RsGxsRecognTagItem *deserialiseTag(void *data, uint32_t *size); - -virtual uint32_t sizeSigner(RsGxsRecognSignerItem *); -virtual bool serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *size); -virtual RsGxsRecognSignerItem *deserialiseSigner(void *data, uint32_t *size); + RsGxsRecognSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_GXS_RECOGN) {} + virtual ~RsGxsRecognSerialiser() {} + virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const; }; /**************************************************************************/ From 5cba0059c85ac7df40f4681199b5794d13a05097 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 28 Apr 2017 23:32:47 +0200 Subject: [PATCH 086/106] moved recognitems to rsitems/ --- libretroshare/src/libretroshare.pro | 4 ++-- libretroshare/src/{serialiser => rsitems}/rsgxsrecognitems.cc | 3 +-- libretroshare/src/{serialiser => rsitems}/rsgxsrecognitems.h | 0 libretroshare/src/services/p3idservice.h | 2 +- libretroshare/src/util/rsrecogn.h | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rsgxsrecognitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rsgxsrecognitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 60fad8f7b..679e7c31a 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -485,7 +485,7 @@ HEADERS += rsitems/rsitem.h \ rsitems/rsdiscovery2items.h \ rsitems/rsheartbeatitems.h \ rsitems/rsrttitems.h \ - serialiser/rsgxsrecognitems.h \ + rsitems/rsgxsrecognitems.h \ rsitems/rsgxsupdateitems.h \ rsitems/rsserviceinfoitems.h \ @@ -630,7 +630,7 @@ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsbwctrlitems.cc \ rsitems/rsdiscovery2items.cc \ rsitems/rsrttitems.cc \ - serialiser/rsgxsrecognitems.cc \ + rsitems/rsgxsrecognitems.cc \ rsitems/rsgxsupdateitems.cc \ rsitems/rsserviceinfoitems.cc \ diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.cc b/libretroshare/src/rsitems/rsgxsrecognitems.cc similarity index 99% rename from libretroshare/src/serialiser/rsgxsrecognitems.cc rename to libretroshare/src/rsitems/rsgxsrecognitems.cc index a95cf8f60..100ede2ba 100644 --- a/libretroshare/src/serialiser/rsgxsrecognitems.cc +++ b/libretroshare/src/rsitems/rsgxsrecognitems.cc @@ -23,8 +23,7 @@ * */ -#include "serialiser/rsgxsrecognitems.h" -#include "serialiser/rsbaseserial.h" +#include "rsitems/rsgxsrecognitems.h" #include "serialization/rstypeserializer.h" /*** diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.h b/libretroshare/src/rsitems/rsgxsrecognitems.h similarity index 100% rename from libretroshare/src/serialiser/rsgxsrecognitems.h rename to libretroshare/src/rsitems/rsgxsrecognitems.h diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index caf29ee73..f745aca83 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -43,7 +43,7 @@ #include "pqi/authgpg.h" -#include "serialiser/rsgxsrecognitems.h" +#include "rsitems/rsgxsrecognitems.h" class PgpAuxUtils; diff --git a/libretroshare/src/util/rsrecogn.h b/libretroshare/src/util/rsrecogn.h index 6909a34ce..4f7b7cd2e 100644 --- a/libretroshare/src/util/rsrecogn.h +++ b/libretroshare/src/util/rsrecogn.h @@ -33,7 +33,7 @@ #include #include -#include "serialiser/rsgxsrecognitems.h" +#include "rsitems/rsgxsrecognitems.h" #include "retroshare/rsgxsifacetypes.h" namespace RsRecogn { From 77adc82aa278f958d4b16befb44fdbfc1eb57c32 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 29 Apr 2017 17:32:23 +0200 Subject: [PATCH 087/106] Fix Missing messages when mark all as read. If message get olders versions, these ones was not marked as read. So it left unread messages on thread despite nothing appears on tree view. --- libretroshare/src/gxs/rsgxsdata.cc | 10 +++++++--- .../src/gui/gxsforums/GxsForumThreadWidget.cpp | 14 +++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsdata.cc b/libretroshare/src/gxs/rsgxsdata.cc index 090a7b602..de1ce4024 100644 --- a/libretroshare/src/gxs/rsgxsdata.cc +++ b/libretroshare/src/gxs/rsgxsdata.cc @@ -239,17 +239,21 @@ void RsGxsMsgMetaData::clear() mMsgId.clear(); mThreadId.clear(); mParentId.clear(); - mAuthorId.clear(); mOrigMsgId.clear(); - mMsgName.clear(); - mServiceString.clear(); + mAuthorId.clear(); signSet.TlvClear(); + mMsgName.clear(); mPublishTs = 0; mMsgFlags = 0; + + mServiceString.clear(); mMsgStatus = 0; + mMsgSize = 0; mChildTs = 0; recvTS = 0; + mHash.clear(); + validated = false; } bool RsGxsMsgMetaData::serialise(void *data, uint32_t *size) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 6afa8dbdd..6402d130a 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -1844,11 +1844,23 @@ void GxsForumThreadWidget::setMsgReadStatus(QList &rows, bool // LIKE THIS BELOW... //std::string grpId = (*Row)->data(COLUMN_THREAD_DATA, ROLE_THREAD_GROUPID).toString().toStdString(); - RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), RsGxsMessageId(msgId)); + RsGxsGrpMsgIdPair msgPair = std::make_pair( groupId(), RsGxsMessageId(msgId) ); uint32_t token; rsGxsForums->setMessageReadStatus(token, msgPair, read); + // Look if older version exist to mark them too + QMap > >::const_iterator it = mPostVersions.find(mOrigThreadId) ; + if(it != mPostVersions.end()) + { + std::cerr << (*it).size() << " versions found " << std::endl; + for(int i=0;i<(*it).size();++i) + { + msgPair = std::make_pair( groupId(), (*it)[i].second ); + rsGxsForums->setMessageReadStatus(token, msgPair, read); + } + } + /* Add message id to ignore list for the next updateDisplay */ mIgnoredMsgId.push_back(RsGxsMessageId(msgId)); From d58c638af893d68dcd7ba5fcd1d4d423fbe7ec58 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Apr 2017 21:46:54 +0200 Subject: [PATCH 088/106] switched wiki and wire items to new serialization --- libretroshare/src/serialiser/rswikiitems.cc | 47 +++++++++++++++ libretroshare/src/serialiser/rswikiitems.h | 66 +++++++-------------- libretroshare/src/serialiser/rswireitems.cc | 39 +++++++++++- libretroshare/src/serialiser/rswireitems.h | 42 +++++-------- 4 files changed, 120 insertions(+), 74 deletions(-) diff --git a/libretroshare/src/serialiser/rswikiitems.cc b/libretroshare/src/serialiser/rswikiitems.cc index fa4b2be72..dbd747b9a 100644 --- a/libretroshare/src/serialiser/rswikiitems.cc +++ b/libretroshare/src/serialiser/rswikiitems.cc @@ -31,7 +31,22 @@ #define GXSID_DEBUG 1 +RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_GXS_TYPE_WIKI) + return NULL ; + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM: return new RsGxsWikiCollectionItem(); + case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM: return new RsGxsWikiCommentItem(); + case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM: return new RsGxsWikiSnapshotItem(); + default: + return NULL ; + } +} + +#ifdef TO_REMOVE uint32_t RsGxsWikiSerialiser::size(RsItem *item) { RsGxsWikiCollectionItem* grp_item = NULL; @@ -117,6 +132,7 @@ RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size) /*****************************************************************************************/ /*****************************************************************************************/ +#endif void RsGxsWikiCollectionItem::clear() { @@ -125,6 +141,7 @@ void RsGxsWikiCollectionItem::clear() collection.mHashTags.clear(); } +#ifdef TO_REMOVE std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsWikiCollectionItem", indent); @@ -154,7 +171,16 @@ uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem return s; } +#endif +void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_CATEGORY,collection.mCategory ,"collection.mCategory") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ; +} + +#ifdef TO_REMOVE bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size) { @@ -277,6 +303,7 @@ RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(v /*****************************************************************************************/ /*****************************************************************************************/ +#endif void RsGxsWikiSnapshotItem::clear() { @@ -284,6 +311,7 @@ void RsGxsWikiSnapshotItem::clear() snapshot.mHashTags.clear(); } +#ifdef TO_REMOVE std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsWikiSnapshotItem", indent); @@ -311,7 +339,15 @@ uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *ite return s; } +#endif +void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ; +} + +#ifdef TO_REMOVE bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size) { @@ -431,12 +467,14 @@ RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void /*****************************************************************************************/ /*****************************************************************************************/ +#endif void RsGxsWikiCommentItem::clear() { comment.mComment.clear(); } +#ifdef TO_REMOVE std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsWikiCommentItem", indent); @@ -460,7 +498,14 @@ uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item) return s; } +#endif +void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ; +} + +#ifdef TO_REMOVE bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size) { @@ -578,3 +623,5 @@ RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *d /*****************************************************************************************/ /*****************************************************************************************/ + +#endif diff --git a/libretroshare/src/serialiser/rswikiitems.h b/libretroshare/src/serialiser/rswikiitems.h index 4247f9d3b..a50102ab4 100644 --- a/libretroshare/src/serialiser/rswikiitems.h +++ b/libretroshare/src/serialiser/rswikiitems.h @@ -29,28 +29,24 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -//#include "serialiser/rstlvtypes.h" +#include "rsitems/rsitem.h" -#include "rsgxsitems.h" +#include "serialiser/rsgxsitems.h" #include "retroshare/rswiki.h" const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02; -const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03; -const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04; +const uint8_t RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM = 0x03; +const uint8_t RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM = 0x04; class RsGxsWikiCollectionItem : public RsGxsGrpItem { - public: + RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) {} + virtual ~RsGxsWikiCollectionItem() {} - RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIKI, - RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;} - virtual ~RsGxsWikiCollectionItem() { return;} - - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void clear(); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsWikiCollection collection; }; @@ -59,11 +55,12 @@ class RsGxsWikiSnapshotItem : public RsGxsMsgItem { public: - RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, - RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; } - virtual ~RsGxsWikiSnapshotItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {} + virtual ~RsGxsWikiSnapshotItem() {} + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsWikiSnapshot snapshot; }; @@ -71,42 +68,23 @@ class RsGxsWikiCommentItem : public RsGxsMsgItem { public: - RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, - RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; } - virtual ~RsGxsWikiCommentItem() { return; } + RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIKI, RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) {} + virtual ~RsGxsWikiCommentItem() {} void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsWikiComment comment; }; -class RsGxsWikiSerialiser : public RsSerialType +class RsGxsWikiSerialiser : public RsServiceSerializer { public: - RsGxsWikiSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_WIKI) - { return; } - virtual ~RsGxsWikiSerialiser() { return; } - - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item); - bool serialiseGxsWikiCollectionItem (RsGxsWikiCollectionItem *item, void *data, uint32_t *size); - RsGxsWikiCollectionItem * deserialiseGxsWikiCollectionItem(void *data, uint32_t *size); - - uint32_t sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item); - bool serialiseGxsWikiSnapshotItem (RsGxsWikiSnapshotItem *item, void *data, uint32_t *size); - RsGxsWikiSnapshotItem * deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size); - - uint32_t sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item); - bool serialiseGxsWikiCommentItem (RsGxsWikiCommentItem *item, void *data, uint32_t *size); - RsGxsWikiCommentItem * deserialiseGxsWikiCommentItem(void *data, uint32_t *size); + RsGxsWikiSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_WIKI) {} + virtual ~RsGxsWikiSerialiser() {} + virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const; }; #endif /* RS_WIKI_ITEMS_H */ diff --git a/libretroshare/src/serialiser/rswireitems.cc b/libretroshare/src/serialiser/rswireitems.cc index 68ec68741..988189b60 100644 --- a/libretroshare/src/serialiser/rswireitems.cc +++ b/libretroshare/src/serialiser/rswireitems.cc @@ -26,12 +26,27 @@ #include #include "rswireitems.h" -#include "serialiser/rstlvbase.h" -#include "serialiser/rsbaseserial.h" + +#include "serialization/rstypeserializer.h" #define WIRE_DEBUG 1 +RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) const +{ + if(service != RS_SERVICE_GXS_TYPE_WIRE) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem(); + case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem(); + default: + return NULL ; + } +} + +#ifdef TO_REMOVE uint32_t RsGxsWireSerialiser::size(RsItem *item) { RsGxsWireGroupItem* grp_item = NULL; @@ -104,12 +119,14 @@ RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size) /*****************************************************************************************/ /*****************************************************************************************/ +#endif void RsGxsWireGroupItem::clear() { group.mDescription.clear(); } +#ifdef TO_REMOVE std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsWireGroupItem", indent); @@ -134,6 +151,14 @@ uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item) return s; } +#endif + +void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ; +} + +#ifdef TO_REMOVE bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size) { @@ -287,6 +312,15 @@ uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item) return s; } +#endif + +void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ; + RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ; +} + +#ifdef TO_REMOVE bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size) { @@ -406,3 +440,4 @@ RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, /*****************************************************************************************/ /*****************************************************************************************/ +#endif diff --git a/libretroshare/src/serialiser/rswireitems.h b/libretroshare/src/serialiser/rswireitems.h index 77258707a..137619aa6 100644 --- a/libretroshare/src/serialiser/rswireitems.h +++ b/libretroshare/src/serialiser/rswireitems.h @@ -43,13 +43,12 @@ class RsGxsWireGroupItem : public RsGxsGrpItem public: - RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIRE, - RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;} - virtual ~RsGxsWireGroupItem() { return;} + RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_WIRE, RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) {} + virtual ~RsGxsWireGroupItem() {} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void clear(); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsWireGroup group; }; @@ -58,36 +57,23 @@ class RsGxsWirePulseItem : public RsGxsMsgItem { public: - RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIRE, - RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; } - virtual ~RsGxsWirePulseItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_WIRE, RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {} + virtual ~RsGxsWirePulseItem() {} + void clear(); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + RsWirePulse pulse; }; -class RsGxsWireSerialiser : public RsSerialType +class RsGxsWireSerialiser : public RsServiceSerializer { public: - RsGxsWireSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_WIRE) - { return; } - virtual ~RsGxsWireSerialiser() { return; } + RsGxsWireSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_WIRE) {} + virtual ~RsGxsWireSerialiser() {} - uint32_t size(RsItem *item); - bool serialise (RsItem *item, void *data, uint32_t *size); - RsItem * deserialise(void *data, uint32_t *size); - - private: - - uint32_t sizeGxsWireGroupItem(RsGxsWireGroupItem *item); - bool serialiseGxsWireGroupItem (RsGxsWireGroupItem *item, void *data, uint32_t *size); - RsGxsWireGroupItem * deserialiseGxsWireGroupItem(void *data, uint32_t *size); - - uint32_t sizeGxsWirePulseItem(RsGxsWirePulseItem *item); - bool serialiseGxsWirePulseItem (RsGxsWirePulseItem *item, void *data, uint32_t *size); - RsGxsWirePulseItem * deserialiseGxsWirePulseItem(void *data, uint32_t *size); + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const ; }; #endif /* RS_WIKI_ITEMS_H */ From 1159c863a228ca8bd0dcb8664637c737f1df8f41 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Apr 2017 21:50:55 +0200 Subject: [PATCH 089/106] moved wiki and wire items to rsitems/ --- libretroshare/src/libretroshare.pro | 8 ++++---- libretroshare/src/{serialiser => rsitems}/rswikiitems.cc | 4 ++-- libretroshare/src/{serialiser => rsitems}/rswikiitems.h | 2 +- libretroshare/src/{serialiser => rsitems}/rswireitems.cc | 0 libretroshare/src/{serialiser => rsitems}/rswireitems.h | 0 libretroshare/src/services/p3wiki.cc | 2 +- libretroshare/src/services/p3wire.cc | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename libretroshare/src/{serialiser => rsitems}/rswikiitems.cc (99%) rename libretroshare/src/{serialiser => rsitems}/rswikiitems.h (98%) rename libretroshare/src/{serialiser => rsitems}/rswireitems.cc (100%) rename libretroshare/src/{serialiser => rsitems}/rswireitems.h (100%) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 679e7c31a..2c503532a 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -821,20 +821,20 @@ wikipoos { # Wiki Service HEADERS += retroshare/rswiki.h \ services/p3wiki.h \ - serialiser/rswikiitems.h + rsitems/rswikiitems.h SOURCES += services/p3wiki.cc \ - serialiser/rswikiitems.cc \ + rsitems/rswikiitems.cc \ } gxsthewire { # Wire Service HEADERS += retroshare/rswire.h \ services/p3wire.h \ - serialiser/rswireitems.h + rsitems/rswireitems.h SOURCES += services/p3wire.cc \ - serialiser/rswireitems.cc \ + rsitems/rswireitems.cc \ } # Posted Service diff --git a/libretroshare/src/serialiser/rswikiitems.cc b/libretroshare/src/rsitems/rswikiitems.cc similarity index 99% rename from libretroshare/src/serialiser/rswikiitems.cc rename to libretroshare/src/rsitems/rswikiitems.cc index dbd747b9a..8da92ab58 100644 --- a/libretroshare/src/serialiser/rswikiitems.cc +++ b/libretroshare/src/rsitems/rswikiitems.cc @@ -25,9 +25,9 @@ #include -#include "rswikiitems.h" +#include "rsitems/rswikiitems.h" #include "serialiser/rstlvbase.h" -#include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" #define GXSID_DEBUG 1 diff --git a/libretroshare/src/serialiser/rswikiitems.h b/libretroshare/src/rsitems/rswikiitems.h similarity index 98% rename from libretroshare/src/serialiser/rswikiitems.h rename to libretroshare/src/rsitems/rswikiitems.h index a50102ab4..378b77e5a 100644 --- a/libretroshare/src/serialiser/rswikiitems.h +++ b/libretroshare/src/rsitems/rswikiitems.h @@ -30,8 +30,8 @@ #include "rsitems/rsserviceids.h" #include "rsitems/rsitem.h" +#include "rsitems/rsgxsitems.h" -#include "serialiser/rsgxsitems.h" #include "retroshare/rswiki.h" const uint8_t RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM = 0x02; diff --git a/libretroshare/src/serialiser/rswireitems.cc b/libretroshare/src/rsitems/rswireitems.cc similarity index 100% rename from libretroshare/src/serialiser/rswireitems.cc rename to libretroshare/src/rsitems/rswireitems.cc diff --git a/libretroshare/src/serialiser/rswireitems.h b/libretroshare/src/rsitems/rswireitems.h similarity index 100% rename from libretroshare/src/serialiser/rswireitems.h rename to libretroshare/src/rsitems/rswireitems.h diff --git a/libretroshare/src/services/p3wiki.cc b/libretroshare/src/services/p3wiki.cc index d91e3d5df..a707596c1 100644 --- a/libretroshare/src/services/p3wiki.cc +++ b/libretroshare/src/services/p3wiki.cc @@ -25,7 +25,7 @@ #include "services/p3wiki.h" #include "retroshare/rsgxsflags.h" -#include "serialiser/rswikiitems.h" +#include "rsitems/rswikiitems.h" #include "util/rsrandom.h" diff --git a/libretroshare/src/services/p3wire.cc b/libretroshare/src/services/p3wire.cc index 0e525d689..7edce4a4d 100644 --- a/libretroshare/src/services/p3wire.cc +++ b/libretroshare/src/services/p3wire.cc @@ -24,7 +24,7 @@ */ #include "services/p3wire.h" -#include "serialiser/rswireitems.h" +#include "rsitems/rswireitems.h" #include "util/rsrandom.h" From 4fbcc1e85f6f5ca3f7cd89ae865719bbf9a20c04 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 29 Apr 2017 19:47:29 +0200 Subject: [PATCH 090/106] Add Double Click on Name for Chat to add their name in text writer. --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 37e2b589e..ead335091 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -48,6 +48,7 @@ #include "gui/common/FilesDefs.h" #include "gui/common/Emoticons.h" #include "gui/chat/ChatLobbyDialog.h" +#include "gui/gxs/GxsIdDetails.h" #include "util/misc.h" #include "util/HandleRichText.h" #include "gui/chat/ChatUserNotify.h"//For BradCast @@ -65,6 +66,8 @@ #define FMM 2.5//fontMetricsMultiplicator +#define PERSONID "PersonId:" + /***** * #define CHAT_DEBUG 1 *****/ @@ -587,6 +590,9 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) if (ui->textBrowser->checkImage(helpEvent->pos(), imageStr)) { toolTipText = imageStr; } + } else if (toolTipText.startsWith(PERSONID)){ + toolTipText = toolTipText.replace(PERSONID, tr("Person id: ") ); + toolTipText = toolTipText.append(tr("\nDouble click on it to add his name on text writer.") ); } } if (!toolTipText.isEmpty()){ @@ -664,6 +670,39 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) } } } + } else if (obj == ui->textBrowser->viewport()) { + if (event->type() == QEvent::MouseButtonDblClick) { + + QMouseEvent* mouseEvent = static_cast(event); + QTextCursor cursor = ui->textBrowser->cursorForPosition(mouseEvent->pos()); + cursor.select(QTextCursor::WordUnderCursor); + if (!cursor.selectedText().isEmpty()){ + QRegExp rx("getIdDetails(mId, details)){ + QString text = QString("@").append(GxsIdDetails::getName(details)).append(" "); + ui->chatTextEdit->textCursor().insertText(text); + } + } + } + } + + } + + } } else { if (event->type() == QEvent::WindowActivate) { if (isVisible() && (window() == NULL || window()->isActiveWindow())) { @@ -963,9 +1002,13 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx formatMsg.replace(QString(""),QString("").arg(timeStamp)); //replace Name anchors with GXS Id QString strGxsId = ""; - if (!gxsId.isNull()) + if (!gxsId.isNull()) { strGxsId = QString::fromStdString(gxsId.toStdString()); - formatMsg.replace(QString(""),QString("").arg(strGxsId)); + formatMsg.replace(QString("") + ,QString("").arg(strGxsId) ); + } else { + formatMsg.replace(QString(""),""); + } QTextCursor textCursor = QTextCursor(ui->textBrowser->textCursor()); textCursor.movePosition(QTextCursor::End); From 4f92f483fa017598ffa20c7a75ce5509874344b3 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Apr 2017 23:02:44 +0200 Subject: [PATCH 091/106] dwicthed GxsTunnel items to new serialization --- libretroshare/src/gxstunnel/p3gxstunnel.cc | 12 ++- .../src/gxstunnel/rsgxstunnelitems.cc | 91 +++++++++++++++++++ .../src/gxstunnel/rsgxstunnelitems.h | 41 ++------- .../src/serialization/rstypeserializer.h | 16 ++-- 4 files changed, 115 insertions(+), 45 deletions(-) diff --git a/libretroshare/src/gxstunnel/p3gxstunnel.cc b/libretroshare/src/gxstunnel/p3gxstunnel.cc index 3ad4198a9..75f50c7d9 100644 --- a/libretroshare/src/gxstunnel/p3gxstunnel.cc +++ b/libretroshare/src/gxstunnel/p3gxstunnel.cc @@ -1185,7 +1185,9 @@ bool p3GxsTunnelService::locked_sendClearTunnelData(RsGxsTunnelDHPublicKeyItem * // RsTurtleGenericDataItem *gitem = new RsTurtleGenericDataItem ; - uint32_t rssize = item->serial_size() ; + RsGxsTunnelSerialiser ser ; + + uint32_t rssize = ser.size(item); gitem->data_size = rssize + 8 ; gitem->data_bytes = rs_malloc(rssize+8) ; @@ -1198,7 +1200,7 @@ bool p3GxsTunnelService::locked_sendClearTunnelData(RsGxsTunnelDHPublicKeyItem * // by convention, we use a IV of 0 for unencrypted data. memset(gitem->data_bytes,0,8) ; - if(!item->serialise(&((uint8_t*)gitem->data_bytes)[8],rssize)) + if(!ser.serialise(item,&((uint8_t*)gitem->data_bytes)[8],&rssize)) { std::cerr << "(EE) Could not serialise item!!!" << std::endl; delete gitem ; @@ -1220,10 +1222,12 @@ bool p3GxsTunnelService::locked_sendClearTunnelData(RsGxsTunnelDHPublicKeyItem * bool p3GxsTunnelService::locked_sendEncryptedTunnelData(RsGxsTunnelItem *item) { - uint32_t rssize = item->serial_size(); + RsGxsTunnelSerialiser ser; + + uint32_t rssize = ser.size(item); RsTemporaryMemory buff(rssize) ; - if(!item->serialise(buff,rssize)) + if(!ser.serialise(item,buff,&rssize)) { std::cerr << "(EE) GxsTunnelService::sendEncryptedTunnelData(): Could not serialise item!" << std::endl; return false; diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc index be0ff42c7..5f14fe079 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc @@ -28,6 +28,7 @@ #include #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" +#include "serialization/rstypeserializer.h" #include "util/rsprint.h" #include "util/rsmemory.h" @@ -35,6 +36,23 @@ //#define GXS_TUNNEL_ITEM_DEBUG 1 +RsItem *RsGxsTunnelSerialiser::create_item(uint16_t service,uint8_t item_subtype) const +{ + if(service != RS_SERVICE_TYPE_GXS_TUNNEL) + return NULL ; + + switch(item_subtype) + { + case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA: return new RsGxsTunnelDataItem(); + case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK: return new RsGxsTunnelDataAckItem(); + case RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY: return new RsGxsTunnelDHPublicKeyItem(); + case RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS: return new RsGxsTunnelStatusItem(); + default: + return NULL ; + } +} + +#ifdef TO_REMOVE std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent); @@ -87,12 +105,14 @@ std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent) } /*************************************************************************/ +#endif RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem() { BN_free(public_key) ; } +#ifdef TO_REMOVE /*************************************************************************/ RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize) @@ -176,7 +196,54 @@ uint32_t RsGxsTunnelStatusItem::serial_size() return s ; } /*************************************************************************/ +#endif +void RsGxsTunnelDHPublicKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process (j,ctx,public_key,"public_key") ; + RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; + RsTypeSerializer::serial_process(j,ctx,gxs_key,"gxs_key") ; +} + +template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM * const & member) +{ + uint32_t s = BN_num_bytes(member) ; + + if(size < offset + 4 + s) + return false ; + + bool ok = true ; + ok &= setRawUInt32(data, size, &offset, s); + + BN_bn2bin(member,&((unsigned char *)data)[offset]) ; + offset += s ; + + return ok; +} +template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM *& member) +{ + uint32_t s=0 ; + bool ok = true ; + ok &= getRawUInt32(data, size, &offset, &s); + + if(s > size || size - s < offset) + return false ; + + member = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ; + offset += s ; + + return ok; +} +template<> uint32_t RsTypeSerializer::serial_size(BIGNUM * const & member) +{ + return 4 + BN_num_bytes(member) ; +} +template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM * const & /* member */) +{ + std::cerr << "[BIGNUM] : " << name << std::endl; +} + +#ifdef TO_REMOVE bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -211,7 +278,14 @@ bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize) } return ok ; } +#endif +void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,status,"status") ; +} + +#ifdef TO_REMOVE bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -249,7 +323,23 @@ bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize) return ok; } +#endif +void RsGxsTunnelDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,unique_item_counter,"unique_item_counter") ; + RsTypeSerializer::serial_process(j,ctx,flags ,"flags") ; + RsTypeSerializer::serial_process(j,ctx,service_id ,"service_id") ; + + RsTypeSerializer::TlvMemBlock_proxy mem(data,data_size) ; + RsTypeSerializer::serial_process(j,ctx,mem,"data") ; +} +void RsGxsTunnelDataAckItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,unique_item_counter,"unique_item_counter") ; +} + +#ifdef TO_REMOVE bool RsGxsTunnelDataItem::serialise(void *dt, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -489,6 +579,7 @@ RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem( return item ; } +#endif diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.h b/libretroshare/src/gxstunnel/rsgxstunnelitems.h index 4da26da0e..1bec905c8 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.h +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.h @@ -60,10 +60,6 @@ class RsGxsTunnelItem: public RsItem virtual ~RsGxsTunnelItem() {} virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; - - virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor }; /*! @@ -81,10 +77,8 @@ public: virtual ~RsGxsTunnelDataItem() {} virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t unique_item_counter; // this allows to make the item unique uint32_t flags; // mainly NEEDS_HACK? @@ -103,10 +97,8 @@ class RsGxsTunnelStatusItem: public RsGxsTunnelItem RsGxsTunnelStatusItem(void *data,uint32_t size) ; // deserialization virtual ~RsGxsTunnelStatusItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t status ; }; @@ -120,12 +112,10 @@ class RsGxsTunnelDataAckItem: public RsGxsTunnelItem RsGxsTunnelDataAckItem(void *data,uint32_t size) ; // deserialization virtual ~RsGxsTunnelDataAckItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); - uint64_t unique_item_counter ; // unique identifier for that item + uint64_t unique_item_counter ; // unique identifier for that item }; @@ -139,10 +129,8 @@ class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem RsGxsTunnelDHPublicKeyItem(void *data,uint32_t size) ; // deserialization virtual ~RsGxsTunnelDHPublicKeyItem() ; - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() ; // deserialise is handled using a constructor + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // Private data to DH public key item // @@ -157,24 +145,11 @@ class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem const RsGxsTunnelDHPublicKeyItem& operator=(const RsGxsTunnelDHPublicKeyItem&) { return *this ;} }; -class RsGxsTunnelSerialiser: public RsSerialType +class RsGxsTunnelSerialiser: public RsServiceSerializer { public: - RsGxsTunnelSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TUNNEL) {} + RsGxsTunnelSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_GXS_TUNNEL) {} - virtual uint32_t size (RsItem *item) - { - return static_cast(item)->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - return static_cast(item)->serialise(data,*size) ; - } - RsItem *deserialise(void *data, uint32_t *pktsize); -private: - static RsGxsTunnelDataAckItem *deserialise_RsGxsTunnelDataAckItem (void *data, uint32_t size) ; - static RsGxsTunnelDataItem *deserialise_RsGxsTunnelDataItem (void *data, uint32_t size) ; - static RsGxsTunnelStatusItem *deserialise_RsGxsTunnelStatusItem (void *data, uint32_t size) ; - static RsGxsTunnelDHPublicKeyItem *deserialise_RsGxsTunnelDHPublicKeyItem(void *data, uint32_t size) ; + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const ; }; diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 3ed0e9c16..a999a24d0 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -339,15 +339,15 @@ class RsTypeSerializer } protected: - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); - template static uint32_t serial_size(const T& /* member */); - template static void print_data(const std::string& name,const T& /* member */); + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); + template static uint32_t serial_size(const T& /* member */); + template static void print_data(const std::string& name,const T& /* member */); - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, uint16_t type_id,const T& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset,uint16_t type_id, T& member); - template static uint32_t serial_size(uint16_t type_id,const T& /* member */); - template static void print_data(const std::string& name,uint16_t type_id,const T& /* member */); + template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, uint16_t type_id,const T& member); + template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset,uint16_t type_id, T& member); + template static uint32_t serial_size(uint16_t type_id,const T& /* member */); + template static void print_data(const std::string& name,uint16_t type_id,const T& /* member */); template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType& member); template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member); From e401b90e023d9cbc86fdbb58a5cbc5b396244f4f Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 30 Apr 2017 16:05:37 +0200 Subject: [PATCH 092/106] moved rsserializer and rstypeserializer to serialiser/ --- libretroshare/src/chat/rschatitems.cc | 2 +- libretroshare/src/chat/rschatitems.h | 2 +- .../src/file_sharing/rsfilelistitems.cc | 2 +- .../src/file_sharing/rsfilelistitems.h | 2 +- .../src/ft/ftturtlefiletransferitem.cc | 2 +- libretroshare/src/grouter/grouteritems.cc | 2 +- .../src/gxstunnel/rsgxstunnelitems.cc | 2 +- libretroshare/src/libretroshare.pro | 8 +- libretroshare/src/rsitems/rsbanlistitems.cc | 2 +- libretroshare/src/rsitems/rsbanlistitems.h | 2 +- libretroshare/src/rsitems/rsbwctrlitems.h | 4 +- libretroshare/src/rsitems/rsconfigitems.cc | 2 +- libretroshare/src/rsitems/rsconfigitems.h | 2 +- .../src/rsitems/rsdiscovery2items.cc | 2 +- libretroshare/src/rsitems/rsdiscovery2items.h | 2 +- .../src/rsitems/rsfiletransferitems.cc | 2 +- .../src/rsitems/rsfiletransferitems.h | 2 +- .../src/rsitems/rsgxschannelitems.cc | 2 +- libretroshare/src/rsitems/rsgxschannelitems.h | 2 +- libretroshare/src/rsitems/rsgxscircleitems.cc | 2 +- .../src/rsitems/rsgxscommentitems.cc | 2 +- libretroshare/src/rsitems/rsgxsforumitems.cc | 2 +- libretroshare/src/rsitems/rsgxsforumitems.h | 2 +- libretroshare/src/rsitems/rsgxsiditems.cc | 2 +- libretroshare/src/rsitems/rsgxsrecognitems.cc | 2 +- .../src/rsitems/rsgxsreputationitems.cc | 2 +- .../src/rsitems/rsgxsreputationitems.h | 2 +- libretroshare/src/rsitems/rsgxsupdateitems.cc | 2 +- libretroshare/src/rsitems/rshistoryitems.cc | 2 +- libretroshare/src/rsitems/rshistoryitems.h | 2 +- libretroshare/src/rsitems/rsitem.h | 2 +- libretroshare/src/rsitems/rsmsgitems.cc | 2 +- libretroshare/src/rsitems/rsnxsitems.cc | 2 +- libretroshare/src/rsitems/rsphotoitems.cc | 2 +- libretroshare/src/rsitems/rsphotoitems.h | 2 +- libretroshare/src/rsitems/rspluginitems.h | 2 +- libretroshare/src/rsitems/rsposteditems.cc | 2 +- libretroshare/src/rsitems/rsrttitems.cc | 2 +- libretroshare/src/rsitems/rsrttitems.h | 2 +- .../src/rsitems/rsserviceinfoitems.cc | 2 +- libretroshare/src/rsitems/rsstatusitems.h | 2 +- libretroshare/src/rsitems/rswikiitems.cc | 2 +- libretroshare/src/rsitems/rswireitems.cc | 2 +- .../rsserializer.cc | 4 +- .../rsserializer.h | 0 .../rstypeserializer.cc | 0 .../rstypeserializer.h | 2 +- .../src/serialization/serial_test.cc | 196 ------------------ libretroshare/src/turtle/rsturtleitem.cc | 2 +- libretroshare/src/turtle/rsturtleitem.h | 2 +- 50 files changed, 52 insertions(+), 248 deletions(-) rename libretroshare/src/{serialization => serialiser}/rsserializer.cc (98%) rename libretroshare/src/{serialization => serialiser}/rsserializer.h (100%) rename libretroshare/src/{serialization => serialiser}/rstypeserializer.cc (100%) rename libretroshare/src/{serialization => serialiser}/rstypeserializer.h (99%) delete mode 100644 libretroshare/src/serialization/serial_test.cc diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 06bb063a7..2b7dd67d8 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -29,7 +29,7 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #include "chat/rschatitems.h" diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 06de87c7f..ddc0a2b86 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -27,7 +27,7 @@ #include "openssl/bn.h" #include "retroshare/rstypes.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" #include "serialiser/rstlvkeys.h" #include "rsitems/rsserviceids.h" #include "rsitems/itempriorities.h" diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index 6934f29d2..7d91549d4 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -24,7 +24,7 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #include "file_sharing/rsfilelistitems.h" diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 8e45ef251..51e40b9c3 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -35,7 +35,7 @@ #include "serialiser/rstlvkeys.h" #include "gxs/rsgxsdata.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" // These items have "flag type" numbers, but this is not used. diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.cc b/libretroshare/src/ft/ftturtlefiletransferitem.cc index 3009fb87c..44722af4b 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -30,7 +30,7 @@ #include #include -#include +#include void RsTurtleFileMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index 48da81548..c856132db 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -3,7 +3,7 @@ #include "serialiser/rstlvbase.h" #include "grouteritems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /**********************************************************************************************/ /* SERIALISER STUFF */ diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc index 5f14fe079..bb56e93cc 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc @@ -28,7 +28,7 @@ #include #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #include "util/rsprint.h" #include "util/rsmemory.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 2c503532a..f8ea1f6a7 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -770,11 +770,11 @@ SOURCES += gxstunnel/p3gxstunnel.cc \ gxstunnel/rsgxstunnelitems.cc # new serialization code -HEADERS += serialization/rsserializer.h \ - serialization/rstypeserializer.h +HEADERS += serialiser/rsserializer.h \ + serialiser/rstypeserializer.h -SOURCES += serialization/rsserializer.cc \ - serialization/rstypeserializer.cc +SOURCES += serialiser/rsserializer.cc \ + serialiser/rstypeserializer.cc # Identity Service HEADERS += retroshare/rsidentity.h \ diff --git a/libretroshare/src/rsitems/rsbanlistitems.cc b/libretroshare/src/rsitems/rsbanlistitems.cc index 85acfb96c..358d20961 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.cc +++ b/libretroshare/src/rsitems/rsbanlistitems.cc @@ -26,7 +26,7 @@ #include "serialiser/rsbaseserial.h" #include "rsitems/rsbanlistitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsbanlistitems.h b/libretroshare/src/rsitems/rsbanlistitems.h index 836fe1b7e..e5660e55c 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.h +++ b/libretroshare/src/rsitems/rsbanlistitems.h @@ -32,7 +32,7 @@ #include "rsitems/rsitem.h" #include "rsitems/itempriorities.h" #include "serialiser/rstlvbanlist.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" #define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01 #define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM_deprecated 0x02 diff --git a/libretroshare/src/rsitems/rsbwctrlitems.h b/libretroshare/src/rsitems/rsbwctrlitems.h index 570e0d87b..71ec641e1 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.h +++ b/libretroshare/src/rsitems/rsbwctrlitems.h @@ -32,8 +32,8 @@ #include "rsitems/rsserviceids.h" #include "rsitems/itempriorities.h" -#include "serialization/rsserializer.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rsserializer.h" +#include "serialiser/rstypeserializer.h" #define RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM 0x01 diff --git a/libretroshare/src/rsitems/rsconfigitems.cc b/libretroshare/src/rsitems/rsconfigitems.cc index 743e35871..15a8dd624 100644 --- a/libretroshare/src/rsitems/rsconfigitems.cc +++ b/libretroshare/src/rsitems/rsconfigitems.cc @@ -28,7 +28,7 @@ #include "rsitems/rsconfigitems.h" #include "retroshare/rspeers.h" // Needed for RsGroupInfo. -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** * #define RSSERIAL_DEBUG 1 * #define RSSERIAL_ERROR_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsconfigitems.h b/libretroshare/src/rsitems/rsconfigitems.h index bc4b9e824..d4ea41898 100644 --- a/libretroshare/src/rsitems/rsconfigitems.h +++ b/libretroshare/src/rsitems/rsconfigitems.h @@ -39,7 +39,7 @@ #include "serialiser/rstlvkeyvalue.h" #include "serialiser/rstlvaddrs.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" class RsGroupInfo; diff --git a/libretroshare/src/rsitems/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc index f9f19270c..0d1d3a493 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -27,7 +27,7 @@ #include "rsitems/rsdiscovery2items.h" #include "serialiser/rsbaseserial.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #if 0 diff --git a/libretroshare/src/rsitems/rsdiscovery2items.h b/libretroshare/src/rsitems/rsdiscovery2items.h index ce30a2928..012ebe1b5 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.h +++ b/libretroshare/src/rsitems/rsdiscovery2items.h @@ -35,7 +35,7 @@ #include "rsitems/rsitem.h" #include "rsitems/itempriorities.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01; const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02; diff --git a/libretroshare/src/rsitems/rsfiletransferitems.cc b/libretroshare/src/rsitems/rsfiletransferitems.cc index cd0ea088d..7579c9560 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.cc +++ b/libretroshare/src/rsitems/rsfiletransferitems.cc @@ -28,7 +28,7 @@ #include "serialiser/rstlvbase.h" #include "rsitems/rsfiletransferitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** * #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsfiletransferitems.h b/libretroshare/src/rsitems/rsfiletransferitems.h index b0ab0972a..85f6d5eab 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.h +++ b/libretroshare/src/rsitems/rsfiletransferitems.h @@ -34,7 +34,7 @@ #include "rsitems/rsserviceids.h" #include "rsitems/itempriorities.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" const uint8_t RS_PKT_SUBTYPE_FT_DATA_REQUEST = 0x01; const uint8_t RS_PKT_SUBTYPE_FT_DATA = 0x02; diff --git a/libretroshare/src/rsitems/rsgxschannelitems.cc b/libretroshare/src/rsitems/rsgxschannelitems.cc index 789357b4c..a8cc067b1 100644 --- a/libretroshare/src/rsitems/rsgxschannelitems.cc +++ b/libretroshare/src/rsitems/rsgxschannelitems.cc @@ -29,7 +29,7 @@ #include "serialiser/rstlvbase.h" #include "serialiser/rsbaseserial.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const { diff --git a/libretroshare/src/rsitems/rsgxschannelitems.h b/libretroshare/src/rsitems/rsgxschannelitems.h index b4caf5197..b0fc67987 100644 --- a/libretroshare/src/rsitems/rsgxschannelitems.h +++ b/libretroshare/src/rsitems/rsgxschannelitems.h @@ -37,7 +37,7 @@ #include "retroshare/rsgxschannels.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" #include "util/rsdir.h" diff --git a/libretroshare/src/rsitems/rsgxscircleitems.cc b/libretroshare/src/rsitems/rsgxscircleitems.cc index a5937b5ab..40ae6cf5f 100644 --- a/libretroshare/src/rsitems/rsgxscircleitems.cc +++ b/libretroshare/src/rsitems/rsgxscircleitems.cc @@ -27,7 +27,7 @@ #include "rsgxscircleitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" //#define CIRCLE_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsgxscommentitems.cc b/libretroshare/src/rsitems/rsgxscommentitems.cc index 4f655cc13..407f64204 100644 --- a/libretroshare/src/rsitems/rsgxscommentitems.cc +++ b/libretroshare/src/rsitems/rsgxscommentitems.cc @@ -28,7 +28,7 @@ #include "rsgxscommentitems.h" #include "serialiser/rstlvbase.h" #include "serialiser/rsbaseserial.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" //#define GXSCOMMENT_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsgxsforumitems.cc b/libretroshare/src/rsitems/rsgxsforumitems.cc index 462f4fcf6..fb5b8f632 100644 --- a/libretroshare/src/rsitems/rsgxsforumitems.cc +++ b/libretroshare/src/rsitems/rsgxsforumitems.cc @@ -27,7 +27,7 @@ #include "rsgxsforumitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" //#define GXSFORUM_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsgxsforumitems.h b/libretroshare/src/rsitems/rsgxsforumitems.h index 8e8d2bc24..5ce8a84ee 100644 --- a/libretroshare/src/rsitems/rsgxsforumitems.h +++ b/libretroshare/src/rsitems/rsgxsforumitems.h @@ -31,7 +31,7 @@ #include "rsitems/rsserviceids.h" #include "rsitems/rsgxsitems.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" #include "retroshare/rsgxsforums.h" diff --git a/libretroshare/src/rsitems/rsgxsiditems.cc b/libretroshare/src/rsitems/rsgxsiditems.cc index cb5ed324e..5bf55b549 100644 --- a/libretroshare/src/rsitems/rsgxsiditems.cc +++ b/libretroshare/src/rsitems/rsgxsiditems.cc @@ -31,7 +31,7 @@ #include "serialiser/rstlvstring.h" #include "util/rsstring.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #define GXSID_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsgxsrecognitems.cc b/libretroshare/src/rsitems/rsgxsrecognitems.cc index 100ede2ba..81b8d866b 100644 --- a/libretroshare/src/rsitems/rsgxsrecognitems.cc +++ b/libretroshare/src/rsitems/rsgxsrecognitems.cc @@ -24,7 +24,7 @@ */ #include "rsitems/rsgxsrecognitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc index 1a50bf9dc..2a559b052 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.cc +++ b/libretroshare/src/rsitems/rsgxsreputationitems.cc @@ -28,7 +28,7 @@ #include "serialiser/rsbaseserial.h" #include "rsitems/rsgxsreputationitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.h b/libretroshare/src/rsitems/rsgxsreputationitems.h index 7c841bd4e..d4134f745 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.h +++ b/libretroshare/src/rsitems/rsgxsreputationitems.h @@ -37,7 +37,7 @@ #include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsreputations.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" #define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01 #define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02 diff --git a/libretroshare/src/rsitems/rsgxsupdateitems.cc b/libretroshare/src/rsitems/rsgxsupdateitems.cc index 259cd1b4a..50f154cb2 100644 --- a/libretroshare/src/rsitems/rsgxsupdateitems.cc +++ b/libretroshare/src/rsitems/rsgxsupdateitems.cc @@ -23,7 +23,7 @@ * */ -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #include "serialiser/rsbaseserial.h" #include "rsgxsupdateitems.h" diff --git a/libretroshare/src/rsitems/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc index 38f2f0254..3280f8eba 100644 --- a/libretroshare/src/rsitems/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -29,7 +29,7 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rshistoryitems.h b/libretroshare/src/rsitems/rshistoryitems.h index 56d12e559..04d3e9ca7 100644 --- a/libretroshare/src/rsitems/rshistoryitems.h +++ b/libretroshare/src/rsitems/rshistoryitems.h @@ -31,7 +31,7 @@ #include "rsitems/rsconfigitems.h" #include "retroshare/rstypes.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" /**************************************************************************/ diff --git a/libretroshare/src/rsitems/rsitem.h b/libretroshare/src/rsitems/rsitem.h index f7f6dae54..8dbda2fb3 100644 --- a/libretroshare/src/rsitems/rsitem.h +++ b/libretroshare/src/rsitems/rsitem.h @@ -2,7 +2,7 @@ #include "util/smallobject.h" #include "retroshare/rstypes.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" class RsItem: public RsMemoryManagement::SmallObject { diff --git a/libretroshare/src/rsitems/rsmsgitems.cc b/libretroshare/src/rsitems/rsmsgitems.cc index 20c98ad1b..09f305fc7 100644 --- a/libretroshare/src/rsitems/rsmsgitems.cc +++ b/libretroshare/src/rsitems/rsmsgitems.cc @@ -31,7 +31,7 @@ #include "rsitems/rsmsgitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsnxsitems.cc b/libretroshare/src/rsitems/rsnxsitems.cc index bfea43843..d6eb8b143 100644 --- a/libretroshare/src/rsitems/rsnxsitems.cc +++ b/libretroshare/src/rsitems/rsnxsitems.cc @@ -2,7 +2,7 @@ #include "util/rsprint.h" #include -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*** * #define RSSERIAL_DEBUG 1 diff --git a/libretroshare/src/rsitems/rsphotoitems.cc b/libretroshare/src/rsitems/rsphotoitems.cc index 9c2f217d9..9c9ff2d02 100644 --- a/libretroshare/src/rsitems/rsphotoitems.cc +++ b/libretroshare/src/rsitems/rsphotoitems.cc @@ -28,7 +28,7 @@ #include "rsitems/rsphotoitems.h" #include "serialiser/rstlvbinary.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #define GXS_PHOTO_SERIAL_DEBUG diff --git a/libretroshare/src/rsitems/rsphotoitems.h b/libretroshare/src/rsitems/rsphotoitems.h index cbaf29700..3819edb88 100644 --- a/libretroshare/src/rsitems/rsphotoitems.h +++ b/libretroshare/src/rsitems/rsphotoitems.h @@ -32,7 +32,7 @@ #include "rsitems/rsgxsitems.h" #include "serialiser/rsserial.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" #include "retroshare/rsphoto.h" diff --git a/libretroshare/src/rsitems/rspluginitems.h b/libretroshare/src/rsitems/rspluginitems.h index d21533c68..f5ff61321 100644 --- a/libretroshare/src/rsitems/rspluginitems.h +++ b/libretroshare/src/rsitems/rspluginitems.h @@ -29,7 +29,7 @@ #include "rsitems/rsitem.h" #include "rsitems/rsconfigitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ; diff --git a/libretroshare/src/rsitems/rsposteditems.cc b/libretroshare/src/rsitems/rsposteditems.cc index 652abed05..378153df3 100644 --- a/libretroshare/src/rsitems/rsposteditems.cc +++ b/libretroshare/src/rsitems/rsposteditems.cc @@ -25,7 +25,7 @@ */ #include "rsitems/rsposteditems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { diff --git a/libretroshare/src/rsitems/rsrttitems.cc b/libretroshare/src/rsitems/rsrttitems.cc index 2ab7292e5..c4c499f79 100644 --- a/libretroshare/src/rsitems/rsrttitems.cc +++ b/libretroshare/src/rsitems/rsrttitems.cc @@ -32,7 +32,7 @@ #include -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /*************************************************************************/ diff --git a/libretroshare/src/rsitems/rsrttitems.h b/libretroshare/src/rsitems/rsrttitems.h index 8f635c3b9..35cf85bae 100644 --- a/libretroshare/src/rsitems/rsrttitems.h +++ b/libretroshare/src/rsitems/rsrttitems.h @@ -33,7 +33,7 @@ #include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" /**************************************************************************/ diff --git a/libretroshare/src/rsitems/rsserviceinfoitems.cc b/libretroshare/src/rsitems/rsserviceinfoitems.cc index 35ba6d02d..d0d2070ab 100644 --- a/libretroshare/src/rsitems/rsserviceinfoitems.cc +++ b/libretroshare/src/rsitems/rsserviceinfoitems.cc @@ -24,7 +24,7 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #include "rsitems/rsserviceinfoitems.h" /*** diff --git a/libretroshare/src/rsitems/rsstatusitems.h b/libretroshare/src/rsitems/rsstatusitems.h index 8c0316a9b..8a8a946b7 100644 --- a/libretroshare/src/rsitems/rsstatusitems.h +++ b/libretroshare/src/rsitems/rsstatusitems.h @@ -30,7 +30,7 @@ #include "rsitems/itempriorities.h" #include "rsitems/rsitem.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" /**************************************************************************/ diff --git a/libretroshare/src/rsitems/rswikiitems.cc b/libretroshare/src/rsitems/rswikiitems.cc index 8da92ab58..ec42e14f0 100644 --- a/libretroshare/src/rsitems/rswikiitems.cc +++ b/libretroshare/src/rsitems/rswikiitems.cc @@ -27,7 +27,7 @@ #include "rsitems/rswikiitems.h" #include "serialiser/rstlvbase.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #define GXSID_DEBUG 1 diff --git a/libretroshare/src/rsitems/rswireitems.cc b/libretroshare/src/rsitems/rswireitems.cc index 988189b60..55a56a803 100644 --- a/libretroshare/src/rsitems/rswireitems.cc +++ b/libretroshare/src/rsitems/rswireitems.cc @@ -27,7 +27,7 @@ #include "rswireitems.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" #define WIRE_DEBUG 1 diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialiser/rsserializer.cc similarity index 98% rename from libretroshare/src/serialization/rsserializer.cc rename to libretroshare/src/serialiser/rsserializer.cc index f9619e839..bc1c9f92a 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialiser/rsserializer.cc @@ -3,8 +3,8 @@ #include "rsitems/rsitem.h" #include "util/rsprint.h" -#include "serialization/rsserializer.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rsserializer.h" +#include "serialiser/rstypeserializer.h" const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 ); const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 ); diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h similarity index 100% rename from libretroshare/src/serialization/rsserializer.h rename to libretroshare/src/serialiser/rsserializer.h diff --git a/libretroshare/src/serialization/rstypeserializer.cc b/libretroshare/src/serialiser/rstypeserializer.cc similarity index 100% rename from libretroshare/src/serialization/rstypeserializer.cc rename to libretroshare/src/serialiser/rstypeserializer.cc diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialiser/rstypeserializer.h similarity index 99% rename from libretroshare/src/serialization/rstypeserializer.h rename to libretroshare/src/serialiser/rstypeserializer.h index a999a24d0..6ad237be9 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialiser/rstypeserializer.h @@ -7,7 +7,7 @@ #include "retroshare/rsflags.h" #include "retroshare/rsids.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" class RsTypeSerializer diff --git a/libretroshare/src/serialization/serial_test.cc b/libretroshare/src/serialization/serial_test.cc deleted file mode 100644 index a8d89a25f..000000000 --- a/libretroshare/src/serialization/serial_test.cc +++ /dev/null @@ -1,196 +0,0 @@ -// COMPILE_LINE: g++ -g serial_test.cc -I.. -o serial_test ../lib/libretroshare.a -lssl -lcrypto -lstdc++ -lpthread -// -// - -#include -#include - -#include "util/rsmemory.h" -#include "util/rsprint.h" -#include "serialiser/rsserial.h" - -#include "rsserializer.h" -#include "rstypeserializer.h" - -#define GET_VARIABLE_NAME(str) #str - -static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff; -static const uint8_t RS_ITEM_SUBTYPE_TEST1 = 0x01 ; - -// Template serialization of RsTypeSerialiser::serial_process() for unknown/new types -// Here we do it for std::set as an example. -// -template<> uint32_t RsTypeSerializer::serial_size(const std::set& s) -{ - return s.size() * 4 + 4 ; -} -template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const std::set& member) -{ - uint32_t tlvsize = serial_size(member) ; - bool ok = true ; - uint32_t offset_save = offset ; - - if(tlvsize + offset > size) - { - std::cerr << "RsTypeSerializer::serialize: error. tlvsize+offset > size, where tlvsize=" << tlvsize << ", offset=" << offset << ", size=" << size << std::endl; - return false ; - } - - ok = ok && RsTypeSerializer::serialize(data,size,offset,member.size()) ; - - for(std::set::const_iterator it(member.begin());it!=member.end();++it) - ok = ok && RsTypeSerializer::serialize(data,size,offset,*it) ; - - if(!ok) - { - std::cerr << "(EE) Cannot serialize std::set" << std::endl; - offset = offset_save ; // return the data in the same condition - } - return ok ; -} - -template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, std::set& member) -{ - bool ok = true ; - uint32_t n = 0 ; - uint32_t offset_save = offset ; - member.clear(); - - ok = ok && RsTypeSerializer::deserialize(data,size,offset,n); - - for(uint32_t i=0;i" << std::endl; - offset = offset_save ; // return the data in the same condition - } - return ok; -} - -template<> void RsTypeSerializer::print_data(const std::string& s,const std::set& set) -{ - std::cerr << " [set] " << s << " : set of size " << set.size() << std::endl; -} - -// New item class. This class needs to define: -// - a serial_process method that tells which members to serialize -// - overload the clear() and print() methods of RsItem -// -class RsTestItem: public RsItem -{ - public: - RsTestItem() : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1) - { - str = "test string"; - ts = time(NULL) ; - - int_set.push_back(lrand48()) ; - int_set.push_back(lrand48()) ; - int_set.push_back(lrand48()) ; - } - - // Derived from RsItem - // - virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx) - { - RsTypeSerializer::TlvString_proxy tt(str,TLV_TYPE_STR_DESCR) ; - - RsTypeSerializer::serial_process(j,ctx,ts ,GET_VARIABLE_NAME(ts) ) ; - RsTypeSerializer::serial_process(j,ctx,tt ,GET_VARIABLE_NAME(str) ) ; - RsTypeSerializer::serial_process(j,ctx,int_set,GET_VARIABLE_NAME(int_set) ) ; - } - - // Derived from RsItem, because they are pure virtuals. Normally print() should disappear soon. - // - virtual void clear() {} - virtual std::ostream& print(std::ostream&,uint16_t) {} - - private: - std::string str ; - uint64_t ts ; - std::vector int_set ; - - friend int main(int argc,char *argv[]); -}; - -// New user-defined serializer class. -// The only required member is the create_item() method, which creates the correct RsItem -// that corresponds to a specific (service,subtype) couple. -// -class RsTestSerializer: public RsSerializer -{ - public: - RsTestSerializer() : RsSerializer(RS_SERVICE_TYPE_TEST) {} - - virtual RsItem *create_item(uint16_t service_id,uint8_t subtype) - { - if(service_id != RS_SERVICE_TYPE_TEST) - return NULL ; - - switch(subtype) - { - case RS_ITEM_SUBTYPE_TEST1: return new RsTestItem(); - - default: - return NULL ; - } - } -}; - -// Methods to check the equality of items. -// -void check(const std::string& s1,const std::string& s2) { assert(s1 == s2) ; } -void check(const uint64_t& s1,const uint64_t& s2) { assert(s1 == s2) ; } -void check(const std::set& s1,const std::set& s2) { assert(s1 == s2) ; } -void check(const std::vector& s1,const std::vector& s2) { assert(s1 == s2) ; } - -int main(int argc,char *argv[]) -{ - try - { - RsTestItem t1 ; - - uint32_t size = RsTestSerializer().size(&t1); - - std::cerr << "t1.serial_size() = " << size << std::endl; - - // Allocate some memory to serialise to - // - RsTemporaryMemory mem1(size); - - std::cerr << "Item to be serialized:" << std::endl; - - RsTestSerializer().print(&t1) ; - RsTestSerializer().serialise(&t1,mem1,&size); - - std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl; - - // Now deserialise into a new item - // - RsItem *t2 = RsTestSerializer().deserialise(mem1,&size); - - // make sure t1 is equal to t2 - // - check(t1.str,dynamic_cast(t2)->str) ; - check(t1.ts,dynamic_cast(t2)->ts) ; - check(t1.int_set,dynamic_cast(t2)->int_set) ; - - delete t2; - - return 0; - } - catch(std::exception& e) - { - std::cerr << "Exception caught: " << e.what() << std::endl; - return 1; - } -} - - diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index 2455c98e5..35b250117 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -6,7 +6,7 @@ #include "rsturtleitem.h" #include "turtleclientservice.h" -#include "serialization/rstypeserializer.h" +#include "serialiser/rstypeserializer.h" //#define P3TURTLE_DEBUG // -----------------------------------------------------------------------------------// diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 8a8a1e49c..78f6155d8 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -13,7 +13,7 @@ #include "retroshare/rstypes.h" #include "turtle/turtletypes.h" -#include "serialization/rsserializer.h" +#include "serialiser/rsserializer.h" const uint8_t RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST = 0x01 ; const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ; From 14076de1e011212eff4f206cd79abf4fde47012f Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 30 Apr 2017 19:17:44 +0200 Subject: [PATCH 093/106] moved code of rsservicerserialiser into rsserializer.h/cc and renamed it into RsRawSerializer --- libretroshare/src/pqi/pqipersongrp.cc | 4 +- libretroshare/src/pqi/pqisslpersongrp.cc | 6 +- libretroshare/src/serialiser/rsserial.h | 19 +-- libretroshare/src/serialiser/rsserializer.cc | 73 +++++++++ libretroshare/src/serialiser/rsserializer.h | 150 +++++++++++++++++- .../src/serialiser/rsserviceserialiser.cc | 74 --------- .../src/serialiser/rsserviceserialiser.h | 10 -- .../src/serialiser/rstypeserializer.cc | 5 +- 8 files changed, 230 insertions(+), 111 deletions(-) diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index a30eb2738..dd9e645a3 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -699,7 +699,7 @@ pqiperson * pqipersongrpDummy::locked_createPerson(const RsPeerId& id, pqilisten NetBinDummy *d1 = new NetBinDummy(pqip, id, PQI_CONNECT_TCP); RsSerialiser *rss = new RsSerialiser(); - rss->addSerialType(new RsServiceSerialiser()); + rss->addSerialType(new RsRawSerialiser()); pqiconnect *pqic = new pqiconnect(pqip, rss, d1); @@ -709,7 +709,7 @@ pqiperson * pqipersongrpDummy::locked_createPerson(const RsPeerId& id, pqilisten NetBinDummy *d2 = new NetBinDummy(pqip, id, PQI_CONNECT_UDP); RsSerialiser *rss2 = new RsSerialiser(); - rss2->addSerialType(new RsServiceSerialiser()); + rss2->addSerialType(new RsRawSerialiser()); pqiconnect *pqic2 = new pqiconnect(pqip, rss2, d2); diff --git a/libretroshare/src/pqi/pqisslpersongrp.cc b/libretroshare/src/pqi/pqisslpersongrp.cc index a1173fd93..ad6ad098c 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.cc +++ b/libretroshare/src/pqi/pqisslpersongrp.cc @@ -87,7 +87,7 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener RsSerialiser *rss = new RsSerialiser(); - rss->addSerialType(new RsServiceSerialiser()); + rss->addSerialType(new RsRawSerialiser()); pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis); @@ -141,7 +141,7 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener ssl_tunnels[id] = pqis ; // keeps for getting crypt info per peer. RsSerialiser *rss = new RsSerialiser(); - rss->addSerialType(new RsServiceSerialiser()); + rss->addSerialType(new RsRawSerialiser()); pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis); @@ -151,7 +151,7 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener pqissludp *pqius = new pqissludp(pqip, mLinkMgr); RsSerialiser *rss2 = new RsSerialiser(); - rss2->addSerialType(new RsServiceSerialiser()); + rss2->addSerialType(new RsRawSerialiser()); pqiconnect *pqiusc = new pqiconnect(pqip, rss2, pqius); diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 248c0a3bc..206f69608 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -65,24 +65,7 @@ const uint8_t RS_PKT_CLASS_CONFIG = 0x02; const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */ class RsItem ; - -class RsSerialType -{ - public: - RsSerialType(uint32_t t); /* only uses top 24bits */ - RsSerialType(uint8_t ver, uint8_t cls, uint8_t t); - RsSerialType(uint8_t ver, uint16_t service); - -virtual ~RsSerialType(); - -virtual uint32_t size(RsItem *); -virtual bool serialise (RsItem *item, void *data, uint32_t *size); -virtual RsItem * deserialise(void *data, uint32_t *size); - -uint32_t PacketId() const; - private: -uint32_t type; -}; +class RsSerialType ; class RsSerialiser diff --git a/libretroshare/src/serialiser/rsserializer.cc b/libretroshare/src/serialiser/rsserializer.cc index bc1c9f92a..ef85008aa 100644 --- a/libretroshare/src/serialiser/rsserializer.cc +++ b/libretroshare/src/serialiser/rsserializer.cc @@ -139,4 +139,77 @@ void RsGenericSerializer::print(RsItem *item) std::cerr << "******************************" << std::endl; } +uint32_t RsRawSerialiser::size(RsItem *i) +{ + RsRawItem *item = dynamic_cast(i); + + if (item) + { + return item->getRawLength(); + } + return 0; +} + +/* serialise the data to the buffer */ +bool RsRawSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) +{ + RsRawItem *item = dynamic_cast(i); + if (!item) + { + return false; + } + + #ifdef RSSERIAL_DEBUG + std::cerr << "RsRawSerialiser::serialise() serializing raw item. pktsize : " << *pktsize; + #endif + + uint32_t tlvsize = item->getRawLength(); + #ifdef RSSERIAL_DEBUG + std::cerr << "tlvsize : " << tlvsize << std::endl; + #endif + + if (*pktsize < tlvsize) + return false; /* not enough space */ + + if (tlvsize > getRsPktMaxSize()) + { + std::cerr << "(EE) Serialised packet is too big. Maximum allowed size is " << getRsPktMaxSize() << ". Serialised size is " << tlvsize << ". Please tune your service to correctly split packets" << std::endl; + return false; /* packet too big */ + } + + *pktsize = tlvsize; + + /* its serialised already!!! */ + memcpy(data, item->getRawData(), tlvsize); + + return true; +} + +RsItem *RsRawSerialiser::deserialise(void *data, uint32_t *pktsize) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + if (RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) + { + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + return NULL; /* not enough data */ + + if (rssize > getRsPktMaxSize()) + return NULL; /* packet too big */ + + /* set the packet length */ + *pktsize = rssize; + + RsRawItem *item = new RsRawItem(rstype, rssize); + void *item_data = item->getRawData(); + + memcpy(item_data, data, rssize); + + return item; +} diff --git a/libretroshare/src/serialiser/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h index 2bea8d23f..639c75806 100644 --- a/libretroshare/src/serialiser/rsserializer.h +++ b/libretroshare/src/serialiser/rsserializer.h @@ -1,5 +1,124 @@ #pragma once +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Retroshare Serialization code // +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Classes +// ======= +// +// RsSerialiser ----------------+ std::map +// +// RsSerialType +// | +// +----------- RsRawSerializer +// | +// +----------- RsGenericSerializer +// | +// +----------- RsConfigSerializer +// | | +// | +----------- Specific config serializers +// | +----------- ... +// | +// +----------- RsServiceSerializer +// | +// +----------- Specific service serializers +// +----------- ... +// +----------- ... +// +// +// Steps to derive a serializer for a new service: +// ============================================== +// +// 1 - create a serializer class, and overload create_item() to create a new item of your own service for each item type constant: +// +// class MyServiceSerializer: public RsServiceSerializer +// { +// MyServiceSerializer() : RsServiceSerializer(MY_SERVICE_IDENTIFIER) {} +// +// RsItem *create_item(uint16_t service,uint8_t item_subtype) +// { +// if(service != MY_SERVICE_IDENTIFIER) return NULL ; +// +// switch(item_subtype) +// { +// case MY_ITEM_SUBTYPE_01: return new MyServiceItem(); +// default: +// return NULL ; +// } +// } +// } +// +// 2 - create your own items, and overload serial_process in order to define the serialized structure: +// +// class MyServiceItem: public RsItem +// { +// virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +// { +// RsTypeSerializer::serial_process (j,ctx,count,"count") ; // uint32_t is not really needed here, except for explicitly avoiding int types convertion +// RsTypeSerializer::serial_process (j,ctx,update_times,"update_times") ; // will serialize the map and its content +// RsTypeSerializer::serial_process(j,ctx,key,"key") ; // note the explicit call to TlvItem +// RsTypeSerializer::serial_process (j,ctx,dh_key,"dh_key") ; // template will automatically require serialise/deserialise/size/print_data for your type +// } +// +// private: +// uint32_t count ; // example of an int type. All int sizes are supported +// std::map update_times ; // example of a std::map. All std containers are supported. +// RsTlvSecurityKey key ; // example of a TlvItem class. +// BIGNUM *dh_key; // example of a class that needs its own serializer (see below) +// }; +// +// Some types may not be already handled by RsTypeSerializer, so in this case, you need to specialise the template for your own type. But this is quite unlikely to +// happen. In most cases, for instance in your structure types, serialization is directly done by calling RsTypeSerializer::serial_process() on each member of the type. +// In case you really need a specific serialization for soe particular type, here is how to do it, with the example of BIGNUM* (a crypto primitive): +// +// template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM * const & member) +// { +// uint32_t s = BN_num_bytes(member) ; +// +// if(size < offset + 4 + s) +// return false ; +// +// bool ok = true ; +// ok &= setRawUInt32(data, size, &offset, s); +// +// BN_bn2bin(member,&((unsigned char *)data)[offset]) ; +// offset += s ; +// +// return ok; +// } +// template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM *& member) +// { +// uint32_t s=0 ; +// bool ok = true ; +// ok &= getRawUInt32(data, size, &offset, &s); +// +// if(s > size || size - s < offset) +// return false ; +// +// member = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ; +// offset += s ; +// +// return ok; +// } +// template<> uint32_t RsTypeSerializer::serial_size(BIGNUM * const & member) +// { +// return 4 + BN_num_bytes(member) ; +// } +// template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM * const & /* member */) +// { +// std::cerr << "[BIGNUM] : " << name << std::endl; +// } +// +// 3 - in your service, overload the serialiser declaration to add your own: +// +// MyService::MyService() +// { +// addSerialType(new MyServiceSerializer()) ; +// } +// +// 4 - in your service, recieve and send items by calling recvItem() and sendItem() respectively. +// #include #include #include @@ -12,6 +131,36 @@ class RsItem ; #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " +class RsSerialType +{ +public: + RsSerialType(uint32_t t); /* only uses top 24bits */ + RsSerialType(uint8_t ver, uint8_t cls, uint8_t t); + RsSerialType(uint8_t ver, uint16_t service); + + virtual ~RsSerialType(); + + virtual uint32_t size(RsItem *)=0; + virtual bool serialise (RsItem *item, void *data, uint32_t *size)=0; + virtual RsItem * deserialise(void *data, uint32_t *size)=0; + + uint32_t PacketId() const; +private: + uint32_t type; +}; + + +class RsRawSerialiser: public RsSerialType +{ + public: + RsRawSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, 0, 0) {} + virtual ~RsRawSerialiser() { } + + virtual uint32_t size(RsItem *); + virtual bool serialise (RsItem *item, void *data, uint32_t *size); + virtual RsItem * deserialise(void *data, uint32_t *size); +}; + class RsGenericSerializer: public RsSerialType { public: @@ -109,4 +258,3 @@ public: - diff --git a/libretroshare/src/serialiser/rsserviceserialiser.cc b/libretroshare/src/serialiser/rsserviceserialiser.cc index 0c953fec3..abdd3e64f 100644 --- a/libretroshare/src/serialiser/rsserviceserialiser.cc +++ b/libretroshare/src/serialiser/rsserviceserialiser.cc @@ -26,78 +26,4 @@ #include "rsitems/rsitem.h" #include "rsserviceserialiser.h" -uint32_t RsServiceSerialiser::size(RsItem *i) -{ - RsRawItem *item = dynamic_cast(i); - - if (item) - { - return item->getRawLength(); - } - return 0; -} - -/* serialise the data to the buffer */ -bool RsServiceSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsRawItem *item = dynamic_cast(i); - if (!item) - { - return false; - } - - #ifdef RSSERIAL_DEBUG - std::cerr << "RsServiceSerialiser::serialise() serializing raw item. pktsize : " << *pktsize; - #endif - - uint32_t tlvsize = item->getRawLength(); - #ifdef RSSERIAL_DEBUG - std::cerr << "tlvsize : " << tlvsize << std::endl; - #endif - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - if (tlvsize > getRsPktMaxSize()) - { - std::cerr << "(EE) Serialised packet is too big. Maximum allowed size is " << getRsPktMaxSize() << ". Serialised size is " << tlvsize << ". Please tune your service to correctly split packets" << std::endl; - return false; /* packet too big */ - } - - *pktsize = tlvsize; - - /* its serialised already!!! */ - memcpy(data, item->getRawData(), tlvsize); - - return true; -} - -RsItem *RsServiceSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - if (RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - if (rssize > getRsPktMaxSize()) - return NULL; /* packet too big */ - - /* set the packet length */ - *pktsize = rssize; - - RsRawItem *item = new RsRawItem(rstype, rssize); - void *item_data = item->getRawData(); - - memcpy(item_data, data, rssize); - - return item; -} - diff --git a/libretroshare/src/serialiser/rsserviceserialiser.h b/libretroshare/src/serialiser/rsserviceserialiser.h index 9bc7d728d..7c00ee3c0 100644 --- a/libretroshare/src/serialiser/rsserviceserialiser.h +++ b/libretroshare/src/serialiser/rsserviceserialiser.h @@ -27,14 +27,4 @@ #include "rsserial.h" -class RsServiceSerialiser: public RsSerialType -{ - public: - RsServiceSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, 0, 0) { } - virtual ~RsServiceSerialiser() { } - - virtual uint32_t size(RsItem *); - virtual bool serialise (RsItem *item, void *data, uint32_t *size); - virtual RsItem * deserialise(void *data, uint32_t *size); -}; diff --git a/libretroshare/src/serialiser/rstypeserializer.cc b/libretroshare/src/serialiser/rstypeserializer.cc index 64ba46f68..fab8c7b2e 100644 --- a/libretroshare/src/serialiser/rstypeserializer.cc +++ b/libretroshare/src/serialiser/rstypeserializer.cc @@ -1,6 +1,5 @@ -#include "serialization/rsserializer.h" -#include "serialization/rstypeserializer.h" - +#include "serialiser/rsserializer.h" +#include "serialiser/rstypeserializer.h" #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvkeys.h" From 24c7c38016efd71f1f1a232c189173ef96250ce2 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 30 Apr 2017 20:08:30 +0200 Subject: [PATCH 094/106] removed old file rssrviceserialiser.h/cc --- libretroshare/src/libretroshare.pro | 2 -- libretroshare/src/pqi/pqipersongrp.cc | 2 +- libretroshare/src/pqi/pqisslpersongrp.cc | 2 +- libretroshare/src/serialiser/rsserializer.h | 8 ++++- .../src/serialiser/rsserviceserialiser.cc | 29 ------------------ .../src/serialiser/rsserviceserialiser.h | 30 ------------------- 6 files changed, 9 insertions(+), 64 deletions(-) delete mode 100644 libretroshare/src/serialiser/rsserviceserialiser.cc delete mode 100644 libretroshare/src/serialiser/rsserviceserialiser.h diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index f8ea1f6a7..dce14eafd 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -456,7 +456,6 @@ HEADERS += rsitems/rsitem.h \ rsitems/itempriorities.h \ serialiser/rsbaseserial.h \ rsitems/rsfiletransferitems.h \ - serialiser/rsserviceserialiser.h \ rsitems/rsconfigitems.h \ rsitems/rshistoryitems.h \ rsitems/rsmsgitems.h \ @@ -609,7 +608,6 @@ SOURCES += plugins/pluginmanager.cc \ SOURCES += serialiser/rsbaseserial.cc \ rsitems/rsfiletransferitems.cc \ - serialiser/rsserviceserialiser.cc \ rsitems/rsconfigitems.cc \ rsitems/rshistoryitems.cc \ rsitems/rsmsgitems.cc \ diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index dd9e645a3..a8afa2b84 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -27,7 +27,7 @@ #include "pqi/p3linkmgr.h" #include "util/rsdebug.h" #include "util/rsprint.h" -#include "serialiser/rsserviceserialiser.h" +#include "serialiser/rsserializer.h" #include diff --git a/libretroshare/src/pqi/pqisslpersongrp.cc b/libretroshare/src/pqi/pqisslpersongrp.cc index ad6ad098c..3670fb5fe 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.cc +++ b/libretroshare/src/pqi/pqisslpersongrp.cc @@ -23,7 +23,7 @@ * */ -#include "serialiser/rsserviceserialiser.h" +#include "serialiser/rsserializer.h" #include "util/rsdebug.h" #include "pqi/pqisslpersongrp.h" diff --git a/libretroshare/src/serialiser/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h index 639c75806..4559b6582 100644 --- a/libretroshare/src/serialiser/rsserializer.h +++ b/libretroshare/src/serialiser/rsserializer.h @@ -117,7 +117,13 @@ // addSerialType(new MyServiceSerializer()) ; // } // -// 4 - in your service, recieve and send items by calling recvItem() and sendItem() respectively. +// If needed, you may serialize your own items by calling: +// +// uint32_t size = MySerializer().size(item) ; +// uint8_t *data = (uint8_t*)malloc(size); +// MySerializer().serialise(item,data,size) ; +// +// 4 - in your service, receive and send items by calling recvItem() and sendItem() respectively. // #include #include diff --git a/libretroshare/src/serialiser/rsserviceserialiser.cc b/libretroshare/src/serialiser/rsserviceserialiser.cc deleted file mode 100644 index abdd3e64f..000000000 --- a/libretroshare/src/serialiser/rsserviceserialiser.cc +++ /dev/null @@ -1,29 +0,0 @@ -/* - * libretroshare/src/serialiser: rsserviceserialiser.cc - * - * 3P/PQI network interface for RetroShare. - * - * Copyright 2013-2013 by Cyril Soler & 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 "rsitems/rsitem.h" -#include "rsserviceserialiser.h" - - diff --git a/libretroshare/src/serialiser/rsserviceserialiser.h b/libretroshare/src/serialiser/rsserviceserialiser.h deleted file mode 100644 index 7c00ee3c0..000000000 --- a/libretroshare/src/serialiser/rsserviceserialiser.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * libretroshare/src/serialiser: rsserviceserialiser.h - * - * 3P/PQI network interface for RetroShare. - * - * Copyright 2013-2013 by Cyril Soler & 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". - * - */ - -#pragma once - -#include "rsserial.h" - - From 16b8947af134da32be7a0a33e5bc5efe2d5ebe90 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 30 Apr 2017 20:31:43 +0200 Subject: [PATCH 095/106] improved serializer documentation --- libretroshare/src/serialiser/rsserializer.cc | 25 ++++++++++++++ libretroshare/src/serialiser/rsserializer.h | 33 +++++++++++++++++++ .../src/serialiser/rstypeserializer.cc | 24 ++++++++++++++ .../src/serialiser/rstypeserializer.h | 24 ++++++++++++++ 4 files changed, 106 insertions(+) diff --git a/libretroshare/src/serialiser/rsserializer.cc b/libretroshare/src/serialiser/rsserializer.cc index ef85008aa..ea6bdd33c 100644 --- a/libretroshare/src/serialiser/rsserializer.cc +++ b/libretroshare/src/serialiser/rsserializer.cc @@ -1,3 +1,28 @@ +/* + * libretroshare/src/serialiser: rsserializer.cc + * + * RetroShare Serialiser. + * + * Copyright 2016 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". + * + */ + #include #include "rsitems/rsitem.h" diff --git a/libretroshare/src/serialiser/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h index 4559b6582..4a325fdab 100644 --- a/libretroshare/src/serialiser/rsserializer.h +++ b/libretroshare/src/serialiser/rsserializer.h @@ -1,3 +1,27 @@ +/* + * libretroshare/src/serialiser: rsserializer.h + * + * RetroShare Serialiser. + * + * Copyright 2016 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 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -137,6 +161,8 @@ class RsItem ; #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " +// This is the base class for serializers. + class RsSerialType { public: @@ -155,6 +181,7 @@ private: uint32_t type; }; +// This class is only used internally to p3service. It should not be used explicitely otherwise. class RsRawSerialiser: public RsSerialType { @@ -167,6 +194,8 @@ class RsRawSerialiser: public RsSerialType virtual RsItem * deserialise(void *data, uint32_t *size); }; +// Top class for all services and config serializers. + class RsGenericSerializer: public RsSerialType { public: @@ -226,6 +255,8 @@ protected: }; +// Top class for service serializers. Derive your on service serializer from this class and overload creat_item(). + class RsServiceSerializer: public RsGenericSerializer { public: @@ -243,6 +274,8 @@ public: RsItem *deserialise(void *data,uint32_t *size) ; }; +// Top class for config serializers. Config serializers are only used internally by RS core. The development of new services or plugins do not need this. + class RsConfigSerializer: public RsGenericSerializer { public: diff --git a/libretroshare/src/serialiser/rstypeserializer.cc b/libretroshare/src/serialiser/rstypeserializer.cc index fab8c7b2e..661897b4b 100644 --- a/libretroshare/src/serialiser/rstypeserializer.cc +++ b/libretroshare/src/serialiser/rstypeserializer.cc @@ -1,3 +1,27 @@ +/* + * libretroshare/src/serialiser: rstypeserializer.cc + * + * RetroShare Serialiser. + * + * Copyright 2017 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". + * + */ #include "serialiser/rsserializer.h" #include "serialiser/rstypeserializer.h" #include "serialiser/rsbaseserial.h" diff --git a/libretroshare/src/serialiser/rstypeserializer.h b/libretroshare/src/serialiser/rstypeserializer.h index 6ad237be9..333f1a364 100644 --- a/libretroshare/src/serialiser/rstypeserializer.h +++ b/libretroshare/src/serialiser/rstypeserializer.h @@ -1,3 +1,27 @@ +/* + * libretroshare/src/serialiser: rstypeserializer.h + * + * RetroShare Serialiser. + * + * Copyright 2017 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 "serialiser/rsserial.h" From 07201e894c66aaf3fb72f669b450701fc6a291ae Mon Sep 17 00:00:00 2001 From: Phenom Date: Mon, 1 May 2017 12:48:11 +0200 Subject: [PATCH 096/106] Fix FriendList Import/Export filename and error message. --- retroshare-gui/src/gui/common/FriendList.cpp | 39 ++++++++++---------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 1bac53b0a..3035cec64 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -1816,25 +1816,26 @@ void FriendList::importFriendlistClicked() */ bool FriendList::importExportFriendlistFileDialog(QString &fileName, bool import) { - if(!misc::getSaveFileName(this, - RshareSettings::LASTDIR_CERT, - (import ? tr("Select file for importing your friendlist from") : - tr("Select a file for exporting your friendlist to")), - tr("XML File (*.xml);;All Files (*)"), - fileName, - NULL, - (import ? QFileDialog::DontConfirmOverwrite : (QFileDialog::Options)0) - )) { - // show error to user - QMessageBox mbox; - mbox.setIcon(QMessageBox::Warning); - mbox.setText(tr("Error")); - mbox.setInformativeText(tr("Failed to get a file!")); - mbox.setStandardButtons(QMessageBox::Ok); - mbox.exec(); - return false; - } - return true; + bool res = true; + if (import) { + res = misc::getOpenFileName(this, RshareSettings::LASTDIR_CERT + , tr("Select file for importing your friendlist from") + , tr("XML File (*.xml);;All Files (*)") + , fileName + , QFileDialog::DontConfirmOverwrite + ); + } else { + res = misc::getSaveFileName(this, RshareSettings::LASTDIR_CERT + , tr("Select a file for exporting your friendlist to") + , tr("XML File (*.xml);;All Files (*)") + , fileName, NULL + , (QFileDialog::Options)0 + ); + } + if ( res && !fileName.endsWith(".xml",Qt::CaseInsensitive) ) + fileName = fileName.append(".xml"); + + return res; } /** From 99d8b7d5d8d26f47368857126be49aabc1a1627f Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 1 May 2017 21:23:34 +0200 Subject: [PATCH 097/106] switched service control items to new serialization --- libretroshare/src/gxs/rsgenexchange.cc | 5 +- libretroshare/src/pqi/p3servicecontrol.cc | 181 ++------------------ libretroshare/src/serialiser/rsserializer.h | 2 +- 3 files changed, 22 insertions(+), 166 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index b946b5931..a970971ff 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -36,6 +36,7 @@ #include "retroshare/rsgrouter.h" #include "retroshare/rsidentity.h" #include "retroshare/rspeers.h" +#include "rsitems/rsnxsitems.h" #include "rsgixs.h" #include "rsgxsutil.h" #include "rsserver/p3face.h" @@ -1293,7 +1294,7 @@ bool RsGenExchange::getSerializedGroupData(const uint32_t &token, RsGxsGroupId& } RsNxsGrp *nxs_grp = *(nxsGrps.begin()); - size = nxs_grp->serial_size() ; + size = RsNxsSerialiser(mServType).size(nxs_grp); id = nxs_grp->metaData->mGroupId ; if(size > 1024*1024 || NULL==(data = (unsigned char *)rs_malloc(size))) @@ -1303,7 +1304,7 @@ bool RsGenExchange::getSerializedGroupData(const uint32_t &token, RsGxsGroupId& return false ; } - return nxs_grp->serialise(data,size) ; + return RsNxsSerialiser(mServType).serialise(nxs_grp,data,&size) ; } bool RsGenExchange::deserializeGroupData(unsigned char *data,uint32_t size) diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index d0d9acbdc..3942232c4 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -28,9 +28,8 @@ #include "p3servicecontrol.h" #include "rsitems/rsserviceids.h" #include "rsitems/rsitem.h" -#include "serialiser/rsserial.h" -#include "serialiser/rsbaseserial.h" -#include "serialiser/rsnxsitems.h" +#include "serialiser/rstypeserializer.h" +#include "rsitems/rsnxsitems.h" #include "pqi/p3cfgmgr.h" #include "pqi/pqiservice.h" @@ -44,184 +43,40 @@ class RsServiceControlItem: public RsItem { public: RsServiceControlItem(uint8_t item_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_SERVICE_CONTROL,item_subtype) {} - - virtual uint32_t serial_size() const =0; - virtual bool serialise(uint8_t *data,uint32_t size) const =0; - - bool serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const - { - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } - #ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; - #endif - offset += 8; - - return true ; - } }; + class RsServicePermissionItem: public RsServiceControlItem, public RsServicePermissions { public: - RsServicePermissionItem() - : RsServiceControlItem(RS_PKT_SUBTYPE_SERVICE_CONTROL_SERVICE_PERMISSIONS) {} - RsServicePermissionItem(const RsServicePermissions& perms) - : RsServiceControlItem(RS_PKT_SUBTYPE_SERVICE_CONTROL_SERVICE_PERMISSIONS), - RsServicePermissions(perms) {} + RsServicePermissionItem(): RsServiceControlItem(RS_PKT_SUBTYPE_SERVICE_CONTROL_SERVICE_PERMISSIONS) {} + RsServicePermissionItem(const RsServicePermissions& perms) : RsServiceControlItem(RS_PKT_SUBTYPE_SERVICE_CONTROL_SERVICE_PERMISSIONS), RsServicePermissions(perms) {} - virtual uint32_t serial_size() const + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - uint32_t s = 8 ; // header + RsTypeSerializer::serial_process(j,ctx,mServiceId,"mServiceId") ; + RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,mServiceName,"mServiceName") ; + RsTypeSerializer::serial_process (j,ctx,mDefaultAllowed,"mDefaultAllowed") ; - s += 4 ; // mServiceId - s += GetTlvStringSize(mServiceName) ; - s += 1 ; // mDefaultAllowed - s += 4 ; // mPeersAllowed.size() - s += mPeersAllowed.size() * RsPeerId::serial_size() ; - s += 4 ; // mPeersAllowed.size() - s += mPeersDenied.size() * RsPeerId::serial_size() ; - - return s ; - } - virtual bool serialise(uint8_t *data,uint32_t size) const - { - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, mServiceId); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, mServiceName); - ok &= setRawUInt8(data, tlvsize, &offset, mDefaultAllowed); - ok &= setRawUInt32(data, tlvsize, &offset, mPeersAllowed.size()); - - for(std::set::const_iterator it(mPeersAllowed.begin());it!=mPeersAllowed.end();++it) - (*it).serialise(data,tlvsize,offset) ; - - ok &= setRawUInt32(data, tlvsize, &offset, mPeersDenied.size()); - - for(std::set::const_iterator it(mPeersDenied.begin());it!=mPeersDenied.end();++it) - (*it).serialise(data,tlvsize,offset) ; - - if(offset != tlvsize) - { - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsGxsChannelSerialiser::serialiseGxsChannelGroupItem() NOK" << std::endl; - - return ok; - } - - static RsServicePermissionItem *deserialise(uint8_t *data, uint32_t size) - { - RsServicePermissionItem *item = new RsServicePermissionItem ; - - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - if(rssize > size) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - return NULL ; - } - - /* add mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &item->mServiceId); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->mServiceName); - - uint8_t v; - ok &= getRawUInt8(data, rssize, &offset, &v) ; - - if (v != 0 && v != 1) - ok = false; - else - item->mDefaultAllowed = (bool)v ; - - uint32_t tmp ; - ok &= getRawUInt32(data, rssize, &offset, &tmp); - - for(uint32_t i=0;imPeersAllowed.insert(peer_id) ; - } - - ok &= getRawUInt32(data, rssize, &offset, &tmp); - - for(uint32_t i=0;imPeersDenied.insert(peer_id) ; - } - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete(item); - return NULL ; - } - - return item; + RsTypeSerializer::serial_process (j,ctx,mPeersAllowed,"mPeersAllowed"); + RsTypeSerializer::serial_process (j,ctx,mPeersDenied ,"mPeersDenied"); } virtual void clear() {} - virtual std::ostream& print(std::ostream& out,uint16_t) - { - std::cerr << __PRETTY_FUNCTION__ << ": not implemented!" << std::endl; - return out ; - } }; -class ServiceControlSerialiser: public RsSerialType +class ServiceControlSerialiser: public RsServiceSerializer { public: - ServiceControlSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICE_CONTROL) {} + ServiceControlSerialiser() : RsServiceSerializer(RS_SERVICE_TYPE_SERVICE_CONTROL) {} - virtual uint32_t size (RsItem *item) + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const { - RsServiceControlItem *scitem = dynamic_cast(item); - if (!scitem) - { - return 0; - } - return scitem->serial_size() ; - } - virtual bool serialise(RsItem *item, void *data, uint32_t *size) - { - RsServiceControlItem *scitem = dynamic_cast(item); - if (!scitem) - { - return false; - } - return scitem->serialise((uint8_t*)data,*size) ; - } - virtual RsItem *deserialise (void *data, uint32_t *size) - { - uint32_t rstype = getRsItemId(data); + if(RS_SERVICE_TYPE_SERVICE_CONTROL != service) + return NULL; - if(RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype) || RS_SERVICE_TYPE_SERVICE_CONTROL != getRsItemService(rstype)) { return NULL; /* wrong type */ } - - switch(getRsItemSubType(rstype)) + switch(item_subtype) { - case RS_PKT_SUBTYPE_SERVICE_CONTROL_SERVICE_PERMISSIONS:return RsServicePermissionItem::deserialise((uint8_t*)data, *size); + case RS_PKT_SUBTYPE_SERVICE_CONTROL_SERVICE_PERMISSIONS: return new RsServicePermissionItem(); default: return NULL ; } diff --git a/libretroshare/src/serialiser/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h index 4a325fdab..c9f1f6403 100644 --- a/libretroshare/src/serialiser/rsserializer.h +++ b/libretroshare/src/serialiser/rsserializer.h @@ -60,7 +60,7 @@ // { // MyServiceSerializer() : RsServiceSerializer(MY_SERVICE_IDENTIFIER) {} // -// RsItem *create_item(uint16_t service,uint8_t item_subtype) +// RsItem *create_item(uint16_t service,uint8_t item_subtype) const // mind the "const"! // { // if(service != MY_SERVICE_IDENTIFIER) return NULL ; // From 861dc165f70e200a3184e84f39c6eae74e9383a9 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 2 May 2017 22:05:54 +0200 Subject: [PATCH 098/106] switched VOIP to new serialization --- plugins/FeedReader/services/p3FeedReader.cc | 2 +- plugins/VOIP/services/p3VOIP.cc | 2 +- plugins/VOIP/services/p3VOIP.h | 2 +- plugins/VOIP/services/rsVOIPItems.cc | 529 ++------------------ plugins/VOIP/services/rsVOIPItems.h | 63 +-- 5 files changed, 52 insertions(+), 546 deletions(-) diff --git a/plugins/FeedReader/services/p3FeedReader.cc b/plugins/FeedReader/services/p3FeedReader.cc index f4f287790..efa3b6688 100644 --- a/plugins/FeedReader/services/p3FeedReader.cc +++ b/plugins/FeedReader/services/p3FeedReader.cc @@ -22,7 +22,7 @@ #include "rsFeedReaderItems.h" #include "p3FeedReader.h" #include "p3FeedReaderThread.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "retroshare/rsiface.h" #include "retroshare/rsgxsforums.h" #include "util/rsstring.h" diff --git a/plugins/VOIP/services/p3VOIP.cc b/plugins/VOIP/services/p3VOIP.cc index b2c3f27bf..4921fe0cc 100644 --- a/plugins/VOIP/services/p3VOIP.cc +++ b/plugins/VOIP/services/p3VOIP.cc @@ -25,7 +25,7 @@ #include "pqi/pqistore.h" #include "pqi/p3linkmgr.h" #include -#include +#include #include // for std::istringstream diff --git a/plugins/VOIP/services/p3VOIP.h b/plugins/VOIP/services/p3VOIP.h index 961496019..4be04af12 100644 --- a/plugins/VOIP/services/p3VOIP.h +++ b/plugins/VOIP/services/p3VOIP.h @@ -27,7 +27,7 @@ #include "services/rsVOIPItems.h" #include "services/p3service.h" #include "serialiser/rstlvbase.h" -#include "serialiser/rsconfigitems.h" +#include "rsitems/rsconfigitems.h" #include "plugins/rspqiservice.h" #include diff --git a/plugins/VOIP/services/rsVOIPItems.cc b/plugins/VOIP/services/rsVOIPItems.cc index cd3132dfd..cf4aefed7 100644 --- a/plugins/VOIP/services/rsVOIPItems.cc +++ b/plugins/VOIP/services/rsVOIPItems.cc @@ -20,8 +20,7 @@ ****************************************************************/ #include -#include "serialiser/rsbaseserial.h" -#include "serialiser/rstlvbase.h" +#include "serialiser/rstypeserializer.h" #include "services/rsVOIPItems.h" @@ -31,505 +30,47 @@ #include -/*************************************************************************/ - -std::ostream& RsVOIPPingItem::print(std::ostream &out, uint16_t indent) +RsItem *RsVOIPSerialiser::create_item(uint16_t service,uint8_t item_subtype) const { - printRsItemBase(out, "RsVOIPPingItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "SeqNo: " << mSeqNo << std::endl; - - printIndent(out, int_Indent); - out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; - - printRsItemEnd(out, "RsVOIPPingItem", indent); - return out; -} - -std::ostream& RsVOIPPongItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsVOIPPongItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "SeqNo: " << mSeqNo << std::endl; - - printIndent(out, int_Indent); - out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; - - printIndent(out, int_Indent); - out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl; - - printRsItemEnd(out, "RsVOIPPongItem", indent); - return out; -} -std::ostream& RsVOIPProtocolItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsVOIPProtocolItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "flags: " << flags << std::endl; - - printIndent(out, int_Indent); - out << "protocol: " << std::hex << (uint32_t)protocol << std::dec << std::endl; - - printRsItemEnd(out, "RsVOIPProtocolItem", indent); - return out; -} -std::ostream& RsVOIPBandwidthItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsVOIPBandwidthItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "flags: " << std::hex << flags << std::dec << std::endl; - - printIndent(out, int_Indent); - out << "speed: " << bytes_per_sec << std::endl; - - printRsItemEnd(out, "RsVOIPBandwidthItem", indent); - return out; -} -std::ostream& RsVOIPDataItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsVOIPDataItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "flags: " << flags << std::endl; - - printIndent(out, int_Indent); - out << "data size: " << std::hex << data_size << std::dec << std::endl; - - printRsItemEnd(out, "RsVOIPDataItem", indent); - return out; -} - -/*************************************************************************/ -uint32_t RsVOIPDataItem::serial_size() const -{ - uint32_t s = 8; /* header */ - s += 4; /* flags */ - s += 4; /* data_size */ - s += data_size; /* data */ - - return s; -} -uint32_t RsVOIPBandwidthItem::serial_size() const -{ - uint32_t s = 8; /* header */ - s += 4; /* flags */ - s += 4; /* bandwidth */ - - return s; -} -uint32_t RsVOIPProtocolItem::serial_size() const -{ - uint32_t s = 8; /* header */ - s += 4; /* flags */ - s += 4; /* protocol */ - - return s; -} -uint32_t RsVOIPPingItem::serial_size() const -{ - uint32_t s = 8; /* header */ - s += 4; /* seqno */ - s += 8; /* pingTS */ - - return s; -} -bool RsVOIPProtocolItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Header: " << ok << std::endl; - std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, (uint32_t)protocol); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl; - } - - return ok; -} -bool RsVOIPBandwidthItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsVOIPSerialiser::serialiseVOIPBandwidthItem() Header: " << ok << std::endl; - std::cerr << "RsVOIPSerialiser::serialiseVOIPBandwidthItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= setRawUInt32(data, tlvsize, &offset, bytes_per_sec); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsVOIPSerialiser::serialiseVOIPBandwidthItem() Size Error! " << std::endl; - } - - return ok; -} -/* serialise the data to the buffer */ -bool RsVOIPDataItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Header: " << ok << std::endl; - std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= setRawUInt32(data, tlvsize, &offset, data_size); - - memcpy( &((uint8_t*)data)[offset],voip_data,data_size) ; - offset += data_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl; - } - - return ok; -} -/* serialise the data to the buffer */ -bool RsVOIPPingItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Header: " << ok << std::endl; - std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, mSeqNo); - ok &= setRawUInt64(data, tlvsize, &offset, mPingTS); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl; - } - - return ok; -} - -RsVOIPProtocolItem::RsVOIPProtocolItem(void *data, uint32_t pktsize) - : RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PROTOCOL != getRsItemSubType(rstype))) - throw std::runtime_error("Wrong packet type!") ; - - if (pktsize < rssize) /* check size */ - throw std::runtime_error("Not enough size!") ; - - bool ok = true; - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint32_t uint_Protocol; - ok &= getRawUInt32(data, rssize, &offset, &uint_Protocol); - protocol = static_cast(uint_Protocol); - ok &= getRawUInt32(data, rssize, &offset, &flags); - - if (offset != rssize) - throw std::runtime_error("Deserialisation error!") ; - - if (!ok) - throw std::runtime_error("Deserialisation error!") ; -} -RsVOIPBandwidthItem::RsVOIPBandwidthItem(void *data, uint32_t pktsize) - : RsVOIPItem(RS_PKT_SUBTYPE_VOIP_BANDWIDTH) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_BANDWIDTH != getRsItemSubType(rstype))) - throw std::runtime_error("Wrong packet type!") ; - - if (pktsize < rssize) /* check size */ - throw std::runtime_error("Not enough size!") ; - - bool ok = true; - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &flags); - ok &= getRawUInt32(data, rssize, &offset, &bytes_per_sec); - - if (offset != rssize) - throw std::runtime_error("Deserialisation error!") ; - - if (!ok) - throw std::runtime_error("Deserialisation error!") ; -} -RsVOIPPingItem::RsVOIPPingItem(void *data, uint32_t pktsize) - : RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PING) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PING != getRsItemSubType(rstype))) - throw std::runtime_error("Wrong packet type!") ; - - if (pktsize < rssize) /* check size */ - throw std::runtime_error("Not enough size!") ; - - bool ok = true; - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &mSeqNo); - ok &= getRawUInt64(data, rssize, &offset, &mPingTS); - - if (offset != rssize) - throw std::runtime_error("Deserialisation error!") ; - - if (!ok) - throw std::runtime_error("Deserialisation error!") ; -} - -/*************************************************************************/ -/*************************************************************************/ - - -uint32_t RsVOIPPongItem::serial_size() const -{ - uint32_t s = 8; /* header */ - s += 4; /* seqno */ - s += 8; /* pingTS */ - s += 8; /* pongTS */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsVOIPPongItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Header: " << ok << std::endl; - std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, mSeqNo); - ok &= setRawUInt64(data, tlvsize, &offset, mPingTS); - ok &= setRawUInt64(data, tlvsize, &offset, mPongTS); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Size Error! " << std::endl; - } - - return ok; -} -RsVOIPDataItem::RsVOIPDataItem(void *data, uint32_t pktsize) - : RsVOIPItem(RS_PKT_SUBTYPE_VOIP_DATA) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_DATA != getRsItemSubType(rstype))) - throw std::runtime_error("Wrong packet subtype") ; - - if (pktsize < rssize) /* check size */ - throw std::runtime_error("Not enough space") ; - - bool ok = true; - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &flags); - ok &= getRawUInt32(data, rssize, &offset, &data_size); - - if(data_size > rssize || rssize - data_size < offset) - throw std::runtime_error("Not enough space.") ; - - voip_data = rs_malloc(data_size) ; - - if(!voip_data) - throw std::runtime_error("Serialization error.") ; - - memcpy(voip_data,&((uint8_t*)data)[offset],data_size) ; - offset += data_size ; - - if (offset != rssize) - throw std::runtime_error("Serialization error.") ; - - if (!ok) - throw std::runtime_error("Serialization error.") ; -} -RsVOIPPongItem::RsVOIPPongItem(void *data, uint32_t pktsize) - : RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PONG) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PONG != getRsItemSubType(rstype))) - throw std::runtime_error("Wrong packet subtype") ; - - if (pktsize < rssize) /* check size */ - throw std::runtime_error("Not enough space") ; - - bool ok = true; - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &mSeqNo); - ok &= getRawUInt64(data, rssize, &offset, &mPingTS); - ok &= getRawUInt64(data, rssize, &offset, &mPongTS); - - if (offset != rssize) - throw std::runtime_error("Serialization error.") ; - - if (!ok) - throw std::runtime_error("Serialization error.") ; -} - -/*************************************************************************/ - -RsItem* RsVOIPSerialiser::deserialise(void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsVOIPSerialiser::deserialise()" << std::endl; -#endif - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype))) + if(service != RS_SERVICE_TYPE_VOIP_PLUGIN) return NULL ; - - try - { - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_VOIP_PING: return new RsVOIPPingItem(data, *pktsize); - case RS_PKT_SUBTYPE_VOIP_PONG: return new RsVOIPPongItem(data, *pktsize); - case RS_PKT_SUBTYPE_VOIP_PROTOCOL: return new RsVOIPProtocolItem(data, *pktsize); - case RS_PKT_SUBTYPE_VOIP_DATA: return new RsVOIPDataItem(data, *pktsize); - default: - return NULL; - } - } - catch(std::exception& e) + switch(item_subtype) { - std::cerr << "RsVOIPSerialiser: deserialization error: " << e.what() << std::endl; - return NULL; + case RS_PKT_SUBTYPE_VOIP_PING: return new RsVOIPPingItem(); + case RS_PKT_SUBTYPE_VOIP_PONG: return new RsVOIPPongItem(); + case RS_PKT_SUBTYPE_VOIP_PROTOCOL: return new RsVOIPProtocolItem(); + case RS_PKT_SUBTYPE_VOIP_DATA: return new RsVOIPDataItem(); + default: + return NULL ; } } +void RsVOIPProtocolItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,protocol,"protocol") ; + RsTypeSerializer::serial_process(j,ctx,flags ,"flags") ; +} + +void RsVOIPPingItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; + RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; +} +void RsVOIPPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; + RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; + RsTypeSerializer::serial_process(j,ctx,mPongTS,"mPongTS") ; +} +void RsVOIPDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,flags ,"flags") ; + + RsTypeSerializer::TlvMemBlock_proxy prox((uint8_t*&)voip_data,data_size) ; + + RsTypeSerializer::serial_process(j,ctx,prox,"data") ; +} /*************************************************************************/ diff --git a/plugins/VOIP/services/rsVOIPItems.h b/plugins/VOIP/services/rsVOIPItems.h index a685f9ef6..222412853 100644 --- a/plugins/VOIP/services/rsVOIPItems.h +++ b/plugins/VOIP/services/rsVOIPItems.h @@ -49,7 +49,7 @@ #include #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" +#include "rsitems/rsitem.h" /**************************************************************************/ @@ -70,31 +70,22 @@ const uint32_t RS_VOIP_FLAGS_AUDIO_DATA = 0x0002 ; class RsVOIPItem: public RsItem { public: - RsVOIPItem(uint8_t voip_subtype) - : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP_PLUGIN,voip_subtype) + RsVOIPItem(uint8_t voip_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP_PLUGIN,voip_subtype) { setPriorityLevel(QOS_PRIORITY_RS_VOIP) ; } virtual ~RsVOIPItem() {} virtual void clear() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; - - virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ? - virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor }; class RsVOIPPingItem: public RsVOIPItem { public: RsVOIPPingItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PING), mSeqNo(0), mPingTS(0) {} - RsVOIPPingItem(void *data,uint32_t size) ; - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() const ; - virtual ~RsVOIPPingItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; @@ -104,17 +95,13 @@ class RsVOIPDataItem: public RsVOIPItem { public: RsVOIPDataItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_DATA) {} - RsVOIPDataItem(void *data,uint32_t size) ; // de-serialization - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() const ; virtual ~RsVOIPDataItem() { free(voip_data) ; voip_data = NULL ; } - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t flags ; uint32_t data_size ; @@ -122,37 +109,31 @@ class RsVOIPDataItem: public RsVOIPItem void *voip_data ; }; +#ifdef TODO class RsVOIPBandwidthItem: public RsVOIPItem { public: RsVOIPBandwidthItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_BANDWIDTH) {} - RsVOIPBandwidthItem(void *data,uint32_t size) ; // de-serialization - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() const ; virtual ~RsVOIPBandwidthItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t flags ; // is that incoming or expected bandwidth? uint32_t bytes_per_sec ; // bandwidth in bytes per sec. }; +#endif class RsVOIPProtocolItem: public RsVOIPItem { public: RsVOIPProtocolItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {} - RsVOIPProtocolItem(void *data,uint32_t size) ; typedef enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3, VoipProtocol_Bandwidth = 4 } en_Protocol; - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() const ; - virtual ~RsVOIPProtocolItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); - en_Protocol protocol ; + uint32_t protocol ; uint32_t flags ; }; @@ -160,38 +141,22 @@ class RsVOIPPongItem: public RsVOIPItem { public: RsVOIPPongItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PONG) {} - RsVOIPPongItem(void *data,uint32_t size) ; - - virtual bool serialise(void *data,uint32_t& size) ; - virtual uint32_t serial_size() const ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual ~RsVOIPPongItem() {} - virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); uint32_t mSeqNo; uint64_t mPingTS; uint64_t mPongTS; }; -class RsVOIPSerialiser: public RsSerialType +class RsVOIPSerialiser: public RsServiceSerializer { public: - RsVOIPSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_VOIP_PLUGIN) - { - } + RsVOIPSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_VOIP_PLUGIN) {} virtual ~RsVOIPSerialiser() {} - virtual uint32_t size (RsItem *item) - { - return dynamic_cast(item)->serial_size() ; - } - - virtual bool serialise (RsItem *item, void *data, uint32_t *size) - { - return dynamic_cast(item)->serialise(data,*size) ; - } - virtual RsItem *deserialise(void *data, uint32_t *size); + virtual RsItem *create_item(uint16_t service,uint8_t item_subtype) const ; }; /**************************************************************************/ From 4bee52c406de7cf6a3c11f97d73f4e5da678861d Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 2 May 2017 22:34:45 +0200 Subject: [PATCH 099/106] removed old unused serialization code --- libretroshare/src/grouter/grouteritems.cc | 822 ------------ libretroshare/src/grouter/p3grouter.cc | 20 - .../src/gxstunnel/rsgxstunnelitems.cc | 459 ------- libretroshare/src/pqi/p3peermgr.cc | 38 - libretroshare/src/rsitems/rsbwctrlitems.cc | 138 -- libretroshare/src/rsitems/rsconfigitems.h | 89 -- .../src/rsitems/rsgxscommentitems.cc | 389 ------ libretroshare/src/rsitems/rsgxsiditems.cc | 616 --------- libretroshare/src/rsitems/rsgxsrecognitems.cc | 548 -------- .../src/rsitems/rsgxsreputationitems.cc | 519 ------- libretroshare/src/rsitems/rshistoryitems.cc | 221 --- libretroshare/src/rsitems/rsnxsitems.cc | 1195 ----------------- libretroshare/src/rsitems/rsrttitems.cc | 334 ----- libretroshare/src/rsitems/rswikiitems.cc | 543 -------- libretroshare/src/rsitems/rswireitems.cc | 379 ------ 15 files changed, 6310 deletions(-) diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index c856132db..5fc4813a7 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -67,81 +67,11 @@ void RsGRouterTransactionChunkItem::serial_process(RsGenericSerializer::Serializ std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl; } -#ifdef TO_REMOVE -RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionChunkItem(void *data, uint32_t tlvsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - if(tlvsize < rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl; - return NULL ; - } - - RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id); - ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_start); - ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_size); - ok &= getRawUInt32(data, tlvsize, &offset, &item->total_size); - - if(item->chunk_size > rssize || offset > rssize - item->chunk_size) // better than if(item->chunk_size + offset > rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl; - delete item; - return NULL ; - } - if( NULL == (item->chunk_data = (uint8_t*)rs_malloc(item->chunk_size))) - { - delete item; - return NULL ; - } - - memcpy(item->chunk_data,&((uint8_t*)data)[offset],item->chunk_size) ; - offset += item->chunk_size ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterTransactionAcknItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; } -#ifdef TO_REMOVE -RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionAcknItem(void *data, uint32_t tlvsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterTransactionAcknItem *item = new RsGRouterTransactionAcknItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,routing_id,"routing_id") ; @@ -174,76 +104,6 @@ void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob } } -#ifdef TO_REMOVE -RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - if(pktsize < rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl; - return NULL ; - } - RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ; - - ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id); - ok &= item->destination_key.deserialise(data, pktsize, offset) ; - ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); - ok &= getRawUInt32(data, pktsize, &offset, &item->data_size); - - if(item->data_size > 0) // This happens when the item data has been deleted from the cache - { - if(item->data_size > rssize || offset > rssize - item->data_size) // better than if(item->data_size + offset > rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl; - delete item; - return NULL ; - } - - if( NULL == (item->data_bytes = (uint8_t*)rs_malloc(item->data_size))) - { - delete item; - return NULL ; - } - - memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ; - offset += item->data_size ; - } - else - item->data_bytes = NULL ; - - ok &= item->signature.GetTlv(data, pktsize, &offset) ; - - ok &= getRawUInt32(data, pktsize, &offset, &item->duplication_factor); - - // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. - - if(item->duplication_factor < 1) - { - item->duplication_factor = 1 ; - std::cerr << "(II) correcting GRouter item duplication factor from 0 to 1, to ensure backward compat." << std::endl; - } - if(item->duplication_factor > GROUTER_MAX_DUPLICATION_FACTOR) - { - std::cerr << "(WW) correcting GRouter item duplication factor of " << item->duplication_factor << ". This is very unexpected." << std::endl; - item->duplication_factor = GROUTER_MAX_DUPLICATION_FACTOR ; - } - - ok &= getRawUInt32(data, pktsize, &offset, &item->flags); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,routing_id,"routing_id") ; @@ -258,33 +118,6 @@ void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJo RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } -#ifdef TO_REMOVE -RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedReceiptItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem() ; - - ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id); - ok &= getRawUInt32(data, pktsize, &offset, &item->flags); - ok &= item->destination_key.deserialise(data, pktsize, offset); - ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); - ok &= item->data_hash.deserialise(data, pktsize, offset); - ok &= item->signature.GetTlv(data, pktsize, &offset); // signature - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; @@ -352,99 +185,11 @@ void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob } } -#ifdef TO_REMOVE -RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ; - - RsPeerId peer_id ; - ok &= peer_id.deserialise(data, pktsize, offset) ; - item->PeerId(peer_id) ; - - ok &= getRawUInt32(data, pktsize, &offset, &item->data_status); - ok &= getRawUInt32(data, pktsize, &offset, &item->tunnel_status); - ok &= getRawTimeT(data, pktsize, &offset, item->received_time_TS); - ok &= getRawTimeT(data, pktsize, &offset, item->last_sent_TS); - - ok &= getRawTimeT(data, pktsize, &offset, item->last_tunnel_request_TS); - ok &= getRawUInt32(data, pktsize, &offset, &item->sending_attempts); - - ok &= getRawUInt32(data, pktsize, &offset, &item->client_id); - ok &= item->item_hash.deserialise(data, pktsize, offset) ; - ok &= item->tunnel_hash.deserialise(data, pktsize, offset) ; - ok &= getRawUInt32(data, pktsize, &offset, &item->routing_flags) ; - - ok &= item->incoming_routes.GetTlv(data,pktsize,&offset) ; - - item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ; - if(item->data_item != NULL) - offset += item->data_item->serial_size() ; - else - ok = false ; - - // Receipt item is optional. - - if (offset < pktsize) - { // - item->receipt_item = deserialise_RsGRouterSignedReceiptItem(&((uint8_t*)data)[offset],pktsize - offset); - if (item->receipt_item != NULL) - offset += item->receipt_item->serial_size(); - else // - ok = false; - } - else // - item->receipt_item = NULL; - - - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterMatrixFriendListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ; } -#ifdef TO_REMOVE -RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterMatrixFriendListItem *item = new RsGRouterMatrixFriendListItem() ; - - uint32_t nb_friends = 0 ; - ok &= getRawUInt32(data, pktsize, &offset, &nb_friends); // file hash - - item->reverse_friend_indices.resize(nb_friends) ; - - for(uint32_t i=0;ok && ireverse_friend_indices[i].deserialise(data, pktsize, offset) ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ; @@ -452,30 +197,6 @@ void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob RsTypeSerializer::serial_process(j,ctx,time_stamp,"time_stamp") ; } -#ifdef TO_REMOVE -RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterMatrixTrackItem *item = new RsGRouterMatrixTrackItem() ; - - ok &= item->provider_id.deserialise(data, pktsize, offset) ; - ok &= item->message_id.deserialise(data,pktsize,offset) ; - ok &= getRawTimeT(data, pktsize, &offset, item->time_stamp) ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ; @@ -489,44 +210,6 @@ template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJ RsTypeSerializer::serial_process (j,ctx,s.time_stamp,name+":time_stamp") ; } -#ifdef TO_REMOVE -RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem() ; - - ok &= item->destination_key.deserialise(data,pktsize,offset) ; - - uint32_t nb_clues = 0 ; - ok &= getRawUInt32(data, pktsize, &offset, &nb_clues); - - item->clues.clear() ; - - for(uint32_t j=0;jclues.push_back(HitE) ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const { RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ; @@ -565,508 +248,3 @@ RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const return item ; } -#ifdef TO_REMOVE -uint32_t RsGRouterGenericDataItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += 4 ; // data_size - s += 4 ; // service id - s += data_size ; // data - s += signature.TlvSize() ; // signature - s += 4 ; // duplication_factor - s += 4 ; // flags - - return s ; -} -uint32_t RsGRouterGenericDataItem::signed_data_size() const -{ - uint32_t s = 0 ; // no header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += 4 ; // data_size - s += 4 ; // service id - s += data_size ; // data - - return s ; -} -uint32_t RsGRouterSignedReceiptItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += data_hash.serial_size() ; - s += 4 ; // state - s += 4 ; // service_id - s += signature.TlvSize() ; // signature - - return s ; -} -uint32_t RsGRouterSignedReceiptItem::signed_data_size() const -{ - uint32_t s = 0 ; // no header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += data_hash.serial_size() ; - s += 4 ; // service_id - s += 4 ; // state - - return s ; -} -uint32_t RsGRouterTransactionChunkItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += 4 ; // chunk_start - s += 4 ; // chunk_size - s += 4 ; // total_size - s += chunk_size ; // data - - return s; -} -uint32_t RsGRouterTransactionAcknItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - - return s; -} -bool RsGRouterTransactionChunkItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, propagation_id); - ok &= setRawUInt32(data, tlvsize, &offset, chunk_start); - ok &= setRawUInt32(data, tlvsize, &offset, chunk_size); - ok &= setRawUInt32(data, tlvsize, &offset, total_size); - - memcpy(&((uint8_t*)data)[offset],chunk_data,chunk_size) ; - offset += chunk_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= destination_key.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= setRawUInt32(data, tlvsize, &offset, data_size); - - memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ; - offset += data_size ; - - ok &= signature.SetTlv(data, tlvsize, &offset) ; - - ok &= setRawUInt32(data, tlvsize, &offset, duplication_factor) ; - ok &= setRawUInt32(data, tlvsize, &offset, flags) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterTransactionAcknItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, propagation_id); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterGenericDataItem::serialise_signed_data(void *data,uint32_t size) const -{ - bool ok = true; - - uint32_t offset = 0; - uint32_t tlvsize = signed_data_size() ; - - if(tlvsize > size) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl; - } - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= destination_key.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= setRawUInt32(data, tlvsize, &offset, data_size); - - memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ; - offset += data_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= destination_key.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= data_hash.serialise(data,tlvsize,offset) ; - ok &= signature.SetTlv(data,tlvsize,&offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t size) const -{ - bool ok = true; - - uint32_t offset=0; - uint32_t tlvsize = signed_data_size() ; - - if(tlvsize > size) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl; - } - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= destination_key.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= data_hash.serialise(data,tlvsize,offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -/* serialise the data to the buffer */ -uint32_t RsGRouterMatrixCluesItem::serial_size() const -{ - uint32_t s = 8 ; // header - - s += destination_key.serial_size() ; // Key size - s += 4 ; // list::size() - s += (4+4+8) * clues.size() ; - - return s ; -} -uint32_t RsGRouterMatrixFriendListItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += 4 ; // reverse_friend_indices.size() - s += RsPeerId::SIZE_IN_BYTES * reverse_friend_indices.size() ; // sha1 for published_key - - return s ; -} - -uint32_t RsGRouterMatrixTrackItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += 8 ; // time_stamp - s += RsPeerId::SIZE_IN_BYTES; // provider_id - s += RsMessageId::SIZE_IN_BYTES; // message_id - - return s ; -} - -uint32_t RsGRouterRoutingInfoItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += PeerId().serial_size() ; - - s += 4 ; // data status_flags - s += 4 ; // tunnel status_flags - s += 8 ; // received_time - s += 8 ; // last_sent_TS - - s += 8 ; // last_TR_TS - s += 4 ; // sending attempts - - s += sizeof(GRouterServiceId) ; // service_id - s += tunnel_hash.serial_size() ; - s += item_hash.serial_size() ; - - s += 4 ; // routing_flags - s += incoming_routes.TlvSize() ; // incoming_routes - - s += data_item->serial_size(); // data_item - - if(receipt_item != NULL) - s += receipt_item->serial_size(); // receipt_item - - return s ; -} - -bool RsGRouterMatrixFriendListItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, reverse_friend_indices.size()); - - for(uint32_t i=0;ok && i::const_iterator it2(clues.begin());it2!=clues.end();++it2) - { - ok &= setRawUInt32(data, tlvsize, &offset, (*it2).friend_id) ; - ok &= setRawUFloat32(data, tlvsize, &offset, (*it2).weight) ; - ok &= setRawTimeT(data, tlvsize, &offset, (*it2).time_stamp) ; - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterMatrixCluesItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -bool RsGRouterMatrixTrackItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= provider_id.serialise(data, tlvsize, offset) ; - ok &= message_id.serialise(data,tlvsize,offset) ; - ok &= setRawTimeT(data, tlvsize, &offset, time_stamp) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterMatrixTrackItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool FriendTrialRecord::deserialise(void *data,uint32_t& offset,uint32_t size) -{ - bool ok = true ; - ok &= friend_id.deserialise(data, size, offset) ; - ok &= getRawTimeT(data, size, &offset, time_stamp) ; - ok &= getRawUFloat32(data, size, &offset, probability) ; - ok &= getRawUInt32(data, size, &offset, &nb_friends) ; - return ok ; -} -bool FriendTrialRecord::serialise(void *data,uint32_t& offset,uint32_t size) const -{ - bool ok = true ; - ok &= friend_id.serialise(data, size, offset) ; - ok &= setRawTimeT(data, size, &offset, time_stamp) ; - ok &= setRawUFloat32(data, size, &offset, probability) ; - ok &= setRawUInt32(data, size, &offset, nb_friends) ; - return ok ; -} -bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= PeerId().serialise(data, tlvsize, offset) ; // we keep this. - ok &= setRawUInt32(data, tlvsize, &offset, data_status) ; - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_status) ; - ok &= setRawTimeT(data, tlvsize, &offset, received_time_TS) ; - ok &= setRawTimeT(data, tlvsize, &offset, last_sent_TS) ; - ok &= setRawTimeT(data, tlvsize, &offset, last_tunnel_request_TS) ; - ok &= setRawUInt32(data, tlvsize, &offset, sending_attempts) ; - - ok &= setRawUInt32(data, tlvsize, &offset, client_id) ; - ok &= item_hash.serialise(data, tlvsize, offset) ; - ok &= tunnel_hash.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, routing_flags) ; - - ok &= incoming_routes.SetTlv(data,tlvsize,&offset) ; - - uint32_t ns = size - offset ; - ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ; - offset += data_item->serial_size() ; - - if(receipt_item != NULL) - { - uint32_t ns = size - offset ; - ok &= receipt_item->serialise( &((uint8_t*)data)[offset], ns) ; - offset += receipt_item->serial_size() ; - } - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterRoutingInfoItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -// -----------------------------------------------------------------------------------// -// ------------------------------------- IO --------------------------------------- // -// -----------------------------------------------------------------------------------// -// - -std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterReceiptItem:" << std::endl ; - o << " direct origin: \""<< PeerId() << "\"" << std::endl ; - o << " Mid: " << std::hex << routing_id << std::dec << std::endl ; - o << " State: " << flags << std::endl ; - o << " Dest: " << destination_key << std::endl ; - o << " Sign: " << signature.keyId << std::endl ; - - return o ; -} -std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterGenericDataItem:" << std::endl ; - o << " Direct origin: \""<< PeerId() << "\"" << std::endl ; - o << " Routing ID: " << std::hex << routing_id << std::dec << "\"" << std::endl ; - o << " Key: " << destination_key.toStdString() << std::endl ; - o << " Data size: " << data_size << std::endl ; - o << " Data hash: " << RsDirUtil::sha1sum(data_bytes,data_size) << std::endl ; - o << " signature key: " << signature.keyId << std::endl; - o << " duplication fac:" << duplication_factor << std::endl; - o << " flags: " << flags << std::endl; - - return o ; -} - -std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterRoutingInfoItem:" << std::endl ; - o << " direct origin: "<< PeerId() << std::endl ; - o << " data status: "<< std::hex<< data_status << std::dec << std::endl ; - o << " tunnel status: "<< tunnel_status << std::endl ; - o << " recv time: "<< received_time_TS << std::endl ; - o << " Last sent: "<< last_sent_TS << std::endl ; - o << " Sending attempts:"<< sending_attempts << std::endl ; - o << " destination key: "<< data_item->destination_key << std::endl ; - o << " Client id: "<< client_id << std::endl ; - o << " item hash: "<< item_hash << std::endl ; - o << " tunnel hash: "<< tunnel_hash << std::endl ; - o << " Data size: "<< data_item->data_size << std::endl ; - o << " Signed receipt: "<< (void*)receipt_item << std::endl ; - - return o ; -} - -std::ostream& RsGRouterMatrixTrackItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterMatrixTrackItem:" << std::endl ; - o << " provider_id: " << provider_id << std::endl; - o << " message_id: " << message_id << std::endl; - o << " time_stamp: " << time_stamp << std::endl; - - return o ; -} -std::ostream& RsGRouterMatrixCluesItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterMatrixCluesItem:" << std::endl ; - o << " destination k: " << destination_key.toStdString() << std::endl; - o << " routing clues: " << clues.size() << std::endl; - - for(std::list::const_iterator it(clues.begin());it!=clues.end();++it) - o << " " << (*it).friend_id << " " << (*it).time_stamp << " " << (*it).weight << std::endl; - - return o ; -} -std::ostream& RsGRouterTransactionChunkItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterTransactionChunkItem:" << std::endl ; - o << " total_size: " << total_size << std::endl; - o << " chunk_size: " << chunk_size << std::endl; - o << " chunk_start: " << chunk_start << std::endl; - - return o ; -} -std::ostream& RsGRouterTransactionAcknItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterTransactionAcknItem:" << std::endl ; - o << " routing id: " << propagation_id << std::endl; - - return o ; -} -std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterMatrixCluesItem:" << std::endl ; - o << " friends: " << reverse_friend_indices.size() << std::endl; - - return o ; -} -#endif diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 998f7e636..d77903df8 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -2205,26 +2205,6 @@ Sha1CheckSum p3GRouter::makeTunnelHash(const RsGxsId& destination,const GRouterS return RsDirUtil::sha1sum(bytes,20) ; } -#ifdef TO_REMOVE -bool p3GRouter::locked_getGxsOwnIdAndClientIdFromHash(const TurtleFileHash& sum,RsGxsId& gxs_id,GRouterServiceId& client_id) -{ - assert( gxs_id.SIZE_IN_BYTES == 16) ; - assert(Sha1CheckSum::SIZE_IN_BYTES == 20) ; - - //gxs_id = RsGxsId(sum.toByteArray());// takes the first 16 bytes - //client_id = sum.toByteArray()[19] + (sum.toByteArray()[18] << 8) ; - - std::map::const_iterator it = _owned_key_ids.find(sum); - - if(it == _owned_key_ids.end()) - return false ; - - gxs_id = it->second.authentication_key ; - client_id = it->second.service_id ; - - return true ; -} -#endif bool p3GRouter::loadList(std::list& items) { { diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc index bb56e93cc..8e488c190 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc @@ -52,152 +52,11 @@ RsItem *RsGxsTunnelSerialiser::create_item(uint16_t service,uint8_t item_subtype } } -#ifdef TO_REMOVE -std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " Signature Key ID: " << signature.keyId << std::endl ; - out << " Public Key ID: " << gxs_key.keyId << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelMsgItem", indent); - return out; -} - -std::ostream& RsGxsTunnelDataItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDataItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ; - out << " service id : " << std::hex << service_id << std::dec << std::endl ; - out << " flags : " << std::hex << flags << std::dec << std::endl ; - out << " size : " << data_size << std::endl ; - out << " data : " << RsUtil::BinToHex(data,std::min(50u,data_size)) << ((data_size>50u)?"...":"") << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelDataItem", indent); - return out; -} -std::ostream& RsGxsTunnelDataAckItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDataItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelDataAckItem", indent); - return out; -} -std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDataItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " flags : " << std::hex << status << std::dec << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelStatusItem", indent); - return out; -} - -/*************************************************************************/ -#endif - RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem() { BN_free(public_key) ; } -#ifdef TO_REMOVE -/*************************************************************************/ - -RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "deserializing packet..."<< std::endl ; -#endif - // look what we have... - if (*pktsize < rssize) /* check size */ - { - std::cerr << "GxsTunnel deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ; - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - /* ready to load */ - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_GXS_TUNNEL != getRsItemService(rstype))) - { -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "GxsTunnel deserialisation: wrong type !" << std::endl ; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY: return deserialise_RsGxsTunnelDHPublicKeyItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA: return deserialise_RsGxsTunnelDataItem (data,*pktsize) ; - case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK: return deserialise_RsGxsTunnelDataAckItem (data,*pktsize) ; - case RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS: return deserialise_RsGxsTunnelStatusItem (data,*pktsize) ; - default: - std::cerr << "Unknown packet type in chat!" << std::endl ; - return NULL ; - } -} - -/*************************************************************************/ - -uint32_t RsGxsTunnelDHPublicKeyItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // BN size - s += BN_num_bytes(public_key) ; // public_key - s += signature.TlvSize() ; // signature - s += gxs_key.TlvSize() ; // gxs_key - - return s ; -} - -uint32_t RsGxsTunnelDataItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 8 ; // counter - s += 4 ; // flags - s += 4 ; // service id - s += 4 ; // data_size - s += data_size; // data - - return s ; -} - -uint32_t RsGxsTunnelDataAckItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 8 ; // counter - - return s ; -} - -uint32_t RsGxsTunnelStatusItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // flags - - return s ; -} -/*************************************************************************/ -#endif - void RsGxsTunnelDHPublicKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,public_key,"public_key") ; @@ -243,88 +102,11 @@ template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM std::cerr << "[BIGNUM] : " << name << std::endl; } -#ifdef TO_REMOVE -bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - uint32_t s = BN_num_bytes(public_key) ; - - ok &= setRawUInt32(data, tlvsize, &offset, s); - - BN_bn2bin(public_key,&((unsigned char *)data)[offset]) ; - offset += s ; - - ok &= signature.SetTlv(data, tlvsize, &offset); - ok &= gxs_key.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelDHPublicKeyItem::serialiseItem() Size Error! offset=" << offset << ", tlvsize=" << tlvsize << std::endl; - } - return ok ; -} -#endif - void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,status,"status") ; } -#ifdef TO_REMOVE -bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, status); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - - return ok; -} -#endif - void RsGxsTunnelDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,unique_item_counter,"unique_item_counter") ; @@ -339,247 +121,6 @@ void RsGxsTunnelDataAckItem::serial_process(RsGenericSerializer::SerializeJob j, RsTypeSerializer::serial_process(j,ctx,unique_item_counter,"unique_item_counter") ; } -#ifdef TO_REMOVE -bool RsGxsTunnelDataItem::serialise(void *dt, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(dt, tlvsize, PacketId(), tlvsize); - -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt64(dt, tlvsize, &offset, unique_item_counter); - ok &= setRawUInt32(dt, tlvsize, &offset, flags); - ok &= setRawUInt32(dt, tlvsize, &offset, service_id); - ok &= setRawUInt32(dt, tlvsize, &offset, data_size); - - if(offset + data_size <= tlvsize) - { - memcpy(&((uint8_t*)dt)[offset],data,data_size) ; - offset += data_size ; - } - else - ok = false ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} -bool RsGxsTunnelDataAckItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, unique_item_counter); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} - -/*************************************************************************/ - -RsGxsTunnelDHPublicKeyItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDHPublicKeyItem(void *data,uint32_t /*size*/) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsTunnelDHPublicKeyItem *item = new RsGxsTunnelDHPublicKeyItem() ; - - uint32_t s=0 ; - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - if(s > rssize || rssize - s < offset) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - item->public_key = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ; - offset += s ; - - ok &= item->signature.GetTlv(data, rssize, &offset) ; - ok &= item->gxs_key.GetTlv(data, rssize, &offset) ; - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} - -RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void *dat,uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(dat); - bool ok = true ; - - if(rssize > size) - { - std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ; - return NULL ; - } - - RsGxsTunnelDataItem *item = new RsGxsTunnelDataItem(); - - /* get mandatory parts first */ - - ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter); - ok &= getRawUInt32(dat, rssize, &offset, &item->flags); - ok &= getRawUInt32(dat, rssize, &offset, &item->service_id); - ok &= getRawUInt32(dat, rssize, &offset, &item->data_size); - - if(item->data_size > rssize || rssize < offset + item->data_size) - { - std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - item->data = (unsigned char*)rs_malloc(item->data_size) ; - - if(item->data == NULL) - { - delete item ; - return NULL ; - } - - memcpy(item->data,&((uint8_t*)dat)[offset],item->data_size) ; - offset += item->data_size ; - - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} - -RsGxsTunnelDataAckItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataAckItem(void *dat,uint32_t /* size */) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(dat); - bool ok = true ; - - RsGxsTunnelDataAckItem *item = new RsGxsTunnelDataAckItem(); - - /* get mandatory parts first */ - - ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter); - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} - -RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(void *dat, uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(dat); - bool ok = true ; - - if(rssize > size) - { - std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ; - return NULL ; - } - - RsGxsTunnelStatusItem *item = new RsGxsTunnelStatusItem(); - - /* get mandatory parts first */ - - ok &= getRawUInt32(dat, rssize, &offset, &item->status); - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelStatusItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} -#endif diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 5ae948d86..cad91f30b 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2294,44 +2294,6 @@ bool p3PeerMgrIMPL::loadList(std::list& load) continue; } -#ifdef TO_REMOVE - RsPeerGroupItem_deprecated *gitem = dynamic_cast(*it) ; - - if (gitem) - { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl; - gitem->print(std::cerr, 10); - std::cerr << std::endl; -#endif - RsGroupInfo ginfo ; - ginfo.flag = gitem->flag ; - ginfo.name = gitem->name ; - ginfo.peerIds = gitem->pgpList.ids ; - - do { ginfo.id = RsNodeGroupId::random(); } while(groupList.find(ginfo.id) != groupList.end()) ; - - // Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id. - - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FRIENDS )) ginfo.id = RS_GROUP_ID_FRIENDS ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_COWORKERS)) ginfo.id = RS_GROUP_ID_COWORKERS ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAMILY )) ginfo.id = RS_GROUP_ID_FAMILY ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ; - - if(!ginfo.id.isNull()) - { - groupList[ginfo.id] = ginfo ; - std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl; - } - else - std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl; - - continue; - } -#endif RsNodeGroupItem *gitem2 = dynamic_cast(*it) ; diff --git a/libretroshare/src/rsitems/rsbwctrlitems.cc b/libretroshare/src/rsitems/rsbwctrlitems.cc index 45c23d2c8..bfa172b45 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.cc +++ b/libretroshare/src/rsitems/rsbwctrlitems.cc @@ -57,143 +57,5 @@ void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsG RsTypeSerializer::serial_process(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(i))) - { - return sizeAllowed(dri); - } - return 0; -} - -bool RsBwCtrlSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsBwCtrlAllowedItem *dri; - - if (NULL != (dri = dynamic_cast(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 - diff --git a/libretroshare/src/rsitems/rsconfigitems.h b/libretroshare/src/rsitems/rsconfigitems.h index d4ea41898..4e31b2d43 100644 --- a/libretroshare/src/rsitems/rsconfigitems.h +++ b/libretroshare/src/rsitems/rsconfigitems.h @@ -140,30 +140,6 @@ class RsPeerBandwidthLimitsItem : public RsItem std::map peers ; }; -#ifdef TO_REMOVE -class RsPeerGroupItem_deprecated : public RsItem -{ -public: - RsPeerGroupItem_deprecated(); - virtual ~RsPeerGroupItem_deprecated(); - - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - /* set data from RsGroupInfo to RsPeerGroupItem */ - void set(RsGroupInfo &groupInfo); - /* get data from RsGroupInfo to RsPeerGroupItem */ - void get(RsGroupInfo &groupInfo); - - /* Mandatory */ - std::string id; - std::string name; - uint32_t flag; - - RsTlvPgpIdSet pgpList; -}; -#endif - class RsNodeGroupItem: public RsItem { public: @@ -216,51 +192,6 @@ class RsPeerConfigSerialiser: public RsConfigSerializer /**************************************************************************/ -#ifdef TO_REMOVE -class RsCacheConfig: public RsItem -{ - public: - RsCacheConfig() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_CACHE_CONFIG, - RS_PKT_SUBTYPE_DEFAULT) - { return; } -virtual ~RsCacheConfig(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); - - RsPeerId pid; /* Mandatory */ - uint16_t cachetypeid; /* Mandatory */ - uint16_t cachesubid; /* Mandatory */ - - std::string path; /* Mandatory */ - std::string name; /* Mandatory */ - RsFileHash hash; /* Mandatory */ - uint64_t size; /* 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); - -}; -#endif - -/**************************************************************************/ - class RsFileTransfer: public RsItem { public: @@ -306,26 +237,6 @@ class RsFileTransfer: public RsItem const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001; -#ifdef TO_REMOVE -/* Used by ft / extralist / configdirs / anyone who wants a basic file */ -class RsFileConfigItem_deprecated: public RsItem -{ -public: - RsFileConfigItem_deprecated() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_FILE_CONFIG, - RS_PKT_SUBTYPE_FILE_ITEM_deprecated) - {} - virtual ~RsFileConfigItem_deprecated() {} - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - RsTlvFileItem file; - uint32_t flags; - std::list parent_groups ; -}; -#endif - class RsFileConfigItem: public RsItem { public: diff --git a/libretroshare/src/rsitems/rsgxscommentitems.cc b/libretroshare/src/rsitems/rsgxscommentitems.cc index 407f64204..8c175a1bd 100644 --- a/libretroshare/src/rsitems/rsgxscommentitems.cc +++ b/libretroshare/src/rsitems/rsgxscommentitems.cc @@ -46,403 +46,14 @@ RsItem *RsGxsCommentSerialiser::create_item(uint16_t service_id,uint8_t item_sub } } -#ifdef TO_REMOVE - -uint32_t RsGxsCommentSerialiser::size(RsItem *item) -{ -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::size()" << std::endl; -#endif - - RsGxsCommentItem* com_item = NULL; - RsGxsVoteItem* vote_item = NULL; - - if((com_item = dynamic_cast(item)) != NULL) - { - return sizeGxsCommentItem(com_item); - } - else if((vote_item = dynamic_cast(item)) != NULL) - { - return sizeGxsVoteItem(vote_item); - } - std::cerr << "RsGxsCommentSerialiser::size() ERROR invalid item" << std::endl; - return 0; -} - -bool RsGxsCommentSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialise()" << std::endl; -#endif - - RsGxsCommentItem* com_item = NULL; - RsGxsVoteItem* vote_item = NULL; - - if((com_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsCommentItem(com_item, data, size); - } - else if((vote_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsVoteItem(vote_item, data, size); - } - std::cerr << "RsGxsCommentSerialiser::serialise() ERROR invalid item" << std::endl; - return false; -} - -RsItem* RsGxsCommentSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (getRsItemService(PacketId()) != getRsItemService(rstype))) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialise() ERROR Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM: - return deserialiseGxsCommentItem(data, size); - break; - case RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM: - return deserialiseGxsVoteItem(data, size); - break; - default: -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsCommentItem::clear() -{ - mMsg.mComment.clear(); -} - -std::ostream& RsGxsCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsCommentItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Comment: " << mMsg.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsCommentItem", indent); - return out; -} - - -uint32_t RsGxsCommentSerialiser::sizeGxsCommentItem(RsGxsCommentItem *item) -{ - - const RsGxsComment& msg = item->mMsg; - uint32_t s = 8; // header - - s += GetTlvStringSize(msg.mComment); // mMsg. - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::sizeGxsCommentItem() is: " << s << std::endl; - msg.print(std::cerr); -#endif - - return s; -} -#endif - void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ; } -#ifdef TO_REMOVE -bool RsGxsCommentSerialiser::serialiseGxsCommentItem(RsGxsCommentItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsCommentItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() Failed size too small" << std::endl; -#endif - - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsCommentItem */ - ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mComment); - - if(offset != tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSCOMMENT_DEBUG - if (!ok) - { - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsCommentItem* RsGxsCommentSerialiser::deserialiseGxsCommentItem(void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (getRsItemService(PacketId()) != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsCommentItem* item = new RsGxsCommentItem(getRsItemService(PacketId())); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mComment); - - if (offset != rssize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsVoteItem::clear() -{ - mMsg.mVoteType = 0; -} - -std::ostream& RsGxsVoteItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsVoteItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "VoteType: " << mMsg.mVoteType << std::endl; - - printRsItemEnd(out ,"RsGxsVoteItem", indent); - return out; -} - - -uint32_t RsGxsCommentSerialiser::sizeGxsVoteItem(RsGxsVoteItem */*item*/) -{ - uint32_t s = 8; // header - - s += 4; // vote flags. - - return s; -} -#endif - void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ; } -#ifdef TO_REMOVE -bool RsGxsCommentSerialiser::serialiseGxsVoteItem(RsGxsVoteItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsVoteItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsVoteItem */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mMsg.mVoteType); - - if(offset != tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSCOMMENT_DEBUG - if (!ok) - { - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsVoteItem* RsGxsCommentSerialiser::deserialiseGxsVoteItem(void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (getRsItemService(PacketId()) != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsVoteItem* item = new RsGxsVoteItem(getRsItemService(PacketId())); - /* skip the header */ - offset += 8; - - ok &= getRawUInt32(data, rssize, &offset, &(item->mMsg.mVoteType)); - - if (offset != rssize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif diff --git a/libretroshare/src/rsitems/rsgxsiditems.cc b/libretroshare/src/rsitems/rsgxsiditems.cc index 5bf55b549..1a4eac4e8 100644 --- a/libretroshare/src/rsitems/rsgxsiditems.cc +++ b/libretroshare/src/rsitems/rsgxsiditems.cc @@ -60,172 +60,12 @@ void RsGxsIdGroupItem::clear() mRecognTags.clear(); mImage.TlvClear(); } -#ifdef TO_REMOVE -RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype))) - return NULL; /* wrong type */ - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM: return deserialise_GxsIdGroupItem(data, size); - case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return deserialise_GxsIdLocalInfoItem(data, size); -#if 0 - case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM: return deserialise_GxsIdOpinionItem(data, size); - case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM: return deserialise_GxsIdCommentItem(data, size); -#endif - default: -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - -bool RsGxsIdItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } - offset += 8; - - return true ; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - - - -uint32_t RsGxsIdLocalInfoItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // number of items - s += mTimeStamps.size() * (RsGxsId::SIZE_IN_BYTES + 8) ; - s += 4 ; // number of contacts - s += mContacts.size() * RsGxsId::SIZE_IN_BYTES ; - - return s; -} - -std::ostream& RsGxsIdLocalInfoItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdLocalInfoItem", indent); - - // convert from binary to hex. - for(std::map::const_iterator it(mTimeStamps.begin());it!=mTimeStamps.end();++it) - out << it->first << " : " << it->second << std::endl; - - printRsItemEnd(out ,"RsGxsIdLocalInfoItem", indent); - return out; -} -std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "MetaData: " << meta << std::endl; - printIndent(out, int_Indent); - out << "PgpIdHash: " << mPgpIdHash << std::endl; - printIndent(out, int_Indent); - - std::string signhex; - // convert from binary to hex. - for(unsigned int i = 0; i < mPgpIdSign.length(); i++) - { - rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) mPgpIdSign[i])); - } - out << "PgpIdSign: " << signhex << std::endl; - printIndent(out, int_Indent); - out << "RecognTags:" << std::endl; - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); - set.print(out, int_Indent + 2); - - printRsItemEnd(out ,"RsGxsIdGroupItem", indent); - return out; -} - - -uint32_t RsGxsIdGroupItem::serial_size() -{ - uint32_t s = 8; // header - - s += Sha1CheckSum::SIZE_IN_BYTES; - s += GetTlvStringSize(mPgpIdSign); - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); - s += set.TlvSize(); - s += mImage.TlvSize() ; - - return s; -} -#endif - void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ; RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ; } -#ifdef TO_REMOVE -bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, tlvsize, &offset, mTimeStamps.size()) ; - - for(std::map::const_iterator it = mTimeStamps.begin();it!=mTimeStamps.end();++it) - { - ok &= it->first.serialise(data,tlvsize,offset) ; - ok &= setRawTimeT(data,tlvsize,&offset,it->second) ; - } - ok &= setRawUInt32(data, tlvsize, &offset, mContacts.size()) ; - - for(std::set::const_iterator it(mContacts.begin());it!=mContacts.end();++it) - ok &= (*it).serialise(data,tlvsize,offset) ; - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; -} -#endif - void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ; @@ -243,43 +83,6 @@ void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; } -#ifdef TO_REMOVE -bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* GxsIdGroupItem */ - ok &= mPgpIdHash.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, mPgpIdSign); - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); - ok &= set.SetTlv(data, tlvsize, &offset); - - ok &= mImage.SetTlv(data,tlvsize,&offset) ; - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; -} -#endif - bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage) { clear(); @@ -320,422 +123,3 @@ bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage) return true ; } -#ifdef TO_REMOVE -RsGxsIdGroupItem* RsGxsIdSerialiser::deserialise_GxsIdGroupItem(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); - /* skip the header */ - offset += 8; - - ok &= item->mPgpIdHash.deserialise(data, rssize, offset); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->mPgpIdSign); - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags); - ok &= set.GetTlv(data, rssize, &offset); - - // image is optional,so that we can continue reading old items. - if(offset < rssize) - ok &= item->mImage.GetTlv(data,rssize,&offset) ; - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsGxsIdLocalInfoItem *RsGxsIdSerialiser::deserialise_GxsIdLocalInfoItem(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdLocalInfoItem* item = new RsGxsIdLocalInfoItem(); - /* skip the header */ - offset += 8; - - uint32_t n=0 ; - ok &= getRawUInt32(data, rssize, &offset, &n) ; - - for(uint32_t i=0;ok && imTimeStamps[gxsid] = TS ; - } - - if (offset < rssize) // backward compatibility, making that section optional. - { - ok &= getRawUInt32(data, rssize, &offset, &n) ; - RsGxsId gxsid ; - - for(uint32_t i=0;ok && imContacts.insert(gxsid) ; - } - } - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#if 0 - -void RsGxsIdOpinionItem::clear() -{ - opinion.mOpinion = 0; - opinion.mReputation = 0; - opinion.mComment = ""; -} - -std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdOpinionItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Opinion: " << opinion.mOpinion << std::endl; - printIndent(out, int_Indent); - out << "Reputation: " << opinion.mReputation << std::endl; - printIndent(out, int_Indent); - out << "Comment: " << opinion.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsIdOpinionItem", indent); - return out; -} - - -uint32_t RsGxsIdOpinionItem::serial_size() -{ - - const RsGxsIdOpinion& opinion = item->opinion; - uint32_t s = 8; // header - - s += 4; // mOpinion. - s += 4; // mReputation. - s += GetTlvStringSize(opinion.mComment); - - return s; -} - -bool RsGxsIdOpinionItem::serialise(void *data, uint32_t *size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* GxsIdOpinionItem */ - ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion); - ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mReputation); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialise_GxsIdOpinionItem(void *data, uint32_t *size) -{ - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem(); - /* skip the header */ - offset += 8; - - ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion)); - ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mReputation)); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsIdCommentItem::clear() -{ - comment.mComment.clear(); -} - -std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdCommentItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Comment: " << comment.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsIdCommentItem", indent); - return out; -} - - -uint32_t RsGxsIdCommentItem::serial_size() -{ - - const RsGxsIdComment& comment = item->comment; - uint32_t s = 8; // header - - s += GetTlvStringSize(comment.mComment); - - return s; -} - -bool RsGxsIdCommentItem::serialise(void *data, uint32_t *size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* GxsIdCommentItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; -} - -RsGxsIdCommentItem* RsGxsIdSerialiser::deserialise_GxsIdCommentItem(void *data, uint32_t *size) -{ - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdCommentItem* item = new RsGxsIdCommentItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif diff --git a/libretroshare/src/rsitems/rsgxsrecognitems.cc b/libretroshare/src/rsitems/rsgxsrecognitems.cc index 81b8d866b..bb6a40ca8 100644 --- a/libretroshare/src/rsitems/rsgxsrecognitems.cc +++ b/libretroshare/src/rsitems/rsgxsrecognitems.cc @@ -63,65 +63,6 @@ void RsGxsRecognReqItem::clear() sign.TlvClear(); } -#ifdef TO_REMOVE -RsGxsRecognReqItem::~RsGxsRecognReqItem() -{ - return; -} - - -std::ostream &RsGxsRecognReqItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsRecognReqItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "issued_at: " << issued_at << std::endl; - - printIndent(out, int_Indent); - out << "period: " << period << std::endl; - - printIndent(out, int_Indent); - out << "tag_class: " << tag_class << std::endl; - - printIndent(out, int_Indent); - out << "tag_type: " << tag_type << std::endl; - - printIndent(out, int_Indent); - out << "identity: " << identity << std::endl; - - printIndent(out, int_Indent); - out << "nickname: " << nickname << std::endl; - - printIndent(out, int_Indent); - out << "comment: " << comment << std::endl; - - printIndent(out, int_Indent); - out << "signature: " << std::endl; - sign.print(out, int_Indent + 2); - - printRsItemEnd(out, "RsGxsRecognReqItem", indent); - return out; -} - - -uint32_t RsGxsRecognSerialiser::sizeReq(RsGxsRecognReqItem *item) -{ - uint32_t s = 8; /* header */ - s += 4; // issued_at; - s += 4; // period; - s += 2; // tag_class; - s += 2; // tag_type; - s += item->identity.serial_size(); - s += GetTlvStringSize(item->nickname); - s += GetTlvStringSize(item->comment); - s += item->sign.TlvSize(); - - return s; -} - -#endif - void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,issued_at ,"issued_at") ; @@ -134,122 +75,6 @@ void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGxsRecognSerialiser::serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeReq(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 << "RsGxsRecognSerialiser::serialiseReq() Header: " << ok << std::endl; - std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->issued_at); - ok &= setRawUInt32(data, tlvsize, &offset, item->period); - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class); - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type); - - - ok &= item->identity.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname); - ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment); - - ok &= item->sign.SetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsGxsRecognReqItem *RsGxsRecognSerialiser::deserialiseReq(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_GXS_RECOGN != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RECOGN_REQ != 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 */ - RsGxsRecognReqItem *item = new RsGxsRecognReqItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &(item->issued_at)); - ok &= getRawUInt32(data, tlvsize, &offset, &(item->period)); - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class)); - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type)); - - - ok &= item->identity.serialise(data, tlvsize, offset); - ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname); - ok &= GetTlvString(data, tlvsize, &offset, 1, item->comment); - ok &= item->sign.GetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -RsGxsRecognTagItem::~RsGxsRecognTagItem() -{ - return; -} -#endif - void RsGxsRecognTagItem::clear() { valid_from = 0; @@ -264,56 +89,6 @@ void RsGxsRecognTagItem::clear() sign.TlvClear(); } -#ifdef TO_REMOVE -std::ostream &RsGxsRecognTagItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsRecognTagItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "valid_from: " << valid_from << std::endl; - - printIndent(out, int_Indent); - out << "valid_to: " << valid_to << std::endl; - - printIndent(out, int_Indent); - out << "tag_class: " << tag_class << std::endl; - - printIndent(out, int_Indent); - out << "tag_type: " << tag_type << std::endl; - - printIndent(out, int_Indent); - out << "identity: " << identity << std::endl; - - printIndent(out, int_Indent); - out << "nickname: " << nickname << std::endl; - - printIndent(out, int_Indent); - out << "signature: " << std::endl; - sign.print(out, int_Indent + 2); - - printRsItemEnd(out, "RsGxsRecognTagItem", indent); - return out; -} - - -uint32_t RsGxsRecognSerialiser::sizeTag(RsGxsRecognTagItem *item) -{ - uint32_t s = 8; /* header */ - s += 4; // valid_from; - s += 4; // valid_to; - s += 2; // tag_class; - s += 2; // tag_type; - - s += item->identity.serial_size(); - s += GetTlvStringSize(item->nickname); - - s += item->sign.TlvSize(); - - return s; -} -#endif - void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,valid_from ,"valid_from") ; @@ -325,122 +100,6 @@ void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGxsRecognSerialiser::serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeTag(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 << "RsGxsRecognSerialiser::serialiseTag() Header: " << ok << std::endl; - std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->valid_from); - ok &= setRawUInt32(data, tlvsize, &offset, item->valid_to); - - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class); - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type); - - - ok &= item->identity.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname); - - ok &= item->sign.SetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsGxsRecognTagItem *RsGxsRecognSerialiser::deserialiseTag(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_GXS_RECOGN != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RECOGN_TAG != 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 */ - RsGxsRecognTagItem *item = new RsGxsRecognTagItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_from)); - ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_to)); - - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class)); - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type)); - - - ok &= item->identity.deserialise(data, tlvsize, offset); - ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname); - ok &= item->sign.GetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -RsGxsRecognSignerItem::~RsGxsRecognSignerItem() -{ - return; -} -#endif - void RsGxsRecognSignerItem::clear() { signing_classes.TlvClear(); @@ -448,43 +107,6 @@ void RsGxsRecognSignerItem::clear() sign.TlvClear(); } -#ifdef TO_REMOVE -std::ostream &RsGxsRecognSignerItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsRecognSignerItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "signing_classes: " << std::endl; - signing_classes.print(out, int_Indent + 2); - - printIndent(out, int_Indent); - out << "key: " << std::endl; - key.print(out, int_Indent + 2); - - printIndent(out, int_Indent); - out << "signature: " << std::endl; - sign.print(out, int_Indent + 2); - - - printRsItemEnd(out, "RsGxsRecognSignerItem", indent); - return out; -} - - - - -uint32_t RsGxsRecognSerialiser::sizeSigner(RsGxsRecognSignerItem *item) -{ - uint32_t s = 8; /* header */ - s += item->signing_classes.TlvSize(); - s += item->key.TlvSize(); - s += item->sign.TlvSize(); - - return s; -} -#endif - void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,signing_classes ,"signing_classes") ; @@ -492,175 +114,5 @@ void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,R RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGxsRecognSerialiser::serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeSigner(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 << "RsGxsRecognSerialiser::serialiseSigner() Header: " << ok << std::endl; - std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->signing_classes.SetTlv(data, tlvsize, &offset); - ok &= item->key.SetTlv(data, tlvsize, &offset); - ok &= item->sign.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsGxsRecognSignerItem *RsGxsRecognSerialiser::deserialiseSigner(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_GXS_RECOGN != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RECOGN_SIGNER != 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 */ - RsGxsRecognSignerItem *item = new RsGxsRecognSignerItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->signing_classes.GetTlv(data, tlvsize, &offset); - ok &= item->key.GetTlv(data, tlvsize, &offset); - ok &= item->sign.GetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - -uint32_t RsGxsRecognSerialiser::size(RsItem *i) -{ - RsGxsRecognReqItem *rqi; - RsGxsRecognTagItem *rti; - RsGxsRecognSignerItem *rsi; - - if (NULL != (rqi = dynamic_cast(i))) - { - return sizeReq(rqi); - } - if (NULL != (rti = dynamic_cast(i))) - { - return sizeTag(rti); - } - if (NULL != (rsi = dynamic_cast(i))) - { - return sizeSigner(rsi); - } - return 0; -} - -bool RsGxsRecognSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsGxsRecognReqItem *rri; - RsGxsRecognTagItem *rti; - RsGxsRecognSignerItem *rsi; - - if (NULL != (rri = dynamic_cast(i))) - { - return serialiseReq(rri, data, pktsize); - } - if (NULL != (rti = dynamic_cast(i))) - { - return serialiseTag(rti, data, pktsize); - } - if (NULL != (rsi = dynamic_cast(i))) - { - return serialiseSigner(rsi, data, pktsize); - } - return false; -} - -RsItem *RsGxsRecognSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - if (*pktsize < getRsPktBaseSize()) - return NULL ; - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_RECOGN_REQ: - return deserialiseReq(data, pktsize); - break; - case RS_PKT_SUBTYPE_RECOGN_TAG: - return deserialiseTag(data, pktsize); - break; - case RS_PKT_SUBTYPE_RECOGN_SIGNER: - return deserialiseSigner(data, pktsize); - break; - default: - return NULL; - break; - } -} - -/*************************************************************************/ -#endif diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc index 2a559b052..7b558131a 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.cc +++ b/libretroshare/src/rsitems/rsgxsreputationitems.cc @@ -88,525 +88,6 @@ void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJo RsTypeSerializer::serial_process(j,ctx,mLastUpdate,"mLastUpdate") ; } -#ifdef TO_REMOVE -// re-defined here, in order to avoid cross-includes -#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100 - -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ - -std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationConfigItem", indent); - - out << "mPeerId: " << mPeerId << std::endl; - out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl; - out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl; - - printRsItemEnd(out, "RsReputationConfigItem", indent); - return out; -} - -std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationSetItem", indent); - - out << "GxsId: " << mGxsId << std::endl; - out << "Owner: " << mOwnerNodeId << std::endl; - out << "mOwnOpinion: " << mOwnOpinion << std::endl; - out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl; - out << "Opinions from neighbors: " << std::endl; - - for(std::map::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it) - out << " " << it->first << ": " << it->second << std::endl; - - printRsItemEnd(out, "RsReputationSetItem", indent); - return out; -} -std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationUpdateItem", indent); - - out << "from: " << PeerId() << std::endl; - out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl; - - for(std::map::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it) - out << " " << it->first << ": " << it->second << std::endl; - - printRsItemEnd(out, "RsReputationUpdateItem", indent); - return out; -} -std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationRequestItem", indent); - - out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl; - - printRsItemEnd(out, "RsReputationRequestItem", indent); - return out; -} -std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationBannedNodeSetItem", indent); - - out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl; - out << "PGP id: " << mPgpId << std::endl; - out << "Known ids: " << mKnownIdentities.ids.size() << std::endl; - - printRsItemEnd(out, "RsReputationRequestItem", indent); - return out; -} -/*************************************************************************/ - -uint32_t RsGxsReputationConfigItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += mPeerId.serial_size() ; // PeerId - s += 4 ; // mLatestUpdate - s += 4 ; // mLastQuery - - return s ; -} - -uint32_t RsGxsReputationSetItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += mGxsId.serial_size() ; - s += 4 ; // mOwnOpinion - s += 4 ; // mOwnOpinionTS - s += 4 ; // mIdentityFlags - s += 4 ; // mLastUsedTS - s += mOwnerNodeId.serial_size() ; - - s += 4 ; // mOpinions.size() - - s += (4+RsPeerId::serial_size()) * mOpinions.size() ; - - return s ; -} - -uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += RsPgpId::serial_size() ; // mPgpId - s += 4 ; // mLastActivityTS; - s += mKnownIdentities.TlvSize(); // mKnownIdentities - - return s ; -} - -uint32_t RsGxsReputationUpdateItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += 4 ; // mLatestUpdate - s += 4 ; // mOpinions.size(); - - s += (RsGxsId::serial_size() + 4) * mOpinions.size() ; - - return s ; -} - -uint32_t RsGxsReputationRequestItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += 4 ; // mLastUpdate - - return s; -} - -/*************************************************************************/ - -bool RsGxsReputationConfigItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= mPeerId.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate); - ok &= setRawUInt32(data, tlvsize, &offset, mLastQuery); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= mGxsId.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion); - ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS); - ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ; - ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ; - ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ; - - ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size()); - - for(std::map::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it) - { - ok &= it->first.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, it->second) ; - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -bool RsGxsReputationBannedNodeSetItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= mPgpId.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS); - ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate); - ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size()); - - for(std::map::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it) - { - ok &= it->first.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, it->second) ; - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -/* serialise the data to the buffer */ -bool RsGxsReputationRequestItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= setRawUInt32(data, tlvsize, &offset, mLastUpdate); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -/*************************************************************************/ - -RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem() ; - - /* add mandatory parts first */ - ok &= item->mPeerId.deserialise(data, size, offset) ; - ok &= getRawUInt32(data, size, &offset, &item->mLatestUpdate); - ok &= getRawUInt32(data, size, &offset, &item->mLastQuery); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ; - - /* add mandatory parts first */ - ok &= item->mPgpId.deserialise(data, size, offset) ; - ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS); - ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - - -RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; - - /* add mandatory parts first */ - ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; - - item->mOwnerNodeId.clear(); // clears up, for backward compat. - - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S); - - for(uint32_t i = 0; ok && (i < S); ++i) - { - RsPeerId pid ; - uint32_t op ; - - ok &= pid.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &op); - - if(ok) - item->mOpinions[pid] = op ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -RsGxsReputationSetItem_deprecated3 *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated3(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ; - - /* add mandatory parts first */ - ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); - ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ; - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S); - - for(uint32_t i = 0; ok && (i < S); ++i) - { - RsPeerId pid ; - uint32_t op ; - - ok &= pid.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &op); - - if(ok) - item->mOpinions[pid] = op ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; - - /* add mandatory parts first */ - ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUsedTS); - ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ; - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S); - - for(uint32_t i = 0; ok && (i < S); ++i) - { - RsPeerId pid ; - uint32_t op ; - - ok &= pid.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &op); - - if(ok) - item->mOpinions[pid] = op ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate); - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S) ; - - for(uint32_t i=0;ok && imOpinions[gid] = op ; - - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -RsGxsReputationRequestItem *RsGxsReputationSerialiser::deserialiseReputationRequestItem(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationRequestItem *item = new RsGxsReputationRequestItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUpdate); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -/*************************************************************************/ - -RsItem *RsGxsReputationSerialiser::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_GXS_TYPE_REPUTATION != getRsItemService(rstype))) - { - std::cerr << "RsReputationSerialiser::deserialise(): wrong item type " << std::hex << rstype << std::dec << std::endl; - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3: return deserialiseReputationSetItem_deprecated3(data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize); - - default: - std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl; - return NULL; - break; - } -} -#endif - /*************************************************************************/ RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const diff --git a/libretroshare/src/rsitems/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc index 3280f8eba..23aa9e38f 100644 --- a/libretroshare/src/rsitems/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -72,225 +72,4 @@ RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONF saveToDisc = true; } -#ifdef TO_REMOVE -/*************************************************************************/ -RsHistoryMsgItem::~RsHistoryMsgItem() -{ -} - -void RsHistoryMsgItem::clear() -{ - incoming = false; - peerId.clear(); - peerName.clear(); - sendTime = 0; - recvTime = 0; - message.clear(); - msgId = 0; - saveToDisc = true; -} - -std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsHistoryMsgItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "chatPeerid: " << chatPeerId << std::endl; - - printIndent(out, int_Indent); - out << "incoming: " << (incoming ? "1" : "0") << std::endl; - - printIndent(out, int_Indent); - out << "peerId: " << peerId << std::endl; - - printIndent(out, int_Indent); - out << "peerName: " << peerName << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << std::endl; - - printIndent(out, int_Indent); - out << "recvTime: " << recvTime << std::endl; - - printIndent(out, int_Indent); - std::string cnv_message(message.begin(), message.end()); - out << "message: " << cnv_message << std::endl; - - printRsItemEnd(out, "RsHistoryMsgItem", indent); - return out; -} - - -RsHistorySerialiser::~RsHistorySerialiser() -{ -} - -uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item) -{ - uint32_t s = 8; /* header */ - s += 2; /* version */ - s += item->chatPeerId.serial_size(); - s += 1; /* incoming */ - s += item->peerId.serial_size(); - s += GetTlvStringSize(item->peerName); - s += 4; /* sendTime */ - s += 4; /* recvTime */ - s += GetTlvStringSize(item->message); - - return s; -} -/* serialise the data to the buffer */ -bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize) -{ - uint32_t tlvsize = sizeHistoryMsgItem(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 << "RsHistorySerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsHistorySerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt16(data, tlvsize, &offset, 0); // version - ok &= item->chatPeerId.serialise(data, tlvsize, offset) ; - uint8_t dummy = item->incoming ? 1 : 0; - ok &= setRawUInt8(data, tlvsize, &offset, dummy); - ok &= item->peerId.serialise(data, tlvsize, offset) ; - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName); - ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime); - ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->message); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsHistorySerialiser::serialiseItem() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsHistoryMsgItem *item = new RsHistoryMsgItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint16_t version = 0; - ok &= getRawUInt16(data, rssize, &offset, &version); - ok &= item->chatPeerId.deserialise(data, rssize, offset) ; - uint8_t dummy; - ok &= getRawUInt8(data, rssize, &offset, &dummy); - item->incoming = (dummy == 1); - ok &= item->peerId.deserialise(data, rssize, offset) ; - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName); - ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime)); - ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime)); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -uint32_t RsHistorySerialiser::size(RsItem *item) -{ - RsHistoryMsgItem* hi; - - if (NULL != (hi = dynamic_cast(item))) - { - return sizeHistoryMsgItem(hi); - } - - return 0; -} - -bool RsHistorySerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize) -{ - RsHistoryMsgItem* hi; - - if (NULL != (hi = dynamic_cast(item))) - { - return serialiseHistoryMsgItem(hi, data, pktsize); - } - - return false; -} - -RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DEFAULT: - return deserialiseHistoryMsgItem(data, pktsize); - } - - return NULL; -} - -/*************************************************************************/ - -#endif diff --git a/libretroshare/src/rsitems/rsnxsitems.cc b/libretroshare/src/rsitems/rsnxsitems.cc index d6eb8b143..104935930 100644 --- a/libretroshare/src/rsitems/rsnxsitems.cc +++ b/libretroshare/src/rsitems/rsnxsitems.cc @@ -212,1199 +212,4 @@ void RsNxsSessionKeyItem::clear() } #endif -#ifdef TO_REMOVE -uint32_t RsNxsSerialiser::size(RsItem *item) -{ - RsNxsItem *nxs_item = dynamic_cast(item) ; - - if(nxs_item != NULL) - return nxs_item->serial_size() ; - else - { - std::cerr << "RsNxsSerialiser::serialise(): Not an RsNxsItem!" << std::endl; - return 0; - } -} - -bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsNxsItem *nxs_item = dynamic_cast(item) ; - - if(nxs_item != NULL) - return nxs_item->serialise(data,*size) ; - else - { - std::cerr << "RsNxsSerialiser::serialise(): Not an RsNxsItem!" << std::endl; - return 0; - } -} - -bool RsNxsItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; -} - -bool RsNxsSyncMsgItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSynMsgItem()" << std::endl; -#endif - - /* RsNxsSyncMsgItem */ - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= grpId.serialise(data, size, offset); - ok &= msgId.serialise(data, size, offset); - ok &= authorId.serialise(data, size, offset); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSynMsgItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsNxsMsg::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, pos); - ok &= msgId.serialise(data, size, offset); - ok &= grpId.serialise(data, size, offset); - ok &= msg.SetTlv(data, size, &offset); - ok &= meta.SetTlv(data, size, &offset); - - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsMsg() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsMsg() NOK" << std::endl; - } -#endif - - return ok; -} - - -bool RsNxsGrp::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - // grp id - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, pos); - ok &= grpId.serialise(data, size, offset); - ok &= grp.SetTlv(data, size, &offset); - ok &= meta.SetTlv(data, size, &offset); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsGrp() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsGrp() NOK" << std::endl; - } -#endif - - return ok; -} -bool RsNxsSyncGrpStatsItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSyncGrpStats()" << std::endl; -#endif - - ok &= setRawUInt32(data, size, &offset, request_type); - ok &= grpId.serialise(data, size, offset) ; - ok &= setRawUInt32(data, size, &offset, number_of_posts); - ok &= setRawUInt32(data, size, &offset, last_post_TS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseSyncGrpStats() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseSyncGrpStats() NOK" << std::endl; - } -#endif - - return ok; -} -bool RsNxsSyncGrpReqItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= setRawUInt32(data, size, &offset, createdSince); - ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_HASH_SHA1, syncHash); - ok &= setRawUInt32(data, size, &offset, updateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseSyncGrp() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseSyncGrp() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsNxsTransacItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt16(data, size, &offset, transactFlag); - ok &= setRawUInt32(data, size, &offset, nItems); - ok &= setRawUInt32(data, size, &offset, updateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsTrans() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsTrans() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsNxsSyncGrpItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* RsNxsSyncm */ - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= grpId.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, publishTs); - ok &= authorId.serialise(data, size, offset); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSyncm( FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsSyncm() NOK" << std::endl; - } -#endif - - return ok; -} - - -bool RsNxsSyncMsgReqItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= setRawUInt32(data, size, &offset, createdSinceTS); - ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_HASH_SHA1, syncHash); - ok &= grpId.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, updateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg( NOK" << std::endl; - } -#endif - - return ok; -} - - -bool RsNxsGroupPublishKeyItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= grpId.serialise(data, size, offset) ; - ok &= private_key.SetTlv(data, size, &offset) ; - - if(offset != tlvsize) - { - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl; - - return ok; -} - -bool RsNxsSessionKeyItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - - if(offset + EVP_MAX_IV_LENGTH >= size) - { - std::cerr << "RsNxsSessionKeyItem::serialize(): error. Not enough room for IV !" << std::endl; - return false ; - } - memcpy(&((uint8_t*)data)[offset],iv,EVP_MAX_IV_LENGTH) ; - offset += EVP_MAX_IV_LENGTH ; - - ok &= setRawUInt32(data, size, &offset, encrypted_session_keys.size()); - - for(std::map::const_iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - { - ok &= it->first.serialise(data, size, offset) ; - ok &= it->second.SetTlv(data, size, &offset) ; - } - - if(offset != tlvsize) - { - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl; - - return ok; -} -bool RsNxsEncryptedDataItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= encrypted_data.SetTlv(data, size, &offset) ; - - if(offset != tlvsize) - { - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl; - - return ok; -} - - - -/*** deserialisation ***/ - -RsNxsGrp* RsNxsSerialiser::deserialNxsGrpItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_GRP_ITEM); - uint32_t offset = 8; - - RsNxsGrp* item = new RsNxsGrp(SERVICE_TYPE); - - /* skip the header */ - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->pos)); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->grp.GetTlv(data, *size, &offset); - ok &= item->meta.GetTlv(data, *size, &offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGrp() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGrp() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -RsNxsMsg* RsNxsSerialiser::deserialNxsMsgItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_MSG_ITEM); - uint32_t offset = 8; - - RsNxsMsg* item = new RsNxsMsg(SERVICE_TYPE); - /* skip the header */ - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->pos)); - ok &= item->msgId.deserialise(data, *size, offset); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->msg.GetTlv(data, *size, &offset); - ok &= item->meta.GetTlv(data, *size, &offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsMsg() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsMsg() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsNxsSyncGrpStatsItem* RsNxsSerialiser::deserialNxsSyncGrpStatsItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM); - uint32_t offset = 8; - - RsNxsSyncGrpStatsItem* item = new RsNxsSyncGrpStatsItem(SERVICE_TYPE) ; - /* skip the header */ - - ok &= getRawUInt32(data, *size, &offset, &(item->request_type)); - ok &= item->grpId.deserialise(data, *size, offset) ; - ok &= getRawUInt32(data, *size, &offset, &(item->number_of_posts)); - ok &= getRawUInt32(data, *size, &offset, &(item->last_post_TS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpStats() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpStats() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -bool RsNxsSerialiser::checkItemHeader(void *data,uint32_t *size,uint8_t subservice_type) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::checkItemHeader()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (subservice_type != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::checkItemHeader() FAIL wrong type" << std::endl; -#endif - return false; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::checkItemHeader() FAIL wrong size" << std::endl; -#endif - return false; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - return true ; -} - -RsNxsSyncGrpReqItem* RsNxsSerialiser::deserialNxsSyncGrpReqItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM); - - RsNxsSyncGrpReqItem* item = new RsNxsSyncGrpReqItem(SERVICE_TYPE); - /* skip the header */ - uint32_t offset = 8; - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= getRawUInt32(data, *size, &offset, &(item->createdSince)); - ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash); - ok &= getRawUInt32(data, *size, &offset, &(item->updateTS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrp() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrp() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -RsNxsSyncGrpItem* RsNxsSerialiser::deserialNxsSyncGrpItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM); - - RsNxsSyncGrpItem* item = new RsNxsSyncGrpItem(SERVICE_TYPE); - /* skip the header */ - uint32_t offset = 8; - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= getRawUInt32(data, *size, &offset, &(item->publishTs)); - ok &= item->authorId.deserialise(data, *size, offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsNxsTransacItem* RsNxsSerialiser::deserialNxsTransacItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM); - uint32_t offset = 8 ; - - RsNxsTransacItem* item = new RsNxsTransacItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag)); - ok &= getRawUInt32(data, *size, &offset, &(item->nItems)); - ok &= getRawUInt32(data, *size, &offset, &(item->updateTS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsTrans() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsTrans() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; - - -} - -RsNxsSyncMsgItem* RsNxsSerialiser::deserialNxsSyncMsgItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM); - uint32_t offset = 8 ; - - RsNxsSyncMsgItem* item = new RsNxsSyncMsgItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->msgId.deserialise(data, *size, offset); - ok &= item->authorId.deserialise(data, *size, offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsgItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsgItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -RsNxsSyncMsgReqItem* RsNxsSerialiser::deserialNxsSyncMsgReqItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM); - uint32_t offset = 8 ; - - RsNxsSyncMsgReqItem* item = new RsNxsSyncMsgReqItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= getRawUInt32(data, *size, &offset, &(item->createdSinceTS)); - ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= getRawUInt32(data, *size, &offset, &(item->updateTS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsg() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsg() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsNxsGroupPublishKeyItem* RsNxsSerialiser::deserialNxsGroupPublishKeyItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM); - uint32_t offset = 8 ; - - RsNxsGroupPublishKeyItem* item = new RsNxsGroupPublishKeyItem(SERVICE_TYPE); - - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->private_key.GetTlv(data, *size, &offset) ; - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsNxsSessionKeyItem *RsNxsSerialiser::deserialNxsSessionKeyItem(void* data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM); - uint32_t offset = 8 ; - - RsNxsSessionKeyItem* item = new RsNxsSessionKeyItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - - if(offset + EVP_MAX_IV_LENGTH >= *size) - { - std::cerr << __PRETTY_FUNCTION__ << ": not enough room for IV." << std::endl; - return NULL ; - } - memcpy(item->iv,&((uint8_t*)data)[offset],EVP_MAX_IV_LENGTH) ; - offset += EVP_MAX_IV_LENGTH ; - - uint32_t n ; - ok &= getRawUInt32(data, *size, &offset, &n) ; - - for(uint32_t i=0;ok && iencrypted_session_keys[gxs_id] = bdata ; - } - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsNxsEncryptedDataItem *RsNxsSerialiser::deserialNxsEncryptedDataItem(void* data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM); - uint32_t offset = 8 ; - - RsNxsEncryptedDataItem* item = new RsNxsEncryptedDataItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - item->encrypted_data.tlvtype = TLV_TYPE_BIN_ENCRYPTED ; - - ok &= item->encrypted_data.GetTlv(data,*size,&offset) ; - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*** size functions ***/ - - -uint32_t RsNxsMsg::serial_size()const -{ - - uint32_t s = 8; //header size - - s += 4; // transaction number - s += 1; // pos - s += grpId.serial_size(); - s += msgId.serial_size(); - s += msg.TlvSize(); - s += meta.TlvSize(); - - return s; -} - -uint32_t RsNxsGrp::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 1; // pos - s += grpId.serial_size(); - s += grp.TlvSize(); - s += meta.TlvSize(); - - return s; -} - -uint32_t RsNxsGroupPublishKeyItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += grpId.serial_size() ; - s += private_key.TlvSize(); - - return s; -} -uint32_t RsNxsSyncGrpReqItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 1; // flag - s += 4; // sync age - s += GetTlvStringSize(syncHash); - s += 4; // updateTS - - return s; -} -uint32_t RsNxsSyncGrpStatsItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // request type - s += grpId.serial_size(); - s += 4; // number_of_posts - s += 4; // last_post_TS - - return s; -} - -uint32_t RsNxsSyncGrpItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 4; // publishTs - s += 1; // flag - s += grpId.serial_size(); - s += authorId.serial_size(); - - return s; -} - - -uint32_t RsNxsSyncMsgReqItem::serial_size() const -{ - - uint32_t s = 8; - - s += 4; // transaction number - s += 1; // flag - s += 4; // age - s += grpId.serial_size(); - s += GetTlvStringSize(syncHash); - s += 4; // updateTS - - return s; -} - - -uint32_t RsNxsSyncMsgItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 1; // flag - s += grpId.serial_size(); - s += msgId.serial_size(); - s += authorId.serial_size(); - - return s; -} - -uint32_t RsNxsTransacItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 2; // flag - s += 4; // nMsgs - s += 4; // updateTS - - return s; -} -uint32_t RsNxsEncryptedDataItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += encrypted_data.TlvSize() ; - - return s; -} -uint32_t RsNxsSessionKeyItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += EVP_MAX_IV_LENGTH ; // iv - s += 4 ; // encrypted_session_keys.size() ; - - for(std::map::const_iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - s += it->first.serial_size() + it->second.TlvSize() ; - - return s; -} - - -std::ostream& RsNxsSyncGrpReqItem::print(std::ostream &out, uint16_t indent) -{ - - printRsItemBase(out, "RsNxsSyncGrp", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "Hash: " << syncHash << std::endl; - printIndent(out , int_Indent); - out << "Sync Age: " << createdSince << std::endl; - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "updateTS: " << updateTS << std::endl; - - printRsItemEnd(out ,"RsNxsSyncGrp", indent); - - return out; -} -std::ostream& RsNxsGroupPublishKeyItem::print(std::ostream &out, uint16_t indent) -{ - - printRsItemBase(out, "RsNxsGroupPublishKeyItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "GroupId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "keyId: " << private_key.keyId << std::endl; - - printRsItemEnd(out ,"RsNxsGroupPublishKeyItem", indent); - - return out; -} - - -std::ostream& RsNxsSyncMsgReqItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSyncMsg", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "GrpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "createdSince: " << createdSinceTS << std::endl; - printIndent(out , int_Indent); - out << "syncHash: " << syncHash << std::endl; - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "updateTS: " << updateTS << std::endl; - - printRsItemEnd(out, "RsNxsSyncMsg", indent); - return out; -} - -std::ostream& RsNxsSyncGrpItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSyncGrpItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "publishTs: " << publishTs << std::endl; - printIndent(out , int_Indent); - out << "authorId: " << authorId << std::endl; - - printRsItemEnd(out , "RsNxsSyncGrpItem", indent); - return out; -} - - - -std::ostream& RsNxsSyncMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSyncMsgItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "msgId: " << msgId << std::endl; - printIndent(out , int_Indent); - out << "authorId: " << authorId << std::endl; - printIndent(out , int_Indent); - - printRsItemEnd(out ,"RsNxsSyncMsgItem", indent); - return out; -} - -RsNxsGrp* RsNxsGrp::clone() const { - RsNxsGrp* grp = new RsNxsGrp(PacketService()); - *grp = *this; - - if(this->metaData) - { - grp->metaData = new RsGxsGrpMetaData(); -// *(grp->metaData) = *(this->metaData); - } - - return grp; -} - -std::ostream& RsNxsGrp::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsGrp", indent); - uint16_t int_Indent = indent + 2; - - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "grp: " << std::endl; - printIndent(out , int_Indent); - out << "pos: " << pos << std::endl; - grp.print(out, int_Indent); - out << "meta: " << std::endl; - meta.print(out, int_Indent); - - printRsItemEnd(out, "RsNxsGrp", indent); - return out; -} - -std::ostream& RsNxsMsg::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsMsg", indent); - uint16_t int_Indent = indent + 2; - - out << "msgId: " << msgId << std::endl; - printIndent(out , int_Indent); - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "pos: " << pos << std::endl; - printIndent(out , int_Indent); - out << "msg: " << std::endl; - msg.print(out, indent); - out << "meta: " << std::endl; - meta.print(out, int_Indent); - - printRsItemEnd(out ,"RsNxsMsg", indent); - return out; -} - -std::ostream& RsNxsSyncGrpStatsItem::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsSyncGrpStats", indent); - uint16_t int_Indent = indent + 2; - - out << "available posts: " << number_of_posts << std::endl; - printIndent(out , int_Indent); - out << "last update: " << last_post_TS << std::endl; - printIndent(out , int_Indent); - out << "group ID: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "request type: " << request_type << std::endl; - printIndent(out , int_Indent); - - printRsItemEnd(out ,"RsNxsSyncGrpStats", indent); - return out; -} -std::ostream& RsNxsTransacItem::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsTransac", indent); - uint16_t int_Indent = indent + 2; - - out << "transactFlag: " << transactFlag << std::endl; - printIndent(out , int_Indent); - out << "nItems: " << nItems << std::endl; - printIndent(out , int_Indent); - out << "timeout: " << timestamp << std::endl; - printIndent(out , int_Indent); - out << "updateTS: " << updateTS << std::endl; - printIndent(out , int_Indent); - out << "transactionNumber: " << transactionNumber << std::endl; - printIndent(out , int_Indent); - - printRsItemEnd(out ,"RsNxsTransac", indent); - return out; -} -std::ostream& RsNxsSessionKeyItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSessionKeyItem", indent); - - out << " iv: " << RsUtil::BinToHex((char*)iv,EVP_MAX_IV_LENGTH) << std::endl; - - out << " encrypted keys: " << std::endl; - - for(std::map::const_iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - out << " id=" << it->first << ": ekey=" << RsUtil::BinToHex((char*)it->second.bin_data,it->second.bin_len) << std::endl; - - printRsItemEnd(out ,"RsNxsSessionKeyItem", indent); - return out; -} -std::ostream& RsNxsEncryptedDataItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsEncryptedDataItem", indent); - - out << " encrypted data: " << RsUtil::BinToHex((char*)encrypted_data.bin_data,std::min(50u,encrypted_data.bin_len)) ; - - if(encrypted_data.bin_len > 50u) - out << "..." ; - - out << std::endl; - - printRsItemEnd(out ,"RsNxsSessionKeyItem", indent); - return out; -} -#endif diff --git a/libretroshare/src/rsitems/rsrttitems.cc b/libretroshare/src/rsitems/rsrttitems.cc index c4c499f79..033975a3b 100644 --- a/libretroshare/src/rsitems/rsrttitems.cc +++ b/libretroshare/src/rsitems/rsrttitems.cc @@ -63,339 +63,5 @@ void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneric RsTypeSerializer::serial_process(j,ctx,mPongTS,"mPongTS") ; } -#ifdef TO_REMOVE -RsRttPingItem::~RsRttPingItem() -{ - return; -} -void RsRttPingItem::clear() -{ - mSeqNo = 0; - mPingTS = 0; -} - -std::ostream& RsRttPingItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsRttPingItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "SeqNo: " << mSeqNo << std::endl; - - printIndent(out, int_Indent); - out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; - - printRsItemEnd(out, "RsRttPingItem", indent); - return out; -} - - - - - -RsRttPongItem::~RsRttPongItem() -{ - return; -} - -void RsRttPongItem::clear() -{ - mSeqNo = 0; - mPingTS = 0; - mPongTS = 0; -} - - -std::ostream& RsRttPongItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsRttPongItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "SeqNo: " << mSeqNo << std::endl; - - printIndent(out, int_Indent); - out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; - - printIndent(out, int_Indent); - out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl; - - printRsItemEnd(out, "RsRttPongItem", indent); - return out; -} - - -/*************************************************************************/ - - -uint32_t RsRttSerialiser::sizeRttPingItem(RsRttPingItem */*item*/) -{ - uint32_t s = 8; /* header */ - s += 4; /* seqno */ - s += 8; /* pingTS */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsRttSerialiser::serialiseRttPingItem(RsRttPingItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeRttPingItem(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 << "RsRttSerialiser::serialiseRttPingItem() Header: " << ok << std::endl; - std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo); - ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size Error! " << std::endl; - } - - return ok; -} - -RsRttPingItem *RsRttSerialiser::deserialiseRttPingItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RTT_PING != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsRttPingItem *item = new RsRttPingItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo)); - ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ -/*************************************************************************/ - - -uint32_t RsRttSerialiser::sizeRttPongItem(RsRttPongItem */*item*/) -{ - uint32_t s = 8; /* header */ - s += 4; /* seqno */ - s += 8; /* pingTS */ - s += 8; /* pongTS */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsRttSerialiser::serialiseRttPongItem(RsRttPongItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeRttPongItem(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 << "RsRttSerialiser::serialiseRttPongItem() Header: " << ok << std::endl; - std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo); - ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS); - ok &= setRawUInt64(data, tlvsize, &offset, item->mPongTS); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size Error! " << std::endl; - } - - return ok; -} - -RsRttPongItem *RsRttSerialiser::deserialiseRttPongItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RTT_PONG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsRttPongItem *item = new RsRttPongItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo)); - ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS)); - ok &= getRawUInt64(data, rssize, &offset, &(item->mPongTS)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -uint32_t RsRttSerialiser::size(RsItem *i) -{ - RsRttPingItem *ping; - RsRttPongItem *pong; - - if (NULL != (ping = dynamic_cast(i))) - { - return sizeRttPingItem(ping); - } - else if (NULL != (pong = dynamic_cast(i))) - { - return sizeRttPongItem(pong); - } - return 0; -} - -bool RsRttSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialise()" << std::endl; -#endif - - RsRttPingItem *ping; - RsRttPongItem *pong; - - if (NULL != (ping = dynamic_cast(i))) - { - return serialiseRttPingItem(ping, data, pktsize); - } - else if (NULL != (pong = dynamic_cast(i))) - { - return serialiseRttPongItem(pong, data, pktsize); - } - return false; -} - -RsItem* RsRttSerialiser::deserialise(void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsRttSerialiser::deserialise()" << std::endl; -#endif - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_RTT != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_RTT_PING: - return deserialiseRttPingItem(data, pktsize); - break; - case RS_PKT_SUBTYPE_RTT_PONG: - return deserialiseRttPongItem(data, pktsize); - break; - default: - return NULL; - break; - } - - return NULL; -} - - -/*************************************************************************/ -#endif diff --git a/libretroshare/src/rsitems/rswikiitems.cc b/libretroshare/src/rsitems/rswikiitems.cc index ec42e14f0..96f9e2768 100644 --- a/libretroshare/src/rsitems/rswikiitems.cc +++ b/libretroshare/src/rsitems/rswikiitems.cc @@ -46,94 +46,6 @@ RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id) } } -#ifdef TO_REMOVE -uint32_t RsGxsWikiSerialiser::size(RsItem *item) -{ - RsGxsWikiCollectionItem* grp_item = NULL; - RsGxsWikiSnapshotItem* snap_item = NULL; - RsGxsWikiCommentItem* com_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWikiCollectionItem(grp_item); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWikiSnapshotItem(snap_item); - } - else if((com_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWikiCommentItem(com_item); - } - return 0; -} - -bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsGxsWikiCollectionItem* grp_item = NULL; - RsGxsWikiSnapshotItem* snap_item = NULL; - RsGxsWikiCommentItem* com_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWikiCollectionItem(grp_item, data, size); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWikiSnapshotItem(snap_item, data, size); - } - else if((com_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWikiCommentItem(com_item, data, size); - } - return false; -} - -RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM: - return deserialiseGxsWikiCollectionItem(data, size); - break; - case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM: - return deserialiseGxsWikiSnapshotItem(data, size); - break; - case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM: - return deserialiseGxsWikiCommentItem(data, size); - break; - default: -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWikiCollectionItem::clear() { collection.mDescription.clear(); @@ -141,38 +53,6 @@ void RsGxsWikiCollectionItem::clear() collection.mHashTags.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWikiCollectionItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << collection.mDescription << std::endl; - printIndent(out, int_Indent); - out << "Category: " << collection.mCategory << std::endl; - printIndent(out, int_Indent); - out << "HashTags: " << collection.mHashTags << std::endl; - - printRsItemEnd(out ,"RsGxsWikiCollectionItem", indent); - return out; -} - - -uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item) -{ - - const RsWikiCollection& collection = item->collection; - uint32_t s = 8; // header - - s += GetTlvStringSize(collection.mDescription); - s += GetTlvStringSize(collection.mCategory); - s += GetTlvStringSize(collection.mHashTags); - - return s; -} -#endif - void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ; @@ -180,448 +60,25 @@ void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ; } -#ifdef TO_REMOVE -bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWikiCollectionItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWikiCollectionItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWikiCollectionItem* item = new RsGxsWikiCollectionItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWikiSnapshotItem::clear() { snapshot.mPage.clear(); snapshot.mHashTags.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWikiSnapshotItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Page: " << snapshot.mPage << std::endl; - - printIndent(out, int_Indent); - out << "HashTags: " << snapshot.mHashTags << std::endl; - - printRsItemEnd(out ,"RsGxsWikiSnapshotItem", indent); - return out; -} - - -uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item) -{ - - const RsWikiSnapshot& snapshot = item->snapshot; - uint32_t s = 8; // header - - s += GetTlvStringSize(snapshot.mPage); - s += GetTlvStringSize(snapshot.mHashTags); - - return s; -} -#endif - void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ; } -#ifdef TO_REMOVE -bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWikiSnapshotItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWikiSnapshotItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWikiSnapshotItem* item = new RsGxsWikiSnapshotItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWikiCommentItem::clear() { comment.mComment.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWikiCommentItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Comment: " << comment.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsWikiCommentItem", indent); - return out; -} - - -uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item) -{ - - const RsWikiComment& comment = item->comment; - uint32_t s = 8; // header - - s += GetTlvStringSize(comment.mComment); - - return s; -} -#endif - void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ; } -#ifdef TO_REMOVE -bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWikiCommentItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWikiCommentItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWikiCommentItem* item = new RsGxsWikiCommentItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -#endif diff --git a/libretroshare/src/rsitems/rswireitems.cc b/libretroshare/src/rsitems/rswireitems.cc index 55a56a803..7a8008ff8 100644 --- a/libretroshare/src/rsitems/rswireitems.cc +++ b/libretroshare/src/rsitems/rswireitems.cc @@ -46,398 +46,19 @@ RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) } } -#ifdef TO_REMOVE -uint32_t RsGxsWireSerialiser::size(RsItem *item) -{ - RsGxsWireGroupItem* grp_item = NULL; - RsGxsWirePulseItem* snap_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWireGroupItem(grp_item); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWirePulseItem(snap_item); - } - return 0; -} - -bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsGxsWireGroupItem* grp_item = NULL; - RsGxsWirePulseItem* snap_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWireGroupItem(grp_item, data, size); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWirePulseItem(snap_item, data, size); - } - return false; -} - -RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: - return deserialiseGxsWireGroupItem(data, size); - break; - case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: - return deserialiseGxsWirePulseItem(data, size); - break; - default: -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWireGroupItem::clear() { group.mDescription.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWireGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << group.mDescription << std::endl; - - printRsItemEnd(out ,"RsGxsWireGroupItem", indent); - return out; -} - - -uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item) -{ - - const RsWireGroup& group = item->group; - uint32_t s = 8; // header - - s += GetTlvStringSize(group.mDescription); - - return s; -} - -#endif - void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ; } -#ifdef TO_REMOVE -bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWireGroupItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWireGroupItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription); - - if(offset != tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef WIRE_DEBUG - if (!ok) - { - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWireGroupItem* item = new RsGxsWireGroupItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription); - - if (offset != rssize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsWirePulseItem::clear() -{ - pulse.mPulseText.clear(); - pulse.mHashTags.clear(); -} - -std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWirePulseItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Page: " << pulse.mPulseText << std::endl; - - printIndent(out, int_Indent); - out << "HashTags: " << pulse.mHashTags << std::endl; - - printRsItemEnd(out ,"RsGxsWirePulseItem", indent); - return out; -} - - -uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item) -{ - - const RsWirePulse& pulse = item->pulse; - uint32_t s = 8; // header - - s += GetTlvStringSize(pulse.mPulseText); - s += GetTlvStringSize(pulse.mHashTags); - - return s; -} - -#endif - void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ; } -#ifdef TO_REMOVE -bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWirePulseItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWirePulseItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags); - - if(offset != tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef WIRE_DEBUG - if (!ok) - { - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype))) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWirePulseItem* item = new RsGxsWirePulseItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags); - - if (offset != rssize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif From 214aaa7c9b08c9a1106497c30ce2006ffa68b838 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 3 May 2017 22:20:58 +0200 Subject: [PATCH 100/106] added safety check for null chunks in TlvMemBlock_proxy deserialization --- .../src/serialiser/rstypeserializer.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/serialiser/rstypeserializer.cc b/libretroshare/src/serialiser/rstypeserializer.cc index 661897b4b..f4cfc0d62 100644 --- a/libretroshare/src/serialiser/rstypeserializer.cc +++ b/libretroshare/src/serialiser/rstypeserializer.cc @@ -32,6 +32,7 @@ #include static const uint32_t MAX_SERIALIZED_ARRAY_SIZE = 500 ; +static const uint32_t MAX_SERIALIZED_CHUNK_SIZE = 10*1024*1024 ; // 10 MB. //=================================================================================================// // Integer types // @@ -231,9 +232,25 @@ template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size bool ok = deserialize(data,size,offset,r.second) ; + if(r.second == 0) + { + r.first = NULL ; + + if(!ok) + offset = saved_offset ; + + return ok ; + } + if(r.second > MAX_SERIALIZED_CHUNK_SIZE) + { + std::cerr << "(EE) RsTypeSerializer::deserialize(): data chunk has size larger than safety size (" << MAX_SERIALIZED_CHUNK_SIZE << "). Item will be dropped." << std::endl; + offset = saved_offset ; + return false ; + } + r.first = (uint8_t*)rs_malloc(r.second) ; - ok = ok && NULL != r.first; + ok = ok && (NULL != r.first); memcpy(r.first,&data[offset],r.second) ; offset += r.second ; From 4f4240d570ae6982e2ae475559ab0b026d31d0a9 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 3 May 2017 22:43:16 +0200 Subject: [PATCH 101/106] fixed bug in history serializer --- libretroshare/src/rsitems/rshistoryitems.cc | 6 +++--- libretroshare/src/rsitems/rshistoryitems.h | 2 +- libretroshare/src/serialiser/rsserializer.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/rsitems/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc index 23aa9e38f..a66299b51 100644 --- a/libretroshare/src/rsitems/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -51,12 +51,12 @@ void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message") ; } -RsItem *RsHistorySerialiser::create_item(uint8_t serial_class,uint8_t serial_type) const +RsItem *RsHistorySerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const { - if(serial_class != RS_PKT_CLASS_CONFIG) + if(item_type != RS_PKT_TYPE_HISTORY_CONFIG) return NULL ; - if(serial_type == RS_PKT_SUBTYPE_DEFAULT) + if(item_subtype == RS_PKT_SUBTYPE_DEFAULT) return new RsHistoryMsgItem(); return NULL ; diff --git a/libretroshare/src/rsitems/rshistoryitems.h b/libretroshare/src/rsitems/rshistoryitems.h index 04d3e9ca7..802754e91 100644 --- a/libretroshare/src/rsitems/rshistoryitems.h +++ b/libretroshare/src/rsitems/rshistoryitems.h @@ -63,7 +63,7 @@ public: RsHistorySerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) {} virtual ~RsHistorySerialiser() {} - virtual RsItem *create_item(uint8_t service,uint8_t type) const ; + virtual RsItem *create_item(uint8_t item_type,uint8_t item_subtype) const ; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rsserializer.h b/libretroshare/src/serialiser/rsserializer.h index c9f1f6403..2cae93ab7 100644 --- a/libretroshare/src/serialiser/rsserializer.h +++ b/libretroshare/src/serialiser/rsserializer.h @@ -289,7 +289,7 @@ public: /*! create_item * should be overloaded to create the correct type of item depending on the data */ - virtual RsItem *create_item(uint8_t /* class */, uint8_t /* item_type */) const=0; + virtual RsItem *create_item(uint8_t /* item_type */, uint8_t /* item_sub_type */) const=0; RsItem *deserialise(void *data,uint32_t *size) ; }; From 6484ea66f7f8119cdb9b06c938367cdd774a493a Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 4 May 2017 21:19:23 +0200 Subject: [PATCH 102/106] improved graph widget --- .../src/gui/common/RSGraphWidget.cpp | 32 +++++++++++++++++-- retroshare-gui/src/gui/common/RSGraphWidget.h | 9 ++++-- .../gui/statistics/BandwidthStatsWidget.cpp | 2 ++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.cpp b/retroshare-gui/src/gui/common/RSGraphWidget.cpp index b7759d846..d0bbaa1dc 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.cpp +++ b/retroshare-gui/src/gui/common/RSGraphWidget.cpp @@ -259,6 +259,7 @@ RSGraphWidget::RSGraphWidget(QWidget *parent) _maxPoints = getNumPoints(); _maxValue = MINUSER_SCALE; + _linewidthscale = 1.0f; _opacity = 0.6 ; _flags = 0; _time_scale = 5.0f ; // in pixels per second. @@ -414,12 +415,16 @@ void RSGraphWidget::paintData() /* Plot the bandwidth as solid lines. If the graph style is currently an * area graph, we end up outlining the integrals. */ - paintLine(points, getColor(i)); + + if(_flags & RSGRAPH_FLAGS_PAINT_STYLE_DOTS) + paintDots(points, getColor(i)); + else + paintLine(points, getColor(i)); } if(_maxValue > 0.0f) { if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y) - _y_scale = _rec.height()*0.8 / log(_maxValue) ; + _y_scale = _rec.height()*0.8 / log(std::max(2.0,_maxValue)) ; else _y_scale = _rec.height()*0.8/_maxValue ; } @@ -539,11 +544,27 @@ void RSGraphWidget::paintLine(const QVector& points, QColor color, Qt:: { /* Save the current brush, plot the line, and restore the old brush */ QPen oldPen = _painter->pen(); - _painter->setPen(QPen(color, lineStyle)); + + QPen newPen(color, lineStyle); + newPen.setWidth(2.0f*_linewidthscale); + _painter->setPen(newPen); _painter->drawPolyline(points.data(), points.size()); _painter->setPen(oldPen); } +void RSGraphWidget::paintDots(const QVector& points, QColor color) +{ + /* Save the current brush, plot the line, and restore the old brush */ + QPen oldPen = _painter->pen(); + _painter->setPen(QPen(color, oldPen.style())); + QBrush oldBrush = _painter->brush(); + _painter->setBrush(QBrush(color)); + for(int i=0;idrawEllipse(QRect(points[i].x(),points[i].y(),5*_linewidthscale,5*_linewidthscale)) ; + + _painter->setPen(oldPen); + _painter->setBrush(oldBrush); +} /** Paints selected total indicators on the graph. */ void RSGraphWidget::paintTotals() { @@ -641,6 +662,11 @@ void RSGraphWidget::wheelEvent(QWheelEvent *e) _time_filter *= 1.1 ; else _time_filter /= 1.1 ; + else if(e->modifiers() & Qt::ControlModifier) + if(e->delta() > 0) + _linewidthscale *= 1.2 ; + else + _linewidthscale /= 1.2 ; else if(e->delta() > 0) _time_scale *= 1.1 ; diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.h b/retroshare-gui/src/gui/common/RSGraphWidget.h index 2159ba0dc..b57833d51 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.h +++ b/retroshare-gui/src/gui/common/RSGraphWidget.h @@ -126,6 +126,7 @@ public: static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes static const uint32_t RSGRAPH_FLAGS_LEGEND_CUMULATED = 0x0040 ;// show the total in the legend rather than current values + static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_DOTS = 0x0080 ;// use dots /** Bandwidth graph style. */ enum GraphStyle @@ -191,8 +192,11 @@ private: void pointsFromData(const std::vector& values, QVector &points ) ; /** Paints a line with the data in points. */ - void paintLine(const QVector& points, QColor color, - Qt::PenStyle lineStyle = Qt::SolidLine); + void paintLine(const QVector& points, QColor color, Qt::PenStyle lineStyle = Qt::SolidLine); + + /** Paint a series of large dots **/ + void paintDots(const QVector& points, QColor color); + /** Paints an integral using the supplied data. */ void paintIntegral(const QVector& points, QColor color, qreal alpha = 1.0); @@ -214,6 +218,7 @@ private: qreal _time_scale ; // horizontal scale in pixels per sec. qreal _time_filter ; // time filter. Goes from 0 to infinity. Will be converted into 1-1/(1+f) + float _linewidthscale ; /** Show the respective lines and counters. */ //bool _showRSDHT; diff --git a/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp b/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp index 6ae112803..9fd2dfa3c 100644 --- a/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp +++ b/retroshare-gui/src/gui/statistics/BandwidthStatsWidget.cpp @@ -201,11 +201,13 @@ void BandwidthStatsWidget::updateUnitSelection(int n) if(n==0) { ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ; + ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_DOTS); ui.legend_CB->setItemText(1,tr("Average")); } else { ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_COUNT) ; + ui.bwgraph_BW->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_DOTS); ui.legend_CB->setItemText(1,tr("Total")); } } From e913f3689a62ba5992238db9b7cab6fd1a67e49d Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 4 May 2017 21:40:32 +0200 Subject: [PATCH 103/106] fixed crash when trying to deserialize an empty buffer in rsrecogn --- libretroshare/src/util/rsrecogn.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libretroshare/src/util/rsrecogn.cc b/libretroshare/src/util/rsrecogn.cc index f42a4dd6f..8580c7780 100644 --- a/libretroshare/src/util/rsrecogn.cc +++ b/libretroshare/src/util/rsrecogn.cc @@ -552,6 +552,9 @@ RsGxsRecognTagItem *RsRecogn::extractTag(const std::string &encoded) std::vector buffer = Radix64::decode(encoded); pktsize = buffer.size(); + if(buffer.empty()) + return NULL ; + RsGxsRecognSerialiser serialiser; RsItem *item = serialiser.deserialise(buffer.data(), &pktsize); From f7f36f697e8d139691fe0715397d95afe1492329 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 5 May 2017 17:52:44 +0200 Subject: [PATCH 104/106] fixup! Merge branch 'master' into gxs_mail_experiments --- libretroshare/src/rsitems/rsnxsitems.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libretroshare/src/rsitems/rsnxsitems.h b/libretroshare/src/rsitems/rsnxsitems.h index 247e664fa..127d876f6 100644 --- a/libretroshare/src/rsitems/rsnxsitems.h +++ b/libretroshare/src/rsitems/rsnxsitems.h @@ -372,8 +372,6 @@ struct RsNxsMsg : RsNxsItem msg(servtype), metaData(NULL) { clear(); } virtual ~RsNxsMsg() { delete metaData; } - virtual void clear(); - virtual void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ); From ea8f800003330eaabb576092a1697b79eb96bfc8 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 8 May 2017 00:19:11 +0200 Subject: [PATCH 105/106] Port GxsTrans to new serialization system RsItem added some comment and more verbose error reporting RsTypeSerializer added support for RsItem derived classes as members added utility macros for better readability of the code and easier handling of RsItem derived members RS_REGISTER_SERIAL_MEMBER(I) RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) RS_REGISTER_ITEM_TYPE(T) RsNxsMsg::serial_process use new macros for better readability and to have an exemple of usage with RsTlvItem derived class Fix undefined reference to RsNxsMsg::print --- libretroshare/src/chat/p3chatservice.cc | 9 +- libretroshare/src/chat/rschatitems.cc | 7 + libretroshare/src/chat/rschatitems.h | 11 + libretroshare/src/gxstrans/p3gxstrans.cc | 20 +- libretroshare/src/gxstrans/p3gxstransitems.cc | 193 +--- libretroshare/src/gxstrans/p3gxstransitems.h | 167 +--- libretroshare/src/rsitems/rsitem.h | 25 +- libretroshare/src/rsitems/rsnxsitems.cc | 26 +- libretroshare/src/rsitems/rsnxsitems.h | 2 +- .../src/serialiser/rstypeserializer.cc | 56 ++ .../src/serialiser/rstypeserializer.h | 867 ++++++++++-------- 11 files changed, 655 insertions(+), 728 deletions(-) diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index 3798666e5..32dbe64a5 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -346,9 +346,9 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg) if(it != mDistantGxsMap.end()) { const DistantEndpoints& de(it->second); - uint32_t sz = ci->serial_size(); + uint32_t sz = _serializer->size(ci); std::vector data; data.resize(sz); - ci->serialise(&data[0], sz); + _serializer->serialise(ci, &data[0], &sz); mGxsTransport.sendMail(tId, GxsTransSubServices::P3_CHAT_SERVICE, de.from, de.to, &data[0], sz); } @@ -717,8 +717,9 @@ bool p3ChatService::receiveGxsTransMail( const RsGxsId& authorId, if(initiateDistantChatConnexion( authorId, recipientId, pid, error_code, false )) { - RsChatMsgItem* item = new RsChatMsgItem( const_cast(data), - dataSize ); + RsChatMsgItem* item = static_cast( + _serializer->deserialise( + const_cast(data), &dataSize )); RsPeerId rd(p3GxsTunnelService::makeGxsTunnelId(authorId, recipientId)); item->PeerId(rd); handleRecvChatMsgItem(item); diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 2b7dd67d8..35ccaa905 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -195,4 +195,11 @@ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci) ci->recvTime = recvTime; } +/* Necessary to serialize `store` that is an STL container with RsChatMsgItem + * inside which is a subtype of RsItem */ +RS_REGISTER_ITEM_TYPE(RsChatMsgItem) +void PrivateOugoingMapItem::serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) +{ RS_REGISTER_SERIAL_MEMBER(store); } diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 617ca3276..253bb66f1 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -325,6 +325,17 @@ class RsChatAvatarItem: public RsChatItem unsigned char *image_data ; // image }; + +struct PrivateOugoingMapItem : RsChatItem +{ + PrivateOugoingMapItem() : RsChatItem(RS_PKT_SUBTYPE_OUTGOING_MAP) {} + + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ); + + std::map store; +}; + struct RsChatSerialiser : RsServiceSerializer { RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index b36a6ade6..4454bf6e1 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -478,14 +478,16 @@ bool p3GxsTrans::dispatchDecryptedMail( const RsGxsId& authorId, } GxsTransSubServices rsrvc = static_cast(csri); - RsNxsTransPresignedReceipt* receipt = new RsNxsTransPresignedReceipt(); uint32_t rcptsize = decrypted_data_size; - if(!receipt->deserialize(decrypted_data, rcptsize, offset)) + RsNxsTransPresignedReceipt* receipt = + static_cast( + RsGxsTransSerializer().deserialise( + const_cast(decrypted_data), &rcptsize ) ); + if(!receipt) { std::cerr << "p3GxsTrans::dispatchDecryptedMail(...) (EE) fatal error " << "deserializing presigned return receipt , something really" << " wrong is happening!" << std::endl; - delete receipt; return false; } std::cout << "p3GxsTrans::dispatchDecryptedMail(...) dispatching receipt " @@ -541,10 +543,10 @@ void p3GxsTrans::processOutgoingRecord(OutgoingRecord& pr) grcpt.meta = pr.mailItem.meta; grcpt.meta.mPublishTs = time(NULL); grcpt.mailId = pr.mailItem.mailId; - uint32_t groff = 0, grsz = grcpt.serial_size(); + uint32_t grsz = RsGxsTransSerializer().size(&grcpt); std::vector grsrz; grsrz.resize(grsz); - grcpt.serialize(&grsrz[0], grsz, groff); + RsGxsTransSerializer().serialise(&grcpt, &grsrz[0], &grsz); pr.presignedReceipt.grpId = mPreferredGroupId; pr.presignedReceipt.metaData = new RsGxsMsgMetaData(); @@ -572,13 +574,14 @@ void p3GxsTrans::processOutgoingRecord(OutgoingRecord& pr) case GxsTransSendStatus::PENDING_PAYLOAD_CREATE: { uint16_t serv = static_cast(pr.clientService); - uint32_t rcptsize = pr.presignedReceipt.serial_size(); + uint32_t rcptsize = RsGxsTransSerializer().size(&pr.presignedReceipt); uint32_t datasize = pr.mailData.size(); pr.mailItem.payload.resize(2 + rcptsize + datasize); uint32_t offset = 0; setRawUInt16(&pr.mailItem.payload[0], 2, &offset, serv); - pr.presignedReceipt.serialise( &pr.mailItem.payload[offset], - rcptsize ); + RsGxsTransSerializer().serialise(&pr.presignedReceipt, + &pr.mailItem.payload[offset], + &rcptsize); offset += rcptsize; memcpy(&pr.mailItem.payload[offset], &pr.mailData[0], datasize); } @@ -781,4 +784,3 @@ bool p3GxsTrans::loadList(std::list&loadList) return true; } - diff --git a/libretroshare/src/gxstrans/p3gxstransitems.cc b/libretroshare/src/gxstrans/p3gxstransitems.cc index eb5736f8e..cab1e2dfb 100644 --- a/libretroshare/src/gxstrans/p3gxstransitems.cc +++ b/libretroshare/src/gxstrans/p3gxstransitems.cc @@ -17,88 +17,14 @@ */ #include "gxstrans/p3gxstransitems.h" +#include "serialiser/rstypeserializer.h" const RsGxsId RsGxsTransMailItem::allRecipientsHint("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - -bool RsGxsTransBaseItem::serialize(uint8_t* data, uint32_t size, - uint32_t& offset) const -{ - bool ok = setRsItemHeader(data+offset, size, PacketId(), size); - ok = ok && (offset += 8); // Take header in account - ok = ok && setRawUInt64(data, size, &offset, mailId); - return ok; -} - -bool RsGxsTransBaseItem::deserialize( const uint8_t* data, uint32_t& size, - uint32_t& offset) -{ - void* hdrPtr = const_cast(data+offset); - uint32_t rssize = getRsItemSize(hdrPtr); - uint32_t roffset = offset + 8; // Take header in account - - void* dataPtr = const_cast(data); - bool ok = rssize <= size; - ok = ok && getRawUInt64(dataPtr, rssize, &roffset, &mailId); - if(ok) { size = rssize; offset = roffset; } - else size = 0; - return ok; -} - -std::ostream& RsGxsTransBaseItem::print(std::ostream &out, uint16_t) -{ return out << __PRETTY_FUNCTION__ << " mailId: " << mailId; } - -bool RsGxsTransSerializer::serialise(RsItem* item, void* data, uint32_t* size) -{ - uint32_t itemSize = RsGxsTransSerializer::size(item); - if(*size < itemSize) - { - std::cout << __PRETTY_FUNCTION__ << " failed due to wrong size: " - << size << " < " << itemSize << std::endl; - return false; - } - - uint8_t* dataPtr = reinterpret_cast(data); - bool ok = false; - switch(static_cast(item->PacketSubType())) - { - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: - { - uint32_t offset = 0; - RsGxsTransMailItem* i = dynamic_cast(item); - ok = i && i->serialize(dataPtr, itemSize, offset); - break; - } - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT: - { - RsGxsTransPresignedReceipt* i = - dynamic_cast(item); - uint32_t offset = 0; - ok = i && i->serialize(dataPtr, itemSize, offset); - break; - } - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: - ok = setRsItemHeader(data, itemSize, item->PacketId(), itemSize); - break; - case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM: - { - uint32_t offset = 0; - OutgoingRecord* i = dynamic_cast(item); - ok = i && i->serialize(dataPtr, itemSize, offset); - break; - } - default: ok = false; break; - } - - if(ok) - { - *size = itemSize; - return true; - } - - std::cout << __PRETTY_FUNCTION__ << " failed!" << std::endl; - return false; -} +OutgoingRecord::OutgoingRecord() : + RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS, + static_cast(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM) ) +{ clear();} OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsTransSubServices cs, const uint8_t* data, uint32_t size ) : @@ -111,102 +37,17 @@ OutgoingRecord::OutgoingRecord( RsGxsId rec, GxsTransSubServices cs, memcpy(&mailData[0], data, size); } -void OutgoingRecord::clear() + +RS_REGISTER_ITEM_TYPE(RsGxsTransMailItem) // for mailItem +RS_REGISTER_ITEM_TYPE(RsNxsTransPresignedReceipt) // for presignedReceipt + +void OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx) { - status = GxsTransSendStatus::UNKNOWN; - recipient.clear(); - mailItem.clear(); - mailData.clear(); - clientService = GxsTransSubServices::UNKNOWN; - presignedReceipt.clear(); + RS_REGISTER_SERIAL_MEMBER_TYPED(status, uint8_t); + RS_REGISTER_SERIAL_MEMBER(recipient); + RS_REGISTER_SERIAL_MEMBER(mailItem); + RS_REGISTER_SERIAL_MEMBER(mailData); + RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t); + RS_REGISTER_SERIAL_MEMBER(presignedReceipt); } - -std::ostream& OutgoingRecord::print(std::ostream& out, uint16_t) -{ return out << "TODO: OutgoingRecordItem::print(...)"; } - -OutgoingRecord::OutgoingRecord() : - RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_GXS_TRANS, - static_cast(GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM) ) -{ clear();} - -uint32_t OutgoingRecord::serial_size() const -{ - return 8 + // Header - 1 + // status - recipient.serial_size() + - mailItem.serial_size() + - 4 + // sizeof(mailData.size()) - mailData.size() + - 2 + // clientService - presignedReceipt.serial_size(); -} - -bool OutgoingRecord::serialize( uint8_t* data, uint32_t size, - uint32_t& offset) const -{ - bool ok = true; - - ok = ok && setRsItemHeader(data+offset, size, PacketId(), size) - && (offset += 8); // Take header in account - - ok = ok && setRawUInt8(data, size, &offset, static_cast(status)); - - ok = ok && recipient.serialise(data, size, offset); - - uint32_t tmpOffset = 0; - uint32_t tmpSize = mailItem.serial_size(); - ok = ok && mailItem.serialize(data+offset, tmpSize, tmpOffset) - && (offset += tmpOffset); - - uint32_t dSize = mailData.size(); - ok = ok && setRawUInt32(data, size, &offset, dSize) - && memcpy(data+offset, &mailData[0], dSize) && (offset += dSize); - - ok = ok && setRawUInt16( data, size, &offset, - static_cast(clientService) ); - - dSize = presignedReceipt.serial_size(); - ok = ok && presignedReceipt.serialise(data+offset, dSize) - && (offset += dSize); - - return ok; -} - -bool OutgoingRecord::deserialize( - const uint8_t* data, uint32_t& size, uint32_t& offset) -{ - bool ok = true; - - void* dataPtr = const_cast(data); - offset += 8; // Header - - uint8_t tmpStatus = 0; - ok = ok && getRawUInt8(dataPtr, size, &offset, &tmpStatus); - status = static_cast(tmpStatus); - - uint32_t tmpSize = size; - ok = ok && recipient.deserialise(dataPtr, tmpSize, offset); - - void* hdrPtr = const_cast(data+offset); - tmpSize = getRsItemSize(hdrPtr); - - uint32_t tmpOffset = 0; - ok = ok && mailItem.deserialize(static_cast(hdrPtr), tmpSize, tmpOffset); - ok = ok && (offset += tmpOffset); - - tmpSize = size; - ok = getRawUInt32(dataPtr, tmpSize, &offset, &tmpSize); - ok = ok && (tmpSize+offset < size); - ok = ok && (mailData.resize(tmpSize), memcpy(&mailData[0], data, tmpSize)); - ok = ok && (offset += tmpSize); - - uint16_t cs = 0; - ok = ok && getRawUInt16(dataPtr, offset+2, &offset, &cs); - clientService = static_cast(cs); - - tmpSize = size; - ok = ok && presignedReceipt.deserialize(data, tmpSize, offset); - - return ok; -} - diff --git a/libretroshare/src/gxstrans/p3gxstransitems.h b/libretroshare/src/gxstrans/p3gxstransitems.h index fa6395f3b..276dd739e 100644 --- a/libretroshare/src/gxstrans/p3gxstransitems.h +++ b/libretroshare/src/gxstrans/p3gxstransitems.h @@ -19,12 +19,13 @@ #include -#include "serialiser/rsgxsitems.h" +#include "rsitems/rsgxsitems.h" #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvidset.h" #include "retroshare/rsgxsflags.h" #include "retroshare/rsgxscircles.h" // For: GXS_CIRCLE_TYPE_PUBLIC #include "services/p3idservice.h" +#include "serialiser/rstypeserializer.h" /// Subservices identifiers (like port for TCP) enum class GxsTransSubServices : uint16_t @@ -65,14 +66,9 @@ struct RsGxsTransBaseItem : RsGxsMsgItem meta = RsMsgMetaData(); } - static uint32_t inline serial_size() - { - return 8 + // Header - 8; // mailId - } - bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const; - bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset); - std::ostream &print(std::ostream &out, uint16_t /*indent = 0*/); + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) + { RS_REGISTER_SERIAL_MEMBER_TYPED(mailId, uint64_t); } }; struct RsGxsTransPresignedReceipt : RsGxsTransBaseItem @@ -149,46 +145,15 @@ struct RsGxsTransMailItem : RsGxsTransBaseItem * is specified */ std::vector payload; - uint32_t serial_size() const + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) { - return RsGxsTransBaseItem::serial_size() + - 1 + // cryptoType - recipientHint.serial_size() + - payload.size(); + RsGxsTransBaseItem::serial_process(j, ctx); + RS_REGISTER_SERIAL_MEMBER_TYPED(cryptoType, uint8_t); + RS_REGISTER_SERIAL_MEMBER(recipientHint); + RS_REGISTER_SERIAL_MEMBER(payload); } - bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const - { - bool ok = size < MAX_SIZE; - ok = ok && RsGxsTransBaseItem::serialize(data, size, offset); - ok = ok && setRawUInt8( data, size, &offset, - static_cast(cryptoType) ); - ok = ok && recipientHint.serialise(data, size, offset); - uint32_t psz = payload.size(); - ok = ok && memcpy(data+offset, &payload[0], psz); - offset += psz; - return ok; - } - bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset) - { - void* sizePtr = const_cast(data+offset); - uint32_t rssize = getRsItemSize(sizePtr); - uint32_t roffset = offset; - bool ok = rssize <= size && size < MAX_SIZE; - ok = ok && RsGxsTransBaseItem::deserialize(data, rssize, roffset); - - void* dataPtr = const_cast(data); - uint8_t crType; - ok = ok && getRawUInt8(dataPtr, rssize, &roffset, &crType); - cryptoType = static_cast(crType); - ok = ok && recipientHint.deserialise(dataPtr, rssize, roffset); - uint32_t psz = rssize - roffset; - ok = ok && (payload.resize(psz), memcpy(&payload[0], data+roffset, psz)); - ok = ok && (roffset += psz); - if(ok) { size = rssize; offset = roffset; } - else size = 0; - return ok; - } void clear() { RsGxsTransBaseItem::clear(); @@ -213,6 +178,11 @@ struct RsGxsTransGroupItem : RsGxsGrpItem meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC; } + // TODO: Talk with Cyril why there is no RsGxsGrpItem::serial_process + virtual void serial_process(RsGenericSerializer::SerializeJob /*j*/, + RsGenericSerializer::SerializeContext& /*ctx*/) + {} + void clear() {} std::ostream &print(std::ostream &out, uint16_t /*indent = 0*/) { return out; } @@ -253,12 +223,10 @@ struct OutgoingRecord : RsItem GxsTransSubServices clientService; RsNxsTransPresignedReceipt presignedReceipt; - uint32_t serial_size() const; - bool serialize(uint8_t* data, uint32_t size, uint32_t& offset) const; - bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset); + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ); - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + void clear() {} private: friend class RsGxsTransSerializer; @@ -266,100 +234,23 @@ private: }; -struct RsGxsTransSerializer : RsSerialType +struct RsGxsTransSerializer : public RsServiceSerializer { - RsGxsTransSerializer() : RsSerialType( RS_PKT_VERSION_SERVICE, - RS_SERVICE_TYPE_GXS_TRANS ) {} + RsGxsTransSerializer() : RsServiceSerializer(RS_SERVICE_TYPE_GXS_TRANS) {} ~RsGxsTransSerializer() {} - uint32_t size(RsItem* item) + RsItem* create_item(uint16_t service_id, uint8_t item_sub_id) const { - uint32_t sz = 0; - switch(static_cast(item->PacketSubType())) - { - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: - { - RsGxsTransMailItem* i = dynamic_cast(item); - if(i) sz = i->serial_size(); - break; - } - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT: - sz = RsGxsTransPresignedReceipt::serial_size(); break; - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: sz = 8; break; - case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM: - { - OutgoingRecord* ci = dynamic_cast(item); - if(ci) sz = ci->serial_size(); - break; - } - default: break; - } + if(service_id != RS_SERVICE_TYPE_GXS_TRANS) return NULL; - return sz; - } - - bool serialise(RsItem* item, void* data, uint32_t* size); - - RsItem* deserialise(void* data, uint32_t* size) - { - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - uint8_t pktv = getRsItemVersion(rstype); - uint16_t srvc = getRsItemService(rstype); - const uint8_t* dataPtr = reinterpret_cast(data); - - if ( (RS_PKT_VERSION_SERVICE != pktv) || // 0x02 - (RS_SERVICE_TYPE_GXS_TRANS != srvc) || // 0x0230 = 560 - (*size < rssize) ) + switch(static_cast(item_sub_id)) { - print_stacktrace(); - return NULL; + case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: return new RsGxsTransMailItem(); + case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT: return new RsGxsTransPresignedReceipt(); + case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: return new RsGxsTransGroupItem(); + case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM: return new OutgoingRecord(); + default: return NULL; } - - *size = rssize; - bool ok = true; - RsItem* ret = NULL; - - switch (static_cast(getRsItemSubType(rstype))) - { - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: - { - RsGxsTransMailItem* i = new RsGxsTransMailItem(); - uint32_t offset = 0; - ok = ok && i->deserialize(dataPtr, *size, offset); - ret = i; - break; - } - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT: - { - RsGxsTransPresignedReceipt* i = new RsGxsTransPresignedReceipt(); - uint32_t offset = 0; - ok &= i->deserialize(dataPtr, *size, offset); - ret = i; - break; - } - case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_GROUP: - { - ret = new RsGxsTransGroupItem(); - break; - } - case GxsTransItemsSubtypes::OUTGOING_RECORD_ITEM: - { - OutgoingRecord* i = new OutgoingRecord(); - uint32_t offset = 0; - ok = ok && i->deserialize(dataPtr, *size, offset); - ret = i; - break; - } - default: - ok = false; - break; - } - - if(ok) return ret; - - delete ret; - return NULL; } }; diff --git a/libretroshare/src/rsitems/rsitem.h b/libretroshare/src/rsitems/rsitem.h index 8dbda2fb3..5698728a0 100644 --- a/libretroshare/src/rsitems/rsitem.h +++ b/libretroshare/src/rsitems/rsitem.h @@ -3,6 +3,7 @@ #include "util/smallobject.h" #include "retroshare/rstypes.h" #include "serialiser/rsserializer.h" +#include "util/stacktrace.h" class RsItem: public RsMemoryManagement::SmallObject { @@ -15,6 +16,8 @@ class RsItem: public RsMemoryManagement::SmallObject #endif virtual ~RsItem(); + + /// TODO: Do this make sense with the new serialization system? virtual void clear() = 0; virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0) @@ -48,21 +51,16 @@ class RsItem: public RsMemoryManagement::SmallObject inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} /** - * @brief serialize this object to the given buffer - * @param Job to do: serialise or deserialize. - * @param data Chunk of memory were to dump the serialized data - * @param size Size of memory chunk - * @param offset Readed to determine at witch offset start writing data, - * written to inform caller were written data ends, the updated value - * is usually passed by the caller to serialize of another - * RsSerializable so it can write on the same chunk of memory just - * after where this RsSerializable has been serialized. - * @return true if serialization successed, false otherwise + * TODO: This should be made pure virtual as soon as all the codebase + * is ported to the new serialization system */ - - virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) + virtual void serial_process(RsGenericSerializer::SerializeJob, + RsGenericSerializer::SerializeContext&)// = 0; { - std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! Class is " << typeid(*this).name() << std::endl; + std::cerr << "(EE) RsItem::serial_process() called by an item using" + << "new serialization classes, but not derived! Class is " + << typeid(*this).name() << std::endl; + print_stacktrace(); } protected: @@ -71,6 +69,7 @@ class RsItem: public RsMemoryManagement::SmallObject uint8_t _priority_level ; }; +/// TODO: Do this make sense with the new serialization system? class RsRawItem: public RsItem { public: diff --git a/libretroshare/src/rsitems/rsnxsitems.cc b/libretroshare/src/rsitems/rsnxsitems.cc index 104935930..200d45391 100644 --- a/libretroshare/src/rsitems/rsnxsitems.cc +++ b/libretroshare/src/rsitems/rsnxsitems.cc @@ -69,15 +69,18 @@ void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ; RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ; } -void RsNxsMsg::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) + +void RsNxsMsg::serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) { - RsTypeSerializer::serial_process (j,ctx,transactionNumber,"transactionNumber") ; - RsTypeSerializer::serial_process (j,ctx,pos ,"pos") ; - RsTypeSerializer::serial_process (j,ctx,msgId ,"msgId") ; - RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ; - RsTypeSerializer::serial_process(j,ctx,msg ,"msg") ; - RsTypeSerializer::serial_process(j,ctx,meta ,"meta") ; + RS_REGISTER_SERIAL_MEMBER_TYPED(transactionNumber, uint32_t); + RS_REGISTER_SERIAL_MEMBER_TYPED(pos, uint8_t); + RS_REGISTER_SERIAL_MEMBER(msgId); + RS_REGISTER_SERIAL_MEMBER(grpId); + RS_REGISTER_SERIAL_MEMBER_TYPED(msg, RsTlvItem); + RS_REGISTER_SERIAL_MEMBER_TYPED(meta, RsTlvItem); } + void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,transactionNumber,"transactionNumber") ; @@ -149,11 +152,14 @@ void RsNxsMsg::clear() meta.TlvClear(); } +std::ostream&RsNxsMsg::print(std::ostream& out, uint16_t /*indent*/) +{ return out; } + void RsNxsGrp::clear() { - grpId.clear(); - grp.TlvClear(); - meta.TlvClear(); + grpId.clear(); + grp.TlvClear(); + meta.TlvClear(); } void RsNxsSyncGrpReqItem::clear() diff --git a/libretroshare/src/rsitems/rsnxsitems.h b/libretroshare/src/rsitems/rsnxsitems.h index 127d876f6..6779989f4 100644 --- a/libretroshare/src/rsitems/rsnxsitems.h +++ b/libretroshare/src/rsitems/rsnxsitems.h @@ -376,7 +376,7 @@ struct RsNxsMsg : RsNxsItem RsGenericSerializer::SerializeContext& ctx ); virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent); + virtual std::ostream &print(std::ostream& out, uint16_t indent); uint8_t pos; /// used for splitting up msg uint8_t count; /// number of split up messages diff --git a/libretroshare/src/serialiser/rstypeserializer.cc b/libretroshare/src/serialiser/rstypeserializer.cc index f4cfc0d62..c2b8bd1c4 100644 --- a/libretroshare/src/serialiser/rstypeserializer.cc +++ b/libretroshare/src/serialiser/rstypeserializer.cc @@ -27,6 +27,8 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvkeys.h" +#include "rsitems/rsitem.h" + #include "util/rsprint.h" #include @@ -306,3 +308,57 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsTlvIt std::cerr << " [" << typeid(s).name() << "] " << n << std::endl; } + +//============================================================================// +// RsItem and derivated // +//============================================================================// + +template<> uint32_t RsTypeSerializer::serial_size(const RsItem& s) +{ + RsGenericSerializer::SerializeContext ctx( + NULL, 0, RsGenericSerializer::FORMAT_BINARY, + RsGenericSerializer::SERIALIZATION_FLAG_NONE ); + + ctx.mOffset = 8; // header size + const_cast(s).serial_process(RsGenericSerializer::SIZE_ESTIMATE, + ctx); + + return ctx.mOffset; +} + +template<> bool RsTypeSerializer::serialize( uint8_t data[], uint32_t size, + uint32_t &offset, const RsItem& s ) +{ + RsGenericSerializer::SerializeContext ctx( + data, size, RsGenericSerializer::FORMAT_BINARY, + RsGenericSerializer::SERIALIZATION_FLAG_NONE ); + ctx.mOffset = offset; + const_cast(s).serial_process(RsGenericSerializer::SERIALIZE, + ctx); + return true; +} + +template<> bool RsTypeSerializer::deserialize( const uint8_t data[], + uint32_t size, uint32_t& offset, + RsItem& s ) +{ + RsGenericSerializer::SerializeContext ctx( + const_cast(data), size, + RsGenericSerializer::FORMAT_BINARY, + RsGenericSerializer::SERIALIZATION_FLAG_NONE ); + ctx.mOffset = offset; + const_cast(s).serial_process(RsGenericSerializer::DESERIALIZE, + ctx); + return true; +} + +template<> void RsTypeSerializer::print_data( const std::string& n, + const RsItem& s ) +{ + RsGenericSerializer::SerializeContext ctx( + NULL, 0, + RsGenericSerializer::FORMAT_BINARY, + RsGenericSerializer::SERIALIZATION_FLAG_NONE ); + const_cast(s).serial_process(RsGenericSerializer::PRINT, + ctx); +} diff --git a/libretroshare/src/serialiser/rstypeserializer.h b/libretroshare/src/serialiser/rstypeserializer.h index 333f1a364..ffc84e72b 100644 --- a/libretroshare/src/serialiser/rstypeserializer.h +++ b/libretroshare/src/serialiser/rstypeserializer.h @@ -33,409 +33,522 @@ #include "serialiser/rsserializer.h" +/** @def RS_REGISTER_SERIAL_MEMBER(I) + * Use this macro to register the members of `YourItem` for serial processing + * inside `YourItem::serial_process(j, ctx)` + * + * Inspired by http://stackoverflow.com/a/39345864 + */ +#define RS_REGISTER_SERIAL_MEMBER(I) \ + do { RsTypeSerializer::serial_process(j, ctx, I, #I); } while(0) -class RsTypeSerializer +/** @def RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) + * This macro usage is similar to @see RS_REGISTER_SERIAL_MEMBER(I) but it + * permit to force serialization/deserialization type, it is expecially useful + * with enum class members ot RsTlvItem derivative members, be very careful with + * the type you pass, as reinterpret_cast on a reference is used that is + * expecially permissive so you can shot your feet if not carefull enough. + * + * If you are using this with an RsItem derivative (so passing RsItem as T) + * consider to register your item type with @see RS_REGISTER_ITEM_TYPE(T) in + * association with @see RS_REGISTER_SERIAL_MEMBER(I) that rely on template + * function generation, as in this particular case + * RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) would cause the serial code rely on + * C++ dynamic dispatching that may have a noticeable impact on runtime + * performances. + */ +#define RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) do {\ + RsTypeSerializer::serial_process(j, ctx, reinterpret_cast(I), #I);\ + } while(0) + +/** @def RS_REGISTER_ITEM_TYPE(T) + * Use this macro into `youritem.cc` only if you need to process members of + * subtypes of RsItem. + * + * The usage of this macro is strictly needed only in some cases, for example if + * you are registering for serialization a member of a container that contains + * items of subclasses of RsItem like * `std::map` + * + * @code{.cpp} +struct PrivateOugoingMapItem : RsChatItem { - public: - // This type should be used to pass a parameter to drive the serialisation if needed. + PrivateOugoingMapItem() : RsChatItem(RS_PKT_SUBTYPE_OUTGOING_MAP) {} - struct TlvMemBlock_proxy: public std::pair - { - TlvMemBlock_proxy(void *& p,uint32_t& s) : std::pair(p,s) {} - TlvMemBlock_proxy(uint8_t*& p,uint32_t& s) : std::pair(*(void**)&p,s) {} - }; + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ); - //=================================================================================================// - // Generic types // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,T& member,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; - break ; - - case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; - break ; - - case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; - break ; - - case RsGenericSerializer::PRINT: - print_data(member_name,member); - break; - default: - ctx.mOk = false ; - throw std::runtime_error("Unknown serial job") ; - } - } - - //=================================================================================================// - // Generic types + type_id // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; - break ; - - case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; - break ; - - case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; - break ; - - case RsGenericSerializer::PRINT: - print_data(member_name,type_id,member); - break; - default: - ctx.mOk = false ; - throw std::runtime_error("Unknown serial job") ; - } - } - //=================================================================================================// - // std::map // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::map& v,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: - { - ctx.mOffset += 4 ; - for(typename std::map::iterator it(v.begin());it!=v.end();++it) - { - serial_process(j,ctx,const_cast(it->first),"map::*it->first") ; - serial_process(j,ctx,const_cast(it->second),"map::*it->second") ; - } - } - break ; - - case RsGenericSerializer::DESERIALIZE: - { - uint32_t n=0 ; - serial_process(j,ctx,n,"temporary size"); - - for(uint32_t i=0;ifirst") ; - serial_process(j,ctx,u,"map::*it->second") ; - - v[t] = u ; - } - } - break ; - - case RsGenericSerializer::SERIALIZE: - { - uint32_t n=v.size(); - serial_process(j,ctx,n,"temporary size"); - - for(typename std::map::iterator it(v.begin());it!=v.end();++it) - { - serial_process(j,ctx,const_cast(it->first),"map::*it->first") ; - serial_process(j,ctx,const_cast(it->second),"map::*it->second") ; - } - } - break ; - - case RsGenericSerializer::PRINT: - { - if(v.empty()) - std::cerr << " Empty map \"" << member_name << "\"" << std::endl; - else - std::cerr << " std::map of " << v.size() << " elements: \"" << member_name << "\"" << std::endl; - - for(typename std::map::iterator it(v.begin());it!=v.end();++it) - { - std::cerr << " " ; - - serial_process(j,ctx,const_cast(it->first),"map::*it->first") ; - serial_process(j,ctx,const_cast(it->second),"map::*it->second") ; - } - } - break; - default: - break; - } - } - - //=================================================================================================// - // std::vector // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::vector& v,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: - { - ctx.mOffset += 4 ; - for(uint32_t i=0;i // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::set& v,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: - { - ctx.mOffset += 4 ; - for(typename std::set::iterator it(v.begin());it!=v.end();++it) - serial_process(j,ctx,const_cast(*it) ,member_name) ; // the const cast here is a hack to avoid serial_process to instantiate serialise(const T&) - } - break ; - - case RsGenericSerializer::DESERIALIZE: - { uint32_t n=0 ; - serial_process(j,ctx,n,"temporary size") ; - - for(uint32_t i=0;i(j,ctx,tmp,member_name) ; - v.insert(tmp); - } - } - break ; - - case RsGenericSerializer::SERIALIZE: - { - uint32_t n=v.size(); - serial_process(j,ctx,n,"temporary size") ; - for(typename std::set::iterator it(v.begin());it!=v.end();++it) - serial_process(j,ctx,const_cast(*it) ,member_name) ; // the const cast here is a hack to avoid serial_process to instantiate serialise(const T&) - } - break ; - - case RsGenericSerializer::PRINT: - { - if(v.empty()) - std::cerr << " Empty set"<< std::endl; - else - std::cerr << " Set of " << v.size() << " elements:" << std::endl; - } - break; - default: - break; - } - } - - - //=================================================================================================// - // std::list // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::list& v,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: - { - ctx.mOffset += 4 ; - for(typename std::list::iterator it(v.begin());it!=v.end();++it) - serial_process(j,ctx,*it ,member_name) ; - } - break ; - - case RsGenericSerializer::DESERIALIZE: - { uint32_t n=0 ; - serial_process(j,ctx,n,"temporary size") ; - - for(uint32_t i=0;i(j,ctx,tmp,member_name) ; - v.push_back(tmp); - } - } - break ; - - case RsGenericSerializer::SERIALIZE: - { - uint32_t n=v.size(); - serial_process(j,ctx,n,"temporary size") ; - for(typename std::list::iterator it(v.begin());it!=v.end();++it) - serial_process(j,ctx,*it ,member_name) ; - } - break ; - - case RsGenericSerializer::PRINT: - { - if(v.empty()) - std::cerr << " Empty list"<< std::endl; - else - std::cerr << " List of " << v.size() << " elements:" << std::endl; - } - break; - default: - break; - } - } - - //=================================================================================================// - // t_RsFlags32<> types // - //=================================================================================================// - - template - static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,t_RsFlags32& v,const std::string& member_name) - { - switch(j) - { - case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += 4 ; - break ; - - case RsGenericSerializer::DESERIALIZE: - { - uint32_t n=0 ; - deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; - v = t_RsFlags32(n) ; - } - break ; - - case RsGenericSerializer::SERIALIZE: - { - uint32_t n=v.toUInt32() ; - serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; - } - break ; - - case RsGenericSerializer::PRINT: - std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl; - break ; - } - - } - - protected: - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, T& member); - template static uint32_t serial_size(const T& /* member */); - template static void print_data(const std::string& name,const T& /* member */); - - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, uint16_t type_id,const T& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset,uint16_t type_id, T& member); - template static uint32_t serial_size(uint16_t type_id,const T& /* member */); - template static void print_data(const std::string& name,uint16_t type_id,const T& /* member */); - - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member); - template static uint32_t serial_size(const t_RsGenericIdType& /* member */); - template static void print_data(const std::string& name,const t_RsGenericIdType& /* member */); - - template static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsTlvList& member); - template static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsTlvList& member); - template static uint32_t serial_size(const t_RsTlvList& /* member */); - template static void print_data(const std::string& name,const t_RsTlvList& /* member */); + std::map store; }; -//=================================================================================================// -// t_RsGenericId<> // -//=================================================================================================// +RS_REGISTER_ITEM_TYPE(RsChatMsgItem) + +void PrivateOugoingMapItem::serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) +{ + // store is of type + RS_REGISTER_SERIAL_MEMBER(store); +} + * @endcode + * + * If you use this macro with a lot of different item types this can cause the + * generated binary grow in size, consider the usage of + * @see RS_REGISTER_SERIAL_MEMBER_TYPED(I, T) passing RsItem as type in that + * case. + */ +#define RS_REGISTER_ITEM_TYPE(T) template<> \ + void RsTypeSerializer::serial_process( \ + RsGenericSerializer::SerializeJob j,\ + RsGenericSerializer::SerializeContext& ctx, T& item,\ + const std::string& /*name*/) { item.serial_process(j, ctx); } + +struct RsTypeSerializer +{ + /** This type should be used to pass a parameter to drive the serialisation + * if needed */ + struct TlvMemBlock_proxy: public std::pair + { + TlvMemBlock_proxy(void*& p, uint32_t& s) : + std::pair(p,s) {} + TlvMemBlock_proxy(uint8_t*& p,uint32_t& s) : + std::pair(*(void**)&p,s) {} + }; + + /// Generic types + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + T& member,const std::string& member_name) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + ctx.mOffset += serial_size(member); + break; + case RsGenericSerializer::DESERIALIZE: + ctx.mOk = ctx.mOk && + deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member); + break; + case RsGenericSerializer::SERIALIZE: + ctx.mOk = ctx.mOk && + serialize(ctx.mData,ctx.mSize,ctx.mOffset,member); + break; + case RsGenericSerializer::PRINT: + print_data(member_name,member); + break; + default: + ctx.mOk = false; + throw std::runtime_error("Unknown serial job"); + } + } + + /// Generic types + type_id + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + uint16_t type_id, T& member, + const std::string& member_name ) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + ctx.mOffset += serial_size(type_id,member); + break; + case RsGenericSerializer::DESERIALIZE: + ctx.mOk = ctx.mOk && + deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member); + break; + case RsGenericSerializer::SERIALIZE: + ctx.mOk = ctx.mOk && + serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member); + break; + case RsGenericSerializer::PRINT: + print_data(member_name,type_id,member); + break; + default: + ctx.mOk = false; + throw std::runtime_error("Unknown serial job"); + } + } + + /// std::map + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + std::map& v, + const std::string& member_name ) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + { + ctx.mOffset += 4; + for(typename std::map::iterator it(v.begin());it!=v.end();++it) + { + serial_process( j, ctx, const_cast(it->first), + "map::*it->first" ); + serial_process( j,ctx,const_cast(it->second), + "map::*it->second" ); + } + break; + } + case RsGenericSerializer::DESERIALIZE: + { + uint32_t n=0; + serial_process(j,ctx,n,"temporary size"); + + for(uint32_t i=0; ifirst"); + serial_process(j, ctx, u, "map::*it->second"); + v[t] = u; + } + break; + } + case RsGenericSerializer::SERIALIZE: + { + uint32_t n=v.size(); + serial_process(j,ctx,n,"temporary size"); + + for(typename std::map::iterator it(v.begin());it!=v.end();++it) + { + serial_process( j, ctx, const_cast(it->first), + "map::*it->first" ); + serial_process( j, ctx, const_cast(it->second), + "map::*it->second" ); + } + break; + } + case RsGenericSerializer::PRINT: + { + if(v.empty()) + std::cerr << " Empty map \"" << member_name << "\"" + << std::endl; + else + std::cerr << " std::map of " << v.size() << " elements: \"" + << member_name << "\"" << std::endl; + + for(typename std::map::iterator it(v.begin());it!=v.end();++it) + { + std::cerr << " "; + + serial_process( j, ctx,const_cast(it->first), + "map::*it->first" ); + serial_process( j, ctx, const_cast(it->second), + "map::*it->second" ); + } + break; + } + default: break; + } + } + + /// std::vector + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + std::vector& v, + const std::string& member_name ) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + { + ctx.mOffset += 4; + for(uint32_t i=0;i + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + std::set& v, const std::string& member_name ) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + { + ctx.mOffset += 4; + for(typename std::set::iterator it(v.begin());it!=v.end();++it) + // the const cast here is a hack to avoid serial_process to + // instantiate serialise(const T&) + serial_process(j,ctx,const_cast(*it) ,member_name); + break; + } + case RsGenericSerializer::DESERIALIZE: + { + uint32_t n=0; + serial_process(j,ctx,n,"temporary size"); + for(uint32_t i=0; i(j,ctx,tmp,member_name); + v.insert(tmp); + } + break; + } + case RsGenericSerializer::SERIALIZE: + { + uint32_t n=v.size(); + serial_process(j,ctx,n,"temporary size"); + for(typename std::set::iterator it(v.begin());it!=v.end();++it) + // the const cast here is a hack to avoid serial_process to + // instantiate serialise(const T&) + serial_process(j,ctx,const_cast(*it) ,member_name); + break; + } + case RsGenericSerializer::PRINT: + { + if(v.empty()) std::cerr << " Empty set"<< std::endl; + else std::cerr << " Set of " << v.size() << " elements:" + << std::endl; + break; + } + default: break; + } + } + + /// std::list + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + std::list& v, + const std::string& member_name ) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: + { + ctx.mOffset += 4; + for(typename std::list::iterator it(v.begin());it!=v.end();++it) + serial_process(j,ctx,*it ,member_name); + break; + } + case RsGenericSerializer::DESERIALIZE: + { + uint32_t n=0; + serial_process(j,ctx,n,"temporary size"); + for(uint32_t i=0;i(j,ctx,tmp,member_name); + v.push_back(tmp); + } + break; + } + case RsGenericSerializer::SERIALIZE: + { + uint32_t n=v.size(); + serial_process(j,ctx,n,"temporary size"); + for(typename std::list::iterator it(v.begin());it!=v.end();++it) + serial_process(j,ctx,*it ,member_name); + break; + } + case RsGenericSerializer::PRINT: + { + if(v.empty()) std::cerr << " Empty list"<< std::endl; + else std::cerr << " List of " << v.size() << " elements:" + << std::endl; + break; + } + default: break; + } + } + + /// t_RsFlags32<> types + template + static void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx, + t_RsFlags32& v, + const std::string& /*member_name*/) + { + switch(j) + { + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += 4; break; + case RsGenericSerializer::DESERIALIZE: + { + uint32_t n=0; + deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n); + v = t_RsFlags32(n); + break; + } + case RsGenericSerializer::SERIALIZE: + { + uint32_t n=v.toUInt32(); + serialize(ctx.mData,ctx.mSize,ctx.mOffset,n); + break; + } + case RsGenericSerializer::PRINT: + std::cerr << " Flags of type " << std::hex << N << " : " + << v.toUInt32() << std::endl; + break; + } + } + +/** TODO + * Serialization format is inside context, but context is not passed to + * following functions, that need to know the format to do the job, actually + * RsGenericSerializer::FORMAT_BINARY is assumed in all of them!! + */ + +protected: + template static bool serialize( + uint8_t data[], uint32_t size, uint32_t &offset, const T& member ); + + template static bool deserialize( + const uint8_t data[], uint32_t size, uint32_t &offset, T& member); + + template static uint32_t serial_size(const T& member); + + template static void print_data( + const std::string& name, const T& member); + + + template static bool serialize( + uint8_t data[], uint32_t size, uint32_t &offset, uint16_t type_id, + const T& member ); + template static bool deserialize( + const uint8_t data[], uint32_t size, uint32_t &offset, + uint16_t type_id, T& member ); + template static uint32_t serial_size( + uint16_t type_id,const T& member ); + template static void print_data( + const std::string& name,uint16_t type_id,const T& member ); + + + template + static bool serialize( + uint8_t data[], uint32_t size, uint32_t &offset, + const t_RsGenericIdType& member ); + + template + static bool deserialize( + const uint8_t data[], uint32_t size, uint32_t &offset, + t_RsGenericIdType& member ); + + template + static uint32_t serial_size( + const t_RsGenericIdType& member ); + + template + static void print_data( + const std::string& name, + const t_RsGenericIdType& member ); + + + template + static bool serialize( + uint8_t data[], uint32_t size, uint32_t &offset, + const t_RsTlvList& member ); + + template + static bool deserialize( + const uint8_t data[], uint32_t size, uint32_t &offset, + t_RsTlvList& member ); + + template + static uint32_t serial_size(const t_RsTlvList& member); + + template + static void print_data( + const std::string& name, + const t_RsTlvList& member); +}; + + + +// t_RsGenericId<> +template +bool RsTypeSerializer::serialize ( + uint8_t data[], uint32_t size, uint32_t &offset, + const t_RsGenericIdType& member ) +{ return (*const_cast *>(&member)).serialise(data,size,offset); } template -bool RsTypeSerializer::serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType& member) -{ - return (*const_cast *>(&member)).serialise(data,size,offset) ; -} +bool RsTypeSerializer::deserialize( + const uint8_t data[], uint32_t size, uint32_t &offset, + t_RsGenericIdType& member ) +{ return member.deserialise(data,size,offset); } template -bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType& member) -{ - return member.deserialise(data,size,offset) ; -} +uint32_t RsTypeSerializer::serial_size( + const t_RsGenericIdType& member ) +{ return member.serial_size(); } template -uint32_t RsTypeSerializer::serial_size(const t_RsGenericIdType& member) +void RsTypeSerializer::print_data( + const std::string& /*name*/, + const t_RsGenericIdType& member ) { - return member.serial_size(); + std::cerr << " [RsGenericId<" << std::hex << UNIQUE_IDENTIFIER << ">] : " + << member << std::endl; } -template -void RsTypeSerializer::print_data(const std::string& /* name */,const t_RsGenericIdType& member) -{ - std::cerr << " [RsGenericId<" << std::hex << UNIQUE_IDENTIFIER << ">] : " << member << std::endl; -} - -//=================================================================================================// -// t_RsTlvList<> // -//=================================================================================================// +// t_RsTlvList<> template -bool RsTypeSerializer::serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsTlvList& member) +bool RsTypeSerializer::serialize( + uint8_t data[], uint32_t size, uint32_t &offset, + const t_RsTlvList& member ) { - return (*const_cast *>(&member)).SetTlv(data,size,&offset) ; + return (*const_cast *>(&member)).SetTlv(data,size,&offset); } template -bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsTlvList& member) +bool RsTypeSerializer::deserialize( + const uint8_t data[], uint32_t size, uint32_t &offset, + t_RsTlvList& member ) { - return member.GetTlv(const_cast(data),size,&offset) ; + return member.GetTlv(const_cast(data),size,&offset); } template -uint32_t RsTypeSerializer::serial_size(const t_RsTlvList& member) -{ - return member.TlvSize(); -} +uint32_t RsTypeSerializer::serial_size( + const t_RsTlvList& member) +{ return member.TlvSize(); } template -void RsTypeSerializer::print_data(const std::string& /* name */,const t_RsTlvList& member) +void RsTypeSerializer::print_data( + const std::string& /*name*/, + const t_RsTlvList& member) { - std::cerr << " [t_RsTlvString<" << std::hex << TLV_TYPE << ">] : size=" << member.mList.size() << std::endl; + std::cerr << " [t_RsTlvString<" << std::hex << TLV_TYPE << ">] : size=" + << member.mList.size() << std::endl; } From 8e9b3c97d5b8fc6b8130ce092a33d11de82d1506 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 8 May 2017 12:03:42 +0200 Subject: [PATCH 106/106] Fix missing include --- libretroshare/src/rsitems/rsitem.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libretroshare/src/rsitems/rsitem.h b/libretroshare/src/rsitems/rsitem.h index 5698728a0..068f9ee83 100644 --- a/libretroshare/src/rsitems/rsitem.h +++ b/libretroshare/src/rsitems/rsitem.h @@ -1,5 +1,7 @@ #pragma once +#include // for typeid + #include "util/smallobject.h" #include "retroshare/rstypes.h" #include "serialiser/rsserializer.h"