2018-07-09 04:12:43 +00:00
|
|
|
#pragma once
|
2018-07-26 22:06:11 +00:00
|
|
|
#include <llarp/iwp.h>
|
2018-07-25 00:35:11 +00:00
|
|
|
#include <llarp/threading.hpp>
|
2018-07-09 04:12:43 +00:00
|
|
|
#include "llarp/iwp/establish_job.hpp"
|
|
|
|
#include "router.hpp"
|
|
|
|
#include "session.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
struct llarp_link
|
|
|
|
{
|
|
|
|
typedef std::mutex mtx_t;
|
2018-07-24 21:34:59 +00:00
|
|
|
typedef std::unique_lock< mtx_t > lock_t;
|
|
|
|
/*
|
2018-07-23 22:36:46 +00:00
|
|
|
typedef llarp::util::DummyMutex mtx_t;
|
|
|
|
typedef llarp::util::DummyLock lock_t;
|
2018-07-24 21:34:59 +00:00
|
|
|
*/
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
llarp_router *router;
|
|
|
|
llarp_crypto *crypto;
|
|
|
|
llarp_logic *logic;
|
|
|
|
llarp_ev_loop *netloop;
|
|
|
|
llarp_async_iwp *iwp;
|
|
|
|
llarp_threadpool *worker;
|
|
|
|
llarp_link *parent = nullptr;
|
|
|
|
llarp_udp_io udp;
|
|
|
|
llarp::Addr addr;
|
|
|
|
char keyfile[255];
|
|
|
|
uint32_t timeout_job_id;
|
|
|
|
|
|
|
|
const char *
|
|
|
|
name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
2018-07-26 22:06:11 +00:00
|
|
|
|
2018-07-09 04:12:43 +00:00
|
|
|
const char *m_name;
|
|
|
|
|
|
|
|
typedef std::unordered_map< llarp::Addr, llarp_link_session *,
|
|
|
|
llarp::addrhash >
|
|
|
|
LinkMap_t;
|
|
|
|
|
|
|
|
LinkMap_t m_sessions;
|
|
|
|
mtx_t m_sessions_Mutex;
|
|
|
|
|
2018-07-23 21:59:43 +00:00
|
|
|
typedef std::unordered_map< llarp::PubKey, llarp::Addr, llarp::PubKey::Hash >
|
2018-07-09 04:12:43 +00:00
|
|
|
SessionMap_t;
|
|
|
|
|
|
|
|
SessionMap_t m_Connected;
|
|
|
|
mtx_t m_Connected_Mutex;
|
2018-07-20 04:50:28 +00:00
|
|
|
std::atomic< bool > pumpingLogic;
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
typedef std::unordered_map< llarp::Addr, llarp_link_session *,
|
|
|
|
llarp::addrhash >
|
|
|
|
PendingSessionMap_t;
|
|
|
|
PendingSessionMap_t m_PendingSessions;
|
|
|
|
mtx_t m_PendingSessions_Mutex;
|
|
|
|
|
|
|
|
llarp::SecretKey seckey;
|
|
|
|
|
2018-07-26 22:06:11 +00:00
|
|
|
llarp_link(const llarp_iwp_args &args);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
2018-07-26 22:06:11 +00:00
|
|
|
~llarp_link();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
has_intro_from(const llarp::Addr &from);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
put_intro_from(llarp_link_session *s);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
remove_intro_from(const llarp::Addr &from);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
// set that src address has identity pubkey
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
MapAddr(const llarp::Addr &src, const llarp::PubKey &identity);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
2018-07-26 22:06:11 +00:00
|
|
|
bool
|
|
|
|
has_session_to(const byte_t *pubkey);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
TickSessions();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
2018-07-26 22:06:11 +00:00
|
|
|
bool
|
|
|
|
sendto(const byte_t *pubkey, llarp_buffer_t buf);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
UnmapAddr(const llarp::Addr &src);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
llarp_link_session *
|
2018-07-26 22:06:11 +00:00
|
|
|
create_session(const llarp::Addr &src);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
has_session_via(const llarp::Addr &dst);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
llarp_link_session *
|
2018-07-26 22:06:11 +00:00
|
|
|
find_session(const llarp::Addr &addr);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
put_session(const llarp::Addr &src, llarp_link_session *impl);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
clear_sessions();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
2018-07-17 04:37:50 +00:00
|
|
|
/// safe iterate sessions
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
iterate_sessions(std::function< bool(llarp_link_session *) > visitor);
|
2018-07-17 04:37:50 +00:00
|
|
|
|
2018-07-10 11:36:55 +00:00
|
|
|
static void
|
2018-07-26 22:06:11 +00:00
|
|
|
handle_logic_pump(void *user);
|
2018-07-10 11:36:55 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
PumpLogic();
|
2018-07-10 11:36:55 +00:00
|
|
|
|
2018-07-09 04:12:43 +00:00
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
RemoveSession(llarp_link_session *s);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
uint8_t *
|
2018-07-26 22:06:11 +00:00
|
|
|
pubkey();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
ensure_privkey();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
keygen(const char *fname);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
static void
|
2018-07-26 22:06:11 +00:00
|
|
|
handle_cleanup_timer(void *l, uint64_t orig, uint64_t left);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
// this is called in net threadpool
|
|
|
|
static void
|
|
|
|
handle_recvfrom(struct llarp_udp_io *udp, const struct sockaddr *saddr,
|
2018-07-26 22:06:11 +00:00
|
|
|
const void *buf, ssize_t sz);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
cancel_timer();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
issue_cleanup_timer(uint64_t timeout);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
void
|
2018-07-26 22:06:11 +00:00
|
|
|
get_our_address(struct llarp_ai *addr);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
2018-07-10 11:36:55 +00:00
|
|
|
static void
|
2018-07-26 22:06:11 +00:00
|
|
|
after_recv(llarp_udp_io *udp);
|
2018-07-10 11:36:55 +00:00
|
|
|
|
2018-07-09 04:12:43 +00:00
|
|
|
bool
|
|
|
|
configure(struct llarp_ev_loop *netloop, const char *ifname, int af,
|
2018-07-26 22:06:11 +00:00
|
|
|
uint16_t port);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
2018-07-10 11:47:22 +00:00
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
start_link(struct llarp_logic *pLogic);
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
stop_link();
|
2018-07-09 04:12:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-07-26 22:06:11 +00:00
|
|
|
try_establish(struct llarp_link_establish_job *job);
|
2018-07-09 04:12:43 +00:00
|
|
|
};
|