node-opcua-transport 2.99.0 → 2.102.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 -9
- package/dist/source/client_tcp_transport.js +38 -71
- package/dist/source/client_tcp_transport.js.map +1 -1
- package/dist/source/server_tcp_transport.d.ts +3 -15
- package/dist/source/server_tcp_transport.js +40 -41
- package/dist/source/server_tcp_transport.js.map +1 -1
- package/dist/source/tcp_transport.d.ts +45 -28
- package/dist/source/tcp_transport.js +160 -110
- package/dist/source/tcp_transport.js.map +1 -1
- package/dist/test_helpers/ITransportPair.d.ts +7 -0
- package/dist/test_helpers/ITransportPair.js +3 -0
- package/dist/test_helpers/ITransportPair.js.map +1 -0
- package/dist/test_helpers/fake_server.d.ts +2 -0
- package/dist/test_helpers/fake_server.js +3 -0
- package/dist/test_helpers/fake_server.js.map +1 -1
- package/dist/test_helpers/half_com_channel.d.ts +17 -10
- package/dist/test_helpers/half_com_channel.js +63 -4
- package/dist/test_helpers/half_com_channel.js.map +1 -1
- package/dist/test_helpers/index.d.ts +2 -2
- package/dist/test_helpers/index.js +2 -2
- package/dist/test_helpers/index.js.map +1 -1
- package/dist/test_helpers/{direct_transport.d.ts → transport_pair_direct.d.ts} +2 -6
- package/dist/test_helpers/{direct_transport.js → transport_pair_direct.js} +11 -18
- package/dist/test_helpers/transport_pair_direct.js.map +1 -0
- package/dist/test_helpers/transport_pair_socket.d.ts +14 -0
- package/dist/test_helpers/transport_pair_socket.js +33 -0
- package/dist/test_helpers/transport_pair_socket.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/source/client_tcp_transport.ts +56 -89
- package/source/server_tcp_transport.ts +48 -50
- package/source/tcp_transport.ts +226 -157
- package/dist/test_helpers/direct_transport.js.map +0 -1
- package/dist/test_helpers/socket_transport.d.ts +0 -10
- package/dist/test_helpers/socket_transport.js +0 -31
- package/dist/test_helpers/socket_transport.js.map +0 -1
|
@@ -4,17 +4,14 @@ import { TCP_transport } from "./tcp_transport";
|
|
|
4
4
|
import { AcknowledgeMessage } from "./AcknowledgeMessage";
|
|
5
5
|
export interface ClientTCP_transport {
|
|
6
6
|
on(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
|
|
7
|
-
on(eventName: "socket_closed", eventHandler: (err: Error | null) => void): this;
|
|
8
7
|
on(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
9
8
|
on(eventName: "connection_break", eventHandler: () => void): this;
|
|
10
9
|
on(eventName: "connect", eventHandler: () => void): this;
|
|
11
10
|
once(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
|
|
12
|
-
once(eventName: "socket_closed", eventHandler: (err: Error | null) => void): this;
|
|
13
11
|
once(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
14
12
|
once(eventName: "connection_break", eventHandler: () => void): this;
|
|
15
13
|
once(eventName: "connect", eventHandler: () => void): this;
|
|
16
14
|
emit(eventName: "chunk", messageChunk: Buffer): boolean;
|
|
17
|
-
emit(eventName: "socket_closed", err?: Error | null): boolean;
|
|
18
15
|
emit(eventName: "close", err?: Error | null): boolean;
|
|
19
16
|
emit(eventName: "connection_break"): boolean;
|
|
20
17
|
emit(eventName: "connect"): boolean;
|
|
@@ -40,7 +37,7 @@ export interface TransportSettingsOptions {
|
|
|
40
37
|
*
|
|
41
38
|
* transport.timeout = 10000;
|
|
42
39
|
*
|
|
43
|
-
* transport.connect(function(err)) {
|
|
40
|
+
* transport.connect(function (err)) {
|
|
44
41
|
* if (err) {
|
|
45
42
|
* // cannot connect
|
|
46
43
|
* } else {
|
|
@@ -50,16 +47,16 @@ export interface TransportSettingsOptions {
|
|
|
50
47
|
* });
|
|
51
48
|
* ....
|
|
52
49
|
*
|
|
53
|
-
* transport.write(message_chunk,'F');
|
|
50
|
+
* transport.write(message_chunk, 'F');
|
|
54
51
|
*
|
|
55
52
|
* ....
|
|
56
53
|
*
|
|
57
|
-
* transport.on("chunk",function(message_chunk) {
|
|
54
|
+
* transport.on("chunk", function (message_chunk) {
|
|
58
55
|
* // do something with chunk from server...
|
|
59
56
|
* });
|
|
60
57
|
*
|
|
61
58
|
*
|
|
62
|
-
*
|
|
59
|
+
* ```
|
|
63
60
|
*
|
|
64
61
|
*
|
|
65
62
|
*/
|
|
@@ -72,14 +69,12 @@ export declare class ClientTCP_transport extends TCP_transport {
|
|
|
72
69
|
serverUri: string;
|
|
73
70
|
numberOfRetry: number;
|
|
74
71
|
parameters?: AcknowledgeMessage;
|
|
75
|
-
private connected;
|
|
76
72
|
private _counter;
|
|
77
73
|
private _helloSettings;
|
|
78
74
|
constructor(transportSettings?: TransportSettingsOptions);
|
|
79
75
|
getTransportSettings(): TransportSettingsOptions;
|
|
80
76
|
dispose(): void;
|
|
81
77
|
connect(endpointUrl: string, callback: ErrorCallback): void;
|
|
82
|
-
protected on_socket_ended(err: Error | null): void;
|
|
83
78
|
private _handle_ACK_response;
|
|
84
79
|
private _send_HELLO_request;
|
|
85
80
|
private _on_ACK_response;
|
|
@@ -6,6 +6,7 @@ exports.ClientTCP_transport = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
const os = require("os");
|
|
8
8
|
const net_1 = require("net");
|
|
9
|
+
const util_1 = require("util");
|
|
9
10
|
const chalk = require("chalk");
|
|
10
11
|
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
11
12
|
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
@@ -22,7 +23,7 @@ const debugLog = debug.make_debugLog(__filename);
|
|
|
22
23
|
const warningLog = debug.make_warningLog(__filename);
|
|
23
24
|
const errorLog = debug.make_errorLog(__filename);
|
|
24
25
|
const gHostname = os.hostname();
|
|
25
|
-
function createClientSocket(endpointUrl) {
|
|
26
|
+
function createClientSocket(endpointUrl, timeout) {
|
|
26
27
|
// create a socket based on Url
|
|
27
28
|
const ep = (0, tools_1.parseEndpointUrl)(endpointUrl);
|
|
28
29
|
const port = parseInt(ep.port, 10);
|
|
@@ -30,19 +31,17 @@ function createClientSocket(endpointUrl) {
|
|
|
30
31
|
let socket;
|
|
31
32
|
switch (ep.protocol) {
|
|
32
33
|
case "opc.tcp:":
|
|
33
|
-
socket = (0, net_1.createConnection)({ host: hostname, port })
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
socket.setNoDelay(true);
|
|
34
|
+
socket = (0, net_1.createConnection)({ host: hostname, port, timeout }, () => {
|
|
35
|
+
doDebug && debugLog(`connected to server! ${hostname}:${port} timeout:${timeout} `);
|
|
36
|
+
});
|
|
37
37
|
return socket;
|
|
38
38
|
case "fake:":
|
|
39
|
-
socket = (0, tcp_transport_1.getFakeTransport)();
|
|
40
39
|
(0, node_opcua_assert_1.assert)(ep.protocol === "fake:", " Unsupported transport protocol");
|
|
41
|
-
|
|
40
|
+
socket = (0, tcp_transport_1.getFakeTransport)();
|
|
42
41
|
return socket;
|
|
43
42
|
case "websocket:":
|
|
44
43
|
case "http:":
|
|
45
|
-
case "https:
|
|
44
|
+
case "https:":
|
|
46
45
|
default: {
|
|
47
46
|
const msg = "[NODE-OPCUA-E05] this transport protocol is not supported :" + ep.protocol;
|
|
48
47
|
errorLog(msg);
|
|
@@ -65,7 +64,7 @@ function createClientSocket(endpointUrl) {
|
|
|
65
64
|
*
|
|
66
65
|
* transport.timeout = 10000;
|
|
67
66
|
*
|
|
68
|
-
* transport.connect(function(err)) {
|
|
67
|
+
* transport.connect(function (err)) {
|
|
69
68
|
* if (err) {
|
|
70
69
|
* // cannot connect
|
|
71
70
|
* } else {
|
|
@@ -75,23 +74,22 @@ function createClientSocket(endpointUrl) {
|
|
|
75
74
|
* });
|
|
76
75
|
* ....
|
|
77
76
|
*
|
|
78
|
-
* transport.write(message_chunk,'F');
|
|
77
|
+
* transport.write(message_chunk, 'F');
|
|
79
78
|
*
|
|
80
79
|
* ....
|
|
81
80
|
*
|
|
82
|
-
* transport.on("chunk",function(message_chunk) {
|
|
81
|
+
* transport.on("chunk", function (message_chunk) {
|
|
83
82
|
* // do something with chunk from server...
|
|
84
83
|
* });
|
|
85
84
|
*
|
|
86
85
|
*
|
|
87
|
-
*
|
|
86
|
+
* ```
|
|
88
87
|
*
|
|
89
88
|
*
|
|
90
89
|
*/
|
|
91
90
|
class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
92
91
|
constructor(transportSettings) {
|
|
93
92
|
super();
|
|
94
|
-
this.connected = false;
|
|
95
93
|
this.endpointUrl = "";
|
|
96
94
|
this.serverUri = "";
|
|
97
95
|
this._counter = 0;
|
|
@@ -113,9 +111,7 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
113
111
|
}
|
|
114
112
|
dispose() {
|
|
115
113
|
/* istanbul ignore next */
|
|
116
|
-
|
|
117
|
-
debugLog(" ClientTCP_transport disposed");
|
|
118
|
-
}
|
|
114
|
+
doDebug && debugLog(" ClientTCP_transport disposed");
|
|
119
115
|
super.dispose();
|
|
120
116
|
}
|
|
121
117
|
connect(endpointUrl, callback) {
|
|
@@ -125,31 +121,32 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
125
121
|
this.endpointUrl = endpointUrl;
|
|
126
122
|
this.serverUri = "urn:" + gHostname + ":Sample";
|
|
127
123
|
/* istanbul ignore next */
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
124
|
+
doDebug && debugLog(chalk.cyan("ClientTCP_transport#connect(endpointUrl = " + endpointUrl + ")"));
|
|
125
|
+
let socket = null;
|
|
131
126
|
try {
|
|
132
|
-
|
|
127
|
+
socket = createClientSocket(endpointUrl, this.timeout);
|
|
133
128
|
}
|
|
134
129
|
catch (err) {
|
|
135
130
|
/* istanbul ignore next */
|
|
136
|
-
|
|
137
|
-
debugLog("CreateClientSocket has failed");
|
|
138
|
-
}
|
|
131
|
+
doDebug && debugLog("CreateClientSocket has failed");
|
|
139
132
|
return callback(err);
|
|
140
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
141
137
|
const _on_socket_error_after_connection = (err) => {
|
|
142
138
|
/* istanbul ignore next */
|
|
143
|
-
|
|
144
|
-
debugLog(" _on_socket_error_after_connection ClientTCP_transport Socket Error", err.message);
|
|
145
|
-
}
|
|
139
|
+
doDebug && debugLog(" _on_socket_error_after_connection ClientTCP_transport Socket Error", err.message);
|
|
146
140
|
// EPIPE : EPIPE (Broken pipe): A write on a pipe, socket, or FIFO for which there is no process to read the
|
|
147
141
|
// data. Commonly encountered at the net and http layers, indicative that the remote side of the stream
|
|
148
142
|
// being written to has been closed.
|
|
149
143
|
// ECONNRESET (Connection reset by peer): A connection was forcibly closed by a peer. This normally results
|
|
150
144
|
// from a loss of the connection on the remote socket due to a timeout or reboot. Commonly encountered
|
|
151
145
|
// via the http and net module
|
|
152
|
-
|
|
146
|
+
// socket termination could happen:
|
|
147
|
+
// * when the socket times out (lost of connection, network outage, etc...)
|
|
148
|
+
// * or, when the server abruptly disconnects the socket ( in case of invalid communication for instance)
|
|
149
|
+
if (err.message.match(/ECONNRESET|EPIPE|premature socket termination/)) {
|
|
153
150
|
/**
|
|
154
151
|
* @event connection_break
|
|
155
152
|
*
|
|
@@ -159,9 +156,7 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
159
156
|
};
|
|
160
157
|
const _on_socket_connect = () => {
|
|
161
158
|
/* istanbul ignore next */
|
|
162
|
-
|
|
163
|
-
debugLog("entering _on_socket_connect");
|
|
164
|
-
}
|
|
159
|
+
doDebug && debugLog("entering _on_socket_connect");
|
|
165
160
|
_remove_connect_listeners();
|
|
166
161
|
this._perform_HEL_ACK_transaction((err) => {
|
|
167
162
|
if (!err) {
|
|
@@ -171,7 +166,6 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
171
166
|
}
|
|
172
167
|
// install error handler to detect connection break
|
|
173
168
|
this._socket.on("error", _on_socket_error_after_connection);
|
|
174
|
-
this.connected = true;
|
|
175
169
|
/**
|
|
176
170
|
* notify the observers that the transport is connected (the socket is connected and the the HEL/ACK
|
|
177
171
|
* transaction has been done)
|
|
@@ -189,18 +183,15 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
189
183
|
const _on_socket_error_for_connect = (err) => {
|
|
190
184
|
// this handler will catch attempt to connect to an inaccessible address.
|
|
191
185
|
/* istanbul ignore next */
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
(0, node_opcua_assert_1.assert)(err instanceof Error);
|
|
186
|
+
doDebug && debugLog(chalk.cyan("ClientTCP_transport#connect - _on_socket_error_for_connect"), err.message);
|
|
187
|
+
(0, node_opcua_assert_1.assert)(util_1.types.isNativeError(err));
|
|
196
188
|
_remove_connect_listeners();
|
|
197
189
|
callback(err);
|
|
198
190
|
};
|
|
199
|
-
const _on_socket_end_for_connect = (
|
|
191
|
+
const _on_socket_end_for_connect = () => {
|
|
200
192
|
/* istanbul ignore next */
|
|
201
|
-
|
|
202
|
-
debugLog(chalk.cyan("ClientTCP_transport#connect -> _on_socket_end_for_connect Socket has been closed by server")
|
|
203
|
-
}
|
|
193
|
+
doDebug &&
|
|
194
|
+
debugLog(chalk.cyan("ClientTCP_transport#connect -> _on_socket_end_for_connect Socket has been closed by server"));
|
|
204
195
|
};
|
|
205
196
|
const _remove_connect_listeners = () => {
|
|
206
197
|
/* istanbul ignore next */
|
|
@@ -210,19 +201,10 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
210
201
|
this._socket.removeListener("error", _on_socket_error_for_connect);
|
|
211
202
|
this._socket.removeListener("end", _on_socket_end_for_connect);
|
|
212
203
|
};
|
|
204
|
+
this._install_socket(socket);
|
|
213
205
|
this._socket.once("error", _on_socket_error_for_connect);
|
|
214
206
|
this._socket.once("end", _on_socket_end_for_connect);
|
|
215
207
|
this._socket.once("connect", _on_socket_connect);
|
|
216
|
-
this._install_socket(this._socket);
|
|
217
|
-
}
|
|
218
|
-
on_socket_ended(err) {
|
|
219
|
-
debugLog("on_socket_ended", this.name, err ? err.message : "");
|
|
220
|
-
if (this.connected) {
|
|
221
|
-
super.on_socket_ended(err);
|
|
222
|
-
}
|
|
223
|
-
// if (this._socket) {
|
|
224
|
-
// this._socket.removeAllListeners();
|
|
225
|
-
// }
|
|
226
208
|
}
|
|
227
209
|
_handle_ACK_response(messageChunk, callback) {
|
|
228
210
|
const _stream = new node_opcua_binary_stream_1.BinaryStream(messageChunk);
|
|
@@ -242,9 +224,7 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
242
224
|
err = new Error("ACK: ERR received " + response.statusCode.toString() + " : " + response.reason);
|
|
243
225
|
err.statusCode = response.statusCode;
|
|
244
226
|
// istanbul ignore next
|
|
245
|
-
|
|
246
|
-
warningLog("receiving ERR instead of Ack", response.toString());
|
|
247
|
-
}
|
|
227
|
+
utils_1.doTraceHelloAck && warningLog("receiving ERR instead of Ack", response.toString());
|
|
248
228
|
callback(err);
|
|
249
229
|
}
|
|
250
230
|
else {
|
|
@@ -254,17 +234,13 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
254
234
|
this.parameters = response;
|
|
255
235
|
this.setLimits(response);
|
|
256
236
|
// istanbul ignore next
|
|
257
|
-
|
|
258
|
-
warningLog("receiving Ack\n", response.toString());
|
|
259
|
-
}
|
|
237
|
+
utils_1.doTraceHelloAck && warningLog("receiving Ack\n", response.toString());
|
|
260
238
|
callback();
|
|
261
239
|
}
|
|
262
240
|
}
|
|
263
241
|
_send_HELLO_request() {
|
|
264
242
|
/* istanbul ignore next */
|
|
265
|
-
|
|
266
|
-
debugLog("entering _send_HELLO_request");
|
|
267
|
-
}
|
|
243
|
+
doDebug && debugLog("entering _send_HELLO_request");
|
|
268
244
|
(0, node_opcua_assert_1.assert)(this._socket);
|
|
269
245
|
(0, node_opcua_assert_1.assert)(isFinite(this.protocolVersion));
|
|
270
246
|
(0, node_opcua_assert_1.assert)(this.endpointUrl.length > 0, " expecting a valid endpoint url");
|
|
@@ -280,17 +256,13 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
280
256
|
sendBufferSize
|
|
281
257
|
});
|
|
282
258
|
// istanbul ignore next
|
|
283
|
-
|
|
284
|
-
warningLog(`sending Hello\n ${helloMessage.toString()}`);
|
|
285
|
-
}
|
|
259
|
+
utils_1.doTraceHelloAck && warningLog(`sending Hello\n ${helloMessage.toString()} `);
|
|
286
260
|
const messageChunk = (0, tools_1.packTcpMessage)("HEL", helloMessage);
|
|
287
261
|
this._write_chunk(messageChunk);
|
|
288
262
|
}
|
|
289
263
|
_on_ACK_response(externalCallback, err, data) {
|
|
290
264
|
/* istanbul ignore next */
|
|
291
|
-
|
|
292
|
-
debugLog("entering _on_ACK_response");
|
|
293
|
-
}
|
|
265
|
+
doDebug && debugLog("entering _on_ACK_response");
|
|
294
266
|
(0, node_opcua_assert_1.assert)(typeof externalCallback === "function");
|
|
295
267
|
(0, node_opcua_assert_1.assert)(this._counter === 0, "Ack response should only be received once !");
|
|
296
268
|
this._counter += 1;
|
|
@@ -298,7 +270,6 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
298
270
|
externalCallback(err || new Error("no data"));
|
|
299
271
|
if (this._socket) {
|
|
300
272
|
this._socket.end();
|
|
301
|
-
// Xx this._socket.removeAllListeners();
|
|
302
273
|
}
|
|
303
274
|
}
|
|
304
275
|
else {
|
|
@@ -314,14 +285,10 @@ class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
314
285
|
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
315
286
|
this._counter = 0;
|
|
316
287
|
/* istanbul ignore next */
|
|
317
|
-
|
|
318
|
-
debugLog("entering _perform_HEL_ACK_transaction");
|
|
319
|
-
}
|
|
288
|
+
doDebug && debugLog("entering _perform_HEL_ACK_transaction");
|
|
320
289
|
this._install_one_time_message_receiver((err, data) => {
|
|
321
290
|
/* istanbul ignore next */
|
|
322
|
-
|
|
323
|
-
debugLog("before _on_ACK_response ", err ? err.message : "");
|
|
324
|
-
}
|
|
291
|
+
doDebug && debugLog("before _on_ACK_response ", err ? err.message : "");
|
|
325
292
|
this._on_ACK_response(callback, err, data);
|
|
326
293
|
});
|
|
327
294
|
this._send_HELLO_request();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client_tcp_transport.js","sourceRoot":"","sources":["../../source/client_tcp_transport.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yBAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"client_tcp_transport.js","sourceRoot":"","sources":["../../source/client_tcp_transport.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yBAAyB;AACzB,6BAAuC;AACvC,+BAA6B;AAC7B,+BAA+B;AAE/B,yDAA2C;AAC3C,uEAAwD;AACxD,qEAA4D;AAG5D,0CAA0C;AAC1C,mDAA+E;AAC/E,mCAA0E;AAE1E,6DAA0D;AAC1D,iDAA8C;AAC9C,uDAAoD;AACpD,mCAA0C;AAE1C,MAAM,OAAO,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACjD,MAAM,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;AACrD,MAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACjD,MAAM,SAAS,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;AAEhC,SAAS,kBAAkB,CAAC,WAAmB,EAAE,OAAe;IAC5D,+BAA+B;IAC/B,MAAM,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAC,IAAK,EAAE,EAAE,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAS,CAAC;IAE9B,IAAI,MAAmB,CAAC;IACxB,QAAQ,EA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
|
|
7
|
-
import { StatusCode } from "node-opcua-status-code";
|
|
8
2
|
import { ErrorCallback } from "node-opcua-status-code";
|
|
9
|
-
import { TCP_transport } from "./tcp_transport";
|
|
10
|
-
/**
|
|
11
|
-
* @class ServerTCP_transport
|
|
12
|
-
* @extends TCP_transport
|
|
13
|
-
* @constructor
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
3
|
+
import { ISocketLike, TCP_transport } from "./tcp_transport";
|
|
16
4
|
export declare class ServerTCP_transport extends TCP_transport {
|
|
17
5
|
static throttleTime: number;
|
|
18
6
|
private _aborted;
|
|
19
7
|
private _helloReceived;
|
|
20
8
|
constructor();
|
|
9
|
+
toString(): string;
|
|
21
10
|
protected _write_chunk(messageChunk: Buffer): void;
|
|
22
11
|
/**
|
|
23
12
|
* Initialize the server transport.
|
|
@@ -35,8 +24,7 @@ export declare class ServerTCP_transport extends TCP_transport {
|
|
|
35
24
|
*
|
|
36
25
|
*
|
|
37
26
|
*/
|
|
38
|
-
init(socket:
|
|
39
|
-
abortWithError(statusCode: StatusCode, extraErrorDescription: string, callback: ErrorCallback): void;
|
|
27
|
+
init(socket: ISocketLike, callback: ErrorCallback): void;
|
|
40
28
|
private _abortWithError;
|
|
41
29
|
private _send_ACK_response;
|
|
42
30
|
private _install_HEL_message_receiver;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServerTCP_transport = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
4
5
|
const chalk = require("chalk");
|
|
5
6
|
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
6
7
|
// opcua requires
|
|
@@ -15,9 +16,10 @@ const tcp_transport_1 = require("./tcp_transport");
|
|
|
15
16
|
const tools_1 = require("./tools");
|
|
16
17
|
const utils_1 = require("./utils");
|
|
17
18
|
const hexDump = debug.hexDump;
|
|
18
|
-
const debugLog = debug.make_debugLog(
|
|
19
|
-
const errorLog = debug.make_errorLog(
|
|
20
|
-
const
|
|
19
|
+
const debugLog = debug.make_debugLog("TRANSPORT");
|
|
20
|
+
const errorLog = debug.make_errorLog("TRANSPORT");
|
|
21
|
+
const warningLog = debug.make_warningLog("TRANSPORT");
|
|
22
|
+
const doDebug = debug.checkDebugFlag("TRANSPORT");
|
|
21
23
|
function clamp_value(value, minVal, maxVal) {
|
|
22
24
|
(0, node_opcua_assert_1.assert)(minVal < maxVal);
|
|
23
25
|
if (value === 0) {
|
|
@@ -33,12 +35,6 @@ function clamp_value(value, minVal, maxVal) {
|
|
|
33
35
|
return value;
|
|
34
36
|
}
|
|
35
37
|
const minimumBufferSize = 8192;
|
|
36
|
-
/**
|
|
37
|
-
* @class ServerTCP_transport
|
|
38
|
-
* @extends TCP_transport
|
|
39
|
-
* @constructor
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
38
|
class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
43
39
|
constructor() {
|
|
44
40
|
super();
|
|
@@ -49,6 +45,12 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
49
45
|
this.maxMessageSize = 4 * 1024;
|
|
50
46
|
this.receiveBufferSize = 4 * 1024;
|
|
51
47
|
}
|
|
48
|
+
toString() {
|
|
49
|
+
let str = super.toString();
|
|
50
|
+
str += "helloReceived...... = " + this._helloReceived + "\n";
|
|
51
|
+
str += "aborted............ = " + this._aborted + "\n";
|
|
52
|
+
return str;
|
|
53
|
+
}
|
|
52
54
|
_write_chunk(messageChunk) {
|
|
53
55
|
// istanbul ignore next
|
|
54
56
|
if (this.sendBufferSize > 0 && messageChunk.length > this.sendBufferSize) {
|
|
@@ -73,34 +75,35 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
73
75
|
*
|
|
74
76
|
*/
|
|
75
77
|
init(socket, callback) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
(0, node_opcua_assert_1.assert)(socket, "missing called!");
|
|
79
|
+
// istanbul ignore next
|
|
80
|
+
debugLog && debugLog(chalk.cyan("init socket"));
|
|
79
81
|
(0, node_opcua_assert_1.assert)(!this._socket, "init already called!");
|
|
80
82
|
(0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a valid callback ");
|
|
81
83
|
this._install_socket(socket);
|
|
82
84
|
this._install_HEL_message_receiver(callback);
|
|
83
85
|
}
|
|
84
|
-
abortWithError(statusCode, extraErrorDescription, callback) {
|
|
85
|
-
return this._abortWithError(statusCode, extraErrorDescription, callback);
|
|
86
|
-
}
|
|
87
86
|
_abortWithError(statusCode, extraErrorDescription, callback) {
|
|
87
|
+
var _a;
|
|
88
88
|
// When a fatal error occurs, the Server shall send an Error Message to the Client and
|
|
89
89
|
// closes the TransportConnection gracefully.
|
|
90
|
-
doDebug && debugLog(chalk.cyan("_abortWithError"));
|
|
90
|
+
doDebug && debugLog(this.name, chalk.cyan("_abortWithError", statusCode.toString(), extraErrorDescription));
|
|
91
91
|
/* istanbul ignore next */
|
|
92
92
|
if (this._aborted) {
|
|
93
|
+
errorLog("Internal Er!ror: _abortWithError already called! Should not happen here");
|
|
93
94
|
// already called
|
|
94
95
|
return callback(new Error(statusCode.name));
|
|
95
96
|
}
|
|
96
97
|
this._aborted = 1;
|
|
98
|
+
(_a = this._socket) === null || _a === void 0 ? void 0 : _a.setTimeout(0);
|
|
99
|
+
const err = new Error(extraErrorDescription + " StatusCode = " + statusCode.name);
|
|
100
|
+
this._theCloseError = err;
|
|
97
101
|
setTimeout(() => {
|
|
98
102
|
// send the error message and close the connection
|
|
99
103
|
this.sendErrorMessage(statusCode, statusCode.description);
|
|
100
|
-
this.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
+
this.prematureTerminate(err, statusCode);
|
|
105
|
+
this._emitClose(err);
|
|
106
|
+
callback(err);
|
|
104
107
|
}, ServerTCP_transport.throttleTime);
|
|
105
108
|
}
|
|
106
109
|
_send_ACK_response(helloMessage) {
|
|
@@ -131,10 +134,11 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
131
134
|
});
|
|
132
135
|
// istanbul ignore next
|
|
133
136
|
if (utils_1.doTraceHelloAck) {
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
warningLog(`received Hello \n${helloMessage.toString()}`);
|
|
138
|
+
warningLog("Client accepts only message of size => ", this.maxMessageSize);
|
|
136
139
|
}
|
|
137
|
-
|
|
140
|
+
// istanbul ignore next
|
|
141
|
+
doDebug && debugLog("Client accepts only message of size => ", this.maxMessageSize);
|
|
138
142
|
const acknowledgeMessage = new AcknowledgeMessage_1.AcknowledgeMessage({
|
|
139
143
|
maxChunkCount: this.maxChunkCount,
|
|
140
144
|
maxMessageSize: this.maxMessageSize,
|
|
@@ -143,9 +147,7 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
143
147
|
sendBufferSize: this.sendBufferSize
|
|
144
148
|
});
|
|
145
149
|
// istanbul ignore next
|
|
146
|
-
|
|
147
|
-
console.log(`sending Ack \n${acknowledgeMessage.toString()}`);
|
|
148
|
-
}
|
|
150
|
+
utils_1.doTraceHelloAck && warningLog(`sending Ack \n${acknowledgeMessage.toString()}`);
|
|
149
151
|
const messageChunk = (0, tools_1.packTcpMessage)("ACK", acknowledgeMessage);
|
|
150
152
|
/* istanbul ignore next*/
|
|
151
153
|
if (doDebug) {
|
|
@@ -158,12 +160,11 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
158
160
|
this.write(messageChunk);
|
|
159
161
|
}
|
|
160
162
|
_install_HEL_message_receiver(callback) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
163
|
+
// istanbul ignore next
|
|
164
|
+
doDebug && debugLog(chalk.cyan("_install_HEL_message_receiver "));
|
|
164
165
|
this._install_one_time_message_receiver((err, data) => {
|
|
165
166
|
if (err) {
|
|
166
|
-
|
|
167
|
+
callback(err);
|
|
167
168
|
}
|
|
168
169
|
else {
|
|
169
170
|
// handle the HEL message
|
|
@@ -172,9 +173,8 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
_on_HEL_message(data, callback) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
176
|
+
// istanbul ignore next
|
|
177
|
+
doDebug && debugLog(chalk.cyan("_on_HEL_message"));
|
|
178
178
|
(0, node_opcua_assert_1.assert)(!this._helloReceived);
|
|
179
179
|
const stream = new node_opcua_binary_stream_1.BinaryStream(data);
|
|
180
180
|
const msgType = data.subarray(0, 3).toString("utf-8");
|
|
@@ -187,13 +187,14 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
187
187
|
try {
|
|
188
188
|
(0, node_opcua_assert_1.assert)(data.length >= 24);
|
|
189
189
|
const helloMessage = (0, tools_1.decodeMessage)(stream, HelloMessage_1.HelloMessage);
|
|
190
|
-
(0, node_opcua_assert_1.assert)(isFinite(this.protocolVersion));
|
|
191
190
|
// OPCUA Spec 1.03 part 6 - page 41
|
|
192
191
|
// The Server shall always accept versions greater than what it supports.
|
|
193
192
|
if (helloMessage.protocolVersion !== this.protocolVersion) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
`
|
|
193
|
+
// istanbul ignore next
|
|
194
|
+
doDebug &&
|
|
195
|
+
debugLog(`warning ! client sent helloMessage.protocolVersion = ` +
|
|
196
|
+
` 0x${helloMessage.protocolVersion.toString(16)} ` +
|
|
197
|
+
`whereas server protocolVersion is 0x${this.protocolVersion.toString(16)}`);
|
|
197
198
|
}
|
|
198
199
|
if (helloMessage.protocolVersion === 0xdeadbeef || helloMessage.protocolVersion < this.protocolVersion) {
|
|
199
200
|
// Note: 0xDEADBEEF is our special version number to simulate BadProtocolVersionUnsupported in tests
|
|
@@ -214,16 +215,14 @@ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
|
214
215
|
}
|
|
215
216
|
catch (err) {
|
|
216
217
|
// connection rejected because of malformed message
|
|
217
|
-
return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err
|
|
218
|
+
return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, util_1.types.isNativeError(err) ? err.message : "", callback);
|
|
218
219
|
}
|
|
219
220
|
callback(); // no Error
|
|
220
221
|
}
|
|
221
222
|
else {
|
|
222
223
|
// invalid packet , expecting HEL
|
|
223
224
|
/* istanbul ignore next*/
|
|
224
|
-
|
|
225
|
-
debugLog(chalk.red("BadCommunicationError ") + "Expecting 'HEL' message to initiate communication");
|
|
226
|
-
}
|
|
225
|
+
doDebug && debugLog(chalk.red("BadCommunicationError ") + "Expecting 'HEL' message to initiate communication");
|
|
227
226
|
this._abortWithError(node_opcua_status_code_1.StatusCodes.BadCommunicationError, "Expecting 'HEL' message to initiate communication", callback);
|
|
228
227
|
}
|
|
229
228
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_tcp_transport.js","sourceRoot":"","sources":["../../source/server_tcp_transport.ts"],"names":[],"mappings":";;;AAMA,+BAA+B;AAC/B,yDAA2C;AAE3C,iBAAiB;AACjB,0CAA0C;AAC1C,uEAAwD;AACxD,qEAA+D;AAC/D,mEAAiE;AAGjE,wBAAwB;AACxB,6DAA0D;AAC1D,iDAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"server_tcp_transport.js","sourceRoot":"","sources":["../../source/server_tcp_transport.ts"],"names":[],"mappings":";;;AAMA,+BAA6B;AAC7B,+BAA+B;AAC/B,yDAA2C;AAE3C,iBAAiB;AACjB,0CAA0C;AAC1C,uEAAwD;AACxD,qEAA+D;AAC/D,mEAAiE;AAGjE,wBAAwB;AACxB,6DAA0D;AAC1D,iDAA8C;AAC9C,mDAA6D;AAC7D,mCAAwD;AACxD,mCAA0C;AAE1C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;AAC9B,MAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;AAClD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