New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ndn/autoconfig

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/autoconfig - npm Package Compare versions

Comparing version 0.0.20240113 to 0.0.20240630

2

lib/fch_browser.js
import { Name } from "@ndn/packet";
import { FCH_DEFAULTS, fetch } from "./platform_browser.js";
import { FCH_DEFAULTS } from "./platform_browser.js";
/** FCH service query. */

@@ -4,0 +4,0 @@ export async function fchQuery(req = {}) {

import { Name } from "@ndn/packet";
import { FCH_DEFAULTS, fetch } from "./platform_node.js";
import { FCH_DEFAULTS } from "./platform_node.js";
/** FCH service query. */

@@ -4,0 +4,0 @@ export async function fchQuery(req = {}) {

@@ -10,7 +10,12 @@ import { Name } from "@ndn/packet";

export interface FchRequest {
/** FCH service URI. */
/**
* FCH service URI.
* @defaultValue https://fch.ndn.today
*/
server?: string;
/**
* Transport protocol, such as "udp".
* Ignored if `transports` is specified.
*
* @remarks
* Ignored if `.transports` is specified.
*/

@@ -20,2 +25,4 @@ transport?: string;

* Number of routers.
*
* @remarks
* Ignored if `transports` is a Record.

@@ -26,2 +33,4 @@ */

* Transport protocols.
*
* @remarks
* If this is an array of transport protocols, the quantity of each is specified by `count`.

@@ -31,5 +40,11 @@ * If this is a Record, each key is a transport protocol and each value is the quantity.

transports?: readonly string[] | Record<string, number>;
/** IPv4 allowed? */
/**
* IPv4 allowed?
* @defaultValue auto detect
*/
ipv4?: boolean;
/** IPv6 allowed? */
/**
* IPv6 allowed?
* @defaultValue auto detect
*/
ipv6?: boolean;

@@ -36,0 +51,0 @@ /** Client geolocation. */

import type { FwFace } from "@ndn/fw";
import { type FchRequest } from "./fch.js";
import { type ConnectRouterOptions } from "./router.js";
/** {@link connectToNetwork} options. */
export interface ConnectNetworkOptions extends ConnectRouterOptions {
/**
* FCH request.
*
* Default is requesting 4 routers.
* Pass false to disable FCH.
* FCH request, or `false` to disable FCH query.
* @defaultValue `{ count: 4 }`
*/

@@ -14,7 +13,15 @@ fch?: FchRequest | false;

* Whether to try HTTP/3 before all other options.
* Default is false.
* @defaultValue false
*
* @remarks
* Ignored if H3Transport is not enabled or supported.
*/
preferH3?: boolean;
/** Consider default IPv4 gateway as a candidate. */
/**
* Whether to consider default IPv4 gateway as a candidate.
* @defaultValue true
*
* @remarks
* This option has no effect if IPv4 gateway cannot be determined, e.g. in browser.
*/
tryDefaultGateway?: boolean;

@@ -26,3 +33,3 @@ /** Fallback routers, used if FCH and default gateway are both unavailable. */

* Faces are ranked by shortest testConnection duration.
* Default is 1.
* @defaultValue 1
*/

@@ -29,0 +36,0 @@ fastest?: number;

import type { FwFace } from "@ndn/fw";
import type { PlatformFchDefaults } from "./fch.js";
import type { ConnectRouterOptions } from "./router.js";
export declare const fetch: typeof globalThis.fetch;
export declare const FCH_DEFAULTS: PlatformFchDefaults;
export declare function getDefaultGateway(): Promise<string>;
export declare function createFace(router: string, { fw, H3Transport, mtu, connectTimeout, addRoutes, }: ConnectRouterOptions): Promise<FwFace>;
import { WsTransport } from "@ndn/ws-transport";
export const fetch = globalThis.fetch;
export const FCH_DEFAULTS = {

@@ -33,3 +32,3 @@ transports({ H3Transport } = {}) {

}
return H3Transport.createFace({ fw, addRoutes, lp: { mtu } }, uri.toString());
return H3Transport.createFace({ fw, addRoutes, lp: { mtu } }, uri.toString(), { connectTimeout });
}

@@ -36,0 +35,0 @@ default: {

import type { FwFace } from "@ndn/fw";
import type { PlatformFchDefaults } from "./fch.js";
import type { ConnectRouterOptions } from "./router.js";
export declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
export declare const FCH_DEFAULTS: PlatformFchDefaults;
export declare function getDefaultGateway(): Promise<string>;
export declare function createFace(router: string, { fw, preferTcp, mtu, connectTimeout, addRoutes, }: ConnectRouterOptions): Promise<FwFace>;

@@ -1,7 +0,3 @@

import * as os from "node:os";
import os from "node:os";
import { splitHostPort, TcpTransport, UdpTransport } from "@ndn/node-transport";
import nodeFetch from "node-fetch";
export function fetch(input, init) {
return nodeFetch(input, init);
}
function hasAddressFamily(want) {

@@ -8,0 +4,0 @@ return Object.values(os.networkInterfaces()).some((addrs) => addrs?.some((addr) => addr.family === want && !addr.internal));

@@ -1,2 +0,2 @@

import { Endpoint } from "@ndn/endpoint";
import { consume } from "@ndn/endpoint";
import { TapFace } from "@ndn/fw";

@@ -36,4 +36,4 @@ import { Interest, Name } from "@ndn/packet";

const abort = new AbortController();
const cOpts = { fw: tapFace.fw, signal: abort.signal };
try {
const endpoint = new Endpoint({ fw: tapFace.fw, signal: abort.signal });
await Promise.any(tc.map((pkt) => {

@@ -45,3 +45,3 @@ if (typeof pkt === "string" && pkt.endsWith("/*")) {

new Interest(pkt, Interest.CanBePrefix, Interest.Lifetime(testConnectionTimeout));
return endpoint.consume(interest);
return consume(interest, cOpts);
}));

@@ -48,0 +48,0 @@ }

@@ -1,2 +0,2 @@

import { Endpoint } from "@ndn/endpoint";
import { consume } from "@ndn/endpoint";
import { TapFace } from "@ndn/fw";

@@ -36,4 +36,4 @@ import { Interest, Name } from "@ndn/packet";

const abort = new AbortController();
const cOpts = { fw: tapFace.fw, signal: abort.signal };
try {
const endpoint = new Endpoint({ fw: tapFace.fw, signal: abort.signal });
await Promise.any(tc.map((pkt) => {

@@ -45,3 +45,3 @@ if (typeof pkt === "string" && pkt.endsWith("/*")) {

new Interest(pkt, Interest.CanBePrefix, Interest.Lifetime(testConnectionTimeout));
return endpoint.consume(interest);
return consume(interest, cOpts);
}));

@@ -48,0 +48,0 @@ }

@@ -5,3 +5,8 @@ import { type Forwarder, type FwFace } from "@ndn/fw";

type TestConnectionPacket = string | Name | Interest;
/** {@link connectToRouter} options. */
export interface ConnectRouterOptions {
/**
* Logical forwarder to attach faces to.
* @defaultValue `Forwarder.getDefault()`
*/
fw?: Forwarder;

@@ -11,2 +16,3 @@ /**

*
* @remarks
* This is only relevant in Node.js environment.

@@ -18,6 +24,7 @@ */

*
* @remarks
* This is only relevant in browser environment.
*
* This should be set to `H3Transport` class instance.
* It reduces browser bundle size in applications that do not use H3Transport.
* This should be set to {@link H3Transport} class instance. Having this option avoids always
* pulling in H3Transport code, to reduce browser bundle size in applications that do not use it.
*/

@@ -31,9 +38,9 @@ H3Transport?: typeof H3Transport;

* Test face connection.
* @defaultValue "/localhop/nfd/rib/list"
*
* @remarks
* - false: skip test.
* - string or Name or Interest or array: express Interest(s) and wait for any Data.
* - string or Name or Interest or array: express Interest(s) and wait for first Data reply.
* If string ends with "/*", it's replaced with a random component.
* - function: execute the custom tester function.
*
* Default is "/localhop/nfd/rib/list".
*/

@@ -43,9 +50,15 @@ testConnection?: false | TestConnectionPacket | TestConnectionPacket[] | ((face: FwFace) => Promise<unknown>);

* InterestLifetime of connection test Interest packets.
* @defaultValue 2000
*
* @remarks
* Used only if testConnection is a string or Name.
* Default is 2000.
*/
testConnectionTimeout?: number;
/** Routes to be added on the created face. Default is ["/"]. */
/**
* Routes to be added on the created face.
* @defaultValue `["/"]`
*/
addRoutes?: NameLike[];
}
/** {@link connectToRouter} result. */
export interface ConnectRouterResult {

@@ -56,3 +69,3 @@ /** Input router string. */

face: FwFace;
/** Execution duration of testConnection function. */
/** Execution duration of testConnection function (in milliseconds). */
testConnectionDuration: number;

@@ -59,0 +72,0 @@ /** Return value from custom testConnection function. */

{
"name": "@ndn/autoconfig",
"version": "0.0.20240113",
"version": "0.0.20240630",
"description": "NDNts: automatic connection establishment",

@@ -22,17 +22,16 @@ "keywords": [

"url": "https://github.com/yoursunny/NDNts.git",
"directory": "packages/autoconfig"
"directory": "pkg/autoconfig"
},
"dependencies": {
"@ndn/endpoint": "0.0.20240113",
"@ndn/fw": "0.0.20240113",
"@ndn/node-transport": "0.0.20240113",
"@ndn/packet": "0.0.20240113",
"@ndn/quic-transport": "0.0.20240113",
"@ndn/ws-transport": "0.0.20240113",
"@ndn/endpoint": "0.0.20240630",
"@ndn/fw": "0.0.20240630",
"@ndn/node-transport": "0.0.20240630",
"@ndn/packet": "0.0.20240630",
"@ndn/quic-transport": "0.0.20240630",
"@ndn/ws-transport": "0.0.20240630",
"default-gateway": "^7.2.2",
"hirestime": "^7.0.3",
"node-fetch": "^3.3.2",
"tslib": "^2.6.2"
"hirestime": "^7.0.4",
"tslib": "^2.6.3"
},
"types": "lib/mod.d.ts"
}

@@ -11,3 +11,3 @@ # @ndn/autoconfig

// other imports for examples
import { Endpoint } from "@ndn/endpoint";
import { consume } from "@ndn/endpoint";
import { Forwarder } from "@ndn/fw";

@@ -64,4 +64,2 @@ import assert from "node:assert/strict";

```ts
const fw = Forwarder.create();
// Connect to NDN network via routers in FCH response, consider default IPv4 gateway as a candidate.

@@ -71,4 +69,3 @@ // Also provide a fallback list in case the above candidates fail.

const faces = await connectToNetwork({
fw,
fallback: ["suns.cs.ucla.edu", "vnetlab.gcom.di.uminho.pt"],
fallback: ["titan.cs.memphis.edu", "vnetlab.gcom.di.uminho.pt"],
connectTimeout: 3000,

@@ -83,3 +80,3 @@ });

const t0 = Date.now();
const data = await new Endpoint({ fw }).consume(`/ndn/edu/memphis/ping/${Math.trunc(Math.random() * 1e8)}`);
const data = await consume(`/ndn/edu/memphis/ping/${Math.trunc(Math.random() * 1e8)}`);
console.log("Interest satisfied", `${data.name}`, `${Date.now() - t0}ms`);

@@ -86,0 +83,0 @@ } catch (err: unknown) {

import { fchQuery, connectToNetwork } from "@ndn/autoconfig";
// other imports for examples
import { Endpoint } from "@ndn/endpoint";
import { consume } from "@ndn/endpoint";
import { Forwarder } from "@ndn/fw";

@@ -46,4 +46,2 @@ import assert from "node:assert/strict";

const fw = Forwarder.create();
// Connect to NDN network via routers in FCH response, consider default IPv4 gateway as a candidate.

@@ -53,4 +51,3 @@ // Also provide a fallback list in case the above candidates fail.

const faces = await connectToNetwork({
fw,
fallback: ["suns.cs.ucla.edu", "vnetlab.gcom.di.uminho.pt"],
fallback: ["titan.cs.memphis.edu", "vnetlab.gcom.di.uminho.pt"],
connectTimeout: 3000,

@@ -65,3 +62,3 @@ });

const t0 = Date.now();
const data = await new Endpoint({ fw }).consume(`/ndn/edu/ucla/ping/${Math.trunc(Math.random() * 1e8)}`);
const data = await consume(`/ndn/edu/memphis/ping/${Math.trunc(Math.random() * 1e8)}`);
console.log("Interest satisfied", `${data.name}`, `${Date.now() - t0}ms`);

@@ -68,0 +65,0 @@ } catch (err: unknown) {

Sorry, the diff of this file is not supported yet

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