|
|
|
|
|
|
|
|
|
|
|
const KEYLENGTH: u8 = 32; |
|
|
|
|
|
|
|
|
|
|
|
pub enum PayloadType { |
|
|
|
|
|
//0-31 system messages (plaintext) |
|
|
|
|
|
Ping = 1, |
|
|
|
|
|
Pong = 2, |
|
|
|
|
|
Error = 3, |
|
|
|
|
|
//32 - 63 Serverside messages (currently plaintext) |
|
|
|
|
|
Init = 32, |
|
|
|
|
|
Join = 33, |
|
|
|
|
|
Exit = 34, |
|
|
|
|
|
//64 -95 initial setup messages(plaintext) |
|
|
|
|
|
DhSetup = 64, |
|
|
|
|
|
DhReturn = 65, |
|
|
|
|
|
//96 - 127 client-client setup messages(DH or old KEY encrypted) |
|
|
|
|
|
AUTHORIZE = 96, |
|
|
|
|
|
KeyCurrent = 97, |
|
|
|
|
|
KeyNew = 98, |
|
|
|
|
|
//128-159 main messages (shared KEY encrypted) |
|
|
|
|
|
Msg = 128, |
|
|
|
|
|
//160-255 reserved |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct Message { |
|
|
|
|
|
// Eigenschaften der Klasse |
|
|
|
|
|
src_id: u32, |
|
|
|
|
|
dest_id: u32, |
|
|
|
|
|
size: u16, |
|
|
|
|
|
payload: Vec<u8>, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Message { |
|
|
|
|
|
fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message { |
|
|
|
|
|
let mut msg = Message { |
|
|
|
|
|
src_id: src_id, |
|
|
|
|
|
dest_id: dest_id, |
|
|
|
|
|
size: size, |
|
|
|
|
|
payload: Vec::with_capacity(size.into()), |
|
|
|
|
|
}; |
|
|
|
|
|
msg.payload[0] = msg_type as u8; |
|
|
|
|
|
msg |
|
|
|
|
|
} |
|
|
|
|
|
// Methoden der Klasse |
|
|
|
|
|
} |