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

136 lines
3.6 KiB
C
Raw Normal View History

2018-01-25 17:24:33 +01:00
#ifndef LLARP_H_
#define LLARP_H_
2018-12-13 22:46:55 +01:00
#ifdef __cplusplus
#include <constants/version.hpp>
2019-01-11 02:19:36 +01:00
#include <ev/ev.h>
2018-12-12 02:12:59 +01:00
#include <handlers/tun.hpp> // for handlers
2018-12-12 03:15:08 +01:00
#include <service/address.hpp> // for service::address
#include <service/endpoint.hpp>
2019-01-11 02:19:36 +01:00
#include <util/logic.hpp>
#include <util/mem.h>
2018-09-20 12:05:42 +02:00
2018-07-17 06:37:50 +02:00
extern "C"
{
2018-05-27 20:03:10 +02:00
#endif
2018-11-06 15:06:09 +01: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 15:06:09 +01:00
2018-07-17 06:37:50 +02:00
/// llarp application context for C api
struct llarp_main;
2018-05-27 20:03:10 +02:00
2018-07-17 06:37:50 +02:00
/// initialize application context and load config
struct llarp_main *
llarp_main_init(const char *fname, bool multiProcess);
2018-05-27 20:03:10 +02:00
2018-07-17 06:37:50 +02:00
/// handle signal for main context
void
llarp_main_signal(struct llarp_main *ptr, int sig);
2018-05-27 20:03:10 +02:00
2019-04-08 17:54:19 +02:00
/// give main context a vpn file descriptor pair (android/ios)
void
2019-04-08 17:54:19 +02:00
llarp_main_inject_vpn_fd(struct llarp_main *m, int rfd, int wfd);
2018-12-13 22:46:55 +01:00
/// setup main context, returns 0 on success
2018-07-17 06:37:50 +02:00
int
llarp_main_setup(struct llarp_main *ptr);
2018-12-13 22:46:55 +01:00
/// run main context, returns 0 on success, blocks until program end
2018-07-17 06:37:50 +02:00
int
llarp_main_run(struct llarp_main *ptr);
2018-05-27 20:03:10 +02:00
2018-12-13 22:46:55 +01:00
/// free main context and end all operations
void
llarp_main_free(struct llarp_main *ptr);
#ifdef __cplusplus
2018-07-17 06:37:50 +02:00
void
llarp_main_abort(struct llarp_main *ptr);
2018-12-13 22:46:55 +01:00
const char *
handleBaseCmdLineArgs(int argc, char *argv[]);
2018-07-17 06:37:50 +02:00
/// load nodeDB into memory
int
llarp_main_loadDatabase(struct llarp_main *ptr);
2018-07-17 06:37:50 +02:00
/// iterator on nodedb entries
int
llarp_main_iterateDatabase(struct llarp_main *ptr,
struct llarp_nodedb_iter i);
2018-07-17 06:37:50 +02:00
/// put RC into nodeDB
bool
2018-09-22 12:23:23 +02:00
llarp_main_putDatabase(struct llarp_main *ptr,
struct llarp::RouterContact &rc);
2018-07-17 06:37:50 +02:00
// fwd declr
struct check_online_request;
2018-07-17 06:37:50 +02:00
/// check_online_request hook definition
typedef void (*check_online_request_hook_func)(struct check_online_request *);
2018-07-17 06:37:50 +02: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 06:37:50 +02: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 12:28:01 +02:00
const llarp::Addr &dnsd_sockaddr,
const llarp::Addr &dnsc_sockaddr);
2018-09-22 12:23:23 +02: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 06:37:50 +02:00
llarp_main_getLocalRC(struct llarp_main *ptr);
2018-12-13 22:37:30 +01:00
/// get RC from nodeDB
llarp::RouterContact *
llarp_main_getDatabase(struct llarp_main *ptr, byte_t *pk);
2018-09-22 12:23:23 +02:00
llarp::handlers::TunEndpoint *
main_router_getFirstTunEndpoint(struct llarp_main *ptr);
llarp_tun_io *
main_router_getRange(struct llarp_main *ptr);
2018-10-10 17:14:45 +02:00
/// map an (host byte order) ip to a hidden service address
2018-09-20 12:05:42 +02:00
bool
2018-09-22 12:23:23 +02:00
main_router_mapAddress(struct llarp_main *ptr,
const llarp::service::Address &addr, uint32_t ip);
2018-09-20 12:05:42 +02:00
2018-09-21 14:53:20 +02:00
/// info of possible path usage
bool
2018-09-22 12:23:23 +02:00
main_router_prefetch(struct llarp_main *ptr,
const llarp::service::Address &addr);
2018-05-27 20:03:10 +02:00
}
#endif
2018-01-25 17:24:33 +01:00
#endif