public ServicesChannel(EventBus eventBus, ServerEndpoint serverEndpoint, ChannelBase proxiedChannel) : base(proxiedChannel.Target) { _eventBus = eventBus; _serverEndpoint = serverEndpoint; _proxiedChannel = proxiedChannel; }
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(); }
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(); }
public async Task MonitorForDisconnect(ServerEndpoint serverEndpoint, CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { await _server.GetNetworkTiming(); await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken); } catch { return; } } }
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); }
public StaticApiServer(ServerEndpoint apiServerEndpoint) { Endpoint = apiServerEndpoint; _taskResult = Task.FromResult(apiServerEndpoint); }
public MonitoredCallInvoker(EventBus eventBus, ServerEndpoint serverEndpoint, CallInvoker impl) { _eventBus = eventBus; _serverEndpoint = serverEndpoint; _impl = impl; }
public ExceptionThrown(ServerEndpoint serverEndpoint, Exception exception) { ServerEndpoint = serverEndpoint; Exception = exception; }