[package] name = "cotton-client" version = "0.1.0" edition.workspace = true license.workspace = true publish.workspace = true description = "CottonDB's client half: the data directory, the device identity's use, the connection — everything the Mac (and one day Android) runs against a server." [lib] name = "cotton_client" path = "src/lib.rs" # One pass of the lane ledger, for the claims sweep. [[bin]] name = "cotton-photos-measure" path = "src/bin/cotton-photos-measure.rs" required-features = ["ingest"] [[bin]] name = "cotton-ledger" path = "src/bin/cotton-ledger.rs" required-features = ["host"] # WHAT A PHONE LINKS, AND WHAT ONLY A HOST DOES (design P2). # # `default = ["host"]` keeps every existing caller — the Mac, the tests, the # workspace's own `cargo test` — exactly as it was. The PHONE builds this crate # with `--no-default-features`, and what it gets is the client half a phone has # always been: `data_dir`, `identity`, `layout`, `replica`, `media`, `seams`, # `sync`, `connection` and `transport`. Nothing else compiles at all, so a # server-shaped dependency cannot arrive by accident. # # The point is not tidiness. Without this, an iPhone app links `x25519-dalek`, # `axum` and a CI runner's supervisor to write a todo. [features] default = ["host"] # Reuse the signed HTTP script from dependent crates' synthetic guards only. test-fixtures = [] # Everything a machine that HOSTS the database does and a phone never will. host = ["ingest", "ci"] # The lane ledger (`src/ci/`) the `cotton-ledger` pass runs; it reads this # Mac's disk and processes through the session host's `machine` and # `processes` modules. ci = ["dep:cotton-session-host"] # Reading the call history and the Photos library off this Mac, and the linked # WhatsApp device. No dependency of its own — it is SQLite over files the OS # put there — but it is a host capability by meaning: an iPhone has no # `~/Library` to read. ingest = [] [dependencies] zeroize = "1" tracing.workspace = true # The file format: the replica IS a store file, and the outbox, the `_media` # ledger and the fold are the store's own — this crate holds the SCHEDULE # around them and no second opinion about what a push means. cotton-store = { path = "../cotton-store" } # The row decisions every source depends on: `import::whatsapp_keys` keys a # WhatsApp conversation, and `messages::resolve_contact` is what turns a number # into somebody the file already knows. cotton-core = { path = "../cotton-core" } # The device row, which is a row of the person's own database and is written # through the tool surface's `Writer` like every other replicated row. A phone # that starts a database alone writes the first one (`start.rs`), and the phone # links `cotton-tools` already — this edge brings no crate into the graph that # was not in it (`cotton-ffi/tests/phone_boundary.rs`). cotton-tools = { path = "../cotton-tools" } serde.workspace = true serde_json.workspace = true thiserror.workspace = true # `_media.local_path` is the ONE absolute path a data directory persists, so a # move rewrites it — one UPDATE per replica, before anything opens one. rusqlite.workspace = true # The snapshot comes down gzipped and is INFLATED AS IT IS WRITTEN — never a # buffer, never whole. Pure Rust (`rust_backend`), because the phone links this. flate2.workspace = true # The device key the server admits. The KEY MATERIAL is the Keychain's (design # M8) and arrives here from Swift; the signing is this crate's. ed25519-dalek.workspace = true base64.workspace = true # Minting a device seed for a REHEARSAL data directory. The packaged app never # reaches this: its seed comes from the Keychain, minted by Swift (design M8). rand.workspace = true # The sync loop and the media drain are tokio tasks with a `Notify` wake and an # interval underneath it — a command that returns immediately and reports # through events (design M2), never a blocking call across the boundary. tokio.workspace = true # The client media store is content-addressed: a file's name IS its sha256, # streamed at a 1 MB high-water mark and never buffered whole. sha2.workspace = true # ONE CALL: `statvfs`, for the replicator's disk floor # (`media::hydrate::free_bytes_at`). There is no free-space reading in Rust's # standard library and this is the smallest thing that has one — already in the # lock file, linked by everything below us, and reached from a single `unsafe` # block that a `#[cfg(not(unix))]` twin answers `None` for. libc = "0.2" hex.workspace = true # The clock the sync loop, the ledger and every stamped row read. Injected — # `Clock` is the trait, `SystemClock` the one a running app uses. chrono = { version = "0.4", default-features = false, features = ["std", "clock", "alloc"] } # WHATWG URL semantics for the one place they are load-bearing: the `path` # field a device signs is `URL.pathname + URL.search` as the SERVER reads it # back, so `/v1/../x` is `/x` and a non-ASCII segment is percent-encoded. # `cotton-core::device::signature::signed_path` is the function; this is its # dependency, declared here because this crate calls it with URLs it builds. url.workspace = true # ── THE WIRE (design P14b, 4b) ────────────────────────────────────────────── # # WHY THERE IS NO HTTP CLIENT CRATE HERE. `reqwest` is banned from the phone # graph (`cotton-ffi/tests/phone_boundary.rs`) because it is on this tree only # for APNs' http2; `ureq` and its cousins bring their own TLS stack, a root # bundle and a second opinion about timeouts. What this client needs is # smaller than any of them and sharper in two places: a socket read timeout # that IS `SNAPSHOT_STALL_MS` (a whole-body timeout is the wrong shape for a # 400 MB file on a slow link) and a request ceiling that is the socket's, not a # future's. So `transport::http1` writes the request and reads the head with # `httparse` — the same parser `tungstenite` already uses one layer up — and # the body is a `Read` over the socket. # # Both are declared NON-OPTIONAL: `remote` mode is the client half's, and a Mac # connected to another Mac signs and dials exactly as a phone does. httparse = "1" # The live channel. The BLOCKING client, not `tokio-tungstenite` (which is # banned from the phone graph and is the tunnel's, with rustls under it): this # crate's transports are blocking by design — see `transport`'s module note — # and a WebSocket over a `TcpStream` this crate already dialled is the same # shape as the request above it. tungstenite = { version = "0.29", default-features = false, features = ["handshake"] } # ── OPTIONAL, and every one of them is `host` only (design P2) ────────────── # # These are host capabilities. Non-Apple clients also use rustls itself for # outbound TLS; the target dependency below enables only that library. # The session host's machine and process readings, for the lane ledger. cotton-session-host = { path = "../cotton-session-host", optional = true } tempfile.workspace = true [dev-dependencies] serde_yaml.workspace = true # `cotton_tools::test_fixtures`: receipts for the rows a test seeds. cotton-tools = { path = "../cotton-tools", features = ["test-fixtures"] } rcgen = { version = "0.13", default-features = false, features = ["pem", "ring"] } time = { version = "0.3", default-features = false, features = ["std"] } # Turns on `cotton_store::test_template`: this crate's tests get their workspace # file for the price of a copy. And `fixtures`: the in-memory device keys a # test's replicas and servers sign with (`signed::KeySigner`). Dev-only — a # phone build never compiles either. cotton-store = { path = "../cotton-store", features = ["test-template", "fixtures"] } serde_json.workspace = true chrono = { version = "0.4", default-features = false, features = ["std", "clock", "alloc"] } # `test-util` for `#[tokio::test(start_paused = true)]`, and DEV ONLY: the CI # runner's registration is bounded by a sixty-second timeout, and a suite that # proved it by waiting sixty seconds would be a suite nobody runs. Paused time # means the test's clock is the test's own, which is the same rule as # `FixedClock` one layer down. tokio = { workspace = true, features = ["test-util"] } # NOTE the position: a `[target.…]` table ends the `[dependencies]` table above it, # so it comes LAST — every optional host dependency it once sat above was silently # Apple-only and the Linux `rust` job built the host with no crates (#422). # Apple keeps Security.framework and the platform trust store. Non-Apple # clients use rustls with bundled Mozilla roots: no OpenSSL installation or # Android JVM initialization is needed before the shared core can dial HTTPS. [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] native-tls = "0.2" [target.'cfg(not(any(target_os = "ios", target_os = "macos")))'.dependencies] rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12", "logging"] } webpki-roots = "1"