Route cellular logins to existing life owners
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 2m1s
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 22s
Foundation / checks (network) (push) Canceled after 1m58s
Foundation / checks (client) (push) Canceled after 2m39s

This commit is contained in:
dingo
2026-10-11 01:32:14 -04:00
parent 636740bc55
commit a6b1c62168
11 changed files with 273 additions and 106 deletions
@@ -45,6 +45,33 @@ PostgresControlLedger::claim(const network::AccountId& account, std::uint64_t se
return network::ControlLease{claimed->generation, claimed->wait, claimed->granted};
}
std::expected<std::optional<std::uint64_t>, network::ControlLedgerError>
PostgresControlLedger::primitive_life_owner(const network::AccountId& account) {
const auto lease = lease_();
if (!lease)
return std::unexpected(network::ControlLedgerError::fenced);
auto* db = db_->get();
if (!db)
return std::unexpected(network::ControlLedgerError::unavailable);
const auto owner =
persistence::primitive_life_owner(*db, key_, *lease, uuid(account), timeout_);
if (!owner) {
note(*db_, owner.error().kind == persistence::LifeReservationError::store
? ControlStoreError::store
: owner.error().kind == persistence::LifeReservationError::unknown
? ControlStoreError::unknown
: owner.error().kind == persistence::LifeReservationError::fenced
? ControlStoreError::fenced
: ControlStoreError::invalid);
return std::unexpected(owner.error().kind == persistence::LifeReservationError::fenced
? network::ControlLedgerError::fenced
: owner.error().kind == persistence::LifeReservationError::invalid
? network::ControlLedgerError::fenced
: network::ControlLedgerError::unavailable);
}
return *owner;
}
std::expected<std::chrono::milliseconds, ControlLedgerError>
PostgresControlLedger::renew(const network::AccountId& account, std::uint64_t generation) {
const auto lease = lease_();
+49 -11
View File
@@ -1,5 +1,6 @@
#include "evo/server/region_sessions.hpp"
#include <algorithm>
#include <set>
#include <utility>
namespace evo::server {
@@ -63,6 +64,10 @@ SessionCloseReason reason_for(SessionGrantError e) {
return e == SessionGrantError::wrong_environment ? SessionCloseReason::wrong_scope
: SessionCloseReason::unauthenticated;
}
bool valid_route_text(const std::string& value) {
return !value.empty() && value.size() <= network::session_address_bytes &&
std::ranges::all_of(value, [](char ch) { return ch > 0x20 && ch < 0x7F; });
}
} // namespace
struct RegionSessions::Impl {
@@ -232,6 +237,24 @@ struct RegionSessions::Impl {
c.account = network::log_label(claims.account);
if (const auto checked = control.check(*grant, now_seconds); !checked)
return close(c, reason_for(checked.error()), now);
if (!config.life_owner_routes.empty()) {
if (!config.ledger)
return close(c, SessionCloseReason::capacity, now);
const auto owner = config.ledger->primitive_life_owner(claims.account);
if (!owner)
return close(c, reason_for(owner.error()), now);
if (*owner && **owner != config.control.region) {
const auto route = std::ranges::find_if(
config.life_owner_routes, [&](const LifeOwnerRoute& candidate) {
return candidate.address.region == **owner;
});
if (route == config.life_owner_routes.end())
return close(c, SessionCloseReason::capacity, now);
if (c.protocol_version >= network::session_protocol_version)
send(c, network::SessionRedirect{route->address});
return close(c, SessionCloseReason::moved, now);
}
}
// Durable control first, so the world never has two controlling regions; then the
// local admission, which check() has just confirmed.
std::optional<network::ControlLease> lease;
@@ -395,11 +418,11 @@ struct RegionSessions::Impl {
const auto decoded = network::decode_session(bytes, &wire_version);
if (c.state != State::established || !decoded || wire_version != c.protocol_version ||
(c.protocol_version != network::session_protocol_version &&
!((config.accept_cellular_intentions &&
c.protocol_version == network::session_protocol_v6) ||
(config.accept_cellular_actions &&
(c.protocol_version == network::session_protocol_v7 ||
c.protocol_version == network::session_protocol_v8)))))
!((config.accept_cellular_intentions &&
c.protocol_version == network::session_protocol_v6) ||
(config.accept_cellular_actions &&
(c.protocol_version == network::session_protocol_v7 ||
c.protocol_version == network::session_protocol_v8)))))
return close(c, SessionCloseReason::protocol, now);
if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded))
return replication.acknowledge(c.session, *ack);
@@ -566,7 +589,8 @@ struct RegionSessions::Impl {
(wire_version == network::session_protocol_v5 && !primitive_v5) ||
(wire_version == network::session_protocol_v6 && !cellular_v6) ||
((wire_version == network::session_protocol_v7 ||
wire_version == network::session_protocol_v8) && !cellular_actions) ||
wire_version == network::session_protocol_v8) &&
!cellular_actions) ||
wire_version > network::session_protocol_v8)
return close(c, SessionCloseReason::unsupported_version, now);
} else if (wire_version != c.protocol_version) {
@@ -642,8 +666,22 @@ RegionSessions::~RegionSessions() = default;
std::expected<std::unique_ptr<RegionSessions>, RegionSessionsError>
RegionSessions::create(RegionSessionsConfig config) {
bool has_own_life_route = config.life_owner_routes.empty();
std::set<std::uint64_t> life_route_regions;
for (const auto& route : config.life_owner_routes) {
const auto& address = route.address;
if (address.region == 0 || !valid_route_text(address.endpoint) ||
!valid_route_text(address.server_name) ||
!life_route_regions.insert(address.region).second)
return std::unexpected(RegionSessionsError::configuration);
has_own_life_route |= address.region == config.control.region;
}
// Connections beyond sessions are headroom for logins and closes still flushing.
if (config.issuer_keys.empty() || (config.handoff != nullptr && config.ledger == nullptr) ||
if (config.issuer_keys.empty() ||
(!config.life_owner_routes.empty() &&
(config.ledger == nullptr || config.life_owner_routes.size() > 4096 ||
!has_own_life_route)) ||
(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) &&
@@ -838,12 +876,12 @@ void RegionSessions::replicate(
m.send_datagram(*c, chunk); // A refused chunk leaves the snapshot unacknowledged.
}
bool RegionSessions::send_cellular_perception(
const network::AccountId& account, const network::CellularPerception& perception) {
bool RegionSessions::send_cellular_perception(const network::AccountId& account,
const network::CellularPerception& perception) {
auto& m = *impl_;
for (const auto& c : m.connections) {
if (c.state != Impl::State::established || c.protocol_version != network::session_protocol_v8 ||
c.account_id != account)
if (c.state != Impl::State::established ||
c.protocol_version != network::session_protocol_v8 || c.account_id != account)
continue;
return m.endpoint
->send_message(c.id, network::encode_session(perception, c.protocol_version))