lokinet/include/llarp/iwp/server.hpp

161 lines
3.1 KiB
C++
Raw Normal View History

#pragma once
2018-07-26 22:06:11 +00:00
#include <llarp/iwp.h>
#include <llarp/threading.hpp>
#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;
*/
typedef llarp::util::DummyMutex mtx_t;
typedef llarp::util::DummyLock lock_t;
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
const char *m_name;
typedef std::unordered_map< llarp::Addr, llarp_link_session *,
llarp::Addr::Hash >
LinkMap_t;
LinkMap_t m_sessions;
mtx_t m_sessions_Mutex;
typedef std::unordered_map< llarp::PubKey, llarp::Addr, llarp::PubKey::Hash >
SessionMap_t;
SessionMap_t m_Connected;
mtx_t m_Connected_Mutex;
2018-07-20 04:50:28 +00:00
std::atomic< bool > pumpingLogic;
typedef std::unordered_map< llarp::Addr, llarp_link_session *,
llarp::Addr::Hash >
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-26 22:06:11 +00:00
~llarp_link();
bool
2018-07-26 22:06:11 +00:00
has_intro_from(const llarp::Addr &from);
void
2018-07-26 22:06:11 +00:00
put_intro_from(llarp_link_session *s);
void
2018-07-26 22:06:11 +00:00
remove_intro_from(const llarp::Addr &from);
// 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-26 22:06:11 +00:00
bool
has_session_to(const byte_t *pubkey);
void
2018-07-26 22:06:11 +00:00
TickSessions();
2018-07-26 22:06:11 +00:00
bool
sendto(const byte_t *pubkey, llarp_buffer_t buf);
void
2018-07-26 22:06:11 +00:00
UnmapAddr(const llarp::Addr &src);
llarp_link_session *
2018-07-26 22:06:11 +00:00
create_session(const llarp::Addr &src);
bool
2018-07-26 22:06:11 +00:00
has_session_via(const llarp::Addr &dst);
llarp_link_session *
2018-07-26 22:06:11 +00:00
find_session(const llarp::Addr &addr);
void
2018-07-26 22:06:11 +00:00
put_session(const llarp::Addr &src, llarp_link_session *impl);
void
2018-07-26 22:06:11 +00:00
clear_sessions();
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
void
2018-07-26 22:06:11 +00:00
RemoveSession(llarp_link_session *s);
uint8_t *
2018-07-26 22:06:11 +00:00
pubkey();
bool
2018-07-26 22:06:11 +00:00
ensure_privkey();
bool
2018-07-26 22:06:11 +00:00
keygen(const char *fname);
static void
2018-07-26 22:06:11 +00:00
handle_cleanup_timer(void *l, uint64_t orig, uint64_t left);
// 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);
void
2018-07-26 22:06:11 +00:00
cancel_timer();
void
2018-07-26 22:06:11 +00:00
issue_cleanup_timer(uint64_t timeout);
void
2018-07-26 22:06:11 +00:00
get_our_address(struct llarp_ai *addr);
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
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-10 11:47:22 +00:00
bool
2018-07-26 22:06:11 +00:00
start_link(struct llarp_logic *pLogic);
bool
2018-07-26 22:06:11 +00:00
stop_link();
bool
2018-07-26 22:06:11 +00:00
try_establish(struct llarp_link_establish_job *job);
};