Make a serde bencode serializer

This commit is contained in:
Igor Katson 2021-07-01 23:37:57 +01:00
parent 563ca78774
commit 5f60f9e1b4
11 changed files with 2436 additions and 142 deletions

View file

@ -301,7 +301,7 @@ impl TorrentManager {
anyhow::bail!("tracker responded with {:?}", response.status());
}
let bytes = response.bytes().await?;
match crate::serde_bencode::from_bytes::<TrackerError>(&bytes) {
match crate::serde_bencode_de::from_bytes::<TrackerError>(&bytes) {
Ok(error) => anyhow::bail!(
"tracker returned failure. Failure reason: {}",
error.failure_reason
@ -310,7 +310,7 @@ impl TorrentManager {
// ignore, assume ok response
}
};
let response = crate::serde_bencode::from_bytes::<TrackerResponse>(&bytes)?;
let response = crate::serde_bencode_de::from_bytes::<TrackerResponse>(&bytes)?;
for peer in response.peers.iter_sockaddrs() {
self.state.add_peer_if_not_seen(peer);