Add M10.4a intentions, actions and admission
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m45s
Foundation / checks (network) (push) Successful in 9m37s
Foundation / checks (client) (push) Successful in 12m14s
Foundation / checks (tsan) (push) Successful in 7m39s
Foundation / checks (checks) (push) Successful in 31m15s
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 32m59s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m45s
Foundation / checks (network) (push) Successful in 9m37s
Foundation / checks (client) (push) Successful in 12m14s
Foundation / checks (tsan) (push) Successful in 7m39s
Foundation / checks (checks) (push) Successful in 31m15s
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 32m59s
Session protocol v1 (not yet deployed, amended in place) gains realtime intentions on datagrams with receipts and a cumulative simulated watermark, and account-scoped actions with stable ids, receipts, final outcomes and queries. IntentAdmission enforces session binding, rate, authority, epoch, vector, sequence, tick window, duplicates and the unresolved bound; RegionSessions and the client carry it over QUIC. Intentions and actions have no biological effect yet. ADR-0092. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "evo/client/region_session.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace evo::client {
|
||||
@@ -16,6 +17,42 @@ struct RegionSessionClient::Impl {
|
||||
std::optional<network::SessionWelcome> welcome;
|
||||
std::optional<SessionCloseReason> reason;
|
||||
std::optional<network::SessionRefreshResult> refresh_result;
|
||||
std::uint64_t next_sequence{1}, server_tick{};
|
||||
std::optional<network::SimulatedThrough> simulated;
|
||||
std::vector<network::IntentionReceipt> intention_receipts;
|
||||
std::vector<network::ActionReceipt> action_receipts;
|
||||
std::vector<network::ActionOutcome> action_outcomes;
|
||||
static constexpr std::size_t max_kept = 1024; // Per kind, until taken; oldest dropped.
|
||||
|
||||
template <typename T> static void keep(std::vector<T>& list, const T& item) {
|
||||
if (list.size() >= max_kept)
|
||||
list.erase(list.begin());
|
||||
list.push_back(item);
|
||||
}
|
||||
void seen_tick(std::uint64_t tick) {
|
||||
server_tick = std::max(server_tick, tick);
|
||||
}
|
||||
// Datagrams: receipts and watermarks only, after Welcome.
|
||||
void datagram(std::span<const std::uint8_t> bytes) {
|
||||
if (state != RegionSessionState::established)
|
||||
return;
|
||||
const auto decoded = network::decode_session(bytes);
|
||||
if (!decoded)
|
||||
return end(SessionCloseReason::protocol, true);
|
||||
if (const auto* m = std::get_if<network::IntentionReceipt>(&*decoded)) {
|
||||
seen_tick(m->server_tick);
|
||||
return keep(intention_receipts, *m);
|
||||
}
|
||||
if (const auto* m = std::get_if<network::SimulatedThrough>(&*decoded)) {
|
||||
if (!welcome || m->epoch != welcome->epoch)
|
||||
return; // Another epoch's watermark says nothing about this session.
|
||||
seen_tick(m->tick);
|
||||
if (!simulated || m->sequence >= simulated->sequence)
|
||||
simulated = *m;
|
||||
return;
|
||||
}
|
||||
end(SessionCloseReason::protocol, true);
|
||||
}
|
||||
|
||||
bool send(const network::SessionMessage& m) {
|
||||
return connection != 0 &&
|
||||
@@ -42,6 +79,7 @@ struct RegionSessionClient::Impl {
|
||||
if (state == RegionSessionState::awaiting_welcome) {
|
||||
if (const auto* m = std::get_if<network::SessionWelcome>(&*decoded)) {
|
||||
welcome = *m;
|
||||
seen_tick(m->server_tick);
|
||||
state = RegionSessionState::established;
|
||||
return;
|
||||
}
|
||||
@@ -52,6 +90,12 @@ struct RegionSessionClient::Impl {
|
||||
refresh_result = *m;
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::ActionReceipt>(&*decoded)) {
|
||||
seen_tick(m->server_tick);
|
||||
return keep(action_receipts, *m);
|
||||
}
|
||||
if (const auto* m = std::get_if<network::ActionOutcome>(&*decoded))
|
||||
return keep(action_outcomes, *m);
|
||||
}
|
||||
end(SessionCloseReason::protocol, true);
|
||||
}
|
||||
@@ -89,6 +133,8 @@ void RegionSessionClient::poll(Clock::time_point now) {
|
||||
m.end(SessionCloseReason::connection_lost, false);
|
||||
} else if (e.kind == EventKind::message) {
|
||||
m.message(e.bytes);
|
||||
} else if (e.kind == EventKind::datagram) {
|
||||
m.datagram(e.bytes);
|
||||
} else if (e.kind == EventKind::closed) {
|
||||
m.connection = 0; // Already gone; nothing to close or send.
|
||||
m.end(SessionCloseReason::connection_lost, false);
|
||||
@@ -113,6 +159,51 @@ void RegionSessionClient::close() {
|
||||
impl_->end(SessionCloseReason::client_closed, true);
|
||||
}
|
||||
|
||||
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)
|
||||
return std::nullopt;
|
||||
const network::SessionIntention intention{
|
||||
m.welcome->session, m.welcome->epoch, m.next_sequence, tick, move_x, move_y};
|
||||
if (!m.endpoint->send_datagram(m.connection, network::encode_session(intention)))
|
||||
return std::nullopt;
|
||||
return m.next_sequence++;
|
||||
}
|
||||
|
||||
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 &&
|
||||
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});
|
||||
}
|
||||
|
||||
std::vector<network::IntentionReceipt> RegionSessionClient::take_intention_receipts() {
|
||||
return std::exchange(impl_->intention_receipts, {});
|
||||
}
|
||||
|
||||
std::vector<network::ActionReceipt> RegionSessionClient::take_action_receipts() {
|
||||
return std::exchange(impl_->action_receipts, {});
|
||||
}
|
||||
|
||||
std::vector<network::ActionOutcome> RegionSessionClient::take_action_outcomes() {
|
||||
return std::exchange(impl_->action_outcomes, {});
|
||||
}
|
||||
|
||||
std::optional<network::SimulatedThrough> RegionSessionClient::simulated() const noexcept {
|
||||
return impl_->simulated;
|
||||
}
|
||||
|
||||
std::uint64_t RegionSessionClient::server_tick() const noexcept {
|
||||
return impl_->server_tick;
|
||||
}
|
||||
|
||||
RegionSessionState RegionSessionClient::state() const noexcept {
|
||||
return impl_->state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user