Implement M9.7 dev region sessions with durable no-effect intentions
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>
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
#include "evo/network/admission.hpp"
|
||||
#include "evo/network/dev_credentials.hpp"
|
||||
#include "evo/network/dev_grant.hpp"
|
||||
#include "evo/network/protocol.hpp"
|
||||
#include "network_test.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::network_test {
|
||||
@@ -122,6 +125,20 @@ void round_trips() {
|
||||
CHECK(r && r->sequence == 9 && r->status == IntentStatus::replayed && r->server_tick == 10);
|
||||
const auto c = decode_close(frame(encode(CloseReason::stale_epoch)));
|
||||
CHECK(c && *c == CloseReason::stale_epoch);
|
||||
CHECK(decode_close(frame(encode(CloseReason::capacity))) == CloseReason::capacity);
|
||||
const auto out = decode_intent_outcome(
|
||||
frame(encode(IntentOutcome{4, IntentFinality::committed_no_effect, 120, 9})));
|
||||
CHECK(out && out->sequence == 4 && out->finality == IntentFinality::committed_no_effect &&
|
||||
out->tick == 120 && out->commit_sequence == 9);
|
||||
CHECK(decode_intent_outcome(
|
||||
frame(encode(IntentOutcome{5, IntentFinality::not_committed, 0, 0}))));
|
||||
// Finality and commit facts must agree.
|
||||
CHECK(refused(decode_intent_outcome(
|
||||
frame(encode(IntentOutcome{4, IntentFinality::committed_no_effect, 120, 0}))),
|
||||
ProtocolError::invalid_value));
|
||||
CHECK(refused(decode_intent_outcome(
|
||||
frame(encode(IntentOutcome{4, IntentFinality::not_committed, 120, 0}))),
|
||||
ProtocolError::invalid_value));
|
||||
|
||||
const auto env = environment();
|
||||
const auto env_bytes = encode(view_header, env);
|
||||
@@ -160,7 +177,7 @@ void frame_rejection() {
|
||||
CHECK(refused(decode_frame(with_header(MessageType{0}, 1, 0, 0, 0)),
|
||||
ProtocolError::unknown_type));
|
||||
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
|
||||
CHECK(refused(decode_frame(with_header(MessageType{8}, 1, 0, 0, 0)),
|
||||
CHECK(refused(decode_frame(with_header(MessageType{9}, 1, 0, 0, 0)),
|
||||
ProtocolError::unknown_type));
|
||||
CHECK(refused(decode_frame(with_header(MessageType::intent, 1, 1, 36, 36)),
|
||||
ProtocolError::reserved_flags));
|
||||
@@ -190,7 +207,7 @@ void frame_rejection() {
|
||||
status[frame_header_bytes + 8] = 8;
|
||||
CHECK(refused(decode_intent_result(frame(status)), ProtocolError::invalid_value));
|
||||
auto reason = encode(CloseReason::normal);
|
||||
reason[frame_header_bytes] = 9;
|
||||
reason[frame_header_bytes] = 10;
|
||||
CHECK(refused(decode_close(frame(reason)), ProtocolError::invalid_value));
|
||||
CHECK(refused(decode_welcome(frame(encode(Welcome{}))), ProtocolError::invalid_value));
|
||||
// A well-formed encoding of an invalid view is rejected by the presentation rules.
|
||||
@@ -237,13 +254,15 @@ void reader() {
|
||||
// identical bytes (canonical, no hidden fields trusted from the wire).
|
||||
void fuzz() {
|
||||
std::mt19937_64 random{0x9E3779B97F4A7C15ULL};
|
||||
const std::vector<Bytes> seeds{*encode(Hello{0, Bytes(dev_grant_bytes, 7)}),
|
||||
encode(Welcome{1, 11, 12, 13, 14, 15, 16, 17, 8, 8, 16}),
|
||||
encode(IntentMessage{1, 2, 3, 4, 5, 6}),
|
||||
encode(IntentResult{1, IntentStatus::outside_window, 2}),
|
||||
encode(CloseReason::rate_limited),
|
||||
encode(view_header, environment()),
|
||||
encode(view_header, organisms(3))};
|
||||
const std::vector<Bytes> seeds{
|
||||
*encode(Hello{0, Bytes(dev_grant_bytes, 7)}),
|
||||
encode(Welcome{1, 11, 12, 13, 14, 15, 16, 17, 8, 8, 16}),
|
||||
encode(IntentMessage{1, 2, 3, 4, 5, 6}),
|
||||
encode(IntentResult{1, IntentStatus::outside_window, 2}),
|
||||
encode(CloseReason::rate_limited),
|
||||
encode(IntentOutcome{3, IntentFinality::committed_no_effect, 4, 5}),
|
||||
encode(view_header, environment()),
|
||||
encode(view_header, organisms(3))};
|
||||
std::size_t accepted = 0;
|
||||
for (int round = 0; round < 30000; ++round) {
|
||||
auto bytes = seeds[random() % seeds.size()];
|
||||
@@ -290,6 +309,10 @@ void fuzz() {
|
||||
if (const auto m = decode_close(*f))
|
||||
again = encode(*m);
|
||||
break;
|
||||
case MessageType::intent_outcome:
|
||||
if (const auto m = decode_intent_outcome(*f))
|
||||
again = encode(*m);
|
||||
break;
|
||||
case MessageType::environment_view:
|
||||
if (const auto m = decode_environment_view(*f))
|
||||
again = encode(m->first, m->second);
|
||||
@@ -362,6 +385,36 @@ void dev_grants() {
|
||||
CHECK(refused(moved.issue(claims(5, 5)), GrantError::invalid_key));
|
||||
}
|
||||
|
||||
void dev_credentials() {
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
CHECK(refused(generate_dev_credentials(DeploymentEnvironment::stage, "dev.test", 30, now),
|
||||
GrantError::not_dev_environment));
|
||||
CHECK(refused(generate_dev_credentials(DeploymentEnvironment::world0, "dev.test", 30, now),
|
||||
GrantError::not_dev_environment));
|
||||
for (const auto* name : {"", "a,CN=evil", "a b", "x\n"})
|
||||
CHECK(refused(generate_dev_credentials(DeploymentEnvironment::dev, name, 30, now),
|
||||
GrantError::invalid_claims));
|
||||
CHECK(refused(generate_dev_credentials(DeploymentEnvironment::dev, "dev.test", 0, now),
|
||||
GrantError::invalid_claims));
|
||||
CHECK(refused(generate_dev_credentials(DeploymentEnvironment::dev, "dev.test", 826, now),
|
||||
GrantError::invalid_claims));
|
||||
const auto made = generate_dev_credentials(DeploymentEnvironment::dev, "dev.test", 30, now);
|
||||
CHECK(made && made->authority_pem.starts_with("-----BEGIN CERTIFICATE-----") &&
|
||||
made->server_certificate_pem.starts_with("-----BEGIN CERTIFICATE-----") &&
|
||||
made->server_key_pem.find("PRIVATE KEY") != std::string::npos);
|
||||
CHECK(std::ranges::any_of(made->grant_key, [](std::uint8_t b) { return b != 0; }));
|
||||
const auto text = format_grant_key(made->grant_key);
|
||||
CHECK(text.size() == 64 && parse_grant_key(" " + text + "\n") == made->grant_key);
|
||||
CHECK(refused(parse_grant_key(text.substr(1)), GrantError::invalid_key));
|
||||
auto upper = text;
|
||||
upper[0] = 'G';
|
||||
CHECK(refused(parse_grant_key(upper), GrantError::invalid_key));
|
||||
// The generated key is usable for grants.
|
||||
CHECK(DevGrantKey::import(DeploymentEnvironment::dev, made->grant_key));
|
||||
const auto a = random_grant_id(), b = random_grant_id();
|
||||
CHECK(a && b && *a != 0 && *a != *b);
|
||||
}
|
||||
|
||||
SessionAdmission admission(std::size_t max_sessions = 4, std::size_t remembered = 8) {
|
||||
AdmissionConfig config;
|
||||
config.world = identity;
|
||||
@@ -452,6 +505,7 @@ void protocol_tests() {
|
||||
reader();
|
||||
fuzz();
|
||||
dev_grants();
|
||||
dev_credentials();
|
||||
admission_rules();
|
||||
}
|
||||
} // namespace evo::network_test
|
||||
|
||||
Reference in New Issue
Block a user