mirror of
https://git.alemi.dev/fedicharter.git
synced 2024-11-23 00:44:48 +01:00
fix: shortcircuit bug when missing metadata
This commit is contained in:
parent
e4b42c7aa9
commit
5adeda80ca
1 changed files with 27 additions and 23 deletions
50
src/main.rs
50
src/main.rs
|
@ -51,48 +51,52 @@ async fn route_crawl_domain(Query(params): Query<Params>) -> Json<MapResult> {
|
||||||
axum::Json(collector.collect().await)
|
axum::Json(collector.collect().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[async_recursion::async_recursion]
|
#[async_recursion::async_recursion]
|
||||||
async fn scan_instance(domain: &str, map: MapHandle) -> Option<()> {
|
async fn scan_instance(domain: &str, map: MapHandle) {
|
||||||
if map.already_scanned(domain).await { return None };
|
if map.already_scanned(domain).await { return };
|
||||||
|
|
||||||
tracing::debug!("scanning instance {}", domain);
|
tracing::debug!("scanning instance {}", domain);
|
||||||
let response = match CACHE.instance_metadata(domain).await {
|
let response = match CACHE.instance_metadata(domain).await {
|
||||||
Ok(Some(r)) => r,
|
Ok(Some(r)) => r,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
tracing::info!("instance {} doesn't provide metadata", domain);
|
tracing::info!("instance {} doesn't provide nodeinfo api", domain);
|
||||||
map.add_node(domain.to_string(), domain.to_string());
|
return map.add_node(domain.to_string(), domain.to_string());
|
||||||
return None
|
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::warn!("could not fetch metadata for {}: {}", domain, e);
|
return tracing::warn!("could not fetch metadata for {}: {}", domain, e);
|
||||||
return None
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let node_name : String = response
|
let metadata = match response.get("metadata") {
|
||||||
.get("metadata")?
|
Some(m) => m,
|
||||||
.get("nodeName")?
|
None => {
|
||||||
.as_str()?
|
tracing::info!("instance {} doesn't provide metadata", domain);
|
||||||
.to_string();
|
return map.add_node(domain.to_string(), domain.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
tracing::info!("adding instance {}", node_name);
|
let node_name = match metadata.get("nodeName") {
|
||||||
|
Some(v) => v.as_str().unwrap_or("").to_string(),
|
||||||
|
None => domain.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
tracing::info!("adding instance {} ({})", node_name, domain);
|
||||||
|
|
||||||
map.add_node(domain.to_string(), node_name);
|
map.add_node(domain.to_string(), node_name);
|
||||||
|
|
||||||
|
let local_bubble = match metadata.get("localBubbleInstances") {
|
||||||
|
None => return tracing::info!("instance {} doesn't provide local bubble data", domain),
|
||||||
|
Some(b) => match b.as_array() {
|
||||||
|
None => return tracing::warn!("instance {} local bubble is not an array", domain),
|
||||||
|
Some(v) => v,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let mut tasks = Vec::new();
|
let mut tasks = Vec::new();
|
||||||
|
|
||||||
for bubble_instance in response
|
for bubble_instance in local_bubble.iter().filter_map(|x| x.as_str().map(|x| x.to_string())) {
|
||||||
.get("metadata")?
|
|
||||||
.get("localBubbleInstances")?
|
|
||||||
.as_array()?
|
|
||||||
.iter()
|
|
||||||
.filter_map(|x| x.as_str().map(|x| x.to_string()))
|
|
||||||
{
|
|
||||||
let _map = map.clone();
|
let _map = map.clone();
|
||||||
map.add_vertex(domain.to_string(), bubble_instance.clone());
|
map.add_vertex(domain.to_string(), bubble_instance.clone());
|
||||||
tasks.push(tokio::spawn(async move { scan_instance(&bubble_instance, _map).await; }));
|
tasks.push(tokio::spawn(async move { scan_instance(&bubble_instance, _map).await; }));
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue