lokinet/llarp/dht/search_job.cpp
Jeff Becker fe01c38d8e
* fix dht feedback loop
* start on dht lookups for hidden services

* make debug logging confurable on runtime with env var LLARP_DEBUG=1

* make eventloop tick only when we get traffic

* make testnet parameters configurable on runtime
2018-07-12 09:43:37 -04:00

78 lines
1.7 KiB
C++

#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,
const std::set< Key_t > &excludes,
llarp_router_lookup_job *j)
: job(j)
, started(llarp_time_now_ms())
, requester(asker)
, requesterTX(tx)
, target(key)
, exclude(excludes)
{
}
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)
{
}
void
SearchJob::FoundIntro(const llarp::service::IntroSet *introset) const
{
if(foundIntroHook)
foundIntroHook(introset);
}
void
SearchJob::FoundRouter(const llarp_rc *router) const
{
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;
}
void
SearchJob::Timeout() const
{
if(job)
{
job->found = false;
job->hook(job);
}
else if(foundIntroHook)
{
foundIntroHook(nullptr);
}
}
} // namespace dht
} // namespace llarp