2. Textile Host Stores (fleetmesh_protocols.textile)#

fleetmesh_protocols.textile implements the host-side components of the Textile data plane: a content-addressed fiber store and quilt store with mountable HTTP route handlers (/api/fibers*, /api/quilts*), together with the hosted leaf relay that serves NIP-77 negentropy synchronization and DIDComm mediation to browser leaves. Its browser counterpart is @fleetmesh/textile.

2.1. Key Derivation#

HostedLeafRelay derives its cryptographic keys from FLEETMESH_LEAF_RELAY_SECRET or, when that variable is unset, from the engine’s node key. Initialization fails if neither key source is available. Because leaves cache the mediator’s descriptor, changing the secret rotates the keys to which leaves seal envelopes.

2.2. Fiber Store#

Content-addressed Fiber Store (node.protocols.textile.fiber_store).

Every fiber’s bytes are stored once, keyed by their 1,024-byte-leaf Bao root (fiber_root). Each author who publishes those bytes holds a claim recording the fiber’s kind, MIME type, visibility and (for interaction fibers) the strand it points at.

class fleetmesh_protocols.textile.fiber_store.StandaloneFiberStore[source]#

Bases: object

Thread-safe fiber blobs + per-author claims, persisted to SQLite (or held in memory).

__init__(db_path=None)[source]#
Parameters:

db_path (str | None)

Return type:

None

has_fiber(root)[source]#
Parameters:

root (str)

Return type:

bool

readable(root, principal=None)[source]#
Parameters:
Return type:

bool

manifest(root, principal=None)[source]#
Parameters:
Return type:

MutableMapping[str, Any] | None

get(root, principal=None)[source]#
Parameters:
Return type:

Tuple[bytes, MutableMapping[str, Any]] | None

get_blob_slice_by_root(root, offset, length)[source]#
Parameters:
Return type:

bytes | None

list_own(principal)[source]#
Parameters:

principal (Mapping[str, Any] | None)

Return type:

List[MutableMapping[str, Any]]

owner_bytes(principal)[source]#
Parameters:

principal (Mapping[str, Any] | None)

Return type:

int

interaction_counts(target_strand_id)[source]#
Parameters:

target_strand_id (str)

Return type:

Dict[str, int]

put(raw, principal, *, kind, mime_type='', visibility='vault_only', target_strand_id='', enforce_quota=True)[source]#
Parameters:
Return type:

MutableMapping[str, Any]

set_visibility(root, principal, visibility)[source]#
Parameters:
Return type:

MutableMapping[str, Any]

release(root, principal)[source]#
Parameters:
Return type:

bool

/api/fibers* HTTP routing for StandaloneFiberStore (node.protocols.textile.fiber_routes).

  • GET /api/fibers the caller’s own fiber manifests

  • GET /api/fibers/<root> bytes as an opaque download (?format=json for base64 + manifest)

  • GET /api/fibers/<root>/manifest manifest only

  • GET /api/fibers/interactions?target=<strand_id> public interaction counts by kind

  • POST /api/fibers {data_b64, kind, mime_type?, visibility?, target_strand_id?}

  • POST /api/fibers/visibility {fiber_root, visibility} on the caller’s claim

  • POST /api/fibers/release {fiber_root} drops the caller’s claim

Unreadable and missing fibers both answer 404.

fleetmesh_protocols.textile.fiber_routes.binary_http_response(raw, *, bao_root, sha256_hex, mime_type, public, filename, as_json, json_extra=None)[source]#

Serve stored bytes so they can never render as a page on the app’s origin.

Parameters:
Return type:

Tuple[int, Any, str, Dict[str, str]]

fleetmesh_protocols.textile.fiber_routes.is_fiber_route(route)[source]#
Parameters:

route (str)

Return type:

bool

fleetmesh_protocols.textile.fiber_routes.handle_fiber_http(store, method, route, query='', body=None, principal=None, *, range_header='')[source]#

Route /api/fibers*. principal must come from the server’s own session resolution.

Parameters:
Return type:

Tuple[int, Any, str, Dict[str, str]] | None

2.3. Quilt Store#

