2018-06-18 22:03:50 +00:00
|
|
|
#include <llarp/nodedb.h>
|
|
|
|
#include <llarp/path.hpp>
|
|
|
|
|
|
|
|
#include "pathbuilder.hpp"
|
|
|
|
#include "router.hpp"
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
PathHopConfig::PathHopConfig()
|
|
|
|
{
|
|
|
|
llarp_rc_clear(&router);
|
|
|
|
}
|
|
|
|
|
|
|
|
PathHopConfig::~PathHopConfig()
|
|
|
|
{
|
|
|
|
llarp_rc_free(&router);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pathbuilder_generated_keys(
|
|
|
|
AsyncPathKeyExchangeContext< llarp_pathbuild_job >* ctx)
|
|
|
|
{
|
|
|
|
llarp::Debug("Generated keys for build");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pathbuilder_start_build(void* user)
|
|
|
|
{
|
|
|
|
// select hops
|
|
|
|
llarp_pathbuild_job* job = static_cast< llarp_pathbuild_job* >(user);
|
|
|
|
size_t idx = 0;
|
|
|
|
while(idx < job->hops.numHops)
|
|
|
|
{
|
|
|
|
job->selectHop(job->router->nodedb, &job->hops.routers[idx], idx);
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// async generate keys
|
|
|
|
AsyncPathKeyExchangeContext< llarp_pathbuild_job >* ctx =
|
|
|
|
new AsyncPathKeyExchangeContext< llarp_pathbuild_job >(
|
|
|
|
&job->router->crypto);
|
|
|
|
|
|
|
|
ctx->AsyncGenerateKeys(new Path(&job->hops), job->router->logic,
|
|
|
|
job->router->tp, job, &pathbuilder_generated_keys);
|
|
|
|
// free rc
|
|
|
|
idx = 0;
|
|
|
|
while(idx < job->hops.numHops)
|
|
|
|
{
|
|
|
|
llarp_rc_free(&job->hops.routers[idx]);
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
llarp_pathbuilder_context::llarp_pathbuilder_context(
|
|
|
|
llarp_router* p_router, struct llarp_dht_context* p_dht)
|
|
|
|
{
|
|
|
|
this->router = p_router;
|
|
|
|
this->dht = p_dht;
|
|
|
|
}
|
|
|
|
|
2018-06-18 22:05:02 +00:00
|
|
|
extern "C" {
|
|
|
|
struct llarp_pathbuilder_context*
|
|
|
|
llarp_pathbuilder_context_new(struct llarp_router* router,
|
|
|
|
struct llarp_dht_context* dht)
|
2018-06-18 22:03:50 +00:00
|
|
|
{
|
2018-06-18 22:05:02 +00:00
|
|
|
return new llarp_pathbuilder_context(router, dht);
|
|
|
|
}
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2018-06-18 22:05:02 +00:00
|
|
|
void
|
|
|
|
llarp_pathbuilder_context_free(struct llarp_pathbuilder_context* ctx)
|
|
|
|
{
|
|
|
|
delete ctx;
|
|
|
|
}
|
2018-06-18 22:03:50 +00:00
|
|
|
|
2018-06-18 22:05:02 +00:00
|
|
|
void
|
|
|
|
llarp_pathbuilder_build_path(struct llarp_pathbuild_job* job)
|
|
|
|
{
|
2018-06-19 09:19:23 +00:00
|
|
|
if (!job->context)
|
|
|
|
{
|
|
|
|
llarp::Error("failed to build path because no context is set in job");
|
|
|
|
return;
|
|
|
|
}
|
2018-06-18 22:05:02 +00:00
|
|
|
job->router = job->context->router;
|
|
|
|
llarp_logic_queue_job(job->router->logic,
|
|
|
|
{job, &llarp::pathbuilder_start_build});
|
|
|
|
}
|
2018-06-19 09:19:23 +00:00
|
|
|
}
|