moved RequestHandler creation#78
Conversation
|
@WarmBeer look good to me. Thank you. |
|
@josecelano maybe this can be further refactored if you think the PacketHandler is too big now. I just quickly moved your code/logic to the right places and didn't change much further than that. |
I think it's ok. I think there are like two levels: packets and requests. I see them as two different OSI levels:
The low level handles the UPD packages, and the higher level handles the BitTorrent requests. In the future, we could move some functions around to create those two levels. For example: async fn send_response(socket: Arc<UdpSocket>, remote_addr: SocketAddr, response: Response) {
debug!("sending response to: {:?}", &remote_addr);
let buffer = vec![0u8; MAX_PACKET_SIZE];
let mut cursor = Cursor::new(buffer);
match response.write(&mut cursor) {
Ok(_) => {
let position = cursor.position() as usize;
let inner = cursor.get_ref();
debug!("{:?}", &inner[..position]);
UdpServer::send_packet(socket, &remote_addr, &inner[..position]).await;
}
Err(_) => { debug!("could not write response to bytes."); }
}
}That function belongs to the server. It converts a Response (higher level) into a UDP Package (lower level). We could move the "packaging" logic to a new mod. I think it makes more sense to use But since there is not much code there and it's easy to refactor, we can do it when we agree on that view. |
No description provided.