Add primitive life calls to the session client
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 2m43s
Foundation / checks (network) (push) Canceled after 39s
Foundation / checks (client) (push) Canceled after 2m49s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 2m43s
Foundation / checks (network) (push) Canceled after 39s
Foundation / checks (client) (push) Canceled after 2m49s
This commit is contained in:
@@ -11,6 +11,7 @@ using Clock = std::chrono::steady_clock;
|
||||
struct RegionSessionClient::Impl {
|
||||
std::unique_ptr<network::quic::Endpoint> endpoint;
|
||||
network::WireGrant grant{};
|
||||
std::uint16_t protocol_version{network::session_protocol_version};
|
||||
Clock::time_point deadline;
|
||||
RegionSessionState state{RegionSessionState::connecting};
|
||||
network::quic::ConnectionId connection{};
|
||||
@@ -23,6 +24,8 @@ struct RegionSessionClient::Impl {
|
||||
std::vector<network::IntentionReceipt> intention_receipts;
|
||||
std::vector<network::ActionReceipt> action_receipts;
|
||||
std::vector<network::ActionOutcome> action_outcomes;
|
||||
std::vector<network::PrimitiveLifeReceipt> primitive_life_receipts;
|
||||
std::vector<network::PrimitiveLifeOutcome> primitive_life_outcomes;
|
||||
std::optional<network::SnapshotAssembler> snapshots;
|
||||
std::uint64_t snapshot_chunks{}, snapshot_bytes{};
|
||||
std::optional<network::HandoffOffer> handoff; // v4: continue at another region.
|
||||
@@ -76,7 +79,8 @@ struct RegionSessionClient::Impl {
|
||||
|
||||
bool send(const network::SessionMessage& m) {
|
||||
return connection != 0 &&
|
||||
endpoint->send_message(connection, network::encode_session(m)).has_value();
|
||||
endpoint->send_message(connection, network::encode_session(m, protocol_version))
|
||||
.has_value();
|
||||
}
|
||||
// Ends the session locally; `tell` sends a Close first (best effort).
|
||||
void end(SessionCloseReason why, bool tell) {
|
||||
@@ -91,9 +95,12 @@ struct RegionSessionClient::Impl {
|
||||
endpoint->close(connection);
|
||||
}
|
||||
void message(std::span<const std::uint8_t> bytes) {
|
||||
const auto decoded = network::decode_session(bytes);
|
||||
std::uint16_t wire_version{};
|
||||
const auto decoded = network::decode_session(bytes, &wire_version);
|
||||
if (!decoded)
|
||||
return end(SessionCloseReason::protocol, true);
|
||||
if (wire_version != protocol_version)
|
||||
return end(SessionCloseReason::unsupported_version, true);
|
||||
if (const auto* m = std::get_if<network::SessionClose>(&*decoded))
|
||||
return end(m->reason, false);
|
||||
if (state == RegionSessionState::awaiting_welcome) {
|
||||
@@ -121,6 +128,12 @@ struct RegionSessionClient::Impl {
|
||||
}
|
||||
if (const auto* m = std::get_if<network::ActionOutcome>(&*decoded))
|
||||
return keep(action_outcomes, *m);
|
||||
if (const auto* m = std::get_if<network::PrimitiveLifeReceipt>(&*decoded)) {
|
||||
seen_tick(m->server_tick);
|
||||
return keep(primitive_life_receipts, *m);
|
||||
}
|
||||
if (const auto* m = std::get_if<network::PrimitiveLifeOutcome>(&*decoded))
|
||||
return keep(primitive_life_outcomes, *m);
|
||||
if (const auto* m = std::get_if<network::HandoffOffer>(&*decoded)) {
|
||||
handoff = *m; // A Close (handed_off) follows.
|
||||
return;
|
||||
@@ -135,11 +148,15 @@ RegionSessionClient::~RegionSessionClient() = default;
|
||||
|
||||
std::expected<std::unique_ptr<RegionSessionClient>, network::quic::EndpointError>
|
||||
RegionSessionClient::connect(RegionSessionClientConfig config, Clock::time_point now) {
|
||||
if (config.protocol_version != network::session_protocol_version &&
|
||||
config.protocol_version != network::session_protocol_v5)
|
||||
return std::unexpected(network::quic::EndpointError::configuration);
|
||||
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->protocol_version = config.protocol_version;
|
||||
impl->grant = config.grant;
|
||||
config.grant.fill(0);
|
||||
impl->deadline = now + config.welcome_deadline;
|
||||
@@ -192,7 +209,8 @@ void RegionSessionClient::close() {
|
||||
std::optional<std::uint64_t>
|
||||
RegionSessionClient::send_intention(std::uint64_t tick, std::int16_t move_x, std::int16_t move_y) {
|
||||
auto& m = *impl_;
|
||||
if (m.state != RegionSessionState::established || m.connection == 0 || !m.welcome)
|
||||
if (m.protocol_version != network::session_protocol_version ||
|
||||
m.state != RegionSessionState::established || m.connection == 0 || !m.welcome)
|
||||
return std::nullopt;
|
||||
const network::SessionIntention intention{
|
||||
m.welcome->session, m.welcome->epoch, m.next_sequence, tick, move_x, move_y};
|
||||
@@ -204,14 +222,38 @@ RegionSessionClient::send_intention(std::uint64_t tick, std::int16_t move_x, std
|
||||
bool RegionSessionClient::send_action(std::uint64_t action_id, network::ActionKind kind,
|
||||
std::uint64_t tick) {
|
||||
auto& m = *impl_;
|
||||
return m.state == RegionSessionState::established && m.welcome &&
|
||||
return m.protocol_version == network::session_protocol_version &&
|
||||
m.state == RegionSessionState::established && m.welcome &&
|
||||
m.send(network::SessionAction{m.welcome->session, m.welcome->epoch, action_id,
|
||||
static_cast<std::uint16_t>(kind), tick});
|
||||
}
|
||||
|
||||
bool RegionSessionClient::query_action(std::uint64_t action_id) {
|
||||
auto& m = *impl_;
|
||||
return m.state == RegionSessionState::established && m.send(network::ActionQuery{action_id});
|
||||
return m.protocol_version == network::session_protocol_version &&
|
||||
m.state == RegionSessionState::established && m.send(network::ActionQuery{action_id});
|
||||
}
|
||||
|
||||
bool RegionSessionClient::request_primitive_life(std::uint64_t request_id) {
|
||||
auto& m = *impl_;
|
||||
return m.protocol_version == network::session_protocol_v5 &&
|
||||
m.state == RegionSessionState::established && m.welcome && request_id != 0 &&
|
||||
m.send(network::PrimitiveLifeRequest{m.welcome->session, m.welcome->epoch, request_id});
|
||||
}
|
||||
|
||||
bool RegionSessionClient::query_primitive_life(std::uint64_t request_id) {
|
||||
auto& m = *impl_;
|
||||
return m.protocol_version == network::session_protocol_v5 &&
|
||||
m.state == RegionSessionState::established && request_id != 0 &&
|
||||
m.send(network::PrimitiveLifeQuery{request_id});
|
||||
}
|
||||
|
||||
std::vector<network::PrimitiveLifeReceipt> RegionSessionClient::take_primitive_life_receipts() {
|
||||
return std::exchange(impl_->primitive_life_receipts, {});
|
||||
}
|
||||
|
||||
std::vector<network::PrimitiveLifeOutcome> RegionSessionClient::take_primitive_life_outcomes() {
|
||||
return std::exchange(impl_->primitive_life_outcomes, {});
|
||||
}
|
||||
|
||||
std::vector<network::IntentionReceipt> RegionSessionClient::take_intention_receipts() {
|
||||
@@ -236,7 +278,8 @@ std::uint64_t RegionSessionClient::server_tick() const noexcept {
|
||||
|
||||
bool RegionSessionClient::set_interest(const network::SessionInterest& interest) {
|
||||
auto& m = *impl_;
|
||||
return m.state == RegionSessionState::established && m.send(interest);
|
||||
return m.protocol_version == network::session_protocol_version &&
|
||||
m.state == RegionSessionState::established && m.send(interest);
|
||||
}
|
||||
|
||||
const network::ReplicatedView* RegionSessionClient::view() const noexcept {
|
||||
|
||||
@@ -391,7 +391,8 @@ struct RegionSessions::Impl {
|
||||
std::uint16_t wire_version{};
|
||||
const auto decoded = network::decode_session(bytes, &wire_version);
|
||||
if (c.state != State::established || !decoded ||
|
||||
wire_version != network::session_protocol_version)
|
||||
wire_version != network::session_protocol_version ||
|
||||
c.protocol_version != network::session_protocol_version)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded))
|
||||
return replication.acknowledge(c.session, *ack);
|
||||
@@ -556,14 +557,21 @@ struct RegionSessions::Impl {
|
||||
if (const auto* m = std::get_if<network::SessionRefresh>(&*decoded))
|
||||
return refresh(c, *m, now_seconds, now);
|
||||
if (const auto* m = std::get_if<network::SessionAction>(&*decoded)) {
|
||||
if (c.protocol_version == network::session_protocol_v5)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
// A durable uniqueness check waits for this poll's single `verify` (M10.9d).
|
||||
if (const auto receipt = intents.admit(c.session, *m, admission()))
|
||||
answer(c, *receipt);
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::ActionQuery>(&*decoded))
|
||||
if (const auto* m = std::get_if<network::ActionQuery>(&*decoded)) {
|
||||
if (c.protocol_version == network::session_protocol_v5)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
return send(c, intents.query(c.session, *m, admission()));
|
||||
}
|
||||
if (const auto* m = std::get_if<network::SessionInterest>(&*decoded)) {
|
||||
if (c.protocol_version == network::session_protocol_v5)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
(void)replication.set_interest(c.session, *m).has_value(); // Clamped by the server.
|
||||
return;
|
||||
}
|
||||
@@ -719,7 +727,9 @@ void RegionSessions::poll(const HostFacts& facts, std::uint64_t now_seconds,
|
||||
if (auto* c = m.by_session(session); c && c->state == Impl::State::established)
|
||||
m.answer(*c, receipt);
|
||||
for (const auto& [session, watermark] : m.intents.simulated(m.admission()))
|
||||
if (auto* c = m.by_session(session); c && c->state == Impl::State::established)
|
||||
if (auto* c = m.by_session(session);
|
||||
c && c->state == Impl::State::established &&
|
||||
c->protocol_version == network::session_protocol_version)
|
||||
m.send_datagram(*c, watermark);
|
||||
for (const auto session : m.control.expire(now_seconds))
|
||||
if (auto* c = m.by_session(session))
|
||||
|
||||
Reference in New Issue
Block a user