@ndn/autoconfig
Advanced tools
Comparing version 0.0.20191223-beta.1 to 0.0.20200606
@@ -0,0 +0,0 @@ import { Forwarder, FwFace } from "@ndn/fw"; |
@@ -0,1 +1,6 @@ | ||
/// #if false | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
/// #endif | ||
import { Endpoint } from "@ndn/endpoint"; | ||
@@ -5,3 +10,11 @@ import { Forwarder, TapFace } from "@ndn/fw"; | ||
import { Interest, Name } from "@ndn/packet"; | ||
/// #if false | ||
const hirestime = __importDefault(require("hirestime")).default; | ||
/* | ||
/// #else | ||
import hirestime from "hirestime"; | ||
/// #endif | ||
/// #if false | ||
*/ | ||
/// #endif | ||
import { createTransport } from "./platform/mod.js"; | ||
@@ -8,0 +21,0 @@ const getNow = hirestime(); |
@@ -10,5 +10,7 @@ export declare function queryFch(opts?: queryFch.Options): Promise<string[]>; | ||
capabilities?: string[]; | ||
/** GPS position in GeoJSON [lon,lat] format, or null to use IP geolocation. */ | ||
position?: null | [number, number]; | ||
/** GPS position in GeoJSON [lon,lat] format, or IpGeolocation. */ | ||
position?: [number, number] | typeof IpGeolocation; | ||
} | ||
/** Set IP geolocation in Options.position. */ | ||
const IpGeolocation: unique symbol; | ||
} |
import { FCH_ALWAYS_CAPABILITIES, fetch } from "./platform/mod.js"; | ||
export async function queryFch(opts = {}) { | ||
const { server = "https://ndn-fch.named-data.net", count = 1, capabilities = [], position = null, } = opts; | ||
let u = `${server.replace(/[/]$/, "")}/?k=${count}`; | ||
const { server = "https://ndn-fch.named-data.net", count = 1, capabilities = [], position = queryFch.IpGeolocation, } = opts; | ||
let u = `${server.replace(/\/$/, "")}/?k=${count}`; | ||
for (const cap of new Set([...capabilities, ...FCH_ALWAYS_CAPABILITIES])) { | ||
u += `&cap=${cap}`; | ||
} | ||
if (position) { | ||
if (position !== queryFch.IpGeolocation) { | ||
u += `&lon=${position[0].toFixed(5)}&lat=${position[1].toFixed(5)}`; | ||
} | ||
const resp = await fetch(u); | ||
if (!resp.ok) { | ||
throw new Error(`invalid NDN-FCH HTTP response ${resp.status}`); | ||
} | ||
const text = await resp.text(); | ||
return text.split(","); | ||
} | ||
(function (queryFch) { | ||
/** Set IP geolocation in Options.position. */ | ||
queryFch.IpGeolocation = Symbol("queryFch.IpGeolocation"); | ||
})(queryFch || (queryFch = {})); |
export * from "./connect"; | ||
export * from "./fch"; | ||
export * from "./testbed"; |
import { Transport } from "@ndn/l3face"; | ||
import { connect } from "../mod"; | ||
export declare const fetch: ((input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>) & ((input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>); | ||
export declare const fetch: typeof globalThis.fetch; | ||
export declare const FCH_ALWAYS_CAPABILITIES: string[]; | ||
export declare function createTransport(host: string, { connectTimeout }: connect.Options): Promise<Transport>; | ||
export declare function getDefaultGateway(): Promise<string>; |
import { WsTransport } from "@ndn/ws-transport"; | ||
export const fetch = self.fetch; | ||
export const fetch = globalThis.fetch; | ||
export const FCH_ALWAYS_CAPABILITIES = ["wss"]; | ||
@@ -4,0 +4,0 @@ export function createTransport(host, { connectTimeout }) { |
@@ -0,0 +0,0 @@ import { Transport } from "@ndn/l3face"; |
@@ -0,4 +1,25 @@ | ||
/// #if false | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
/// #endif | ||
import { TcpTransport } from "@ndn/node-transport"; | ||
/// #if false | ||
const defaultGateway = __importDefault(require("default-gateway")).default; | ||
/* | ||
/// #else | ||
import defaultGateway from "default-gateway"; | ||
/// #endif | ||
/// #if false | ||
*/ | ||
/// #endif | ||
/// #if false | ||
const nodeFetch = __importDefault(require("node-fetch")).default; | ||
/* | ||
/// #else | ||
import nodeFetch from "node-fetch"; | ||
/// #endif | ||
/// #if false | ||
*/ | ||
/// #endif | ||
export const fetch = nodeFetch; | ||
@@ -5,0 +26,0 @@ export const FCH_ALWAYS_CAPABILITIES = []; |
@@ -0,0 +0,0 @@ import { FwFace } from "@ndn/fw"; |
@@ -1,6 +0,19 @@ | ||
import { collect, filter, pipeline, take, transform } from "streaming-iterables"; | ||
/// #if false | ||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
const { __importDefault } = require("tslib"); | ||
/// #endif | ||
/// #if false | ||
const { collect, filter, pipeline, transform } = require("streaming-iterables"); | ||
/* | ||
/// #else | ||
import { collect, filter, pipeline, transform } from "streaming-iterables"; | ||
/// #endif | ||
/// #if false | ||
*/ | ||
/// #endif | ||
import { connect, queryFch } from "./mod.js"; | ||
import { getDefaultGateway } from "./platform/mod.js"; | ||
export async function connectToTestbed(opts = {}) { | ||
const { fchFallback = [], count = 1, tryDefaultGateway = true, preferFastest = false, } = opts; | ||
const { fchFallback = [], tryDefaultGateway = true, preferFastest = false, } = opts; | ||
const hosts = await queryFch(opts).catch(() => fchFallback); | ||
@@ -11,5 +24,5 @@ if (tryDefaultGateway) { | ||
} | ||
catch (err) { } | ||
catch { } | ||
} | ||
const faces = await pipeline(() => hosts, transform(Infinity, (host) => connect(host, opts).catch(() => undefined)), filter((res) => !!res), take(count), collect); | ||
const faces = await pipeline(() => hosts, transform(Infinity, (host) => connect(host, opts).catch(() => undefined)), filter((res) => !!res), collect); | ||
if (preferFastest && faces.length > 1) { | ||
@@ -16,0 +29,0 @@ faces.sort(({ testConnectionDuration: d1 }, { testConnectionDuration: d2 }) => d1 - d2); |
{ | ||
"name": "@ndn/autoconfig", | ||
"version": "0.0.20191223-beta.1", | ||
"version": "0.0.20200606", | ||
"description": "NDNts: automatic connection establishment", | ||
@@ -28,14 +28,14 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/endpoint": "0.0.20191223-beta.1", | ||
"@ndn/fw": "0.0.20191223-beta.1", | ||
"@ndn/l3face": "0.0.20191223-beta.1", | ||
"@ndn/node-transport": "0.0.20191223-beta.1", | ||
"@ndn/packet": "0.0.20191223-beta.1", | ||
"@ndn/ws-transport": "0.0.20191223-beta.1", | ||
"default-gateway": "^5.0.5", | ||
"hirestime": "^4.0.0", | ||
"@ndn/endpoint": "0.0.20200606", | ||
"@ndn/fw": "0.0.20200606", | ||
"@ndn/l3face": "0.0.20200606", | ||
"@ndn/node-transport": "0.0.20200606", | ||
"@ndn/packet": "0.0.20200606", | ||
"@ndn/ws-transport": "0.0.20200606", | ||
"default-gateway": "^6.0.1", | ||
"hirestime": "^6.0.1", | ||
"node-fetch": "^2.6.0", | ||
"streaming-iterables": "^4.1.1", | ||
"streaming-iterables": "^4.1.2", | ||
"tslib": "*" | ||
} | ||
} |
@@ -38,3 +38,3 @@ # @ndn/autoconfig | ||
// Ask for router at specific location: | ||
hosts = await queryFch({ position: [121.403351, 31.007990] }); | ||
hosts = await queryFch({ position: [121.403351, 31.007990] }); // eslint-disable-line unicorn/no-zero-fractions | ||
console.log("near @yoursunny's birthplace", hosts); | ||
@@ -41,0 +41,0 @@ ``` |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
11498
220
3
+ Added@ndn/endpoint@0.0.20200606(transitive)
+ Added@ndn/fw@0.0.20200606(transitive)
+ Added@ndn/l3face@0.0.20200606(transitive)
+ Added@ndn/lp@0.0.20200606(transitive)
+ Added@ndn/node-transport@0.0.20200606(transitive)
+ Added@ndn/packet@0.0.20200606(transitive)
+ Added@ndn/tlv@0.0.20200606(transitive)
+ Added@ndn/ws-transport@0.0.20200606(transitive)
+ Added@types/retry@0.12.5(transitive)
+ Addeddefault-gateway@6.0.3(transitive)
+ Addedexeca@5.1.1(transitive)
+ Addedget-iterator@1.0.2(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedhirestime@6.1.0(transitive)
+ Addedhuman-signals@2.1.0(transitive)
+ Addedit-keepalive@1.2.0(transitive)
+ Addedmnemonist@0.36.1(transitive)
+ Addedobliterator@1.6.1(transitive)
+ Addedp-event@4.2.0(transitive)
+ Addedretry@0.12.0(transitive)
+ Addedtyped-emitter@1.4.0(transitive)
- Removed@ndn/endpoint@0.0.20191223-beta.1(transitive)
- Removed@ndn/fw@0.0.20191223-beta.1(transitive)
- Removed@ndn/l3face@0.0.20191223-beta.1(transitive)
- Removed@ndn/lp@0.0.20191223-beta.1(transitive)
- Removed@ndn/node-transport@0.0.20191223-beta.1(transitive)
- Removed@ndn/packet@0.0.20191223-beta.1(transitive)
- Removed@ndn/tlv@0.0.20191223-beta.1(transitive)
- Removed@ndn/ws-transport@0.0.20191223-beta.1(transitive)
- Removeddefault-gateway@5.0.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexeca@3.4.0(transitive)
- Removedget-stream@5.2.0(transitive)
- Removedhirestime@4.0.0(transitive)
- Removedhuman-signals@1.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-finally@2.0.1(transitive)
- Removedpump@3.0.2(transitive)
- Removedstrict-event-emitter-types@2.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updated@ndn/endpoint@0.0.20200606
Updated@ndn/fw@0.0.20200606
Updated@ndn/l3face@0.0.20200606
Updated@ndn/packet@0.0.20200606
Updateddefault-gateway@^6.0.1
Updatedhirestime@^6.0.1
Updatedstreaming-iterables@^4.1.2