Skip to main content

hyprstream_9p/
lib.rs

1//! 9P2000.L codec and server-side translator for hyprstream.
2//!
3//! Two halves:
4//!
5//! - **Codec** ([`msg`]): the full 9P2000.L wire format. `read_from` / `write_to`
6//!   style helpers for *both* client and server sides — T-message parsers +
7//!   R-message encoders live alongside the original client-side encoders +
8//!   R-message parsers.
9//!
10//! - **Translator** ([`translator`]): a server that accepts 9P connections
11//!   (TCP transport now; virtio-9P later), maintains a server-side fid table,
12//!   and translates each T-message into a [`backend::Backend`] call. The
13//!   backend is the capnp-RPC seam: the `hyprstream` binary crate ships a
14//!   `ModelBackend` that turns each call into a `nine.capnp` envelope against
15//!   the model service's `fs` scope — the inverse of `RemoteModelMount`
16//!   (VFS → RPC).
17//!
18//! ## Client side
19//!
20//! [`client`] is the transport-agnostic 9P2000.L client ([`client::P9Client`]),
21//! driven by a [`client::P9Transport`]. Two transports back it:
22//!
23//! - **wasm** ([`dma`], [`wanix_mount`]) — SharedArrayBuffer DMA ring to a
24//!   browser Wanix server; single-threaded, so [`wanix_mount::WanixMount`] uses
25//!   `unsafe impl Send/Sync`.
26//! - **native** ([`socket_transport`], [`remote_mount`]) — a real Unix/TCP
27//!   socket ([`socket_transport::SocketTransport`]) exposed as a genuinely
28//!   `Send + Sync` VFS [`Mount`](hyprstream_vfs::Mount)
29//!   ([`remote_mount::Remote9pMount`]). This is the client half of #708: dial a
30//!   remote 9P server and import its tree into the host namespace. It is the
31//!   exact inverse of [`mount_backend::MountBackend`] (Mount → 9P server) and
32//!   shares the same [`client::P9Transport`] / [`msg`] wire core, so a future
33//!   9P-over-WebSocket server reuses the same seam.
34//!
35//! The wasm `WanixMount` and native `Remote9pMount` are deliberately *separate*
36//! types rather than one renamed generic: they have incompatible `Send`/`Sync`
37//! stories (wasm's `unsafe impl` is only sound single-threaded, native is
38//! genuinely thread-safe) and are gated to disjoint targets.
39
40#[cfg(not(target_arch = "wasm32"))]
41pub mod backend;
42pub mod client;
43#[cfg(not(target_arch = "wasm32"))]
44pub mod memory;
45pub mod msg;
46// The translator is the server-side TCP/UDS accept loop (tokio::net). `net`
47// pulls `mio`, which has no wasm32 backend, so these modules are native-only.
48// The browser/wasm build reaches the backend through the DMA/Wanix client path.
49#[cfg(not(target_arch = "wasm32"))]
50pub mod translator;
51// 9P reference-monitor contract (S2 / #568): attach-time token verification,
52// optional full token/IFC composition, and the mandatory per-op access-decider
53// seam. Native-only alongside `translator`, its only consumer today.
54#[cfg(not(target_arch = "wasm32"))]
55pub mod mac_seam;
56// `MountBackend` bridges a VFS `Mount` (+ `Subject`) to the `Backend` seam so
57// the translator can export it over TCP/UDS. Native-only (drives async Mount ops).
58#[cfg(not(target_arch = "wasm32"))]
59pub mod mount_backend;
60// The socket 9P *client* Mount (import a remote 9P namespace over UDS/TCP). Uses
61// `tokio::net`, so native-only — the wasm build imports via the DMA/Wanix path.
62#[cfg(not(target_arch = "wasm32"))]
63pub mod remote_mount;
64#[cfg(not(target_arch = "wasm32"))]
65pub mod socket_transport;
66
67#[cfg(target_arch = "wasm32")]
68pub mod dma;
69#[cfg(target_arch = "wasm32")]
70pub mod wanix_mount;
71
72#[cfg(not(target_arch = "wasm32"))]
73pub use backend::{Backend, OpenResult, StatResult, WalkResult};
74pub use client::{P9Client, P9Transport};
75#[cfg(not(target_arch = "wasm32"))]
76pub use mac_seam::{
77    anonymous_floor, AccessDecider, Action, AnonymousAuthenticator, AttachAuthenticator,
78    DenyAllDecider, DenyUnlabeledResolver, ObjectLabelResolver, ObjectRef, ReferenceMonitor,
79    ReferenceMonitorDenyReason, SessionContext, VerifiedAttach, VerifiedAttachIdentity,
80    VerifiedTokenScope,
81};
82#[cfg(not(target_arch = "wasm32"))]
83pub use mount_backend::{AttachAuthorizer, MountBackend};
84#[cfg(not(target_arch = "wasm32"))]
85pub use remote_mount::Remote9pMount;
86#[cfg(not(target_arch = "wasm32"))]
87pub use socket_transport::SocketTransport;
88#[cfg(not(target_arch = "wasm32"))]
89pub use translator::{
90    serve_mount_uds, serve_mount_vsock, serve_mount_vsock_raw, FidTable, Translator,
91};