lokinet/include/llarp/iwp/server.hpp

160 lines
3.0 KiB
C++
Raw Normal View History

#pragma once
2018-08-10 21:34:11 +00:00
#include <llarp/iwp.hpp>
#include <llarp/threading.hpp>
#include "llarp/iwp/establish_job.hpp"
#include "router.hpp"
#include "session.hpp"
2018-08-18 01:30:11 +00:00
#ifndef __linux__
#ifdef saddr
#undef saddr
#endif
#endif
#include <algorithm>
#include <fstream>
struct llarp_link
{
2018-08-29 20:40:26 +00:00
typedef llarp::util::Mutex mtx_t;
typedef llarp::util::Lock 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;
2018-08-10 21:34:11 +00:00
std::string keyfile;
uint32_t timeout_job_id;
const char *
name() const
{
return m_name;
}
2018-07-26 22:06:11 +00:00
const char *m_name;
2018-08-29 20:40:26 +00:00
typedef std::unordered_map<
llarp::Addr, std::unique_ptr< 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;
2018-08-29 20:40:26 +00:00
typedef std::unordered_map<
llarp::Addr, std::unique_ptr< 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
remove_intro_from(const llarp::Addr &from);
2018-08-14 21:17:18 +00:00
/// does nothing if we have no session already established
void
KeepAliveSessionTo(const byte_t *pubkey);
/// does nothing if we have no session already established
void
CloseSessionTo(const byte_t *pubkey);
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);
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);
2018-08-29 20:40:26 +00:00
void
MapAddr(const llarp::Addr &addr, const llarp::PubKey &pk);
void
2018-08-29 20:40:26 +00:00
visit_session(
const llarp::Addr &addr,
std::function< void(const std::unique_ptr< llarp_link_session > &) >
visit);
void
2018-08-29 20:40:26 +00:00
pending_session_active(const llarp::Addr &addr);
2018-07-17 04:37:50 +00:00
void
2018-08-29 20:40:26 +00:00
clear_sessions();
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
const 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-08-30 18:48:43 +00:00
get_our_address(llarp::AddressInfo &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);
};