You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/service/endpoint_util.hpp

78 lines
1.9 KiB
C++

#pragma once
#include "endpoint_types.hpp"
namespace llarp::service
{
struct EndpointUtil
{
static void
12 months ago
ExpireSNodeSessions(llarp_time_t now, SNodeConnectionMap& sessions);
static void
12 months ago
ExpirePendingTx(llarp_time_t now, PendingLookupsMap& lookups);
static void
12 months ago
ExpirePendingRouterLookups(llarp_time_t now, PendingRoutersMap& routers);
static void
12 months ago
DeregisterDeadSessions(llarp_time_t now, ConnectionMap& sessions);
static void
TickRemoteSessions(
12 months ago
llarp_time_t now,
ConnectionMap& remoteSessions,
ConnectionMap& deadSessions,
std::unordered_map<ConvoTag, Session>& sessions);
static void
12 months ago
ExpireConvoSessions(llarp_time_t now, std::unordered_map<ConvoTag, Session>& sessions);
static void
12 months ago
StopRemoteSessions(ConnectionMap& remoteSessions);
static void
12 months ago
StopSnodeSessions(SNodeConnectionMap& sessions);
static bool
12 months ago
HasPathToService(const Address& addr, const ConnectionMap& remoteSessions);
static bool
12 months ago
GetConvoTagsForService(
const std::unordered_map<ConvoTag, Session>& sessions,
const Address& addr,
std::set<ConvoTag>& tags);
};
template <typename Endpoint_t>
static path::Path::UniqueEndpointSet_t
GetManyPathsWithUniqueEndpoints(
Endpoint_t* ep,
size_t N,
std::optional<dht::Key_t> maybeLocation = std::nullopt,
size_t tries = 10)
{
std::unordered_set<RouterID> exclude;
path::Path::UniqueEndpointSet_t paths;
do
{
--tries;
path::Path_ptr path;
if (maybeLocation)
{
path = ep->GetEstablishedPathClosestTo(RouterID{maybeLocation->as_array()}, exclude);
}
else
{
path = ep->PickRandomEstablishedPath();
}
if (path and path->IsReady())
{
paths.emplace(path);
exclude.insert(path->Endpoint());
}
} while (tries > 0 and paths.size() < N);
return paths;
}
} // namespace llarp::service