mirror of https://github.com/oxen-io/lokinet
more
This commit is contained in:
parent
f7e52a1878
commit
7b46e44859
|
@ -25,6 +25,7 @@ set(LIB_SRC
|
|||
llarp/exit_info.c
|
||||
llarp/exit_route.c
|
||||
llarp/iwp_link.c
|
||||
llarp/link.c
|
||||
llarp/link_intro.cpp
|
||||
llarp/link_relay_down.cpp
|
||||
llarp/link_relay_up.cpp
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
[router]
|
||||
threads=1
|
||||
|
||||
[netdb]
|
||||
dir=./tmp-nodes
|
||||
|
||||
[links]
|
||||
lo=1090
|
||||
lo=eth
|
||||
#lo=eth
|
||||
|
|
|
@ -10,21 +10,22 @@ struct llarp_main {
|
|||
struct llarp_nodedb *nodedb;
|
||||
struct llarp_ev_loop *mainloop;
|
||||
char nodedb_dir[256];
|
||||
int exitcode;
|
||||
};
|
||||
|
||||
void iter_main_config(struct llarp_config_iterator *itr, const char *section,
|
||||
const char *key, const char *val) {
|
||||
struct llarp_main *m = (struct llarp_main *)itr->user;
|
||||
|
||||
if (!strcmp(section, "router")) {
|
||||
if (!strcmp(key, "threads")) {
|
||||
int workers = atoi(val);
|
||||
if (workers > 0 && m->worker == NULL) {
|
||||
printf("%s: %d worker threads\n", section, workers);
|
||||
m->worker = llarp_init_threadpool(workers);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strcmp(section, "nodedb")) {
|
||||
if (!strcmp(section, "netdb")) {
|
||||
if (!strcmp(key, "dir")) {
|
||||
strncpy(m->nodedb_dir, val, sizeof(m->nodedb_dir));
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ int shutdown_llarp(struct llarp_main *m) {
|
|||
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
return m->exitcode;
|
||||
}
|
||||
|
||||
struct llarp_main llarp = {
|
||||
|
@ -87,7 +88,8 @@ struct llarp_main llarp = {
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
{0}
|
||||
{0},
|
||||
1
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -96,9 +98,8 @@ int main(int argc, char *argv[]) {
|
|||
llarp_mem_stdlib();
|
||||
llarp_new_config(&llarp.config);
|
||||
llarp_ev_loop_alloc(&llarp.mainloop);
|
||||
printf("%s starting up\n", LLARP_VERSION);
|
||||
printf("%s loading config file %s\n", LLARP_VERSION, conffname);
|
||||
if (!llarp_load_config(llarp.config, conffname)) {
|
||||
printf("Loaded config %s\n", conffname);
|
||||
struct llarp_config_iterator iter;
|
||||
iter.user = &llarp;
|
||||
iter.visit = iter_main_config;
|
||||
|
@ -123,14 +124,18 @@ int main(int argc, char *argv[]) {
|
|||
llarp_run_router(llarp.router, llarp.logic);
|
||||
|
||||
printf("running mainloop\n");
|
||||
llarp.exitcode = 0;
|
||||
llarp_ev_loop_run(llarp.mainloop);
|
||||
} else
|
||||
printf("Failed to configure router\n");
|
||||
} else
|
||||
printf("failed to initialize nodedb at %s\n", dir);
|
||||
}
|
||||
} else
|
||||
printf("no nodedb defined\n");
|
||||
|
||||
return shutdown_llarp(&llarp);
|
||||
} else
|
||||
printf("Failed to load config %s\n", conffname);
|
||||
|
||||
return shutdown_llarp(&llarp);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ struct llarp_link {
|
|||
void (*free_impl)(struct llarp_link *);
|
||||
};
|
||||
|
||||
/** checks if all members are initialized */
|
||||
bool llarp_link_initialized(struct llarp_link * link);
|
||||
|
||||
|
||||
struct llarp_link_session {
|
||||
void *impl;
|
||||
struct llarp_rc *(*remote_rc)(struct llarp_link_session *);
|
||||
|
|
|
@ -107,5 +107,5 @@ bool dtls_link_init(struct llarp_link * link, struct llarp_dtls_args args, struc
|
|||
link->iter_sessions = dtls_link_iter_sessions;
|
||||
link->try_establish = dtls_link_try_establish;
|
||||
link->free_impl = dtls_link_free;
|
||||
return false;
|
||||
return llarp_link_initialized(link);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ bool iwp_link_init(struct llarp_link * link, struct iwp_configure_args args,
|
|||
struct llarp_msg_muxer * muxer)
|
||||
{
|
||||
|
||||
return true;
|
||||
return llarp_link_initialized(link);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include <llarp/link.h>
|
||||
|
||||
bool llarp_link_initialized(struct llarp_link * link)
|
||||
{
|
||||
return link && link->impl && link->name && link->configure && link->start_link && link->stop_link && link->iter_sessions && link->try_establish && link->free_impl;
|
||||
}
|
||||
|
|
@ -88,26 +88,32 @@ void router_iter_config(llarp_config_iterator *iter, const char *section,
|
|||
if (StrEq(val, "eth")) {
|
||||
struct llarp_link *link = llarp::Alloc<llarp_link>();
|
||||
iwp_configure_args args = {.crypto = &self->crypto, .keyfile=self->transport_keyfile};
|
||||
iwp_link_init(link, args, &self->muxer);
|
||||
if (link->configure(link, key, AF_PACKET, LLARP_ETH_PROTO)) {
|
||||
printf("ethernet link configured on %s\n", key);
|
||||
self->AddLink(link);
|
||||
} else {
|
||||
delete link;
|
||||
printf("failed to configure ethernet link for %s\n", key);
|
||||
if(iwp_link_init(link, args, &self->muxer))
|
||||
{
|
||||
if (link->configure(link, key, AF_PACKET, LLARP_ETH_PROTO))
|
||||
{
|
||||
printf("ethernet link configured on %s\n", key);
|
||||
self->AddLink(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
delete link;
|
||||
printf("failed to configure ethernet link for %s\n", key);
|
||||
} else {
|
||||
struct llarp_link *link = llarp::Alloc<llarp_link>();
|
||||
uint16_t port = std::atoi(val);
|
||||
iwp_configure_args args = {.crypto = &self->crypto, .keyfile=self->transport_keyfile};
|
||||
iwp_link_init(link, args, &self->muxer);
|
||||
if (link->configure(link, key, AF_INET6, port)) {
|
||||
printf("inet link configured on %s port %d\n", key, port);
|
||||
self->AddLink(link);
|
||||
} else {
|
||||
delete link;
|
||||
printf("failed to configure inet link for %s port %d\n", key, port);
|
||||
if(iwp_link_init(link, args, &self->muxer))
|
||||
{
|
||||
if (link->configure(link, key, AF_INET6, port))
|
||||
{
|
||||
printf("inet link configured on %s port %d\n", key, port);
|
||||
self->AddLink(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
delete link;
|
||||
printf("failed to configure inet link for %s port %d\n", key, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue