Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// tslint:disable:no-console
import * as chalk from "chalk";
import { EventEmitter } from "events";
import * as _ from "underscore";
import { assert } from "node-opcua-assert";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { ObjectRegistry } from "node-opcua-object-registry";
import { StatusCode, StatusCodes } from "node-opcua-status-code";
import { PublishRequest, PublishResponse, SubscriptionAcknowledgement } from "node-opcua-types";
import { Subscription } from "./server_subscription";
import { SubscriptionState } from "./server_subscription";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
function traceLog(...args: [any?, ...any[]]) {
if (!doDebug) {
return;
}
const a: string[] = args.map((x?: any) => x!);
a.unshift(chalk.yellow(" TRACE "));
console.log.apply(null, a as [any?, ...any[]]);
}
export interface ServerSidePublishEngineOptions {
maxPublishRequestInQueue?: number;
}
interface PublishData {
request: PublishRequest;
/**
* @module node-opcua-server
*/
// tslint:disable:no-console
import * as chalk from "chalk";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { ServerSidePublishEngine } from "./server_publish_engine";
import { Subscription } from "./server_subscription";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
/**
* the ServerSidePublishEngineForOrphanSubscription is keeping track of
* live subscription that have been detached from timed out session.
* It takes care of providing back those subscription to any session that
* will claim them again with transferSubscription service
* It also make sure that subscription are properly disposed when they expire.
*
* @internal
*/
export class ServerSidePublishEngineForOrphanSubscription extends ServerSidePublishEngine {
constructor(options: any) {
super(options);
}
import {
BaseUAObject,
check_options_correctness_against_schema,
ConstructorFuncWithSchema,
FieldCategory,
FieldType,
initialize_field,
initialize_field_array,
StructuredTypeSchema
} from "node-opcua-factory";
import { ExpandedNodeId, NodeIdType } from "node-opcua-nodeid";
import { TypeDictionary } from "./parse_binary_xsd";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
export function getOrCreateConstructor(
fieldType: string,
typeDictionary: TypeDictionary,
encodingDefaultBinary?: ExpandedNodeId,
encodingDefaultXml?: ExpandedNodeId
): AnyConstructorFunc {
if (typeDictionary.hasStructuredType(fieldType)) {
return typeDictionary.getStructureTypeConstructor(fieldType);
}
const schema = typeDictionary.structuredTypes[fieldType];
// istanbul ignore next
if (!schema) {
throw new Error("Unknown type in dictionary " + fieldType);
const _ = require("underscore");
const assert = require("node-opcua-assert").assert;
const once = require("once");
const delayed = require("delayed");
const endpoints_service = require("node-opcua-service-endpoints");
const GetEndpointsRequest = endpoints_service.GetEndpointsRequest;
const GetEndpointsResponse = endpoints_service.GetEndpointsResponse;
const MessageSecurityMode = require("node-opcua-service-secure-channel").MessageSecurityMode;
const toURI = require("node-opcua-secure-channel").toURI;
const SecurityPolicy = require("node-opcua-secure-channel").SecurityPolicy;
const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);
const OPCUASecureObject = require("node-opcua-common").OPCUASecureObject;
const ClientSecureChannelLayer = require("node-opcua-secure-channel/src/client/client_secure_channel_layer").ClientSecureChannelLayer;
const ClientSession = require("./client_session").ClientSession;
const defaultConnectionStrategy = {
initialDelay: 1000,
maxDelay: 20*1000,// 20 seconds
maxRetry: -1, // infinite
randomisationFactor: 0.1
};
/**
* @class OPCUAClientBase
const BaseNode = require("../base_node").BaseNode;
const AttributeIds = require("node-opcua-data-model").AttributeIds;
const NodeClass = require("node-opcua-data-model").NodeClass;
const TimeZoneDataType = require("node-opcua-common").TimeZoneDataType;
const StateMachine = require("../state_machine/finite_state_machine").StateMachine;
const UATwoStateVariable = require("../ua_two_state_variable").UATwoStateVariable;
const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;
const coerceLocalizedText = require("node-opcua-data-model").coerceLocalizedText;
const LocalizedText = require("node-opcua-data-model").LocalizedText;
const NodeId = require("node-opcua-nodeid").NodeId;
const EventData = require("../address_space_add_event_type").EventData;
const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);
const AddressSpace = require("../address_space").AddressSpace;
const Namespace = require("../namespace").Namespace;
const SessionContext = require("../session_context").SessionContext;
const utils = require("node-opcua-utils");
function _visit(self, node, prefix) {
const aggregates = node.getAggregates();
aggregates.forEach(function(aggregate) {
if (aggregate instanceof UAVariable) {
let name = aggregate.browseName.toString();
name = utils.lowerFirstLetter(name);
import * as chalk from "chalk";
import { EventEmitter } from "events";
import { assert } from "node-opcua-assert";
import { ServerState } from "node-opcua-common";
import { VariableIds } from "node-opcua-constants";
import { DataValue } from "node-opcua-data-value";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { coerceNodeId } from "node-opcua-nodeid";
import { ErrorCallback } from "node-opcua-secure-channel";
import { StatusCodes } from "node-opcua-status-code";
import { ClientSessionImpl } from "./private/client_session_impl";
const serverStatusStateNodeId = coerceNodeId(VariableIds.Server_ServerStatus_State);
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
const warningLog = debugLog;
const emptyCallback = (err?: Error) => {
};
export interface ClientSessionKeepAliveManagerEvents {
on(event: "keepalive", eventHandler: (lastKnownServerState: ServerState) => void): ClientSessionKeepAliveManager;
}
export class ClientSessionKeepAliveManager extends EventEmitter implements ClientSessionKeepAliveManagerEvents {
private readonly session: ClientSessionImpl;
private timerId?: NodeJS.Timer;
private pingTimeout: number;
private lastKnownState?: ServerState;
private checkInterval: number;
const ClientTCP_transport = require("node-opcua-transport").ClientTCP_transport;
const hexDump = require("node-opcua-debug").hexDump;
const StatusCodes = require("node-opcua-status-code").StatusCodes;
const crypto_utils = require("node-opcua-crypto");
const verify_message_chunk = require("node-opcua-chunkmanager").verify_message_chunk;
const MessageSecurityMode = require("node-opcua-service-secure-channel").MessageSecurityMode;
const backoff = require("backoff");
const debug = require("node-opcua-debug");
const debugLog = debug.make_debugLog(__filename);
const doDebug = debug.checkDebugFlag(__filename);
const get_clock_tick = require("node-opcua-utils").get_clock_tick;
const readMessageHeader = require("node-opcua-chunkmanager").readMessageHeader;
const MessageBuilder = require("../message_builder").MessageBuilder;
const messageHeaderToString = require("../message_header_to_string").messageHeaderToString;
const MessageChunker = require("../message_chunker").MessageChunker;
const secure_channel_service = require("../services");
const securityPolicy_m = require("../security_policy");
const SecurityPolicy = securityPolicy_m.SecurityPolicy;
const OpenSecureChannelRequest = secure_channel_service.OpenSecureChannelRequest;
const CloseSecureChannelRequest = secure_channel_service.CloseSecureChannelRequest;
const OpenSecureChannelResponse = secure_channel_service.OpenSecureChannelResponse;
const AsymmetricAlgorithmSecurityHeader = secure_channel_service.AsymmetricAlgorithmSecurityHeader;
import chalk from "chalk";
import { EventEmitter } from "events";
import * as _ from "underscore";
import { assert } from "node-opcua-assert";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { PublishRequest, PublishResponse, RepublishRequest, RepublishResponse } from "node-opcua-service-subscription";
import { StatusCodes } from "node-opcua-status-code";
import { ClientSession, SubscriptionId } from "../client_session";
import { ClientSubscription } from "../client_subscription";
import { ClientSessionImpl } from "../private/client_session_impl";
import { ClientSubscriptionImpl } from "./client_subscription_impl";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
/**
* A client side implementation to deal with publish service.
*
* @class ClientSidePublishEngine
* The ClientSidePublishEngine encapsulates the mechanism to
* deal with a OPCUA Server and constantly sending PublishRequest
* The ClientSidePublishEngine also performs notification acknowledgements.
* Finally, ClientSidePublishEngine dispatch PublishResponse to the correct
* Subscription id callback
*
* @param session {ClientSession} - the client session
*
*
* @constructor
*/
MonitoredItemModifyRequest,
MonitoredItemModifyResult,
MonitoringMode, SetMonitoringModeResponse
} from "node-opcua-service-subscription";
import { StatusCode, StatusCodes } from "node-opcua-status-code";
import { MonitoredItemCreateRequestOptions } from "node-opcua-types";
import { ClientMonitoredItemBase } from "./client_monitored_item_base";
import { SetMonitoringModeRequestLike } from "./client_session";
import { ClientSubscription } from "./client_subscription";
import { Callback, ErrorCallback } from "./common";
import { ClientMonitoredItemImpl } from "./private/client_monitored_item_impl";
import { ClientSessionImpl } from "./private/client_session_impl";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
/**
* @internal
*/
export class ClientMonitoredItemToolbox {
public static _toolbox_monitor(
subscription: ClientSubscription,
timestampsToReturn: TimestampsToReturn,
monitoredItems: ClientMonitoredItemBase[],
done: ErrorCallback
) {
assert(_.isFunction(done));
const itemsToCreate: MonitoredItemCreateRequestOptions[] = [];
for (const monitoredItem of monitoredItems) {
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { ExpandedNodeId } from "node-opcua-nodeid";
import {
DataTypeFactory,
} from "./datatype_factory";
import {
ConstructorFuncWithSchema,
ConstructorFunc
} from "./constructor_type";
import { BaseUAObject } from "./factories_baseobject";
import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
let globalFactory: DataTypeFactory;
export function getStandartDataTypeFactory(): DataTypeFactory {
if (!globalFactory) {
globalFactory = new DataTypeFactory([]);
globalFactory.targetNamespace = "http://opcfoundation.org/UA/";
}
return globalFactory;
}
export function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema {
return getStandartDataTypeFactory().getStructureTypeConstructor(typeName);
}
export function hasStructuredType(typeName: string): boolean {
return getStandartDataTypeFactory().hasStructuredType(typeName);
}
export function getStructuredTypeSchema(typeName: string): StructuredTypeSchema {