node-opcua-server 2.166.0 → 2.167.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/base_server.js +1 -3
- package/dist/base_server.js.map +1 -1
- package/dist/opcua_server.js +3 -3
- package/dist/opcua_server.js.map +1 -1
- package/dist/register_server_manager.d.ts +8 -8
- package/dist/register_server_manager.js +40 -40
- package/dist/register_server_manager.js.map +1 -1
- package/dist/server_end_point.d.ts +2 -2
- package/dist/server_end_point.js +5 -12
- package/dist/server_end_point.js.map +1 -1
- package/package.json +42 -41
- package/source/base_server.ts +2 -4
- package/source/opcua_server.ts +18 -11
- package/source/register_server_manager.ts +75 -72
- package/source/server_end_point.ts +16 -23
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.167.0",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module server",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -b",
|
|
7
7
|
"lint": "eslint source test",
|
|
8
8
|
"format": "prettier --write source test",
|
|
9
9
|
"clean": "npx rimraf -g node_modules dist *.tsbuildinfo certificates",
|
|
10
|
-
"test": "mocha"
|
|
10
|
+
"test": "mocha",
|
|
11
|
+
"test:check": "tsc --noEmit -p test/tsconfig.json"
|
|
11
12
|
},
|
|
12
13
|
"main": "./dist/index.js",
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
@@ -19,53 +20,53 @@
|
|
|
19
20
|
"chalk": "4.1.2",
|
|
20
21
|
"dequeue": "^1.0.5",
|
|
21
22
|
"lodash": "4.17.23",
|
|
22
|
-
"node-opcua-address-space": "2.
|
|
23
|
-
"node-opcua-address-space-base": "2.
|
|
23
|
+
"node-opcua-address-space": "2.167.0",
|
|
24
|
+
"node-opcua-address-space-base": "2.167.0",
|
|
24
25
|
"node-opcua-assert": "2.164.0",
|
|
25
|
-
"node-opcua-basic-types": "2.
|
|
26
|
-
"node-opcua-binary-stream": "2.
|
|
27
|
-
"node-opcua-certificate-manager": "2.
|
|
28
|
-
"node-opcua-client": "2.
|
|
29
|
-
"node-opcua-common": "2.
|
|
26
|
+
"node-opcua-basic-types": "2.167.0",
|
|
27
|
+
"node-opcua-binary-stream": "2.167.0",
|
|
28
|
+
"node-opcua-certificate-manager": "2.167.0",
|
|
29
|
+
"node-opcua-client": "2.167.0",
|
|
30
|
+
"node-opcua-common": "2.167.0",
|
|
30
31
|
"node-opcua-constants": "2.157.0",
|
|
31
|
-
"node-opcua-crypto": "5.3.
|
|
32
|
-
"node-opcua-data-model": "2.
|
|
33
|
-
"node-opcua-data-value": "2.
|
|
34
|
-
"node-opcua-date-time": "2.
|
|
32
|
+
"node-opcua-crypto": "5.3.3",
|
|
33
|
+
"node-opcua-data-model": "2.167.0",
|
|
34
|
+
"node-opcua-data-value": "2.167.0",
|
|
35
|
+
"node-opcua-date-time": "2.167.0",
|
|
35
36
|
"node-opcua-debug": "2.165.0",
|
|
36
|
-
"node-opcua-extension-object": "2.
|
|
37
|
-
"node-opcua-factory": "2.
|
|
38
|
-
"node-opcua-hostname": "2.
|
|
39
|
-
"node-opcua-nodeid": "2.
|
|
37
|
+
"node-opcua-extension-object": "2.167.0",
|
|
38
|
+
"node-opcua-factory": "2.167.0",
|
|
39
|
+
"node-opcua-hostname": "2.167.0",
|
|
40
|
+
"node-opcua-nodeid": "2.167.0",
|
|
40
41
|
"node-opcua-nodesets": "2.163.1",
|
|
41
|
-
"node-opcua-numeric-range": "2.
|
|
42
|
+
"node-opcua-numeric-range": "2.167.0",
|
|
42
43
|
"node-opcua-object-registry": "2.165.0",
|
|
43
|
-
"node-opcua-pki": "6.
|
|
44
|
-
"node-opcua-secure-channel": "2.
|
|
45
|
-
"node-opcua-service-browse": "2.
|
|
46
|
-
"node-opcua-service-call": "2.
|
|
47
|
-
"node-opcua-service-discovery": "2.
|
|
48
|
-
"node-opcua-service-endpoints": "2.
|
|
49
|
-
"node-opcua-service-filter": "2.
|
|
50
|
-
"node-opcua-service-history": "2.
|
|
51
|
-
"node-opcua-service-node-management": "2.
|
|
52
|
-
"node-opcua-service-query": "2.
|
|
53
|
-
"node-opcua-service-read": "2.
|
|
54
|
-
"node-opcua-service-register-node": "2.
|
|
55
|
-
"node-opcua-service-secure-channel": "2.
|
|
56
|
-
"node-opcua-service-session": "2.
|
|
57
|
-
"node-opcua-service-subscription": "2.
|
|
58
|
-
"node-opcua-service-translate-browse-path": "2.
|
|
59
|
-
"node-opcua-service-write": "2.
|
|
60
|
-
"node-opcua-status-code": "2.
|
|
61
|
-
"node-opcua-transport": "2.
|
|
62
|
-
"node-opcua-types": "2.
|
|
44
|
+
"node-opcua-pki": "6.12.0",
|
|
45
|
+
"node-opcua-secure-channel": "2.167.0",
|
|
46
|
+
"node-opcua-service-browse": "2.167.0",
|
|
47
|
+
"node-opcua-service-call": "2.167.0",
|
|
48
|
+
"node-opcua-service-discovery": "2.167.0",
|
|
49
|
+
"node-opcua-service-endpoints": "2.167.0",
|
|
50
|
+
"node-opcua-service-filter": "2.167.0",
|
|
51
|
+
"node-opcua-service-history": "2.167.0",
|
|
52
|
+
"node-opcua-service-node-management": "2.167.0",
|
|
53
|
+
"node-opcua-service-query": "2.167.0",
|
|
54
|
+
"node-opcua-service-read": "2.167.0",
|
|
55
|
+
"node-opcua-service-register-node": "2.167.0",
|
|
56
|
+
"node-opcua-service-secure-channel": "2.167.0",
|
|
57
|
+
"node-opcua-service-session": "2.167.0",
|
|
58
|
+
"node-opcua-service-subscription": "2.167.0",
|
|
59
|
+
"node-opcua-service-translate-browse-path": "2.167.0",
|
|
60
|
+
"node-opcua-service-write": "2.167.0",
|
|
61
|
+
"node-opcua-status-code": "2.167.0",
|
|
62
|
+
"node-opcua-transport": "2.167.0",
|
|
63
|
+
"node-opcua-types": "2.167.0",
|
|
63
64
|
"node-opcua-utils": "2.165.0",
|
|
64
|
-
"node-opcua-variant": "2.
|
|
65
|
+
"node-opcua-variant": "2.167.0",
|
|
65
66
|
"thenify-ex": "4.4.0"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"node-opcua-data-access": "2.
|
|
69
|
+
"node-opcua-data-access": "2.167.0",
|
|
69
70
|
"node-opcua-leak-detector": "2.165.0",
|
|
70
71
|
"node-opcua-test-helpers": "2.157.0"
|
|
71
72
|
},
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
"internet of things"
|
|
85
86
|
],
|
|
86
87
|
"homepage": "http://node-opcua.github.io/",
|
|
87
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "5decfa86ee53a36ecd3bb454e7bf6e3dd27c7a4e",
|
|
88
89
|
"files": [
|
|
89
90
|
"dist",
|
|
90
91
|
"source"
|
package/source/base_server.ts
CHANGED
|
@@ -13,7 +13,7 @@ import chalk from "chalk";
|
|
|
13
13
|
import { assert } from "node-opcua-assert";
|
|
14
14
|
import { getDefaultCertificateManager, makeSubject, type OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
15
15
|
import { performCertificateSanityCheck } from "node-opcua-client";
|
|
16
|
-
import { type IOPCUASecureObjectOptions, makeApplicationUrn, OPCUASecureObject } from "node-opcua-common";
|
|
16
|
+
import { type IOPCUASecureObjectOptions, invalidateCachedSecrets, makeApplicationUrn, OPCUASecureObject } from "node-opcua-common";
|
|
17
17
|
import { exploreCertificate } from "node-opcua-crypto/web";
|
|
18
18
|
import { coerceLocalizedText } from "node-opcua-data-model";
|
|
19
19
|
import { installPeriodicClockAdjustment, uninstallPeriodicClockAdjustment } from "node-opcua-date-time";
|
|
@@ -339,9 +339,7 @@ export class OPCUABaseServer extends OPCUASecureObject {
|
|
|
339
339
|
// recreate with current hostnames
|
|
340
340
|
await this.createDefaultCertificate();
|
|
341
341
|
// invalidate cached cert so next getCertificate() reloads from disk
|
|
342
|
-
|
|
343
|
-
priv.$$certificate = null;
|
|
344
|
-
priv.$$certificateChain = null;
|
|
342
|
+
invalidateCachedSecrets(this);
|
|
345
343
|
}
|
|
346
344
|
|
|
347
345
|
private _checkCertificateSanMismatch(): void {
|
package/source/opcua_server.ts
CHANGED
|
@@ -37,7 +37,7 @@ import { assert } from "node-opcua-assert";
|
|
|
37
37
|
import type { ByteString, UAString } from "node-opcua-basic-types";
|
|
38
38
|
import { getDefaultCertificateManager, type OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
39
39
|
import { ServerState } from "node-opcua-common";
|
|
40
|
-
import { type Certificate, exploreCertificate, type Nonce } from "node-opcua-crypto/web";
|
|
40
|
+
import { type Certificate, combine_der, exploreCertificate, type Nonce } from "node-opcua-crypto/web";
|
|
41
41
|
import {
|
|
42
42
|
AttributeIds,
|
|
43
43
|
filterDiagnosticOperationLevel,
|
|
@@ -149,6 +149,7 @@ import { DataType, type Variant, VariantArrayType } from "node-opcua-variant";
|
|
|
149
149
|
import { withCallback } from "thenify-ex";
|
|
150
150
|
|
|
151
151
|
import { OPCUABaseServer, type OPCUABaseServerOptions } from "./base_server";
|
|
152
|
+
import { extractPasswordFromDecryptedBlob } from "./extract_password_from_blob";
|
|
152
153
|
import { Factory } from "./factory";
|
|
153
154
|
import type { IChannelData } from "./i_channel_data";
|
|
154
155
|
import type { IRegisterServerManager } from "./i_register_server_manager";
|
|
@@ -158,9 +159,15 @@ import { RegisterServerManager } from "./register_server_manager";
|
|
|
158
159
|
import { RegisterServerManagerHidden } from "./register_server_manager_hidden";
|
|
159
160
|
import { RegisterServerManagerMDNSONLY } from "./register_server_manager_mdns_only";
|
|
160
161
|
import type { SamplingFunc } from "./sampling_func";
|
|
161
|
-
import { extractPasswordFromDecryptedBlob } from "./extract_password_from_blob";
|
|
162
162
|
import type { ServerCapabilitiesOptions } from "./server_capabilities";
|
|
163
|
-
import {
|
|
163
|
+
import {
|
|
164
|
+
type AdvertisedEndpoint,
|
|
165
|
+
type EndpointDescriptionEx,
|
|
166
|
+
type IServerTransportSettings,
|
|
167
|
+
normalizeAdvertisedEndpoints,
|
|
168
|
+
OPCUAServerEndPoint,
|
|
169
|
+
parseOpcTcpUrl
|
|
170
|
+
} from "./server_end_point";
|
|
164
171
|
import { type ClosingReason, type CreateSessionOption, ServerEngine } from "./server_engine";
|
|
165
172
|
import type { ServerSession } from "./server_session";
|
|
166
173
|
import type { CreateMonitoredItemHook, DeleteMonitoredItemHook, Subscription } from "./server_subscription";
|
|
@@ -2113,7 +2120,7 @@ export class OPCUAServer extends OPCUABaseServer {
|
|
|
2113
2120
|
// If the securityPolicyUri is None and none of the UserTokenPolicies requires
|
|
2114
2121
|
// encryption, the Server shall not send an ApplicationInstanceCertificate and the Client
|
|
2115
2122
|
// shall ignore the ApplicationInstanceCertificate.
|
|
2116
|
-
serverCertificate: hasEncryption ? serverCertificateChain : undefined,
|
|
2123
|
+
serverCertificate: hasEncryption && serverCertificateChain.length > 0 ? combine_der(serverCertificateChain) : undefined,
|
|
2117
2124
|
|
|
2118
2125
|
// The endpoints provided by the server.
|
|
2119
2126
|
// The Server shall return a set of EndpointDescriptions available for the serverUri
|
|
@@ -3818,7 +3825,7 @@ export class OPCUAServer extends OPCUABaseServer {
|
|
|
3818
3825
|
// xx hostname,
|
|
3819
3826
|
resourcePath: serverOption.resourcePath || "",
|
|
3820
3827
|
|
|
3821
|
-
advertisedEndpoints: endpointOptions.advertisedEndpoints
|
|
3828
|
+
advertisedEndpoints: endpointOptions.advertisedEndpoints
|
|
3822
3829
|
|
|
3823
3830
|
// TODO userTokenTypes: endpointOptions.userTokenTypes || undefined,
|
|
3824
3831
|
|
|
@@ -4047,7 +4054,7 @@ export interface RaiseEventAuditActivateSessionEventData extends RaiseEventAudit
|
|
|
4047
4054
|
}
|
|
4048
4055
|
|
|
4049
4056
|
// tslint:disable:no-empty-interface
|
|
4050
|
-
export interface RaiseEventTransitionEventData extends RaiseEventData {
|
|
4057
|
+
export interface RaiseEventTransitionEventData extends RaiseEventData {}
|
|
4051
4058
|
|
|
4052
4059
|
export interface RaiseEventAuditUrlMismatchEventTypeData extends RaiseEventData {
|
|
4053
4060
|
endpointUrl: PseudoVariantString;
|
|
@@ -4077,7 +4084,7 @@ export interface RaiseAuditCertificateDataMismatchEventData extends RaiseAuditCe
|
|
|
4077
4084
|
*/
|
|
4078
4085
|
invalidUri: PseudoVariantString;
|
|
4079
4086
|
}
|
|
4080
|
-
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData {
|
|
4087
|
+
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData {}
|
|
4081
4088
|
/**
|
|
4082
4089
|
* This EventType inherits all Properties of the AuditCertificateEventType.
|
|
4083
4090
|
*
|
|
@@ -4089,7 +4096,7 @@ export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCerti
|
|
|
4089
4096
|
* There are no additional Properties defined for this EventType.
|
|
4090
4097
|
*
|
|
4091
4098
|
*/
|
|
4092
|
-
export interface RaiseAuditCertificateExpiredEventData extends RaiseAuditCertificateEventData {
|
|
4099
|
+
export interface RaiseAuditCertificateExpiredEventData extends RaiseAuditCertificateEventData {}
|
|
4093
4100
|
/**
|
|
4094
4101
|
* This EventType inherits all Properties of the AuditCertificateEventType.
|
|
4095
4102
|
*
|
|
@@ -4099,7 +4106,7 @@ export interface RaiseAuditCertificateExpiredEventData extends RaiseAuditCertifi
|
|
|
4099
4106
|
*
|
|
4100
4107
|
* There are no additional Properties defined for this EventType.
|
|
4101
4108
|
*/
|
|
4102
|
-
export interface RaiseAuditCertificateInvalidEventData extends RaiseAuditCertificateEventData {
|
|
4109
|
+
export interface RaiseAuditCertificateInvalidEventData extends RaiseAuditCertificateEventData {}
|
|
4103
4110
|
/**
|
|
4104
4111
|
* This EventType inherits all Properties of the AuditCertificateEventType.
|
|
4105
4112
|
*
|
|
@@ -4109,7 +4116,7 @@ export interface RaiseAuditCertificateInvalidEventData extends RaiseAuditCertifi
|
|
|
4109
4116
|
* If a trust chain is involved then the certificate that failed in the trust chain should be described.
|
|
4110
4117
|
* There are no additional Properties defined for this EventType.
|
|
4111
4118
|
*/
|
|
4112
|
-
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData {
|
|
4119
|
+
export interface RaiseAuditCertificateUntrustedEventData extends RaiseAuditCertificateEventData {}
|
|
4113
4120
|
/**
|
|
4114
4121
|
* This EventType inherits all Properties of the AuditCertificateEventType.
|
|
4115
4122
|
*
|
|
@@ -4132,7 +4139,7 @@ export interface RaiseAuditCertificateRevokedEventData extends RaiseAuditCertifi
|
|
|
4132
4139
|
*
|
|
4133
4140
|
* There are no additional Properties defined for this EventType
|
|
4134
4141
|
*/
|
|
4135
|
-
export interface RaiseAuditCertificateMismatchEventData extends RaiseAuditCertificateEventData {
|
|
4142
|
+
export interface RaiseAuditCertificateMismatchEventData extends RaiseAuditCertificateEventData {}
|
|
4136
4143
|
|
|
4137
4144
|
const opts = { multiArgs: false };
|
|
4138
4145
|
OPCUAServer.prototype.initialize = withCallback(OPCUAServer.prototype.initialize, opts);
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* @module node-opcua-server
|
|
3
3
|
*/
|
|
4
4
|
// tslint:disable:no-console
|
|
5
|
-
import { EventEmitter } from "events";
|
|
5
|
+
import { EventEmitter } from "node:events";
|
|
6
6
|
import chalk from "chalk";
|
|
7
7
|
|
|
8
8
|
import { assert } from "node-opcua-assert";
|
|
9
|
-
import { UAString } from "node-opcua-basic-types";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
OPCUAClientBaseOptions,
|
|
15
|
-
ResponseCallback
|
|
16
|
-
} from "node-opcua-client";
|
|
17
|
-
import { make_debugLog, checkDebugFlag, make_warningLog } from "node-opcua-debug";
|
|
9
|
+
import type { UAString } from "node-opcua-basic-types";
|
|
10
|
+
import type { OPCUACertificateManager } from "node-opcua-certificate-manager";
|
|
11
|
+
import { coerceLocalizedText, type LocalizedTextOptions, OPCUAClientBase, type ResponseCallback } from "node-opcua-client";
|
|
12
|
+
import { exploreCertificate } from "node-opcua-crypto/web";
|
|
13
|
+
import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
|
|
18
14
|
import { resolveFullyQualifiedDomainName } from "node-opcua-hostname";
|
|
19
15
|
import { coerceSecurityPolicy, MessageSecurityMode, SecurityPolicy } from "node-opcua-secure-channel";
|
|
20
16
|
import {
|
|
21
17
|
RegisterServer2Request,
|
|
22
|
-
RegisterServer2Response,
|
|
18
|
+
type RegisterServer2Response,
|
|
23
19
|
RegisterServerRequest,
|
|
24
|
-
RegisterServerResponse
|
|
20
|
+
type RegisterServerResponse
|
|
25
21
|
} from "node-opcua-service-discovery";
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
import {
|
|
23
|
+
type ApplicationType,
|
|
24
|
+
type EndpointDescription,
|
|
25
|
+
MdnsDiscoveryConfiguration,
|
|
26
|
+
type RegisteredServerOptions
|
|
27
|
+
} from "node-opcua-types";
|
|
28
|
+
import { type IRegisterServerManager, RegisterServerManagerStatus } from "./i_register_server_manager";
|
|
29
|
+
|
|
30
|
+
const _doDebug = checkDebugFlag("REGISTER_LDS");
|
|
32
31
|
const debugLog = make_debugLog("REGISTER_LDS");
|
|
33
32
|
const warningLog = make_warningLog("REGISTER_LDS");
|
|
34
33
|
|
|
35
|
-
|
|
36
34
|
const g_DefaultRegistrationServerTimeout = 8 * 60 * 1000; // 8 minutes
|
|
37
35
|
|
|
38
36
|
function securityPolicyLevel(securityPolicy: UAString): number {
|
|
@@ -110,7 +108,7 @@ function constructRegisteredServer(server: IPartialServer, isOnline: boolean): R
|
|
|
110
108
|
assert(!isOnline || discoveryUrls.length >= 1, "expecting some discoveryUrls if we go online .... ");
|
|
111
109
|
|
|
112
110
|
const info = exploreCertificate(server.getCertificate());
|
|
113
|
-
const
|
|
111
|
+
const _commonName = info.tbsCertificate.subject.commonName ?? "";
|
|
114
112
|
|
|
115
113
|
const serverUri = info.tbsCertificate.extensions?.subjectAltName?.uniformResourceIdentifier[0];
|
|
116
114
|
// c8 ignore next
|
|
@@ -122,7 +120,7 @@ function constructRegisteredServer(server: IPartialServer, isOnline: boolean): R
|
|
|
122
120
|
"\n subjectAltName : ",
|
|
123
121
|
info.tbsCertificate.extensions?.subjectAltName,
|
|
124
122
|
"\n commonName : ",
|
|
125
|
-
info.tbsCertificate.subject.commonName
|
|
123
|
+
info.tbsCertificate.subject.commonName,
|
|
126
124
|
"\n serverInfo.applicationUri : ",
|
|
127
125
|
server.serverInfo.applicationUri
|
|
128
126
|
);
|
|
@@ -203,7 +201,7 @@ async function sendRegisterServerRequest(server: IPartialServer, client: ClientB
|
|
|
203
201
|
const request = constructRegisterServer2Request(server, isOnline);
|
|
204
202
|
|
|
205
203
|
await new Promise<void>((resolve, reject) => {
|
|
206
|
-
client.performMessageTransaction(request, (err: Error | null,
|
|
204
|
+
client.performMessageTransaction(request, (err: Error | null, _response?: RegisterServer2Response) => {
|
|
207
205
|
if (!err) {
|
|
208
206
|
// RegisterServerResponse
|
|
209
207
|
debugLog("RegisterServerManager#_registerServer sendRegisterServer2Request has succeeded (isOnline", isOnline, ")");
|
|
@@ -213,7 +211,7 @@ async function sendRegisterServerRequest(server: IPartialServer, client: ClientB
|
|
|
213
211
|
debugLog("RegisterServerManager#_registerServer" + " falling back to using sendRegisterServerRequest instead");
|
|
214
212
|
// fall back to
|
|
215
213
|
const request1 = constructRegisterServerRequest(server, isOnline);
|
|
216
|
-
client.performMessageTransaction(request1, (err1: Error | null,
|
|
214
|
+
client.performMessageTransaction(request1, (err1: Error | null, _response1?: RegisterServerResponse) => {
|
|
217
215
|
if (!err1) {
|
|
218
216
|
debugLog(
|
|
219
217
|
"RegisterServerManager#_registerServer sendRegisterServerRequest " + "has succeeded (isOnline",
|
|
@@ -227,10 +225,9 @@ async function sendRegisterServerRequest(server: IPartialServer, client: ClientB
|
|
|
227
225
|
isOnline,
|
|
228
226
|
")"
|
|
229
227
|
);
|
|
230
|
-
reject(err1
|
|
228
|
+
reject(err1);
|
|
231
229
|
});
|
|
232
230
|
});
|
|
233
|
-
|
|
234
231
|
});
|
|
235
232
|
}
|
|
236
233
|
|
|
@@ -256,7 +253,7 @@ export interface RegisterServerManagerOptions {
|
|
|
256
253
|
let g_registeringClientCounter = 0;
|
|
257
254
|
/**
|
|
258
255
|
* RegisterServerManager is responsible to Register an opcua server on a LDS or LDS-ME server
|
|
259
|
-
* This class takes in charge :
|
|
256
|
+
* This class takes in charge :
|
|
260
257
|
* - the initial registration of a server
|
|
261
258
|
* - the regular registration renewal (every 8 minutes or so ...)
|
|
262
259
|
* - dealing with cases where LDS is not up and running when server starts.
|
|
@@ -349,7 +346,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
349
346
|
public async start(): Promise<void> {
|
|
350
347
|
debugLog("RegisterServerManager#start");
|
|
351
348
|
if (this.state !== RegisterServerManagerStatus.INACTIVE) {
|
|
352
|
-
throw new Error(
|
|
349
|
+
throw new Error(`RegisterServer process already started: ${RegisterServerManagerStatus[this.state]}`);
|
|
353
350
|
}
|
|
354
351
|
this.discoveryServerEndpointUrl = resolveFullyQualifiedDomainName(this.discoveryServerEndpointUrl);
|
|
355
352
|
|
|
@@ -359,7 +356,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
359
356
|
// This method is called without await to ensure it is non-blocking.
|
|
360
357
|
// The catch block handles any synchronous errors.
|
|
361
358
|
this.#_runRegistrationProcess().catch((err) => {
|
|
362
|
-
warningLog("Synchronous error in #_runRegistrationProcess: ",
|
|
359
|
+
warningLog("Synchronous error in #_runRegistrationProcess: ", err?.message);
|
|
363
360
|
});
|
|
364
361
|
}
|
|
365
362
|
|
|
@@ -370,7 +367,12 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
370
367
|
*/
|
|
371
368
|
async #_runRegistrationProcess(): Promise<void> {
|
|
372
369
|
while (this.getState() !== RegisterServerManagerStatus.WAITING && !this.#_isTerminating()) {
|
|
373
|
-
debugLog(
|
|
370
|
+
debugLog(
|
|
371
|
+
"RegisterServerManager#_runRegistrationProcess - state =",
|
|
372
|
+
RegisterServerManagerStatus[this.state],
|
|
373
|
+
"isTerminating =",
|
|
374
|
+
this.#_isTerminating()
|
|
375
|
+
);
|
|
374
376
|
try {
|
|
375
377
|
if (this.getState() === RegisterServerManagerStatus.INACTIVE) {
|
|
376
378
|
this.#_setState(RegisterServerManagerStatus.INITIALIZING);
|
|
@@ -399,7 +401,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
399
401
|
this.#_trigger_next();
|
|
400
402
|
return;
|
|
401
403
|
} catch (err) {
|
|
402
|
-
debugLog("RegisterServerManager#_runRegistrationProcess - operation failed!", (
|
|
404
|
+
debugLog("RegisterServerManager#_runRegistrationProcess - operation failed!", (err as Error).message);
|
|
403
405
|
if (!this.#_isTerminating()) {
|
|
404
406
|
this.#_setState(RegisterServerManagerStatus.INACTIVE);
|
|
405
407
|
this.#_emitEvent("serverRegistrationFailure");
|
|
@@ -413,7 +415,10 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
413
415
|
}
|
|
414
416
|
}
|
|
415
417
|
#_isTerminating(): boolean {
|
|
416
|
-
return
|
|
418
|
+
return (
|
|
419
|
+
this.getState() === RegisterServerManagerStatus.UNREGISTERING ||
|
|
420
|
+
this.getState() === RegisterServerManagerStatus.DISPOSING
|
|
421
|
+
);
|
|
417
422
|
}
|
|
418
423
|
|
|
419
424
|
/**
|
|
@@ -435,30 +440,28 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
435
440
|
assert(typeof this.discoveryServerEndpointUrl === "string");
|
|
436
441
|
assert(this.state === RegisterServerManagerStatus.INITIALIZING);
|
|
437
442
|
|
|
438
|
-
|
|
439
443
|
this.selectedEndpoint = undefined;
|
|
440
444
|
|
|
441
|
-
const applicationName = coerceLocalizedText(this.server.serverInfo.applicationName
|
|
445
|
+
const applicationName = coerceLocalizedText(this.server.serverInfo.applicationName)?.text || undefined;
|
|
442
446
|
this.server.serverCertificateManager.referenceCounter++;
|
|
443
447
|
|
|
444
448
|
const server = this.server;
|
|
445
449
|
const prefix = `Client-${g_registeringClientCounter++}`;
|
|
446
450
|
const action = "initializing";
|
|
447
451
|
const ldsInfo = this.discoveryServerEndpointUrl;
|
|
448
|
-
const
|
|
449
|
-
const clientName = `${prefix} for server ${
|
|
452
|
+
const serverAppUri = this.server?.serverInfo.applicationUri ?? "";
|
|
453
|
+
const clientName = `${prefix} for server ${serverAppUri} to LDS ${ldsInfo} for ${action}`;
|
|
450
454
|
|
|
451
455
|
const registrationClient = OPCUAClientBase.create({
|
|
452
456
|
clientName,
|
|
453
457
|
applicationName,
|
|
454
|
-
applicationUri: server.serverInfo.applicationUri
|
|
458
|
+
applicationUri: server.serverInfo.applicationUri ?? "",
|
|
455
459
|
connectionStrategy: infinite_connectivity_strategy,
|
|
456
460
|
clientCertificateManager: server.serverCertificateManager,
|
|
457
461
|
certificateFile: server.certificateFile,
|
|
458
462
|
privateKeyFile: server.privateKeyFile
|
|
459
463
|
}) as ClientBaseEx;
|
|
460
464
|
|
|
461
|
-
|
|
462
465
|
registrationClient.on("backoff", (nbRetry: number, delay: number) => {
|
|
463
466
|
if (this.state !== RegisterServerManagerStatus.INITIALIZING) return; // Ignore event if state has changed
|
|
464
467
|
debugLog("RegisterServerManager - received backoff");
|
|
@@ -489,24 +492,18 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
489
492
|
return;
|
|
490
493
|
}
|
|
491
494
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
+
const endpoints = await registrationClient.getEndpoints();
|
|
496
|
+
if (!endpoints || endpoints.length === 0) {
|
|
497
|
+
throw new Error("Cannot retrieve endpoints from discovery server");
|
|
498
|
+
}
|
|
499
|
+
const endpoint = findSecureEndpoint(endpoints);
|
|
495
500
|
if (!endpoint) {
|
|
496
501
|
throw new Error("Cannot find Secure endpoint");
|
|
497
502
|
}
|
|
498
503
|
|
|
499
|
-
|
|
500
|
-
assert(endpoint.serverCertificate);
|
|
501
|
-
this.selectedEndpoint = endpoint;
|
|
502
|
-
} else {
|
|
503
|
-
this.selectedEndpoint = undefined;
|
|
504
|
-
}
|
|
504
|
+
this.selectedEndpoint = endpoint.serverCertificate ? endpoint : undefined;
|
|
505
505
|
|
|
506
506
|
this._serverEndpoints = registrationClient._serverEndpoints;
|
|
507
|
-
} catch (err) {
|
|
508
|
-
// Do not set state to INACTIVE or rethrow here, let the caller handle it.
|
|
509
|
-
throw err;
|
|
510
507
|
} finally {
|
|
511
508
|
if (this._registration_client) {
|
|
512
509
|
const tmp = this._registration_client;
|
|
@@ -557,7 +554,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
557
554
|
this.#_setState(RegisterServerManagerStatus.REGISTERING);
|
|
558
555
|
this.#_emitEvent("serverRegistrationPending");
|
|
559
556
|
|
|
560
|
-
this.#_registerOrUnregisterServer(/*isOnline=*/true)
|
|
557
|
+
this.#_registerOrUnregisterServer(/*isOnline=*/ true)
|
|
561
558
|
.then(() => after_register())
|
|
562
559
|
.catch((err) => after_register(err));
|
|
563
560
|
}, this.timeout);
|
|
@@ -577,7 +574,6 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
577
574
|
this._registrationTimerId = null;
|
|
578
575
|
}
|
|
579
576
|
|
|
580
|
-
|
|
581
577
|
// Immediately set state to signal a stop
|
|
582
578
|
this.#_setState(RegisterServerManagerStatus.UNREGISTERING);
|
|
583
579
|
|
|
@@ -586,7 +582,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
586
582
|
|
|
587
583
|
if (this.selectedEndpoint) {
|
|
588
584
|
try {
|
|
589
|
-
await this.#_registerOrUnregisterServer(/* isOnline= */false);
|
|
585
|
+
await this.#_registerOrUnregisterServer(/* isOnline= */ false);
|
|
590
586
|
this.#_setState(RegisterServerManagerStatus.UNREGISTERED);
|
|
591
587
|
this.#_emitEvent("serverUnregistered");
|
|
592
588
|
} catch (err) {
|
|
@@ -615,9 +611,12 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
615
611
|
debugLog("RegisterServerManager#_registerServer isOnline:", isOnline);
|
|
616
612
|
|
|
617
613
|
assert(this.selectedEndpoint, "must have a selected endpoint");
|
|
618
|
-
assert(this.server
|
|
614
|
+
assert(this.server?.serverType !== undefined, " must have a valid server Type");
|
|
619
615
|
|
|
620
|
-
|
|
616
|
+
if (!this.server) {
|
|
617
|
+
throw new Error("RegisterServerManager: server is not set");
|
|
618
|
+
}
|
|
619
|
+
const server = this.server;
|
|
621
620
|
const selectedEndpoint = this.selectedEndpoint;
|
|
622
621
|
if (!selectedEndpoint) {
|
|
623
622
|
warningLog("Warning: cannot register server - no endpoint available");
|
|
@@ -626,18 +625,18 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
626
625
|
}
|
|
627
626
|
|
|
628
627
|
server.serverCertificateManager.referenceCounter++;
|
|
629
|
-
const applicationName: string | undefined = coerceLocalizedText(server.serverInfo.applicationName
|
|
628
|
+
const applicationName: string | undefined = coerceLocalizedText(server.serverInfo.applicationName)?.text || undefined;
|
|
630
629
|
|
|
631
630
|
const prefix = `Client-${g_registeringClientCounter++}`;
|
|
632
631
|
const action = isOnline ? "registering" : "unregistering";
|
|
633
632
|
const ldsInfo = this.discoveryServerEndpointUrl;
|
|
634
|
-
const
|
|
635
|
-
const clientName = `${prefix} for server ${
|
|
633
|
+
const serverAppUri = server.serverInfo.applicationUri ?? "";
|
|
634
|
+
const clientName = `${prefix} for server ${serverAppUri} to LDS ${ldsInfo} for ${action}`;
|
|
636
635
|
|
|
637
636
|
const client = OPCUAClientBase.create({
|
|
638
637
|
clientName,
|
|
639
638
|
applicationName,
|
|
640
|
-
applicationUri: server.serverInfo.applicationUri
|
|
639
|
+
applicationUri: server.serverInfo.applicationUri ?? "",
|
|
641
640
|
connectionStrategy: no_retry_connectivity_strategy,
|
|
642
641
|
clientCertificateManager: server.serverCertificateManager,
|
|
643
642
|
|
|
@@ -645,8 +644,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
645
644
|
securityPolicy: coerceSecurityPolicy(selectedEndpoint.securityPolicyUri),
|
|
646
645
|
serverCertificate: selectedEndpoint.serverCertificate,
|
|
647
646
|
certificateFile: server.certificateFile,
|
|
648
|
-
privateKeyFile: server.privateKeyFile
|
|
649
|
-
|
|
647
|
+
privateKeyFile: server.privateKeyFile
|
|
650
648
|
}) as ClientBaseEx;
|
|
651
649
|
client.on("backoff", (nbRetry, delay) => {
|
|
652
650
|
debugLog(client.clientCertificateManager, "backoff trying to connect to the LDS has failed", nbRetry, delay);
|
|
@@ -654,30 +652,36 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
654
652
|
|
|
655
653
|
this._registration_client = client;
|
|
656
654
|
|
|
657
|
-
|
|
655
|
+
const endpointUrl = selectedEndpoint.endpointUrl;
|
|
656
|
+
if (!endpointUrl) {
|
|
657
|
+
throw new Error("selectedEndpoint.endpointUrl is missing — cannot connect to LDS");
|
|
658
|
+
}
|
|
659
|
+
debugLog("lds endpoint uri : ", endpointUrl);
|
|
658
660
|
|
|
659
|
-
const state = isOnline ? "
|
|
661
|
+
const state = isOnline ? "RegisterServer" : "UnRegisterServer";
|
|
660
662
|
try {
|
|
661
|
-
await client.connect(
|
|
663
|
+
await client.connect(endpointUrl);
|
|
662
664
|
|
|
663
665
|
// Check state again after connection is established
|
|
664
666
|
if (this.getState() === expectedState) {
|
|
665
667
|
try {
|
|
666
|
-
await sendRegisterServerRequest(server, client as ClientBaseEx, isOnline)
|
|
668
|
+
await sendRegisterServerRequest(server, client as ClientBaseEx, isOnline);
|
|
667
669
|
} catch (err) {
|
|
668
670
|
if (this.getState() !== expectedState) {
|
|
669
|
-
warningLog(
|
|
670
|
-
|
|
671
|
+
warningLog(
|
|
672
|
+
`${state} '${this.server?.serverInfo.applicationUri}' to the LDS has failed during secure connection to the LDS server`
|
|
673
|
+
);
|
|
674
|
+
warningLog(chalk.red(" Error message:"), (err as Error).message); // Do not rethrow here, let the caller
|
|
671
675
|
}
|
|
672
676
|
}
|
|
673
677
|
} else {
|
|
674
678
|
debugLog("RegisterServerManager#_registerServer: aborted ");
|
|
675
679
|
}
|
|
676
|
-
|
|
677
680
|
} catch (err) {
|
|
678
681
|
if (this.getState() !== expectedState) {
|
|
679
|
-
|
|
680
|
-
|
|
682
|
+
warningLog(
|
|
683
|
+
`${state} '${this.server?.serverInfo.applicationUri}' cannot connect to LDS at endpoint ${client.clientName}, ${selectedEndpoint.endpointUrl} :`
|
|
684
|
+
);
|
|
681
685
|
warningLog(chalk.red(" Error message:"), (err as Error).message);
|
|
682
686
|
}
|
|
683
687
|
} finally {
|
|
@@ -700,8 +704,7 @@ export class RegisterServerManager extends EventEmitter implements IRegisterServ
|
|
|
700
704
|
if (this._registration_client) {
|
|
701
705
|
const client = this._registration_client;
|
|
702
706
|
this._registration_client = null;
|
|
703
|
-
debugLog("RegisterServerManager#_cancel_pending_client_if_any "
|
|
704
|
-
+ "=> wee need to disconnect_registration_client");
|
|
707
|
+
debugLog("RegisterServerManager#_cancel_pending_client_if_any " + "=> wee need to disconnect_registration_client");
|
|
705
708
|
try {
|
|
706
709
|
await client.disconnect();
|
|
707
710
|
} catch (err) {
|