mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
more
This commit is contained in:
parent
f022a5bcdf
commit
64d5265102
|
@ -20,7 +20,7 @@ set(LIB_SRC
|
|||
llarp/config.cpp
|
||||
llarp/crypto_async.c
|
||||
llarp/crypto_libsodium.cpp
|
||||
llarp/dtls_link.c
|
||||
llarp/dtls_link.cpp
|
||||
llarp/ev.cpp
|
||||
llarp/exit_info.c
|
||||
llarp/exit_route.c
|
||||
|
|
|
@ -4,6 +4,6 @@ threads=1
|
|||
[netdb]
|
||||
dir=./tmp-nodes
|
||||
|
||||
[links]
|
||||
[dtls-links]
|
||||
lo=1090
|
||||
#lo=eth
|
||||
|
|
|
@ -60,6 +60,7 @@ struct llarp_link_ev_listener {
|
|||
const char *);
|
||||
};
|
||||
|
||||
|
||||
struct llarp_link {
|
||||
void *impl;
|
||||
const char *(*name)(void);
|
||||
|
|
|
@ -21,7 +21,8 @@ bool Config::Load(const char *fname) {
|
|||
router = find_section(top, "router", section_t{});
|
||||
network = find_section(top, "network", section_t{});
|
||||
netdb = find_section(top, "netdb", section_t{});
|
||||
links = find_section(top, "links", section_t{});
|
||||
iwp_links = find_section(top, "iwp-links", section_t{});
|
||||
dtls_links = find_section(top, "dtls-links", section_t{});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -52,7 +53,8 @@ void llarp_config_iter(struct llarp_config *conf,
|
|||
std::map<std::string, llarp::Config::section_t &> sections = {
|
||||
{"router", conf->impl.router},
|
||||
{"network", conf->impl.network},
|
||||
{"links", conf->impl.links},
|
||||
{"dtls-links", conf->impl.dtls_links},
|
||||
{"iwp-links", conf->impl.iwp_links},
|
||||
{"netdb", conf->impl.netdb}};
|
||||
for (const auto §ion : sections)
|
||||
for (const auto &item : section.second)
|
||||
|
|
|
@ -12,7 +12,8 @@ struct Config {
|
|||
section_t router;
|
||||
section_t network;
|
||||
section_t netdb;
|
||||
section_t links;
|
||||
section_t iwp_links;
|
||||
section_t dtls_links;
|
||||
|
||||
bool Load(const char *fname);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
#include <llarp/dtls.h>
|
||||
#include <llarp/net.h>
|
||||
#include <map>
|
||||
#include "crypto.hpp"
|
||||
|
||||
struct dtls_session
|
||||
{
|
||||
};
|
||||
|
||||
struct dtls_link
|
||||
{
|
||||
|
@ -11,19 +17,22 @@ struct dtls_link
|
|||
char keyfile[255];
|
||||
char certfile[255];
|
||||
uint32_t timeout_job_id;
|
||||
std::map<llarp::pubkey, llarp_link_session> sessions;
|
||||
};
|
||||
|
||||
static struct dtls_link * dtls_link_alloc(struct llarp_alloc * mem, struct llarp_msg_muxer * muxer, const char * keyfile, const char * certfile)
|
||||
{
|
||||
struct dtls_link * link = mem->alloc(mem, sizeof(struct dtls_link), 8);
|
||||
if(link)
|
||||
void * ptr = mem->alloc(mem, sizeof(struct dtls_link), 8);
|
||||
if(ptr)
|
||||
{
|
||||
struct dtls_link * link = new (ptr) dtls_link;
|
||||
link->mem = mem;
|
||||
link->msghandler = muxer;
|
||||
strncpy(link->keyfile, keyfile, sizeof(link->keyfile));
|
||||
strncpy(link->certfile, certfile, sizeof(link->certfile));
|
||||
return link;
|
||||
}
|
||||
return link;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,7 +56,7 @@ static void dtls_link_issue_cleanup_timer(struct dtls_link * link, uint64_t time
|
|||
|
||||
static bool dtls_link_configure(struct llarp_link * l, struct llarp_ev_loop * netloop, const char * ifname, int af, uint16_t port)
|
||||
{
|
||||
struct dtls_link * link = l->impl;
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
if(!llarp_getifaddr(ifname, af, &link->udp.addr))
|
||||
return false;
|
||||
link->netloop = netloop;
|
||||
|
@ -56,7 +65,7 @@ static bool dtls_link_configure(struct llarp_link * l, struct llarp_ev_loop * ne
|
|||
|
||||
static bool dtls_link_start(struct llarp_link * l, struct llarp_logic * logic)
|
||||
{
|
||||
struct dtls_link * link = l->impl;
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
link->timeout_job_id = 0;
|
||||
link->logic = logic;
|
||||
// start cleanup timer
|
||||
|
@ -71,7 +80,7 @@ static void dtls_link_cleanup_dead_sessions(struct dtls_link * link)
|
|||
|
||||
static void dtls_link_cleanup_timer(void * l, uint64_t orig, uint64_t left)
|
||||
{
|
||||
struct dtls_link * link = l;
|
||||
dtls_link * link = static_cast<dtls_link*>(l);
|
||||
// clear out previous id of job
|
||||
link->timeout_job_id = 0;
|
||||
if(!left)
|
||||
|
@ -85,7 +94,7 @@ static void dtls_link_cleanup_timer(void * l, uint64_t orig, uint64_t left)
|
|||
|
||||
static bool dtls_link_stop(struct llarp_link *l)
|
||||
{
|
||||
struct dtls_link * link = l->impl;
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
if(link->timeout_job_id)
|
||||
{
|
||||
llarp_logic_cancel_call(link->logic, link->timeout_job_id);
|
||||
|
@ -96,11 +105,10 @@ static bool dtls_link_stop(struct llarp_link *l)
|
|||
|
||||
static void dtls_link_iter_sessions(struct llarp_link * l, struct llarp_link_session_iter * iter)
|
||||
{
|
||||
/*
|
||||
struct dtls_link * link = l->impl;
|
||||
struct llarp_link_session * session;
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
iter->link = l;
|
||||
*/
|
||||
for (auto & item : link->sessions)
|
||||
if(!iter->visit(iter, &item.second)) return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,13 +116,26 @@ static void dtls_link_try_establish(struct llarp_link * link, struct llarp_link_
|
|||
{
|
||||
}
|
||||
|
||||
static void dtls_link_mark_session_active(struct llarp_link * link, struct llarp_link_session * s)
|
||||
{
|
||||
}
|
||||
|
||||
static struct llarp_link_session * dtls_link_session_for_addr(struct llarp_link * link, const struct sockaddr * saddr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void dtls_link_free(struct llarp_link *l)
|
||||
{
|
||||
struct dtls_link * link = l->impl;
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
struct llarp_alloc * mem = link->mem;
|
||||
link->~dtls_link();
|
||||
mem->free(mem, link);
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
void dtls_link_init(struct llarp_link * link, struct llarp_dtls_args args, struct llarp_msg_muxer * muxer)
|
||||
{
|
||||
link->impl = dtls_link_alloc(args.mem, muxer, args.keyfile, args.certfile);
|
||||
|
@ -128,5 +149,9 @@ void dtls_link_init(struct llarp_link * link, struct llarp_dtls_args args, struc
|
|||
link->stop_link = dtls_link_stop;
|
||||
link->iter_sessions = dtls_link_iter_sessions;
|
||||
link->try_establish = dtls_link_try_establish;
|
||||
link->acquire_session_for_addr = dtls_link_session_for_addr;
|
||||
link->mark_session_active = dtls_link_mark_session_active;
|
||||
link->free_impl = dtls_link_free;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,17 @@
|
|||
#include <llarp/mem.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void Zero(void * ptr, size_t sz)
|
||||
{
|
||||
uint8_t * p = (uint8_t *) ptr;
|
||||
while(sz--)
|
||||
{
|
||||
*p = 0;
|
||||
++p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@ template <typename T>
|
|||
static T *Alloc(llarp_alloc *mem) {
|
||||
return static_cast<T *>(mem->alloc(mem, sizeof(T), alignment<T>()));
|
||||
}
|
||||
|
||||
void Zero(void * ptr, size_t sz);
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "router.hpp"
|
||||
#include <llarp/ibfq.h>
|
||||
#include <llarp/dtls.h>
|
||||
#include <llarp/iwp.h>
|
||||
#include <llarp/link.h>
|
||||
#include <llarp/proto.h>
|
||||
#include <llarp/router.h>
|
||||
|
@ -97,44 +98,56 @@ void router_iter_config(llarp_config_iterator *iter, const char *section,
|
|||
const char *key, const char *val)
|
||||
{
|
||||
llarp_router *self = static_cast<llarp_router *>(iter->user);
|
||||
llarp_dtls_args args = {
|
||||
.mem = self->mem,
|
||||
.keyfile=self->transport_keyfile,
|
||||
.certfile=self->transport_certfile,
|
||||
};
|
||||
if (StrEq(section, "links"))
|
||||
int af;
|
||||
uint16_t proto;
|
||||
if (StrEq(val, "eth"))
|
||||
{
|
||||
if (StrEq(val, "eth")) {
|
||||
struct llarp_link *link = llarp::Alloc<llarp_link>(self->mem);
|
||||
dtls_link_init(link, args, &self->muxer);
|
||||
if(llarp_link_initialized(link))
|
||||
{
|
||||
if (link->configure(link, self->netloop, key, AF_PACKET, LLARP_ETH_PROTO))
|
||||
{
|
||||
printf("ethernet link configured on %s\n", key);
|
||||
self->AddLink(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self->mem->free(self->mem, link);
|
||||
printf("failed to configure ethernet link for %s\n", key);
|
||||
} else {
|
||||
struct llarp_link *link = llarp::Alloc<llarp_link>(self->mem);
|
||||
uint16_t port = std::atoi(val);
|
||||
dtls_link_init(link, args, &self->muxer);
|
||||
if(llarp_link_initialized(link))
|
||||
{
|
||||
if (link->configure(link, self->netloop, key, AF_INET6, port))
|
||||
{
|
||||
printf("inet link configured on %s port %d\n", key, port);
|
||||
self->AddLink(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self->mem->free(self->mem, link);
|
||||
printf("failed to configure inet link for %s port %d\n", key, port);
|
||||
af = AF_PACKET;
|
||||
proto = LLARP_ETH_PROTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
proto = std::atoi(val);
|
||||
}
|
||||
|
||||
struct llarp_link *link;
|
||||
if (StrEq(section, "dtls-links"))
|
||||
{
|
||||
link = llarp::Alloc<llarp_link>(self->mem);
|
||||
llarp::Zero(link, sizeof(*link));
|
||||
llarp_dtls_args args = {
|
||||
.mem = self->mem,
|
||||
.keyfile=self->transport_keyfile,
|
||||
.certfile=self->transport_certfile,
|
||||
};
|
||||
dtls_link_init(link, args, &self->muxer);
|
||||
}
|
||||
else if (StrEq(section, "iwp-links"))
|
||||
{
|
||||
link = llarp::Alloc<llarp_link>(self->mem);
|
||||
llarp::Zero(link, sizeof(*link));
|
||||
|
||||
iwp_configure_args args = {
|
||||
.mem = self->mem,
|
||||
.crypto = &self->crypto,
|
||||
.keyfile=self->transport_keyfile,
|
||||
};
|
||||
iwp_link_init(link, args, &self->muxer);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
if(llarp_link_initialized(link))
|
||||
{
|
||||
if (link->configure(link, self->netloop, key, af, proto))
|
||||
{
|
||||
printf("link configured on %s\n", key);
|
||||
self->AddLink(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self->mem->free(self->mem, link);
|
||||
printf("failed to configure link for %s\n", key);
|
||||
}
|
||||
|
||||
} // namespace llarp
|
||||
|
|
Loading…
Reference in a new issue