Add durable cellular action protocol v7
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
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 (client) (push) Canceled after 1m16s
Foundation / checks (ecs) (push) Canceled after 1m8s
Foundation / checks (network) (push) Canceled after 37s

This commit is contained in:
dingo
2026-10-10 22:57:03 -04:00
parent d0c7a938f1
commit d1717410d6
7 changed files with 163 additions and 18 deletions
+54 -9
View File
@@ -12,6 +12,7 @@ constexpr std::size_t refresh_result_bytes = 1 + 8;
constexpr std::size_t close_bytes = 1;
constexpr std::size_t intention_bytes = (std::size_t{4} * 8) + 4;
constexpr std::size_t cellular_intention_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
constexpr std::size_t cellular_action_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + 8;
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
constexpr std::size_t action_bytes = (std::size_t{3} * 8) + 2 + 8;
@@ -103,15 +104,15 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
std::holds_alternative<PrimitiveLifeReceipt>(message) ||
std::holds_alternative<PrimitiveLifeOutcome>(message) ||
std::holds_alternative<PrimitiveLifeQuery>(message);
const auto version = std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
: is_life ? session_protocol_v5
: session_protocol_version;
const auto version = std::holds_alternative<CellularAction>(message) ? session_protocol_v7
: std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
: is_life ? session_protocol_v5 : session_protocol_version;
return encode_session(message, version);
}
std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uint16_t version) {
if (version != session_protocol_version && version != session_protocol_v5 &&
version != session_protocol_v6)
version != session_protocol_v6 && version != session_protocol_v7)
return {};
if (version == session_protocol_version &&
(std::holds_alternative<PrimitiveLifeRequest>(message) ||
@@ -121,6 +122,11 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
return {};
if (version != session_protocol_v6 && std::holds_alternative<CellularIntention>(message))
return {};
if (version != session_protocol_v7 && std::holds_alternative<CellularAction>(message))
return {};
if (version != session_protocol_v7 && std::holds_alternative<ActionOutcome>(message) &&
std::get<ActionOutcome>(message).result == ActionResult::committed)
return {};
struct Encoder {
std::uint16_t version;
std::vector<std::uint8_t> operator()(const SessionHello& m) const {
@@ -173,6 +179,18 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
put(out, m.intake_y_um, 4);
return out;
}
std::vector<std::uint8_t> operator()(const CellularAction& m) const {
auto out = header(SessionMessageType::cellular_action, cellular_action_bytes, version);
for (const auto v : {m.session, m.epoch, m.action_id, m.tick})
put(out, v, 8);
put(out, static_cast<std::uint16_t>(m.move_x), 2);
put(out, static_cast<std::uint16_t>(m.move_y), 2);
out.push_back(m.has_intake_target ? 1 : 0);
put(out, 0, 3);
put(out, m.intake_x_um, 4);
put(out, m.intake_y_um, 4);
return out;
}
std::vector<std::uint8_t> operator()(const IntentionReceipt& m) const {
auto out =
header(SessionMessageType::intention_receipt, intention_receipt_bytes, version);
@@ -304,7 +322,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return std::unexpected(SessionCodecError::bad_magic);
const auto wire_version = static_cast<std::uint16_t>(get(bytes, 4, 2));
if (wire_version != session_protocol_version && wire_version != session_protocol_v5 &&
wire_version != session_protocol_v6)
wire_version != session_protocol_v6 && wire_version != session_protocol_v7)
return std::unexpected(SessionCodecError::unsupported_version);
if (version)
*version = wire_version;
@@ -366,7 +384,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return m; // Ranges belong to admission, which answers with a status.
}
case static_cast<std::uint8_t>(SessionMessageType::cellular_intention): {
if (wire_version < session_protocol_v6)
if (wire_version != session_protocol_v6)
return std::unexpected(SessionCodecError::unsupported_version);
if (!expect(cellular_intention_bytes))
return std::unexpected(SessionCodecError::wrong_length);
@@ -386,6 +404,28 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
return std::unexpected(SessionCodecError::invalid_value);
return m;
}
case static_cast<std::uint8_t>(SessionMessageType::cellular_action): {
if (wire_version != session_protocol_v7)
return std::unexpected(SessionCodecError::unsupported_version);
if (!expect(cellular_action_bytes))
return std::unexpected(SessionCodecError::wrong_length);
CellularAction m;
m.session = get(payload, 0, 8);
m.epoch = get(payload, 8, 8);
m.action_id = get(payload, 16, 8);
m.tick = get(payload, 24, 8);
m.move_x = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 32, 2)));
m.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 34, 2)));
if (payload[36] > 1 || payload[37] != 0 || payload[38] != 0 || payload[39] != 0)
return std::unexpected(SessionCodecError::invalid_value);
m.has_intake_target = payload[36] != 0;
m.intake_x_um = static_cast<std::uint32_t>(get(payload, 40, 4));
m.intake_y_um = static_cast<std::uint32_t>(get(payload, 44, 4));
if (!m.session || !m.epoch || !m.action_id || !m.tick ||
(!m.has_intake_target && (m.intake_x_um || m.intake_y_um)))
return std::unexpected(SessionCodecError::invalid_value);
return m;
}
case static_cast<std::uint8_t>(SessionMessageType::intention_receipt): {
if (!expect(intention_receipt_bytes))
return std::unexpected(SessionCodecError::wrong_length);
@@ -422,10 +462,15 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
if (!expect(action_outcome_bytes))
return std::unexpected(SessionCodecError::wrong_length);
if (payload[8] < static_cast<std::uint8_t>(ActionResult::committed_no_effect) ||
payload[8] > static_cast<std::uint8_t>(ActionResult::unknown))
payload[8] > static_cast<std::uint8_t>(ActionResult::committed) ||
(payload[8] == static_cast<std::uint8_t>(ActionResult::committed) &&
wire_version != session_protocol_v7))
return std::unexpected(SessionCodecError::invalid_value);
return ActionOutcome{get(payload, 0, 8), static_cast<ActionResult>(payload[8]),
get(payload, 9, 8), get(payload, 17, 8)};
const ActionOutcome m{get(payload, 0, 8), static_cast<ActionResult>(payload[8]),
get(payload, 9, 8), get(payload, 17, 8)};
if (m.result == ActionResult::committed && (!m.tick || !m.commit_sequence))
return std::unexpected(SessionCodecError::invalid_value);
return m;
}
case static_cast<std::uint8_t>(SessionMessageType::action_query): {
if (!expect(action_query_bytes))