@lakutata/netif 0.0.0-stage → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +299 -2
- package/README.zh-CN.md +229 -0
- package/binding.gyp +43 -0
- package/dist/cjs/exceptions/NetIfException.d.ts +17 -0
- package/dist/cjs/exceptions/NetIfException.js +24 -0
- package/dist/cjs/exceptions/NetIfNotEnforcedException.d.ts +12 -0
- package/dist/cjs/exceptions/NetIfNotEnforcedException.js +19 -0
- package/dist/cjs/exceptions/NetIfNotFoundException.d.ts +12 -0
- package/dist/cjs/exceptions/NetIfNotFoundException.js +19 -0
- package/dist/cjs/exceptions/NetIfNotSupportedException.d.ts +12 -0
- package/dist/cjs/exceptions/NetIfNotSupportedException.js +19 -0
- package/dist/cjs/exceptions/NetIfTimeoutException.d.ts +11 -0
- package/dist/cjs/exceptions/NetIfTimeoutException.js +18 -0
- package/dist/cjs/exports/Netif.d.ts +11 -0
- package/dist/cjs/exports/Netif.js +26 -0
- package/dist/cjs/lib/Addon.d.ts +5 -0
- package/dist/cjs/lib/Addon.js +9 -0
- package/dist/cjs/lib/Attachment.d.ts +152 -0
- package/dist/cjs/lib/Attachment.js +415 -0
- package/dist/cjs/lib/Enforcement.d.ts +22 -0
- package/dist/cjs/lib/Enforcement.js +45 -0
- package/dist/cjs/lib/Functions.d.ts +66 -0
- package/dist/cjs/lib/Functions.js +97 -0
- package/dist/cjs/lib/InterfaceListener.d.ts +92 -0
- package/dist/cjs/lib/InterfaceListener.js +99 -0
- package/dist/cjs/lib/InterfaceUDPSocket.d.ts +119 -0
- package/dist/cjs/lib/InterfaceUDPSocket.js +245 -0
- package/dist/cjs/lib/Internal.d.ts +10 -0
- package/dist/cjs/lib/Internal.js +9 -0
- package/dist/cjs/lib/Native.d.ts +54 -0
- package/dist/cjs/lib/Native.js +83 -0
- package/dist/cjs/lib/NetworkInterface.d.ts +313 -0
- package/dist/cjs/lib/NetworkInterface.js +391 -0
- package/dist/cjs/lib/Registry.d.ts +26 -0
- package/dist/cjs/lib/Registry.js +103 -0
- package/dist/cjs/lib/Snapshot.d.ts +17 -0
- package/dist/cjs/lib/Snapshot.js +84 -0
- package/dist/cjs/lib/Types.d.ts +63 -0
- package/dist/cjs/lib/Types.js +2 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/exceptions/NetIfException.js +20 -0
- package/dist/esm/exceptions/NetIfNotEnforcedException.js +15 -0
- package/dist/esm/exceptions/NetIfNotFoundException.js +15 -0
- package/dist/esm/exceptions/NetIfNotSupportedException.js +15 -0
- package/dist/esm/exceptions/NetIfTimeoutException.js +14 -0
- package/dist/esm/exports/Netif.js +9 -0
- package/dist/esm/lib/Addon.js +10 -0
- package/dist/esm/lib/Attachment.js +410 -0
- package/dist/esm/lib/Enforcement.js +41 -0
- package/dist/esm/lib/Functions.js +92 -0
- package/dist/esm/lib/InterfaceListener.js +95 -0
- package/dist/esm/lib/InterfaceUDPSocket.js +241 -0
- package/dist/esm/lib/Internal.js +6 -0
- package/dist/esm/lib/Native.js +75 -0
- package/dist/esm/lib/NetworkInterface.js +386 -0
- package/dist/esm/lib/Registry.js +100 -0
- package/dist/esm/lib/Snapshot.js +79 -0
- package/dist/esm/lib/Types.js +1 -0
- package/dist/types/exceptions/NetIfException.d.ts +17 -0
- package/dist/types/exceptions/NetIfNotEnforcedException.d.ts +12 -0
- package/dist/types/exceptions/NetIfNotFoundException.d.ts +12 -0
- package/dist/types/exceptions/NetIfNotSupportedException.d.ts +12 -0
- package/dist/types/exceptions/NetIfTimeoutException.d.ts +11 -0
- package/dist/types/exports/Netif.d.ts +11 -0
- package/dist/types/lib/Addon.d.ts +5 -0
- package/dist/types/lib/Attachment.d.ts +152 -0
- package/dist/types/lib/Enforcement.d.ts +22 -0
- package/dist/types/lib/Functions.d.ts +66 -0
- package/dist/types/lib/InterfaceListener.d.ts +92 -0
- package/dist/types/lib/InterfaceUDPSocket.d.ts +119 -0
- package/dist/types/lib/Internal.d.ts +10 -0
- package/dist/types/lib/Native.d.ts +54 -0
- package/dist/types/lib/NetworkInterface.d.ts +313 -0
- package/dist/types/lib/Registry.d.ts +26 -0
- package/dist/types/lib/Snapshot.d.ts +17 -0
- package/dist/types/lib/Types.d.ts +63 -0
- package/native/Interfaces.cpp +34 -0
- package/native/Interfaces.h +47 -0
- package/native/Sockets.h +36 -0
- package/native/Watcher.h +27 -0
- package/native/addon.cpp +195 -0
- package/native/darwin/Interfaces.cpp +150 -0
- package/native/darwin/Sockets.cpp +44 -0
- package/native/darwin/Watcher.cpp +113 -0
- package/native/linux/Interfaces.cpp +133 -0
- package/native/linux/RouteNetlink.h +38 -0
- package/native/linux/Sockets.cpp +89 -0
- package/native/linux/Watcher.cpp +70 -0
- package/native/windows/Interfaces.cpp +78 -0
- package/native/windows/Sockets.cpp +56 -0
- package/native/windows/Watcher.cpp +53 -0
- package/package.json +81 -4
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetIfException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The base of the exceptions of the package: catch it for any of them. Its `errno` is the code of the error of the
|
|
6
|
+
* system (`'EADDRINUSE'`, `'EACCES'`…) when the system refused something, `'E_NETIF'` for an error of the package, the
|
|
7
|
+
* one of the subclass otherwise; its `name` is the name of its class.
|
|
8
|
+
*/
|
|
9
|
+
class NetIfException extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* An exception of a message.
|
|
12
|
+
* @param message The message.
|
|
13
|
+
* @param options The error that caused it (`cause`).
|
|
14
|
+
*/
|
|
15
|
+
constructor(message, options) {
|
|
16
|
+
super(message, options);
|
|
17
|
+
/**
|
|
18
|
+
* `'E_NETIF'`, the code of the error of the system, or the one of the subclass.
|
|
19
|
+
*/
|
|
20
|
+
this.errno = 'E_NETIF';
|
|
21
|
+
this.name = new.target.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NetIfException = NetIfException;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NetIfException } from './NetIfException.js';
|
|
2
|
+
/**
|
|
3
|
+
* A listening with `strict: true` that the system cannot guarantee: the connections and the datagrams reaching the
|
|
4
|
+
* addresses of the interface through another interface would not be refused. Its message tells why (the system, the
|
|
5
|
+
* interface and its setting, the permission missing) and what to do. Its `errno` is `'E_NETIF_NOT_ENFORCED'`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NetIfNotEnforcedException extends NetIfException {
|
|
8
|
+
/**
|
|
9
|
+
* `'E_NETIF_NOT_ENFORCED'`.
|
|
10
|
+
*/
|
|
11
|
+
errno: string | number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetIfNotEnforcedException = void 0;
|
|
4
|
+
const NetIfException_js_1 = require("./NetIfException.js");
|
|
5
|
+
/**
|
|
6
|
+
* A listening with `strict: true` that the system cannot guarantee: the connections and the datagrams reaching the
|
|
7
|
+
* addresses of the interface through another interface would not be refused. Its message tells why (the system, the
|
|
8
|
+
* interface and its setting, the permission missing) and what to do. Its `errno` is `'E_NETIF_NOT_ENFORCED'`.
|
|
9
|
+
*/
|
|
10
|
+
class NetIfNotEnforcedException extends NetIfException_js_1.NetIfException {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
/**
|
|
14
|
+
* `'E_NETIF_NOT_ENFORCED'`.
|
|
15
|
+
*/
|
|
16
|
+
this.errno = 'E_NETIF_NOT_ENFORCED';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NetIfNotEnforcedException = NetIfNotEnforcedException;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NetIfException } from './NetIfException.js';
|
|
2
|
+
/**
|
|
3
|
+
* A network interface that cannot be found: an interface given by an index that does not exist (an index is never
|
|
4
|
+
* given again once its interface is gone), or a hardware address that several interfaces have (a bridge and its ports).
|
|
5
|
+
* Its `errno` is `'E_NETIF_NOT_FOUND'`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NetIfNotFoundException extends NetIfException {
|
|
8
|
+
/**
|
|
9
|
+
* `'E_NETIF_NOT_FOUND'`.
|
|
10
|
+
*/
|
|
11
|
+
errno: string | number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetIfNotFoundException = void 0;
|
|
4
|
+
const NetIfException_js_1 = require("./NetIfException.js");
|
|
5
|
+
/**
|
|
6
|
+
* A network interface that cannot be found: an interface given by an index that does not exist (an index is never
|
|
7
|
+
* given again once its interface is gone), or a hardware address that several interfaces have (a bridge and its ports).
|
|
8
|
+
* Its `errno` is `'E_NETIF_NOT_FOUND'`.
|
|
9
|
+
*/
|
|
10
|
+
class NetIfNotFoundException extends NetIfException_js_1.NetIfException {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
/**
|
|
14
|
+
* `'E_NETIF_NOT_FOUND'`.
|
|
15
|
+
*/
|
|
16
|
+
this.errno = 'E_NETIF_NOT_FOUND';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NetIfNotFoundException = NetIfNotFoundException;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NetIfException } from './NetIfException.js';
|
|
2
|
+
/**
|
|
3
|
+
* An operation the system, or the way the interface is listened on, cannot do: `bindSocket()` outside Linux, the
|
|
4
|
+
* broadcasts and the multicast of a UDP socket bound to the addresses of an interface on Linux and macOS. Its `errno` is
|
|
5
|
+
* `'E_NETIF_NOT_SUPPORTED'`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NetIfNotSupportedException extends NetIfException {
|
|
8
|
+
/**
|
|
9
|
+
* `'E_NETIF_NOT_SUPPORTED'`.
|
|
10
|
+
*/
|
|
11
|
+
errno: string | number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetIfNotSupportedException = void 0;
|
|
4
|
+
const NetIfException_js_1 = require("./NetIfException.js");
|
|
5
|
+
/**
|
|
6
|
+
* An operation the system, or the way the interface is listened on, cannot do: `bindSocket()` outside Linux, the
|
|
7
|
+
* broadcasts and the multicast of a UDP socket bound to the addresses of an interface on Linux and macOS. Its `errno` is
|
|
8
|
+
* `'E_NETIF_NOT_SUPPORTED'`.
|
|
9
|
+
*/
|
|
10
|
+
class NetIfNotSupportedException extends NetIfException_js_1.NetIfException {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
/**
|
|
14
|
+
* `'E_NETIF_NOT_SUPPORTED'`.
|
|
15
|
+
*/
|
|
16
|
+
this.errno = 'E_NETIF_NOT_SUPPORTED';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NetIfNotSupportedException = NetIfNotSupportedException;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NetIfException } from './NetIfException.js';
|
|
2
|
+
/**
|
|
3
|
+
* A wait that ended before what it waited for happened: `waitForAddress()` whose interface got no address in time.
|
|
4
|
+
* Its `errno` is `'E_NETIF_TIMEOUT'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NetIfTimeoutException extends NetIfException {
|
|
7
|
+
/**
|
|
8
|
+
* `'E_NETIF_TIMEOUT'`.
|
|
9
|
+
*/
|
|
10
|
+
errno: string | number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetIfTimeoutException = void 0;
|
|
4
|
+
const NetIfException_js_1 = require("./NetIfException.js");
|
|
5
|
+
/**
|
|
6
|
+
* A wait that ended before what it waited for happened: `waitForAddress()` whose interface got no address in time.
|
|
7
|
+
* Its `errno` is `'E_NETIF_TIMEOUT'`.
|
|
8
|
+
*/
|
|
9
|
+
class NetIfTimeoutException extends NetIfException_js_1.NetIfException {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/**
|
|
13
|
+
* `'E_NETIF_TIMEOUT'`.
|
|
14
|
+
*/
|
|
15
|
+
this.errno = 'E_NETIF_TIMEOUT';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.NetIfTimeoutException = NetIfTimeoutException;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { NetIfException } from '../exceptions/NetIfException.js';
|
|
2
|
+
export { NetIfNotFoundException } from '../exceptions/NetIfNotFoundException.js';
|
|
3
|
+
export { NetIfTimeoutException } from '../exceptions/NetIfTimeoutException.js';
|
|
4
|
+
export { NetIfNotEnforcedException } from '../exceptions/NetIfNotEnforcedException.js';
|
|
5
|
+
export { NetIfNotSupportedException } from '../exceptions/NetIfNotSupportedException.js';
|
|
6
|
+
export { type InterfaceAddress, type NetworkInterfaceInfo } from '../lib/Types.js';
|
|
7
|
+
export { listenOn, listenOnAll, listInterfaces } from '../lib/Functions.js';
|
|
8
|
+
export { type ListeningAddress } from '../lib/Attachment.js';
|
|
9
|
+
export { InterfaceListener, type InterfaceListenerEvents, type ListenOptions } from '../lib/InterfaceListener.js';
|
|
10
|
+
export { type AddressChange, type BindSocketOptions, type BoundSocket, type InterfaceSelector, NetworkInterface, type NetworkInterfaceEvents, type WaitForAddressOptions } from '../lib/NetworkInterface.js';
|
|
11
|
+
export { InterfaceUDPSocket, type InterfaceUDPSocketEvents, type UDPSocketOptions } from '../lib/InterfaceUDPSocket.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterfaceUDPSocket = exports.NetworkInterface = exports.InterfaceListener = exports.listInterfaces = exports.listenOnAll = exports.listenOn = exports.NetIfNotSupportedException = exports.NetIfNotEnforcedException = exports.NetIfTimeoutException = exports.NetIfNotFoundException = exports.NetIfException = void 0;
|
|
4
|
+
var NetIfException_js_1 = require("../exceptions/NetIfException.js");
|
|
5
|
+
Object.defineProperty(exports, "NetIfException", { enumerable: true, get: function () { return NetIfException_js_1.NetIfException; } });
|
|
6
|
+
var NetIfNotFoundException_js_1 = require("../exceptions/NetIfNotFoundException.js");
|
|
7
|
+
Object.defineProperty(exports, "NetIfNotFoundException", { enumerable: true, get: function () { return NetIfNotFoundException_js_1.NetIfNotFoundException; } });
|
|
8
|
+
var NetIfTimeoutException_js_1 = require("../exceptions/NetIfTimeoutException.js");
|
|
9
|
+
Object.defineProperty(exports, "NetIfTimeoutException", { enumerable: true, get: function () { return NetIfTimeoutException_js_1.NetIfTimeoutException; } });
|
|
10
|
+
var NetIfNotEnforcedException_js_1 = require("../exceptions/NetIfNotEnforcedException.js");
|
|
11
|
+
Object.defineProperty(exports, "NetIfNotEnforcedException", { enumerable: true, get: function () { return NetIfNotEnforcedException_js_1.NetIfNotEnforcedException; } });
|
|
12
|
+
var NetIfNotSupportedException_js_1 = require("../exceptions/NetIfNotSupportedException.js");
|
|
13
|
+
Object.defineProperty(exports, "NetIfNotSupportedException", { enumerable: true, get: function () { return NetIfNotSupportedException_js_1.NetIfNotSupportedException; } });
|
|
14
|
+
var Functions_js_1 = require("../lib/Functions.js");
|
|
15
|
+
Object.defineProperty(exports, "listenOn", { enumerable: true, get: function () { return Functions_js_1.listenOn; } });
|
|
16
|
+
Object.defineProperty(exports, "listenOnAll", { enumerable: true, get: function () { return Functions_js_1.listenOnAll; } });
|
|
17
|
+
Object.defineProperty(exports, "listInterfaces", { enumerable: true, get: function () { return Functions_js_1.listInterfaces; } });
|
|
18
|
+
var InterfaceListener_js_1 = require("../lib/InterfaceListener.js");
|
|
19
|
+
Object.defineProperty(exports, "InterfaceListener", { enumerable: true, get: function () { return InterfaceListener_js_1.InterfaceListener; } });
|
|
20
|
+
var NetworkInterface_js_1 = require("../lib/NetworkInterface.js");
|
|
21
|
+
Object.defineProperty(exports, "NetworkInterface", { enumerable: true, get: function () { return NetworkInterface_js_1.NetworkInterface; } });
|
|
22
|
+
var InterfaceUDPSocket_js_1 = require("../lib/InterfaceUDPSocket.js");
|
|
23
|
+
Object.defineProperty(exports, "InterfaceUDPSocket", { enumerable: true, get: function () { return InterfaceUDPSocket_js_1.InterfaceUDPSocket; } });
|
|
24
|
+
|
|
25
|
+
//The default of the entry: the entry itself (scripts/package-build/cjs-package.mjs)
|
|
26
|
+
if (!Object.prototype.hasOwnProperty.call(exports, 'default')) Object.defineProperty(exports, 'default', {value: exports})
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The addon of the package (build/Release/netif.node), written by the build (scripts/addon.mjs) in place of this one: a
|
|
3
|
+
* require of its file by a path from the module, which the builder of lakutata follows when it packs an application
|
|
4
|
+
*/
|
|
5
|
+
export declare const addon: unknown;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addon = void 0;
|
|
4
|
+
try {
|
|
5
|
+
exports.addon = require(require("node:path").join(__dirname, "..", "..", "..", "build", "Release", "netif.node"));
|
|
6
|
+
} catch (error) {
|
|
7
|
+
if (error?.code === 'MODULE_NOT_FOUND') throw new Error("The addon of @lakutata/netif (build/Release/netif.node) is not built: the install script of the package did not run. Bun and pnpm run it only for the dependencies they trust (trustedDependencies in the package.json for Bun, pnpm approve-builds for pnpm): allow it, then install again or run npm rebuild @lakutata/netif.", {cause: error});
|
|
8
|
+
throw error;
|
|
9
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { type Family } from './Enforcement.js';
|
|
3
|
+
import { type NetworkInterface } from './NetworkInterface.js';
|
|
4
|
+
import { type InterfaceAddress } from './Types.js';
|
|
5
|
+
/**
|
|
6
|
+
* An address a listener or a UDP socket of an interface can be reached at.
|
|
7
|
+
*/
|
|
8
|
+
export interface ListeningAddress {
|
|
9
|
+
/**
|
|
10
|
+
* The address (an IPv6 address without its scope).
|
|
11
|
+
*/
|
|
12
|
+
address: string;
|
|
13
|
+
/**
|
|
14
|
+
* `'IPv4'` or `'IPv6'`.
|
|
15
|
+
*/
|
|
16
|
+
family: 'IPv4' | 'IPv6';
|
|
17
|
+
/**
|
|
18
|
+
* The port.
|
|
19
|
+
*/
|
|
20
|
+
port: number;
|
|
21
|
+
/**
|
|
22
|
+
* IPv6 only: the scope of the address (the index of the interface for a link-local one), 0 for a global one.
|
|
23
|
+
*/
|
|
24
|
+
scopeid?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The options common to the listeners and the UDP sockets of an interface
|
|
28
|
+
*/
|
|
29
|
+
export interface AttachmentOptions {
|
|
30
|
+
port: number;
|
|
31
|
+
family?: 'IPv4' | 'IPv6' | 'both';
|
|
32
|
+
strict?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* What a socket of an attachment is made on: a socket bound to the interface (Linux, its descriptor), or an address of
|
|
36
|
+
* the interface (the host with its scope, and the port)
|
|
37
|
+
*/
|
|
38
|
+
export type Target = {
|
|
39
|
+
fd: number;
|
|
40
|
+
} | {
|
|
41
|
+
host: string;
|
|
42
|
+
port: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A socket of an attachment: bound to the interface, or to one of its addresses
|
|
46
|
+
*/
|
|
47
|
+
export interface Endpoint<Handle> {
|
|
48
|
+
key: string;
|
|
49
|
+
family: Family;
|
|
50
|
+
handle: Handle;
|
|
51
|
+
address?: InterfaceAddress;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The code of the error of the system an error carries
|
|
55
|
+
*/
|
|
56
|
+
export declare function codeOf(error: unknown): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* The sockets of an interface kept matching it (the base of the listeners and the UDP sockets): on Linux sockets bound
|
|
59
|
+
* to the interface, one by family, made again when the interface is plugged back (a new index); elsewhere (and on Linux
|
|
60
|
+
* without the permission to bind) a socket by address of the interface, made and closed as its addresses change. The
|
|
61
|
+
* guarantee that the system refuses what comes through another interface (`enforced`), followed; with `strict` the
|
|
62
|
+
* sockets are closed while it is lost. The changes of the interface are followed one at a time.
|
|
63
|
+
*/
|
|
64
|
+
export declare abstract class Attachment<Events extends Record<keyof Events, unknown[]>, Handle> extends EventEmitter<Events> {
|
|
65
|
+
#private;
|
|
66
|
+
/**
|
|
67
|
+
* The interface.
|
|
68
|
+
*/
|
|
69
|
+
readonly networkInterface: NetworkInterface;
|
|
70
|
+
protected readonly families: Family[];
|
|
71
|
+
protected readonly strict: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Internal: the options checked.
|
|
74
|
+
* @param networkInterface The interface.
|
|
75
|
+
* @param options The port, the families and `strict`.
|
|
76
|
+
* @param ownsInterface Whether the interface is closed with it.
|
|
77
|
+
*/
|
|
78
|
+
protected constructor(networkInterface: NetworkInterface, options: AttachmentOptions, ownsInterface: boolean);
|
|
79
|
+
/**
|
|
80
|
+
* Whether a TCP (true) or a UDP socket is bound to the interface
|
|
81
|
+
*/
|
|
82
|
+
protected abstract readonly stream: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Makes a socket of a family on the target: its handle once it listens (or is bound)
|
|
85
|
+
*/
|
|
86
|
+
protected abstract openHandle(target: Target, family: Family): Promise<Handle>;
|
|
87
|
+
/**
|
|
88
|
+
* The port of a socket made
|
|
89
|
+
*/
|
|
90
|
+
protected abstract portOf(handle: Handle): number | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Closes a socket
|
|
93
|
+
*/
|
|
94
|
+
protected abstract closeHandle(handle: Handle): void;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the system refuses, through another interface, what is sent to the addresses of the interface: always on
|
|
97
|
+
* Linux (the sockets are bound to the interface), on Windows while every other interface receives with the strong
|
|
98
|
+
* host model and does not forward, on macOS when it is set to (`net.inet.ip.check_interface` 2, forwarding off).
|
|
99
|
+
*/
|
|
100
|
+
get enforced(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Why what comes through another interface is not refused, `undefined` while it is.
|
|
103
|
+
*/
|
|
104
|
+
get reason(): string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* The port, `undefined` until a port 0 was given one by the system.
|
|
107
|
+
*/
|
|
108
|
+
get port(): number | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Whether the interface is listened on now (it exists, and has an address where its addresses are listened on).
|
|
111
|
+
*/
|
|
112
|
+
get listening(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* The addresses it can be reached at now. On Linux the sockets bound to the interface also get what is sent to
|
|
115
|
+
* another address of the machine through the interface.
|
|
116
|
+
*/
|
|
117
|
+
get addresses(): ListeningAddress[];
|
|
118
|
+
/**
|
|
119
|
+
* Whether it was closed.
|
|
120
|
+
*/
|
|
121
|
+
get closed(): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the sockets are bound to the interface (Linux), not to its addresses
|
|
124
|
+
*/
|
|
125
|
+
protected get boundToInterface(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* The sockets now
|
|
128
|
+
*/
|
|
129
|
+
protected endpoints(): Endpoint<Handle>[];
|
|
130
|
+
/**
|
|
131
|
+
* A socket made, before it is counted (its settings applied: the broadcasts, the multicast groups)
|
|
132
|
+
*/
|
|
133
|
+
protected prepare(_endpoint: Endpoint<Handle>): void;
|
|
134
|
+
/**
|
|
135
|
+
* A socket closed, no longer counted
|
|
136
|
+
*/
|
|
137
|
+
protected released(_endpoint: Endpoint<Handle>): void;
|
|
138
|
+
/**
|
|
139
|
+
* Internal: the first binding, which the method that made it waits for.
|
|
140
|
+
* @returns It.
|
|
141
|
+
*/
|
|
142
|
+
start(): Promise<this>;
|
|
143
|
+
/**
|
|
144
|
+
* Stops: the sockets closed (the listener does not wait for the connections established, which are left to the
|
|
145
|
+
* server).
|
|
146
|
+
*/
|
|
147
|
+
close(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* An error of a binding again, or of a socket: the error event, the binding retried a little later
|
|
150
|
+
*/
|
|
151
|
+
protected failed(error: unknown): void;
|
|
152
|
+
}
|