chore: remove dead code and stale comments

- Drop dead Rooms/Room infrastructure and the rooms field on Context.
- Remove unused ActorMessage::Tick variant and the now-empty handler arm.
- Strip dead active-thread tracking machinery from ThreadPool (unused
  getters, _id/_active_threads/_total_threads parameters).
- Flatten ServerActor::initiate_connection: the duplicated retry block
  was a copy-paste retry against the same address with the same args
  and could never succeed where the first attempt failed.
- Delete commented-out print_hex2/decode debug stubs, dead test
  fixtures in login.rs and message_user.rs, the 47-line commented body
  of RoomListHandler, and assorted // TODO theater.
This commit is contained in:
michel
2026-04-26 17:20:45 +02:00
parent 574833bf61
commit 44846cdfa8
11 changed files with 43 additions and 380 deletions
+3 -19
View File
@@ -3,25 +3,9 @@ use std::{collections::VecDeque, net::TcpStream};
use crate::message::Message;
// # why buffered message reader?
// the stream comes in chunks of bytes: 1024 for example
// the soulseek protocol has binary messages
// the first 4 bytes of the message represent the message size
// the rest of the bytes represent the message itself
//
// # how to implement the buffered message reader?
// read 4 bytes from the stream
// if the stream has less than 4 bytes, buffer then add the rest of the bytes to the buffered
// message reader buffer and return
// if the stream has 4 bytes, read the message size
// if the stream is as long as the message size + 4 bytes, read the message
// create a new message struct and read the message size from the buffer, thats a message
// the rest of the bytes are the next message so you call the read function again with the rest of the bytes
// else
// buffer the rest of the bytes and return
//
//
//
// Soulseek messages are length-prefixed (u32 LE size, then payload). TCP gives us
// arbitrary-sized chunks, so we accumulate into a buffer and only emit a Message
// once size + 4 bytes are available.
pub struct MessageReader {
buffer: VecDeque<u8>,
-47
View File
@@ -93,50 +93,6 @@ impl Message {
trace!("");
}
}
//
// pub fn print_hex2(&self) -> String {
// let data = &self.data;
// let mut out = String::from("");
// const BYTES_PER_LINE: usize = 16;
//
// let chunks = data.chunks(BYTES_PER_LINE);
// for (i, chunk) in chunks.enumerate() {
// // Print the offset
// // out += &format!("{:04x} ", i * BYTES_PER_LINE);
//
// // Print the hexadecimal part
// for j in 0..BYTES_PER_LINE {
// if j < chunk.len() {
// out += &format!("{:02x} ", chunk[j]);
// } else {
// // out += &format!(" ");
// }
//
// // Add extra space in the middle
// // if j == 7 {
// // out += &format!(" ");
// // }
// }
//
// // // Print the ASCII part
// // let mut i = 0;
// // for &byte in chunk {
// // i = i + 1;
// // if byte.is_ascii_graphic() || byte.is_ascii_whitespace() {
// // print!("{}", byte as char);
// // } else {messa
// // print!(".");
// // }
// //
// // if i == 8 {
// // print!(" ");
// // }
// // }
// //
// }
// println!("{:?}", out.trim());
// return out.trim().into();
// }
#[allow(dead_code)]
pub fn get_message_code_u32(&self) -> u32 {
@@ -390,9 +346,6 @@ impl Message {
},
}
}
// pub fn decode(&self) {
// println!("{:?}", self.data);
// }
}
#[test]
@@ -26,16 +26,3 @@ impl MessageHandler<ServerMessage> for LoginHandler {
sender.send(ServerMessage::LoginStatus(true)).unwrap();
}
}
// fn build_login_response_message() -> Message {
// return Message::new_with_data([
// 50, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 81, 170, 162, 77, 32, 0, 0, 0, 101, 102, 99, 97,
// 51, 52, 102, 99, 52, 99, 56, 98, 101, 56, 98, 55, 101, 102, 51, 56, 97, 102, 50, 54, 50,
// 52, 100, 101, 53, 52, 54, 52, 0,
// ]);
// }
// #[test]
// fn test_can_handle() {
// assert_eq!(true, LoginHandler.can_handle(build_login_response_message());
// );
// }
@@ -106,7 +106,6 @@ impl MessageFactory {
.write_int32(41)
.write_int32(transfer.token)
.write_bool(true)
// .write_int64(transfer.size)
.clone()
}
pub fn build_pierce_firewall_message(token: u32) -> Message {
@@ -154,8 +153,6 @@ fn test_build_login_message() {
]
.to_vec();
// println!("{:?}", print_hex(message.get_data()));
// assert_eq!(expect, message.get_data());
assert_eq!(expect, message.get_data())
}
@@ -29,37 +29,3 @@ impl MessageHandler<ServerMessage> for MessageUser {
user_message.print()
}
}
// #[cfg(test)]
// use std::sync::mpsc;
// #[cfg(test)]
// use std::sync::mpsc::{Receiver, Sender};
//
// #[test]
// fn test_handle() {
// let (message_sender, _message_reader): (Sender<Message>, Receiver<Message>) = mpsc::channel();
//
// let context = Arc::new(Mutex::new(Context::new(Arc::new(Mutex::new(
// message_sender,
// )))));
// let mut message = Message::new_with_data(vec![
// 254, 0, 0, 0, 22, 0, 0, 0, 153, 102, 47, 0, 58, 65, 228, 102, 6, 0, 0, 0, 115, 101, 114,
// 118, 101, 114, 227, 0, 0, 0, 89, 111, 117, 114, 32, 99, 111, 110, 110, 101, 99, 116, 105,
// 111, 110, 32, 105, 115, 32, 114, 101, 115, 116, 114, 105, 99, 116, 101, 100, 58, 32, 89,
// 111, 117, 32, 99, 97, 110, 110, 111, 116, 32, 115, 101, 97, 114, 99, 104, 32, 111, 114, 32,
// 99, 104, 97, 116, 46, 32, 89, 111, 117, 114, 32, 99, 108, 105, 101, 110, 116, 32, 118, 101,
// 114, 115, 105, 111, 110, 32, 105, 115, 32, 116, 111, 111, 32, 111, 108, 100, 46, 32, 89,
// 111, 117, 32, 110, 101, 101, 100, 32, 116, 111, 32, 117, 112, 103, 114, 97, 100, 101, 32,
// 116, 111, 32, 116, 104, 101, 32, 108, 97, 116, 101, 115, 116, 32, 118, 101, 114, 115, 105,
// 111, 110, 46, 32, 67, 108, 111, 115, 101, 32, 116, 104, 105, 115, 32, 99, 108, 105, 101,
// 110, 116, 44, 32, 100, 111, 119, 110, 108, 111, 97, 100, 32, 110, 101, 119, 32, 118, 101,
// 114, 115, 105, 111, 110, 32, 102, 114, 111, 109, 32, 104, 116, 116, 112, 58, 47, 47, 119,
// 119, 119, 46, 115, 108, 115, 107, 110, 101, 116, 46, 111, 114, 103, 44, 32, 105, 110, 115,
// 116, 97, 108, 108, 32, 105, 116, 32, 97, 110, 100, 32, 114, 101, 99, 111, 110, 110, 101,
// 99, 116, 46, 1,
// ]);
// message.set_pointer(8);
// MessageUser.handle(&mut message.clone(), context.clone());
// assert_eq!(1, context.lock().unwrap().get_user_messages().len());
// }
// // }
@@ -12,51 +12,7 @@ impl MessageHandler<ServerMessage> for RoomListHandler {
}
fn handle(&self, _message: &mut Message, _sender: Sender<ServerMessage>) {
// let num_public_rooms = message.read_int32();
// for _ in 0..num_public_rooms {
// rooms.public_rooms.push(Room::new(message.read_string(), 0));
// }
//
// let num_public_rooms = message.read_int32();
// for i in 0..num_public_rooms {
// rooms.public_rooms[i as usize].set_number_of_users(message.read_int32());
// }
//
// let num_owned_private_rooms = message.read_int32();
// for _ in 0..num_owned_private_rooms {
// rooms
// .owned_private_rooms
// .push(Room::new(message.read_string(), 0));
// }
//
// let num_owned_private_rooms = message.read_int32();
// for i in 0..num_owned_private_rooms {
// rooms.owned_private_rooms[i as usize].set_number_of_users(message.read_int32());
// }
//
// let num_private_rooms = message.read_int32();
// for _ in 0..num_private_rooms {
// rooms
// .private_rooms
// .push(Room::new(message.read_string(), 0));
// }
//
// let num_private_rooms = message.read_int32();
// for i in 0..num_private_rooms {
// rooms.private_rooms[i as usize].set_number_of_users(message.read_int32());
// }
//
// let num_operated_private_rooms = message.read_int32();
// for _ in 0..num_operated_private_rooms {
// rooms
// .operated_private_rooms
// .push(Room::new(message.read_string(), 0));
// }
// let num_operated_private_rooms = message.read_int32();
// for i in 0..num_operated_private_rooms {
// rooms.operated_private_rooms[i as usize].set_number_of_users(message.read_int32());
// }
// cvat.notify_all();
// rooms.print();
// Room listing is not yet exposed to the client; this handler exists
// so the dispatcher can ack code 64 without logging an unknown message.
}
}