oxedyne/fe2o3/fe2o3_shield/src/srv/constant.rs
6.1 KiB, 41 runs
created by r1870400018:860, 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::{ |
| 2 | cfg::ServerConfig, |
| 3 | msg::core::MsgType, |
| 4 | pow::DifficultyProfile, |
| 5 | }; |
| 6 | |
| 7 | use oxedyne_fe2o3_core::{ |
| 8 | prelude::*, |
| 9 | byte::Encoding, |
| 10 | }; |
| 11 | use oxedyne_fe2o3_jdat::{ |
| 12 | prelude::*, |
| 13 | version::SemVer, |
| 14 | }; |
| 15 | |
| 16 | use std::{ |
| 17 | mem, |
| 18 | time::Duration, |
| 19 | }; |
| 20 | |
| 21 | |
| 22 | impl ServerConfig { |
| 23 | pub fn check_constants() -> Outcome<()> { |
| 24 | //if CHECK_INTERVAL > USER_REQUEST_TIMEOUT { |
| 25 | // return Err(err!( |
| 26 | // "The prescribed constant check interval, {:?}, should not be larger than the \ |
| 27 | // constant maximum wait, {:?}.", CHECK_INTERVAL, |
| 28 | // USER_REQUEST_TIMEOUT, |
| 29 | // ), Invalid, Input)); |
| 30 | //} |
| 31 | Ok(()) |
| 32 | } |
| 33 | } |
| 34 | // |
| 35 | pub const VERSION: SemVer = SemVer::new(0, 5, 0); |
| 36 | pub const STACK_SIZE: usize = 2 * 1024 * 1024; |
| 37 | pub const UDP_BUFFER_SIZE: usize = 1_400; |
| 38 | //// Mostly completely arbitrary... |
| 39 | pub const POW_CREATE_TIMEOUT: Duration = Duration::from_secs(30); |
| 40 | pub const POW_CREATE_COUNT_LIM: usize = usize::MAX; |
| 41 | pub const POW_TIME_HORIZON_SEC: u64 = 600; |
| 42 | pub const DEFAULT_UDP_PACKET_SIZE: usize = 700; |
| 43 | pub const REQ_TIMER_LEN: usize = 100; |
| 44 | pub const MAX_ALLOWED_AVG_REQ_PER_SEC: u64 = 30; |
| 45 | pub const POW_DIFFICULTY_PROFILE: DifficultyProfile = DifficultyProfile::Linear; |
| 46 | pub const POW_MAX_ZERO_BITS: u16 = 30; |
| 47 | pub const POW_MIN_ZERO_BITS: u16 = 0; // TODO add bypass when zbits == 0 |
| 48 | pub const POW_NONCE_LEN: usize = 8; |
| 49 | pub const POW_CODE_LEN: usize = 8; |
| 50 | pub const POW_ADDR_LEN: usize = 16; |
| 51 | pub const POW_TIMESTAMP_LEN: usize = 8; |
| 52 | pub const POW_PREFIX_LEN: usize = |
| 53 | 2 * POW_ADDR_LEN |
| 54 | + POW_CODE_LEN; |
| 55 | pub const POW_PREIMAGE_LEN: usize = |
| 56 | POW_PREFIX_LEN |
| 57 | + POW_TIMESTAMP_LEN; |
| 58 | pub const POW_INPUT_LEN: usize = |
| 59 | POW_PREIMAGE_LEN |
| 60 | + POW_NONCE_LEN; |
| 61 | pub const THROTTLED_INTERVAL_MIN: Duration = Duration::from_secs(1); |
| 62 | pub const ADDR_THROTTLE_SUNSET_SECS_MIN: u64 = 1_800; // 30 min |
| 63 | pub const ADDR_THROTTLE_SUNSET_SECS_MAX: u64 = 259_200; // 3 days |
| 64 | pub const THROTTLE_COUNT_BEFORE_BLACKLIST: u16 = 10; |
| 65 | pub const SESSION_REQUEST_EXPIRY: Duration = Duration::from_secs(600); // 10 min |
| 66 | pub const PARTIAL_MESSAGE_SUNSET: Duration = Duration::from_secs(600); // 10 min |
| 67 | pub const MSG_ASSEMBLY_SUNSET: Duration = Duration::from_secs(600); |
| 68 | pub const MSG_ASSEMBLY_IDLE_MAX: Duration = Duration::from_secs(60); |
| 69 | pub const MSG_ASSEMBLY_REP_TOTAL_LIM: u8 = 128; |
| 70 | pub const MSG_ASSEMBLY_REP_PACKET_LIM: u8 = 32; |
| 71 | pub const MSG_ASSEMBLY_GC_INTERVAL: Duration = Duration::from_secs(600); |
| 72 | pub const MSG_ASSEMBLY_SHARDS: usize = 10; |
| 73 | pub const DEFAULT_MSG_ENCODING: Encoding = Encoding::Binary; |
| 74 | pub const UGRD_SHARDMAP_INIT_SHARDS: usize = 10; |
| 75 | pub const AGRD_SHARDMAP_INIT_SHARDS: usize = 10; |
| 76 | pub const GUARD_SHARDMAP_SALT_LEN: usize = 8; |
| 77 | |
| 78 | pub const SESSION_ID_KIND: Kind = Kind::U64; |
| 79 | |
| 80 | pub const MSG_TYPE_BYTE_LEN: usize = mem::size_of::<MsgType>(); |
| 81 | |
| 82 | // Application payloads ======================================================== |
| 83 | // |
| 84 | // Discriminants below `MSG_TYPE_USER_START` belong to the protocol. Two of them |
| 85 | // carry a library user's own bytes, which the protocol chunks, proofs, signs |
| 86 | // and reassembles without reading. |
| 87 | pub const MSG_TYPE_APP_REQUEST: MsgType = 1_024; |
| 88 | pub const MSG_TYPE_APP_REPLY: MsgType = 1_025; |
| 89 | pub const MSG_TYPE_USER_START: MsgType = 2_048; |
| 90 | pub const MSG_CMD_APP_REQUEST: &'static str = "app"; |
| 91 | pub const MSG_CMD_APP_REPLY: &'static str = "appr"; |
| 92 | pub const APP_REPLY_WAIT: Duration = Duration::from_secs(20); |
| 93 | pub const POW_TX_MIN_ZERO_BITS: u16 = 1; |
| 94 | |
| 95 | pub const SERVER_INT_CHANNEL_CHECK_INTERVAL: Duration = Duration::from_nanos(1_000); |
| 96 | pub const SERVER_EXT_SOCKET_CHECK_INTERVAL: Duration = Duration::from_millis(100); |
| 97 | |
| 98 | pub const SERVER_BOT_ERROR_COUNT_WARNING: usize = 10; |
| 99 | |
| 100 | pub const TRUSTED_SEEDS_MIN: usize = 3; |
| 101 | |
| 102 | // Schemes ===================================================================== |
| 103 | // Chunking. |
| 104 | // Min chunk size rationale: |
| 105 | // (Daticle::BU64 + AES_GCM) overhead, safety factor of 2 |
| 106 | pub const MIN_CHUNK_SIZE: usize = (9 + 12)*2; |
| 107 | //pub const DEFAULT_WIRE_CHUNK_BYTES: usize = 1_024; // 1 KiB |
| 108 | |
| 109 | // Hashing. |
| 110 | pub const USER_PASS_HASH_SALT_LEN: usize = 16; |
| 111 | pub const SALT8: [u8; 8] = [ |
| 112 | 0x15, 0x04, 0x84, 0x1e, 0xf2, 0x07, 0x19, 0xbc, |
| 113 | ]; |
| 114 | pub const SALT16: [u8; 16] = [ |
| 115 | 0xc9, 0x48, 0xcc, 0xbe, 0xd5, 0xd1, 0x16, 0x6c, |
| 116 | 0xc2, 0x2a, 0x78, 0x85, 0xce, 0x3e, 0x25, 0xcd, |
| 117 | ]; |
| 118 | pub const SALT32: [u8; 32] = [ |
| 119 | 0xbd, 0xd5, 0x81, 0xba, 0x0c, 0xeb, 0x4f, 0xad, |
| 120 | 0x23, 0x72, 0xd4, 0xac, 0x92, 0xeb, 0xa6, 0x6f, |
| 121 | 0xf9, 0x65, 0x4f, 0x04, 0xca, 0xd5, 0x8b, 0x73, |
| 122 | 0xb2, 0xfa, 0x72, 0x39, 0x21, 0x6b, 0x6c, 0x5f, |
| 123 | ]; |
| 124 | |
| 125 | // Credits: |
| 126 | // Image: https://ascii-generator.site/ |
| 127 | // Text: https://www.asciiart.eu/text-to-ascii-art Nancyj Improved with touch ups. |
| 128 | pub const SPLASH: &'static str = |
| 129 | r#" |
| 130 | - |
| 131 | ******* |
| 132 | ***************** |
| 133 | *************************** |
| 134 | ***=:::::::::::::::::::=*** 88888888b .o88888o. |
| 135 | ***: :+*** 88 d8' `8b |
| 136 | *******+=. .=+******* 88aaaa .d8888b. 88 88 |
| 137 | ********** ********** 88 88ooood8 d8888b. 88 88 d8888b. |
| 138 | ********= =******** 88 88. ... `88 Y8. .8P `88 |
| 139 | *****+:. .---. .:+***** dP `88888P' .aaadP' `888888P' aaad8' |
| 140 | ****+ -*****- =**** 88' `88 |
| 141 | ****---*******---**** Y88888P d88888P |
| 142 | ***************** |
| 143 | *********** |
| 144 | '"' Shield Protocol and Server |
| 145 | |
| 146 | "#; |