pub struct Dictionary {
pub attributes: HashMap<u32, RadiusAttributeDef>,
pub vendors: HashMap<String, u32>,
}Fields§
§attributes: HashMap<u32, RadiusAttributeDef>§vendors: HashMap<String, u32>Implementations§
Source§impl Dictionary
impl Dictionary
Sourcepub fn load_embedded() -> Result<Self, String>
pub fn load_embedded() -> Result<Self, String>
Examples found in repository?
examples/server.rs (line 11)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let dict = Arc::new(Dictionary::load_embedded()?);
12 let secret = "test123";
13
14 let dict_acct = dict.clone();
15 let dict_auth = dict.clone();
16 let secret_acct = secret.to_string();
17 let secret_auth = secret.to_string();
18
19 let acct_server = serve_accounting_async("0.0.0.0:1813", dict_acct, &secret_acct, move |packet| async move {
20 println!("📨 Accounting ID {} from {:?}", packet.identifier, packet.username());
21 for attr in packet.attributes {
22 println!(" → Type {}: {:?}", attr.typ, attr.value);
23 }
24 Ok(())
25 });
26
27 let auth_server = serve_async("0.0.0.0:1812", dict_auth, &secret_auth, move |packet| async move {
28 println!("🔍 Incoming ID {} from {:?}", packet.identifier, packet.username());
29
30 if let Some(username) = packet.username() {
31 if username.trim() == "ec:30:b3:6d:24:6a" {
32 Ok(packet.reply_accept(vec![
33 RadiusAttribute::session_timeout(3600),
34 RadiusAttribute::reply_message("Welcome, admin."),
35 ]))
36 } else {
37 Ok(packet.reply_reject("User not allowed"))
38 }
39 } else {
40 Ok(packet.reply_reject("Missing username"))
41 }
42 });
43
44 // Run both servers concurrently
45 tokio::try_join!(acct_server, auth_server)?;
46
47 Ok(())
48}pub fn parse_from_str(content: &str) -> Result<Self, String>
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self, String>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Dictionary
impl RefUnwindSafe for Dictionary
impl Send for Dictionary
impl Sync for Dictionary
impl Unpin for Dictionary
impl UnwindSafe for Dictionary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more