Add M10.3b session login over QUIC
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 3m13s
Foundation / checks (client) (push) Successful in 12m12s
Foundation / checks (network) (push) Successful in 8m56s
Foundation / checks (tsan) (push) Successful in 7m42s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 19m14s
Foundation / checks (checks) (push) Canceled after 31m28s

Session protocol v1 session messages (Hello with grant, Welcome, Refresh,
RefreshResult, Close with reasons) on the QUIC reliable stream. RegionSessions
verifies grants with the issuer public keys and admits them through SessionControl:
a newer grant closes the account's old connection as superseded, expiry and epoch
advances close sessions, every close is announced and flushed. RegionSessionClient
logs in, refreshes in place and reports why a session ended. ADR-0091.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-03 21:12:00 -04:00
co-authored by Claude Opus 5.5
parent 01b4b06a09
commit 7956143cd8
17 changed files with 1262 additions and 7 deletions
+127
View File
@@ -0,0 +1,127 @@
#include "evo/client/region_session.hpp"
#include <utility>
namespace evo::client {
namespace {
using network::SessionCloseReason;
using Clock = std::chrono::steady_clock;
} // namespace
struct RegionSessionClient::Impl {
std::unique_ptr<network::quic::Endpoint> endpoint;
network::WireGrant grant{};
Clock::time_point deadline;
RegionSessionState state{RegionSessionState::connecting};
network::quic::ConnectionId connection{};
std::optional<network::SessionWelcome> welcome;
std::optional<SessionCloseReason> reason;
std::optional<network::SessionRefreshResult> refresh_result;
bool send(const network::SessionMessage& m) {
return connection != 0 &&
endpoint->send_message(connection, network::encode_session(m)).has_value();
}
// Ends the session locally; `tell` sends a Close first (best effort).
void end(SessionCloseReason why, bool tell) {
if (state == RegionSessionState::closed)
return;
if (tell)
(void)send(network::SessionClose{why});
state = RegionSessionState::closed;
reason = why;
grant.fill(0);
if (connection != 0)
endpoint->close(connection);
}
void message(std::span<const std::uint8_t> bytes) {
const auto decoded = network::decode_session(bytes);
if (!decoded)
return end(SessionCloseReason::protocol, true);
if (const auto* m = std::get_if<network::SessionClose>(&*decoded))
return end(m->reason, false);
if (state == RegionSessionState::awaiting_welcome) {
if (const auto* m = std::get_if<network::SessionWelcome>(&*decoded)) {
welcome = *m;
state = RegionSessionState::established;
return;
}
} else if (state == RegionSessionState::established) {
if (const auto* m = std::get_if<network::SessionRefreshResult>(&*decoded)) {
if (m->status == 0)
welcome->expires_at = m->expires_at;
refresh_result = *m;
return;
}
}
end(SessionCloseReason::protocol, true);
}
};
RegionSessionClient::RegionSessionClient(std::unique_ptr<Impl> impl) : impl_{std::move(impl)} {}
RegionSessionClient::~RegionSessionClient() = default;
std::expected<std::unique_ptr<RegionSessionClient>, network::quic::EndpointError>
RegionSessionClient::connect(RegionSessionClientConfig config, Clock::time_point now) {
auto endpoint = network::quic::Endpoint::connect(config.transport);
if (!endpoint)
return std::unexpected(endpoint.error());
auto impl = std::make_unique<Impl>();
impl->endpoint = std::move(*endpoint);
impl->grant = config.grant;
config.grant.fill(0);
impl->deadline = now + config.welcome_deadline;
return std::unique_ptr<RegionSessionClient>{new RegionSessionClient{std::move(impl)}};
}
void RegionSessionClient::poll(Clock::time_point now) {
auto& m = *impl_;
for (auto& e : m.endpoint->poll()) {
using network::quic::EventKind;
if (m.state == RegionSessionState::closed)
continue;
if (e.kind == EventKind::connected && m.state == RegionSessionState::connecting) {
m.connection = e.connection;
m.state = RegionSessionState::awaiting_welcome;
network::SessionHello hello;
hello.grant = m.grant;
m.grant.fill(0); // The grant is a credential: keep it no longer than needed.
if (!m.send(hello))
m.end(SessionCloseReason::connection_lost, false);
} else if (e.kind == EventKind::message) {
m.message(e.bytes);
} else if (e.kind == EventKind::closed) {
m.connection = 0; // Already gone; nothing to close or send.
m.end(SessionCloseReason::connection_lost, false);
}
}
if ((m.state == RegionSessionState::connecting ||
m.state == RegionSessionState::awaiting_welcome) &&
now >= m.deadline)
m.end(SessionCloseReason::timeout, false);
}
bool RegionSessionClient::refresh(const network::WireGrant& grant) {
return impl_->state == RegionSessionState::established &&
impl_->send(network::SessionRefresh{grant});
}
std::optional<network::SessionRefreshResult> RegionSessionClient::take_refresh_result() {
return std::exchange(impl_->refresh_result, std::nullopt);
}
void RegionSessionClient::close() {
impl_->end(SessionCloseReason::client_closed, true);
}
RegionSessionState RegionSessionClient::state() const noexcept {
return impl_->state;
}
const std::optional<network::SessionWelcome>& RegionSessionClient::welcome() const noexcept {
return impl_->welcome;
}
std::optional<SessionCloseReason> RegionSessionClient::close_reason() const noexcept {
return impl_->reason;
}
} // namespace evo::client