Expand description
Where pairing records live.
A pairing record is the long-term key the client keeps for a server it has paired with, and the
pairing PSK is the key that admits the client to the pairing activity in the first place. Both
belong to the host: it owns the file, its permissions, its backups and its lifetime. Storage
is the whole surface the client needs, and a host that has no store configures none - the client
then does not pair at all, and a plain guest session is unchanged.
§Order and eviction
Storage::load_pairings returns records oldest first, and a store the client writes keeps at
most MAX_PAIRINGS. persist_pairing drops the first record that does not back the live
connection, so eviction follows the order the store returns. That order is insertion order, not
use order: a record only moves to the end when it is stored again, and the client does that
after a completed pairing, not when it selects a record. A record kept since long ago can
therefore be evicted before one used recently.
§Capacity
A store the client writes keeps at most MAX_PAIRINGS records. The floor is five and it is a
floor, not a ceiling on what a host may hand back: a store the crate reads but did not write may
hold more, and the client uses it as it is. The client never evicts the record backing the live
connection, because losing it would drop the peer it is talking to.
The rules are enforced by persist_pairing, not by a backend: a host implements the four
primitive operations of Storage and the crate does the ordering, the capacity and the
live-record pin on top of them. A pairing therefore never fails for lack of space, whichever
store the host chose. Calling Storage::store_pairing directly skips the live-record pin;
FileStorage trims to the floor as a safety net, a host backend may not trim at all, and neither
can know which connection is live. A host that writes a record itself calls persist_pairing
rather than reimplementing either rule.
§File backend
FileStorage implements the trait over one JSON file and is available with the
storage-file feature. It writes a temporary file in the same directory and renames it over the
store, so a crash leaves either the old store or the new one; it creates its file with mode
0600 on Unix; and it refuses a file whose shape it does not recognise instead of rewriting it.
No key, encoded or raw, appears in its Debug output or in an error.
Structs§
- File
Storage - A pairing store in one JSON file, behind the
storage-filefeature.
Constants§
- MAX_
PAIRINGS - Most pairing records the client keeps in a store.
Traits§
- Storage
- The place pairing records and the pairing PSK live.
Functions§
- evict
- Drops the oldest record that is not
livewhenrecordsholds more thanMAX_PAIRINGS. - persist_
pairing - Stores
recordunder the record rules: newest at the end, at mostMAX_PAIRINGS, never the record backing the live connection.