mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-31 18:29:02 -04:00
dwicthed GxsTunnel items to new serialization
This commit is contained in:
parent
1159c863a2
commit
4f92f483fa
4 changed files with 115 additions and 45 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
|
@ -35,6 +36,23 @@
|
|||
|
||||
//#define GXS_TUNNEL_ITEM_DEBUG 1
|
||||
|
||||
RsItem *RsGxsTunnelSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_GXS_TUNNEL)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA: return new RsGxsTunnelDataItem();
|
||||
case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK: return new RsGxsTunnelDataAckItem();
|
||||
case RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY: return new RsGxsTunnelDHPublicKeyItem();
|
||||
case RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS: return new RsGxsTunnelStatusItem();
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent);
|
||||
|
@ -87,12 +105,14 @@ std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent)
|
|||
}
|
||||
|
||||
/*************************************************************************/
|
||||
#endif
|
||||
|
||||
RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem()
|
||||
{
|
||||
BN_free(public_key) ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
|
@ -176,7 +196,54 @@ uint32_t RsGxsTunnelStatusItem::serial_size()
|
|||
return s ;
|
||||
}
|
||||
/*************************************************************************/
|
||||
#endif
|
||||
|
||||
void RsGxsTunnelDHPublicKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,public_key,"public_key") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,gxs_key,"gxs_key") ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM * const & member)
|
||||
{
|
||||
uint32_t s = BN_num_bytes(member) ;
|
||||
|
||||
if(size < offset + 4 + s)
|
||||
return false ;
|
||||
|
||||
bool ok = true ;
|
||||
ok &= setRawUInt32(data, size, &offset, s);
|
||||
|
||||
BN_bn2bin(member,&((unsigned char *)data)[offset]) ;
|
||||
offset += s ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, BIGNUM *& member)
|
||||
{
|
||||
uint32_t s=0 ;
|
||||
bool ok = true ;
|
||||
ok &= getRawUInt32(data, size, &offset, &s);
|
||||
|
||||
if(s > size || size - s < offset)
|
||||
return false ;
|
||||
|
||||
member = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ;
|
||||
offset += s ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
template<> uint32_t RsTypeSerializer::serial_size(BIGNUM * const & member)
|
||||
{
|
||||
return 4 + BN_num_bytes(member) ;
|
||||
}
|
||||
template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM * const & /* member */)
|
||||
{
|
||||
std::cerr << "[BIGNUM] : " << name << std::endl;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
|
@ -211,7 +278,14 @@ bool RsGxsTunnelDHPublicKeyItem::serialise(void *data,uint32_t& pktsize)
|
|||
}
|
||||
return ok ;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,status,"status") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
|
@ -249,7 +323,23 @@ bool RsGxsTunnelStatusItem::serialise(void *data, uint32_t& pktsize)
|
|||
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsGxsTunnelDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<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") ;
|
||||
|
||||
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") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsGxsTunnelDataItem::serialise(void *dt, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
|
@ -489,6 +579,7 @@ RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(
|
|||
|
||||
return item ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue