Skip to content

Commit

Permalink
dont need to validate reserved bits
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoyu2002 committed May 26, 2024
1 parent 698e4e1 commit 5c463d7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Debug for ClientError {
ClientError::GetPeersError(e) => write!(f, "GetPeersError: {}", e),
ClientError::HandshakeError(e) => write!(
f,
"HandshakeError: Peer: {}, Status: {}, Message: {} Handshake: {}",
"HandshakeError: Peer: {}, Status: {}, Message: {} Handshake:\n{}",
e.peer,
e.status,
e.message,
Expand Down Expand Up @@ -115,13 +115,6 @@ impl Client {
));
}

// don't need to validate reserved bytes
// if &handshake[20..28] != [0; 8] {
// return Err(ClientError::ValidateHandshakeError(
// "Invalid reserved bytes".to_string(),
// ));
// }

if &handshake[28..48] != info_hash {
return Err(ClientError::ValidateHandshakeError(
"Invalid info hash".to_string(),
Expand Down Expand Up @@ -199,12 +192,14 @@ impl Client {

match handle
.await
.map_err(|_| ClientError::GetPeersError(String::from("Failed to get peer")))?
.map_err(|e| ClientError::GetPeersError(String::from(e.to_string())))?
{
Ok((peer_id, stream)) => {
println!(
"Connected to peer {} with id {}",
stream.peer_addr().unwrap(),
stream.peer_addr().map_err(|_| {
ClientError::GetPeersError(String::from("Failed to get peer addr"))
})?,
peer_id
);
self.connections.push(stream);
Expand Down

0 comments on commit 5c463d7

Please sign in to comment.