@ndn/node-transport
Advanced tools
Comparing version 0.0.20230121 to 0.0.20240113
export * from "./hostport_browser.js"; | ||
export * from "./tcp-transport_browser.js"; | ||
export * from "./unix-transport_browser.js"; | ||
export * as udp_helper from "./udp-helper_browser.js"; | ||
import * as udp_helper from "./udp-helper_browser.js"; export { udp_helper }; | ||
export * from "./udp-transport_browser.js"; |
export * from "./hostport_node.js"; | ||
export * from "./tcp-transport_node.js"; | ||
export * from "./unix-transport_node.js"; | ||
export * as udp_helper from "./udp-helper_node.js"; | ||
import * as udp_helper from "./udp-helper_node.js"; export { udp_helper }; | ||
export * from "./udp-transport_node.js"; |
export * from "./hostport.js"; | ||
export * from "./tcp-transport.js"; | ||
export * from "./unix-transport.js"; | ||
export * as udp_helper from "./udp-helper.js"; | ||
import * as udp_helper from "./udp-helper.js"; export { udp_helper }; | ||
export * from "./udp-transport.js"; |
/// <reference types="node" /> | ||
import * as net from "node:net"; | ||
import { L3Face, StreamTransport } from "@ndn/l3face"; | ||
import type { Except } from "type-fest"; | ||
/** TCP socket transport. */ | ||
@@ -11,3 +12,3 @@ export declare class TcpTransport extends StreamTransport { | ||
export declare namespace TcpTransport { | ||
type NetConnectOpts = Omit<net.TcpNetConnectOpts, "port"> & Partial<Pick<net.TcpNetConnectOpts, "port">>; | ||
type NetConnectOpts = Except<net.TcpNetConnectOpts, "port"> & Partial<Pick<net.TcpNetConnectOpts, "port">>; | ||
interface Options { | ||
@@ -32,3 +33,22 @@ /** Connect timeout (in milliseconds). */ | ||
/** Create a transport and add to forwarder. */ | ||
const createFace: L3Face.CreateFaceFunc<TcpTransport, [arg1?: string | (Omit<net.TcpNetConnectOpts, "port"> & Partial<Pick<net.TcpNetConnectOpts, "port">> & Options) | undefined, port?: number | undefined, opts?: Options | undefined]>; | ||
const createFace: L3Face.CreateFaceFunc<TcpTransport, [arg1?: string | ({ | ||
timeout?: number | undefined; | ||
host?: string | undefined; | ||
localAddress?: string | undefined; | ||
localPort?: number | undefined; | ||
hints?: number | undefined; | ||
family?: number | undefined; | ||
lookup?: net.LookupFunction | undefined; | ||
noDelay?: boolean | undefined; | ||
keepAlive?: boolean | undefined; | ||
keepAliveInitialDelay?: number | undefined; | ||
autoSelectFamily?: boolean | undefined; | ||
autoSelectFamilyAttemptTimeout?: number | undefined; | ||
onread?: net.OnReadOpts | undefined; | ||
fd?: number | undefined; | ||
allowHalfOpen?: boolean | undefined; | ||
readable?: boolean | undefined; | ||
writable?: boolean | undefined; | ||
signal?: AbortSignal | undefined; | ||
} & Partial<Pick<net.TcpNetConnectOpts, "port">> & Options) | undefined, port?: number | undefined, opts?: Options | undefined]>; | ||
} |
@@ -8,8 +8,2 @@ import * as dgram from "dgram"; | ||
const DEFAULT_MULTICAST_PORT = 56363; | ||
export function intfHasAddressFamily(want, { family }) { | ||
// https://github.com/nodejs/node/issues/42787 | ||
// Node.js 16.x: NetworkInterfaceInfo.family is either "IPv4" or "IPv6" | ||
// Node.js 18.x: NetworkInterfaceInfo.family is either 4 or 6 | ||
return family === want || family === `IPv${want}`; | ||
} | ||
export async function openSocket({ family, recvBufferSize, sendBufferSize, bind = {}, }) { | ||
@@ -56,5 +50,10 @@ family ??= bind.address?.includes(":") ? 6 : 4; | ||
export function listMulticastIntfs() { | ||
return Object.values(os.networkInterfaces()) | ||
.flatMap((addrs = []) => addrs.filter((a) => intfHasAddressFamily(4, a) && !a.internal) | ||
.map(({ address }) => address).slice(0, 1)); | ||
return Object.values(os.networkInterfaces()).flatMap((addrs = []) => { | ||
for (const addr of addrs) { | ||
if (addr.family === "IPv4" && !addr.internal) { | ||
return addr.address; | ||
} | ||
} | ||
return []; | ||
}); | ||
} | ||
@@ -61,0 +60,0 @@ export async function openMulticastRx(opts) { |
@@ -8,8 +8,2 @@ import * as dgram from "node:dgram"; | ||
const DEFAULT_MULTICAST_PORT = 56363; | ||
export function intfHasAddressFamily(want, { family }) { | ||
// https://github.com/nodejs/node/issues/42787 | ||
// Node.js 16.x: NetworkInterfaceInfo.family is either "IPv4" or "IPv6" | ||
// Node.js 18.x: NetworkInterfaceInfo.family is either 4 or 6 | ||
return family === want || family === `IPv${want}`; | ||
} | ||
export async function openSocket({ family, recvBufferSize, sendBufferSize, bind = {}, }) { | ||
@@ -56,5 +50,10 @@ family ??= bind.address?.includes(":") ? 6 : 4; | ||
export function listMulticastIntfs() { | ||
return Object.values(os.networkInterfaces()) | ||
.flatMap((addrs = []) => addrs.filter((a) => intfHasAddressFamily(4, a) && !a.internal) | ||
.map(({ address }) => address).slice(0, 1)); | ||
return Object.values(os.networkInterfaces()).flatMap((addrs = []) => { | ||
for (const addr of addrs) { | ||
if (addr.family === "IPv4" && !addr.internal) { | ||
return addr.address; | ||
} | ||
} | ||
return []; | ||
}); | ||
} | ||
@@ -61,0 +60,0 @@ export async function openMulticastRx(opts) { |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as dgram from "node:dgram"; | ||
import * as os from "node:os"; | ||
export declare const DEFAULT_MTU = 65000; | ||
export type Socket = dgram.Socket; | ||
export interface SocketBufferOption { | ||
recvBufferSize?: number; | ||
sendBufferSize?: number; | ||
} | ||
export type SocketBufferOptions = Pick<dgram.SocketOptions, "recvBufferSize" | "sendBufferSize">; | ||
export type AddressFamily = 4 | 6; | ||
export declare function intfHasAddressFamily(want: AddressFamily, { family }: os.NetworkInterfaceInfo): boolean; | ||
export interface AddressFamilyOption { | ||
export interface OpenSocketOptions extends SocketBufferOptions { | ||
/** | ||
@@ -19,4 +13,2 @@ * IPv4 or IPv6. | ||
family?: AddressFamily; | ||
} | ||
export interface OpenSocketOptions extends SocketBufferOption, AddressFamilyOption { | ||
/** Bind options, such as local address and port. */ | ||
@@ -41,3 +33,3 @@ bind?: dgram.BindOptions; | ||
export declare function listMulticastIntfs(): string[]; | ||
export interface MulticastOptions extends SocketBufferOption { | ||
export interface MulticastOptions extends SocketBufferOptions { | ||
/** IPv4 address of local network interface. */ | ||
@@ -44,0 +36,0 @@ intf: string; |
/// <reference types="node" /> | ||
import type { AddressInfo } from "node:net"; | ||
import { L3Face, Transport } from "@ndn/l3face"; | ||
import type { Except } from "type-fest"; | ||
import * as udp from "./udp-helper.js"; | ||
@@ -35,5 +36,12 @@ /** UDP socket transport. */ | ||
/** Create multicast transports on every interface. */ | ||
function multicasts(opts?: Omit<udp.MulticastOptions, "intf">): Promise<UdpTransport[]>; | ||
function multicasts(opts?: Except<udp.MulticastOptions, "intf">): Promise<UdpTransport[]>; | ||
/** Create multicast transports on every interface. */ | ||
const createMulticastFaces: L3Face.CreateFaceFunc<UdpTransport[], [opts?: Omit<udp.MulticastOptions, "intf"> | undefined]>; | ||
const createMulticastFaces: L3Face.CreateFaceFunc<UdpTransport[], [opts?: { | ||
group?: string | undefined; | ||
port?: number | undefined; | ||
multicastTtl?: number | undefined; | ||
multicastLoopback?: boolean | undefined; | ||
recvBufferSize?: number | undefined; | ||
sendBufferSize?: number | undefined; | ||
} | undefined]>; | ||
} |
{ | ||
"name": "@ndn/node-transport", | ||
"version": "0.0.20230121", | ||
"version": "0.0.20240113", | ||
"description": "NDNts: Low-Level Transports for Node.js", | ||
@@ -23,5 +23,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/l3face": "0.0.20230121", | ||
"@ndn/l3face": "0.0.20240113", | ||
"event-iterator": "^2.0.0", | ||
"tslib": "^2.4.1", | ||
"tslib": "^2.6.2", | ||
"type-fest": "^4.9.0", | ||
"url-format-lax": "^2.0.0", | ||
@@ -28,0 +29,0 @@ "url-parse-lax": "^5.0.0" |
@@ -30,6 +30,8 @@ # @ndn/node-transport | ||
```ts | ||
// NOTICE: ndnts-demo-*.ndn.today hostnames are not intended for general application use. | ||
// UnixTransport.connect() establishes a UNIX socket connection. | ||
// It accepts a Unix socket path. | ||
try { | ||
const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock"); | ||
const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock"); | ||
await useInL3Face(unix); | ||
@@ -43,3 +45,3 @@ } catch (err: unknown) { // NFD is not running | ||
try { | ||
const tcp4 = await TcpTransport.connect("hobo.cs.arizona.edu", 6363); | ||
const tcp4 = await TcpTransport.connect("wundngw.wustl.edu", 6363); | ||
await useInL3Face(tcp4); | ||
@@ -52,3 +54,3 @@ } catch (err: unknown) { // router unavailable | ||
try { | ||
const tcp6 = await TcpTransport.connect({ host: "ndnhub.ipv6.lip6.fr", family: 6 }); | ||
const tcp6 = await TcpTransport.connect({ host: "ndnts-demo-tcp6.ndn.today", family: 6 }); | ||
await useInL3Face(tcp6); | ||
@@ -61,3 +63,3 @@ } catch (err: unknown) { // router unavailable | ||
try { | ||
const udp4 = await UdpTransport.connect("hobo.cs.arizona.edu"); | ||
const udp4 = await UdpTransport.connect("wundngw.wustl.edu"); | ||
await useInL3Face(udp4); | ||
@@ -68,5 +70,5 @@ } catch (err: unknown) { // router unavailable | ||
// Select IPv6 with `type: "udp6"`. Default is IPv4 only. | ||
// Select IPv6 with `family: 6`. Default is IPv4 only, unless host is a literal IPv6 address. | ||
try { | ||
const udp6 = await UdpTransport.connect({ host: "ndnhub.ipv6.lip6.fr", family: 6 }); | ||
const udp6 = await UdpTransport.connect({ host: "ndnts-demo-udp6.ndn.today", family: 6 }); | ||
await useInL3Face(udp6); | ||
@@ -92,3 +94,3 @@ } catch (err: unknown) { // router unavailable | ||
Transports are normally used to construct **L3Face** objects (from `@ndn/l3face` package), which are in turned add to the **Forwarder** (from `@ndn/fw` package). | ||
Transports are normally used to construct **L3Face** objects (from `@ndn/l3face` package), which are in turn added to the **Forwarder** (from `@ndn/fw` package). | ||
Each transport provides a `createFace` convenience function to construct a transport and add it to the forwarder. | ||
@@ -104,3 +106,3 @@ | ||
// It returns a FwFace instance (from @ndn/fw package). | ||
const face = await UdpTransport.createFace({}, "ndnhub.ipv6.lip6.fr"); | ||
const face = await UdpTransport.createFace({}, "wundngw.wustl.edu"); | ||
face.close(); | ||
@@ -132,4 +134,4 @@ // TcpTransport.createFace() and UnixTransport.createFace() behave similarly. | ||
// We want to know if something goes wrong. | ||
face.on("rxerror", (err) => console.warn(err)); | ||
face.on("txerror", (err) => console.warn(err)); | ||
face.addEventListener("rxerror", (evt) => console.warn(evt.detail)); | ||
face.addEventListener("txerror", (evt) => console.warn(evt.detail)); | ||
@@ -142,3 +144,3 @@ await Promise.all([ | ||
await delay(50); | ||
const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`); | ||
const interest = new Interest(`/ndn/edu/memphis/ping/NDNts/${seq++}`); | ||
console.log(`${transport} <I ${interest.name}`); | ||
@@ -145,0 +147,0 @@ yield FwPacket.create(interest); |
@@ -14,3 +14,3 @@ import { TcpTransport, UdpTransport, UnixTransport } from "@ndn/node-transport"; | ||
try { | ||
const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock"); | ||
const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock"); | ||
await useInL3Face(unix); | ||
@@ -24,3 +24,3 @@ } catch (err: unknown) { // NFD is not running | ||
try { | ||
const tcp4 = await TcpTransport.connect("hobo.cs.arizona.edu", 6363); | ||
const tcp4 = await TcpTransport.connect("suns.cs.ucla.edu", 6363); | ||
await useInL3Face(tcp4); | ||
@@ -41,3 +41,3 @@ } catch (err: unknown) { // router unavailable | ||
try { | ||
const udp4 = await UdpTransport.connect("hobo.cs.arizona.edu"); | ||
const udp4 = await UdpTransport.connect("suns.cs.ucla.edu"); | ||
await useInL3Face(udp4); | ||
@@ -48,3 +48,3 @@ } catch (err: unknown) { // router unavailable | ||
// Select IPv6 with `type: "udp6"`. Default is IPv4 only. | ||
// Select IPv6 with `family: 6`. Default is IPv4 only, unless host is a literal IPv6 address. | ||
try { | ||
@@ -69,3 +69,3 @@ const udp6 = await UdpTransport.connect({ host: "ndnhub.ipv6.lip6.fr", family: 6 }); | ||
// It returns a FwFace instance (from @ndn/fw package). | ||
const face = await UdpTransport.createFace({}, "ndnhub.ipv6.lip6.fr"); | ||
const face = await UdpTransport.createFace({}, "suns.cs.ucla.edu"); | ||
face.close(); | ||
@@ -87,4 +87,4 @@ // TcpTransport.createFace() and UnixTransport.createFace() behave similarly. | ||
// We want to know if something goes wrong. | ||
face.on("rxerror", (err) => console.warn(err)); | ||
face.on("txerror", (err) => console.warn(err)); | ||
face.addEventListener("rxerror", (evt) => console.warn(evt.detail)); | ||
face.addEventListener("txerror", (evt) => console.warn(evt.detail)); | ||
@@ -97,3 +97,3 @@ await Promise.all([ | ||
await delay(50); | ||
const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`); | ||
const interest = new Interest(`/ndn/edu/ucla/ping/NDNts/${seq++}`); | ||
console.log(`${transport} <I ${interest.name}`); | ||
@@ -100,0 +100,0 @@ yield FwPacket.create(interest); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39919
889
160
6
+ Addedtype-fest@^4.9.0
+ Added@ndn/fw@0.0.20240113(transitive)
+ Added@ndn/l3face@0.0.20240113(transitive)
+ Added@ndn/lp@0.0.20240113(transitive)
+ Added@ndn/packet@0.0.20240113(transitive)
+ Added@ndn/tlv@0.0.20240113(transitive)
+ Added@ndn/util@0.0.20240113(transitive)
+ Addedabortable-iterator@5.1.0(transitive)
+ Addedit-stream-types@2.0.2(transitive)
+ Addedp-event@6.0.1(transitive)
+ Addedp-timeout@6.1.3(transitive)
+ Addedstreaming-iterables@8.0.1(transitive)
+ Addedtype-fest@4.30.0(transitive)
+ Addedtypescript-event-target@1.1.1(transitive)
- Removed@ndn/fw@0.0.20230121(transitive)
- Removed@ndn/l3face@0.0.20230121(transitive)
- Removed@ndn/lp@0.0.20230121(transitive)
- Removed@ndn/packet@0.0.20230121(transitive)
- Removed@ndn/tlv@0.0.20230121(transitive)
- Removed@ndn/util@0.0.20230121(transitive)
- Removedabortable-iterator@4.0.3(transitive)
- Removedit-stream-types@1.0.5(transitive)
- Removedp-event@5.0.1(transitive)
- Removedp-timeout@5.1.0(transitive)
- Removedrxjs@7.8.1(transitive)
- Removedstreaming-iterables@7.1.0(transitive)
- Removedtyped-emitter@2.1.0(transitive)
Updated@ndn/l3face@0.0.20240113
Updatedtslib@^2.6.2