Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
VxDxK committed Sep 1, 2024
1 parent d73b0b4 commit 8a3f4dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 2 additions & 5 deletions torrent-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ impl Client {
return;
}
let connection = connection.unwrap();
let bt_conn = PeerConnection::handshake(
connection,
&meta.info.info_hash.clone(),
&client_id,
);
let bt_conn =
PeerConnection::handshake(connection, &meta.info.info_hash.clone(), &client_id);
match bt_conn {
Ok(_) => println!("conn ok"),
Err(e) => println!("err {}", e.to_string()),
Expand Down
17 changes: 16 additions & 1 deletion torrent-client/src/peer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ impl PeerConnection {
let _ = tcp_connection.write_all(bytes.as_ref())?;
let read_bytes = tcp_connection.read(bytes.as_mut())?;
if read_bytes != 68 {
return Err(HandshakeFailed(format!("Invalid bytes count received {read_bytes}")))
return Err(HandshakeFailed(format!(
"Invalid bytes count received {read_bytes}"
)));
}

let response = HandshakeMessage::from_bytes(bytes)?;
Expand All @@ -104,6 +106,19 @@ impl PeerConnection {
}
}

pub enum Messages {
KeepAlive,
Choke,
UnChoke,
Interested,
NotInterested,
Have,
Request,
Piece,
Cancel,
Port
}

#[cfg(test)]
mod tests {
use crate::peer::connection::{HandshakeMessage, BIT_TORRENT_PROTOCOL_STRING};
Expand Down

0 comments on commit 8a3f4dd

Please sign in to comment.