Optimize on transmit haves

This commit is contained in:
Igor Katson 2021-06-28 16:55:50 +01:00
parent 14b62b45c5
commit b4b22ea9a4
2 changed files with 70 additions and 33 deletions

View file

@ -202,12 +202,7 @@ impl PeerConnection {
Message::Bitfield(b) => self.on_bitfield(handle, b.clone_to_owned()).await?,
Message::Choke => self.on_i_am_choked(handle),
Message::Unchoke => self.on_i_am_unchoked(handle),
Message::Interested => {
warn!(
"{} is interested, but support for interested messages not implemented",
handle
)
}
Message::Interested => self.on_peer_interested(handle),
Message::Piece(piece) => {
self.on_received_piece(handle, piece)
.context("error in on_received_piece()")?;
@ -368,6 +363,15 @@ impl PeerConnection {
.mark_i_am_choked(handle, true);
}
fn on_peer_interested(&self, handle: PeerHandle) {
debug!("peer {} is interested", handle);
self.state
.locked
.write()
.peers
.mark_peer_interested(handle, true);
}
async fn requester(self, handle: PeerHandle) -> anyhow::Result<()> {
let notify = match self.state.locked.read().peers.get_live(handle) {
Some(l) => l.have_notify.clone(),
@ -573,11 +577,7 @@ impl PeerConnection {
index, handle
);
let state_clone = self.state.clone();
let index = piece.index;
spawn("transmit haves", async move {
state_clone.task_transmit_haves(index).await
});
self.state.maybe_transmit_haves(chunk_info.piece_index);
}
false => {
warn!(