Add v5 primitive-life session wire protocol
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (client) (push) Successful in 12m41s
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 (postgres) (push) Canceled after 2m43s
Foundation / checks (network) (push) Canceled after 13m22s
Foundation / checks (checks) (push) Canceled after 15m28s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (client) (push) Successful in 12m41s
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 (postgres) (push) Canceled after 2m43s
Foundation / checks (network) (push) Canceled after 13m22s
Foundation / checks (checks) (push) Canceled after 15m28s
This commit is contained in:
@@ -85,8 +85,13 @@ Local checks do not close ADR-0097's reference-worker qualification.
|
||||
- 11.2c-2d: C++ object-store publication, verified predecessor replay, exact-byte
|
||||
retry and profile-3 recovery adapter with SQL life-binding reconciliation. Full
|
||||
PostgreSQL/process/recovery and upgrade qualification passes.
|
||||
- Remaining 11.2d: primitive-capable region host and explicit new-life session
|
||||
protocol, crash-boundary qualification and readiness integration. The generic
|
||||
two-profile host still cannot serve profile 3.
|
||||
- 11.2d-1: versioned v5 new-life request/receipt/outcome/query wire codec, keeping
|
||||
v4 the default and rejecting v5 at the current server until negotiation and life
|
||||
handling are implemented. Network and QUIC suites pass; targeted manual compile
|
||||
and link were needed because the normal Ninja build invocation idles. Host
|
||||
admission and durable execution are a separate slice.
|
||||
- Remaining 11.2d: primitive-capable region host, server admission/execution,
|
||||
crash-boundary qualification and readiness integration. The generic two-profile
|
||||
host still cannot serve profile 3.
|
||||
|
||||
No deployed world has been provisioned or changed by this work.
|
||||
|
||||
@@ -5636,3 +5636,24 @@ No production world was provisioned or changed. The new adapter can persist and
|
||||
recover profile 3, but `RegionHost` and session routing remain limited to the
|
||||
existing environmental/lineage profiles; no primitive session can yet reach this
|
||||
adapter.
|
||||
|
||||
## 2026-10-10 — M11.2d-1 session protocol v5 (in progress)
|
||||
|
||||
Added the v5 wire schema and codec changes for a separate reliable primitive-life
|
||||
request, receipt, outcome and query family. v4 remains the default, and current
|
||||
RegionSessions explicitly rejects v5 until per-connection negotiation and life
|
||||
handling land. MSVC compilation of the changed network test units, protocol object,
|
||||
client/server session bridge objects succeeded; affected libraries and test binaries
|
||||
were relinked from CMake-generated commands. `ctest --preset network` passed (2/2),
|
||||
and `ctest --preset quic` passed (5/5), including the new assertion that an
|
||||
unnegotiated v5 Hello is refused.
|
||||
|
||||
The ordinary `tools/windows-check.ps1 -Preset network -Action check` invocation
|
||||
still configures successfully, then leaves Ninja idle without output or child
|
||||
compiler processes. WSL startup is denied by this host. Thus these are targeted
|
||||
MSVC compile/link and CTest results, not a successful full preset build.
|
||||
|
||||
The operator's live-region smoke test did pass using the prebuilt v4
|
||||
`evo-session-probe`, `C:\Dev\tokens\m10-grants.bin` grant 0 and the supplied dev CA:
|
||||
`void.aeternalisgames.com:7400` returned Welcome, exit 0. This confirms existing v4
|
||||
connectivity only; it does not execute or validate v5 or primitive-life handling.
|
||||
|
||||
@@ -21,8 +21,9 @@ inline constexpr std::uint32_t session_magic = 0x4E535645; // Bytes "EVSN".
|
||||
// v3 (M10.6, ADR-0094): v2 plus probe marker records inside snapshot chunks.
|
||||
// v4 (M10.8c, ADR-0096): v3 plus HandoffOffer and SessionRedirect (stream), close reasons
|
||||
// handed_off and moved, and ghost marker records. v1-v3 were deployed to evolution-dev and
|
||||
// are frozen; only v4 is accepted.
|
||||
// are frozen; v4 remains the default. v5 adds reliable primitive-life operations.
|
||||
inline constexpr std::uint16_t session_protocol_version = 4;
|
||||
inline constexpr std::uint16_t session_protocol_v5 = 5;
|
||||
inline constexpr std::size_t session_address_bytes = 64; // Endpoint or server name field.
|
||||
inline constexpr std::size_t session_datagram_bytes = 1200; // Whole message, ADR-0089.
|
||||
inline constexpr std::size_t session_header_bytes = 8;
|
||||
@@ -45,7 +46,11 @@ enum class SessionMessageType : std::uint8_t {
|
||||
snapshot_chunk, // Server -> client, datagram: part of one snapshot (v2).
|
||||
snapshot_ack, // Client -> server, datagram: newest complete snapshot (v2).
|
||||
handoff_offer, // Server -> client, stream: continue at another region (v4).
|
||||
redirect // Server -> client, stream: the account's probe is elsewhere (v4).
|
||||
redirect, // Server -> client, stream: the account's probe is elsewhere (v4).
|
||||
primitive_life_request = 18,
|
||||
primitive_life_receipt,
|
||||
primitive_life_outcome,
|
||||
primitive_life_query
|
||||
};
|
||||
// Admission answers for intentions and actions (wire 0..10).
|
||||
enum class AdmitStatus : std::uint8_t {
|
||||
@@ -166,6 +171,33 @@ struct ActionQuery {
|
||||
std::uint64_t action_id{};
|
||||
friend bool operator==(const ActionQuery&, const ActionQuery&) = default;
|
||||
};
|
||||
enum class PrimitiveLifeResult : std::uint8_t {
|
||||
born = 1,
|
||||
insufficient_funding,
|
||||
no_placement,
|
||||
pending,
|
||||
unknown
|
||||
};
|
||||
struct PrimitiveLifeRequest {
|
||||
std::uint64_t session{}, epoch{}, request_id{};
|
||||
friend bool operator==(const PrimitiveLifeRequest&, const PrimitiveLifeRequest&) = default;
|
||||
};
|
||||
struct PrimitiveLifeReceipt {
|
||||
std::uint64_t request_id{};
|
||||
AdmitStatus status{};
|
||||
std::uint64_t server_tick{};
|
||||
friend bool operator==(const PrimitiveLifeReceipt&, const PrimitiveLifeReceipt&) = default;
|
||||
};
|
||||
struct PrimitiveLifeOutcome {
|
||||
std::uint64_t request_id{};
|
||||
PrimitiveLifeResult result{};
|
||||
std::uint64_t life_identity{}, commit_sequence{};
|
||||
friend bool operator==(const PrimitiveLifeOutcome&, const PrimitiveLifeOutcome&) = default;
|
||||
};
|
||||
struct PrimitiveLifeQuery {
|
||||
std::uint64_t request_id{};
|
||||
friend bool operator==(const PrimitiveLifeQuery&, const PrimitiveLifeQuery&) = default;
|
||||
};
|
||||
// The client's spatial focus: one Z slice, a centre and a radius in cells. The server
|
||||
// clamps the radius to its maximum and filters authoritatively (ADR-0093).
|
||||
struct SessionInterest {
|
||||
@@ -216,10 +248,15 @@ using SessionMessage =
|
||||
std::variant<SessionHello, SessionWelcome, SessionRefresh, SessionRefreshResult, SessionClose,
|
||||
SessionIntention, IntentionReceipt, SimulatedThrough, SessionAction, ActionReceipt,
|
||||
ActionOutcome, ActionQuery, SessionInterest, SnapshotChunk, SnapshotAck,
|
||||
HandoffOffer, SessionRedirect>;
|
||||
HandoffOffer, SessionRedirect, PrimitiveLifeRequest, PrimitiveLifeReceipt,
|
||||
PrimitiveLifeOutcome, PrimitiveLifeQuery>;
|
||||
|
||||
[[nodiscard]] std::vector<std::uint8_t> encode_session(const SessionMessage& message);
|
||||
[[nodiscard]] std::vector<std::uint8_t> encode_session(const SessionMessage& message,
|
||||
std::uint16_t version);
|
||||
// Exactly one message; any other length for its type rejects.
|
||||
[[nodiscard]] std::expected<SessionMessage, SessionCodecError>
|
||||
decode_session(std::span<const std::uint8_t> bytes);
|
||||
[[nodiscard]] std::expected<SessionMessage, SessionCodecError>
|
||||
decode_session(std::span<const std::uint8_t> bytes, std::uint16_t* version);
|
||||
} // namespace evo::network
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# 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
|
||||
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.
|
||||
|
||||
| Type | Direction | Payload | Bytes |
|
||||
|---|---|---|---:|
|
||||
| 18 PrimitiveLifeRequest | client → server, reliable stream | session u64, epoch u64, request_id u64 | 24 |
|
||||
| 19 PrimitiveLifeReceipt | server → client, reliable stream | request_id u64, admission status u8 (0–10), server_tick u64 | 17 |
|
||||
| 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 |
|
||||
|
||||
Result values: 1 born (identity and commit sequence must both be nonzero), 2 insufficient
|
||||
funding, 3 no placement, 4 pending (query only), 5 unknown (query only). Non-born results
|
||||
carry zero identity and commit sequence. Request IDs are a separate namespace from M10
|
||||
action IDs. Receipt reports admission only; it does not claim that a life was durably born.
|
||||
@@ -24,6 +24,10 @@ constexpr std::uint8_t max_snapshot_chunks = 16;
|
||||
constexpr std::size_t address_bytes = 8 + (2 * session_address_bytes);
|
||||
constexpr std::size_t handoff_offer_bytes = 16 + address_bytes + session_grant_wire_bytes;
|
||||
constexpr std::size_t redirect_bytes = address_bytes;
|
||||
constexpr std::size_t life_request_bytes = 24;
|
||||
constexpr std::size_t life_receipt_bytes = 17;
|
||||
constexpr std::size_t life_outcome_bytes = 25;
|
||||
constexpr std::size_t life_query_bytes = 8;
|
||||
|
||||
void put(std::vector<std::uint8_t>& out, std::uint64_t v, std::size_t count) {
|
||||
for (std::size_t i = 0; i < count; ++i)
|
||||
@@ -35,11 +39,12 @@ std::uint64_t get(std::span<const std::uint8_t> in, std::size_t at, std::size_t
|
||||
v |= static_cast<std::uint64_t>(in[at + i]) << (8 * i);
|
||||
return v;
|
||||
}
|
||||
std::vector<std::uint8_t> header(SessionMessageType type, std::size_t payload) {
|
||||
std::vector<std::uint8_t> header(SessionMessageType type, std::size_t payload,
|
||||
std::uint16_t version = session_protocol_version) {
|
||||
std::vector<std::uint8_t> out;
|
||||
out.reserve(session_header_bytes + payload);
|
||||
put(out, session_magic, 4);
|
||||
put(out, session_protocol_version, 2);
|
||||
put(out, version, 2);
|
||||
out.push_back(static_cast<std::uint8_t>(type));
|
||||
out.push_back(0);
|
||||
return out;
|
||||
@@ -93,38 +98,55 @@ WireGrant grant_at(std::span<const std::uint8_t> in, std::size_t at) {
|
||||
} // namespace
|
||||
|
||||
std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
const auto is_life = std::holds_alternative<PrimitiveLifeRequest>(message) ||
|
||||
std::holds_alternative<PrimitiveLifeReceipt>(message) ||
|
||||
std::holds_alternative<PrimitiveLifeOutcome>(message) ||
|
||||
std::holds_alternative<PrimitiveLifeQuery>(message);
|
||||
return encode_session(message, is_life ? session_protocol_v5 : session_protocol_version);
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uint16_t version) {
|
||||
if (version != session_protocol_version && version != session_protocol_v5)
|
||||
return {};
|
||||
if (version == session_protocol_version &&
|
||||
(std::holds_alternative<PrimitiveLifeRequest>(message) ||
|
||||
std::holds_alternative<PrimitiveLifeReceipt>(message) ||
|
||||
std::holds_alternative<PrimitiveLifeOutcome>(message) ||
|
||||
std::holds_alternative<PrimitiveLifeQuery>(message)))
|
||||
return {};
|
||||
struct Encoder {
|
||||
std::uint16_t version;
|
||||
std::vector<std::uint8_t> operator()(const SessionHello& m) const {
|
||||
auto out = header(SessionMessageType::hello, hello_bytes);
|
||||
auto out = header(SessionMessageType::hello, hello_bytes, version);
|
||||
put(out, m.required_features, 4);
|
||||
out.insert(out.end(), m.grant.begin(), m.grant.end());
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionWelcome& m) const {
|
||||
auto out = header(SessionMessageType::welcome, welcome_bytes);
|
||||
auto out = header(SessionMessageType::welcome, welcome_bytes, version);
|
||||
for (const auto v : {m.session, m.epoch, m.world, m.frame, m.region, m.expires_at,
|
||||
m.server_seconds, m.server_tick})
|
||||
put(out, v, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionRefresh& m) const {
|
||||
auto out = header(SessionMessageType::refresh, refresh_bytes);
|
||||
auto out = header(SessionMessageType::refresh, refresh_bytes, version);
|
||||
out.insert(out.end(), m.grant.begin(), m.grant.end());
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionRefreshResult& m) const {
|
||||
auto out = header(SessionMessageType::refresh_result, refresh_result_bytes);
|
||||
auto out = header(SessionMessageType::refresh_result, refresh_result_bytes, version);
|
||||
out.push_back(m.status);
|
||||
put(out, m.expires_at, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionClose& m) const {
|
||||
auto out = header(SessionMessageType::close, close_bytes);
|
||||
auto out = header(SessionMessageType::close, close_bytes, version);
|
||||
out.push_back(static_cast<std::uint8_t>(m.reason));
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionIntention& m) const {
|
||||
auto out = header(SessionMessageType::intention, intention_bytes);
|
||||
auto out = header(SessionMessageType::intention, intention_bytes, version);
|
||||
for (const auto v : {m.session, m.epoch, m.sequence, m.tick})
|
||||
put(out, v, 8);
|
||||
put(out, static_cast<std::uint16_t>(m.move_x), 2);
|
||||
@@ -132,20 +154,21 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const IntentionReceipt& m) const {
|
||||
auto out = header(SessionMessageType::intention_receipt, intention_receipt_bytes);
|
||||
auto out =
|
||||
header(SessionMessageType::intention_receipt, intention_receipt_bytes, version);
|
||||
put(out, m.sequence, 8);
|
||||
out.push_back(static_cast<std::uint8_t>(m.status));
|
||||
put(out, m.server_tick, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SimulatedThrough& m) const {
|
||||
auto out = header(SessionMessageType::simulated_through, simulated_bytes);
|
||||
auto out = header(SessionMessageType::simulated_through, simulated_bytes, version);
|
||||
for (const auto v : {m.epoch, m.sequence, m.tick})
|
||||
put(out, v, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionAction& m) const {
|
||||
auto out = header(SessionMessageType::action, action_bytes);
|
||||
auto out = header(SessionMessageType::action, action_bytes, version);
|
||||
for (const auto v : {m.session, m.epoch, m.action_id})
|
||||
put(out, v, 8);
|
||||
put(out, m.kind, 2);
|
||||
@@ -153,7 +176,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const ActionReceipt& m) const {
|
||||
auto out = header(SessionMessageType::action_receipt, action_receipt_bytes);
|
||||
auto out = header(SessionMessageType::action_receipt, action_receipt_bytes, version);
|
||||
put(out, m.action_id, 8);
|
||||
out.push_back(static_cast<std::uint8_t>(m.status));
|
||||
put(out, m.server_tick, 8);
|
||||
@@ -161,7 +184,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const ActionOutcome& m) const {
|
||||
auto out = header(SessionMessageType::action_outcome, action_outcome_bytes);
|
||||
auto out = header(SessionMessageType::action_outcome, action_outcome_bytes, version);
|
||||
put(out, m.action_id, 8);
|
||||
out.push_back(static_cast<std::uint8_t>(m.result));
|
||||
put(out, m.tick, 8);
|
||||
@@ -169,12 +192,12 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const ActionQuery& m) const {
|
||||
auto out = header(SessionMessageType::action_query, action_query_bytes);
|
||||
auto out = header(SessionMessageType::action_query, action_query_bytes, version);
|
||||
put(out, m.action_id, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionInterest& m) const {
|
||||
auto out = header(SessionMessageType::interest, interest_bytes);
|
||||
auto out = header(SessionMessageType::interest, interest_bytes, version);
|
||||
for (const auto v : {m.x, m.y, m.z})
|
||||
put(out, static_cast<std::uint64_t>(v), 8);
|
||||
put(out, m.radius, 2);
|
||||
@@ -182,7 +205,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SnapshotChunk& m) const {
|
||||
auto out = header(SessionMessageType::snapshot_chunk,
|
||||
snapshot_chunk_header_bytes + m.records.size());
|
||||
snapshot_chunk_header_bytes + m.records.size(), version);
|
||||
for (const auto v :
|
||||
{m.epoch, m.tick, m.baseline, m.field_revision, m.organism_revision})
|
||||
put(out, v, 8);
|
||||
@@ -194,14 +217,14 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SnapshotAck& m) const {
|
||||
auto out = header(SessionMessageType::snapshot_ack, snapshot_ack_bytes);
|
||||
auto out = header(SessionMessageType::snapshot_ack, snapshot_ack_bytes, version);
|
||||
put(out, m.epoch, 8);
|
||||
put(out, m.tick, 8);
|
||||
return out;
|
||||
}
|
||||
// Invalid text fields are encoded as given; the receiver refuses them.
|
||||
std::vector<std::uint8_t> operator()(const HandoffOffer& m) const {
|
||||
auto out = header(SessionMessageType::handoff_offer, handoff_offer_bytes);
|
||||
auto out = header(SessionMessageType::handoff_offer, handoff_offer_bytes, version);
|
||||
out.insert(out.end(), m.transfer.begin(), m.transfer.end());
|
||||
put_address(out, m.destination);
|
||||
out.insert(out.end(), m.ticket.begin(), m.ticket.end());
|
||||
@@ -209,23 +232,61 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const SessionRedirect& m) const {
|
||||
auto out = header(SessionMessageType::redirect, redirect_bytes);
|
||||
auto out = header(SessionMessageType::redirect, redirect_bytes, version);
|
||||
put_address(out, m.owner);
|
||||
out.resize(session_header_bytes + redirect_bytes);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const PrimitiveLifeRequest& m) const {
|
||||
auto out =
|
||||
header(SessionMessageType::primitive_life_request, life_request_bytes, version);
|
||||
put(out, m.session, 8);
|
||||
put(out, m.epoch, 8);
|
||||
put(out, m.request_id, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const PrimitiveLifeReceipt& m) const {
|
||||
auto out =
|
||||
header(SessionMessageType::primitive_life_receipt, life_receipt_bytes, version);
|
||||
put(out, m.request_id, 8);
|
||||
out.push_back(static_cast<std::uint8_t>(m.status));
|
||||
put(out, m.server_tick, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const PrimitiveLifeOutcome& m) const {
|
||||
auto out =
|
||||
header(SessionMessageType::primitive_life_outcome, life_outcome_bytes, version);
|
||||
put(out, m.request_id, 8);
|
||||
out.push_back(static_cast<std::uint8_t>(m.result));
|
||||
put(out, m.life_identity, 8);
|
||||
put(out, m.commit_sequence, 8);
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const PrimitiveLifeQuery& m) const {
|
||||
auto out = header(SessionMessageType::primitive_life_query, life_query_bytes, version);
|
||||
put(out, m.request_id, 8);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
return std::visit(Encoder{}, message);
|
||||
return std::visit(Encoder{version}, message);
|
||||
}
|
||||
|
||||
std::expected<SessionMessage, SessionCodecError>
|
||||
decode_session(std::span<const std::uint8_t> bytes) {
|
||||
return decode_session(bytes, nullptr);
|
||||
}
|
||||
|
||||
std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const std::uint8_t> bytes,
|
||||
std::uint16_t* version) {
|
||||
if (bytes.size() < session_header_bytes)
|
||||
return std::unexpected(SessionCodecError::truncated);
|
||||
if (get(bytes, 0, 4) != session_magic)
|
||||
return std::unexpected(SessionCodecError::bad_magic);
|
||||
if (get(bytes, 4, 2) != session_protocol_version)
|
||||
const auto wire_version = static_cast<std::uint16_t>(get(bytes, 4, 2));
|
||||
if (wire_version != session_protocol_version && wire_version != session_protocol_v5)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
if (version)
|
||||
*version = wire_version;
|
||||
if (bytes[7] != 0)
|
||||
return std::unexpected(SessionCodecError::reserved_flags);
|
||||
const auto payload = bytes.subspan(session_header_bytes);
|
||||
@@ -383,6 +444,52 @@ decode_session(std::span<const std::uint8_t> bytes) {
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return SessionRedirect{std::move(*owner)};
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::primitive_life_request): {
|
||||
if (wire_version < session_protocol_v5)
|
||||
return std::unexpected(SessionCodecError::unknown_type);
|
||||
if (!expect(life_request_bytes))
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
PrimitiveLifeRequest m{get(payload, 0, 8), get(payload, 8, 8), get(payload, 16, 8)};
|
||||
if (!m.session || !m.epoch || !m.request_id)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::primitive_life_receipt): {
|
||||
if (wire_version < session_protocol_v5)
|
||||
return std::unexpected(SessionCodecError::unknown_type);
|
||||
if (!expect(life_receipt_bytes))
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
if (payload[8] > max_admit_status)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return PrimitiveLifeReceipt{get(payload, 0, 8), static_cast<AdmitStatus>(payload[8]),
|
||||
get(payload, 9, 8)};
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::primitive_life_outcome): {
|
||||
if (wire_version < session_protocol_v5)
|
||||
return std::unexpected(SessionCodecError::unknown_type);
|
||||
if (!expect(life_outcome_bytes))
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
if (payload[8] < 1 || payload[8] > static_cast<std::uint8_t>(PrimitiveLifeResult::unknown))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
const PrimitiveLifeOutcome m{get(payload, 0, 8),
|
||||
static_cast<PrimitiveLifeResult>(payload[8]),
|
||||
get(payload, 9, 8), get(payload, 17, 8)};
|
||||
if (!m.request_id ||
|
||||
(m.result == PrimitiveLifeResult::born && (!m.life_identity || !m.commit_sequence)) ||
|
||||
(m.result != PrimitiveLifeResult::born && (m.life_identity || m.commit_sequence)))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::primitive_life_query): {
|
||||
if (wire_version < session_protocol_v5)
|
||||
return std::unexpected(SessionCodecError::unknown_type);
|
||||
if (!expect(life_query_bytes))
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
const auto id = get(payload, 0, 8);
|
||||
if (!id)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return PrimitiveLifeQuery{id};
|
||||
}
|
||||
default:
|
||||
return std::unexpected(SessionCodecError::unknown_type);
|
||||
}
|
||||
|
||||
@@ -386,8 +386,10 @@ struct RegionSessions::Impl {
|
||||
void datagram(Connection& c, std::span<const std::uint8_t> bytes, Clock::time_point now) {
|
||||
if (c.state == State::closing)
|
||||
return;
|
||||
const auto decoded = network::decode_session(bytes);
|
||||
if (c.state != State::established || !decoded)
|
||||
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)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded))
|
||||
return replication.acknowledge(c.session, *ack);
|
||||
@@ -527,13 +529,18 @@ struct RegionSessions::Impl {
|
||||
return;
|
||||
if (c.state == State::pending) // Nothing is expected before Welcome.
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
const auto decoded = network::decode_session(bytes);
|
||||
std::uint16_t wire_version{};
|
||||
const auto decoded = network::decode_session(bytes, &wire_version);
|
||||
if (!decoded)
|
||||
return close(c,
|
||||
decoded.error() == network::SessionCodecError::unsupported_version
|
||||
? 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)
|
||||
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);
|
||||
|
||||
@@ -371,7 +371,7 @@ void session_codec() {
|
||||
mutated.at(0) ^= 1;
|
||||
CHECK(refused(decode_session(mutated), SessionCodecError::bad_magic));
|
||||
mutated = bytes;
|
||||
mutated.at(4) = 5; // A future version.
|
||||
mutated.at(4) = 6; // A future version.
|
||||
CHECK(refused(decode_session(mutated), SessionCodecError::unsupported_version));
|
||||
mutated = bytes;
|
||||
mutated.at(7) = 1;
|
||||
@@ -400,6 +400,21 @@ void session_codec() {
|
||||
CHECK(std::get<SessionIntention>(*decode_session(encode_session(intent))) == intent);
|
||||
const ActionOutcome outcome{5, ActionResult::not_committed, 0, 0};
|
||||
CHECK(std::get<ActionOutcome>(*decode_session(encode_session(outcome))) == outcome);
|
||||
const std::array<SessionMessage, 4> life_messages{
|
||||
PrimitiveLifeRequest{7, 8, 9}, PrimitiveLifeReceipt{9, AdmitStatus::admitted, 10},
|
||||
PrimitiveLifeOutcome{9, PrimitiveLifeResult::born, 11, 12}, PrimitiveLifeQuery{9}};
|
||||
for (const auto& message : life_messages) {
|
||||
const auto bytes = encode_session(message);
|
||||
std::uint16_t version{};
|
||||
const auto decoded = decode_session(bytes, &version);
|
||||
CHECK(bytes.at(4) == 5 && version == session_protocol_v5);
|
||||
CHECK(decoded && decoded->index() == message.index());
|
||||
CHECK(decoded && encode_session(*decoded) == bytes);
|
||||
auto v4 = bytes;
|
||||
v4.at(4) = 4;
|
||||
CHECK(refused(decode_session(v4), SessionCodecError::unknown_type));
|
||||
}
|
||||
CHECK(encode_session(life_messages[0], session_protocol_version).empty());
|
||||
// A state claim appended to an intention (position, energy) is not a valid message.
|
||||
auto claimed = encode_session(intent);
|
||||
for (int i = 0; i < 16; ++i)
|
||||
|
||||
@@ -315,8 +315,11 @@ void login_rules(const Files& f) {
|
||||
CHECK(raw_peer(h, std::nullopt) == Reason::timeout);
|
||||
CHECK(raw_peer(h, std::vector<std::uint8_t>{1, 2, 3}) == Reason::protocol);
|
||||
auto future = encode_session(SessionHello{0, h.issuer.grant(carol, 2, start + 60)});
|
||||
future.at(4) = 5;
|
||||
future.at(4) = 6;
|
||||
CHECK(raw_peer(h, future) == Reason::unsupported_version);
|
||||
const auto unnegotiated_v5 =
|
||||
encode_session(SessionHello{0, h.issuer.grant(carol, 2, start + 60)}, session_protocol_v5);
|
||||
CHECK(raw_peer(h, unnegotiated_v5) == Reason::unsupported_version);
|
||||
CHECK(raw_peer(h, encode_session(SessionClose{Reason::client_closed})) == Reason::protocol);
|
||||
CHECK(raw_peer(h, encode_session(SessionHello{1, h.issuer.grant(carol, 3, start + 60)})) ==
|
||||
Reason::protocol); // Unknown required feature.
|
||||
|
||||
Reference in New Issue
Block a user