node-opcua-transport 2.64.1 → 2.65.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.
Files changed (35) hide show
  1. package/dist/source/AcknowledgeMessage.d.ts +27 -27
  2. package/dist/source/AcknowledgeMessage.js +78 -78
  3. package/dist/source/HelloMessage.d.ts +27 -27
  4. package/dist/source/HelloMessage.js +94 -94
  5. package/dist/source/TCPErrorMessage.d.ts +18 -18
  6. package/dist/source/TCPErrorMessage.js +46 -46
  7. package/dist/source/client_tcp_transport.d.ts +68 -68
  8. package/dist/source/client_tcp_transport.js +313 -313
  9. package/dist/source/index.d.ts +11 -11
  10. package/dist/source/index.js +23 -23
  11. package/dist/source/message_builder_base.d.ts +61 -61
  12. package/dist/source/message_builder_base.js +206 -206
  13. package/dist/source/server_tcp_transport.d.ts +48 -48
  14. package/dist/source/server_tcp_transport.js +226 -226
  15. package/dist/source/tcp_transport.d.ts +126 -126
  16. package/dist/source/tcp_transport.js +357 -357
  17. package/dist/source/tools.d.ts +13 -13
  18. package/dist/source/tools.js +103 -103
  19. package/dist/source/utils.d.ts +2 -2
  20. package/dist/source/utils.js +8 -8
  21. package/dist/test-fixtures/fixture_full_tcp_packets.d.ts +21 -21
  22. package/dist/test-fixtures/fixture_full_tcp_packets.js +41 -41
  23. package/dist/test-fixtures/index.d.ts +1 -1
  24. package/dist/test-fixtures/index.js +13 -13
  25. package/dist/test_helpers/direct_transport.d.ts +14 -14
  26. package/dist/test_helpers/direct_transport.js +62 -62
  27. package/dist/test_helpers/fake_server.d.ts +17 -17
  28. package/dist/test_helpers/fake_server.js +54 -54
  29. package/dist/test_helpers/half_com_channel.d.ts +10 -10
  30. package/dist/test_helpers/half_com_channel.js +31 -31
  31. package/dist/test_helpers/index.d.ts +4 -4
  32. package/dist/test_helpers/index.js +16 -16
  33. package/dist/test_helpers/socket_transport.d.ts +10 -10
  34. package/dist/test_helpers/socket_transport.js +30 -30
  35. package/package.json +4 -4
