Merge branch 'json_experiments'

This commit is contained in:
Gioacchino Mazzurco 2018-04-27 18:17:09 +02:00
commit f3ae61b462
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
38 changed files with 1480 additions and 604 deletions

View file

@ -28,6 +28,7 @@
#include "rsitems/rsconfigitems.h"
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
#include "serialiser/rsserializable.h"
#include "serialiser/rstypeserializer.h"
/***
* #define RSSERIAL_DEBUG 1
@ -89,7 +90,7 @@ void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunk_strategy,"chunk_strategy") ;
RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ;
RS_SERIAL_PROCESS(compressed_chunk_map);
}
void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
@ -192,31 +193,6 @@ void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
RsTypeSerializer::serial_process<RsTlvItem>(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)

View file

@ -91,48 +91,6 @@ void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::Seria
RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ;
}
//===================================================================================================//
// CompressedChunkMap //
//===================================================================================================//
template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s)
{
return 4 + 4*s._map.size() ;
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s)
{
bool ok = true ;
ok &= setRawUInt32(data, size, &offset, s._map.size());
for(uint32_t i=0;i<s._map.size() && ok;++i)
ok &= setRawUInt32(data, size, &offset, s._map[i]);
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s)
{
uint32_t S =0;
bool ok = getRawUInt32(data, size, &offset, &S);
if(ok)
{
s._map.resize(S) ;
for(uint32_t i=0;i<S && ok;++i)
ok &= getRawUInt32(data, size, &offset, &(s._map[i]));
}
return ok;
}
template<> void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s)
{
std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl;
}
//===================================================================================================//
// Serializer //
//===================================================================================================//

View file

@ -97,31 +97,6 @@ void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos");
}
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
bool ok = true ;
ok = ok && setRawUInt32(data,size,&offset,info.time_stamp);
ok = ok && setRawUInt32(data,size,&offset,info.message_count);
return ok;
}
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
bool ok = true ;
ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp);
ok = ok && getRawUInt32(data,size,&offset,&info.message_count);
return ok;
}
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)
{
std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl;
}
void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId");
@ -134,5 +109,3 @@ void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_send_delay,"msg_send_delay") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_req_delay,"msg_req_delay") ;
}

View file

@ -28,18 +28,11 @@
#if 0
#include <map>
#include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h"
#endif
#include "gxs/rsgxs.h"
#include "gxs/rsgxsdata.h"
#include "serialiser/rstlvidset.h"
#include "serialiser/rstypeserializer.h"
#include "serialiser/rsserializable.h"
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_UPDATE = 0x01;
@ -140,17 +133,26 @@ public:
class RsGxsMsgUpdate
{
public:
struct MsgUpdateInfo
struct MsgUpdateInfo : RsSerializable
{
MsgUpdateInfo(): time_stamp(0), message_count(0) {}
uint32_t time_stamp ;
uint32_t message_count ;
/// @see RsSerializable
void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx)
{
RS_SERIAL_PROCESS(time_stamp);
RS_SERIAL_PROCESS(message_count);
}
};
std::map<RsGxsGroupId, MsgUpdateInfo> msgUpdateInfos;
};
class RsGxsMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsMsgUpdate
{
public:

View file

@ -1,76 +1,96 @@
#pragma once
/*
* RetroShare Serialiser.
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <typeinfo> // for typeid
#include "util/smallobject.h"
#include "retroshare/rstypes.h"
#include "serialiser/rsserializer.h"
#include "serialiser/rsserializable.h"
#include "util/stacktrace.h"
#include <typeinfo>
class RsItem: public RsMemoryManagement::SmallObject
struct RsItem : RsMemoryManagement::SmallObject, RsSerializable
{
public:
explicit RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
explicit 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) ;
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
#endif
virtual ~RsItem();
virtual ~RsItem();
/// TODO: Do this make sense with the new serialization system?
virtual void clear() = 0;
/// 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)
{
RsGenericSerializer::SerializeContext ctx(NULL,0,RsGenericSerializer::FORMAT_BINARY,RsGenericSerializer::SERIALIZATION_FLAG_NONE);
serial_process(RsGenericSerializer::PRINT,ctx) ;
return out;
}
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);
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; }
/// source / destination id
const RsPeerId& PeerId() const { return peerId; }
void PeerId(const RsPeerId& id) { peerId = id; }
/* complete id */
uint32_t PacketId() const;
/// complete id
uint32_t PacketId() const;
/* id parts */
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType() 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);
/// 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 ;}
inline uint8_t priority_level() const { return _priority_level ;}
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
/**
* 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,
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;
print_stacktrace();
}
/**
* TODO: This default implementation should be removed and childs structs
* implement ::serial_process(...) as soon as all the codebase is ported to
* the new serialization system
*/
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;
print_stacktrace();
}
protected:
uint32_t type;
RsPeerId peerId;
uint8_t _priority_level ;
protected:
uint32_t type;
RsPeerId peerId;
uint8_t _priority_level;
};
/// TODO: Do this make sense with the new serialization system?

View file

@ -73,12 +73,12 @@ void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene
void RsNxsMsg::serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
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);
RS_SERIAL_PROCESS(transactionNumber);
RS_SERIAL_PROCESS(pos);
RS_SERIAL_PROCESS(msgId);
RS_SERIAL_PROCESS(grpId);
RS_SERIAL_PROCESS(msg);
RS_SERIAL_PROCESS(meta);
}
void RsNxsGrp::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)