Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrpcCopyClient" /> class.
 /// </summary>
 internal GrpcCopyClient(GrpcCopyClientKey key, int?clientBufferSize)
 {
     GrpcEnvironment.InitializeIfNeeded();
     _channel    = new Channel(key.Host, key.GrpcPort, ChannelCredentials.Insecure, GrpcEnvironment.DefaultConfiguration);
     _client     = new ContentServer.ContentServerClient(_channel);
     _bufferSize = clientBufferSize ?? ContentStore.Grpc.CopyConstants.DefaultBufferSize;
     Key         = key;
 }
Exemplo n.º 2
0
 internal GrpcCopyClient(GrpcCopyClientKey key, int?clientBufferSize, int?copyTimeoutInSeconds)
 {
     GrpcEnvironment.InitializeIfNeeded();
     _clock                 = SystemClock.Instance;
     _channel               = new Channel(key.Host, key.GrpcPort, ChannelCredentials.Insecure, GrpcEnvironment.DefaultConfiguration);
     _client                = new ContentServer.ContentServerClient(_channel);
     _bufferSize            = clientBufferSize ?? ContentStore.Grpc.CopyConstants.DefaultBufferSize;
     _copyConnectionTimeout = copyTimeoutInSeconds.HasValue ? TimeSpan.FromSeconds(copyTimeoutInSeconds.Value) : ContentStore.Grpc.CopyConstants.DefaultConnectionTimeoutSeconds;
     Key = key;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrpcCopyClient" /> class.
        /// </summary>
        internal GrpcCopyClient(GrpcCopyClientKey key, Configuration config)
        {
            GrpcEnvironment.InitializeIfNeeded();
            _channel    = new Channel(key.Host, key.GrpcPort, ChannelCredentials.Insecure, GrpcEnvironment.DefaultConfiguration);
            _client     = new ContentServer.ContentServerClient(_channel);
            _bufferSize = config.ClientBufferSize ?? ContentStore.Grpc.CopyConstants.DefaultBufferSize;
            var bandwidthSource = config.MinimumBandwidthMbPerSec == null
                ? (IBandwidthLimitSource) new HistoricalBandwidthLimitSource()
                : new ConstantBandwidthLimit(config.MinimumBandwidthMbPerSec.Value);

            _bandwidthChecker = new BandwidthChecker(bandwidthSource, config.BandwidthCheckInterval);
            Key = key;
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }