node-opcua-transport 2.51.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/.mocharc.yml +10 -0
- package/LICENSE +20 -0
- package/dist/source/AcknowledgeMessage.d.ts +27 -0
- package/dist/source/AcknowledgeMessage.js +79 -0
- package/dist/source/AcknowledgeMessage.js.map +1 -0
- package/dist/source/HelloMessage.d.ts +27 -0
- package/dist/source/HelloMessage.js +95 -0
- package/dist/source/HelloMessage.js.map +1 -0
- package/dist/source/TCPErrorMessage.d.ts +18 -0
- package/dist/source/TCPErrorMessage.js +47 -0
- package/dist/source/TCPErrorMessage.js.map +1 -0
- package/dist/source/client_tcp_transport.d.ts +68 -0
- package/dist/source/client_tcp_transport.js +315 -0
- package/dist/source/client_tcp_transport.js.map +1 -0
- package/dist/source/index.d.ts +11 -0
- package/dist/source/index.js +24 -0
- package/dist/source/index.js.map +1 -0
- package/dist/source/message_builder_base.d.ts +61 -0
- package/dist/source/message_builder_base.js +207 -0
- package/dist/source/message_builder_base.js.map +1 -0
- package/dist/source/server_tcp_transport.d.ts +45 -0
- package/dist/source/server_tcp_transport.js +232 -0
- package/dist/source/server_tcp_transport.js.map +1 -0
- package/dist/source/tcp_transport.d.ts +117 -0
- package/dist/source/tcp_transport.js +350 -0
- package/dist/source/tcp_transport.js.map +1 -0
- package/dist/source/tools.d.ts +13 -0
- package/dist/source/tools.js +99 -0
- package/dist/source/tools.js.map +1 -0
- package/dist/source/utils.d.ts +2 -0
- package/dist/source/utils.js +9 -0
- package/dist/source/utils.js.map +1 -0
- package/dist/test-fixtures/fixture_full_tcp_packets.d.ts +21 -0
- package/dist/test-fixtures/fixture_full_tcp_packets.js +413 -0
- package/dist/test-fixtures/fixture_full_tcp_packets.js.map +1 -0
- package/dist/test-fixtures/index.d.ts +1 -0
- package/dist/test-fixtures/index.js +14 -0
- package/dist/test-fixtures/index.js.map +1 -0
- package/dist/test_helpers/direct_transport.d.ts +14 -0
- package/dist/test_helpers/direct_transport.js +63 -0
- package/dist/test_helpers/direct_transport.js.map +1 -0
- package/dist/test_helpers/fake_server.d.ts +15 -0
- package/dist/test_helpers/fake_server.js +56 -0
- package/dist/test_helpers/fake_server.js.map +1 -0
- package/dist/test_helpers/half_com_channel.d.ts +10 -0
- package/dist/test_helpers/half_com_channel.js +35 -0
- package/dist/test_helpers/half_com_channel.js.map +1 -0
- package/dist/test_helpers/index.d.ts +4 -0
- package/dist/test_helpers/index.js +17 -0
- package/dist/test_helpers/index.js.map +1 -0
- package/dist/test_helpers/socket_transport.d.ts +8 -0
- package/dist/test_helpers/socket_transport.js +30 -0
- package/dist/test_helpers/socket_transport.js.map +1 -0
- package/package.json +50 -0
- package/source/AcknowledgeMessage.ts +112 -0
- package/source/HelloMessage.ts +133 -0
- package/source/TCPErrorMessage.ts +57 -0
- package/source/client_tcp_transport.ts +366 -0
- package/source/index.ts +11 -0
- package/source/message_builder_base.ts +263 -0
- package/source/server_tcp_transport.ts +284 -0
- package/source/tcp_transport.ts +450 -0
- package/source/tools.ts +113 -0
- package/source/utils.ts +4 -0
- package/test_helpers/direct_transport.ts +78 -0
- package/test_helpers/fake_server.ts +71 -0
- package/test_helpers/half_com_channel.ts +38 -0
- package/test_helpers/index.ts +4 -0
- package/test_helpers/socket_transport.ts +34 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientTCP_transport = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-transport
|
|
6
|
+
*/
|
|
7
|
+
// tslint:disable:class-name
|
|
8
|
+
// system
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const chalk = require("chalk");
|
|
11
|
+
const net_1 = require("net");
|
|
12
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
13
|
+
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
14
|
+
const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
|
|
15
|
+
const tcp_transport_1 = require("./tcp_transport");
|
|
16
|
+
const tools_1 = require("./tools");
|
|
17
|
+
const debug = require("node-opcua-debug");
|
|
18
|
+
const AcknowledgeMessage_1 = require("./AcknowledgeMessage");
|
|
19
|
+
const HelloMessage_1 = require("./HelloMessage");
|
|
20
|
+
const TCPErrorMessage_1 = require("./TCPErrorMessage");
|
|
21
|
+
const utils_1 = require("./utils");
|
|
22
|
+
const doDebug = debug.checkDebugFlag(__filename);
|
|
23
|
+
const debugLog = debug.make_debugLog(__filename);
|
|
24
|
+
const errorLog = debug.make_errorLog(__filename);
|
|
25
|
+
const gHostname = os.hostname();
|
|
26
|
+
function createClientSocket(endpointUrl) {
|
|
27
|
+
// create a socket based on Url
|
|
28
|
+
const ep = (0, tools_1.parseEndpointUrl)(endpointUrl);
|
|
29
|
+
const port = parseInt(ep.port, 10);
|
|
30
|
+
const hostname = ep.hostname;
|
|
31
|
+
let socket;
|
|
32
|
+
switch (ep.protocol) {
|
|
33
|
+
case "opc.tcp:":
|
|
34
|
+
socket = (0, net_1.createConnection)({ host: hostname, port });
|
|
35
|
+
// // Setting true for noDelay will immediately fire off data each time socket.write() is called.
|
|
36
|
+
socket.setNoDelay(true);
|
|
37
|
+
return socket;
|
|
38
|
+
case "fake:":
|
|
39
|
+
socket = (0, tcp_transport_1.getFakeTransport)();
|
|
40
|
+
(0, node_opcua_assert_1.assert)(ep.protocol === "fake:", " Unsupported transport protocol");
|
|
41
|
+
process.nextTick(() => socket.emit("connect"));
|
|
42
|
+
return socket;
|
|
43
|
+
case "websocket:":
|
|
44
|
+
case "http:":
|
|
45
|
+
case "https:FF":
|
|
46
|
+
default: {
|
|
47
|
+
const msg = "[NODE-OPCUA-E05] this transport protocol is not supported :" + ep.protocol;
|
|
48
|
+
errorLog(msg);
|
|
49
|
+
throw new Error(msg);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* a ClientTCP_transport connects to a remote server socket and
|
|
55
|
+
* initiates a communication with a HEL/ACK transaction.
|
|
56
|
+
* It negotiates the communication parameters with the other end.
|
|
57
|
+
*
|
|
58
|
+
* @class ClientTCP_transport
|
|
59
|
+
* @extends TCP_transport
|
|
60
|
+
* @constructor
|
|
61
|
+
* @example
|
|
62
|
+
*
|
|
63
|
+
* ```javascript
|
|
64
|
+
* const transport = ClientTCP_transport(url);
|
|
65
|
+
*
|
|
66
|
+
* transport.timeout = 10000;
|
|
67
|
+
*
|
|
68
|
+
* transport.connect(function(err)) {
|
|
69
|
+
* if (err) {
|
|
70
|
+
* // cannot connect
|
|
71
|
+
* } else {
|
|
72
|
+
* // connected
|
|
73
|
+
*
|
|
74
|
+
* }
|
|
75
|
+
* });
|
|
76
|
+
* ....
|
|
77
|
+
*
|
|
78
|
+
* transport.write(message_chunk,'F');
|
|
79
|
+
*
|
|
80
|
+
* ....
|
|
81
|
+
*
|
|
82
|
+
* transport.on("message",function(message_chunk) {
|
|
83
|
+
* // do something with message from server...
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
*
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
class ClientTCP_transport extends tcp_transport_1.TCP_transport {
|
|
92
|
+
constructor() {
|
|
93
|
+
super();
|
|
94
|
+
this.connected = false;
|
|
95
|
+
this.endpointUrl = "";
|
|
96
|
+
this.serverUri = "";
|
|
97
|
+
this._counter = 0;
|
|
98
|
+
this.numberOfRetry = 0;
|
|
99
|
+
}
|
|
100
|
+
dispose() {
|
|
101
|
+
/* istanbul ignore next */
|
|
102
|
+
if (doDebug) {
|
|
103
|
+
debugLog(" ClientTCP_transport disposed");
|
|
104
|
+
}
|
|
105
|
+
super.dispose();
|
|
106
|
+
}
|
|
107
|
+
connect(endpointUrl, callback) {
|
|
108
|
+
(0, node_opcua_assert_1.assert)(arguments.length === 2);
|
|
109
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
110
|
+
const ep = (0, tools_1.parseEndpointUrl)(endpointUrl);
|
|
111
|
+
this.endpointUrl = endpointUrl;
|
|
112
|
+
this.serverUri = "urn:" + gHostname + ":Sample";
|
|
113
|
+
/* istanbul ignore next */
|
|
114
|
+
if (doDebug) {
|
|
115
|
+
debugLog(chalk.cyan("ClientTCP_transport#connect(endpointUrl = " + endpointUrl + ")"));
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
this._socket = createClientSocket(endpointUrl);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
/* istanbul ignore next */
|
|
122
|
+
if (doDebug) {
|
|
123
|
+
debugLog("CreateClientSocket has failed");
|
|
124
|
+
}
|
|
125
|
+
return callback(err);
|
|
126
|
+
}
|
|
127
|
+
const _on_socket_error_after_connection = (err) => {
|
|
128
|
+
/* istanbul ignore next */
|
|
129
|
+
if (doDebug) {
|
|
130
|
+
debugLog(" _on_socket_error_after_connection ClientTCP_transport Socket Error", err.message);
|
|
131
|
+
}
|
|
132
|
+
// EPIPE : EPIPE (Broken pipe): A write on a pipe, socket, or FIFO for which there is no process to read the
|
|
133
|
+
// data. Commonly encountered at the net and http layers, indicative that the remote side of the stream
|
|
134
|
+
// being written to has been closed.
|
|
135
|
+
// ECONNRESET (Connection reset by peer): A connection was forcibly closed by a peer. This normally results
|
|
136
|
+
// from a loss of the connection on the remote socket due to a timeout or reboot. Commonly encountered
|
|
137
|
+
// via the http and net module
|
|
138
|
+
if (err.message.match(/ECONNRESET|EPIPE/)) {
|
|
139
|
+
/**
|
|
140
|
+
* @event connection_break
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
143
|
+
this.emit("connection_break");
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const _on_socket_connect = () => {
|
|
147
|
+
/* istanbul ignore next */
|
|
148
|
+
if (doDebug) {
|
|
149
|
+
debugLog("entering _on_socket_connect");
|
|
150
|
+
}
|
|
151
|
+
_remove_connect_listeners();
|
|
152
|
+
this._perform_HEL_ACK_transaction((err) => {
|
|
153
|
+
if (!err) {
|
|
154
|
+
/* istanbul ignore next */
|
|
155
|
+
if (!this._socket) {
|
|
156
|
+
throw new Error("internal error");
|
|
157
|
+
}
|
|
158
|
+
// install error handler to detect connection break
|
|
159
|
+
this._socket.on("error", _on_socket_error_after_connection);
|
|
160
|
+
this.connected = true;
|
|
161
|
+
/**
|
|
162
|
+
* notify the observers that the transport is connected (the socket is connected and the the HEL/ACK
|
|
163
|
+
* transaction has been done)
|
|
164
|
+
* @event connect
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
this.emit("connect");
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
debugLog("_perform_HEL_ACK_transaction has failed with err=", err.message);
|
|
171
|
+
}
|
|
172
|
+
callback(err);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const _on_socket_error_for_connect = (err) => {
|
|
176
|
+
// this handler will catch attempt to connect to an inaccessible address.
|
|
177
|
+
/* istanbul ignore next */
|
|
178
|
+
if (doDebug) {
|
|
179
|
+
debugLog(chalk.cyan("ClientTCP_transport#connect - _on_socket_error_for_connect"), err.message);
|
|
180
|
+
}
|
|
181
|
+
(0, node_opcua_assert_1.assert)(err instanceof Error);
|
|
182
|
+
_remove_connect_listeners();
|
|
183
|
+
callback(err);
|
|
184
|
+
};
|
|
185
|
+
const _on_socket_end_for_connect = (err) => {
|
|
186
|
+
/* istanbul ignore next */
|
|
187
|
+
if (doDebug) {
|
|
188
|
+
debugLog(chalk.cyan("ClientTCP_transport#connect -> _on_socket_end_for_connect Socket has been closed by server"), err);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const _remove_connect_listeners = () => {
|
|
192
|
+
/* istanbul ignore next */
|
|
193
|
+
if (!this._socket) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this._socket.removeListener("error", _on_socket_error_for_connect);
|
|
197
|
+
this._socket.removeListener("end", _on_socket_end_for_connect);
|
|
198
|
+
};
|
|
199
|
+
this._socket.once("error", _on_socket_error_for_connect);
|
|
200
|
+
this._socket.once("end", _on_socket_end_for_connect);
|
|
201
|
+
this._socket.once("connect", _on_socket_connect);
|
|
202
|
+
this._install_socket(this._socket);
|
|
203
|
+
}
|
|
204
|
+
on_socket_ended(err) {
|
|
205
|
+
debugLog("on_socket_ended", this.name, err ? err.message : "");
|
|
206
|
+
if (this.connected) {
|
|
207
|
+
super.on_socket_ended(err);
|
|
208
|
+
}
|
|
209
|
+
// if (this._socket) {
|
|
210
|
+
// this._socket.removeAllListeners();
|
|
211
|
+
// }
|
|
212
|
+
}
|
|
213
|
+
_handle_ACK_response(messageChunk, callback) {
|
|
214
|
+
const _stream = new node_opcua_binary_stream_1.BinaryStream(messageChunk);
|
|
215
|
+
const messageHeader = (0, node_opcua_chunkmanager_1.readMessageHeader)(_stream);
|
|
216
|
+
let err;
|
|
217
|
+
/* istanbul ignore next */
|
|
218
|
+
if (messageHeader.isFinal !== "F") {
|
|
219
|
+
err = new Error(" invalid ACK message");
|
|
220
|
+
return callback(err);
|
|
221
|
+
}
|
|
222
|
+
let responseClass;
|
|
223
|
+
let response;
|
|
224
|
+
if (messageHeader.msgType === "ERR") {
|
|
225
|
+
responseClass = TCPErrorMessage_1.TCPErrorMessage;
|
|
226
|
+
_stream.rewind();
|
|
227
|
+
response = (0, tools_1.decodeMessage)(_stream, responseClass);
|
|
228
|
+
err = new Error("ACK: ERR received " + response.statusCode.toString() + " : " + response.reason);
|
|
229
|
+
err.statusCode = response.statusCode;
|
|
230
|
+
// istanbul ignore next
|
|
231
|
+
if (utils_1.doTraceHelloAck) {
|
|
232
|
+
console.log("receiving ERR instead of Ack", response.toString());
|
|
233
|
+
}
|
|
234
|
+
callback(err);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
responseClass = AcknowledgeMessage_1.AcknowledgeMessage;
|
|
238
|
+
_stream.rewind();
|
|
239
|
+
response = (0, tools_1.decodeMessage)(_stream, responseClass);
|
|
240
|
+
this.parameters = response;
|
|
241
|
+
// istanbul ignore next
|
|
242
|
+
if (utils_1.doTraceHelloAck) {
|
|
243
|
+
console.log("receiving Ack\n", response.toString());
|
|
244
|
+
}
|
|
245
|
+
callback();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
_send_HELLO_request() {
|
|
249
|
+
/* istanbul ignore next */
|
|
250
|
+
if (doDebug) {
|
|
251
|
+
debugLog("entering _send_HELLO_request");
|
|
252
|
+
}
|
|
253
|
+
(0, node_opcua_assert_1.assert)(this._socket);
|
|
254
|
+
(0, node_opcua_assert_1.assert)(isFinite(this.protocolVersion));
|
|
255
|
+
(0, node_opcua_assert_1.assert)(this.endpointUrl.length > 0, " expecting a valid endpoint url");
|
|
256
|
+
// Write a message to the socket as soon as the client is connected,
|
|
257
|
+
// the server will receive it as message from the client
|
|
258
|
+
const helloMessage = new HelloMessage_1.HelloMessage({
|
|
259
|
+
endpointUrl: this.endpointUrl,
|
|
260
|
+
maxChunkCount: 0,
|
|
261
|
+
maxMessageSize: 0,
|
|
262
|
+
protocolVersion: this.protocolVersion,
|
|
263
|
+
receiveBufferSize: 1024 * 64 * 10,
|
|
264
|
+
sendBufferSize: 1024 * 64 * 10 // 8192 min,
|
|
265
|
+
});
|
|
266
|
+
// istanbul ignore next
|
|
267
|
+
if (utils_1.doTraceHelloAck) {
|
|
268
|
+
console.log(`sending Hello\n ${helloMessage.toString()}`);
|
|
269
|
+
}
|
|
270
|
+
const messageChunk = (0, tools_1.packTcpMessage)("HEL", helloMessage);
|
|
271
|
+
this._write_chunk(messageChunk);
|
|
272
|
+
}
|
|
273
|
+
_on_ACK_response(externalCallback, err, data) {
|
|
274
|
+
/* istanbul ignore next */
|
|
275
|
+
if (doDebug) {
|
|
276
|
+
debugLog("entering _on_ACK_response");
|
|
277
|
+
}
|
|
278
|
+
(0, node_opcua_assert_1.assert)(typeof externalCallback === "function");
|
|
279
|
+
(0, node_opcua_assert_1.assert)(this._counter === 0, "Ack response should only be received once !");
|
|
280
|
+
this._counter += 1;
|
|
281
|
+
if (err || !data) {
|
|
282
|
+
externalCallback(err || new Error("no data"));
|
|
283
|
+
if (this._socket) {
|
|
284
|
+
this._socket.end();
|
|
285
|
+
// Xx this._socket.removeAllListeners();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
this._handle_ACK_response(data, externalCallback);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
_perform_HEL_ACK_transaction(callback) {
|
|
293
|
+
/* istanbul ignore next */
|
|
294
|
+
if (!this._socket) {
|
|
295
|
+
return callback(new Error("No socket available to perform HEL/ACK transaction"));
|
|
296
|
+
}
|
|
297
|
+
(0, node_opcua_assert_1.assert)(this._socket, "expecting a valid socket to send a message");
|
|
298
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
299
|
+
this._counter = 0;
|
|
300
|
+
/* istanbul ignore next */
|
|
301
|
+
if (doDebug) {
|
|
302
|
+
debugLog("entering _perform_HEL_ACK_transaction");
|
|
303
|
+
}
|
|
304
|
+
this._install_one_time_message_receiver((err, data) => {
|
|
305
|
+
/* istanbul ignore next */
|
|
306
|
+
if (doDebug) {
|
|
307
|
+
debugLog("before _on_ACK_response ", err ? err.message : "");
|
|
308
|
+
}
|
|
309
|
+
this._on_ACK_response(callback, err, data);
|
|
310
|
+
});
|
|
311
|
+
this._send_HELLO_request();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.ClientTCP_transport = ClientTCP_transport;
|
|
315
|
+
//# sourceMappingURL=client_tcp_transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_tcp_transport.js","sourceRoot":"","sources":["../../source/client_tcp_transport.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,4BAA4B;AAC5B,SAAS;AACT,yBAAyB;AACzB,+BAA+B;AAE/B,6BAA+C;AAC/C,yDAA2C;AAC3C,uEAAwD;A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AAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACjE;YACD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC/B,CAAC;CACJ;AAjQD,kDAiQC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-transport
|
|
3
|
+
*/
|
|
4
|
+
export * from "./HelloMessage";
|
|
5
|
+
export * from "./AcknowledgeMessage";
|
|
6
|
+
export * from "./TCPErrorMessage";
|
|
7
|
+
export * from "./client_tcp_transport";
|
|
8
|
+
export * from "./server_tcp_transport";
|
|
9
|
+
export * from "./tcp_transport";
|
|
10
|
+
export * from "./tools";
|
|
11
|
+
export * from "./message_builder_base";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
/**
|
|
14
|
+
* @module node-opcua-transport
|
|
15
|
+
*/
|
|
16
|
+
__exportStar(require("./HelloMessage"), exports);
|
|
17
|
+
__exportStar(require("./AcknowledgeMessage"), exports);
|
|
18
|
+
__exportStar(require("./TCPErrorMessage"), exports);
|
|
19
|
+
__exportStar(require("./client_tcp_transport"), exports);
|
|
20
|
+
__exportStar(require("./server_tcp_transport"), exports);
|
|
21
|
+
__exportStar(require("./tcp_transport"), exports);
|
|
22
|
+
__exportStar(require("./tools"), exports);
|
|
23
|
+
__exportStar(require("./message_builder_base"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;GAEG;AACH,iDAA+B;AAC/B,uDAAqC;AACrC,oDAAkC;AAClC,yDAAuC;AACvC,yDAAuC;AACvC,kDAAgC;AAChC,0CAAwB;AACxB,yDAAuC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-transport
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
import { BinaryStream } from "node-opcua-binary-stream";
|
|
7
|
+
import { SequenceHeader } from "node-opcua-chunkmanager";
|
|
8
|
+
import { MessageHeader, PacketAssembler, PacketInfo } from "node-opcua-packet-assembler";
|
|
9
|
+
export declare function readRawMessageHeader(data: Buffer): PacketInfo;
|
|
10
|
+
/**
|
|
11
|
+
* @class MessageBuilderBase
|
|
12
|
+
* @extends EventEmitter
|
|
13
|
+
* @uses PacketAssembler
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param options {Object}
|
|
16
|
+
* @param [options.signatureLength=0] {number}
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export declare class MessageBuilderBase extends EventEmitter {
|
|
20
|
+
readonly signatureLength: number;
|
|
21
|
+
readonly options: {
|
|
22
|
+
signatureLength?: number;
|
|
23
|
+
};
|
|
24
|
+
readonly _packetAssembler: PacketAssembler;
|
|
25
|
+
channelId: number;
|
|
26
|
+
totalMessageSize: number;
|
|
27
|
+
sequenceHeader: SequenceHeader | null;
|
|
28
|
+
_tick0: number;
|
|
29
|
+
_tick1: number;
|
|
30
|
+
protected id: string;
|
|
31
|
+
protected totalBodySize: number;
|
|
32
|
+
protected messageChunks: Buffer[];
|
|
33
|
+
protected messageHeader?: MessageHeader;
|
|
34
|
+
private _securityDefeated;
|
|
35
|
+
private _hasReceivedError;
|
|
36
|
+
private blocks;
|
|
37
|
+
private readonly _expectedChannelId;
|
|
38
|
+
private offsetBodyStart;
|
|
39
|
+
constructor(options?: {
|
|
40
|
+
signatureLength?: number;
|
|
41
|
+
});
|
|
42
|
+
dispose(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Feed message builder with some data
|
|
45
|
+
* @method feed
|
|
46
|
+
* @param data
|
|
47
|
+
*/
|
|
48
|
+
feed(data: Buffer): void;
|
|
49
|
+
protected _decodeMessageBody(fullMessageBody: Buffer): boolean;
|
|
50
|
+
protected _read_headers(binaryStream: BinaryStream): boolean;
|
|
51
|
+
protected _report_error(errorMessage: string): false;
|
|
52
|
+
private _init_new;
|
|
53
|
+
/**
|
|
54
|
+
* append a message chunk
|
|
55
|
+
* @method _append
|
|
56
|
+
* @param chunk
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
private _append;
|
|
60
|
+
private _feed_messageChunk;
|
|
61
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageBuilderBase = exports.readRawMessageHeader = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-transport
|
|
6
|
+
*/
|
|
7
|
+
const events_1 = require("events");
|
|
8
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
+
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
10
|
+
const node_opcua_buffer_utils_1 = require("node-opcua-buffer-utils");
|
|
11
|
+
const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
|
|
12
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
13
|
+
const node_opcua_packet_assembler_1 = require("node-opcua-packet-assembler");
|
|
14
|
+
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
15
|
+
const doPerfMonitoring = process.env.NODEOPCUADEBUG && process.env.NODEOPCUADEBUG.indexOf("PERF") >= 0;
|
|
16
|
+
const errorLog = (0, node_opcua_debug_1.make_errorLog)("MessageBuilder");
|
|
17
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("MessageBuilder");
|
|
18
|
+
function readRawMessageHeader(data) {
|
|
19
|
+
const messageHeader = (0, node_opcua_chunkmanager_1.readMessageHeader)(new node_opcua_binary_stream_1.BinaryStream(data));
|
|
20
|
+
return {
|
|
21
|
+
extra: "",
|
|
22
|
+
length: messageHeader.length,
|
|
23
|
+
messageHeader
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.readRawMessageHeader = readRawMessageHeader;
|
|
27
|
+
/**
|
|
28
|
+
* @class MessageBuilderBase
|
|
29
|
+
* @extends EventEmitter
|
|
30
|
+
* @uses PacketAssembler
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param options {Object}
|
|
33
|
+
* @param [options.signatureLength=0] {number}
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
class MessageBuilderBase extends events_1.EventEmitter {
|
|
37
|
+
constructor(options) {
|
|
38
|
+
super();
|
|
39
|
+
this.id = "";
|
|
40
|
+
this._tick0 = 0;
|
|
41
|
+
this._tick1 = 0;
|
|
42
|
+
this._hasReceivedError = false;
|
|
43
|
+
this.blocks = [];
|
|
44
|
+
this.messageChunks = [];
|
|
45
|
+
this._expectedChannelId = 0;
|
|
46
|
+
options = options || {};
|
|
47
|
+
this.signatureLength = options.signatureLength || 0;
|
|
48
|
+
this.options = options;
|
|
49
|
+
this._packetAssembler = new node_opcua_packet_assembler_1.PacketAssembler({
|
|
50
|
+
minimumSizeInBytes: 0,
|
|
51
|
+
readMessageFunc: readRawMessageHeader
|
|
52
|
+
});
|
|
53
|
+
this._packetAssembler.on("message", (messageChunk) => this._feed_messageChunk(messageChunk));
|
|
54
|
+
this._packetAssembler.on("newMessage", (info, data) => {
|
|
55
|
+
if (doPerfMonitoring) {
|
|
56
|
+
// record tick 0: when the first data is received
|
|
57
|
+
this._tick0 = (0, node_opcua_utils_1.get_clock_tick)();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* notify the observers that a new message is being built
|
|
62
|
+
* @event start_chunk
|
|
63
|
+
* @param info
|
|
64
|
+
* @param data
|
|
65
|
+
*/
|
|
66
|
+
this.emit("start_chunk", info, data);
|
|
67
|
+
});
|
|
68
|
+
this._securityDefeated = false;
|
|
69
|
+
this.totalBodySize = 0;
|
|
70
|
+
this.totalMessageSize = 0;
|
|
71
|
+
this.channelId = 0;
|
|
72
|
+
this.offsetBodyStart = 0;
|
|
73
|
+
this.sequenceHeader = null;
|
|
74
|
+
this._init_new();
|
|
75
|
+
}
|
|
76
|
+
dispose() {
|
|
77
|
+
this.removeAllListeners();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Feed message builder with some data
|
|
81
|
+
* @method feed
|
|
82
|
+
* @param data
|
|
83
|
+
*/
|
|
84
|
+
feed(data) {
|
|
85
|
+
if (!this._securityDefeated && !this._hasReceivedError) {
|
|
86
|
+
this._packetAssembler.feed(data);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
_decodeMessageBody(fullMessageBody) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
_read_headers(binaryStream) {
|
|
93
|
+
try {
|
|
94
|
+
this.messageHeader = (0, node_opcua_chunkmanager_1.readMessageHeader)(binaryStream);
|
|
95
|
+
(0, node_opcua_assert_1.assert)(binaryStream.length === 8, "expecting message header to be 8 bytes");
|
|
96
|
+
this.channelId = binaryStream.readUInt32();
|
|
97
|
+
(0, node_opcua_assert_1.assert)(binaryStream.length === 12);
|
|
98
|
+
// verifying secure ChannelId
|
|
99
|
+
if (this._expectedChannelId && this.channelId !== this._expectedChannelId) {
|
|
100
|
+
return this._report_error("Invalid secure channel Id");
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
_report_error(errorMessage) {
|
|
109
|
+
this._hasReceivedError = true;
|
|
110
|
+
/**
|
|
111
|
+
* notify the observers that an error has occurred
|
|
112
|
+
* @event error
|
|
113
|
+
* @param error the error to raise
|
|
114
|
+
*/
|
|
115
|
+
debugLog("Error ", this.id, errorMessage);
|
|
116
|
+
// xx errorLog(new Error());
|
|
117
|
+
this.emit("error", new Error(errorMessage), this.sequenceHeader ? this.sequenceHeader.requestId : null);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
_init_new() {
|
|
121
|
+
this._securityDefeated = false;
|
|
122
|
+
this._hasReceivedError = false;
|
|
123
|
+
this.totalBodySize = 0;
|
|
124
|
+
this.totalMessageSize = 0;
|
|
125
|
+
this.blocks = [];
|
|
126
|
+
this.messageChunks = [];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* append a message chunk
|
|
130
|
+
* @method _append
|
|
131
|
+
* @param chunk
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
_append(chunk) {
|
|
135
|
+
if (this._hasReceivedError) {
|
|
136
|
+
// the message builder is in error mode and further message chunks should be discarded.
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
this.messageChunks.push(chunk);
|
|
140
|
+
this.totalMessageSize += chunk.length;
|
|
141
|
+
const binaryStream = new node_opcua_binary_stream_1.BinaryStream(chunk);
|
|
142
|
+
if (!this._read_headers(binaryStream)) {
|
|
143
|
+
return this._report_error(`Invalid message header detected`);
|
|
144
|
+
}
|
|
145
|
+
(0, node_opcua_assert_1.assert)(binaryStream.length >= 12);
|
|
146
|
+
// verify message chunk length
|
|
147
|
+
if (this.messageHeader.length !== chunk.length) {
|
|
148
|
+
// tslint:disable:max-line-length
|
|
149
|
+
return this._report_error(`Invalid messageChunk size: the provided chunk is ${chunk.length} bytes long but header specifies ${this.messageHeader.length}`);
|
|
150
|
+
}
|
|
151
|
+
// the start of the message body block
|
|
152
|
+
const offsetBodyStart = binaryStream.length;
|
|
153
|
+
// the end of the message body block
|
|
154
|
+
const offsetBodyEnd = binaryStream.buffer.length;
|
|
155
|
+
this.totalBodySize += offsetBodyEnd - offsetBodyStart;
|
|
156
|
+
this.offsetBodyStart = offsetBodyStart;
|
|
157
|
+
// add message body to a queue
|
|
158
|
+
// note : Buffer.slice create a shared memory !
|
|
159
|
+
// use Buffer.clone
|
|
160
|
+
const sharedBuffer = chunk.slice(this.offsetBodyStart, offsetBodyEnd);
|
|
161
|
+
const clonedBuffer = (0, node_opcua_buffer_utils_1.createFastUninitializedBuffer)(sharedBuffer.length);
|
|
162
|
+
sharedBuffer.copy(clonedBuffer, 0, 0);
|
|
163
|
+
this.blocks.push(clonedBuffer);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
_feed_messageChunk(chunk) {
|
|
167
|
+
(0, node_opcua_assert_1.assert)(chunk);
|
|
168
|
+
const messageHeader = (0, node_opcua_chunkmanager_1.readMessageHeader)(new node_opcua_binary_stream_1.BinaryStream(chunk));
|
|
169
|
+
/**
|
|
170
|
+
* notify the observers that new message chunk has been received
|
|
171
|
+
* @event chunk
|
|
172
|
+
* @param messageChunk the raw message chunk
|
|
173
|
+
*/
|
|
174
|
+
this.emit("chunk", chunk);
|
|
175
|
+
if (messageHeader.isFinal === "F") {
|
|
176
|
+
// last message
|
|
177
|
+
this._append(chunk);
|
|
178
|
+
if (this._hasReceivedError) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const fullMessageBody = this.blocks.length === 1 ? this.blocks[0] : Buffer.concat(this.blocks);
|
|
182
|
+
if (doPerfMonitoring) {
|
|
183
|
+
// record tick 1: when a complete message has been received ( all chunks assembled)
|
|
184
|
+
this._tick1 = (0, node_opcua_utils_1.get_clock_tick)();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* notify the observers that a full message has been received
|
|
188
|
+
* @event full_message_body
|
|
189
|
+
* @param full_message_body the full message body made of all concatenated chunks.
|
|
190
|
+
*/
|
|
191
|
+
this.emit("full_message_body", fullMessageBody);
|
|
192
|
+
this._decodeMessageBody(fullMessageBody);
|
|
193
|
+
// be ready for next block
|
|
194
|
+
this._init_new();
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
else if (messageHeader.isFinal === "A") {
|
|
198
|
+
return this._report_error("received and Abort Message");
|
|
199
|
+
}
|
|
200
|
+
else if (messageHeader.isFinal === "C") {
|
|
201
|
+
return this._append(chunk);
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.MessageBuilderBase = MessageBuilderBase;
|
|
207
|
+
//# sourceMappingURL=message_builder_base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_builder_base.js","sourceRoot":"","sources":["../../source/message_builder_base.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mCAAsC;AACtC,yDAA2C;AAE3C,uEAAwD;AACxD,qEAAwE;AACxE,qEAA4E;AAC5E,uDAAgE;AAChE,6EAAyF;AACzF,uDAAkD;AAElD,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAEvG,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,gBAAgB,CAAC,CAAC;AACjD,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,gBAAgB,CAAC,CAAC;AAEjD,SAAgB,oBAAoB,CAAC,IAAY;IAC7C,MAAM,aAAa,GAAG,IAAA,2CAAiB,EAAC,IAAI,uCAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE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