Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions members/nullnet-server/src/http_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub async fn serve(state: AppState) {
.with_state(state);

let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), HTTP_PORT);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
let listener = tokio::net::TcpListener::bind(addr)
.await
.expect("failed to bind HTTP listener");
axum::serve(listener, app).await.expect("HTTP server error");
}
4 changes: 2 additions & 2 deletions members/nullnet-server/src/http_server/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ struct PoolJson {
}

pub(super) async fn pool_handler(State(state): State<AppState>) -> impl IntoResponse {
let (total, in_use, free) = state.orchestrator.pool_stats().await;
let (total, in_use) = state.orchestrator.pool_stats().await;
axum::Json(PoolJson {
total,
in_use,
free,
free: total - in_use,
})
}
21 changes: 13 additions & 8 deletions members/nullnet-server/src/net_id_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ impl NetIdPool {
}
}

/// Returns (total_capacity, in_use, free).
pub(crate) fn stats(&self) -> (u32, u32, u32) {
/// Returns (total_capacity, in_use).
pub(crate) fn stats(&self) -> (u32, u32) {
let capacity = *MAX_NET_ID - MIN_NET_ID + 1;
let in_use = (self.next_fresh - MIN_NET_ID) - self.freed.len() as u32;
(capacity, in_use, capacity - in_use)
(capacity, in_use)
}
}

Expand Down Expand Up @@ -134,7 +134,8 @@ mod tests {
#[test]
fn test_stats_fresh_pool() {
let pool = NetIdPool::new();
let (total, in_use, free) = pool.stats();
let (total, in_use) = pool.stats();
let free = total - in_use;
assert!(total > 0);
assert_eq!(in_use, 0);
assert_eq!(free, total);
Expand All @@ -146,7 +147,8 @@ mod tests {
pool.allocate();
pool.allocate();
pool.allocate();
let (total, in_use, free) = pool.stats();
let (total, in_use) = pool.stats();
let free = total - in_use;
assert_eq!(in_use, 3);
assert_eq!(free, total - 3);
}
Expand All @@ -158,7 +160,8 @@ mod tests {
pool.allocate();
pool.allocate();
pool.free(id);
let (total, in_use, free) = pool.stats();
let (total, in_use) = pool.stats();
let free = total - in_use;
assert_eq!(in_use, 2);
assert_eq!(free, total - 2);
}
Expand All @@ -167,7 +170,8 @@ mod tests {
fn test_stats_exhausted_pool() {
let mut pool = NetIdPool::new();
pool.next_fresh = *MAX_NET_ID + 1;
let (total, in_use, free) = pool.stats();
let (total, in_use) = pool.stats();
let free = total - in_use;
assert_eq!(in_use, total);
assert_eq!(free, 0);
}
Expand All @@ -179,7 +183,8 @@ mod tests {
let id = pool.allocate().unwrap();
pool.allocate();
pool.free(id);
let (total, in_use, free) = pool.stats();
let (total, in_use) = pool.stats();
let free = total - in_use;
assert_eq!(total, in_use + free);
}
}
4 changes: 2 additions & 2 deletions members/nullnet-server/src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ impl Orchestrator {
}

pub(crate) async fn connected_node_ips(&self) -> Vec<IpAddr> {
self.clients.read().await.keys().cloned().collect()
self.clients.read().await.keys().copied().collect()
}

pub(crate) async fn pool_stats(&self) -> (u32, u32, u32) {
pub(crate) async fn pool_stats(&self) -> (u32, u32) {
self.net_id_pool.lock().await.stats()
}

Expand Down