Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_shield/tests/msg.rs

3.6 KiB, 16 runs

created by r1870400018:898, 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 oxedyne_fe2o3_shield::{
2// cfg::ServerConfig,
3// core::Shield,
4// guard::{
5// data::UserData,
6// user::{
7// UserLog,
8// UserState,
9// },
10// },
11// msg::syntax,
12//};
13//
14//use oxedyne_fe2o3_bot::id::BotId;
15//use oxedyne_fe2o3_core::{
16// prelude::*,
17// rand::Rand,
18//};
19//use oxedyne_fe2o3_crypto::{
20// enc::EncryptionScheme,
21// sign::SignatureScheme,
22//};
23//use oxedyne_fe2o3_hash::{
24// csum::ChecksumScheme,
25// hash::HashScheme,
26//};
27//use oxedyne_fe2o3_net::id::{
28// MessageId,
29// SessionId,
30// UserId,
31//};
32//
33//use std::{
34// mem,
35// sync::Arc,
36// time::Duration,
37//};
38//
39//use base64;
40//
41//pub fn test_msg(_filter: &'static str) -> Outcome<()> {
42//
43// const POW_ZBITS: u16 = 5;
44//
45// pub type MidTyp = u64; // Message Id
46// pub type SidTyp = u64; // Session Id
47// pub type UidTyp = u128; // User Id
48//
49// const MID_LEN: usize = mem::size_of::<MidTyp>();
50// const SID_LEN: usize = mem::size_of::<SidTyp>();
51// const UID_LEN: usize = mem::size_of::<UidTyp>();
52//
53// pub type Mid = MessageId<{MID_LEN}, MidTyp>;
54// pub type Sid = SessionId<{SID_LEN}, SidTyp>;
55// pub type Uid = UserId<{UID_LEN}, UidTyp>;
56//
57// let server_id = BotId(Rand::rand_u64());
58// let chunk_cfg = ServerConfig::new_chunk_cfg(1_000, 200, true, true);
59// let syntax = res!(ServerConfig::syntax_default());
60// let shield_params = Shield::params(
61// [0u8; 8],
62// Mid::default(),
63// Sid::default(),
64// Uid::default(),
65// server_id,
66// None::<EncryptionScheme>,
67// None::<ChecksumScheme>,
68// None::<HashScheme>,
69// Some(SignatureScheme::new_ed25519()),
70// None::<EncryptionScheme>,
71// Some(chunk_cfg),
72// syntax.clone(),
73// );
74// let (shield, server) = res!(Shield::new(
75// None::<&str>,
76// shield_params,
77// ));
78//
79// // Add a user.
80// const TEST_USER: Uid = UserId(1);
81// const TEST_USER_SECRET_POW_CODE: [u8; 8] = [0x03, 0x48, 0x9f, 0x6a, 0xd4, 0x86, 0xe3, 0x35];
82// // The code can also be distributed to the user alphanumerically.
83// test!("Code: {:02x?}", TEST_USER_SECRET_POW_CODE);
84// let code_string_std_no_pad = base64::encode_config(TEST_USER_SECRET_POW_CODE, base64::STANDARD_NO_PAD);
85// test!("Code [std_no_pad]: '{}'", code_string_std_no_pad);
86// let code_from_std_no_pad = base64::decode_config(code_string_std_no_pad, base64::STANDARD_NO_PAD);
87// test!("Code [std_no_pad]: {:02x?}", code_from_std_no_pad);
88//
89// let (key, locked_map) = res!(shield.user_guard.get_locked_map(&TEST_USER));
90// {
91// let mut unlocked_map = lock_write!(locked_map);
92// let ulog = UserLog {
93// state: UserState::Whitelist,
94// data: UserData {
95// code: Some(TEST_USER_SECRET_POW_CODE),
96// ..Default::default()
97// },
98// };
99// unlocked_map.insert(key, ulog);
100// }
101//
102// res!(shield.start(server));
103//
104// // Now send messages to the server.
105// {
106//
107// let msg_builder = res!(shield.msg_builder_default(
108// TEST_USER_SECRET_POW_CODE,
109// POW_ZBITS,
110// ));
111//
112// res!(syntax::HReq1::send(
113// syntax.clone(),
114// &msg_builder,
115// None::<Mid>,
116// None::<Sid>,
117// Uid::new(1),
118// ));
119//
120// thread::sleep(Duration::from_secs(3));
121//
122// for line in oxedyne_fe2o3_text::string::to_lines(fmt!("{:?}", shield.user_guard), " ") {
123// debug!("{}", line);
124// }
125//
126// }
127//
128// Ok(())
129//}