mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 22:22:45 -04:00
fixed a few bugs in chat serialization
This commit is contained in:
parent
03c31ceacc
commit
ae9d0b2ab4
3 changed files with 43 additions and 28 deletions
|
@ -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));
|
mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id));
|
||||||
|
|
||||||
uint32_t size = obj->serial_size_no_signature() ;
|
uint32_t size = obj->serial_size_for_signature() ;
|
||||||
RsTemporaryMemory memory(size) ;
|
RsTemporaryMemory memory(size) ;
|
||||||
|
|
||||||
#ifdef DEBUG_CHAT_LOBBIES
|
#ifdef DEBUG_CHAT_LOBBIES
|
||||||
|
@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
|
||||||
std::cerr << " signature id: " << obj->signature.keyId << std::endl;
|
std::cerr << " signature id: " << obj->signature.keyId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!obj->serialize_no_signature(memory,size))
|
if(!obj->serialize_for_signature(memory,size))
|
||||||
{
|
{
|
||||||
std::cerr << " (EE) Cannot serialise message item. " << std::endl;
|
std::cerr << " (EE) Cannot serialise message item. " << std::endl;
|
||||||
return false ;
|
return false ;
|
||||||
|
@ -239,7 +239,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
|
||||||
uint32_t error_status ;
|
uint32_t error_status ;
|
||||||
RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ;
|
RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ;
|
||||||
|
|
||||||
if(!mGixs->validateData(memory,obj->serial_size_no_signature(),obj->signature,false,use_info,error_status))
|
if(!mGixs->validateData(memory,obj->serial_size_for_signature(),obj->signature,false,use_info,error_status))
|
||||||
{
|
{
|
||||||
bool res = false ;
|
bool res = false ;
|
||||||
|
|
||||||
|
@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
|
||||||
|
|
||||||
// now sign the object, if the lobby expects it
|
// now sign the object, if the lobby expects it
|
||||||
|
|
||||||
uint32_t size = item.serial_size_no_signature() ;
|
uint32_t size = item.serial_size_for_signature() ;
|
||||||
RsTemporaryMemory memory(size) ;
|
RsTemporaryMemory memory(size) ;
|
||||||
|
|
||||||
if(!item.serialize_no_signature(memory,size))
|
if(!item.serialize_for_signature(memory,size))
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) Cannot sign message item. " << std::endl;
|
std::cerr << "(EE) Cannot sign message item. " << std::endl;
|
||||||
return false ;
|
return false ;
|
||||||
|
|
|
@ -491,12 +491,15 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize
|
||||||
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
{
|
{
|
||||||
RsChatMsgItem::serial_process(j,ctx) ;
|
RsChatMsgItem::serial_process(j,ctx) ;
|
||||||
|
|
||||||
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
|
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
|
||||||
|
|
||||||
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
|
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
|
||||||
}
|
}
|
||||||
|
void RsChatLobbyMsgItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsChatMsgItem::serial_process(j,ctx) ;
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
|
||||||
|
RsChatLobbyBouncingObject::serial_process(j,ctx,false) ;
|
||||||
|
}
|
||||||
#ifdef TO_BE_REMOVED
|
#ifdef TO_BE_REMOVED
|
||||||
/* serialise the data to the buffer */
|
/* serialise the data to the buffer */
|
||||||
bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||||
|
@ -646,7 +649,16 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex
|
||||||
|
|
||||||
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
|
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
|
||||||
}
|
}
|
||||||
|
void RsChatLobbyEventItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::TlvString_proxy tt(string1,TLV_TYPE_STR_NAME) ;
|
||||||
|
|
||||||
|
RsTypeSerializer::serial_process<uint8_t>(j,ctx,event_type,"event_type") ;
|
||||||
|
RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ;
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime ,"sendTime") ;
|
||||||
|
|
||||||
|
RsChatLobbyBouncingObject::serial_process(j,ctx,false) ;
|
||||||
|
}
|
||||||
#ifdef TO_BE_REMOVED
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
|
@ -1400,22 +1412,22 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t RsChatLobbyBouncingObject::serial_size_no_signature() const
|
uint32_t RsChatLobbyBouncingObject::serial_size_for_signature() const
|
||||||
{
|
{
|
||||||
SerializeContext ctx(NULL,0);
|
SerializeContext ctx(NULL,0);
|
||||||
|
|
||||||
ctx.mOffset = 8;
|
ctx.mOffset = 8;
|
||||||
|
|
||||||
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process(RsItem::SERIALIZE,ctx,false) ;
|
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process_for_signature(RsItem::SIZE_ESTIMATE,ctx) ;
|
||||||
|
|
||||||
return ctx.mOffset ;
|
return ctx.mOffset ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t size) const
|
bool RsChatLobbyBouncingObject::serialize_for_signature(uint8_t *data,uint32_t size) const
|
||||||
{
|
{
|
||||||
SerializeContext ctx(data,0);
|
SerializeContext ctx(data,0);
|
||||||
|
|
||||||
uint32_t tlvsize = serial_size_no_signature() ;
|
uint32_t tlvsize = serial_size_for_signature() ;
|
||||||
|
|
||||||
if(tlvsize > size)
|
if(tlvsize > size)
|
||||||
throw std::runtime_error("Cannot serialise: not enough room.") ;
|
throw std::runtime_error("Cannot serialise: not enough room.") ;
|
||||||
|
@ -1428,7 +1440,7 @@ bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t si
|
||||||
ctx.mOffset = 8;
|
ctx.mOffset = 8;
|
||||||
ctx.mSize = tlvsize;
|
ctx.mSize = tlvsize;
|
||||||
|
|
||||||
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process(RsItem::SERIALIZE,ctx,false) ;
|
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process_for_signature(RsItem::SERIALIZE,ctx) ;
|
||||||
|
|
||||||
if(ctx.mSize != ctx.mOffset)
|
if(ctx.mSize != ctx.mOffset)
|
||||||
{
|
{
|
||||||
|
|
|
@ -137,15 +137,16 @@ public:
|
||||||
|
|
||||||
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
|
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
|
||||||
|
|
||||||
uint32_t serial_size_no_signature() const ;
|
uint32_t serial_size_for_signature() const ;
|
||||||
bool serialize_no_signature(uint8_t *data,uint32_t size) const ;
|
bool serialize_for_signature(uint8_t *data,uint32_t size) const ;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// The functions below handle the serialisation of data that is specific to the bouncing object level.
|
// 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
|
// 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.
|
// serialise() methods, otherwise the wrong method will be called when serialising from this top level class.
|
||||||
|
|
||||||
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature);
|
virtual void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature);
|
||||||
|
virtual void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)=0;
|
||||||
|
|
||||||
virtual uint32_t PacketId() const= 0;
|
virtual uint32_t PacketId() const= 0;
|
||||||
};
|
};
|
||||||
|
@ -159,6 +160,7 @@ public:
|
||||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
|
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
|
||||||
|
|
||||||
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ;
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ;
|
||||||
|
void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand
|
||||||
|
|
||||||
ChatLobbyMsgId parent_msg_id ; // Used for threaded chat.
|
ChatLobbyMsgId parent_msg_id ; // Used for threaded chat.
|
||||||
|
|
||||||
|
@ -175,6 +177,7 @@ class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject
|
||||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
|
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
|
||||||
//
|
//
|
||||||
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
|
void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand
|
||||||
|
|
||||||
// members.
|
// members.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue