@ndn/autoconfig
This package is part of NDNts, Named Data Networking libraries for the modern web.
This package enables connection to global NDN testbed using NDN-FCH service.
import { queryFch, connectToTestbed } from "@ndn/autoconfig";
import { Endpoint } from "@ndn/endpoint";
import { Forwarder } from "@ndn/fw";
import { Name } from "@ndn/packet";
import { strict as assert } from "assert";
(async () => {
if (process.env.CI) { return; }
Query NDN-FCH Service
queryFch
function sends a query to NDN-FCH service.
let hosts = await queryFch();
assert.equal(hosts.length, 1);
console.log("closest HUB", hosts);
hosts = await queryFch({ count: 4 });
assert(hosts.length > 1);
console.log("four routers", hosts);
hosts = await queryFch({ capabilities: ["wss"] });
console.log("supports secure WebSocket", hosts);
hosts = await queryFch({ position: [121.403351, 31.007990] });
console.log("near @yoursunny's birthplace", hosts);
Connect to Testbed
const fw = Forwarder.create();
let faces = await connectToTestbed({
count: 4,
fw,
tryDefaultGateway: true,
fchFallback: ["hobo.cs.arizona.edu", "titan.cs.memphis.edu"],
});
assert(faces.length > 0);
faces.forEach((face) => {
console.log("connected to", `${face}`);
face.close();
});
faces = await connectToTestbed({
count: 4,
fw,
preferFastest: true,
connectTimeout: 3000,
testConnection: new Name(`/ndn/edu/arizona/ping/${Math.floor(Math.random() * 1e9)}`),
tryDefaultGateway: false,
});
assert.equal(faces.length, 1);
const [fastestFace] = faces;
console.log("fastest face is", `${fastestFace}`);
await new Endpoint({ fw }).consume(`/ndn/edu/ucla/ping/${Math.floor(Math.random() * 1e9)}`);
fastestFace.close();
})();