lokinet/include/llarp.h

133 lines
3.5 KiB
C
Raw Normal View History

2018-01-25 16:24:33 +00:00
#ifndef LLARP_H_
#define LLARP_H_
2018-12-13 21:46:55 +00:00
#ifdef __cplusplus
#include <constants/version.hpp>
2019-01-11 01:19:36 +00:00
#include <ev/ev.h>
2018-12-12 01:12:59 +00:00
#include <handlers/tun.hpp> // for handlers
2018-12-12 02:15:08 +00:00
#include <service/address.hpp> // for service::address
#include <service/endpoint.hpp>
2019-09-01 13:26:16 +00:00
#include <util/thread/logic.hpp>
#include <util/mem.h>
2018-09-20 10:05:42 +00:00
2018-07-17 04:37:50 +00:00
extern "C"
{
2018-05-27 18:03:10 +00:00
#endif
2018-11-06 14:06:09 +00:00
/// ensure configuration exists
/// populate with defaults
/// return if this succeeded
/// if overwrite is true then overwrite old config file
/// if basedir is not nullptr then use basedir as an absolute
/// base path for all files in config
bool
llarp_ensure_config(const char *, const char *, bool overwrite,
bool asrouter);
2018-11-06 14:06:09 +00:00
2018-07-17 04:37:50 +00:00
/// llarp application context for C api
struct llarp_main;
2018-05-27 18:03:10 +00:00
2018-07-17 04:37:50 +00:00
/// initialize application context and load config
struct llarp_main *
llarp_main_init(const char *fname, bool multiProcess);
2018-05-27 18:03:10 +00:00
2018-07-17 04:37:50 +00:00
/// handle signal for main context
void
llarp_main_signal(struct llarp_main *ptr, int sig);
2018-05-27 18:03:10 +00:00
2019-04-08 15:54:19 +00:00
/// give main context a vpn file descriptor pair (android/ios)
void
2019-04-08 15:54:19 +00:00
llarp_main_inject_vpn_fd(struct llarp_main *m, int rfd, int wfd);
2018-12-13 21:46:55 +00:00
/// setup main context, returns 0 on success
2018-07-17 04:37:50 +00:00
int
2019-05-28 00:19:25 +00:00
llarp_main_setup(struct llarp_main *ptr, bool debugMode);
2018-12-13 21:46:55 +00:00
/// run main context, returns 0 on success, blocks until program end
2018-07-17 04:37:50 +00:00
int
llarp_main_run(struct llarp_main *ptr);
2018-05-27 18:03:10 +00:00
2018-12-13 21:46:55 +00:00
/// free main context and end all operations
void
llarp_main_free(struct llarp_main *ptr);
#ifdef __cplusplus
2018-07-17 04:37:50 +00:00
void
llarp_main_abort(struct llarp_main *ptr);
2018-12-13 21:46:55 +00:00
const char *
handleBaseCmdLineArgs(int argc, char *argv[]);
2018-07-17 04:37:50 +00:00
/// load nodeDB into memory
int
llarp_main_loadDatabase(struct llarp_main *ptr);
2018-07-17 04:37:50 +00:00
/// iterator on nodedb entries
int
llarp_main_iterateDatabase(struct llarp_main *ptr,
struct llarp_nodedb_iter i);
2018-07-17 04:37:50 +00:00
/// put RC into nodeDB
bool
2018-09-22 10:23:23 +00:00
llarp_main_putDatabase(struct llarp_main *ptr,
struct llarp::RouterContact &rc);
2018-07-17 04:37:50 +00:00
// fwd declr
struct check_online_request;
2018-07-17 04:37:50 +00:00
/// check_online_request hook definition
typedef void (*check_online_request_hook_func)(struct check_online_request *);
2018-07-17 04:37:50 +00:00
struct check_online_request
{
struct llarp_main *ptr;
struct llarp_router_lookup_job *job;
bool online;
size_t nodes;
bool first;
check_online_request_hook_func hook;
};
/// get RC from DHT but wait until online
2018-07-17 04:37:50 +00:00
void
llarp_main_queryDHT(struct check_online_request *request);
/// get RC from DHT
void
llarp_main_queryDHT_RC(struct llarp_main *ptr,
struct llarp_router_lookup_job *job);
/// set up DNS libs with a context
bool
llarp_main_init_dnsd(struct llarp_main *ptr, struct dnsd_context *dnsd,
2018-09-29 10:28:01 +00:00
const llarp::Addr &dnsd_sockaddr,
const llarp::Addr &dnsc_sockaddr);
2018-09-22 10:23:23 +00:00
/// set up dotLokiLookup with logic for setting timers
bool
llarp_main_init_dotLokiLookup(struct llarp_main *ptr,
struct dotLokiLookup *dll);
llarp::RouterContact *
2018-07-17 04:37:50 +00:00
llarp_main_getLocalRC(struct llarp_main *ptr);
2018-12-13 21:37:30 +00:00
/// get RC from nodeDB
llarp::RouterContact *
llarp_main_getDatabase(struct llarp_main *ptr, byte_t *pk);
llarp_tun_io *
main_router_getRange(struct llarp_main *ptr);
2018-10-10 15:14:45 +00:00
/// map an (host byte order) ip to a hidden service address
2018-09-20 10:05:42 +00:00
bool
2018-09-22 10:23:23 +00:00
main_router_mapAddress(struct llarp_main *ptr,
const llarp::service::Address &addr, uint32_t ip);
2018-09-20 10:05:42 +00:00
2018-09-21 12:53:20 +00:00
/// info of possible path usage
bool
2018-09-22 10:23:23 +00:00
main_router_prefetch(struct llarp_main *ptr,
const llarp::service::Address &addr);
2018-05-27 18:03:10 +00:00
}
#endif
2018-01-25 16:24:33 +00:00
#endif