@@ -1,48 +1,48 @@
1
- /// <reference types="node" />
2
- /**
3
- * @module node-opcua-transport
4
- */
5
- import { Socket } from "net";
6
- import { StatusCode } from "node-opcua-status-code";
7
- import { ErrorCallback } from "node-opcua-status-code";
8
- import { TCP_transport } from "./tcp_transport";
9
- /**
10
- * @class ServerTCP_transport
11
- * @extends TCP_transport
12
- * @constructor
13
- *
14
- */
15
- export declare class ServerTCP_transport extends TCP_transport {
16
- static throttleTime: number;
17
- receiveBufferSize: number;
18
- sendBufferSize: number;
19
- maxMessageSize: number;
20
- maxChunkCount: number;
21
- protocolVersion: number;
22
- private _aborted;
23
- private _helloReceived;
24
- constructor();
25
- protected _write_chunk(messageChunk: Buffer): void;
26
- /**
27
- * Initialize the server transport.
28
- *
29
- *
30
- * The ServerTCP_transport initialization process starts by waiting for the client to send a "HEL" message.
31
- *
32
- * The ServerTCP_transport replies with a "ACK" message and then start waiting for further messages of any size.
33
- *
34
- * The callback function received an error:
35
- * - if no message from the client is received within the ```self.timeout``` period,
36
- * - or, if the connection has dropped within the same interval.
37
- * - if the protocol version specified within the HEL message is invalid or is greater
38
- * than ```self.protocolVersion```
39
- *
40
- *
41
- */
42
- init(socket: Socket, callback: ErrorCallback): void;
43
- abortWithError(statusCode: StatusCode, extraErrorDescription: string, callback: ErrorCallback): void;
44
- private _abortWithError;
45
- private _send_ACK_response;
46
- private _install_HEL_message_receiver;
47
- private _on_HEL_message;
48
- }
1
+ /// <reference types="node" />
2
+ /**
3
+ * @module node-opcua-transport
4
+ */
5
+ import { Socket } from "net";
6
+ import { StatusCode } from "node-opcua-status-code";
7
+ import { ErrorCallback } from "node-opcua-status-code";
8
+ import { TCP_transport } from "./tcp_transport";
9
+ /**
10
+ * @class ServerTCP_transport
11
+ * @extends TCP_transport
12
+ * @constructor
13
+ *
14
+ */
15
+ export declare class ServerTCP_transport extends TCP_transport {
16
+ static throttleTime: number;
17
+ receiveBufferSize: number;
18
+ sendBufferSize: number;
19
+ maxMessageSize: number;
20
+ maxChunkCount: number;
21
+ protocolVersion: number;
22
+ private _aborted;
23
+ private _helloReceived;
24
+ constructor();
25
+ protected _write_chunk(messageChunk: Buffer): void;
26
+ /**
27
+ * Initialize the server transport.
28
+ *
29
+ *
30
+ * The ServerTCP_transport initialization process starts by waiting for the client to send a "HEL" message.
31
+ *
32
+ * The ServerTCP_transport replies with a "ACK" message and then start waiting for further messages of any size.
33
+ *
34
+ * The callback function received an error:
35
+ * - if no message from the client is received within the ```self.timeout``` period,
36
+ * - or, if the connection has dropped within the same interval.
37
+ * - if the protocol version specified within the HEL message is invalid or is greater
38
+ * than ```self.protocolVersion```
39
+ *
40
+ *
41
+ */
42
+ init(socket: Socket, callback: ErrorCallback): void;
43
+ abortWithError(statusCode: StatusCode, extraErrorDescription: string, callback: ErrorCallback): void;
44
+ private _abortWithError;
45
+ private _send_ACK_response;
46
+ private _install_HEL_message_receiver;
47
+ private _on_HEL_message;
48
+ }
@@ -1,227 +1,227 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServerTCP_transport = void 0;
4
- const chalk = require("chalk");
5
- const node_opcua_assert_1 = require("node-opcua-assert");
6
- // opcua requires
7
- const debug = require("node-opcua-debug");
8
- const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
9
- const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
10
- const node_opcua_status_code_1 = require("node-opcua-status-code");
11
- // this package requires
12
- const AcknowledgeMessage_1 = require("./AcknowledgeMessage");
13
- const HelloMessage_1 = require("./HelloMessage");
14
- const tcp_transport_1 = require("./tcp_transport");
15
- const TCPErrorMessage_1 = require("./TCPErrorMessage");
16
- const tools_1 = require("./tools");
17
- const utils_1 = require("./utils");
18
- const hexDump = debug.hexDump;
19
- const debugLog = debug.make_debugLog(__filename);
20
- const errorLog = debug.make_errorLog(__filename);
21
- const doDebug = debug.checkDebugFlag(__filename);
22
- function clamp_value(value, minVal, maxVal) {
23
- (0, node_opcua_assert_1.assert)(minVal < maxVal);
24
- if (value === 0) {
25
- return maxVal;
26
- }
27
- if (value < minVal) {
28
- return minVal;
29
- }
30
- /* istanbul ignore next*/
31
- if (value >= maxVal) {
32
- return maxVal;
33
- }
34
- return value;
35
- }
36
- const minimumBufferSize = 8192;
37
- /**
38
- * @class ServerTCP_transport
39
- * @extends TCP_transport
40
- * @constructor
41
- *
42
- */
43
- class ServerTCP_transport extends tcp_transport_1.TCP_transport {
44
- constructor() {
45
- super();
46
- this._aborted = 0;
47
- this._helloReceived = false;
48
- this.receiveBufferSize = 0;
49
- this.sendBufferSize = 0;
50
- this.maxMessageSize = 0;
51
- this.maxChunkCount = 0;
52
- this.protocolVersion = 0;
53
- }
54
- _write_chunk(messageChunk) {
55
- if (this.sendBufferSize > 0 && messageChunk.length > this.sendBufferSize) {
56
- errorLog("write chunk exceed sendBufferSize messageChunk length = ", messageChunk.length, "sendBufferSize = ", this.sendBufferSize);
57
- }
58
- super._write_chunk(messageChunk);
59
- }
60
- /**
61
- * Initialize the server transport.
62
- *
63
- *
64
- * The ServerTCP_transport initialization process starts by waiting for the client to send a "HEL" message.
65
- *
66
- * The ServerTCP_transport replies with a "ACK" message and then start waiting for further messages of any size.
67
- *
68
- * The callback function received an error:
69
- * - if no message from the client is received within the ```self.timeout``` period,
70
- * - or, if the connection has dropped within the same interval.
71
- * - if the protocol version specified within the HEL message is invalid or is greater
72
- * than ```self.protocolVersion```
73
- *
74
- *
75
- */
76
- init(socket, callback) {
77
- if (debugLog) {
78
- debugLog(chalk.cyan("init socket"));
79
- }
80
- (0, node_opcua_assert_1.assert)(!this._socket, "init already called!");
81
- (0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a valid callback ");
82
- this._install_socket(socket);
83
- this._install_HEL_message_receiver(callback);
84
- }
85
- abortWithError(statusCode, extraErrorDescription, callback) {
86
- return this._abortWithError(statusCode, extraErrorDescription, callback);
87
- }
88
- _abortWithError(statusCode, extraErrorDescription, callback) {
89
- if (debugLog) {
90
- debugLog(chalk.cyan("_abortWithError"));
91
- }
92
- (0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a callback");
93
- /* istanbul ignore else */
94
- if (!this._aborted) {
95
- this._aborted = 1;
96
- setTimeout(() => {
97
- // send the error message and close the connection
98
- (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(node_opcua_status_code_1.StatusCodes, statusCode.name));
99
- /* istanbul ignore next*/
100
- if (doDebug) {
101
- debugLog(chalk.red(" Server aborting because ") + chalk.cyan(statusCode.name));
102
- debugLog(chalk.red(" extraErrorDescription ") + chalk.cyan(extraErrorDescription));
103
- }
104
- const errorResponse = new TCPErrorMessage_1.TCPErrorMessage({
105
- reason: statusCode.description,
106
- statusCode
107
- });
108
- const messageChunk = (0, tools_1.packTcpMessage)("ERR", errorResponse);
109
- this.write(messageChunk);
110
- this.disconnect(() => {
111
- this._aborted = 2;
112
- callback(new Error(extraErrorDescription + " StatusCode = " + statusCode.name));
113
- });
114
- }, ServerTCP_transport.throttleTime);
115
- }
116
- else {
117
- callback(new Error(statusCode.name));
118
- }
119
- }
120
- _send_ACK_response(helloMessage) {
121
- (0, node_opcua_assert_1.assert)(helloMessage.receiveBufferSize >= minimumBufferSize);
122
- (0, node_opcua_assert_1.assert)(helloMessage.sendBufferSize >= minimumBufferSize);
123
- this.receiveBufferSize = clamp_value(helloMessage.receiveBufferSize, 8192, 512 * 1024);
124
- this.sendBufferSize = clamp_value(helloMessage.sendBufferSize, 8192, 512 * 1024);
125
- this.maxMessageSize = clamp_value(helloMessage.maxMessageSize, 100000, 64 * 1024 * 1024);
126
- this.maxChunkCount = clamp_value(helloMessage.maxChunkCount, 0, 65535);
127
- // istanbul ignore next
128
- if (utils_1.doTraceHelloAck) {
129
- console.log(`received Hello \n${helloMessage.toString()}`);
130
- }
131
- debugLog("Client accepts only message of size => ", this.maxMessageSize);
132
- const acknowledgeMessage = new AcknowledgeMessage_1.AcknowledgeMessage({
133
- maxChunkCount: this.maxChunkCount,
134
- maxMessageSize: this.maxMessageSize,
135
- protocolVersion: this.protocolVersion,
136
- receiveBufferSize: this.receiveBufferSize,
137
- sendBufferSize: this.sendBufferSize
138
- });
139
- // istanbul ignore next
140
- if (utils_1.doTraceHelloAck) {
141
- console.log(`sending Ack \n${acknowledgeMessage.toString()}`);
142
- }
143
- const messageChunk = (0, tools_1.packTcpMessage)("ACK", acknowledgeMessage);
144
- /* istanbul ignore next*/
145
- if (doDebug) {
146
- (0, node_opcua_chunkmanager_1.verify_message_chunk)(messageChunk);
147
- debugLog("server send: " + chalk.yellow("ACK"));
148
- debugLog("server send: " + hexDump(messageChunk));
149
- debugLog("acknowledgeMessage=", acknowledgeMessage);
150
- }
151
- // send the ACK reply
152
- this.write(messageChunk);
153
- }
154
- _install_HEL_message_receiver(callback) {
155
- if (debugLog) {
156
- debugLog(chalk.cyan("_install_HEL_message_receiver "));
157
- }
158
- this._install_one_time_message_receiver((err, data) => {
159
- if (err) {
160
- this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err.message, callback);
161
- }
162
- else {
163
- // handle the HEL message
164
- this._on_HEL_message(data, callback);
165
- }
166
- });
167
- }
168
- _on_HEL_message(data, callback) {
169
- if (debugLog) {
170
- debugLog(chalk.cyan("_on_HEL_message"));
171
- }
172
- (0, node_opcua_assert_1.assert)(!this._helloReceived);
173
- const stream = new node_opcua_binary_stream_1.BinaryStream(data);
174
- const msgType = data.slice(0, 3).toString("ascii");
175
- /* istanbul ignore next*/
176
- if (doDebug) {
177
- debugLog("SERVER received " + chalk.yellow(msgType));
178
- debugLog("SERVER received " + hexDump(data));
179
- }
180
- if (msgType === "HEL") {
181
- try {
182
- (0, node_opcua_assert_1.assert)(data.length >= 24);
183
- const helloMessage = (0, tools_1.decodeMessage)(stream, HelloMessage_1.HelloMessage);
184
- (0, node_opcua_assert_1.assert)(isFinite(this.protocolVersion));
185
- // OPCUA Spec 1.03 part 6 - page 41
186
- // The Server shall always accept versions greater than what it supports.
187
- if (helloMessage.protocolVersion !== this.protocolVersion) {
188
- debugLog(`warning ! client sent helloMessage.protocolVersion = ` +
189
- ` 0x${helloMessage.protocolVersion.toString(16)} ` +
190
- `whereas server protocolVersion is 0x${this.protocolVersion.toString(16)}`);
191
- }
192
- if (helloMessage.protocolVersion === 0xdeadbeef || helloMessage.protocolVersion < this.protocolVersion) {
193
- // Note: 0xDEADBEEF is our special version number to simulate BadProtocolVersionUnsupported in tests
194
- // invalid protocol version requested by client
195
- return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadProtocolVersionUnsupported, "Protocol Version Error" + this.protocolVersion, callback);
196
- }
197
- // OPCUA Spec 1.04 part 6 - page 45
198
- // UASC is designed to operate with different TransportProtocols that may have limited buffer
199
- // sizes. For this reason, OPC UA Secure Conversation will break OPC UA Messages into several
200
- // pieces (called ‘MessageChunks’) that are smaller than the buffer size allowed by the
201
- // TransportProtocol. UASC requires a TransportProtocol buffer size that is at least 8 192 bytes
202
- if (helloMessage.receiveBufferSize < minimumBufferSize || helloMessage.sendBufferSize < minimumBufferSize) {
203
- return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, "Buffer size too small (should be at least " + minimumBufferSize, callback);
204
- }
205
- // the helloMessage shall only be received once.
206
- this._helloReceived = true;
207
- this._send_ACK_response(helloMessage);
208
- }
209
- catch (err) {
210
- // connection rejected because of malformed message
211
- return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err instanceof Error ? err.message : "", callback);
212
- }
213
- callback(); // no Error
214
- }
215
- else {
216
- // invalid packet , expecting HEL
217
- /* istanbul ignore next*/
218
- if (doDebug) {
219
- debugLog(chalk.red("BadCommunicationError ") + "Expecting 'HEL' message to initiate communication");
220
- }
221
- this._abortWithError(node_opcua_status_code_1.StatusCodes.BadCommunicationError, "Expecting 'HEL' message to initiate communication", callback);
222
- }
223
- }
224
- }
225
- exports.ServerTCP_transport = ServerTCP_transport;
226
- ServerTCP_transport.throttleTime = 1000;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerTCP_transport = void 0;
4
+ const chalk = require("chalk");
5
+ const node_opcua_assert_1 = require("node-opcua-assert");
6
+ // opcua requires
7
+ const debug = require("node-opcua-debug");
8
+ const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
9
+ const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
10
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
11
+ // this package requires
12
+ const AcknowledgeMessage_1 = require("./AcknowledgeMessage");
13
+ const HelloMessage_1 = require("./HelloMessage");
14
+ const tcp_transport_1 = require("./tcp_transport");
15
+ const TCPErrorMessage_1 = require("./TCPErrorMessage");
16
+ const tools_1 = require("./tools");
17
+ const utils_1 = require("./utils");
18
+ const hexDump = debug.hexDump;
19
+ const debugLog = debug.make_debugLog(__filename);
20
+ const errorLog = debug.make_errorLog(__filename);
21
+ const doDebug = debug.checkDebugFlag(__filename);
22
+ function clamp_value(value, minVal, maxVal) {
23
+ (0, node_opcua_assert_1.assert)(minVal < maxVal);
24
+ if (value === 0) {
25
+ return maxVal;
26
+ }
27
+ if (value < minVal) {
28
+ return minVal;
29
+ }
30
+ /* istanbul ignore next*/
31
+ if (value >= maxVal) {
32
+ return maxVal;
33
+ }
34
+ return value;
35
+ }
36
+ const minimumBufferSize = 8192;
37
+ /**
38
+ * @class ServerTCP_transport
39
+ * @extends TCP_transport
40
+ * @constructor
41
+ *
42
+ */
43
+ class ServerTCP_transport extends tcp_transport_1.TCP_transport {
44
+ constructor() {
45
+ super();
46
+ this._aborted = 0;
47
+ this._helloReceived = false;
48
+ this.receiveBufferSize = 0;
49
+ this.sendBufferSize = 0;
50
+ this.maxMessageSize = 0;
51
+ this.maxChunkCount = 0;
52
+ this.protocolVersion = 0;
53
+ }
54
+ _write_chunk(messageChunk) {
55
+ if (this.sendBufferSize > 0 && messageChunk.length > this.sendBufferSize) {
56
+ errorLog("write chunk exceed sendBufferSize messageChunk length = ", messageChunk.length, "sendBufferSize = ", this.sendBufferSize);
57
+ }
58
+ super._write_chunk(messageChunk);
59
+ }
60
+ /**
61
+ * Initialize the server transport.
62
+ *
63
+ *
64
+ * The ServerTCP_transport initialization process starts by waiting for the client to send a "HEL" message.
65
+ *
66
+ * The ServerTCP_transport replies with a "ACK" message and then start waiting for further messages of any size.
67
+ *
68
+ * The callback function received an error:
69
+ * - if no message from the client is received within the ```self.timeout``` period,
70
+ * - or, if the connection has dropped within the same interval.
71
+ * - if the protocol version specified within the HEL message is invalid or is greater
72
+ * than ```self.protocolVersion```
73
+ *
74
+ *
75
+ */
76
+ init(socket, callback) {
77
+ if (debugLog) {
78
+ debugLog(chalk.cyan("init socket"));
79
+ }
80
+ (0, node_opcua_assert_1.assert)(!this._socket, "init already called!");
81
+ (0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a valid callback ");
82
+ this._install_socket(socket);
83
+ this._install_HEL_message_receiver(callback);
84
+ }
85
+ abortWithError(statusCode, extraErrorDescription, callback) {
86
+ return this._abortWithError(statusCode, extraErrorDescription, callback);
87
+ }
88
+ _abortWithError(statusCode, extraErrorDescription, callback) {
89
+ if (debugLog) {
90
+ debugLog(chalk.cyan("_abortWithError"));
91
+ }
92
+ (0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a callback");
93
+ /* istanbul ignore else */
94
+ if (!this._aborted) {
95
+ this._aborted = 1;
96
+ setTimeout(() => {
97
+ // send the error message and close the connection
98
+ (0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(node_opcua_status_code_1.StatusCodes, statusCode.name));
99
+ /* istanbul ignore next*/
100
+ if (doDebug) {
101
+ debugLog(chalk.red(" Server aborting because ") + chalk.cyan(statusCode.name));
102
+ debugLog(chalk.red(" extraErrorDescription ") + chalk.cyan(extraErrorDescription));
103
+ }
104
+ const errorResponse = new TCPErrorMessage_1.TCPErrorMessage({
105
+ reason: statusCode.description,
106
+ statusCode
107
+ });
108
+ const messageChunk = (0, tools_1.packTcpMessage)("ERR", errorResponse);
109
+ this.write(messageChunk);
110
+ this.disconnect(() => {
111
+ this._aborted = 2;
112
+ callback(new Error(extraErrorDescription + " StatusCode = " + statusCode.name));
113
+ });
114
+ }, ServerTCP_transport.throttleTime);
115
+ }
116
+ else {
117
+ callback(new Error(statusCode.name));
118
+ }
119
+ }
120
+ _send_ACK_response(helloMessage) {
121
+ (0, node_opcua_assert_1.assert)(helloMessage.receiveBufferSize >= minimumBufferSize);
122
+ (0, node_opcua_assert_1.assert)(helloMessage.sendBufferSize >= minimumBufferSize);
123
+ this.receiveBufferSize = clamp_value(helloMessage.receiveBufferSize, 8192, 512 * 1024);
124
+ this.sendBufferSize = clamp_value(helloMessage.sendBufferSize, 8192, 512 * 1024);
125
+ this.maxMessageSize = clamp_value(helloMessage.maxMessageSize, 100000, 64 * 1024 * 1024);
126
+ this.maxChunkCount = clamp_value(helloMessage.maxChunkCount, 0, 65535);
127
+ // istanbul ignore next
128
+ if (utils_1.doTraceHelloAck) {
129
+ console.log(`received Hello \n${helloMessage.toString()}`);
130
+ }
131
+ debugLog("Client accepts only message of size => ", this.maxMessageSize);
132
+ const acknowledgeMessage = new AcknowledgeMessage_1.AcknowledgeMessage({
133
+ maxChunkCount: this.maxChunkCount,
134
+ maxMessageSize: this.maxMessageSize,
135
+ protocolVersion: this.protocolVersion,
136
+ receiveBufferSize: this.receiveBufferSize,
137
+ sendBufferSize: this.sendBufferSize
138
+ });
139
+ // istanbul ignore next
140
+ if (utils_1.doTraceHelloAck) {
141
+ console.log(`sending Ack \n${acknowledgeMessage.toString()}`);
142
+ }
143
+ const messageChunk = (0, tools_1.packTcpMessage)("ACK", acknowledgeMessage);
144
+ /* istanbul ignore next*/
145
+ if (doDebug) {
146
+ (0, node_opcua_chunkmanager_1.verify_message_chunk)(messageChunk);
147
+ debugLog("server send: " + chalk.yellow("ACK"));
148
+ debugLog("server send: " + hexDump(messageChunk));
149
+ debugLog("acknowledgeMessage=", acknowledgeMessage);
150
+ }
151
+ // send the ACK reply
152
+ this.write(messageChunk);
153
+ }
154
+ _install_HEL_message_receiver(callback) {
155
+ if (debugLog) {
156
+ debugLog(chalk.cyan("_install_HEL_message_receiver "));
157
+ }
158
+ this._install_one_time_message_receiver((err, data) => {
159
+ if (err) {
160
+ this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err.message, callback);
161
+ }
162
+ else {
163
+ // handle the HEL message
164
+ this._on_HEL_message(data, callback);
165
+ }
166
+ });
167
+ }
168
+ _on_HEL_message(data, callback) {
169
+ if (debugLog) {
170
+ debugLog(chalk.cyan("_on_HEL_message"));
171
+ }
172
+ (0, node_opcua_assert_1.assert)(!this._helloReceived);
173
+ const stream = new node_opcua_binary_stream_1.BinaryStream(data);
174
+ const msgType = data.slice(0, 3).toString("ascii");
175
+ /* istanbul ignore next*/
176
+ if (doDebug) {
177
+ debugLog("SERVER received " + chalk.yellow(msgType));
178
+ debugLog("SERVER received " + hexDump(data));
179
+ }
180
+ if (msgType === "HEL") {
181
+ try {
182
+ (0, node_opcua_assert_1.assert)(data.length >= 24);
183
+ const helloMessage = (0, tools_1.decodeMessage)(stream, HelloMessage_1.HelloMessage);
184
+ (0, node_opcua_assert_1.assert)(isFinite(this.protocolVersion));
185
+ // OPCUA Spec 1.03 part 6 - page 41
186
+ // The Server shall always accept versions greater than what it supports.
187
+ if (helloMessage.protocolVersion !== this.protocolVersion) {
188
+ debugLog(`warning ! client sent helloMessage.protocolVersion = ` +
189
+ ` 0x${helloMessage.protocolVersion.toString(16)} ` +
190
+ `whereas server protocolVersion is 0x${this.protocolVersion.toString(16)}`);
191
+ }
192
+ if (helloMessage.protocolVersion === 0xdeadbeef || helloMessage.protocolVersion < this.protocolVersion) {
193
+ // Note: 0xDEADBEEF is our special version number to simulate BadProtocolVersionUnsupported in tests
194
+ // invalid protocol version requested by client
195
+ return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadProtocolVersionUnsupported, "Protocol Version Error" + this.protocolVersion, callback);
196
+ }
197
+ // OPCUA Spec 1.04 part 6 - page 45
198
+ // UASC is designed to operate with different TransportProtocols that may have limited buffer
199
+ // sizes. For this reason, OPC UA Secure Conversation will break OPC UA Messages into several
200
+ // pieces (called ‘MessageChunks’) that are smaller than the buffer size allowed by the
201
+ // TransportProtocol. UASC requires a TransportProtocol buffer size that is at least 8 192 bytes
202
+ if (helloMessage.receiveBufferSize < minimumBufferSize || helloMessage.sendBufferSize < minimumBufferSize) {
203
+ return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, "Buffer size too small (should be at least " + minimumBufferSize, callback);
204
+ }
205
+ // the helloMessage shall only be received once.
206
+ this._helloReceived = true;
207
+ this._send_ACK_response(helloMessage);
208
+ }
209
+ catch (err) {
210
+ // connection rejected because of malformed message
211
+ return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err instanceof Error ? err.message : "", callback);
212
+ }
213
+ callback(); // no Error
214
+ }
215
+ else {
216
+ // invalid packet , expecting HEL
217
+ /* istanbul ignore next*/
218
+ if (doDebug) {
219
+ debugLog(chalk.red("BadCommunicationError ") + "Expecting 'HEL' message to initiate communication");
220
+ }
221
+ this._abortWithError(node_opcua_status_code_1.StatusCodes.BadCommunicationError, "Expecting 'HEL' message to initiate communication", callback);
222
+ }
223
+ }
224
+ }
225
+ exports.ServerTCP_transport = ServerTCP_transport;
226
+ ServerTCP_transport.throttleTime = 1000;
227
227
  //# sourceMappingURL=server_tcp_transport.js.map