mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-10-24 06:12:38 +00:00
Inject router in API State
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
2 files changed
+7
-1
No files matched your search
@@ -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
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user