Check the chunk before uploading

This commit is contained in:
Igor Katson 2021-06-28 22:21:21 +01:00
parent df282ae9d8
commit b26af687b7
4 changed files with 22 additions and 9 deletions

View file

@ -263,18 +263,22 @@ impl PeerConnection {
}
};
let tx = self
.state
.locked
.read()
.peers
.clone_tx(peer_handle)
.ok_or_else(|| {
let tx = {
let g = self.state.locked.read();
if !g.chunks.is_chunk_ready_to_upload(&chunk_info) {
anyhow::bail!(
"got request for a chunk that is not ready to upload. chunk {:?}",
&chunk_info
);
}
g.peers.clone_tx(peer_handle).ok_or_else(|| {
anyhow::anyhow!(
"peer {} died, dropping chunk that it requested",
peer_handle
)
})?;
})?
};
// TODO: this is not super efficient as it does copying multiple times.
// Theoretically, this could be done in the sending code, so that it reads straight into