lib/client/client_secure_channel_layer.js
/**
 * a ClientSecureChannelLayer represents the client side of the OPCUA secure channel.
 * @class ClientSecureChannelLayer
 * @extends EventEmitter
 * @uses MessageChunker
 * @uses MessageBuilder
 * @param options
 * @param {Number} [options.defaultSecureTokenLifetime=30000 = 30 seconds]
 * @param [options.securityMode=MessageSecurityMode.NONE]
 * @param [options.securityPolicy=SecurityPolicy.None]
 * @param [options.serverCertificate=null] the serverCertificate (required if securityMode!=None)
 * @param options.parent {OPCUAClientBase} parent
 * @param [options.factory] an factory that provides a method createObjectId(id) for the message builder
 * @param [options.transportTimeout = ClientSecureChannelLayer.defaultTransportTimeout = 10 seconds] the transport timeout interval in ms
 * @param [options.connectionStrategy] {Object}
 * @param [options.connectionStrategy.maxRetry      = 10]
 * @param [options.connectionStrategy.initialDelay  = 10]
 * @param [options.connectionStrategy.maxDelay      = 10000]
 * @constructor
 */
a ClientSecureChannelLayer represents the client side of the OPCUA secure channel.
a ClientSecureChannelLayer represents the client side of the OPCUA secure channel .
function ClientSecureChannelLayer(options) {
    options = options || {};
    EventEmitter.call(this);
    assert(this instanceof ClientSecureChannelLayer);
    var self = this;
    self._lastRequestId = 0;
    self.parent = options.parent;
    self.clientNonce = null; 
    self._request_queue = [];
    self.protocolVersion = 0;
    self.messageChunker = new MessageChunker({
        derivedKeys: null
    });
    self.defaultSecureTokenLifetime = options.defaultSecureTokenLifetime || 30000;
    self.securityMode = options.securityMode || MessageSecurityMode.NONE;
    self.securityPolicy = options.securityPolicy || SecurityPolicy.None;
    self.serverCertificate = options.serverCertificate;
    assert(self.securityMode !== MessageSecurityMode.INVALID, "invalid security Mode");
    if (self.securityMode !== MessageSecurityMode.NONE) {
        assert(self.serverCertificate instanceof Buffer, "Expecting a valid certificate when security mode is not None");
        assert(self.securityPolicy !== SecurityPolicy.None, "Security Policy None is not a valid choice");
    }
    self.messageBuilder = new MessageBuilder();
    self.messageBuilder.securityMode = self.securityMode;
    self.messageBuilder.privateKey = self.getPrivateKey();
    self._request_data = {};
    self.messageBuilder
        .on("message", _on_message_received.bind(this))
        .on("start_chunk", function () {
        }).on("error", function (err, requestId) {
            debugLog("request id = ", requestId,err);
            var request_data = self._request_data[requestId];
            console.log(" message was ");
            console.log(request_data);
            if (!request_data) {
                request_data = self._request_data[requestId + 1];
                console.log(" message was 2:", request_data ? request_data.request.toString() : "<null>");
            }
             xx console.log(request_data.request.toString());
        });
    self.__in_normal_close_operation = false;
    self._renew_security_token_requested = 0;
    self._timedout_request_count = 0;
    self.transportTimeout = options.transportTimeout || ClientSecureChannelLayer.defaultTransportTimeout;
    self.channelId = g_channelId;
    g_channelId += 1;
    options.connectionStrategy = options.connectionStrategy || {};
    self.connectionStrategy = {};
    self.connectionStrategy.maxRetry     = utils.isNullOrUndefined(options.connectionStrategy.maxRetry)   ? 10 : options.connectionStrategy.maxRetry;
    self.connectionStrategy.initialDelay = options.connectionStrategy.initialDelay || 10    ;
    self.connectionStrategy.maxDelay     = options.connectionStrategy.maxDelay     || 10000 ;
    var r = options.connectionStrategy.randomisationFactor;
    self.connectionStrategy.randomisationFactor = ( r === undefined ) ? 0 : r;
}
function ClientSecureChannelLayer ( options ) { options = options || { } ; EventEmitter . call ( this ) ; assert ( this instanceof ClientSecureChannelLayer ) ; var self = this ; self . _lastRequestId = 0 ; self . parent = options . parent ; self . clientNonce = null ; self . _request_queue = [ ] ; self . protocolVersion = 0 ; self . messageChunker = new MessageChunker ( { derivedKeys : null } ) ; self . defaultSecureTokenLifetime = options . defaultSecureTokenLifetime || 30000 ; self . securityMode = options . securityMode || MessageSecurityMode . NONE ; self . securityPolicy = options . securityPolicy || SecurityPolicy . None ; self . serverCertificate = options . serverCertificate ; assert ( self . securityMode !== MessageSecurityMode . INVALID , "invalid security Mode" ) ; if ( self . securityMode !== MessageSecurityMode . NONE ) { assert ( self . serverCertificate instanceof Buffer , "Expecting a valid certificate when security mode is not None" ) ; assert ( self . securityPolicy !== SecurityPolicy . None , "Security Policy None is not a valid choice" ) ; } self . messageBuilder = new MessageBuilder ( ) ; self . messageBuilder . securityMode = self . securityMode ; self . messageBuilder . privateKey = self . getPrivateKey ( ) ; self . _request_data = { } ; self . messageBuilder . on ( "message" , _on_message_received . bind ( this ) ) . on ( "start_chunk" , function ( ) { } ) . on ( "error" , function ( err , requestId ) { debugLog ( "request id = " , requestId , err ) ; var request_data = self . _request_data [ requestId ] ; console . log ( " message was " ) ; console . log ( request_data ) ; if ( ! request_data ) { request_data = self . _request_data [ requestId + 1 ] ; console . log ( " message was 2:" , request_data ? request_data . request . toString ( ) : "<null>" ) ; } } ) ; self . __in_normal_close_operation = false ; self . _renew_security_token_requested = 0 ; self . _timedout_request_count = 0 ; self . transportTimeout = options . transportTimeout || ClientSecureChannelLayer . defaultTransportTimeout ; self . channelId = g_channelId ; g_channelId += 1 ; options . connectionStrategy = options . connectionStrategy || { } ; self . connectionStrategy = { } ; self . connectionStrategy . maxRetry = utils . isNullOrUndefined ( options . connectionStrategy . maxRetry ) ? 10 : options . connectionStrategy . maxRetry ; self . connectionStrategy . initialDelay = options . connectionStrategy . initialDelay || 10 ; self . connectionStrategy . maxDelay = options . connectionStrategy . maxDelay || 10000 ; var r = options . connectionStrategy . randomisationFactor ; self . connectionStrategy . randomisationFactor = ( r === undefined ) ? 0 : r ; }
a ClientSecureChannelLayer represents the client side of the OPCUA secure channel.
a ClientSecureChannelLayer represents the client side of the OPCUA secure channel .
// will be created when needed // record tick2: when the first response chunk is received // request_data._tick2 = get_clock_tick(); // // xx console.log(request_data.request.toString());