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
+4
View File
@@ -9,6 +9,7 @@ pub use message_reader::*;
use std::str;
#[derive(Debug, PartialEq)]
#[allow(dead_code)]
pub enum MessageType {
Server,
Peer,
@@ -141,6 +142,7 @@ impl Message {
pub fn new_with_data(data: Vec<u8>) -> Self {
Self { data, pointer: 0 }
}
#[allow(dead_code)]
pub fn reset_pointer(&mut self) {
self.pointer = 0;
}
@@ -244,6 +246,7 @@ impl Message {
self
}
#[allow(dead_code)]
pub fn write_int64(&mut self, value: u64) -> &mut Self {
self.data.extend_from_slice(&value.to_le_bytes());
self
@@ -258,6 +261,7 @@ impl Message {
self
}
#[allow(dead_code)]
pub fn write_raw_hex_string(&mut self, val: &str) -> &mut Self {
let mut b = Vec::new();
for i in (0..val.len()).step_by(2) {
+1 -1
View File
@@ -10,7 +10,7 @@ impl MessageHandler<PeerOperation> for UploadFailedHandler {
fn get_code(&self) -> u8 {
46
}
fn handle(&self, message: &mut Message, sender: Sender<PeerOperation>) {
fn handle(&self, message: &mut Message, _sender: Sender<PeerOperation>) {
let upload_failed = UploadFailed::new_from_message(message);
info!("Upload failed for ${}", upload_failed.filename);
}
+15 -2
View File
@@ -1,4 +1,4 @@
use crate::{message::Message, types::Transfer, utils::md5};
use crate::{message::Message, peer::ConnectionType, types::Transfer, utils::md5};
pub struct MessageFactory;
impl MessageFactory {
@@ -91,7 +91,20 @@ impl MessageFactory {
}
pub fn build_pierce_firewall_message(token: u32) -> Message {
Message::new()
.write_int32(0) // PierceFirewall message code
.write_int32(0) // PierceFirewall message code
.write_int32(token)
.clone()
}
#[allow(dead_code)]
pub fn build_peer_init_message(
own_username: &str,
connection_type: ConnectionType,
token: u32,
) -> Message {
Message::new()
.write_string(own_username)
.write_string(&connection_type.to_string())
.write_int32(token)
.clone()
}