mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
RsGxsChannels local search support
This commit is contained in:
parent
f670a18b13
commit
2b58e3f461
@ -3429,3 +3429,9 @@ void RsGenExchange::turtleSearchRequest(const std::string& match_string)
|
|||||||
{
|
{
|
||||||
mNetService->turtleSearchRequest(match_string) ;
|
mNetService->turtleSearchRequest(match_string) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RsGenExchange::localSearch( const std::string& matchString,
|
||||||
|
std::list<RsGxsGroupSummary>& results )
|
||||||
|
{
|
||||||
|
return mNetService->search(matchString, results);
|
||||||
|
}
|
||||||
|
@ -313,6 +313,15 @@ public:
|
|||||||
void turtleGroupRequest(const RsGxsGroupId& group_id);
|
void turtleGroupRequest(const RsGxsGroupId& group_id);
|
||||||
void turtleSearchRequest(const std::string& match_string);
|
void turtleSearchRequest(const std::string& match_string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Search local groups. Blocking API.
|
||||||
|
* @param matchString string to look for in the search
|
||||||
|
* @param results storage for results
|
||||||
|
* @return false on error, true otherwise
|
||||||
|
*/
|
||||||
|
bool localSearch( const std::string& matchString,
|
||||||
|
std::list<RsGxsGroupSummary>& results );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool messagePublicationTest(const RsGxsMsgMetaData&) ;
|
bool messagePublicationTest(const RsGxsMsgMetaData&) ;
|
||||||
|
@ -287,6 +287,19 @@ public:
|
|||||||
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
|
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
|
||||||
rstime_t maxWait = 300 ) = 0;
|
rstime_t maxWait = 300 ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Search local channels
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] matchString string to look for in the search
|
||||||
|
* @param multiCallback function that will be called for each result
|
||||||
|
* @param[in] maxWait maximum wait time in seconds for search results
|
||||||
|
* @return false on error, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool localSearchRequest(
|
||||||
|
const std::string& matchString,
|
||||||
|
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
|
||||||
|
rstime_t maxWait = 30 ) = 0;
|
||||||
|
|
||||||
|
|
||||||
/* Following functions are deprecated as they expose internal functioning
|
/* Following functions are deprecated as they expose internal functioning
|
||||||
* semantic, instead of a safe to use API */
|
* semantic, instead of a safe to use API */
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "retroshare/rsnotify.h"
|
#include "retroshare/rsnotify.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
// For Dummy Msgs.
|
// For Dummy Msgs.
|
||||||
#include "util/rsrandom.h"
|
#include "util/rsrandom.h"
|
||||||
@ -50,7 +51,7 @@
|
|||||||
* #define GXSCHANNEL_DEBUG 1
|
* #define GXSCHANNEL_DEBUG 1
|
||||||
****/
|
****/
|
||||||
|
|
||||||
/*extern*/ RsGxsChannels *rsGxsChannels = nullptr;
|
/*extern*/ RsGxsChannels* rsGxsChannels = nullptr;
|
||||||
|
|
||||||
|
|
||||||
#define GXSCHANNEL_STOREPERIOD (3600 * 24 * 30)
|
#define GXSCHANNEL_STOREPERIOD (3600 * 24 * 30)
|
||||||
@ -1969,6 +1970,31 @@ bool p3GxsChannels::turtleChannelRequest(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @see RsGxsChannels::localSearchRequest
|
||||||
|
bool p3GxsChannels::localSearchRequest(
|
||||||
|
const std::string& matchString,
|
||||||
|
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
|
||||||
|
rstime_t maxWait )
|
||||||
|
{
|
||||||
|
if(matchString.empty())
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << " match string can't be empty!"
|
||||||
|
<< std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto timeout = std::chrono::steady_clock::now() + std::chrono::seconds(maxWait);
|
||||||
|
RsThread::async([=]()
|
||||||
|
{
|
||||||
|
std::list<RsGxsGroupSummary> results;
|
||||||
|
RsGenExchange::localSearch(matchString, results);
|
||||||
|
if(std::chrono::steady_clock::now() < timeout)
|
||||||
|
for(const RsGxsGroupSummary& result : results) multiCallback(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void p3GxsChannels::receiveDistantSearchResults(
|
void p3GxsChannels::receiveDistantSearchResults(
|
||||||
TurtleRequestId id, const RsGxsGroupId& grpId )
|
TurtleRequestId id, const RsGxsGroupId& grpId )
|
||||||
{
|
{
|
||||||
|
@ -118,6 +118,11 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
|
|||||||
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
|
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
|
||||||
rstime_t maxWait = 300 );
|
rstime_t maxWait = 300 );
|
||||||
|
|
||||||
|
/// @see RsGxsChannels::localSearchRequest
|
||||||
|
virtual bool localSearchRequest(const std::string& matchString,
|
||||||
|
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
|
||||||
|
rstime_t maxWait = 30 ) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver
|
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver
|
||||||
* @see RsGxsNetService::receiveTurtleSearchResults
|
* @see RsGxsNetService::receiveTurtleSearchResults
|
||||||
|
Loading…
Reference in New Issue
Block a user