Foundation / checks (ecs) (push) Successful in 2m21s
Foundation / checks (deploy) (push) Successful in 4m1s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 7m21s
Foundation / checks (network) (push) Canceled after 9m43s
Foundation / checks (checks) (push) Canceled after 9m49s
Foundation / checks (postgres) (push) Canceled after 9m43s
Foundation / checks (client) (push) Canceled after 9m48s
Sign In / Register opens the system browser (PKCE S256, loopback 127.0.0.1:47600) and keeps the refresh token in Windows Credential Manager. The client then fetches a 10-minute grant from grants.aeternalisgames.com and connects to the cellular DEV region. It renews the grant about a minute before expiry through SessionRefresh, and again after a lost connection. Sign Out closes the session and revokes the login at the broker and at Keycloak. Grant replies are cross-checked against the grant record before use. The manual grant-bundle path stays for developers. The bounded JSON reader moves to evo_json (evo::serialization), shared by the broker and the client. Adds the client-auth tests. Completes work started in another session: main.cpp wiring, refresh expiry tracking, no requests for a superseded session, and clang-tidy and Windows header-order fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
4.0 KiB
C++
101 lines
4.0 KiB
C++
#pragma once
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
// M9.8c launcher model (toolkit- and network-independent). Validates what the user
|
|
// typed, loads the two credential files within bounds, and tracks the connect flow.
|
|
// M10.5c (ADR-0093): grant records are M10 session grants (network::session_grant_bytes),
|
|
// issued by `evo-session-probe grants`; the default endpoint is the dev route (ADR-0087).
|
|
// Error texts are fixed: they never contain file contents, grant bytes or keys, and
|
|
// nothing here is persisted or logged.
|
|
namespace evo::client {
|
|
inline constexpr std::size_t grant_record_bytes = 160; // network::session_grant_bytes.
|
|
inline constexpr std::size_t max_grant_records = 64; // As issued by the probe.
|
|
inline constexpr std::size_t max_authority_bytes = 65536; // One small PEM CA.
|
|
inline constexpr std::size_t max_field_bytes = 1024; // Every text field.
|
|
using GrantRecord = std::array<std::uint8_t, grant_record_bytes>;
|
|
|
|
enum class LaunchError : std::uint8_t {
|
|
endpoint,
|
|
server_name,
|
|
authority_path,
|
|
grants_path,
|
|
authority_unreadable,
|
|
authority_invalid,
|
|
grants_unreadable,
|
|
grants_invalid,
|
|
grant_refused,
|
|
server_unreachable,
|
|
grants_exhausted,
|
|
no_session
|
|
};
|
|
[[nodiscard]] std::string_view launch_error_text(LaunchError error) noexcept;
|
|
|
|
// Defaults: the dev route (ADR-0087) and the name on its certificate.
|
|
struct ConnectForm {
|
|
std::string endpoint{"void.aeternalisgames.com:7400"}, server_name{"void.aeternalisgames.com"};
|
|
std::string authority_path, grants_path;
|
|
};
|
|
struct Endpoint {
|
|
std::string host;
|
|
std::uint16_t port{};
|
|
};
|
|
struct ConnectMaterial {
|
|
Endpoint endpoint;
|
|
std::string server_name, authority_pem;
|
|
std::string authority_path; // The same CA as a file (the QUIC stack loads it too).
|
|
std::vector<GrantRecord> grants;
|
|
};
|
|
// "host:port", "[ipv6]:port" or "a.b.c.d:port"; plain DNS host names only.
|
|
[[nodiscard]] std::expected<Endpoint, LaunchError> parse_endpoint(std::string_view text);
|
|
[[nodiscard]] std::expected<ConnectMaterial, LaunchError> load_connect(const ConnectForm& form);
|
|
// Broker grants stay in memory; the existing pinned region CA is still required.
|
|
[[nodiscard]] std::expected<ConnectMaterial, LaunchError>
|
|
load_connect(const ConnectForm& form, std::span<const GrantRecord> grants);
|
|
|
|
// What the session reports while connecting, reduced to what the launcher decides on.
|
|
enum class ConnectSignal : std::uint8_t {
|
|
welcome, // A session was opened.
|
|
lost, // Transport/TLS failure or deadline before a Close.
|
|
refused, // Closed as unauthenticated/expired/duplicate: this grant cannot work.
|
|
not_ready, // Closed as shutdown/capacity: the session retries later with the next grant.
|
|
exhausted // No unused grant remains.
|
|
};
|
|
enum class LaunchPhase : std::uint8_t { choosing, fixture, connecting, connected, failed };
|
|
class Launcher {
|
|
public:
|
|
static constexpr int max_attempts_without_welcome = 3;
|
|
void start_fixture() noexcept;
|
|
// From choosing or failed (retry). The caller then creates a fresh session.
|
|
[[nodiscard]] bool begin_connect() noexcept;
|
|
// Cancel returns to choosing from connecting, connected or failed; the caller
|
|
// drops its session. Fixture mode also returns to choosing.
|
|
void cancel() noexcept;
|
|
// Lost connections after a welcome are reconnects, not failures; before any
|
|
// welcome, repeated loss means the endpoint, name or CA is wrong.
|
|
void observe(ConnectSignal signal) noexcept;
|
|
void fail(LaunchError error) noexcept;
|
|
[[nodiscard]] LaunchPhase phase() const noexcept {
|
|
return phase_;
|
|
}
|
|
[[nodiscard]] LaunchError error() const noexcept {
|
|
return error_;
|
|
}
|
|
[[nodiscard]] bool ever_connected() const noexcept {
|
|
return welcomed_;
|
|
}
|
|
|
|
private:
|
|
LaunchPhase phase_{LaunchPhase::choosing};
|
|
LaunchError error_{LaunchError::no_session};
|
|
int losses_{};
|
|
bool welcomed_{};
|
|
};
|
|
} // namespace evo::client
|