Run a non-blocking TLS 1.3 session server inside evo-server's loop: environment views come from the region's own field/terrain stores with an explicitly empty organism presentation; admitted intentions ride the next synthetic input (content unchanged) and return a durable no-effect outcome from the host's final acknowledgement, or not_committed when dropped. Sessions are bound to their connection, epochs close stale sessions, and connections have bounded output, input rate and deadlines. SessionClient and evo-client --connect consume one single-use grant per Hello (refusals before admission keep it), reset to a fresh baseline on every session, keep stale views visible and report in-flight intentions as unknown after loss. evo-dev-session generates dev credentials, grant bundles and runs a restart probe. The dev deployment gains a drill-time, loopback-only listener with an optional Secret, enforced by the policy check, and tools/ops/session-drill.sh. Protocol v1 gains IntentOutcome and the capacity close reason before any deployment. ADR-0083 records the maintainer-confirmed decisions; M8-dev/stage remains not passed and no cluster change was made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.4 KiB
C++
77 lines
3.4 KiB
C++
#pragma once
|
|
#include "evo/network/admission.hpp"
|
|
#include "evo/network/dev_grant.hpp"
|
|
#include "evo/network/tcp.hpp"
|
|
#include "evo/network/tls_channel.hpp"
|
|
#include <array>
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <deque>
|
|
#include <expected>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// M9.7 dev session server (ADR-0083). Host-agnostic and non-blocking: the region
|
|
// host calls poll() from its own loop, publishes views of its state, lets admitted
|
|
// intentions ride host inputs via carry(), and reports durable/lost outcomes. It
|
|
// never touches simulation state and never decides an outcome.
|
|
namespace evo::network {
|
|
using RequestId = std::array<std::uint8_t, 16>;
|
|
struct SessionServerConfig {
|
|
std::string listen; // Numeric address:port.
|
|
ServerCredentials credentials;
|
|
AdmissionConfig admission; // `epoch` is ignored: it follows RegionFacts.
|
|
std::size_t max_connections{4};
|
|
std::chrono::milliseconds hello_deadline{5000}; // Accept to Welcome.
|
|
std::size_t max_output_bytes{std::size_t{1} << 20};
|
|
std::size_t max_input_bytes_per_second{65536};
|
|
std::size_t max_pending_intents{64}; // Admitted, not yet carried.
|
|
std::size_t max_carried_intents{1024}; // Carried, awaiting durable/lost.
|
|
};
|
|
// The host's current authority facts, read once per loop iteration.
|
|
struct RegionFacts {
|
|
bool ready{};
|
|
std::uint64_t epoch{}, simulated_tick{}, committed_tick{}, commit_sequence{};
|
|
};
|
|
enum class SessionServerError : std::uint8_t { configuration, listen, credentials };
|
|
struct SessionEvent {
|
|
enum class Kind : std::uint8_t { opened, closed, refused } kind{};
|
|
std::uint64_t session{}, subject{};
|
|
CloseReason reason{};
|
|
};
|
|
class SessionServer {
|
|
public:
|
|
[[nodiscard]] static std::expected<std::unique_ptr<SessionServer>, SessionServerError>
|
|
create(SessionServerConfig config, DevGrantKey key);
|
|
SessionServer(const SessionServer&) = delete;
|
|
SessionServer& operator=(const SessionServer&) = delete;
|
|
~SessionServer();
|
|
[[nodiscard]] std::uint16_t port() const noexcept;
|
|
// Accepts, handshakes, admits and writes; never blocks. `now_seconds` is wall
|
|
// time for grant validity; `now` is monotonic time for connection deadlines.
|
|
void poll(const RegionFacts& facts, std::uint64_t now_seconds,
|
|
std::chrono::steady_clock::time_point now);
|
|
// The latest views; each session receives only the newest (older unsent views are
|
|
// replaced, never queued). New sessions receive the latest as their baseline.
|
|
void publish(const client::EnvironmentPresentation& environment,
|
|
const client::OrganismPresentation& organisms, const RegionFacts& facts);
|
|
// The oldest admitted intention whose intended tick is <= `tick`, to ride the host
|
|
// input for `tick`. The host input's content stays host-chosen.
|
|
[[nodiscard]] std::optional<RequestId> carry(std::uint64_t tick);
|
|
// Host final acknowledgement / drop for a request id; ids not carried here are ignored.
|
|
void committed(const RequestId& request, std::uint64_t tick, std::uint64_t commit_sequence);
|
|
void not_committed(const RequestId& request);
|
|
[[nodiscard]] std::vector<SessionEvent> take_events();
|
|
[[nodiscard]] std::size_t connections() const noexcept;
|
|
[[nodiscard]] std::size_t sessions() const noexcept;
|
|
|
|
private:
|
|
struct Impl;
|
|
explicit SessionServer(std::unique_ptr<Impl> impl);
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
} // namespace evo::network
|