net186-as-set/src/bgpq4.ts

22 lines
554 B
TypeScript

import { execFile } from "node:child_process";
import LRUCache from "lru-cache";
const cache = new LRUCache({
max: 500,
ttl: 1000 * 60 * 5,
});
export default async function bgpq4(asSet: string): Promise<number[]> {
if (cache.has(asSet)) return cache.get(asSet) as number[];
const answer: { as: number[] } = await new Promise((resolve) => {
execFile("bgpq4", ["-tjl", "as", "-L", "6", asSet], (error, stdout) => {
if (error) {
throw error;
}
resolve(JSON.parse(stdout));
});
});
cache.set(asSet, answer.as);
return answer.as;
}