mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
sereral fixes to GXS distant search
This commit is contained in:
parent
7a135c5c43
commit
84194b6234
12 changed files with 172 additions and 107 deletions
|
@ -930,7 +930,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||
#endif
|
||||
std::list<RsTurtleSearchResultItem*> search_results ;
|
||||
|
||||
item->performLocalSearch(req,search_results) ;
|
||||
locked_performLocalSearch(item,req,search_results) ;
|
||||
|
||||
for(auto it(search_results.begin());it!=search_results.end();++it)
|
||||
sendItem(*it) ;
|
||||
|
@ -999,6 +999,97 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||
#endif
|
||||
}
|
||||
|
||||
// This function should be removed in the future, when file search will also use generic search items.
|
||||
|
||||
void p3turtle::locked_performLocalSearch(RsTurtleSearchRequestItem *item,TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>& search_results)
|
||||
{
|
||||
RsTurtleFileSearchRequestItem *ftsearch = dynamic_cast<RsTurtleFileSearchRequestItem*>(item) ;
|
||||
|
||||
if(ftsearch != NULL)
|
||||
{
|
||||
locked_performLocalSearch_files(ftsearch,req,search_results) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
RsTurtleGenericSearchRequestItem *gnsearch = dynamic_cast<RsTurtleGenericSearchRequestItem*>(item) ;
|
||||
|
||||
if(gnsearch != NULL)
|
||||
{
|
||||
locked_performLocalSearch_generic(gnsearch,req,search_results) ;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3turtle::locked_performLocalSearch_generic(RsTurtleGenericSearchRequestItem *item,TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>& result)
|
||||
{
|
||||
unsigned char *search_result_data = NULL ;
|
||||
uint32_t search_result_data_len = 0 ;
|
||||
|
||||
auto it = _registered_services.find(item->service_id) ;
|
||||
|
||||
if(it == _registered_services.end())
|
||||
return ;
|
||||
|
||||
if(it->second->receiveSearchRequest(item->search_data,item->search_data_len,search_result_data,search_result_data_len))
|
||||
{
|
||||
RsTurtleGenericSearchResultItem *result_item = new RsTurtleGenericSearchResultItem ;
|
||||
|
||||
result_item->result_data = search_result_data ;
|
||||
result_item->result_data_len = search_result_data_len ;
|
||||
|
||||
result.push_back(result_item) ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3turtle::locked_performLocalSearch_files(RsTurtleFileSearchRequestItem *item,TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>& result)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "Performing rsFiles->search()" << std::endl ;
|
||||
#endif
|
||||
// now, search!
|
||||
std::list<TurtleFileInfo> initialResults ;
|
||||
item->search(initialResults) ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << initialResults.size() << " matches found." << std::endl ;
|
||||
#endif
|
||||
result.clear() ;
|
||||
RsTurtleFTSearchResultItem *res_item = NULL ;
|
||||
uint32_t item_size = 0 ;
|
||||
|
||||
static const uint32_t RSTURTLE_MAX_SEARCH_RESPONSE_SIZE = 10000 ;
|
||||
|
||||
for(auto it(initialResults.begin());it!=initialResults.end();++it)
|
||||
{
|
||||
if(res_item == NULL)
|
||||
{
|
||||
res_item = new RsTurtleFTSearchResultItem ;
|
||||
item_size = 0 ;
|
||||
|
||||
res_item->depth = 0 ;
|
||||
res_item->request_id = item->request_id ;
|
||||
res_item->PeerId(item->PeerId()) ; // send back to the same guy
|
||||
|
||||
result.push_back(res_item) ;
|
||||
}
|
||||
res_item->result.push_back(*it);
|
||||
|
||||
// Let's chop search results items into several chunks of finite size to avoid exceeding streamer's capacity.
|
||||
//
|
||||
++req.result_count ; // increase hit number for this particular search request.
|
||||
|
||||
item_size += 8 /* size */ + it->hash.serial_size() + it->name.size() ;
|
||||
|
||||
if(item_size > RSTURTLE_MAX_SEARCH_RESPONSE_SIZE || req.result_count >= TURTLE_SEARCH_RESULT_MAX_HITS)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Sending back chunk of size " << item_size << ", for " << res_item->result.size() << " elements." << std::endl ;
|
||||
#endif
|
||||
res_item = NULL ; // forces creation of a new item.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
||||
{
|
||||
std::list<std::pair<RsTurtleSearchResultItem*,RsTurtleClientService*> > results_to_notify_off_mutex ;
|
||||
|
@ -1771,59 +1862,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
|||
// ------------------------------ IO with libretroshare ----------------------------//
|
||||
// -----------------------------------------------------------------------------------//
|
||||
//
|
||||
void RsTurtleFileSearchRequestItem::performLocalSearch(TurtleSearchRequestInfo &req, std::list<RsTurtleSearchResultItem*>& result) const
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "Performing rsFiles->search()" << std::endl ;
|
||||
#endif
|
||||
// now, search!
|
||||
std::list<TurtleFileInfo> initialResults ;
|
||||
search(initialResults) ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << initialResults.size() << " matches found." << std::endl ;
|
||||
#endif
|
||||
result.clear() ;
|
||||
RsTurtleFTSearchResultItem *res_item = NULL ;
|
||||
uint32_t item_size = 0 ;
|
||||
|
||||
static const uint32_t RSTURTLE_MAX_SEARCH_RESPONSE_SIZE = 10000 ;
|
||||
|
||||
for(auto it(initialResults.begin());it!=initialResults.end();++it)
|
||||
{
|
||||
if(res_item == NULL)
|
||||
{
|
||||
res_item = new RsTurtleFTSearchResultItem ;
|
||||
item_size = 0 ;
|
||||
|
||||
res_item->depth = 0 ;
|
||||
res_item->request_id = request_id ;
|
||||
res_item->PeerId(PeerId()) ; // send back to the same guy
|
||||
|
||||
result.push_back(res_item) ;
|
||||
}
|
||||
res_item->result.push_back(*it);
|
||||
|
||||
// Let's chop search results items into several chunks of finite size to avoid exceeding streamer's capacity.
|
||||
//
|
||||
++req.result_count ; // increase hit number for this particular search request.
|
||||
|
||||
item_size += 8 /* size */ + it->hash.serial_size() + it->name.size() ;
|
||||
|
||||
if(item_size > RSTURTLE_MAX_SEARCH_RESPONSE_SIZE || req.result_count >= TURTLE_SEARCH_RESULT_MAX_HITS)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Sending back chunk of size " << item_size << ", for " << res_item->result.size() << " elements." << std::endl ;
|
||||
#endif
|
||||
res_item = NULL ; // forces creation of a new item.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RsTurtleGenericSearchRequestItem::performLocalSearch(TurtleSearchRequestInfo &req, std::list<RsTurtleSearchResultItem*>& result) const
|
||||
{
|
||||
std::cerr << "(EE) p3turtle: Missing code to perform actual GXS search" << std::endl;
|
||||
}
|
||||
|
||||
void RsTurtleStringSearchRequestItem::search(std::list<TurtleFileInfo>& result) const
|
||||
{
|
||||
|
@ -1967,22 +2006,22 @@ TurtleRequestId p3turtle::turtleSearch(unsigned char *search_bin_data,uint32_t s
|
|||
|
||||
// Form a request packet that simulates a request from us.
|
||||
//
|
||||
RsTurtleGenericSearchRequestItem *item = new RsTurtleGenericSearchRequestItem ;
|
||||
RsTurtleGenericSearchRequestItem item ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "performing search. OwnId = " << _own_id << std::endl ;
|
||||
#endif
|
||||
|
||||
item->PeerId(_own_id) ;
|
||||
item->service_id = client_service->serviceId();
|
||||
item->search_data = search_bin_data ;
|
||||
item->search_data_len = search_bin_data_len ;
|
||||
item->request_id = id ;
|
||||
item->depth = 0 ;
|
||||
item.PeerId(_own_id) ;
|
||||
item.service_id = client_service->serviceId();
|
||||
item.search_data = search_bin_data ;
|
||||
item.search_data_len = search_bin_data_len ;
|
||||
item.request_id = id ;
|
||||
item.depth = 0 ;
|
||||
|
||||
// send it
|
||||
|
||||
handleSearchRequest(item) ;
|
||||
handleSearchRequest(&item) ;
|
||||
|
||||
return id ;
|
||||
}
|
||||
|
@ -2056,10 +2095,10 @@ bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId&
|
|||
if(_registered_services.empty())
|
||||
std::cerr << "Turtle router has no services registered. Tunnel requests cannot be handled." << std::endl;
|
||||
|
||||
for(std::list<RsTurtleClientService*>::const_iterator it(_registered_services.begin());it!=_registered_services.end();++it)
|
||||
if( (*it)->handleTunnelRequest(hash,peer_id))
|
||||
for(auto it(_registered_services.begin());it!=_registered_services.end();++it)
|
||||
if( (*it).second->handleTunnelRequest(hash,peer_id))
|
||||
{
|
||||
service = *it ;
|
||||
service = it->second ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
@ -2069,14 +2108,9 @@ bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId&
|
|||
|
||||
void p3turtle::registerTunnelService(RsTurtleClientService *service)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
for(std::list<RsTurtleClientService*>::const_iterator it(_registered_services.begin());it!=_registered_services.end();++it)
|
||||
if(service == *it)
|
||||
throw std::runtime_error("p3turtle::registerTunnelService(): Cannot register the same service twice. Please fix the code!") ;
|
||||
#endif
|
||||
std::cerr << "p3turtle: registered new tunnel service " << (void*)service << std::endl;
|
||||
std::cerr << "p3turtle: registered new tunnel service with ID=" << std::hex << service->serviceId() << std::dec << " and pointer " << (void*)service << std::endl;
|
||||
|
||||
_registered_services.push_back(service) ;
|
||||
_registered_services[service->serviceId()] = service ;
|
||||
_serialiser->registerClientService(service) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -397,7 +397,9 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||
//------ Functions connecting the turtle router to other components.----------//
|
||||
|
||||
/// Performs a search calling local cache and search structure.
|
||||
void performLocalSearch(const std::string& match_string,std::list<TurtleFileInfo>& result) ;
|
||||
void locked_performLocalSearch (RsTurtleSearchRequestItem *item,TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>& result) ;
|
||||
void locked_performLocalSearch_files (RsTurtleFileSearchRequestItem *item,TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>& result) ;
|
||||
void locked_performLocalSearch_generic(RsTurtleGenericSearchRequestItem *item,TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>& result) ;
|
||||
|
||||
/// Returns true if the file with given hash is hosted locally, and accessible in anonymous mode the supplied peer.
|
||||
virtual bool performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId& client_peer_id,RsTurtleClientService *& service);
|
||||
|
@ -419,7 +421,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||
std::map<TurtleTunnelRequestId,TurtleTunnelRequestInfo> _tunnel_requests_origins ;
|
||||
|
||||
/// stores adequate tunnels for each file hash locally managed
|
||||
std::map<TurtleFileHash,TurtleHashInfo> _incoming_file_hashes ;
|
||||
std::map<TurtleFileHash,TurtleHashInfo> _incoming_file_hashes ;
|
||||
|
||||
/// stores file info for each file we provide.
|
||||
std::map<TurtleTunnelId,RsTurtleClientService *> _outgoing_tunnel_client_services ;
|
||||
|
@ -434,7 +436,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||
std::set<TurtleFileHash> _hashes_to_remove ;
|
||||
|
||||
/// List of client services that have regitered.
|
||||
std::list<RsTurtleClientService*> _registered_services ;
|
||||
std::map<uint16_t,RsTurtleClientService*> _registered_services ;
|
||||
|
||||
time_t _last_clean_time ;
|
||||
time_t _last_tunnel_management_time ;
|
||||
|
|
|
@ -75,9 +75,11 @@ RsTurtleSearchRequestItem *RsTurtleGenericSearchRequestItem::clone() const
|
|||
{
|
||||
RsTurtleGenericSearchRequestItem *sr = new RsTurtleGenericSearchRequestItem ;
|
||||
|
||||
memcpy(sr,this,sizeof(RsTurtleGenericSearchRequestItem)) ;
|
||||
|
||||
sr->search_data = (unsigned char*)rs_malloc(search_data_len) ;
|
||||
memcpy(sr->search_data,search_data,search_data_len) ;
|
||||
sr->search_data_len = search_data_len ;
|
||||
|
||||
return sr ;
|
||||
}
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r)
|
||||
|
|
|
@ -57,26 +57,18 @@ class RsTurtleItem: public RsItem
|
|||
// +---- RsTurtleSearchRequestItem
|
||||
// | |
|
||||
// | +---- RsTurtleFileSearchRequestItem
|
||||
// | | |
|
||||
// | | +---- RsTurtleFileSearchRequestItem
|
||||
// | | |
|
||||
// | | +---- RsTurtleStringSearchRequestItem
|
||||
// | | |
|
||||
// | | +---- RsTurtleReqExpSearchRequestItem
|
||||
// | | |
|
||||
// | | +---- RsTurtleStringSearchRequestItem
|
||||
// | | |
|
||||
// | | +---- RsTurtleReqExpSearchRequestItem
|
||||
// | |
|
||||
// | +---- RsTurtleGxsSearchRequestItem
|
||||
// | |
|
||||
// | +---- RsTurtleGxsGroupRequestItem
|
||||
// | +---- RsTurtleGenericSearchRequestItem
|
||||
// |
|
||||
// +---- RsTurtleSearchResultItem
|
||||
// |
|
||||
// +---- RsTurtleFTSearchResultItem
|
||||
// |
|
||||
// +---- RsTurtleGxsSearchResultItem
|
||||
// |
|
||||
// +---- RsTurtleGxsSearchResultGroupSummaryItem
|
||||
// |
|
||||
// +---- RsTurtleGxsSearchResultGroupDataItem
|
||||
// +---- RsTurtleGenericSearchResultItem
|
||||
//
|
||||
|
||||
class RsTurtleSearchResultItem ;
|
||||
|
@ -89,8 +81,6 @@ class RsTurtleSearchRequestItem: public RsTurtleItem
|
|||
|
||||
virtual RsTurtleSearchRequestItem *clone() const = 0 ; // used for cloning in routing methods
|
||||
|
||||
virtual void performLocalSearch(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const = 0 ; // abstracts the search method
|
||||
|
||||
virtual std::string GetKeywords() = 0;
|
||||
|
||||
uint32_t request_id ; // randomly generated request id.
|
||||
|
@ -103,9 +93,6 @@ class RsTurtleFileSearchRequestItem: public RsTurtleSearchRequestItem
|
|||
RsTurtleFileSearchRequestItem(uint32_t subtype) : RsTurtleSearchRequestItem(subtype) {}
|
||||
virtual ~RsTurtleFileSearchRequestItem() {}
|
||||
|
||||
virtual void performLocalSearch(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const ; // abstracts the search method
|
||||
|
||||
protected:
|
||||
virtual void search(std::list<TurtleFileInfo> &) const =0;
|
||||
};
|
||||
|
||||
|
@ -115,8 +102,9 @@ class RsTurtleStringSearchRequestItem: public RsTurtleFileSearchRequestItem
|
|||
RsTurtleStringSearchRequestItem() : RsTurtleFileSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {}
|
||||
virtual ~RsTurtleStringSearchRequestItem() {}
|
||||
|
||||
std::string match_string ; // string to match
|
||||
virtual void search(std::list<TurtleFileInfo> &) const ;
|
||||
|
||||
std::string match_string ; // string to match
|
||||
std::string GetKeywords() { return match_string; }
|
||||
|
||||
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; }
|
||||
|
@ -124,7 +112,6 @@ class RsTurtleStringSearchRequestItem: public RsTurtleFileSearchRequestItem
|
|||
void clear() { match_string.clear() ; }
|
||||
|
||||
protected:
|
||||
virtual void search(std::list<TurtleFileInfo> &) const ;
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
|
@ -144,10 +131,11 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleFileSearchRequestItem
|
|||
return exs;
|
||||
}
|
||||
|
||||
virtual void search(std::list<TurtleFileInfo> &) const ;
|
||||
|
||||
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; }
|
||||
void clear() { expr = RsRegularExpression::LinearizedExpression(); }
|
||||
protected:
|
||||
virtual void search(std::list<TurtleFileInfo> &) const ;
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
};
|
||||
|
||||
|
@ -166,7 +154,6 @@ class RsTurtleGenericSearchRequestItem: public RsTurtleSearchRequestItem
|
|||
virtual RsTurtleSearchRequestItem *clone() const ;
|
||||
void clear() { free(search_data); search_data=NULL; search_data_len=0; }
|
||||
|
||||
virtual void performLocalSearch(TurtleSearchRequestInfo &req, std::list<RsTurtleSearchResultItem*>& result) const;
|
||||
protected:
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue