2018-09-02 20:25:42 +02:00
|
|
|
#ifndef LLARP_LINK_SESSION_HPP
|
|
|
|
#define LLARP_LINK_SESSION_HPP
|
|
|
|
|
2019-01-13 17:30:07 +01:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-11 02:42:02 +01:00
|
|
|
#include <net/net.hpp>
|
2019-10-02 15:06:14 +02:00
|
|
|
#include <ev/ev.hpp>
|
2018-12-12 02:55:30 +01:00
|
|
|
#include <router_contact.hpp>
|
2019-01-10 20:41:51 +01:00
|
|
|
#include <util/types.hpp>
|
2018-12-12 02:55:30 +01:00
|
|
|
|
2018-09-06 13:46:19 +02:00
|
|
|
#include <functional>
|
2018-09-02 20:25:42 +02:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct LinkIntroMessage;
|
|
|
|
struct ILinkMessage;
|
2018-09-04 21:15:06 +02:00
|
|
|
struct ILinkLayer;
|
2019-07-26 18:19:31 +02:00
|
|
|
|
2019-04-19 17:10:26 +02:00
|
|
|
struct ILinkSession
|
2018-09-02 20:25:42 +02:00
|
|
|
{
|
2019-08-29 13:45:58 +02:00
|
|
|
virtual ~ILinkSession() = default;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
2019-07-26 18:19:31 +02:00
|
|
|
/// delivery status of a message
|
|
|
|
enum class DeliveryStatus
|
|
|
|
{
|
|
|
|
eDeliverySuccess = 0,
|
|
|
|
eDeliveryDropped = 1
|
|
|
|
};
|
|
|
|
|
2019-08-29 13:45:58 +02:00
|
|
|
/// equiv of shared_from_this but for the interface type so
|
|
|
|
/// that each implementation can use shared_from_this
|
|
|
|
virtual std::shared_ptr< ILinkSession >
|
|
|
|
BorrowSelf() = 0;
|
|
|
|
|
2019-04-02 11:03:53 +02:00
|
|
|
/// hook for utp for when we have established a connection
|
|
|
|
virtual void
|
2019-08-29 13:45:58 +02:00
|
|
|
OnLinkEstablished(ILinkLayer *){};
|
2019-04-02 11:03:53 +02:00
|
|
|
|
2018-09-03 15:10:56 +02:00
|
|
|
/// called every event loop tick
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual void
|
|
|
|
Pump() = 0;
|
2018-09-03 15:10:56 +02:00
|
|
|
|
|
|
|
/// called every timer tick
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual void Tick(llarp_time_t) = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
2019-07-26 18:19:31 +02:00
|
|
|
/// message delivery result hook function
|
|
|
|
using CompletionHandler = std::function< void(DeliveryStatus) >;
|
|
|
|
|
2019-10-02 15:06:14 +02:00
|
|
|
using Packet_t = PacketBuffer;
|
2019-09-12 16:34:27 +02:00
|
|
|
using Message_t = std::vector< byte_t >;
|
|
|
|
|
2018-09-02 20:25:42 +02:00
|
|
|
/// send a message buffer to the remote endpoint
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual bool
|
2019-09-12 16:34:27 +02:00
|
|
|
SendMessageBuffer(Message_t, CompletionHandler handler) = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
2018-09-04 14:41:25 +02:00
|
|
|
/// start the connection
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual void
|
|
|
|
Start() = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual void
|
|
|
|
Close() = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
2019-08-29 13:45:58 +02:00
|
|
|
/// recv packet on low layer
|
|
|
|
/// not used by utp
|
2019-09-12 16:34:27 +02:00
|
|
|
virtual void Recv_LL(Packet_t)
|
2019-08-29 13:45:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:03:53 +02:00
|
|
|
/// send a keepalive to the remote endpoint
|
|
|
|
virtual bool
|
|
|
|
SendKeepAlive() = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
|
|
|
/// return true if we are established
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual bool
|
2019-05-07 15:04:43 +02:00
|
|
|
IsEstablished() const = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
|
|
|
/// return true if this session has timed out
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual bool
|
|
|
|
TimedOut(llarp_time_t now) const = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
|
|
|
|
/// get remote public identity key
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual PubKey
|
|
|
|
GetPubKey() const = 0;
|
2018-12-17 21:46:08 +01:00
|
|
|
|
2018-09-07 19:41:49 +02:00
|
|
|
/// get remote address
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual Addr
|
|
|
|
GetRemoteEndpoint() const = 0;
|
2018-09-08 17:53:20 +02:00
|
|
|
|
2018-12-17 21:46:08 +01:00
|
|
|
// get remote rc
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual RouterContact
|
|
|
|
GetRemoteRC() const = 0;
|
2018-12-17 21:46:08 +01:00
|
|
|
|
2018-09-08 17:53:20 +02:00
|
|
|
/// handle a valid LIM
|
|
|
|
std::function< bool(const LinkIntroMessage *msg) > GotLIM;
|
2018-09-18 22:56:22 +02:00
|
|
|
|
|
|
|
/// send queue current blacklog
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual size_t
|
|
|
|
SendQueueBacklog() const = 0;
|
2018-12-17 21:46:08 +01:00
|
|
|
|
|
|
|
/// get parent link layer
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual ILinkLayer *
|
|
|
|
GetLinkLayer() const = 0;
|
2018-12-19 17:17:41 +01:00
|
|
|
|
|
|
|
/// renegotiate session when we have a new RC locally
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual bool
|
|
|
|
RenegotiateSession() = 0;
|
2019-03-18 13:25:32 +01:00
|
|
|
|
|
|
|
/// return true if we should send an explicit keepalive message
|
2019-04-02 11:03:53 +02:00
|
|
|
virtual bool
|
|
|
|
ShouldPing() const = 0;
|
2019-04-19 17:10:26 +02:00
|
|
|
|
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
2018-09-02 20:25:42 +02:00
|
|
|
};
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|