/// <summary> /// Bootstraps the Tcp IoT Hub Gateway /// </summary> /// <param name="certificate2">Server certificate for Tls</param> /// <param name="threadCount"># of threads to be used</param> /// <param name="cancellationToken">Cancellation flag</param> /// <returns></returns> public async Task RunAsync(int threadCount, CancellationToken cancellationToken) { Contract.Requires(threadCount > 0); try { var firstHandler = new DataBasedTenancyHandler(); await this.RunAsync(threadCount, cancellationToken, firstHandler, false); } catch (Exception ex) { //BootstrapperEventSource.Log.Error("Failed to start", ex); this.CloseAsync(); } }
public async Task RunAsync2(int threadCount, CancellationToken cancellationToken, X509Certificate2 cert = null, ServerTlsSettings serverTlsSettings = null, RemoteCertificateValidationCallback rcvb = null) { Contract.Requires(threadCount > 0); try { //BootstrapperEventSource.Log.Info("Starting", null); //PerformanceCounters.ConnectionsEstablishedTotal.RawValue = 0; //PerformanceCounters.ConnectionsCurrent.RawValue = 0; this.parentEventLoopGroup = new MultithreadEventLoopGroup(1); this.eventLoopGroup = new MultithreadEventLoopGroup(threadCount); ChannelHandlerAdapter handler = null; if (cert != null && serverTlsSettings != null) { handler = new TlsHandler(stream => new SslStream(stream, true, rcvb), serverTlsSettings); } else { handler = new DataBasedTenancyHandler(); } ServerBootstrap bootstrap = this.SetupBootstrap(handler); //BootstrapperEventSource.Log.Info($"Initializing TLS endpoint on port {this.settings.ListeningPort.ToString()} with certificate {this.tlsCertificate.Thumbprint}.", null); this.serverChannel = await bootstrap.BindAsync(IPAddress.Any, rcvb != null?this.settings.SecureListeningPort : this.settings.ListeningPort); this.serverChannel.CloseCompletion.LinkOutcome(this.closeCompletionSource); cancellationToken.Register(this.CloseAsync); //BootstrapperEventSource.Log.Info("Started", null); } catch (Exception ex) { //BootstrapperEventSource.Log.Error("Failed to start", ex); this.CloseAsync(); } }