internal GrpcCopyClient(GrpcCopyClientKey key, GrpcCopyClientConfiguration configuration, IClock?clock = null, ByteArrayPool?sharedBufferPool = null) { Key = key; _configuration = configuration; _clock = clock ?? SystemClock.Instance; GrpcEnvironment.WaitUntilInitialized(); _channel = new Channel(key.Host, key.GrpcPort, ChannelCredentials.Insecure, options: GrpcEnvironment.GetClientOptions(_configuration.GrpcCoreClientOptions)); _client = new ContentServer.ContentServerClient(_channel); _bandwidthChecker = new BandwidthChecker(configuration.BandwidthCheckerConfiguration); _pool = sharedBufferPool ?? new ByteArrayPool(_configuration.ClientBufferSizeBytes); }
/// <nodoc /> public static GrpcCopyClientConfiguration FromDistributedContentSettings(DistributedContentSettings dcs) { var grpcCopyClientConfiguration = new GrpcCopyClientConfiguration(); ApplyIfNotNull(dcs.GrpcCopyClientBufferSizeBytes, v => grpcCopyClientConfiguration.ClientBufferSizeBytes = v); ApplyIfNotNull(dcs.GrpcCopyClientConnectOnStartup, v => grpcCopyClientConfiguration.ConnectOnStartup = v); ApplyIfNotNull(dcs.GrpcCopyClientDisconnectionTimeoutSeconds, v => grpcCopyClientConfiguration.DisconnectionTimeout = TimeSpan.FromSeconds(v)); ApplyIfNotNull(dcs.GrpcCopyClientConnectionTimeoutSeconds, v => grpcCopyClientConfiguration.ConnectionTimeout = TimeSpan.FromSeconds(v)); ApplyIfNotNull(dcs.TimeToFirstByteTimeoutInSeconds, v => grpcCopyClientConfiguration.TimeToFirstByteTimeout = TimeSpan.FromSeconds(v)); ApplyIfNotNull(dcs.GrpcCopyClientOperationDeadlineSeconds, v => grpcCopyClientConfiguration.OperationDeadline = TimeSpan.FromSeconds(v)); ApplyIfNotNull(dcs.GrpcCopyClientPropagateCallingMachineName, v => grpcCopyClientConfiguration.PropagateCallingMachineName = v); ApplyIfNotNull(dcs.GrpcCopyClientGrpcCoreClientOptions, v => grpcCopyClientConfiguration.GrpcCoreClientOptions = v); grpcCopyClientConfiguration.BandwidthCheckerConfiguration = BandwidthChecker.Configuration.FromDistributedContentSettings(dcs); return(grpcCopyClientConfiguration); }
internal GrpcCopyClient(Context context, GrpcCopyClientKey key, GrpcCopyClientConfiguration configuration, IClock?clock = null, ByteArrayPool?sharedBufferPool = null) { Key = key; _configuration = configuration; _clock = clock ?? SystemClock.Instance; GrpcEnvironment.WaitUntilInitialized(); var channelCreds = ChannelCredentials.Insecure; bool?encryptionEnabled = _configuration.GrpcCoreClientOptions?.EncryptionEnabled; Tracer.Info(context, $"Grpc Encryption Enabled = {encryptionEnabled == true}, GRPC Port: {key.GrpcPort}"); List <ChannelOption> options = new List <ChannelOption>(GrpcEnvironment.GetClientOptions(_configuration.GrpcCoreClientOptions)); if (encryptionEnabled == true) { try { channelCreds = TryGetSecureChannelCredentials(context, _configuration, out var hostName) ?? ChannelCredentials.Insecure; if (channelCreds != ChannelCredentials.Insecure) { options.Add(new ChannelOption(ChannelOptions.SslTargetNameOverride, hostName)); } } catch (Exception ex) { Tracer.Error(context, ex, $"Creating Encrypted Grpc Channel Failed."); } } Tracer.Debug(context, $"Client connecting to {key.Host}:{key.GrpcPort}. Channel Encrypted = {channelCreds != ChannelCredentials.Insecure}"); _channel = new Channel(key.Host, key.GrpcPort, channelCreds, options: options); _client = new ContentServer.ContentServerClient(_channel); _bandwidthChecker = new BandwidthChecker(_configuration.BandwidthCheckerConfiguration); _pool = sharedBufferPool ?? new ByteArrayPool(_configuration.ClientBufferSizeBytes); }