Skip to main content

Module ninep_bridge

Module ninep_bridge 

Source
Expand description

Shared sync→async bridge for 9P-style Mount implementations that proxy to a Cap’n Proto RPC service (nine.capnp envelope).

Both RemoteModelMount (1-level scope: first path component = model ref) and RemoteRegistryMount (2-level scope: repo → worktree, with async UUID resolution) translate synchronous VFS Mount trait calls into async RPC requests by embedding a dedicated single-threaded tokio runtime and block_on-ing each op. The runtime, the local-fid allocator, the DashMap<u32, S> that tracks remote fid state, the anyhow → MountError mapping, the opaque RemoteFidKey newtype stored in Fid, and the packed 9P stat parser used for directory reads are identical across the two mounts — only the RPC client type, the scope extraction, and which RPC method names / directory byte format differ.

This module factors out the shared pieces:

  • NinePBridge<S> — owns the runtime + fid map + fid allocator. Each mount holds one of these and supplies its own fid-state type S.
  • map_err — anyhow::Error → MountError classification.
  • RemoteFidKey — the opaque newtype stored inside hyprstream_vfs::Fid.
  • parse_dir_stats — decode packed 9P stat entries from a directory read() response (the format the model service’s SyntheticTree emits).

What stays mount-specific:

  • the top-level Mount impl (walk’s scope extraction differs: 1-level vs 2-level with async get_by_name resolution),
  • the request-struct construction (each generated client module has its own NpWalk/NpOpen/… types),
  • the stat RPC method name (stat on ModelFsClient, np_stat on WorktreeClient),
  • the directory-entry byte format (packed 9P stats for the model service vs name_len+name+is_dir+size for the registry worktree service).

Structs§

NinePBridge
Shared sync→async bridge plumbing for a 9P Mount proxying to a Cap’n Proto RPC service.
RemoteFidKey
Newtype stored inside the opaque hyprstream_vfs::Fid.

Functions§

fid_key
Downcast the opaque Fid to its RemoteFidKey, returning MountError::InvalidArgument on a type mismatch. All Mount ops start with this. Free-standing so callers don’t need to name the bridge’s fid-state type parameter.
map_err
Classify an anyhow::Error (as surfaced by the generated RPC clients) into a MountError by string-matching the common 9P / filesystem error phrases. Identical for every backing service. Free-standing so callers don’t need to name the bridge’s fid-state type parameter.
parse_dir_stats
Parse packed 9P stat entries from a directory read() response.