Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndn/autoconfig

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/autoconfig

NDNts: automatic connection establishment

  • 0.0.20191223-beta.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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";

// other imports for examples
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.

// The simplest query:
let hosts = await queryFch();
assert.equal(hosts.length, 1);
console.log("closest HUB", hosts);

// Ask for multiple routers:
hosts = await queryFch({ count: 4 });
assert(hosts.length > 1);
console.log("four routers", hosts);

// Ask for secure WebSocket capability:
hosts = await queryFch({ capabilities: ["wss"] });
console.log("supports secure WebSocket", hosts);

// Ask for router at specific location:
hosts = await queryFch({ position: [121.403351, 31.007990] });
console.log("near @yoursunny's birthplace", hosts);

Connect to Testbed

const fw = Forwarder.create();

// Create up to four faces, and consider default IPv4 gateway as a candidate.
// In case NDN-FCH is unavailable, use a list of backup routers.
let faces = await connectToTestbed({
  count: 4,
  fw,
  tryDefaultGateway: true,
  fchFallback: ["hobo.cs.arizona.edu", "titan.cs.memphis.edu"],
});
assert(faces.length >= 1);
faces.forEach((face) => {
  console.log("connected to", `${face}`);
  face.close();
});

// Try up to four candidates with 3-second timeout, and keep the fastest face only.
faces = await connectToTestbed({
  count: 4,
  fw,
  preferFastest: true,
  connectTimeout: 3000,
  testConnection: new Name(`/ndn/edu/arizona/ping/${Math.floor(Math.random() * 99999999)}`),
  tryDefaultGateway: false,
});
assert.equal(faces.length, 1);
faces.forEach((face) => {
  console.log("fastest face is", `${face}`);
  face.close();
});
})();

Keywords

FAQs

Package last updated on 23 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc