diff --git a/frontend/src/cache.js b/frontend/src/cache.js index a729eb9..cf8d60a 100644 --- a/frontend/src/cache.js +++ b/frontend/src/cache.js @@ -1,8 +1,4 @@ export let routers; -export let communities; export const initCache = async () => { - [routers, communities] = await Promise.all([ - fetch("/api/routers").then(resp => resp.json()), - fetch("/communities.json").then(resp => resp.json()) - ]); + routers = await fetch("/api/routers").then(resp => resp.json()); }; diff --git a/frontend/src/resultsView.js b/frontend/src/resultsView.js index 8a43be5..7fa0700 100644 --- a/frontend/src/resultsView.js +++ b/frontend/src/resultsView.js @@ -2,16 +2,16 @@ import { html, render } from 'lit-html'; import { go } from './router.js'; import { searchTemplate } from './search.js'; import ndjsonStream from 'can-ndjson-stream'; -import { routers, communities } from './cache.js'; +import { routers } from './cache.js'; -const resultTemplate = (result, havePeerColumn, asn_names) => html` +const resultTemplate = (result, havePeerColumn, dnsMap, asnMap, communityMap) => html` ${result.client_name} ${havePeerColumn ? html`${result.peer_address}` : ``} ${result.net} ${result.as_path.map(asn => html` - ${asn_names[asn] !== undefined - ? html`${asn}` + ${asn in asnMap + ? html`${asn}` : html`${asn}`} `)} ${[ @@ -19,8 +19,8 @@ const resultTemplate = (result, havePeerColumn, asn_names) => html` ...(result.communities || []) ] .map(community => community.join(":")) - .map(community => community in communities - ? html`
${communities[community]}
` + .map(community => community in communityMap + ? html`
${communityMap[community]}
` : html`
${community}
` ) }
@@ -28,15 +28,15 @@ const resultTemplate = (result, havePeerColumn, asn_names) => html` ${result.med} ${result.local_pref} - ${result?.nexthop_resolved?.ReverseDns !== undefined - ? html`${result?.nexthop_resolved?.ReverseDns}` + ${result.nexthop in dnsMap + ? html`${dnsMap[result.nexthop]}` : html`${result.nexthop}`} ${result.state} `; -const resultsTemplate = (query, { routeResults, asn_names }, done) => html` +const resultsTemplate = (query, { routeResults, dnsMap, asnMap, communityMap }, done) => html` ${searchTemplate(query)}
@@ -57,7 +57,7 @@ const resultsTemplate = (query, { routeResults, asn_names }, done) => html` - ${routeResults.map(result => resultTemplate(result, routeResults.some(result => result.peer_address), asn_names))} + ${routeResults.map(result => resultTemplate(result, routeResults.some(result => result.peer_address), dnsMap, asnMap, communityMap))} ` : ''} @@ -82,9 +82,13 @@ const processResults = (results) => { const routeResults = results.filter(r => !!r.Route).map(r => r.Route); const dnsResults = results.filter(r => !!r.ReverseDns).map(r => r.ReverseDns); const asnResults = results.filter(r => !!r.AsnName).map(r => r.AsnName); + const communityResults = results.filter(r => !!r.CommunityDescription).map(r => r.CommunityDescription); - const asn_names = Object.fromEntries(asnResults.map(r => [r.asn, r.asn_name ])); - const dnsMap = Object.fromEntries(dnsResults.map(r => [r.nexthop, { nexthop_resolved: r.nexthop_resolved }])); + const dnsMap = Object.fromEntries(dnsResults.map(r => [r.nexthop, r.nexthop_resolved])); + const asnMap = Object.fromEntries(asnResults.map(r => [r.asn, r.asn_name ])); + const communityMap = Object.fromEntries(communityResults.map(r => [r.community, r.community_description ])); + + console.log(asnMap, communityMap, dnsMap); // stage 1, combine pre- and post-policy adj-in tables // start out with PostPolicy @@ -157,14 +161,7 @@ const processResults = (results) => { return 0; }); - // add resolved nexthop data - for (const result of newResults) { - if (result.nexthop in dnsMap) { - Object.assign(result, dnsMap[result.nexthop]) - } - } - - return { routeResults: newResults, asn_names }; + return { routeResults: newResults, asnMap, communityMap, dnsMap }; }; export const resultsView = async (query) => {