Expand description
Lean, sync-first server/network boundary exposure layer (blocking transport, TLS opt-in).
netbat is a lean, blocking transport boundary: nb exposes, sb dispatches,
bp records. It stays narrow in remit — synchronous and blocking per
connection, with a small default dependency graph (TLS is opt-in). This
crate can describe server-facing modules, endpoints, and route tables around
syncbat modules or cores. It can also handle bounded sync transport
frames, but it does not own dispatch decisions, run handlers directly, or
write batpak records.
The crate is designed to be imported as:
use netbat as nb;§Frame round-trip
Encode a CALL request, decode it back, and inspect the parts. The
encoder enforces the operation-name grammar via the substrate
OperationName newtype; downstream code never re-parses.
use netbat as nb;
let frame = nb::encode_request("system.heartbeat", &[0xde, 0xad]);
assert_eq!(frame, b"NETBAT/1 CALL system.heartbeat dead\n");
let parsed = nb::decode_line(&frame, &nb::Limits::default()).expect("decode");
assert_eq!(parsed.operation(), "system.heartbeat");
assert_eq!(parsed.input(), &[0xde, 0xad]);§Response framing
encode_response emits either OK <hex>\n or ERR <code> <hex>\n.
The ERR-frame code is a stable token from
NetbatError::code — never a runtime
string. The message half is hex of UTF-8 text, not MessagePack.
use netbat as nb;
// Success: OK <hex>\n
let ok = nb::encode_response(Ok(b"hi"));
assert_eq!(ok, b"OK 6869\n");
// Error: ERR <code> <hex>\n
let err = nb::NetbatError::MalformedRequest { reason: "bad" };
let err_frame = nb::encode_response(Err(&err));
assert!(err_frame.starts_with(b"ERR malformed_request "));
assert!(err_frame.ends_with(b"\n"));§Connection limits and dispatch
A blocking listener caps the connections it serves through
ConnectionLimit (the connection_limit field on TcpServerConfig and
TcpSubscriptionServerConfig). The default,
ConnectionLimit::Concurrent, is an in-flight permit pool sized at
DEFAULT_MAX_CONNECTIONS: at most n connections are served at once and a
freed slot is immediately reusable. It REPLACES the pre-0.9 max_connections
lifetime accept budget, which is now the explicit opt-in
ConnectionLimit::Lifetime; ConnectionLimit::Unlimited removes the gate
entirely.
The subscription listener additionally chooses how each accepted session is
served via SubscriptionDispatch. The default,
SubscriptionDispatch::Concurrent, spawns a contained worker per session
so subscribers stream concurrently (gated by the same permit pool);
SubscriptionDispatch::Sequential keeps the pre-0.9 inline behavior where
one long-lived subscriber blocks the accept loop until its session ends.
use netbat as nb;
// Both listeners default to a concurrent in-flight permit pool, and
// subscriptions are served concurrently.
assert!(matches!(
nb::ConnectionLimit::default(),
nb::ConnectionLimit::Concurrent(_),
));
assert_eq!(nb::SubscriptionDispatch::default(), nb::SubscriptionDispatch::Concurrent);
// Opt into the pre-0.9 lifetime accept budget — or remove the gate entirely.
let config = nb::TcpServerConfig::default()
.with_connection_limit(nb::ConnectionLimit::Unlimited);
assert_eq!(config.connection_limit, nb::ConnectionLimit::Unlimited);§Security / transport trust model
netbat has no authentication and no authorization, by design. Identity
and access control are downstream-domain concerns: authenticate and
authorize at a fronting proxy or in the application layer that owns the
syncbat runtime, never inside netbat. netbat only frames bytes, maps
stable error codes, and moves bounded request/response and subscription
frames over a blocking transport.
Without the tls feature (the default) netbat speaks plaintext and so
assumes a trusted transport: bind it to loopback, a private network
segment, or behind a TLS-terminating reverse proxy. There is no in-process
confidentiality on the plaintext path.
Enabling the opt-in tls feature adds server-only TLS (rustls): it
provides confidentiality and server identity only — it does not
authenticate the client (auth still lives above netbat). Build a
TlsServerConfig from PEM and pass TransportSecurity::Tls to
serve_tcp_listener_secured (or
serve_tcp_subscription_listener_secured). The rustls handshake runs on
the per-connection worker after the concurrency permit is acquired, so a
slow or hostile handshake occupies at most one worker+permit slot and never
blocks the accept loop; a failed handshake (for example, a cleartext peer) is
counted in TcpServeStats::tls_handshake_failures and the connection is
dropped — never listener-fatal. See TlsServerConfig for a PEM example.
Structs§
- Client
Window - Client-side receive window (nonzero).
- Core
Health - Borrowed health check over a syncbat core’s mounted operation descriptors.
- Cursor
Bytes - Opaque cursor bytes carried on the wire as lowercase hex.
- Delivery
Index - Monotonic per-subscription delivery index (nonzero).
- Endpoint
- A syncbat operation exposed at a server/network boundary.
- Introspection
- Introspection report for exposed boundary metadata.
- IoTimeouts
- Optional read/write timeout hints for listener owners.
- Limits
- Bounded transport limits for netbat’s blocking line protocol.
- Operation
Name - Stable operation name. Validated once at construction; downstream code never re-parses the grammar.
- Payload
Schema Ref - Opaque payload schema ref token (interpreted above netbat).
- Request
Frame - Decoded request frame for netbat’s blocking line protocol.
- Response
Frame - Encoded runtime output returned through a netbat transport frame.
- Route
- A mounted boundary route.
- Server
- Minimal server-boundary registry.
- Server
Module - Server-facing wrapper for a data-oriented syncbat module.
- Shutdown
Handle - Shared shutdown flag for blocking TCP listener loops.
- Stream
Reason Code - Stable lowercase stream reason/code token.
- SubAck
Frame NETBAT/2 SUB_ACKframe.- SubCancel
Frame NETBAT/2 SUB_CANCELframe.- SubEnd
Frame NETBAT/2 SUB_ENDframe.- SubErr
Frame NETBAT/2 SUB_ERRframe.- SubEvent
Frame NETBAT/2 SUB_EVENTframe.- SubWatermark
Frame NETBAT/2 SUB_WATERMARKframe.- Subscribe
Frame NETBAT/2 SUBSCRIBEframe.- Subscription
Token - Globally unique subscription id (
orders.open.v1grammar). - TcpServe
Stats - Summary returned after a blocking TCP listener exits.
- TcpServer
Config - Blocking TCP server limits.
- TcpSubscription
Serve Stats - Summary returned after a NETBAT/2 subscription listener exits.
- TcpSubscription
Server Config - Blocking NETBAT/2 subscription listener configuration.
Enums§
- Connection
Limit - How a listener caps the connections it serves.
- Maybe
Cursor - Optional cursor field encoded as
-when absent. - Netbat
Error - Error returned by netbat transport framing or syncbat dispatch.
- Operation
Name Error - Operation-name grammar violation surfaced by
OperationName::new. - Route
Validation Error - Boundary route validation failure.
- Stream
Frame - Decoded NETBAT/2 streaming frame.
- Subscription
Dispatch - How the subscription listener dispatches each accepted session.
- Transport
Security - Transport security applied to a request listener’s accepted connections.
Constants§
- CALL_
VERB - Request verb used by netbat’s line protocol.
- DEFAULT_
MAX_ CONNECTIONS - Default concurrent connection cap. Matches the pre-0.9
max_connectionsmagnitude so a default listener admits the same volume, now as an in-flight concurrency cap rather than a lifetime accept budget. - DEFAULT_
MAX_ CURSOR_ BYTES - Default maximum opaque cursor bytes decoded from stream frames.
- DEFAULT_
MAX_ INPUT_ BYTES - Default maximum decoded input size accepted by the line transport.
- DEFAULT_
MAX_ LINE_ BYTES - Default maximum request line size accepted by the line transport.
- DEFAULT_
MAX_ OPERATION_ NAME_ BYTES - Default maximum operation name size accepted by the line transport.
- DEFAULT_
MAX_ OUTPUT_ BYTES - Default maximum handler output size encoded into a response frame.
- DEFAULT_
MAX_ REQUESTS_ PER_ CONNECTION - Default maximum requests served from one accepted TCP connection.
- DEFAULT_
MAX_ STREAM_ ERROR_ MESSAGE_ BYTES - Default maximum decoded SUB_ERR message bytes.
- DEFAULT_
MAX_ STREAM_ PAYLOAD_ BYTES - Default maximum decoded subscription event payload bytes.
- DEFAULT_
MAX_ SUBSCRIPTION_ ID_ BYTES - Default maximum subscription id bytes accepted by NETBAT/2 stream frames.
- LAYER_
RULE - Stable crate-layer rule for docs, diagnostics, and tests.
- LINE_
PROTOCOL_ VERSION - Current version token accepted by netbat’s versioned line protocol.
- MAX_
ROUTE_ PATH_ BYTES - Maximum bytes accepted for a boundary route path.
- PROTOCOL_
PREFIX - Prefix used by every versioned netbat line-protocol token.
- STREAM_
PROTOCOL_ VERSION - Current version token accepted by NETBAT/2 subscription streaming frames.
- SUBSCRIBE_
VERB - Open/resume verb for NETBAT/2 streaming frames.
- SUB_
ACK_ VERB - Cumulative ack verb for NETBAT/2 streaming frames.
- SUB_
CANCEL_ VERB - Cancel verb for NETBAT/2 streaming frames.
- SUB_
END_ VERB - End verb for NETBAT/2 streaming frames.
- SUB_
ERR_ VERB - Error verb for NETBAT/2 streaming frames.
- SUB_
EVENT_ VERB - Delivery verb for NETBAT/2 streaming frames.
- SUB_
WATERMARK_ VERB - Watermark verb for NETBAT/2 streaming frames.
Functions§
- decode_
hex - Decode a lowercase or uppercase hexadecimal byte string with a decoded-size limit.
- decode_
hex_ str - Decode a lowercase or uppercase hexadecimal
&str. - decode_
line - Decode one netbat line-protocol request.
- decode_
stream_ line - Decode one NETBAT/2 streaming line frame.
- dispatch_
frame - Dispatch a decoded request frame through syncbat.
- encode_
hex - Encode
bytesas a lowercase hexadecimal byte string and return the owned buffer. - encode_
hex_ into - Append lowercase hexadecimal encoding of
bytesintooutput. - encode_
hex_ str - Encode
bytesas a lowercase hexadecimalString. - encode_
request - Encode a stable versioned request line.
- encode_
response - Encode a stable response line.
- encode_
stream_ frame - Encode one NETBAT/2 streaming frame as a newline-terminated line.
- inspect_
core_ operations - Inspect whether named operations are mounted in a borrowed syncbat core.
- introspect_
modules - Build an introspection report over server-facing module metadata.
- serve_
stream - Serve one request from an already-accepted blocking stream.
- serve_
subscription_ stream - Serve one NETBAT/2 subscription stream over split reader/writer handles.
- serve_
tcp_ listener - Serve a blocking TCP listener until shutdown or limits stop it.
- serve_
tcp_ listener_ secured - Serve a blocking TCP listener with a chosen
TransportSecurity. - serve_
tcp_ subscription_ listener - Serve a blocking NETBAT/2 subscription TCP listener.
- serve_
tcp_ subscription_ listener_ secured - Serve a NETBAT/2 subscription listener with a chosen
TransportSecurity.