aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/grpc/client/grpc_common.h
diff options
context:
space:
mode:
authorDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:16 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:16 +0300
commit17e20fa084178ddcb16255f974dbde74fb93608b (patch)
tree39605336c0b4d33928df69a256102c515fdf6ff5 /library/cpp/grpc/client/grpc_common.h
parent97df5ca7413550bf233fc6c7210e292fca0a51af (diff)
downloadydb-17e20fa084178ddcb16255f974dbde74fb93608b.tar.gz
Restoring authorship annotation for Daniil Cherednik <dcherednik@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/grpc/client/grpc_common.h')
-rw-r--r--library/cpp/grpc/client/grpc_common.h88
1 files changed, 44 insertions, 44 deletions
diff --git a/library/cpp/grpc/client/grpc_common.h b/library/cpp/grpc/client/grpc_common.h
index ffcdafe045..ac62e8b331 100644
--- a/library/cpp/grpc/client/grpc_common.h
+++ b/library/cpp/grpc/client/grpc_common.h
@@ -1,53 +1,53 @@
-#pragma once
-
-#include <grpc++/grpc++.h>
+#pragma once
+
+#include <grpc++/grpc++.h>
#include <grpc++/resource_quota.h>
-
+
#include <util/datetime/base.h>
-#include <unordered_map>
-#include <util/generic/string.h>
-
-constexpr ui64 DEFAULT_GRPC_MESSAGE_SIZE_LIMIT = 64000000;
-
+#include <unordered_map>
+#include <util/generic/string.h>
+
+constexpr ui64 DEFAULT_GRPC_MESSAGE_SIZE_LIMIT = 64000000;
+
namespace NGrpc {
-
-struct TGRpcClientConfig {
- TString Locator; // format host:port
- TDuration Timeout = TDuration::Max(); // request timeout
- ui64 MaxMessageSize = DEFAULT_GRPC_MESSAGE_SIZE_LIMIT; // Max request and response size
+
+struct TGRpcClientConfig {
+ TString Locator; // format host:port
+ TDuration Timeout = TDuration::Max(); // request timeout
+ ui64 MaxMessageSize = DEFAULT_GRPC_MESSAGE_SIZE_LIMIT; // Max request and response size
ui64 MaxInboundMessageSize = 0; // overrides MaxMessageSize for incoming requests
ui64 MaxOutboundMessageSize = 0; // overrides MaxMessageSize for outgoing requests
- ui32 MaxInFlight = 0;
+ ui32 MaxInFlight = 0;
bool EnableSsl = false;
TString SslCaCert; //Implicitly enables Ssl if not empty
grpc_compression_algorithm CompressionAlgoritm = GRPC_COMPRESS_NONE;
ui64 MemQuota = 0;
- std::unordered_map<TString, TString> StringChannelParams;
- std::unordered_map<TString, int> IntChannelParams;
+ std::unordered_map<TString, TString> StringChannelParams;
+ std::unordered_map<TString, int> IntChannelParams;
TString LoadBalancingPolicy = { };
TString SslTargetNameOverride = { };
-
- TGRpcClientConfig() = default;
- TGRpcClientConfig(const TGRpcClientConfig&) = default;
- TGRpcClientConfig(TGRpcClientConfig&&) = default;
- TGRpcClientConfig& operator=(const TGRpcClientConfig&) = default;
- TGRpcClientConfig& operator=(TGRpcClientConfig&&) = default;
-
- TGRpcClientConfig(const TString& locator, TDuration timeout = TDuration::Max(),
+
+ TGRpcClientConfig() = default;
+ TGRpcClientConfig(const TGRpcClientConfig&) = default;
+ TGRpcClientConfig(TGRpcClientConfig&&) = default;
+ TGRpcClientConfig& operator=(const TGRpcClientConfig&) = default;
+ TGRpcClientConfig& operator=(TGRpcClientConfig&&) = default;
+
+ TGRpcClientConfig(const TString& locator, TDuration timeout = TDuration::Max(),
ui64 maxMessageSize = DEFAULT_GRPC_MESSAGE_SIZE_LIMIT, ui32 maxInFlight = 0, TString caCert = "",
grpc_compression_algorithm compressionAlgorithm = GRPC_COMPRESS_NONE, bool enableSsl = false)
- : Locator(locator)
- , Timeout(timeout)
- , MaxMessageSize(maxMessageSize)
- , MaxInFlight(maxInFlight)
+ : Locator(locator)
+ , Timeout(timeout)
+ , MaxMessageSize(maxMessageSize)
+ , MaxInFlight(maxInFlight)
, EnableSsl(enableSsl)
- , SslCaCert(caCert)
+ , SslCaCert(caCert)
, CompressionAlgoritm(compressionAlgorithm)
- {}
-};
-
-inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRpcClientConfig& config, grpc_socket_mutator* mutator = nullptr){
- grpc::ChannelArguments args;
+ {}
+};
+
+inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRpcClientConfig& config, grpc_socket_mutator* mutator = nullptr){
+ grpc::ChannelArguments args;
args.SetMaxReceiveMessageSize(config.MaxInboundMessageSize ? config.MaxInboundMessageSize : config.MaxMessageSize);
args.SetMaxSendMessageSize(config.MaxOutboundMessageSize ? config.MaxOutboundMessageSize : config.MaxMessageSize);
args.SetCompressionAlgorithm(config.CompressionAlgoritm);
@@ -65,9 +65,9 @@ inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRp
quota.Resize(config.MemQuota);
args.SetResourceQuota(quota);
}
- if (mutator) {
- args.SetSocketMutator(mutator);
- }
+ if (mutator) {
+ args.SetSocketMutator(mutator);
+ }
if (!config.LoadBalancingPolicy.empty()) {
args.SetLoadBalancingPolicyName(config.LoadBalancingPolicy);
}
@@ -75,10 +75,10 @@ inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRp
args.SetSslTargetNameOverride(config.SslTargetNameOverride);
}
if (config.EnableSsl || config.SslCaCert) {
- return grpc::CreateCustomChannel(config.Locator, grpc::SslCredentials(grpc::SslCredentialsOptions{config.SslCaCert, "", ""}), args);
- } else {
- return grpc::CreateCustomChannel(config.Locator, grpc::InsecureChannelCredentials(), args);
- }
-}
-
+ return grpc::CreateCustomChannel(config.Locator, grpc::SslCredentials(grpc::SslCredentialsOptions{config.SslCaCert, "", ""}), args);
+ } else {
+ return grpc::CreateCustomChannel(config.Locator, grpc::InsecureChannelCredentials(), args);
+ }
+}
+
} // namespace NGRpc