node-opcua-client 2.178.0 → 2.179.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alarms_and_conditions/client_alarm_tools.js +7 -5
- package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
- package/dist/alarms_and_conditions/client_tools.js +38 -28
- package/dist/alarms_and_conditions/client_tools.js.map +1 -1
- package/dist/client_base.js.map +1 -1
- package/dist/client_monitored_item.d.ts +1 -1
- package/dist/client_monitored_item.js +4 -2
- package/dist/client_monitored_item.js.map +1 -1
- package/dist/client_monitored_item_group.d.ts +4 -3
- package/dist/client_monitored_item_group.js +8 -5
- package/dist/client_monitored_item_group.js.map +1 -1
- package/dist/client_monitored_item_toolbox.js +4 -2
- package/dist/client_monitored_item_toolbox.js.map +1 -1
- package/dist/client_session.d.ts +9 -2
- package/dist/client_session_keepalive_manager.d.ts +1 -1
- package/dist/client_session_keepalive_manager.js +50 -29
- package/dist/client_session_keepalive_manager.js.map +1 -1
- package/dist/client_subscription.d.ts +2 -2
- package/dist/client_subscription.js +3 -1
- package/dist/client_subscription.js.map +1 -1
- package/dist/common.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/opcua_client.js +1 -0
- package/dist/opcua_client.js.map +1 -1
- package/dist/private/client_base_impl.js +125 -65
- package/dist/private/client_base_impl.js.map +1 -1
- package/dist/private/client_monitored_item_group_impl.d.ts +1 -0
- package/dist/private/client_monitored_item_group_impl.js +6 -8
- package/dist/private/client_monitored_item_group_impl.js.map +1 -1
- package/dist/private/client_monitored_item_impl.js +0 -4
- package/dist/private/client_monitored_item_impl.js.map +1 -1
- package/dist/private/client_publish_engine.js +62 -28
- package/dist/private/client_publish_engine.js.map +1 -1
- package/dist/private/client_session_impl.d.ts +49 -17
- package/dist/private/client_session_impl.js +240 -143
- package/dist/private/client_session_impl.js.map +1 -1
- package/dist/private/client_subscription_impl.js +15 -12
- package/dist/private/client_subscription_impl.js.map +1 -1
- package/dist/private/i_private_client.d.ts +1 -1
- package/dist/private/opcua_client_impl.js +12 -10
- package/dist/private/opcua_client_impl.js.map +1 -1
- package/dist/private/reconnection/client_publish_engine_reconnection.js +17 -7
- package/dist/private/reconnection/client_publish_engine_reconnection.js.map +1 -1
- package/dist/private/reconnection/client_subscription_reconnection.js +11 -7
- package/dist/private/reconnection/client_subscription_reconnection.js.map +1 -1
- package/dist/private/reconnection/reconnection.js +31 -14
- package/dist/private/reconnection/reconnection.js.map +1 -1
- package/dist/reverse/client_reverse_connect.js.map +1 -1
- package/dist/tools/findservers.js.map +1 -1
- package/dist/tools/read_history_server_capabilities.d.ts +2 -1
- package/dist/tools/read_history_server_capabilities.js +6 -3
- package/dist/tools/read_history_server_capabilities.js.map +1 -1
- package/package.json +50 -50
- package/source/alarms_and_conditions/client_alarm_tools.ts +10 -8
- package/source/alarms_and_conditions/client_tools.ts +71 -30
- package/source/client_base.ts +0 -1
- package/source/client_monitored_item.ts +10 -9
- package/source/client_monitored_item_base.ts +2 -8
- package/source/client_monitored_item_group.ts +13 -10
- package/source/client_monitored_item_toolbox.ts +4 -2
- package/source/client_session.ts +10 -3
- package/source/client_session_keepalive_manager.ts +72 -55
- package/source/client_subscription.ts +6 -3
- package/source/common.ts +4 -0
- package/source/index.ts +1 -1
- package/source/opcua_client.ts +1 -0
- package/source/private/client_base_impl.ts +179 -102
- package/source/private/client_monitored_item_group_impl.ts +17 -18
- package/source/private/client_monitored_item_impl.ts +0 -4
- package/source/private/client_publish_engine.ts +78 -40
- package/source/private/client_session_impl.ts +393 -236
- package/source/private/client_subscription_impl.ts +20 -25
- package/source/private/i_private_client.ts +1 -1
- package/source/private/opcua_client_impl.ts +13 -10
- package/source/private/reconnection/client_publish_engine_reconnection.ts +22 -21
- package/source/private/reconnection/client_subscription_reconnection.ts +12 -8
- package/source/private/reconnection/reconnection.ts +35 -18
- package/source/reverse/client_reverse_connect.ts +11 -3
- package/source/tools/findservers.ts +0 -1
- package/source/tools/read_history_server_capabilities.ts +9 -7
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6DAA2C;AAC3C,uDAA2C;AAAlC,2GAAA,MAAM,OAAA;AACf,uDAAwE;AAA/D,gHAAA,WAAW,OAAA;AAAE,2HAAA,sBAAsB,OAAA;AAC5C,uEAAgH;AAAvG,qIAAA,wBAAwB,OAAA;AAA6B,2HAAA,cAAc,OAAA;AAC5E,mDAAiC;AACjC,6EAA2D;AAC3D,uEAAqD;AACrD,uEAAqD;AACrD,gDAA8B;AAC9B,0DAAwC;AACxC,+DAA6C;AAC7C,gEAA8C;AAC9C,mDAAiC;AACjC,wDAAsC;AACtC,iDAA+B;AAC/B,iDAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6DAA2C;AAC3C,uDAA2C;AAAlC,2GAAA,MAAM,OAAA;AACf,uDAAwE;AAA/D,gHAAA,WAAW,OAAA;AAAE,2HAAA,sBAAsB,OAAA;AAC5C,uEAAgH;AAAvG,qIAAA,wBAAwB,OAAA;AAA6B,2HAAA,cAAc,OAAA;AAC5E,mDAAiC;AACjC,6EAA2D;AAC3D,uEAAqD;AACrD,uEAAqD;AACrD,gDAA8B;AAC9B,0DAAwC;AACxC,+DAA6C;AAC7C,gEAA8C;AAC9C,mDAAiC;AACjC,wDAAsC;AACtC,iDAA+B;AAC/B,iDAA+B;AAC/B,yEAA0E;AAAjE,gIAAA,uBAAuB,OAAA;AAChC,mEAAiD;AACjD,sDAAoC;AACpC,2EAAyD;AACzD,uDAAqC;AACrC,2CAAyB;AAEzB,yDAA2C;AAC9B,QAAA,KAAK,GAAG,MAAM,CAAC;AAE5B,oEAAsD;AACzC,QAAA,YAAY,GAAG,YAAY,CAAC;AAEzC,6EAA2D;AAC3D,uDAAuD;AAA9C,uHAAA,kBAAkB,OAAA;AAC3B,uDAAqC;AACrC,wDAAsC;AACtC,wDAAsC;AACtC,qDAU0B;AATtB,kHAAA,cAAc,OAAA;AACd,2GAAA,OAAO,OAAA;AACP,4GAAA,QAAQ,OAAA;AACR,iHAAA,aAAa,OAAA;AACb,mHAAA,eAAe,OAAA;AACf,kHAAA,cAAc,OAAA;AACd,kHAAA,cAAc,OAAA;AACd,+GAAA,WAAW,OAAA;AACX,oHAAA,gBAAgB,OAAA;AAEpB,GAAG;AACH,uDAU2B;AATvB,yHAAA,oBAAoB,OAAA;AACpB,iHAAA,YAAY,OAAA;AACZ,mHAAA,cAAc,OAAA;AACd,uHAAA,kBAAkB,OAAA;AAClB,+GAAA,UAAU,OAAA;AACV,2GAAA,MAAM,OAAA;AAEN,kHAAA,aAAa,OAAA;AACb,+GAAA,UAAU,OAAA;AAEd,4DAA0C;AAC1C,4DAA0C;AAC1C,4DAA0C;AAC1C,0DAAwC;AACxC,+DAA6C;AAC7C,+DAA6C;AAC7C,+DAA6C;AAC7C,4DAA0C;AAC1C,6DAA2C;AAC3C,2DAAyC;AACzC,0DAAwC;AACxC,oEAAkD;AAClD,6DAA2C;AAC3C,kEAAgD;AAChD,2EAAyD;AACzD,2DAAyC;AACzC,iEAAgF;AAAxD,oHAAA,UAAU,OAAA;AAAE,qHAAA,WAAW,OAAA;AAC/C,qDAAsD;AAA7C,sHAAA,kBAAkB,OAAA;AAC3B,qDAAmC"}
|
package/dist/opcua_client.js
CHANGED
|
@@ -18,6 +18,7 @@ const opcua_client_impl_1 = require("./private/opcua_client_impl");
|
|
|
18
18
|
* });
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: interface merges instance-side typings; static factory + static accessors can't be expressed as a namespace (get/set)
|
|
21
22
|
class OPCUAClient {
|
|
22
23
|
/**
|
|
23
24
|
* Create a new OPC UA client instance.
|
package/dist/opcua_client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opcua_client.js","sourceRoot":"","sources":["../source/opcua_client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAeH,mEAA8D;AA6M9D;;;;;;;;;;;;GAYG;AACH,MAAa,WAAW;IACpB;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA2B;QAC5C,OAAO,IAAI,mCAAe,CAAC,OAAO,CAA2B,CAAC;IAClE,CAAC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAC7B,WAAmB,EACnB,YAA+B,EAC/B,aAAkC;QAElC,OAAO,mCAAe,CAAC,aAAa,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IACnF,CAAC;IACM,MAAM,KAAK,4BAA4B,CAAC,4BAAoC;QAC/E,mCAAe,CAAC,4BAA4B,GAAG,4BAA4B,CAAC;IAChF,CAAC;IACM,MAAM,KAAK,4BAA4B;QAC1C,OAAO,mCAAe,CAAC,4BAA4B,CAAC;IACxD,CAAC;CACJ;AA5CD,kCA4CC"}
|
|
1
|
+
{"version":3,"file":"opcua_client.js","sourceRoot":"","sources":["../source/opcua_client.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAeH,mEAA8D;AA6M9D;;;;;;;;;;;;GAYG;AACH,wKAAwK;AACxK,MAAa,WAAW;IACpB;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA2B;QAC5C,OAAO,IAAI,mCAAe,CAAC,OAAO,CAA2B,CAAC;IAClE,CAAC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAC7B,WAAmB,EACnB,YAA+B,EAC/B,aAAkC;QAElC,OAAO,mCAAe,CAAC,aAAa,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IACnF,CAAC;IACM,MAAM,KAAK,4BAA4B,CAAC,4BAAoC;QAC/E,mCAAe,CAAC,4BAA4B,GAAG,4BAA4B,CAAC;IAChF,CAAC;IACM,MAAM,KAAK,4BAA4B;QAC1C,OAAO,mCAAe,CAAC,4BAA4B,CAAC;IACxD,CAAC;CACJ;AA5CD,kCA4CC"}
|
|
@@ -7,7 +7,6 @@ exports.ClientBaseImpl = void 0;
|
|
|
7
7
|
/**
|
|
8
8
|
* @module node-opcua-client-private
|
|
9
9
|
*/
|
|
10
|
-
// tslint:disable:no-unused-expression
|
|
11
10
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
12
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
12
|
const global_mutex_1 = require("@ster5/global-mutex");
|
|
@@ -183,15 +182,18 @@ async function _verify_serverCertificate(certificateManager, serverCertificate)
|
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
const forceEndpointDiscoveryOnConnect = !!parseInt(process.env.NODEOPCUA_CLIENT_FORCE_ENDPOINT_DISCOVERY || "0", 10);
|
|
186
|
-
|
|
185
|
+
// c8 ignore next
|
|
186
|
+
doDebug && debugLog("forceEndpointDiscoveryOnConnect = ", forceEndpointDiscoveryOnConnect);
|
|
187
187
|
class ClockAdjustment {
|
|
188
188
|
constructor() {
|
|
189
|
-
|
|
189
|
+
// c8 ignore next
|
|
190
|
+
doDebug && debugLog("installPeriodicClockAdjustment ", node_opcua_date_time_1.periodicClockAdjustment.timerInstallationCount);
|
|
190
191
|
(0, node_opcua_date_time_1.installPeriodicClockAdjustment)();
|
|
191
192
|
}
|
|
192
193
|
dispose() {
|
|
193
194
|
(0, node_opcua_date_time_1.uninstallPeriodicClockAdjustment)();
|
|
194
|
-
|
|
195
|
+
// c8 ignore next
|
|
196
|
+
doDebug && debugLog("uninstallPeriodicClockAdjustment ", node_opcua_date_time_1.periodicClockAdjustment.timerInstallationCount);
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
/*
|
|
@@ -217,7 +219,6 @@ let g_ClientCounter = 0;
|
|
|
217
219
|
/**
|
|
218
220
|
* @internal
|
|
219
221
|
*/
|
|
220
|
-
// tslint:disable-next-line: max-classes-per-file
|
|
221
222
|
class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
222
223
|
/**
|
|
223
224
|
* total number of requests that been canceled due to timeout
|
|
@@ -348,8 +349,7 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
348
349
|
}
|
|
349
350
|
const cm = options.clientCertificateManager;
|
|
350
351
|
options.privateKeyFile = options.privateKeyFile || cm.privateKey;
|
|
351
|
-
options.certificateFile =
|
|
352
|
-
options.certificateFile || node_path_1.default.join(cm.rootDir, "own/certs/client_certificate.pem");
|
|
352
|
+
options.certificateFile = options.certificateFile || node_path_1.default.join(cm.rootDir, "own/certs/client_certificate.pem");
|
|
353
353
|
super(options);
|
|
354
354
|
}
|
|
355
355
|
this.#hasUserProvidedProvider = hasUserProvidedProvider;
|
|
@@ -360,6 +360,9 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
360
360
|
(0, node_opcua_assert_1.assert)(!this.applicationName.match(/urn:/), "applicationName should not be a URI");
|
|
361
361
|
// we need to delay _applicationUri initialization
|
|
362
362
|
this._applicationUri = options.applicationUri || this._getBuiltApplicationUri();
|
|
363
|
+
if (!options.clientCertificateManager) {
|
|
364
|
+
throw new Error("internal error: clientCertificateManager should have been set above");
|
|
365
|
+
}
|
|
363
366
|
this.clientCertificateManager = options.clientCertificateManager;
|
|
364
367
|
this.clientCertificateManager.referenceCounter++;
|
|
365
368
|
this._secureChannel = null;
|
|
@@ -403,11 +406,14 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
403
406
|
if (!this.isReconnecting) {
|
|
404
407
|
warningLog("internal error: _cancel_reconnection should only be used when reconnecting is in progress");
|
|
405
408
|
}
|
|
406
|
-
|
|
409
|
+
// c8 ignore next
|
|
410
|
+
doDebug && debugLog("canceling reconnection : ", this.clientName);
|
|
407
411
|
this._reconnectionIsCanceled = true;
|
|
408
412
|
// c8 ignore next
|
|
409
413
|
if (!this._secureChannel) {
|
|
410
|
-
|
|
414
|
+
// c8 ignore next
|
|
415
|
+
doDebug &&
|
|
416
|
+
debugLog("_cancel_reconnection: Nothing to do for !", this.clientName, " because secure channel doesn't exist");
|
|
411
417
|
return callback(); // nothing to do
|
|
412
418
|
}
|
|
413
419
|
this._secureChannel.abortConnection(( /*err?: Error*/) => {
|
|
@@ -416,9 +422,11 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
416
422
|
});
|
|
417
423
|
}
|
|
418
424
|
_recreate_secure_channel(callback) {
|
|
419
|
-
|
|
425
|
+
// c8 ignore next
|
|
426
|
+
doDebug && debugLog("_recreate_secure_channel... while internalState is", this._internalState);
|
|
420
427
|
if (!this.knowsServerEndpoint) {
|
|
421
|
-
|
|
428
|
+
// c8 ignore next
|
|
429
|
+
doDebug && debugLog("Cannot reconnect , server endpoint is unknown");
|
|
422
430
|
callback(new Error("Cannot reconnect, server endpoint is unknown - this.knowsServerEndpoint = false"));
|
|
423
431
|
return;
|
|
424
432
|
}
|
|
@@ -440,7 +448,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
440
448
|
return callback(new Error(`Reconnection has been canceled - ${this.clientName}`));
|
|
441
449
|
};
|
|
442
450
|
const _failAndRetry = (err, message, callback) => {
|
|
443
|
-
|
|
451
|
+
// c8 ignore next
|
|
452
|
+
doDebug && debugLog("failAndRetry; ", message);
|
|
444
453
|
if (this._reconnectionIsCanceled) {
|
|
445
454
|
return _when_reconnectionIsCanceled(callback);
|
|
446
455
|
}
|
|
@@ -455,12 +464,14 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
455
464
|
this.emit("after_reconnection", null); // send after callback
|
|
456
465
|
(0, node_opcua_assert_1.assert)(this._secureChannel, "expecting a secureChannel here ");
|
|
457
466
|
// a new channel has be created and a new connection is established
|
|
458
|
-
|
|
467
|
+
// c8 ignore next
|
|
468
|
+
doDebug && debugLog(chalk_1.default.bgWhite.red("ClientBaseImpl: RECONNECTED !!!"));
|
|
459
469
|
this._setInternalState("reconnecting_newchannel_connected");
|
|
460
470
|
return callback();
|
|
461
471
|
};
|
|
462
472
|
const _attempt_to_recreate_secure_channel = (callback) => {
|
|
463
|
-
|
|
473
|
+
// c8 ignore next
|
|
474
|
+
doDebug && debugLog("attempt to recreate a new secure channel");
|
|
464
475
|
if (this._reconnectionIsCanceled) {
|
|
465
476
|
return _when_reconnectionIsCanceled(callback);
|
|
466
477
|
}
|
|
@@ -536,7 +547,9 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
536
547
|
_internal_create_secure_channel(connectionStrategy, callback) {
|
|
537
548
|
(0, node_opcua_assert_1.assert)(this._secureChannel === null);
|
|
538
549
|
(0, node_opcua_assert_1.assert)(typeof this.endpointUrl === "string");
|
|
539
|
-
|
|
550
|
+
// c8 ignore next
|
|
551
|
+
doDebug &&
|
|
552
|
+
debugLog("_internal_create_secure_channel creating new ClientSecureChannelLayer _internalState =", this._internalState, this.clientName);
|
|
540
553
|
const secureChannel = new node_opcua_secure_channel_1.ClientSecureChannelLayer({
|
|
541
554
|
connectionStrategy,
|
|
542
555
|
defaultSecureTokenLifetime: this.defaultSecureTokenLifetime,
|
|
@@ -561,11 +574,14 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
561
574
|
this.emit("secure_channel_created", secureChannel);
|
|
562
575
|
const step2_openSecureChannel = () => {
|
|
563
576
|
return new Promise((resolve, reject) => {
|
|
564
|
-
|
|
577
|
+
// c8 ignore next
|
|
578
|
+
doDebug && debugLog("_internal_create_secure_channel before secureChannel.create");
|
|
565
579
|
secureChannel.create(this.endpointUrl, (err) => {
|
|
566
|
-
|
|
580
|
+
// c8 ignore next
|
|
581
|
+
doDebug && debugLog("_internal_create_secure_channel after secureChannel.create");
|
|
567
582
|
if (!this._secureChannel) {
|
|
568
|
-
|
|
583
|
+
// c8 ignore next
|
|
584
|
+
doDebug && debugLog("_secureChannel has been closed during the transaction !");
|
|
569
585
|
return reject(new Error("Secure Channel Closed"));
|
|
570
586
|
}
|
|
571
587
|
if (err) {
|
|
@@ -583,7 +599,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
583
599
|
this._setInternalState("connecting");
|
|
584
600
|
this.getEndpoints((err /*, endpoints?: EndpointDescription[]*/) => {
|
|
585
601
|
if (!this._secureChannel) {
|
|
586
|
-
|
|
602
|
+
// c8 ignore next
|
|
603
|
+
doDebug && debugLog("_secureChannel has been closed during the transaction ! (while getEndpoints)");
|
|
587
604
|
return reject(new Error("Secure Channel Closed"));
|
|
588
605
|
}
|
|
589
606
|
if (err) {
|
|
@@ -654,11 +671,15 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
654
671
|
}
|
|
655
672
|
warningLog("Creating default certificate ... please wait");
|
|
656
673
|
await ClientBaseImpl.createCertificate(this.clientCertificateManager, this.certificateFile, this.applicationName, this._getBuiltApplicationUri());
|
|
657
|
-
|
|
674
|
+
// c8 ignore next
|
|
675
|
+
doDebug && debugLog("privateKey = ", this.privateKeyFile);
|
|
658
676
|
if ("privateKey" in this.clientCertificateManager) {
|
|
659
|
-
|
|
677
|
+
// c8 ignore next
|
|
678
|
+
doDebug &&
|
|
679
|
+
debugLog(" = ", this.clientCertificateManager.privateKey);
|
|
660
680
|
}
|
|
661
|
-
|
|
681
|
+
// c8 ignore next
|
|
682
|
+
doDebug && debugLog("certificateFile = ", this.certificateFile);
|
|
662
683
|
const _certificate = this.getCertificate();
|
|
663
684
|
// Note: do NOT eagerly call this.getPrivateKey() here. A freshly
|
|
664
685
|
// generated key may already be passphrase-encrypted on disk (when
|
|
@@ -731,7 +752,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
731
752
|
}
|
|
732
753
|
_internalState = "uninitialized";
|
|
733
754
|
_handleUnrecoverableConnectionFailure(err, callback) {
|
|
734
|
-
|
|
755
|
+
// c8 ignore next
|
|
756
|
+
doDebug && debugLog(err.message);
|
|
735
757
|
// Terminal connect failure: make sure the client is removed from the leak registry. A
|
|
736
758
|
// synchronous throw out of _connectStep2 (e.g. an invalid SecureChannel config) lands here
|
|
737
759
|
// WITHOUT the error-branch unregister ever running, which would otherwise leak the client.
|
|
@@ -742,7 +764,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
742
764
|
callback(err);
|
|
743
765
|
}
|
|
744
766
|
_handleDisconnectionWhileConnecting(err, callback) {
|
|
745
|
-
|
|
767
|
+
// c8 ignore next
|
|
768
|
+
doDebug && debugLog(err.message);
|
|
746
769
|
// see _handleUnrecoverableConnectionFailure: idempotent unregister guards against a leaked
|
|
747
770
|
// client when a connect attempt fails before the error-branch unregister runs.
|
|
748
771
|
client_base_1.OPCUAClientBase.registry.unregister(this);
|
|
@@ -751,7 +774,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
751
774
|
callback(err);
|
|
752
775
|
}
|
|
753
776
|
_handleSuccessfulConnection(callback) {
|
|
754
|
-
|
|
777
|
+
// c8 ignore next
|
|
778
|
+
doDebug && debugLog(" Connected successfully to ", this.endpointUrl);
|
|
755
779
|
this.emit("connected");
|
|
756
780
|
this._setInternalState("connected");
|
|
757
781
|
callback();
|
|
@@ -779,13 +803,15 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
779
803
|
this._setInternalState("connecting");
|
|
780
804
|
this.initializeCM()
|
|
781
805
|
.then(() => {
|
|
782
|
-
|
|
806
|
+
// c8 ignore next
|
|
807
|
+
doDebug && debugLog("ClientBaseImpl#connect ", endpointUrl, this.clientName);
|
|
783
808
|
if (this._internalState === "disconnecting" || this._internalState === "disconnected") {
|
|
784
809
|
return this._handleDisconnectionWhileConnecting(new Error("premature disconnection 1"), callback);
|
|
785
810
|
}
|
|
786
811
|
if (!this.serverCertificate &&
|
|
787
812
|
(forceEndpointDiscoveryOnConnect || this.securityMode !== node_opcua_service_secure_channel_1.MessageSecurityMode.None)) {
|
|
788
|
-
|
|
813
|
+
// c8 ignore next
|
|
814
|
+
doDebug && debugLog("Fetching certificates from endpoints");
|
|
789
815
|
this.fetchServerCertificate(endpointUrl, (err, adjustedEndpointUrl) => {
|
|
790
816
|
if (err) {
|
|
791
817
|
return this._handleUnrecoverableConnectionFailure(err, callback);
|
|
@@ -794,11 +820,14 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
794
820
|
return this._handleDisconnectionWhileConnecting(new Error("premature disconnection 2"), callback);
|
|
795
821
|
}
|
|
796
822
|
if (forceEndpointDiscoveryOnConnect) {
|
|
797
|
-
|
|
823
|
+
// c8 ignore next
|
|
824
|
+
doDebug &&
|
|
825
|
+
debugLog("connecting with adjusted endpoint : ", adjustedEndpointUrl, " was =", endpointUrl);
|
|
798
826
|
this._connectStep2(adjustedEndpointUrl || "", callback);
|
|
799
827
|
}
|
|
800
828
|
else {
|
|
801
|
-
|
|
829
|
+
// c8 ignore next
|
|
830
|
+
doDebug && debugLog("connecting with endpoint : ", endpointUrl);
|
|
802
831
|
this._connectStep2(endpointUrl, callback);
|
|
803
832
|
}
|
|
804
833
|
});
|
|
@@ -868,7 +897,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
868
897
|
this._setInternalState("connecting");
|
|
869
898
|
this.initializeCM()
|
|
870
899
|
.then(() => {
|
|
871
|
-
|
|
900
|
+
// c8 ignore next
|
|
901
|
+
doDebug && debugLog("ClientBaseImpl#connectReverse ", placeholderEndpointUrl, this.clientName);
|
|
872
902
|
if (this._internalState === "disconnecting" || this._internalState === "disconnected") {
|
|
873
903
|
return this._handleDisconnectionWhileConnecting(new Error("premature disconnection 1"), callback);
|
|
874
904
|
}
|
|
@@ -889,7 +919,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
889
919
|
this.endpointUrl = endpointUrl;
|
|
890
920
|
this._clockAdjuster = this._clockAdjuster || new ClockAdjustment();
|
|
891
921
|
client_base_1.OPCUAClientBase.registry.register(this);
|
|
892
|
-
|
|
922
|
+
// c8 ignore next
|
|
923
|
+
doDebug && debugLog("__connectStep2 ", this._internalState);
|
|
893
924
|
this._internal_create_secure_channel(this.connectionStrategy, (err) => {
|
|
894
925
|
if (!err) {
|
|
895
926
|
this._handleSuccessfulConnection(callback);
|
|
@@ -900,14 +931,17 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
900
931
|
this._clockAdjuster.dispose();
|
|
901
932
|
this._clockAdjuster = undefined;
|
|
902
933
|
}
|
|
903
|
-
|
|
934
|
+
// c8 ignore next
|
|
935
|
+
doDebug && debugLog(chalk_1.default.red("SecureChannel creation has failed with error :", err.message));
|
|
904
936
|
if (err.message.match(/ECONNABORTED/)) {
|
|
905
|
-
|
|
937
|
+
// c8 ignore next
|
|
938
|
+
doDebug && debugLog(chalk_1.default.yellow(`- The client cannot to :${endpointUrl}. Connection has been aborted.`));
|
|
906
939
|
err = new Error("The connection has been aborted");
|
|
907
940
|
this._handleUnrecoverableConnectionFailure(err, callback);
|
|
908
941
|
}
|
|
909
942
|
else if (err.message.match(/ECONNREF/)) {
|
|
910
|
-
|
|
943
|
+
// c8 ignore next
|
|
944
|
+
doDebug && debugLog(chalk_1.default.yellow(`- The client cannot to :${endpointUrl}. Server is not reachable.`));
|
|
911
945
|
err = new Error(`The connection cannot be established with server ${endpointUrl} .\n` +
|
|
912
946
|
"Please check that the server is up and running or your network configuration.\n" +
|
|
913
947
|
"Err = (" +
|
|
@@ -931,7 +965,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
931
965
|
// this may happen if the Server has closed the connection abruptly for some unknown reason
|
|
932
966
|
// or if the tcp connection has been broken.
|
|
933
967
|
callback(new Error("performMessageTransaction: No SecureChannel , connection may have been canceled abruptly by server" +
|
|
934
|
-
" while performing " +
|
|
968
|
+
" while performing " +
|
|
969
|
+
request.schema.name));
|
|
935
970
|
return;
|
|
936
971
|
}
|
|
937
972
|
if (this._internalState !== "connected" &&
|
|
@@ -1096,7 +1131,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1096
1131
|
if (!this._secureChannel.isValid()) {
|
|
1097
1132
|
return callback(null);
|
|
1098
1133
|
}
|
|
1099
|
-
|
|
1134
|
+
// c8 ignore next
|
|
1135
|
+
doDebug && debugLog(chalk_1.default.bgWhite.green("_closeSession ") + this._secureChannel.channelId);
|
|
1100
1136
|
const request = new node_opcua_service_session_1.CloseSessionRequest({
|
|
1101
1137
|
deleteSubscriptions
|
|
1102
1138
|
});
|
|
@@ -1124,7 +1160,6 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1124
1160
|
callback?.(err ? err : undefined);
|
|
1125
1161
|
});
|
|
1126
1162
|
}
|
|
1127
|
-
// eslint-disable-next-line max-statements
|
|
1128
1163
|
disconnect(...args) {
|
|
1129
1164
|
const callback = args[0];
|
|
1130
1165
|
(0, node_opcua_assert_1.assert)(typeof callback === "function", "expecting a callback function here");
|
|
@@ -1152,14 +1187,18 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1152
1187
|
callback();
|
|
1153
1188
|
return undefined;
|
|
1154
1189
|
}
|
|
1155
|
-
|
|
1190
|
+
// c8 ignore next
|
|
1191
|
+
doDebug && debugLog("disconnecting client! (will set reconnectionIsCanceled to true");
|
|
1156
1192
|
this._reconnectionIsCanceled = true;
|
|
1157
|
-
|
|
1193
|
+
// c8 ignore next
|
|
1194
|
+
doDebug && debugLog("ClientBaseImpl#disconnect", this.endpointUrl);
|
|
1158
1195
|
if (this.isReconnecting && !this._reconnectionIsCanceled) {
|
|
1159
|
-
|
|
1196
|
+
// c8 ignore next
|
|
1197
|
+
doDebug && debugLog("ClientBaseImpl#disconnect called while reconnection is in progress");
|
|
1160
1198
|
// let's abort the reconnection process
|
|
1161
1199
|
this._cancel_reconnection((err) => {
|
|
1162
|
-
|
|
1200
|
+
// c8 ignore next
|
|
1201
|
+
doDebug && debugLog("ClientBaseImpl#disconnect reconnection has been canceled", this.applicationName);
|
|
1163
1202
|
(0, node_opcua_assert_1.assert)(!err, " why would this fail ?");
|
|
1164
1203
|
// sessions cannot be cancelled properly and must be discarded.
|
|
1165
1204
|
this.disconnect(callback);
|
|
@@ -1167,7 +1206,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1167
1206
|
return undefined;
|
|
1168
1207
|
}
|
|
1169
1208
|
if (this._sessions.length && !this.keepPendingSessionsOnDisconnect) {
|
|
1170
|
-
|
|
1209
|
+
// c8 ignore next
|
|
1210
|
+
doDebug && debugLog("warning : disconnection : closing pending sessions");
|
|
1171
1211
|
// disconnect has been called whereas living session exists
|
|
1172
1212
|
// we need to close them first .... (unless keepPendingSessionsOnDisconnect)
|
|
1173
1213
|
this._close_pending_sessions(( /*err*/) => {
|
|
@@ -1175,13 +1215,15 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1175
1215
|
});
|
|
1176
1216
|
return undefined;
|
|
1177
1217
|
}
|
|
1178
|
-
|
|
1218
|
+
// c8 ignore next
|
|
1219
|
+
doDebug && debugLog("Disconnecting !");
|
|
1179
1220
|
this._setInternalState("disconnecting");
|
|
1180
1221
|
if (this.clientCertificateManager) {
|
|
1181
1222
|
const tmp = this.clientCertificateManager;
|
|
1182
1223
|
// (this as any).clientCertificateManager = null;
|
|
1183
1224
|
tmp.dispose().catch((err) => {
|
|
1184
|
-
|
|
1225
|
+
// c8 ignore next
|
|
1226
|
+
doDebug && debugLog("Error disposing clientCertificateManager", err.message);
|
|
1185
1227
|
});
|
|
1186
1228
|
}
|
|
1187
1229
|
if (this._sessions.length) {
|
|
@@ -1201,7 +1243,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1201
1243
|
if (this._secureChannel) {
|
|
1202
1244
|
let tmpChannel = this._secureChannel;
|
|
1203
1245
|
this._secureChannel = null;
|
|
1204
|
-
|
|
1246
|
+
// c8 ignore next
|
|
1247
|
+
doDebug && debugLog("Closing channel");
|
|
1205
1248
|
tmpChannel.close(() => {
|
|
1206
1249
|
this._secureChannel = tmpChannel;
|
|
1207
1250
|
tmpChannel = null;
|
|
@@ -1266,7 +1309,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1266
1309
|
}
|
|
1267
1310
|
fetchServerCertificate(endpointUrl, callback) {
|
|
1268
1311
|
const discoveryUrl = this.discoveryUrl.length > 0 ? this.discoveryUrl : endpointUrl;
|
|
1269
|
-
|
|
1312
|
+
// c8 ignore next
|
|
1313
|
+
doDebug && debugLog("OPCUAClientImpl : getting serverCertificate");
|
|
1270
1314
|
// we have not been given the serverCertificate but this certificate
|
|
1271
1315
|
// is required as the connection is to be secured.
|
|
1272
1316
|
//
|
|
@@ -1343,8 +1387,12 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1343
1387
|
const isCA = tbs.extensions?.basicConstraints?.cA === true;
|
|
1344
1388
|
const isSelfSigned = JSON.stringify(tbs.subject) === JSON.stringify(tbs.issuer);
|
|
1345
1389
|
const certType = isCA
|
|
1346
|
-
?
|
|
1347
|
-
|
|
1390
|
+
? isSelfSigned
|
|
1391
|
+
? "Root CA"
|
|
1392
|
+
: "Intermediate CA"
|
|
1393
|
+
: isSelfSigned
|
|
1394
|
+
? "Application (self-signed)"
|
|
1395
|
+
: "Application (CA-signed)";
|
|
1348
1396
|
const ski = tbs.extensions?.subjectKeyIdentifier ?? "-";
|
|
1349
1397
|
const aki = tbs.extensions?.authorityKeyIdentifier?.keyIdentifier ?? "-";
|
|
1350
1398
|
const notBefore = tbs.validity.notBefore.toISOString();
|
|
@@ -1416,7 +1464,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1416
1464
|
resolved = true;
|
|
1417
1465
|
if (err) {
|
|
1418
1466
|
const msg = session.authenticationToken ? session.authenticationToken.toString() : "";
|
|
1419
|
-
|
|
1467
|
+
// c8 ignore next
|
|
1468
|
+
doDebug && debugLog(` failing to close session ${msg}`);
|
|
1420
1469
|
}
|
|
1421
1470
|
resolve();
|
|
1422
1471
|
});
|
|
@@ -1427,9 +1476,11 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1427
1476
|
.then(() => {
|
|
1428
1477
|
// c8 ignore next
|
|
1429
1478
|
if (this._sessions.length > 0) {
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
.
|
|
1479
|
+
// c8 ignore next
|
|
1480
|
+
doDebug &&
|
|
1481
|
+
debugLog(this._sessions
|
|
1482
|
+
.map((s) => (s.authenticationToken ? s.authenticationToken.toString() : ""))
|
|
1483
|
+
.join(" "));
|
|
1433
1484
|
}
|
|
1434
1485
|
(0, node_opcua_assert_1.assert)(this._sessions.length === 0, " failed to disconnect exiting sessions ");
|
|
1435
1486
|
callback();
|
|
@@ -1472,7 +1523,9 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1472
1523
|
});
|
|
1473
1524
|
secureChannel.on("lifetime_75", (token) => {
|
|
1474
1525
|
// secureChannel requests a new token
|
|
1475
|
-
|
|
1526
|
+
// c8 ignore next
|
|
1527
|
+
doDebug &&
|
|
1528
|
+
debugLog("SecureChannel Security Token ", token.tokenId, "live time was =", token.revisedLifetime, " is about to expired , it's time to request a new token");
|
|
1476
1529
|
// forward message to upper level
|
|
1477
1530
|
this.emit("lifetime_75", token);
|
|
1478
1531
|
});
|
|
@@ -1484,7 +1537,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1484
1537
|
if (err) {
|
|
1485
1538
|
this._setInternalState("panic");
|
|
1486
1539
|
}
|
|
1487
|
-
|
|
1540
|
+
// c8 ignore next
|
|
1541
|
+
doDebug && debugLog(chalk_1.default.yellow.bold(" ClientBaseImpl emitting close"), err?.message);
|
|
1488
1542
|
this._destroy_secure_channel();
|
|
1489
1543
|
if (!err || !this.reconnectOnFailure) {
|
|
1490
1544
|
if (err) {
|
|
@@ -1500,7 +1554,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1500
1554
|
if (this.reconnectOnFailure &&
|
|
1501
1555
|
this._internalState !== "reconnecting" &&
|
|
1502
1556
|
this._internalState !== "reconnecting_newchannel_connected") {
|
|
1503
|
-
|
|
1557
|
+
// c8 ignore next
|
|
1558
|
+
doDebug && debugLog(" ClientBaseImpl emitting connection_lost");
|
|
1504
1559
|
this._setInternalState("reconnecting");
|
|
1505
1560
|
/**
|
|
1506
1561
|
* @event connection_lost
|
|
@@ -1549,7 +1604,8 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1549
1604
|
__innerRepairConnection() {
|
|
1550
1605
|
if (this.isUnusable())
|
|
1551
1606
|
return;
|
|
1552
|
-
|
|
1607
|
+
// c8 ignore next
|
|
1608
|
+
doDebug && debugLog("Entering _repairConnection ", this._internalState);
|
|
1553
1609
|
if (this.#insideRepairConnection) {
|
|
1554
1610
|
errorLog("_repairConnection already in progress internal state = ", this._internalState, "clientName =", this.clientName);
|
|
1555
1611
|
this.#shouldRepairAgain = true;
|
|
@@ -1557,11 +1613,14 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1557
1613
|
}
|
|
1558
1614
|
this.emit("repairConnectionStarted");
|
|
1559
1615
|
this.#insideRepairConnection = true;
|
|
1560
|
-
|
|
1616
|
+
// c8 ignore next
|
|
1617
|
+
doDebug && debugLog("recreating new secure channel ", this._internalState);
|
|
1561
1618
|
this._recreate_secure_channel((err1) => {
|
|
1562
|
-
|
|
1619
|
+
// c8 ignore next
|
|
1620
|
+
doDebug && debugLog("secureChannel#on(close) => _recreate_secure_channel returns ", err1 ? err1.message : "OK");
|
|
1563
1621
|
if (err1) {
|
|
1564
|
-
|
|
1622
|
+
// c8 ignore next
|
|
1623
|
+
doDebug && debugLog("_recreate_secure_channel has failed: err = ", err1.message);
|
|
1565
1624
|
this.emit("close", err1);
|
|
1566
1625
|
this.#insideRepairConnection = false;
|
|
1567
1626
|
if (this.#shouldRepairAgain) {
|
|
@@ -1584,8 +1643,11 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1584
1643
|
debugLog("err= ", err2.message);
|
|
1585
1644
|
}
|
|
1586
1645
|
// we still need to retry connecting here !!!
|
|
1587
|
-
|
|
1588
|
-
|
|
1646
|
+
// c8 ignore next
|
|
1647
|
+
if (doDebug) {
|
|
1648
|
+
debugLog("Disconnected following reconnection failure", err2.message);
|
|
1649
|
+
debugLog(`I will retry OPCUA client reconnection in ${client_base_1.OPCUAClientBase.retryDelay / 1000} seconds`);
|
|
1650
|
+
}
|
|
1589
1651
|
this.#insideRepairConnection = false;
|
|
1590
1652
|
this.#shouldRepairAgain = false;
|
|
1591
1653
|
this._destroy_secure_channel();
|
|
@@ -1632,14 +1694,14 @@ class ClientBaseImpl extends node_opcua_common_1.OPCUASecureObject {
|
|
|
1632
1694
|
}
|
|
1633
1695
|
}
|
|
1634
1696
|
exports.ClientBaseImpl = ClientBaseImpl;
|
|
1635
|
-
// tslint:disable-next-line: max-classes-per-file
|
|
1636
1697
|
class TmpClient extends ClientBaseImpl {
|
|
1637
1698
|
constructor(options) {
|
|
1638
1699
|
options.clientName = `${options.clientName || ""}_TmpClient`;
|
|
1639
1700
|
super(options);
|
|
1640
1701
|
}
|
|
1641
1702
|
connect(endpoint, callback) {
|
|
1642
|
-
|
|
1703
|
+
// c8 ignore next
|
|
1704
|
+
doDebug && debugLog("connecting to TmpClient");
|
|
1643
1705
|
// c8 ignore next
|
|
1644
1706
|
if (this._internalState !== "disconnected") {
|
|
1645
1707
|
callback?.(new Error(`TmpClient#connect: invalid internal state = ${this._internalState}`));
|
|
@@ -1655,8 +1717,6 @@ class TmpClient extends ClientBaseImpl {
|
|
|
1655
1717
|
});
|
|
1656
1718
|
}
|
|
1657
1719
|
}
|
|
1658
|
-
// tslint:disable:no-var-requires
|
|
1659
|
-
// tslint:disable:max-line-length
|
|
1660
1720
|
const thenify_ex_1 = require("thenify-ex");
|
|
1661
1721
|
ClientBaseImpl.prototype.connect = (0, thenify_ex_1.withCallback)(ClientBaseImpl.prototype.connect);
|
|
1662
1722
|
ClientBaseImpl.prototype.connectReverse = (0, thenify_ex_1.withCallback)(ClientBaseImpl.prototype.connectReverse);
|