From bd9ddca0ceb4e5ad1a58306994d8b88c053105ee Mon Sep 17 00:00:00 2001 From: Yureka Date: Thu, 18 Jan 2024 14:36:53 +0100 Subject: [PATCH] resolve asn names --- src/api.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/api.rs b/src/api.rs index 694395e..ac423c0 100644 --- a/src/api.rs +++ b/src/api.rs @@ -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`. @@ -114,6 +118,7 @@ async fn query( // for deduplicating the nexthop resolutions let mut have_resolved = HashSet::new(); + let mut have_asn = HashSet::new(); let stream = store .get_routes(query) @@ -142,6 +147,22 @@ async fn query( })) } } + 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 })