node-opcua-transport 2.172.0 → 2.173.0
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/dist/source/client_tcp_transport.d.ts +4 -39
- package/dist/source/client_tcp_transport.js +7 -158
- package/dist/source/client_tcp_transport.js.map +1 -1
- package/dist/source/client_transport_base.d.ts +64 -0
- package/dist/source/client_transport_base.js +183 -0
- package/dist/source/client_transport_base.js.map +1 -0
- package/dist/source/i_client_transport.d.ts +10 -1
- package/dist/source/index.browser.d.ts +62 -0
- package/dist/source/index.browser.js +79 -0
- package/dist/source/index.browser.js.map +1 -0
- package/dist/source/index.d.ts +1 -0
- package/dist/source/index.js +1 -0
- package/dist/source/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -9
- package/source/client_tcp_transport.ts +16 -217
- package/source/client_transport_base.ts +238 -0
- package/source/i_client_transport.ts +11 -1
- package/source/index.browser.ts +62 -0
- package/source/index.ts +1 -0
|
@@ -2,28 +2,9 @@
|
|
|
2
2
|
* @module node-opcua-transport
|
|
3
3
|
*/
|
|
4
4
|
import type { ErrorCallback } from "node-opcua-status-code";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export
|
|
8
|
-
on(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
|
|
9
|
-
on(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
10
|
-
on(eventName: "connection_break", eventHandler: (err: Error | null) => void): this;
|
|
11
|
-
on(eventName: "connect", eventHandler: () => void): this;
|
|
12
|
-
once(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
|
|
13
|
-
once(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
14
|
-
once(eventName: "connection_break", eventHandler: (err: Error | null) => void): this;
|
|
15
|
-
once(eventName: "connect", eventHandler: () => void): this;
|
|
16
|
-
emit(eventName: "chunk", messageChunk: Buffer): boolean;
|
|
17
|
-
emit(eventName: "close", err?: Error | null): boolean;
|
|
18
|
-
emit(eventName: "connection_break", err?: Error | null): boolean;
|
|
19
|
-
emit(eventName: "connect"): boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface TransportSettingsOptions {
|
|
22
|
-
maxChunkCount?: number;
|
|
23
|
-
maxMessageSize?: number;
|
|
24
|
-
receiveBufferSize?: number;
|
|
25
|
-
sendBufferSize?: number;
|
|
26
|
-
}
|
|
5
|
+
import { ClientTransportBase } from "./client_transport_base";
|
|
6
|
+
import type { TransportSettingsOptions } from "./i_client_transport";
|
|
7
|
+
export type { TransportSettingsOptions };
|
|
27
8
|
/**
|
|
28
9
|
* a ClientTCP_transport connects to a remote server socket and
|
|
29
10
|
* initiates a communication with a HEL/ACK transaction.
|
|
@@ -59,23 +40,7 @@ export interface TransportSettingsOptions {
|
|
|
59
40
|
*
|
|
60
41
|
*
|
|
61
42
|
*/
|
|
62
|
-
export declare class ClientTCP_transport extends
|
|
63
|
-
static defaultMaxChunk: number;
|
|
64
|
-
static defaultMaxMessageSize: number;
|
|
65
|
-
static defaultReceiveBufferSize: number;
|
|
66
|
-
static defaultSendBufferSize: number;
|
|
67
|
-
endpointUrl: string;
|
|
68
|
-
serverUri: string;
|
|
69
|
-
numberOfRetry: number;
|
|
70
|
-
parameters?: AcknowledgeMessage;
|
|
71
|
-
private _counter;
|
|
72
|
-
private _helloSettings;
|
|
73
|
-
constructor(transportSettings?: TransportSettingsOptions);
|
|
74
|
-
getTransportSettings(): TransportSettingsOptions;
|
|
43
|
+
export declare class ClientTCP_transport extends ClientTransportBase {
|
|
75
44
|
dispose(): void;
|
|
76
45
|
connect(endpointUrl: string, callback: ErrorCallback): void;
|
|
77
|
-
private _handle_ACK_response;
|
|
78
|
-
private _send_HELLO_request;
|
|
79
|
-
private _on_ACK_response;
|
|
80
|
-
private _perform_HEL_ACK_transaction;
|
|
81
46
|
}
|
|
@@ -12,24 +12,18 @@ const node_os_1 = __importDefault(require("node:os"));
|
|
|
12
12
|
const node_util_1 = require("node:util");
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
14
|
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
15
|
-
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
16
|
-
const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
|
|
17
15
|
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
18
|
-
const
|
|
19
|
-
const HelloMessage_1 = require("./HelloMessage");
|
|
20
|
-
const TCPErrorMessage_1 = require("./TCPErrorMessage");
|
|
16
|
+
const client_transport_base_1 = require("./client_transport_base");
|
|
21
17
|
const tcp_transport_1 = require("./tcp_transport");
|
|
22
18
|
const tools_1 = require("./tools");
|
|
23
|
-
const utils_1 = require("./utils");
|
|
24
19
|
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
25
20
|
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
26
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
27
21
|
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
28
22
|
const gHostname = node_os_1.default.hostname();
|
|
29
23
|
function createClientSocket(endpointUrl, timeout) {
|
|
30
24
|
// create a socket based on Url
|
|
31
25
|
const ep = (0, tools_1.parseEndpointUrl)(endpointUrl);
|
|
32
|
-
const port = parseInt(ep.port, 10);
|
|
26
|
+
const port = parseInt(ep.port || "4840", 10);
|
|
33
27
|
const hostname = ep.hostname;
|
|
34
28
|
let socket;
|
|
35
29
|
switch (ep.protocol) {
|
|
@@ -86,39 +80,7 @@ function createClientSocket(endpointUrl, timeout) {
|
|
|
86
80
|
*
|
|
87
81
|
*
|
|
88
82
|
*/
|
|
89
|
-
|
|
90
|
-
class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
91
|
-
static defaultMaxChunk = 0; // 0 - no limits
|
|
92
|
-
static defaultMaxMessageSize = 0; // 0 - no limits
|
|
93
|
-
static defaultReceiveBufferSize = 1024 * 64 * 10;
|
|
94
|
-
static defaultSendBufferSize = 1024 * 64 * 10; // 8192 min,
|
|
95
|
-
endpointUrl;
|
|
96
|
-
serverUri;
|
|
97
|
-
numberOfRetry;
|
|
98
|
-
parameters;
|
|
99
|
-
_counter;
|
|
100
|
-
_helloSettings;
|
|
101
|
-
constructor(transportSettings) {
|
|
102
|
-
super();
|
|
103
|
-
this.endpointUrl = "";
|
|
104
|
-
this.serverUri = "";
|
|
105
|
-
this._counter = 0;
|
|
106
|
-
this.numberOfRetry = 0;
|
|
107
|
-
// initially before HEL/ACK
|
|
108
|
-
this.maxChunkCount = 1;
|
|
109
|
-
this.maxMessageSize = 4 * 1024;
|
|
110
|
-
this.receiveBufferSize = 4 * 1024;
|
|
111
|
-
transportSettings = transportSettings || {};
|
|
112
|
-
this._helloSettings = {
|
|
113
|
-
maxChunkCount: transportSettings.maxChunkCount || ClientTCP_transport.defaultMaxChunk,
|
|
114
|
-
maxMessageSize: transportSettings.maxMessageSize || ClientTCP_transport.defaultMaxMessageSize,
|
|
115
|
-
receiveBufferSize: transportSettings.receiveBufferSize || ClientTCP_transport.defaultReceiveBufferSize,
|
|
116
|
-
sendBufferSize: transportSettings.sendBufferSize || ClientTCP_transport.defaultSendBufferSize
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
getTransportSettings() {
|
|
120
|
-
return this._helloSettings;
|
|
121
|
-
}
|
|
83
|
+
class ClientTCP_transport extends client_transport_base_1.ClientTransportBase {
|
|
122
84
|
dispose() {
|
|
123
85
|
/* c8 ignore next */
|
|
124
86
|
doDebug && debugLog(" ClientTCP_transport disposed");
|
|
@@ -131,7 +93,8 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
131
93
|
doDebug && debugLog(chalk_1.default.cyan(`ClientTCP_transport#connect(endpointUrl = ${endpointUrl})`));
|
|
132
94
|
let socket = null;
|
|
133
95
|
try {
|
|
134
|
-
|
|
96
|
+
// validate the URL upfront so a parse error is reported synchronously
|
|
97
|
+
(0, tools_1.parseEndpointUrl)(endpointUrl);
|
|
135
98
|
socket = createClientSocket(endpointUrl, this.timeout);
|
|
136
99
|
socket.setTimeout(this.timeout >> 1, () => {
|
|
137
100
|
this.forceConnectionBreak();
|
|
@@ -143,30 +106,6 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
143
106
|
callback(err);
|
|
144
107
|
return;
|
|
145
108
|
}
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
*/
|
|
149
|
-
const _on_socket_error_after_connection = (err) => {
|
|
150
|
-
/* c8 ignore next */
|
|
151
|
-
doDebug && debugLog(" _on_socket_error_after_connection ClientTCP_transport Socket Error", err.message);
|
|
152
|
-
// EPIPE : EPIPE (Broken pipe): A write on a pipe, socket, or FIFO for which there is no process to read the
|
|
153
|
-
// data. Commonly encountered at the net and http layers, indicative that the remote side of the stream
|
|
154
|
-
// being written to has been closed.
|
|
155
|
-
// ECONNRESET (Connection reset by peer): A connection was forcibly closed by a peer. This normally results
|
|
156
|
-
// from a loss of the connection on the remote socket due to a timeout or reboot. Commonly encountered
|
|
157
|
-
// via the http and net module
|
|
158
|
-
// socket termination could happen:
|
|
159
|
-
// * when the socket times out (lost of connection, network outage, etc...)
|
|
160
|
-
// * or, when the server abruptly disconnects the socket ( in case of invalid communication for instance)
|
|
161
|
-
if (err.message.match(/ECONNRESET|EPIPE|premature socket termination/)) {
|
|
162
|
-
/**
|
|
163
|
-
* @event connection_break
|
|
164
|
-
*
|
|
165
|
-
*/
|
|
166
|
-
doDebug && debugLog("connection_break after reconnection", endpointUrl);
|
|
167
|
-
this.emit("connection_break", err);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
109
|
const _on_socket_connect = () => {
|
|
171
110
|
/* c8 ignore next */
|
|
172
111
|
doDebug && debugLog("entering _on_socket_connect");
|
|
@@ -177,13 +116,12 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
177
116
|
if (!this._socket) {
|
|
178
117
|
return callback(new Error("Abandoned"));
|
|
179
118
|
}
|
|
180
|
-
// install
|
|
181
|
-
this.
|
|
119
|
+
// install the post-connect "connection break" detector inherited from ClientTransportBase
|
|
120
|
+
this._install_post_connect_error_handler(endpointUrl);
|
|
182
121
|
/**
|
|
183
122
|
* notify the observers that the transport is connected (the socket is connected and the the HEL/ACK
|
|
184
123
|
* transaction has been done)
|
|
185
124
|
* @event connect
|
|
186
|
-
*
|
|
187
125
|
*/
|
|
188
126
|
this.emit("connect");
|
|
189
127
|
}
|
|
@@ -219,95 +157,6 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
219
157
|
this._socket?.once("end", _on_socket_end_for_connect);
|
|
220
158
|
this._socket?.once("connect", _on_socket_connect);
|
|
221
159
|
}
|
|
222
|
-
_handle_ACK_response(messageChunk, callback) {
|
|
223
|
-
const _stream = new node_opcua_binary_stream_1.BinaryStream(messageChunk);
|
|
224
|
-
const messageHeader = (0, node_opcua_chunkmanager_1.readMessageHeader)(_stream);
|
|
225
|
-
let err = null;
|
|
226
|
-
/* c8 ignore next */
|
|
227
|
-
if (messageHeader.isFinal !== "F") {
|
|
228
|
-
err = new Error(" invalid ACK message");
|
|
229
|
-
return callback(err);
|
|
230
|
-
}
|
|
231
|
-
let responseClass;
|
|
232
|
-
let response;
|
|
233
|
-
if (messageHeader.msgType === "ERR") {
|
|
234
|
-
responseClass = TCPErrorMessage_1.TCPErrorMessage;
|
|
235
|
-
_stream.rewind();
|
|
236
|
-
response = (0, tools_1.decodeMessage)(_stream, responseClass);
|
|
237
|
-
err = new Error(`ACK: ERR received ${response.statusCode.toString()} : ${response.reason}`);
|
|
238
|
-
err.statusCode = response.statusCode;
|
|
239
|
-
// c8 ignore next
|
|
240
|
-
utils_1.doTraceHelloAck && warningLog("receiving ERR instead of Ack", response.toString());
|
|
241
|
-
callback(err);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
responseClass = AcknowledgeMessage_1.AcknowledgeMessage;
|
|
245
|
-
_stream.rewind();
|
|
246
|
-
response = (0, tools_1.decodeMessage)(_stream, responseClass);
|
|
247
|
-
this.parameters = response;
|
|
248
|
-
this.setLimits(response);
|
|
249
|
-
// c8 ignore next
|
|
250
|
-
utils_1.doTraceHelloAck && warningLog("receiving Ack\n", response.toString());
|
|
251
|
-
callback();
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
_send_HELLO_request() {
|
|
255
|
-
/* c8 ignore next */
|
|
256
|
-
doDebug && debugLog("entering _send_HELLO_request");
|
|
257
|
-
(0, node_opcua_assert_1.assert)(this._socket);
|
|
258
|
-
(0, node_opcua_assert_1.assert)(Number.isFinite(this.protocolVersion));
|
|
259
|
-
(0, node_opcua_assert_1.assert)(this.endpointUrl.length > 0, " expecting a valid endpoint url");
|
|
260
|
-
const { maxChunkCount, maxMessageSize, receiveBufferSize, sendBufferSize } = this._helloSettings;
|
|
261
|
-
// Write a message to the socket as soon as the client is connected,
|
|
262
|
-
// the server will receive it as message from the client
|
|
263
|
-
const helloMessage = new HelloMessage_1.HelloMessage({
|
|
264
|
-
endpointUrl: this.endpointUrl,
|
|
265
|
-
protocolVersion: this.protocolVersion,
|
|
266
|
-
maxChunkCount,
|
|
267
|
-
maxMessageSize,
|
|
268
|
-
receiveBufferSize,
|
|
269
|
-
sendBufferSize
|
|
270
|
-
});
|
|
271
|
-
// c8 ignore next
|
|
272
|
-
utils_1.doTraceHelloAck && warningLog(`sending Hello\n ${helloMessage.toString()} `);
|
|
273
|
-
const messageChunk = (0, tools_1.packTcpMessage)("HEL", helloMessage);
|
|
274
|
-
this._write_chunk(messageChunk);
|
|
275
|
-
}
|
|
276
|
-
_on_ACK_response(externalCallback, err, data) {
|
|
277
|
-
/* c8 ignore next */
|
|
278
|
-
doDebug && debugLog("entering _on_ACK_response");
|
|
279
|
-
(0, node_opcua_assert_1.assert)(typeof externalCallback === "function");
|
|
280
|
-
(0, node_opcua_assert_1.assert)(this._counter === 0, "Ack response should only be received once !");
|
|
281
|
-
this._counter += 1;
|
|
282
|
-
if (err || !data) {
|
|
283
|
-
if (this._socket) {
|
|
284
|
-
const s = this._socket;
|
|
285
|
-
this._socket = null;
|
|
286
|
-
s.destroy();
|
|
287
|
-
}
|
|
288
|
-
externalCallback(err || new Error("no data"));
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
this._handle_ACK_response(data, externalCallback);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
_perform_HEL_ACK_transaction(callback) {
|
|
295
|
-
/* c8 ignore next */
|
|
296
|
-
if (!this._socket) {
|
|
297
|
-
return callback(new Error("No socket available to perform HEL/ACK transaction"));
|
|
298
|
-
}
|
|
299
|
-
(0, node_opcua_assert_1.assert)(this._socket, "expecting a valid socket to send a message");
|
|
300
|
-
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
301
|
-
this._counter = 0;
|
|
302
|
-
/* c8 ignore next */
|
|
303
|
-
doDebug && debugLog("entering _perform_HEL_ACK_transaction");
|
|
304
|
-
this._install_one_time_message_receiver((err, data) => {
|
|
305
|
-
/* c8 ignore next */
|
|
306
|
-
doDebug && debugLog("before _on_ACK_response ", err ? err.message : "");
|
|
307
|
-
this._on_ACK_response(callback, err, data);
|
|
308
|
-
});
|
|
309
|
-
this._send_HELLO_request();
|
|
310
|
-
}
|
|
311
160
|
}
|
|
312
161
|
exports.ClientTCP_transport = ClientTCP_transport;
|
|
313
162
|
//# sourceMappingURL=client_tcp_transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client_tcp_transport.js","sourceRoot":"","sources":["../../source/client_tcp_transport.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,uCAA4C;AAC5C,sDAAyB;AACzB,yCAAkC;AAClC,kDAA0B;AAE1B,yDAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"client_tcp_transport.js","sourceRoot":"","sources":["../../source/client_tcp_transport.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,u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,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAChB,OAAO;YACX,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAC;YACnE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,0BAA0B,CAAC,CAAC;QACnE,CAAC,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAE7B,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,EAAE,0BAA0B,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACtD,CAAC;CACJ;AAtFD,kDAsFC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-transport
|
|
3
|
+
*
|
|
4
|
+
* Transport-agnostic base class for client-side OPC UA transports.
|
|
5
|
+
*
|
|
6
|
+
* Owns the UACP HEL/ACK handshake, the negotiated transport settings, and the
|
|
7
|
+
* post-connect connection-break detector. Concrete subclasses (`ClientTCP_transport`,
|
|
8
|
+
* `ClientWS_transport`, ...) implement only the socket-creation step in `connect()`.
|
|
9
|
+
*
|
|
10
|
+
* Browser-safe: does not import `node:net`, `node:os`, `node:util`, or any other
|
|
11
|
+
* Node-only built-in beyond what `TCP_transport` already inherits from `node:events`.
|
|
12
|
+
*/
|
|
13
|
+
import type { ErrorCallback } from "node-opcua-status-code";
|
|
14
|
+
import { AcknowledgeMessage } from "./AcknowledgeMessage";
|
|
15
|
+
import type { TransportSettingsOptions } from "./i_client_transport";
|
|
16
|
+
import { TCP_transport } from "./tcp_transport";
|
|
17
|
+
export interface ClientTransportBase {
|
|
18
|
+
on(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
|
|
19
|
+
on(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
20
|
+
on(eventName: "connection_break", eventHandler: (err: Error | null) => void): this;
|
|
21
|
+
on(eventName: "connect", eventHandler: () => void): this;
|
|
22
|
+
once(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
|
|
23
|
+
once(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
24
|
+
once(eventName: "connection_break", eventHandler: (err: Error | null) => void): this;
|
|
25
|
+
once(eventName: "connect", eventHandler: () => void): this;
|
|
26
|
+
emit(eventName: "chunk", messageChunk: Buffer): boolean;
|
|
27
|
+
emit(eventName: "close", err?: Error | null): boolean;
|
|
28
|
+
emit(eventName: "connection_break", err?: Error | null): boolean;
|
|
29
|
+
emit(eventName: "connect"): boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare abstract class ClientTransportBase extends TCP_transport {
|
|
32
|
+
static defaultMaxChunk: number;
|
|
33
|
+
static defaultMaxMessageSize: number;
|
|
34
|
+
static defaultReceiveBufferSize: number;
|
|
35
|
+
static defaultSendBufferSize: number;
|
|
36
|
+
endpointUrl: string;
|
|
37
|
+
serverUri: string;
|
|
38
|
+
numberOfRetry: number;
|
|
39
|
+
parameters?: AcknowledgeMessage;
|
|
40
|
+
private _counter;
|
|
41
|
+
private _helloSettings;
|
|
42
|
+
constructor(transportSettings?: TransportSettingsOptions);
|
|
43
|
+
getTransportSettings(): TransportSettingsOptions;
|
|
44
|
+
dispose(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Connect to `endpointUrl` and perform the UACP HEL/ACK handshake.
|
|
47
|
+
* Concrete subclasses are responsible for opening the underlying socket
|
|
48
|
+
* (TCP, WebSocket, ...) and then driving the inherited HEL/ACK machinery.
|
|
49
|
+
*/
|
|
50
|
+
abstract connect(endpointUrl: string, callback: ErrorCallback): void;
|
|
51
|
+
/**
|
|
52
|
+
* Install the post-connect "connection break" detector. Subclasses call this
|
|
53
|
+
* once the underlying socket is open and the HEL/ACK transaction has succeeded.
|
|
54
|
+
*
|
|
55
|
+
* Detects ECONNRESET / EPIPE / premature socket termination on the live socket
|
|
56
|
+
* and re-emits them as `connection_break` so reconnection logic upstream can
|
|
57
|
+
* react.
|
|
58
|
+
*/
|
|
59
|
+
protected _install_post_connect_error_handler(endpointUrl: string): void;
|
|
60
|
+
protected _perform_HEL_ACK_transaction(callback: ErrorCallback): void;
|
|
61
|
+
private _send_HELLO_request;
|
|
62
|
+
private _on_ACK_response;
|
|
63
|
+
private _handle_ACK_response;
|
|
64
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-transport
|
|
4
|
+
*
|
|
5
|
+
* Transport-agnostic base class for client-side OPC UA transports.
|
|
6
|
+
*
|
|
7
|
+
* Owns the UACP HEL/ACK handshake, the negotiated transport settings, and the
|
|
8
|
+
* post-connect connection-break detector. Concrete subclasses (`ClientTCP_transport`,
|
|
9
|
+
* `ClientWS_transport`, ...) implement only the socket-creation step in `connect()`.
|
|
10
|
+
*
|
|
11
|
+
* Browser-safe: does not import `node:net`, `node:os`, `node:util`, or any other
|
|
12
|
+
* Node-only built-in beyond what `TCP_transport` already inherits from `node:events`.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ClientTransportBase = void 0;
|
|
16
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
17
|
+
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
18
|
+
const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
|
|
19
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
20
|
+
const AcknowledgeMessage_1 = require("./AcknowledgeMessage");
|
|
21
|
+
const HelloMessage_1 = require("./HelloMessage");
|
|
22
|
+
const TCPErrorMessage_1 = require("./TCPErrorMessage");
|
|
23
|
+
const tcp_transport_1 = require("./tcp_transport");
|
|
24
|
+
const tools_1 = require("./tools");
|
|
25
|
+
const utils_1 = require("./utils");
|
|
26
|
+
// Use a string category instead of `__filename` so the module loads in
|
|
27
|
+
// browsers without a Node-style filename global.
|
|
28
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("ClientTransportBase");
|
|
29
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("ClientTransportBase");
|
|
30
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)("ClientTransportBase");
|
|
31
|
+
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: companion to the interface above
|
|
32
|
+
class ClientTransportBase extends tcp_transport_1.TCP_transport {
|
|
33
|
+
static defaultMaxChunk = 0; // 0 - no limits
|
|
34
|
+
static defaultMaxMessageSize = 0; // 0 - no limits
|
|
35
|
+
static defaultReceiveBufferSize = 1024 * 64 * 10;
|
|
36
|
+
static defaultSendBufferSize = 1024 * 64 * 10; // 8192 min,
|
|
37
|
+
endpointUrl;
|
|
38
|
+
serverUri;
|
|
39
|
+
numberOfRetry;
|
|
40
|
+
parameters;
|
|
41
|
+
_counter;
|
|
42
|
+
_helloSettings;
|
|
43
|
+
constructor(transportSettings) {
|
|
44
|
+
super();
|
|
45
|
+
this.endpointUrl = "";
|
|
46
|
+
this.serverUri = "";
|
|
47
|
+
this._counter = 0;
|
|
48
|
+
this.numberOfRetry = 0;
|
|
49
|
+
// initially before HEL/ACK
|
|
50
|
+
this.maxChunkCount = 1;
|
|
51
|
+
this.maxMessageSize = 4 * 1024;
|
|
52
|
+
this.receiveBufferSize = 4 * 1024;
|
|
53
|
+
transportSettings = transportSettings || {};
|
|
54
|
+
this._helloSettings = {
|
|
55
|
+
maxChunkCount: transportSettings.maxChunkCount || ClientTransportBase.defaultMaxChunk,
|
|
56
|
+
maxMessageSize: transportSettings.maxMessageSize || ClientTransportBase.defaultMaxMessageSize,
|
|
57
|
+
receiveBufferSize: transportSettings.receiveBufferSize || ClientTransportBase.defaultReceiveBufferSize,
|
|
58
|
+
sendBufferSize: transportSettings.sendBufferSize || ClientTransportBase.defaultSendBufferSize
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
getTransportSettings() {
|
|
62
|
+
return this._helloSettings;
|
|
63
|
+
}
|
|
64
|
+
dispose() {
|
|
65
|
+
/* c8 ignore next */
|
|
66
|
+
doDebug && debugLog(" ClientTransportBase disposed");
|
|
67
|
+
super.dispose();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Install the post-connect "connection break" detector. Subclasses call this
|
|
71
|
+
* once the underlying socket is open and the HEL/ACK transaction has succeeded.
|
|
72
|
+
*
|
|
73
|
+
* Detects ECONNRESET / EPIPE / premature socket termination on the live socket
|
|
74
|
+
* and re-emits them as `connection_break` so reconnection logic upstream can
|
|
75
|
+
* react.
|
|
76
|
+
*/
|
|
77
|
+
_install_post_connect_error_handler(endpointUrl) {
|
|
78
|
+
if (!this._socket)
|
|
79
|
+
return;
|
|
80
|
+
this._socket.on("error", (err) => {
|
|
81
|
+
// EPIPE : a write on a pipe/socket/FIFO with no reader.
|
|
82
|
+
// ECONNRESET : connection forcibly closed by the peer (timeout, reboot, ...).
|
|
83
|
+
// "premature socket termination" : abrupt close mid-message.
|
|
84
|
+
if (err.message.match(/ECONNRESET|EPIPE|premature socket termination/)) {
|
|
85
|
+
/* c8 ignore next */
|
|
86
|
+
doDebug && debugLog("connection_break after reconnection", endpointUrl);
|
|
87
|
+
this.emit("connection_break", err);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
_perform_HEL_ACK_transaction(callback) {
|
|
92
|
+
/* c8 ignore next */
|
|
93
|
+
if (!this._socket) {
|
|
94
|
+
callback(new Error("No socket available to perform HEL/ACK transaction"));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
(0, node_opcua_assert_1.assert)(this._socket, "expecting a valid socket to send a message");
|
|
98
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
99
|
+
this._counter = 0;
|
|
100
|
+
/* c8 ignore next */
|
|
101
|
+
doDebug && debugLog("entering _perform_HEL_ACK_transaction");
|
|
102
|
+
this._install_one_time_message_receiver((err, data) => {
|
|
103
|
+
/* c8 ignore next */
|
|
104
|
+
doDebug && debugLog("before _on_ACK_response ", err ? err.message : "");
|
|
105
|
+
this._on_ACK_response(callback, err, data);
|
|
106
|
+
});
|
|
107
|
+
this._send_HELLO_request();
|
|
108
|
+
}
|
|
109
|
+
_send_HELLO_request() {
|
|
110
|
+
/* c8 ignore next */
|
|
111
|
+
doDebug && debugLog("entering _send_HELLO_request");
|
|
112
|
+
(0, node_opcua_assert_1.assert)(this._socket);
|
|
113
|
+
(0, node_opcua_assert_1.assert)(Number.isFinite(this.protocolVersion));
|
|
114
|
+
(0, node_opcua_assert_1.assert)(this.endpointUrl.length > 0, " expecting a valid endpoint url");
|
|
115
|
+
const { maxChunkCount, maxMessageSize, receiveBufferSize, sendBufferSize } = this._helloSettings;
|
|
116
|
+
const helloMessage = new HelloMessage_1.HelloMessage({
|
|
117
|
+
endpointUrl: this.endpointUrl,
|
|
118
|
+
protocolVersion: this.protocolVersion,
|
|
119
|
+
maxChunkCount,
|
|
120
|
+
maxMessageSize,
|
|
121
|
+
receiveBufferSize,
|
|
122
|
+
sendBufferSize
|
|
123
|
+
});
|
|
124
|
+
// c8 ignore next
|
|
125
|
+
utils_1.doTraceHelloAck && warningLog(`sending Hello\n ${helloMessage.toString()} `);
|
|
126
|
+
const messageChunk = (0, tools_1.packTcpMessage)("HEL", helloMessage);
|
|
127
|
+
this._write_chunk(messageChunk);
|
|
128
|
+
}
|
|
129
|
+
_on_ACK_response(externalCallback, err, data) {
|
|
130
|
+
/* c8 ignore next */
|
|
131
|
+
doDebug && debugLog("entering _on_ACK_response");
|
|
132
|
+
(0, node_opcua_assert_1.assert)(typeof externalCallback === "function");
|
|
133
|
+
(0, node_opcua_assert_1.assert)(this._counter === 0, "Ack response should only be received once !");
|
|
134
|
+
this._counter += 1;
|
|
135
|
+
if (err || !data) {
|
|
136
|
+
if (this._socket) {
|
|
137
|
+
const s = this._socket;
|
|
138
|
+
this._socket = null;
|
|
139
|
+
s.destroy();
|
|
140
|
+
}
|
|
141
|
+
externalCallback(err || new Error("no data"));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this._handle_ACK_response(data, externalCallback);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_handle_ACK_response(messageChunk, callback) {
|
|
148
|
+
const _stream = new node_opcua_binary_stream_1.BinaryStream(messageChunk);
|
|
149
|
+
const messageHeader = (0, node_opcua_chunkmanager_1.readMessageHeader)(_stream);
|
|
150
|
+
let err = null;
|
|
151
|
+
/* c8 ignore next */
|
|
152
|
+
if (messageHeader.isFinal !== "F") {
|
|
153
|
+
err = new Error(" invalid ACK message");
|
|
154
|
+
callback(err);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
let responseClass;
|
|
158
|
+
let response;
|
|
159
|
+
if (messageHeader.msgType === "ERR") {
|
|
160
|
+
responseClass = TCPErrorMessage_1.TCPErrorMessage;
|
|
161
|
+
_stream.rewind();
|
|
162
|
+
response = (0, tools_1.decodeMessage)(_stream, responseClass);
|
|
163
|
+
err = new Error(`ACK: ERR received ${response.statusCode.toString()} : ${response.reason}`);
|
|
164
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy diagnostic field tacked onto Error
|
|
165
|
+
err.statusCode = response.statusCode;
|
|
166
|
+
// c8 ignore next
|
|
167
|
+
utils_1.doTraceHelloAck && warningLog("receiving ERR instead of Ack", response.toString());
|
|
168
|
+
callback(err);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
responseClass = AcknowledgeMessage_1.AcknowledgeMessage;
|
|
172
|
+
_stream.rewind();
|
|
173
|
+
response = (0, tools_1.decodeMessage)(_stream, responseClass);
|
|
174
|
+
this.parameters = response;
|
|
175
|
+
this.setLimits(response);
|
|
176
|
+
// c8 ignore next
|
|
177
|
+
utils_1.doTraceHelloAck && warningLog("receiving Ack\n", response.toString());
|
|
178
|
+
callback();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.ClientTransportBase = ClientTransportBase;
|
|
183
|
+
//# sourceMappingURL=client_transport_base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_transport_base.js","sourceRoot":"","sources":["../../source/client_transport_base.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,yDAA2C;AAC3C,uEAAwD;AACxD,qEAA4D;AAC5D,uDAAkF;AAGlF,6DAA0D;AAC1D,iDAA8C;AAE9C,uDAAoD;AACpD,mDAAgD;AAChD,mCAAwD;AACxD,mCAA0C;AAE1C,uEAAuE;AACvE,iDAAiD;AACjD,MAAM,OAAO,GAAG,IAAA,iCAAc,EAAC,qBAAqB,CAAC,CAAC;AACtD,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,qBAAqB,CAAC,CAAC;AACtD,MAAM,UAAU,GAAG,IAAA,kCAAe,EAAC,qBAAqB,CAAC,CAAC;AAmB1D,4FAA4F;AAC5F,MAAsB,mBAAoB,SAAQ,6BAAa;IACpD,MAAM,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC,gBAAgB;IAC5C,MAAM,CAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,gBAAgB;IAClD,MAAM,CAAC,wBAAwB,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;IACjD,MAAM,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,YAAY;IAE3D,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,aAAa,CAAS;IACtB,UAAU,CAAsB;IAE/B,QAAQ,CAAS;IACjB,cAAc,CAKpB;IAEF,YAAY,iBAA4C;QACpD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC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AC;YAEtE,QAAQ,EAAE,CAAC;QACf,CAAC;IACL,CAAC;;AAzLL,kDA0LC"}
|
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
* @module node-opcua-transport
|
|
3
3
|
*/
|
|
4
4
|
import type { AcknowledgeMessage } from "./AcknowledgeMessage";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Options used to construct a client transport. Passed through {@link IClientTransportFactory.create}
|
|
7
|
+
* and applied to the UACP HEL message during the handshake.
|
|
8
|
+
*/
|
|
9
|
+
export interface TransportSettingsOptions {
|
|
10
|
+
maxChunkCount?: number;
|
|
11
|
+
maxMessageSize?: number;
|
|
12
|
+
receiveBufferSize?: number;
|
|
13
|
+
sendBufferSize?: number;
|
|
14
|
+
}
|
|
6
15
|
/**
|
|
7
16
|
* The minimal surface that {@link ClientSecureChannelLayer} (and anything else acting as
|
|
8
17
|
* a secure-channel client) uses from a transport. {@link ClientTCP_transport} already
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
* Copyright (c) 2022-2025 Sterfive SAS - 833264583 RCS ORLEANS - France (https://www.sterfive.com)
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
* the Software without restriction, including without limitation the rights to
|
|
8
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @module node-opcua-transport/browser
|
|
17
|
+
*
|
|
18
|
+
* Browser-safe subset of `node-opcua-transport`. Selected automatically by
|
|
19
|
+
* bundlers (esbuild, webpack, vite, rollup) via the `"browser"` condition in
|
|
20
|
+
* this package's `exports` map.
|
|
21
|
+
*
|
|
22
|
+
* Excludes Node-only modules whose top-level `import "node:net" | "node:os"`
|
|
23
|
+
* statements would otherwise crash a `platform: "browser"` bundle even though
|
|
24
|
+
* the runtime never reaches them:
|
|
25
|
+
* - `client_tcp_transport` — opens a `net.Socket`
|
|
26
|
+
* - `default_client_transport_factory` — instantiates `ClientTCP_transport`
|
|
27
|
+
* - `server_tcp_transport` — Node-side server endpoint
|
|
28
|
+
*
|
|
29
|
+
* Browser-side OPC UA transports (e.g. `ClientWS_transport` from
|
|
30
|
+
* `node-opcua-client-browser`) extend `ClientTransportBase` from this entry,
|
|
31
|
+
* implement their own `connect()`, and inherit the inherited HEL/ACK,
|
|
32
|
+
* packet-assembly, and lifecycle machinery.
|
|
33
|
+
*
|
|
34
|
+
* ## Bundler configuration required
|
|
35
|
+
*
|
|
36
|
+
* Several files still re-exported here import `node:events` (e.g.
|
|
37
|
+
* `tcp_transport.ts`, `message_builder_base.ts`). Browser bundlers do not
|
|
38
|
+
* auto-polyfill `node:`-prefixed built-ins; consumers must alias them to
|
|
39
|
+
* polyfill packages. Example (esbuild):
|
|
40
|
+
*
|
|
41
|
+
* alias: {
|
|
42
|
+
* "node:events": "events",
|
|
43
|
+
* "node:util": "util",
|
|
44
|
+
* "node:buffer": "buffer"
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* Transitively, `node-opcua-debug` and `node-opcua-utils` also need these
|
|
48
|
+
* aliases. We deliberately do not declare the polyfills as dependencies of
|
|
49
|
+
* the transport package — Node consumers would pay the install cost for no
|
|
50
|
+
* benefit, and Node would prefer the npm port over its own built-in.
|
|
51
|
+
*/
|
|
52
|
+
export * from "./AcknowledgeMessage";
|
|
53
|
+
export * from "./client_transport_base";
|
|
54
|
+
export * from "./HelloMessage";
|
|
55
|
+
export * from "./i_client_transport";
|
|
56
|
+
export * from "./i_hello_ack_limits";
|
|
57
|
+
export * from "./message_builder_base";
|
|
58
|
+
export * from "./status_codes";
|
|
59
|
+
export * from "./TCPErrorMessage";
|
|
60
|
+
export * from "./tcp_transport";
|
|
61
|
+
export * from "./tools";
|
|
62
|
+
export * from "./utils";
|