2017-04-25 15:21:46 -04:00
|
|
|
#include "util/rsprint.h"
|
2013-11-02 10:35:33 -04:00
|
|
|
#include "serialiser/rsbaseserial.h"
|
|
|
|
#include "serialiser/rstlvbase.h"
|
|
|
|
#include "grouteritems.h"
|
|
|
|
|
|
|
|
/**********************************************************************************************/
|
2017-04-25 15:21:46 -04:00
|
|
|
/* SERIALISER STUFF */
|
2013-11-02 10:35:33 -04:00
|
|
|
/**********************************************************************************************/
|
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
RsItem *RsGRouterSerialiser::create_item(uint16_t service_id,uint8_t subtype) const
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2017-04-25 15:21:46 -04:00
|
|
|
if(RS_SERVICE_TYPE_GROUTER != service_id)
|
|
|
|
return NULL; /* wrong type */
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
switch(subtype)
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2017-04-25 15:21:46 -04:00
|
|
|
case RS_PKT_SUBTYPE_GROUTER_DATA: return new RsGRouterGenericDataItem ();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: return new RsGRouterTransactionChunkItem();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: return new RsGRouterTransactionAcknItem ();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_SIGNED_RECEIPT: return new RsGRouterSignedReceiptItem ();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_MATRIX_CLUES: return new RsGRouterMatrixCluesItem ();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK: return new RsGRouterMatrixTrackItem ();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST: return new RsGRouterMatrixFriendListItem();
|
|
|
|
case RS_PKT_SUBTYPE_GROUTER_ROUTING_INFO: return new RsGRouterRoutingInfoItem ();
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2017-04-25 15:21:46 -04:00
|
|
|
RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_start ,"chunk_start") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_size ,"chunk_size") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,total_size ,"total_size") ;
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
// Hack for backward compatibility (the chunk size is not directly next to the chunk data)
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
if(j == RsItem::DESERIALIZE)
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2017-04-25 15:21:46 -04:00
|
|
|
if(chunk_size > ctx.mSize || ctx.mOffset > ctx.mSize - chunk_size) // better than if(chunk_size + offset > size)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
|
|
|
|
ctx.mOk = false ;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if( NULL == (chunk_data = (uint8_t*)rs_malloc(chunk_size)))
|
|
|
|
{
|
|
|
|
ctx.mOk = false ;
|
|
|
|
return ;
|
|
|
|
}
|
2015-10-25 18:07:17 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
memcpy(chunk_data,&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_size) ;
|
|
|
|
ctx.mOffset += chunk_size ;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
else if(j== RsItem::SERIALIZE)
|
|
|
|
{
|
|
|
|
memcpy(&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_data,chunk_size) ;
|
|
|
|
ctx.mOffset += chunk_size ;
|
|
|
|
}
|
|
|
|
else if(j== RsItem::SIZE_ESTIMATE)
|
|
|
|
ctx.mOffset += chunk_size ;
|
|
|
|
else
|
|
|
|
std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl;
|
|
|
|
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#ifdef TO_REMOVE
|
2015-01-15 15:33:24 -05:00
|
|
|
RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionChunkItem(void *data, uint32_t tlvsize) const
|
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
2016-01-11 19:26:54 -05:00
|
|
|
if(tlvsize < rssize)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
2015-01-15 15:33:24 -05:00
|
|
|
RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem() ;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id);
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_start);
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_size);
|
|
|
|
ok &= getRawUInt32(data, tlvsize, &offset, &item->total_size);
|
|
|
|
|
2016-01-11 19:26:54 -05:00
|
|
|
if(item->chunk_size > rssize || offset > rssize - item->chunk_size) // better than if(item->chunk_size + offset > rssize)
|
2015-01-15 15:33:24 -05:00
|
|
|
{
|
2016-01-11 19:26:54 -05:00
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2015-01-15 15:33:24 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
2016-01-12 21:43:04 -05:00
|
|
|
if( NULL == (item->chunk_data = (uint8_t*)rs_malloc(item->chunk_size)))
|
2015-01-15 15:33:24 -05:00
|
|
|
{
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2015-01-15 15:33:24 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(item->chunk_data,&((uint8_t*)data)[offset],item->chunk_size) ;
|
|
|
|
offset += item->chunk_size ;
|
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2015-01-15 15:33:24 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2015-01-15 15:33:24 -05:00
|
|
|
return item;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterTransactionAcknItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TO_REMOVE
|
2015-01-19 08:53:36 -05:00
|
|
|
RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionAcknItem(void *data, uint32_t tlvsize) const
|
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
|
|
|
RsGRouterTransactionAcknItem *item = new RsGRouterTransactionAcknItem() ;
|
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id);
|
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2015-01-19 08:53:36 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process<uint64_t>(j,ctx,routing_id,"routing_id") ;
|
|
|
|
RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,service_id,"service_id") ;
|
|
|
|
|
|
|
|
RsTypeSerializer::TlvMemBlock_proxy prox(data_bytes,data_size) ;
|
|
|
|
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,prox,"data") ;
|
|
|
|
|
|
|
|
if(ctx.mFlags & RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,duplication_factor,"duplication_factor") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
|
|
|
|
|
|
|
|
if(j == RsItem::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more.
|
|
|
|
{
|
|
|
|
if(duplication_factor < 1)
|
|
|
|
{
|
|
|
|
duplication_factor = 1 ;
|
|
|
|
std::cerr << "(II) correcting GRouter item duplication factor from 0 to 1, to ensure backward compat." << std::endl;
|
|
|
|
}
|
|
|
|
if(duplication_factor > GROUTER_MAX_DUPLICATION_FACTOR)
|
|
|
|
{
|
|
|
|
std::cerr << "(WW) correcting GRouter item duplication factor of " << duplication_factor << ". This is very unexpected." << std::endl;
|
|
|
|
duplication_factor = GROUTER_MAX_DUPLICATION_FACTOR ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TO_REMOVE
|
2014-03-29 10:18:05 -04:00
|
|
|
RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2013-12-23 11:05:46 -05:00
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
2016-01-11 19:26:54 -05:00
|
|
|
if(pktsize < rssize)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2013-12-23 11:05:46 -05:00
|
|
|
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ;
|
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
|
|
|
|
ok &= item->destination_key.deserialise(data, pktsize, offset) ;
|
2016-01-11 19:26:54 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->service_id);
|
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->data_size);
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2016-01-30 20:27:56 -05:00
|
|
|
if(item->data_size > 0) // This happens when the item data has been deleted from the cache
|
2013-12-23 11:05:46 -05:00
|
|
|
{
|
2016-01-30 20:27:56 -05:00
|
|
|
if(item->data_size > rssize || offset > rssize - item->data_size) // better than if(item->data_size + offset > rssize)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl;
|
|
|
|
delete item;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NULL == (item->data_bytes = (uint8_t*)rs_malloc(item->data_size)))
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ;
|
|
|
|
offset += item->data_size ;
|
2016-01-11 19:26:54 -05:00
|
|
|
}
|
2016-01-30 20:27:56 -05:00
|
|
|
else
|
|
|
|
item->data_bytes = NULL ;
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2016-01-11 19:26:54 -05:00
|
|
|
ok &= item->signature.GetTlv(data, pktsize, &offset) ;
|
2015-01-11 17:18:28 -05:00
|
|
|
|
2016-01-30 20:27:56 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->duplication_factor);
|
|
|
|
|
|
|
|
// make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more.
|
|
|
|
|
|
|
|
if(item->duplication_factor < 1)
|
|
|
|
{
|
|
|
|
item->duplication_factor = 1 ;
|
|
|
|
std::cerr << "(II) correcting GRouter item duplication factor from 0 to 1, to ensure backward compat." << std::endl;
|
|
|
|
}
|
|
|
|
if(item->duplication_factor > GROUTER_MAX_DUPLICATION_FACTOR)
|
|
|
|
{
|
|
|
|
std::cerr << "(WW) correcting GRouter item duplication factor of " << item->duplication_factor << ". This is very unexpected." << std::endl;
|
|
|
|
item->duplication_factor = GROUTER_MAX_DUPLICATION_FACTOR ;
|
|
|
|
}
|
|
|
|
|
2016-01-11 19:26:54 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->flags);
|
2015-01-11 17:18:28 -05:00
|
|
|
|
2016-01-11 19:26:54 -05:00
|
|
|
if (offset != rssize || !ok)
|
2013-12-23 11:05:46 -05:00
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2013-12-23 11:05:46 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterSignedReceiptItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process<uint64_t> (j,ctx,routing_id,"routing_id") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
|
|
|
RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t> (j,ctx,service_id,"service_id") ;
|
|
|
|
RsTypeSerializer::serial_process (j,ctx,data_hash,"data_hash") ;
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
if(ctx.mFlags & RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TO_REMOVE
|
2015-01-19 08:53:36 -05:00
|
|
|
RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedReceiptItem(void *data, uint32_t pktsize) const
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2013-12-23 11:05:46 -05:00
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
2015-01-19 08:53:36 -05:00
|
|
|
RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem() ;
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2015-01-19 08:53:36 -05:00
|
|
|
ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id);
|
2015-01-20 08:04:10 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->flags);
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= item->destination_key.deserialise(data, pktsize, offset);
|
2015-04-09 17:34:50 -04:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->service_id);
|
2015-01-20 08:04:10 -05:00
|
|
|
ok &= item->data_hash.deserialise(data, pktsize, offset);
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= item->signature.GetTlv(data, pktsize, &offset); // signature
|
2013-12-23 11:05:46 -05:00
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2013-12-23 11:05:46 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2013-12-23 11:05:46 -05:00
|
|
|
return item;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,data_status,"data_status") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_status,"tunnel_status") ;
|
|
|
|
RsTypeSerializer::serial_process<time_t> (j,ctx,received_time_TS,"received_time_TS") ;
|
|
|
|
RsTypeSerializer::serial_process<time_t> (j,ctx,last_sent_TS,"last_sent_TS") ;
|
|
|
|
|
|
|
|
RsTypeSerializer::serial_process<time_t> (j,ctx,last_tunnel_request_TS,"last_tunnel_request_TS") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sending_attempts,"sending_attempts") ;
|
|
|
|
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,client_id,"client_id") ;
|
|
|
|
RsTypeSerializer::serial_process (j,ctx,item_hash,"item_hash") ;
|
|
|
|
RsTypeSerializer::serial_process (j,ctx,tunnel_hash,"tunnel_hash") ;
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,routing_flags,"routing_flags") ;
|
|
|
|
|
|
|
|
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,incoming_routes,"incoming_routes") ;
|
|
|
|
|
|
|
|
// Hack for backward compatibility. Normally we should need a single commandline to serialise/deserialise a single item here.
|
|
|
|
// But the full item is serialised, so we need the header.
|
|
|
|
|
|
|
|
if(j == RsItem::DESERIALIZE)
|
|
|
|
{
|
|
|
|
data_item = new RsGRouterGenericDataItem() ;
|
|
|
|
|
|
|
|
ctx.mOffset += 8 ;
|
|
|
|
data_item->serial_process(j,ctx) ;
|
|
|
|
|
|
|
|
if(ctx.mOffset < ctx.mSize)
|
|
|
|
{
|
|
|
|
receipt_item = new RsGRouterSignedReceiptItem();
|
|
|
|
|
|
|
|
ctx.mOffset += 8 ;
|
|
|
|
receipt_item->serial_process(j,ctx) ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
receipt_item = NULL ;
|
|
|
|
}
|
|
|
|
else if(j == RsItem::SERIALIZE)
|
|
|
|
{
|
|
|
|
uint32_t remaining_size = ctx.mSize - ctx.mOffset;
|
|
|
|
ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size) ;
|
|
|
|
ctx.mOffset += RsGRouterSerialiser().size(data_item) ;
|
|
|
|
|
|
|
|
if(receipt_item != NULL)
|
|
|
|
{
|
|
|
|
remaining_size = ctx.mSize - ctx.mOffset;
|
|
|
|
ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size);
|
|
|
|
ctx.mOffset += RsGRouterSerialiser().size(data_item) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(j == RsItem::PRINT)
|
|
|
|
{
|
|
|
|
std::cerr << " [Serialized data] " << std::endl;
|
|
|
|
|
|
|
|
if(receipt_item != NULL)
|
|
|
|
std::cerr << " [Receipt item ]" << std::endl;
|
|
|
|
}
|
|
|
|
else if(j == RsItem::SIZE_ESTIMATE)
|
|
|
|
{
|
|
|
|
ctx.mOffset += RsGRouterSerialiser().size(data_item) ;
|
|
|
|
|
|
|
|
if(receipt_item != NULL)
|
|
|
|
ctx.mOffset += RsGRouterSerialiser().size(receipt_item) ;
|
|
|
|
}
|
|
|
|
}
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
#ifdef TO_REMOVE
|
2014-03-29 10:18:05 -04:00
|
|
|
RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *data, uint32_t pktsize) const
|
2013-12-27 15:06:47 -05:00
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
|
|
|
RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ;
|
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
RsPeerId peer_id ;
|
|
|
|
ok &= peer_id.deserialise(data, pktsize, offset) ;
|
|
|
|
item->PeerId(peer_id) ;
|
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->data_status);
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->tunnel_status);
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= getRawTimeT(data, pktsize, &offset, item->received_time_TS);
|
2015-04-20 17:24:22 -04:00
|
|
|
ok &= getRawTimeT(data, pktsize, &offset, item->last_sent_TS);
|
2015-01-22 09:33:19 -05:00
|
|
|
|
|
|
|
ok &= getRawTimeT(data, pktsize, &offset, item->last_tunnel_request_TS);
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->sending_attempts);
|
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->client_id);
|
2015-04-18 15:59:27 -04:00
|
|
|
ok &= item->item_hash.deserialise(data, pktsize, offset) ;
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= item->tunnel_hash.deserialise(data, pktsize, offset) ;
|
2015-04-12 17:43:52 -04:00
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &item->routing_flags) ;
|
|
|
|
|
|
|
|
ok &= item->incoming_routes.GetTlv(data,pktsize,&offset) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ;
|
2014-04-21 08:39:30 -04:00
|
|
|
if(item->data_item != NULL)
|
|
|
|
offset += item->data_item->serial_size() ;
|
|
|
|
else
|
|
|
|
ok = false ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2016-10-22 17:48:19 -04:00
|
|
|
// Receipt item is optional.
|
|
|
|
|
|
|
|
if (offset < pktsize)
|
|
|
|
{ //
|
|
|
|
item->receipt_item = deserialise_RsGRouterSignedReceiptItem(&((uint8_t*)data)[offset],pktsize - offset);
|
|
|
|
if (item->receipt_item != NULL)
|
|
|
|
offset += item->receipt_item->serial_size();
|
|
|
|
else //
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
else //
|
|
|
|
item->receipt_item = NULL;
|
2015-01-22 09:33:19 -05:00
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
|
2014-04-21 09:08:42 -04:00
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2013-12-27 15:06:47 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterMatrixFriendListItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TO_REMOVE
|
2014-03-29 10:18:05 -04:00
|
|
|
RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(void *data, uint32_t pktsize) const
|
2013-12-27 15:06:47 -05:00
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
|
|
|
RsGRouterMatrixFriendListItem *item = new RsGRouterMatrixFriendListItem() ;
|
|
|
|
|
|
|
|
uint32_t nb_friends = 0 ;
|
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &nb_friends); // file hash
|
|
|
|
|
2015-04-12 17:43:52 -04:00
|
|
|
item->reverse_friend_indices.resize(nb_friends) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
for(uint32_t i=0;ok && i<nb_friends;++i)
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->reverse_friend_indices[i].deserialise(data, pktsize, offset) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2013-12-27 15:06:47 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterMatrixTrackItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ;
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ;
|
|
|
|
RsTypeSerializer::serial_process<time_t>(j,ctx,time_stamp,"time_stamp") ;
|
|
|
|
}
|
2015-10-25 18:07:17 -04:00
|
|
|
|
2017-04-25 15:21:46 -04:00
|
|
|
#ifdef TO_REMOVE
|
2015-10-25 18:07:17 -04:00
|
|
|
RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackItem(void *data, uint32_t pktsize) const
|
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
|
|
|
RsGRouterMatrixTrackItem *item = new RsGRouterMatrixTrackItem() ;
|
|
|
|
|
2015-10-26 23:38:10 -04:00
|
|
|
ok &= item->provider_id.deserialise(data, pktsize, offset) ;
|
2015-10-25 18:07:17 -04:00
|
|
|
ok &= item->message_id.deserialise(data,pktsize,offset) ;
|
|
|
|
ok &= getRawTimeT(data, pktsize, &offset, item->time_stamp) ;
|
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
|
|
|
delete item;
|
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void RsGRouterMatrixCluesItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ;
|
|
|
|
RsTypeSerializer::serial_process(j,ctx,clues,"clues") ;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name)
|
|
|
|
{
|
|
|
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s.friend_id,name+":friend_id") ;
|
|
|
|
RsTypeSerializer::serial_process<float> (j,ctx,s.weight,name+":weight") ;
|
|
|
|
RsTypeSerializer::serial_process<time_t> (j,ctx,s.time_stamp,name+":time_stamp") ;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TO_REMOVE
|
2014-03-29 10:18:05 -04:00
|
|
|
RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const
|
2013-12-27 15:06:47 -05:00
|
|
|
{
|
|
|
|
uint32_t offset = 8; // skip the header
|
|
|
|
uint32_t rssize = getRsItemSize(data);
|
|
|
|
bool ok = true ;
|
|
|
|
|
|
|
|
RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem() ;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= item->destination_key.deserialise(data,pktsize,offset) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
uint32_t nb_clues = 0 ;
|
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &nb_clues);
|
|
|
|
|
|
|
|
item->clues.clear() ;
|
|
|
|
|
|
|
|
for(uint32_t j=0;j<nb_clues;++j)
|
|
|
|
{
|
|
|
|
RoutingMatrixHitEntry HitE ;
|
|
|
|
|
|
|
|
ok &= getRawUInt32(data, pktsize, &offset, &HitE.friend_id);
|
|
|
|
ok &= getRawUFloat32(data, pktsize, &offset, HitE.weight);
|
|
|
|
ok &= getRawTimeT(data, pktsize, &offset, HitE.time_stamp);
|
|
|
|
|
|
|
|
item->clues.push_back(HitE) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != rssize || !ok)
|
|
|
|
{
|
|
|
|
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
2015-03-28 13:23:52 -04:00
|
|
|
delete item;
|
2013-12-27 15:06:47 -05:00
|
|
|
return NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|
|
|
|
|
2013-12-22 12:04:13 -05:00
|
|
|
RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
|
|
|
|
{
|
2015-01-22 09:33:19 -05:00
|
|
|
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2015-01-22 09:33:19 -05:00
|
|
|
// copy all members
|
2013-12-22 12:04:13 -05:00
|
|
|
|
2015-01-22 09:33:19 -05:00
|
|
|
*item = *this ;
|
2013-12-22 12:04:13 -05:00
|
|
|
|
2015-01-22 09:33:19 -05:00
|
|
|
// then duplicate the memory chunk
|
2013-12-22 12:04:13 -05:00
|
|
|
|
2016-01-13 00:13:16 -05:00
|
|
|
if(data_size > 0)
|
|
|
|
{
|
|
|
|
item->data_bytes = (uint8_t*)rs_malloc(data_size) ;
|
2016-01-13 12:22:55 -05:00
|
|
|
|
|
|
|
if(item->data_bytes == NULL)
|
|
|
|
{
|
|
|
|
delete item ;
|
|
|
|
return NULL ;
|
|
|
|
}
|
2016-01-13 00:13:16 -05:00
|
|
|
memcpy(item->data_bytes,data_bytes,data_size) ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
item->data_bytes = NULL ;
|
2015-01-11 17:18:28 -05:00
|
|
|
|
2015-01-22 09:33:19 -05:00
|
|
|
return item ;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const
|
|
|
|
{
|
|
|
|
RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem ;
|
|
|
|
|
|
|
|
// copy all members
|
|
|
|
|
|
|
|
*item = *this ;
|
2013-12-22 12:04:13 -05:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
return item ;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
|
|
|
|
#ifdef TO_REMOVE
|
2013-11-02 10:35:33 -04:00
|
|
|
uint32_t RsGRouterGenericDataItem::serial_size() const
|
|
|
|
{
|
2015-01-11 17:18:28 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += sizeof(GRouterMsgPropagationId) ; // routing id
|
|
|
|
s += destination_key.serial_size() ; // destination_key
|
|
|
|
s += 4 ; // data_size
|
2015-04-09 17:34:50 -04:00
|
|
|
s += 4 ; // service id
|
2015-01-11 17:18:28 -05:00
|
|
|
s += data_size ; // data
|
|
|
|
s += signature.TlvSize() ; // signature
|
2016-01-30 20:27:56 -05:00
|
|
|
s += 4 ; // duplication_factor
|
2015-01-11 17:18:28 -05:00
|
|
|
s += 4 ; // flags
|
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
uint32_t RsGRouterGenericDataItem::signed_data_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 0 ; // no header
|
|
|
|
s += sizeof(GRouterMsgPropagationId) ; // routing id
|
|
|
|
s += destination_key.serial_size() ; // destination_key
|
|
|
|
s += 4 ; // data_size
|
2015-04-09 17:34:50 -04:00
|
|
|
s += 4 ; // service id
|
2015-01-11 17:18:28 -05:00
|
|
|
s += data_size ; // data
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
return s ;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2015-01-19 08:53:36 -05:00
|
|
|
uint32_t RsGRouterSignedReceiptItem::serial_size() const
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2015-01-20 08:04:10 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += sizeof(GRouterMsgPropagationId) ; // routing id
|
|
|
|
s += destination_key.serial_size() ; // destination_key
|
|
|
|
s += data_hash.serial_size() ;
|
2015-01-11 17:18:28 -05:00
|
|
|
s += 4 ; // state
|
2015-04-09 17:34:50 -04:00
|
|
|
s += 4 ; // service_id
|
2015-01-11 17:18:28 -05:00
|
|
|
s += signature.TlvSize() ; // signature
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2015-01-20 08:04:10 -05:00
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
uint32_t RsGRouterSignedReceiptItem::signed_data_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 0 ; // no header
|
|
|
|
s += sizeof(GRouterMsgPropagationId) ; // routing id
|
|
|
|
s += destination_key.serial_size() ; // destination_key
|
|
|
|
s += data_hash.serial_size() ;
|
2015-04-09 17:34:50 -04:00
|
|
|
s += 4 ; // service_id
|
2015-01-20 08:04:10 -05:00
|
|
|
s += 4 ; // state
|
|
|
|
|
|
|
|
return s ;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2015-01-15 15:33:24 -05:00
|
|
|
uint32_t RsGRouterTransactionChunkItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += sizeof(GRouterMsgPropagationId) ; // routing id
|
|
|
|
s += 4 ; // chunk_start
|
|
|
|
s += 4 ; // chunk_size
|
|
|
|
s += 4 ; // total_size
|
|
|
|
s += chunk_size ; // data
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2015-01-19 08:53:36 -05:00
|
|
|
uint32_t RsGRouterTransactionAcknItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += sizeof(GRouterMsgPropagationId) ; // routing id
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2015-01-15 15:33:24 -05:00
|
|
|
bool RsGRouterTransactionChunkItem::serialise(void *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 &= setRawUInt64(data, tlvsize, &offset, propagation_id);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, chunk_start);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, chunk_size);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, total_size);
|
|
|
|
|
|
|
|
memcpy(&((uint8_t*)data)[offset],chunk_data,chunk_size) ;
|
|
|
|
offset += chunk_size ;
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2013-11-02 10:35:33 -04:00
|
|
|
bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
|
|
|
|
{
|
2015-01-11 17:18:28 -05:00
|
|
|
uint32_t tlvsize,offset=0;
|
|
|
|
bool ok = true;
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
if(!serialise_header(data,size,tlvsize,offset))
|
|
|
|
return false ;
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
|
|
|
|
ok &= destination_key.serialise(data, tlvsize, offset) ;
|
2015-04-09 17:34:50 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
|
2013-12-23 11:05:46 -05:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
|
|
|
|
offset += data_size ;
|
|
|
|
|
|
|
|
ok &= signature.SetTlv(data, tlvsize, &offset) ;
|
|
|
|
|
2016-01-30 20:27:56 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, duplication_factor) ;
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags) ;
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2014-11-13 17:27:01 -05:00
|
|
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
2015-01-11 17:18:28 -05:00
|
|
|
}
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
return ok;
|
|
|
|
}
|
2015-01-19 08:53:36 -05:00
|
|
|
bool RsGRouterTransactionAcknItem::serialise(void *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 &= setRawUInt64(data, tlvsize, &offset, propagation_id);
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2016-06-02 20:23:22 -04:00
|
|
|
bool RsGRouterGenericDataItem::serialise_signed_data(void *data,uint32_t size) const
|
2015-01-11 17:18:28 -05:00
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uint32_t tlvsize = signed_data_size() ;
|
2016-06-02 20:23:22 -04:00
|
|
|
|
|
|
|
if(tlvsize > size)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl;
|
|
|
|
}
|
2015-01-11 17:18:28 -05:00
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
|
|
|
|
ok &= destination_key.serialise(data, tlvsize, offset) ;
|
2015-04-09 17:34:50 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
|
|
|
|
|
|
|
|
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
|
|
|
|
offset += data_size ;
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2015-01-19 08:53:36 -05:00
|
|
|
bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2013-12-23 11:05:46 -05:00
|
|
|
uint32_t tlvsize,offset=0;
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if(!serialise_header(data,size,tlvsize,offset))
|
|
|
|
return false ;
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2013-12-23 11:05:46 -05:00
|
|
|
/* add mandatory parts first */
|
2015-01-19 08:53:36 -05:00
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
|
2015-01-20 08:04:10 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= destination_key.serialise(data,tlvsize,offset) ;
|
2015-04-09 17:34:50 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
2015-01-20 08:04:10 -05:00
|
|
|
ok &= data_hash.serialise(data,tlvsize,offset) ;
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= signature.SetTlv(data,tlvsize,&offset) ;
|
2013-12-23 11:05:46 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2015-01-11 17:18:28 -05:00
|
|
|
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl;
|
2013-12-23 11:05:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
2016-06-02 20:23:22 -04:00
|
|
|
bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t size) const
|
2015-01-20 08:04:10 -05:00
|
|
|
{
|
|
|
|
bool ok = true;
|
2013-11-02 10:35:33 -04:00
|
|
|
|
2015-01-20 08:04:10 -05:00
|
|
|
uint32_t offset=0;
|
|
|
|
uint32_t tlvsize = signed_data_size() ;
|
2016-06-02 20:23:22 -04:00
|
|
|
|
|
|
|
if(tlvsize > size)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl;
|
|
|
|
}
|
2015-01-20 08:04:10 -05:00
|
|
|
|
|
|
|
/* add mandatory parts first */
|
|
|
|
ok &= setRawUInt64(data, tlvsize, &offset, routing_id);
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
|
|
|
ok &= destination_key.serialise(data,tlvsize,offset) ;
|
2015-04-09 17:34:50 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
2015-01-20 08:04:10 -05:00
|
|
|
ok &= data_hash.serialise(data,tlvsize,offset) ;
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2013-12-27 15:06:47 -05:00
|
|
|
/* serialise the data to the buffer */
|
|
|
|
uint32_t RsGRouterMatrixCluesItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
s += destination_key.serial_size() ; // Key size
|
2013-12-27 15:06:47 -05:00
|
|
|
s += 4 ; // list<RoutingMatrixHitEntry>::size()
|
|
|
|
s += (4+4+8) * clues.size() ;
|
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
uint32_t RsGRouterMatrixFriendListItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += 4 ; // reverse_friend_indices.size()
|
2014-05-09 17:44:52 -04:00
|
|
|
s += RsPeerId::SIZE_IN_BYTES * reverse_friend_indices.size() ; // sha1 for published_key
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
2015-10-25 18:07:17 -04:00
|
|
|
|
|
|
|
uint32_t RsGRouterMatrixTrackItem::serial_size() const
|
|
|
|
{
|
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += 8 ; // time_stamp
|
|
|
|
s += RsPeerId::SIZE_IN_BYTES; // provider_id
|
|
|
|
s += RsMessageId::SIZE_IN_BYTES; // message_id
|
|
|
|
|
|
|
|
return s ;
|
|
|
|
}
|
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
uint32_t RsGRouterRoutingInfoItem::serial_size() const
|
|
|
|
{
|
2015-01-22 04:50:44 -05:00
|
|
|
uint32_t s = 8 ; // header
|
|
|
|
s += PeerId().serial_size() ;
|
2015-01-22 09:33:19 -05:00
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
s += 4 ; // data status_flags
|
|
|
|
s += 4 ; // tunnel status_flags
|
|
|
|
s += 8 ; // received_time
|
2015-04-20 17:24:22 -04:00
|
|
|
s += 8 ; // last_sent_TS
|
2015-01-22 09:33:19 -05:00
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
s += 8 ; // last_TR_TS
|
|
|
|
s += 4 ; // sending attempts
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
s += sizeof(GRouterServiceId) ; // service_id
|
|
|
|
s += tunnel_hash.serial_size() ;
|
2015-04-18 15:59:27 -04:00
|
|
|
s += item_hash.serial_size() ;
|
2015-01-22 04:50:44 -05:00
|
|
|
|
2015-04-12 17:43:52 -04:00
|
|
|
s += 4 ; // routing_flags
|
|
|
|
s += incoming_routes.TlvSize() ; // incoming_routes
|
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
s += data_item->serial_size(); // data_item
|
2015-01-22 09:33:19 -05:00
|
|
|
|
|
|
|
if(receipt_item != NULL)
|
|
|
|
s += receipt_item->serial_size(); // receipt_item
|
2015-01-22 04:50:44 -05:00
|
|
|
|
|
|
|
return s ;
|
2013-12-27 15:06:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGRouterMatrixFriendListItem::serialise(void *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, reverse_friend_indices.size());
|
|
|
|
|
|
|
|
for(uint32_t i=0;ok && i<reverse_friend_indices.size();++i)
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= reverse_friend_indices[i].serialise(data,tlvsize,offset) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2014-11-13 17:27:01 -05:00
|
|
|
std::cerr << "RsGRouterMatrixFriendListItem::serialisedata() size error! " << std::endl;
|
2013-12-27 15:06:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
bool RsGRouterMatrixCluesItem::serialise(void *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 */
|
2014-03-17 16:56:06 -04:00
|
|
|
ok &= destination_key.serialise(data,tlvsize,offset) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, clues.size());
|
|
|
|
|
|
|
|
for(std::list<RoutingMatrixHitEntry>::const_iterator it2(clues.begin());it2!=clues.end();++it2)
|
|
|
|
{
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, (*it2).friend_id) ;
|
|
|
|
ok &= setRawUFloat32(data, tlvsize, &offset, (*it2).weight) ;
|
|
|
|
ok &= setRawTimeT(data, tlvsize, &offset, (*it2).time_stamp) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2014-11-13 17:27:01 -05:00
|
|
|
std::cerr << "RsGRouterMatrixCluesItem::serialisedata() size error! " << std::endl;
|
2013-12-27 15:06:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2014-03-29 10:18:05 -04:00
|
|
|
|
2015-10-25 18:07:17 -04:00
|
|
|
bool RsGRouterMatrixTrackItem::serialise(void *data,uint32_t& size) const
|
|
|
|
{
|
|
|
|
uint32_t tlvsize,offset=0;
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if(!serialise_header(data,size,tlvsize,offset))
|
|
|
|
return false ;
|
|
|
|
|
2015-10-26 23:38:10 -04:00
|
|
|
ok &= provider_id.serialise(data, tlvsize, offset) ;
|
2015-10-25 18:07:17 -04:00
|
|
|
ok &= message_id.serialise(data,tlvsize,offset) ;
|
|
|
|
ok &= setRawTimeT(data, tlvsize, &offset, time_stamp) ;
|
|
|
|
|
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cerr << "RsGRouterMatrixTrackItem::serialisedata() size error! " << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
2014-03-29 10:18:05 -04:00
|
|
|
bool FriendTrialRecord::deserialise(void *data,uint32_t& offset,uint32_t size)
|
|
|
|
{
|
|
|
|
bool ok = true ;
|
|
|
|
ok &= friend_id.deserialise(data, size, offset) ;
|
|
|
|
ok &= getRawTimeT(data, size, &offset, time_stamp) ;
|
|
|
|
ok &= getRawUFloat32(data, size, &offset, probability) ;
|
|
|
|
ok &= getRawUInt32(data, size, &offset, &nb_friends) ;
|
|
|
|
return ok ;
|
|
|
|
}
|
|
|
|
bool FriendTrialRecord::serialise(void *data,uint32_t& offset,uint32_t size) const
|
|
|
|
{
|
|
|
|
bool ok = true ;
|
|
|
|
ok &= friend_id.serialise(data, size, offset) ;
|
|
|
|
ok &= setRawTimeT(data, size, &offset, time_stamp) ;
|
|
|
|
ok &= setRawUFloat32(data, size, &offset, probability) ;
|
|
|
|
ok &= setRawUInt32(data, size, &offset, nb_friends) ;
|
|
|
|
return ok ;
|
|
|
|
}
|
2013-12-27 15:06:47 -05:00
|
|
|
bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
uint32_t tlvsize,offset=0;
|
|
|
|
bool ok = true;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if(!serialise_header(data,size,tlvsize,offset))
|
|
|
|
return false ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= PeerId().serialise(data, tlvsize, offset) ; // we keep this.
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, data_status) ;
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, tunnel_status) ;
|
2015-01-11 17:18:28 -05:00
|
|
|
ok &= setRawTimeT(data, tlvsize, &offset, received_time_TS) ;
|
2015-04-20 17:24:22 -04:00
|
|
|
ok &= setRawTimeT(data, tlvsize, &offset, last_sent_TS) ;
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= setRawTimeT(data, tlvsize, &offset, last_tunnel_request_TS) ;
|
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, sending_attempts) ;
|
|
|
|
|
2014-04-21 08:39:30 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, client_id) ;
|
2015-04-18 15:59:27 -04:00
|
|
|
ok &= item_hash.serialise(data, tlvsize, offset) ;
|
2015-01-22 04:50:44 -05:00
|
|
|
ok &= tunnel_hash.serialise(data, tlvsize, offset) ;
|
2015-04-12 17:43:52 -04:00
|
|
|
ok &= setRawUInt32(data, tlvsize, &offset, routing_flags) ;
|
|
|
|
|
|
|
|
ok &= incoming_routes.SetTlv(data,tlvsize,&offset) ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
2015-01-11 17:18:28 -05:00
|
|
|
uint32_t ns = size - offset ;
|
|
|
|
ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ;
|
2015-01-22 04:50:44 -05:00
|
|
|
offset += data_item->serial_size() ;
|
|
|
|
|
|
|
|
if(receipt_item != NULL)
|
|
|
|
{
|
|
|
|
uint32_t ns = size - offset ;
|
|
|
|
ok &= receipt_item->serialise( &((uint8_t*)data)[offset], ns) ;
|
|
|
|
offset += receipt_item->serial_size() ;
|
|
|
|
}
|
2014-03-17 16:56:06 -04:00
|
|
|
if (offset != tlvsize)
|
|
|
|
{
|
|
|
|
ok = false;
|
2014-11-13 17:27:01 -05:00
|
|
|
std::cerr << "RsGRouterRoutingInfoItem::serialisedata() size error! " << std::endl;
|
2014-03-17 16:56:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2013-12-27 15:06:47 -05:00
|
|
|
}
|
|
|
|
|
2013-11-02 10:35:33 -04:00
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
// ------------------------------------- IO --------------------------------------- //
|
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
//
|
2015-10-25 18:07:17 -04:00
|
|
|
|
2015-01-19 08:53:36 -05:00
|
|
|
std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t)
|
2013-11-02 10:35:33 -04:00
|
|
|
{
|
2015-01-11 17:18:28 -05:00
|
|
|
o << "RsGRouterReceiptItem:" << std::endl ;
|
|
|
|
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
|
2015-01-22 04:50:44 -05:00
|
|
|
o << " Mid: " << std::hex << routing_id << std::dec << std::endl ;
|
2015-01-20 08:04:10 -05:00
|
|
|
o << " State: " << flags << std::endl ;
|
2015-01-11 17:18:28 -05:00
|
|
|
o << " Dest: " << destination_key << std::endl ;
|
|
|
|
o << " Sign: " << signature.keyId << std::endl ;
|
|
|
|
|
|
|
|
return o ;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
|
|
|
std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
2015-01-11 17:18:28 -05:00
|
|
|
o << "RsGRouterGenericDataItem:" << std::endl ;
|
|
|
|
o << " Direct origin: \""<< PeerId() << "\"" << std::endl ;
|
|
|
|
o << " Routing ID: " << std::hex << routing_id << std::dec << "\"" << std::endl ;
|
|
|
|
o << " Key: " << destination_key.toStdString() << std::endl ;
|
|
|
|
o << " Data size: " << data_size << std::endl ;
|
|
|
|
o << " Data hash: " << RsDirUtil::sha1sum(data_bytes,data_size) << std::endl ;
|
|
|
|
o << " signature key: " << signature.keyId << std::endl;
|
2016-01-30 20:27:56 -05:00
|
|
|
o << " duplication fac:" << duplication_factor << std::endl;
|
2015-01-11 17:18:28 -05:00
|
|
|
o << " flags: " << flags << std::endl;
|
|
|
|
|
|
|
|
return o ;
|
2013-11-02 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
2013-12-27 15:06:47 -05:00
|
|
|
std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
2015-01-22 04:50:44 -05:00
|
|
|
o << "RsGRouterRoutingInfoItem:" << std::endl ;
|
|
|
|
o << " direct origin: "<< PeerId() << std::endl ;
|
|
|
|
o << " data status: "<< std::hex<< data_status << std::dec << std::endl ;
|
|
|
|
o << " tunnel status: "<< tunnel_status << std::endl ;
|
|
|
|
o << " recv time: "<< received_time_TS << std::endl ;
|
2015-04-20 17:24:22 -04:00
|
|
|
o << " Last sent: "<< last_sent_TS << std::endl ;
|
2015-01-22 04:50:44 -05:00
|
|
|
o << " Sending attempts:"<< sending_attempts << std::endl ;
|
|
|
|
o << " destination key: "<< data_item->destination_key << std::endl ;
|
|
|
|
o << " Client id: "<< client_id << std::endl ;
|
2015-04-18 15:59:27 -04:00
|
|
|
o << " item hash: "<< item_hash << std::endl ;
|
2015-01-22 04:50:44 -05:00
|
|
|
o << " tunnel hash: "<< tunnel_hash << std::endl ;
|
|
|
|
o << " Data size: "<< data_item->data_size << std::endl ;
|
|
|
|
o << " Signed receipt: "<< (void*)receipt_item << std::endl ;
|
2013-12-27 15:06:47 -05:00
|
|
|
|
|
|
|
return o ;
|
|
|
|
}
|
|
|
|
|
2015-10-25 18:07:17 -04:00
|
|
|
std::ostream& RsGRouterMatrixTrackItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
|
|
|
o << "RsGRouterMatrixTrackItem:" << std::endl ;
|
|
|
|
o << " provider_id: " << provider_id << std::endl;
|
|
|
|
o << " message_id: " << message_id << std::endl;
|
|
|
|
o << " time_stamp: " << time_stamp << std::endl;
|
|
|
|
|
|
|
|
return o ;
|
|
|
|
}
|
2013-12-27 15:06:47 -05:00
|
|
|
std::ostream& RsGRouterMatrixCluesItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
|
|
|
o << "RsGRouterMatrixCluesItem:" << std::endl ;
|
|
|
|
o << " destination k: " << destination_key.toStdString() << std::endl;
|
|
|
|
o << " routing clues: " << clues.size() << std::endl;
|
|
|
|
|
|
|
|
for(std::list<RoutingMatrixHitEntry>::const_iterator it(clues.begin());it!=clues.end();++it)
|
|
|
|
o << " " << (*it).friend_id << " " << (*it).time_stamp << " " << (*it).weight << std::endl;
|
|
|
|
|
|
|
|
return o ;
|
|
|
|
}
|
2015-01-15 15:33:24 -05:00
|
|
|
std::ostream& RsGRouterTransactionChunkItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
|
|
|
o << "RsGRouterTransactionChunkItem:" << std::endl ;
|
|
|
|
o << " total_size: " << total_size << std::endl;
|
|
|
|
o << " chunk_size: " << chunk_size << std::endl;
|
|
|
|
o << " chunk_start: " << chunk_start << std::endl;
|
|
|
|
|
|
|
|
return o ;
|
|
|
|
}
|
2015-01-19 08:53:36 -05:00
|
|
|
std::ostream& RsGRouterTransactionAcknItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
|
|
|
o << "RsGRouterTransactionAcknItem:" << std::endl ;
|
|
|
|
o << " routing id: " << propagation_id << std::endl;
|
|
|
|
|
|
|
|
return o ;
|
|
|
|
}
|
2013-12-27 15:06:47 -05:00
|
|
|
std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t)
|
|
|
|
{
|
|
|
|
o << "RsGRouterMatrixCluesItem:" << std::endl ;
|
|
|
|
o << " friends: " << reverse_friend_indices.size() << std::endl;
|
|
|
|
|
|
|
|
return o ;
|
|
|
|
}
|
2017-04-25 15:21:46 -04:00
|
|
|
#endif
|