Example #1
0
 public ServicesChannel(EventBus eventBus, ServerEndpoint serverEndpoint, ChannelBase proxiedChannel) :
     base(proxiedChannel.Target)
 {
     _eventBus       = eventBus;
     _serverEndpoint = serverEndpoint;
     _proxiedChannel = proxiedChannel;
 }
Example #2
0
        private async Task AttemptEndpointConnection(EndpointProviderRunner endpointRunner, ServerEndpoint serverEndpoint,
                                                     CancellationToken stoppingToken)
        {
            _logger.LogDebug($"Attempting to connect with {serverEndpoint.Uri}");

            var httpClient = _endpointClientFactory.CreateHttpClient(serverEndpoint);

            if (!(await _serverIdentifyVerifier.VerifyServer(serverEndpoint, httpClient, stoppingToken)))
            {
                return;
            }

            if (stoppingToken.IsCancellationRequested)
            {
                return;
            }

            Endpoint        = serverEndpoint;
            ServicesChannel = new ServicesChannel(EventBus, serverEndpoint, Grpc.Net.Client.GrpcChannel.ForAddress(
                                                      serverEndpoint.Uri, new Grpc.Net.Client.GrpcChannelOptions
            {
                DisposeHttpClient = false,
                HttpClient        = httpClient
            }));

            SetConnectedState();
        }
Example #3
0
        public async Task MonitorForDisconnect(ServerEndpoint serverEndpoint, CancellationToken stoppingToken)
        {
            _serverEndpoint = serverEndpoint;

            RegisterEventHandlers();
            //  use a local stopping token tied to the original token
            //  so that we can register callbacks when the token is cancelled
            //  without leaving garbage on the token over successive calls
            using (var localStoppingToken = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken))
            {
                await WaitForExceptionOrCancellation(localStoppingToken.Token);
            }
            UnregisterEventHandlers();
        }
Example #4
0
        public async Task MonitorForDisconnect(ServerEndpoint serverEndpoint, CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    await _server.GetNetworkTiming();

                    await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
                }
                catch
                {
                    return;
                }
            }
        }
Example #5
0
        public async Task <bool> VerifyServer(ServerEndpoint serverEndpoint, HttpClient httpClient, CancellationToken stoppingToken)
        {
            var channel = GrpcChannel.ForAddress(serverEndpoint.Uri, new GrpcChannelOptions
            {
                DisposeHttpClient = false,
                HttpClient        = httpClient
            });

            var client = new Information.InformationClient(channel);

            try
            {
                var version = await client.GetServerVersionAsync(Services.Empty.Instance);
            }
            catch
            {
                _logger.LogDebug($"Server couldn't be reached");
                return(false);
            }

            _logger.LogDebug($"Contacted server");

            //  todo: query server for identity credentials
            return(serverEndpoint.IdentityPolicy.IsValid(
 public HttpClient CreateHttpClient(ServerEndpoint serverEndpoint)
 {
     return(_httpClient);
 }
Example #7
0
 public StaticApiServer(ServerEndpoint apiServerEndpoint)
 {
     Endpoint    = apiServerEndpoint;
     _taskResult = Task.FromResult(apiServerEndpoint);
 }
Example #8
0
 public MonitoredCallInvoker(EventBus eventBus, ServerEndpoint serverEndpoint, CallInvoker impl)
 {
     _eventBus       = eventBus;
     _serverEndpoint = serverEndpoint;
     _impl           = impl;
 }
Example #9
0
 public ExceptionThrown(ServerEndpoint serverEndpoint, Exception exception)
 {
     ServerEndpoint = serverEndpoint;
     Exception      = exception;
 }