2018-01-25 16:24:33 +00:00
|
|
|
#ifndef LLARP_H_
|
|
|
|
#define LLARP_H_
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2018-12-13 21:46:55 +00:00
|
|
|
#ifdef __cplusplus
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <ev.h>
|
|
|
|
#include <mem.h>
|
2018-12-13 21:37:30 +00:00
|
|
|
#include <logic.hpp>
|
|
|
|
#include <version.hpp>
|
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>
|
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, bool);
|
|
|
|
|
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
|
|
|
|
2018-11-26 22:46:22 +00:00
|
|
|
/// give main context a vpn file descriptor (android/ios)
|
|
|
|
void
|
2018-12-02 18:07:07 +00:00
|
|
|
llarp_main_inject_vpn_fd(struct llarp_main *m, int fd);
|
2018-11-26 22:46:22 +00:00
|
|
|
|
2018-12-13 21:46:55 +00:00
|
|
|
/// setup main context, returns 0 on success
|
2018-07-17 04:37:50 +00:00
|
|
|
int
|
|
|
|
llarp_main_setup(struct llarp_main *ptr);
|
2018-06-23 14:56:59 +00:00
|
|
|
|
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-07-03 11:25:36 +00:00
|
|
|
|
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-06-19 09:44:53 +00:00
|
|
|
|
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-06-19 09:44:53 +00:00
|
|
|
|
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,
|
2018-09-24 13:10:36 +00:00
|
|
|
struct llarp::RouterContact &rc);
|
2018-06-19 09:44:53 +00:00
|
|
|
|
2018-07-17 04:37:50 +00:00
|
|
|
// fwd declr
|
|
|
|
struct check_online_request;
|
2018-06-28 11:31:15 +00:00
|
|
|
|
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-06-28 11:31:15 +00:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-08-09 11:22:57 +00:00
|
|
|
/// 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);
|
|
|
|
|
2018-08-09 11:22:57 +00:00
|
|
|
/// 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);
|
2018-08-09 11:22:57 +00:00
|
|
|
|
2018-09-19 12:22:34 +00:00
|
|
|
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);
|
|
|
|
|
2018-09-22 10:23:23 +00:00
|
|
|
llarp::handlers::TunEndpoint *
|
|
|
|
main_router_getFirstTunEndpoint(struct llarp_main *ptr);
|
|
|
|
|
2018-09-20 12:34:53 +00:00
|
|
|
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
|