1#ifndef NANOMMO_GATEWAY_GATEWAY_H_
2#define NANOMMO_GATEWAY_GATEWAY_H_
10#include "absl/status/statusor.h"
11#include "asio/io_context.hpp"
12#include "asio/ip/tcp.hpp"
13#include "asio/ssl/context.hpp"
26using Route = std::function<absl::StatusOr<Upstream>(std::string_view path)>;
30 std::string_view public_host, uint16_t port)>;
46 static absl::StatusOr<std::unique_ptr<Gateway>>
Create(
47 asio::io_context& io, uint16_t
port, asio::ssl::context& tls,
53 uint16_t
port()
const {
return acceptor_.local_endpoint().port(); }
56 Gateway(asio::io_context& io, asio::ssl::context& tls,
Route route);
60 asio::ip::tcp::acceptor acceptor_;
61 asio::ssl::context& tls_;
Gateway(const Gateway &)=delete
static constexpr std::size_t kMaxMessage
A page's message larger than this is refused, as the servers would.
static absl::StatusOr< std::unique_ptr< Gateway > > Create(asio::io_context &io, uint16_t port, asio::ssl::context &tls, Route route)
Listens on the port (0 for any), or returns why it can't.
Gateway & operator=(const Gateway &)=delete
std::function< absl::StatusOr< std::string >( std::string_view public_host, uint16_t port)> WorldAddress
Finds a world's own address by the host and port players reach it at.
std::function< absl::StatusOr< Upstream >(std::string_view path)> Route
Where a page's path leads, or why nowhere.
std::string Accept(std::string_view key)
The server's answer that switches the connection over to WebSocket.
Route Routes(Upstream login, WorldAddress world_address)