mirror of https://github.com/oxen-io/lokinet
format
parent
1fdfdc0244
commit
58247343bf
@ -1,12 +1,10 @@
|
|||||||
#include "link_handlers.hpp"
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp {
|
||||||
{
|
namespace frame {
|
||||||
namespace frame
|
bool process_intro(struct llarp_frame_handler* h, struct llarp_link_session* s,
|
||||||
{
|
llarp_buffer_t msg) {
|
||||||
bool process_intro(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg)
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace frame
|
||||||
|
} // namespace llarp
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
#include "link_handlers.hpp"
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp {
|
||||||
{
|
namespace frame {
|
||||||
namespace frame
|
bool process_relay_down(struct llarp_frame_handler* h,
|
||||||
{
|
struct llarp_link_session* s, llarp_buffer_t msg) {
|
||||||
bool process_relay_down(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg)
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace frame
|
||||||
|
} // namespace llarp
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
#include "link_handlers.hpp"
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp {
|
||||||
{
|
namespace frame {
|
||||||
namespace frame
|
bool process_relay_up(struct llarp_frame_handler* h,
|
||||||
{
|
struct llarp_link_session* s, llarp_buffer_t msg) {
|
||||||
bool process_relay_up(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg)
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace frame
|
||||||
|
} // namespace llarp
|
||||||
|
@ -1,53 +1,46 @@
|
|||||||
#include <llarp/msg_handler.h>
|
#include <llarp/msg_handler.h>
|
||||||
#include "router.hpp"
|
|
||||||
#include "link_handlers.hpp"
|
#include "link_handlers.hpp"
|
||||||
|
#include "router.hpp"
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp {
|
||||||
{
|
struct llarp_frame_handler introduce_handler = {
|
||||||
struct llarp_frame_handler introduce_handler = {
|
|
||||||
.paths = nullptr,
|
.paths = nullptr,
|
||||||
.parent = nullptr,
|
.parent = nullptr,
|
||||||
.process = &llarp::frame::process_intro
|
.process = &llarp::frame::process_intro};
|
||||||
};
|
|
||||||
|
|
||||||
struct llarp_frame_handler lrdm_handler = {
|
struct llarp_frame_handler lrdm_handler = {
|
||||||
.paths = nullptr,
|
.paths = nullptr,
|
||||||
.parent = nullptr,
|
.parent = nullptr,
|
||||||
.process = &llarp::frame::process_relay_down
|
.process = &llarp::frame::process_relay_down};
|
||||||
};
|
|
||||||
|
|
||||||
struct llarp_frame_handler lrum_handler = {
|
struct llarp_frame_handler lrum_handler = {
|
||||||
.paths = nullptr,
|
.paths = nullptr,
|
||||||
.parent = nullptr,
|
.parent = nullptr,
|
||||||
.process = &llarp::frame::process_relay_up
|
.process = &llarp::frame::process_relay_up};
|
||||||
};
|
|
||||||
|
|
||||||
static struct llarp_frame_handler * find_frame_handler(struct llarp_router * r, const char ch)
|
static struct llarp_frame_handler* find_frame_handler(struct llarp_router* r,
|
||||||
{
|
const char ch) {
|
||||||
struct llarp_frame_handler * handler = nullptr;
|
struct llarp_frame_handler* handler = nullptr;
|
||||||
switch(ch)
|
switch (ch) {
|
||||||
{
|
|
||||||
case 'i':
|
case 'i':
|
||||||
handler = &introduce_handler;
|
handler = &introduce_handler;
|
||||||
}
|
|
||||||
if(handler)
|
|
||||||
{
|
|
||||||
handler->paths = r->paths;
|
|
||||||
handler->parent = &r->muxer;
|
|
||||||
}
|
|
||||||
return handler;
|
|
||||||
}
|
}
|
||||||
|
if (handler) {
|
||||||
static struct llarp_msg_handler * find_msg_handler(struct llarp_router * r, const char ch)
|
handler->paths = r->paths;
|
||||||
{
|
handler->parent = &r->muxer;
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct llarp_msg_handler* find_msg_handler(struct llarp_router* r,
|
||||||
|
const char ch) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} // namespace llarp
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void llarp_msg_muxer_init(struct llarp_msg_muxer * muxer)
|
void llarp_msg_muxer_init(struct llarp_msg_muxer* muxer) {
|
||||||
{
|
muxer->link_handler_for = &llarp::find_frame_handler;
|
||||||
muxer->link_handler_for = &llarp::find_frame_handler;
|
muxer->routing_handler_for = &llarp::find_msg_handler;
|
||||||
muxer->routing_handler_for = &llarp::find_msg_handler;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,30 @@
|
|||||||
#include "net.hpp"
|
#include "net.hpp"
|
||||||
#include "str.hpp"
|
#include "str.hpp"
|
||||||
|
|
||||||
#include <ifaddrs.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
|
namespace llarp {
|
||||||
|
namespace net {
|
||||||
|
bool GetIfAddr(const std::string& ifname, int af, sockaddr* addr) {
|
||||||
|
ifaddrs* ifa = nullptr;
|
||||||
|
bool found = false;
|
||||||
|
socklen_t sl = sizeof(sockaddr_in6);
|
||||||
|
if (af == AF_INET) sl = sizeof(sockaddr_in);
|
||||||
|
|
||||||
namespace llarp
|
if (getifaddrs(&ifa) == -1) return false;
|
||||||
{
|
ifaddrs* i = ifa;
|
||||||
namespace net
|
while (i) {
|
||||||
{
|
if (llarp::StrEq(i->ifa_name, ifname.c_str()) && i->ifa_addr &&
|
||||||
bool GetIfAddr(const std::string & ifname, int af, sockaddr * addr)
|
i->ifa_addr->sa_family == af) {
|
||||||
{
|
memcpy(addr, i->ifa_addr, sl);
|
||||||
ifaddrs * ifa = nullptr;
|
found = true;
|
||||||
bool found = false;
|
break;
|
||||||
socklen_t sl = sizeof(sockaddr_in6);
|
|
||||||
if(af == AF_INET)
|
|
||||||
sl = sizeof(sockaddr_in);
|
|
||||||
|
|
||||||
if(getifaddrs(&ifa) == -1)
|
|
||||||
return false;
|
|
||||||
ifaddrs * i = ifa;
|
|
||||||
while(i)
|
|
||||||
{
|
|
||||||
if(llarp::StrEq(i->ifa_name, ifname.c_str()) && i->ifa_addr && i->ifa_addr->sa_family == af)
|
|
||||||
{
|
|
||||||
memcpy(addr, i->ifa_addr, sl);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i = i->ifa_next;
|
|
||||||
}
|
|
||||||
if(ifa) freeifaddrs(ifa);
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
i = i->ifa_next;
|
||||||
}
|
}
|
||||||
|
if (ifa) freeifaddrs(ifa);
|
||||||
|
return found;
|
||||||
}
|
}
|
||||||
|
} // namespace net
|
||||||
|
} // namespace llarp
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
#ifndef LLARP_NET_HPP
|
#ifndef LLARP_NET_HPP
|
||||||
#define LLARP_NET_HPP
|
#define LLARP_NET_HPP
|
||||||
#include <string>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp {
|
||||||
{
|
namespace net {
|
||||||
namespace net
|
bool GetIfAddr(const std::string& ifname, int af, sockaddr* addr);
|
||||||
{
|
|
||||||
bool GetIfAddr(const std::string & ifname, int af, sockaddr * addr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace llarp
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,43 +1,40 @@
|
|||||||
#ifndef LLARP_ROUTER_HPP
|
#ifndef LLARP_ROUTER_HPP
|
||||||
#define LLARP_ROUTER_HPP
|
#define LLARP_ROUTER_HPP
|
||||||
#include <llarp/router.h>
|
|
||||||
#include <llarp/link.h>
|
#include <llarp/link.h>
|
||||||
|
#include <llarp/router.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "mem.hpp"
|
#include "mem.hpp"
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp {
|
||||||
{
|
struct router_links {
|
||||||
struct router_links
|
llarp_link *link = nullptr;
|
||||||
{
|
router_links *next = nullptr;
|
||||||
llarp_link * link = nullptr;
|
};
|
||||||
router_links * next = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace llarp
|
|
||||||
|
|
||||||
struct llarp_router {
|
} // namespace llarp
|
||||||
struct llarp_threadpool *tp;
|
|
||||||
llarp::router_links links;
|
|
||||||
llarp_crypto crypto;
|
|
||||||
llarp_msg_muxer muxer;
|
|
||||||
llarp_path_context * paths;
|
|
||||||
|
|
||||||
static void *operator new(size_t sz) {
|
struct llarp_router {
|
||||||
return llarp_g_mem.alloc(sz, llarp::alignment<llarp_router>());
|
struct llarp_threadpool *tp;
|
||||||
}
|
llarp::router_links links;
|
||||||
|
llarp_crypto crypto;
|
||||||
|
llarp_msg_muxer muxer;
|
||||||
|
llarp_path_context *paths;
|
||||||
|
|
||||||
static void operator delete(void *ptr) { llarp_g_mem.free(ptr); }
|
static void *operator new(size_t sz) {
|
||||||
|
return llarp_g_mem.alloc(sz, llarp::alignment<llarp_router>());
|
||||||
|
}
|
||||||
|
|
||||||
llarp_router();
|
static void operator delete(void *ptr) { llarp_g_mem.free(ptr); }
|
||||||
~llarp_router();
|
|
||||||
|
|
||||||
void AddLink(struct llarp_link *link);
|
llarp_router();
|
||||||
|
~llarp_router();
|
||||||
|
|
||||||
void ForEachLink(std::function<void(llarp_link *)> visitor);
|
void AddLink(struct llarp_link *link);
|
||||||
|
|
||||||
void Close();
|
void ForEachLink(std::function<void(llarp_link *)> visitor);
|
||||||
};
|
|
||||||
|
|
||||||
|
void Close();
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue