[verified] fix(file): pace chunks to fit rendezvous rate limit
All checks were successful
ci / test (pull_request) Successful in 2m42s
All checks were successful
ci / test (pull_request) Successful in 2m42s
Sender-side only. First chunk attempt is immediate; later attempts (retries and later chunks) wait 3s. Three attempts per chunk, then fail closed. Token bucket 30/60s burst 10 is unchanged. A 1 MiB file is 17 one-shot sessions; pacing floor is 16*3s = 48s plus handshake time. Latency trade, not a security fix.
This commit is contained in:
parent
cb91ba2b78
commit
4bbc2de9ab
5 changed files with 122 additions and 4 deletions
|
|
@ -486,12 +486,13 @@ impl Node {
|
|||
}
|
||||
|
||||
/// One-shot file to a friend. Fail closed; no outbox, no resume.
|
||||
/// Chunks are paced (`file::CHUNK_PACE`) with bounded per-chunk retry so
|
||||
/// a 1 MiB transfer fits the receiver's rendezvous token bucket.
|
||||
pub async fn send_file(&self, friend_pk: &[u8], path: &Path) -> Result<String, String> {
|
||||
let (name, bytes) = file::read_limited(path).map_err(|e| e.to_string())?;
|
||||
let chunks = file::chunks(&name, &bytes).map_err(|e| e.to_string())?;
|
||||
for chunk in &chunks {
|
||||
self.send_once(friend_pk, &file::encode(chunk)).await?;
|
||||
}
|
||||
let frames: Vec<Vec<u8>> = chunks.iter().map(file::encode).collect();
|
||||
file::send_chunks(frames.len(), |i| self.send_once(friend_pk, &frames[i])).await?;
|
||||
self.store
|
||||
.lock()
|
||||
.map_err(|e| e.to_string())?
|
||||
|
|
|
|||
Loading…
Reference in a new issue