2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-03-29 14:30:19 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/constants/link_layer.hpp>
|
|
|
|
#include <llarp/crypto/crypto.hpp>
|
|
|
|
#include <llarp/crypto/encrypted.hpp>
|
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/link/server.hpp>
|
|
|
|
#include <llarp/config/key_manager.hpp>
|
2021-02-23 10:48:50 +00:00
|
|
|
|
2019-12-03 17:58:53 +00:00
|
|
|
#include <memory>
|
2019-03-29 14:30:19 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/ev/ev.hpp>
|
2021-02-22 13:26:32 +00:00
|
|
|
|
|
|
|
namespace llarp::iwp
|
2019-03-29 14:30:19 +00:00
|
|
|
{
|
2021-02-22 13:26:32 +00:00
|
|
|
struct Session;
|
|
|
|
|
|
|
|
struct LinkLayer final : public ILinkLayer
|
2019-03-29 14:30:19 +00:00
|
|
|
{
|
2021-02-22 13:26:32 +00:00
|
|
|
LinkLayer(
|
|
|
|
std::shared_ptr<KeyManager> keyManager,
|
|
|
|
std::shared_ptr<EventLoop> ev,
|
|
|
|
GetRCFunc getrc,
|
|
|
|
LinkMessageHandler h,
|
|
|
|
SignBufferFunc sign,
|
|
|
|
BeforeConnectFunc_t before,
|
|
|
|
SessionEstablishedHandler est,
|
|
|
|
SessionRenegotiateHandler reneg,
|
|
|
|
TimeoutHandler timeout,
|
|
|
|
SessionClosedHandler closed,
|
|
|
|
PumpDoneHandler pumpDone,
|
|
|
|
WorkerFunc_t dowork,
|
|
|
|
bool permitInbound);
|
|
|
|
|
|
|
|
std::shared_ptr<ILinkSession>
|
|
|
|
NewOutboundSession(const RouterContact& rc, const AddressInfo& ai) override;
|
|
|
|
|
|
|
|
const char*
|
|
|
|
Name() const override;
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
Rank() const override;
|
|
|
|
|
|
|
|
void
|
|
|
|
RecvFrom(const SockAddr& from, ILinkSession::Packet_t pkt) override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
MapAddr(const RouterID& pk, ILinkSession* s) override;
|
|
|
|
|
|
|
|
void
|
2021-02-22 15:01:05 +00:00
|
|
|
UnmapAddr(const SockAddr& addr);
|
2021-02-22 13:26:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
WakeupPlaintext();
|
|
|
|
|
|
|
|
void
|
|
|
|
AddWakeup(std::weak_ptr<Session> peer);
|
|
|
|
|
2021-07-01 12:30:29 +00:00
|
|
|
std::string
|
|
|
|
PrintableName() const;
|
|
|
|
|
2021-02-22 13:26:32 +00:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
HandleWakeupPlaintext();
|
|
|
|
|
2021-03-02 02:06:20 +00:00
|
|
|
const std::shared_ptr<EventLoopWakeup> m_Wakeup;
|
2021-03-09 18:39:40 +00:00
|
|
|
std::unordered_map<SockAddr, std::weak_ptr<Session>> m_PlaintextRecv;
|
|
|
|
std::unordered_map<SockAddr, RouterID> m_AuthedAddrs;
|
2021-07-01 12:14:43 +00:00
|
|
|
const bool m_Inbound;
|
2021-02-22 13:26:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using LinkLayer_ptr = std::shared_ptr<LinkLayer>;
|
|
|
|
} // namespace llarp::iwp
|