lokinet/llarp/utp/linklayer.hpp

113 lines
2.3 KiB
C++
Raw Normal View History

2019-03-29 14:23:19 +00:00
#ifndef LLARP_UTP_LINKLAYER_HPP
#define LLARP_UTP_LINKLAYER_HPP
2019-03-29 14:03:07 +00:00
2019-03-29 14:23:19 +00:00
#include <utp/inbound_message.hpp>
2019-03-29 14:03:07 +00:00
#include <crypto/crypto.hpp>
#include <crypto/types.hpp>
#include <link/server.hpp>
#include <utp.h>
#include <deque>
namespace llarp
{
namespace utp
{
struct LinkLayer final : public ILinkLayer
{
utp_context* _utp_ctx = nullptr;
Crypto* _crypto = nullptr;
// low level read callback
static uint64
OnRead(utp_callback_arguments* arg);
// low level sendto callback
static uint64
SendTo(utp_callback_arguments* arg);
/// error callback
static uint64
OnError(utp_callback_arguments* arg);
/// state change callback
static uint64
OnStateChange(utp_callback_arguments*);
static uint64
OnConnect(utp_callback_arguments*);
/// accept callback
static uint64
OnAccept(utp_callback_arguments*);
/// logger callback
static uint64
OnLog(utp_callback_arguments* arg);
/// construct
LinkLayer(Crypto* crypto, const SecretKey& routerEncSecret,
GetRCFunc getrc, LinkMessageHandler h, SignBufferFunc sign,
SessionEstablishedHandler established,
SessionRenegotiateHandler reneg, TimeoutHandler timeout,
SessionClosedHandler closed);
/// destruct
~LinkLayer();
/// get AI rank
uint16_t
2019-04-02 09:03:53 +00:00
Rank() const override;
2019-03-29 14:03:07 +00:00
/// handle low level recv
void
2019-04-02 09:03:53 +00:00
RecvFrom(const Addr& from, const void* buf, size_t sz) override;
2019-03-29 14:03:07 +00:00
#ifdef __linux__
/// process ICMP stuff on linux
void
ProcessICMP();
#endif
Crypto*
2019-04-02 09:03:53 +00:00
OurCrypto() override
{
return _crypto;
}
2019-03-29 14:03:07 +00:00
/// pump sessions
void
2019-04-02 09:03:53 +00:00
Pump() override;
2019-03-29 14:03:07 +00:00
/// stop link layer
void
Stop();
/// regenerate transport keypair
bool
2019-04-02 09:03:53 +00:00
KeyGen(SecretKey& k) override;
2019-03-29 14:03:07 +00:00
/// do tick
void
Tick(llarp_time_t now);
/// create new outbound session
2019-04-02 09:03:53 +00:00
std::shared_ptr< ILinkSession >
NewOutboundSession(const RouterContact& rc,
const AddressInfo& addr) override;
2019-03-29 14:03:07 +00:00
/// create new socket
utp_socket*
NewSocket();
/// get ai name
const char*
2019-04-02 09:03:53 +00:00
Name() const override;
2019-03-29 14:03:07 +00:00
};
} // namespace utp
} // namespace llarp
#endif