cryptographic signature, put registration and messages structure
This commit is contained in:
50
client-network/src/messages_structure.rs
Normal file
50
client-network/src/messages_structure.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
struct UDPMessage {
|
||||
id: [u8; 4],
|
||||
msg_type: u8,
|
||||
length: [u8; 2],
|
||||
body: [u8; 985],
|
||||
signature: [u8; 32],
|
||||
}
|
||||
|
||||
struct HandshakeMessage {
|
||||
id: [u8; 4],
|
||||
msg_type: u8,
|
||||
length: [u8; 2],
|
||||
extensions: [u8; 4],
|
||||
name: [u8; 981],
|
||||
signature: [u8; 32],
|
||||
}
|
||||
|
||||
impl UDPMessage {
|
||||
pub fn ping(id: i32) -> UDPMessage {
|
||||
UDPMessage { id: id.to_ne_bytes(), msg_type: 0, length: [0; 2], body: [0; 985], signature: [0; 32]}
|
||||
}
|
||||
|
||||
pub fn error(id: i32) -> UDPMessage {
|
||||
|
||||
UDPMessage { id: id.to_ne_bytes(), msg_type: 129, length: [0; 2], body: [0; 985], signature: [0; 32]}
|
||||
}
|
||||
|
||||
pub fn hello(id: i32, length: i16, username: String) -> HandshakeMessage {
|
||||
let username_bytes = username.as_bytes();
|
||||
|
||||
let mut body: [u8; 981] = [0; 981];
|
||||
|
||||
let length_to_copy = username_bytes.len().min(981);
|
||||
body[..length_to_copy].copy_from_slice(&username_bytes[..length_to_copy]);
|
||||
HandshakeMessage {id: id.to_ne_bytes(), msg_type: 1, length: length.to_ne_bytes(), extensions: [0;4], name: body, signature: [0;32]}
|
||||
|
||||
}
|
||||
|
||||
pub fn helloReply(id: i32, length: i16, username: String) -> HandshakeMessage {
|
||||
let username_bytes = username.as_bytes();
|
||||
|
||||
let mut body: [u8; 981] = [0; 981];
|
||||
|
||||
let length_to_copy = username_bytes.len().min(981);
|
||||
body[..length_to_copy].copy_from_slice(&username_bytes[..length_to_copy]);
|
||||
HandshakeMessage {id: id.to_ne_bytes(), msg_type: 130, length: length.to_ne_bytes(), extensions: [0;4], name: body, signature: [0;32]}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user