Skip to content

Commit

Permalink
resolve asn names
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyuyureka committed Jan 18, 2024
1 parent d4904e1 commit bd9ddca
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub enum ApiResult {
nexthop: IpAddr,
nexthop_resolved: ResolvedNexthop,
},
AsnName {
asn: u32,
asn_name: String,
},
}

// Make our own error that wraps `anyhow::Error`.
Expand Down Expand Up @@ -114,6 +118,7 @@ async fn query<T: Store>(

// for deduplicating the nexthop resolutions
let mut have_resolved = HashSet::new();
let mut have_asn = HashSet::new();

let stream = store
.get_routes(query)
Expand Down Expand Up @@ -142,6 +147,22 @@ async fn query<T: Store>(
}))
}
}
for asn in route.attrs.as_path.into_iter().flat_map(|x| x) {
if have_asn.insert(asn) {
let resolver = resolver.clone();
futures.push(Box::pin(async move {
resolver
.txt_lookup(format!("as{}.asn.cymru.com.", asn))
.await
.ok()
.and_then(|txt| txt.iter().next().map(|x| x.to_string()))
.map(|asn_name| ApiResult::AsnName {
asn,
asn_name,
})
}))
}
}

futures
})
Expand Down

0 comments on commit bd9ddca

Please sign in to comment.