Skip to content

Commit

Permalink
remove mutex and use u16 type for port
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Oct 20, 2024
1 parent 358ac58 commit af13562
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
9 changes: 1 addition & 8 deletions fl-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct AppState {
#[derive(Debug, Default, Clone, Deserialize)]
pub struct Config {
pub host: String,
pub port: usize,
pub port: u16,
pub store_url: Vec<String>,
pub flist_dir: String,

Expand All @@ -45,13 +45,6 @@ pub async fn parse_config(filepath: &str) -> Result<Config> {
anyhow::bail!("host '{}' is invalid", c.host)
}

if c.port > 65535 {
anyhow::bail!(format!(
"port '{}' is invalid, must be between [0, 65535]",
c.port
))
}

rfs::store::parse_router(&c.store_url)
.await
.context("failed to parse store urls")?;
Expand Down
21 changes: 7 additions & 14 deletions fl-server/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Mutex};
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
Expand All @@ -15,29 +15,22 @@ pub trait DB: Send + Sync {

#[derive(Debug, ToSchema)]
pub struct MapDB {
users: Mutex<HashMap<String, User>>,
users: HashMap<String, User>,
}

impl MapDB {
pub fn new(users: &[User]) -> Self {
Self {
users: Mutex::new(
users
.to_vec()
.iter()
.map(|u| (u.username.clone(), u.to_owned()))
.collect(),
),
users: users
.iter()
.map(|u| (u.username.clone(), u.to_owned()))
.collect(),
}
}
}

impl DB for MapDB {
fn get_user_by_username(&self, username: &str) -> Option<User> {
self.users
.lock()
.expect("failed to lock users map")
.get(username)
.cloned()
self.users.get(username).cloned()
}
}

0 comments on commit af13562

Please sign in to comment.