fixed merged with upstream/master

This commit is contained in:
csoler 2018-08-28 23:42:24 +02:00
commit c9b30f5a72
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
88 changed files with 3867 additions and 977 deletions

View file

@ -928,7 +928,6 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
for(auto it(search_results.begin());it!=search_results.end();++it)
{
(*it)->request_id = item->request_id ;
(*it)->depth = 0 ;
(*it)->PeerId(item->PeerId()) ;
sendItem(*it) ;
@ -1133,7 +1132,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
std::list<std::pair<RsTurtleSearchResultItem*,RsTurtleClientService*> > results_to_notify_off_mutex ;
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
RS_STACK_MUTEX(mTurtleMtx);
// Find who actually sent the corresponding request.
//
std::map<TurtleRequestId,TurtleSearchRequestInfo>::iterator it = _search_requests_origins.find(item->request_id) ;
@ -1195,11 +1194,10 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
// of the files found can be further reached by a tunnel.
fwd_item->PeerId(it->second.origin) ;
fwd_item->depth = 0 ; // obfuscate the depth for non immediate friends. Result will always be 0. This effectively removes the information.
sendItem(fwd_item) ;
}
}
} // mTurtleMtx end
// now we notify clients off-mutex.
@ -1212,7 +1210,16 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
if(ftsr!=NULL)
{
RsServer::notify()->notifyTurtleSearchResult(ftsr->request_id,ftsr->result) ;
ftServer *client = dynamic_cast<ftServer*>((*it).second) ;
if(!client)
{
std::cerr << "(EE) received turtle FT search result but the service is not a ftServer!!" << std::endl;
continue;
}
//RsServer::notify()->notifyTurtleSearchResult(ftsr->request_id,ftsr->result) ;
client->receiveSearchResult(ftsr);
continue ;
}

View file

@ -193,13 +193,20 @@ RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(RsRegularExpression::Linearized
void RsTurtleFTSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
// This depth was previously a member of SearchResult parent class that was set to be always 0. It's removed, but we have to stay backward compatible.
uint16_t depth_retrocompat_unused_placeholder = 0 ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth_retrocompat_unused_placeholder,"depth") ;
RsTypeSerializer::serial_process (j,ctx,result ,"result") ;
}
void RsTurtleGenericSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
// This depth was previously a member of SearchResult parent class that was set to be always 0. It's removed, but we have to stay backward compatible.
uint16_t depth_retrocompat_unused_placeholder = 0 ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth_retrocompat_unused_placeholder,"depth") ;
RsTypeSerializer::TlvMemBlock_proxy prox(result_data,result_data_len) ;
RsTypeSerializer::serial_process(j,ctx,prox,"search_data") ;
@ -212,59 +219,9 @@ RsTurtleSearchResultItem *RsTurtleGenericSearchResultItem::duplicate() const
memcpy(sr->result_data,result_data,result_data_len) ;
sr->result_data_len = result_data_len ;
sr->request_id = request_id ;
sr->depth = depth ;
return sr ;
}
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;
}
RS_TYPE_SERIALIZER_TO_JSON_NOT_IMPLEMENTED_DEF(TurtleFileInfo)
RS_TYPE_SERIALIZER_FROM_JSON_NOT_IMPLEMENTED_DEF(TurtleFileInfo)
void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ;

View file

@ -191,12 +191,9 @@ class RsTurtleGenericSearchRequestItem: public RsTurtleSearchRequestItem
class RsTurtleSearchResultItem: public RsTurtleItem
{
public:
RsTurtleSearchResultItem(uint8_t subtype) : RsTurtleItem(subtype), request_id(0), depth(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ;}
RsTurtleSearchResultItem(uint8_t subtype) : RsTurtleItem(subtype), request_id(0) { setPriorityLevel(QOS_PRIORITY_RS_TURTLE_SEARCH_RESULT) ;}
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.
virtual uint32_t count() const =0;
virtual void pop() =0;