fix(sdk): surface Sent/Queued on send(), and build the SDK in CI

Node::send() became Result<OutboxStatus, String> in the local-outbox work,
which broke crates/onionwire-sdk — and nothing noticed, because the SDK is a
separate cargo workspace that root CI never compiles.

- Wire::send() returns WResult<SendState> (Sent | Queued)
- ChatMessage.delivery for outgoing rows
- New sdk job in ci.yml (own target volume; rustls workspace)
- Refresh SDK Cargo.lock + README (SQLCipher / outbox facts)

Rebased onto main after #50/#54: no src/node.rs changes (WAL checkpoint lives
in Store now). README at-rest claims kept from #55.
This commit is contained in:
agent 2026-09-12 18:16:21 -04:00
commit e30c9f1699
No known key found for this signature in database
5 changed files with 208 additions and 28 deletions

View file

@ -11,7 +11,10 @@
//! the friend.
//! * Transport is in-process Arti. There is no `tor` binary, no torrc, no
//! Orbot pipe. If the onion service cannot publish, this fails closed.
//! * Chat bodies are encrypted at rest. Identity keys in sqlite are not.
//! * Chat bodies are encrypted at rest, and the whole sqlite file is
//! SQLCipher on top of that (see the root crate).
//! * A chat send that cannot reach the peer's onion is queued in a local
//! outbox and retried — see [`SendState`]. Nothing leaves the device.
//!
//! Lifecycle: a node is started by [`open_wire`] and stopped by
//! [`Wire::shutdown`]. Between those, [`Wire::tor_state`] is the observable
@ -27,7 +30,7 @@ use std::sync::{Arc, Mutex, OnceLock};
use onionwire::hs::TorState as CoreTorState;
use onionwire::node::{FlushOutcome as CoreFlushOutcome, Node};
use onionwire::qr;
use onionwire::outbox::OutboxStatus;use onionwire::qr;
uniffi::setup_scaffolding!();
@ -98,11 +101,34 @@ pub struct FriendInfo {
pub last_connect_ok: bool,
}
/// What `send()` did with the message.
///
/// The core has a local outbox: when a friend's onion is unreachable the
/// message is written to the local sqlite store and a background worker
/// retries it with backoff. Nothing is handed to a third party — every attempt
/// is a fresh handshake straight to that friend's onion — but until a circuit
/// takes it the message exists only on this device. A consumer must not render
/// `Queued` as delivered.
#[derive(Debug, Clone, Copy, PartialEq, Eq, uniffi::Enum)]
pub enum SendState {
/// The frame reached the peer's onion service during this call.
Sent,
/// The peer's onion was unreachable: the message is in the local outbox,
/// local-only until the retry worker delivers it (or it ends `Failed`).
Queued,
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct ChatMessage {
/// "in" or "out".
pub direction: String,
pub body: String,
/// Outgoing messages only: `"sent"`, `"queued"`, `"sending"` or
/// `"failed: <reason>"`. `None` for incoming messages. An outgoing row with
/// no outbox row is one the peer accepted on the first attempt, so it reads
/// `"sent"` — never treat a missing value as "delivered" on the app side,
/// read this field.
pub delivery: Option<String>,
}
#[derive(Debug, Clone, uniffi::Record)]
@ -332,34 +358,44 @@ impl Wire {
.map_err(WireError::new)
}
/// Send one message. Returns once the outcome is known: delivered now, or
/// queued for retry because the peer's onion is unreachable. A protocol
/// error (bad signature, bad frame) still fails immediately and is never
/// queued. Use [`flush`](Self::flush) to retry the queue on demand.
pub async fn send(&self, pubkey_hex: String, body: String) -> WResult<()> {
/// Send one chat message.
///
/// Returns [`SendState::Sent`] when the frame reached the peer's onion
/// service during this call, and [`SendState::Queued`] when it did not: the
/// message is then in the local outbox and a background worker retries it
/// with exponential backoff (30s doubling, capped at 30 min, 8 attempts)
/// until it lands or ends terminally failed. A queued send is local-only —
/// show it as pending, not delivered.
///
/// A protocol error (signature mismatch, malformed or oversize frame) is
/// not retryable and still fails here; nothing is queued in that case.
pub async fn send(&self, pubkey_hex: String, body: String) -> WResult<SendState> {
let pk = unhex(&pubkey_hex)?;
self.node()?
let status = self
.node()?
.send(&pk, body.as_bytes())
.await
.map_err(WireError::new)?;
Ok(())
}
Ok(send_state(status)) }
/// Chat history for a friend, oldest first. Bodies are decrypted here;
/// they are stored encrypted at rest.
/// they are stored encrypted at rest. Outgoing rows carry their delivery
/// state in [`ChatMessage::delivery`].
pub async fn messages(&self, pubkey_hex: String) -> WResult<Vec<ChatMessage>> {
let pk = unhex(&pubkey_hex)?;
let rows = self
.node()?
.list_messages(&pk)
.map_err(WireError::new)?;
Ok(rows
.into_iter()
.map(|m| ChatMessage {
let rows = self.node()?.list_messages(&pk).map_err(WireError::new)?;
let mut out = Vec::with_capacity(rows.len());
for m in rows {
let status = self
.node()?
.outbox_status_of_message(m.id)
.map_err(WireError::new)?;
out.push(ChatMessage { body: String::from_utf8_lossy(&m.plaintext).into_owned(),
delivery: delivery_of(&m.dir, status),
direction: m.dir,
body: String::from_utf8_lossy(&m.plaintext).into_owned(),
})
.collect())
});
}
Ok(out)
}
/// Delete every message body. Identity and friends survive.
@ -415,6 +451,30 @@ fn unhex(s: &str) -> WResult<Vec<u8>> {
.collect()
}
/// `Node::send` only ever yields `Sent` or `Queued`; `Sending`/`Failed` exist
/// only on stored outbox rows. Everything that is not a completed send maps to
/// `Queued`, so a status this build does not know about is never reported as
/// delivered — the fail-safe direction for a caller that hides its retry UI.
fn send_state(status: OutboxStatus) -> SendState {
match status {
OutboxStatus::Sent => SendState::Sent,
_ => SendState::Queued,
}
}
/// Delivery string for one stored chat row. `None` for incoming rows. An
/// outgoing row with no outbox row was accepted on the first attempt, so it is
/// reported as `"sent"` rather than left blank.
fn delivery_of(dir: &str, status: Option<OutboxStatus>) -> Option<String> {
if dir != "out" {
return None;
}
Some(match status {
None | Some(OutboxStatus::Sent) => "sent".to_string(),
Some(other) => other.to_string(),
})
}
#[cfg(test)]
mod tests {
//! No Tor here on purpose: these exercise the *lifecycle* contract of the
@ -422,6 +482,7 @@ mod tests {
//! node is exactly the state `shutdown()` leaves behind.
use super::*;
use onionwire::outbox::OutboxStatus;
fn stopped_wire() -> Wire {
Wire {
@ -482,4 +543,42 @@ mod tests {
);
assert_eq!(TorState::from(CoreTorState::Stopped), TorState::Stopped);
}
#[test]
fn sent_is_sent_everything_else_is_queued() {
assert_eq!(send_state(OutboxStatus::Sent), SendState::Sent);
assert_eq!(send_state(OutboxStatus::Queued), SendState::Queued);
// `Node::send` never returns these today, but they exist on stored
// rows. Unknown states map to `Queued` — the safe direction: never
// report a send as delivered unless the core says `Sent`.
assert_eq!(send_state(OutboxStatus::Sending), SendState::Queued);
assert_eq!(
send_state(OutboxStatus::Failed("no route".into())),
SendState::Queued
);
}
#[test]
fn delivery_is_reported_for_outgoing_rows_only() {
assert_eq!(delivery_of("in", Some(OutboxStatus::Queued)), None);
// Outgoing row with no outbox row: delivered on the first attempt.
assert_eq!(delivery_of("out", None).as_deref(), Some("sent"));
assert_eq!(
delivery_of("out", Some(OutboxStatus::Sent)).as_deref(),
Some("sent")
);
assert_eq!(
delivery_of("out", Some(OutboxStatus::Queued)).as_deref(),
Some("queued")
);
assert_eq!(
delivery_of("out", Some(OutboxStatus::Sending)).as_deref(),
Some("sending")
);
assert_eq!(
delivery_of("out", Some(OutboxStatus::Failed("no route".into()))).as_deref(),
Some("failed: no route")
);
}
}