mirror of https://github.com/oxen-io/lokinet
more
parent
ae76b6b376
commit
1fdfdc0244
@ -1,4 +1,4 @@
|
|||||||
[router]
|
[router]
|
||||||
|
|
||||||
[links]
|
[links]
|
||||||
eth0=ip
|
lo=ip
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef LLARP_DHT_H_
|
||||||
|
#define LLARP_DHT_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct llarp_dht_context;
|
||||||
|
|
||||||
|
struct llarp_dht_context * llarp_dht_context_new();
|
||||||
|
void llarp_dht_context_free(struct llarp_dht_context * dht);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -1,17 +1,19 @@
|
|||||||
#include "exit_info.hpp"
|
#include "exit_info.hpp"
|
||||||
#include "bencode.hpp"
|
#include "bencode.hpp"
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buff) {
|
|
||||||
return llarp::BEncode(*xi, buff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace llarp {
|
namespace llarp {
|
||||||
bool BEncode(const llarp_xi &xi, llarp_buffer_t *buff) {
|
template<>
|
||||||
|
bool BEncode(const struct llarp_xi &xi, llarp_buffer_t *buff) {
|
||||||
return bencodeDict(buff) &&
|
return bencodeDict(buff) &&
|
||||||
bencodeDict_Bytes(buff, "a", &xi.address, sizeof(xi.address)) &&
|
bencodeDict_Bytes(buff, "a", &xi.address, sizeof(xi.address)) &&
|
||||||
bencodeDict_Bytes(buff, "b", &xi.netmask, sizeof(xi.netmask)) &&
|
bencodeDict_Bytes(buff, "b", &xi.netmask, sizeof(xi.netmask)) &&
|
||||||
bencodeDict_Int(buff, "v", 0) && bencodeEnd(buff);
|
bencodeDict_Int(buff, "v", 0) && bencodeEnd(buff);
|
||||||
}
|
}
|
||||||
} // namespace llarp
|
} // namespace llarp
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buff) {
|
||||||
|
return llarp::BEncode(*xi, buff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef LLARP_LINK_HANDLERS_HPP
|
||||||
|
#define LLARP_LINK_HANDLERS_HPP
|
||||||
|
#include <llarp/msg_handler.h>
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace frame
|
||||||
|
{
|
||||||
|
bool process_intro(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg);
|
||||||
|
bool process_relay_commit(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);
|
||||||
|
bool process_relay_up(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg);
|
||||||
|
bool process_relay_accept(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg);
|
||||||
|
bool process_relay_status(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg);
|
||||||
|
bool process_relay_exit(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,12 @@
|
|||||||
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace frame
|
||||||
|
{
|
||||||
|
bool process_intro(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace frame
|
||||||
|
{
|
||||||
|
bool process_relay_down(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace frame
|
||||||
|
{
|
||||||
|
bool process_relay_up(struct llarp_frame_handler * h, struct llarp_link_session * s, llarp_buffer_t msg)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
#include <llarp/msg_handler.h>
|
||||||
|
#include "router.hpp"
|
||||||
|
#include "link_handlers.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
struct llarp_frame_handler introduce_handler = {
|
||||||
|
.paths = nullptr,
|
||||||
|
.parent = nullptr,
|
||||||
|
.process = &llarp::frame::process_intro
|
||||||
|
};
|
||||||
|
|
||||||
|
struct llarp_frame_handler lrdm_handler = {
|
||||||
|
.paths = nullptr,
|
||||||
|
.parent = nullptr,
|
||||||
|
.process = &llarp::frame::process_relay_down
|
||||||
|
};
|
||||||
|
|
||||||
|
struct llarp_frame_handler lrum_handler = {
|
||||||
|
.paths = nullptr,
|
||||||
|
.parent = nullptr,
|
||||||
|
.process = &llarp::frame::process_relay_up
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct llarp_frame_handler * find_frame_handler(struct llarp_router * r, const char ch)
|
||||||
|
{
|
||||||
|
struct llarp_frame_handler * handler = nullptr;
|
||||||
|
switch(ch)
|
||||||
|
{
|
||||||
|
case 'i':
|
||||||
|
handler = &introduce_handler;
|
||||||
|
}
|
||||||
|
if(handler)
|
||||||
|
{
|
||||||
|
handler->paths = r->paths;
|
||||||
|
handler->parent = &r->muxer;
|
||||||
|
}
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct llarp_msg_handler * find_msg_handler(struct llarp_router * r, const char ch)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
void llarp_msg_muxer_init(struct llarp_msg_muxer * muxer)
|
||||||
|
{
|
||||||
|
muxer->link_handler_for = &llarp::find_frame_handler;
|
||||||
|
muxer->routing_handler_for = &llarp::find_msg_handler;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
#include "net.hpp"
|
||||||
|
#include "str.hpp"
|
||||||
|
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <arpa/inet.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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef LLARP_NET_HPP
|
||||||
|
#define LLARP_NET_HPP
|
||||||
|
#include <string>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
namespace net
|
||||||
|
{
|
||||||
|
bool GetIfAddr(const std::string & ifname, int af, sockaddr * addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef LLARP_ROUTER_HPP
|
||||||
|
#define LLARP_ROUTER_HPP
|
||||||
|
#include <llarp/router.h>
|
||||||
|
#include <llarp/link.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "mem.hpp"
|
||||||
|
|
||||||
|
namespace llarp
|
||||||
|
{
|
||||||
|
struct router_links
|
||||||
|
{
|
||||||
|
llarp_link * link = nullptr;
|
||||||
|
router_links * next = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace llarp
|
||||||
|
|
||||||
|
struct llarp_router {
|
||||||
|
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) {
|
||||||
|
return llarp_g_mem.alloc(sz, llarp::alignment<llarp_router>());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void operator delete(void *ptr) { llarp_g_mem.free(ptr); }
|
||||||
|
|
||||||
|
llarp_router();
|
||||||
|
~llarp_router();
|
||||||
|
|
||||||
|
void AddLink(struct llarp_link *link);
|
||||||
|
|
||||||
|
void ForEachLink(std::function<void(llarp_link *)> visitor);
|
||||||
|
|
||||||
|
void Close();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue