2018-02-01 18:06:49 +01:00
|
|
|
#ifndef LLARP_DHT_H_
|
|
|
|
#define LLARP_DHT_H_
|
2018-05-25 11:17:08 +02:00
|
|
|
|
2018-06-01 16:08:54 +02:00
|
|
|
#include <llarp/buffer.h>
|
2018-06-01 23:35:17 +02:00
|
|
|
#include <llarp/router.h>
|
2018-06-01 16:08:54 +02:00
|
|
|
|
2018-05-25 11:17:08 +02:00
|
|
|
/**
|
|
|
|
* dht.h
|
|
|
|
*
|
|
|
|
* DHT functions
|
|
|
|
*/
|
|
|
|
|
2018-02-01 18:07:01 +01:00
|
|
|
struct llarp_dht_context;
|
2018-02-01 18:06:49 +01:00
|
|
|
|
2018-05-25 11:17:08 +02:00
|
|
|
/// allocator
|
2018-05-22 17:54:19 +02:00
|
|
|
struct llarp_dht_context*
|
2018-06-01 23:35:17 +02:00
|
|
|
llarp_dht_context_new(struct llarp_router* parent);
|
2018-05-25 11:17:08 +02:00
|
|
|
|
|
|
|
/// deallocator
|
2018-05-22 17:54:19 +02:00
|
|
|
void
|
|
|
|
llarp_dht_context_free(struct llarp_dht_context* dht);
|
2018-02-01 18:06:49 +01:00
|
|
|
|
2018-06-01 23:35:17 +02:00
|
|
|
/// start dht context with our location in keyspace
|
2018-06-01 16:08:54 +02:00
|
|
|
void
|
2018-06-01 23:35:17 +02:00
|
|
|
llarp_dht_context_start(struct llarp_dht_context* ctx, const byte_t* key);
|
2018-06-01 16:08:54 +02:00
|
|
|
|
2018-06-01 23:35:17 +02:00
|
|
|
struct llarp_router_lookup_job;
|
|
|
|
|
2018-06-18 09:54:50 +02:00
|
|
|
typedef void (*llarp_router_lookup_handler)(struct llarp_router_lookup_job*);
|
2018-06-01 23:35:17 +02:00
|
|
|
|
|
|
|
struct llarp_router_lookup_job
|
|
|
|
{
|
2018-06-28 13:33:52 +02:00
|
|
|
/// can be anything but usually a class context for hook
|
2018-06-01 23:35:17 +02:00
|
|
|
void* user;
|
2018-06-18 09:54:50 +02:00
|
|
|
llarp_router_lookup_handler hook;
|
2018-06-01 23:35:17 +02:00
|
|
|
struct llarp_dht_context* dht;
|
2018-06-12 13:57:14 +02:00
|
|
|
byte_t target[PUBKEYSIZE];
|
2018-06-01 23:35:17 +02:00
|
|
|
bool found;
|
2018-07-08 15:22:02 +02:00
|
|
|
// make sure you initialize addr and exits
|
2018-06-06 14:59:15 +02:00
|
|
|
struct llarp_rc result;
|
2018-07-08 15:22:02 +02:00
|
|
|
bool iterative;
|
2018-06-01 23:35:17 +02:00
|
|
|
};
|
|
|
|
|
2018-06-13 18:32:34 +02:00
|
|
|
/// start allowing dht participation on a context
|
|
|
|
void
|
|
|
|
llarp_dht_allow_transit(struct llarp_dht_context* ctx);
|
|
|
|
|
2018-06-14 16:04:42 +02:00
|
|
|
/// put router as a dht peer
|
2018-06-01 23:35:17 +02:00
|
|
|
void
|
2018-06-14 16:04:42 +02:00
|
|
|
llarp_dht_put_peer(struct llarp_dht_context* ctx, struct llarp_rc* rc);
|
2018-06-01 23:35:17 +02:00
|
|
|
|
2018-06-14 16:04:42 +02:00
|
|
|
/// remove router from tracked dht peer list
|
2018-06-01 23:35:17 +02:00
|
|
|
void
|
2018-06-14 16:04:42 +02:00
|
|
|
llarp_dht_remove_peer(struct llarp_dht_context* ctx, const byte_t* id);
|
2018-06-01 23:35:17 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
llarp_dht_lookup_router(struct llarp_dht_context* ctx,
|
|
|
|
struct llarp_router_lookup_job* job);
|
|
|
|
|
2018-02-01 18:06:49 +01:00
|
|
|
#endif
|