2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-06-26 21:39:29 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/status.hpp>
|
|
|
|
#include <llarp/util/types.hpp>
|
2022-07-16 00:41:14 +00:00
|
|
|
#include <llarp/util/formattable.hpp>
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct ILinkSession;
|
|
|
|
struct RouterID;
|
|
|
|
struct RouterContact;
|
|
|
|
|
|
|
|
enum class SessionResult
|
|
|
|
{
|
|
|
|
Establish,
|
|
|
|
Timeout,
|
|
|
|
RouterNotFound,
|
|
|
|
InvalidRouter,
|
2021-07-01 16:29:42 +00:00
|
|
|
NoLink,
|
|
|
|
EstablishFail
|
2019-06-26 21:39:29 +00:00
|
|
|
};
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
constexpr std::string_view
|
|
|
|
ToString(SessionResult sr)
|
2021-07-01 16:10:26 +00:00
|
|
|
{
|
2022-07-16 00:41:14 +00:00
|
|
|
return sr == llarp::SessionResult::Establish ? "success"sv
|
|
|
|
: sr == llarp::SessionResult::Timeout ? "timeout"sv
|
|
|
|
: sr == llarp::SessionResult::NoLink ? "no link"sv
|
|
|
|
: sr == llarp::SessionResult::InvalidRouter ? "invalid router"sv
|
|
|
|
: sr == llarp::SessionResult::RouterNotFound ? "not found"sv
|
|
|
|
: sr == llarp::SessionResult::EstablishFail ? "establish failed"sv
|
|
|
|
: "???"sv;
|
2021-07-01 16:10:26 +00:00
|
|
|
}
|
2022-07-16 00:41:14 +00:00
|
|
|
template <>
|
|
|
|
constexpr inline bool IsToStringFormattable<SessionResult> = true;
|
2021-07-01 16:10:26 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using RouterCallback = std::function<void(const RouterID&, const SessionResult)>;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
struct IOutboundSessionMaker
|
|
|
|
{
|
|
|
|
virtual ~IOutboundSessionMaker() = default;
|
|
|
|
|
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
OnSessionEstablished(ILinkSession* session) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
OnConnectTimeout(ILinkSession* session) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
CreateSessionTo(const RouterID& router, RouterCallback on_result) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
CreateSessionTo(const RouterContact& rc, RouterCallback on_result) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HavePendingSessionTo(const RouterID& router) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2019-12-09 15:17:02 +00:00
|
|
|
ConnectToRandomRouters(int numDesired) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
2019-08-12 12:40:38 +00:00
|
|
|
|
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
ShouldConnectTo(const RouterID& router) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|