11 KiB
Migrating to the 1.4 source API
The 1.4 source line is used by Ratspeak 1.0.37. The published standalone command-line download remains 1.3.0; these APIs and migration commands require a matching 1.4 source build.
Messages now retain the exact signed bytes received or finalized for sending.
Verification, storage, and delivery metadata cannot change those bytes. The
message_api and message module paths export the same types.
Construct, sign, then finalize
This fragment uses ? to propagate MessageError from the enclosing function.
use lxmf_core::message_api::{DeliveryMethod, LxMessageDraft};
use rns_crypto::ed25519::Ed25519PrivateKey;
let mut draft = LxMessageDraft::new(
[0x11; 16], [0x22; 16], "Hello", "A message", DeliveryMethod::Direct,
)?;
draft.set_field(0x105_u64, vec![1, 2, 3])?;
// When using a router, prepare and durably commit its reply-ticket intent here.
let signed = draft.sign(&Ed25519PrivateKey::generate())?;
let stamp = signed.generate_recipient_stamp()?;
let message = signed.finalize(stamp)?;
let bytes = message.wire_bytes();
Use sign_with for an external or hardware signer. Both signing methods consume
the draft. Signing refuses a router-prepared ticket whose persistence intent is
still pending. SignedLxMessage exposes the stable message ID for recipient
stamp work, but cannot be sent. finalize(None) explicitly chooses no recipient
stamp. A finalized message has no content setters, signing method, or assignable
hash/signature/stamp. To change content, construct a new draft and explicitly
copy the desired fields; reply tickets and authentication state are not copied
implicitly. Propagation encryption/stamps belong to their separate send owner.
Read the immutable message
| Previous access | Replacement |
|---|---|
message.destination_hash, source_hash |
destination_hash(), source_hash() |
message.hash or message.message_id |
message_id(); always present |
message.signature |
signature(); always present |
message.title, content |
title_text(), content_text() return Cow<str>; *_bytes() preserve exact bytes |
message.timestamp |
timestamp() |
message.fields, msgpack_field_ids |
fields() and coherent FieldValueRef |
message.stamp |
recipient_stamp() |
message.signature_validated |
successful source-bound verify capability |
message.wire_payload |
wire_bytes() for the complete image |
Mutable delivery metadata remains available through MessageMetadata and
field access (message.method, message.progress, etc.). It cannot alter
content or create authentication authority.
wire_bytes() borrows the complete image; wire_owned() cheaply shares its
ownership for asynchronous writes. pack() explicitly copies it into a Vec.
pack_payload() copies the original payload. unpack_owned(Bytes, limits)
takes ownership without copying; unpack(&[u8]) makes a convenience copy.
Container and paper exports preserve these bytes. Repeated verification is pure.
verify(&full_reticulum_public_key) checks that the complete 64-byte public key
binds the claimed lxmf.delivery source, then verifies the signature. It returns
a private-construction VerifiedLxMessage for sender-authorized operations such
as ticket learning. verify_signature(&ed25519_key) remains available for
detached diagnostics, but does not establish source identity. Parsing and an
unknown sender are not authenticated-sender status.
Fields and profiles
FieldId preserves integers from i64::MIN through u64::MAX. Nonnegative IDs
serialize as MessagePack unsigned64; negative IDs as signed64. Equivalent
positive signed and unsigned integer encodings compare equal. Outer duplicate
IDs are rejected, including alternative encodings of the same number. IDs above
255 and negative IDs remain custom keys and never alias a standard field.
set_field emits a binary value. set_msgpack_field accepts exactly one validated
encoded MessagePack value. set_field_value accepts their coherent FieldValue
representation. FieldValueRef::encoded() exposes exact encoded bytes;
as_binary() unwraps only binary. Binary bytes that happen to look like a map
or array do not become structured values. Recognized schema readers can use
unique_map() to reject duplicate integer/text keys before acting; unknown
nested values remain opaque. MessagePayload is a semantic DTO, not an archive
or signature source.
The host default profile permits 4,096 outer fields and 134,217,727 complete
wire bytes. Use new_with_limits and unpack_owned with the same explicit
MessageDecodeLimits when selecting another local policy. Construction checks
count and exact size before signing and finalization, including stamp framing.
These are parser/construction ceilings, not transport promises: Resource segment
limits, metadata, encryption and propagation wrapping impose separate admission
checks. The embedded profile retains 64 fields and depth 8; host-valid custom
messages are not automatically compatible with every device.
Old corrupted files are never silently repaired or re-signed. A hash-shaped filename that disagrees with its decoded message ID returns a distinct error; the file is retained. Restore original bytes from a trusted backup when available. Unknown sender keys cannot establish whether an old signature is valid.
Use the reviewed compatible minor line (for example ~1.4.0) or an exact source
revision when migrating dependents together. A default caret requirement permits
subsequent minor lines. Do not mix dependent code still using mutable messages
with this API.
Router, propagation, and asynchronous ownership
prepare_outbound(&mut draft) returns an OutboundTicketIntent; persist it
through the intended durable state store before signing. A pending intent blocks
the exact draft's signer. submit_signed takes a SignedLxMessage and handles
recipient-stamp work before finalization; defer_stamp and the deferred map also
own signed messages. The former mutable get_stamp work belongs to
SignedLxMessage::generate_recipient_stamp, while frozen-message stamp checks
are read-only and return a result for the current policy.
learn_ticket_from_inbound takes a successful VerifiedLxMessage. When a worker
must retain authentication across an asynchronous handoff, use to_owned() and
later OwnedVerifiedLxMessage::as_verified(). The owned capability shares the
original bytes and does not expose mutable authenticated state.
Replace pack_propagated_encrypted* with PropagationEnvelope in the
propagation_send module. It owns the frozen message, encrypted blob, exact TID
and PN stamp. Reuse that envelope for retries; regenerate only the work whose
policy changed. The old message transient_id and propagation_stamp fields no
longer exist. PendingDelivery.message is a retained delivery owner that can
release payload bytes when an idle Link only needs metadata/receipt state.
Replace take_received_messages with take_downloaded_messages. Keep each
leased image and admission token until validation and durable local commit;
resolve the token with the explicit disposition and durable receipt. A fetched
message or Resource proof is not permission to purge remote data.
Hosted propagation accepts a validated opaque encrypted/stamped blob through
ValidatedOpaquePropagationBlob and plan_opaque_admission, followed by the
plan's durable persistence and exact commit. Plain accept_message,
accept_propagated_blob, their old planning variants and sync plaintext
admission are removed: plaintext signatures are not relay storage authority.
Use a durable node store and follow the relay store migration.
A nondurable PropagationNode::new cannot acknowledge relay storage.
Hosted /get handlers must use the bounded deferred request API in
rns_runtime::LinkManager, after installing its exact endpoint dispatch handle.
Check the handler registration result. Retain DeferredRequestResponder inside
the actual blocking worker through store planning, durable purge and verified
file reads; cancellation of an async caller must not detach uncharged I/O.
Pass response_byte_limit() to both handle_get_request_bounded and
into_response_with_served_count_bounded, using the configured propagation
transfer ceiling when registering the handler. These methods reject malformed
requests before purge, deduplicate wants, preserve complete-message accounting
and build one bounded response. An absent client limit still obeys the local
ceiling. The runtime fences responses to the original Link generation and keeps
Resource credits until the transfer releases its data. Sent acknowledges
queue acceptance or Resource initiation, not remote delivery.
unpack_propagation_wrapper_owned(Bytes, limit) returns shared Bytes payloads
and checks framing/counts before allocation. The Vec-returning compatibility
helper still copies explicitly. FieldValueRef::from_encoded validates exactly
one borrowed value, and as_text accepts UTF8 MessagePack text only; binary data
is not silently interpreted. Use unique_map before acting on recognized map
keys. Text/media projections borrow where possible; repaired UTF8 allocates only
the exact replacement length.
constants::ENCRYPTED_PACKET_MAX_CONTENT is LXMF 1.2.0's single-packet
content limit, 287 bytes, which LxmRouter::try_send applies to opportunistic
messages. Applications that choose a delivery method themselves should compare
against it rather than a hard-coded limit.
Resuming a signed message
SignedLxMessage::to_resumable() returns a ResumableLxMessage to store before
submit_signed; as_bytes() and ResumableLxMessage::from_bytes move it
through storage. It keeps the signed, unstamped message and the stamp cost it
was signed under. It is not a wire message, and LxMessage::unpack rejects it.
After a restart, LxmRouter::restore_signed(&stored, &active_public_key, method) verifies the message as sent by the active identity, so no signing key
is needed. It attaches the current outbound ticket and uses the larger of the
stored and current stamp costs. Set delivery metadata such as auto_compress,
then call submit_signed. The message keeps its id, so recipients deduplicate a
copy that was already delivered.
submit_signed now refuses a message whose id is already queued, awaiting its
stamp or delivery, with MessageError::AlreadyQueued. Treat that result as
already queued; it is not evidence of transmission or recipient delivery.
Retaining delivered destinations
LxmRouter::take_destination_retains() returns the destinations whose messages
were delivered since the last call; the router keeps the newest 256. Send each
as TransportQuery::RetainDestination through Reticulum's control plane
(ReticulumHandle::query_control), which forwards to a shared instance, so the
destination's identity outlives its path, as in Python LXMF.
The API ledger retains its original compatibility floor and lists exact removed
rendered lines. Metadata fields moved under MessageMetadata retain ordinary
field access through Deref; duplicate message_api snapshot paths describe the
same type migration. No unrelated API removal is waived.