/// <summary> /// Update the reverse connect configuration from the application configuration. /// </summary> private void UpdateConfiguration(ApplicationConfiguration configuration) { ClearConnections(true); // get the configuration for the reverse connections. var reverseConnect = configuration.ServerConfiguration.ReverseConnect; // add configuration reverse client connection properties. if (reverseConnect != null) { lock (m_connectionsLock) { m_connectInterval = reverseConnect.ConnectInterval > 0 ? reverseConnect.ConnectInterval : DefaultReverseConnectInterval; m_connectTimeout = reverseConnect.ConnectTimeout > 0 ? reverseConnect.ConnectTimeout : DefaultReverseConnectTimeout; m_rejectTimeout = reverseConnect.RejectTimeout > 0 ? reverseConnect.RejectTimeout : DefaultReverseConnectRejectTimeout; foreach (var client in reverseConnect.Clients) { var uri = Utils.ParseUri(client.EndpointUrl); if (uri != null) { if (m_connections.ContainsKey(uri)) { Utils.Trace("Warning: ServerConfiguration.ReverseConnect contains duplicate EndpointUrl: {0}.", uri); } else { m_connections[uri] = new ReverseConnectProperty(uri, client.Timeout, client.MaxSessionCount, true, client.Enabled); Utils.Trace("Reverse Connection added for EndpointUrl: {0}.", uri); } } } } } }
/// <summary> /// Track reverse connection status. /// </summary> protected override void OnConnectionStatusChanged(object sender, ConnectionStatusEventArgs e) { lock (m_connections) { ReverseConnectProperty reverseConnection = null; if (m_connections.TryGetValue(e.EndpointUrl, out reverseConnection)) { ServiceResult priorStatus = reverseConnection.ServiceResult; if (ServiceResult.IsBad(e.ChannelStatus)) { reverseConnection.ServiceResult = e.ChannelStatus; if (e.ChannelStatus.Code == StatusCodes.BadTcpMessageTypeInvalid) { reverseConnection.State = ReverseConnectState.Rejected; reverseConnection.RejectTime = DateTime.UtcNow; Utils.Trace($"Client Rejected Connection! [{reverseConnection.State}][{e.EndpointUrl}]"); return; } else { reverseConnection.State = ReverseConnectState.Closed; Utils.Trace($"Connection Error! [{reverseConnection.State}][{e.EndpointUrl}]"); return; } } reverseConnection.State = e.Closed ? ReverseConnectState.Closed : ReverseConnectState.Connected; Utils.Trace($"New Connection State! [{reverseConnection.State}][{e.EndpointUrl}]"); } else { Utils.Trace($"Warning: Status changed for unknown connection: [{e.ChannelStatus}][{e.EndpointUrl}]"); } } }
/// <summary> /// Update the reverse connect configuration from the application configuration. /// </summary> private void UpdateConfiguration(ApplicationConfiguration configuration) { ClearConnections(true); // get the configuration for the reverse connections. var reverseConnect = configuration.ServerConfiguration.ReverseConnect; // add configuration reverse client connection properties. if (reverseConnect != null) { lock (m_connections) { m_connectInterval = reverseConnect.ConnectInterval > 0 ? reverseConnect.ConnectInterval : DefaultReverseConnectInterval; m_connectTimeout = reverseConnect.ConnectTimeout > 0 ? reverseConnect.ConnectTimeout : DefaultReverseConnectTimeout; m_rejectTimeout = reverseConnect.RejectTimeout > 0 ? reverseConnect.RejectTimeout : DefaultReverseConnectRejectTimeout; foreach (var client in reverseConnect.Clients) { var uri = Utils.ParseUri(client.EndpointUrl); if (uri != null) { m_connections[uri] = new ReverseConnectProperty(uri, client.Timeout, true); } } } } }
/// <summary> /// Add a reverse connection url. /// </summary> public virtual void AddReverseConnection(Uri url, int timeout = 0) { var reverseConnection = new ReverseConnectProperty(url, timeout, false); lock (m_connections) { m_connections[url] = reverseConnection; StartTimer(false); } }
/// <summary> /// Add a reverse connection url. /// </summary> public virtual void AddReverseConnection(Uri url, int timeout = 0, int maxSessionCount = 0, bool enabled = true) { if (m_connections.ContainsKey(url)) { throw new ArgumentException("Connection for specified clientUrl is already configured", nameof(url)); } else { var reverseConnection = new ReverseConnectProperty(url, timeout, maxSessionCount, false, enabled); lock (m_connectionsLock) { m_connections[url] = reverseConnection; Utils.Trace("Reverse Connection added for EndpointUrl: {0}.", url); StartTimer(false); } } }