Dispatch read one byte of the code, so a code with a non-zero high byte was handled as its low byte. Message::get_message_code now reads the whole little-endian uint32 and handlers register by u32. PeerInit and PierceFirewall, the only frames with a one-byte code, get their own accessor for the listener's first frame.
29 lines
752 B
Rust
29 lines
752 B
Rust
use std::sync::mpsc::Sender;
|
|
|
|
use crate::{
|
|
message::{Message, MessageHandler},
|
|
peer::PeerMessage,
|
|
trace,
|
|
};
|
|
|
|
pub struct PeerInit;
|
|
impl MessageHandler<PeerMessage> for PeerInit {
|
|
fn get_code(&self) -> u32 {
|
|
1
|
|
}
|
|
|
|
fn handle(&self, message: &mut Message, sender: Sender<PeerMessage>) {
|
|
message.set_pointer(4);
|
|
let _message_code = message.read_int8();
|
|
let username = message.read_string();
|
|
let connection_type = message.read_string();
|
|
let token = message.read_int32();
|
|
trace!(
|
|
"PeerInit: username: {}, connection_type: {}, token: {}",
|
|
username, connection_type, token
|
|
);
|
|
|
|
let _ = sender.send(PeerMessage::SetUsername(username));
|
|
}
|
|
}
|