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,45 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Socket } from "net";
|
|
3
|
+
import { StatusCode } from "node-opcua-status-code";
|
|
4
|
+
import { ErrorCallback } from "node-opcua-status-code";
|
|
5
|
+
import { TCP_transport } from "./tcp_transport";
|
|
6
|
+
/**
|
|
7
|
+
* @class ServerTCP_transport
|
|
8
|
+
* @extends TCP_transport
|
|
9
|
+
* @constructor
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare class ServerTCP_transport extends TCP_transport {
|
|
13
|
+
static throttleTime: number;
|
|
14
|
+
receiveBufferSize: number;
|
|
15
|
+
sendBufferSize: number;
|
|
16
|
+
maxMessageSize: number;
|
|
17
|
+
maxChunkCount: number;
|
|
18
|
+
protocolVersion: number;
|
|
19
|
+
private _aborted;
|
|
20
|
+
private _helloReceived;
|
|
21
|
+
constructor();
|
|
22
|
+
protected _write_chunk(messageChunk: Buffer): void;
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the server transport.
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* The ServerTCP_transport initialization process starts by waiting for the client to send a "HEL" message.
|
|
28
|
+
*
|
|
29
|
+
* The ServerTCP_transport replies with a "ACK" message and then start waiting for further messages of any size.
|
|
30
|
+
*
|
|
31
|
+
* The callback function received an error:
|
|
32
|
+
* - if no message from the client is received within the ```self.timeout``` period,
|
|
33
|
+
* - or, if the connection has dropped within the same interval.
|
|
34
|
+
* - if the protocol version specified within the HEL message is invalid or is greater
|
|
35
|
+
* than ```self.protocolVersion```
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
init(socket: Socket, callback: ErrorCallback): void;
|
|
40
|
+
abortWithError(statusCode: StatusCode, extraErrorDescription: string, callback: ErrorCallback): void;
|
|
41
|
+
private _abortWithError;
|
|
42
|
+
private _send_ACK_response;
|
|
43
|
+
private _install_HEL_message_receiver;
|
|
44
|
+
private _on_HEL_message;
|
|
45
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerTCP_transport = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-transport
|
|
6
|
+
*/
|
|
7
|
+
// tslint:disable:class-name
|
|
8
|
+
// system
|
|
9
|
+
const chalk = require("chalk");
|
|
10
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
11
|
+
// opcua requires
|
|
12
|
+
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
|
|
13
|
+
const node_opcua_chunkmanager_1 = require("node-opcua-chunkmanager");
|
|
14
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
15
|
+
// this package requires
|
|
16
|
+
const AcknowledgeMessage_1 = require("./AcknowledgeMessage");
|
|
17
|
+
const HelloMessage_1 = require("./HelloMessage");
|
|
18
|
+
const tcp_transport_1 = require("./tcp_transport");
|
|
19
|
+
const TCPErrorMessage_1 = require("./TCPErrorMessage");
|
|
20
|
+
const tools_1 = require("./tools");
|
|
21
|
+
const debug = require("node-opcua-debug");
|
|
22
|
+
const utils_1 = require("./utils");
|
|
23
|
+
const hexDump = debug.hexDump;
|
|
24
|
+
const debugLog = debug.make_debugLog(__filename);
|
|
25
|
+
const errorLog = debug.make_errorLog(__filename);
|
|
26
|
+
const doDebug = debug.checkDebugFlag(__filename);
|
|
27
|
+
function clamp_value(value, minVal, maxVal) {
|
|
28
|
+
(0, node_opcua_assert_1.assert)(minVal < maxVal);
|
|
29
|
+
if (value === 0) {
|
|
30
|
+
return maxVal;
|
|
31
|
+
}
|
|
32
|
+
if (value < minVal) {
|
|
33
|
+
return minVal;
|
|
34
|
+
}
|
|
35
|
+
/* istanbul ignore next*/
|
|
36
|
+
if (value >= maxVal) {
|
|
37
|
+
return maxVal;
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
const minimumBufferSize = 8192;
|
|
42
|
+
/**
|
|
43
|
+
* @class ServerTCP_transport
|
|
44
|
+
* @extends TCP_transport
|
|
45
|
+
* @constructor
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
class ServerTCP_transport extends tcp_transport_1.TCP_transport {
|
|
49
|
+
constructor() {
|
|
50
|
+
super();
|
|
51
|
+
this._aborted = 0;
|
|
52
|
+
this._helloReceived = false;
|
|
53
|
+
this.receiveBufferSize = 0;
|
|
54
|
+
this.sendBufferSize = 0;
|
|
55
|
+
this.maxMessageSize = 0;
|
|
56
|
+
this.maxChunkCount = 0;
|
|
57
|
+
this.protocolVersion = 0;
|
|
58
|
+
}
|
|
59
|
+
_write_chunk(messageChunk) {
|
|
60
|
+
if (this.sendBufferSize > 0 && messageChunk.length > this.sendBufferSize) {
|
|
61
|
+
errorLog("write chunk exceed sendBufferSize messageChunk length = ", messageChunk.length, "sendBufferSize = ", this.sendBufferSize);
|
|
62
|
+
}
|
|
63
|
+
super._write_chunk(messageChunk);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Initialize the server transport.
|
|
67
|
+
*
|
|
68
|
+
*
|
|
69
|
+
* The ServerTCP_transport initialization process starts by waiting for the client to send a "HEL" message.
|
|
70
|
+
*
|
|
71
|
+
* The ServerTCP_transport replies with a "ACK" message and then start waiting for further messages of any size.
|
|
72
|
+
*
|
|
73
|
+
* The callback function received an error:
|
|
74
|
+
* - if no message from the client is received within the ```self.timeout``` period,
|
|
75
|
+
* - or, if the connection has dropped within the same interval.
|
|
76
|
+
* - if the protocol version specified within the HEL message is invalid or is greater
|
|
77
|
+
* than ```self.protocolVersion```
|
|
78
|
+
*
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
init(socket, callback) {
|
|
82
|
+
if (debugLog) {
|
|
83
|
+
debugLog(chalk.cyan("init socket"));
|
|
84
|
+
}
|
|
85
|
+
(0, node_opcua_assert_1.assert)(!this._socket, "init already called!");
|
|
86
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a valid callback ");
|
|
87
|
+
this._install_socket(socket);
|
|
88
|
+
this._install_HEL_message_receiver(callback);
|
|
89
|
+
}
|
|
90
|
+
abortWithError(statusCode, extraErrorDescription, callback) {
|
|
91
|
+
return this._abortWithError(statusCode, extraErrorDescription, callback);
|
|
92
|
+
}
|
|
93
|
+
_abortWithError(statusCode, extraErrorDescription, callback) {
|
|
94
|
+
if (debugLog) {
|
|
95
|
+
debugLog(chalk.cyan("_abortWithError"));
|
|
96
|
+
}
|
|
97
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a callback");
|
|
98
|
+
/* istanbul ignore else */
|
|
99
|
+
if (!this._aborted) {
|
|
100
|
+
this._aborted = 1;
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
// send the error message and close the connection
|
|
103
|
+
(0, node_opcua_assert_1.assert)(node_opcua_status_code_1.StatusCodes.hasOwnProperty(statusCode.name));
|
|
104
|
+
/* istanbul ignore next*/
|
|
105
|
+
if (doDebug) {
|
|
106
|
+
debugLog(chalk.red(" Server aborting because ") + chalk.cyan(statusCode.name));
|
|
107
|
+
debugLog(chalk.red(" extraErrorDescription ") + chalk.cyan(extraErrorDescription));
|
|
108
|
+
}
|
|
109
|
+
const errorResponse = new TCPErrorMessage_1.TCPErrorMessage({
|
|
110
|
+
reason: statusCode.description,
|
|
111
|
+
statusCode
|
|
112
|
+
});
|
|
113
|
+
const messageChunk = (0, tools_1.packTcpMessage)("ERR", errorResponse);
|
|
114
|
+
this.write(messageChunk);
|
|
115
|
+
this.disconnect(() => {
|
|
116
|
+
this._aborted = 2;
|
|
117
|
+
callback(new Error(extraErrorDescription + " StatusCode = " + statusCode.name));
|
|
118
|
+
});
|
|
119
|
+
}, ServerTCP_transport.throttleTime);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
callback(new Error(statusCode.name));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_send_ACK_response(helloMessage) {
|
|
126
|
+
(0, node_opcua_assert_1.assert)(helloMessage.receiveBufferSize >= minimumBufferSize);
|
|
127
|
+
(0, node_opcua_assert_1.assert)(helloMessage.sendBufferSize >= minimumBufferSize);
|
|
128
|
+
this.receiveBufferSize = clamp_value(helloMessage.receiveBufferSize, 8192, 512 * 1024);
|
|
129
|
+
this.sendBufferSize = clamp_value(helloMessage.sendBufferSize, 8192, 512 * 1024);
|
|
130
|
+
this.maxMessageSize = clamp_value(helloMessage.maxMessageSize, 100000, 64 * 1024 * 1024);
|
|
131
|
+
this.maxChunkCount = clamp_value(helloMessage.maxChunkCount, 0, 65535);
|
|
132
|
+
// istanbul ignore next
|
|
133
|
+
if (utils_1.doTraceHelloAck) {
|
|
134
|
+
console.log(`received Hello \n${helloMessage.toString()}`);
|
|
135
|
+
}
|
|
136
|
+
debugLog("Client accepts only message of size => ", this.maxMessageSize);
|
|
137
|
+
const acknowledgeMessage = new AcknowledgeMessage_1.AcknowledgeMessage({
|
|
138
|
+
maxChunkCount: this.maxChunkCount,
|
|
139
|
+
maxMessageSize: this.maxMessageSize,
|
|
140
|
+
protocolVersion: this.protocolVersion,
|
|
141
|
+
receiveBufferSize: this.receiveBufferSize,
|
|
142
|
+
sendBufferSize: this.sendBufferSize
|
|
143
|
+
});
|
|
144
|
+
// istanbul ignore next
|
|
145
|
+
if (utils_1.doTraceHelloAck) {
|
|
146
|
+
console.log(`sending Ack \n${acknowledgeMessage.toString()}`);
|
|
147
|
+
}
|
|
148
|
+
const messageChunk = (0, tools_1.packTcpMessage)("ACK", acknowledgeMessage);
|
|
149
|
+
/* istanbul ignore next*/
|
|
150
|
+
if (doDebug) {
|
|
151
|
+
(0, node_opcua_chunkmanager_1.verify_message_chunk)(messageChunk);
|
|
152
|
+
debugLog("server send: " + chalk.yellow("ACK"));
|
|
153
|
+
debugLog("server send: " + hexDump(messageChunk));
|
|
154
|
+
debugLog("acknowledgeMessage=", acknowledgeMessage);
|
|
155
|
+
}
|
|
156
|
+
// send the ACK reply
|
|
157
|
+
this.write(messageChunk);
|
|
158
|
+
}
|
|
159
|
+
_install_HEL_message_receiver(callback) {
|
|
160
|
+
if (debugLog) {
|
|
161
|
+
debugLog(chalk.cyan("_install_HEL_message_receiver "));
|
|
162
|
+
}
|
|
163
|
+
this._install_one_time_message_receiver((err, data) => {
|
|
164
|
+
if (err) {
|
|
165
|
+
this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err.message, callback);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// handle the HEL message
|
|
169
|
+
this._on_HEL_message(data, callback);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
_on_HEL_message(data, callback) {
|
|
174
|
+
if (debugLog) {
|
|
175
|
+
debugLog(chalk.cyan("_on_HEL_message"));
|
|
176
|
+
}
|
|
177
|
+
(0, node_opcua_assert_1.assert)(!this._helloReceived);
|
|
178
|
+
const stream = new node_opcua_binary_stream_1.BinaryStream(data);
|
|
179
|
+
const msgType = data.slice(0, 3).toString("ascii");
|
|
180
|
+
/* istanbul ignore next*/
|
|
181
|
+
if (doDebug) {
|
|
182
|
+
debugLog("SERVER received " + chalk.yellow(msgType));
|
|
183
|
+
debugLog("SERVER received " + hexDump(data));
|
|
184
|
+
}
|
|
185
|
+
if (msgType === "HEL") {
|
|
186
|
+
try {
|
|
187
|
+
(0, node_opcua_assert_1.assert)(data.length >= 24);
|
|
188
|
+
const helloMessage = (0, tools_1.decodeMessage)(stream, HelloMessage_1.HelloMessage);
|
|
189
|
+
(0, node_opcua_assert_1.assert)(isFinite(this.protocolVersion));
|
|
190
|
+
// OPCUA Spec 1.03 part 6 - page 41
|
|
191
|
+
// The Server shall always accept versions greater than what it supports.
|
|
192
|
+
if (helloMessage.protocolVersion !== this.protocolVersion) {
|
|
193
|
+
debugLog(`warning ! client sent helloMessage.protocolVersion = ` +
|
|
194
|
+
` 0x${helloMessage.protocolVersion.toString(16)} ` +
|
|
195
|
+
`whereas server protocolVersion is 0x${this.protocolVersion.toString(16)}`);
|
|
196
|
+
}
|
|
197
|
+
if (helloMessage.protocolVersion === 0xdeadbeef || helloMessage.protocolVersion < this.protocolVersion) {
|
|
198
|
+
// Note: 0xDEADBEEF is our special version number to simulate BadProtocolVersionUnsupported in tests
|
|
199
|
+
// invalid protocol version requested by client
|
|
200
|
+
return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadProtocolVersionUnsupported, "Protocol Version Error" + this.protocolVersion, callback);
|
|
201
|
+
}
|
|
202
|
+
// OPCUA Spec 1.04 part 6 - page 45
|
|
203
|
+
// UASC is designed to operate with different TransportProtocols that may have limited buffer
|
|
204
|
+
// sizes. For this reason, OPC UA Secure Conversation will break OPC UA Messages into several
|
|
205
|
+
// pieces (called ‘MessageChunks’) that are smaller than the buffer size allowed by the
|
|
206
|
+
// TransportProtocol. UASC requires a TransportProtocol buffer size that is at least 8 192 bytes
|
|
207
|
+
if (helloMessage.receiveBufferSize < minimumBufferSize || helloMessage.sendBufferSize < minimumBufferSize) {
|
|
208
|
+
return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, "Buffer size too small (should be at least " + minimumBufferSize, callback);
|
|
209
|
+
}
|
|
210
|
+
// the helloMessage shall only be received once.
|
|
211
|
+
this._helloReceived = true;
|
|
212
|
+
this._send_ACK_response(helloMessage);
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
// connection rejected because of malformed message
|
|
216
|
+
return this._abortWithError(node_opcua_status_code_1.StatusCodes.BadConnectionRejected, err instanceof Error ? err.message : "", callback);
|
|
217
|
+
}
|
|
218
|
+
callback(); // no Error
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// invalid packet , expecting HEL
|
|
222
|
+
/* istanbul ignore next*/
|
|
223
|
+
if (doDebug) {
|
|
224
|
+
debugLog(chalk.red("BadCommunicationError ") + "Expecting 'HEL' message to initiate communication");
|
|
225
|
+
}
|
|
226
|
+
this._abortWithError(node_opcua_status_code_1.StatusCodes.BadCommunicationError, "Expecting 'HEL' message to initiate communication", callback);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.ServerTCP_transport = ServerTCP_transport;
|
|
231
|
+
ServerTCP_transport.throttleTime = 1000;
|
|
232
|
+
//# sourceMappingURL=server_tcp_transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server_tcp_transport.js","sourceRoot":"","sources":["../../source/server_tcp_transport.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,4BAA4B;AAC5B,SAAS;AACT,+BAA+B;AAE/B,yDAA2C;AAE3C,iBAAiB;AACjB,uE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Y,KAAK,CAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAA,CAAC,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;aACrH;YACD,QAAQ,EAAE,CAAC,CAAC,WAAW;SAC1B;aAAM;YACH,iCAAiC;YACjC,yBAAyB;YACzB,IAAI,OAAO,EAAE;gBACT,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,GAAG,mDAAmD,CAAC,CAAC;aACvG;YACD,IAAI,CAAC,eAAe,CAAC,oCAAW,CAAC,qBAAqB,EAAE,mDAAmD,EAAE,QAAQ,CAAC,CAAC;SAC1H;IACL,CAAC;;AAnOL,kDAoOC;AAnOiB,gCAAY,GAAW,IAAI,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { Socket } from "net";
|
|
4
|
+
import { ErrorCallback, CallbackWithData } from "node-opcua-status-code";
|
|
5
|
+
export declare function setFakeTransport(mockSocket: any): void;
|
|
6
|
+
export declare function getFakeTransport(): any;
|
|
7
|
+
export interface TCP_transport {
|
|
8
|
+
on(eventName: "message", eventHandler: (message: Buffer) => void): this;
|
|
9
|
+
once(eventName: "message", eventHandler: (message: Buffer) => void): this;
|
|
10
|
+
on(eventName: "socket_closed", eventHandler: (err: Error | null) => void): this;
|
|
11
|
+
once(eventName: "socket_closed", eventHandler: (err: Error | null) => void): this;
|
|
12
|
+
on(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
13
|
+
once(eventName: "close", eventHandler: (err: Error | null) => void): this;
|
|
14
|
+
}
|
|
15
|
+
export declare class TCP_transport extends EventEmitter {
|
|
16
|
+
private static registry;
|
|
17
|
+
/**
|
|
18
|
+
* indicates the version number of the OPCUA protocol used
|
|
19
|
+
* @default 0
|
|
20
|
+
*/
|
|
21
|
+
protocolVersion: number;
|
|
22
|
+
bytesWritten: number;
|
|
23
|
+
bytesRead: number;
|
|
24
|
+
chunkWrittenCount: number;
|
|
25
|
+
chunkReadCount: number;
|
|
26
|
+
name: string;
|
|
27
|
+
_socket: Socket | null;
|
|
28
|
+
/**
|
|
29
|
+
* the size of the header in bytes
|
|
30
|
+
* @default 8
|
|
31
|
+
*/
|
|
32
|
+
private readonly headerSize;
|
|
33
|
+
private _disconnecting;
|
|
34
|
+
private _timerId;
|
|
35
|
+
private _onSocketClosedHasBeenCalled;
|
|
36
|
+
private _onSocketEndedHasBeenCalled;
|
|
37
|
+
private _theCallback?;
|
|
38
|
+
private _on_error_during_one_time_message_receiver;
|
|
39
|
+
private _pendingBuffer?;
|
|
40
|
+
private packetAssembler?;
|
|
41
|
+
private _timeout;
|
|
42
|
+
constructor();
|
|
43
|
+
get timeout(): number;
|
|
44
|
+
set timeout(value: number);
|
|
45
|
+
dispose(): void;
|
|
46
|
+
/**
|
|
47
|
+
* ```createChunk``` is used to construct a pre-allocated chunk to store up to ```length``` bytes of data.
|
|
48
|
+
* The created chunk includes a prepended header for ```chunk_type``` of size ```self.headerSize```.
|
|
49
|
+
*
|
|
50
|
+
* @method createChunk
|
|
51
|
+
* @param msgType
|
|
52
|
+
* @param chunkType {String} chunk type. should be 'F' 'C' or 'A'
|
|
53
|
+
* @param length
|
|
54
|
+
* @return a buffer object with the required length representing the chunk.
|
|
55
|
+
*
|
|
56
|
+
* Note:
|
|
57
|
+
* - only one chunk can be created at a time.
|
|
58
|
+
* - a created chunk should be committed using the ```write``` method before an other one is created.
|
|
59
|
+
*/
|
|
60
|
+
createChunk(msgType: string, chunkType: string, length: number): Buffer;
|
|
61
|
+
/**
|
|
62
|
+
* write the message_chunk on the socket.
|
|
63
|
+
* @method write
|
|
64
|
+
* @param messageChunk
|
|
65
|
+
*
|
|
66
|
+
* Notes:
|
|
67
|
+
* - the message chunk must have been created by ```createChunk```.
|
|
68
|
+
* - once a message chunk has been written, it is possible to call ```createChunk``` again.
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
write(messageChunk: Buffer): void;
|
|
72
|
+
get isDisconnecting(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* disconnect the TCP layer and close the underlying socket.
|
|
75
|
+
* The ```"close"``` event will be emitted to the observers with err=null.
|
|
76
|
+
*
|
|
77
|
+
* @method disconnect
|
|
78
|
+
* @async
|
|
79
|
+
* @param callback
|
|
80
|
+
*/
|
|
81
|
+
disconnect(callback: ErrorCallback): void;
|
|
82
|
+
isValid(): boolean;
|
|
83
|
+
protected _write_chunk(messageChunk: Buffer): void;
|
|
84
|
+
protected on_socket_ended(err: Error | null): void;
|
|
85
|
+
/**
|
|
86
|
+
* @method _install_socket
|
|
87
|
+
* @param socket {Socket}
|
|
88
|
+
* @protected
|
|
89
|
+
*/
|
|
90
|
+
protected _install_socket(socket: Socket): void;
|
|
91
|
+
prematureTerminate(err: Error): void;
|
|
92
|
+
/**
|
|
93
|
+
* @method _install_one_time_message_receiver
|
|
94
|
+
*
|
|
95
|
+
* install a one time message receiver callback
|
|
96
|
+
*
|
|
97
|
+
* Rules:
|
|
98
|
+
* * TCP_transport will not emit the ```message``` event, while the "one time message receiver" is in operation.
|
|
99
|
+
* * the TCP_transport will wait for the next complete message chunk and call the provided callback func
|
|
100
|
+
* ```callback(null,messageChunk);```
|
|
101
|
+
*
|
|
102
|
+
* if a messageChunk is not received within ```TCP_transport.timeout``` or if the underlying socket reports
|
|
103
|
+
* an error, the callback function will be called with an Error.
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
protected _install_one_time_message_receiver(callback: CallbackWithData): void;
|
|
107
|
+
private _fulfill_pending_promises;
|
|
108
|
+
private _on_message_received;
|
|
109
|
+
private _cleanup_timers;
|
|
110
|
+
private _start_one_time_message_receiver;
|
|
111
|
+
private on_socket_closed;
|
|
112
|
+
private _on_socket_data;
|
|
113
|
+
private _on_socket_close;
|
|
114
|
+
private _on_socket_ended_message;
|
|
115
|
+
private _on_socket_end;
|
|
116
|
+
private _on_socket_error;
|
|
117
|
+
}
|