Update handshake deserialize to error on wrong messages

This commit is contained in:
Igor Katson 2024-03-09 19:50:28 +00:00
parent 56527ae8d7
commit 5a12095959
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -531,12 +531,15 @@ impl Handshake<ByteBuf<'static>> {
expected_len,
"handshake",
))?;
Ok((
Self::bopts()
.deserialize(hbuf)
.map_err(|e| MessageDeserializeError::Other(e.into()))?,
expected_len,
))
let h = Self::bopts()
.deserialize::<Handshake<ByteBuf<'_>>>(hbuf)
.map_err(|e| MessageDeserializeError::Other(e.into()))?;
if h.pstr.0 != PSTR_BT1.as_bytes() {
return Err(MessageDeserializeError::Other(anyhow::anyhow!(
"pstr doesn't match bittorrent V1"
)));
}
Ok((h, expected_len))
}
}