Skip to main content

Module protocol

Module protocol 

Source
Expand description

LiNo substitution operations over TCP/IP (issue #105).

Two interchangeable protocols carry LiNo documents between a client and a server:

  • TextLinoProtocol: UTF-8 LiNo text, each message ended by a line holding only . (SMTP-style dot-stuffing keeps the framing unambiguous).
  • BinaryLinoProtocol: a self-delimiting LinksPacket of binary links notation, made of sections of links that share one reference width (1, 2, 4 or 8 bytes) and one arity range. By default every link is a doublet and the whole packet uses the narrowest width that fits; the options external references, arity (for example 2..3 or 1..) and packed widths can be switched on one by one.

The binary links notation itself (packets, the LiNo mapping, the canonical text form) comes from [links_notation::binary]; this module re-exports it and adds the transport: message framing, the server, the client and the store archive.

Both implement LinoProtocol, so a LinoConnection or a LinksClient switches protocol by swapping one value. A LinksServer detects the protocol of every message and answers in kind.

A request is a substitution query, so it covers create, read, update and delete; the reply lists the (before) (after) changes, exactly like clink --changes. The empty request reads the whole store.

use link_cli::protocol::{format_document, parse_document, BinaryLinoOptions, BinaryLinoProtocol};

let document = parse_document("() ((1 1))").unwrap();
let binary = BinaryLinoProtocol::with_options(
    BinaryLinoOptions::default().with_external_references(true),
);
let bytes = binary.encode(&document).unwrap();
assert_eq!(binary.decode(&bytes).unwrap(), document);
assert_eq!(format_document(&document), "() ((1 1))");

Re-exports§

pub use archive::export_store;
pub use archive::export_store_file;
pub use archive::import_store;
pub use archive::import_store_file;
pub use links_operations::GenericLinksOperation;
pub use links_operations::LinksNotification;
pub use links_operations::LinksOperation;
pub use triplets_operations::execute_triplets_request;
pub use triplets_operations::TripletsNotification;
pub use triplets_operations::TripletsOperation;

Modules§

archive
Store archive: a whole links store in binary links notation.
ipc
Interchangeable inter-process communication transports (issue #140).
links_operations
The links interface (ILinks in C#, [doublets::Links] in Rust) as LiNo documents, so a store behind a LinksServer is used exactly like a local one through RemoteLinks.
packet
Binary links notation: a self-delimiting packet of links.
triplets_operations
The triplets of a server in triplet mode (issue #152) as LiNo documents, so a store behind a LinksServer is used exactly like a local Triplets store through RemoteLinks.

Structs§

ArityRange
How many references the links of a section hold: min..=max, where max = None means no upper bound.
BinaryLinoOptions
Optional features of the binary LiNo protocol.
BinaryLinoProtocol
Binary links packets of [links_notation::binary]; every message is self-delimiting, so no extra framing is needed.
DecodeLimits
Safety limits applied while decoding untrusted input.
LinksClient
Sends substitution queries to a LiNo server over any LinoProtocol.
LinksPacket
A decoded binary links packet.
LinksServer
A bound, not yet serving, LiNo server.
LinksSessions
A store served to many sessions, each with its subject (issue #149).
LinoConnection
A byte stream decorated with a LinoProtocol.
ProtocolLimits
Limits applied to incoming messages of either protocol.
RemoteLinks
A links store served by a LinksServer, usable wherever a local store is.
Section
A run of links at consecutive addresses sharing an arity range and a reference width.
ServerOptions
Server configuration.
SessionId
A session of a LinksSessions, as LinksSessions::open returns it.
ShutdownHandle
Stops a running LinksServer::serve from another thread.
TextLinoProtocol
UTF-8 LiNo text, one message per block of lines ended by a line holding only .. Lines starting with . get one extra . (SMTP dot-stuffing).

Enums§

AcceptedProtocols
Which protocols a server accepts.
BinaryError
A failure while encoding or decoding a packet or LiNo document.
MessageFormat
The wire format a message arrived in, so a reply can use the same one.
ProtocolError
Everything that can go wrong while encoding, decoding or exchanging a LiNo message.
Reference
One reference inside a packet.

Constants§

DEFAULT_MAX_PENDING_NOTIFICATIONS
The default of ServerOptions::max_pending_notifications.
DEFAULT_MAX_TEXT_BYTES
The default limit of a text message: 64 MiB.

Traits§

LinoProtocol
Reads and writes whole LiNo documents on a byte stream.
TimedStream
A stream whose reads can time out, so a LinoConnection over it can wait for a message.

Functions§

decode_document
Converts a packet back into a document.
encode_document
Converts a document into a packet.
encode_document_with_limits
Converts a native model into a packet using caller-selected work budgets.
error_document
The reply document for a failed request: (error: 'message').
error_message
Returns the message of an (error: 'message') reply.
execute_request
Executes one request against storage.
execute_request_for
Executes an owned protocol document with the selected address type. Checked storage policies admit the document before recursive formatting.
format_document
Formats a document as canonical LiNo text, one top-level link per line.
format_link
Formats one link as it appears nested inside another link.
format_reference
Quotes a reference when it would not survive parsing as a bare word.
is_binary_start
True when byte starts a binary message rather than a text one.
parse_document
Parses LiNo text into a canonical document. Blank input is the empty document.
parse_document_with_limits
Parses bounded transport text before converting or formatting its document. The upstream grammar enforces depth before building its recursive model.
query_document
Carries the exact original query text, including quoted-reference kinds. Older peers must explicitly support this envelope before a client uses it.
read_any_document
Reads one message in whichever protocol the peer used.

Type Aliases§

Authenticator
The subject of a token, or None when the token is not valid: answers (auth: token).
LinoDocument
A LiNo document: the list of top-level links of a message.
ProtocolResult
Result alias used throughout crate::protocol.
Readable
Which links a subscriber may see: see LinksServer::with_readable.