mirror of https://github.com/oxen-io/lokinet
more
parent
e4005102ba
commit
f7e52a1878
@ -0,0 +1,19 @@
|
||||
#ifndef LLARP_DTLS_H_
|
||||
#define LLARP_DTLS_H_
|
||||
|
||||
#include <llarp/link.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct llarp_dtls_args {
|
||||
char key_file[255];
|
||||
char cert_file[255];
|
||||
};
|
||||
|
||||
bool dtls_link_init(struct llarp_link* link, struct llarp_dtls_args args,
|
||||
struct llarp_msg_muxer* muxer);
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,111 @@
|
||||
#include <llarp/dtls.h>
|
||||
|
||||
|
||||
struct dtls_link
|
||||
{
|
||||
struct llarp_logic * logic;
|
||||
uint32_t timeout_job_id;
|
||||
};
|
||||
|
||||
static struct dtls_link * dtls_link_alloc(struct llarp_msg_muxer * muxer, char * keyfile, char * certfile)
|
||||
{
|
||||
struct dtls_link * link = llarp_g_mem.alloc(sizeof(struct dtls_link), 8);
|
||||
return link;
|
||||
}
|
||||
|
||||
|
||||
static const char * dtls_link_name(struct llarp_link * l)
|
||||
{
|
||||
(void) l;
|
||||
return "dtls";
|
||||
}
|
||||
|
||||
// forward declare
|
||||
static void dtls_link_cleanup_timer(void * l, uint64_t orig, uint64_t left);
|
||||
|
||||
static void dtls_link_issue_cleanup_timer(struct dtls_link * link, uint64_t timeout)
|
||||
{
|
||||
struct llarp_timeout_job job = {
|
||||
.timeout = timeout,
|
||||
.user = link,
|
||||
.handler = &dtls_link_cleanup_timer
|
||||
};
|
||||
link->timeout_job_id = llarp_logic_call_later(link->logic, job);
|
||||
}
|
||||
|
||||
static bool dtls_link_start(struct llarp_link * l, struct llarp_logic * logic)
|
||||
{
|
||||
struct dtls_link * link = l->impl;
|
||||
link->timeout_job_id = 0;
|
||||
link->logic = logic;
|
||||
// start cleanup timer
|
||||
dtls_link_issue_cleanup_timer(link, 1000); // every 1 second
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dtls_link_cleanup_dead_sessions(struct dtls_link * link)
|
||||
{
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
static void dtls_link_cleanup_timer(void * l, uint64_t orig, uint64_t left)
|
||||
{
|
||||
struct dtls_link * link = l;
|
||||
// clear out previous id of job
|
||||
link->timeout_job_id = 0;
|
||||
if(!left)
|
||||
{
|
||||
dtls_link_cleanup_dead_sessions(link);
|
||||
//TODO: exponential backoff for cleanup timer ?
|
||||
dtls_link_issue_cleanup_timer(link, orig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool dtls_link_stop(struct llarp_link *l)
|
||||
{
|
||||
struct dtls_link * link = l->impl;
|
||||
if(link->timeout_job_id)
|
||||
{
|
||||
llarp_logic_cancel_call(link->logic, link->timeout_job_id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
iter->link = l;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
static void dtls_link_try_establish(struct llarp_link * link, struct llarp_link_establish_job job, struct llarp_link_session_listener l)
|
||||
{
|
||||
}
|
||||
|
||||
static void dtls_link_free(struct llarp_link *l)
|
||||
{
|
||||
llarp_g_mem.free(l->impl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool dtls_link_init(struct llarp_link * link, struct llarp_dtls_args args, struct llarp_msg_muxer * muxer)
|
||||
{
|
||||
link->impl = dtls_link_alloc(muxer, args.key_file, args.cert_file);
|
||||
link->name = dtls_link_name;
|
||||
/*
|
||||
link->register_listener = dtls_link_reg_listener;
|
||||
link->deregister_listener = dtls_link_dereg_listener;
|
||||
*/
|
||||
link->start_link = dtls_link_start;
|
||||
link->stop_link = dtls_link_stop;
|
||||
link->iter_sessions = dtls_link_iter_sessions;
|
||||
link->try_establish = dtls_link_try_establish;
|
||||
link->free_impl = dtls_link_free;
|
||||
return false;
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
#include <llarp/iwp.h>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
namespace iwp {
|
||||
|
||||
struct link_impl {
|
||||
link_impl(llarp_seckey_t k, llarp_msg_muxer *m) : muxer(m) {
|
||||
memcpy(seckey, k, sizeof(seckey));
|
||||
}
|
||||
|
||||
std::list<llarp_link_ev_listener> link_listeners;
|
||||
|
||||
llarp_seckey_t seckey;
|
||||
|
||||
llarp_msg_muxer *muxer;
|
||||
|
||||
std::string linkname;
|
||||
|
||||
bool configure(const char *ifname, int af, uint16_t port) {
|
||||
// todo: implement
|
||||
linkname = std::string(ifname) + std::string("+") + std::to_string(port);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *name() { return linkname.c_str(); }
|
||||
|
||||
bool start(llarp_logic *logic) {
|
||||
// todo: implement
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stop() {
|
||||
// todo: implement
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static bool configure(struct llarp_link *l, const char *ifname, int af,
|
||||
uint16_t port) {
|
||||
link_impl *link = static_cast<link_impl *>(l->impl);
|
||||
return link->configure(ifname, af, port);
|
||||
}
|
||||
|
||||
static bool start_link(struct llarp_link *l, struct llarp_logic *logic) {
|
||||
link_impl *link = static_cast<link_impl *>(l->impl);
|
||||
return link->start(logic);
|
||||
}
|
||||
|
||||
static bool stop_link(struct llarp_link *l) {
|
||||
link_impl *link = static_cast<link_impl *>(l->impl);
|
||||
return link->stop();
|
||||
}
|
||||
|
||||
static void free_link(struct llarp_link *l) {
|
||||
link_impl *link = static_cast<link_impl *>(l->impl);
|
||||
delete link;
|
||||
}
|
||||
|
||||
static const char *link_name(struct llarp_link *l) {
|
||||
link_impl *link = static_cast<link_impl *>(l->impl);
|
||||
return link->name();
|
||||
}
|
||||
|
||||
} // namespace iwp
|
||||
|
||||
extern "C" {
|
||||
|
||||
bool iwp_link_init(struct llarp_link *link, struct iwp_configure_args args,
|
||||
struct llarp_msg_muxer *muxer) {
|
||||
llarp_seckey_t seckey;
|
||||
args.crypto->keygen(&seckey);
|
||||
link->impl = new iwp::link_impl(seckey, muxer);
|
||||
|
||||
link->name = &iwp::link_name;
|
||||
link->configure = &iwp::configure;
|
||||
link->start_link = &iwp::start_link;
|
||||
link->stop_link = &iwp::stop_link;
|
||||
link->free = &iwp::free_link;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
#include <llarp/iwp.h>
|
||||
|
||||
|
||||
|
||||
bool iwp_link_init(struct llarp_link * link, struct iwp_configure_args args,
|
||||
struct llarp_msg_muxer * muxer)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue