public Task StartAsync(CancellationToken cancellationToken)
        {
            var certificate = new X509Certificate2(_options.CertificateFile);

            _runtime = new HalibutRuntime(_serviceFactory, certificate, _trustProvider);

            if (_options.Trust.Count > 0)
            {
                foreach (var item in _options.Trust)
                {
                    _trustProvider.Add(item);
                }
            }

            _runtime.OnUnauthorizedClientConnect = _options.OnUnauthorizedClientConnect;

            switch (_options.Mode)
            {
            case HalibutServerMode.Listening:
                _runtime.Listen(_options.Listen.EndPoint);
                break;

            case HalibutServerMode.Polling:
                _runtime.Poll(new Uri($"poll://{_options.Polling.Subscription}"), new ServiceEndPoint(new Uri(_options.Polling.BaseUri), _options.Polling.RemoteThumbPrint, _options.ProxyDetails));

                break;

            case HalibutServerMode.WebSocketPolling:
                _runtime.Poll(new Uri($"poll://{_options.Polling.Subscription}"), new ServiceEndPoint(new Uri(_options.Polling.BaseUri), _options.Polling.RemoteThumbPrint, _options.ProxyDetails));
                break;
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public void OctopusCanSendMessagesToWebSocketPollingTentacle()
        {
            var       services    = GetDelegateServiceFactory();
            const int octopusPort = 8450;

            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort);

            try
            {
                using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                    using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                    {
                        octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut");
                        octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                        tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint));

                        var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                        for (var i = 0; i < 2000; i++)
                        {
                            echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "...");
                        }
                    }
            }
            catch (NotSupportedException nse) when(nse.Message == "The netstandard build of this library cannot act as the client in a WebSocket polling setup")
            {
                Assert.Inconclusive("This test cannot run on the netstandard build");
            }
            finally
            {
                RemoveSslCertBindingFor("0.0.0.0:" + octopusPort);
            }
        }
Esempio n. 3
0
        public void OctopusCanSendMessagesToWebSocketPollingTentacle()
        {
            const int octopusPort = 8450;

            AddSslCertToLocalStoreAndRegisterFor("0.0.0.0:" + octopusPort);

            try
            {
                using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                    using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                    {
                        octopus.ListenWebSocket($"https://+:{octopusPort}/Halibut");
                        octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                        tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri($"wss://localhost:{octopusPort}/Halibut"), Certificates.SslThumbprint));

                        var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                        for (var i = 0; i < 2000; i++)
                        {
                            echo.SayHello("Deploy package A" + i).Should().Be("Deploy package A" + i + "...");
                        }
                    }
            }
            finally
            {
                RemoveSslCertBindingFor("0.0.0.0:" + octopusPort);
            }
        }
Esempio n. 4
0
        const string SslCertificateThumbprint = "6E5C6492129B75A4C83E1A23797AF6344092E5C2"; // For WebSockets. This is different to the internally configured thumbprint
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .MinimumLevel.Warning()
                         .CreateLogger();

            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                //Although this is the "Server" because it is the thing handling a request
                //in Octopus terms, this would be the Tentacle, being asked to do some work

                //Begin Listening Setup
                //server.Listen(endPoint);
                //server.Trust("2074529C99D93D5955FEECA859AEAC6092741205");
                //End Listening Setup

                //Begin Polling Setup
                //server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:8433"), "2074529C99D93D5955FEECA859AEAC6092741205"));
                //End Polling Setup

                //Begin WebSocket Polling Setup

                server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint));
                //End WebSocket Polling Setup

                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");
                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
Esempio n. 5
0
        public void FailWhenServerThrowsAnExceptionOnPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                    var ex   = Assert.Throws <HalibutClientException>(() => echo.Crash());
                    ex.Message.Should().Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contain("divide by zero");
                }
        }
Esempio n. 6
0
        public void OctopusCanSendMessagesToPollingTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                    for (var i = 0; i < 2000; i++)
                    {
                        Assert.That(echo.SayHello("Deploy package A" + i), Is.EqualTo("Deploy package A" + i + "..."));
                    }
                }
        }
