You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/dht.cpp

73 lines
1.4 KiB
C++

6 years ago
#include <llarp/bencode.hpp>
#include <llarp/dht.hpp>
#include <llarp/messages/dht.hpp>
#include <llarp/messages/dht_immediate.hpp>
#include "router.hpp"
6 years ago
#include "router_contact.hpp"
#include <sodium.h>
6 years ago
#include <algorithm> // std::find
#include <set>
llarp_dht_context::llarp_dht_context(llarp_router *router)
{
parent = router;
}
6 years ago
struct llarp_dht_context *
llarp_dht_context_new(struct llarp_router *router)
{
6 years ago
return new llarp_dht_context(router);
}
6 years ago
void
llarp_dht_context_free(struct llarp_dht_context *ctx)
{
delete ctx;
}
6 years ago
void
llarp_dht_put_peer(struct llarp_dht_context *ctx, struct llarp_rc *rc)
6 years ago
{
llarp::dht::RCNode n(rc);
ctx->impl.nodes->PutNode(n);
}
6 years ago
void
llarp_dht_remove_peer(struct llarp_dht_context *ctx, const byte_t *id)
{
llarp::dht::Key_t k = id;
ctx->impl.nodes->DelNode(k);
}
6 years ago
void
llarp_dht_set_msg_handler(struct llarp_dht_context *ctx,
llarp_dht_msg_handler handler)
{
ctx->impl.custom_handler = handler;
}
6 years ago
void
llarp_dht_allow_transit(llarp_dht_context *ctx)
{
ctx->impl.allowTransit = true;
}
6 years ago
6 years ago
void
llarp_dht_context_start(struct llarp_dht_context *ctx, const byte_t *key)
{
ctx->impl.Init(key, ctx->parent);
}
6 years ago
void
llarp_dht_lookup_router(struct llarp_dht_context *ctx,
struct llarp_router_lookup_job *job)
{
job->dht = ctx;
job->found = false;
llarp_logic_queue_job(ctx->parent->logic,
{job, &llarp::dht::Context::queue_router_lookup});
}