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

@ndn/node-transport

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/node-transport - npm Package Compare versions

Comparing version 0.0.20210930 to 0.0.20220501

LICENSE

7

lib/hostport_browser.js

@@ -1,6 +0,3 @@

import { __importDefault, __importStar } from "tslib";
// @ts-expect-error typing unavailable
import _cjsDefaultImport0 from "url-format-lax"; const urlFormat = __importDefault(_cjsDefaultImport0).default;
// @ts-expect-error typing unavailable
import _cjsDefaultImport1 from "url-parse-lax"; const urlParse = __importDefault(_cjsDefaultImport1).default;
import urlFormat from "url-format-lax";
import urlParse from "url-parse-lax";
/** Combine host and port into a network address of the form "host:port". */

@@ -7,0 +4,0 @@ export function joinHostPort(hostname, port) {

@@ -1,6 +0,3 @@

import { __importDefault, __importStar } from "tslib";
// @ts-expect-error typing unavailable
import _cjsDefaultImport0 from "url-format-lax"; const urlFormat = __importDefault(_cjsDefaultImport0).default;
// @ts-expect-error typing unavailable
import _cjsDefaultImport1 from "url-parse-lax"; const urlParse = __importDefault(_cjsDefaultImport1).default;
import urlFormat from "url-format-lax";
import urlParse from "url-parse-lax";
/** Combine host and port into a network address of the form "host:port". */

@@ -7,0 +4,0 @@ export function joinHostPort(hostname, port) {

/// <reference types="node" />
/// <reference types="web" />
import { L3Face, StreamTransport } from "@ndn/l3face";
import type { AbortSignal } from "abort-controller";
import * as net from "node:net";

@@ -18,3 +16,3 @@ /** TCP socket transport. */

/** AbortSignal that allows canceling connection attempt via AbortController. */
signal?: AbortSignal | globalThis.AbortSignal;
signal?: AbortSignal;
}

@@ -21,0 +19,0 @@ /**

@@ -1,5 +0,5 @@

import { __importDefault, __importStar } from "tslib";
import * as dgram from "dgram";
import * as os from "os";
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default;
import { pEvent } from "p-event";
export const DEFAULT_MTU = 65000;
const DEFAULT_UNICAST_PORT = 6363;

@@ -9,3 +9,3 @@ const DEFAULT_MULTICAST_GROUP = "224.0.23.170";

export async function openSocket({ family, recvBufferSize, sendBufferSize, bind = {}, }) {
family ?? (family = bind.address?.includes(":") ? 6 : 4);
family ??= bind.address?.includes(":") ? 6 : 4;
const sock = dgram.createSocket({

@@ -12,0 +12,0 @@ type: `udp${family}`,

@@ -1,5 +0,5 @@

import { __importDefault, __importStar } from "tslib";
import * as dgram from "node:dgram";
import * as os from "node:os";
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default;
import { pEvent } from "p-event";
export const DEFAULT_MTU = 65000;
const DEFAULT_UNICAST_PORT = 6363;

@@ -9,3 +9,3 @@ const DEFAULT_MULTICAST_GROUP = "224.0.23.170";

export async function openSocket({ family, recvBufferSize, sendBufferSize, bind = {}, }) {
family ?? (family = bind.address?.includes(":") ? 6 : 4);
family ??= bind.address?.includes(":") ? 6 : 4;
const sock = dgram.createSocket({

@@ -12,0 +12,0 @@ type: `udp${family}`,

/// <reference types="node" />
import * as dgram from "node:dgram";
export declare const DEFAULT_MTU = 65000;
export declare type Socket = dgram.Socket;

@@ -4,0 +5,0 @@ export interface SocketBufferOption {

@@ -1,4 +0,3 @@

import { __importDefault, __importStar } from "tslib";
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face";
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default;
import { pEventIterator } from "p-event";
import { joinHostPort } from "./hostport_browser.js";

@@ -41,6 +40,7 @@ import * as udp from "./udp-helper_browser.js";

}
this.rx = rxFromPacketIterable(pEvent.iterator(this.rxSock, "message", {
this.rx = rxFromPacketIterable(pEventIterator(this.rxSock, "message", {
resolutionEvents: ["close"],
}));
}
get mtu() { return udp.DEFAULT_MTU; }
close() {

@@ -47,0 +47,0 @@ try {

@@ -1,4 +0,3 @@

import { __importDefault, __importStar } from "tslib";
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face";
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default;
import { pEventIterator } from "p-event";
import { joinHostPort } from "./hostport_node.js";

@@ -41,6 +40,7 @@ import * as udp from "./udp-helper_node.js";

}
this.rx = rxFromPacketIterable(pEvent.iterator(this.rxSock, "message", {
this.rx = rxFromPacketIterable(pEventIterator(this.rxSock, "message", {
resolutionEvents: ["close"],
}));
}
get mtu() { return udp.DEFAULT_MTU; }
close() {

@@ -47,0 +47,0 @@ try {

@@ -15,2 +15,3 @@ /// <reference types="node" />

constructor(multicastTx: udp.Socket, multicastRx: udp.Socket);
get mtu(): number;
close(): void;

@@ -17,0 +18,0 @@ readonly tx: (iterable: AsyncIterable<Uint8Array>) => Promise<void>;

{
"name": "@ndn/node-transport",
"version": "0.0.20210930",
"version": "0.0.20220501",
"description": "NDNts: Low-Level Transports for Node.js",

@@ -23,10 +23,10 @@ "keywords": [

"dependencies": {
"@ndn/l3face": "0.0.20210930",
"abort-controller": "^3.0.0",
"p-event": "^4.2.0",
"tslib": "^2.3.1",
"url-format-lax": "^1.0.0",
"url-parse-lax": "^4.0.0"
"@ndn/l3face": "0.0.20220501",
"p-event": "^5.0.1",
"tslib": "^2.4.0",
"url-format-lax": "^2.0.0",
"url-parse-lax": "^5.0.0"
},
"types": "lib/mod.d.ts"
"types": "lib/mod.d.ts",
"readme": "# @ndn/node-transport\n\nThis package is part of [NDNts](https://yoursunny.com/p/NDNts/), Named Data Networking libraries for the modern web.\n\nThis package implements socket transports for Node.js environment.\n\n```ts\nimport { TcpTransport, UdpTransport, UnixTransport } from \"@ndn/node-transport\";\n\n// other imports for examples\nimport { FwPacket } from \"@ndn/fw\";\nimport { L3Face, Transport } from \"@ndn/l3face\";\nimport { Data, Interest } from \"@ndn/packet\";\nimport { setTimeout as delay } from \"node:timers/promises\";\n\nif (process.env.CI) { process.exit(0); }\n```\n\n## Transport Types\n\nThere are three transport types:\n\n* UnixTransport: Unix socket or Windows named pipe.\n* TcpTransport: TCP tunnel (IPv4 or IPv6).\n* UdpTransport: UDP unicast tunnel (IPv4 or IPv6) or UDP multicast group (IPv4 only).\n\nThe `connect()` function of each transport creates a transport.\n\n```ts\n// UnixTransport.connect() establishes a UNIX socket connection.\n// It accepts a Unix socket path.\ntry {\n const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? \"/run/nfd.sock\");\n await useInL3Face(unix);\n} catch (err: unknown) { // NFD is not running\n console.warn(\"unix\", err);\n}\n\n// TcpTransport.connect() establishes a TCP tunnel.\n// It accepts either host+port or an options object for net.connect().\ntry {\n const tcp4 = await TcpTransport.connect(\"hobo.cs.arizona.edu\", 6363);\n await useInL3Face(tcp4);\n} catch (err: unknown) { // router unavailable\n console.warn(\"tcp4\", err);\n}\n\n// Select IPv4 with `family: 4` or select IPv6 with `family: 6`. Default is both.\ntry {\n const tcp6 = await TcpTransport.connect({ host: \"ndnhub.ipv6.lip6.fr\", family: 6 });\n await useInL3Face(tcp6);\n} catch (err: unknown) { // router unavailable\n console.warn(\"tcp6\", err);\n}\n\n// UdpTransport.connect() establishes a UDP tunnel.\ntry {\n const udp4 = await UdpTransport.connect(\"hobo.cs.arizona.edu\");\n await useInL3Face(udp4);\n} catch (err: unknown) { // router unavailable\n console.warn(\"udp4\", err);\n}\n\n// Select IPv6 with `type: \"udp6\"`. Default is IPv4 only.\ntry {\n const udp6 = await UdpTransport.connect({ host: \"ndnhub.ipv6.lip6.fr\", family: 6 });\n await useInL3Face(udp6);\n} catch (err: unknown) { // router unavailable\n console.warn(\"udp6\", err);\n}\n```\n\nTo use UDP multicast, each network interface needs to have a separate transport.\nIt's easiest to let NDNts automatically create transports on every network interface.\n\n```ts\n// UdpTransport.multicasts() attempts to create UDP multicast transports on every\n// network interface, skipping network interfaces where socket creation fails.\nconst multicasts = await UdpTransport.multicasts();\nfor (const transport of multicasts) {\n await useInL3Face(transport);\n}\n```\n\n## How to Use a Transport\n\nTransports are normally used to construct **L3Face** objects (from `@ndn/l3face` package), which are in turned add to the **Forwarder** (from `@ndn/fw` package).\nEach transport provides a `createFace` convenience function to construct a transport and add it to the forwarder.\n\nSee `@ndn/ws-transport` package documentation for a complete example of `createFace` function.\n\n```ts\n// UdpTransport.createFace() constructs a UDP unicast transport, and adds it to a forwarder.\n// First parameters allows setting L3Face attributes and NDNLP service options, or attaching\n// the face to a non-default Forwarder instance. This argument is required.\n// Subsequent parameters are same as the corresponding connect() function.\n// It returns a FwFace instance (from @ndn/fw package).\nconst face = await UdpTransport.createFace({}, \"ndnhub.ipv6.lip6.fr\");\nface.close();\n// TcpTransport.createFace() and UnixTransport.createFace() behave similarly.\n\n// UdpTransport.createMulticastFaces() constructs UDP multicast transports on every network\n// interface and adds them to a forwarder.\nconst faces = await UdpTransport.createMulticastFaces({});\nfor (const face of faces) {\n face.close();\n}\n```\n\n## L3Face Low-Level Details\n\nL3Face allows sending and receiving layer-3 packets on a transport.\nL3Face does not provide Interest-Data matching logic, timeout scheduler, etc.\nIt is more like a forwarder's face.\n\nThis section presents the low-level details of how to use a \"raw\" transport with `L3Face` class.\n\n```ts\nasync function useInL3Face(transport: Transport) {\n\n // Transports are normally used in a network layer face.\n const face = new L3Face(transport);\n\n // We want to know if something goes wrong.\n face.on(\"rxerror\", (err) => console.warn(err));\n face.on(\"txerror\", (err) => console.warn(err));\n\n await Promise.all([\n face.tx({ async *[Symbol.asyncIterator]() {\n // Send five Interests.\n let seq = Math.trunc(Math.random() * 1e8);\n for (let i = 0; i < 5; ++i) {\n await delay(50);\n const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`);\n console.log(`${transport} <I ${interest.name}`);\n yield FwPacket.create(interest);\n }\n await delay(500);\n } }),\n (async () => {\n let nData = 0;\n for await (const { l3 } of face.rx) {\n if (!(l3 instanceof Data)) {\n continue;\n }\n // Print incoming Data name.\n console.log(`${transport} >D ${l3.name}`);\n if (++nData >= 5) {\n return;\n }\n }\n })(),\n ]);\n\n // L3Face and Transport are automatically closed when TX iterable is exhausted.\n}\n```\n"
}

@@ -13,6 +13,6 @@ # @ndn/node-transport

import { L3Face, Transport } from "@ndn/l3face";
import { Data, Interest, Name } from "@ndn/packet";
import { Data, Interest } from "@ndn/packet";
import { setTimeout as delay } from "node:timers/promises";
(async () => {
if (process.env.CI) { return; }
if (process.env.CI) { process.exit(0); }
```

@@ -34,3 +34,3 @@

try {
const unix = await UnixTransport.connect("/run/nfd.sock");
const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock");
await useInL3Face(unix);

@@ -101,3 +101,2 @@ } catch (err: unknown) { // NFD is not running

const face = await UdpTransport.createFace({}, "ndnhub.ipv6.lip6.fr");
face.addRoute(new Name("/ndn"));
face.close();

@@ -112,3 +111,2 @@ // TcpTransport.createFace() and UnixTransport.createFace() behave similarly.

}
})();
```

@@ -137,5 +135,5 @@

// Send five Interests.
let seq = Math.floor(Math.random() * 1e9);
let seq = Math.trunc(Math.random() * 1e8);
for (let i = 0; i < 5; ++i) {
await new Promise((r) => setTimeout(r, 50));
await delay(50);
const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`);

@@ -145,3 +143,3 @@ console.log(`${transport} <I ${interest.name}`);

}
await new Promise((r) => setTimeout(r, 500));
await delay(500);
} }),

@@ -148,0 +146,0 @@ (async () => {

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