Fix: unchoke now sent after Bitfield properly, not before

This commit is contained in:
Igor Katson 2024-08-31 12:09:36 +01:00
parent 3f014ee80a
commit b60850946e
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 6 additions and 3 deletions

View file

@ -283,6 +283,12 @@ impl<H: PeerConnectionHandler> PeerConnection<H> {
trace!("sent bitfield");
}
let len = MessageOwned::Unchoke.serialize(&mut write_buf, &Default::default)?;
with_timeout(rwtimeout, write_half.write_all(&write_buf[..len]))
.await
.context("error writing unchoke")?;
trace!("sent unchoke");
let mut broadcast_closed = false;
loop {
@ -378,7 +384,6 @@ impl<H: PeerConnectionHandler> PeerConnection<H> {
with_timeout(rwtimeout, write_half.write_all(&write_buf[..len]))
.await
.context("error writing the message to peer")?;
write_buf.clear();
if let Some(uploaded_add) = uploaded_add {
self.handler.on_uploaded_bytes(uploaded_add)

View file

@ -892,8 +892,6 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler {
fn on_handshake<B>(&self, handshake: Handshake<B>) -> anyhow::Result<()> {
self.state.set_peer_live(self.addr, handshake);
self.tx
.send(WriterRequest::Message(MessageOwned::Unchoke))?;
Ok(())
}