2018-02-01 17:06:49 +00:00
|
|
|
#ifndef LLARP_ROUTER_HPP
|
|
|
|
#define LLARP_ROUTER_HPP
|
|
|
|
#include <llarp/link.h>
|
2018-02-01 17:07:01 +00:00
|
|
|
#include <llarp/router.h>
|
2018-05-20 17:45:47 +00:00
|
|
|
#include <llarp/router_contact.h>
|
2018-02-01 17:06:49 +00:00
|
|
|
#include <functional>
|
2018-05-22 15:54:19 +00:00
|
|
|
#include <list>
|
2018-05-20 17:45:47 +00:00
|
|
|
#include <map>
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-20 17:45:47 +00:00
|
|
|
#include "fs.hpp"
|
2018-05-22 15:54:19 +00:00
|
|
|
#include "mem.hpp"
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct try_connect_ctx
|
|
|
|
{
|
|
|
|
llarp_router *router = nullptr;
|
|
|
|
llarp_ai addr;
|
|
|
|
};
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-02-01 17:07:01 +00:00
|
|
|
} // namespace llarp
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_router
|
|
|
|
{
|
2018-04-05 14:23:14 +00:00
|
|
|
bool ready;
|
2018-05-20 17:45:47 +00:00
|
|
|
// transient iwp encryption key
|
|
|
|
fs::path transport_keyfile = "transport.key";
|
|
|
|
|
|
|
|
// nodes to connect to on startup
|
2018-05-22 15:54:19 +00:00
|
|
|
std::map< std::string, fs::path > connect;
|
2018-05-20 17:45:47 +00:00
|
|
|
|
|
|
|
// long term identity key
|
|
|
|
fs::path ident_keyfile = "identity.key";
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-05-20 17:45:47 +00:00
|
|
|
// path to write our self signed rc to
|
|
|
|
fs::path our_rc_file = "rc.signed";
|
|
|
|
|
|
|
|
llarp_rc rc;
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_ev_loop *netloop;
|
2018-05-18 20:08:57 +00:00
|
|
|
llarp_threadpool *tp;
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_logic *logic;
|
2018-02-01 17:07:01 +00:00
|
|
|
llarp_crypto crypto;
|
|
|
|
llarp_msg_muxer muxer;
|
|
|
|
llarp_path_context *paths;
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_alloc *mem;
|
2018-05-20 17:45:47 +00:00
|
|
|
llarp_seckey_t identity;
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
std::list< llarp_link * > links;
|
|
|
|
std::map< char, llarp_frame_handler > frame_handlers;
|
|
|
|
|
|
|
|
llarp_router(llarp_alloc *mem);
|
2018-02-01 17:07:01 +00:00
|
|
|
~llarp_router();
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
AddLink(struct llarp_link *link);
|
|
|
|
|
|
|
|
void
|
|
|
|
Close();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Ready();
|
|
|
|
|
|
|
|
void
|
|
|
|
Run();
|
|
|
|
|
|
|
|
bool
|
|
|
|
EnsureIdentity();
|
|
|
|
|
|
|
|
bool
|
|
|
|
SaveRC();
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
uint8_t *
|
|
|
|
pubkey()
|
|
|
|
{
|
|
|
|
return llarp_seckey_topublic(identity);
|
|
|
|
}
|
2018-02-01 17:06:49 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
try_connect(fs::path rcfile);
|
2018-04-05 14:23:14 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
has_session_to(const uint8_t *pubkey) const;
|
2018-05-20 17:45:47 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
static bool
|
|
|
|
iter_try_connect(llarp_router_link_iter *i, llarp_router *router,
|
|
|
|
llarp_link *l);
|
2018-05-20 17:45:47 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
static void
|
|
|
|
on_try_connect_result(llarp_link_establish_job *job);
|
2018-02-01 17:07:01 +00:00
|
|
|
};
|
2018-02-01 17:06:49 +00:00
|
|
|
|
|
|
|
#endif
|