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` (E0308 at src/lib.rs:195) — and nothing
noticed, because the SDK is a separate cargo workspace that root CI never
compiles and android-release.yml only builds on a v*.*.* tag.
- `Wire::send()` now returns `WResult<SendState>` (`Sent` | `Queued`) instead
of swallowing the outcome as `()`. A queued send is local-only until the
retry worker gets a circuit through, so the Kotlin boundary must be able to
tell it apart from a delivered one.
- `ChatMessage` gains `delivery: Option<String>` ("sent" | "queued" |
"sending" | "failed: <reason>"), populated from the message's outbox row;
`None` for incoming messages. An outgoing row with no outbox row was accepted
on the first attempt, so it reads "sent".
- New `sdk` job in `.forgejo/workflows/ci.yml`: `cargo test --locked` +
`cargo clippy --locked --all-targets -- -D warnings` in `crates/onionwire-sdk`
in the same rust:1.91-bookworm container, with its own target volume (the SDK
resolves the root crate with rustls, so sharing the root job's target dir
would thrash feature-unified artifacts).
- Drift found while un-rotting it: the SDK `Cargo.lock` was stale (missing
`sha2`, added to the root crate by the zeroize work), so `--locked` failed;
and the SDK README still said "no outbox, no spool in v1" and "identity keys
in sqlite are plaintext", both untrue since the outbox and SQLCipher landed.
Tests: crates/onionwire-sdk 4 passed (2 new unit tests over the status
mapping), clippy clean; root `cargo test --locked` clean. The CI job body was
smoke-run locally in the same container image before being committed.
# Conflicts:
# crates/onionwire-sdk/src/lib.rs
This commit is contained in:
parent
2cbe7d41e5
commit
168727ac39
20 changed files with 306 additions and 103 deletions
18
src/node.rs
18
src/node.rs
|
|
@ -251,7 +251,8 @@ impl Node {
|
|||
/// `sending`; `Outbox::reset_stale` requeues those on the next unlock, the
|
||||
/// same recovery the parent uses for a process that died mid-attempt.
|
||||
async fn drain(&self, budget: Duration) -> Result<FlushOutcome, String> {
|
||||
let attempted = match tokio::time::timeout(budget, self.outbox.flush_all(unix_now())).await {
|
||||
let attempted = match tokio::time::timeout(budget, self.outbox.flush_all(unix_now())).await
|
||||
{
|
||||
Ok(Ok(rows)) => Some(rows),
|
||||
Ok(Err(e)) => return Err(e),
|
||||
Err(_) => {
|
||||
|
|
@ -733,7 +734,10 @@ impl Node {
|
|||
|
||||
/// Pending and failed outbox rows for a friend, for UI surfacing.
|
||||
/// Delivered rows are dropped, so a message absent here was sent.
|
||||
pub fn outbox_pending(&self, friend_pk: &[u8]) -> Result<Vec<crate::store::OutboxEntry>, String> {
|
||||
pub fn outbox_pending(
|
||||
&self,
|
||||
friend_pk: &[u8],
|
||||
) -> Result<Vec<crate::store::OutboxEntry>, String> {
|
||||
self.outbox.pending(friend_pk)
|
||||
}
|
||||
|
||||
|
|
@ -1055,7 +1059,8 @@ fn checkpoint_wal(home: &Path) -> Result<(), String> {
|
|||
if !db.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
let conn = rusqlite::Connection::open(&db).map_err(|e| format!("open {}: {e}", db.display()))?;
|
||||
let conn =
|
||||
rusqlite::Connection::open(&db).map_err(|e| format!("open {}: {e}", db.display()))?;
|
||||
let (busy, log, checkpointed): (i64, i64, i64) = conn
|
||||
.query_row("PRAGMA wal_checkpoint(TRUNCATE)", [], |row| {
|
||||
Ok((row.get(0)?, row.get(1)?, row.get(2)?))
|
||||
|
|
@ -1145,8 +1150,11 @@ mod lifecycle_tests {
|
|||
conn.execute_batch("CREATE TABLE t (id INTEGER PRIMARY KEY, v BLOB);")
|
||||
.expect("create table");
|
||||
for _ in 0..64 {
|
||||
conn.execute("INSERT INTO t (v) VALUES (?1)", rusqlite::params![vec![7u8; 512]])
|
||||
.expect("insert");
|
||||
conn.execute(
|
||||
"INSERT INTO t (v) VALUES (?1)",
|
||||
rusqlite::params![vec![7u8; 512]],
|
||||
)
|
||||
.expect("insert");
|
||||
}
|
||||
|
||||
let wal = home.join("onionwire.db-wal");
|
||||
|
|
|
|||
|
|
@ -99,10 +99,9 @@ impl Deliverer for ArtiDeliverer {
|
|||
.connect((onion, HS_PORT))
|
||||
.await
|
||||
.map_err(|e| format!("connect {onion}:{HS_PORT}: {e}"))?;
|
||||
let mut sess =
|
||||
session::handshake_initiator(&mut stream, &self.keys, pinned_id, prekey)
|
||||
.await
|
||||
.map_err(|e| e.into_message())?;
|
||||
let mut sess = session::handshake_initiator(&mut stream, &self.keys, pinned_id, prekey)
|
||||
.await
|
||||
.map_err(|e| e.into_message())?;
|
||||
let ct = sess.encrypt(plaintext).map_err(|e| e.into_message())?;
|
||||
frame::write_frame(&mut stream, &ct)
|
||||
.await
|
||||
|
|
@ -145,7 +144,11 @@ impl Outbox {
|
|||
/// protocol error or a bad local state, never retried.
|
||||
pub async fn send(&self, friend_pk: &[u8], plaintext: &[u8]) -> Result<OutboxStatus, String> {
|
||||
let (onion, prekey) = self.target(friend_pk)?;
|
||||
match self.deliverer.deliver(&onion, friend_pk, &prekey, plaintext).await {
|
||||
match self
|
||||
.deliverer
|
||||
.deliver(&onion, friend_pk, &prekey, plaintext)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
self.store()?.append_message(friend_pk, "out", plaintext)?;
|
||||
Ok(OutboxStatus::Sent)
|
||||
|
|
@ -155,14 +158,7 @@ impl Outbox {
|
|||
let now = unix_now();
|
||||
let store = self.store()?;
|
||||
let message_id = store.append_message_id(friend_pk, "out", plaintext)?;
|
||||
store.enqueue_outbox(
|
||||
friend_pk,
|
||||
message_id,
|
||||
1,
|
||||
now + backoff_secs(0),
|
||||
&e,
|
||||
now,
|
||||
)?;
|
||||
store.enqueue_outbox(friend_pk, message_id, 1, now + backoff_secs(0), &e, now)?;
|
||||
Ok(OutboxStatus::Queued)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
src/store.rs
43
src/store.rs
|
|
@ -802,17 +802,13 @@ impl Store {
|
|||
}
|
||||
|
||||
pub fn append_message(&self, friend_pk: &[u8], dir: &str, plaintext: &[u8]) -> Result<()> {
|
||||
self.append_message_id(friend_pk, dir, plaintext).map(|_| ())
|
||||
self.append_message_id(friend_pk, dir, plaintext)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Same as `append_message`, returning the row id so an outbox row can
|
||||
/// point at the body instead of storing a second copy.
|
||||
pub fn append_message_id(
|
||||
&self,
|
||||
friend_pk: &[u8],
|
||||
dir: &str,
|
||||
plaintext: &[u8],
|
||||
) -> Result<i64> {
|
||||
pub fn append_message_id(&self, friend_pk: &[u8], dir: &str, plaintext: &[u8]) -> Result<i64> {
|
||||
if dir != "in" && dir != "out" {
|
||||
return Err(Error("dir must be in or out".into()));
|
||||
}
|
||||
|
|
@ -861,11 +857,7 @@ impl Store {
|
|||
let aad = message_aad(friend_id, &dir, id);
|
||||
let plaintext = crate::backup::aead_decrypt(&self.msg_key, &blob, &aad)
|
||||
.map_err(|_| Error("message decrypt failed".into()))?;
|
||||
out.push(Message {
|
||||
id,
|
||||
dir,
|
||||
plaintext,
|
||||
});
|
||||
out.push(Message { id, dir, plaintext });
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
|
@ -1115,7 +1107,10 @@ fn friend_from_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<Friend> {
|
|||
fn gen_prekey() -> (Zeroizing<Vec<u8>>, Vec<u8>) {
|
||||
let sk = StaticSecret::random_from_rng(OsRng);
|
||||
let pk = X25519Public::from(&sk);
|
||||
(Zeroizing::new(sk.to_bytes().to_vec()), pk.to_bytes().to_vec())
|
||||
(
|
||||
Zeroizing::new(sk.to_bytes().to_vec()),
|
||||
pk.to_bytes().to_vec(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Per-install KDF salt for the whole-database key. Not secret (a salt never
|
||||
|
|
@ -1638,22 +1633,16 @@ mod at_rest {
|
|||
params![salt.as_slice(), wrapped],
|
||||
)
|
||||
.unwrap();
|
||||
for (dir, body) in [
|
||||
("in", "legacy-body-xyz"),
|
||||
("out", "legacy-reply-xyz"),
|
||||
] {
|
||||
for (dir, body) in [("in", "legacy-body-xyz"), ("out", "legacy-reply-xyz")] {
|
||||
conn.execute(
|
||||
"INSERT INTO messages (friend_id, dir, plaintext, created_at) VALUES (1, ?1, x'', 7)",
|
||||
params![dir],
|
||||
)
|
||||
.unwrap();
|
||||
let id = conn.last_insert_rowid();
|
||||
let blob = crate::backup::aead_encrypt(
|
||||
&data_key,
|
||||
body.as_bytes(),
|
||||
&message_aad(1, dir, id),
|
||||
)
|
||||
.unwrap();
|
||||
let blob =
|
||||
crate::backup::aead_encrypt(&data_key, body.as_bytes(), &message_aad(1, dir, id))
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"UPDATE messages SET plaintext = ?1 WHERE id = ?2",
|
||||
params![blob, id],
|
||||
|
|
@ -1681,7 +1670,8 @@ mod at_rest {
|
|||
"fixture must be a plaintext sqlite file"
|
||||
);
|
||||
|
||||
let store = Store::open_at_with_passphrase(dir.path(), "legacy-pass").expect("open+upgrade");
|
||||
let store =
|
||||
Store::open_at_with_passphrase(dir.path(), "legacy-pass").expect("open+upgrade");
|
||||
assert_eq!(
|
||||
store.self_identity().unwrap().identity_sk[..],
|
||||
LEGACY_IDENTITY_SK[..]
|
||||
|
|
@ -1703,7 +1693,10 @@ mod at_rest {
|
|||
);
|
||||
for (needle, what) in [
|
||||
(b"legacy-body-xyz".to_vec(), "message body"),
|
||||
(fingerprint(&LEGACY_FRIEND_PK).into_bytes(), "friend pubkey hex"),
|
||||
(
|
||||
fingerprint(&LEGACY_FRIEND_PK).into_bytes(),
|
||||
"friend pubkey hex",
|
||||
),
|
||||
(LEGACY_IDENTITY_SK.to_vec(), "identity secret"),
|
||||
(b"legacy-friend.onion".to_vec(), "locator"),
|
||||
] {
|
||||
|
|
|
|||
|
|
@ -276,8 +276,10 @@ pub fn chat_with_delivery(
|
|||
// second), and `pending` is ordered by row id, so a hypothetical duplicate
|
||||
// resolves to the newest — the same rule the store's own
|
||||
// `outbox_status_of_message` uses.
|
||||
let by_id: HashMap<i64, &OutboxEntry> =
|
||||
pending.iter().map(|entry| (entry.message_id, entry)).collect();
|
||||
let by_id: HashMap<i64, &OutboxEntry> = pending
|
||||
.iter()
|
||||
.map(|entry| (entry.message_id, entry))
|
||||
.collect();
|
||||
let mut tags: Vec<Option<String>> = vec![None; msgs.len()];
|
||||
for (i, msg) in msgs.iter().enumerate() {
|
||||
if msg.dir != "out" {
|
||||
|
|
|
|||
Loading…
Reference in a new issue