1#ifndef NANOMMO_GATEWAY_WORLD_LIST_H_
2#define NANOMMO_GATEWAY_WORLD_LIST_H_
12#include "absl/status/statusor.h"
13#include "asio/io_context.hpp"
14#include "asio/steady_timer.hpp"
15#include "asio/thread_pool.hpp"
34 using Clock = std::chrono::steady_clock;
35 using Fetch = std::function<absl::StatusOr<std::vector<ListedWorld>>()>;
38 static constexpr std::chrono::seconds
kStale{10};
53 void Take(absl::StatusOr<std::vector<ListedWorld>> worlds,
54 Clock::time_point at);
58 absl::StatusOr<std::string>
Find(std::string_view public_host, uint16_t port,
59 Clock::time_point now)
const;
64 asio::io_context& io_;
66 asio::steady_timer timer_;
67 asio::thread_pool thread_{1};
68 std::vector<ListedWorld> worlds_;
69 std::optional<Clock::time_point> fetched_;
WorldList(asio::io_context &io, Fetch fetch)
absl::StatusOr< std::string > Find(std::string_view public_host, uint16_t port, Clock::time_point now) const
void Take(absl::StatusOr< std::vector< ListedWorld > > worlds, Clock::time_point at)
std::chrono::steady_clock Clock
WorldList & operator=(const WorldList &)=delete
WorldList(const WorldList &)=delete
~WorldList()
Destroy it once the io_context has stopped.
std::function< absl::StatusOr< std::vector< ListedWorld > >()> Fetch
void Start()
Asks for the list now, and every second after.
static constexpr std::chrono::seconds kStale
A list this old says nothing about now, so every world is refused.