mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Merge branch 'master' into gxs_mail_experiments
This commit is contained in:
commit
5159e326c7
335 changed files with 12307 additions and 24670 deletions
|
@ -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
|
||||
|
|
|
@ -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 ~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,20 @@ 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
|
||||
struct RsChatSerialiser : RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;}
|
||||
RsChatDHPublicKeyItem(void *data,uint32_t size) ; // deserialization
|
||||
RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) :
|
||||
RsServiceSerializer( RS_SERVICE_TYPE_CHAT,
|
||||
RsGenericSerializer::FORMAT_BINARY, flags ) {}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::map<uint64_t, RsChatMsgItem> store;
|
||||
};
|
||||
|
||||
class RsChatSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsChatSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_CHAT) {}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue