feat: implement download peer

This commit is contained in:
Michel de Graaf
2025-07-31 20:06:41 +02:00
parent 956cb824bd
commit 9553537bc6
9 changed files with 590 additions and 7 deletions
+15 -3
View File
@@ -1,6 +1,7 @@
pub mod default_peer;
pub use default_peer::*;
pub mod download_peer;
pub mod listen;
use crate::message::Message;
@@ -40,6 +41,17 @@ impl FromStr for ConnectionType {
}
}
impl fmt::Display for ConnectionType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
ConnectionType::P => "P",
ConnectionType::F => "F",
ConnectionType::D => "D",
};
write!(f, "{}", s)
}
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Peer {
@@ -128,7 +140,7 @@ fn test_new_from_message() {
assert!(matches!(peer.connection_type, ConnectionType::P));
assert_eq!(peer.host, "45.37.25.27");
assert_eq!(peer.port, 2234);
assert_eq!(peer.token, Some("b24e1900".to_string()));
assert_eq!(peer.token, Some(1683702));
assert_eq!(peer.privileged, 0);
assert_eq!(peer.unknown, 0);
assert_eq!(peer.obfuscated_port, 0);
@@ -150,7 +162,7 @@ fn test_new_from_message2() {
assert!(matches!(peer.connection_type, ConnectionType::P));
assert_eq!(peer.host, "68.63.128.119");
assert_eq!(peer.port, 2235);
assert_eq!(peer.token, Some("3a100000".to_string()));
assert_eq!(peer.token, Some(4122));
assert_eq!(peer.privileged, 0);
assert_eq!(peer.unknown, 1);
assert_eq!(peer.obfuscated_port, 0);