nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
nanommo::WorldList Class Reference

#include <world_list.h>

Public Types

using Clock = std::chrono::steady_clock
using Fetch = std::function<absl::StatusOr<std::vector<ListedWorld>>()>

Public Member Functions

 WorldList (asio::io_context &io, Fetch fetch)
 WorldList (const WorldList &)=delete
WorldList & operator= (const WorldList &)=delete
 ~WorldList ()
 Destroy it once the io_context has stopped.
void Start ()
 Asks for the list now, and every second after.
void Take (absl::StatusOr< std::vector< ListedWorld > > worlds, Clock::time_point at)
absl::StatusOr< std::string > Find (std::string_view public_host, uint16_t port, Clock::time_point now) const

Static Public Attributes

static constexpr std::chrono::seconds kStale {10}
 A list this old says nothing about now, so every world is refused.

Detailed Description

The worlds Consul lists, which the gateway may connect pages to. Asking Consul waits on the network, so it's done on a thread of its own, once a second, and the list it brings back is read and changed on the io_context's thread alone, where the gateway runs: a page's route never waits for Consul.

Definition at line 32 of file world_list.h.

Member Typedef Documentation

◆ Clock

using nanommo::WorldList::Clock = std::chrono::steady_clock

Definition at line 34 of file world_list.h.

◆ Fetch

using nanommo::WorldList::Fetch = std::function<absl::StatusOr<std::vector<ListedWorld>>()>

Definition at line 35 of file world_list.h.

Constructor & Destructor Documentation

◆ WorldList() [1/2]

nanommo::WorldList::WorldList ( asio::io_context & io,
Fetch fetch )

Definition at line 15 of file world_list.cc.

◆ WorldList() [2/2]

nanommo::WorldList::WorldList ( const WorldList & )
delete

◆ ~WorldList()

nanommo::WorldList::~WorldList ( )

Destroy it once the io_context has stopped.

Definition at line 18 of file world_list.cc.

Member Function Documentation

◆ Find()

absl::StatusOr< std::string > nanommo::WorldList::Find ( std::string_view public_host,
uint16_t port,
Clock::time_point now ) const

The world's own address: NotFound when it isn't on the list, and Unavailable when there's no list newer than kStale.

Definition at line 59 of file world_list.cc.

◆ operator=()

WorldList & nanommo::WorldList::operator= ( const WorldList & )
delete

◆ Start()

void nanommo::WorldList::Start ( )

Asks for the list now, and every second after.

Definition at line 23 of file world_list.cc.

◆ Take()

void nanommo::WorldList::Take ( absl::StatusOr< std::vector< ListedWorld > > worlds,
Clock::time_point at )

A list that came back at the time, on the io_context's thread. An error keeps the list from before, which grows stale.

Definition at line 48 of file world_list.cc.

Member Data Documentation

◆ kStale

std::chrono::seconds nanommo::WorldList::kStale {10}
staticconstexpr

A list this old says nothing about now, so every world is refused.

Definition at line 38 of file world_list.h.


The documentation for this class was generated from the following files: