/// <summary> /// Start the server. /// </summary> public void Start() { try { // Start the server. if (_serverSecureV6 != null) { _serverSecureV6.StartListeningThread(); } // Start the server. if (_serverSecureV4 != null) { _serverSecureV4.StartListeningThread(); } } catch (Exception) { if (_serverSecureV6 != null) { _serverSecureV6.Dispose(); } if (_serverSecureV4 != null) { _serverSecureV4.Dispose(); } _serverSecureV6 = null; _serverSecureV4 = null; throw; } }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. If disposing /// equals true, the method has been called directly or indirectly by a user's /// code. Managed and unmanaged resources can be disposed. If disposing equals /// false, the method has been called by the runtime from inside the finalizer /// and you should not reference other objects. Only unmanaged resources can /// be disposed. /// </summary> protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this._disposed) { // Note disposing has been done. _disposed = true; // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { if (_serverSecureV6 != null) { _serverSecureV6.Dispose(); } if (_serverSecureV4 != null) { _serverSecureV4.Dispose(); } } // Call the appropriate methods to clean up // unmanaged resources here. _serverSecureV6 = null; _serverSecureV4 = null; _lockObject = null; } }
/// <summary> /// Stop the server. /// </summary> public void Stop() { try { // Stop the server. if (_serverSecureV6 != null) { _serverSecureV6.StopListeningThread(); } // Stop the server. if (_serverSecureV4 != null) { _serverSecureV4.StopListeningThread(); } } catch { } finally { if (_serverSecureV6 != null) { _serverSecureV6.Dispose(); } if (_serverSecureV4 != null) { _serverSecureV4.Dispose(); } _serverSecureV6 = null; _serverSecureV4 = null; } }
/// <summary> /// Initialise the server. /// </summary> private void Init() { try { // Get the certificate reader. Nequeo.Security.Configuration.Reader certificateReader = new Nequeo.Security.Configuration.Reader(); Nequeo.Net.Configuration.Reader hostReader = new Nequeo.Net.Configuration.Reader(); string remoteHostPrefix = "TlsServerSingle_"; string remoteHostProviderFullName = remoteHostPrefix + "RemoteHost"; string socketProviderHostPrefix = "ProxyTlsServerSingle_"; string hostProviderFullNameSecure = socketProviderHostPrefix + "SocketProviderV6Ssl"; // If the host has not been set then get the // remote host from the configuration file. if (String.IsNullOrEmpty(_remoteHost)) { _remoteHost = hostReader.GetRemoteHost(remoteHostProviderFullName).Host; } // If the port has not been set then get the // remote port from the configuration file. if (_remotePort < 1) { _remotePort = hostReader.GetRemoteHost(remoteHostProviderFullName).Port; } // Get the data, add the remote server. _remoteServers = new ConcurrentBag <RemoteServer>(); _remoteServers.Add( new RemoteServer() { Name = _remoteHost, Host = _remoteHost, Port = _remotePort } ); // Start the server. _serverSecureV6 = new Nequeo.Net.ProxyServer(System.Net.IPAddress.IPv6Any, hostReader.GetServerHost(hostProviderFullNameSecure).Port, _remoteServers, _algorithmType); _serverSecureV6.Name = "Proxy TLS Server"; _serverSecureV6.ServiceName = "ProxyTLSServer"; _serverSecureV6.InterceptItems = _interceptItems; _serverSecureV6.Timeout = hostReader.GetServerHost(hostProviderFullNameSecure).ClientTimeOut; _serverSecureV6.ReadBufferSize = 32768; _serverSecureV6.WriteBufferSize = 32768; _serverSecureV6.ResponseBufferCapacity = 10000000; _serverSecureV6.RequestBufferCapacity = 10000000; // Start the server. _serverSecureV4 = new Nequeo.Net.ProxyServer(System.Net.IPAddress.Any, hostReader.GetServerHost(hostProviderFullNameSecure).Port, _remoteServers, _algorithmType); _serverSecureV4.Name = "Proxy TLS Server"; _serverSecureV4.ServiceName = "ProxyTLSServer"; _serverSecureV4.InterceptItems = _interceptItems; _serverSecureV4.Timeout = hostReader.GetServerHost(hostProviderFullNameSecure).ClientTimeOut; _serverSecureV4.ReadBufferSize = 32768; _serverSecureV4.WriteBufferSize = 32768; _serverSecureV4.ResponseBufferCapacity = 10000000; _serverSecureV4.RequestBufferCapacity = 10000000; // Look for the certificate information in the configuration file. // Get the certificate if any. X509Certificate2 serverCertificate = certificateReader.GetServerCredentials(); // If a certificate exists. if (serverCertificate != null) { // Get the secure servers. _serverSecureV6.UseSslConnection = true; _serverSecureV6.WaitForTlsCommand = true; _serverSecureV6.X509Certificate = serverCertificate; _serverSecureV4.UseSslConnection = true; _serverSecureV4.WaitForTlsCommand = true; _serverSecureV4.X509Certificate = serverCertificate; } } catch (Exception) { if (_serverSecureV6 != null) { _serverSecureV6.Dispose(); } if (_serverSecureV4 != null) { _serverSecureV4.Dispose(); } _serverSecureV6 = null; _serverSecureV4 = null; throw; } }
/// <summary> /// Initialise the server. /// </summary> private void Init() { try { // Get the data. _remoteServers = new ConcurrentBag <RemoteServer>(); _loadServers = Data.Helper.GetLoadBalanceServer(); // For each load balance server in the file // add to the remote server collection. foreach (Nequeo.Net.Data.contextServer item in _loadServers.servers) { // Add the remote server. _remoteServers.Add( new RemoteServer() { Name = item.name, Host = item.host, Port = item.port, Secure = item.secure } ); } // Get the certificate reader. Nequeo.Security.Configuration.Reader certificateReader = new Nequeo.Security.Configuration.Reader(); Nequeo.Net.Configuration.Reader hostReader = new Nequeo.Net.Configuration.Reader(); string socketProviderHostPrefix = "LoadBalance_"; string hostProviderFullName = socketProviderHostPrefix + "SocketProviderV6"; string hostProviderFullNameSecure = socketProviderHostPrefix + "SocketProviderV6Ssl"; // Start the server. _serverV6 = new Nequeo.Net.ProxyServer(System.Net.IPAddress.IPv6Any, hostReader.GetServerHost(hostProviderFullName).Port, _remoteServers, _algorithmType); _serverV6.Name = "Load Balance Server"; _serverV6.ServiceName = "LoadBalanceServer"; _serverV6.InterceptItems = _interceptItems; _serverV6.Timeout = hostReader.GetServerHost(hostProviderFullName).ClientTimeOut; _serverV6.ReadBufferSize = 32768; _serverV6.WriteBufferSize = 32768; _serverV6.ResponseBufferCapacity = 10000000; _serverV6.RequestBufferCapacity = 10000000; // Start the server. _serverV4 = new Nequeo.Net.ProxyServer(System.Net.IPAddress.Any, hostReader.GetServerHost(hostProviderFullName).Port, _remoteServers, _algorithmType); _serverV4.Name = "Load Balance Server"; _serverV4.ServiceName = "LoadBalanceServer"; _serverV4.InterceptItems = _interceptItems; _serverV4.Timeout = hostReader.GetServerHost(hostProviderFullName).ClientTimeOut; _serverV4.ReadBufferSize = 32768; _serverV4.WriteBufferSize = 32768; _serverV4.ResponseBufferCapacity = 10000000; _serverV4.RequestBufferCapacity = 10000000; // Start the server. _serverSecureV6 = new Nequeo.Net.ProxyServer(System.Net.IPAddress.IPv6Any, hostReader.GetServerHost(hostProviderFullNameSecure).Port, _remoteServers, _algorithmType); _serverSecureV6.Name = "Load Balance Server"; _serverSecureV6.ServiceName = "LoadBalanceServer"; _serverSecureV6.InterceptItems = _interceptItems; _serverSecureV6.Timeout = hostReader.GetServerHost(hostProviderFullNameSecure).ClientTimeOut; _serverSecureV6.ReadBufferSize = 32768; _serverSecureV6.WriteBufferSize = 32768; _serverSecureV6.ResponseBufferCapacity = 10000000; _serverSecureV6.RequestBufferCapacity = 10000000; // Start the server. _serverSecureV4 = new Nequeo.Net.ProxyServer(System.Net.IPAddress.Any, hostReader.GetServerHost(hostProviderFullNameSecure).Port, _remoteServers, _algorithmType); _serverSecureV4.Name = "Load Balance Server"; _serverSecureV4.ServiceName = "LoadBalanceServer"; _serverSecureV4.InterceptItems = _interceptItems; _serverSecureV4.Timeout = hostReader.GetServerHost(hostProviderFullNameSecure).ClientTimeOut; _serverSecureV4.ReadBufferSize = 32768; _serverSecureV4.WriteBufferSize = 32768; _serverSecureV4.ResponseBufferCapacity = 10000000; _serverSecureV4.RequestBufferCapacity = 10000000; try { // Look for the certificate information in the configuration file. // Get the certificate if any. X509Certificate2 serverCertificate = certificateReader.GetServerCredentials(); // If a certificate exists. if (serverCertificate != null) { // Get the secure servers. _serverSecureV6.UseSslConnection = true; _serverSecureV6.X509Certificate = serverCertificate; _serverSecureV4.UseSslConnection = true; _serverSecureV4.X509Certificate = serverCertificate; } } catch { } } catch (Exception) { if (_serverV6 != null) { _serverV6.Dispose(); } if (_serverSecureV6 != null) { _serverSecureV6.Dispose(); } if (_serverV4 != null) { _serverV4.Dispose(); } if (_serverSecureV4 != null) { _serverSecureV4.Dispose(); } _serverV6 = null; _serverSecureV6 = null; _serverV4 = null; _serverSecureV4 = null; throw; } }