Define cellular owner diagnostics v9
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (postgres) (push) Failing after 53s
Foundation / checks (tsan) (push) Failing after 32s
Foundation / checks (network) (push) Failing after 3m1s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (postgres) (push) Failing after 53s
Foundation / checks (tsan) (push) Failing after 32s
Foundation / checks (network) (push) Failing after 3m1s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -14,6 +14,9 @@ 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 cellular_perception_prefix_bytes = 8 + 8 + 2;
|
||||
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
||||
constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
||||
cellular_perception_prefix_bytes + cellular_diagnostics_bytes;
|
||||
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
|
||||
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
|
||||
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
|
||||
@@ -33,6 +36,20 @@ constexpr std::size_t life_receipt_bytes = 17;
|
||||
constexpr std::size_t life_outcome_bytes = 25;
|
||||
constexpr std::size_t life_query_bytes = 8;
|
||||
|
||||
bool valid_diagnostics(const CellularLifeDiagnostics& diagnostics) {
|
||||
const auto movement = static_cast<std::uint8_t>(diagnostics.movement);
|
||||
const auto intake = static_cast<std::uint8_t>(diagnostics.intake);
|
||||
if (movement > static_cast<std::uint8_t>(CellularMovementResult::insufficient_energy) ||
|
||||
intake > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact))
|
||||
return false;
|
||||
if (!diagnostics.has_tick_effects)
|
||||
return diagnostics.maintenance_cost_pj == 0 && diagnostics.movement_cost_pj == 0 &&
|
||||
diagnostics.movement == CellularMovementResult::not_reported &&
|
||||
diagnostics.intake == CellularIntakeResult::not_reported;
|
||||
return diagnostics.movement != CellularMovementResult::not_reported &&
|
||||
diagnostics.intake != CellularIntakeResult::not_reported;
|
||||
}
|
||||
|
||||
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)
|
||||
out.push_back(static_cast<std::uint8_t>(v >> (8 * i)));
|
||||
@@ -106,17 +123,21 @@ 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<CellularPerception>(message) ? session_protocol_v8
|
||||
: std::holds_alternative<CellularAction>(message) ? session_protocol_v7
|
||||
: std::holds_alternative<CellularIntention>(message) ? session_protocol_v6
|
||||
: is_life ? session_protocol_v5 : session_protocol_version;
|
||||
const auto version =
|
||||
std::holds_alternative<CellularPerception>(message)
|
||||
? (std::get<CellularPerception>(message).diagnostics ? session_protocol_v9
|
||||
: session_protocol_v8)
|
||||
: 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_v7 &&
|
||||
version != session_protocol_v8)
|
||||
version != session_protocol_v8 && version != session_protocol_v9)
|
||||
return {};
|
||||
if (version == session_protocol_version &&
|
||||
(std::holds_alternative<PrimitiveLifeRequest>(message) ||
|
||||
@@ -127,20 +148,28 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
if (version != session_protocol_v6 && std::holds_alternative<CellularIntention>(message))
|
||||
return {};
|
||||
if (version != session_protocol_v7 && version != session_protocol_v8 &&
|
||||
std::holds_alternative<CellularAction>(message))
|
||||
version != session_protocol_v9 && std::holds_alternative<CellularAction>(message))
|
||||
return {};
|
||||
if (version != session_protocol_v7 && version != session_protocol_v8 &&
|
||||
std::holds_alternative<ActionOutcome>(message) &&
|
||||
version != session_protocol_v9 && std::holds_alternative<ActionOutcome>(message) &&
|
||||
std::get<ActionOutcome>(message).result == ActionResult::committed)
|
||||
return {};
|
||||
if (version != session_protocol_v8 && std::holds_alternative<CellularPerception>(message))
|
||||
if (version != session_protocol_v8 && version != session_protocol_v9 &&
|
||||
std::holds_alternative<CellularPerception>(message))
|
||||
return {};
|
||||
if (const auto* perception = std::get_if<CellularPerception>(&message)) {
|
||||
if (!perception->tick || perception->patches.size() > max_cellular_perceived_patches ||
|
||||
(!perception->life_identity && !perception->patches.empty()) ||
|
||||
!std::ranges::is_sorted(perception->patches, [](const auto& a, const auto& b) {
|
||||
return std::pair{a.x_um, a.y_um} < std::pair{b.x_um, b.y_um};
|
||||
}) ||
|
||||
(version == session_protocol_v8 && perception->diagnostics) ||
|
||||
(version == session_protocol_v9 && perception->life_identity &&
|
||||
!perception->diagnostics) ||
|
||||
(perception->life_identity == 0 && perception->diagnostics) ||
|
||||
(perception->diagnostics && !valid_diagnostics(*perception->diagnostics)) ||
|
||||
!std::ranges::is_sorted(perception->patches,
|
||||
[](const auto& a, const auto& b) {
|
||||
return std::pair{a.x_um, a.y_um} <
|
||||
std::pair{b.x_um, b.y_um};
|
||||
}) ||
|
||||
std::adjacent_find(perception->patches.begin(), perception->patches.end(),
|
||||
[](const auto& a, const auto& b) {
|
||||
return a.x_um == b.x_um && a.y_um == b.y_um;
|
||||
@@ -213,12 +242,27 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
|
||||
auto out = header(SessionMessageType::cellular_perception,
|
||||
cellular_perception_prefix_bytes +
|
||||
(version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
|
||||
: cellular_perception_prefix_bytes) +
|
||||
m.patches.size() * cellular_perceived_patch_bytes,
|
||||
version);
|
||||
put(out, m.tick, 8);
|
||||
put(out, m.life_identity, 8);
|
||||
put(out, m.patches.size(), 2);
|
||||
if (version == session_protocol_v9) {
|
||||
const auto& d = m.diagnostics;
|
||||
put(out, d ? d->reserve_energy_pj : 0, 8);
|
||||
for (const auto value : d ? d->reserve_matter_fg : std::array<std::uint64_t, 4>{})
|
||||
put(out, value, 8);
|
||||
put(out, d ? d->maintenance_cost_pj : 0, 8);
|
||||
put(out, d ? d->movement_cost_pj : 0, 8);
|
||||
out.push_back(d ? static_cast<std::uint8_t>(d->movement)
|
||||
: static_cast<std::uint8_t>(CellularMovementResult::not_reported));
|
||||
out.push_back(d ? static_cast<std::uint8_t>(d->intake)
|
||||
: static_cast<std::uint8_t>(CellularIntakeResult::not_reported));
|
||||
out.push_back(d && d->has_tick_effects ? 1 : 0);
|
||||
put(out, 0, 5);
|
||||
}
|
||||
for (const auto& patch : m.patches) {
|
||||
put(out, patch.x_um, 4);
|
||||
put(out, patch.y_um, 4);
|
||||
@@ -360,7 +404,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
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_v7 &&
|
||||
wire_version != session_protocol_v8)
|
||||
wire_version != session_protocol_v8 && wire_version != session_protocol_v9)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
if (version)
|
||||
*version = wire_version;
|
||||
@@ -443,7 +487,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::cellular_action): {
|
||||
if (wire_version != session_protocol_v7 && wire_version != session_protocol_v8)
|
||||
if (wire_version != session_protocol_v7 && wire_version != session_protocol_v8 &&
|
||||
wire_version != session_protocol_v9)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
if (!expect(cellular_action_bytes))
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
@@ -465,22 +510,55 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
return m;
|
||||
}
|
||||
case static_cast<std::uint8_t>(SessionMessageType::cellular_perception): {
|
||||
if (wire_version != session_protocol_v8)
|
||||
if (wire_version != session_protocol_v8 && wire_version != session_protocol_v9)
|
||||
return std::unexpected(SessionCodecError::unsupported_version);
|
||||
if (payload.size() < cellular_perception_prefix_bytes)
|
||||
const auto prefix = wire_version == session_protocol_v9
|
||||
? cellular_perception_v9_prefix_bytes
|
||||
: cellular_perception_prefix_bytes;
|
||||
if (payload.size() < prefix)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
const auto count = static_cast<std::size_t>(get(payload, 16, 2));
|
||||
if (count > max_cellular_perceived_patches ||
|
||||
payload.size() != cellular_perception_prefix_bytes +
|
||||
count * cellular_perceived_patch_bytes)
|
||||
payload.size() != prefix + count * cellular_perceived_patch_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
CellularPerception m;
|
||||
m.tick = get(payload, 0, 8);
|
||||
m.life_identity = get(payload, 8, 8);
|
||||
if (!m.tick || (!m.life_identity && count))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
if (wire_version == session_protocol_v9) {
|
||||
CellularLifeDiagnostics d;
|
||||
d.reserve_energy_pj = get(payload, 18, 8);
|
||||
for (std::size_t channel = 0; channel < d.reserve_matter_fg.size(); ++channel)
|
||||
d.reserve_matter_fg[channel] = get(payload, 26 + channel * 8, 8);
|
||||
d.maintenance_cost_pj = get(payload, 58, 8);
|
||||
d.movement_cost_pj = get(payload, 66, 8);
|
||||
if (payload[74] >
|
||||
static_cast<std::uint8_t>(CellularMovementResult::insufficient_energy) ||
|
||||
payload[75] > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact) ||
|
||||
payload[76] > 1 ||
|
||||
std::ranges::any_of(payload.subspan(77, 5),
|
||||
[](std::uint8_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
d.movement = static_cast<CellularMovementResult>(payload[74]);
|
||||
d.intake = static_cast<CellularIntakeResult>(payload[75]);
|
||||
d.has_tick_effects = payload[76] != 0;
|
||||
if (m.life_identity)
|
||||
m.diagnostics = d;
|
||||
else if (d.reserve_energy_pj ||
|
||||
std::ranges::any_of(d.reserve_matter_fg,
|
||||
[](std::uint64_t value) { return value != 0; }) ||
|
||||
d.maintenance_cost_pj || d.movement_cost_pj || d.has_tick_effects ||
|
||||
d.movement != CellularMovementResult::not_reported ||
|
||||
d.intake != CellularIntakeResult::not_reported)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
}
|
||||
if (wire_version == session_protocol_v9 && m.life_identity && !m.diagnostics)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
if (m.diagnostics && !valid_diagnostics(*m.diagnostics))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.patches.reserve(count);
|
||||
std::size_t offset = cellular_perception_prefix_bytes;
|
||||
std::size_t offset = prefix;
|
||||
for (std::size_t i = 0; i < count; ++i) {
|
||||
CellularPerceivedPatch patch;
|
||||
patch.x_um = static_cast<std::uint32_t>(get(payload, offset, 4));
|
||||
@@ -488,9 +566,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
patch.energy_pj = get(payload, offset + 8, 8);
|
||||
for (std::size_t channel = 0; channel < patch.matter_fg.size(); ++channel)
|
||||
patch.matter_fg[channel] = get(payload, offset + 16 + channel * 8, 8);
|
||||
if (!m.patches.empty() &&
|
||||
!(std::pair{m.patches.back().x_um, m.patches.back().y_um} <
|
||||
std::pair{patch.x_um, patch.y_um}))
|
||||
if (!m.patches.empty() && !(std::pair{m.patches.back().x_um, m.patches.back().y_um} <
|
||||
std::pair{patch.x_um, patch.y_um}))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.patches.push_back(patch);
|
||||
offset += cellular_perceived_patch_bytes;
|
||||
@@ -535,7 +612,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
if (payload[8] < static_cast<std::uint8_t>(ActionResult::committed_no_effect) ||
|
||||
payload[8] > static_cast<std::uint8_t>(ActionResult::committed) ||
|
||||
(payload[8] == static_cast<std::uint8_t>(ActionResult::committed) &&
|
||||
wire_version != session_protocol_v7 && wire_version != session_protocol_v8))
|
||||
wire_version != session_protocol_v7 && wire_version != session_protocol_v8 &&
|
||||
wire_version != session_protocol_v9))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
const ActionOutcome m{get(payload, 0, 8), static_cast<ActionResult>(payload[8]),
|
||||
get(payload, 9, 8), get(payload, 17, 8)};
|
||||
|
||||
Reference in New Issue
Block a user