2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-04-30 01:06:20 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "endpoint_types.hpp"
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
struct EndpointUtil
|
|
|
|
{
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
ExpireSNodeSessions(llarp_time_t now, SNodeSessions& sessions);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
ExpirePendingTx(llarp_time_t now, PendingLookups& lookups);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
ExpirePendingRouterLookups(llarp_time_t now, PendingRouters& routers);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
DeregisterDeadSessions(llarp_time_t now, Sessions& sessions);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2020-04-07 18:38:56 +00:00
|
|
|
TickRemoteSessions(
|
|
|
|
llarp_time_t now, Sessions& remoteSessions, Sessions& deadSessions, ConvoMap& sessions);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
ExpireConvoSessions(llarp_time_t now, ConvoMap& sessions);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
StopRemoteSessions(Sessions& remoteSessions);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static void
|
2019-07-15 09:15:51 +00:00
|
|
|
StopSnodeSessions(SNodeSessions& sessions);
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
static bool
|
2019-07-15 09:15:51 +00:00
|
|
|
HasPathToService(const Address& addr, const Sessions& remoteSessions);
|
2019-05-07 08:29:47 +00:00
|
|
|
|
|
|
|
static bool
|
2020-04-07 18:38:56 +00:00
|
|
|
GetConvoTagsForService(
|
|
|
|
const ConvoMap& sessions, const Address& addr, std::set<ConvoTag>& tags);
|
2019-04-30 01:06:20 +00:00
|
|
|
};
|
2020-02-10 18:46:42 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
template <typename Endpoint_t>
|
2020-02-12 16:40:48 +00:00
|
|
|
static path::Path::UniqueEndpointSet_t
|
2021-06-02 19:52:13 +00:00
|
|
|
GetManyPathsWithUniqueEndpoints(
|
|
|
|
Endpoint_t* ep,
|
|
|
|
size_t N,
|
|
|
|
std::optional<dht::Key_t> maybeLocation = std::nullopt,
|
|
|
|
size_t tries = 10)
|
2020-02-10 18:46:42 +00:00
|
|
|
{
|
2021-06-02 19:52:13 +00:00
|
|
|
std::unordered_set<RouterID> exclude;
|
2020-02-10 18:46:42 +00:00
|
|
|
path::Path::UniqueEndpointSet_t paths;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--tries;
|
2021-06-02 19:52:13 +00:00
|
|
|
path::Path_ptr path;
|
|
|
|
if (maybeLocation)
|
|
|
|
{
|
|
|
|
path = ep->GetEstablishedPathClosestTo(RouterID{maybeLocation->as_array()}, exclude);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = ep->PickRandomEstablishedPath();
|
|
|
|
}
|
2021-05-03 15:35:40 +00:00
|
|
|
if (path and path->IsReady())
|
2021-06-02 19:52:13 +00:00
|
|
|
{
|
2020-02-10 18:46:42 +00:00
|
|
|
paths.emplace(path);
|
2021-06-02 19:52:13 +00:00
|
|
|
exclude.insert(path->Endpoint());
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
} while (tries > 0 and paths.size() < N);
|
2020-02-12 16:40:48 +00:00
|
|
|
return paths;
|
2020-02-10 18:46:42 +00:00
|
|
|
}
|
2019-04-30 01:06:20 +00:00
|
|
|
} // namespace service
|
|
|
|
|
|
|
|
} // namespace llarp
|