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 "server.hpp"
|
|
|
|
#include <llarp/util/types.hpp>
|
|
|
|
#include <llarp/peerstats/peer_db.hpp>
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
#include <functional>
|
2020-11-10 14:24:58 +00:00
|
|
|
#include <optional>
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
struct llarp_buffer_t;
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct RouterContact;
|
|
|
|
struct ILinkSession;
|
|
|
|
struct IOutboundSessionMaker;
|
|
|
|
struct RouterID;
|
|
|
|
|
|
|
|
struct ILinkManager
|
|
|
|
{
|
|
|
|
virtual ~ILinkManager() = default;
|
|
|
|
|
|
|
|
virtual LinkLayer_ptr
|
2020-04-07 18:38:56 +00:00
|
|
|
GetCompatibleLink(const RouterContact& rc) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
virtual IOutboundSessionMaker*
|
2019-06-26 21:39:29 +00:00
|
|
|
GetSessionMaker() const = 0;
|
|
|
|
|
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
SendTo(
|
|
|
|
const RouterID& remote,
|
|
|
|
const llarp_buffer_t& buf,
|
|
|
|
ILinkSession::CompletionHandler completed) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HasSessionTo(const RouterID& remote) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
2021-06-07 22:31:57 +00:00
|
|
|
// it is fine to have both an inbound and outbound session with
|
|
|
|
// another relay, and is useful for network testing. This test
|
|
|
|
// is more specific for use with "should we connect outbound?"
|
|
|
|
virtual bool
|
|
|
|
HasOutboundSessionTo(const RouterID& remote) const = 0;
|
|
|
|
|
2020-11-10 14:24:58 +00:00
|
|
|
/// return true if the session with this pubkey is a client
|
|
|
|
/// return false if the session with this pubkey is a router
|
|
|
|
/// return std::nullopt we have no session with this pubkey
|
|
|
|
virtual std::optional<bool>
|
|
|
|
SessionIsClient(RouterID remote) const = 0;
|
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual void
|
|
|
|
PumpLinks() = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
AddLink(LinkLayer_ptr link, bool inbound = false) = 0;
|
|
|
|
|
|
|
|
virtual bool
|
2021-03-02 22:27:35 +00:00
|
|
|
StartLinks() = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
Stop() = 0;
|
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
PersistSessionUntil(const RouterID& remote, llarp_time_t until) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
ForEachPeer(
|
|
|
|
std::function<void(const ILinkSession*, bool)> visit, bool randomize = false) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
ForEachPeer(std::function<void(ILinkSession*)> visit) = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
ForEachInboundLink(std::function<void(LinkLayer_ptr)> visit) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
2021-02-08 11:35:24 +00:00
|
|
|
virtual void
|
|
|
|
ForEachOutboundLink(std::function<void(LinkLayer_ptr)> visit) const = 0;
|
|
|
|
|
2020-11-10 14:24:58 +00:00
|
|
|
/// close all connections to this peer
|
|
|
|
/// remove all link layer commits
|
|
|
|
virtual void
|
|
|
|
DeregisterPeer(RouterID remote) = 0;
|
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual size_t
|
|
|
|
NumberOfConnectedRouters() const = 0;
|
|
|
|
|
|
|
|
virtual size_t
|
|
|
|
NumberOfConnectedClients() const = 0;
|
|
|
|
|
2019-12-03 17:03:19 +00:00
|
|
|
virtual size_t
|
|
|
|
NumberOfPendingConnections() const = 0;
|
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
GetRandomConnectedRouter(RouterContact& router) const = 0;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
CheckPersistingSessions(llarp_time_t now) = 0;
|
|
|
|
|
2020-06-04 16:00:30 +00:00
|
|
|
virtual void
|
|
|
|
updatePeerDb(std::shared_ptr<PeerDb> peerDb) = 0;
|
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|