mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
sereral fixes to GXS distant search
This commit is contained in:
parent
7a135c5c43
commit
84194b6234
@ -95,6 +95,8 @@ public:
|
|||||||
|
|
||||||
// Implements RsTurtleClientService
|
// Implements RsTurtleClientService
|
||||||
//
|
//
|
||||||
|
|
||||||
|
uint16_t serviceId() const { return RS_SERVICE_TYPE_FILE_TRANSFER ; }
|
||||||
virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
virtual bool handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) ;
|
||||||
virtual void receiveTurtleData(const RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
virtual void receiveTurtleData(const RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||||
//virtual void receiveSearchResult(RsTurtleSearchResultItem *item);// TODO
|
//virtual void receiveSearchResult(RsTurtleSearchResultItem *item);// TODO
|
||||||
|
@ -208,6 +208,7 @@ protected:
|
|||||||
// Interaction with turtle router //
|
// Interaction with turtle router //
|
||||||
//===================================================//
|
//===================================================//
|
||||||
|
|
||||||
|
uint16_t serviceId() const { return RS_SERVICE_TYPE_GROUTER; }
|
||||||
virtual bool handleTunnelRequest(const RsFileHash& /*hash*/,const RsPeerId& /*peer_id*/) ;
|
virtual bool handleTunnelRequest(const RsFileHash& /*hash*/,const RsPeerId& /*peer_id*/) ;
|
||||||
virtual void receiveTurtleData(const RsTurtleGenericTunnelItem */*item*/,const RsFileHash& /*hash*/,const RsPeerId& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/);
|
virtual void receiveTurtleData(const RsTurtleGenericTunnelItem */*item*/,const RsFileHash& /*hash*/,const RsPeerId& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/);
|
||||||
virtual void addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) ;
|
virtual void addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) ;
|
||||||
|
@ -272,12 +272,12 @@
|
|||||||
NXS_NET_DEBUG_8 gxs distant sync
|
NXS_NET_DEBUG_8 gxs distant sync
|
||||||
|
|
||||||
***/
|
***/
|
||||||
#define NXS_NET_DEBUG_0 1
|
//#define NXS_NET_DEBUG_0 1
|
||||||
#define NXS_NET_DEBUG_1 1
|
//#define NXS_NET_DEBUG_1 1
|
||||||
//#define NXS_NET_DEBUG_2 1
|
//#define NXS_NET_DEBUG_2 1
|
||||||
//#define NXS_NET_DEBUG_3 1
|
//#define NXS_NET_DEBUG_3 1
|
||||||
//#define NXS_NET_DEBUG_4 1
|
//#define NXS_NET_DEBUG_4 1
|
||||||
#define NXS_NET_DEBUG_5 1
|
//#define NXS_NET_DEBUG_5 1
|
||||||
//#define NXS_NET_DEBUG_6 1
|
//#define NXS_NET_DEBUG_6 1
|
||||||
//#define NXS_NET_DEBUG_7 1
|
//#define NXS_NET_DEBUG_7 1
|
||||||
#define NXS_NET_DEBUG_8 1
|
#define NXS_NET_DEBUG_8 1
|
||||||
@ -5143,5 +5143,8 @@ bool RsGxsNetService::search(const std::string& substring,std::list<RsGxsGroupSu
|
|||||||
group_infos.push_back(s) ;
|
group_infos.push_back(s) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG_8
|
||||||
|
GXSNETDEBUG___ << " performing local substring search in response to distant request. Found " << group_infos.size() << " responses." << std::endl;
|
||||||
|
#endif
|
||||||
return !group_infos.empty();
|
return !group_infos.empty();
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include "gxs/rsnxs.h"
|
#include "gxs/rsnxs.h"
|
||||||
#include "rsgxsnettunnel.h"
|
#include "rsgxsnettunnel.h"
|
||||||
|
|
||||||
#define DEBUG_RSGXSNETTUNNEL 1
|
//#define DEBUG_RSGXSNETTUNNEL 1
|
||||||
|
|
||||||
#define GXS_NET_TUNNEL_NOT_IMPLEMENTED() { std::cerr << __PRETTY_FUNCTION__ << ": not yet implemented." << std::endl; }
|
#define GXS_NET_TUNNEL_NOT_IMPLEMENTED() { std::cerr << __PRETTY_FUNCTION__ << ": not yet implemented." << std::endl; }
|
||||||
#define GXS_NET_TUNNEL_DEBUG() std::cerr << time(NULL) << " : GXS_NET_TUNNEL: " << __FUNCTION__ << " : "
|
#define GXS_NET_TUNNEL_DEBUG() std::cerr << time(NULL) << " : GXS_NET_TUNNEL: " << __FUNCTION__ << " : "
|
||||||
@ -181,8 +181,12 @@ public:
|
|||||||
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_VIRTUAL_PEER: return new RsGxsNetTunnelVirtualPeerItem ;
|
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_VIRTUAL_PEER: return new RsGxsNetTunnelVirtualPeerItem ;
|
||||||
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_KEEP_ALIVE : return new RsGxsNetTunnelKeepAliveItem ;
|
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_KEEP_ALIVE : return new RsGxsNetTunnelKeepAliveItem ;
|
||||||
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_RANDOM_BIAS : return new RsGxsNetTunnelRandomBiasItem ;
|
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_RANDOM_BIAS : return new RsGxsNetTunnelRandomBiasItem ;
|
||||||
|
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_TURTLE_SEARCH_SUBSTRING : return new RsGxsNetTunnelTurtleSearchSubstringItem;
|
||||||
|
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_TURTLE_SEARCH_GROUP_REQUEST : return new RsGxsNetTunnelTurtleSearchGroupRequestItem;
|
||||||
|
case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_TURTLE_SEARCH_GROUP_SUMMARY : return new RsGxsNetTunnelTurtleSearchGroupSummaryItem;
|
||||||
|
//case RS_PKT_SUBTYPE_GXS_NET_TUNNEL_TURTLE_SEARCH_GROUP_DATA : return new RsGxsNetTunnelTurtleSearchGroupDataItem;
|
||||||
default:
|
default:
|
||||||
GXS_NET_TUNNEL_ERROR() << "type ID " << std::hex << item_subtype << std::dec << " is not handled!" << std::endl;
|
GXS_NET_TUNNEL_ERROR() << "type ID " << std::hex << (int)item_subtype << std::dec << " is not handled!" << std::endl;
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,6 +209,11 @@ void RsTypeSerializer::serial_process( RsGenericSerializer::SerializeJob j, RsGe
|
|||||||
// Interface with rest of the software //
|
// Interface with rest of the software //
|
||||||
//===========================================================================================================================================//
|
//===========================================================================================================================================//
|
||||||
|
|
||||||
|
uint16_t RsGxsNetTunnelService::serviceId() const
|
||||||
|
{
|
||||||
|
return RS_SERVICE_TYPE_GXS_NET_TUNNEL;
|
||||||
|
}
|
||||||
|
|
||||||
bool RsGxsNetTunnelService::registerSearchableService(RsNetworkExchangeService *gxs_service)
|
bool RsGxsNetTunnelService::registerSearchableService(RsNetworkExchangeService *gxs_service)
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||||
@ -727,11 +736,13 @@ void RsGxsNetTunnelService::data_tick()
|
|||||||
sendKeepAlivePackets() ;
|
sendKeepAlivePackets() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_RSGXSNETTUNNEL
|
||||||
if(mLastDump + 10 < now)
|
if(mLastDump + 10 < now)
|
||||||
{
|
{
|
||||||
mLastDump = now;
|
mLastDump = now;
|
||||||
dump();
|
dump();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rstime::rs_usleep(1*1000*1000) ; // 1 sec
|
rstime::rs_usleep(1*1000*1000) ; // 1 sec
|
||||||
}
|
}
|
||||||
@ -972,6 +983,7 @@ TurtleRequestId RsGxsNetTunnelService::turtleSearchRequest(const std::string& ma
|
|||||||
|
|
||||||
RsGxsNetTunnelSerializer().serialise(&search_item,mem,&size);
|
RsGxsNetTunnelSerializer().serialise(&search_item,mem,&size);
|
||||||
|
|
||||||
|
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||||
return mTurtle->turtleSearch(mem,size,this) ;
|
return mTurtle->turtleSearch(mem,size,this) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -985,14 +997,20 @@ bool RsGxsNetTunnelService::receiveSearchRequest(unsigned char *search_request_d
|
|||||||
|
|
||||||
if(substring_sr != NULL)
|
if(substring_sr != NULL)
|
||||||
{
|
{
|
||||||
auto it = mSearchableServices.find(substring_sr->service) ;
|
GXS_NET_TUNNEL_DEBUG() << " : type is substring for service " << std::hex << (int)substring_sr->service << std::dec << std::endl;
|
||||||
|
|
||||||
std::list<RsGxsGroupSummary> results ;
|
std::list<RsGxsGroupSummary> results ;
|
||||||
|
|
||||||
|
RS_STACK_MUTEX(mGxsNetTunnelMtx);
|
||||||
|
|
||||||
|
auto it = mSearchableServices.find(substring_sr->service) ;
|
||||||
|
|
||||||
if(it != mSearchableServices.end() && it->second->search(substring_sr->substring_match,results))
|
if(it != mSearchableServices.end() && it->second->search(substring_sr->substring_match,results))
|
||||||
{
|
{
|
||||||
RsGxsNetTunnelTurtleSearchGroupSummaryItem search_result_item ;
|
RsGxsNetTunnelTurtleSearchGroupSummaryItem search_result_item ;
|
||||||
|
|
||||||
|
GXS_NET_TUNNEL_DEBUG() << " : " << results.size() << " result found. Sending back." << std::endl;
|
||||||
|
|
||||||
search_result_item.service = substring_sr->service ;
|
search_result_item.service = substring_sr->service ;
|
||||||
search_result_item.group_infos = results ;
|
search_result_item.group_infos = results ;
|
||||||
|
|
||||||
@ -1044,11 +1062,13 @@ void RsGxsNetTunnelService::receiveSearchResult(TurtleSearchRequestId request_id
|
|||||||
{
|
{
|
||||||
RsItem *item = RsGxsNetTunnelSerializer().deserialise(search_result_data,&search_result_data_len);
|
RsItem *item = RsGxsNetTunnelSerializer().deserialise(search_result_data,&search_result_data_len);
|
||||||
|
|
||||||
|
GXS_NET_TUNNEL_DEBUG() << " : received search result for search request " << std::hex << request_id << "" << std::endl;
|
||||||
|
|
||||||
RsGxsNetTunnelTurtleSearchGroupSummaryItem *result_gs = dynamic_cast<RsGxsNetTunnelTurtleSearchGroupSummaryItem *>(item) ;
|
RsGxsNetTunnelTurtleSearchGroupSummaryItem *result_gs = dynamic_cast<RsGxsNetTunnelTurtleSearchGroupSummaryItem *>(item) ;
|
||||||
|
|
||||||
if(result_gs != NULL)
|
if(result_gs != NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "Received group summary result for search request " << std::hex << request_id << " for service " << result_gs->service << std::dec << ": " << std::endl;
|
GXS_NET_TUNNEL_DEBUG() << " : result is of type group summary result for service " << result_gs->service << std::dec << ": " << std::endl;
|
||||||
|
|
||||||
for(auto it(result_gs->group_infos.begin());it!=result_gs->group_infos.end();++it)
|
for(auto it(result_gs->group_infos.begin());it!=result_gs->group_infos.end();++it)
|
||||||
std::cerr << " group " << (*it).group_id << ": " << (*it).group_name << ", " << (*it).number_of_messages << " messages, last is " << time(NULL)-(*it).last_message_ts << " secs ago." << std::endl;
|
std::cerr << " group " << (*it).group_id << ": " << (*it).group_name << ", " << (*it).number_of_messages << " messages, last is " << time(NULL)-(*it).last_message_ts << " secs ago." << std::endl;
|
||||||
|
@ -187,6 +187,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool getVirtualPeers(std::list<RsGxsNetTunnelVirtualPeerId>& peers) ; // returns the virtual peers for this service
|
bool getVirtualPeers(std::list<RsGxsNetTunnelVirtualPeerId>& peers) ; // returns the virtual peers for this service
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief serviceId
|
||||||
|
* Overloads the method in RsTurtleClientService.
|
||||||
|
* \return
|
||||||
|
* The service id for RsGxsNetTunnel.
|
||||||
|
*/
|
||||||
|
uint16_t serviceId() const ;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief sendData
|
* \brief sendData
|
||||||
* send data to this virtual peer, and takes memory ownership (deletes the item)
|
* send data to this virtual peer, and takes memory ownership (deletes the item)
|
||||||
|
@ -127,6 +127,8 @@ public:
|
|||||||
explicit p3GxsTunnelService(RsGixs *pids) ;
|
explicit p3GxsTunnelService(RsGixs *pids) ;
|
||||||
virtual void connectToTurtleRouter(p3turtle *) ;
|
virtual void connectToTurtleRouter(p3turtle *) ;
|
||||||
|
|
||||||
|
uint16_t serviceId() const { return RS_SERVICE_TYPE_GXS_TUNNEL ; }
|
||||||
|
|
||||||
// Creates the invite if the public key of the distant peer is available.
|
// Creates the invite if the public key of the distant peer is available.
|
||||||
// Om success, stores the invite in the map above, so that we can respond to tunnel requests.
|
// Om success, stores the invite in the map above, so that we can respond to tunnel requests.
|
||||||
//
|
//
|
||||||
|
@ -1621,6 +1621,11 @@ int RsServer::StartupRetroShare()
|
|||||||
serviceCtrl->registerServiceMonitor(mBwCtrl, mBwCtrl->getServiceInfo().mServiceType);
|
serviceCtrl->registerServiceMonitor(mBwCtrl, mBwCtrl->getServiceInfo().mServiceType);
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
// Turtle search for GXS services
|
||||||
|
|
||||||
|
mGxsNetTunnel->registerSearchableService(gxschannels_ns) ;
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
|
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
|
||||||
//
|
//
|
||||||
|
@ -47,7 +47,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define DEBUG_IDS 1
|
|
||||||
/****
|
/****
|
||||||
* #define DEBUG_IDS 1
|
* #define DEBUG_IDS 1
|
||||||
* #define DEBUG_RECOGN 1
|
* #define DEBUG_RECOGN 1
|
||||||
|
@ -930,7 +930,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||||||
#endif
|
#endif
|
||||||
std::list<RsTurtleSearchResultItem*> search_results ;
|
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)
|
for(auto it(search_results.begin());it!=search_results.end();++it)
|
||||||
sendItem(*it) ;
|
sendItem(*it) ;
|
||||||
@ -999,6 +999,97 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||||||
#endif
|
#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)
|
void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
||||||
{
|
{
|
||||||
std::list<std::pair<RsTurtleSearchResultItem*,RsTurtleClientService*> > results_to_notify_off_mutex ;
|
std::list<std::pair<RsTurtleSearchResultItem*,RsTurtleClientService*> > results_to_notify_off_mutex ;
|
||||||
@ -1771,59 +1862,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
|||||||
// ------------------------------ IO with libretroshare ----------------------------//
|
// ------------------------------ 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
|
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.
|
// Form a request packet that simulates a request from us.
|
||||||
//
|
//
|
||||||
RsTurtleGenericSearchRequestItem *item = new RsTurtleGenericSearchRequestItem ;
|
RsTurtleGenericSearchRequestItem item ;
|
||||||
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "performing search. OwnId = " << _own_id << std::endl ;
|
std::cerr << "performing search. OwnId = " << _own_id << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
item->PeerId(_own_id) ;
|
item.PeerId(_own_id) ;
|
||||||
item->service_id = client_service->serviceId();
|
item.service_id = client_service->serviceId();
|
||||||
item->search_data = search_bin_data ;
|
item.search_data = search_bin_data ;
|
||||||
item->search_data_len = search_bin_data_len ;
|
item.search_data_len = search_bin_data_len ;
|
||||||
item->request_id = id ;
|
item.request_id = id ;
|
||||||
item->depth = 0 ;
|
item.depth = 0 ;
|
||||||
|
|
||||||
// send it
|
// send it
|
||||||
|
|
||||||
handleSearchRequest(item) ;
|
handleSearchRequest(&item) ;
|
||||||
|
|
||||||
return id ;
|
return id ;
|
||||||
}
|
}
|
||||||
@ -2056,10 +2095,10 @@ bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId&
|
|||||||
if(_registered_services.empty())
|
if(_registered_services.empty())
|
||||||
std::cerr << "Turtle router has no services registered. Tunnel requests cannot be handled." << std::endl;
|
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)
|
for(auto it(_registered_services.begin());it!=_registered_services.end();++it)
|
||||||
if( (*it)->handleTunnelRequest(hash,peer_id))
|
if( (*it).second->handleTunnelRequest(hash,peer_id))
|
||||||
{
|
{
|
||||||
service = *it ;
|
service = it->second ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2069,14 +2108,9 @@ bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId&
|
|||||||
|
|
||||||
void p3turtle::registerTunnelService(RsTurtleClientService *service)
|
void p3turtle::registerTunnelService(RsTurtleClientService *service)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
std::cerr << "p3turtle: registered new tunnel service with ID=" << std::hex << service->serviceId() << std::dec << " and pointer " << (void*)service << std::endl;
|
||||||
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;
|
|
||||||
|
|
||||||
_registered_services.push_back(service) ;
|
_registered_services[service->serviceId()] = service ;
|
||||||
_serialiser->registerClientService(service) ;
|
_serialiser->registerClientService(service) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +397,9 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||||||
//------ Functions connecting the turtle router to other components.----------//
|
//------ Functions connecting the turtle router to other components.----------//
|
||||||
|
|
||||||
/// Performs a search calling local cache and search structure.
|
/// 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.
|
/// 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);
|
virtual bool performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId& client_peer_id,RsTurtleClientService *& service);
|
||||||
@ -434,7 +436,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||||||
std::set<TurtleFileHash> _hashes_to_remove ;
|
std::set<TurtleFileHash> _hashes_to_remove ;
|
||||||
|
|
||||||
/// List of client services that have regitered.
|
/// 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_clean_time ;
|
||||||
time_t _last_tunnel_management_time ;
|
time_t _last_tunnel_management_time ;
|
||||||
|
@ -75,9 +75,11 @@ RsTurtleSearchRequestItem *RsTurtleGenericSearchRequestItem::clone() const
|
|||||||
{
|
{
|
||||||
RsTurtleGenericSearchRequestItem *sr = new RsTurtleGenericSearchRequestItem ;
|
RsTurtleGenericSearchRequestItem *sr = new RsTurtleGenericSearchRequestItem ;
|
||||||
|
|
||||||
|
memcpy(sr,this,sizeof(RsTurtleGenericSearchRequestItem)) ;
|
||||||
|
|
||||||
sr->search_data = (unsigned char*)rs_malloc(search_data_len) ;
|
sr->search_data = (unsigned char*)rs_malloc(search_data_len) ;
|
||||||
memcpy(sr->search_data,search_data,search_data_len) ;
|
memcpy(sr->search_data,search_data,search_data_len) ;
|
||||||
sr->search_data_len = search_data_len ;
|
|
||||||
return sr ;
|
return sr ;
|
||||||
}
|
}
|
||||||
template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r)
|
template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r)
|
||||||
|
@ -58,25 +58,17 @@ class RsTurtleItem: public RsItem
|
|||||||
// | |
|
// | |
|
||||||
// | +---- RsTurtleFileSearchRequestItem
|
// | +---- RsTurtleFileSearchRequestItem
|
||||||
// | | |
|
// | | |
|
||||||
// | | +---- RsTurtleFileSearchRequestItem
|
|
||||||
// | | |
|
|
||||||
// | | +---- RsTurtleStringSearchRequestItem
|
// | | +---- RsTurtleStringSearchRequestItem
|
||||||
// | | |
|
// | | |
|
||||||
// | | +---- RsTurtleReqExpSearchRequestItem
|
// | | +---- RsTurtleReqExpSearchRequestItem
|
||||||
// | |
|
// | |
|
||||||
// | +---- RsTurtleGxsSearchRequestItem
|
// | +---- RsTurtleGenericSearchRequestItem
|
||||||
// | |
|
|
||||||
// | +---- RsTurtleGxsGroupRequestItem
|
|
||||||
// |
|
// |
|
||||||
// +---- RsTurtleSearchResultItem
|
// +---- RsTurtleSearchResultItem
|
||||||
// |
|
// |
|
||||||
// +---- RsTurtleFTSearchResultItem
|
// +---- RsTurtleFTSearchResultItem
|
||||||
// |
|
// |
|
||||||
// +---- RsTurtleGxsSearchResultItem
|
// +---- RsTurtleGenericSearchResultItem
|
||||||
// |
|
|
||||||
// +---- RsTurtleGxsSearchResultGroupSummaryItem
|
|
||||||
// |
|
|
||||||
// +---- RsTurtleGxsSearchResultGroupDataItem
|
|
||||||
//
|
//
|
||||||
|
|
||||||
class RsTurtleSearchResultItem ;
|
class RsTurtleSearchResultItem ;
|
||||||
@ -89,8 +81,6 @@ class RsTurtleSearchRequestItem: public RsTurtleItem
|
|||||||
|
|
||||||
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(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const = 0 ; // abstracts the search method
|
|
||||||
|
|
||||||
virtual std::string GetKeywords() = 0;
|
virtual std::string GetKeywords() = 0;
|
||||||
|
|
||||||
uint32_t request_id ; // randomly generated request id.
|
uint32_t request_id ; // randomly generated request id.
|
||||||
@ -103,9 +93,6 @@ class RsTurtleFileSearchRequestItem: public RsTurtleSearchRequestItem
|
|||||||
RsTurtleFileSearchRequestItem(uint32_t subtype) : RsTurtleSearchRequestItem(subtype) {}
|
RsTurtleFileSearchRequestItem(uint32_t subtype) : RsTurtleSearchRequestItem(subtype) {}
|
||||||
virtual ~RsTurtleFileSearchRequestItem() {}
|
virtual ~RsTurtleFileSearchRequestItem() {}
|
||||||
|
|
||||||
virtual void performLocalSearch(TurtleSearchRequestInfo& req,std::list<RsTurtleSearchResultItem*>&) const ; // abstracts the search method
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void search(std::list<TurtleFileInfo> &) const =0;
|
virtual void search(std::list<TurtleFileInfo> &) const =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,8 +102,9 @@ class RsTurtleStringSearchRequestItem: public RsTurtleFileSearchRequestItem
|
|||||||
RsTurtleStringSearchRequestItem() : RsTurtleFileSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {}
|
RsTurtleStringSearchRequestItem() : RsTurtleFileSearchRequestItem(RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST) {}
|
||||||
virtual ~RsTurtleStringSearchRequestItem() {}
|
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; }
|
std::string GetKeywords() { return match_string; }
|
||||||
|
|
||||||
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; }
|
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleStringSearchRequestItem(*this) ; }
|
||||||
@ -124,7 +112,6 @@ class RsTurtleStringSearchRequestItem: public RsTurtleFileSearchRequestItem
|
|||||||
void clear() { match_string.clear() ; }
|
void clear() { match_string.clear() ; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void search(std::list<TurtleFileInfo> &) const ;
|
|
||||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -144,10 +131,11 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleFileSearchRequestItem
|
|||||||
return exs;
|
return exs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void search(std::list<TurtleFileInfo> &) const ;
|
||||||
|
|
||||||
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; }
|
virtual RsTurtleSearchRequestItem *clone() const { return new RsTurtleRegExpSearchRequestItem(*this) ; }
|
||||||
void clear() { expr = RsRegularExpression::LinearizedExpression(); }
|
void clear() { expr = RsRegularExpression::LinearizedExpression(); }
|
||||||
protected:
|
protected:
|
||||||
virtual void search(std::list<TurtleFileInfo> &) const ;
|
|
||||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -166,7 +154,6 @@ class RsTurtleGenericSearchRequestItem: public RsTurtleSearchRequestItem
|
|||||||
virtual RsTurtleSearchRequestItem *clone() const ;
|
virtual RsTurtleSearchRequestItem *clone() const ;
|
||||||
void clear() { free(search_data); search_data=NULL; search_data_len=0; }
|
void clear() { free(search_data); search_data=NULL; search_data_len=0; }
|
||||||
|
|
||||||
virtual void performLocalSearch(TurtleSearchRequestInfo &req, std::list<RsTurtleSearchResultItem*>& result) const;
|
|
||||||
protected:
|
protected:
|
||||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user