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,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCP_transport = exports.getFakeTransport = exports.setFakeTransport = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-transport
|
|
6
|
+
*/
|
|
7
|
+
const chalk = require("chalk");
|
|
8
|
+
const events_1 = require("events");
|
|
9
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
10
|
+
const node_opcua_buffer_utils_1 = require("node-opcua-buffer-utils");
|
|
11
|
+
const debug = require("node-opcua-debug");
|
|
12
|
+
const node_opcua_object_registry_1 = require("node-opcua-object-registry");
|
|
13
|
+
const node_opcua_packet_assembler_1 = require("node-opcua-packet-assembler");
|
|
14
|
+
const message_builder_base_1 = require("./message_builder_base");
|
|
15
|
+
const tools_1 = require("./tools");
|
|
16
|
+
const debugLog = debug.make_debugLog(__filename);
|
|
17
|
+
const doDebug = debug.checkDebugFlag(__filename);
|
|
18
|
+
const errorLog = debug.make_errorLog(__filename);
|
|
19
|
+
let fakeSocket = { invalid: true };
|
|
20
|
+
function setFakeTransport(mockSocket) {
|
|
21
|
+
fakeSocket = mockSocket;
|
|
22
|
+
}
|
|
23
|
+
exports.setFakeTransport = setFakeTransport;
|
|
24
|
+
function getFakeTransport() {
|
|
25
|
+
if (fakeSocket.invalid) {
|
|
26
|
+
throw new Error("getFakeTransport: setFakeTransport must be called first - BadProtocolVersionUnsupported");
|
|
27
|
+
}
|
|
28
|
+
return fakeSocket;
|
|
29
|
+
}
|
|
30
|
+
exports.getFakeTransport = getFakeTransport;
|
|
31
|
+
let counter = 0;
|
|
32
|
+
// tslint:disable:class-name
|
|
33
|
+
class TCP_transport extends events_1.EventEmitter {
|
|
34
|
+
constructor() {
|
|
35
|
+
super();
|
|
36
|
+
this.name = this.constructor.name + counter;
|
|
37
|
+
counter += 1;
|
|
38
|
+
this._timerId = null;
|
|
39
|
+
this._timeout = 30000; // 30 seconds timeout
|
|
40
|
+
this._socket = null;
|
|
41
|
+
this.headerSize = 8;
|
|
42
|
+
this.protocolVersion = 0;
|
|
43
|
+
this._disconnecting = false;
|
|
44
|
+
this._pendingBuffer = undefined;
|
|
45
|
+
this.bytesWritten = 0;
|
|
46
|
+
this.bytesRead = 0;
|
|
47
|
+
this._theCallback = undefined;
|
|
48
|
+
this.chunkWrittenCount = 0;
|
|
49
|
+
this.chunkReadCount = 0;
|
|
50
|
+
this._onSocketClosedHasBeenCalled = false;
|
|
51
|
+
this._onSocketEndedHasBeenCalled = false;
|
|
52
|
+
TCP_transport.registry.register(this);
|
|
53
|
+
}
|
|
54
|
+
get timeout() {
|
|
55
|
+
return this._timeout;
|
|
56
|
+
}
|
|
57
|
+
set timeout(value) {
|
|
58
|
+
debugLog("Setting socket " + this.name + " timeout = ", value);
|
|
59
|
+
this._timeout = value;
|
|
60
|
+
}
|
|
61
|
+
dispose() {
|
|
62
|
+
this._cleanup_timers();
|
|
63
|
+
(0, node_opcua_assert_1.assert)(!this._timerId);
|
|
64
|
+
if (this._socket) {
|
|
65
|
+
this._socket.destroy();
|
|
66
|
+
this._socket.removeAllListeners();
|
|
67
|
+
this._socket = null;
|
|
68
|
+
}
|
|
69
|
+
TCP_transport.registry.unregister(this);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* ```createChunk``` is used to construct a pre-allocated chunk to store up to ```length``` bytes of data.
|
|
73
|
+
* The created chunk includes a prepended header for ```chunk_type``` of size ```self.headerSize```.
|
|
74
|
+
*
|
|
75
|
+
* @method createChunk
|
|
76
|
+
* @param msgType
|
|
77
|
+
* @param chunkType {String} chunk type. should be 'F' 'C' or 'A'
|
|
78
|
+
* @param length
|
|
79
|
+
* @return a buffer object with the required length representing the chunk.
|
|
80
|
+
*
|
|
81
|
+
* Note:
|
|
82
|
+
* - only one chunk can be created at a time.
|
|
83
|
+
* - a created chunk should be committed using the ```write``` method before an other one is created.
|
|
84
|
+
*/
|
|
85
|
+
createChunk(msgType, chunkType, length) {
|
|
86
|
+
(0, node_opcua_assert_1.assert)(msgType === "MSG");
|
|
87
|
+
(0, node_opcua_assert_1.assert)(this._pendingBuffer === undefined, "createChunk has already been called ( use write first)");
|
|
88
|
+
const totalLength = length + this.headerSize;
|
|
89
|
+
const buffer = (0, node_opcua_buffer_utils_1.createFastUninitializedBuffer)(totalLength);
|
|
90
|
+
(0, tools_1.writeTCPMessageHeader)("MSG", chunkType, totalLength, buffer);
|
|
91
|
+
this._pendingBuffer = buffer;
|
|
92
|
+
return buffer;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* write the message_chunk on the socket.
|
|
96
|
+
* @method write
|
|
97
|
+
* @param messageChunk
|
|
98
|
+
*
|
|
99
|
+
* Notes:
|
|
100
|
+
* - the message chunk must have been created by ```createChunk```.
|
|
101
|
+
* - once a message chunk has been written, it is possible to call ```createChunk``` again.
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
write(messageChunk) {
|
|
105
|
+
(0, node_opcua_assert_1.assert)(this._pendingBuffer === undefined || this._pendingBuffer === messageChunk, " write should be used with buffer created by createChunk");
|
|
106
|
+
const header = (0, message_builder_base_1.readRawMessageHeader)(messageChunk);
|
|
107
|
+
(0, node_opcua_assert_1.assert)(header.length === messageChunk.length);
|
|
108
|
+
(0, node_opcua_assert_1.assert)(["F", "C", "A"].indexOf(header.messageHeader.isFinal) !== -1);
|
|
109
|
+
this._write_chunk(messageChunk);
|
|
110
|
+
this._pendingBuffer = undefined;
|
|
111
|
+
}
|
|
112
|
+
get isDisconnecting() {
|
|
113
|
+
return this._disconnecting;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* disconnect the TCP layer and close the underlying socket.
|
|
117
|
+
* The ```"close"``` event will be emitted to the observers with err=null.
|
|
118
|
+
*
|
|
119
|
+
* @method disconnect
|
|
120
|
+
* @async
|
|
121
|
+
* @param callback
|
|
122
|
+
*/
|
|
123
|
+
disconnect(callback) {
|
|
124
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a callback function, but got " + callback);
|
|
125
|
+
if (this._disconnecting) {
|
|
126
|
+
callback();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
(0, node_opcua_assert_1.assert)(!this._disconnecting, "TCP Transport has already been disconnected");
|
|
130
|
+
this._disconnecting = true;
|
|
131
|
+
// xx assert(!this._theCallback,
|
|
132
|
+
// "disconnect shall not be called while the 'one time message receiver' is in operation");
|
|
133
|
+
this._cleanup_timers();
|
|
134
|
+
if (this._socket) {
|
|
135
|
+
this._socket.end();
|
|
136
|
+
this._socket.destroy();
|
|
137
|
+
// xx this._socket.removeAllListeners();
|
|
138
|
+
this._socket = null;
|
|
139
|
+
}
|
|
140
|
+
this.on_socket_ended(null);
|
|
141
|
+
setImmediate(() => {
|
|
142
|
+
callback();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
isValid() {
|
|
146
|
+
return this._socket !== null && !this._socket.destroyed && !this._disconnecting;
|
|
147
|
+
}
|
|
148
|
+
_write_chunk(messageChunk) {
|
|
149
|
+
if (this._socket !== null) {
|
|
150
|
+
this.bytesWritten += messageChunk.length;
|
|
151
|
+
this.chunkWrittenCount++;
|
|
152
|
+
this._socket.write(messageChunk);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
on_socket_ended(err) {
|
|
156
|
+
(0, node_opcua_assert_1.assert)(!this._onSocketEndedHasBeenCalled);
|
|
157
|
+
this._onSocketEndedHasBeenCalled = true; // we don't want to send close event twice ...
|
|
158
|
+
/**
|
|
159
|
+
* notify the observers that the transport layer has been disconnected.
|
|
160
|
+
* @event close
|
|
161
|
+
* @param err the Error object or null
|
|
162
|
+
*/
|
|
163
|
+
this.emit("close", err || null);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @method _install_socket
|
|
167
|
+
* @param socket {Socket}
|
|
168
|
+
* @protected
|
|
169
|
+
*/
|
|
170
|
+
_install_socket(socket) {
|
|
171
|
+
(0, node_opcua_assert_1.assert)(socket);
|
|
172
|
+
this._socket = socket;
|
|
173
|
+
if (doDebug) {
|
|
174
|
+
debugLog(" TCP_transport#_install_socket ", this.name);
|
|
175
|
+
}
|
|
176
|
+
// install packet assembler ...
|
|
177
|
+
this.packetAssembler = new node_opcua_packet_assembler_1.PacketAssembler({
|
|
178
|
+
readMessageFunc: message_builder_base_1.readRawMessageHeader,
|
|
179
|
+
minimumSizeInBytes: this.headerSize
|
|
180
|
+
});
|
|
181
|
+
/* istanbul ignore next */
|
|
182
|
+
if (!this.packetAssembler) {
|
|
183
|
+
throw new Error("Internal Error");
|
|
184
|
+
}
|
|
185
|
+
this.packetAssembler.on("message", (messageChunk) => this._on_message_received(messageChunk));
|
|
186
|
+
this._socket
|
|
187
|
+
.on("data", (data) => this._on_socket_data(data))
|
|
188
|
+
.on("close", (hadError) => this._on_socket_close(hadError))
|
|
189
|
+
.on("end", (err) => this._on_socket_end(err))
|
|
190
|
+
.on("error", (err) => this._on_socket_error(err));
|
|
191
|
+
// set socket timeout
|
|
192
|
+
debugLog(" TCP_transport#install => setting " + this.name + " _socket.setTimeout to ", this.timeout);
|
|
193
|
+
// let use a large timeout here to make sure that we not conflict with our internal timeout
|
|
194
|
+
this._socket.setTimeout(this.timeout + 2000, () => {
|
|
195
|
+
debugLog(` _socket ${this.name} has timed out (timeout = ${this.timeout})`);
|
|
196
|
+
this.prematureTerminate(new Error("INTERNAL_EPIPE timeout=" + this.timeout));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
prematureTerminate(err) {
|
|
200
|
+
debugLog("prematureTerminate", err ? err.message : "");
|
|
201
|
+
if (this._socket) {
|
|
202
|
+
err.message = "EPIPE_" + err.message;
|
|
203
|
+
// we consider this as an error
|
|
204
|
+
const _s = this._socket;
|
|
205
|
+
_s.end();
|
|
206
|
+
_s.destroy(); // new Error("Socket has timed out"));
|
|
207
|
+
_s.emit("error", err);
|
|
208
|
+
this._socket = null;
|
|
209
|
+
this.dispose();
|
|
210
|
+
_s.removeAllListeners();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @method _install_one_time_message_receiver
|
|
215
|
+
*
|
|
216
|
+
* install a one time message receiver callback
|
|
217
|
+
*
|
|
218
|
+
* Rules:
|
|
219
|
+
* * TCP_transport will not emit the ```message``` event, while the "one time message receiver" is in operation.
|
|
220
|
+
* * the TCP_transport will wait for the next complete message chunk and call the provided callback func
|
|
221
|
+
* ```callback(null,messageChunk);```
|
|
222
|
+
*
|
|
223
|
+
* if a messageChunk is not received within ```TCP_transport.timeout``` or if the underlying socket reports
|
|
224
|
+
* an error, the callback function will be called with an Error.
|
|
225
|
+
*
|
|
226
|
+
*/
|
|
227
|
+
_install_one_time_message_receiver(callback) {
|
|
228
|
+
(0, node_opcua_assert_1.assert)(!this._theCallback, "callback already set");
|
|
229
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
230
|
+
this._theCallback = callback;
|
|
231
|
+
this._start_one_time_message_receiver();
|
|
232
|
+
}
|
|
233
|
+
_fulfill_pending_promises(err, data) {
|
|
234
|
+
this._cleanup_timers();
|
|
235
|
+
if (this._socket && this._on_error_during_one_time_message_receiver) {
|
|
236
|
+
this._socket.removeListener("close", this._on_error_during_one_time_message_receiver);
|
|
237
|
+
this._on_error_during_one_time_message_receiver = null;
|
|
238
|
+
}
|
|
239
|
+
const callback = this._theCallback;
|
|
240
|
+
this._theCallback = undefined;
|
|
241
|
+
if (callback) {
|
|
242
|
+
callback(err, data);
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
_on_message_received(messageChunk) {
|
|
248
|
+
const hasCallback = this._fulfill_pending_promises(null, messageChunk);
|
|
249
|
+
this.chunkReadCount++;
|
|
250
|
+
if (!hasCallback) {
|
|
251
|
+
/**
|
|
252
|
+
* notify the observers that a message chunk has been received
|
|
253
|
+
* @event message
|
|
254
|
+
* @param message_chunk the message chunk
|
|
255
|
+
*/
|
|
256
|
+
this.emit("message", messageChunk);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
_cleanup_timers() {
|
|
260
|
+
if (this._timerId) {
|
|
261
|
+
clearTimeout(this._timerId);
|
|
262
|
+
this._timerId = null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
_start_one_time_message_receiver() {
|
|
266
|
+
(0, node_opcua_assert_1.assert)(!this._timerId, "timer already started");
|
|
267
|
+
// Setup timeout detection timer ....
|
|
268
|
+
this._timerId = setTimeout(() => {
|
|
269
|
+
this._timerId = null;
|
|
270
|
+
this._fulfill_pending_promises(new Error(`Timeout in waiting for data on socket ( timeout was = ${this.timeout} ms)`));
|
|
271
|
+
}, this.timeout);
|
|
272
|
+
// also monitored
|
|
273
|
+
if (this._socket) {
|
|
274
|
+
// to do = intercept socket error as well
|
|
275
|
+
this._on_error_during_one_time_message_receiver = (err) => {
|
|
276
|
+
this._fulfill_pending_promises(new Error(`ERROR in waiting for data on socket ( timeout was = ${this.timeout} ms) ` + (err === null || err === void 0 ? void 0 : err.message)));
|
|
277
|
+
};
|
|
278
|
+
this._socket.on("close", this._on_error_during_one_time_message_receiver);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
on_socket_closed(err) {
|
|
282
|
+
if (this._onSocketClosedHasBeenCalled) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
(0, node_opcua_assert_1.assert)(!this._onSocketClosedHasBeenCalled);
|
|
286
|
+
this._onSocketClosedHasBeenCalled = true; // we don't want to send close event twice ...
|
|
287
|
+
/**
|
|
288
|
+
* notify the observers that the transport layer has been disconnected.
|
|
289
|
+
* @event socket_closed
|
|
290
|
+
* @param err the Error object or null
|
|
291
|
+
*/
|
|
292
|
+
this.emit("socket_closed", err || null);
|
|
293
|
+
}
|
|
294
|
+
_on_socket_data(data) {
|
|
295
|
+
if (!this.packetAssembler) {
|
|
296
|
+
throw new Error("internal Error");
|
|
297
|
+
}
|
|
298
|
+
this.bytesRead += data.length;
|
|
299
|
+
if (data.length > 0) {
|
|
300
|
+
this.packetAssembler.feed(data);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
_on_socket_close(hadError) {
|
|
304
|
+
// istanbul ignore next
|
|
305
|
+
if (doDebug) {
|
|
306
|
+
debugLog(chalk.red(" SOCKET CLOSE : "), chalk.yellow("had_error ="), chalk.cyan(hadError.toString()), this.name);
|
|
307
|
+
}
|
|
308
|
+
if (this._socket) {
|
|
309
|
+
debugLog(" remote address = ", this._socket.remoteAddress, " ", this._socket.remoteFamily, " ", this._socket.remotePort);
|
|
310
|
+
}
|
|
311
|
+
if (hadError) {
|
|
312
|
+
if (this._socket) {
|
|
313
|
+
this._socket.destroy();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const err = hadError ? new Error("ERROR IN SOCKET " + hadError.toString()) : undefined;
|
|
317
|
+
this.on_socket_closed(err);
|
|
318
|
+
this.dispose();
|
|
319
|
+
}
|
|
320
|
+
_on_socket_ended_message(err) {
|
|
321
|
+
if (this._disconnecting) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
debugLog(chalk.red("Transport Connection ended") + " " + this.name);
|
|
325
|
+
(0, node_opcua_assert_1.assert)(!this._disconnecting);
|
|
326
|
+
err = err || new Error("_socket has been disconnected by third party");
|
|
327
|
+
this.on_socket_ended(err);
|
|
328
|
+
this._disconnecting = true;
|
|
329
|
+
debugLog(" bytesRead = ", this.bytesRead);
|
|
330
|
+
debugLog(" bytesWritten = ", this.bytesWritten);
|
|
331
|
+
this._fulfill_pending_promises(new Error("Connection aborted - ended by server : " + (err ? err.message : "")));
|
|
332
|
+
}
|
|
333
|
+
_on_socket_end(err) {
|
|
334
|
+
// istanbul ignore next
|
|
335
|
+
if (doDebug) {
|
|
336
|
+
debugLog(chalk.red(" SOCKET END : err="), chalk.yellow(err ? err.message : "null"), this.name);
|
|
337
|
+
}
|
|
338
|
+
this._on_socket_ended_message(err);
|
|
339
|
+
}
|
|
340
|
+
_on_socket_error(err) {
|
|
341
|
+
// istanbul ignore next
|
|
342
|
+
if (doDebug) {
|
|
343
|
+
debugLog(chalk.red(" SOCKET ERROR : "), chalk.yellow(err.message), this.name);
|
|
344
|
+
}
|
|
345
|
+
// node The "close" event will be called directly following this event.
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.TCP_transport = TCP_transport;
|
|
349
|
+
TCP_transport.registry = new node_opcua_object_registry_1.ObjectRegistry();
|
|
350
|
+
//# sourceMappingURL=tcp_transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tcp_transport.js","s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K,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;SAClG;QACD,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IAEO,gBAAgB,CAAC,GAAU;QAC/B,uBAAuB;QACvB,IAAI,OAAO,EAAE;YACT,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;SACjF;QACD,uEAAuE;IAC3E,CAAC;;AAnZL,sCAoZC;AAnZkB,sBAAQ,GAAG,IAAI,2CAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-transport
|
|
4
|
+
*/
|
|
5
|
+
import * as url from "url";
|
|
6
|
+
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
|
|
7
|
+
import { BaseUAObject } from "node-opcua-factory";
|
|
8
|
+
export declare type ConstructorFunc = new (...args: any[]) => BaseUAObject;
|
|
9
|
+
export declare function decodeMessage(stream: BinaryStream, classNameConstructor: ConstructorFunc): BaseUAObject;
|
|
10
|
+
export declare function packTcpMessage(msgType: string, encodableObject: BaseUAObject): Buffer;
|
|
11
|
+
export declare function parseEndpointUrl(endpointUrl: string): url.Url;
|
|
12
|
+
export declare function is_valid_endpointUrl(endpointUrl: string): boolean;
|
|
13
|
+
export declare function writeTCPMessageHeader(msgType: string, chunkType: string, totalLength: number, stream: OutputBinaryStream): void;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeTCPMessageHeader = exports.is_valid_endpointUrl = exports.parseEndpointUrl = exports.packTcpMessage = exports.decodeMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-transport
|
|
6
|
+
*/
|
|
7
|
+
const url = require("url");
|
|
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 TCPErrorMessage_1 = require("./TCPErrorMessage");
|
|
13
|
+
function is_valid_msg_type(msgType) {
|
|
14
|
+
(0, node_opcua_assert_1.assert)(["HEL", "ACK", "ERR",
|
|
15
|
+
"OPN", "MSG", "CLO" // OPC Unified Architecture, Part 6 page 36
|
|
16
|
+
].indexOf(msgType) >= 0, "invalid message type " + msgType);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function decodeMessage(stream, classNameConstructor) {
|
|
20
|
+
(0, node_opcua_assert_1.assert)(stream instanceof node_opcua_binary_stream_1.BinaryStream);
|
|
21
|
+
(0, node_opcua_assert_1.assert)(classNameConstructor instanceof Function, " expecting a function for " + classNameConstructor);
|
|
22
|
+
const header = (0, node_opcua_chunkmanager_1.readMessageHeader)(stream);
|
|
23
|
+
(0, node_opcua_assert_1.assert)(stream.length === 8);
|
|
24
|
+
let obj;
|
|
25
|
+
if (header.msgType === "ERR") {
|
|
26
|
+
obj = new TCPErrorMessage_1.TCPErrorMessage();
|
|
27
|
+
obj.decode(stream);
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
obj = new classNameConstructor();
|
|
32
|
+
obj.decode(stream);
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.decodeMessage = decodeMessage;
|
|
37
|
+
function packTcpMessage(msgType, encodableObject) {
|
|
38
|
+
(0, node_opcua_assert_1.assert)(is_valid_msg_type(msgType));
|
|
39
|
+
const messageChunk = (0, node_opcua_buffer_utils_1.createFastUninitializedBuffer)(encodableObject.binaryStoreSize() + 8);
|
|
40
|
+
// encode encodeableObject in a packet
|
|
41
|
+
const stream = new node_opcua_binary_stream_1.BinaryStream(messageChunk);
|
|
42
|
+
encodeMessage(msgType, encodableObject, stream);
|
|
43
|
+
return messageChunk;
|
|
44
|
+
}
|
|
45
|
+
exports.packTcpMessage = packTcpMessage;
|
|
46
|
+
// opc.tcp://xleuri11022:51210/UA/SampleServer
|
|
47
|
+
function parseEndpointUrl(endpointUrl) {
|
|
48
|
+
const _url = url.parse(endpointUrl);
|
|
49
|
+
if (!_url.protocol || !_url.hostname) {
|
|
50
|
+
throw new Error("Invalid endpoint url " + endpointUrl);
|
|
51
|
+
}
|
|
52
|
+
return _url;
|
|
53
|
+
/*
|
|
54
|
+
const r = /^([a-z.]*):\/\/([a-zA-Z_\-.\-0-9]*):([0-9]*)(\/.*){0,1}/;
|
|
55
|
+
|
|
56
|
+
const matches = r.exec(endpointUrl);
|
|
57
|
+
|
|
58
|
+
if (!matches) {
|
|
59
|
+
throw new Error("Invalid endpoint url " + endpointUrl);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
protocol: matches[1],
|
|
63
|
+
|
|
64
|
+
hostname: matches[2],
|
|
65
|
+
|
|
66
|
+
port: parseInt(matches[3], 10),
|
|
67
|
+
|
|
68
|
+
address: matches[4] || ""
|
|
69
|
+
};
|
|
70
|
+
*/
|
|
71
|
+
}
|
|
72
|
+
exports.parseEndpointUrl = parseEndpointUrl;
|
|
73
|
+
function is_valid_endpointUrl(endpointUrl) {
|
|
74
|
+
const e = parseEndpointUrl(endpointUrl);
|
|
75
|
+
return e.hasOwnProperty("hostname");
|
|
76
|
+
}
|
|
77
|
+
exports.is_valid_endpointUrl = is_valid_endpointUrl;
|
|
78
|
+
function writeTCPMessageHeader(msgType, chunkType, totalLength, stream) {
|
|
79
|
+
if (stream instanceof Buffer) {
|
|
80
|
+
stream = new node_opcua_binary_stream_1.BinaryStream(stream);
|
|
81
|
+
}
|
|
82
|
+
(0, node_opcua_assert_1.assert)(is_valid_msg_type(msgType));
|
|
83
|
+
(0, node_opcua_assert_1.assert)(["A", "F", "C"].indexOf(chunkType) !== -1);
|
|
84
|
+
stream.writeUInt8(msgType.charCodeAt(0));
|
|
85
|
+
stream.writeUInt8(msgType.charCodeAt(1));
|
|
86
|
+
stream.writeUInt8(msgType.charCodeAt(2));
|
|
87
|
+
// Chunk type
|
|
88
|
+
stream.writeUInt8(chunkType.charCodeAt(0)); // reserved
|
|
89
|
+
stream.writeUInt32(totalLength);
|
|
90
|
+
}
|
|
91
|
+
exports.writeTCPMessageHeader = writeTCPMessageHeader;
|
|
92
|
+
function encodeMessage(msgType, messageContent, stream) {
|
|
93
|
+
// the length of the message, in bytes. (includes the 8 bytes of the message header)
|
|
94
|
+
const totalLength = messageContent.binaryStoreSize() + 8;
|
|
95
|
+
writeTCPMessageHeader(msgType, "F", totalLength, stream);
|
|
96
|
+
messageContent.encode(stream);
|
|
97
|
+
(0, node_opcua_assert_1.assert)(totalLength === stream.length, "invalid message size");
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../source/tools.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2BAA2B;AAE3B,yDAA2C;AAC3C,uEAA4E;AAC5E,qEAAwE;AACxE,qEAA4D;AAE5D,uDAAoD;AAGpD,SAAS,iBAAiB,CAAC,OAAe;IACtC,IAAA,0BAAM,EAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK;QACvB,KAAK,EAAE,KAAK,EAAE,KAAK,CAAI,2CAA2C;KACrE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC;AAChB,CAAC;AAID,SAAgB,aAA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IAEzD,qBAAqB,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACzD,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAA,0BAAM,EAAC,WAAW,KAAK,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.doTraceChunk = exports.doTraceHelloAck = void 0;
|
|
5
|
+
//
|
|
6
|
+
const transportFlag = (((_b = (_a = process.env) === null || _a === void 0 ? void 0 : _a.NODEOPCUADEBUG) === null || _b === void 0 ? void 0 : _b.match(/TRANSPORT{([^}]*)}/)) || [])[1] || "";
|
|
7
|
+
exports.doTraceHelloAck = transportFlag.match(/HELACK/);
|
|
8
|
+
exports.doTraceChunk = transportFlag.match(/CHUNK/);
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../source/utils.ts"],"names":[],"mappings":";;;;AAAA,GAAG;AACH,MAAM,aAAa,GAAG,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,GAAG,0CAAE,cAAc,0CAAE,KAAK,CAAC,oBAAoB,CAAC,KAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACnF,QAAA,eAAe,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAChD,QAAA,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const helloMessage1: Buffer;
|
|
3
|
+
export declare const altered_helloMessage1: Buffer;
|
|
4
|
+
export declare const altered_helloMessage2: Buffer;
|
|
5
|
+
export declare const altered_helloMessage3: Buffer;
|
|
6
|
+
export declare const ackResponse1: Buffer;
|
|
7
|
+
export declare const openChannelRequest1: Buffer;
|
|
8
|
+
export declare const altered_openChannelRequest1: Buffer;
|
|
9
|
+
export declare const altered_openChannelRequest2: Buffer;
|
|
10
|
+
export declare const openSecureChannelResponse1: Buffer;
|
|
11
|
+
export declare const getEndpointsRequest1: Buffer;
|
|
12
|
+
export declare const altered_getEndpointsRequest1: Buffer;
|
|
13
|
+
export declare const getEndpointsRequest2_chunk1: Buffer;
|
|
14
|
+
export declare const getEndpointsRequest2_chunk2: Buffer;
|
|
15
|
+
export declare const closeSecureChannelRequest1: Buffer;
|
|
16
|
+
export declare const closeSecureChannelResponse: Buffer;
|
|
17
|
+
export declare const packet_cs_6: Buffer;
|
|
18
|
+
export declare const activateSesionRequest: Buffer;
|
|
19
|
+
export declare const activateSesionResponse: Buffer;
|
|
20
|
+
export declare const packect_outtec: Buffer;
|
|
21
|
+
export declare const random_packet: Buffer;
|