Wire M10.8c-1 region handoff: protocol v4, durable probes, crossing, ghosts
Foundation / checks (deploy) (push) Successful in 3m29s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (client) (push) Successful in 12m51s
Foundation / checks (network) (push) Successful in 13m0s
Foundation / checks (tsan) (push) Successful in 7m50s
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 32m4s
Foundation / checks (postgres) (push) Canceled after 19m13s

ADR-0096. Session protocol v4 (v3 is deployed and frozen) adds HandoffOffer,
SessionRedirect, close reasons handed_off and moved, and ghost marker records.
Sessions use the durable probe record: logins open it where it was saved
(redirected when it lives elsewhere), and session ends save it. A marker
crossing into a neighbour's area is frozen, prepared, its control released
and a signed ticket offered; uncommitted transfers are aborted after the
ticket's lifetime. The destination shows arriving probes as ghosts (schema
v13 incoming_probe_transfers) and opens the marker where it crossed.

Refreshes the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 21:24:42 -04:00
co-authored by Claude Opus 5.5
parent 97a3756e46
commit a7a3d12283
39 changed files with 1315 additions and 68 deletions
+78 -1
View File
@@ -1,5 +1,7 @@
#include "evo/network/session_protocol.hpp"
#include <algorithm>
#include <optional>
#include <string>
namespace evo::network {
namespace {
@@ -19,6 +21,9 @@ constexpr std::uint8_t max_admit_status = static_cast<std::uint8_t>(AdmitStatus:
constexpr std::size_t interest_bytes = (3 * std::size_t{8}) + 2;
constexpr std::size_t snapshot_ack_bytes = 2 * std::size_t{8};
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;
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)
@@ -41,7 +46,44 @@ std::vector<std::uint8_t> header(SessionMessageType type, std::size_t payload) {
}
bool wire_reason(std::uint64_t v) {
return v >= static_cast<std::uint8_t>(SessionCloseReason::client_closed) &&
v <= static_cast<std::uint8_t>(SessionCloseReason::shutdown);
v <= static_cast<std::uint8_t>(SessionCloseReason::moved);
}
// Printable ASCII without spaces, then zero padding to the field size.
bool valid_text(const std::string& s) {
return !s.empty() && s.size() <= session_address_bytes &&
std::ranges::all_of(s, [](char ch) { return ch > 0x20 && ch < 0x7F; });
}
void put_text(std::vector<std::uint8_t>& out, const std::string& s) {
for (std::size_t i = 0; i < session_address_bytes; ++i)
out.push_back(i < s.size() ? static_cast<std::uint8_t>(s[i]) : std::uint8_t{0});
}
std::optional<std::string> text_at(std::span<const std::uint8_t> in, std::size_t at) {
std::string s;
std::size_t i = 0;
for (; i < session_address_bytes && in[at + i] != 0; ++i)
s.push_back(static_cast<char>(in[at + i]));
for (; i < session_address_bytes; ++i)
if (in[at + i] != 0)
return std::nullopt; // Bytes after the terminator must be padding.
if (!valid_text(s))
return std::nullopt;
return s;
}
void put_address(std::vector<std::uint8_t>& out, const RegionAddress& a) {
put(out, a.region, 8);
put_text(out, a.endpoint);
put_text(out, a.server_name);
}
std::optional<RegionAddress> address_at(std::span<const std::uint8_t> in, std::size_t at) {
RegionAddress a;
a.region = get(in, at, 8);
auto endpoint = text_at(in, at + 8);
auto name = text_at(in, at + 8 + session_address_bytes);
if (a.region == 0 || !endpoint || !name)
return std::nullopt;
a.endpoint = std::move(*endpoint);
a.server_name = std::move(*name);
return a;
}
WireGrant grant_at(std::span<const std::uint8_t> in, std::size_t at) {
WireGrant g{};
@@ -157,6 +199,21 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message) {
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);
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());
out.resize(session_header_bytes + handoff_offer_bytes); // Overlong text truncates.
return out;
}
std::vector<std::uint8_t> operator()(const SessionRedirect& m) const {
auto out = header(SessionMessageType::redirect, redirect_bytes);
put_address(out, m.owner);
out.resize(session_header_bytes + redirect_bytes);
return out;
}
};
return std::visit(Encoder{}, message);
}
@@ -306,6 +363,26 @@ decode_session(std::span<const std::uint8_t> bytes) {
return std::unexpected(SessionCodecError::wrong_length);
return SnapshotAck{get(payload, 0, 8), get(payload, 8, 8)};
}
case static_cast<std::uint8_t>(SessionMessageType::handoff_offer): {
if (!expect(handoff_offer_bytes))
return std::unexpected(SessionCodecError::wrong_length);
HandoffOffer m;
std::copy_n(payload.begin(), m.transfer.size(), m.transfer.begin());
auto destination = address_at(payload, 16);
if (!destination || std::ranges::all_of(m.transfer, [](auto b) { return b == 0; }))
return std::unexpected(SessionCodecError::invalid_value);
m.destination = std::move(*destination);
m.ticket = grant_at(payload, 16 + address_bytes);
return m;
}
case static_cast<std::uint8_t>(SessionMessageType::redirect): {
if (!expect(redirect_bytes))
return std::unexpected(SessionCodecError::wrong_length);
auto owner = address_at(payload, 0);
if (!owner)
return std::unexpected(SessionCodecError::invalid_value);
return SessionRedirect{std::move(*owner)};
}
default:
return std::unexpected(SessionCodecError::unknown_type);
}