2019-04-30 01:06:20 +00:00
|
|
|
#ifndef LLARP_SERVICE_ENDPOINT_UTIL_HPP
|
|
|
|
#define LLARP_SERVICE_ENDPOINT_UTIL_HPP
|
|
|
|
|
2019-07-15 09:15:51 +00:00
|
|
|
#include <service/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
|
2019-07-15 09:15:51 +00:00
|
|
|
TickRemoteSessions(llarp_time_t now, Sessions& remoteSessions,
|
|
|
|
Sessions& deadSessions);
|
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
|
2019-07-15 09:15:51 +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
|
|
|
|
|
|
|
template < typename Endpoint_t >
|
2020-02-12 16:40:48 +00:00
|
|
|
static path::Path::UniqueEndpointSet_t
|
2020-02-10 18:46:42 +00:00
|
|
|
GetManyPathsWithUniqueEndpoints(Endpoint_t* ep, size_t N, size_t tries = 10)
|
|
|
|
{
|
|
|
|
path::Path::UniqueEndpointSet_t paths;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--tries;
|
|
|
|
const auto path = ep->PickRandomEstablishedPath();
|
|
|
|
if(path)
|
|
|
|
paths.emplace(path);
|
|
|
|
} 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
|
|
|
|
|
|
|
|
#endif
|