You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

message.rs 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const KEYLENGTH: u8 = 32;
  2. pub enum PayloadType {
  3. //0-31 system messages (plaintext)
  4. Ping = 1,
  5. Pong = 2,
  6. Error = 3,
  7. //32 - 63 Serverside messages (currently plaintext)
  8. Init = 32,
  9. Join = 33,
  10. Exit = 34,
  11. //64 -95 initial setup messages(plaintext)
  12. DhSetup = 64,
  13. DhReturn = 65,
  14. //96 - 127 client-client setup messages(DH or old KEY encrypted)
  15. AUTHORIZE = 96,
  16. KeyCurrent = 97,
  17. KeyNew = 98,
  18. //128-159 main messages (shared KEY encrypted)
  19. Msg = 128,
  20. //160-255 reserved
  21. }
  22. struct Message {
  23. // Eigenschaften der Klasse
  24. src_id: u32,
  25. dest_id: u32,
  26. size: u16,
  27. payload: Vec<u8>,
  28. }
  29. impl Message {
  30. fn new(src_id: u32, dest_id: u32, size: u16, msg_type: PayloadType) -> Message {
  31. let mut msg = Message {
  32. src_id: src_id,
  33. dest_id: dest_id,
  34. size: size,
  35. payload: Vec::with_capacity(size.into()),
  36. };
  37. msg.payload[0] = msg_type as u8;
  38. msg
  39. }
  40. // Methoden der Klasse
  41. }