oxedyne/fe2o3/fe2o3_shield/src/srv/guard/data.rs
1.8 KiB, 20 runs
created by r1870400018:866, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use crate::srv::msg::handshake::HandshakeType; |
| 2 | |
| 3 | use oxedyne_fe2o3_core::{ |
| 4 | prelude::*, |
| 5 | }; |
| 6 | use oxedyne_fe2o3_crypto::{ |
| 7 | keys::{ |
| 8 | PublicKey, |
| 9 | SecretKey, |
| 10 | }, |
| 11 | scheme::SchemeTimestamp, |
| 12 | }; |
| 13 | use oxedyne_fe2o3_hash::pow::ZeroBits; |
| 14 | use oxedyne_fe2o3_jdat::id::{ |
| 15 | IdDat, |
| 16 | NumIdDat, |
| 17 | }; |
| 18 | |
| 19 | use std::{ |
| 20 | collections::{ |
| 21 | BTreeMap, |
| 22 | BTreeSet, |
| 23 | }, |
| 24 | net::{ |
| 25 | IpAddr, |
| 26 | SocketAddr, |
| 27 | }, |
| 28 | str::FromStr, |
| 29 | time::SystemTime, |
| 30 | }; |
| 31 | |
| 32 | pub struct Address; |
| 33 | |
| 34 | impl Address { |
| 35 | |
| 36 | pub fn server_address<S: Into<String> + std::fmt::Display>(addr: S, port: u16) -> String { |
| 37 | fmt!("{}:{}", addr, port) |
| 38 | } |
| 39 | |
| 40 | pub fn socket_address_udp< |
| 41 | S: Into<String> + std::fmt::Display, |
| 42 | >( |
| 43 | addr: S, |
| 44 | port: u16, |
| 45 | ) |
| 46 | -> Outcome<SocketAddr> |
| 47 | { |
| 48 | let sock_addr = SocketAddr::new(res!(IpAddr::from_str(&addr.into())), port); |
| 49 | Ok(sock_addr) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #[derive(Clone, Debug, Default)] |
| 54 | pub struct AddressData { |
| 55 | pub my_zbits: ZeroBits, |
| 56 | pub your_zbits: ZeroBits, |
| 57 | pub pending: Option<(HandshakeType, SystemTime)>, |
| 58 | } |
| 59 | |
| 60 | impl AsMut<AddressData> for AddressData { |
| 61 | fn as_mut(&mut self) -> &mut AddressData { |
| 62 | self |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #[derive(Clone, Debug, Default)] |
| 67 | pub struct UserData< |
| 68 | const SIDL: usize, |
| 69 | const C: usize, |
| 70 | SID: NumIdDat<SIDL>, |
| 71 | > { |
| 72 | pub sigtpk_opt: Option<PublicKey>, // My record of your current public signing key. |
| 73 | pub sigtpk_opt_old: Option<PublicKey>, // My record of your old public signing key. |
| 74 | pub waiting_for_sigpk: bool, |
| 75 | pub sessions: BTreeMap<IdDat<SIDL, SID>, SecretKey>, |
| 76 | pub code: Option<[u8; C]>, |
| 77 | pub pack_sigpk_set: BTreeSet<PublicKey>, |
| 78 | pub pack_sigpk_map: BTreeMap<SchemeTimestamp, Vec<u8>>, |
| 79 | pub sign_pack_this: Option<Vec<u8>>, |
| 80 | } |