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>
55 lines
2.1 KiB
C++
55 lines
2.1 KiB
C++
#pragma once
|
|
#include "evo/network/tls_channel.hpp"
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
// Minimal non-blocking TCP for the M9.7 dev session (ADR-0083), Windows and Linux.
|
|
// Plaintext bytes only: every session byte travels inside TlsChannel. No socket
|
|
// handle crosses this header. One owner thread per object.
|
|
namespace evo::network {
|
|
class TcpStream final : public ByteTransport {
|
|
public:
|
|
// Resolves `host` (blocking, bounded by the system resolver) and starts a
|
|
// non-blocking connect. Reads/writes return 0 until the connection completes.
|
|
[[nodiscard]] static std::expected<std::unique_ptr<TcpStream>, TransportError>
|
|
connect(const std::string& host, std::uint16_t port);
|
|
TcpStream(const TcpStream&) = delete;
|
|
TcpStream& operator=(const TcpStream&) = delete;
|
|
~TcpStream() override;
|
|
[[nodiscard]] std::expected<std::size_t, TransportError>
|
|
write(std::span<const std::uint8_t> bytes) override;
|
|
[[nodiscard]] std::expected<std::size_t, TransportError>
|
|
read(std::span<std::uint8_t> bytes) override;
|
|
|
|
private:
|
|
friend class TcpListener;
|
|
TcpStream(std::intptr_t socket, bool connecting) : socket_{socket}, connecting_{connecting} {}
|
|
[[nodiscard]] std::expected<bool, TransportError> ready();
|
|
std::intptr_t socket_;
|
|
bool connecting_;
|
|
};
|
|
class TcpListener {
|
|
public:
|
|
// Numeric address only ("127.0.0.1:7400", "[::1]:7400", "0.0.0.0:7400"); port 0
|
|
// picks a free port.
|
|
[[nodiscard]] static std::expected<std::unique_ptr<TcpListener>, TransportError>
|
|
listen(std::string_view address);
|
|
TcpListener(const TcpListener&) = delete;
|
|
TcpListener& operator=(const TcpListener&) = delete;
|
|
~TcpListener();
|
|
// A pending connection, or nullptr when none is waiting.
|
|
[[nodiscard]] std::expected<std::unique_ptr<TcpStream>, TransportError> accept();
|
|
[[nodiscard]] std::uint16_t port() const noexcept {
|
|
return port_;
|
|
}
|
|
|
|
private:
|
|
TcpListener(std::intptr_t socket, std::uint16_t port) : socket_{socket}, port_{port} {}
|
|
std::intptr_t socket_;
|
|
std::uint16_t port_;
|
|
};
|
|
} // namespace evo::network
|