2018-07-11 13:20:14 +00:00
|
|
|
#include <llarp/dht/search_job.hpp>
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
SearchJob::SearchJob()
|
|
|
|
{
|
|
|
|
started = 0;
|
|
|
|
requester.Zero();
|
|
|
|
target.Zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchJob::SearchJob(const Key_t &asker, uint64_t tx, const Key_t &key,
|
2018-07-12 13:43:37 +00:00
|
|
|
const std::set< Key_t > &excludes,
|
|
|
|
llarp_router_lookup_job *j)
|
2018-07-11 13:20:14 +00:00
|
|
|
: job(j)
|
|
|
|
, started(llarp_time_now_ms())
|
|
|
|
, requester(asker)
|
|
|
|
, requesterTX(tx)
|
|
|
|
, target(key)
|
|
|
|
, exclude(excludes)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-12 13:43:37 +00:00
|
|
|
SearchJob::SearchJob(const Key_t &asker, uint64_t tx, const Key_t &key,
|
|
|
|
const std::set< Key_t > &excludes,
|
|
|
|
IntroSetHookFunc foundIntroset)
|
|
|
|
: foundIntroHook(foundIntroset)
|
|
|
|
, started(llarp_time_now_ms())
|
|
|
|
, requester(asker)
|
|
|
|
, requesterTX(tx)
|
|
|
|
, target(key)
|
|
|
|
, exclude(excludes)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-18 20:58:16 +00:00
|
|
|
SearchJob::SearchJob(const Key_t &asker, uint64_t tx,
|
|
|
|
IntroSetHookFunc found)
|
|
|
|
: foundIntroHook(found)
|
|
|
|
, started(llarp_time_now_ms())
|
|
|
|
, requester(asker)
|
|
|
|
, requesterTX(tx)
|
|
|
|
{
|
|
|
|
target.Zero();
|
|
|
|
}
|
|
|
|
|
2018-07-12 13:43:37 +00:00
|
|
|
void
|
2018-07-18 03:10:21 +00:00
|
|
|
SearchJob::FoundIntros(
|
2018-07-20 04:50:28 +00:00
|
|
|
const std::vector< llarp::service::IntroSet > &introsets) const
|
2018-07-12 13:43:37 +00:00
|
|
|
{
|
|
|
|
if(foundIntroHook)
|
2018-07-18 03:10:21 +00:00
|
|
|
foundIntroHook(introsets);
|
2018-07-12 13:43:37 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
void
|
2018-07-12 13:43:37 +00:00
|
|
|
SearchJob::FoundRouter(const llarp_rc *router) const
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
|
|
|
if(job && job->hook)
|
|
|
|
{
|
|
|
|
if(router)
|
|
|
|
{
|
|
|
|
job->found = true;
|
|
|
|
llarp_rc_copy(&job->result, router);
|
|
|
|
}
|
|
|
|
job->hook(job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SearchJob::IsExpired(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
return now - started >= JobTimeout;
|
|
|
|
}
|
2018-07-12 13:43:37 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SearchJob::Timeout() const
|
|
|
|
{
|
|
|
|
if(job)
|
|
|
|
{
|
|
|
|
job->found = false;
|
|
|
|
job->hook(job);
|
|
|
|
}
|
|
|
|
else if(foundIntroHook)
|
|
|
|
{
|
2018-07-18 03:10:21 +00:00
|
|
|
foundIntroHook({});
|
2018-07-12 13:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|