@@ -22,12 +22,13 @@ struct TGRpcClientConfig {
22
22
ui32 MaxInFlight = 0 ;
23
23
bool EnableSsl = false ;
24
24
grpc::SslCredentialsOptions SslCredentials;
25
- grpc_compression_algorithm CompressionAlgoritm = GRPC_COMPRESS_NONE;
25
+ grpc_compression_algorithm CompressionAlgorithm = GRPC_COMPRESS_NONE;
26
26
ui64 MemQuota = 0 ;
27
27
std::unordered_map<std::string, std::string> StringChannelParams;
28
28
std::unordered_map<std::string, int > IntChannelParams;
29
29
std::string LoadBalancingPolicy = { };
30
30
std::string SslTargetNameOverride = { };
31
+ bool UseXds = false ;
31
32
32
33
TGRpcClientConfig () = default ;
33
34
TGRpcClientConfig (const TGRpcClientConfig&) = default ;
@@ -46,15 +47,16 @@ struct TGRpcClientConfig {
46
47
, SslCredentials{.pem_root_certs = NYdb::TStringType{caCert},
47
48
.pem_private_key = NYdb::TStringType{clientPrivateKey},
48
49
.pem_cert_chain = NYdb::TStringType{clientCert}}
49
- , CompressionAlgoritm(compressionAlgorithm)
50
+ , CompressionAlgorithm(compressionAlgorithm)
51
+ , UseXds((Locator.starts_with(" xds:///" )))
50
52
{}
51
53
};
52
54
53
55
inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface (const TGRpcClientConfig& config, grpc_socket_mutator* mutator = nullptr ){
54
56
grpc::ChannelArguments args;
55
57
args.SetMaxReceiveMessageSize (config.MaxInboundMessageSize ? config.MaxInboundMessageSize : config.MaxMessageSize );
56
58
args.SetMaxSendMessageSize (config.MaxOutboundMessageSize ? config.MaxOutboundMessageSize : config.MaxMessageSize );
57
- args.SetCompressionAlgorithm (config.CompressionAlgoritm );
59
+ args.SetCompressionAlgorithm (config.CompressionAlgorithm );
58
60
59
61
for (const auto & kvp: config.StringChannelParams ) {
60
62
args.SetString (NYdb::TStringType{kvp.first }, NYdb::TStringType{kvp.second });
@@ -78,11 +80,16 @@ inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRp
78
80
if (!config.SslTargetNameOverride .empty ()) {
79
81
args.SetSslTargetNameOverride (NYdb::TStringType{config.SslTargetNameOverride });
80
82
}
83
+ std::shared_ptr<grpc::ChannelCredentials> channelCredentials = nullptr ;
81
84
if (config.EnableSsl || !config.SslCredentials .pem_root_certs .empty ()) {
82
- return grpc::CreateCustomChannel ( grpc::string (config. Locator ), grpc::SslCredentials (config.SslCredentials ), args );
85
+ channelCredentials = grpc::SslCredentials (config.SslCredentials );
83
86
} else {
84
- return grpc::CreateCustomChannel ( grpc::string (config. Locator ), grpc::InsecureChannelCredentials (), args );
87
+ channelCredentials = grpc::InsecureChannelCredentials ();
85
88
}
89
+ if (config.UseXds ) {
90
+ channelCredentials = grpc::XdsCredentials (channelCredentials);
91
+ }
92
+ return grpc::CreateCustomChannel (grpc::string (config.Locator ), channelCredentials, args);
86
93
}
87
94
88
95
}
0 commit comments