Quilt store: per-owner quilt views for cross-device sync and channel pages (node.protocols.textile.quilt_store).

fleetmesh_protocols.textile.quilt_store.compute_fabric_root(fabric, snapshot)[source]#
Parameters:
Return type:

str

fleetmesh_protocols.textile.quilt_store.compute_quilt_root(quilt)[source]#
Parameters:

quilt (Mapping[str, Any])

Return type:

str

fleetmesh_protocols.textile.quilt_store.validate_quilt_view(view, principal, *, owner_ref=None)[source]#

Problems with a published view (empty when it may be stored).

Parameters:
Return type:

List[str]

fleetmesh_protocols.textile.quilt_store.group_owner_id(circle_id)[source]#

A circle’s identity as a quilt owner: its own namespace, apart from user identity ids.

Parameters:

circle_id (str)

Return type:

str

class fleetmesh_protocols.textile.quilt_store.StandaloneQuiltStore[source]#

Bases: object

Latest quilt view per (owner, audience), persisted to SQLite (or held in memory).

__init__(db_path=None, keyring=None)[source]#
Parameters:
  • db_path (str | None)

  • keyring (Any)

Return type:

None

add_alias(ref, owner_key)[source]#
Parameters:
Return type:

None

publish(views, principal)[source]#
Parameters:
Return type:

List[str]

publish_group(circle, view, principal)[source]#
Parameters:
Return type:

str

get_group_view(circle_id, audience, is_member)[source]#
Parameters:
Return type:

MutableMapping[str, Any] | None

get_view(owner_ref, audience, principal=None)[source]#
Parameters:
Return type:

MutableMapping[str, Any] | None

/api/quilts* HTTP routing for StandaloneQuiltStore (node.protocols.textile.quilt_routes).

  • POST /api/quilts {views: [MeshQuiltView…]} publishes the caller’s quilt views

  • GET /api/quilts/me?audience=self the caller’s own view (cross-device sync)

  • GET /api/quilts/<identity_id|did> an owner’s public view (channel pages)

  • POST /api/quilts/group {circle_id, view} a member publishes their circle’s quilt view

  • GET /api/quilts/group/<circle_id>?audience=circle|public a circle’s view (circle for members)

GET answers {ok: true, view: null} when there is no view the caller may read.

fleetmesh_protocols.textile.quilt_routes.is_quilt_route(route)[source]#
Parameters:

route (str)

Return type:

bool

fleetmesh_protocols.textile.quilt_routes.handle_quilt_http(store, method, route, query='', body=None, principal=None, circle_access=None)[source]#

circle_access(circle_id, principal) gives (circle, is_member).

Parameters:
Return type:

Tuple[int, Any, str, Dict[str, str]] | None

2.4. Hosted Leaf Relay#

FleetMesh Hosted Leaf Relay & Mediator (node.protocols.textile.hosted_relay).

Hosts an embedded Nostr/Fleetmesh Leaf Relay & Mediator, advertising a signed kind 11801 descriptor, mediating DIDComm v2 envelopes (coordinate-mediation/2.0, routing/2.0, messagepickup/2.0 & 3.0), and indexing the 4-layer Textile hierarchy (Fibers -> Strands -> Fabrics -> Quilts).

class fleetmesh_protocols.textile.hosted_relay.HostedLeafRelay[source]#

Bases: object

Embedded Leaf Relay, DIDComm v2 Mediator, and Textile Negentropy Engine.

MAX_EVENTS: int = 10000#
MAX_NEG_SESSIONS: int = 256#
MAX_DESCRIPTORS: int = 10000#
__init__(engine, default_domain='fleetmesh.org')[source]#
Parameters:
  • engine (Any)

  • default_domain (str)

Return type:

None

default_endpoint()[source]#
Return type:

str

build_mediator_descriptor(endpoint=None, now=None)[source]#
Parameters:
  • endpoint (str | None)

  • now (int | None)

Return type:

MutableMapping[str, Any]

get_mediator_config(endpoint_override=None)[source]#
Parameters:

endpoint_override (str | None)

Return type:

MutableMapping[str, Any]

release_owner(leaf_did, owner_did)[source]#

