mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge branch 'gxs_mail_experiments' into qmlapp_pex_alpha
This commit is contained in:
commit
8f306346a4
@ -35,17 +35,17 @@
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/rsprint.h"
|
||||
|
||||
#include <serialiser/rsmsgitems.h>
|
||||
#include "rsitems/rsmsgitems.h"
|
||||
|
||||
#include <retroshare/rsmsgs.h>
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include <retroshare/rsiface.h>
|
||||
#include "retroshare/rsmsgs.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
|
||||
#include <rsserver/p3face.h>
|
||||
#include <services/p3idservice.h>
|
||||
#include <gxs/gxssecurity.h>
|
||||
#include <turtle/p3turtle.h>
|
||||
#include <retroshare/rsids.h>
|
||||
#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
|
||||
@ -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;
|
||||
|
@ -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 = RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast<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->serialise_signed_part(memory,size))
|
||||
if(!RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast<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->signed_serial_size(),obj->signature,false,use_info,error_status))
|
||||
if(!mGixs->validateData(memory,size,obj->signature,false,use_info,error_status))
|
||||
{
|
||||
bool res = false ;
|
||||
|
||||
@ -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 ;
|
||||
@ -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 = RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).size(dynamic_cast<RsItem*>(&item)) ;
|
||||
RsTemporaryMemory memory(size) ;
|
||||
|
||||
if(!item.serialise_signed_part(memory,size))
|
||||
if(!RsChatSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE).serialise(dynamic_cast<RsItem*>(&item),memory,&size))
|
||||
{
|
||||
std::cerr << "(EE) Cannot sign message item. " << std::endl;
|
||||
return false ;
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include "gxstrans/p3gxstrans.h"
|
||||
|
||||
#include "chat/p3chatservice.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
/****
|
||||
* #define CHAT_DEBUG 1
|
||||
@ -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<uint8_t> 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<uint8_t*>(data),
|
||||
dataSize );
|
||||
RsChatMsgItem* item = static_cast<RsChatMsgItem*>(
|
||||
_serializer->deserialise(
|
||||
const_cast<uint8_t*>(data), &dataSize ));
|
||||
RsPeerId rd(p3GxsTunnelService::makeGxsTunnelId(authorId, recipientId));
|
||||
item->PeerId(rd);
|
||||
handleRecvChatMsgItem(item);
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
#include "rsitems/rsmsgitems.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/pqiservicemonitor.h"
|
||||
#include "chat/distantchat.h"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -27,8 +27,11 @@
|
||||
|
||||
#include "openssl/bn.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
@ -79,7 +82,7 @@ const uint8_t RS_PKT_SUBTYPE_OUTGOING_MAP = 0x1B ;
|
||||
|
||||
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,11 +94,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) { return out; } // 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() {}
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -108,14 +109,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
uint32_t chatFlags;
|
||||
uint32_t sendTime;
|
||||
@ -138,21 +139,15 @@ 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.
|
||||
|
||||
virtual uint32_t signed_serial_size() =0;
|
||||
virtual bool serialise_signed_part(void *data,uint32_t& size) = 0;
|
||||
|
||||
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.
|
||||
|
||||
uint32_t serialized_size(bool include_signature) ;
|
||||
bool serialise_to_memory(void *data,uint32_t tlvsize,uint32_t& offset,bool include_signature) ;
|
||||
bool deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) ;
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
virtual uint32_t PacketId() const= 0;
|
||||
};
|
||||
|
||||
class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
|
||||
@ -160,55 +155,44 @@ 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
|
||||
|
||||
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 ?
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
ChatLobbyMsgId parent_msg_id ; // Used for threaded chat.
|
||||
|
||||
protected:
|
||||
virtual uint32_t PacketId() const { return RsChatMsgItem::PacketId() ; }
|
||||
};
|
||||
|
||||
class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject
|
||||
{
|
||||
public:
|
||||
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
|
||||
RsChatLobbyEventItem(void *data,uint32_t size) ; // deserialization /// TODO!!!
|
||||
public:
|
||||
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
|
||||
|
||||
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() ;
|
||||
virtual ~RsChatLobbyEventItem() {}
|
||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
|
||||
//
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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
|
||||
|
||||
// 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
|
||||
{
|
||||
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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
struct VisibleChatLobbyInfo
|
||||
@ -224,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
std::vector<VisibleChatLobbyInfo> lobbies ;
|
||||
};
|
||||
@ -239,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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,22 +259,18 @@ class RsChatLobbyInviteItem: public RsChatItem
|
||||
*/
|
||||
struct RsPrivateChatMsgConfigItem : RsChatItem
|
||||
{
|
||||
RsPrivateChatMsgConfigItem() :RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG) {}
|
||||
RsPrivateChatMsgConfigItem(void *data,uint32_t size) ; // deserialization
|
||||
RsPrivateChatMsgConfigItem() :
|
||||
RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG) {}
|
||||
|
||||
virtual ~RsPrivateChatMsgConfigItem() {}
|
||||
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();
|
||||
/* Deserialize is handled using a constructor,it would be better have a
|
||||
* deserialize method as constructor cannot fails while deserialization can.
|
||||
*/
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx );
|
||||
|
||||
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
||||
/** set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
||||
void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags);
|
||||
/* get data from RsPrivateChatMsgConfigItem to RsChatMsgItem */
|
||||
/** get data from RsPrivateChatMsgConfigItem to RsChatMsgItem */
|
||||
void get(RsChatMsgItem *ci);
|
||||
|
||||
RsPeerId configPeerId;
|
||||
@ -314,43 +280,20 @@ struct RsPrivateChatMsgConfigItem : 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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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.
|
||||
@ -359,13 +302,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t flags ;
|
||||
std::string status_string;
|
||||
@ -377,183 +317,31 @@ 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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t image_size ; // size of data in bytes
|
||||
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) ;}
|
||||
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
|
||||
|
||||
// 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 ;}
|
||||
};
|
||||
|
||||
|
||||
struct PrivateOugoingMapItem : RsChatItem
|
||||
{
|
||||
PrivateOugoingMapItem() : RsChatItem(RS_PKT_SUBTYPE_OUTGOING_MAP) {}
|
||||
|
||||
uint32_t serial_size()
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4; // number of entries
|
||||
for( auto entry : store )
|
||||
{
|
||||
s += 8; // key size
|
||||
s += entry.second.serial_size();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
bool 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 = ok && setRsItemHeader(data, tlvsize, PacketId(), tlvsize)
|
||||
&& (offset += 8);
|
||||
|
||||
ok = ok && setRawUInt32(data, tlvsize, &offset, store.size());
|
||||
|
||||
for( auto entry : store )
|
||||
{
|
||||
ok = ok && setRawUInt64(data, tlvsize, &offset, entry.first);
|
||||
|
||||
uint8_t* hdrPtr = static_cast<uint8_t*>(data) + offset;
|
||||
uint32_t tmpsize = entry.second.serial_size();
|
||||
ok = ok && entry.second.serialise(hdrPtr, tmpsize)
|
||||
&& (offset += tmpsize);
|
||||
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "PrivateOugoingMapItem::serialise() Size Error!"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
PrivateOugoingMapItem* deserialise(const uint8_t* data, uint32_t& pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint8_t* dataPtr = const_cast<uint8_t*>(data);
|
||||
uint32_t rstype = getRsItemId(dataPtr);
|
||||
uint32_t rssize = getRsItemSize(dataPtr);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_CHAT != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_OUTGOING_MAP != getRsItemSubType(rstype))
|
||||
) return NULL; /* wrong type */
|
||||
|
||||
if (pktsize < rssize) return NULL; /* check size not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
PrivateOugoingMapItem* item = new PrivateOugoingMapItem();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
// get map size first */
|
||||
uint32_t s = 0;
|
||||
ok = ok && getRawUInt32(dataPtr, rssize, &offset, &s);
|
||||
|
||||
for(uint32_t i=0; i<s && ok; ++i)
|
||||
{
|
||||
uint64_t msgId;
|
||||
|
||||
ok = ok && getRawUInt64(dataPtr, rssize, &offset, &msgId);
|
||||
|
||||
uint8_t* hdrPtr = const_cast<uint8_t*>(data); hdrPtr += offset;
|
||||
uint32_t tmpSize = getRsItemSize(hdrPtr);
|
||||
RsChatMsgItem msgItem(hdrPtr, tmpSize); offset+= tmpSize;
|
||||
item->store.insert(std::make_pair(msgId, msgItem));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t /*indent*/ = 0)
|
||||
{
|
||||
return out << "PrivateOugoingMapItem store size: " << store.size()
|
||||
<< std::endl;
|
||||
}
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx );
|
||||
|
||||
std::map<uint64_t, RsChatMsgItem> store;
|
||||
};
|
||||
|
||||
class RsChatSerialiser: public RsSerialType
|
||||
struct RsChatSerialiser : RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsChatSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_CHAT) {}
|
||||
RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) :
|
||||
RsServiceSerializer( RS_SERVICE_TYPE_CHAT,
|
||||
RsGenericSerializer::FORMAT_BINARY, flags ) {}
|
||||
|
||||
virtual uint32_t size (RsItem *item)
|
||||
{
|
||||
return static_cast<RsChatItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return static_cast<RsChatItem *>(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) const;
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "tcponudp/udprelay.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
|
@ -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"
|
||||
|
@ -24,342 +24,41 @@
|
||||
*/
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#include "file_sharing/rsfilelistitems.h"
|
||||
|
||||
RsItem* RsFileListsSerialiser::deserialise(void *data, uint32_t *size)
|
||||
void RsFileListsSyncRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
#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;
|
||||
|
||||
}
|
||||
}
|
||||
RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags ,"flags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,request_id,"request_id") ;
|
||||
}
|
||||
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") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags ,"flags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ;
|
||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,request_id,"request_id") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,directory_content_data,"directory_content_data") ;
|
||||
}
|
||||
|
||||
uint32_t RsFileListsSerialiser::size(RsItem *item)
|
||||
RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
{
|
||||
RsFileListsItem *flst_item = dynamic_cast<RsFileListsItem*>(item) ;
|
||||
if(service != RS_SERVICE_TYPE_FILE_DATABASE)
|
||||
return NULL ;
|
||||
|
||||
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<RsFileListsItem*>(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)
|
||||
switch(type)
|
||||
{
|
||||
std::cerr << "RsFileListsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl;
|
||||
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 ;
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
void RsFileListsSyncRequestItem::clear()
|
||||
{
|
||||
}
|
||||
void RsFileListsSyncResponseItem::clear()
|
||||
{
|
||||
directory_content_data.TlvClear();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -27,13 +27,16 @@
|
||||
#include <map>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
#include "serialiser/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 +57,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,11 +77,9 @@ 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 bool serialise(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const ;
|
||||
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.
|
||||
@ -98,10 +94,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsFileHash entry_hash ; // hash of the directory to sync
|
||||
RsFileHash checksum ; // checksum of the bindary data, for checking
|
||||
@ -112,24 +106,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 RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
RsFileListsSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_FILE_DATABASE) {}
|
||||
RsFileListsSerialiser() : RsServiceSerializer(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 ;
|
||||
};
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* for (u)sleep() */
|
||||
#include <time.h>
|
||||
|
@ -53,7 +53,7 @@ class p3ServiceControl;
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <retroshare/rstypes.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include "ft/ftextralist.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "util/rsdir.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* for (u)sleep() */
|
||||
@ -396,7 +396,8 @@ bool ftExtraList::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
||||
std::map<RsFileHash, FileDetails>::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<RsItem *>& load)
|
||||
for(it = load.begin(); it != load.end(); ++it)
|
||||
{
|
||||
|
||||
RsFileConfigItem_deprecated *fi = dynamic_cast<RsFileConfigItem_deprecated *>(*it);
|
||||
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
||||
if (!fi)
|
||||
{
|
||||
delete (*it);
|
||||
|
@ -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
|
||||
@ -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(),RsServiceSerializer(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) const
|
||||
{
|
||||
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<RsTurtleGenericTunnelItem*>(deserialise(&edata[clear_item_offset],&edata_size)) ;
|
||||
|
||||
if(decrypted_item == NULL)
|
||||
return false ;
|
||||
|
@ -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 RsServiceSerializer
|
||||
{
|
||||
|
||||
public:
|
||||
@ -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 RsTurtleGenericTunnelItem *deserialiseItem(void *data,uint32_t size) const ;
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_type) const ;
|
||||
virtual RsServiceSerializer *serializer() { return this ; }
|
||||
|
||||
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
|
||||
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
|
||||
|
@ -27,539 +27,48 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <util/rsmemory.h>
|
||||
#include <serialiser/itempriorities.h>
|
||||
#include <rsitems/itempriorities.h>
|
||||
#include <ft/ftturtlefiletransferitem.h>
|
||||
|
||||
uint32_t RsTurtleFileRequestItem::serial_size() const
|
||||
#include <serialiser/rstypeserializer.h>
|
||||
|
||||
void RsTurtleFileMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 8 ; // file offset
|
||||
s += 4 ; // chunk size
|
||||
|
||||
return s ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,direction,"direction") ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileDataItem::serial_size() const
|
||||
void RsTurtleFileMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
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 ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,direction,"direction") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,compressed_map._map,"map") ;
|
||||
}
|
||||
void RsTurtleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
|
||||
}
|
||||
void RsTurtleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,check_sum,"check_sum") ;
|
||||
}
|
||||
|
||||
uint32_t RsTurtleFileMapRequestItem::serial_size() const
|
||||
void RsTurtleFileRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_size,"chunk_size") ;
|
||||
}
|
||||
void RsTurtleFileDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += 4 ; // tunnel id
|
||||
s += 4 ; // direction
|
||||
RsTypeSerializer::TlvMemBlock_proxy prox(chunk_data,chunk_size) ;
|
||||
|
||||
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 ;
|
||||
}
|
||||
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<compressed_map._map.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, compressed_map._map[i]);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
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, chunk_number);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ;
|
||||
print(std::cerr,2) ;
|
||||
#endif
|
||||
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, chunk_number);
|
||||
ok &= check_sum.serialise(data, tlvsize, offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
RsTurtleFileMapItem::RsTurtleFileMapItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
uint32_t s,d ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &d);
|
||||
direction = d ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &s) ;
|
||||
|
||||
compressed_map._map.resize(s) ;
|
||||
|
||||
for(uint32_t i=0;i<s && ok;++i)
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &(compressed_map._map[i])) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleFileMapRequestItem::RsTurtleFileMapRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_MAP_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map request item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &direction);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleChunkCrcItem::RsTurtleChunkCrcItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_CHUNK_CRC) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_number) ;
|
||||
ok &= check_sum.deserialise(data, pktsize, offset) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_CHUNK_CRC_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file map item" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
|
||||
/* add mandatory parts first */
|
||||
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &tunnel_id) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &chunk_number) ;
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if (offset != pktsize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
bool RsTurtleFileRequestItem::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);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsTurtleTunnelOkItem::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsTurtleFileRequestItem::RsTurtleFileRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_REQUEST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_REQUEST) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file request" << 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 &= getRawUInt64(data, pktsize, &offset, &chunk_offset);
|
||||
ok &= getRawUInt32(data, pktsize, &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("RsTurtleTunnelOkItem::() error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
RsTurtleFileDataItem::~RsTurtleFileDataItem()
|
||||
{
|
||||
free(chunk_data) ;
|
||||
}
|
||||
RsTurtleFileDataItem::RsTurtleFileDataItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_FILE_DATA)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_DATA) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " type = file request" << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
bool ok = true ;
|
||||
|
||||
if(rssize > 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<compressed_map._map.size();++i)
|
||||
o << std::hex << compressed_map._map[i] << std::dec << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
std::ostream& RsTurtleFileMapRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "File map request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " direction : " << direction << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& RsTurtleChunkCrcRequestItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC request item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " chunk num : " << chunk_number << std::endl ;
|
||||
|
||||
return o ;
|
||||
}
|
||||
std::ostream& RsTurtleChunkCrcItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "Chunk CRC item:" << std::endl ;
|
||||
|
||||
o << " tunnel id : " << std::hex << tunnel_id << std::dec << std::endl ;
|
||||
o << " chunk num : " << chunk_number << std::endl ;
|
||||
o << " sha1 sum : " << check_sum.toStdString() << std::endl ;
|
||||
|
||||
return o ;
|
||||
RsTypeSerializer::serial_process(j,ctx,prox,"chunk_data") ;
|
||||
}
|
||||
|
||||
|
@ -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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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"
|
||||
@ -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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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 ;
|
||||
|
||||
if(item->chunk_data == NULL)
|
||||
return NULL ;
|
||||
memcpy(item->chunk_data,chunk_data,chunk_size) ;
|
||||
return item ;
|
||||
}
|
||||
|
||||
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 ;
|
||||
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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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 serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) ;
|
||||
|
||||
// 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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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,RsGenericSerializer::FORMAT_BINARY,flags) {}
|
||||
|
||||
virtual uint32_t size (RsItem *item)
|
||||
{
|
||||
RsGRouterItem *gitem = dynamic_cast<RsGRouterItem *>(item);
|
||||
if (!gitem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return gitem->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGRouterItem *gitem = dynamic_cast<RsGRouterItem *>(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 ;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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"
|
||||
@ -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<RsGRouterTransactionItem*>(&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<RsGRouterTransactionItem*>(&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::list<RsGRouter
|
||||
item->print(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::list<RsGRouter
|
||||
throw ;
|
||||
}
|
||||
|
||||
if(!item->serialise(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) ;
|
||||
|
||||
@ -1952,28 +1955,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)
|
||||
@ -1993,15 +2013,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) ;
|
||||
|
||||
@ -2188,26 +2209,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<Sha1CheckSum, GRouterPublishedKeyInfo>::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<RsItem*>& items)
|
||||
{
|
||||
{
|
||||
|
@ -28,7 +28,8 @@
|
||||
*/
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
|
@ -32,8 +32,8 @@
|
||||
|
||||
#include "inttypes.h"
|
||||
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include "rsgxs.h"
|
||||
#include "util/contentvalue.h"
|
||||
|
@ -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"
|
||||
@ -1292,7 +1293,7 @@ bool RsGenExchange::getSerializedGroupData(uint32_t token, RsGxsGroupId& id,
|
||||
}
|
||||
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)))
|
||||
@ -1302,7 +1303,7 @@ bool RsGenExchange::getSerializedGroupData(uint32_t token, RsGxsGroupId& id,
|
||||
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,
|
||||
@ -1380,7 +1381,8 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem
|
||||
}
|
||||
}
|
||||
else if(data.bin_len > 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;
|
||||
}
|
||||
|
@ -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<class GxsItem, typename Identity = std::string>
|
||||
|
@ -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)
|
||||
|
@ -29,10 +29,9 @@
|
||||
#include <string>
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
struct RsGroupMetaData;
|
||||
struct RsMsgMetaData;
|
||||
|
@ -3517,10 +3517,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 ;
|
||||
@ -3547,7 +3547,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
|
||||
|
@ -33,8 +33,8 @@
|
||||
#include "rsgds.h"
|
||||
#include "rsnxsobserver.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "serialiser/rsgxsupdateitems.h"
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
#include "rsitems/rsgxsupdateitems.h"
|
||||
#include "rsgxsnetutils.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "rsgixs.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
#include "rsgixs.h"
|
||||
|
||||
class p3ServiceControl;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define GXSUTIL_H_
|
||||
|
||||
#include <vector>
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
#include "rsgds.h"
|
||||
|
||||
class RsGixs ;
|
||||
|
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <set>
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
|
||||
|
||||
class RsNxsObserver
|
||||
|
@ -478,14 +478,16 @@ bool p3GxsTrans::dispatchDecryptedMail( const RsGxsId& authorId,
|
||||
}
|
||||
GxsTransSubServices rsrvc = static_cast<GxsTransSubServices>(csri);
|
||||
|
||||
RsNxsTransPresignedReceipt* receipt = new RsNxsTransPresignedReceipt();
|
||||
uint32_t rcptsize = decrypted_data_size;
|
||||
if(!receipt->deserialize(decrypted_data, rcptsize, offset))
|
||||
RsNxsTransPresignedReceipt* receipt =
|
||||
static_cast<RsNxsTransPresignedReceipt*>(
|
||||
RsGxsTransSerializer().deserialise(
|
||||
const_cast<uint8_t*>(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<uint8_t> 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<uint16_t>(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<RsItem *>&loadList)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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<uint8_t*>(data+offset);
|
||||
uint32_t rssize = getRsItemSize(hdrPtr);
|
||||
uint32_t roffset = offset + 8; // Take header in account
|
||||
|
||||
void* dataPtr = const_cast<uint8_t*>(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<uint8_t*>(data);
|
||||
bool ok = false;
|
||||
switch(static_cast<GxsTransItemsSubtypes>(item->PacketSubType()))
|
||||
{
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
{
|
||||
uint32_t offset = 0;
|
||||
RsGxsTransMailItem* i = dynamic_cast<RsGxsTransMailItem*>(item);
|
||||
ok = i && i->serialize(dataPtr, itemSize, offset);
|
||||
break;
|
||||
}
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
|
||||
{
|
||||
RsGxsTransPresignedReceipt* i =
|
||||
dynamic_cast<RsGxsTransPresignedReceipt*>(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<OutgoingRecord*>(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<uint8_t>(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<uint8_t>(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<uint8_t>(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<uint16_t>(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<uint8_t*>(data);
|
||||
offset += 8; // Header
|
||||
|
||||
uint8_t tmpStatus = 0;
|
||||
ok = ok && getRawUInt8(dataPtr, size, &offset, &tmpStatus);
|
||||
status = static_cast<GxsTransSendStatus>(tmpStatus);
|
||||
|
||||
uint32_t tmpSize = size;
|
||||
ok = ok && recipient.deserialise(dataPtr, tmpSize, offset);
|
||||
|
||||
void* hdrPtr = const_cast<uint8_t*>(data+offset);
|
||||
tmpSize = getRsItemSize(hdrPtr);
|
||||
|
||||
uint32_t tmpOffset = 0;
|
||||
ok = ok && mailItem.deserialize(static_cast<uint8_t*>(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<GxsTransSubServices>(cs);
|
||||
|
||||
tmpSize = size;
|
||||
ok = ok && presignedReceipt.deserialize(data, tmpSize, offset);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#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<uint8_t> 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<uint8_t>(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<uint8_t*>(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<uint8_t*>(data);
|
||||
uint8_t crType;
|
||||
ok = ok && getRawUInt8(dataPtr, rssize, &roffset, &crType);
|
||||
cryptoType = static_cast<RsGxsTransEncryptionMode>(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<GxsTransItemsSubtypes>(item->PacketSubType()))
|
||||
{
|
||||
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
|
||||
{
|
||||
RsGxsTransMailItem* i = dynamic_cast<RsGxsTransMailItem*>(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<OutgoingRecord*>(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<uint8_t*>(data);
|
||||
|
||||
if ( (RS_PKT_VERSION_SERVICE != pktv) || // 0x02
|
||||
(RS_SERVICE_TYPE_GXS_TRANS != srvc) || // 0x0230 = 560
|
||||
(*size < rssize) )
|
||||
switch(static_cast<GxsTransItemsSubtypes>(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<GxsTransItemsSubtypes>(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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1186,7 +1186,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) ;
|
||||
@ -1199,7 +1201,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 ;
|
||||
@ -1221,10 +1223,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;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
@ -35,459 +36,89 @@
|
||||
|
||||
//#define GXS_TUNNEL_ITEM_DEBUG 1
|
||||
|
||||
std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent)
|
||||
RsItem *RsGxsTunnelSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
if(service != RS_SERVICE_TYPE_GXS_TUNNEL)
|
||||
return NULL ;
|
||||
|
||||
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;
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem()
|
||||
{
|
||||
BN_free(public_key) ;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
void RsGxsTunnelDHPublicKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
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 ;
|
||||
}
|
||||
RsTypeSerializer::serial_process (j,ctx,public_key,"public_key") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,gxs_key,"gxs_key") ;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsGxsTunnelDHPublicKeyItem::serial_size()
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM * const & member)
|
||||
{
|
||||
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
|
||||
uint32_t s = BN_num_bytes(member) ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
if(size < offset + 4 + s)
|
||||
return false ;
|
||||
|
||||
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
|
||||
bool ok = true ;
|
||||
ok &= setRawUInt32(data, size, &offset, s);
|
||||
|
||||
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 ;
|
||||
}
|
||||
/*************************************************************************/
|
||||
|
||||
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]) ;
|
||||
BN_bn2bin(member,&((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 ;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize)
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM *& member)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
uint32_t s=0 ;
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, size, &offset, &s);
|
||||
|
||||
RsGxsTunnelDHPublicKeyItem *item = new RsGxsTunnelDHPublicKeyItem() ;
|
||||
if(s > size || size - s < offset)
|
||||
return false ;
|
||||
|
||||
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) ;
|
||||
member = 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 ;
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void *dat,uint32_t size)
|
||||
template<> uint32_t RsTypeSerializer::serial_size(BIGNUM * const & member)
|
||||
{
|
||||
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 ;
|
||||
return 4 + BN_num_bytes(member) ;
|
||||
}
|
||||
|
||||
RsGxsTunnelDataAckItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataAckItem(void *dat,uint32_t /* size */)
|
||||
template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM * const & /* member */)
|
||||
{
|
||||
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 ;
|
||||
std::cerr << "[BIGNUM] : " << name << std::endl;
|
||||
}
|
||||
|
||||
RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(void *dat, uint32_t size)
|
||||
void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(dat);
|
||||
bool ok = true ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,status,"status") ;
|
||||
}
|
||||
|
||||
if(rssize > size)
|
||||
{
|
||||
std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
void RsGxsTunnelDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx,unique_item_counter,"unique_item_counter") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags ,"flags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,service_id ,"service_id") ;
|
||||
|
||||
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 ;
|
||||
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<uint64_t>(j,ctx,unique_item_counter,"unique_item_counter") ;
|
||||
}
|
||||
|
||||
|
||||
@ -505,3 +136,4 @@ RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -27,9 +27,12 @@
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
@ -57,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
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -78,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?
|
||||
@ -100,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 ;
|
||||
};
|
||||
@ -117,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
|
||||
};
|
||||
|
||||
|
||||
@ -136,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
|
||||
//
|
||||
@ -154,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<RsGxsTunnelItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return static_cast<RsGxsTunnelItem *>(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 ;
|
||||
};
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
@ -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
|
||||
@ -457,17 +457,17 @@ HEADERS += grouter/groutercache.h \
|
||||
grouter/groutertypes.h \
|
||||
grouter/rsgrouterclient.h
|
||||
|
||||
HEADERS += serialiser/itempriorities.h \
|
||||
HEADERS += rsitems/rsitem.h \
|
||||
rsitems/itempriorities.h \
|
||||
serialiser/rsbaseserial.h \
|
||||
serialiser/rsfiletransferitems.h \
|
||||
serialiser/rsserviceserialiser.h \
|
||||
serialiser/rsconfigitems.h \
|
||||
serialiser/rshistoryitems.h \
|
||||
serialiser/rsmsgitems.h \
|
||||
rsitems/rsfiletransferitems.h \
|
||||
rsitems/rsconfigitems.h \
|
||||
rsitems/rshistoryitems.h \
|
||||
rsitems/rsmsgitems.h \
|
||||
serialiser/rsserial.h \
|
||||
serialiser/rsserviceids.h \
|
||||
rsitems/rsserviceids.h \
|
||||
serialiser/rsserviceitems.h \
|
||||
serialiser/rsstatusitems.h \
|
||||
rsitems/rsstatusitems.h \
|
||||
serialiser/rstlvaddrs.h \
|
||||
serialiser/rstlvbase.h \
|
||||
serialiser/rstlvitem.h \
|
||||
@ -484,14 +484,14 @@ HEADERS += serialiser/itempriorities.h \
|
||||
serialiser/rstlvlist.h \
|
||||
serialiser/rstlvmaps.h \
|
||||
serialiser/rstlvbanlist.h \
|
||||
serialiser/rsbanlistitems.h \
|
||||
serialiser/rsbwctrlitems.h \
|
||||
serialiser/rsdiscovery2items.h \
|
||||
serialiser/rsheartbeatitems.h \
|
||||
serialiser/rsrttitems.h \
|
||||
serialiser/rsgxsrecognitems.h \
|
||||
serialiser/rsgxsupdateitems.h \
|
||||
serialiser/rsserviceinfoitems.h \
|
||||
rsitems/rsbanlistitems.h \
|
||||
rsitems/rsbwctrlitems.h \
|
||||
rsitems/rsdiscovery2items.h \
|
||||
rsitems/rsheartbeatitems.h \
|
||||
rsitems/rsrttitems.h \
|
||||
rsitems/rsgxsrecognitems.h \
|
||||
rsitems/rsgxsupdateitems.h \
|
||||
rsitems/rsserviceinfoitems.h \
|
||||
|
||||
HEADERS += services/p3msgservice.h \
|
||||
services/p3service.h \
|
||||
@ -609,17 +609,14 @@ 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 \
|
||||
serialiser/rsfiletransferitems.cc \
|
||||
serialiser/rsserviceserialiser.cc \
|
||||
serialiser/rsconfigitems.cc \
|
||||
serialiser/rshistoryitems.cc \
|
||||
serialiser/rsmsgitems.cc \
|
||||
rsitems/rsfiletransferitems.cc \
|
||||
rsitems/rsconfigitems.cc \
|
||||
rsitems/rshistoryitems.cc \
|
||||
rsitems/rsmsgitems.cc \
|
||||
serialiser/rsserial.cc \
|
||||
serialiser/rsstatusitems.cc \
|
||||
serialiser/rstlvaddrs.cc \
|
||||
serialiser/rstlvbase.cc \
|
||||
serialiser/rstlvitem.cc \
|
||||
@ -632,14 +629,13 @@ SOURCES += serialiser/rsbaseserial.cc \
|
||||
serialiser/rstlvkeyvalue.cc \
|
||||
serialiser/rstlvgenericparam.cc \
|
||||
serialiser/rstlvbanlist.cc \
|
||||
serialiser/rsbanlistitems.cc \
|
||||
serialiser/rsbwctrlitems.cc \
|
||||
serialiser/rsdiscovery2items.cc \
|
||||
serialiser/rsheartbeatitems.cc \
|
||||
serialiser/rsrttitems.cc \
|
||||
serialiser/rsgxsrecognitems.cc \
|
||||
serialiser/rsgxsupdateitems.cc \
|
||||
serialiser/rsserviceinfoitems.cc \
|
||||
rsitems/rsbanlistitems.cc \
|
||||
rsitems/rsbwctrlitems.cc \
|
||||
rsitems/rsdiscovery2items.cc \
|
||||
rsitems/rsrttitems.cc \
|
||||
rsitems/rsgxsrecognitems.cc \
|
||||
rsitems/rsgxsupdateitems.cc \
|
||||
rsitems/rsserviceinfoitems.cc \
|
||||
|
||||
SOURCES += services/p3msgservice.cc \
|
||||
services/p3service.cc \
|
||||
@ -726,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 \
|
||||
@ -739,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 \
|
||||
@ -752,12 +748,12 @@ HEADERS += serialiser/rsnxsitems.h \
|
||||
gxs/rsgxsrequesttypes.h
|
||||
|
||||
|
||||
SOURCES += serialiser/rsnxsitems.cc \
|
||||
SOURCES += rsitems/rsnxsitems.cc \
|
||||
gxs/rsdataservice.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 \
|
||||
@ -776,85 +772,92 @@ HEADERS += gxstunnel/p3gxstunnel.h \
|
||||
SOURCES += gxstunnel/p3gxstunnel.cc \
|
||||
gxstunnel/rsgxstunnelitems.cc
|
||||
|
||||
# new serialization code
|
||||
HEADERS += serialiser/rsserializer.h \
|
||||
serialiser/rstypeserializer.h
|
||||
|
||||
SOURCES += serialiser/rsserializer.cc \
|
||||
serialiser/rstypeserializer.cc
|
||||
|
||||
# Identity Service
|
||||
HEADERS += retroshare/rsidentity.h \
|
||||
gxs/rsgixs.h \
|
||||
services/p3idservice.h \
|
||||
serialiser/rsgxsiditems.h \
|
||||
rsitems/rsgxsiditems.h \
|
||||
services/p3gxsreputation.h \
|
||||
serialiser/rsgxsreputationitems.h \
|
||||
rsitems/rsgxsreputationitems.h \
|
||||
|
||||
SOURCES += services/p3idservice.cc \
|
||||
serialiser/rsgxsiditems.cc \
|
||||
rsitems/rsgxsiditems.cc \
|
||||
services/p3gxsreputation.cc \
|
||||
serialiser/rsgxsreputationitems.cc \
|
||||
rsitems/rsgxsreputationitems.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 \
|
||||
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 \
|
||||
services/p3gxschannels.h \
|
||||
services/p3gxscommon.h \
|
||||
serialiser/rsgxscommentitems.h \
|
||||
serialiser/rsgxschannelitems.h \
|
||||
rsitems/rsgxscommentitems.h \
|
||||
rsitems/rsgxschannelitems.h \
|
||||
|
||||
SOURCES += services/p3gxschannels.cc \
|
||||
services/p3gxscommon.cc \
|
||||
serialiser/rsgxscommentitems.cc \
|
||||
serialiser/rsgxschannelitems.cc \
|
||||
rsitems/rsgxscommentitems.cc \
|
||||
rsitems/rsgxschannelitems.cc \
|
||||
|
||||
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
|
||||
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
|
||||
HEADERS += services/p3photoservice.h \
|
||||
retroshare/rsphoto.h \
|
||||
serialiser/rsphotoitems.h \
|
||||
rsitems/rsphotoitems.h \
|
||||
|
||||
SOURCES += services/p3photoservice.cc \
|
||||
serialiser/rsphotoitems.cc \
|
||||
rsitems/rsphotoitems.cc \
|
||||
}
|
||||
|
||||
rs_gxs_trans {
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <serialiser/rstlvtypes.h>
|
||||
#endif
|
||||
|
||||
#include <serialiser/rspluginitems.h>
|
||||
|
||||
#include <rsitems/rspluginitems.h>
|
||||
|
||||
#include <rsserver/p3face.h>
|
||||
#include <util/rsdir.h>
|
||||
@ -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 ;
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#define LIMIT_CERTIFICATE_SIZE 1
|
||||
#define MAX_CERTIFICATE_SIZE 10000
|
||||
|
@ -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"
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <util/rsdiscspace.h>
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
/*
|
||||
#define CONFIG_DEBUG 1
|
||||
|
@ -26,11 +26,11 @@
|
||||
#include <time.h>
|
||||
|
||||
#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 "serialiser/rsmsgitems.h"
|
||||
#include "rsitems/rsmsgitems.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include "serialiser/rshistoryitems.h"
|
||||
#include "rsitems/rshistoryitems.h"
|
||||
#include "retroshare/rshistory.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
@ -2295,43 +2295,6 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
||||
continue;
|
||||
}
|
||||
|
||||
RsPeerGroupItem_deprecated *gitem = dynamic_cast<RsPeerGroupItem_deprecated *>(*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;
|
||||
}
|
||||
|
||||
RsNodeGroupItem *gitem2 = dynamic_cast<RsNodeGroupItem*>(*it) ;
|
||||
|
||||
if (gitem2)
|
||||
|
@ -26,10 +26,10 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "p3servicecontrol.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "rsitems/rsnxsitems.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "pqi/pqiservice.h"
|
||||
|
||||
@ -43,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<uint32_t>(j,ctx,mServiceId,"mServiceId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,mServiceName,"mServiceName") ;
|
||||
RsTypeSerializer::serial_process<bool> (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<RsPeerId>::const_iterator it(mPeersAllowed.begin());it!=mPeersAllowed.end();++it)
|
||||
(*it).serialise(data,tlvsize,offset) ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mPeersDenied.size());
|
||||
|
||||
for(std::set<RsPeerId>::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;i<tmp && offset < rssize;++i)
|
||||
{
|
||||
RsPeerId peer_id ;
|
||||
ok &= peer_id.deserialise(data,rssize,offset) ;
|
||||
item->mPeersAllowed.insert(peer_id) ;
|
||||
}
|
||||
|
||||
ok &= getRawUInt32(data, rssize, &offset, &tmp);
|
||||
|
||||
for(uint32_t i=0;i<tmp && offset < rssize;++i)
|
||||
{
|
||||
RsPeerId peer_id ;
|
||||
ok &= peer_id.deserialise(data,rssize,offset) ;
|
||||
item->mPeersDenied.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<RsServiceControlItem *>(item);
|
||||
if (!scitem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return scitem->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsServiceControlItem *scitem = dynamic_cast<RsServiceControlItem *>(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 ;
|
||||
}
|
||||
|
@ -27,8 +27,7 @@
|
||||
#ifndef PQI_TOP_HEADER
|
||||
#define PQI_TOP_HEADER
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
class P3Interface
|
||||
{
|
||||
|
@ -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 <stdio.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsserviceserialiser.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
#include "pqi/pqisslpersongrp.h"
|
||||
@ -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);
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "pqi/pqistore.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include <iostream>
|
||||
@ -309,24 +310,25 @@ int pqistore::readPkt(RsItem **item_out)
|
||||
}
|
||||
|
||||
// workout how much more to read.
|
||||
int extralen = getRsItemSize(block) - blen;
|
||||
int totallen = extralen+blen;
|
||||
int blocklength = getRsItemSize(block);
|
||||
|
||||
// make sure that totallen is not a crazy number. If so, we drop the entire stream that might be corrupted.
|
||||
// make sure that blocklength is not a crazy number. If so, we drop the entire stream that might be corrupted.
|
||||
|
||||
if(totallen > 1024*1024)
|
||||
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 ;
|
||||
@ -520,17 +522,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)
|
||||
if(blocklength < blen || blocklength > 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)
|
||||
{
|
||||
|
@ -59,11 +59,12 @@ template<int n> 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<FLAGS_TAG_SERVICE_PERM > ServicePermissionFlags ;
|
||||
//
|
||||
typedef t_RsFlags32<FLAGS_TAG_SERVICE_CHAT > ChatLobbyFlags ;
|
||||
|
||||
// Flags for serializer
|
||||
//
|
||||
typedef t_RsFlags32<FLAGS_TAG_SERIALIZER > SerializationFlags ;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <retroshare/rstypes.h>
|
||||
#include <retroshare/rsids.h>
|
||||
|
||||
typedef GXSGroupId RsGxsGroupId;
|
||||
typedef Sha1CheckSum RsGxsMessageId;
|
||||
|
@ -136,7 +136,7 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> 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 ;
|
||||
|
@ -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;
|
||||
|
@ -52,7 +52,7 @@ class RsPhotoThumbnail
|
||||
|
||||
// Holds Thumbnail image.
|
||||
uint8_t *data;
|
||||
int size;
|
||||
uint32_t size;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
|
@ -58,6 +58,7 @@ class RsRtt
|
||||
virtual ~RsRtt() { return; }
|
||||
|
||||
virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list<RsRttPongResult> &results) = 0;
|
||||
virtual double getMeanOffset(const RsPeerId& id) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
71
libretroshare/src/rsitems/rsbanlistitems.cc
Normal file
71
libretroshare/src/rsitems/rsbanlistitems.cc
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbanlist.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsbanlistitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsBanListItem::clear()
|
||||
{
|
||||
peerList.TlvClear();
|
||||
}
|
||||
|
||||
void RsBanListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ;
|
||||
}
|
||||
|
||||
void RsBanListConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,type,"type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
|
||||
RsTypeSerializer::serial_process<time_t> (j,ctx,update_time,"update_time") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,banned_peers,"banned_peers") ;
|
||||
}
|
||||
RsItem *RsBanListSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_TYPE_BANLIST)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM: return new RsBanListConfigItem ;
|
||||
case RS_PKT_SUBTYPE_BANLIST_ITEM: return new RsBanListItem ;
|
||||
default:
|
||||
std::cerr << "(EE) unknown item subtype " << (int)item_sub_id << " in RsBanListSerialiser::create_item()" << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,15 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
#include "serialiser/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 +44,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvBanList peerList;
|
||||
};
|
||||
@ -64,40 +64,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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 RsServiceSerializer
|
||||
{
|
||||
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() :RsServiceSerializer(RS_SERVICE_TYPE_BANLIST) {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
61
libretroshare/src/rsitems/rsbwctrlitems.cc
Normal file
61
libretroshare/src/rsitems/rsbwctrlitems.cc
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbwctrlitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsbwctrlitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsBwCtrlSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_BWCTRL)
|
||||
return NULL ;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM: return new RsBwCtrlAllowedItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RsBwCtrlAllowedItem::clear()
|
||||
{
|
||||
allowedBw = 0;
|
||||
}
|
||||
|
||||
void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,9 +28,12 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM 0x01
|
||||
|
||||
@ -38,44 +41,29 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
virtual ~RsBwCtrlAllowedItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual ~RsBwCtrlAllowedItem() {}
|
||||
virtual void clear();
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class RsBwCtrlSerialiser: public RsSerialType
|
||||
class RsBwCtrlSerialiser: public RsServiceSerializer
|
||||
{
|
||||
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() :RsServiceSerializer(RS_SERVICE_TYPE_BWCTRL) {}
|
||||
virtual ~RsBwCtrlSerialiser() {}
|
||||
|
||||
RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
268
libretroshare/src/rsitems/rsconfigitems.cc
Normal file
268
libretroshare/src/rsitems/rsconfigitems.cc
Normal file
@ -0,0 +1,268 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsconfigitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie, Chris Parker.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
***/
|
||||
|
||||
#define RSSERIAL_ERROR_DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsFileConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_FILE_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,allPeerIds,"allPeerIds") ;
|
||||
|
||||
RsTypeSerializer::serial_process (j,ctx,cPeerId,"cPeerId") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,state,"state") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,in,"in") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,transferred,"transferred") ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,crate,"crate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,trate,"trate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,lrate,"lrate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,ltransfer,"ltransfer") ;
|
||||
|
||||
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") ;
|
||||
}
|
||||
|
||||
void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,parent_groups,"parent_groups") ;
|
||||
}
|
||||
|
||||
RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_GENERAL_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_KEY_VALUE: return new RsConfigKeyValueSet();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsConfigKeyValueSet::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,tlvkvs,"tlvkvs") ;
|
||||
}
|
||||
|
||||
RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_PEER_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
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;
|
||||
}
|
||||
void RsPeerNetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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<uint32_t>(j,ctx,netMode,"netMode") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_disc,"vs_disc") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_dht,"vs_dht") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lastContact,"lastContact") ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV4,"localAddrV4") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrV4,"extAddrV4") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV6,"localAddrV6") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrV6,"extAddrV6") ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DYNDNS,dyndns,"dyndns") ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrList,"localAddrList") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,extAddrList,"extAddrList") ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DOMADDR,domain_addr,"domain_addr") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,domain_port,"domain_port") ;
|
||||
}
|
||||
|
||||
void RsPeerBandwidthLimitsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peers,"peers") ;
|
||||
}
|
||||
|
||||
void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
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)
|
||||
{
|
||||
id = g.id ;
|
||||
name = g.name ;
|
||||
flag = g.flag ;
|
||||
pgpList.ids = g.peerIds;
|
||||
}
|
||||
|
||||
void RsNodeGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
|
||||
RsTypeSerializer::serial_process<uint32_t>(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<uint32_t>(j,ctx,flag,"flag") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpList,"pgpList") ;
|
||||
}
|
||||
|
||||
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 == RsGenericSerializer::DESERIALIZE)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"pgp_ids.size()") ;
|
||||
|
||||
pgp_ids.resize(v) ;
|
||||
service_flags.resize(v) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t s = pgp_ids.size();
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s,"pgp_ids.size()") ;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<pgp_ids.size();++i)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,pgp_ids[i],"pgp_ids[i]") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,service_flags[i],"service_flags[i]") ;
|
||||
}
|
||||
}
|
||||
|
289
libretroshare/src/rsitems/rsconfigitems.h
Normal file
289
libretroshare/src/rsitems/rsconfigitems.h
Normal file
@ -0,0 +1,289 @@
|
||||
#ifndef RS_CONFIG_ITEMS_SERIALISER_H
|
||||
#define RS_CONFIG_ITEMS_SERIALISER_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsconfigitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvkeyvalue.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
class RsGroupInfo;
|
||||
|
||||
const uint8_t RS_PKT_TYPE_GENERAL_CONFIG = 0x01;
|
||||
const uint8_t RS_PKT_TYPE_PEER_CONFIG = 0x02;
|
||||
const uint8_t RS_PKT_TYPE_CACHE_CONFIG = 0x03;
|
||||
const uint8_t RS_PKT_TYPE_FILE_CONFIG = 0x04;
|
||||
const uint8_t RS_PKT_TYPE_PLUGIN_CONFIG = 0x05;
|
||||
const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
|
||||
|
||||
/* GENERAL CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
|
||||
|
||||
/* PEER CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_STUN = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_NET = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_GROUP_deprecated = 0x04;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_PERMISSIONS = 0x05;
|
||||
const uint8_t RS_PKT_SUBTYPE_PEER_BANDLIMITS = 0x06;
|
||||
const uint8_t RS_PKT_SUBTYPE_NODE_GROUP = 0x07;
|
||||
|
||||
/* FILE CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_TRANSFER = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FILE_ITEM_deprecated = 0x02;
|
||||
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) {}
|
||||
|
||||
virtual ~RsPeerNetItem(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
/* networking information */
|
||||
RsPeerId peerId; /* 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 */
|
||||
|
||||
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||
|
||||
std::string dyndns;
|
||||
|
||||
RsTlvIpAddrSet localAddrList;
|
||||
RsTlvIpAddrSet extAddrList;
|
||||
|
||||
// for proxy connection.
|
||||
std::string domain_addr;
|
||||
uint16_t domain_port;
|
||||
};
|
||||
|
||||
// This item should be merged with the next item, but that is not backward compatible.
|
||||
class RsPeerServicePermissionItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerServicePermissionItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_PERMISSIONS) {}
|
||||
virtual ~RsPeerServicePermissionItem() {}
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
pgp_ids.clear() ;
|
||||
service_flags.clear() ;
|
||||
}
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
|
||||
/* Mandatory */
|
||||
std::vector<RsPgpId> pgp_ids ;
|
||||
std::vector<ServicePermissionFlags> service_flags ;
|
||||
};
|
||||
class RsPeerBandwidthLimitsItem : public RsItem
|
||||
{
|
||||
public:
|
||||
RsPeerBandwidthLimitsItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_PEER_BANDLIMITS) {}
|
||||
virtual ~RsPeerBandwidthLimitsItem() {}
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
peers.clear() ;
|
||||
}
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
/* Mandatory */
|
||||
std::map<RsPgpId,PeerBandwidthLimits> peers ;
|
||||
};
|
||||
|
||||
class RsNodeGroupItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsNodeGroupItem(): RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP){}
|
||||
virtual ~RsNodeGroupItem() {}
|
||||
|
||||
virtual void clear() { pgpList.TlvClear();}
|
||||
|
||||
explicit RsNodeGroupItem(const RsGroupInfo&) ;
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// /* set data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void set(RsGroupInfo &groupInfo);
|
||||
// /* get data from RsGroupInfo to RsPeerGroupItem */
|
||||
// void get(RsGroupInfo &groupInfo);
|
||||
|
||||
/* Mandatory */
|
||||
RsNodeGroupId id;
|
||||
std::string name;
|
||||
uint32_t flag;
|
||||
|
||||
RsTlvPgpIdSet pgpList;
|
||||
};
|
||||
|
||||
class RsPeerStunItem: public RsItem
|
||||
{
|
||||
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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvPeerIdSet stunList; /* Mandatory */
|
||||
};
|
||||
|
||||
class RsPeerConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsPeerConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PEER_CONFIG) {}
|
||||
|
||||
virtual ~RsPeerConfigSerialiser(){}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileTransfer: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileTransfer() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_TRANSFER)
|
||||
{
|
||||
state = 0;
|
||||
in = 0;
|
||||
transferred = 0;
|
||||
crate = 0;
|
||||
trate = 0;
|
||||
lrate = 0;
|
||||
ltransfer = 0;
|
||||
flags = 0;
|
||||
chunk_strategy = 0;
|
||||
}
|
||||
virtual ~RsFileTransfer(){}
|
||||
virtual void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvFileItem file;
|
||||
RsTlvPeerIdSet allPeerIds;
|
||||
|
||||
RsPeerId cPeerId;
|
||||
|
||||
uint16_t state;
|
||||
uint16_t in;
|
||||
|
||||
uint64_t transferred;
|
||||
uint32_t crate;
|
||||
uint32_t trate;
|
||||
|
||||
uint32_t lrate;
|
||||
uint32_t ltransfer;
|
||||
|
||||
// chunk information
|
||||
uint32_t flags ;
|
||||
uint32_t chunk_strategy ; // strategy flags for chunks
|
||||
CompressedChunkMap compressed_chunk_map ; // chunk availability (bitwise)
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001;
|
||||
|
||||
class RsFileConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsFileConfigItem() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_ITEM) {}
|
||||
virtual ~RsFileConfigItem() {}
|
||||
virtual void clear() { parent_groups.TlvClear(); }
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvFileItem file;
|
||||
uint32_t flags;
|
||||
RsTlvNodeGroupIdSet parent_groups ;
|
||||
};
|
||||
/**************************************************************************/
|
||||
|
||||
class RsFileConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsFileConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG) { }
|
||||
virtual ~RsFileConfigSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
/* Config items that are used generally */
|
||||
|
||||
class RsConfigKeyValueSet: public RsItem
|
||||
{
|
||||
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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsTlvKeyValueSet tlvkvs;
|
||||
};
|
||||
|
||||
|
||||
class RsGeneralConfigSerialiser: public RsConfigSerializer
|
||||
{
|
||||
public:
|
||||
RsGeneralConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG) {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_CONFIG_ITEMS_SERIALISER_H */
|
293
libretroshare/src/rsitems/rsdiscovery2items.cc
Normal file
293
libretroshare/src/rsitems/rsdiscovery2items.cc
Normal file
@ -0,0 +1,293 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsdiscitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsitems/rsdiscovery2items.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#endif
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
***/
|
||||
|
||||
#define RSSERIAL_ERROR_DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mode,"mode") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
|
||||
}
|
||||
|
||||
void RsDiscPgpCertItem::clear()
|
||||
{
|
||||
pgpId.clear();
|
||||
pgpCert.clear();
|
||||
}
|
||||
|
||||
|
||||
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") ;
|
||||
}
|
||||
|
||||
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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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<uint32_t>(j,ctx,netMode,"netMode");
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_disc,"vs_disc");
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,vs_dht,"vs_dht");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lastContact,"lastContact");
|
||||
|
||||
// This is a hack. Normally we should have to different item types, in order to avoid this nonesense.
|
||||
|
||||
if(j == RsGenericSerializer::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<uint16_t>(j,ctx,hiddenPort,"hiddenPort");
|
||||
}
|
||||
else
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV4,"localAddrV4");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, extAddrV4,"extAddrV4");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,localAddrV6,"localAddrV6");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx, extAddrV6,"extAddrV6");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(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");
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
#if 0
|
||||
|
||||
RsDiscServicesItem::~RsDiscServicesItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsDiscServicesItem::clear()
|
||||
{
|
||||
version.clear();
|
||||
mServiceIdMap.TlvClear();
|
||||
}
|
||||
|
||||
std::ostream &RsDiscServicesItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsDiscServicesItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "version: " << version << std::endl;
|
||||
mServiceIdMap.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out, "RsDiscServicesItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsDiscSerialiser::sizeServices(RsDiscServicesItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->version); /* version */
|
||||
s += item->mServiceIdMap.TlvSize();
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsDiscSerialiser::serialiseServices(RsDiscServicesItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeServices(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::serialiseServices() Header: " << ok << std::endl;
|
||||
std::cerr << "RsDiscSerialiser::serialiseServices() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version);
|
||||
ok &= item->mServiceIdMap.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize) {
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::serialiseServices() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(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::deserialiseServices() Wrong Type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
{
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() Not Enough Space" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsDiscServicesItem *item = new RsDiscServicesItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version);
|
||||
ok &= item->mServiceIdMap.GetTlv(data, rssize, &offset);
|
||||
|
||||
if (offset != rssize) {
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() offset != rssize" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
#ifdef RSSERIAL_ERROR_DEBUG
|
||||
std::cerr << "RsDiscSerialiser::deserialiseServices() ok = false" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
#endif
|
@ -31,7 +31,11 @@
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.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;
|
||||
@ -52,18 +56,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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
uint32_t mode;
|
||||
RsTlvPgpIdSet pgpIdSet;
|
||||
@ -73,18 +77,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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsPgpId pgpId;
|
||||
std::string pgpCert;
|
||||
@ -93,18 +97,18 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
class RsDiscContactItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
RsDiscContactItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsPgpId pgpId;
|
||||
RsPeerId sslId;
|
||||
@ -126,7 +130,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 +168,14 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
#endif
|
||||
|
||||
|
||||
class RsDiscSerialiser: public RsSerialType
|
||||
class RsDiscSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsDiscSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC)
|
||||
{ return; }
|
||||
RsDiscSerialiser() :RsServiceSerializer(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 ;
|
||||
};
|
||||
|
||||
|
156
libretroshare/src/rsitems/rsfiletransferitems.cc
Normal file
156
libretroshare/src/rsitems/rsfiletransferitems.cc
Normal file
@ -0,0 +1,156 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "rsitems/rsfiletransferitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define DEBUG_TRANSFERS 1
|
||||
***/
|
||||
|
||||
|
||||
#ifdef DEBUG_TRANSFERS
|
||||
#include "util/rsprint.h"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void RsFileTransferDataRequestItem::clear()
|
||||
{
|
||||
file.TlvClear();
|
||||
fileoffset = 0;
|
||||
chunksize = 0;
|
||||
}
|
||||
void RsFileTransferDataItem::clear()
|
||||
{
|
||||
fd.TlvClear();
|
||||
}
|
||||
|
||||
void RsFileTransferDataRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint64_t> (j,ctx,fileoffset,"fileoffset") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunksize, "chunksize") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file, "file") ;
|
||||
}
|
||||
|
||||
void RsFileTransferDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,fd,"fd") ;
|
||||
}
|
||||
|
||||
void RsFileTransferChunkMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,is_client,"is_client") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
}
|
||||
|
||||
void RsFileTransferChunkMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<bool> (j,ctx,is_client, "is_client") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ;
|
||||
}
|
||||
|
||||
void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
|
||||
}
|
||||
|
||||
void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ;
|
||||
}
|
||||
|
||||
//===================================================================================================//
|
||||
// CompressedChunkMap //
|
||||
//===================================================================================================//
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s)
|
||||
{
|
||||
return 4 + 4*s._map.size() ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt32(data, size, &offset, s._map.size());
|
||||
|
||||
for(uint32_t i=0;i<s._map.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, size, &offset, s._map[i]);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s)
|
||||
{
|
||||
uint32_t S =0;
|
||||
bool ok = getRawUInt32(data, size, &offset, &S);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
s._map.resize(S) ;
|
||||
|
||||
for(uint32_t i=0;i<S && ok;++i)
|
||||
ok &= getRawUInt32(data, size, &offset, &(s._map[i]));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s)
|
||||
{
|
||||
std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl;
|
||||
}
|
||||
|
||||
//===================================================================================================//
|
||||
// Serializer //
|
||||
//===================================================================================================//
|
||||
|
||||
RsItem *RsFileTransferSerialiser::create_item(uint16_t service_type,uint8_t item_type) const
|
||||
{
|
||||
if(service_type != RS_SERVICE_TYPE_FILE_TRANSFER)
|
||||
return NULL ;
|
||||
|
||||
switch(item_type)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FT_DATA_REQUEST : return new RsFileTransferDataRequestItem();
|
||||
case RS_PKT_SUBTYPE_FT_DATA : return new RsFileTransferDataItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST : return new RsFileTransferChunkMapRequestItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_MAP : return new RsFileTransferChunkMapItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST : return new RsFileTransferSingleChunkCrcRequestItem();
|
||||
case RS_PKT_SUBTYPE_FT_CHUNK_CRC : return new RsFileTransferSingleChunkCrcItem() ;
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
@ -29,10 +29,12 @@
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_DATA_REQUEST = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_DATA = 0x02;
|
||||
@ -53,20 +55,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 +70,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
@ -103,11 +92,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual void clear();
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
@ -122,10 +109,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
@ -142,11 +128,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
@ -163,11 +147,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
@ -183,11 +165,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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
virtual void clear() {}
|
||||
|
||||
// Private data part.
|
||||
//
|
||||
@ -196,65 +176,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 RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsFileTransferSerialiser(): RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_FILE_TRANSFER) {}
|
||||
RsFileTransferSerialiser(): RsServiceSerializer(RS_SERVICE_TYPE_FILE_TRANSFER) {}
|
||||
|
||||
virtual ~RsFileTransferSerialiser() {}
|
||||
|
||||
virtual uint32_t size(RsItem *item)
|
||||
{
|
||||
RsFileTransferItem *ftitem = dynamic_cast<RsFileTransferItem *>(item);
|
||||
if (!ftitem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ftitem->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsFileTransferItem *ftitem = dynamic_cast<RsFileTransferItem *>(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) const ;
|
||||
|
||||
};
|
||||
|
173
libretroshare/src/rsitems/rsgxschannelitems.cc
Normal file
173
libretroshare/src/rsitems/rsgxschannelitems.cc
Normal file
@ -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 <iostream>
|
||||
|
||||
#include "rsgxschannelitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialiser/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<RsTlvItem>(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<RsGxsFile>::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<RsTlvFileItem>::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<RsTlvItem>(j,ctx,mAttachment,"mAttachment") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mThumbnail,"mThumbnail") ;
|
||||
}
|
@ -28,33 +28,32 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
#include "rsitems/rsserviceids.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 "serialiser/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);
|
||||
@ -68,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:
|
||||
@ -89,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 */
|
124
libretroshare/src/rsitems/rsgxscircleitems.cc
Normal file
124
libretroshare/src/rsitems/rsgxscircleitems.cc
Normal file
@ -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 <iostream>
|
||||
|
||||
#include "rsgxscircleitems.h"
|
||||
|
||||
#include "serialiser/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<uint32_t>(j,ctx,time_stamp,"time_stamp") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,time_out ,"time_out") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,subscription_type ,"subscription_type") ;
|
||||
}
|
||||
|
||||
void RsGxsCircleGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,gxsIdSet,"gxsIdSet") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(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;
|
||||
}
|
||||
|
@ -28,13 +28,13 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "rsitems/rsserviceids.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;
|
||||
@ -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 */
|
59
libretroshare/src/rsitems/rsgxscommentitems.cc
Normal file
59
libretroshare/src/rsitems/rsgxscommentitems.cc
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxscommentitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxscommentitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/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 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ;
|
||||
}
|
||||
|
||||
void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ;
|
||||
}
|
||||
|
@ -28,9 +28,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
|
||||
@ -43,11 +41,11 @@ 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;
|
||||
};
|
||||
@ -57,40 +55,23 @@ 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() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_COMMENT_ITEMS_H */
|
67
libretroshare/src/rsitems/rsgxsforumitems.cc
Normal file
67
libretroshare/src/rsitems/rsgxsforumitems.cc
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsforumitems.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 <iostream>
|
||||
|
||||
#include "rsgxsforumitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define GXSFORUM_DEBUG 1
|
||||
|
||||
RsItem *RsGxsForumSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_FORUMS)
|
||||
return NULL ;
|
||||
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
void RsGxsForumGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
}
|
||||
|
||||
void RsGxsForumGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,mGroup.mDescription,"mGroup.Description");
|
||||
}
|
||||
void RsGxsForumMsgItem::clear()
|
||||
{
|
||||
mMsg.mMsg.clear();
|
||||
}
|
||||
|
||||
void RsGxsForumMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,mMsg.mMsg,"mGroup.Description");
|
||||
}
|
||||
|
||||
|
||||
|
77
libretroshare/src/rsitems/rsgxsforumitems.h
Normal file
77
libretroshare/src/rsitems/rsgxsforumitems.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsforumitems.h
|
||||
*
|
||||
* 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 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_FORUM_ITEMS_H
|
||||
#define RS_GXS_FORUM_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM = 0x03;
|
||||
|
||||
class RsGxsForumGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class RsGxsForumMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
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 RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsGxsForumSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_FORUMS) {}
|
||||
virtual ~RsGxsForumSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_FORUM_ITEMS_H */
|
125
libretroshare/src/rsitems/rsgxsiditems.cc
Normal file
125
libretroshare/src/rsitems/rsgxsiditems.cc
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsiditems.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 <iostream>
|
||||
|
||||
#include "rsgxsiditems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvstring.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include "serialiser/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();
|
||||
}
|
||||
void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ;
|
||||
}
|
||||
|
||||
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<RsTlvItem>(j,ctx,rset,"mRecognTags") ;
|
||||
|
||||
// image is optional
|
||||
|
||||
if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize)
|
||||
return ;
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
|
||||
}
|
||||
|
||||
bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = group.mMeta;
|
||||
mPgpIdHash = group.mPgpIdHash;
|
||||
mPgpIdSign = group.mPgpIdSign;
|
||||
mRecognTags = group.mRecognTags;
|
||||
|
||||
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 RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mPgpIdHash = mPgpIdHash;
|
||||
group.mPgpIdSign = mPgpIdSign;
|
||||
group.mRecognTags = mRecognTags;
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "rsgxsitems.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<RsGxsId,time_t> mTimeStamps ;
|
||||
std::set<RsGxsId> 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<RsGxsIdItem *>(item);
|
||||
if (!idItem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return idItem->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsIdItem *idItem = dynamic_cast<RsGxsIdItem *>(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 */
|
@ -26,16 +26,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvkeys.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
|
||||
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta);
|
||||
|
||||
|
||||
class RsGxsGrpItem : public RsItem
|
||||
{
|
||||
|
||||
@ -45,7 +43,6 @@ public:
|
||||
: RsItem(RS_PKT_VERSION_SERVICE, service, subtype) { return; }
|
||||
virtual ~RsGxsGrpItem(){}
|
||||
|
||||
|
||||
RsGroupMetaData meta;
|
||||
};
|
||||
|
118
libretroshare/src/rsitems/rsgxsrecognitems.cc
Normal file
118
libretroshare/src/rsitems/rsgxsrecognitems.cc
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsrecogitems.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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsitems/rsgxsrecognitems.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsRecognSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const
|
||||
{
|
||||
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()
|
||||
{
|
||||
issued_at = 0;
|
||||
period = 0;
|
||||
tag_class = 0;
|
||||
tag_type = 0;
|
||||
|
||||
identity.clear();
|
||||
nickname.clear();
|
||||
comment.clear();
|
||||
|
||||
sign.TlvClear();
|
||||
|
||||
}
|
||||
void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,issued_at ,"issued_at") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,period ,"period") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_class ,"tag_class") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (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<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
void RsGxsRecognTagItem::clear()
|
||||
{
|
||||
valid_from = 0;
|
||||
valid_to = 0;
|
||||
|
||||
tag_class = 0;
|
||||
tag_type = 0;
|
||||
|
||||
identity.clear();
|
||||
nickname.clear();
|
||||
|
||||
sign.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,valid_from ,"valid_from") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,valid_to ,"valid_to") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_class ,"tag_class") ;
|
||||
RsTypeSerializer::serial_process<uint16_t> (j,ctx,tag_type ,"tag_type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,identity ,"identity");
|
||||
RsTypeSerializer::serial_process (j,ctx,1,nickname ,"nickname") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
void RsGxsRecognSignerItem::clear()
|
||||
{
|
||||
signing_classes.TlvClear();
|
||||
key.TlvClear();
|
||||
sign.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signing_classes ,"signing_classes") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,key ,"key");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,sign ,"sign") ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,8 +28,10 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
|
||||
@ -43,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;
|
||||
}
|
||||
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;
|
||||
@ -79,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;
|
||||
@ -104,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;
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
110
libretroshare/src/rsitems/rsgxsreputationitems.cc
Normal file
110
libretroshare/src/rsitems/rsgxsreputationitems.cc
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbanlist.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsgxsreputationitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsGxsReputationSetItem::clear()
|
||||
{
|
||||
mOpinions.clear() ;
|
||||
}
|
||||
|
||||
void RsGxsReputationUpdateItem::clear()
|
||||
{
|
||||
mOpinions.clear() ;
|
||||
}
|
||||
|
||||
void RsGxsReputationBannedNodeSetItem::clear()
|
||||
{
|
||||
mKnownIdentities.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsReputationConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastQuery,"mLastQuery") ;
|
||||
}
|
||||
|
||||
void RsGxsReputationBannedNodeSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,mLastActivityTS,"mLastActivityTS") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mKnownIdentities,"mKnownIdentities") ;
|
||||
}
|
||||
|
||||
void RsGxsReputationSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinion,"mOwnOpinion") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinionTS,"mOwnOpinionTS") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mIdentityFlags,"mIdentityFlags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUsedTS,"mLastUsedTS") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,mOwnerNodeId,"mOwnerNodeId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
|
||||
}
|
||||
|
||||
void RsGxsReputationUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
|
||||
}
|
||||
void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,17 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
|
||||
#include "serialiser/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 +58,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 +68,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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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 +87,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 +97,8 @@ public:
|
||||
RsPgpId mOwnerNodeId;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
};
|
||||
#endif
|
||||
|
||||
class RsGxsReputationSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
@ -116,10 +112,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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
@ -136,10 +130,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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
RsPgpId mPgpId ;
|
||||
uint32_t mLastActivityTS ;
|
||||
@ -153,10 +145,8 @@ 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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
uint32_t mLatestUpdate;
|
||||
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
|
||||
@ -169,40 +159,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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
|
||||
|
||||
uint32_t mLastUpdate;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsReputationSerialiser: public RsSerialType
|
||||
class RsGxsReputationSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_REPUTATION){}
|
||||
|
||||
RsGxsReputationSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_REPUTATION){}
|
||||
virtual ~RsGxsReputationSerialiser(){}
|
||||
|
||||
virtual uint32_t size(RsItem *item)
|
||||
{
|
||||
return dynamic_cast<RsReputationItem*>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return dynamic_cast<RsReputationItem*>(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;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
138
libretroshare/src/rsitems/rsgxsupdateitems.cc
Normal file
138
libretroshare/src/rsitems/rsgxsupdateitems.cc
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxsupdateitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "rsgxsupdateitems.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 */
|
||||
/**********************************************************************************************/
|
||||
|
||||
void RsGxsGrpUpdateItem::clear()
|
||||
{
|
||||
grpUpdateTS = 0;
|
||||
peerID.clear();
|
||||
}
|
||||
|
||||
void RsGxsMsgUpdateItem::clear()
|
||||
{
|
||||
msgUpdateInfos.clear();
|
||||
peerID.clear();
|
||||
}
|
||||
|
||||
void RsGxsServerMsgUpdateItem::clear()
|
||||
{
|
||||
msgUpdateTS = 0;
|
||||
grpId.clear();
|
||||
}
|
||||
|
||||
void RsGxsServerGrpUpdateItem::clear()
|
||||
{
|
||||
grpUpdateTS = 0;
|
||||
}
|
||||
|
||||
/**********************************************************************************************/
|
||||
/* SERIALISER */
|
||||
/**********************************************************************************************/
|
||||
|
||||
void RsGxsGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,peerID,"peerID");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
|
||||
}
|
||||
|
||||
void RsGxsServerGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
|
||||
}
|
||||
|
||||
void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,peerID,"peerID");
|
||||
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");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgUpdateTS,"msgUpdateTS");
|
||||
}
|
||||
void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_keep_delay,"msg_keep_delay") ;
|
||||
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") ;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#if 0
|
||||
#include <map>
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.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<RsGxsNetServiceItem *>(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<RsGxsNetServiceItem *>(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;
|
||||
};
|
@ -28,8 +28,9 @@
|
||||
#ifndef RS_HEARTBEAT_ITEMS_H
|
||||
#define RS_HEARTBEAT_ITEMS_H
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01;
|
||||
|
||||
@ -41,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 ;
|
||||
}
|
||||
};
|
||||
|
||||
|
75
libretroshare/src/rsitems/rshistoryitems.cc
Normal file
75
libretroshare/src/rsitems/rshistoryitems.cc
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2011 by Thunder.
|
||||
*
|
||||
* 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/rshistoryitems.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
uint16_t version=0;
|
||||
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,version,"version") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,chatPeerId,"chatPeerId") ;
|
||||
RsTypeSerializer::serial_process<bool> (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<uint32_t>(j,ctx,sendTime,"sendTime") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message,"message") ;
|
||||
}
|
||||
|
||||
RsItem *RsHistorySerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_type != RS_PKT_TYPE_HISTORY_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
if(item_subtype == 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)
|
||||
{
|
||||
incoming = false;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
msgId = 0;
|
||||
saveToDisc = true;
|
||||
}
|
||||
|
||||
|
@ -26,20 +26,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "serialiser/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(RsGenericSerializer::SerializeJob j,RsGenericSerializer::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();
|
||||
RsHistorySerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG) {}
|
||||
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);
|
||||
|
||||
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 item_type,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
91
libretroshare/src/rsitems/rsitem.h
Normal file
91
libretroshare/src/rsitems/rsitem.h
Normal file
@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include <typeinfo> // for typeid
|
||||
|
||||
#include "util/smallobject.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "util/stacktrace.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();
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
||||
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 ;}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
protected:
|
||||
uint32_t type;
|
||||
RsPeerId peerId;
|
||||
uint8_t _priority_level ;
|
||||
};
|
||||
|
||||
/// TODO: Do this make sense with the new serialization system?
|
||||
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;
|
||||
};
|
182
libretroshare/src/rsitems/rsmsgitems.cc
Normal file
182
libretroshare/src/rsitems/rsmsgitems.cc
Normal file
@ -0,0 +1,182 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "rsitems/rsmsgitems.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
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;
|
||||
msgFlags = 0;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
subject.clear();
|
||||
message.clear();
|
||||
|
||||
rspeerid_msgto.TlvClear();
|
||||
rspeerid_msgcc.TlvClear();
|
||||
rspeerid_msgbcc.TlvClear();
|
||||
|
||||
rsgxsid_msgto.TlvClear();
|
||||
rsgxsid_msgcc.TlvClear();
|
||||
rsgxsid_msgbcc.TlvClear();
|
||||
|
||||
attachment.TlvClear();
|
||||
}
|
||||
|
||||
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<uint32_t>(j,ctx,(uint32_t&)time_stamp,"time_stamp") ;
|
||||
}
|
||||
void RsMsgTagType::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,rgb_color,"rgb_color") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tagId,"tagId") ;
|
||||
}
|
||||
|
||||
void RsMsgTags::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
|
||||
#warning this is not the correct way to serialise here. We should directly call serial_process<std::vector<uint32_t> >() but for backward compatibility, we cannot
|
||||
|
||||
if(j == RsGenericSerializer::DESERIALIZE)
|
||||
while(ctx.mOffset < ctx.mSize)
|
||||
{
|
||||
uint32_t n ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,n,"tagIds element") ;
|
||||
tagIds.push_back(n) ;
|
||||
}
|
||||
else
|
||||
for(std::list<uint32_t>::iterator it(tagIds.begin());it!=tagIds.end();++it)
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,*it,"tagIds element") ;
|
||||
}
|
||||
|
||||
void RsMsgSrcId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ;
|
||||
}
|
||||
|
||||
void RsMsgGRouterMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ;
|
||||
}
|
||||
|
||||
void RsMsgGRouterMap::clear()
|
||||
{
|
||||
ongoing_msgs.clear() ;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void RsMsgDistantMessagesHashMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ;
|
||||
}
|
||||
|
||||
void RsMsgParentId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgParentId,"msgParentId") ;
|
||||
}
|
||||
|
||||
void RsMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgFlags,"msgFlags");
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime");
|
||||
RsTypeSerializer::serial_process<uint32_t>(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<RsTlvItem>(j,ctx,rspeerid_msgto,"rspeerid_msgto");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgcc,"rspeerid_msgcc");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rspeerid_msgbcc,"rspeerid_msgbcc");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgto,"rsgxsid_msgto");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgcc,"rsgxsid_msgcc");
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rsgxsid_msgbcc,"rsgxsid_msgbcc");
|
||||
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,attachment,"attachment");
|
||||
|
||||
if(ctx.mFlags & RsServiceSerializer::SERIALIZATION_FLAG_CONFIG)
|
||||
RsTypeSerializer::serial_process<uint32_t>(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();
|
||||
}
|
||||
|
@ -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"
|
||||
@ -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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::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 RsServiceSerializer
|
||||
{
|
||||
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)
|
||||
:RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){}
|
||||
|
||||
virtual ~RsMsgSerialiser() {}
|
||||
|
||||
virtual uint32_t size(RsItem *item)
|
||||
{
|
||||
return dynamic_cast<RsMessageItem*>(item)->serial_size(m_bConfiguration) ;
|
||||
}
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return dynamic_cast<RsMessageItem*>(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 ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
221
libretroshare/src/rsitems/rsnxsitems.cc
Normal file
221
libretroshare/src/rsitems/rsnxsitems.cc
Normal file
@ -0,0 +1,221 @@
|
||||
#include "rsnxsitems.h"
|
||||
#include "util/rsprint.h"
|
||||
#include <iomanip>
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
const uint8_t RsNxsSyncGrpItem::FLAG_REQUEST = 0x001;
|
||||
const uint8_t RsNxsSyncGrpItem::FLAG_RESPONSE = 0x002;
|
||||
|
||||
const uint8_t RsNxsSyncMsgItem::FLAG_REQUEST = 0x001;
|
||||
const uint8_t RsNxsSyncMsgItem::FLAG_RESPONSE = 0x002;
|
||||
|
||||
const uint8_t RsNxsSyncGrpItem::FLAG_USE_SYNC_HASH = 0x0001;
|
||||
const uint8_t RsNxsSyncMsgItem::FLAG_USE_SYNC_HASH = 0x0001;
|
||||
|
||||
const uint8_t RsNxsSyncMsgReqItem::FLAG_USE_HASHED_GROUP_ID = 0x02;
|
||||
|
||||
/** transaction state **/
|
||||
const uint16_t RsNxsTransacItem::FLAG_BEGIN_P1 = 0x0001;
|
||||
const uint16_t RsNxsTransacItem::FLAG_BEGIN_P2 = 0x0002;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_SUCCESS = 0x0004;
|
||||
const uint16_t RsNxsTransacItem::FLAG_CANCEL = 0x0008;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_FAIL_NUM = 0x0010;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_FAIL_TIMEOUT = 0x0020;
|
||||
const uint16_t RsNxsTransacItem::FLAG_END_FAIL_FULL = 0x0040;
|
||||
|
||||
|
||||
/** transaction type **/
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_GRP_LIST_RESP = 0x0100;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_MSG_LIST_RESP = 0x0200;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_GRP_LIST_REQ = 0x0400;
|
||||
const uint16_t RsNxsTransacItem::FLAG_TYPE_MSG_LIST_REQ = 0x0800;
|
||||
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::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != SERVICE_TYPE)
|
||||
return NULL ;
|
||||
|
||||
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:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RsNxsSyncMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (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 )
|
||||
{
|
||||
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<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,pos ,"pos") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,grp ,"grp") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,meta ,"meta") ;
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpStatsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,request_type ,"request_type") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,number_of_posts,"number_of_posts") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,last_post_TS ,"last_post_TS") ;
|
||||
}
|
||||
|
||||
void RsNxsSyncGrpReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,createdSince ,"createdSince") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_HASH_SHA1,syncHash,"syncHash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
|
||||
}
|
||||
|
||||
void RsNxsTransacItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,transactFlag ,"transactFlag") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,nItems ,"nItems") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,updateTS ,"updateTS") ;
|
||||
}
|
||||
void RsNxsSyncGrpItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,publishTs ,"publishTs") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,authorId ,"authorId") ;
|
||||
}
|
||||
void RsNxsSyncMsgReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<uint8_t> (j,ctx,flag ,"flag") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(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<uint32_t>(j,ctx,updateTS ,"updateTS") ;
|
||||
}
|
||||
void RsNxsGroupPublishKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,grpId ,"grpId") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,private_key ,"private_key") ;
|
||||
}
|
||||
void RsNxsEncryptedDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,transactionNumber,"transactionNumber") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(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();
|
||||
}
|
||||
|
||||
std::ostream&RsNxsMsg::print(std::ostream& out, uint16_t /*indent*/)
|
||||
{ return out; }
|
||||
|
||||
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<RsGxsId,RsTlvBinaryData>::iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it)
|
||||
it->second.TlvClear() ;
|
||||
|
||||
encrypted_session_keys.clear() ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -30,7 +30,8 @@
|
||||
#include <map>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
@ -71,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
|
||||
};
|
||||
@ -102,13 +96,10 @@ 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
|
||||
@ -126,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
|
||||
@ -148,13 +137,11 @@ 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 ;
|
||||
@ -193,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 ; }
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const ;
|
||||
RsNxsTransacItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM) { clear(); }
|
||||
virtual ~RsNxsTransacItem() {}
|
||||
|
||||
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;
|
||||
@ -223,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; }
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
RsNxsSyncGrpItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM) { clear();}
|
||||
virtual ~RsNxsSyncGrpItem() {}
|
||||
|
||||
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
|
||||
@ -243,6 +224,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#ifdef SUSPENDED_CODE_27042017
|
||||
/*!
|
||||
* Use to send to peer list of grps
|
||||
* held by server peer
|
||||
@ -255,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<RsGxsId, RsTlvBinaryData> encrypted_session_keys; // encrypted session keys
|
||||
};
|
||||
#endif
|
||||
/*!
|
||||
* Use to send to peer list of grps
|
||||
* held by server peer
|
||||
@ -281,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
|
||||
///
|
||||
@ -305,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;
|
||||
@ -353,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;
|
||||
@ -379,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; }
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
RsNxsSyncMsgItem(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_SYNC_MSG_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);
|
||||
|
||||
uint8_t flag; // response/req
|
||||
RsGxsGroupId grpId;
|
||||
@ -406,12 +372,11 @@ struct RsNxsMsg : RsNxsItem
|
||||
msg(servtype), metaData(NULL) { clear(); }
|
||||
virtual ~RsNxsMsg() { delete metaData; }
|
||||
|
||||
virtual uint32_t serial_size() const;
|
||||
virtual bool serialise(void *data,uint32_t& size) const;
|
||||
bool deserialize(const uint8_t* data, uint32_t& size, uint32_t& offset);
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
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
|
||||
@ -441,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
|
||||
@ -465,13 +427,11 @@ class RsNxsSearchResultMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsNxsSearchResultMsgItem() : context(0) { return;}
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const;
|
||||
virtual uint32_t serial_size() const;
|
||||
RsNxsSearchResultMsgItem() : context(0) {}
|
||||
|
||||
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
|
||||
@ -492,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;
|
||||
@ -535,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;
|
||||
};
|
||||
|
120
libretroshare/src/rsitems/rsphotoitems.cc
Normal file
120
libretroshare/src/rsitems/rsphotoitems.cc
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, 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 <iostream>
|
||||
|
||||
#include "rsitems/rsphotoitems.h"
|
||||
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
|
||||
RsItem *RsGxsPhotoSerialiser::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 ;
|
||||
}
|
||||
}
|
||||
|
||||
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<RsTlvItem>(j,ctx,b,"thumbnail binary data") ;
|
||||
}
|
||||
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<RsTlvItem>(j,ctx, b, "mThumbnail") ;
|
||||
}
|
||||
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<uint32_t>(j,ctx,comment.mCommentFlag,"mCommentFlag");
|
||||
}
|
||||
|
||||
void RsGxsPhotoAlbumItem::clear()
|
||||
{
|
||||
album.mCaption.clear();
|
||||
album.mCategory.clear();
|
||||
album.mDescription.clear();
|
||||
album.mHashTags.clear();
|
||||
album.mOther.clear();
|
||||
album.mPhotoPath.clear();
|
||||
album.mPhotographer.clear();
|
||||
album.mWhen.clear();
|
||||
album.mWhere.clear();
|
||||
album.mThumbnail.deleteImage();
|
||||
}
|
||||
|
||||
void RsGxsPhotoCommentItem::clear()
|
||||
{
|
||||
comment.mComment.clear();
|
||||
comment.mCommentFlag = 0;
|
||||
}
|
||||
|
||||
void RsGxsPhotoPhotoItem::clear()
|
||||
{
|
||||
photo.mCaption.clear();
|
||||
photo.mCategory.clear();
|
||||
photo.mDescription.clear();
|
||||
photo.mHashTags.clear();
|
||||
photo.mOther.clear();
|
||||
photo.mPhotographer.clear();
|
||||
photo.mWhen.clear();
|
||||
photo.mWhere.clear();
|
||||
photo.mThumbnail.deleteImage();
|
||||
}
|
96
libretroshare/src/rsitems/rsphotoitems.h
Normal file
96
libretroshare/src/rsitems/rsphotoitems.h
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Christopher Evi-Parker, 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPHOTOV2ITEMS_H_
|
||||
#define RSPHOTOV2ITEMS_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsserializer.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_COMMENT_ITEM = 0x04;
|
||||
|
||||
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
virtual ~RsGxsPhotoAlbumItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPhotoAlbum album;
|
||||
};
|
||||
|
||||
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class RsGxsPhotoCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) {}
|
||||
virtual ~RsGxsPhotoCommentItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
RsPhotoComment comment;
|
||||
};
|
||||
|
||||
class RsGxsPhotoSerialiser : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
|
||||
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_ */
|
@ -26,14 +26,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#if 0
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#endif
|
||||
#include "serialiser/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<RsPluginItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return dynamic_cast<RsPluginItem *>(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<RsTlvItem>(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 ;
|
||||
}
|
||||
};
|
||||
|
||||
|
63
libretroshare/src/rsitems/rsposteditems.cc
Normal file
63
libretroshare/src/rsitems/rsposteditems.cc
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/gxs: rsopsteditems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012-2013 by Robert Fernie, Christopher Evi-Parker
|
||||
*
|
||||
* 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 "rsitems/rsposteditems.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
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") ;
|
||||
}
|
||||
|
||||
void RsGxsPostedGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,mGroup.mDescription,"mGroup.mDescription") ;
|
||||
}
|
||||
|
||||
RsItem *RsGxsPostedSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_POSTED)
|
||||
return NULL ;
|
||||
|
||||
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();
|
||||
}
|
||||
void RsGxsPostedGroupItem::clear()
|
||||
{
|
||||
mGroup.mDescription.clear();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user