Esempio n. 7
0
        public void OctopusCanSendMessagesToPollingTentacle()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                for (var i = 0; i < 2000; i++)
                {
                    Assert.That(echo.SayHello("Deploy package A" + i), Is.EqualTo("Deploy package A" + i + "..."));
                }
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .MinimumLevel.Warning()
                         .CreateLogger();
            Console.Title = "Halibut Server";
            var certificate = new X509Certificate2("HalibutServer.pfx");

            var endPoint = new IPEndPoint(IPAddress.IPv6Any, 8433);

            var services = new DelegateServiceFactory();

            services.Register <IUserService>(() => new UserService());

            using (var server = new HalibutRuntime(services, certificate))
            {
                server.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("wss://localhost:8433/Halibut"), SslCertificateThumbprint));
                Console.WriteLine("Server listening on port 8433. Type 'exit' to quit, or 'cls' to clear...");
                while (true)
                {
                    var line = Console.ReadLine();
                    if (string.Equals("cls", line, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                        continue;
                    }

                    if (string.Equals("q", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (string.Equals("exit", line, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    Console.WriteLine("Unknown command. Enter 'q' to quit.");
                }
            }
        }
Esempio n. 9
0
        static void RunWebSocketPollingClient(HalibutRuntime server, X509Certificate2 clientCertificate, string remoteThumbprint, string trustedCertificate, bool expectSuccess = true)
        {
            using (var runtime = new HalibutRuntime(clientCertificate))
            {
                runtime.ListenWebSocket("https://+:8434/Halibut");
                runtime.Trust(trustedCertificate);

                var serverEndpoint = new ServiceEndPoint(new Uri("wss://localhost:8434/Halibut"), Certificates.SslThumbprint)
                {
                    TcpClientConnectTimeout = TimeSpan.FromSeconds(5)
                };
                server.Poll(new Uri("poll://SQ-WEBSOCKETPOLL"), serverEndpoint);

                var clientEndpoint = new ServiceEndPoint("poll://SQ-WEBSOCKETPOLL", remoteThumbprint);
                var calculator     = runtime.CreateClient <ICalculatorService>(clientEndpoint);

                MakeRequest(calculator, "websocket polling", expectSuccess);

                runtime.Disconnect(clientEndpoint);
            }
        }
Esempio n. 10
0
        public void StreamsCanBeSentToPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
                using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
                {
                    var octopusPort = octopus.Listen();
                    octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                    tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                    var echo = octopus.CreateClient <IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);

                    var data = new byte[1024 * 1024 + 15];
                    new Random().NextBytes(data);

                    for (var i = 0; i < 100; i++)
                    {
                        var count = echo.CountBytes(DataStream.FromBytes(data));
                        Assert.That(count, Is.EqualTo(1024 * 1024 + 15));
                    }
                }
        }
Esempio n. 11
0
        static void RunPollingClient(HalibutRuntime server, X509Certificate2 clientCertificate, string remoteThumbprint, bool expectSuccess = true)
        {
            using (var runtime = new HalibutRuntime(clientCertificate))
            {
                runtime.Listen(new IPEndPoint(IPAddress.IPv6Any, 8433));
                runtime.Trust(Certificates.OctopusPublicThumbprint);

                //setup polling
                var serverEndpoint = new ServiceEndPoint(new Uri("https://localhost:8433"), Certificates.TentaclePollingPublicThumbprint)
                {
                    TcpClientConnectTimeout = TimeSpan.FromSeconds(5)
                };
                server.Poll(new Uri("poll://SQ-TENTAPOLL"), serverEndpoint);

                var clientEndpoint = new ServiceEndPoint("poll://SQ-TENTAPOLL", remoteThumbprint);

                var calculator = runtime.CreateClient <ICalculatorService>(clientEndpoint);

                MakeRequest(calculator, "polling", expectSuccess);

                runtime.Disconnect(clientEndpoint);
            }
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            var services = new DelegateServiceFactory();

            services.Register <ICalculatorService>(() => new CalculatorService());

            using (var client = new HalibutRuntime(services, ClientCertificate))
                using (var server = new HalibutRuntime(services, ServerCertificate))
                {
                    var octopusPort = client.Listen();
                    client.Trust(ServerCertificate.Thumbprint);

                    server.Poll(new Uri(PollUrl), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), ClientCertificate.Thumbprint));

                    var calculator = client.CreateClient <ICalculatorService>(PollUrl, ServerCertificate.Thumbprint);
                    var result     = calculator.Add(12, 18);
                    Debug.Assert(result == 30);
                }
            Console.ReadKey();
        }
Esempio n. 13
0
        public void FailWhenServerThrowsAnExceptionOnPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);
                var ex = Assert.Throws<HalibutClientException>(() => echo.Crash());
                Assert.That(ex.Message, Does.Contain("at Halibut.Tests.TestServices.EchoService.Crash()").And.Contains("divide by zero"));
            }
        }
Esempio n. 14
0
        public void StreamsCanBeSentToPolling()
        {
            using (var octopus = new HalibutRuntime(services, Certificates.Octopus))
            using (var tentaclePolling = new HalibutRuntime(services, Certificates.TentaclePolling))
            {
                var octopusPort = octopus.Listen();
                octopus.Trust(Certificates.TentaclePollingPublicThumbprint);

                tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri("https://localhost:" + octopusPort), Certificates.OctopusPublicThumbprint));

                var echo = octopus.CreateClient<IEchoService>("poll://SQ-TENTAPOLL", Certificates.TentaclePollingPublicThumbprint);

                var data = new byte[1024 * 1024 + 15];
                new Random().NextBytes(data);

                for (var i = 0; i < 100; i++)
                {
                    var count = echo.CountBytes(DataStream.FromBytes(data));
                    Assert.That(count, Is.EqualTo(1024 * 1024 + 15));
                }
            }
        }