@cosyte/mllp 0.1.9 → 0.1.11
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/CHANGELOG.md +10 -0
- package/dist/index.cjs +83 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -7
- package/dist/index.d.ts +135 -7
- package/dist/index.mjs +83 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1615,9 +1615,18 @@ type ConnectionErrorPhase = "connect" | "send" | "receive" | "close" | "reconnec
|
|
|
1615
1615
|
* server, …). See `isTlsProtocolError` for the boundary. Pure TCP-level
|
|
1616
1616
|
* failures (`ECONNREFUSED`, `ETIMEDOUT`, …) on a TLS-configured
|
|
1617
1617
|
* connection carry **no** `connectionCause`, the same shape as plaintext.
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
1618
|
+
* - `'framing-fatal'`, the peer sent bytes the decoder could not accept, or a
|
|
1619
|
+
* frame past the size cap. Classified **permanent**.
|
|
1620
|
+
* - `'connect-timeout'`, the connection was not established within
|
|
1621
|
+
* `ClientOptions.connectTimeoutMs`: the TCP connect, or the TLS handshake
|
|
1622
|
+
* after it, did not complete in time and the socket was destroyed. Nothing
|
|
1623
|
+
* was written, so no message reached the peer. The `cause` carries
|
|
1624
|
+
* `code: 'ETIMEDOUT'`, and it is classified **transient** by
|
|
1625
|
+
* `isTransientConnectionError`, like the operating system's own connect
|
|
1626
|
+
* timeout: a peer that is down or unreachable now may answer later.
|
|
1627
|
+
*
|
|
1628
|
+
* Scope note: the `'tls-verify'`/`'tls-handshake'`/`'connect-timeout'` values
|
|
1629
|
+
* are attached on the client's **initial `connect()` path**. Failures on the auto-reconnect
|
|
1621
1630
|
* path surface as raw socket errors, their transient/permanent
|
|
1622
1631
|
* classification still applies, but they do not (yet) carry a
|
|
1623
1632
|
* `connectionCause`.
|
|
@@ -1630,7 +1639,7 @@ type ConnectionErrorPhase = "connect" | "send" | "receive" | "close" | "reconnec
|
|
|
1630
1639
|
* }
|
|
1631
1640
|
* ```
|
|
1632
1641
|
*/
|
|
1633
|
-
type ConnectionErrorCause = "fifo-unsafe" | "in-flight-orphan" | "tls-verify" | "tls-handshake" | "framing-fatal";
|
|
1642
|
+
type ConnectionErrorCause = "fifo-unsafe" | "in-flight-orphan" | "tls-verify" | "tls-handshake" | "framing-fatal" | "connect-timeout";
|
|
1634
1643
|
/**
|
|
1635
1644
|
* Thrown (or emitted via `onError`) for socket-layer problems such as
|
|
1636
1645
|
* connection refused, ECONNRESET, ETIMEDOUT, or DNS failure.
|
|
@@ -1856,6 +1865,56 @@ interface AckModeWarningEvent {
|
|
|
1856
1865
|
/** Wall-clock time at point of emission. */
|
|
1857
1866
|
readonly timestamp: Date;
|
|
1858
1867
|
}
|
|
1868
|
+
/**
|
|
1869
|
+
* The stable code on a {@link ConnectionRejectedEvent}: a connection arrived while the server
|
|
1870
|
+
* already held {@link ServerOptions.maxConnections} connections, and it was closed at accept.
|
|
1871
|
+
*
|
|
1872
|
+
* Part of the public surface: renaming or removing it is a breaking change.
|
|
1873
|
+
*
|
|
1874
|
+
* @example
|
|
1875
|
+
* ```typescript
|
|
1876
|
+
* import { MLLP_CONNECTION_LIMIT_REACHED } from '@cosyte/mllp';
|
|
1877
|
+
* server.on('connectionRejected', (e) => {
|
|
1878
|
+
* if (e.code === MLLP_CONNECTION_LIMIT_REACHED) metrics.increment('mllp.over_cap');
|
|
1879
|
+
* });
|
|
1880
|
+
* ```
|
|
1881
|
+
*/
|
|
1882
|
+
declare const MLLP_CONNECTION_LIMIT_REACHED = "MLLP_CONNECTION_LIMIT_REACHED";
|
|
1883
|
+
/**
|
|
1884
|
+
* Payload of the server `'connectionRejected'` event: a connection was closed at accept and never
|
|
1885
|
+
* reached the server's handler.
|
|
1886
|
+
*
|
|
1887
|
+
* Emitted when a connection arrives while the server already holds
|
|
1888
|
+
* {@link ServerOptions.maxConnections} sockets. The socket is closed before any byte is read from
|
|
1889
|
+
* it and before any TLS handshake, so the rejected peer never becomes a `Connection`, never fires
|
|
1890
|
+
* `'connection'` and never reaches `onMessage`. The peer sees its connection close; a client that
|
|
1891
|
+
* reconnects will try again.
|
|
1892
|
+
*
|
|
1893
|
+
* **PHI-safe by construction:** a stable code, a fixed message, the configured cap and the peer's
|
|
1894
|
+
* address and port (the routing metadata the `'connection'` event already carries), never a byte
|
|
1895
|
+
* of payload. The object is `Object.freeze()`'d before emission.
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* ```typescript
|
|
1899
|
+
* server.on('connectionRejected', ({ code, remoteAddress }) => {
|
|
1900
|
+
* logger.warn({ code, remoteAddress });
|
|
1901
|
+
* });
|
|
1902
|
+
* ```
|
|
1903
|
+
*/
|
|
1904
|
+
interface ConnectionRejectedEvent {
|
|
1905
|
+
/** Why the connection was closed. */
|
|
1906
|
+
readonly code: typeof MLLP_CONNECTION_LIMIT_REACHED;
|
|
1907
|
+
/** Fixed text for `code`. Never interpolated. */
|
|
1908
|
+
readonly message: string;
|
|
1909
|
+
/** The configured {@link ServerOptions.maxConnections}. */
|
|
1910
|
+
readonly maxConnections: number;
|
|
1911
|
+
/** The rejected peer's address, or `null` if it could not be read. */
|
|
1912
|
+
readonly remoteAddress: string | null;
|
|
1913
|
+
/** The rejected peer's port, or `null` if it could not be read. */
|
|
1914
|
+
readonly remotePort: number | null;
|
|
1915
|
+
/** Wall-clock time at point of emission. */
|
|
1916
|
+
readonly timestamp: Date;
|
|
1917
|
+
}
|
|
1859
1918
|
/**
|
|
1860
1919
|
* Observability snapshot returned by `server.getStats()`.
|
|
1861
1920
|
*
|
|
@@ -2008,6 +2067,23 @@ interface ServerOptions {
|
|
|
2008
2067
|
* @default false
|
|
2009
2068
|
*/
|
|
2010
2069
|
allowWildcardBind?: boolean;
|
|
2070
|
+
/**
|
|
2071
|
+
* The most connections this server holds at once. A connection that arrives while the server
|
|
2072
|
+
* already holds this many is closed at accept: it never reaches `onMessage` or the
|
|
2073
|
+
* `'connection'` event, and the server emits `'connectionRejected'`
|
|
2074
|
+
* ({@link ConnectionRejectedEvent}, code `MLLP_CONNECTION_LIMIT_REACHED`) instead.
|
|
2075
|
+
*
|
|
2076
|
+
* The count is of open sockets, the number that bounds file descriptors: it includes a TLS
|
|
2077
|
+
* handshake still in progress, and a connection counts until its socket has fully closed. An
|
|
2078
|
+
* over-cap TLS connection is closed before its handshake, so it costs no handshake work and is
|
|
2079
|
+
* not a `'tlsClientError'`.
|
|
2080
|
+
*
|
|
2081
|
+
* Must be a positive integer; anything else throws a `RangeError` at construction. Unset means
|
|
2082
|
+
* no cap.
|
|
2083
|
+
*
|
|
2084
|
+
* @default undefined (no cap)
|
|
2085
|
+
*/
|
|
2086
|
+
maxConnections?: number;
|
|
2011
2087
|
}
|
|
2012
2088
|
/**
|
|
2013
2089
|
* Options for `createStarterServer()`, the "three lines of code" factory.
|
|
@@ -2080,6 +2156,9 @@ interface StarterServerOptions extends ServerOptions {
|
|
|
2080
2156
|
* `'tlsNegotiated'` ({@link NegotiatedTlsParameters}, the protocol version and cipher
|
|
2081
2157
|
* suite each accepted link actually negotiated, once per completed handshake and never
|
|
2082
2158
|
* on a plaintext listener).
|
|
2159
|
+
* With {@link ServerOptions.maxConnections} set, `'connectionRejected'`
|
|
2160
|
+
* ({@link ConnectionRejectedEvent}) reports each connection closed at accept because the server
|
|
2161
|
+
* was already full; such a connection never fires `'connection'` and never reaches `onMessage`.
|
|
2083
2162
|
* All event payloads are `Object.freeze()`'d before emission.
|
|
2084
2163
|
*
|
|
2085
2164
|
* @example
|
|
@@ -2134,6 +2213,13 @@ declare class MllpServer extends EventEmitter {
|
|
|
2134
2213
|
* @param opts - Server options (bind host/port, auto-ACK policy, message handler, framing, …).
|
|
2135
2214
|
*/
|
|
2136
2215
|
constructor(opts: ServerOptions);
|
|
2216
|
+
/**
|
|
2217
|
+
* Report a connection the listener closed at accept because the cap was full.
|
|
2218
|
+
*
|
|
2219
|
+
* Contained: this runs inside the listener's own 'drop' callback, so a throwing subscriber would
|
|
2220
|
+
* otherwise unwind into the accept path. The throw is surfaced on 'error' instead.
|
|
2221
|
+
*/
|
|
2222
|
+
private _onConnectionOverCap;
|
|
2137
2223
|
/**
|
|
2138
2224
|
* Start listening on the given port.
|
|
2139
2225
|
*
|
|
@@ -3065,6 +3151,26 @@ interface ClientOptions {
|
|
|
3065
3151
|
* @default undefined (off)
|
|
3066
3152
|
*/
|
|
3067
3153
|
readonly deadPeerTimeoutMs?: number;
|
|
3154
|
+
/**
|
|
3155
|
+
* Bound, in milliseconds, on establishing each connection: the TCP connect and, when
|
|
3156
|
+
* {@link ClientOptions.tls} is set, the TLS handshake after it. The clock starts when the
|
|
3157
|
+
* socket is created and stops at `'connect'` (plaintext) or `'secureConnect'` (TLS).
|
|
3158
|
+
*
|
|
3159
|
+
* On expiry the socket is destroyed. On `connect()` the promise rejects with an
|
|
3160
|
+
* `MllpConnectionError` whose `phase` is `'connect'` and whose `connectionCause` is
|
|
3161
|
+
* `'connect-timeout'`; nothing was written, so no message can have reached the peer. On an
|
|
3162
|
+
* auto-reconnect attempt the failure feeds the reconnect policy like any other connect
|
|
3163
|
+
* failure: `RetryContext.lastError` carries `code: 'ETIMEDOUT'` and it is classified
|
|
3164
|
+
* **transient**, so the client backs off and tries again.
|
|
3165
|
+
*
|
|
3166
|
+
* Must be an integer from 1 to 2147483647 (the largest delay a Node timer takes); anything else
|
|
3167
|
+
* throws a `RangeError` at construction. Unset means no bound of our own: a connect waits on
|
|
3168
|
+
* the operating system, and a TLS handshake against a peer that accepts the TCP connection and
|
|
3169
|
+
* never answers waits indefinitely.
|
|
3170
|
+
*
|
|
3171
|
+
* @default undefined (no bound)
|
|
3172
|
+
*/
|
|
3173
|
+
readonly connectTimeoutMs?: number;
|
|
3068
3174
|
/**
|
|
3069
3175
|
* Enable TLS (MLLPS) for this connection. `true` enables TLS with
|
|
3070
3176
|
* all defaults, including certificate verification **on**. Pass a
|
|
@@ -3304,6 +3410,9 @@ declare class MllpClient extends EventEmitter {
|
|
|
3304
3410
|
* TLS failures carry a `connectionCause`: `'tls-verify'` for certificate
|
|
3305
3411
|
* verification failures, `'tls-handshake'` for TLS-protocol-shaped failures
|
|
3306
3412
|
* ({@link isTlsProtocolError}); pure TCP failures carry none.
|
|
3413
|
+
* - `MllpConnectionError({ phase: 'connect', connectionCause: 'connect-timeout' })` if
|
|
3414
|
+
* {@link ClientOptions.connectTimeoutMs} is set and the TCP connect, or the TLS handshake
|
|
3415
|
+
* after it, did not complete in time. The socket is destroyed; nothing was written.
|
|
3307
3416
|
* - `MllpTlsConfigurationError` if the configured cipher-suite list cannot be
|
|
3308
3417
|
* honoured (the runtime rejects it, or `atnaTransportSecurity` and `ciphers`
|
|
3309
3418
|
* both declare one). Raised **before** a socket is opened, so nothing is left
|
|
@@ -3348,6 +3457,18 @@ declare class MllpClient extends EventEmitter {
|
|
|
3348
3457
|
* against it.
|
|
3349
3458
|
*/
|
|
3350
3459
|
private _createSocketAndTransport;
|
|
3460
|
+
/**
|
|
3461
|
+
* Bound one connection attempt by {@link ClientOptions.connectTimeoutMs}, when it is set.
|
|
3462
|
+
*
|
|
3463
|
+
* Armed after the `Connection` has registered its own socket listeners (its set-once
|
|
3464
|
+
* `onClose`/`onError` would otherwise remove ours). The timer stops at the socket's connect
|
|
3465
|
+
* event (`'secureConnect'` for TLS, so the handshake is inside the bound) or at its `'close'`,
|
|
3466
|
+
* whichever comes first; a refused connect or an abort therefore leaves no timer behind. On
|
|
3467
|
+
* expiry the socket is destroyed with a {@link ConnectTimeoutCause}, which reaches the same
|
|
3468
|
+
* `'error'` listeners as any other connect failure: `connect()` rejects, and a reconnect
|
|
3469
|
+
* attempt hands it to the reconnect classifier.
|
|
3470
|
+
*/
|
|
3471
|
+
private _armConnectTimeout;
|
|
3351
3472
|
/**
|
|
3352
3473
|
* Wrap a connect-phase socket error as `MllpConnectionError`, classifying
|
|
3353
3474
|
* TLS failures into the additive `connectionCause`:
|
|
@@ -3885,6 +4006,11 @@ interface StarterClientOptions {
|
|
|
3885
4006
|
readonly keepaliveIntervalMs?: number;
|
|
3886
4007
|
/** Application-idle dead-peer timeout ms. */
|
|
3887
4008
|
readonly deadPeerTimeoutMs?: number;
|
|
4009
|
+
/**
|
|
4010
|
+
* Bound on the TCP connect and TLS handshake, in ms. Passthrough to
|
|
4011
|
+
* `ClientOptions.connectTimeoutMs`; unset means no bound, as there.
|
|
4012
|
+
*/
|
|
4013
|
+
readonly connectTimeoutMs?: number;
|
|
3888
4014
|
/** Enable TLS (MLLPS) for this connection. Passthrough to `ClientOptions.tls`. */
|
|
3889
4015
|
readonly tls?: TlsOptions | true;
|
|
3890
4016
|
/**
|
|
@@ -4295,7 +4421,9 @@ declare function isTlsProtocolError(err: unknown): boolean;
|
|
|
4295
4421
|
* Classification table:
|
|
4296
4422
|
* - `ENOTFOUND`, `EACCES` → **permanent** (`false`)
|
|
4297
4423
|
* - `ECONNREFUSED`, `ECONNRESET`, `ETIMEDOUT`, `EHOSTUNREACH`,
|
|
4298
|
-
* `ENETUNREACH`, `EPIPE` → **transient** (`true`)
|
|
4424
|
+
* `ENETUNREACH`, `EPIPE` → **transient** (`true`). An expired
|
|
4425
|
+
* `ClientOptions.connectTimeoutMs` is one of these: its error carries
|
|
4426
|
+
* `ETIMEDOUT`, the code of the operating system's own connect timeout.
|
|
4299
4427
|
* - `CERT_*` and `UNABLE_TO_VERIFY_LEAF_SIGNATURE` /
|
|
4300
4428
|
* `DEPTH_ZERO_SELF_SIGNED_CERT` / `SELF_SIGNED_CERT_IN_CHAIN`
|
|
4301
4429
|
* (any {@link isTlsVerificationErrorCode} code) → **permanent** (`false`),
|
|
@@ -4952,5 +5080,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
|
|
|
4952
5080
|
*/
|
|
4953
5081
|
declare const VERSION: string;
|
|
4954
5082
|
|
|
4955
|
-
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
4956
|
-
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
|
|
5083
|
+
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
5084
|
+
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionRejectedEvent, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1615,9 +1615,18 @@ type ConnectionErrorPhase = "connect" | "send" | "receive" | "close" | "reconnec
|
|
|
1615
1615
|
* server, …). See `isTlsProtocolError` for the boundary. Pure TCP-level
|
|
1616
1616
|
* failures (`ECONNREFUSED`, `ETIMEDOUT`, …) on a TLS-configured
|
|
1617
1617
|
* connection carry **no** `connectionCause`, the same shape as plaintext.
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
1618
|
+
* - `'framing-fatal'`, the peer sent bytes the decoder could not accept, or a
|
|
1619
|
+
* frame past the size cap. Classified **permanent**.
|
|
1620
|
+
* - `'connect-timeout'`, the connection was not established within
|
|
1621
|
+
* `ClientOptions.connectTimeoutMs`: the TCP connect, or the TLS handshake
|
|
1622
|
+
* after it, did not complete in time and the socket was destroyed. Nothing
|
|
1623
|
+
* was written, so no message reached the peer. The `cause` carries
|
|
1624
|
+
* `code: 'ETIMEDOUT'`, and it is classified **transient** by
|
|
1625
|
+
* `isTransientConnectionError`, like the operating system's own connect
|
|
1626
|
+
* timeout: a peer that is down or unreachable now may answer later.
|
|
1627
|
+
*
|
|
1628
|
+
* Scope note: the `'tls-verify'`/`'tls-handshake'`/`'connect-timeout'` values
|
|
1629
|
+
* are attached on the client's **initial `connect()` path**. Failures on the auto-reconnect
|
|
1621
1630
|
* path surface as raw socket errors, their transient/permanent
|
|
1622
1631
|
* classification still applies, but they do not (yet) carry a
|
|
1623
1632
|
* `connectionCause`.
|
|
@@ -1630,7 +1639,7 @@ type ConnectionErrorPhase = "connect" | "send" | "receive" | "close" | "reconnec
|
|
|
1630
1639
|
* }
|
|
1631
1640
|
* ```
|
|
1632
1641
|
*/
|
|
1633
|
-
type ConnectionErrorCause = "fifo-unsafe" | "in-flight-orphan" | "tls-verify" | "tls-handshake" | "framing-fatal";
|
|
1642
|
+
type ConnectionErrorCause = "fifo-unsafe" | "in-flight-orphan" | "tls-verify" | "tls-handshake" | "framing-fatal" | "connect-timeout";
|
|
1634
1643
|
/**
|
|
1635
1644
|
* Thrown (or emitted via `onError`) for socket-layer problems such as
|
|
1636
1645
|
* connection refused, ECONNRESET, ETIMEDOUT, or DNS failure.
|
|
@@ -1856,6 +1865,56 @@ interface AckModeWarningEvent {
|
|
|
1856
1865
|
/** Wall-clock time at point of emission. */
|
|
1857
1866
|
readonly timestamp: Date;
|
|
1858
1867
|
}
|
|
1868
|
+
/**
|
|
1869
|
+
* The stable code on a {@link ConnectionRejectedEvent}: a connection arrived while the server
|
|
1870
|
+
* already held {@link ServerOptions.maxConnections} connections, and it was closed at accept.
|
|
1871
|
+
*
|
|
1872
|
+
* Part of the public surface: renaming or removing it is a breaking change.
|
|
1873
|
+
*
|
|
1874
|
+
* @example
|
|
1875
|
+
* ```typescript
|
|
1876
|
+
* import { MLLP_CONNECTION_LIMIT_REACHED } from '@cosyte/mllp';
|
|
1877
|
+
* server.on('connectionRejected', (e) => {
|
|
1878
|
+
* if (e.code === MLLP_CONNECTION_LIMIT_REACHED) metrics.increment('mllp.over_cap');
|
|
1879
|
+
* });
|
|
1880
|
+
* ```
|
|
1881
|
+
*/
|
|
1882
|
+
declare const MLLP_CONNECTION_LIMIT_REACHED = "MLLP_CONNECTION_LIMIT_REACHED";
|
|
1883
|
+
/**
|
|
1884
|
+
* Payload of the server `'connectionRejected'` event: a connection was closed at accept and never
|
|
1885
|
+
* reached the server's handler.
|
|
1886
|
+
*
|
|
1887
|
+
* Emitted when a connection arrives while the server already holds
|
|
1888
|
+
* {@link ServerOptions.maxConnections} sockets. The socket is closed before any byte is read from
|
|
1889
|
+
* it and before any TLS handshake, so the rejected peer never becomes a `Connection`, never fires
|
|
1890
|
+
* `'connection'` and never reaches `onMessage`. The peer sees its connection close; a client that
|
|
1891
|
+
* reconnects will try again.
|
|
1892
|
+
*
|
|
1893
|
+
* **PHI-safe by construction:** a stable code, a fixed message, the configured cap and the peer's
|
|
1894
|
+
* address and port (the routing metadata the `'connection'` event already carries), never a byte
|
|
1895
|
+
* of payload. The object is `Object.freeze()`'d before emission.
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* ```typescript
|
|
1899
|
+
* server.on('connectionRejected', ({ code, remoteAddress }) => {
|
|
1900
|
+
* logger.warn({ code, remoteAddress });
|
|
1901
|
+
* });
|
|
1902
|
+
* ```
|
|
1903
|
+
*/
|
|
1904
|
+
interface ConnectionRejectedEvent {
|
|
1905
|
+
/** Why the connection was closed. */
|
|
1906
|
+
readonly code: typeof MLLP_CONNECTION_LIMIT_REACHED;
|
|
1907
|
+
/** Fixed text for `code`. Never interpolated. */
|
|
1908
|
+
readonly message: string;
|
|
1909
|
+
/** The configured {@link ServerOptions.maxConnections}. */
|
|
1910
|
+
readonly maxConnections: number;
|
|
1911
|
+
/** The rejected peer's address, or `null` if it could not be read. */
|
|
1912
|
+
readonly remoteAddress: string | null;
|
|
1913
|
+
/** The rejected peer's port, or `null` if it could not be read. */
|
|
1914
|
+
readonly remotePort: number | null;
|
|
1915
|
+
/** Wall-clock time at point of emission. */
|
|
1916
|
+
readonly timestamp: Date;
|
|
1917
|
+
}
|
|
1859
1918
|
/**
|
|
1860
1919
|
* Observability snapshot returned by `server.getStats()`.
|
|
1861
1920
|
*
|
|
@@ -2008,6 +2067,23 @@ interface ServerOptions {
|
|
|
2008
2067
|
* @default false
|
|
2009
2068
|
*/
|
|
2010
2069
|
allowWildcardBind?: boolean;
|
|
2070
|
+
/**
|
|
2071
|
+
* The most connections this server holds at once. A connection that arrives while the server
|
|
2072
|
+
* already holds this many is closed at accept: it never reaches `onMessage` or the
|
|
2073
|
+
* `'connection'` event, and the server emits `'connectionRejected'`
|
|
2074
|
+
* ({@link ConnectionRejectedEvent}, code `MLLP_CONNECTION_LIMIT_REACHED`) instead.
|
|
2075
|
+
*
|
|
2076
|
+
* The count is of open sockets, the number that bounds file descriptors: it includes a TLS
|
|
2077
|
+
* handshake still in progress, and a connection counts until its socket has fully closed. An
|
|
2078
|
+
* over-cap TLS connection is closed before its handshake, so it costs no handshake work and is
|
|
2079
|
+
* not a `'tlsClientError'`.
|
|
2080
|
+
*
|
|
2081
|
+
* Must be a positive integer; anything else throws a `RangeError` at construction. Unset means
|
|
2082
|
+
* no cap.
|
|
2083
|
+
*
|
|
2084
|
+
* @default undefined (no cap)
|
|
2085
|
+
*/
|
|
2086
|
+
maxConnections?: number;
|
|
2011
2087
|
}
|
|
2012
2088
|
/**
|
|
2013
2089
|
* Options for `createStarterServer()`, the "three lines of code" factory.
|
|
@@ -2080,6 +2156,9 @@ interface StarterServerOptions extends ServerOptions {
|
|
|
2080
2156
|
* `'tlsNegotiated'` ({@link NegotiatedTlsParameters}, the protocol version and cipher
|
|
2081
2157
|
* suite each accepted link actually negotiated, once per completed handshake and never
|
|
2082
2158
|
* on a plaintext listener).
|
|
2159
|
+
* With {@link ServerOptions.maxConnections} set, `'connectionRejected'`
|
|
2160
|
+
* ({@link ConnectionRejectedEvent}) reports each connection closed at accept because the server
|
|
2161
|
+
* was already full; such a connection never fires `'connection'` and never reaches `onMessage`.
|
|
2083
2162
|
* All event payloads are `Object.freeze()`'d before emission.
|
|
2084
2163
|
*
|
|
2085
2164
|
* @example
|
|
@@ -2134,6 +2213,13 @@ declare class MllpServer extends EventEmitter {
|
|
|
2134
2213
|
* @param opts - Server options (bind host/port, auto-ACK policy, message handler, framing, …).
|
|
2135
2214
|
*/
|
|
2136
2215
|
constructor(opts: ServerOptions);
|
|
2216
|
+
/**
|
|
2217
|
+
* Report a connection the listener closed at accept because the cap was full.
|
|
2218
|
+
*
|
|
2219
|
+
* Contained: this runs inside the listener's own 'drop' callback, so a throwing subscriber would
|
|
2220
|
+
* otherwise unwind into the accept path. The throw is surfaced on 'error' instead.
|
|
2221
|
+
*/
|
|
2222
|
+
private _onConnectionOverCap;
|
|
2137
2223
|
/**
|
|
2138
2224
|
* Start listening on the given port.
|
|
2139
2225
|
*
|
|
@@ -3065,6 +3151,26 @@ interface ClientOptions {
|
|
|
3065
3151
|
* @default undefined (off)
|
|
3066
3152
|
*/
|
|
3067
3153
|
readonly deadPeerTimeoutMs?: number;
|
|
3154
|
+
/**
|
|
3155
|
+
* Bound, in milliseconds, on establishing each connection: the TCP connect and, when
|
|
3156
|
+
* {@link ClientOptions.tls} is set, the TLS handshake after it. The clock starts when the
|
|
3157
|
+
* socket is created and stops at `'connect'` (plaintext) or `'secureConnect'` (TLS).
|
|
3158
|
+
*
|
|
3159
|
+
* On expiry the socket is destroyed. On `connect()` the promise rejects with an
|
|
3160
|
+
* `MllpConnectionError` whose `phase` is `'connect'` and whose `connectionCause` is
|
|
3161
|
+
* `'connect-timeout'`; nothing was written, so no message can have reached the peer. On an
|
|
3162
|
+
* auto-reconnect attempt the failure feeds the reconnect policy like any other connect
|
|
3163
|
+
* failure: `RetryContext.lastError` carries `code: 'ETIMEDOUT'` and it is classified
|
|
3164
|
+
* **transient**, so the client backs off and tries again.
|
|
3165
|
+
*
|
|
3166
|
+
* Must be an integer from 1 to 2147483647 (the largest delay a Node timer takes); anything else
|
|
3167
|
+
* throws a `RangeError` at construction. Unset means no bound of our own: a connect waits on
|
|
3168
|
+
* the operating system, and a TLS handshake against a peer that accepts the TCP connection and
|
|
3169
|
+
* never answers waits indefinitely.
|
|
3170
|
+
*
|
|
3171
|
+
* @default undefined (no bound)
|
|
3172
|
+
*/
|
|
3173
|
+
readonly connectTimeoutMs?: number;
|
|
3068
3174
|
/**
|
|
3069
3175
|
* Enable TLS (MLLPS) for this connection. `true` enables TLS with
|
|
3070
3176
|
* all defaults, including certificate verification **on**. Pass a
|
|
@@ -3304,6 +3410,9 @@ declare class MllpClient extends EventEmitter {
|
|
|
3304
3410
|
* TLS failures carry a `connectionCause`: `'tls-verify'` for certificate
|
|
3305
3411
|
* verification failures, `'tls-handshake'` for TLS-protocol-shaped failures
|
|
3306
3412
|
* ({@link isTlsProtocolError}); pure TCP failures carry none.
|
|
3413
|
+
* - `MllpConnectionError({ phase: 'connect', connectionCause: 'connect-timeout' })` if
|
|
3414
|
+
* {@link ClientOptions.connectTimeoutMs} is set and the TCP connect, or the TLS handshake
|
|
3415
|
+
* after it, did not complete in time. The socket is destroyed; nothing was written.
|
|
3307
3416
|
* - `MllpTlsConfigurationError` if the configured cipher-suite list cannot be
|
|
3308
3417
|
* honoured (the runtime rejects it, or `atnaTransportSecurity` and `ciphers`
|
|
3309
3418
|
* both declare one). Raised **before** a socket is opened, so nothing is left
|
|
@@ -3348,6 +3457,18 @@ declare class MllpClient extends EventEmitter {
|
|
|
3348
3457
|
* against it.
|
|
3349
3458
|
*/
|
|
3350
3459
|
private _createSocketAndTransport;
|
|
3460
|
+
/**
|
|
3461
|
+
* Bound one connection attempt by {@link ClientOptions.connectTimeoutMs}, when it is set.
|
|
3462
|
+
*
|
|
3463
|
+
* Armed after the `Connection` has registered its own socket listeners (its set-once
|
|
3464
|
+
* `onClose`/`onError` would otherwise remove ours). The timer stops at the socket's connect
|
|
3465
|
+
* event (`'secureConnect'` for TLS, so the handshake is inside the bound) or at its `'close'`,
|
|
3466
|
+
* whichever comes first; a refused connect or an abort therefore leaves no timer behind. On
|
|
3467
|
+
* expiry the socket is destroyed with a {@link ConnectTimeoutCause}, which reaches the same
|
|
3468
|
+
* `'error'` listeners as any other connect failure: `connect()` rejects, and a reconnect
|
|
3469
|
+
* attempt hands it to the reconnect classifier.
|
|
3470
|
+
*/
|
|
3471
|
+
private _armConnectTimeout;
|
|
3351
3472
|
/**
|
|
3352
3473
|
* Wrap a connect-phase socket error as `MllpConnectionError`, classifying
|
|
3353
3474
|
* TLS failures into the additive `connectionCause`:
|
|
@@ -3885,6 +4006,11 @@ interface StarterClientOptions {
|
|
|
3885
4006
|
readonly keepaliveIntervalMs?: number;
|
|
3886
4007
|
/** Application-idle dead-peer timeout ms. */
|
|
3887
4008
|
readonly deadPeerTimeoutMs?: number;
|
|
4009
|
+
/**
|
|
4010
|
+
* Bound on the TCP connect and TLS handshake, in ms. Passthrough to
|
|
4011
|
+
* `ClientOptions.connectTimeoutMs`; unset means no bound, as there.
|
|
4012
|
+
*/
|
|
4013
|
+
readonly connectTimeoutMs?: number;
|
|
3888
4014
|
/** Enable TLS (MLLPS) for this connection. Passthrough to `ClientOptions.tls`. */
|
|
3889
4015
|
readonly tls?: TlsOptions | true;
|
|
3890
4016
|
/**
|
|
@@ -4295,7 +4421,9 @@ declare function isTlsProtocolError(err: unknown): boolean;
|
|
|
4295
4421
|
* Classification table:
|
|
4296
4422
|
* - `ENOTFOUND`, `EACCES` → **permanent** (`false`)
|
|
4297
4423
|
* - `ECONNREFUSED`, `ECONNRESET`, `ETIMEDOUT`, `EHOSTUNREACH`,
|
|
4298
|
-
* `ENETUNREACH`, `EPIPE` → **transient** (`true`)
|
|
4424
|
+
* `ENETUNREACH`, `EPIPE` → **transient** (`true`). An expired
|
|
4425
|
+
* `ClientOptions.connectTimeoutMs` is one of these: its error carries
|
|
4426
|
+
* `ETIMEDOUT`, the code of the operating system's own connect timeout.
|
|
4299
4427
|
* - `CERT_*` and `UNABLE_TO_VERIFY_LEAF_SIGNATURE` /
|
|
4300
4428
|
* `DEPTH_ZERO_SELF_SIGNED_CERT` / `SELF_SIGNED_CERT_IN_CHAIN`
|
|
4301
4429
|
* (any {@link isTlsVerificationErrorCode} code) → **permanent** (`false`),
|
|
@@ -4952,5 +5080,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
|
|
|
4952
5080
|
*/
|
|
4953
5081
|
declare const VERSION: string;
|
|
4954
5082
|
|
|
4955
|
-
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
4956
|
-
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
|
|
5083
|
+
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
5084
|
+
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionRejectedEvent, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1742,6 +1742,8 @@ function isWildcardHost(host) {
|
|
|
1742
1742
|
}
|
|
1743
1743
|
return false;
|
|
1744
1744
|
}
|
|
1745
|
+
var MLLP_CONNECTION_LIMIT_REACHED = "MLLP_CONNECTION_LIMIT_REACHED";
|
|
1746
|
+
var CONNECTION_LIMIT_MESSAGE = "connection closed at accept: the server already holds maxConnections connections";
|
|
1745
1747
|
var SERVER_DEFAULT_FRAMING = {
|
|
1746
1748
|
allowFsOnly: true,
|
|
1747
1749
|
allowLfAfterFs: true,
|
|
@@ -1788,6 +1790,12 @@ var MllpServer = class extends EventEmitter {
|
|
|
1788
1790
|
*/
|
|
1789
1791
|
constructor(opts) {
|
|
1790
1792
|
super();
|
|
1793
|
+
const maxConnections = opts.maxConnections;
|
|
1794
|
+
if (maxConnections !== void 0 && !(Number.isSafeInteger(maxConnections) && maxConnections >= 1)) {
|
|
1795
|
+
throw new RangeError(
|
|
1796
|
+
"ServerOptions.maxConnections must be a positive integer, or left unset for no cap"
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1791
1799
|
this._opts = opts;
|
|
1792
1800
|
this._isTls = opts.tls !== void 0;
|
|
1793
1801
|
let cipherPolicy = null;
|
|
@@ -1844,6 +1852,29 @@ var MllpServer = class extends EventEmitter {
|
|
|
1844
1852
|
this.emit("error", err);
|
|
1845
1853
|
}
|
|
1846
1854
|
});
|
|
1855
|
+
if (maxConnections !== void 0) {
|
|
1856
|
+
this._netServer.maxConnections = maxConnections;
|
|
1857
|
+
this._netServer.on("drop", (data) => {
|
|
1858
|
+
this._onConnectionOverCap(maxConnections, data);
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Report a connection the listener closed at accept because the cap was full.
|
|
1864
|
+
*
|
|
1865
|
+
* Contained: this runs inside the listener's own 'drop' callback, so a throwing subscriber would
|
|
1866
|
+
* otherwise unwind into the accept path. The throw is surfaced on 'error' instead.
|
|
1867
|
+
*/
|
|
1868
|
+
_onConnectionOverCap(maxConnections, data) {
|
|
1869
|
+
const event = Object.freeze({
|
|
1870
|
+
code: MLLP_CONNECTION_LIMIT_REACHED,
|
|
1871
|
+
message: CONNECTION_LIMIT_MESSAGE,
|
|
1872
|
+
maxConnections,
|
|
1873
|
+
remoteAddress: data?.remoteAddress ?? null,
|
|
1874
|
+
remotePort: data?.remotePort ?? null,
|
|
1875
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
1876
|
+
});
|
|
1877
|
+
this._emitContained("connectionRejected", event);
|
|
1847
1878
|
}
|
|
1848
1879
|
/**
|
|
1849
1880
|
* Start listening on the given port.
|
|
@@ -3206,6 +3237,14 @@ var OUTBOUND_WARNING_CONTEXT = Object.freeze({
|
|
|
3206
3237
|
byteOffset: 0,
|
|
3207
3238
|
elapsedSinceSendMs: 0
|
|
3208
3239
|
});
|
|
3240
|
+
var MAX_CONNECT_TIMEOUT_MS = 2147483647;
|
|
3241
|
+
var CONNECT_TIMEOUT_MESSAGE = "connect timed out: the connection, including its TLS handshake when TLS is on, was not established within connectTimeoutMs";
|
|
3242
|
+
var ConnectTimeoutCause = class extends Error {
|
|
3243
|
+
code = "ETIMEDOUT";
|
|
3244
|
+
constructor() {
|
|
3245
|
+
super(CONNECT_TIMEOUT_MESSAGE);
|
|
3246
|
+
}
|
|
3247
|
+
};
|
|
3209
3248
|
function identityOptions(host, servername) {
|
|
3210
3249
|
const target = servername ?? host;
|
|
3211
3250
|
if (isIP(target) === 0) return { servername: target };
|
|
@@ -3336,6 +3375,12 @@ var MllpClient = class extends EventEmitter {
|
|
|
3336
3375
|
*/
|
|
3337
3376
|
constructor(opts) {
|
|
3338
3377
|
super();
|
|
3378
|
+
const connectTimeoutMs = opts.connectTimeoutMs;
|
|
3379
|
+
if (connectTimeoutMs !== void 0 && !(Number.isInteger(connectTimeoutMs) && connectTimeoutMs >= 1 && connectTimeoutMs <= MAX_CONNECT_TIMEOUT_MS)) {
|
|
3380
|
+
throw new RangeError(
|
|
3381
|
+
"ClientOptions.connectTimeoutMs must be an integer from 1 to 2147483647, or left unset for no bound"
|
|
3382
|
+
);
|
|
3383
|
+
}
|
|
3339
3384
|
this._opts = opts;
|
|
3340
3385
|
this._ackTimeoutMs = opts.ackTimeoutMs ?? 3e4;
|
|
3341
3386
|
this._applicationAckTimeoutMs = opts.applicationAckTimeoutMs;
|
|
@@ -3379,6 +3424,9 @@ var MllpClient = class extends EventEmitter {
|
|
|
3379
3424
|
* TLS failures carry a `connectionCause`: `'tls-verify'` for certificate
|
|
3380
3425
|
* verification failures, `'tls-handshake'` for TLS-protocol-shaped failures
|
|
3381
3426
|
* ({@link isTlsProtocolError}); pure TCP failures carry none.
|
|
3427
|
+
* - `MllpConnectionError({ phase: 'connect', connectionCause: 'connect-timeout' })` if
|
|
3428
|
+
* {@link ClientOptions.connectTimeoutMs} is set and the TCP connect, or the TLS handshake
|
|
3429
|
+
* after it, did not complete in time. The socket is destroyed; nothing was written.
|
|
3382
3430
|
* - `MllpTlsConfigurationError` if the configured cipher-suite list cannot be
|
|
3383
3431
|
* honoured (the runtime rejects it, or `atnaTransportSecurity` and `ciphers`
|
|
3384
3432
|
* both declare one). Raised **before** a socket is opened, so nothing is left
|
|
@@ -3437,6 +3485,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
3437
3485
|
const conn = new Connection(connOpts);
|
|
3438
3486
|
this._attachConnection(conn);
|
|
3439
3487
|
const connectEventName = this._opts.tls !== void 0 ? "secureConnect" : "connect";
|
|
3488
|
+
this._armConnectTimeout(socket, connectEventName);
|
|
3440
3489
|
const cleanup = () => {
|
|
3441
3490
|
if (signal !== void 0) {
|
|
3442
3491
|
signal.removeEventListener("abort", abortHandler);
|
|
@@ -3511,6 +3560,29 @@ var MllpClient = class extends EventEmitter {
|
|
|
3511
3560
|
});
|
|
3512
3561
|
return { socket, transport: new TlsTransport(socket) };
|
|
3513
3562
|
}
|
|
3563
|
+
/**
|
|
3564
|
+
* Bound one connection attempt by {@link ClientOptions.connectTimeoutMs}, when it is set.
|
|
3565
|
+
*
|
|
3566
|
+
* Armed after the `Connection` has registered its own socket listeners (its set-once
|
|
3567
|
+
* `onClose`/`onError` would otherwise remove ours). The timer stops at the socket's connect
|
|
3568
|
+
* event (`'secureConnect'` for TLS, so the handshake is inside the bound) or at its `'close'`,
|
|
3569
|
+
* whichever comes first; a refused connect or an abort therefore leaves no timer behind. On
|
|
3570
|
+
* expiry the socket is destroyed with a {@link ConnectTimeoutCause}, which reaches the same
|
|
3571
|
+
* `'error'` listeners as any other connect failure: `connect()` rejects, and a reconnect
|
|
3572
|
+
* attempt hands it to the reconnect classifier.
|
|
3573
|
+
*/
|
|
3574
|
+
_armConnectTimeout(socket, connectEventName) {
|
|
3575
|
+
const timeoutMs = this._opts.connectTimeoutMs;
|
|
3576
|
+
if (timeoutMs === void 0) return;
|
|
3577
|
+
const timer = setTimeout(() => {
|
|
3578
|
+
socket.destroy(new ConnectTimeoutCause());
|
|
3579
|
+
}, timeoutMs);
|
|
3580
|
+
const stop = () => {
|
|
3581
|
+
clearTimeout(timer);
|
|
3582
|
+
};
|
|
3583
|
+
socket.once(connectEventName, stop);
|
|
3584
|
+
socket.once("close", stop);
|
|
3585
|
+
}
|
|
3514
3586
|
/**
|
|
3515
3587
|
* Wrap a connect-phase socket error as `MllpConnectionError`, classifying
|
|
3516
3588
|
* TLS failures into the additive `connectionCause`:
|
|
@@ -3525,6 +3597,13 @@ var MllpClient = class extends EventEmitter {
|
|
|
3525
3597
|
* same shape as plaintext connect failures.
|
|
3526
3598
|
*/
|
|
3527
3599
|
_wrapConnectError(err, phase) {
|
|
3600
|
+
if (err instanceof ConnectTimeoutCause) {
|
|
3601
|
+
return new MllpConnectionError(err.message, {
|
|
3602
|
+
cause: err,
|
|
3603
|
+
phase,
|
|
3604
|
+
connectionCause: "connect-timeout"
|
|
3605
|
+
});
|
|
3606
|
+
}
|
|
3528
3607
|
if (this._opts.tls === void 0) {
|
|
3529
3608
|
return new MllpConnectionError(err.message, { cause: err, phase });
|
|
3530
3609
|
}
|
|
@@ -4017,6 +4096,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
4017
4096
|
this._emitNegotiatedTlsParameters(socket);
|
|
4018
4097
|
};
|
|
4019
4098
|
const connectEventName = this._opts.tls !== void 0 ? "secureConnect" : "connect";
|
|
4099
|
+
this._armConnectTimeout(socket, connectEventName);
|
|
4020
4100
|
socket.once("error", (sErr) => {
|
|
4021
4101
|
if (this._lastError === null || this._lastError.message !== sErr.message) {
|
|
4022
4102
|
this._lastError = sErr;
|
|
@@ -4829,6 +4909,7 @@ async function createStarterClient(opts) {
|
|
|
4829
4909
|
...opts.retryStrategy !== void 0 ? { retryStrategy: opts.retryStrategy } : {},
|
|
4830
4910
|
...opts.keepaliveIntervalMs !== void 0 ? { keepaliveIntervalMs: opts.keepaliveIntervalMs } : {},
|
|
4831
4911
|
...opts.deadPeerTimeoutMs !== void 0 ? { deadPeerTimeoutMs: opts.deadPeerTimeoutMs } : {},
|
|
4912
|
+
...opts.connectTimeoutMs !== void 0 ? { connectTimeoutMs: opts.connectTimeoutMs } : {},
|
|
4832
4913
|
...opts.tls !== void 0 ? { tls: opts.tls } : {}
|
|
4833
4914
|
};
|
|
4834
4915
|
const client = createClient(clientOpts);
|
|
@@ -5149,8 +5230,8 @@ async function runDifferential(options = {}) {
|
|
|
5149
5230
|
}
|
|
5150
5231
|
|
|
5151
5232
|
// src/index.ts
|
|
5152
|
-
var VERSION = "0.1.
|
|
5233
|
+
var VERSION = "0.1.11";
|
|
5153
5234
|
|
|
5154
|
-
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, VERSION, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, createWarning, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
5235
|
+
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, VERSION, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, createWarning, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
5155
5236
|
//# sourceMappingURL=index.mjs.map
|
|
5156
5237
|
//# sourceMappingURL=index.mjs.map
|