Enable authenticated primitive life sessions
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m59s
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 6m2s
Foundation / checks (network) (push) Canceled after 3m53s
Foundation / checks (client) (push) Canceled after 6m8s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m59s
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 6m2s
Foundation / checks (network) (push) Canceled after 3m53s
Foundation / checks (client) (push) Canceled after 6m8s
This commit is contained in:
+172
-5
@@ -48,9 +48,11 @@
|
||||
// --crash-at <point>:<n> (tests only, M7.7) SIGKILLs this process at the n-th
|
||||
// occurrence of before-upload, before-transaction, after-commit or after-ack (right
|
||||
// after a step's acknowledgements are written and flushed).
|
||||
// --profile primitive (M11.2d-5) starts the creation-only profile-3 host. It requires
|
||||
// an owner-provisioned checkpoint, becomes ready only after recovery, and does not
|
||||
// accept M9/M10 sessions, synthetic tick input or genesis provisioning.
|
||||
// --profile primitive (M11.2d) starts the creation-only profile-3 host. It requires
|
||||
// an owner-provisioned checkpoint and becomes ready only after recovery. Optional
|
||||
// --primitive-* flags enable the v5 new-life listener; biology ticks and genesis
|
||||
// provisioning remain disabled.
|
||||
#include "evo/biology/founder.hpp"
|
||||
#include "evo/processes/development_opening.hpp"
|
||||
#include "evo/server/lifecycle/primitive_lives.hpp"
|
||||
#include "evo/server/ops_http.hpp"
|
||||
@@ -58,15 +60,22 @@
|
||||
#include "evo/server/region_host.hpp"
|
||||
#include "m10_bridge.hpp"
|
||||
#include "session_bridge.hpp"
|
||||
#ifdef EVO_SERVER_M10
|
||||
#include "evo/server/pg_slot.hpp"
|
||||
#include "evo/server/postgres_control_ledger.hpp"
|
||||
#include "evo/server/region_sessions.hpp"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cerrno>
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
@@ -99,6 +108,17 @@ struct Options {
|
||||
std::uint64_t objects_reserve_mib{1024};
|
||||
server_app::SessionOptions session;
|
||||
server_app::M10Options m10;
|
||||
struct PrimitiveSessionOptions {
|
||||
std::string listen, certificate, key, issuer, environment;
|
||||
[[nodiscard]] bool any() const noexcept {
|
||||
return !listen.empty() || !certificate.empty() || !key.empty() || !issuer.empty() ||
|
||||
!environment.empty();
|
||||
}
|
||||
[[nodiscard]] bool complete() const noexcept {
|
||||
return !listen.empty() && !certificate.empty() && !key.empty() && !issuer.empty() &&
|
||||
!environment.empty();
|
||||
}
|
||||
} primitive_session;
|
||||
};
|
||||
|
||||
// Kills this process without any cleanup: the real SIGKILL, at a chosen boundary.
|
||||
@@ -246,6 +266,17 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
o.m10.neighbours.emplace_back(value);
|
||||
else if (flag == "--m10-load-governor" && (value == "on" || value == "off"))
|
||||
o.m10.load_governor = value == "on";
|
||||
else if (flag == "--primitive-listen")
|
||||
o.primitive_session.listen = value;
|
||||
else if (flag == "--primitive-cert")
|
||||
o.primitive_session.certificate = value;
|
||||
else if (flag == "--primitive-key")
|
||||
o.primitive_session.key = value;
|
||||
else if (flag == "--primitive-issuer")
|
||||
o.primitive_session.issuer = value;
|
||||
else if (flag == "--primitive-environment" &&
|
||||
(value == "dev" || value == "stage" || value == "world0"))
|
||||
o.primitive_session.environment = value;
|
||||
else if (flag == "--crash-at") {
|
||||
const auto colon = value.find(':');
|
||||
const auto ordinal =
|
||||
@@ -276,8 +307,11 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
// M10 sessions (ADR-0091/0092) need every setting and the QUIC build.
|
||||
if (o.m10.any() && (!server_app::m10_available || !o.m10.complete()))
|
||||
return std::nullopt;
|
||||
// Primitive profile serves only the creation-only host in this slice. It
|
||||
// cannot accept M9/M10 sessions or synthetic biological ticks.
|
||||
// Primitive profile serves only the creation-only host. Its optional listener
|
||||
// uses a separate v5 contract and never enables the M9/M10 action path.
|
||||
if (o.primitive_session.any() &&
|
||||
(!server_app::m10_available || !o.primitive_session.complete() || o.profile != "primitive"))
|
||||
return std::nullopt;
|
||||
if (o.profile == "primitive" &&
|
||||
(o.synthetic || !o.crash_point.empty() || o.session.any() || o.m10.any() ||
|
||||
o.host.flush_interval != 1000ms || o.drain != 10000ms))
|
||||
@@ -605,6 +639,118 @@ template <typename State> int serve(Options& o) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef EVO_SERVER_M10
|
||||
namespace {
|
||||
using PrimitiveWireOutcome = network::PrimitiveLifeOutcome;
|
||||
|
||||
PrimitiveWireOutcome primitive_wire_outcome(std::uint64_t request,
|
||||
const server::PrimitiveHostReply& reply) {
|
||||
using network::PrimitiveLifeResult;
|
||||
PrimitiveLifeResult result = PrimitiveLifeResult::unknown;
|
||||
std::uint64_t identity = 0, sequence = 0;
|
||||
if (reply.kind == server::PrimitiveHostReplyKind::born && reply.published) {
|
||||
result = PrimitiveLifeResult::born;
|
||||
identity = reply.published->identity;
|
||||
sequence = reply.published->commit_sequence;
|
||||
} else if (reply.kind == server::PrimitiveHostReplyKind::pending) {
|
||||
result = PrimitiveLifeResult::pending;
|
||||
} else if (reply.kind == server::PrimitiveHostReplyKind::refused) {
|
||||
switch (reply.reservation.refusal) {
|
||||
case persistence::LifeRefusal::insufficient_funding:
|
||||
result = PrimitiveLifeResult::insufficient_funding;
|
||||
break;
|
||||
case persistence::LifeRefusal::no_placement:
|
||||
result = PrimitiveLifeResult::no_placement;
|
||||
break;
|
||||
case persistence::LifeRefusal::cancelled:
|
||||
result = PrimitiveLifeResult::cancelled;
|
||||
break;
|
||||
case persistence::LifeRefusal::existing_life:
|
||||
result = PrimitiveLifeResult::existing_life;
|
||||
break;
|
||||
case persistence::LifeRefusal::none:
|
||||
result = PrimitiveLifeResult::unknown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// A reservation owned by another region is never asserted as a birth here. The current
|
||||
// session can query again after it reaches the owner; region routing stays explicit.
|
||||
return {request, result, identity, sequence};
|
||||
}
|
||||
|
||||
struct PrimitiveSessionBridge {
|
||||
std::unique_ptr<server::PgSlot> slot;
|
||||
std::unique_ptr<server::PostgresControlLedger> ledger;
|
||||
std::unique_ptr<server::RegionSessions> sessions;
|
||||
};
|
||||
|
||||
std::optional<PrimitiveSessionBridge>
|
||||
open_primitive_sessions(const Options::PrimitiveSessionOptions& options,
|
||||
server::PrimitiveRegionHost& host, persistence::RegionKey key,
|
||||
std::uint64_t frame, const persistence::PgOptions& pg) {
|
||||
PrimitiveSessionBridge bridge;
|
||||
if (!options.any())
|
||||
return bridge;
|
||||
const auto colon = options.listen.rfind(':');
|
||||
std::uint16_t port{};
|
||||
if (colon == std::string::npos ||
|
||||
std::from_chars(options.listen.data() + colon + 1,
|
||||
options.listen.data() + options.listen.size(), port)
|
||||
.ec != std::errc{}) {
|
||||
std::puts("error primitive-listen");
|
||||
return std::nullopt;
|
||||
}
|
||||
std::ifstream issuer_file(options.issuer, std::ios::binary);
|
||||
std::vector<char> issuer((std::istreambuf_iterator<char>(issuer_file)), {});
|
||||
if (issuer.size() != network::grant_public_key_bytes) {
|
||||
std::puts("error primitive-issuer");
|
||||
return std::nullopt;
|
||||
}
|
||||
network::RegionSessionsConfig config;
|
||||
config.transport.listen_address = options.listen.substr(0, colon);
|
||||
config.transport.port = port;
|
||||
config.transport.certificate_pem_file = options.certificate;
|
||||
config.transport.key_pem_file = options.key;
|
||||
config.control.environment = options.environment == "dev" ? network::DeploymentEnvironment::dev
|
||||
: options.environment == "stage"
|
||||
? network::DeploymentEnvironment::stage
|
||||
: network::DeploymentEnvironment::world0;
|
||||
config.control.world = {key.world, frame};
|
||||
config.control.region = key.region;
|
||||
config.control.epoch = 1;
|
||||
config.control.max_sessions = 512;
|
||||
config.transport.limits.max_connections = 576;
|
||||
network::GrantPublicKey issuer_key{};
|
||||
std::copy(issuer.begin(), issuer.end(), issuer_key.begin());
|
||||
config.issuer_keys.push_back({1, issuer_key});
|
||||
bridge.slot = std::make_unique<server::PgSlot>(pg, std::chrono::seconds{2});
|
||||
bridge.ledger = std::make_unique<server::PostgresControlLedger>(
|
||||
*bridge.slot, key, [&host] { return host.authority(); });
|
||||
config.ledger = bridge.ledger.get();
|
||||
config.create_primitive_life = [&host](const network::AccountId& account,
|
||||
std::uint64_t generation, std::uint64_t request) {
|
||||
const auto result =
|
||||
host.new_life(account.bytes, generation, request, biology::founder_life_rules);
|
||||
return primitive_wire_outcome(request, result);
|
||||
};
|
||||
config.query_primitive_life = [&host](const network::AccountId& account,
|
||||
std::uint64_t generation, std::uint64_t request) {
|
||||
return primitive_wire_outcome(request, host.query_life(account.bytes, generation, request));
|
||||
};
|
||||
auto sessions = server::RegionSessions::create(std::move(config));
|
||||
if (!sessions) {
|
||||
std::puts(sessions.error() == server::RegionSessionsError::transport
|
||||
? "error primitive-listen"
|
||||
: "error primitive-session");
|
||||
return std::nullopt;
|
||||
}
|
||||
bridge.sessions = std::move(*sessions);
|
||||
std::printf("primitive listening %u\n", static_cast<unsigned>(bridge.sessions->port()));
|
||||
return bridge;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
int serve_primitive(Options& o) {
|
||||
auto objects = persistence::FilesystemObjectStore::open(
|
||||
o.objects, o.host.key, server::max_primitive_lives_bytes, nullptr,
|
||||
@@ -624,6 +770,12 @@ int serve_primitive(Options& o) {
|
||||
return 2;
|
||||
}
|
||||
auto& host = **made;
|
||||
#ifdef EVO_SERVER_M10
|
||||
auto primitive_sessions =
|
||||
open_primitive_sessions(o.primitive_session, host, o.host.key, o.host.frame, o.pg);
|
||||
if (!primitive_sessions)
|
||||
return 2;
|
||||
#endif
|
||||
std::unique_ptr<server::OpsServer> ops;
|
||||
if (!o.ops_listen.empty()) {
|
||||
auto listening = server::OpsServer::listen(o.ops_listen);
|
||||
@@ -667,10 +819,23 @@ int serve_primitive(Options& o) {
|
||||
};
|
||||
for (;;) {
|
||||
if (stop_requested) {
|
||||
#ifdef EVO_SERVER_M10
|
||||
if (primitive_sessions->sessions)
|
||||
primitive_sessions->sessions->shutdown(std::chrono::steady_clock::now());
|
||||
#endif
|
||||
host.drain();
|
||||
return finish(0);
|
||||
}
|
||||
const auto& status = host.step();
|
||||
#ifdef EVO_SERVER_M10
|
||||
if (primitive_sessions->sessions)
|
||||
primitive_sessions->sessions->poll(
|
||||
{status.ready, status.epoch, status.simulated_tick},
|
||||
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count()),
|
||||
std::chrono::steady_clock::now());
|
||||
#endif
|
||||
set_ready(status.ready);
|
||||
if (!phase || *phase != status.phase) {
|
||||
phase = status.phase;
|
||||
@@ -716,6 +881,8 @@ int main(int argc, char** argv) {
|
||||
"--objects DIR --build HEX64 [--retained HEX64]... [--pg-hostaddr A "
|
||||
"--pg-passfile F --pg-ca F] [--flush-ms N] [--drain-ms N] "
|
||||
"[--lease-profile default|fast] [--ready-file PATH] "
|
||||
"[--primitive-listen ADDRESS:PORT --primitive-cert F --primitive-key F "
|
||||
"--primitive-issuer F --primitive-environment dev|stage|world0] "
|
||||
"[--ops-listen ADDRESS:PORT] [--synthetic-inputs development-v1 "
|
||||
"[--synthetic-until TICK] [--accelerate N] [--session-listen ADDRESS:PORT "
|
||||
"--session-cert F --session-key F --session-grant-key F "
|
||||
|
||||
+4
-3
@@ -47,9 +47,10 @@ the maintainer chose directional rounding):
|
||||
control. A reservation spends nothing and is not a spawned organism.
|
||||
Atomic body/checkpoint publication and life binding are in the adapter. The
|
||||
separate profile-3 region host now recovers and durably publishes a new life,
|
||||
without advancing biology. v5 session integration, runtime profile selection,
|
||||
and process-kill qualification remain; the v17 PostgreSQL and host integration
|
||||
tests are waiting on CI confirmation.
|
||||
without advancing biology. v5 authenticated session execution and primitive
|
||||
profile selection are implemented; cross-region owner routing/reconnect,
|
||||
process-kill qualification and this session-process CI run remain. The v17
|
||||
PostgreSQL and host integration tests have prior CI confirmation.
|
||||
|
||||
Open from M10 (BACKLOG):
|
||||
- the maintainer's native-client observation, moved to the later 2k drill;
|
||||
|
||||
@@ -120,9 +120,21 @@ Local checks do not close ADR-0097's reference-worker qualification.
|
||||
provisions or advances biology. The process test checks ready-after-recovery,
|
||||
missing-genesis refusal, no tick advance and clean lease release. Linux CI
|
||||
compilation and PostgreSQL process evidence remain pending.
|
||||
- Next 11.2d subsection: authenticated v5 session admission and routing through
|
||||
the primitive host, followed by process-kill qualification and readiness
|
||||
integration. Until that gate passes, the new profile selection is recovery
|
||||
and operations only; it is not a playable server.
|
||||
- 11.2d-6 implementation: primitive profile can opt into QUIC v5; that listener
|
||||
requires durable account control and accepts v5 only, while other region
|
||||
listeners remain v4-only. Life requests are tied to the admitted session,
|
||||
current epoch and authenticated account-control generation, then call the
|
||||
primitive host; query calls its read-only path. The QUIC contract test covers
|
||||
v5 Hello, Welcome, durable-generation binding, receipt and outcome. Runtime
|
||||
process/PostgreSQL qualification remains pending CI.
|
||||
- Cross-region owner routing and reconnect-to-existing-life are not complete.
|
||||
The accepted v5 outcome has no owner-region/address field, while the delivery
|
||||
row requires routing. The host can identify a different reservation owner but
|
||||
the wire contract cannot direct a client there. Resolve this contract before
|
||||
implementing routing; do not claim 11.2 complete until owner routing,
|
||||
process-kill qualification and restart retry pass.
|
||||
Proposed resolution for ADR review: define a v6 response that names the owning
|
||||
region, plus an authoritative region-address resolution contract; alternatively,
|
||||
specify a server-side router. Do not treat a client-provided endpoint as trusted.
|
||||
|
||||
No deployed world has been provisioned or changed by this work.
|
||||
|
||||
@@ -5777,3 +5777,25 @@ tests cannot run in this Windows environment: WSL launch was denied with
|
||||
`E_ACCESSDENIED`, and the configured Linux compiler is not available directly in
|
||||
PowerShell. CI compilation and runtime qualification are pending. No deployed
|
||||
world was provisioned or changed.
|
||||
|
||||
## 2026-10-10 — M11.2d-6 authenticated v5 session execution (CI pending)
|
||||
|
||||
`RegionSessions` now negotiates a per-connection protocol version, keeps existing
|
||||
regions v4-only, and enables primitive-profile v5 only with durable account control
|
||||
and both life handlers. V5 welcomes and stream replies use v5; mismatched versions
|
||||
close. Life requests require the authenticated session id, current control epoch,
|
||||
ready host and nonzero durable generation; the callback receives the verified grant's
|
||||
account identity, never a client-supplied account. Query is read-only. Primitive
|
||||
`evo-server` can opt into the dedicated QUIC listener with an issuer key and
|
||||
database-backed control ledger. A QUIC contract test exercises v5 Hello/Welcome and
|
||||
life receipt/outcome with a fake durable ledger.
|
||||
|
||||
Ran clang-format 19.1.5 on changed C++ files and `git diff --check`; both passed.
|
||||
MSVC 19.44 Release/NDEBUG compilation of `region_sessions.cpp` and
|
||||
`quic_sessions.cpp`, manual relinking of the focused executable, and
|
||||
`ctest --preset quic` all passed (5/5). The normal Ninja build stalled as recorded
|
||||
above. PostgreSQL is unavailable locally, and the server process target is Linux-only;
|
||||
full `evo-server` compilation and real PostgreSQL process results await CI.
|
||||
Cross-region routing remains incomplete because the accepted v5 outcome does not
|
||||
carry an owner region/address; see the delivery plan. No deployed world was provisioned
|
||||
or changed.
|
||||
|
||||
@@ -57,6 +57,9 @@ class PrimitiveRegionHost {
|
||||
[[nodiscard]] PrimitiveHostReply new_life(const persistence::Uuid& account,
|
||||
std::uint64_t generation, std::uint64_t request,
|
||||
std::uint32_t rules);
|
||||
// Read-only retry/query. It never creates a reservation or life.
|
||||
[[nodiscard]] PrimitiveHostReply query_life(const persistence::Uuid& account,
|
||||
std::uint64_t generation, std::uint64_t request);
|
||||
[[nodiscard]] std::optional<persistence::LeaseGrant> authority() const;
|
||||
[[nodiscard]] const HostStatus& status() const noexcept {
|
||||
return status_;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
@@ -91,6 +92,14 @@ struct RegionSessionsConfig {
|
||||
// M10.8d recovery: this often, open outgoing transfers prepared more than ticket_lifetime
|
||||
// + 10 s ago (by the store's clock, e.g. by a process that died) are aborted.
|
||||
std::chrono::milliseconds overdue_poll{5000};
|
||||
// v5 is accepted only when both primitive-life handlers are supplied. Callbacks
|
||||
// receive the authenticated account and durable control generation for this session.
|
||||
std::function<network::PrimitiveLifeOutcome(const network::AccountId&, std::uint64_t,
|
||||
std::uint64_t)>
|
||||
create_primitive_life;
|
||||
std::function<network::PrimitiveLifeOutcome(const network::AccountId&, std::uint64_t,
|
||||
std::uint64_t)>
|
||||
query_primitive_life;
|
||||
};
|
||||
// The region host's authority, read once per poll.
|
||||
struct HostFacts {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# M11 primitive-life session protocol, version 5
|
||||
|
||||
Version 5 adds the reliable new-life request family to the v4 session protocol. All
|
||||
messages 1–17 retain their v4 layout. Version 4 remains the default for existing clients;
|
||||
per-connection server negotiation is not part of this codec-only gate. A v4 peer rejects
|
||||
types 18–21. Integers are
|
||||
messages 1–17 retain their v4 layout. Version 4 remains the default for existing regions;
|
||||
primitive-profile servers require v5, while other region servers continue to refuse it.
|
||||
The server binds life requests to the authenticated account-control generation and requires
|
||||
durable account control before accepting v5. A v4 peer rejects types 18–21. Integers are
|
||||
little-endian, the 8-byte `EVSN` header has zero flags, and each message has the exact size
|
||||
below. This schema describes the wire codec only; server admission and durable execution
|
||||
are separate implementation gates.
|
||||
@@ -15,6 +16,12 @@ are separate implementation gates.
|
||||
| 20 PrimitiveLifeOutcome | server → client, reliable stream | request_id u64, result u8, life_identity u64, commit_sequence u64 | 25 |
|
||||
| 21 PrimitiveLifeQuery | client → server, reliable stream | request_id u64 | 8 |
|
||||
|
||||
The server sends `Welcome` in the same protocol version as `Hello`. Every later stream
|
||||
message must use that negotiated version. Primitive-life messages are reliable-stream only;
|
||||
datagrams retain the v4 rules. A request is admitted only when session id and epoch match,
|
||||
the region is ready and durable control is held; the receipt precedes the durable outcome.
|
||||
Queries are read-only and use the same authenticated account and control generation.
|
||||
|
||||
Result values: 1 born (identity and commit sequence must both be nonzero), 2 insufficient
|
||||
funding, 3 no placement, 4 existing life, 5 cancelled, 6 pending (query only), 7 unknown
|
||||
(query only). Non-born results carry zero identity and commit sequence. A region-control
|
||||
|
||||
@@ -256,6 +256,14 @@ PrimitiveHostReply PrimitiveRegionHost::query(const persistence::Uuid& account,
|
||||
return reply(PrimitiveHostReplyKind::pending, value.reservation);
|
||||
}
|
||||
|
||||
PrimitiveHostReply PrimitiveRegionHost::query_life(const persistence::Uuid& account,
|
||||
std::uint64_t generation,
|
||||
std::uint64_t request) {
|
||||
if (!status_.ready || !authority_.may_begin_commit(LeaseClock::now()))
|
||||
return reply(PrimitiveHostReplyKind::unavailable, {});
|
||||
return query(account, generation, request);
|
||||
}
|
||||
|
||||
PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& account,
|
||||
std::uint64_t generation, std::uint64_t request,
|
||||
std::uint32_t rules) {
|
||||
|
||||
@@ -72,6 +72,7 @@ struct RegionSessions::Impl {
|
||||
network::quic::ConnectionId id{};
|
||||
State state{State::hello};
|
||||
std::uint64_t session{};
|
||||
std::uint16_t protocol_version{network::session_protocol_version};
|
||||
std::string account;
|
||||
Clock::time_point deadline; // Hello, pending (Welcome due) or close flush.
|
||||
bool close_requested{};
|
||||
@@ -128,7 +129,8 @@ struct RegionSessions::Impl {
|
||||
}
|
||||
void send(const Connection& c, const network::SessionMessage& m) {
|
||||
// A refused send (budget) leaves the peer to observe the transport close instead.
|
||||
(void)endpoint->send_message(c.id, network::encode_session(m)).has_value();
|
||||
(void)endpoint->send_message(c.id, network::encode_session(m, c.protocol_version))
|
||||
.has_value();
|
||||
}
|
||||
// Realtime answers: a refused datagram is dropped; cumulative watermarks cover it.
|
||||
void send_datagram(const Connection& c, const network::SessionMessage& m) {
|
||||
@@ -537,10 +539,15 @@ struct RegionSessions::Impl {
|
||||
? SessionCloseReason::unsupported_version
|
||||
: SessionCloseReason::protocol,
|
||||
now);
|
||||
// v5 has a codec and schema, but per-connection negotiation and life handling
|
||||
// land in the following server gate. Do not silently accept v5 and answer v4.
|
||||
if (wire_version != network::session_protocol_version)
|
||||
if (c.state == State::hello) {
|
||||
c.protocol_version = wire_version;
|
||||
const bool primitive_v5 = static_cast<bool>(config.create_primitive_life);
|
||||
if ((primitive_v5 && wire_version != network::session_protocol_v5) ||
|
||||
(wire_version == network::session_protocol_v5 && !primitive_v5))
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
} else if (wire_version != c.protocol_version) {
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
}
|
||||
if (c.state == State::hello) {
|
||||
if (const auto* m = std::get_if<network::SessionHello>(&*decoded))
|
||||
return hello(c, *m, now_seconds, now);
|
||||
@@ -566,6 +573,23 @@ struct RegionSessions::Impl {
|
||||
c.deadline = now; // Nothing left to flush to a peer that is leaving.
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::PrimitiveLifeRequest>(&*decoded)) {
|
||||
const auto status = m->session != c.session ? network::AdmitStatus::unknown_session
|
||||
: m->epoch != control.epoch() ? network::AdmitStatus::stale_epoch
|
||||
: !facts.ready || c.generation == 0
|
||||
? network::AdmitStatus::not_ready
|
||||
: network::AdmitStatus::admitted;
|
||||
send(c, network::PrimitiveLifeReceipt{m->request_id, status, facts.simulated_tick});
|
||||
if (status == network::AdmitStatus::admitted)
|
||||
send(c, config.create_primitive_life(c.account_id, c.generation, m->request_id));
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::PrimitiveLifeQuery>(&*decoded)) {
|
||||
if (c.generation == 0)
|
||||
return send(c, network::PrimitiveLifeOutcome{
|
||||
m->request_id, network::PrimitiveLifeResult::unknown, 0, 0});
|
||||
return send(c, config.query_primitive_life(c.account_id, c.generation, m->request_id));
|
||||
}
|
||||
close(c, SessionCloseReason::protocol, now);
|
||||
}
|
||||
};
|
||||
@@ -579,6 +603,8 @@ RegionSessions::create(RegionSessionsConfig config) {
|
||||
if (config.issuer_keys.empty() || (config.handoff != nullptr && config.ledger == nullptr) ||
|
||||
(config.handoff_key != nullptr && config.probes == nullptr) ||
|
||||
config.ticket_lifetime == 0 || config.ticket_lifetime > network::max_ticket_lifetime ||
|
||||
((config.create_primitive_life || config.query_primitive_life) &&
|
||||
(!config.create_primitive_life || !config.query_primitive_life || !config.ledger)) ||
|
||||
config.transport.limits.max_connections < config.control.max_sessions ||
|
||||
config.hello_deadline.count() <= 0 || config.close_flush.count() <= 0 ||
|
||||
config.renew_interval.count() <= 0 || config.safety_margin.count() <= 0 ||
|
||||
|
||||
@@ -388,6 +388,60 @@ struct FakeLedger final : ControlLedger {
|
||||
std::vector<std::uint64_t> renewed, released;
|
||||
};
|
||||
|
||||
void primitive_v5_session(const Files& f) {
|
||||
FakeLedger ledger;
|
||||
Harness h{f, 4, 64, &ledger, [](server::RegionSessionsConfig& c) {
|
||||
c.create_primitive_life = [](const AccountId& a, std::uint64_t generation,
|
||||
std::uint64_t request) {
|
||||
CHECK(a == account(0xA5) && generation == 1);
|
||||
return PrimitiveLifeOutcome{request, PrimitiveLifeResult::born, 77, 88};
|
||||
};
|
||||
c.query_primitive_life = [](const AccountId&, std::uint64_t,
|
||||
std::uint64_t request) {
|
||||
return PrimitiveLifeOutcome{request, PrimitiveLifeResult::unknown, 0, 0};
|
||||
};
|
||||
}};
|
||||
auto peer = h.raw();
|
||||
quic::ConnectionId id = 0;
|
||||
std::uint64_t session = 0, epoch = 0;
|
||||
bool sent_request = false;
|
||||
std::optional<PrimitiveLifeReceipt> receipt;
|
||||
std::optional<PrimitiveLifeOutcome> outcome;
|
||||
const auto end = Clock::now() + std::chrono::seconds{10};
|
||||
while (Clock::now() < end && !outcome) {
|
||||
h.pump();
|
||||
for (auto& e : peer->poll()) {
|
||||
if (e.kind == quic::EventKind::connected) {
|
||||
id = e.connection;
|
||||
CHECK(peer->send_message(
|
||||
id, encode_session(SessionHello{0, h.issuer.grant(account(0xA5), 1)},
|
||||
session_protocol_v5)));
|
||||
} else if (e.kind == quic::EventKind::message) {
|
||||
const auto decoded = decode_session(e.bytes);
|
||||
CHECK(decoded.has_value());
|
||||
if (const auto* welcome = std::get_if<SessionWelcome>(&*decoded)) {
|
||||
session = welcome->session;
|
||||
epoch = welcome->epoch;
|
||||
if (!sent_request) {
|
||||
sent_request = true;
|
||||
CHECK(peer->send_message(
|
||||
id, encode_session(PrimitiveLifeRequest{session, epoch, 42},
|
||||
session_protocol_v5)));
|
||||
}
|
||||
} else if (const auto* got = std::get_if<PrimitiveLifeReceipt>(&*decoded)) {
|
||||
receipt = *got;
|
||||
} else if (const auto* life = std::get_if<PrimitiveLifeOutcome>(&*decoded)) {
|
||||
outcome = *life;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{1});
|
||||
}
|
||||
CHECK(receipt == PrimitiveLifeReceipt{42, AdmitStatus::admitted, 100});
|
||||
CHECK(outcome == PrimitiveLifeOutcome{42, PrimitiveLifeResult::born, 77, 88});
|
||||
CHECK(!ledger.claims.empty() && ledger.claims.back().account == account(0xA5));
|
||||
}
|
||||
|
||||
// M10.4: intentions, actions and their distinct answers against a simulated host.
|
||||
void intentions_and_actions(const Files& f) {
|
||||
Harness h{f};
|
||||
@@ -1209,6 +1263,7 @@ void storm(const Files& f) {
|
||||
int main() try {
|
||||
const auto files = credentials();
|
||||
login_rules(files);
|
||||
primitive_v5_session(files);
|
||||
limits(files);
|
||||
durable_control(files);
|
||||
intentions_and_actions(files);
|
||||
|
||||
Reference in New Issue
Block a user