lokinet/llarp/dht.cpp

62 lines
1.3 KiB
C++
Raw Normal View History

2018-07-11 13:21:44 +00:00
#include <llarp/dht.h>
2018-06-01 14:08:54 +00:00
#include "router.hpp"
2018-06-13 16:32:34 +00:00
#include "router_contact.hpp"
2018-06-01 14:08:54 +00:00
2018-06-01 21:35:17 +00:00
llarp_dht_context::llarp_dht_context(llarp_router *router)
{
parent = router;
}
2018-07-09 12:30:01 +00:00
struct llarp_dht_context *
llarp_dht_context_new(struct llarp_router *router)
2018-06-01 14:08:54 +00:00
{
2018-07-09 12:30:01 +00:00
return new llarp_dht_context(router);
}
2018-06-01 14:08:54 +00:00
2018-07-09 12:30:01 +00:00
void
llarp_dht_context_free(struct llarp_dht_context *ctx)
{
delete ctx;
}
2018-06-01 14:08:54 +00:00
2018-07-09 12:30:01 +00:00
void
llarp_dht_put_peer(struct llarp_dht_context *ctx, struct llarp_rc *rc)
2018-06-01 21:35:17 +00:00
2018-07-09 12:30:01 +00:00
{
llarp::dht::RCNode n(rc);
2018-07-13 09:27:13 +00:00
llarp::LogDebug("Adding ", n.ID, " to DHT");
2018-07-09 12:30:01 +00:00
ctx->impl.nodes->PutNode(n);
}
2018-06-01 21:35:17 +00:00
2018-07-09 12:30:01 +00:00
void
llarp_dht_remove_peer(struct llarp_dht_context *ctx, const byte_t *id)
{
llarp::dht::Key_t k = id;
2018-07-13 09:27:13 +00:00
llarp::LogDebug("Removing ", k, " to DHT");
2018-07-09 12:30:01 +00:00
ctx->impl.nodes->DelNode(k);
}
2018-06-01 21:35:17 +00:00
2018-07-09 12:30:01 +00:00
void
llarp_dht_allow_transit(llarp_dht_context *ctx)
{
ctx->impl.allowTransit = true;
}
2018-06-13 16:32:34 +00:00
2018-07-09 12:30:01 +00:00
void
llarp_dht_context_start(struct llarp_dht_context *ctx, const byte_t *key)
{
ctx->impl.Init(key, ctx->parent);
}
2018-06-01 21:35:17 +00:00
2018-07-09 12:30:01 +00:00
void
llarp_dht_lookup_router(struct llarp_dht_context *ctx,
struct llarp_router_lookup_job *job)
{
job->dht = ctx;
job->found = false;
2018-07-16 03:32:13 +00:00
// TODO: check for reuse
llarp_rc_clear(&job->result);
2018-07-09 12:30:01 +00:00
llarp_logic_queue_job(ctx->parent->logic,
{job, &llarp::dht::Context::queue_router_lookup});
}