2018-04-08 12:18:16 +00:00
|
|
|
#ifndef LLARP_NODEDB_H
|
|
|
|
#define LLARP_NODEDB_H
|
|
|
|
#include <llarp/common.h>
|
|
|
|
#include <llarp/crypto.h>
|
2018-05-30 20:56:47 +00:00
|
|
|
#include <llarp/router_contact.h>
|
2018-05-31 13:08:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* nodedb.h
|
|
|
|
*
|
|
|
|
* persistent storage API for router contacts
|
|
|
|
*/
|
|
|
|
|
2018-04-08 12:18:16 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-04-30 16:14:20 +00:00
|
|
|
struct llarp_nodedb;
|
|
|
|
|
|
|
|
/** create an empty nodedb */
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_nodedb *
|
2018-05-28 13:49:44 +00:00
|
|
|
llarp_nodedb_new(struct llarp_crypto *crypto);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
|
|
|
/** free a nodedb and all loaded rc */
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_nodedb_free(struct llarp_nodedb **n);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
|
|
|
/** ensure a nodedb fs skiplist structure is at dir
|
|
|
|
create if not there.
|
|
|
|
*/
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_nodedb_ensure_dir(const char *dir);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
|
|
|
/** load entire nodedb from fs skiplist at dir */
|
2018-05-22 15:54:19 +00:00
|
|
|
ssize_t
|
|
|
|
llarp_nodedb_load_dir(struct llarp_nodedb *n, const char *dir);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
|
|
|
/** store entire nodedb to fs skiplist at dir */
|
2018-05-22 15:54:19 +00:00
|
|
|
ssize_t
|
|
|
|
llarp_nodedb_store_dir(struct llarp_nodedb *n, const char *dir);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_nodedb_iter
|
|
|
|
{
|
2018-04-30 16:14:20 +00:00
|
|
|
void *user;
|
|
|
|
struct llarp_rc *rc;
|
|
|
|
bool (*visit)(struct llarp_nodedb_iter *);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
iterate over all loaded rc with an iterator
|
|
|
|
*/
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_nodedb_iterate_all(struct llarp_nodedb *n, struct llarp_nodedb_iter i);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
find rc by rc.k being value k
|
|
|
|
returns true if found otherwise returns false
|
|
|
|
*/
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_nodedb_find_rc(struct llarp_nodedb *n, struct llarp_rc *rc,
|
2018-06-12 11:57:14 +00:00
|
|
|
const byte_t *k);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
2018-05-30 20:56:47 +00:00
|
|
|
/**
|
|
|
|
return true if we have a rc with rc.k of value k on disk
|
|
|
|
otherwise return false
|
|
|
|
*/
|
|
|
|
bool
|
2018-06-12 11:57:14 +00:00
|
|
|
llarp_nodedb_has_rc(struct llarp_nodedb *n, const byte_t *k);
|
2018-05-30 20:56:47 +00:00
|
|
|
|
2018-04-30 16:14:20 +00:00
|
|
|
/**
|
|
|
|
put an rc into the node db
|
|
|
|
overwrites with new contents if already present
|
|
|
|
flushes the single entry to disk
|
|
|
|
returns true on success and false on error
|
|
|
|
*/
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_nodedb_put_rc(struct llarp_nodedb *n, struct llarp_rc *rc);
|
2018-04-30 16:14:20 +00:00
|
|
|
|
2018-05-30 20:56:47 +00:00
|
|
|
/**
|
|
|
|
struct for async rc verification
|
|
|
|
*/
|
|
|
|
struct llarp_async_verify_rc;
|
|
|
|
|
|
|
|
typedef void (*llarp_async_verify_rc_hook_func)(struct llarp_async_verify_rc *);
|
|
|
|
|
2018-05-31 13:08:06 +00:00
|
|
|
/// verify rc request
|
2018-05-30 20:56:47 +00:00
|
|
|
struct llarp_async_verify_rc
|
|
|
|
{
|
2018-06-07 09:36:30 +00:00
|
|
|
/// async_verify_context
|
2018-05-30 20:56:47 +00:00
|
|
|
void *user;
|
2018-06-07 09:36:30 +00:00
|
|
|
/// nodedb storage
|
|
|
|
struct llarp_nodedb *nodedb;
|
|
|
|
// llarp_logic for llarp_logic_queue_job
|
|
|
|
struct llarp_logic *logic; // includes a llarp_threadpool
|
2018-06-13 11:40:49 +00:00
|
|
|
//struct llarp_crypto *crypto; // probably don't need this because we have it in the nodedb
|
2018-06-07 09:36:30 +00:00
|
|
|
struct llarp_threadpool *cryptoworker;
|
|
|
|
struct llarp_threadpool *diskworker;
|
|
|
|
|
2018-05-31 13:08:06 +00:00
|
|
|
/// router contact (should this be a pointer?)
|
2018-05-30 20:56:47 +00:00
|
|
|
struct llarp_rc rc;
|
2018-05-31 13:08:06 +00:00
|
|
|
/// result
|
2018-05-30 20:56:47 +00:00
|
|
|
bool valid;
|
2018-05-31 13:08:06 +00:00
|
|
|
/// hook
|
2018-05-30 20:56:47 +00:00
|
|
|
llarp_async_verify_rc_hook_func hook;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
struct for async rc verification
|
|
|
|
data is loaded in disk io threadpool
|
|
|
|
crypto is done on the crypto worker threadpool
|
|
|
|
result is called on the logic thread
|
|
|
|
*/
|
|
|
|
void
|
2018-06-13 11:40:49 +00:00
|
|
|
llarp_nodedb_async_verify(struct llarp_async_verify_rc *job);
|
2018-05-30 20:56:47 +00:00
|
|
|
|
2018-04-08 12:18:16 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|