2019-06-26 21:39:29 +00:00
|
|
|
#ifndef LLARP_LINK_MANAGER_HPP
|
|
|
|
#define LLARP_LINK_MANAGER_HPP
|
|
|
|
|
|
|
|
#include <link/i_link_manager.hpp>
|
|
|
|
|
|
|
|
#include <util/compare_ptr.hpp>
|
2019-09-01 13:26:16 +00:00
|
|
|
#include <util/thread/threading.hpp>
|
2019-06-26 21:39:29 +00:00
|
|
|
#include <link/server.hpp>
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <set>
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct IRouterContactManager;
|
|
|
|
|
|
|
|
struct LinkManager final : public ILinkManager
|
|
|
|
{
|
|
|
|
public:
|
2019-07-30 23:42:13 +00:00
|
|
|
~LinkManager() override = default;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
LinkLayer_ptr
|
|
|
|
GetCompatibleLink(const RouterContact &rc) const override;
|
|
|
|
|
|
|
|
IOutboundSessionMaker *
|
|
|
|
GetSessionMaker() const override;
|
|
|
|
|
|
|
|
bool
|
2019-07-26 16:19:31 +00:00
|
|
|
SendTo(const RouterID &remote, const llarp_buffer_t &buf,
|
|
|
|
ILinkSession::CompletionHandler completed) override;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
HasSessionTo(const RouterID &remote) const override;
|
|
|
|
|
|
|
|
void
|
|
|
|
PumpLinks() override;
|
|
|
|
|
|
|
|
void
|
|
|
|
AddLink(LinkLayer_ptr link, bool inbound = false) override;
|
|
|
|
|
|
|
|
bool
|
2019-09-05 17:39:09 +00:00
|
|
|
StartLinks(Logic_ptr logic,
|
|
|
|
std::shared_ptr< thread::ThreadPool > worker) override;
|
2019-06-26 21:39:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Stop() override;
|
|
|
|
|
|
|
|
void
|
|
|
|
PersistSessionUntil(const RouterID &remote, llarp_time_t until) override;
|
|
|
|
|
|
|
|
void
|
|
|
|
ForEachPeer(std::function< void(const ILinkSession *, bool) > visit,
|
|
|
|
bool randomize = false) const override;
|
|
|
|
|
|
|
|
void
|
|
|
|
ForEachPeer(std::function< void(ILinkSession *) > visit) override;
|
|
|
|
|
|
|
|
void
|
|
|
|
ForEachInboundLink(
|
|
|
|
std::function< void(LinkLayer_ptr) > visit) const override;
|
|
|
|
|
|
|
|
size_t
|
|
|
|
NumberOfConnectedRouters() const override;
|
|
|
|
|
|
|
|
size_t
|
|
|
|
NumberOfConnectedClients() const override;
|
|
|
|
|
2019-12-03 17:03:19 +00:00
|
|
|
size_t
|
|
|
|
NumberOfPendingConnections() const override;
|
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
bool
|
|
|
|
GetRandomConnectedRouter(RouterContact &router) const override;
|
|
|
|
|
|
|
|
void
|
|
|
|
CheckPersistingSessions(llarp_time_t now) override;
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
util::StatusObject
|
2019-06-26 21:39:29 +00:00
|
|
|
ExtractStatus() const override;
|
|
|
|
|
|
|
|
void
|
|
|
|
Init(IOutboundSessionMaker *sessionMaker);
|
|
|
|
|
|
|
|
private:
|
|
|
|
LinkLayer_ptr
|
|
|
|
GetLinkWithSessionTo(const RouterID &remote) const;
|
|
|
|
|
|
|
|
std::atomic< bool > stopping;
|
|
|
|
mutable util::Mutex _mutex; // protects m_PersistingSessions
|
|
|
|
|
|
|
|
using LinkSet = std::set< LinkLayer_ptr, ComparePtr< LinkLayer_ptr > >;
|
|
|
|
|
|
|
|
LinkSet outboundLinks;
|
|
|
|
LinkSet inboundLinks;
|
|
|
|
|
|
|
|
// sessions to persist -> timestamp to end persist at
|
|
|
|
std::unordered_map< RouterID, llarp_time_t, RouterID::Hash >
|
|
|
|
m_PersistingSessions GUARDED_BY(_mutex);
|
|
|
|
|
|
|
|
IOutboundSessionMaker *_sessionMaker;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif // LLARP_LINK_MANAGER_HPP
|