A leaf no longer picks up for an owner it has moved away from.

Parameters:
  • leaf_did (str)

  • owner_did (str)

Return type:

None

register_leaf_binding(leaf_did, agreement_pk_hex, owner_did='')[source]#
Parameters:
  • leaf_did (str)

  • agreement_pk_hex (str)

  • owner_did (str)

Return type:

None

collect_textile_inventory(scope='all')[source]#
Parameters:

scope (str)

Return type:

MutableMapping[str, Any]

process_frame(frame, sub_map=None, is_http=True)[source]#
Parameters:
Return type:

list[list[Any]]

handle_http_frames(body)[source]#
Parameters:

body (Any)

Return type:

MutableMapping[str, Any]

get_nip11_info(endpoint_override=None)[source]#
Parameters:

endpoint_override (str | None)

Return type:

MutableMapping[str, Any]

handle_websocket_upgrade(handler)[source]#
Parameters:

handler (Any)

Return type:

bool

Hosted Leaf Relay Inventory & RFC 6455 WebSocket Transport (node.protocols.textile.leaf_relay).

fleetmesh_protocols.textile.leaf_relay.det_hex(seed)[source]#

SHA-256 hex of seed: how hosted relays derive their keys and synthetic inventory ids.

Not canonical_bao_hex (a Bao leaf hash, sha256(0x00 || seed)): deployed mediators derived their agreement, transport and operator keys with plain SHA-256, and leaves cache the descriptor carrying those keys, so a different derivation silently rotates every hosted mediator’s keys.

Parameters:

seed (str)

Return type:

str

fleetmesh_protocols.textile.leaf_relay.canonical_bao_hex(seed)[source]#
Parameters:

seed (str)

Return type:

str

fleetmesh_protocols.textile.leaf_relay.encode_varint(n)[source]#
Parameters:

n (int)

Return type:

bytes

fleetmesh_protocols.textile.leaf_relay.decode_varint(buf, i)[source]#
Parameters:
Return type:

tuple[int, int]

fleetmesh_protocols.textile.leaf_relay.neg_fingerprint(items)#

NIP-77’s, over the ids in order-independent fashion. fleetmesh_core/storage/replication.py owns the algorithm; this exists so the caller reads in terms of items.

Parameters:

items (Sequence[tuple[int, str]])

Return type:

bytes

fleetmesh_protocols.textile.leaf_relay.NegBound#

alias of Bound

fleetmesh_protocols.textile.leaf_relay.encode_neg_message(ranges)#

ranges: [(upper Bound, mode, payload)] in ascending order.

Parameters:

ranges (Sequence[tuple[Bound, int, Any]])

Return type:

bytes

fleetmesh_protocols.textile.leaf_relay.decode_neg_message(buf)#

Bytes to ranges, or an exception. Never a partial parse.

A message arrives from a peer that has proved nothing yet, so this rejects rather than repairs. The reference implementation makes the same choices, and where it normalises instead of rejecting - a bound after infinity - so does this, because two implementations that read the same bytes differently is the failure this whole module exists to avoid.

Parameters:

buf (bytes)

Return type:

list[tuple[Bound, int, Any]]

class fleetmesh_protocols.textile.leaf_relay.NegentropyServer[source]#

Bases: object

Server-side NIP-77 Negentropy V1 reconciler.

__init__(items)[source]#
Parameters:

items (Iterable[tuple[int, str]])

Return type:

None

reconcile(message)[source]#
Parameters:

message (bytes)

Return type:

bytes | None

fleetmesh_protocols.textile.leaf_relay.build_engine_textile_inventory(engine, node_pk, descriptors_map, verify_event_fn=<function <lambda>>)[source]#

Collect the 8-layer Textile inventory (Fibers, Strands, Fabrics, Quilts, Spools, Chunks, Suits, Fits).

Parameters:
Return type:

MutableMapping[str, Any]

fleetmesh_protocols.textile.leaf_relay.serve_relay_websocket(handler, ws_subs, lock, process_frame)[source]#

RFC 6455 WebSocket upgrade and frame loop for HostedLeafRelay.

Parameters:
Return type:

bool