mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-10-23 06:01:16 +00:00
Expose API handler to list fallback routes
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
1 file changed
+25
+25
@@ -103,6 +103,7 @@ impl Http {
|
||||
let admin_routes = Router::new()
|
||||
.route("/admin/peers", get(get_peers))
|
||||
.route("/admin/routes/selected", get(get_selected_routes))
|
||||
.route("/admin/routes/fallback", get(get_fallback_routes))
|
||||
.with_state(server_state.clone());
|
||||
let msg_routes = Router::new()
|
||||
.route("/messages", get(get_message).post(push_message))
|
||||
@@ -373,6 +374,30 @@ async fn get_selected_routes(State(state): State<HttpServerState>) -> Json<Vec<R
|
||||
Json(routes)
|
||||
}
|
||||
|
||||
/// List all active fallback routes.
|
||||
async fn get_fallback_routes(State(state): State<HttpServerState>) -> Json<Vec<Route>> {
|
||||
debug!("Loading fallback routes");
|
||||
let routes = state
|
||||
.router
|
||||
.lock()
|
||||
.unwrap()
|
||||
.load_fallback_routes()
|
||||
.into_iter()
|
||||
.map(|sr| Route {
|
||||
subnet: sr.source().subnet().to_string(),
|
||||
next_hop: sr.neighbour().connection_identifier().clone(),
|
||||
metric: if sr.metric().is_infinite() {
|
||||
Metric::Infinite
|
||||
} else {
|
||||
Metric::Value(sr.metric().into())
|
||||
},
|
||||
seqno: sr.seqno().into(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Json(routes)
|
||||
}
|
||||
|
||||
impl Serialize for Metric {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
||||
Reference in new issue
Block a user