2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/net/net.hpp>
|
|
|
|
#include <llarp/ev/ev.hpp>
|
|
|
|
#include <llarp/router_contact.hpp>
|
|
|
|
#include <llarp/util/types.hpp>
|
2018-12-12 01:55:30 +00:00
|
|
|
|
2018-09-06 11:46:19 +00:00
|
|
|
#include <functional>
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct LinkIntroMessage;
|
|
|
|
struct ILinkMessage;
|
2018-09-04 19:15:06 +00:00
|
|
|
struct ILinkLayer;
|
2019-07-26 16:19:31 +00:00
|
|
|
|
2020-06-04 16:00:30 +00:00
|
|
|
struct SessionStats
|
|
|
|
{
|
|
|
|
// rate
|
|
|
|
uint64_t currentRateRX = 0;
|
|
|
|
uint64_t currentRateTX = 0;
|
|
|
|
|
|
|
|
uint64_t totalPacketsRX = 0;
|
|
|
|
|
|
|
|
uint64_t totalAckedTX = 0;
|
|
|
|
uint64_t totalDroppedTX = 0;
|
|
|
|
uint64_t totalInFlightTX = 0;
|
|
|
|
};
|
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
struct ILinkSession
|
2018-09-02 18:25:42 +00:00
|
|
|
{
|
2019-08-29 11:45:58 +00:00
|
|
|
virtual ~ILinkSession() = default;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-07-26 16:19:31 +00:00
|
|
|
/// delivery status of a message
|
|
|
|
enum class DeliveryStatus
|
|
|
|
{
|
|
|
|
eDeliverySuccess = 0,
|
|
|
|
eDeliveryDropped = 1
|
|
|
|
};
|
|
|
|
|
2019-04-02 09:03:53 +00:00
|
|
|
/// hook for utp for when we have established a connection
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
OnLinkEstablished(ILinkLayer*){};
|
2019-04-02 09:03:53 +00:00
|
|
|
|
2021-11-11 14:17:48 +00:00
|
|
|
/// called during pumping
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual void
|
|
|
|
Pump() = 0;
|
2018-09-03 13:10:56 +00:00
|
|
|
|
|
|
|
/// called every timer tick
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual void Tick(llarp_time_t) = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-07-26 16:19:31 +00:00
|
|
|
/// message delivery result hook function
|
2020-04-07 18:38:56 +00:00
|
|
|
using CompletionHandler = std::function<void(DeliveryStatus)>;
|
2019-07-26 16:19:31 +00:00
|
|
|
|
2020-05-21 14:20:47 +00:00
|
|
|
using Packet_t = std::vector<byte_t>;
|
2020-04-07 18:38:56 +00:00
|
|
|
using Message_t = std::vector<byte_t>;
|
2019-09-12 14:34:27 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
/// send a message buffer to the remote endpoint
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual bool
|
2019-09-12 14:34:27 +00:00
|
|
|
SendMessageBuffer(Message_t, CompletionHandler handler) = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2018-09-04 12:41:25 +00:00
|
|
|
/// start the connection
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual void
|
|
|
|
Start() = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual void
|
|
|
|
Close() = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
2019-08-29 11:45:58 +00:00
|
|
|
/// recv packet on low layer
|
|
|
|
/// not used by utp
|
2019-11-19 16:24:29 +00:00
|
|
|
virtual bool Recv_LL(Packet_t)
|
2019-08-29 11:45:58 +00:00
|
|
|
{
|
2019-11-19 16:24:29 +00:00
|
|
|
return true;
|
2019-08-29 11:45:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 09:03:53 +00:00
|
|
|
/// send a keepalive to the remote endpoint
|
|
|
|
virtual bool
|
|
|
|
SendKeepAlive() = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
/// return true if we are established
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual bool
|
2019-05-07 13:04:43 +00:00
|
|
|
IsEstablished() const = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
/// return true if this session has timed out
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual bool
|
|
|
|
TimedOut(llarp_time_t now) const = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
|
|
|
|
/// get remote public identity key
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual PubKey
|
|
|
|
GetPubKey() const = 0;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2020-01-21 17:31:48 +00:00
|
|
|
/// is an inbound session or not
|
|
|
|
virtual bool
|
|
|
|
IsInbound() const = 0;
|
|
|
|
|
2018-09-07 17:41:49 +00:00
|
|
|
/// get remote address
|
2021-02-22 15:01:05 +00:00
|
|
|
virtual const SockAddr&
|
2019-04-02 09:03:53 +00:00
|
|
|
GetRemoteEndpoint() const = 0;
|
2018-09-08 15:53:20 +00:00
|
|
|
|
2018-12-17 20:46:08 +00:00
|
|
|
// get remote rc
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual RouterContact
|
|
|
|
GetRemoteRC() const = 0;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
2020-11-10 14:24:58 +00:00
|
|
|
/// is this session a session to a relay?
|
|
|
|
bool
|
|
|
|
IsRelay() const;
|
|
|
|
|
2018-09-08 15:53:20 +00:00
|
|
|
/// handle a valid LIM
|
2020-04-07 18:38:56 +00:00
|
|
|
std::function<bool(const LinkIntroMessage* msg)> GotLIM;
|
2018-09-18 20:56:22 +00:00
|
|
|
|
|
|
|
/// send queue current blacklog
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual size_t
|
|
|
|
SendQueueBacklog() const = 0;
|
2018-12-17 20:46:08 +00:00
|
|
|
|
|
|
|
/// get parent link layer
|
2020-04-07 18:38:56 +00:00
|
|
|
virtual ILinkLayer*
|
2019-04-02 09:03:53 +00:00
|
|
|
GetLinkLayer() const = 0;
|
2018-12-19 16:17:41 +00:00
|
|
|
|
|
|
|
/// renegotiate session when we have a new RC locally
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual bool
|
|
|
|
RenegotiateSession() = 0;
|
2019-03-18 12:25:32 +00:00
|
|
|
|
|
|
|
/// return true if we should send an explicit keepalive message
|
2019-04-02 09:03:53 +00:00
|
|
|
virtual bool
|
|
|
|
ShouldPing() const = 0;
|
2019-04-19 15:10:26 +00:00
|
|
|
|
2020-06-04 16:00:30 +00:00
|
|
|
/// return the current stats for this session
|
|
|
|
virtual SessionStats
|
|
|
|
GetSessionStats() const = 0;
|
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
2021-11-11 21:46:53 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
HandlePlaintext() = 0;
|
2018-09-02 18:25:42 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp
|