mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
moved turtle and FT to new serialization
This commit is contained in:
parent
3453a3e57d
commit
636450f14d
12 changed files with 419 additions and 161 deletions
|
@ -852,12 +852,14 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||
item->print(std::cerr,0) ;
|
||||
#endif
|
||||
|
||||
if(item->serial_size() > TURTLE_MAX_SEARCH_REQ_ACCEPTED_SERIAL_SIZE)
|
||||
uint32_t item_size = RsTurtleSerialiser().size(item);
|
||||
|
||||
if(item_size > TURTLE_MAX_SEARCH_REQ_ACCEPTED_SERIAL_SIZE)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Dropping, because the serial size exceeds the accepted limit." << std::endl ;
|
||||
#endif
|
||||
std::cerr << " Caught a turtle search item with arbitrary large size from " << item->PeerId() << " of size " << item->serial_size() << " and depth " << item->depth << ". This is not allowed => dropping." << std::endl;
|
||||
std::cerr << " Caught a turtle search item with arbitrary large size from " << item->PeerId() << " of size " << item_size << " and depth " << item->depth << ". This is not allowed => dropping." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
|
@ -1074,7 +1076,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
|||
if(item->shouldStampTunnel())
|
||||
tunnel.time_stamp = time(NULL) ;
|
||||
|
||||
tunnel.transfered_bytes += static_cast<RsTurtleItem*>(item)->serial_size() ;
|
||||
tunnel.transfered_bytes += RsTurtleSerialiser().size(item);
|
||||
|
||||
if(item->PeerId() == tunnel.local_dst)
|
||||
item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
|
@ -1100,7 +1102,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
|||
#endif
|
||||
item->PeerId(tunnel.local_src) ;
|
||||
|
||||
_traffic_info_buffer.unknown_updn_Bps += static_cast<RsTurtleItem*>(item)->serial_size() ;
|
||||
_traffic_info_buffer.unknown_updn_Bps += RsTurtleSerialiser().size(item) ;
|
||||
|
||||
// This has been disabled for compilation reasons. Not sure we actually need it.
|
||||
//
|
||||
|
@ -1118,7 +1120,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
|||
#endif
|
||||
item->PeerId(tunnel.local_dst) ;
|
||||
|
||||
_traffic_info_buffer.unknown_updn_Bps += static_cast<RsTurtleItem*>(item)->serial_size() ;
|
||||
_traffic_info_buffer.unknown_updn_Bps += RsTurtleSerialiser().size(item);
|
||||
|
||||
sendItem(item) ;
|
||||
return ;
|
||||
|
@ -1126,7 +1128,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
|||
|
||||
// item is for us. Use the locked region to record the data.
|
||||
|
||||
_traffic_info_buffer.data_dn_Bps += item->serial_size() ;
|
||||
_traffic_info_buffer.data_dn_Bps += RsTurtleSerialiser().size(item);
|
||||
}
|
||||
|
||||
// The packet was not forwarded, so it is for us. Let's treat it.
|
||||
|
@ -1246,7 +1248,7 @@ void p3turtle::sendTurtleData(const RsPeerId& virtual_peer_id,RsTurtleGenericTun
|
|||
|
||||
item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever.
|
||||
|
||||
uint32_t ss = item->serial_size() ;
|
||||
uint32_t ss = RsTurtleSerialiser().size(item);
|
||||
|
||||
if(item->shouldStampTunnel())
|
||||
tunnel.time_stamp = time(NULL) ;
|
||||
|
@ -1380,7 +1382,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
|||
|
||||
{
|
||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||
_traffic_info_buffer.tr_dn_Bps += static_cast<RsTurtleItem*>(item)->serial_size() ;
|
||||
_traffic_info_buffer.tr_dn_Bps += RsTurtleSerialiser().size(item);
|
||||
|
||||
float distance_to_maximum = std::min(100.0f,_traffic_info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ;
|
||||
float corrected_distance = pow(distance_to_maximum,DISTANCE_SQUEEZING_POWER) ;
|
||||
|
@ -1572,7 +1574,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
|||
|
||||
{
|
||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||
_traffic_info_buffer.tr_up_Bps += static_cast<RsTurtleItem*>(fwd_item)->serial_size() ;
|
||||
_traffic_info_buffer.tr_up_Bps += RsTurtleSerialiser().size(fwd_item);
|
||||
}
|
||||
|
||||
sendItem(fwd_item) ;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "rsturtleitem.h"
|
||||
#include "turtleclientservice.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
|
||||
//#define P3TURTLE_DEBUG
|
||||
// -----------------------------------------------------------------------------------//
|
||||
// -------------------------------- Serialization. --------------------------------- //
|
||||
|
@ -16,6 +18,7 @@
|
|||
// ---------------------------------- Packet sizes -----------------------------------//
|
||||
//
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
uint32_t RsTurtleStringSearchRequestItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
@ -102,19 +105,13 @@ uint32_t RsTurtleGenericDataItem::serial_size() const
|
|||
|
||||
return s ;
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// ---------------------------------- Serialization ----------------------------------//
|
||||
//
|
||||
RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size)
|
||||
RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype)
|
||||
{
|
||||
// look what we have...
|
||||
|
||||
/* get the type */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "p3turtle: deserialising packet: " << std::endl ;
|
||||
#endif
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype)))
|
||||
if (RS_SERVICE_TYPE_TURTLE != service)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Wrong type !!" << std::endl ;
|
||||
|
@ -122,43 +119,38 @@ RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size)
|
|||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
try
|
||||
switch(getRsItemSubType(item_subtype))
|
||||
{
|
||||
#endif
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST : return new RsTurtleStringSearchRequestItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST : return new RsTurtleRegExpSearchRequestItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_SEARCH_RESULT : return new RsTurtleSearchResultItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem(data,*size) ;
|
||||
case RS_TURTLE_SUBTYPE_GENERIC_DATA : return new RsTurtleGenericDataItem(data,*size) ;
|
||||
|
||||
default:
|
||||
break ;
|
||||
}
|
||||
// now try all client services
|
||||
//
|
||||
RsItem *item = NULL ;
|
||||
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST : return new RsTurtleStringSearchRequestItem();
|
||||
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST : return new RsTurtleRegExpSearchRequestItem();
|
||||
case RS_TURTLE_SUBTYPE_SEARCH_RESULT : return new RsTurtleSearchResultItem();
|
||||
case RS_TURTLE_SUBTYPE_OPEN_TUNNEL : return new RsTurtleOpenTunnelItem();
|
||||
case RS_TURTLE_SUBTYPE_TUNNEL_OK : return new RsTurtleTunnelOkItem();
|
||||
case RS_TURTLE_SUBTYPE_GENERIC_DATA : return new RsTurtleGenericDataItem();
|
||||
|
||||
for(uint32_t i=0;i<_client_services.size();++i)
|
||||
if((item = _client_services[i]->deserialiseItem(data,*size)) != NULL)
|
||||
return item ;
|
||||
|
||||
std::cerr << "Unknown packet type in RsTurtle (not even handled by client services)!" << std::endl ;
|
||||
return NULL ;
|
||||
#ifndef WINDOWS_SYS
|
||||
default:
|
||||
break ;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception raised: " << e.what() << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
#endif
|
||||
// now try all client services
|
||||
//
|
||||
RsItem *item = NULL ;
|
||||
|
||||
for(uint32_t i=0;i<_client_services.size();++i)
|
||||
if((item = _client_services[i]->create_item(service,item_subtype)) != NULL)
|
||||
return item ;
|
||||
|
||||
std::cerr << "Unknown packet type in RsTurtle (not even handled by client services)!" << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
void RsTurtleStringSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
|
@ -242,7 +234,95 @@ bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) co
|
|||
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsTurtleRegExpSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth,"depth") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,expr,"expr") ;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r)
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 4 ; // number of strings
|
||||
|
||||
for(unsigned int i=0;i<r._strings.size();++i)
|
||||
s += GetTlvStringSize(r._strings[i]) ;
|
||||
|
||||
s += 4 ; // number of ints
|
||||
s += 4 * r._ints.size() ;
|
||||
s += 4 ; // number of tokens
|
||||
s += r._tokens.size() ; // uint8_t has size 1
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,RsRegularExpression::LinearizedExpression& expr)
|
||||
{
|
||||
uint32_t saved_offset = offset ;
|
||||
|
||||
uint32_t n =0 ;
|
||||
bool ok = true ;
|
||||
|
||||
ok &= getRawUInt32(data,size,&offset,&n) ;
|
||||
|
||||
if(ok) expr._tokens.resize(n) ;
|
||||
|
||||
for(uint32_t i=0;i<n && ok;++i) ok &= getRawUInt8(data,size,&offset,&expr._tokens[i]) ;
|
||||
|
||||
ok &= getRawUInt32(data,size,&offset,&n) ;
|
||||
|
||||
if(ok) expr._ints.resize(n) ;
|
||||
|
||||
for(uint32_t i=0;i<n && ok;++i) ok &= getRawUInt32(data,size,&offset,&expr._ints[i]) ;
|
||||
|
||||
ok &= getRawUInt32(data,size,&offset,&n);
|
||||
|
||||
if (ok) expr._strings.resize(n);
|
||||
|
||||
for(uint32_t i=0;i<n && ok;++i) ok &= GetTlvString(data, size, &offset, TLV_TYPE_STR_VALUE, expr._strings[i]);
|
||||
|
||||
if(!ok)
|
||||
offset = saved_offset ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const RsRegularExpression::LinearizedExpression& expr)
|
||||
{
|
||||
uint32_t saved_offset = offset ;
|
||||
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt32(data,size,&offset,expr._tokens.size()) ;
|
||||
|
||||
for(unsigned int i=0;i<expr._tokens.size();++i) ok &= setRawUInt8(data,size,&offset,expr._tokens[i]) ;
|
||||
|
||||
ok &= setRawUInt32(data,size,&offset,expr._ints.size()) ;
|
||||
|
||||
for(unsigned int i=0;i<expr._ints.size();++i) ok &= setRawUInt32(data,size,&offset,expr._ints[i]) ;
|
||||
|
||||
ok &= setRawUInt32(data,size,&offset,expr._strings.size()) ;
|
||||
|
||||
for(unsigned int i=0;i<expr._strings.size();++i) ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_VALUE, expr._strings[i]);
|
||||
|
||||
|
||||
if(!ok)
|
||||
offset = saved_offset ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegularExpression::LinearizedExpression& expr)
|
||||
{
|
||||
std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
RsTurtleStringSearchRequestItem::RsTurtleStringSearchRequestItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST)
|
||||
{
|
||||
|
@ -309,6 +389,62 @@ RsTurtleRegExpSearchRequestItem::RsTurtleRegExpSearchRequestItem(void *data,uint
|
|||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsTurtleSearchResultItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,result ,"result") ;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const TurtleFileInfo& i)
|
||||
{
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // size
|
||||
s += i.hash.SIZE_IN_BYTES ;
|
||||
s += GetTlvStringSize(i.name) ;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[],uint32_t size,uint32_t& offset,TurtleFileInfo& i)
|
||||
{
|
||||
uint32_t saved_offset = offset ;
|
||||
bool ok = true ;
|
||||
|
||||
ok &= getRawUInt64(data, size, &offset, &i.size); // file size
|
||||
ok &= i.hash.deserialise(data, size, offset); // file hash
|
||||
ok &= GetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // file name
|
||||
|
||||
if(!ok)
|
||||
offset = saved_offset ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[],uint32_t size,uint32_t& offset,const TurtleFileInfo& i)
|
||||
{
|
||||
uint32_t saved_offset = offset ;
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt64(data, size, &offset, i.size); // file size
|
||||
ok &= i.hash.serialise(data, size, offset); // file hash
|
||||
ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_NAME, i.name); // file name
|
||||
|
||||
if(!ok)
|
||||
offset = saved_offset ;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleFileInfo& i)
|
||||
{
|
||||
std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
|
||||
bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
|
@ -394,7 +530,17 @@ RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize)
|
|||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id ,"request_id") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,partial_tunnel_id,"partial_tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
|
@ -460,7 +606,15 @@ RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize)
|
|||
throw std::runtime_error("RsTurtleOpenTunnelItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsTurtleTunnelOkItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id ,"tunnel_id") ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize = serial_size();
|
||||
|
@ -522,7 +676,18 @@ RsTurtleTunnelOkItem::RsTurtleTunnelOkItem(void *data,uint32_t pktsize)
|
|||
throw std::runtime_error("RsTurtleTunnelOkItem::() unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id ,"tunnel_id") ;
|
||||
|
||||
RsTypeSerializer::TlvMemBlock_proxy prox(data_bytes,data_size) ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,prox,"data bytes") ;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
RsTurtleGenericDataItem::RsTurtleGenericDataItem(void *data,uint32_t pktsize)
|
||||
: RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_GENERIC_DATA)
|
||||
{
|
||||
|
@ -604,6 +769,7 @@ bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) const
|
|||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
// ------------------------------------- IO --------------------------------------- //
|
||||
// -----------------------------------------------------------------------------------//
|
||||
|
@ -681,3 +847,4 @@ std::ostream& RsTurtleGenericDataItem::print(std::ostream& o, uint16_t)
|
|||
|
||||
return o ;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include "serialiser/rsserviceids.h"
|
||||
#include "turtle/turtletypes.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
|
||||
const uint8_t RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST = 0x01 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_OPEN_TUNNEL = 0x03 ;
|
||||
|
@ -17,14 +19,14 @@ const uint8_t RS_TURTLE_SUBTYPE_CLOSE_TUNNEL = 0x05 ;
|
|||
const uint8_t RS_TURTLE_SUBTYPE_TUNNEL_CLOSED = 0x06 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_REQUEST = 0x07 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_DATA = 0x08 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST = 0x09 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_GENERIC_DATA = 0x0a ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP = 0x10 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST = 0x11 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC = 0x14 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST = 0x15 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP = 0x10 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST = 0x11 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC = 0x12 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_FILE_CRC_REQUEST = 0x13 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC = 0x14 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST = 0x15 ;
|
||||
|
||||
/***********************************************************************************/
|
||||
/* Basic Turtle Item Class */
|
||||
|
@ -34,11 +36,6 @@ class RsTurtleItem: public RsItem
|
|||
{
|
||||
public:
|
||||
RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {}
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) const = 0 ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
|
@ -50,29 +47,26 @@ class RsTurtleSearchResultItem: public RsTurtleItem
|
|||
{
|
||||
public:
|
||||
RsTurtleSearchResultItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_SEARCH_RESULT), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ;}
|
||||
RsTurtleSearchResultItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
TurtleSearchRequestId request_id ; // Randomly generated request id.
|
||||
|
||||
uint16_t depth ; // The depth of a search result is obfuscated in this way:
|
||||
// If the actual depth is 1, this field will be 1.
|
||||
// If the actual depth is > 1, this field is a larger arbitrary integer.
|
||||
|
||||
uint16_t depth ; // The depth of a search result is obfuscated in this way:
|
||||
// If the actual depth is 1, this field will be 1.
|
||||
// If the actual depth is > 1, this field is a larger arbitrary integer.
|
||||
std::list<TurtleFileInfo> result ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
void clear() { result.clear() ; }
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
|
||||
};
|
||||
|
||||
class RsTurtleSearchRequestItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleSearchRequestItem(uint32_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_REQUEST) ;}
|
||||
virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods
|
||||
|
||||
virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods
|
||||
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const = 0 ; // abstracts the search method
|
||||
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
|
@ -83,34 +77,31 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem
|
|||
{
|
||||
public:
|
||||
RsTurtleStringSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {}
|
||||
RsTurtleStringSearchRequestItem(void *data,uint32_t size) ;
|
||||
|
||||
std::string match_string ; // string to match
|
||||
|
||||
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; }
|
||||
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
void clear() { match_string.clear() ; }
|
||||
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
};
|
||||
|
||||
class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
|
||||
{
|
||||
public:
|
||||
RsTurtleRegExpSearchRequestItem() : RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST) {}
|
||||
RsTurtleRegExpSearchRequestItem(void *data,uint32_t size) ;
|
||||
|
||||
RsRegularExpression::LinearizedExpression expr ; // Reg Exp in linearised mode
|
||||
|
||||
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; }
|
||||
virtual void performLocalSearch(std::list<TurtleFileInfo>&) const ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
void clear() { expr = RsRegularExpression::LinearizedExpression(); }
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
|
@ -121,34 +112,28 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem
|
|||
{
|
||||
public:
|
||||
RsTurtleOpenTunnelItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_OPEN_TUNNEL), request_id(0), partial_tunnel_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_OPEN_TUNNEL) ;}
|
||||
RsTurtleOpenTunnelItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
TurtleFileHash file_hash ; // hash to match
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
uint32_t partial_tunnel_id ; // uncomplete tunnel id. Will be completed at destination.
|
||||
uint16_t depth ; // Used for limiting search depth.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
void clear() { file_hash.clear() ;}
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
};
|
||||
|
||||
class RsTurtleTunnelOkItem: public RsTurtleItem
|
||||
{
|
||||
public:
|
||||
RsTurtleTunnelOkItem() : RsTurtleItem(RS_TURTLE_SUBTYPE_TUNNEL_OK), tunnel_id(0), request_id(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_TUNNEL_OK) ;}
|
||||
RsTurtleTunnelOkItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t tunnel_id ; // id of the tunnel. Should be identical for a tunnel between two same peers for the same hash.
|
||||
uint32_t request_id ; // randomly generated request id corresponding to the intial request.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
void clear() {}
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
|
@ -198,8 +183,6 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem
|
|||
{
|
||||
public:
|
||||
RsTurtleGenericDataItem() : RsTurtleGenericTunnelItem(RS_TURTLE_SUBTYPE_GENERIC_DATA), data_size(0), data_bytes(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_FILE_REQUEST);}
|
||||
RsTurtleGenericDataItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual ~RsTurtleGenericDataItem() { if(data_bytes != NULL) free(data_bytes) ; }
|
||||
|
||||
virtual bool shouldStampTunnel() const { return true ; }
|
||||
|
@ -207,30 +190,26 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem
|
|||
uint32_t data_size ;
|
||||
void *data_bytes ;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
void clear()
|
||||
{
|
||||
free(data_bytes) ;
|
||||
data_bytes = NULL ;
|
||||
data_size = 0;
|
||||
}
|
||||
protected:
|
||||
virtual bool serialize(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
void serial_process(SerializeJob j,SerializeContext& ctx);
|
||||
};
|
||||
|
||||
/***********************************************************************************/
|
||||
/* Turtle Serialiser class */
|
||||
/***********************************************************************************/
|
||||
|
||||
class RsTurtleSerialiser: public RsSerialType
|
||||
class RsTurtleSerialiser: public RsSerializer
|
||||
{
|
||||
public:
|
||||
RsTurtleSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_TURTLE) {}
|
||||
RsTurtleSerialiser() : RsSerializer(RS_SERVICE_TYPE_TURTLE) {}
|
||||
|
||||
virtual uint32_t size (RsItem *item)
|
||||
{
|
||||
return dynamic_cast<RsTurtleItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return dynamic_cast<RsTurtleItem *>(item)->serialize(data,*size) ;
|
||||
}
|
||||
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
||||
virtual RsItem *create_item(uint16_t service,uint8_t item_subtype);
|
||||
|
||||
// This is used by the turtle router to add services to its serialiser.
|
||||
// Client services are only used for deserialising, since the serialisation is
|
||||
|
|
|
@ -71,12 +71,12 @@ class RsTurtleClientService
|
|||
std::cerr << "!!!!!! Received Data from turtle router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
|
||||
}
|
||||
|
||||
// Method for deserialising specific items of the client service. The
|
||||
// Method for creating specific items of the client service. The
|
||||
// method has a default behavior of not doing anything, since most client
|
||||
// services might only use the generic item already provided by the turtle
|
||||
// router: RsTurtleGenericDataItem
|
||||
|
||||
virtual RsTurtleGenericTunnelItem *deserialiseItem(void */*data*/, uint32_t /*size*/) const { return NULL ; }
|
||||
virtual RsTurtleGenericTunnelItem *create_item(uint16_t service,uint8_t item_type) const { return NULL ; }
|
||||
|
||||
// These methods are called by the turtle router to add/remove virtual peers when tunnels are created/deleted
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue