Inject router in API State

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet committed 2024-02-26 12:00:49 +01:00
1 parent 1fb8e0ec55
commit 08c58645ec
2 files changed
+7 -1

No files matched your search

+6
View File
@@ -1,6 +1,7 @@
use std::{
net::{IpAddr, SocketAddr},
ops::Deref,
sync::{Arc, Mutex},
time::Duration,
};
@@ -31,7 +32,10 @@ pub struct Http {
}
#[derive(Clone)]
/// Shared state accessible in HTTP endpoint handlers.
struct HttpServerState {
/// Access to the (`Router`)(crate::router::Router) state. This is only meant as read only view.
router: Arc<Mutex<crate::router::Router>>,
/// Access to the connection state of (`Peer`)[crate::peer::Peer]s.
peer_manager: PeerManager,
/// Access to messages.
@@ -86,11 +90,13 @@ impl MessageDestination {
impl Http {
/// Spawns a new HTTP API server on the provided listening address.
pub fn spawn(
router: crate::router::Router,
peer_manager: PeerManager,
message_stack: MessageStack,
listen_addr: &SocketAddr,
) -> Self {
let server_state = HttpServerState {
router: Arc::new(Mutex::new(router)),
peer_manager,
message_stack,
};
+1 -1
View File
@@ -161,7 +161,7 @@ impl Stack {
let ms = MessageStack::new(data_plane, msg_receiver);
let api = Http::spawn(pm.clone(), ms.clone(), &config.api_addr);
let api = Http::spawn(router.clone(), pm.clone(), ms.clone(), &config.api_addr);
Ok(Stack {
_router: router,