donet_core/
globals.rs

1/*
2    This file is part of Donet.
3
4    Copyright © 2024 Max Rodriguez
5
6    Donet is free software; you can redistribute it and/or modify
7    it under the terms of the GNU Affero General Public License,
8    as published by the Free Software Foundation, either version 3
9    of the License, or (at your option) any later version.
10
11    Donet is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    GNU Affero General Public License for more details.
15
16    You should have received a copy of the GNU Affero General Public
17    License along with Donet. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Includes definitions of type aliases for Donet concepts,
21//! and the full definition of the network protocol message types.
22
23use super::protocol::*;
24use cfg_if::cfg_if;
25use std::mem;
26
27// ---------- Type Definitions --------- //
28
29pub type MsgType = u16;
30pub type DgSizeTag = u16;
31pub type Channel = u64;
32pub type DoId = u32;
33pub type Zone = u32;
34pub type DClassId = u16;
35pub type FieldId = u16;
36pub type DCFileHash = u32; // 32-bit hash
37
38/// Impl converting protocol enumerator to u16 (MsgType)
39impl From<Protocol> for MsgType {
40    fn from(value: Protocol) -> Self {
41        value as MsgType
42    }
43}
44
45// ---------- Type Limits ---------- //
46
47pub const DG_SIZE_MAX: DgSizeTag = u16::MAX;
48pub const CHANNEL_MAX: Channel = u64::MAX;
49pub const DOID_MAX: DoId = u32::MAX;
50pub const ZONE_MAX: Zone = u32::MAX;
51pub const ZONE_BITS: usize = 8 * mem::size_of::<Zone>();
52
53// ---------- Constants ---------- //
54
55pub const INVALID_DOID: DoId = 0;
56pub const INVALID_CHANNEL: Channel = 0;
57pub const CONTROL_CHANNEL: Channel = 1;
58pub const BCHAN_CLIENTS: Channel = 10;
59pub const BCHAN_STATESERVERS: Channel = 12;
60pub const BCHAN_DBSERVERS: Channel = 13;
61
62// ---------- DC File Feature ---------- //
63
64cfg_if! {
65    if #[cfg(feature = "dcfile")] {
66        // DC File Constants
67        pub static HISTORICAL_DC_KEYWORDS: &[&str] = &[
68            "ram", "required", "db", "airecv", "ownrecv",
69            "clrecv", "broadcast", "ownsend", "clsend",
70        ];
71        pub static DC_VIEW_SUFFIXES: &[&str] = &["AI", "OV", "UD"];
72        pub static MAX_PRIME_NUMBERS: u16 = 10000;
73    }
74}
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn msgtype_from_impl() {
82        assert_eq!(MsgType::from(Protocol::MDRemoveChannel), 9001);
83        assert_eq!(MsgType::from(Protocol::CAAddInterest), 1200);
84        assert_eq!(MsgType::from(Protocol::SSDeleteAIObjects), 2009);
85    }
86}