@ndn/node-transport
Advanced tools
Comparing version 0.0.20210203 to 0.0.20210930
@@ -0,5 +1,5 @@ | ||
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"; | ||
export * from "./udp-transport_browser.js"; | ||
import * as udp_helper_1 from "./udp-helper_browser.js"; | ||
export { udp_helper_1 as udp_helper }; |
@@ -0,5 +1,5 @@ | ||
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"; | ||
export * from "./udp-transport_node.js"; | ||
import * as udp_helper_1 from "./udp-helper_node.js"; | ||
export { udp_helper_1 as udp_helper }; |
@@ -0,4 +1,5 @@ | ||
export * from "./hostport"; | ||
export * from "./tcp-transport"; | ||
export * from "./unix-transport"; | ||
export * as udp_helper from "./udp-helper"; | ||
export * from "./udp-transport"; | ||
export * as udp_helper from "./udp-helper"; |
import { L3Face, StreamTransport } from "@ndn/l3face"; | ||
import * as net from "net"; | ||
import { joinHostPort } from "./hostport_browser.js"; | ||
const DEFAULT_PORT = 6363; | ||
@@ -8,3 +9,3 @@ /** TCP socket transport. */ | ||
super(sock, { | ||
describe: `TCP(${sock.remoteAddress}:${sock.remotePort})`, | ||
describe: `TCP(${joinHostPort(sock.remoteAddress, sock.remotePort)})`, | ||
local: sock.localAddress === sock.remoteAddress, | ||
@@ -19,10 +20,12 @@ }); | ||
(function (TcpTransport) { | ||
function connect(arg1, port = DEFAULT_PORT, opts = {}) { | ||
var _a; | ||
const connectOpts = typeof arg1 === "undefined" ? { port } : | ||
function connect(arg1, port, opts) { | ||
return connectImpl(arg1, port, opts); | ||
} | ||
TcpTransport.connect = connect; | ||
function connectImpl(arg1, port = DEFAULT_PORT, opts = {}) { | ||
const connectOpts = arg1 === undefined ? { port } : | ||
typeof arg1 === "string" ? { host: arg1, port } : | ||
{ host: arg1.host, port: (_a = arg1.port) !== null && _a !== void 0 ? _a : DEFAULT_PORT, family: arg1.family }; | ||
{ host: arg1.host, port: arg1.port ?? DEFAULT_PORT, family: arg1.family }; | ||
const { connectTimeout = 10000, signal, } = typeof arg1 === "object" ? arg1 : opts; | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
const sock = net.connect(connectOpts); | ||
@@ -36,10 +39,9 @@ sock.setNoDelay(true); | ||
const onabort = () => fail(new Error("abort")); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", () => onabort); | ||
signal?.addEventListener("abort", onabort); | ||
sock.on("error", () => undefined); | ||
sock.once("error", fail); | ||
sock.once("connect", () => { | ||
var _a; | ||
clearTimeout(timeout); | ||
sock.off("error", fail); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", onabort); | ||
signal?.removeEventListener("abort", onabort); | ||
resolve(new TcpTransport(sock, connectOpts)); | ||
@@ -49,5 +51,4 @@ }); | ||
} | ||
TcpTransport.connect = connect; | ||
/** Create a transport and add to forwarder. */ | ||
TcpTransport.createFace = L3Face.makeCreateFace(TcpTransport.connect); | ||
TcpTransport.createFace = L3Face.makeCreateFace(connectImpl); | ||
})(TcpTransport || (TcpTransport = {})); |
import { L3Face, StreamTransport } from "@ndn/l3face"; | ||
import * as net from "net"; | ||
import * as net from "node:net"; | ||
import { joinHostPort } from "./hostport_node.js"; | ||
const DEFAULT_PORT = 6363; | ||
@@ -8,3 +9,3 @@ /** TCP socket transport. */ | ||
super(sock, { | ||
describe: `TCP(${sock.remoteAddress}:${sock.remotePort})`, | ||
describe: `TCP(${joinHostPort(sock.remoteAddress, sock.remotePort)})`, | ||
local: sock.localAddress === sock.remoteAddress, | ||
@@ -19,10 +20,12 @@ }); | ||
(function (TcpTransport) { | ||
function connect(arg1, port = DEFAULT_PORT, opts = {}) { | ||
var _a; | ||
const connectOpts = typeof arg1 === "undefined" ? { port } : | ||
function connect(arg1, port, opts) { | ||
return connectImpl(arg1, port, opts); | ||
} | ||
TcpTransport.connect = connect; | ||
function connectImpl(arg1, port = DEFAULT_PORT, opts = {}) { | ||
const connectOpts = arg1 === undefined ? { port } : | ||
typeof arg1 === "string" ? { host: arg1, port } : | ||
{ host: arg1.host, port: (_a = arg1.port) !== null && _a !== void 0 ? _a : DEFAULT_PORT, family: arg1.family }; | ||
{ host: arg1.host, port: arg1.port ?? DEFAULT_PORT, family: arg1.family }; | ||
const { connectTimeout = 10000, signal, } = typeof arg1 === "object" ? arg1 : opts; | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
const sock = net.connect(connectOpts); | ||
@@ -36,10 +39,9 @@ sock.setNoDelay(true); | ||
const onabort = () => fail(new Error("abort")); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", () => onabort); | ||
signal?.addEventListener("abort", onabort); | ||
sock.on("error", () => undefined); | ||
sock.once("error", fail); | ||
sock.once("connect", () => { | ||
var _a; | ||
clearTimeout(timeout); | ||
sock.off("error", fail); | ||
(_a = signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", onabort); | ||
signal?.removeEventListener("abort", onabort); | ||
resolve(new TcpTransport(sock, connectOpts)); | ||
@@ -49,5 +51,4 @@ }); | ||
} | ||
TcpTransport.connect = connect; | ||
/** Create a transport and add to forwarder. */ | ||
TcpTransport.createFace = L3Face.makeCreateFace(TcpTransport.connect); | ||
TcpTransport.createFace = L3Face.makeCreateFace(connectImpl); | ||
})(TcpTransport || (TcpTransport = {})); |
/// <reference types="node" /> | ||
/// <reference types="web" /> | ||
import { L3Face, StreamTransport } from "@ndn/l3face"; | ||
import type { AbortSignal } from "abort-controller"; | ||
import * as net from "net"; | ||
import * as net from "node:net"; | ||
/** TCP socket transport. */ | ||
@@ -32,3 +33,3 @@ export declare class TcpTransport extends StreamTransport { | ||
/** Create a transport and add to forwarder. */ | ||
const createFace: L3Face.CreateFaceFunc<typeof connect>; | ||
const createFace: L3Face.CreateFaceFunc<TcpTransport, [arg1?: string | (Omit<net.TcpNetConnectOpts, "port"> & Partial<Pick<net.TcpNetConnectOpts, "port">> & Options) | undefined, port?: number | undefined, opts?: Options | undefined]>; | ||
} |
@@ -8,3 +8,4 @@ import { __importDefault, __importStar } from "tslib"; | ||
const DEFAULT_MULTICAST_PORT = 56363; | ||
async function openSocket({ family = 4, recvBufferSize, sendBufferSize, bind = {}, }) { | ||
export async function openSocket({ family, recvBufferSize, sendBufferSize, bind = {}, }) { | ||
family ?? (family = bind.address?.includes(":") ? 6 : 4); | ||
const sock = dgram.createSocket({ | ||
@@ -11,0 +12,0 @@ type: `udp${family}`, |
import { __importDefault, __importStar } from "tslib"; | ||
import * as dgram from "dgram"; | ||
import * as os from "os"; | ||
import * as dgram from "node:dgram"; | ||
import * as os from "node:os"; | ||
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default; | ||
@@ -8,3 +8,4 @@ const DEFAULT_UNICAST_PORT = 6363; | ||
const DEFAULT_MULTICAST_PORT = 56363; | ||
async function openSocket({ family = 4, recvBufferSize, sendBufferSize, bind = {}, }) { | ||
export async function openSocket({ family, recvBufferSize, sendBufferSize, bind = {}, }) { | ||
family ?? (family = bind.address?.includes(":") ? 6 : 4); | ||
const sock = dgram.createSocket({ | ||
@@ -11,0 +12,0 @@ type: `udp${family}`, |
/// <reference types="node" /> | ||
import * as dgram from "dgram"; | ||
import * as dgram from "node:dgram"; | ||
export declare type Socket = dgram.Socket; | ||
declare type SocketOptions = Pick<dgram.SocketOptions, "recvBufferSize" | "sendBufferSize">; | ||
interface AddressFamilyOption { | ||
export interface SocketBufferOption { | ||
recvBufferSize?: number; | ||
sendBufferSize?: number; | ||
} | ||
export declare type AddressFamily = 4 | 6; | ||
export interface AddressFamilyOption { | ||
/** | ||
* IPv4 or IPv6. | ||
* Default is IPv4, unless `host` is an IPv6 address (contains a colon). | ||
* Default is IPv4, unless hostname is an IPv6 address (contains a colon). | ||
*/ | ||
family?: 4 | 6; | ||
family?: AddressFamily; | ||
} | ||
export declare type OpenSocketOptions = SocketOptions & AddressFamilyOption & { | ||
export interface OpenSocketOptions extends SocketBufferOption, AddressFamilyOption { | ||
/** Bind options, such as local address and port. */ | ||
bind?: dgram.BindOptions; | ||
}; | ||
export interface ConnectOptions extends AddressFamilyOption { | ||
} | ||
export declare function openSocket({ family, recvBufferSize, sendBufferSize, bind, }: OpenSocketOptions): Promise<Socket>; | ||
export interface ConnectOptions { | ||
/** Remote address. */ | ||
@@ -23,6 +28,7 @@ host: string; | ||
export declare function connect(sock: Socket, { host, port, }: ConnectOptions): Promise<Socket>; | ||
export declare type UnicastOptions = OpenSocketOptions & ConnectOptions; | ||
export interface UnicastOptions extends OpenSocketOptions, ConnectOptions { | ||
} | ||
export declare function openUnicast(opts: UnicastOptions): Promise<Socket>; | ||
export declare function listMulticastIntfs(): string[]; | ||
export declare type MulticastOptions = SocketOptions & { | ||
export interface MulticastOptions extends SocketBufferOption { | ||
/** IPv4 address of local network interface. */ | ||
@@ -38,5 +44,4 @@ intf: string; | ||
multicastLoopback?: boolean; | ||
}; | ||
} | ||
export declare function openMulticastRx(opts: MulticastOptions): Promise<Socket>; | ||
export declare function openMulticastTx(opts: MulticastOptions): Promise<Socket>; | ||
export {}; |
import { __importDefault, __importStar } from "tslib"; | ||
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face"; | ||
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default; | ||
import { joinHostPort } from "./hostport_browser.js"; | ||
import * as udp from "./udp-helper_browser.js"; | ||
@@ -9,10 +10,17 @@ /** UDP socket transport. */ | ||
super({ | ||
describe: rxSock ? `UDPm(${txSock.address().address})` : `UDP(${txSock.remoteAddress().address})`, | ||
describe: (() => { | ||
const [scheme, { address, port }] = rxSock ? ["UDPm", txSock.address()] : ["UDP", txSock.remoteAddress()]; | ||
return `${scheme}(${joinHostPort(address, port)})`; | ||
})(), | ||
multicast: !!rxSock, | ||
}); | ||
this.tx = async (iterable) => { | ||
for await (const pkt of iterable) { | ||
this.txSock.send(pkt); | ||
try { | ||
for await (const pkt of iterable) { | ||
this.txSock.send(pkt); | ||
} | ||
} | ||
this.close(); | ||
finally { | ||
this.close(); | ||
} | ||
}; | ||
@@ -49,3 +57,7 @@ if (rxSock) { | ||
(function (UdpTransport) { | ||
async function connect(arg1, port) { | ||
function connect(arg1, port) { | ||
return connectImpl(arg1, port); | ||
} | ||
UdpTransport.connect = connect; | ||
async function connectImpl(arg1, port) { | ||
const opts = typeof arg1 === "string" ? { host: arg1, port } : arg1; | ||
@@ -55,5 +67,4 @@ const sock = await udp.openUnicast(opts); | ||
} | ||
UdpTransport.connect = connect; | ||
/** Create a unicast transport and add to forwarder. */ | ||
UdpTransport.createFace = L3Face.makeCreateFace(connect); | ||
UdpTransport.createFace = L3Face.makeCreateFace(connectImpl); | ||
/** Create a multicast transport. */ | ||
@@ -60,0 +71,0 @@ async function multicast(opts) { |
import { __importDefault, __importStar } from "tslib"; | ||
import { L3Face, rxFromPacketIterable, Transport } from "@ndn/l3face"; | ||
import _cjsDefaultImport0 from "p-event"; const pEvent = __importDefault(_cjsDefaultImport0).default; | ||
import { joinHostPort } from "./hostport_node.js"; | ||
import * as udp from "./udp-helper_node.js"; | ||
@@ -9,10 +10,17 @@ /** UDP socket transport. */ | ||
super({ | ||
describe: rxSock ? `UDPm(${txSock.address().address})` : `UDP(${txSock.remoteAddress().address})`, | ||
describe: (() => { | ||
const [scheme, { address, port }] = rxSock ? ["UDPm", txSock.address()] : ["UDP", txSock.remoteAddress()]; | ||
return `${scheme}(${joinHostPort(address, port)})`; | ||
})(), | ||
multicast: !!rxSock, | ||
}); | ||
this.tx = async (iterable) => { | ||
for await (const pkt of iterable) { | ||
this.txSock.send(pkt); | ||
try { | ||
for await (const pkt of iterable) { | ||
this.txSock.send(pkt); | ||
} | ||
} | ||
this.close(); | ||
finally { | ||
this.close(); | ||
} | ||
}; | ||
@@ -49,3 +57,7 @@ if (rxSock) { | ||
(function (UdpTransport) { | ||
async function connect(arg1, port) { | ||
function connect(arg1, port) { | ||
return connectImpl(arg1, port); | ||
} | ||
UdpTransport.connect = connect; | ||
async function connectImpl(arg1, port) { | ||
const opts = typeof arg1 === "string" ? { host: arg1, port } : arg1; | ||
@@ -55,5 +67,4 @@ const sock = await udp.openUnicast(opts); | ||
} | ||
UdpTransport.connect = connect; | ||
/** Create a unicast transport and add to forwarder. */ | ||
UdpTransport.createFace = L3Face.makeCreateFace(connect); | ||
UdpTransport.createFace = L3Face.makeCreateFace(connectImpl); | ||
/** Create a multicast transport. */ | ||
@@ -60,0 +71,0 @@ async function multicast(opts) { |
/// <reference types="node" /> | ||
import { L3Face, Transport } from "@ndn/l3face"; | ||
import type { AddressInfo } from "net"; | ||
import type { AddressInfo } from "node:net"; | ||
import * as udp from "./udp-helper"; | ||
@@ -16,3 +16,3 @@ /** UDP socket transport. */ | ||
close(): void; | ||
tx: (iterable: AsyncIterable<Uint8Array>) => Promise<void>; | ||
readonly tx: (iterable: AsyncIterable<Uint8Array>) => Promise<void>; | ||
} | ||
@@ -29,11 +29,11 @@ export declare namespace UdpTransport { | ||
/** Create a unicast transport and add to forwarder. */ | ||
const createFace: L3Face.CreateFaceFunc<typeof connect>; | ||
const createFace: L3Face.CreateFaceFunc<UdpTransport, [arg1: string | udp.UnicastOptions, port?: number | undefined]>; | ||
/** Create a multicast transport. */ | ||
function multicast(opts: udp.MulticastOptions): Promise<UdpTransport>; | ||
/** Create a multicast transport and add to forwarder. */ | ||
const createMulticastFace: L3Face.CreateFaceFunc<typeof multicast>; | ||
const createMulticastFace: L3Face.CreateFaceFunc<UdpTransport, [opts: udp.MulticastOptions]>; | ||
/** Create multicast transports on every interface. */ | ||
function multicasts(opts?: Omit<udp.MulticastOptions, "intf">): Promise<UdpTransport[]>; | ||
/** Create multicast transports on every interface. */ | ||
const createMulticastFaces: L3Face.CreateFaceFunc<typeof multicasts>; | ||
const createMulticastFaces: L3Face.CreateFaceFunc<UdpTransport[], [opts?: Omit<udp.MulticastOptions, "intf"> | undefined]>; | ||
} |
import { L3Face, StreamTransport } from "@ndn/l3face"; | ||
import * as net from "net"; | ||
import * as net from "node:net"; | ||
/** Unix socket transport. */ | ||
@@ -4,0 +4,0 @@ export class UnixTransport extends StreamTransport { |
/// <reference types="node" /> | ||
import { L3Face, StreamTransport } from "@ndn/l3face"; | ||
import * as net from "net"; | ||
import * as net from "node:net"; | ||
/** Unix socket transport. */ | ||
@@ -17,3 +17,3 @@ export declare class UnixTransport extends StreamTransport { | ||
/** Create a transport and add to forwarder. */ | ||
const createFace: L3Face.CreateFaceFunc<typeof connect>; | ||
const createFace: L3Face.CreateFaceFunc<UnixTransport, [pathOrOpts: string | net.IpcNetConnectOpts]>; | ||
} |
{ | ||
"name": "@ndn/node-transport", | ||
"version": "0.0.20210203", | ||
"version": "0.0.20210930", | ||
"description": "NDNts: Low-Level Transports for Node.js", | ||
@@ -23,8 +23,10 @@ "keywords": [ | ||
"dependencies": { | ||
"@ndn/l3face": "0.0.20210203", | ||
"@ndn/l3face": "0.0.20210930", | ||
"abort-controller": "^3.0.0", | ||
"p-event": "^4.2.0", | ||
"tslib": "^2.1.0" | ||
"tslib": "^2.3.1", | ||
"url-format-lax": "^1.0.0", | ||
"url-parse-lax": "^4.0.0" | ||
}, | ||
"types": "lib/mod.d.ts" | ||
} |
@@ -14,2 +14,3 @@ # @ndn/node-transport | ||
import { Data, Interest, Name } from "@ndn/packet"; | ||
(async () => { | ||
@@ -40,3 +41,3 @@ if (process.env.CI) { return; } | ||
// TcpTransport.connect() establishes a TCP tunnel. | ||
// It accepts either host+port or an options object for net.createConnection(). | ||
// It accepts either host+port or an options object for net.connect(). | ||
try { | ||
@@ -81,5 +82,5 @@ const tcp4 = await TcpTransport.connect("hobo.cs.arizona.edu", 6363); | ||
const multicasts = await UdpTransport.multicasts(); | ||
multicasts.forEach(async (transport, i) => { | ||
for (const transport of multicasts) { | ||
await useInL3Face(transport); | ||
}); | ||
} | ||
``` | ||
@@ -108,3 +109,5 @@ | ||
const faces = await UdpTransport.createMulticastFaces({}); | ||
faces.forEach((face) => face.close()); | ||
for (const face of faces) { | ||
face.close(); | ||
} | ||
})(); | ||
@@ -111,0 +114,0 @@ ``` |
33489
20
728
160
3
6
+ Addedurl-format-lax@^1.0.0
+ Addedurl-parse-lax@^4.0.0
+ Added@ndn/fw@0.0.20210930(transitive)
+ Added@ndn/l3face@0.0.20210930(transitive)
+ Added@ndn/lp@0.0.20210930(transitive)
+ Added@ndn/packet@0.0.20210930(transitive)
+ Added@ndn/tlv@0.0.20210930(transitive)
+ Addedabortable-iterator@3.0.2(transitive)
+ Addedit-pushable@1.4.2(transitive)
+ Addedprepend-http@3.0.1(transitive)
+ Addedretry@0.13.1(transitive)
+ Addedstreaming-iterables@6.2.0(transitive)
+ Addedurl-format-lax@1.0.0(transitive)
+ Addedurl-parse-lax@4.0.0(transitive)
- Removed@ndn/fw@0.0.20210203(transitive)
- Removed@ndn/l3face@0.0.20210203(transitive)
- Removed@ndn/lp@0.0.20210203(transitive)
- Removed@ndn/packet@0.0.20210203(transitive)
- Removed@ndn/tlv@0.0.20210203(transitive)
- Removedit-pushable@1.4.0(transitive)
- Removedretry@0.12.0(transitive)
- Removedstreaming-iterables@5.0.4(transitive)
Updated@ndn/l3face@0.0.20210930
Updatedtslib@^2.3.1