mirror of https://github.com/oxen-io/lokinet
it binds
This commit is contained in:
parent
64d5265102
commit
4959067af2
|
@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
if (llarp_configure_router(llarp.router, llarp.config)) {
|
||||
|
||||
llarp.logic = llarp_init_logic();
|
||||
llarp.logic = llarp_init_logic(mem);
|
||||
printf("starting router\n");
|
||||
|
||||
llarp_run_router(llarp.router, llarp.logic);
|
||||
|
|
|
@ -84,6 +84,7 @@ struct llarp_link {
|
|||
bool llarp_link_initialized(struct llarp_link * link);
|
||||
|
||||
struct llarp_link_session {
|
||||
struct sockaddr addr;
|
||||
void *impl;
|
||||
struct llarp_rc *(*remote_rc)(struct llarp_link_session *);
|
||||
/** send an entire message, splits up into smaller pieces and does encryption
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#ifdef __linux__
|
||||
#include <linux/if_packet.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <llarp/net.h>
|
||||
#include <map>
|
||||
#include "crypto.hpp"
|
||||
#include "net.hpp"
|
||||
|
||||
struct dtls_session
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ struct dtls_link
|
|||
struct llarp_alloc * mem;
|
||||
struct llarp_logic * logic;
|
||||
struct llarp_ev_loop * netloop;
|
||||
struct llarp_msg_muxer * msghandler;
|
||||
struct llarp_msg_muxer * muxer;
|
||||
struct llarp_udp_io udp;
|
||||
char keyfile[255];
|
||||
char certfile[255];
|
||||
|
@ -27,7 +28,7 @@ static struct dtls_link * dtls_link_alloc(struct llarp_alloc * mem, struct llarp
|
|||
{
|
||||
struct dtls_link * link = new (ptr) dtls_link;
|
||||
link->mem = mem;
|
||||
link->msghandler = muxer;
|
||||
link->muxer = muxer;
|
||||
strncpy(link->keyfile, keyfile, sizeof(link->keyfile));
|
||||
strncpy(link->certfile, certfile, sizeof(link->certfile));
|
||||
return link;
|
||||
|
@ -57,8 +58,21 @@ 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)
|
||||
{
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
link->udp.addr.sa_family = af;
|
||||
if(!llarp_getifaddr(ifname, af, &link->udp.addr))
|
||||
return false;
|
||||
switch(af)
|
||||
{
|
||||
case AF_INET:
|
||||
((sockaddr_in *)&link->udp.addr)->sin_port = htons(port);
|
||||
break;
|
||||
case AF_INET6:
|
||||
((sockaddr_in6 *)(&link->udp.addr))->sin6_port = htons(port);
|
||||
break;
|
||||
// TODO: AF_PACKET
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
link->netloop = netloop;
|
||||
return llarp_ev_add_udp(link->netloop, &link->udp) != -1;
|
||||
}
|
||||
|
@ -120,8 +134,16 @@ static void dtls_link_mark_session_active(struct llarp_link * link, struct llarp
|
|||
{
|
||||
}
|
||||
|
||||
static struct llarp_link_session * dtls_link_session_for_addr(struct llarp_link * link, const struct sockaddr * saddr)
|
||||
static struct llarp_link_session * dtls_link_session_for_addr(struct llarp_link * l, const struct sockaddr * saddr)
|
||||
{
|
||||
if(saddr)
|
||||
{
|
||||
dtls_link * link = static_cast<dtls_link*>(l->impl);
|
||||
for(auto & session : link->sessions)
|
||||
{
|
||||
if(session.second.addr == *saddr) return &link->sessions[session.first];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -140,10 +162,6 @@ void dtls_link_init(struct llarp_link * link, struct llarp_dtls_args args, struc
|
|||
{
|
||||
link->impl = dtls_link_alloc(args.mem, muxer, args.keyfile, args.certfile);
|
||||
link->name = dtls_link_name;
|
||||
/*
|
||||
link->register_listener = dtls_link_reg_listener;
|
||||
link->deregister_listener = dtls_link_dereg_listener;
|
||||
*/
|
||||
link->configure = dtls_link_configure;
|
||||
link->start_link = dtls_link_start;
|
||||
link->stop_link = dtls_link_stop;
|
||||
|
|
|
@ -16,6 +16,7 @@ void llarp_ev_loop_alloc(struct llarp_ev_loop **ev) {
|
|||
#ifdef __FreeBSD__
|
||||
*ev = new llarp_kqueue_loop;
|
||||
#endif
|
||||
(*ev)->init();
|
||||
}
|
||||
|
||||
void llarp_ev_loop_free(struct llarp_ev_loop **ev) {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef EV_EPOLL_HPP
|
||||
#define EV_EPOLL_HPP
|
||||
#include <netinet/in.h>
|
||||
#include <llarp/net.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include "ev.hpp"
|
||||
|
||||
namespace llarp {
|
||||
|
@ -83,6 +84,9 @@ struct llarp_epoll_loop : public llarp_ev_loop {
|
|||
case AF_INET6:
|
||||
slen = sizeof(struct sockaddr_in6);
|
||||
break;
|
||||
case AF_PACKET:
|
||||
slen = sizeof(struct sockaddr_ll);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
@ -101,12 +105,14 @@ struct llarp_epoll_loop : public llarp_ev_loop {
|
|||
}
|
||||
|
||||
bool udp_listen(llarp_udp_io* l) {
|
||||
printf("udp_listen()\n");
|
||||
int fd = udp_bind(&l->addr);
|
||||
if (fd == -1) return false;
|
||||
llarp::udp_listener* listener = new llarp::udp_listener(fd, l);
|
||||
epoll_event ev;
|
||||
ev.data.ptr = listener;
|
||||
ev.events = EPOLLIN;
|
||||
printf("epoll_ctl()\n");
|
||||
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
|
||||
delete listener;
|
||||
return false;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <cstdio>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -11,15 +12,19 @@ bool llarp_getifaddr(const char * ifname, int af, struct sockaddr* addr) {
|
|||
bool found = false;
|
||||
socklen_t sl = sizeof(sockaddr_in6);
|
||||
if (af == AF_INET) sl = sizeof(sockaddr_in);
|
||||
if (af == AF_PACKET) sl = sizeof(sockaddr_ll);
|
||||
|
||||
if (getifaddrs(&ifa) == -1) return false;
|
||||
ifaddrs* i = ifa;
|
||||
while (i) {
|
||||
if (llarp::StrEq(i->ifa_name, ifname) && i->ifa_addr &&
|
||||
i->ifa_addr->sa_family == af) {
|
||||
memcpy(addr, i->ifa_addr, sl);
|
||||
found = true;
|
||||
break;
|
||||
if (i->ifa_addr)
|
||||
{
|
||||
if (llarp::StrEq(i->ifa_name, ifname) && i->ifa_addr->sa_family == af) {
|
||||
memcpy(addr, i->ifa_addr, sl);
|
||||
addr->sa_family = af;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
i = i->ifa_next;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef LLARP_NET_HPP
|
||||
#define LLARP_NET_HPP
|
||||
#include <llarp/net.h>
|
||||
|
||||
bool operator == (const sockaddr& a, const sockaddr& b)
|
||||
{
|
||||
socklen_t sz = sizeof(a.sa_data);
|
||||
switch(a.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
sz = sizeof(sockaddr_in);
|
||||
break;
|
||||
case AF_INET6:
|
||||
sz = sizeof(sockaddr_in6);
|
||||
break;
|
||||
case AF_PACKET:
|
||||
sz = sizeof(sockaddr_ll);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return a.sa_family == b.sa_family && memcmp(a.sa_data, b.sa_data, sz) == 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -107,6 +107,7 @@ void router_iter_config(llarp_config_iterator *iter, const char *section,
|
|||
}
|
||||
else
|
||||
{
|
||||
af = AF_INET;
|
||||
proto = std::atoi(val);
|
||||
}
|
||||
|
||||
|
@ -139,9 +140,10 @@ void router_iter_config(llarp_config_iterator *iter, const char *section,
|
|||
|
||||
if(llarp_link_initialized(link))
|
||||
{
|
||||
printf("link initialized...");
|
||||
if (link->configure(link, self->netloop, key, af, proto))
|
||||
{
|
||||
printf("link configured on %s\n", key);
|
||||
printf("configured on %s\n", key);
|
||||
self->AddLink(link);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue