Files
aevolution/include/evo/client/region_session.hpp
T
dingoandClaude Opus 5.5 27d2645aaa
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (network) (push) Successful in 9m46s
Foundation / checks (client) (push) Successful in 13m6s
Foundation / checks (tsan) (push) Successful in 8m2s
Foundation / checks (checks) (push) Successful in 32m25s
Foundation / checks (postgres) (push) Successful in 38m45s
Foundation / postgres-tools (push) Successful in 16s
Foundation / image (push) Successful in 2m34s
Foundation / server-image (push) Successful in 4m2s
Probe: resolve host names and report the QUIC close cause
evo-session-probe resolves a host name to IPv4 and prints the address DNS answered,
and its closed line names why the QUIC connection ended (untrusted: the server
answered but failed the pinned check; idle: nothing answered), via the new
RegionSessionClient::transport_cause. Records the UDP route reachability check
(not yet the authenticated acceptance run).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:31:19 -04:00

73 lines
4.0 KiB
C++

#pragma once
#include "evo/network/quic_transport.hpp"
#include "evo/network/session_protocol.hpp"
#include <chrono>
#include <cstdint>
#include <expected>
#include <memory>
#include <optional>
#include <vector>
// M10.3b client-side session login over QUIC (ADR-0091, schemas/network/session-v1.md).
// Owned by one thread, which calls poll(). Sends Hello with the grant once the pinned
// connection is up (then forgets the grant), waits for Welcome or Close, and can renew
// the session in place with a newer grant. A Close from the server, a malformed message,
// the Welcome deadline or a lost transport ends the session; reconnecting needs a new
// client and a fresh grant (ADR-0089). M10.4 (ADR-0092): intentions as datagrams with
// receipts and a simulated watermark; actions with stable ids, receipts and final outcomes.
// The client never treats a receipt or the watermark as a final outcome. Views are 10.5.
namespace evo::client {
struct RegionSessionClientConfig {
network::quic::ClientConfig transport;
network::WireGrant grant{};
std::chrono::milliseconds welcome_deadline{5000}; // Connect to Welcome.
};
enum class RegionSessionState : std::uint8_t { connecting, awaiting_welcome, established, closed };
class RegionSessionClient {
public:
[[nodiscard]] static std::expected<std::unique_ptr<RegionSessionClient>,
network::quic::EndpointError>
connect(RegionSessionClientConfig config, std::chrono::steady_clock::time_point now);
RegionSessionClient(const RegionSessionClient&) = delete;
RegionSessionClient& operator=(const RegionSessionClient&) = delete;
~RegionSessionClient();
void poll(std::chrono::steady_clock::time_point now);
// Sends a newer grant for the open session; false unless established and sent.
[[nodiscard]] bool refresh(const network::WireGrant& grant);
// The latest refresh answer, once (an accepted one also updates welcome().expires_at).
[[nodiscard]] std::optional<network::SessionRefreshResult> take_refresh_result();
// Sends Close{client_closed} and closes the connection.
void close();
// Realtime intention for `tick` (server_tick + 1 ..= + 8); returns its sequence, or
// nothing unless established and sent (also while the QUIC datagram extension is not yet
// negotiated, just after Welcome: retry). Datagrams may be lost: no receipt is not a
// refusal.
[[nodiscard]] std::optional<std::uint64_t>
send_intention(std::uint64_t tick, std::int16_t move_x, std::int16_t move_y);
// A discrete action with a caller-chosen id, unique for the account (stable across
// retries and reconnects). False unless established and sent.
[[nodiscard]] bool send_action(std::uint64_t action_id, network::ActionKind kind,
std::uint64_t tick);
[[nodiscard]] bool query_action(std::uint64_t action_id);
[[nodiscard]] std::vector<network::IntentionReceipt> take_intention_receipts();
[[nodiscard]] std::vector<network::ActionReceipt> take_action_receipts();
[[nodiscard]] std::vector<network::ActionOutcome> take_action_outcomes();
// Newest simulated watermark of this session's epoch.
[[nodiscard]] std::optional<network::SimulatedThrough> simulated() const noexcept;
// Latest server tick seen (Welcome, receipts, watermarks); 0 before Welcome.
[[nodiscard]] std::uint64_t server_tick() const noexcept;
[[nodiscard]] RegionSessionState state() const noexcept;
[[nodiscard]] const std::optional<network::SessionWelcome>& welcome() const noexcept;
[[nodiscard]] std::optional<network::SessionCloseReason> close_reason() const noexcept;
// Why the QUIC connection itself ended (e.g. `untrusted`: the server answered but its
// certificate failed the pinned check), when it ended without a session Close.
[[nodiscard]] std::optional<network::quic::CloseCause> transport_cause() const noexcept;
private:
struct Impl;
explicit RegionSessionClient(std::unique_ptr<Impl> impl);
std::unique_ptr<Impl> impl_;
};
} // namespace evo::client