1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/include/llarp/dht.h

73 lines
1.5 KiB
C
Raw Normal View History

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:06:49 +01:00
#ifdef __cplusplus
extern "C" {
#endif
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
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
void
llarp_dht_context_free(struct llarp_dht_context* dht);
2018-02-01 18:06:49 +01:00
2018-06-01 16:08:54 +02:00
struct llarp_dht_msg;
/// handler function
/// f(outmsg, inmsg)
/// returns true if outmsg has been filled otherwise returns false
typedef bool (*llarp_dht_msg_handler)(struct llarp_dht_msg*,
struct llarp_dht_msg*);
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
// override dht message handler with custom handler
void
llarp_dht_set_msg_handler(struct llarp_dht_context* ctx,
llarp_dht_msg_handler func);
2018-06-01 23:35:17 +02:00
struct llarp_router_lookup_job;
typedef void (*llarp_rotuer_lookup_handler)(struct llarp_router_lookup_job*);
struct llarp_router_lookup_job
{
void* user;
llarp_rotuer_lookup_handler hook;
struct llarp_dht_context* dht;
llarp_pubkey_t target;
bool found;
llarp_rc result;
};
// shallow copy
void
llarp_dht_put_local_router(struct llarp_dht_context* ctx, struct llarp_rc* rc);
void
llarp_dht_remove_local_router(struct llarp_dht_context* ctx, const byte_t* id);
void
llarp_dht_lookup_router(struct llarp_dht_context* ctx,
struct llarp_router_lookup_job* job);
2018-02-01 18:06:49 +01:00
#ifdef __cplusplus
}
#endif
#endif