[relay] Files: a file route for same-size encrypted chunks with its own quotas; the client seals chunks in STREAM and sends a file payload inside MLS
ci / check (pull_request) Has been cancelled
ci / check (pull_request) Has been cancelled
The relay stores files (id, upload and fetch token hashes, chunk count, uploaded hour) and chunks (file id, index, ciphertext): every chunk is 256 000 bytes, so it learns the size rounded up to 250 KiB and nothing finer, and it keeps no fetch count. Only the uploader's token puts or deletes, only the fetch token gets, a chunk never changes; per-file and relay-wide quotas answer 507; files go after 30 days, incomplete ones after 24 hours. The client pads a file to whole chunks and seals each with ChaCha20-Poly1305 in the aead crate's STREAM, under a key made for that file; the key, name, type, size and thumbnail travel only in the new `file` payload, which shares `seq` with text. Also: every route now answers a bare 413 (axum's own carried a text). PROTOCOL.md §1, §4, §5, §7, §8.
This commit is contained in:
@@ -0,0 +1,365 @@
|
||||
//! Files (`.agents/features/files.md`). No I/O: runs on the Android emulator too.
|
||||
|
||||
use tabellarius_client::*;
|
||||
use tabellarius_protocol::{CreateFile, MailboxId, Sha256Hash, Token};
|
||||
|
||||
type C = Client<MemoryTransport>;
|
||||
|
||||
fn pair(relay: &MemoryTransport, receipts: bool) -> (C, ContactId, C, ContactId) {
|
||||
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||
eva.set_receipts(receipts);
|
||||
jan.set_receipts(receipts);
|
||||
let invite = eva.create_invite().expect("invite");
|
||||
let jan_side = jan.accept_invite(&invite).expect("accept");
|
||||
let Some(Event::Joined {
|
||||
contact: eva_side, ..
|
||||
}) = eva.poll().expect("poll").first().cloned()
|
||||
else {
|
||||
panic!("no join")
|
||||
};
|
||||
jan.poll().expect("poll");
|
||||
(eva, eva_side, jan, jan_side)
|
||||
}
|
||||
|
||||
fn content(size: usize, seed: u8) -> Vec<u8> {
|
||||
(0..size)
|
||||
.map(|i| ((i * 7 + seed as usize) % 253) as u8)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Sends `bytes` from `from` to its contact `to`, and returns the event the other side receives.
|
||||
fn send_file(from: &mut C, to: ContactId, other: &mut C, bytes: &[u8], name: &str) -> Event {
|
||||
let up = from.start_upload(bytes.len() as u64).expect("start");
|
||||
from.upload(&up, bytes).expect("upload");
|
||||
let out = from
|
||||
.compose_file(to, &up, name, "application/pdf", None)
|
||||
.expect("compose");
|
||||
from.deliver(&out).expect("deliver");
|
||||
let mut events = other.poll().expect("poll");
|
||||
assert_eq!(events.len(), 1, "{events:?}");
|
||||
events.remove(0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn files_of_every_shape_go_both_ways_and_come_back_byte_for_byte() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, jan_side) = pair(&relay, false);
|
||||
let sizes = [
|
||||
1,
|
||||
1000,
|
||||
FILE_CHUNK_PLAIN,
|
||||
FILE_CHUNK_PLAIN + 1,
|
||||
3 * FILE_CHUNK_PLAIN - 1,
|
||||
];
|
||||
for (i, size) in sizes.into_iter().enumerate() {
|
||||
let bytes = content(size, i as u8);
|
||||
let (from, to, other) = if i % 2 == 0 {
|
||||
(&mut eva, eva_side, &mut jan)
|
||||
} else {
|
||||
(&mut jan, jan_side, &mut eva)
|
||||
};
|
||||
let Event::File {
|
||||
file, name, seq, ..
|
||||
} = send_file(from, to, other, &bytes, "Lístky.pdf")
|
||||
else {
|
||||
panic!("not a file")
|
||||
};
|
||||
assert_eq!(name, "Lístky.pdf");
|
||||
assert_eq!(seq, i as u64 / 2 + 1, "a file shares the sender's seq");
|
||||
assert_eq!(file.size(), size as u64);
|
||||
assert_eq!(other.download(&file).expect("download"), bytes, "{size}");
|
||||
}
|
||||
// Every chunk on the relay is the same size, whatever the file's.
|
||||
let chunks = relay.stored_chunks();
|
||||
assert_eq!(chunks.len(), 1 + 1 + 1 + 2 + 3);
|
||||
assert!(chunks.iter().all(|c| c.len() == FILE_CHUNK_BYTES));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_is_a_message_a_receipt_covers_it_and_a_reaction_or_reply_can_name_it() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, jan_side) = pair(&relay, true);
|
||||
eva.send(eva_side, "Posílám menu").expect("send");
|
||||
jan.poll().expect("poll");
|
||||
let Event::File { seq, .. } = send_file(&mut eva, eva_side, &mut jan, b"%PDF-1.7", "Menu.pdf")
|
||||
else {
|
||||
panic!("not a file")
|
||||
};
|
||||
assert_eq!(seq, 2);
|
||||
assert_eq!(eva.sent_seq(eva_side), Some(2));
|
||||
// Jan's receipt for it reached Eva.
|
||||
let events = eva.poll().expect("poll");
|
||||
assert!(
|
||||
events.contains(&Event::Delivered {
|
||||
contact: eva_side,
|
||||
upto: 2
|
||||
}),
|
||||
"{events:?}"
|
||||
);
|
||||
let the_file = MessageRef {
|
||||
author: eva.author(),
|
||||
seq: 2,
|
||||
};
|
||||
let out = jan.react(jan_side, the_file, Some("👍")).expect("react");
|
||||
jan.deliver(&out).expect("deliver");
|
||||
let out = jan
|
||||
.compose_text(jan_side, "Díky", Some(the_file))
|
||||
.expect("reply");
|
||||
jan.deliver(&out).expect("deliver");
|
||||
let events = eva.poll().expect("poll");
|
||||
assert!(events.contains(&Event::Reaction {
|
||||
contact: eva_side,
|
||||
to: the_file,
|
||||
emoji: Some("👍".into())
|
||||
}));
|
||||
assert!(events.iter().any(|e| matches!(
|
||||
e,
|
||||
Event::Message { reply_to: Some(r), .. } if *r == the_file
|
||||
)));
|
||||
}
|
||||
|
||||
/// A relay that hands out another chunk than the one asked for, or a changed one.
|
||||
#[derive(Clone)]
|
||||
struct Lying {
|
||||
inner: MemoryTransport,
|
||||
how: fn(u32, Vec<u8>, &MemoryTransport, &tabellarius_protocol::FileId, &Token) -> Vec<u8>,
|
||||
}
|
||||
|
||||
impl Transport for Lying {
|
||||
fn create_mailbox(
|
||||
&self,
|
||||
r: &tabellarius_protocol::CreateMailbox,
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.create_mailbox(r)
|
||||
}
|
||||
fn post(&self, id: &MailboxId, post: &Token, blob: &[u8]) -> Result<(), TransportError> {
|
||||
self.inner.post(id, post, blob)
|
||||
}
|
||||
fn fetch(&self, id: &MailboxId, fetch: &Token) -> Result<Vec<Vec<u8>>, TransportError> {
|
||||
self.inner.fetch(id, fetch)
|
||||
}
|
||||
fn acknowledge(&self, id: &MailboxId, f: &Token, h: &Sha256Hash) -> Result<(), TransportError> {
|
||||
self.inner.acknowledge(id, f, h)
|
||||
}
|
||||
fn create_invite(&self, r: &tabellarius_protocol::CreateInvite) -> Result<(), TransportError> {
|
||||
self.inner.create_invite(r)
|
||||
}
|
||||
fn rotate_post_token(
|
||||
&self,
|
||||
id: &MailboxId,
|
||||
f: &Token,
|
||||
h: &Sha256Hash,
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.rotate_post_token(id, f, h)
|
||||
}
|
||||
fn claim_invite(
|
||||
&self,
|
||||
id: &tabellarius_protocol::InviteId,
|
||||
s: &Token,
|
||||
) -> Result<Vec<u8>, TransportError> {
|
||||
self.inner.claim_invite(id, s)
|
||||
}
|
||||
fn set_push(
|
||||
&self,
|
||||
id: &MailboxId,
|
||||
f: &Token,
|
||||
e: Option<&tabellarius_protocol::PushEndpoint>,
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.set_push(id, f, e)
|
||||
}
|
||||
fn create_file(&self, r: &CreateFile) -> Result<(), TransportError> {
|
||||
self.inner.create_file(r)
|
||||
}
|
||||
fn put_chunk(
|
||||
&self,
|
||||
id: &tabellarius_protocol::FileId,
|
||||
u: &Token,
|
||||
i: u32,
|
||||
c: &[u8],
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.put_chunk(id, u, i, c)
|
||||
}
|
||||
fn get_chunk(
|
||||
&self,
|
||||
id: &tabellarius_protocol::FileId,
|
||||
f: &Token,
|
||||
i: u32,
|
||||
) -> Result<Vec<u8>, TransportError> {
|
||||
let honest = self.inner.get_chunk(id, f, i)?;
|
||||
Ok((self.how)(i, honest, &self.inner, id, f))
|
||||
}
|
||||
fn delete_file(
|
||||
&self,
|
||||
id: &tabellarius_protocol::FileId,
|
||||
u: &Token,
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.delete_file(id, u)
|
||||
}
|
||||
}
|
||||
|
||||
/// Uploads a three-chunk file from Eva and gives Jan a client whose relay lies in the way `how`.
|
||||
fn through_a_lying_relay(
|
||||
how: fn(u32, Vec<u8>, &MemoryTransport, &tabellarius_protocol::FileId, &Token) -> Vec<u8>,
|
||||
) -> Result<Vec<u8>, ClientError> {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, _) = pair(&relay, false);
|
||||
let bytes = content(2 * FILE_CHUNK_PLAIN + 10, 3);
|
||||
let Event::File { file, .. } = send_file(&mut eva, eva_side, &mut jan, &bytes, "a.bin") else {
|
||||
panic!("not a file")
|
||||
};
|
||||
let honest = jan.download(&file).expect("honest relay");
|
||||
assert_eq!(honest, bytes);
|
||||
let liar = Client::new("Jan", Lying { inner: relay, how }).expect("liar");
|
||||
liar.download(&file)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_chunk_tampered_with_swapped_or_repeated_on_the_relay_is_refused() {
|
||||
// One bit flipped in the middle chunk.
|
||||
let flipped = through_a_lying_relay(|i, mut c, _, _, _| {
|
||||
if i == 1 {
|
||||
c[1000] ^= 0x20;
|
||||
}
|
||||
c
|
||||
});
|
||||
assert_eq!(flipped, Err(ClientError::FileDamaged));
|
||||
// Chunks 0 and 1 swapped.
|
||||
let swapped = through_a_lying_relay(|i, c, inner, id, f| match i {
|
||||
0 => inner.get_chunk(id, f, 1).expect("chunk"),
|
||||
1 => inner.get_chunk(id, f, 0).expect("chunk"),
|
||||
_ => c,
|
||||
});
|
||||
assert_eq!(swapped, Err(ClientError::FileDamaged));
|
||||
// The middle chunk served as the last one too (a file cut short and padded out).
|
||||
let repeated = through_a_lying_relay(|i, c, inner, id, f| {
|
||||
if i == 2 {
|
||||
inner.get_chunk(id, f, 1).expect("chunk")
|
||||
} else {
|
||||
c
|
||||
}
|
||||
});
|
||||
assert_eq!(repeated, Err(ClientError::FileDamaged));
|
||||
// A chunk one byte short.
|
||||
let short = through_a_lying_relay(|_, mut c, _, _, _| {
|
||||
c.pop();
|
||||
c
|
||||
});
|
||||
assert_eq!(short, Err(ClientError::FileDamaged));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_chunk_from_another_file_does_not_open() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, _) = pair(&relay, false);
|
||||
let bytes = content(100, 1);
|
||||
let Event::File { file: fa, .. } = send_file(&mut eva, eva_side, &mut jan, &bytes, "a") else {
|
||||
panic!("not a file")
|
||||
};
|
||||
let chunk_a = relay.stored_chunks().remove(0);
|
||||
assert!(fa.open(0, &chunk_a).is_ok());
|
||||
// The same bytes sent again: another key, so a's chunk does not open as b's.
|
||||
let Event::File { file: fb, .. } = send_file(&mut eva, eva_side, &mut jan, &bytes, "b") else {
|
||||
panic!("not a file")
|
||||
};
|
||||
assert_eq!(fb.open(0, &chunk_a), Err(ClientError::FileDamaged));
|
||||
assert_eq!(jan.download(&fb).expect("b"), bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_chunk_is_not_found_and_the_download_works_once_it_is_up() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, _) = pair(&relay, false);
|
||||
let bytes = content(FILE_CHUNK_PLAIN + 5, 9);
|
||||
let up = eva.start_upload(bytes.len() as u64).expect("start");
|
||||
eva.create_file(&up).expect("create");
|
||||
eva.put_chunk(&up, 0, up.part(&bytes, 0).expect("part"))
|
||||
.expect("chunk 0");
|
||||
// The message overtakes the upload.
|
||||
let out = eva
|
||||
.compose_file(eva_side, &up, "late.bin", "application/octet-stream", None)
|
||||
.expect("compose");
|
||||
eva.deliver(&out).expect("deliver");
|
||||
let Some(Event::File { file, .. }) = jan.poll().expect("poll").first().cloned() else {
|
||||
panic!("no file")
|
||||
};
|
||||
assert_eq!(
|
||||
jan.download(&file),
|
||||
Err(ClientError::Transport(TransportError::NotFound))
|
||||
);
|
||||
assert!(jan.get_chunk(&file, 0).is_ok(), "the first chunk is there");
|
||||
eva.put_chunk(&up, 1, up.part(&bytes, 1).expect("part"))
|
||||
.expect("chunk 1");
|
||||
assert_eq!(jan.download(&file).expect("download"), bytes);
|
||||
assert_eq!(
|
||||
jan.get_chunk(&file, 2),
|
||||
Err(ClientError::BadFile),
|
||||
"past the end"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_upload_resumes_after_a_crash_from_its_saved_form() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, _) = pair(&relay, false);
|
||||
let bytes = content(3 * FILE_CHUNK_PLAIN, 4);
|
||||
let up = eva.start_upload(bytes.len() as u64).expect("start");
|
||||
let saved = serde_json::to_string(&up).expect("save");
|
||||
eva.create_file(&up).expect("create");
|
||||
eva.put_chunk(&up, 0, up.part(&bytes, 0).expect("part"))
|
||||
.expect("chunk 0");
|
||||
// Crash. The outbox gives the upload back; it starts again from the beginning.
|
||||
let again: FileUpload = serde_json::from_str(&saved).expect("restore");
|
||||
assert_eq!(again, up);
|
||||
eva.upload(&again, &bytes)
|
||||
.expect("create and chunk 0 again are accepted");
|
||||
let out = eva
|
||||
.compose_file(eva_side, &again, "a.bin", "application/octet-stream", None)
|
||||
.expect("compose");
|
||||
eva.deliver(&out).expect("deliver");
|
||||
let Some(Event::File { file, .. }) = jan.poll().expect("poll").first().cloned() else {
|
||||
panic!("no file")
|
||||
};
|
||||
assert_eq!(jan.download(&file).expect("download"), bytes);
|
||||
assert_eq!(relay.stored_chunks().len(), 3);
|
||||
// What is saved holds no plaintext, and its Debug shows no secret.
|
||||
assert!(!saved.contains("a.bin"));
|
||||
assert_eq!(format!("{up:?}"), "FileUpload(3 chunks)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_wrong_bytes_for_a_file_are_refused_before_anything_is_sent() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (eva, _, _jan, _) = pair(&relay, false);
|
||||
let up = eva.start_upload(10).expect("start");
|
||||
assert_eq!(eva.upload(&up, &[1; 9]), Err(ClientError::BadFile));
|
||||
assert_eq!(eva.put_chunk(&up, 0, &[1; 11]), Err(ClientError::BadFile));
|
||||
assert_eq!(eva.put_chunk(&up, 1, &[1; 10]), Err(ClientError::BadFile));
|
||||
assert_eq!(relay.stored_chunks().len(), 0);
|
||||
assert_eq!(eva.start_upload(0).err(), Some(ClientError::BadFile));
|
||||
assert_eq!(
|
||||
eva.start_upload(MAX_FILE_BYTES + 1).err(),
|
||||
Some(ClientError::BadFile)
|
||||
);
|
||||
assert!(eva.start_upload(MAX_FILE_BYTES).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stranger_with_the_file_id_cannot_change_or_delete_it() {
|
||||
let relay = MemoryTransport::default();
|
||||
let (mut eva, eva_side, mut jan, _) = pair(&relay, false);
|
||||
let bytes = content(50, 2);
|
||||
let Event::File { file, .. } = send_file(&mut eva, eva_side, &mut jan, &bytes, "a") else {
|
||||
panic!()
|
||||
};
|
||||
let stranger = Token::from_bytes([7; 32]);
|
||||
assert_eq!(
|
||||
relay.put_chunk(&file.id(), &stranger, 0, &vec![0; FILE_CHUNK_BYTES]),
|
||||
Err(TransportError::NotFound)
|
||||
);
|
||||
assert_eq!(
|
||||
relay.delete_file(&file.id(), &stranger),
|
||||
Err(TransportError::NotFound)
|
||||
);
|
||||
assert_eq!(jan.download(&file).expect("still there"), bytes);
|
||||
}
|
||||
@@ -51,6 +51,7 @@ impl Http {
|
||||
"200" | "201" | "204" => Ok(resp[split + 4..].to_vec()),
|
||||
"404" => Err(TransportError::NotFound),
|
||||
"409" => Err(TransportError::Conflict),
|
||||
"507" => Err(TransportError::Full),
|
||||
_ => Err(TransportError::Failed),
|
||||
}
|
||||
}
|
||||
@@ -148,6 +149,31 @@ impl Transport for Http {
|
||||
}
|
||||
.map(|_| ())
|
||||
}
|
||||
fn create_file(&self, req: &CreateFile) -> Result<(), TransportError> {
|
||||
let body = serde_json::to_vec(req).map_err(|_| TransportError::Failed)?;
|
||||
self.call("POST", "/v0/files", None, &body, true)
|
||||
.map(|_| ())
|
||||
}
|
||||
fn put_chunk(
|
||||
&self,
|
||||
id: &FileId,
|
||||
upload: &Token,
|
||||
index: u32,
|
||||
chunk: &[u8],
|
||||
) -> Result<(), TransportError> {
|
||||
let path = format!("/v0/files/{}/chunks/{index}", id.to_wire());
|
||||
self.call("PUT", &path, Some(upload), chunk, false)
|
||||
.map(|_| ())
|
||||
}
|
||||
fn get_chunk(&self, id: &FileId, fetch: &Token, index: u32) -> Result<Vec<u8>, TransportError> {
|
||||
let path = format!("/v0/files/{}/chunks/{index}", id.to_wire());
|
||||
self.call("GET", &path, Some(fetch), &[], false)
|
||||
}
|
||||
fn delete_file(&self, id: &FileId, upload: &Token) -> Result<(), TransportError> {
|
||||
let path = format!("/v0/files/{}", id.to_wire());
|
||||
self.call("DELETE", &path, Some(upload), &[], false)
|
||||
.map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts the real relay on 127.0.0.1:<free port> with its database in `db`.
|
||||
@@ -279,6 +305,86 @@ fn pair_and_talk_through_a_real_relay_which_never_sees_a_name_or_a_word() {
|
||||
assert!(waiting.len() >= 4096, "the relay stored something");
|
||||
}
|
||||
|
||||
/// Files (`.agents/features/files.md` §5): a photo through the real relay. Its name, type,
|
||||
/// thumbnail and content are in no byte of the relay's database, before or after the download, and
|
||||
/// every chunk the relay holds is the same size.
|
||||
#[test]
|
||||
fn a_file_goes_through_the_real_relay_which_never_sees_its_name_type_or_content() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let db = dir.path().join("relay.db");
|
||||
let relay = Http(start_relay(&db));
|
||||
let mut eva = Client::new("Eva", relay.clone()).expect("eva");
|
||||
let mut jan = Client::new("Jan", relay.clone()).expect("jan");
|
||||
eva.set_receipts(false);
|
||||
jan.set_receipts(false);
|
||||
let invite = eva.create_invite().expect("invite");
|
||||
let jan_side = jan.accept_invite(&invite).expect("accept");
|
||||
eva.poll().expect("poll");
|
||||
jan.poll().expect("poll");
|
||||
|
||||
// Two chunks and a bit, every one of them full of canaries, so any plaintext would be found.
|
||||
let line = b"FILE-CONTENT-CANARY-7f3a ";
|
||||
let content: Vec<u8> = line
|
||||
.iter()
|
||||
.copied()
|
||||
.cycle()
|
||||
.take(2 * FILE_CHUNK_PLAIN + 999)
|
||||
.collect();
|
||||
let name = "FILENAME-CANARY-Menu.jpg";
|
||||
let mime = "image/x-mime-canary";
|
||||
let mut thumb = vec![0xFF, 0xD8, 0xFF, 0xE0];
|
||||
thumb.extend_from_slice(b"THUMBNAIL-CANARY");
|
||||
let up = jan.start_upload(content.len() as u64).expect("start");
|
||||
jan.upload(&up, &content).expect("upload");
|
||||
let out = jan
|
||||
.compose_file(jan_side, &up, name, mime, Some(&thumb))
|
||||
.expect("compose");
|
||||
jan.deliver(&out).expect("deliver");
|
||||
let waiting = std::fs::read(&db).expect("db");
|
||||
|
||||
let events = eva.poll().expect("poll");
|
||||
let Some(Event::File {
|
||||
file,
|
||||
name: got_name,
|
||||
mime: got_mime,
|
||||
thumb: got_thumb,
|
||||
seq,
|
||||
..
|
||||
}) = events.first().cloned()
|
||||
else {
|
||||
panic!("no file: {events:?}");
|
||||
};
|
||||
assert_eq!((got_name.as_str(), got_mime.as_str(), seq), (name, mime, 1));
|
||||
assert_eq!(got_thumb.as_deref(), Some(thumb.as_slice()));
|
||||
assert_eq!(file.chunks(), 3);
|
||||
assert_eq!(eva.download(&file).expect("download"), content);
|
||||
let after = std::fs::read(&db).expect("db");
|
||||
|
||||
for snapshot in [&waiting, &after] {
|
||||
for (what, needle) in [
|
||||
("file content", &line[..]),
|
||||
("file name", name.as_bytes()),
|
||||
("media type", mime.as_bytes()),
|
||||
("thumbnail", b"THUMBNAIL-CANARY".as_slice()),
|
||||
] {
|
||||
assert!(
|
||||
!contains(snapshot, needle),
|
||||
"{what} is readable in the relay's database"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
waiting.len() >= 3 * FILE_CHUNK_BYTES,
|
||||
"the three chunks were stored"
|
||||
);
|
||||
// The sender deletes it early; the relay answers 404 from then on.
|
||||
jan.delete_file(&up).expect("delete");
|
||||
assert_eq!(
|
||||
eva.get_chunk(&file, 0),
|
||||
Err(ClientError::Transport(TransportError::NotFound))
|
||||
);
|
||||
}
|
||||
|
||||
// Wake-up (`.agents/features/wake-up.md` §2.4): an endpoint per mailbox, set and cleared through the
|
||||
// real relay with the mailbox's fetch token.
|
||||
#[test]
|
||||
|
||||
@@ -325,6 +325,33 @@ impl Transport for Flaky {
|
||||
fn create_invite(&self, r: &tabellarius_protocol::CreateInvite) -> Result<(), TransportError> {
|
||||
self.inner.create_invite(r)
|
||||
}
|
||||
fn create_file(&self, r: &tabellarius_protocol::CreateFile) -> Result<(), TransportError> {
|
||||
self.inner.create_file(r)
|
||||
}
|
||||
fn put_chunk(
|
||||
&self,
|
||||
id: &tabellarius_protocol::FileId,
|
||||
upload: &tabellarius_protocol::Token,
|
||||
index: u32,
|
||||
chunk: &[u8],
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.put_chunk(id, upload, index, chunk)
|
||||
}
|
||||
fn get_chunk(
|
||||
&self,
|
||||
id: &tabellarius_protocol::FileId,
|
||||
fetch: &tabellarius_protocol::Token,
|
||||
index: u32,
|
||||
) -> Result<Vec<u8>, TransportError> {
|
||||
self.inner.get_chunk(id, fetch, index)
|
||||
}
|
||||
fn delete_file(
|
||||
&self,
|
||||
id: &tabellarius_protocol::FileId,
|
||||
upload: &tabellarius_protocol::Token,
|
||||
) -> Result<(), TransportError> {
|
||||
self.inner.delete_file(id, upload)
|
||||
}
|
||||
fn set_push(
|
||||
&self,
|
||||
id: &tabellarius_protocol::MailboxId,
|
||||
|
||||
Reference in New Issue
Block a user