Merge branch 'master' into server-builder

pull/23690/head
Karthik Ravi Shankar 5 years ago
commit e7197614ba
  1. 2
      .github/ISSUE_TEMPLATE/bug_report.md
  2. 2
      .github/ISSUE_TEMPLATE/cleanup_request.md
  3. 2
      .github/ISSUE_TEMPLATE/feature_request.md
  4. 2
      .github/ISSUE_TEMPLATE/question.md
  5. 2
      .github/pull_request_template.md
  6. 2
      BUILD
  7. 1
      BUILD.gn
  8. 3
      CMakeLists.txt
  9. 3
      Makefile
  10. 8
      bazel/grpc_deps.bzl
  11. 3
      build_autogenerated.yaml
  12. 3
      cmake/re2.cmake
  13. 5
      doc/grpc_xds_features.md
  14. 1
      gRPC-C++.podspec
  15. 5
      include/grpc/impl/codegen/port_platform.h
  16. 4
      include/grpcpp/impl/codegen/server_interface.h
  17. 51
      include/grpcpp/security/server_credentials.h
  18. 89
      include/grpcpp/security/server_credentials_impl.h
  19. 8
      include/grpcpp/server_builder.h
  20. 24
      include/grpcpp/support/error_details.h
  21. 48
      include/grpcpp/support/error_details_impl.h
  22. 6
      setup.py
  23. 67
      src/boringssl/gen_build_yaml.py
  24. 2
      src/core/ext/filters/client_channel/client_channel.h
  25. 5
      src/core/ext/filters/client_channel/http_connect_handshaker.cc
  26. 47
      src/core/ext/filters/client_channel/server_address.cc
  27. 46
      src/core/ext/filters/client_channel/server_address.h
  28. 117
      src/core/ext/transport/chttp2/client/chttp2_connector.cc
  29. 19
      src/core/ext/transport/chttp2/client/chttp2_connector.h
  30. 44
      src/core/ext/transport/chttp2/server/chttp2_server.cc
  31. 3
      src/core/ext/transport/chttp2/server/chttp2_server.h
  32. 4
      src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc
  33. 12
      src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc
  34. 5
      src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc
  35. 43
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  36. 2
      src/core/ext/transport/chttp2/transport/flow_control.cc
  37. 4
      src/core/ext/transport/chttp2/transport/frame_settings.cc
  38. 2
      src/core/ext/transport/chttp2/transport/internal.h
  39. 11
      src/core/ext/transport/chttp2/transport/writing.cc
  40. 6
      src/core/ext/transport/inproc/inproc_transport.cc
  41. 2
      src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h
  42. 2
      src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h
  43. 72
      src/core/ext/upb-generated/google/protobuf/descriptor.upb.c
  44. 2
      src/core/ext/upb-generated/google/protobuf/struct.upb.h
  45. 22
      src/core/ext/upb-generated/validate/validate.upb.c
  46. 2
      src/core/ext/upb-generated/validate/validate.upb.h
  47. 2
      src/core/lib/channel/channelz.cc
  48. 2
      src/core/lib/channel/channelz.h
  49. 6
      src/core/lib/iomgr/endpoint.cc
  50. 9
      src/core/lib/iomgr/endpoint.h
  51. 43
      src/core/lib/iomgr/endpoint_cfstream.cc
  52. 48
      src/core/lib/iomgr/tcp_custom.cc
  53. 44
      src/core/lib/iomgr/tcp_posix.cc
  54. 36
      src/core/lib/iomgr/tcp_windows.cc
  55. 8
      src/core/lib/security/transport/secure_endpoint.cc
  56. 24
      src/core/lib/surface/call.cc
  57. 3
      src/core/lib/surface/call.h
  58. 2
      src/core/lib/surface/init.cc
  59. 2309
      src/core/lib/surface/server.cc
  60. 450
      src/core/lib/surface/server.h
  61. 1
      src/cpp/server/external_connection_acceptor_impl.h
  62. 4
      src/cpp/server/secure_server_credentials.cc
  63. 14
      src/cpp/server/server_cc.cc
  64. 6
      src/cpp/server/server_credentials.cc
  65. 4
      src/cpp/util/error_details.cc
  66. 27
      src/ruby/spec/generic/active_call_spec.rb
  67. 19
      templates/tools/distrib/python/grpc_version.py.template
  68. 1
      templates/tools/dockerfile/interoptest/grpc_interop_cxx/Dockerfile.template
  69. 3
      templates/tools/dockerfile/interoptest/grpc_interop_dart/build_interop.sh.template
  70. 6
      test/core/bad_client/bad_client.cc
  71. 2
      test/core/bad_client/tests/bad_streaming_id.cc
  72. 2
      test/core/bad_client/tests/badreq.cc
  73. 2
      test/core/bad_client/tests/connection_prefix.cc
  74. 2
      test/core/bad_client/tests/headers.cc
  75. 2
      test/core/bad_client/tests/initial_settings_frame.cc
  76. 2
      test/core/bad_client/tests/out_of_bounds.cc
  77. 2
      test/core/bad_client/tests/server_registered_method.cc
  78. 2
      test/core/bad_client/tests/simple_request.cc
  79. 2
      test/core/bad_client/tests/unknown_frame.cc
  80. 2
      test/core/bad_client/tests/window_overflow.cc
  81. 5
      test/core/bad_connection/close_fd_test.cc
  82. 2
      test/core/channel/channelz_test.cc
  83. 146
      test/core/end2end/bad_server_response_test.cc
  84. 4
      test/core/end2end/fixtures/h2_sockpair+trace.cc
  85. 4
      test/core/end2end/fixtures/h2_sockpair.cc
  86. 4
      test/core/end2end/fixtures/h2_sockpair_1byte.cc
  87. 2
      test/core/end2end/fuzzers/server_fuzzer.cc
  88. 4
      test/core/end2end/tests/channelz.cc
  89. 4
      test/core/handshake/client_ssl.cc
  90. 98
      test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc
  91. 9
      test/core/util/mock_endpoint.cc
  92. 14
      test/core/util/passthru_endpoint.cc
  93. 30
      test/core/util/reconnect_server.cc
  94. 2
      test/core/util/reconnect_server.h
  95. 9
      test/core/util/test_config.cc
  96. 8
      test/core/util/trickle_endpoint.cc
  97. 7
      test/cpp/end2end/filter_end2end_test.cc
  98. 11
      test/cpp/end2end/generic_end2end_test.cc
  99. 5
      test/cpp/end2end/port_sharing_end2end_test.cc
  100. 4
      test/cpp/end2end/server_interceptors_end2end_test.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -2,7 +2,7 @@
name: Report a bug
about: Create a report to help us improve
labels: kind/bug, priority/P2
assignees: markdroth
assignees: nicolasnoble
---

@ -2,7 +2,7 @@
name: Request a cleanup
about: Suggest a cleanup in our repository
labels: kind/internal cleanup, priority/P2
assignees: markdroth
assignees: nicolasnoble
---

@ -2,7 +2,7 @@
name: Request a feature
about: Suggest an idea for this project
labels: kind/enhancement, priority/P2
assignees: markdroth
assignees: nicolasnoble
---

@ -2,7 +2,7 @@
name: Ask a question
about: Ask a question
labels: kind/question, priority/P3
assignees: markdroth
assignees: nicolasnoble
---

@ -8,4 +8,4 @@ If you know who should review your pull request, please remove the mentioning be
-->
@markdroth
@nicolasnoble

@ -251,7 +251,6 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/security/auth_metadata_processor.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/security/tls_credentials_options.h",
"include/grpcpp/server.h",
"include/grpcpp/server_impl.h",
@ -408,7 +407,6 @@ grpc_cc_library(
hdrs = [
"include/grpc++/support/error_details.h",
"include/grpcpp/support/error_details.h",
"include/grpcpp/support/error_details_impl.h",
],
language = "c++",
standalone = True,

@ -1177,7 +1177,6 @@ config("grpc_config") {
"include/grpcpp/security/auth_metadata_processor.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/security/tls_credentials_options.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",

@ -2820,7 +2820,6 @@ foreach(_hdr
include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/security/tls_credentials_options.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
@ -2990,7 +2989,6 @@ target_link_libraries(grpc++_error_details
foreach(_hdr
include/grpc++/support/error_details.h
include/grpcpp/support/error_details.h
include/grpcpp/support/error_details_impl.h
)
string(REPLACE "include/" "" _path ${_hdr})
get_filename_component(_path ${_path} PATH)
@ -3512,7 +3510,6 @@ foreach(_hdr
include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/security/tls_credentials_options.h
include/grpcpp/server.h
include/grpcpp/server_builder.h

@ -4944,7 +4944,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/security/tls_credentials_options.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
@ -5121,7 +5120,6 @@ LIBGRPC++_ERROR_DETAILS_SRC = \
PUBLIC_HEADERS_CXX += \
include/grpc++/support/error_details.h \
include/grpcpp/support/error_details.h \
include/grpcpp/support/error_details_impl.h \
LIBGRPC++_ERROR_DETAILS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_ERROR_DETAILS_SRC))))
@ -5634,7 +5632,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/security/tls_credentials_options.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \

@ -283,11 +283,11 @@ def grpc_deps():
if "upb" not in native.existing_rules():
http_archive(
name = "upb",
sha256 = "79f7de61203c4ee5e4fcb2f17c5f3338119d6eb94aca8bce05332d2c1cfee108",
strip_prefix = "upb-92e63da73328d01b417cf26c2de7b0a27a0f83af",
sha256 = "7992217989f3156f8109931c1fc6db3434b7414957cb82371552377beaeb9d6c",
strip_prefix = "upb-382d5afc60e05470c23e8de19b19fc5ad231e732",
urls = [
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/protocolbuffers/upb/archive/92e63da73328d01b417cf26c2de7b0a27a0f83af.tar.gz",
"https://github.com/protocolbuffers/upb/archive/92e63da73328d01b417cf26c2de7b0a27a0f83af.tar.gz",
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/protocolbuffers/upb/archive/382d5afc60e05470c23e8de19b19fc5ad231e732.tar.gz",
"https://github.com/protocolbuffers/upb/archive/382d5afc60e05470c23e8de19b19fc5ad231e732.tar.gz",
],
)

@ -2152,7 +2152,6 @@ libs:
- include/grpcpp/security/auth_metadata_processor.h
- include/grpcpp/security/credentials.h
- include/grpcpp/security/server_credentials.h
- include/grpcpp/security/server_credentials_impl.h
- include/grpcpp/security/tls_credentials_options.h
- include/grpcpp/server.h
- include/grpcpp/server_builder.h
@ -2277,7 +2276,6 @@ libs:
public_headers:
- include/grpc++/support/error_details.h
- include/grpcpp/support/error_details.h
- include/grpcpp/support/error_details_impl.h
headers: []
src:
- src/proto/grpc/status/status.proto
@ -2536,7 +2534,6 @@ libs:
- include/grpcpp/security/auth_metadata_processor.h
- include/grpcpp/security/credentials.h
- include/grpcpp/security/server_credentials.h
- include/grpcpp/security/server_credentials_impl.h
- include/grpcpp/security/tls_credentials_options.h
- include/grpcpp/server.h
- include/grpcpp/server_builder.h

@ -21,6 +21,9 @@ if(gRPC_RE2_PROVIDER STREQUAL "module")
set(RE2_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/re2)
endif()
if(EXISTS "${RE2_ROOT_DIR}/CMakeLists.txt")
# Explicitly disable BUILD_TESTING to avoid re2's CMakeLists.txt triggering https://github.com/grpc/grpc/issues/23586
option(BUILD_TESTING "re2.cmake explicitly disabled CTest's BUILD_TESTING option." OFF)
include_directories("${RE2_ROOT_DIR}")
add_subdirectory(${RE2_ROOT_DIR} third_party/re2)

@ -36,5 +36,6 @@ to authenticate with the xDS server.
Features | gRFCs | [C++, Python,<br> Ruby, PHP, C#](https://github.com/grpc/grpc/releases) | [Java](https://github.com/grpc/grpc-java/releases) | [Go](https://github.com/grpc/grpc-go/releases)
---------|--------|--------------|------|------
**xDS Infrastructure in gRPC client channel:**<br>LDS->RDS->CDS->EDS flow,<br>ADS stream, | [A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md) | v1.30.0 | v1.30.0 | v1.30.0 |
**Load Balancing:**<br>Virtual host matching,<br>Only default path ("" or "/") matching,<br>Priority-based weighted round-robin locality picking,<br>Round-robin endpoint picking within locality,<br>Cluster route action,<br>Client-side Load reporting via [LRS](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/load_stats/v2/lrs.proto)| [A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md) | v1.30.0 | v1.30.0 | v1.30.0 |
**xDS Infrastructure in gRPC client channel:**<ul><li>LDS->RDS->CDS->EDS flow</li><li>ADS stream</li></ul> | [A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md) | v1.30.0 | v1.30.0 | v1.30.0 |
**Load Balancing:**<ul><li>[Virtual host](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route_components.proto#route-virtualhost) domains matching</li><li>Only default path ("" or "/") matching</li><li>Priority-based weighted round-robin locality picking</li><li>Round-robin endpoint picking within locality</li><li>[Cluster](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route_components.proto#envoy-api-msg-route-routeaction) route action</li><li>Client-side Load reporting via [LRS](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/load_stats/v2/lrs.proto)</li></ul> | [A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md) | v1.30.0 | v1.30.0 | v1.30.0 |
Request matching based on:<ul><li>[Path](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route_components.proto#route-routematch) (prefix, full path and safe regex)</li><li>[Headers](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route_components.proto#route-headermatcher)</li></ul>Request routing to multiple clusters based on [weights](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route_components.proto#route-weightedcluster) | [A28](https://github.com/grpc/proposal/blob/master/A28-xds-traffic-splitting-and-routing.md) | v1.31.0 | v1.31.0 | v1.31.0 |

@ -164,7 +164,6 @@ Pod::Spec.new do |s|
'include/grpcpp/security/auth_metadata_processor.h',
'include/grpcpp/security/credentials.h',
'include/grpcpp/security/server_credentials.h',
'include/grpcpp/security/server_credentials_impl.h',
'include/grpcpp/security/tls_credentials_options.h',
'include/grpcpp/server.h',
'include/grpcpp/server_builder.h',

@ -31,8 +31,13 @@
* Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil
*/
#ifndef GPR_ABSEIL_SYNC
#if defined(__APPLE__)
// This is disabled on Apple platforms because macos/grpc_basictests_c_cpp
// fails with this. https://github.com/grpc/grpc/issues/23661
#else
#define GPR_ABSEIL_SYNC 1
#endif
#endif // GPR_ABSEIL_SYNC
/* Get windows.h included everywhere (we need it) */
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)

@ -36,12 +36,12 @@ namespace grpc_impl {
class Channel;
class CompletionQueue;
class ServerCompletionQueue;
class ServerCredentials;
} // namespace grpc_impl
namespace grpc {
class AsyncGenericService;
class GenericServerContext;
class ServerCredentials;
class Service;
extern CoreCodegenInterface* g_core_codegen_interface;
@ -173,7 +173,7 @@ class ServerInterface : public internal::CallHook {
///
/// \warning It's an error to call this method on an already started server.
virtual int AddListeningPort(const std::string& addr,
grpc_impl::ServerCredentials* creds) = 0;
ServerCredentials* creds) = 0;
/// Start the server.
///

@ -1,6 +1,6 @@
/*
*
* Copyright 2019 gRPC authors.
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,7 +19,15 @@
#ifndef GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#include <grpcpp/security/server_credentials_impl.h>
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/security/tls_credentials_options.h>
#include <grpcpp/support/config.h>
struct grpc_server;
namespace grpc_impl {
@ -27,8 +35,6 @@ class Server;
} // namespace grpc_impl
namespace grpc {
typedef ::grpc_impl::ServerCredentials ServerCredentials;
/// Options to create ServerCredentials with SSL
struct SslServerCredentialsOptions {
/// \warning Deprecated
@ -55,16 +61,45 @@ struct SslServerCredentialsOptions {
grpc_ssl_client_certificate_request_type client_certificate_request;
};
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials {
public:
virtual ~ServerCredentials();
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) = 0;
private:
friend class ::grpc_impl::Server;
/// Tries to bind \a server to the given \a addr (eg, localhost:1234,
/// 192.168.1.1:31416, [::1]:27182, etc.)
///
/// \return bound port number on success, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const std::string& addr, grpc_server* server) = 0;
};
/// Builds SSL ServerCredentials given SSL specific options
std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options);
const grpc::SslServerCredentialsOptions& options);
std::shared_ptr<ServerCredentials> InsecureServerCredentials();
namespace experimental {
typedef ::grpc_impl::experimental::AltsServerCredentialsOptions
AltsServerCredentialsOptions;
/// Options to create ServerCredentials with ALTS
struct AltsServerCredentialsOptions {
/// Add fields if needed.
};
/// Builds ALTS ServerCredentials given ALTS specific options
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
@ -73,7 +108,7 @@ std::shared_ptr<ServerCredentials> LocalServerCredentials(
/// Builds TLS ServerCredentials given TLS options.
std::shared_ptr<ServerCredentials> TlsServerCredentials(
const ::grpc::experimental::TlsCredentialsOptions& options);
const experimental::TlsCredentialsOptions& options);
} // namespace experimental
} // namespace grpc

@ -1,89 +0,0 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/security/tls_credentials_options.h>
#include <grpcpp/support/config.h>
struct grpc_server;
namespace grpc {
struct SslServerCredentialsOptions;
} // namespace grpc
namespace grpc_impl {
class Server;
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials {
public:
virtual ~ServerCredentials();
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) = 0;
private:
friend class ::grpc_impl::Server;
/// Tries to bind \a server to the given \a addr (eg, localhost:1234,
/// 192.168.1.1:31416, [::1]:27182, etc.)
///
/// \return bound port number on success, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const std::string& addr, grpc_server* server) = 0;
};
/// Builds SSL ServerCredentials given SSL specific options
std::shared_ptr<ServerCredentials> SslServerCredentials(
const grpc::SslServerCredentialsOptions& options);
/// Builds insecure server credentials.
std::shared_ptr<ServerCredentials> InsecureServerCredentials();
namespace experimental {
/// Options to create ServerCredentials with ALTS
struct AltsServerCredentialsOptions {
/// Add fields if needed.
};
/// Builds ALTS ServerCredentials given ALTS specific options
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type);
/// Builds TLS ServerCredentials given TLS options.
std::shared_ptr<ServerCredentials> TlsServerCredentials(
const grpc::experimental::TlsCredentialsOptions& options);
} // namespace experimental
} // namespace grpc_impl
#endif // GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H

@ -43,13 +43,13 @@ namespace grpc_impl {
class CompletionQueue;
class Server;
class ServerCompletionQueue;
class ServerCredentials;
} // namespace grpc_impl
namespace grpc {
class AsyncGenericService;
class ResourceQuota;
class ServerCredentials;
class Service;
namespace testing {
class ServerBuilderPluginTest;
@ -134,7 +134,7 @@ class ServerBuilder {
/// does not modify this pointer.
ServerBuilder& AddListeningPort(
const std::string& addr_uri,
std::shared_ptr<grpc_impl::ServerCredentials> creds,
std::shared_ptr<grpc::ServerCredentials> creds,
int* selected_port = nullptr);
/// Add a completion queue for handling asynchronous services.
@ -316,7 +316,7 @@ class ServerBuilder {
/// Experimental, to be deprecated
struct Port {
std::string addr;
std::shared_ptr<grpc_impl::ServerCredentials> creds;
std::shared_ptr<ServerCredentials> creds;
int* selected_port;
};
@ -384,7 +384,7 @@ class ServerBuilder {
/// List of completion queues added via \a AddCompletionQueue method.
std::vector<grpc_impl::ServerCompletionQueue*> cqs_;
std::shared_ptr<grpc_impl::ServerCredentials> creds_;
std::shared_ptr<grpc::ServerCredentials> creds_;
std::vector<std::unique_ptr<grpc::ServerBuilderPlugin>> plugins_;
grpc_resource_quota* resource_quota_;
grpc::AsyncGenericService* generic_service_{nullptr};

@ -19,7 +19,7 @@
#ifndef GRPCPP_SUPPORT_ERROR_DETAILS_H
#define GRPCPP_SUPPORT_ERROR_DETAILS_H
#include <grpcpp/support/error_details_impl.h>
#include <grpcpp/support/status.h>
namespace google {
namespace rpc {
@ -29,15 +29,19 @@ class Status;
namespace grpc {
static inline Status ExtractErrorDetails(const Status& from,
::google::rpc::Status* to) {
return ::grpc_impl::ExtractErrorDetails(from, to);
}
static inline Status SetErrorDetails(const ::google::rpc::Status& from,
Status* to) {
return ::grpc_impl::SetErrorDetails(from, to);
}
/// Map a \a grpc::Status to a \a google::rpc::Status.
/// The given \a to object will be cleared.
/// On success, returns status with OK.
/// Returns status with \a INVALID_ARGUMENT, if failed to deserialize.
/// Returns status with \a FAILED_PRECONDITION, if \a to is nullptr.
grpc::Status ExtractErrorDetails(const grpc::Status& from,
::google::rpc::Status* to);
/// Map \a google::rpc::Status to a \a grpc::Status.
/// Returns OK on success.
/// Returns status with \a FAILED_PRECONDITION if \a to is nullptr.
grpc::Status SetErrorDetails(const ::google::rpc::Status& from,
grpc::Status* to);
} // namespace grpc

@ -1,48 +0,0 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H
#define GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H
#include <grpcpp/support/status.h>
namespace google {
namespace rpc {
class Status;
} // namespace rpc
} // namespace google
namespace grpc_impl {
/// Map a \a grpc::Status to a \a google::rpc::Status.
/// The given \a to object will be cleared.
/// On success, returns status with OK.
/// Returns status with \a INVALID_ARGUMENT, if failed to deserialize.
/// Returns status with \a FAILED_PRECONDITION, if \a to is nullptr.
grpc::Status ExtractErrorDetails(const grpc::Status& from,
::google::rpc::Status* to);
/// Map \a google::rpc::Status to a \a grpc::Status.
/// Returns OK on success.
/// Returns status with \a FAILED_PRECONDITION if \a to is nullptr.
grpc::Status SetErrorDetails(const ::google::rpc::Status& from,
grpc::Status* to);
} // namespace grpc_impl
#endif // GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H

@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""A setup module for the GRPC Python package."""
# setuptools need to be imported before distutils. Otherwise it might lead to
# undesirable behaviors or errors.
import setuptools
from distutils import cygwinccompiler
from distutils import extension as _extension
from distutils import util
@ -25,7 +30,6 @@ import shutil
import sys
import sysconfig
import setuptools
from setuptools.command import egg_info
import subprocess

@ -13,24 +13,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import shutil
import sys
import json
import os
import sys
import yaml
sys.dont_write_bytecode = True
boring_ssl_root = os.path.abspath(
os.path.join(os.path.dirname(sys.argv[0]),
'../../third_party/boringssl-with-bazel/src'))
sys.path.append(os.path.join(boring_ssl_root, 'util'))
run_dir = os.path.dirname(sys.argv[0])
sources_path = os.path.abspath(
os.path.join(run_dir,
'../../third_party/boringssl-with-bazel/sources.json'))
try:
import generate_build_files
except ImportError:
print(yaml.dump({}))
sys.exit()
with open(sources_path, 'r') as s:
sources = json.load(s)
except IOError:
sources_path = os.path.abspath(
os.path.join(run_dir,
'../../../../third_party/openssl/boringssl/sources.json'))
with open(sources_path, 'r') as s:
sources = json.load(s)
def map_dir(filename):
@ -38,18 +38,19 @@ def map_dir(filename):
class Grpc(object):
"""Implements a "platform" in the sense of boringssl's generate_build_files.py"""
yaml = None
"""Adapter for boring-SSL json sources files. """
def WriteFiles(self, files, asm_outputs):
test_binaries = ['ssl_test', 'crypto_test']
def __init__(self, sources):
self.yaml = None
self.WriteFiles(sources)
def WriteFiles(self, files):
test_binaries = ['ssl_test', 'crypto_test']
self.yaml = {
'#':
'generated with src/boringssl/gen_build_yaml.py',
'raw_boringssl_build_output_for_debugging': {
'files': files,
'asm_outputs': asm_outputs,
},
'libs': [
{
@ -120,29 +121,5 @@ class Grpc(object):
}
os.chdir(os.path.dirname(sys.argv[0]))
os.mkdir('src')
try:
for f in os.listdir(boring_ssl_root):
os.symlink(os.path.join(boring_ssl_root, f), os.path.join('src', f))
grpc_platform = Grpc()
# We use a hack to run boringssl's util/generate_build_files.py as part of this script.
# The call will populate "grpc_platform" with boringssl's source file metadata.
# As a side effect this script generates err_data.c and crypto_test_data.cc (requires golang)
# Both of these files are already available under third_party/boringssl-with-bazel
# so we don't need to generate them again, but there's no option to disable that behavior.
# - crypto_test_data.cc is required to run boringssl_crypto_test but we already
# use the copy under third_party/boringssl-with-bazel so we just delete it
# - err_data.c is already under third_party/boringssl-with-bazel so we just delete it
generate_build_files.main([grpc_platform])
print(yaml.dump(grpc_platform.yaml))
finally:
# we don't want err_data.c and crypto_test_data.cc (see comment above)
if os.path.exists('err_data.c'):
os.remove('err_data.c')
if os.path.exists('crypto_test_data.cc'):
os.remove('crypto_test_data.cc')
shutil.rmtree('src')
grpc_platform = Grpc(sources)
print(yaml.dump(grpc_platform.yaml))

@ -79,4 +79,4 @@ void grpc_client_channel_stop_connectivity_watch(
grpc_core::RefCountedPtr<grpc_core::SubchannelCall>
grpc_client_channel_get_subchannel_call(grpc_call_element* elem);
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_H */
#endif // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_H

@ -325,10 +325,9 @@ void HttpConnectHandshaker::DoHandshake(grpc_tcp_server_acceptor* /*acceptor*/,
args_ = args;
on_handshake_done_ = on_handshake_done;
// Log connection via proxy.
char* proxy_name = grpc_endpoint_get_peer(args->endpoint);
std::string proxy_name(grpc_endpoint_get_peer(args->endpoint));
gpr_log(GPR_INFO, "Connecting to server %s via HTTP proxy %s", server_name,
proxy_name);
gpr_free(proxy_name);
proxy_name.c_str());
// Construct HTTP CONNECT request.
grpc_httpcli_request request;
request.host = server_name;

@ -26,23 +26,56 @@ namespace grpc_core {
// ServerAddress
//
ServerAddress::ServerAddress(const grpc_resolved_address& address,
grpc_channel_args* args)
: address_(address), args_(args) {}
ServerAddress::ServerAddress(
const grpc_resolved_address& address, grpc_channel_args* args,
std::map<const char*, std::unique_ptr<AttributeInterface>> attributes)
: address_(address), args_(args), attributes_(std::move(attributes)) {}
ServerAddress::ServerAddress(const void* address, size_t address_len,
grpc_channel_args* args)
: args_(args) {
ServerAddress::ServerAddress(
const void* address, size_t address_len, grpc_channel_args* args,
std::map<const char*, std::unique_ptr<AttributeInterface>> attributes)
: args_(args), attributes_(std::move(attributes)) {
memcpy(address_.addr, address, address_len);
address_.len = static_cast<socklen_t>(address_len);
}
namespace {
int CompareAttributes(
const std::map<const char*,
std::unique_ptr<ServerAddress::AttributeInterface>>&
attributes1,
const std::map<const char*,
std::unique_ptr<ServerAddress::AttributeInterface>>&
attributes2) {
auto it2 = attributes2.begin();
for (auto it1 = attributes1.begin(); it1 != attributes1.end(); ++it1) {
// attributes2 has fewer elements than attributes1
if (it2 == attributes2.end()) return -1;
// compare keys
int retval = strcmp(it1->first, it2->first);
if (retval != 0) return retval;
// compare values
retval = it1->second->Cmp(it2->second.get());
if (retval != 0) return retval;
++it2;
}
// attributes1 has fewer elements than attributes2
if (it2 != attributes2.end()) return 1;
// equal
return 0;
}
} // namespace
int ServerAddress::Cmp(const ServerAddress& other) const {
if (address_.len > other.address_.len) return 1;
if (address_.len < other.address_.len) return -1;
int retval = memcmp(address_.addr, other.address_.addr, address_.len);
if (retval != 0) return retval;
return grpc_channel_args_compare(args_, other.args_);
retval = grpc_channel_args_compare(args_, other.args_);
if (retval != 0) return retval;
return CompareAttributes(attributes_, other.attributes_);
}
} // namespace grpc_core

@ -21,6 +21,8 @@
#include <grpc/support/port_platform.h>
#include <map>
#include "absl/container/inlined_vector.h"
#include "src/core/lib/channel/channel_args.h"
@ -37,26 +39,54 @@ namespace grpc_core {
// args when a subchannel is created for this address.
class ServerAddress {
public:
// Base clas for resolver-supplied attributes.
// Unlike channel args, these attributes don't affect subchannel
// uniqueness or behavior. They are for use by LB policies only.
class AttributeInterface {
public:
virtual ~AttributeInterface();
// Creates a copy of the attribute.
virtual std::unique_ptr<AttributeInterface> Copy() const = 0;
// Compares this attribute with another.
virtual int Cmp(const AttributeInterface* other) const = 0;
};
// Takes ownership of args.
ServerAddress(const grpc_resolved_address& address, grpc_channel_args* args);
ServerAddress(const grpc_resolved_address& address, grpc_channel_args* args,
std::map<const char*, std::unique_ptr<AttributeInterface>>
attributes = {});
ServerAddress(const void* address, size_t address_len,
grpc_channel_args* args);
grpc_channel_args* args,
std::map<const char*, std::unique_ptr<AttributeInterface>>
attributes = {});
~ServerAddress() { grpc_channel_args_destroy(args_); }
// Copyable.
ServerAddress(const ServerAddress& other)
: address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {}
: address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {
for (const auto& p : other.attributes_) {
attributes_[p.first] = p.second->Copy();
}
}
ServerAddress& operator=(const ServerAddress& other) {
address_ = other.address_;
grpc_channel_args_destroy(args_);
args_ = grpc_channel_args_copy(other.args_);
attributes_.clear();
for (const auto& p : other.attributes_) {
attributes_[p.first] = p.second->Copy();
}
return *this;
}
// Movable.
ServerAddress(ServerAddress&& other)
: address_(other.address_), args_(other.args_) {
: address_(other.address_),
args_(other.args_),
attributes_(std::move(other.attributes_)) {
other.args_ = nullptr;
}
ServerAddress& operator=(ServerAddress&& other) {
@ -64,6 +94,7 @@ class ServerAddress {
grpc_channel_args_destroy(args_);
args_ = other.args_;
other.args_ = nullptr;
attributes_ = std::move(other.attributes_);
return *this;
}
@ -74,9 +105,16 @@ class ServerAddress {
const grpc_resolved_address& address() const { return address_; }
const grpc_channel_args* args() const { return args_; }
const AttributeInterface* GetAttribute(const char* key) const {
auto it = attributes_.find(key);
if (it == attributes_.end()) return nullptr;
return it->second.get();
}
private:
grpc_resolved_address address_;
grpc_channel_args* args_;
std::map<const char*, std::unique_ptr<AttributeInterface>> attributes_;
};
//

@ -129,6 +129,15 @@ void Chttp2Connector::StartHandshakeLocked() {
endpoint_ = nullptr; // Endpoint handed off to handshake manager.
}
namespace {
void NullThenSchedClosure(const DebugLocation& location, grpc_closure** closure,
grpc_error* error) {
grpc_closure* c = *closure;
*closure = nullptr;
ExecCtx::Run(location, c, error);
}
} // namespace
void Chttp2Connector::OnHandshakeDone(void* arg, grpc_error* error) {
auto* args = static_cast<HandshakerArgs*>(arg);
Chttp2Connector* self = static_cast<Chttp2Connector*>(args->user_data);
@ -154,53 +163,99 @@ void Chttp2Connector::OnHandshakeDone(void* arg, grpc_error* error) {
error = GRPC_ERROR_REF(error);
}
self->result_->Reset();
NullThenSchedClosure(DEBUG_LOCATION, &self->notify_, error);
} else if (args->endpoint != nullptr) {
grpc_endpoint_delete_from_pollset_set(args->endpoint,
self->args_.interested_parties);
self->result_->transport =
grpc_create_chttp2_transport(args->args, args->endpoint, true);
self->result_->socket_node =
grpc_chttp2_transport_get_socket_node(self->result_->transport);
self->result_->channel_args = args->args;
GPR_ASSERT(self->result_->transport != nullptr);
// TODO(roth): We ideally want to wait until we receive HTTP/2
// settings from the server before we consider the connection
// established. If that doesn't happen before the connection
// timeout expires, then we should consider the connection attempt a
// failure and feed that information back into the backoff code.
// We could pass a notify_on_receive_settings callback to
// grpc_chttp2_transport_start_reading() to let us know when
// settings are received, but we would need to figure out how to use
// that information here.
//
// Unfortunately, we don't currently have a way to split apart the two
// effects of scheduling c->notify: we start sending RPCs immediately
// (which we want to do) and we consider the connection attempt successful
// (which we don't want to do until we get the notify_on_receive_settings
// callback from the transport). If we could split those things
// apart, then we could start sending RPCs but then wait for our
// timeout before deciding if the connection attempt is successful.
// If the attempt is not successful, then we would tear down the
// transport and feed the failure back into the backoff code.
//
// In addition, even if we did that, we would probably not want to do
// so until after transparent retries is implemented. Otherwise, any
// RPC that we attempt to send on the connection before the timeout
// would fail instead of being retried on a subsequent attempt.
self->endpoint_ = args->endpoint;
self->Ref().release(); // Ref held by OnReceiveSettings()
GRPC_CLOSURE_INIT(&self->on_receive_settings_, OnReceiveSettings, self,
grpc_schedule_on_exec_ctx);
self->Ref().release(); // Ref held by OnTimeout()
grpc_chttp2_transport_start_reading(self->result_->transport,
args->read_buffer, nullptr);
self->result_->channel_args = args->args;
args->read_buffer,
&self->on_receive_settings_);
GRPC_CLOSURE_INIT(&self->on_timeout_, OnTimeout, self,
grpc_schedule_on_exec_ctx);
grpc_timer_init(&self->timer_, self->args_.deadline, &self->on_timeout_);
} else {
// If the handshaking succeeded but there is no endpoint, then the
// handshaker may have handed off the connection to some external
// code. Just verify that exit_early flag is set.
GPR_DEBUG_ASSERT(args->exit_early);
NullThenSchedClosure(DEBUG_LOCATION, &self->notify_, error);
}
grpc_closure* notify = self->notify_;
self->notify_ = nullptr;
ExecCtx::Run(DEBUG_LOCATION, notify, error);
self->handshake_mgr_.reset();
}
self->Unref();
}
void Chttp2Connector::OnReceiveSettings(void* arg, grpc_error* error) {
Chttp2Connector* self = static_cast<Chttp2Connector*>(arg);
{
MutexLock lock(&self->mu_);
if (!self->notify_error_.has_value()) {
if (error != GRPC_ERROR_NONE) {
// Transport got an error while waiting on SETTINGS frame.
// TODO(yashykt): The following two lines should be moved to
// SubchannelConnector::Result::Reset()
grpc_transport_destroy(self->result_->transport);
grpc_channel_args_destroy(self->result_->channel_args);
self->result_->Reset();
}
self->MaybeNotify(GRPC_ERROR_REF(error));
grpc_timer_cancel(&self->timer_);
} else {
// OnTimeout() was already invoked. Call Notify() again so that notify_
// can be invoked.
self->MaybeNotify(GRPC_ERROR_NONE);
}
}
self->Unref();
}
void Chttp2Connector::OnTimeout(void* arg, grpc_error* error) {
Chttp2Connector* self = static_cast<Chttp2Connector*>(arg);
{
MutexLock lock(&self->mu_);
if (!self->notify_error_.has_value()) {
// The transport did not receive the settings frame in time. Destroy the
// transport.
// TODO(yashykt): The following two lines should be moved to
// SubchannelConnector::Result::Reset()
grpc_transport_destroy(self->result_->transport);
grpc_channel_args_destroy(self->result_->channel_args);
self->result_->Reset();
self->MaybeNotify(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"connection attempt timed out before receiving SETTINGS frame"));
} else {
// OnReceiveSettings() was already invoked. Call Notify() again so that
// notify_ can be invoked.
self->MaybeNotify(GRPC_ERROR_NONE);
}
}
self->Unref();
}
void Chttp2Connector::MaybeNotify(grpc_error* error) {
if (notify_error_.has_value()) {
GRPC_ERROR_UNREF(error);
NullThenSchedClosure(DEBUG_LOCATION, &notify_, notify_error_.value());
// Clear out the endpoint, since it is the responsibility of the transport
// to shut it down.
// Clear state for a new Connect().
grpc_endpoint_delete_from_pollset_set(endpoint_, args_.interested_parties);
// We do not destroy the endpoint here, since it is the responsibility of
// the transport to shut it down.
endpoint_ = nullptr;
notify_error_.reset();
} else {
notify_error_ = error;
}
}
} // namespace grpc_core

@ -39,6 +39,19 @@ class Chttp2Connector : public SubchannelConnector {
static void Connected(void* arg, grpc_error* error);
void StartHandshakeLocked();
static void OnHandshakeDone(void* arg, grpc_error* error);
static void OnReceiveSettings(void* arg, grpc_error* error);
static void OnTimeout(void* arg, grpc_error* error);
// We cannot invoke notify_ until both OnTimeout() and OnReceiveSettings()
// have been called since that is an indicator to the upper layer that we are
// done with the connection attempt. So, the notification process is broken
// into two steps. 1) Either OnTimeout() or OnReceiveSettings() gets invoked
// first. Whichever gets invoked, calls MaybeNotify() to set the result and
// triggers the other callback to be invoked. 2) When the other callback is
// invoked, we call MaybeNotify() again to actually invoke the notify_
// callback. Note that this only happens if the handshake is done and the
// connector is waiting on the SETTINGS frame.
void MaybeNotify(grpc_error* error);
Mutex mu_;
Args args_;
@ -47,9 +60,13 @@ class Chttp2Connector : public SubchannelConnector {
bool shutdown_ = false;
bool connecting_ = false;
// Holds the endpoint when first created before being handed off to
// the handshake manager.
// the handshake manager, and then again after handshake is done.
grpc_endpoint* endpoint_ = nullptr;
grpc_closure connected_;
grpc_closure on_receive_settings_;
grpc_timer timer_;
grpc_closure on_timeout_;
absl::optional<grpc_error*> notify_error_;
RefCountedPtr<HandshakeManager> handshake_mgr_;
};

@ -53,19 +53,19 @@
namespace grpc_core {
namespace {
class Chttp2ServerListener : public ServerListenerInterface {
class Chttp2ServerListener : public Server::ListenerInterface {
public:
static grpc_error* Create(grpc_server* server, const char* addr,
static grpc_error* Create(Server* server, const char* addr,
grpc_channel_args* args, int* port_num);
static grpc_error* CreateWithAcceptor(grpc_server* server, const char* name,
static grpc_error* CreateWithAcceptor(Server* server, const char* name,
grpc_channel_args* args);
// Do not instantiate directly. Use one of the factory methods above.
Chttp2ServerListener(grpc_server* server, grpc_channel_args* args);
Chttp2ServerListener(Server* server, grpc_channel_args* args);
~Chttp2ServerListener();
void Start(grpc_server* server,
void Start(Server* server,
const std::vector<grpc_pollset*>* pollsets) override;
channelz::ListenSocketNode* channelz_listen_socket_node() const override {
@ -113,10 +113,10 @@ class Chttp2ServerListener : public ServerListenerInterface {
static void TcpServerShutdownComplete(void* arg, grpc_error* error);
static void DestroyListener(grpc_server* /*server*/, void* arg,
static void DestroyListener(Server* /*server*/, void* arg,
grpc_closure* destroy_done);
grpc_server* const server_;
Server* const server_;
grpc_channel_args* const args_;
grpc_tcp_server* tcp_server_;
Mutex mu_;
@ -194,12 +194,10 @@ void Chttp2ServerListener::ConnectionState::OnHandshakeDone(void* arg,
{
MutexLock lock(&self->listener_->mu_);
grpc_resource_user* resource_user =
grpc_server_get_default_resource_user(self->listener_->server_);
self->listener_->server_->default_resource_user();
if (error != GRPC_ERROR_NONE || self->listener_->shutdown_) {
const char* error_str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "Handshaking failed: %s", error_str);
grpc_resource_user* resource_user =
grpc_server_get_default_resource_user(self->listener_->server_);
if (resource_user != nullptr) {
grpc_resource_user_free(resource_user,
GRPC_RESOURCE_QUOTA_CHANNEL_SIZE);
@ -224,10 +222,9 @@ void Chttp2ServerListener::ConnectionState::OnHandshakeDone(void* arg,
if (args->endpoint != nullptr) {
grpc_transport* transport = grpc_create_chttp2_transport(
args->args, args->endpoint, false, resource_user);
grpc_server_setup_transport(
self->listener_->server_, transport, self->accepting_pollset_,
args->args, grpc_chttp2_transport_get_socket_node(transport),
resource_user);
self->listener_->server_->SetupTransport(
transport, self->accepting_pollset_, args->args,
grpc_chttp2_transport_get_socket_node(transport), resource_user);
// Use notify_on_receive_settings callback to enforce the
// handshake deadline.
// Note: The reinterpret_cast<>s here are safe, because
@ -270,7 +267,7 @@ void Chttp2ServerListener::ConnectionState::OnHandshakeDone(void* arg,
// Chttp2ServerListener
//
grpc_error* Chttp2ServerListener::Create(grpc_server* server, const char* addr,
grpc_error* Chttp2ServerListener::Create(Server* server, const char* addr,
grpc_channel_args* args,
int* port_num) {
std::vector<grpc_error*> error_list;
@ -327,8 +324,7 @@ grpc_error* Chttp2ServerListener::Create(grpc_server* server, const char* addr,
addr, absl::StrFormat("chttp2 listener %s", addr));
}
/* Register with the server only upon success */
grpc_server_add_listener(server,
OrphanablePtr<ServerListenerInterface>(listener));
server->AddListener(OrphanablePtr<Server::ListenerInterface>(listener));
return GRPC_ERROR_NONE;
}();
if (resolved != nullptr) {
@ -352,7 +348,7 @@ grpc_error* Chttp2ServerListener::Create(grpc_server* server, const char* addr,
return error;
}
grpc_error* Chttp2ServerListener::CreateWithAcceptor(grpc_server* server,
grpc_error* Chttp2ServerListener::CreateWithAcceptor(Server* server,
const char* name,
grpc_channel_args* args) {
Chttp2ServerListener* listener = new Chttp2ServerListener(server, args);
@ -366,12 +362,11 @@ grpc_error* Chttp2ServerListener::CreateWithAcceptor(grpc_server* server,
TcpServerFdHandler** arg_val =
grpc_channel_args_find_pointer<TcpServerFdHandler*>(args, name);
*arg_val = grpc_tcp_server_create_fd_handler(listener->tcp_server_);
grpc_server_add_listener(server,
OrphanablePtr<ServerListenerInterface>(listener));
server->AddListener(OrphanablePtr<Server::ListenerInterface>(listener));
return GRPC_ERROR_NONE;
}
Chttp2ServerListener::Chttp2ServerListener(grpc_server* server,
Chttp2ServerListener::Chttp2ServerListener(Server* server,
grpc_channel_args* args)
: server_(server), args_(args) {
GRPC_CLOSURE_INIT(&tcp_server_shutdown_complete_, TcpServerShutdownComplete,
@ -383,7 +378,7 @@ Chttp2ServerListener::~Chttp2ServerListener() {
}
/* Server callback: start listening on our ports */
void Chttp2ServerListener::Start(grpc_server* /*server*/,
void Chttp2ServerListener::Start(Server* /*server*/,
const std::vector<grpc_pollset*>* pollsets) {
{
MutexLock lock(&mu_);
@ -400,8 +395,7 @@ void Chttp2ServerListener::SetOnDestroyDone(grpc_closure* on_destroy_done) {
RefCountedPtr<HandshakeManager> Chttp2ServerListener::CreateHandshakeManager() {
MutexLock lock(&mu_);
if (shutdown_) return nullptr;
grpc_resource_user* resource_user =
grpc_server_get_default_resource_user(server_);
grpc_resource_user* resource_user = server_->default_resource_user();
if (resource_user != nullptr &&
!grpc_resource_user_safe_alloc(resource_user,
GRPC_RESOURCE_QUOTA_CHANNEL_SIZE)) {
@ -475,7 +469,7 @@ void Chttp2ServerListener::Orphan() {
// Chttp2ServerAddPort()
//
grpc_error* Chttp2ServerAddPort(grpc_server* server, const char* addr,
grpc_error* Chttp2ServerAddPort(Server* server, const char* addr,
grpc_channel_args* args, int* port_num) {
if (strncmp(addr, "external:", 9) == 0) {
return grpc_core::Chttp2ServerListener::CreateWithAcceptor(server, addr,

@ -24,12 +24,13 @@
#include <grpc/impl/codegen/grpc_types.h>
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/surface/server.h"
namespace grpc_core {
/// Adds a port to \a server. Sets \a port_num to the port number.
/// Takes ownership of \a args.
grpc_error* Chttp2ServerAddPort(grpc_server* server, const char* addr,
grpc_error* Chttp2ServerAddPort(Server* server, const char* addr,
grpc_channel_args* args, int* port_num);
} // namespace grpc_core

@ -33,8 +33,8 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) {
GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2,
(server, addr));
grpc_error* err = grpc_core::Chttp2ServerAddPort(
server, addr,
grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num);
server->core_server.get(), addr,
grpc_channel_args_copy(server->core_server->channel_args()), &port_num);
if (err != GRPC_ERROR_NONE) {
const char* msg = grpc_error_string(err);
gpr_log(GPR_ERROR, "%s", msg);

@ -41,21 +41,21 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server,
GPR_ASSERT(reserved == nullptr);
grpc_core::ExecCtx exec_ctx;
grpc_core::Server* core_server = server->core_server.get();
const grpc_channel_args* server_args = core_server->channel_args();
std::string name = absl::StrCat("fd:", fd);
grpc_endpoint* server_endpoint =
grpc_tcp_create(grpc_fd_create(fd, name.c_str(), true),
grpc_server_get_channel_args(server), name.c_str());
grpc_endpoint* server_endpoint = grpc_tcp_create(
grpc_fd_create(fd, name.c_str(), true), server_args, name.c_str());
const grpc_channel_args* server_args = grpc_server_get_channel_args(server);
grpc_transport* transport = grpc_create_chttp2_transport(
server_args, server_endpoint, false /* is_client */);
for (grpc_pollset* pollset : grpc_server_get_pollsets(server)) {
for (grpc_pollset* pollset : core_server->pollsets()) {
grpc_endpoint_add_to_pollset(server_endpoint, pollset);
}
grpc_server_setup_transport(server, transport, nullptr, server_args, nullptr);
core_server->SetupTransport(transport, nullptr, server_args, nullptr);
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr);
}

@ -68,10 +68,11 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr,
args_to_add[0] = grpc_server_credentials_to_arg(creds);
args_to_add[1] = grpc_security_connector_to_arg(sc.get());
args =
grpc_channel_args_copy_and_add(grpc_server_get_channel_args(server),
grpc_channel_args_copy_and_add(server->core_server->channel_args(),
args_to_add, GPR_ARRAY_SIZE(args_to_add));
// Add server port.
err = grpc_core::Chttp2ServerAddPort(server, addr, args, &port_num);
err = grpc_core::Chttp2ServerAddPort(server->core_server.get(), addr, args,
&port_num);
done:
sc.reset(DEBUG_LOCATION, "server");

@ -226,7 +226,6 @@ grpc_chttp2_transport::~grpc_chttp2_transport() {
GRPC_ERROR_UNREF(closed_with_error);
gpr_free(ping_acks);
gpr_free(peer_string);
}
static const grpc_transport_vtable* get_vtable(void);
@ -378,11 +377,9 @@ static bool read_channel_args(grpc_chttp2_transport* t,
}
}
if (channelz_enabled) {
// TODO(ncteisen): add an API to endpoint to query for local addr, and pass
// it in here, so SocketNode knows its own address.
t->channelz_socket =
grpc_core::MakeRefCounted<grpc_core::channelz::SocketNode>(
"", t->peer_string,
std::string(grpc_endpoint_get_local_address(t->ep)), t->peer_string,
absl::StrFormat("%s %s", get_vtable()->name, t->peer_string));
}
return enable_bdp;
@ -594,7 +591,7 @@ static void close_transport_locked(grpc_chttp2_transport* t,
}
if (t->notify_on_receive_settings != nullptr) {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, t->notify_on_receive_settings,
GRPC_ERROR_CANCELLED);
GRPC_ERROR_REF(error));
t->notify_on_receive_settings = nullptr;
}
GRPC_ERROR_UNREF(error);
@ -795,7 +792,7 @@ static void set_write_state(grpc_chttp2_transport* t,
grpc_chttp2_write_state st, const char* reason) {
GRPC_CHTTP2_IF_TRACING(
gpr_log(GPR_INFO, "W:%p %s [%s] state %s -> %s [%s]", t,
t->is_client ? "CLIENT" : "SERVER", t->peer_string,
t->is_client ? "CLIENT" : "SERVER", t->peer_string.c_str(),
write_state_name(t->write_state), write_state_name(st), reason));
t->write_state = st;
// If the state is being reset back to idle, it means a write was just
@ -1084,7 +1081,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
// We want to log this irrespective of whether http tracing is enabled if we
// received a GOAWAY with a non NO_ERROR code.
if (goaway_error != GRPC_HTTP2_NO_ERROR) {
gpr_log(GPR_INFO, "%s: Got goaway [%d] err=%s", t->peer_string,
gpr_log(GPR_INFO, "%s: Got goaway [%d] err=%s", t->peer_string.c_str(),
goaway_error, grpc_error_string(t->goaway_error));
}
// When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug
@ -1216,7 +1213,7 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t,
"Error in HTTP transport completing operation");
closure->error_data.error = grpc_error_set_str(
closure->error_data.error, GRPC_ERROR_STR_TARGET_ADDRESS,
grpc_slice_from_copied_string(t->peer_string));
grpc_slice_from_copied_string(t->peer_string.c_str()));
}
closure->error_data.error =
grpc_error_add_child(closure->error_data.error, error);
@ -1474,7 +1471,7 @@ static void perform_stream_op_locked(void* stream_op,
}
if (op_payload->send_initial_metadata.peer_string != nullptr) {
gpr_atm_rel_store(op_payload->send_initial_metadata.peer_string,
(gpr_atm)t->peer_string);
(gpr_atm)t->peer_string.c_str());
}
}
@ -1587,7 +1584,7 @@ static void perform_stream_op_locked(void* stream_op,
op_payload->recv_initial_metadata.trailing_metadata_available;
if (op_payload->recv_initial_metadata.peer_string != nullptr) {
gpr_atm_rel_store(op_payload->recv_initial_metadata.peer_string,
(gpr_atm)t->peer_string);
(gpr_atm)t->peer_string.c_str());
}
grpc_chttp2_maybe_complete_recv_initial_metadata(t, s);
}
@ -1755,9 +1752,8 @@ static void retry_initiate_ping_locked(void* tp, grpc_error* error) {
void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) {
grpc_chttp2_ping_queue* pq = &t->ping_queue;
if (pq->inflight_id != id) {
char* from = grpc_endpoint_get_peer(t->ep);
gpr_log(GPR_DEBUG, "Unknown ping response from %s: %" PRIx64, from, id);
gpr_free(from);
gpr_log(GPR_DEBUG, "Unknown ping response from %s: %" PRIx64,
t->peer_string.c_str(), id);
return;
}
grpc_core::ExecCtx::RunList(DEBUG_LOCATION,
@ -1769,7 +1765,7 @@ void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) {
static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) {
// We want to log this irrespective of whether http tracing is enabled
gpr_log(GPR_INFO, "%s: Sending goaway err=%s", t->peer_string,
gpr_log(GPR_INFO, "%s: Sending goaway err=%s", t->peer_string.c_str(),
grpc_error_string(error));
t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED;
grpc_http2_error_code http_error;
@ -2641,7 +2637,7 @@ static void start_bdp_ping(void* tp, grpc_error* error) {
static void start_bdp_ping_locked(void* tp, grpc_error* error) {
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_INFO, "%s: Start BDP ping err=%s", t->peer_string,
gpr_log(GPR_INFO, "%s: Start BDP ping err=%s", t->peer_string.c_str(),
grpc_error_string(error));
}
if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
@ -2665,7 +2661,7 @@ static void finish_bdp_ping(void* tp, grpc_error* error) {
static void finish_bdp_ping_locked(void* tp, grpc_error* error) {
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp);
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s", t->peer_string,
gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s", t->peer_string.c_str(),
grpc_error_string(error));
}
if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) {
@ -2835,7 +2831,7 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) {
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace) ||
GRPC_TRACE_FLAG_ENABLED(grpc_keepalive_trace)) {
gpr_log(GPR_INFO, "%s: Start keepalive ping", t->peer_string);
gpr_log(GPR_INFO, "%s: Start keepalive ping", t->peer_string.c_str());
}
GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog");
GRPC_CLOSURE_INIT(&t->keepalive_watchdog_fired_locked,
@ -2859,7 +2855,7 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) {
if (error == GRPC_ERROR_NONE) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace) ||
GRPC_TRACE_FLAG_ENABLED(grpc_keepalive_trace)) {
gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string);
gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string.c_str());
}
if (!t->keepalive_ping_started) {
// start_keepalive_ping_locked has not run yet. Reschedule
@ -2897,7 +2893,7 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) {
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
if (error == GRPC_ERROR_NONE) {
gpr_log(GPR_INFO, "%s: Keepalive watchdog fired. Closing transport.",
t->peer_string);
t->peer_string.c_str());
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
close_transport_locked(
t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
@ -3205,7 +3201,7 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) {
// disconnect cleanly
if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory",
t->peer_string);
t->peer_string.c_str());
}
send_goaway(t,
grpc_error_set_int(
@ -3216,7 +3212,8 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) {
gpr_log(GPR_INFO,
"HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
" streams",
t->peer_string, grpc_chttp2_stream_map_size(&t->stream_map));
t->peer_string.c_str(),
grpc_chttp2_stream_map_size(&t->stream_map));
}
t->benign_reclaimer_registered = false;
if (error != GRPC_ERROR_CANCELLED) {
@ -3241,8 +3238,8 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) {
grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(
grpc_chttp2_stream_map_rand(&t->stream_map));
if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) {
gpr_log(GPR_INFO, "HTTP2: %s - abandon stream id %d", t->peer_string,
s->id);
gpr_log(GPR_INFO, "HTTP2: %s - abandon stream id %d",
t->peer_string.c_str(), s->id);
}
grpc_chttp2_cancel_stream(
t, s,

@ -175,7 +175,7 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t,
bool enable_bdp_probe)
: t_(t),
enable_bdp_probe_(enable_bdp_probe),
bdp_estimator_(t->peer_string),
bdp_estimator_(t->peer_string.c_str()),
pid_controller_(grpc_core::PidController::Args()
.set_gain_p(4)
.set_gain_i(8)

@ -228,8 +228,8 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
parser->incoming_settings[id] = parser->value;
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_INFO, "CHTTP2:%s:%s: got setting %s = %d",
t->is_client ? "CLI" : "SVR", t->peer_string, sp->name,
parser->value);
t->is_client ? "CLI" : "SVR", t->peer_string.c_str(),
sp->name, parser->value);
}
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
gpr_log(GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)",

@ -290,7 +290,7 @@ struct grpc_chttp2_transport {
grpc_transport base; /* must be first */
grpc_core::RefCount refs;
grpc_endpoint* ep;
char* peer_string;
std::string peer_string;
grpc_resource_user* resource_user;

@ -58,7 +58,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) {
GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace) ||
GRPC_TRACE_FLAG_ENABLED(grpc_keepalive_trace)) {
gpr_log(GPR_INFO, "%s: Ping delayed [%s]: already pinging",
t->is_client ? "CLIENT" : "SERVER", t->peer_string);
t->is_client ? "CLIENT" : "SERVER", t->peer_string.c_str());
}
return;
}
@ -69,7 +69,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) {
GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace) ||
GRPC_TRACE_FLAG_ENABLED(grpc_keepalive_trace)) {
gpr_log(GPR_INFO, "%s: Ping delayed [%s]: too many recent pings: %d/%d",
t->is_client ? "CLIENT" : "SERVER", t->peer_string,
t->is_client ? "CLIENT" : "SERVER", t->peer_string.c_str(),
t->ping_state.pings_before_data_required,
t->ping_policy.max_pings_without_data);
}
@ -95,7 +95,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) {
gpr_log(GPR_INFO,
"%s: Ping delayed [%s]: not enough time elapsed since last ping. "
" Last ping %f: Next ping %f: Now %f",
t->is_client ? "CLIENT" : "SERVER", t->peer_string,
t->is_client ? "CLIENT" : "SERVER", t->peer_string.c_str(),
static_cast<double>(t->ping_state.last_ping_sent_time),
static_cast<double>(next_allowed_ping), static_cast<double>(now));
}
@ -125,7 +125,7 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) {
GRPC_TRACE_FLAG_ENABLED(grpc_bdp_estimator_trace) ||
GRPC_TRACE_FLAG_ENABLED(grpc_keepalive_trace)) {
gpr_log(GPR_INFO, "%s: Ping sent [%s]: %d/%d",
t->is_client ? "CLIENT" : "SERVER", t->peer_string,
t->is_client ? "CLIENT" : "SERVER", t->peer_string.c_str(),
t->ping_state.pings_before_data_required,
t->ping_policy.max_pings_without_data);
}
@ -165,7 +165,8 @@ static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s,
"helpful data: [fc:pending=%" PRIdPTR ":pending-compressed=%" PRIdPTR
":flowed=%" PRId64 ":peer_initwin=%d:t_win=%" PRId64
":s_win=%d:s_delta=%" PRId64 "]",
t->peer_string, t, s->id, staller, s->flow_controlled_buffer.length,
t->peer_string.c_str(), t, s->id, staller,
s->flow_controlled_buffer.length,
s->stream_compression_method ==
GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS
? 0

@ -1276,7 +1276,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server,
const char* args_to_remove[] = {GRPC_ARG_MAX_CONNECTION_IDLE_MS,
GRPC_ARG_MAX_CONNECTION_AGE_MS};
const grpc_channel_args* server_args = grpc_channel_args_copy_and_remove(
grpc_server_get_channel_args(server), args_to_remove,
server->core_server->channel_args(), args_to_remove,
GPR_ARRAY_SIZE(args_to_remove));
// Add a default authority channel argument for the client
@ -1293,8 +1293,8 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server,
client_args);
// TODO(ncteisen): design and support channelz GetSocket for inproc.
grpc_server_setup_transport(server, server_transport, nullptr, server_args,
nullptr);
server->core_server->SetupTransport(server_transport, nullptr, server_args,
nullptr);
grpc_channel* channel = grpc_channel_create(
"inproc", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport);

@ -199,7 +199,7 @@ UPB_INLINE envoy_config_cluster_v3_Cluster_lb_config_oneofcases envoy_config_clu
UPB_INLINE upb_strview envoy_config_cluster_v3_Cluster_name(const envoy_config_cluster_v3_Cluster *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview); }
UPB_INLINE bool envoy_config_cluster_v3_Cluster_has_type(const envoy_config_cluster_v3_Cluster *msg) { return _upb_getoneofcase(msg, UPB_SIZE(168, 288)) == 2; }
UPB_INLINE int32_t envoy_config_cluster_v3_Cluster_type(const envoy_config_cluster_v3_Cluster *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(160, 280), UPB_SIZE(168, 288), 2, envoy_config_cluster_v3_Cluster_STATIC); }
UPB_INLINE int32_t envoy_config_cluster_v3_Cluster_type(const envoy_config_cluster_v3_Cluster *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(160, 280), UPB_SIZE(168, 288), 2, 0); }
UPB_INLINE bool envoy_config_cluster_v3_Cluster_has_eds_cluster_config(const envoy_config_cluster_v3_Cluster *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(48, 64)); }
UPB_INLINE const envoy_config_cluster_v3_Cluster_EdsClusterConfig* envoy_config_cluster_v3_Cluster_eds_cluster_config(const envoy_config_cluster_v3_Cluster *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 64), const envoy_config_cluster_v3_Cluster_EdsClusterConfig*); }
UPB_INLINE bool envoy_config_cluster_v3_Cluster_has_connect_timeout(const envoy_config_cluster_v3_Cluster *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(52, 72)); }

@ -594,7 +594,7 @@ typedef enum {
UPB_INLINE google_api_expr_v1alpha1_Constant_constant_kind_oneofcases google_api_expr_v1alpha1_Constant_constant_kind_case(const google_api_expr_v1alpha1_Constant* msg) { return (google_api_expr_v1alpha1_Constant_constant_kind_oneofcases)*UPB_PTR_AT(msg, UPB_SIZE(8, 16), int32_t); }
UPB_INLINE bool google_api_expr_v1alpha1_Constant_has_null_value(const google_api_expr_v1alpha1_Constant *msg) { return _upb_getoneofcase(msg, UPB_SIZE(8, 16)) == 1; }
UPB_INLINE int32_t google_api_expr_v1alpha1_Constant_null_value(const google_api_expr_v1alpha1_Constant *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(0, 0), UPB_SIZE(8, 16), 1, google_protobuf_NULL_VALUE); }
UPB_INLINE int32_t google_api_expr_v1alpha1_Constant_null_value(const google_api_expr_v1alpha1_Constant *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(0, 0), UPB_SIZE(8, 16), 1, 0); }
UPB_INLINE bool google_api_expr_v1alpha1_Constant_has_bool_value(const google_api_expr_v1alpha1_Constant *msg) { return _upb_getoneofcase(msg, UPB_SIZE(8, 16)) == 2; }
UPB_INLINE bool google_api_expr_v1alpha1_Constant_bool_value(const google_api_expr_v1alpha1_Constant *msg) { return UPB_READ_ONEOF(msg, bool, UPB_SIZE(0, 0), UPB_SIZE(8, 16), 2, false); }
UPB_INLINE bool google_api_expr_v1alpha1_Constant_has_int64_value(const google_api_expr_v1alpha1_Constant *msg) { return _upb_getoneofcase(msg, UPB_SIZE(8, 16)) == 3; }

@ -36,9 +36,9 @@ static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6]
};
static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{2, UPB_SIZE(12, 24), 2, 0, 9, 1},
{3, UPB_SIZE(36, 72), 0, 0, 9, 3},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(12, 24), 2, 0, 12, 1},
{3, UPB_SIZE(36, 72), 0, 0, 12, 3},
{4, UPB_SIZE(40, 80), 0, 0, 11, 3},
{5, UPB_SIZE(44, 88), 0, 1, 11, 3},
{6, UPB_SIZE(48, 96), 0, 4, 11, 3},
@ -47,7 +47,7 @@ static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12]
{9, UPB_SIZE(32, 64), 5, 5, 11, 1},
{10, UPB_SIZE(56, 112), 0, 0, 5, 3},
{11, UPB_SIZE(60, 120), 0, 0, 5, 3},
{12, UPB_SIZE(20, 40), 3, 0, 9, 1},
{12, UPB_SIZE(20, 40), 3, 0, 12, 1},
};
const upb_msglayout google_protobuf_FileDescriptorProto_msginit = {
@ -67,7 +67,7 @@ static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = {
};
static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(16, 32), 0, 4, 11, 3},
{3, UPB_SIZE(20, 40), 0, 0, 11, 3},
{4, UPB_SIZE(24, 48), 0, 3, 11, 3},
@ -76,7 +76,7 @@ static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = {
{7, UPB_SIZE(12, 24), 2, 5, 11, 1},
{8, UPB_SIZE(36, 72), 0, 6, 11, 3},
{9, UPB_SIZE(40, 80), 0, 2, 11, 3},
{10, UPB_SIZE(44, 88), 0, 0, 9, 3},
{10, UPB_SIZE(44, 88), 0, 0, 12, 3},
};
const upb_msglayout google_protobuf_DescriptorProto_msginit = {
@ -131,16 +131,16 @@ static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1
};
static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = {
{1, UPB_SIZE(36, 40), 6, 0, 9, 1},
{2, UPB_SIZE(44, 56), 7, 0, 9, 1},
{1, UPB_SIZE(36, 40), 6, 0, 12, 1},
{2, UPB_SIZE(44, 56), 7, 0, 12, 1},
{3, UPB_SIZE(24, 24), 3, 0, 5, 1},
{4, UPB_SIZE(8, 8), 1, 0, 14, 1},
{5, UPB_SIZE(16, 16), 2, 0, 14, 1},
{6, UPB_SIZE(52, 72), 8, 0, 9, 1},
{7, UPB_SIZE(60, 88), 9, 0, 9, 1},
{6, UPB_SIZE(52, 72), 8, 0, 12, 1},
{7, UPB_SIZE(60, 88), 9, 0, 12, 1},
{8, UPB_SIZE(76, 120), 11, 0, 11, 1},
{9, UPB_SIZE(28, 28), 4, 0, 5, 1},
{10, UPB_SIZE(68, 104), 10, 0, 9, 1},
{10, UPB_SIZE(68, 104), 10, 0, 12, 1},
{17, UPB_SIZE(32, 32), 5, 0, 8, 1},
};
@ -155,7 +155,7 @@ static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1
};
static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(12, 24), 2, 0, 11, 1},
};
@ -172,11 +172,11 @@ static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3]
};
static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(16, 32), 0, 2, 11, 3},
{3, UPB_SIZE(12, 24), 2, 1, 11, 1},
{4, UPB_SIZE(20, 40), 0, 0, 11, 3},
{5, UPB_SIZE(24, 48), 0, 0, 9, 3},
{5, UPB_SIZE(24, 48), 0, 0, 12, 3},
};
const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = {
@ -201,7 +201,7 @@ static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_subms
};
static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = {
{1, UPB_SIZE(8, 8), 2, 0, 9, 1},
{1, UPB_SIZE(8, 8), 2, 0, 12, 1},
{2, UPB_SIZE(4, 4), 1, 0, 5, 1},
{3, UPB_SIZE(16, 24), 3, 0, 11, 1},
};
@ -218,7 +218,7 @@ static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs
};
static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = {
{1, UPB_SIZE(4, 8), 1, 0, 9, 1},
{1, UPB_SIZE(4, 8), 1, 0, 12, 1},
{2, UPB_SIZE(16, 32), 0, 0, 11, 3},
{3, UPB_SIZE(12, 24), 2, 1, 11, 1},
};
@ -234,9 +234,9 @@ static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[
};
static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = {
{1, UPB_SIZE(4, 8), 3, 0, 9, 1},
{2, UPB_SIZE(12, 24), 4, 0, 9, 1},
{3, UPB_SIZE(20, 40), 5, 0, 9, 1},
{1, UPB_SIZE(4, 8), 3, 0, 12, 1},
{2, UPB_SIZE(12, 24), 4, 0, 12, 1},
{3, UPB_SIZE(20, 40), 5, 0, 12, 1},
{4, UPB_SIZE(28, 56), 6, 0, 11, 1},
{5, UPB_SIZE(1, 1), 1, 0, 8, 1},
{6, UPB_SIZE(2, 2), 2, 0, 8, 1},
@ -253,11 +253,11 @@ static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = {
};
static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = {
{1, UPB_SIZE(28, 32), 11, 0, 9, 1},
{8, UPB_SIZE(36, 48), 12, 0, 9, 1},
{1, UPB_SIZE(28, 32), 11, 0, 12, 1},
{8, UPB_SIZE(36, 48), 12, 0, 12, 1},
{9, UPB_SIZE(8, 8), 1, 0, 14, 1},
{10, UPB_SIZE(16, 16), 2, 0, 8, 1},
{11, UPB_SIZE(44, 64), 13, 0, 9, 1},
{11, UPB_SIZE(44, 64), 13, 0, 12, 1},
{16, UPB_SIZE(17, 17), 3, 0, 8, 1},
{17, UPB_SIZE(18, 18), 4, 0, 8, 1},
{18, UPB_SIZE(19, 19), 5, 0, 8, 1},
@ -265,14 +265,14 @@ static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = {
{23, UPB_SIZE(21, 21), 7, 0, 8, 1},
{27, UPB_SIZE(22, 22), 8, 0, 8, 1},
{31, UPB_SIZE(23, 23), 9, 0, 8, 1},
{36, UPB_SIZE(52, 80), 14, 0, 9, 1},
{37, UPB_SIZE(60, 96), 15, 0, 9, 1},
{39, UPB_SIZE(68, 112), 16, 0, 9, 1},
{40, UPB_SIZE(76, 128), 17, 0, 9, 1},
{41, UPB_SIZE(84, 144), 18, 0, 9, 1},
{36, UPB_SIZE(52, 80), 14, 0, 12, 1},
{37, UPB_SIZE(60, 96), 15, 0, 12, 1},
{39, UPB_SIZE(68, 112), 16, 0, 12, 1},
{40, UPB_SIZE(76, 128), 17, 0, 12, 1},
{41, UPB_SIZE(84, 144), 18, 0, 12, 1},
{42, UPB_SIZE(24, 24), 10, 0, 8, 1},
{44, UPB_SIZE(92, 160), 19, 0, 9, 1},
{45, UPB_SIZE(100, 176), 20, 0, 9, 1},
{44, UPB_SIZE(92, 160), 19, 0, 12, 1},
{45, UPB_SIZE(100, 176), 20, 0, 12, 1},
{999, UPB_SIZE(108, 192), 0, 0, 11, 3},
};
@ -402,12 +402,12 @@ static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1]
static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = {
{2, UPB_SIZE(56, 80), 0, 0, 11, 3},
{3, UPB_SIZE(32, 32), 4, 0, 9, 1},
{3, UPB_SIZE(32, 32), 4, 0, 12, 1},
{4, UPB_SIZE(8, 8), 1, 0, 4, 1},
{5, UPB_SIZE(16, 16), 2, 0, 3, 1},
{6, UPB_SIZE(24, 24), 3, 0, 1, 1},
{7, UPB_SIZE(40, 48), 5, 0, 12, 1},
{8, UPB_SIZE(48, 64), 6, 0, 9, 1},
{8, UPB_SIZE(48, 64), 6, 0, 12, 1},
};
const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
@ -417,7 +417,7 @@ const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
};
static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = {
{1, UPB_SIZE(4, 8), 2, 0, 9, 2},
{1, UPB_SIZE(4, 8), 2, 0, 12, 2},
{2, UPB_SIZE(1, 1), 1, 0, 8, 2},
};
@ -444,9 +444,9 @@ const upb_msglayout google_protobuf_SourceCodeInfo_msginit = {
static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = {
{1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED},
{2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED},
{3, UPB_SIZE(4, 8), 1, 0, 9, 1},
{4, UPB_SIZE(12, 24), 2, 0, 9, 1},
{6, UPB_SIZE(28, 56), 0, 0, 9, 3},
{3, UPB_SIZE(4, 8), 1, 0, 12, 1},
{4, UPB_SIZE(12, 24), 2, 0, 12, 1},
{6, UPB_SIZE(28, 56), 0, 0, 12, 3},
};
const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = {
@ -471,7 +471,7 @@ const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = {
static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
{1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED},
{2, UPB_SIZE(12, 16), 3, 0, 9, 1},
{2, UPB_SIZE(12, 16), 3, 0, 12, 1},
{3, UPB_SIZE(4, 4), 1, 0, 5, 1},
{4, UPB_SIZE(8, 8), 2, 0, 5, 1},
};

@ -105,7 +105,7 @@ typedef enum {
UPB_INLINE google_protobuf_Value_kind_oneofcases google_protobuf_Value_kind_case(const google_protobuf_Value* msg) { return (google_protobuf_Value_kind_oneofcases)*UPB_PTR_AT(msg, UPB_SIZE(8, 16), int32_t); }
UPB_INLINE bool google_protobuf_Value_has_null_value(const google_protobuf_Value *msg) { return _upb_getoneofcase(msg, UPB_SIZE(8, 16)) == 1; }
UPB_INLINE int32_t google_protobuf_Value_null_value(const google_protobuf_Value *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(0, 0), UPB_SIZE(8, 16), 1, google_protobuf_NULL_VALUE); }
UPB_INLINE int32_t google_protobuf_Value_null_value(const google_protobuf_Value *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(0, 0), UPB_SIZE(8, 16), 1, 0); }
UPB_INLINE bool google_protobuf_Value_has_number_value(const google_protobuf_Value *msg) { return _upb_getoneofcase(msg, UPB_SIZE(8, 16)) == 2; }
UPB_INLINE double google_protobuf_Value_number_value(const google_protobuf_Value *msg) { return UPB_READ_ONEOF(msg, double, UPB_SIZE(0, 0), UPB_SIZE(8, 16), 2, 0); }
UPB_INLINE bool google_protobuf_Value_has_string_value(const google_protobuf_Value *msg) { return _upb_getoneofcase(msg, UPB_SIZE(8, 16)) == 3; }

@ -274,17 +274,17 @@ const upb_msglayout validate_BoolRules_msginit = {
};
static const upb_msglayout_field validate_StringRules__fields[25] = {
{1, UPB_SIZE(60, 64), 8, 0, 9, 1},
{1, UPB_SIZE(60, 64), 8, 0, 12, 1},
{2, UPB_SIZE(8, 8), 1, 0, 4, 1},
{3, UPB_SIZE(16, 16), 2, 0, 4, 1},
{4, UPB_SIZE(24, 24), 3, 0, 4, 1},
{5, UPB_SIZE(32, 32), 4, 0, 4, 1},
{6, UPB_SIZE(68, 80), 9, 0, 9, 1},
{7, UPB_SIZE(76, 96), 10, 0, 9, 1},
{8, UPB_SIZE(84, 112), 11, 0, 9, 1},
{9, UPB_SIZE(92, 128), 12, 0, 9, 1},
{10, UPB_SIZE(108, 160), 0, 0, 9, 3},
{11, UPB_SIZE(112, 168), 0, 0, 9, 3},
{6, UPB_SIZE(68, 80), 9, 0, 12, 1},
{7, UPB_SIZE(76, 96), 10, 0, 12, 1},
{8, UPB_SIZE(84, 112), 11, 0, 12, 1},
{9, UPB_SIZE(92, 128), 12, 0, 12, 1},
{10, UPB_SIZE(108, 160), 0, 0, 12, 3},
{11, UPB_SIZE(112, 168), 0, 0, 12, 3},
{12, UPB_SIZE(120, 176), UPB_SIZE(-129, -185), 0, 8, 1},
{13, UPB_SIZE(120, 176), UPB_SIZE(-129, -185), 0, 8, 1},
{14, UPB_SIZE(120, 176), UPB_SIZE(-129, -185), 0, 8, 1},
@ -296,7 +296,7 @@ static const upb_msglayout_field validate_StringRules__fields[25] = {
{20, UPB_SIZE(48, 48), 6, 0, 4, 1},
{21, UPB_SIZE(120, 176), UPB_SIZE(-129, -185), 0, 8, 1},
{22, UPB_SIZE(120, 176), UPB_SIZE(-129, -185), 0, 8, 1},
{23, UPB_SIZE(100, 144), 13, 0, 9, 1},
{23, UPB_SIZE(100, 144), 13, 0, 12, 1},
{24, UPB_SIZE(120, 176), UPB_SIZE(-129, -185), 0, 14, 1},
{25, UPB_SIZE(56, 56), 7, 0, 8, 1},
};
@ -311,7 +311,7 @@ static const upb_msglayout_field validate_BytesRules__fields[13] = {
{1, UPB_SIZE(32, 32), 4, 0, 12, 1},
{2, UPB_SIZE(8, 8), 1, 0, 4, 1},
{3, UPB_SIZE(16, 16), 2, 0, 4, 1},
{4, UPB_SIZE(40, 48), 5, 0, 9, 1},
{4, UPB_SIZE(40, 48), 5, 0, 12, 1},
{5, UPB_SIZE(48, 64), 6, 0, 12, 1},
{6, UPB_SIZE(56, 80), 7, 0, 12, 1},
{7, UPB_SIZE(64, 96), 8, 0, 12, 1},
@ -390,8 +390,8 @@ const upb_msglayout validate_MapRules_msginit = {
static const upb_msglayout_field validate_AnyRules__fields[3] = {
{1, UPB_SIZE(1, 1), 1, 0, 8, 1},
{2, UPB_SIZE(4, 8), 0, 0, 9, 3},
{3, UPB_SIZE(8, 16), 0, 0, 9, 3},
{2, UPB_SIZE(4, 8), 0, 0, 12, 3},
{3, UPB_SIZE(8, 16), 0, 0, 12, 3},
};
const upb_msglayout validate_AnyRules_msginit = {

@ -1363,7 +1363,7 @@ UPB_INLINE bool validate_StringRules_uuid(const validate_StringRules *msg) { ret
UPB_INLINE bool validate_StringRules_has_not_contains(const validate_StringRules *msg) { return _upb_hasbit(msg, 13); }
UPB_INLINE upb_strview validate_StringRules_not_contains(const validate_StringRules *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(100, 144), upb_strview); }
UPB_INLINE bool validate_StringRules_has_well_known_regex(const validate_StringRules *msg) { return _upb_getoneofcase(msg, UPB_SIZE(128, 184)) == 24; }
UPB_INLINE int32_t validate_StringRules_well_known_regex(const validate_StringRules *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(120, 176), UPB_SIZE(128, 184), 24, validate_UNKNOWN); }
UPB_INLINE int32_t validate_StringRules_well_known_regex(const validate_StringRules *msg) { return UPB_READ_ONEOF(msg, int32_t, UPB_SIZE(120, 176), UPB_SIZE(128, 184), 24, 0); }
UPB_INLINE bool validate_StringRules_has_strict(const validate_StringRules *msg) { return _upb_hasbit(msg, 7); }
UPB_INLINE bool validate_StringRules_strict(const validate_StringRules *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(56, 56), bool); }

@ -283,7 +283,7 @@ void ChannelNode::RemoveChildSubchannel(intptr_t child_uuid) {
// ServerNode
//
ServerNode::ServerNode(grpc_server* /*server*/, size_t channel_tracer_max_nodes)
ServerNode::ServerNode(size_t channel_tracer_max_nodes)
: BaseNode(EntityType::kServer, ""), trace_(channel_tracer_max_nodes) {}
ServerNode::~ServerNode() {}

@ -238,7 +238,7 @@ class ChannelNode : public BaseNode {
// Handles channelz bookkeeping for servers
class ServerNode : public BaseNode {
public:
ServerNode(grpc_server* server, size_t channel_tracer_max_nodes);
explicit ServerNode(size_t channel_tracer_max_nodes);
~ServerNode() override;

@ -52,10 +52,14 @@ void grpc_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) {
void grpc_endpoint_destroy(grpc_endpoint* ep) { ep->vtable->destroy(ep); }
char* grpc_endpoint_get_peer(grpc_endpoint* ep) {
absl::string_view grpc_endpoint_get_peer(grpc_endpoint* ep) {
return ep->vtable->get_peer(ep);
}
absl::string_view grpc_endpoint_get_local_address(grpc_endpoint* ep) {
return ep->vtable->get_local_address(ep);
}
int grpc_endpoint_get_fd(grpc_endpoint* ep) { return ep->vtable->get_fd(ep); }
grpc_resource_user* grpc_endpoint_get_resource_user(grpc_endpoint* ep) {

@ -21,6 +21,8 @@
#include <grpc/support/port_platform.h>
#include "absl/strings/string_view.h"
#include <grpc/slice.h>
#include <grpc/slice_buffer.h>
#include <grpc/support/time.h>
@ -46,7 +48,8 @@ struct grpc_endpoint_vtable {
void (*shutdown)(grpc_endpoint* ep, grpc_error* why);
void (*destroy)(grpc_endpoint* ep);
grpc_resource_user* (*get_resource_user)(grpc_endpoint* ep);
char* (*get_peer)(grpc_endpoint* ep);
absl::string_view (*get_peer)(grpc_endpoint* ep);
absl::string_view (*get_local_address)(grpc_endpoint* ep);
int (*get_fd)(grpc_endpoint* ep);
bool (*can_track_err)(grpc_endpoint* ep);
};
@ -59,7 +62,9 @@ struct grpc_endpoint_vtable {
void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices,
grpc_closure* cb, bool urgent);
char* grpc_endpoint_get_peer(grpc_endpoint* ep);
absl::string_view grpc_endpoint_get_peer(grpc_endpoint* ep);
absl::string_view grpc_endpoint_get_local_address(grpc_endpoint* ep);
/* Get the file descriptor used by \a ep. Return -1 if \a ep is not using an fd.
*/

@ -34,6 +34,8 @@
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/error_cfstream.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
@ -55,7 +57,8 @@ struct CFStreamEndpoint {
grpc_closure read_action;
grpc_closure write_action;
char* peer_string;
std::string peer_string;
std::string local_address;
grpc_resource_user* resource_user;
grpc_resource_user_slice_allocator slice_allocator;
};
@ -64,8 +67,7 @@ static void CFStreamFree(CFStreamEndpoint* ep) {
CFRelease(ep->read_stream);
CFRelease(ep->write_stream);
CFSTREAM_HANDLE_UNREF(ep->stream_sync, "free");
gpr_free(ep->peer_string);
gpr_free(ep);
delete ep;
}
#ifndef NDEBUG
@ -110,7 +112,7 @@ static grpc_error* CFStreamAnnotateError(grpc_error* src_error,
grpc_error_set_int(src_error, GRPC_ERROR_INT_GRPC_STATUS,
GRPC_STATUS_UNAVAILABLE),
GRPC_ERROR_STR_TARGET_ADDRESS,
grpc_slice_from_copied_string(ep->peer_string));
grpc_slice_from_copied_string(ep->peer_string.c_str()));
}
static void CallReadCb(CFStreamEndpoint* ep, grpc_error* error) {
@ -124,7 +126,8 @@ static void CallReadCb(CFStreamEndpoint* ep, grpc_error* error) {
for (i = 0; i < ep->read_slices->count; i++) {
char* dump = grpc_dump_slice(ep->read_slices->slices[i],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", ep, ep->peer_string, dump);
gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", ep, ep->peer_string.c_str(),
dump);
gpr_free(dump);
}
}
@ -230,7 +233,8 @@ static void WriteAction(void* arg, grpc_error* error) {
if (grpc_tcp_trace.enabled()) {
grpc_slice trace_slice = grpc_slice_sub(slice, 0, write_size);
char* dump = grpc_dump_slice(trace_slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", ep, ep->peer_string, dump);
gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", ep, ep->peer_string.c_str(),
dump);
gpr_free(dump);
grpc_slice_unref_internal(trace_slice);
}
@ -309,9 +313,14 @@ grpc_resource_user* CFStreamGetResourceUser(grpc_endpoint* ep) {
return ep_impl->resource_user;
}
char* CFStreamGetPeer(grpc_endpoint* ep) {
absl::string_view CFStreamGetPeer(grpc_endpoint* ep) {
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
return gpr_strdup(ep_impl->peer_string);
return ep_impl->peer_string;
}
absl::string_view CFStreamGetLocalAddress(grpc_endpoint* ep) {
CFStreamEndpoint* ep_impl = reinterpret_cast<CFStreamEndpoint*>(ep);
return ep_impl->local_address;
}
int CFStreamGetFD(grpc_endpoint* ep) { return 0; }
@ -332,6 +341,7 @@ static const grpc_endpoint_vtable vtable = {CFStreamRead,
CFStreamDestroy,
CFStreamGetResourceUser,
CFStreamGetPeer,
CFStreamGetLocalAddress,
CFStreamGetFD,
CFStreamCanTrackErr};
@ -339,8 +349,7 @@ grpc_endpoint* grpc_cfstream_endpoint_create(
CFReadStreamRef read_stream, CFWriteStreamRef write_stream,
const char* peer_string, grpc_resource_quota* resource_quota,
CFStreamHandle* stream_sync) {
CFStreamEndpoint* ep_impl =
static_cast<CFStreamEndpoint*>(gpr_malloc(sizeof(CFStreamEndpoint)));
CFStreamEndpoint* ep_impl = new CFStreamEndpoint;
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG,
"CFStream endpoint:%p create readStream:%p writeStream: %p",
@ -355,7 +364,19 @@ grpc_endpoint* grpc_cfstream_endpoint_create(
ep_impl->stream_sync = stream_sync;
CFSTREAM_HANDLE_REF(ep_impl->stream_sync, "endpoint create");
ep_impl->peer_string = gpr_strdup(peer_string);
ep_impl->peer_string = peer_string;
const int* native_handle =
reinterpret_cast<const int*>(CFReadStreamCopyProperty(
ep_impl->read_stream, kCFStreamPropertySocketNativeHandle));
grpc_resolved_address resolved_local_addr;
resolved_local_addr.len = sizeof(resolved_local_addr.addr);
if (getsockname(*native_handle,
reinterpret_cast<sockaddr*>(resolved_local_addr.addr),
&resolved_local_addr.len) < 0) {
ep_impl->local_address = "";
} else {
ep_impl->local_address = grpc_sockaddr_to_uri(&resolved_local_addr);
}
ep_impl->read_cb = nil;
ep_impl->write_cb = nil;
ep_impl->read_slices = nil;

@ -32,6 +32,7 @@
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/iomgr_custom.h"
#include "src/core/lib/iomgr/resource_quota.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/iomgr/tcp_custom.h"
#include "src/core/lib/iomgr/tcp_server.h"
@ -57,24 +58,24 @@ struct custom_tcp_endpoint {
gpr_refcount refcount;
grpc_custom_socket* socket;
grpc_closure* read_cb;
grpc_closure* write_cb;
grpc_closure* read_cb = nullptr;
grpc_closure* write_cb = nullptr;
grpc_slice_buffer* read_slices;
grpc_slice_buffer* write_slices;
grpc_slice_buffer* read_slices = nullptr;
grpc_slice_buffer* write_slices = nullptr;
grpc_resource_user* resource_user;
grpc_resource_user_slice_allocator slice_allocator;
bool shutting_down;
char* peer_string;
std::string peer_string;
std::string local_address;
};
static void tcp_free(grpc_custom_socket* s) {
custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)s->endpoint;
grpc_resource_user_unref(tcp->resource_user);
gpr_free(tcp->peer_string);
gpr_free(tcp);
delete tcp;
s->refs--;
if (s->refs == 0) {
grpc_custom_socket_vtable->destroy(s);
@ -132,7 +133,8 @@ static void call_read_cb(custom_tcp_endpoint* tcp, grpc_error* error) {
for (i = 0; i < tcp->read_slices->count; i++) {
char* dump = grpc_dump_slice(tcp->read_slices->slices[i],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_INFO, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump);
gpr_log(GPR_INFO, "READ %p (peer=%s): %s", tcp, tcp->peer_string.c_str(),
dump);
gpr_free(dump);
}
}
@ -233,8 +235,8 @@ static void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* write_slices,
for (j = 0; j < write_slices->count; j++) {
char* data = grpc_dump_slice(write_slices->slices[j],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_INFO, "WRITE %p (peer=%s): %s", tcp->socket, tcp->peer_string,
data);
gpr_log(GPR_INFO, "WRITE %p (peer=%s): %s", tcp->socket,
tcp->peer_string.c_str(), data);
gpr_free(data);
}
}
@ -317,9 +319,14 @@ static void endpoint_destroy(grpc_endpoint* ep) {
grpc_custom_socket_vtable->close(tcp->socket, custom_close_callback);
}
static char* endpoint_get_peer(grpc_endpoint* ep) {
static absl::string_view endpoint_get_peer(grpc_endpoint* ep) {
custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep;
return gpr_strdup(tcp->peer_string);
return tcp->peer_string;
}
static absl::string_view endpoint_get_local_address(grpc_endpoint* ep) {
custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep;
return tcp->local_address;
}
static grpc_resource_user* endpoint_get_resource_user(grpc_endpoint* ep) {
@ -340,27 +347,36 @@ static grpc_endpoint_vtable vtable = {endpoint_read,
endpoint_destroy,
endpoint_get_resource_user,
endpoint_get_peer,
endpoint_get_local_address,
endpoint_get_fd,
endpoint_can_track_err};
grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket,
grpc_resource_quota* resource_quota,
const char* peer_string) {
custom_tcp_endpoint* tcp =
(custom_tcp_endpoint*)gpr_malloc(sizeof(custom_tcp_endpoint));
custom_tcp_endpoint* tcp = new custom_tcp_endpoint;
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx;
if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "Creating TCP endpoint %p", socket);
}
memset(tcp, 0, sizeof(custom_tcp_endpoint));
socket->refs++;
socket->endpoint = (grpc_endpoint*)tcp;
tcp->socket = socket;
tcp->base.vtable = &vtable;
gpr_ref_init(&tcp->refcount, 1);
tcp->peer_string = gpr_strdup(peer_string);
tcp->peer_string = peer_string;
grpc_resolved_address resolved_local_addr;
resolved_local_addr.len = sizeof(resolved_local_addr.addr);
if (grpc_custom_socket_vtable->getsockname(
socket, reinterpret_cast<sockaddr*>(resolved_local_addr.addr),
reinterpret_cast<int*>(&resolved_local_addr.len)) !=
GRPC_ERROR_NONE) {
tcp->local_address = "";
} else {
tcp->local_address = grpc_sockaddr_to_uri(&resolved_local_addr);
}
tcp->shutting_down = false;
tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string);
grpc_resource_user_slice_allocator_init(

@ -54,6 +54,7 @@
#include "src/core/lib/iomgr/buffer_list.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
@ -351,6 +352,8 @@ using grpc_core::TcpZerocopySendRecord;
namespace {
struct grpc_tcp {
grpc_tcp(int max_sends, size_t send_bytes_threshold)
: tcp_zerocopy_send_ctx(max_sends, send_bytes_threshold) {}
grpc_endpoint base;
grpc_fd* em_fd;
int fd;
@ -385,7 +388,8 @@ struct grpc_tcp {
grpc_closure write_done_closure;
grpc_closure error_closure;
char* peer_string;
std::string peer_string;
std::string local_address;
grpc_resource_user* resource_user;
grpc_resource_user_slice_allocator slice_allocator;
@ -605,7 +609,7 @@ static grpc_error* tcp_annotate_error(grpc_error* src_error, grpc_tcp* tcp) {
* choose to retry. */
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE),
GRPC_ERROR_STR_TARGET_ADDRESS,
grpc_slice_from_copied_string(tcp->peer_string));
grpc_slice_from_copied_string(tcp->peer_string.c_str()));
}
static void tcp_handle_read(void* arg /* grpc_tcp */, grpc_error* error);
@ -623,7 +627,6 @@ static void tcp_free(grpc_tcp* tcp) {
"tcp_unref_orphan");
grpc_slice_buffer_destroy_internal(&tcp->last_read_buffer);
grpc_resource_user_unref(tcp->resource_user);
gpr_free(tcp->peer_string);
/* The lock is not really necessary here, since all refs have been released */
gpr_mu_lock(&tcp->tb_mu);
grpc_core::TracedBuffer::Shutdown(
@ -632,8 +635,7 @@ static void tcp_free(grpc_tcp* tcp) {
gpr_mu_unlock(&tcp->tb_mu);
tcp->outgoing_buffer_arg = nullptr;
gpr_mu_destroy(&tcp->tb_mu);
tcp->tcp_zerocopy_send_ctx.~TcpZerocopySendCtx();
gpr_free(tcp);
delete tcp;
}
#ifndef NDEBUG
@ -680,7 +682,8 @@ static void call_read_cb(grpc_tcp* tcp, grpc_error* error) {
gpr_log(GPR_INFO, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg);
size_t i;
const char* str = grpc_error_string(error);
gpr_log(GPR_INFO, "READ %p (peer=%s) error=%s", tcp, tcp->peer_string, str);
gpr_log(GPR_INFO, "READ %p (peer=%s) error=%s", tcp,
tcp->peer_string.c_str(), str);
if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
for (i = 0; i < tcp->incoming_buffer->count; i++) {
@ -1563,7 +1566,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
size_t i;
for (i = 0; i < buf->count; i++) {
gpr_log(GPR_INFO, "WRITE %p (peer=%s)", tcp, tcp->peer_string);
gpr_log(GPR_INFO, "WRITE %p (peer=%s)", tcp, tcp->peer_string.c_str());
if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
char* data =
grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
@ -1637,9 +1640,14 @@ static void tcp_delete_from_pollset_set(grpc_endpoint* ep,
grpc_pollset_set_del_fd(pollset_set, tcp->em_fd);
}
static char* tcp_get_peer(grpc_endpoint* ep) {
static absl::string_view tcp_get_peer(grpc_endpoint* ep) {
grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
return gpr_strdup(tcp->peer_string);
return tcp->peer_string;
}
static absl::string_view tcp_get_local_address(grpc_endpoint* ep) {
grpc_tcp* tcp = reinterpret_cast<grpc_tcp*>(ep);
return tcp->local_address;
}
static int tcp_get_fd(grpc_endpoint* ep) {
@ -1677,6 +1685,7 @@ static const grpc_endpoint_vtable vtable = {tcp_read,
tcp_destroy,
tcp_get_resource_user,
tcp_get_peer,
tcp_get_local_address,
tcp_get_fd,
tcp_can_track_err};
@ -1745,10 +1754,21 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
tcp_read_chunk_size = GPR_CLAMP(tcp_read_chunk_size, tcp_min_read_chunk_size,
tcp_max_read_chunk_size);
grpc_tcp* tcp = static_cast<grpc_tcp*>(gpr_malloc(sizeof(grpc_tcp)));
grpc_tcp* tcp = new grpc_tcp(tcp_tx_zerocopy_max_simult_sends,
tcp_tx_zerocopy_send_bytes_thresh);
tcp->base.vtable = &vtable;
tcp->peer_string = gpr_strdup(peer_string);
tcp->peer_string = peer_string;
tcp->fd = grpc_fd_wrapped_fd(em_fd);
grpc_resolved_address resolved_local_addr;
memset(&resolved_local_addr, 0, sizeof(resolved_local_addr));
resolved_local_addr.len = sizeof(resolved_local_addr.addr);
if (getsockname(tcp->fd,
reinterpret_cast<sockaddr*>(resolved_local_addr.addr),
&resolved_local_addr.len) < 0) {
tcp->local_address = "";
} else {
tcp->local_address = grpc_sockaddr_to_uri(&resolved_local_addr);
}
tcp->read_cb = nullptr;
tcp->write_cb = nullptr;
tcp->current_zerocopy_send = nullptr;
@ -1765,8 +1785,6 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
tcp->socket_ts_enabled = false;
tcp->ts_capable = true;
tcp->outgoing_buffer_arg = nullptr;
new (&tcp->tcp_zerocopy_send_ctx) TcpZerocopySendCtx(
tcp_tx_zerocopy_max_simult_sends, tcp_tx_zerocopy_send_bytes_thresh);
if (tcp_tx_zerocopy_enabled && !tcp->tcp_zerocopy_send_ctx.memory_limited()) {
#ifdef GRPC_LINUX_ERRQUEUE
const int enable = 1;

@ -125,17 +125,17 @@ typedef struct grpc_tcp {
int shutting_down;
grpc_error* shutdown_error;
char* peer_string;
std::string peer_string;
std::string local_address;
} grpc_tcp;
static void tcp_free(grpc_tcp* tcp) {
grpc_winsocket_destroy(tcp->socket);
gpr_mu_destroy(&tcp->mu);
gpr_free(tcp->peer_string);
grpc_slice_buffer_destroy_internal(&tcp->last_read_buffer);
grpc_resource_user_unref(tcp->resource_user);
if (tcp->shutting_down) GRPC_ERROR_UNREF(tcp->shutdown_error);
gpr_free(tcp);
delete tcp;
}
#ifndef NDEBUG
@ -213,8 +213,8 @@ static void on_read(void* tcpp, grpc_error* error) {
for (i = 0; i < tcp->read_slices->count; i++) {
char* dump = grpc_dump_slice(tcp->read_slices->slices[i],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_INFO, "READ %p (peer=%s): %s", tcp, tcp->peer_string,
dump);
gpr_log(GPR_INFO, "READ %p (peer=%s): %s", tcp,
tcp->peer_string.c_str(), dump);
gpr_free(dump);
}
}
@ -361,7 +361,8 @@ static void win_write(grpc_endpoint* ep, grpc_slice_buffer* slices,
for (i = 0; i < slices->count; i++) {
char* data =
grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_INFO, "WRITE %p (peer=%s): %s", tcp, tcp->peer_string, data);
gpr_log(GPR_INFO, "WRITE %p (peer=%s): %s", tcp, tcp->peer_string.c_str(),
data);
gpr_free(data);
}
}
@ -475,9 +476,14 @@ static void win_destroy(grpc_endpoint* ep) {
TCP_UNREF(tcp, "destroy");
}
static char* win_get_peer(grpc_endpoint* ep) {
static absl::string_view win_get_peer(grpc_endpoint* ep) {
grpc_tcp* tcp = (grpc_tcp*)ep;
return gpr_strdup(tcp->peer_string);
return tcp->peer_string;
}
static absl::string_view win_get_local_address(grpc_endpoint* ep) {
grpc_tcp* tcp = (grpc_tcp*)ep;
return tcp->local_address;
}
static grpc_resource_user* win_get_resource_user(grpc_endpoint* ep) {
@ -498,6 +504,7 @@ static grpc_endpoint_vtable vtable = {win_read,
win_destroy,
win_get_resource_user,
win_get_peer,
win_get_local_address,
win_get_fd,
win_can_track_err};
@ -514,7 +521,7 @@ grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket,
}
}
}
grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp));
grpc_tcp* tcp = new grpc_tcp;
memset(tcp, 0, sizeof(grpc_tcp));
tcp->base.vtable = &vtable;
tcp->socket = socket;
@ -522,7 +529,16 @@ grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket,
gpr_ref_init(&tcp->refcount, 1);
GRPC_CLOSURE_INIT(&tcp->on_read, on_read, tcp, grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&tcp->on_write, on_write, tcp, grpc_schedule_on_exec_ctx);
tcp->peer_string = gpr_strdup(peer_string);
grpc_resolved_address resolved_local_addr;
resolved_local_addr.len = sizeof(resolved_local_addr.addr);
if (getsockname(tcp->socket->socket,
reinterpret_cast<sockaddr*>(resolved_local_addr.addr),
&resolved_local_addr.len) < 0) {
tcp->local_address = "";
} else {
tcp->local_address = grpc_sockaddr_to_uri(&resolved_local_addr);
}
tcp->peer_string = peer_string;
grpc_slice_buffer_init(&tcp->last_read_buffer);
tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string);
grpc_resource_quota_unref_internal(resource_quota);

@ -401,11 +401,16 @@ static void endpoint_delete_from_pollset_set(grpc_endpoint* secure_ep,
grpc_endpoint_delete_from_pollset_set(ep->wrapped_ep, pollset_set);
}
static char* endpoint_get_peer(grpc_endpoint* secure_ep) {
static absl::string_view endpoint_get_peer(grpc_endpoint* secure_ep) {
secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_peer(ep->wrapped_ep);
}
static absl::string_view endpoint_get_local_address(grpc_endpoint* secure_ep) {
secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_local_address(ep->wrapped_ep);
}
static int endpoint_get_fd(grpc_endpoint* secure_ep) {
secure_endpoint* ep = reinterpret_cast<secure_endpoint*>(secure_ep);
return grpc_endpoint_get_fd(ep->wrapped_ep);
@ -431,6 +436,7 @@ static const grpc_endpoint_vtable vtable = {endpoint_read,
endpoint_destroy,
endpoint_get_resource_user,
endpoint_get_peer,
endpoint_get_local_address,
endpoint_get_fd,
endpoint_can_track_err};

@ -245,7 +245,7 @@ struct grpc_call {
struct {
int* cancelled;
// backpointer to owning server if this is a server side call.
grpc_server* server;
grpc_core::Server* core_server;
} server;
} final_op;
gpr_atm status_error = 0;
@ -374,7 +374,7 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
} else {
GRPC_STATS_INC_SERVER_CALLS_CREATED();
call->final_op.server.cancelled = nullptr;
call->final_op.server.server = args->server;
call->final_op.server.core_server = args->server;
GPR_ASSERT(args->add_initial_metadata_count == 0);
call->send_extra_metadata_count = 0;
}
@ -476,11 +476,11 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
if (channelz_channel != nullptr) {
channelz_channel->RecordCallStarted();
}
} else {
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(call->final_op.server.server);
if (channelz_server != nullptr) {
channelz_server->RecordCallStarted();
} else if (call->final_op.server.core_server != nullptr) {
grpc_core::channelz::ServerNode* channelz_node =
call->final_op.server.core_server->channelz_node();
if (channelz_node != nullptr) {
channelz_node->RecordCallStarted();
}
}
@ -759,15 +759,15 @@ static void set_final_status(grpc_call* call, grpc_error* error) {
} else {
*call->final_op.server.cancelled =
error != GRPC_ERROR_NONE || !call->sent_server_trailing_metadata;
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(call->final_op.server.server);
if (channelz_server != nullptr) {
grpc_core::channelz::ServerNode* channelz_node =
call->final_op.server.core_server->channelz_node();
if (channelz_node != nullptr) {
if (*call->final_op.server.cancelled ||
reinterpret_cast<grpc_error*>(
gpr_atm_acq_load(&call->status_error)) != GRPC_ERROR_NONE) {
channelz_server->RecordCallFailed();
channelz_node->RecordCallFailed();
} else {
channelz_server->RecordCallSucceeded();
channelz_node->RecordCallSucceeded();
}
}
GRPC_ERROR_UNREF(error);

@ -25,6 +25,7 @@
#include "src/core/lib/channel/context.h"
#include "src/core/lib/gprpp/arena.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/server.h"
#include <grpc/grpc.h>
#include <grpc/impl/codegen/compression_types.h>
@ -34,7 +35,7 @@ typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success,
typedef struct grpc_call_create_args {
grpc_channel* channel;
grpc_server* server;
grpc_core::Server* server;
grpc_call* parent;
uint32_t propagation_mask;

@ -102,7 +102,7 @@ static void register_builtin_channel_init() {
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
append_filter, (void*)&grpc_lame_filter);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter,
(void*)&grpc_server_top_filter);
(void*)&grpc_core::Server::kServerTopFilter);
}
typedef struct grpc_plugin {

File diff suppressed because it is too large Load Diff

@ -1,121 +1,397 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef GRPC_CORE_LIB_SURFACE_SERVER_H
#define GRPC_CORE_LIB_SURFACE_SERVER_H
#include <grpc/support/port_platform.h>
#include <list>
#include <vector>
#include "absl/types/optional.h"
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/transport/transport.h"
extern const grpc_channel_filter grpc_server_top_filter;
/** Lightweight tracing of server channel state */
extern grpc_core::TraceFlag grpc_server_channel_trace;
namespace grpc_core {
/// Interface for listeners.
/// Implementations must override the Orphan() method, which should stop
/// listening and initiate destruction of the listener.
class ServerListenerInterface : public Orphanable {
extern TraceFlag grpc_server_channel_trace;
class Server : public InternallyRefCounted<Server> {
public:
virtual ~ServerListenerInterface() = default;
// Filter vtable.
static const grpc_channel_filter kServerTopFilter;
/// Starts listening. This listener may refer to the pollset object beyond
/// this call, so it is a pointer rather than a reference.
virtual void Start(grpc_server* server,
const std::vector<grpc_pollset*>* pollsets) = 0;
// Opaque type used for registered methods.
struct RegisteredMethod;
/// Returns the channelz node for the listen socket, or null if not
/// supported.
virtual channelz::ListenSocketNode* channelz_listen_socket_node() const = 0;
// An object to represent the most relevant characteristics of a
// newly-allocated call object when using an AllocatingRequestMatcherBatch.
struct BatchCallAllocation {
grpc_experimental_completion_queue_functor* tag;
grpc_call** call;
grpc_metadata_array* initial_metadata;
grpc_call_details* details;
};
/// Sets a closure to be invoked by the listener when its destruction
/// is complete.
virtual void SetOnDestroyDone(grpc_closure* on_destroy_done) = 0;
};
// An object to represent the most relevant characteristics of a
// newly-allocated call object when using an
// AllocatingRequestMatcherRegistered.
struct RegisteredCallAllocation {
grpc_experimental_completion_queue_functor* tag;
grpc_call** call;
grpc_metadata_array* initial_metadata;
gpr_timespec* deadline;
grpc_byte_buffer** optional_payload;
};
} // namespace grpc_core
/// Interface for listeners.
/// Implementations must override the Orphan() method, which should stop
/// listening and initiate destruction of the listener.
class ListenerInterface : public Orphanable {
public:
virtual ~ListenerInterface() = default;
/* Add a listener to the server: when the server starts, it will call Start(),
and when it shuts down, it will orphan the listener. */
void grpc_server_add_listener(
grpc_server* server,
grpc_core::OrphanablePtr<grpc_core::ServerListenerInterface> listener);
/// Starts listening. This listener may refer to the pollset object beyond
/// this call, so it is a pointer rather than a reference.
virtual void Start(Server* server,
const std::vector<grpc_pollset*>* pollsets) = 0;
/* Setup a transport - creates a channel stack, binds the transport to the
server */
void grpc_server_setup_transport(
grpc_server* server, grpc_transport* transport,
grpc_pollset* accepting_pollset, const grpc_channel_args* args,
const grpc_core::RefCountedPtr<grpc_core::channelz::SocketNode>&
socket_node,
grpc_resource_user* resource_user = nullptr);
/// Returns the channelz node for the listen socket, or null if not
/// supported.
virtual channelz::ListenSocketNode* channelz_listen_socket_node() const = 0;
grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
grpc_server* server);
/// Sets a closure to be invoked by the listener when its destruction
/// is complete.
virtual void SetOnDestroyDone(grpc_closure* on_destroy_done) = 0;
};
const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server);
explicit Server(const grpc_channel_args* args);
~Server();
grpc_resource_user* grpc_server_get_default_resource_user(grpc_server* server);
void Orphan() override;
bool grpc_server_has_open_connections(grpc_server* server);
const grpc_channel_args* channel_args() const { return channel_args_; }
grpc_resource_user* default_resource_user() const {
return default_resource_user_;
}
channelz::ServerNode* channelz_node() const { return channelz_node_.get(); }
// Do not call this before grpc_server_start. Returns the pollsets. The vector
// itself is immutable, but the pollsets inside are mutable. The result is valid
// for the lifetime of the server.
const std::vector<grpc_pollset*>& grpc_server_get_pollsets(grpc_server* server);
// Do not call this before Start(). Returns the pollsets. The
// vector itself is immutable, but the pollsets inside are mutable. The
// result is valid for the lifetime of the server.
const std::vector<grpc_pollset*>& pollsets() const { return pollsets_; }
namespace grpc_core {
bool HasOpenConnections();
// An object to represent the most relevant characteristics of a newly-allocated
// call object when using an AllocatingRequestMatcherBatch
struct ServerBatchCallAllocation {
grpc_experimental_completion_queue_functor* tag;
grpc_call** call;
grpc_metadata_array* initial_metadata;
grpc_call_details* details;
};
// Adds a listener to the server. When the server starts, it will call
// the listener's Start() method, and when it shuts down, it will orphan
// the listener.
void AddListener(OrphanablePtr<ListenerInterface> listener);
// An object to represent the most relevant characteristics of a newly-allocated
// call object when using an AllocatingRequestMatcherRegistered
struct ServerRegisteredCallAllocation {
grpc_experimental_completion_queue_functor* tag;
grpc_call** call;
grpc_metadata_array* initial_metadata;
gpr_timespec* deadline;
grpc_byte_buffer** optional_payload;
};
// Starts listening for connections.
void Start();
// Sets up a transport. Creates a channel stack and binds the transport to
// the server. Called from the listener when a new connection is accepted.
void SetupTransport(grpc_transport* transport,
grpc_pollset* accepting_pollset,
const grpc_channel_args* args,
const RefCountedPtr<channelz::SocketNode>& socket_node,
grpc_resource_user* resource_user = nullptr);
void RegisterCompletionQueue(grpc_completion_queue* cq);
// Functions to specify that a specific registered method or the unregistered
// collection should use a specific allocator for request matching.
void SetRegisteredMethodAllocator(
grpc_completion_queue* cq, void* method_tag,
std::function<RegisteredCallAllocation()> allocator);
void SetBatchMethodAllocator(grpc_completion_queue* cq,
std::function<BatchCallAllocation()> allocator);
RegisteredMethod* RegisterMethod(
const char* method, const char* host,
grpc_server_register_method_payload_handling payload_handling,
uint32_t flags);
grpc_call_error RequestCall(grpc_call** call, grpc_call_details* details,
grpc_metadata_array* request_metadata,
grpc_completion_queue* cq_bound_to_call,
grpc_completion_queue* cq_for_notification,
void* tag);
grpc_call_error RequestRegisteredCall(
RegisteredMethod* rm, grpc_call** call, gpr_timespec* deadline,
grpc_metadata_array* request_metadata,
grpc_byte_buffer** optional_payload,
grpc_completion_queue* cq_bound_to_call,
grpc_completion_queue* cq_for_notification, void* tag_new);
void ShutdownAndNotify(grpc_completion_queue* cq, void* tag);
void CancelAllCalls();
private:
struct RequestedCall;
struct ChannelRegisteredMethod {
RegisteredMethod* server_registered_method = nullptr;
uint32_t flags;
bool has_host;
ExternallyManagedSlice method;
ExternallyManagedSlice host;
};
class RequestMatcherInterface;
class RealRequestMatcher;
class AllocatingRequestMatcherBase;
class AllocatingRequestMatcherBatch;
class AllocatingRequestMatcherRegistered;
class ChannelData {
public:
ChannelData() = default;
~ChannelData();
void InitTransport(RefCountedPtr<Server> server, grpc_channel* channel,
size_t cq_idx, grpc_transport* transport,
intptr_t channelz_socket_uuid);
RefCountedPtr<Server> server() const { return server_; }
grpc_channel* channel() const { return channel_; }
size_t cq_idx() const { return cq_idx_; }
ChannelRegisteredMethod* GetRegisteredMethod(const grpc_slice& host,
const grpc_slice& path,
bool is_idempotent);
// Filter vtable functions.
static grpc_error* InitChannelElement(grpc_channel_element* elem,
grpc_channel_element_args* args);
static void DestroyChannelElement(grpc_channel_element* elem);
private:
class ConnectivityWatcher;
static void AcceptStream(void* arg, grpc_transport* /*transport*/,
const void* transport_server_data);
void Destroy();
static void FinishDestroy(void* arg, grpc_error* error);
RefCountedPtr<Server> server_;
grpc_channel* channel_;
// The index into Server::cqs_ of the CQ used as a starting point for
// where to publish new incoming calls.
size_t cq_idx_;
absl::optional<std::list<ChannelData*>::iterator> list_position_;
// A hash-table of the methods and hosts of the registered methods.
// TODO(vjpai): Convert this to an STL map type as opposed to a direct
// bucket implementation. (Consider performance impact, hash function to
// use, etc.)
std::unique_ptr<std::vector<ChannelRegisteredMethod>> registered_methods_;
uint32_t registered_method_max_probes_;
grpc_closure finish_destroy_channel_closure_;
intptr_t channelz_socket_uuid_;
};
class CallData {
public:
enum class CallState {
NOT_STARTED, // Waiting for metadata.
PENDING, // Initial metadata read, not flow controlled in yet.
ACTIVATED, // Flow controlled in, on completion queue.
ZOMBIED, // Cancelled before being queued.
};
CallData(grpc_call_element* elem, const grpc_call_element_args& args,
RefCountedPtr<Server> server);
~CallData();
// Starts the recv_initial_metadata batch on the call.
// Invoked from ChannelData::AcceptStream().
void Start(grpc_call_element* elem);
void SetState(CallState state);
// Attempts to move from PENDING to ACTIVATED state. Returns true
// on success.
bool MaybeActivate();
// Publishes an incoming call to the application after it has been
// matched.
void Publish(size_t cq_idx, RequestedCall* rc);
void KillZombie();
// Functions to specify that a specific registered method or the unregistered
// collection should use a specific allocator for request matching.
void SetServerRegisteredMethodAllocator(
grpc_server* server, grpc_completion_queue* cq, void* method_tag,
std::function<ServerRegisteredCallAllocation()> allocator);
void SetServerBatchMethodAllocator(
grpc_server* server, grpc_completion_queue* cq,
std::function<ServerBatchCallAllocation()> allocator);
void FailCallCreation();
// Filter vtable functions.
static grpc_error* InitCallElement(grpc_call_element* elem,
const grpc_call_element_args* args);
static void DestroyCallElement(grpc_call_element* elem,
const grpc_call_final_info* /*final_info*/,
grpc_closure* /*ignored*/);
static void StartTransportStreamOpBatch(
grpc_call_element* elem, grpc_transport_stream_op_batch* batch);
private:
// Helper functions for handling calls at the top of the call stack.
static void RecvInitialMetadataBatchComplete(void* arg, grpc_error* error);
void StartNewRpc(grpc_call_element* elem);
static void PublishNewRpc(void* arg, grpc_error* error);
// Functions used inside the call stack.
void StartTransportStreamOpBatchImpl(grpc_call_element* elem,
grpc_transport_stream_op_batch* batch);
static void RecvInitialMetadataReady(void* arg, grpc_error* error);
static void RecvTrailingMetadataReady(void* arg, grpc_error* error);
RefCountedPtr<Server> server_;
grpc_call* call_;
Atomic<CallState> state_{CallState::NOT_STARTED};
absl::optional<grpc_slice> path_;
absl::optional<grpc_slice> host_;
grpc_millis deadline_ = GRPC_MILLIS_INF_FUTURE;
grpc_completion_queue* cq_new_ = nullptr;
RequestMatcherInterface* matcher_ = nullptr;
grpc_byte_buffer* payload_ = nullptr;
grpc_closure kill_zombie_closure_;
grpc_metadata_array initial_metadata_ =
grpc_metadata_array(); // Zero-initialize the C struct.
grpc_closure recv_initial_metadata_batch_complete_;
grpc_metadata_batch* recv_initial_metadata_ = nullptr;
uint32_t recv_initial_metadata_flags_ = 0;
grpc_closure recv_initial_metadata_ready_;
grpc_closure* original_recv_initial_metadata_ready_;
grpc_error* recv_initial_metadata_error_ = GRPC_ERROR_NONE;
bool seen_recv_trailing_metadata_ready_ = false;
grpc_closure recv_trailing_metadata_ready_;
grpc_closure* original_recv_trailing_metadata_ready_;
grpc_error* recv_trailing_metadata_error_ = GRPC_ERROR_NONE;
grpc_closure publish_;
CallCombiner* call_combiner_;
};
struct Listener {
explicit Listener(OrphanablePtr<ListenerInterface> l)
: listener(std::move(l)) {}
OrphanablePtr<ListenerInterface> listener;
grpc_closure destroy_done;
};
struct ShutdownTag {
ShutdownTag(void* tag_arg, grpc_completion_queue* cq_arg)
: tag(tag_arg), cq(cq_arg) {}
void* const tag;
grpc_completion_queue* const cq;
grpc_cq_completion completion;
};
static void ListenerDestroyDone(void* arg, grpc_error* error);
static void DoneShutdownEvent(void* server,
grpc_cq_completion* /*completion*/) {
static_cast<Server*>(server)->Unref();
}
static void DoneRequestEvent(void* req, grpc_cq_completion* completion);
void FailCall(size_t cq_idx, RequestedCall* rc, grpc_error* error);
grpc_call_error QueueRequestedCall(size_t cq_idx, RequestedCall* rc);
void MaybeFinishShutdown();
void KillPendingWorkLocked(grpc_error* error);
static grpc_call_error ValidateServerRequest(
grpc_completion_queue* cq_for_notification, void* tag,
grpc_byte_buffer** optional_payload, RegisteredMethod* rm);
grpc_call_error ValidateServerRequestAndCq(
size_t* cq_idx, grpc_completion_queue* cq_for_notification, void* tag,
grpc_byte_buffer** optional_payload, RegisteredMethod* rm);
std::vector<grpc_channel*> GetChannelsLocked() const;
grpc_channel_args* const channel_args_;
grpc_resource_user* default_resource_user_ = nullptr;
RefCountedPtr<channelz::ServerNode> channelz_node_;
std::vector<grpc_completion_queue*> cqs_;
std::vector<grpc_pollset*> pollsets_;
bool started_ = false;
// The two following mutexes control access to server-state.
// mu_global_ controls access to non-call-related state (e.g., channel state).
// mu_call_ controls access to call-related state (e.g., the call lists).
//
// If they are ever required to be nested, you must lock mu_global_
// before mu_call_. This is currently used in shutdown processing
// (ShutdownAndNotify() and MaybeFinishShutdown()).
Mutex mu_global_; // mutex for server and channel state
Mutex mu_call_; // mutex for call-specific state
// startup synchronization: flag is protected by mu_global_, signals whether
// we are doing the listener start routine or not.
bool starting_ = false;
CondVar starting_cv_;
std::vector<std::unique_ptr<RegisteredMethod>> registered_methods_;
// Request matcher for unregistered methods.
std::unique_ptr<RequestMatcherInterface> unregistered_request_matcher_;
std::atomic_bool shutdown_flag_{false};
bool shutdown_published_ = false;
std::vector<ShutdownTag> shutdown_tags_;
std::list<ChannelData*> channels_;
std::list<Listener> listeners_;
size_t listeners_destroyed_ = 0;
// The last time we printed a shutdown progress message.
gpr_timespec last_shutdown_message_time_;
};
} // namespace grpc_core
struct grpc_server {
grpc_core::OrphanablePtr<grpc_core::Server> core_server;
};
#endif /* GRPC_CORE_LIB_SURFACE_SERVER_H */

@ -23,7 +23,6 @@
#include <grpc/impl/codegen/grpc_types.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/security/server_credentials_impl.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/support/channel_arguments.h>

@ -92,10 +92,6 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
status.error_message().c_str());
}
} // namespace grpc
namespace grpc {
int SecureServerCredentials::AddPortToServer(const std::string& addr,
grpc_server* server) {
return grpc_server_add_secure_http2_port(server, addr.c_str(), creds_);

@ -547,7 +547,7 @@ class Server::CallbackRequest final
// is nullptr since these services don't have pre-defined methods.
CallbackRequest(Server* server, grpc::internal::RpcServiceMethod* method,
grpc::CompletionQueue* cq,
grpc_core::ServerRegisteredCallAllocation* data)
grpc_core::Server::RegisteredCallAllocation* data)
: server_(server),
method_(method),
has_request_payload_(method->method_type() ==
@ -568,7 +568,7 @@ class Server::CallbackRequest final
// For generic services, method is nullptr since these services don't have
// pre-defined methods.
CallbackRequest(Server* server, grpc::CompletionQueue* cq,
grpc_core::ServerBatchCallAllocation* data)
grpc_core::Server::BatchCallAllocation* data)
: server_(server),
method_(nullptr),
has_request_payload_(false),
@ -1063,9 +1063,9 @@ bool Server::RegisterService(const std::string* host, grpc::Service* service) {
has_callback_methods_ = true;
grpc::internal::RpcServiceMethod* method_value = method.get();
grpc::CompletionQueue* cq = CallbackCQ();
grpc_core::SetServerRegisteredMethodAllocator(
server_, cq->cq(), method_registration_tag, [this, cq, method_value] {
grpc_core::ServerRegisteredCallAllocation result;
server_->core_server->SetRegisteredMethodAllocator(
cq->cq(), method_registration_tag, [this, cq, method_value] {
grpc_core::Server::RegisteredCallAllocation result;
new CallbackRequest<grpc::CallbackServerContext>(this, method_value,
cq, &result);
return result;
@ -1104,8 +1104,8 @@ void Server::RegisterCallbackGenericService(
generic_handler_.reset(service->Handler());
grpc::CompletionQueue* cq = CallbackCQ();
grpc_core::SetServerBatchMethodAllocator(server_, cq->cq(), [this, cq] {
grpc_core::ServerBatchCallAllocation result;
server_->core_server->SetBatchMethodAllocator(cq->cq(), [this, cq] {
grpc_core::Server::BatchCallAllocation result;
new CallbackRequest<grpc::GenericCallbackServerContext>(this, cq, &result);
return result;
});

@ -16,10 +16,10 @@
*
*/
#include <grpcpp/security/server_credentials_impl.h>
#include <grpcpp/security/server_credentials.h>
namespace grpc_impl {
namespace grpc {
ServerCredentials::~ServerCredentials() {}
} // namespace grpc_impl
} // namespace grpc

@ -20,7 +20,7 @@
#include "src/proto/grpc/status/status.pb.h"
namespace grpc_impl {
namespace grpc {
grpc::Status ExtractErrorDetails(const grpc::Status& from,
::google::rpc::Status* to) {
@ -47,4 +47,4 @@ grpc::Status SetErrorDetails(const ::google::rpc::Status& from,
return grpc::Status::OK;
}
} // namespace grpc_impl
} // namespace grpc

@ -43,6 +43,16 @@ describe GRPC::ActiveCall do
@server = new_core_server_for_testing(nil)
server_port = @server.add_http2_port(host, :this_port_is_insecure)
@server.start
@received_rpcs_queue = Queue.new
@server_thread = Thread.new do
begin
received_rpc = @server.request_call
rescue GRPC::Core::CallError, StandardError => e
# enqueue the exception in this case as a way to indicate the error
received_rpc = e
end
@received_rpcs_queue.push(received_rpc)
end
@ch = GRPC::Core::Channel.new("0.0.0.0:#{server_port}", nil,
:this_channel_is_insecure)
end
@ -50,6 +60,7 @@ describe GRPC::ActiveCall do
after(:each) do
@server.shutdown_and_notify(deadline)
@server.close
@server_thread.join
end
describe 'restricted view methods' do
@ -105,7 +116,7 @@ describe GRPC::ActiveCall do
client_call.remote_send(msg)
# check that server rpc new was received
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
expect(recvd_rpc).to_not eq nil
recvd_call = recvd_rpc.call
@ -130,7 +141,7 @@ describe GRPC::ActiveCall do
client_call.remote_send(msg)
# confirm that the message was marshalled
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
recvd_call = recvd_rpc.call
server_ops = {
CallOps::SEND_INITIAL_METADATA => nil
@ -160,7 +171,7 @@ describe GRPC::ActiveCall do
call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil) if f == 1
# confirm that the message was marshalled
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
recvd_call = recvd_rpc.call
server_ops = {
CallOps::SEND_INITIAL_METADATA => nil
@ -321,7 +332,7 @@ describe GRPC::ActiveCall do
call = make_test_call
metadata = { k1: 'v1', k2: 'v2' }
ActiveCall.client_invoke(call, metadata)
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
recvd_call = recvd_rpc.call
expect(recvd_call).to_not be_nil
expect(recvd_rpc.metadata).to_not be_nil
@ -339,7 +350,7 @@ describe GRPC::ActiveCall do
call = make_test_call
ActiveCall.client_invoke(call)
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
server_call = ActiveCall.new(
recvd_rpc.call,
@pass_through,
@ -405,7 +416,7 @@ describe GRPC::ActiveCall do
client_call = make_test_call
ActiveCall.client_invoke(client_call)
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
recvd_call = recvd_rpc.call
server_call = ActiveCall.new(
@ -575,7 +586,7 @@ describe GRPC::ActiveCall do
@client_call = make_test_call
@client_call.run_batch(CallOps::SEND_INITIAL_METADATA => {})
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
recvd_call = recvd_rpc.call
@server_call = ActiveCall.new(
recvd_call,
@ -654,7 +665,7 @@ describe GRPC::ActiveCall do
end
def expect_server_to_be_invoked(**kw)
recvd_rpc = @server.request_call
recvd_rpc = @received_rpcs_queue.pop
expect(recvd_rpc).to_not eq nil
recvd_call = recvd_rpc.call
recvd_call.run_batch(CallOps::SEND_INITIAL_METADATA => kw)

@ -0,0 +1,19 @@
%YAML 1.2
--- |
# Copyright 2020 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!!
VERSION = '${settings.python_version.pep440()}'

@ -19,6 +19,7 @@
<%include file="../../apt_get_basic.include"/>
<%include file="../../python_deps.include"/>
<%include file="../../cxx_deps.include"/>
<%include file="../../cmake_jessie_backports.include"/>
<%include file="../../run_tests_addons.include"/>
# Define the default command.
CMD ["bash"]

@ -25,4 +25,5 @@
cp -r /var/local/jenkins/service_account $HOME || true
cd /var/local/git/grpc-dart/interop
/usr/lib/dart/bin/pub get --verbose
# De-flake attempt: run the cmd one more time in case of transient failure
/usr/lib/dart/bin/pub get --verbose || /usr/lib/dart/bin/pub get --verbose

@ -65,8 +65,8 @@ static void set_done_write(void* arg, grpc_error* /*error*/) {
static void server_setup_transport(void* ts, grpc_transport* transport) {
thd_args* a = static_cast<thd_args*>(ts);
grpc_core::ExecCtx exec_ctx;
grpc_server_setup_transport(a->server, transport, nullptr,
grpc_server_get_channel_args(a->server), nullptr);
a->server->core_server->SetupTransport(
transport, nullptr, a->server->core_server->channel_args(), nullptr);
}
/* Sets the read_done event */
@ -219,7 +219,7 @@ void grpc_run_bad_client_test(
grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq));
/* Check a ground truth */
GPR_ASSERT(grpc_server_has_open_connections(a.server));
GPR_ASSERT(a.server->core_server->HasOpenConnections());
gpr_event_init(&a.done_thd);
a.validator = server_validator;

@ -76,7 +76,7 @@ namespace {
void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -31,7 +31,7 @@
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -21,7 +21,7 @@
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -25,7 +25,7 @@
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -24,7 +24,7 @@
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -31,7 +31,7 @@ namespace {
void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -68,7 +68,7 @@ static void verifier_succeeds(grpc_server* server, grpc_completion_queue* cq,
static void verifier_fails(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -115,7 +115,7 @@ static void verifier(grpc_server* server, grpc_completion_queue* cq,
static void failure_verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -26,7 +26,7 @@
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -44,7 +44,7 @@
static void verifier(grpc_server* server, grpc_completion_queue* cq,
void* /*registered_method*/) {
while (grpc_server_has_open_connections(server)) {
while (server->core_server->HasOpenConnections()) {
GPR_ASSERT(grpc_completion_queue_next(
cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
.type == GRPC_QUEUE_TIMEOUT);

@ -73,9 +73,8 @@ static test_ctx g_ctx;
static void server_setup_transport(grpc_transport* transport) {
grpc_core::ExecCtx exec_ctx;
grpc_endpoint_add_to_pollset(g_ctx.ep->server, grpc_cq_pollset(g_ctx.cq));
grpc_server_setup_transport(g_ctx.server, transport, nullptr,
grpc_server_get_channel_args(g_ctx.server),
nullptr);
g_ctx.server->core_server->SetupTransport(
transport, nullptr, g_ctx.server->core_server->channel_args(), nullptr);
}
static void client_setup_transport(grpc_transport* transport) {

@ -519,7 +519,7 @@ TEST_F(ChannelzRegistryBasedTest, InternalChannelTest) {
TEST(ChannelzServerTest, BasicServerAPIFunctionality) {
grpc_core::ExecCtx exec_ctx;
ServerFixture server(10);
ServerNode* channelz_server = grpc_server_get_channelz_node(server.server());
ServerNode* channelz_server = server.server()->core_server->channelz_node();
channelz_server->RecordCallStarted();
channelz_server->RecordCallFailed();
channelz_server->RecordCallSucceeded();

@ -29,6 +29,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
@ -47,15 +48,16 @@
"Content-Length: 0\n" \
"Date: Tue, 07 Jun 2016 17:43:20 GMT\n\n"
#define HTTP2_RESP(STATUS_CODE) \
"\x00\x00\x00\x04\x00\x00\x00\x00\x00" \
"\x00\x00>\x01\x04\x00\x00\x00\x01" \
"\x10\x0e" \
"content-length\x01" \
"0" \
"\x10\x0c" \
"content-type\x10" \
"application/grpc" \
#define HTTP2_SETTINGS_FRAME "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
#define HTTP2_RESP(STATUS_CODE) \
"\x00\x00>\x01\x04\x00\x00\x00\x01" \
"\x10\x0e" \
"content-length\x01" \
"0" \
"\x10\x0c" \
"content-type\x10" \
"application/grpc" \
"\x10\x07:status\x03" #STATUS_CODE
#define UNPARSEABLE_RESP "Bad Request\n"
@ -63,8 +65,6 @@
#define HTTP2_DETAIL_MSG(STATUS_CODE) \
"Received http2 header with status: " #STATUS_CODE
#define HTTP1_DETAIL_MSG "Trying to connect an http1.x server"
/* TODO(zyc) Check the content of incoming data instead of using this length */
/* The 'bad' server will start sending responses after reading this amount of
* data from the client. */
@ -80,24 +80,32 @@ struct rpc_state {
grpc_slice_buffer outgoing_buffer;
grpc_endpoint* tcp;
gpr_atm done_atm;
bool write_done;
bool http2_response;
bool send_settings;
const char* response_payload;
size_t response_payload_length;
bool connection_attempt_made;
};
static int server_port;
static struct rpc_state state;
static grpc_closure on_read;
static grpc_closure on_writing_settings_frame;
static grpc_closure on_write;
static void* tag(intptr_t t) { return (void*)t; }
static void done_write(void* /*arg*/, grpc_error* error) {
GPR_ASSERT(error == GRPC_ERROR_NONE);
gpr_atm_rel_store(&state.done_atm, 1);
}
static void done_writing_settings_frame(void* /* arg */, grpc_error* error) {
GPR_ASSERT(error == GRPC_ERROR_NONE);
grpc_endpoint_read(state.tcp, &state.temp_incoming_buffer, &on_read,
/*urgent=*/false);
}
static void handle_write() {
grpc_slice slice = grpc_slice_from_copied_buffer(
state.response_payload, state.response_payload_length);
@ -108,7 +116,10 @@ static void handle_write() {
}
static void handle_read(void* /*arg*/, grpc_error* error) {
GPR_ASSERT(error == GRPC_ERROR_NONE);
if (error != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "handle_read error: %s", grpc_error_string(error));
return;
}
state.incoming_data_length += state.temp_incoming_buffer.length;
size_t i;
@ -119,11 +130,14 @@ static void handle_read(void* /*arg*/, grpc_error* error) {
gpr_free(dump);
}
gpr_log(GPR_DEBUG, "got %" PRIuPTR " bytes, expected %" PRIuPTR " bytes",
gpr_log(GPR_DEBUG,
"got %" PRIuPTR " bytes, expected %" PRIuPTR
" bytes or a non-HTTP2 response to be sent",
state.incoming_data_length,
SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD);
if (state.incoming_data_length >=
SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD) {
SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD ||
!state.http2_response) {
handle_write();
} else {
grpc_endpoint_read(state.tcp, &state.temp_incoming_buffer, &on_read,
@ -137,14 +151,26 @@ static void on_connect(void* arg, grpc_endpoint* tcp,
gpr_free(acceptor);
test_tcp_server* server = static_cast<test_tcp_server*>(arg);
GRPC_CLOSURE_INIT(&on_read, handle_read, nullptr, grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&on_writing_settings_frame, done_writing_settings_frame,
nullptr, grpc_schedule_on_exec_ctx);
GRPC_CLOSURE_INIT(&on_write, done_write, nullptr, grpc_schedule_on_exec_ctx);
grpc_slice_buffer_init(&state.temp_incoming_buffer);
grpc_slice_buffer_init(&state.outgoing_buffer);
state.connection_attempt_made = true;
state.tcp = tcp;
state.incoming_data_length = 0;
grpc_endpoint_add_to_pollset(tcp, server->pollset[0]);
grpc_endpoint_read(tcp, &state.temp_incoming_buffer, &on_read,
/*urgent=*/false);
if (state.send_settings) {
// Send settings frame from server
grpc_slice slice = grpc_slice_from_static_buffer(
HTTP2_SETTINGS_FRAME, sizeof(HTTP2_SETTINGS_FRAME) - 1);
grpc_slice_buffer_add(&state.outgoing_buffer, slice);
grpc_endpoint_write(state.tcp, &state.outgoing_buffer,
&on_writing_settings_frame, nullptr);
} else {
grpc_endpoint_read(state.tcp, &state.temp_incoming_buffer, &on_read,
/*urgent=*/false);
}
}
static gpr_timespec n_sec_deadline(int seconds) {
@ -166,13 +192,20 @@ static void start_rpc(int target_port, grpc_status_code expected_status,
state.cq = grpc_completion_queue_create_for_next(nullptr);
cqv = cq_verifier_create(state.cq);
state.target = grpc_core::JoinHostPort("127.0.0.1", target_port);
state.channel =
grpc_insecure_channel_create(state.target.c_str(), nullptr, nullptr);
grpc_slice host = grpc_slice_from_static_string("localhost");
// The default connect deadline is 20 seconds, so reduce the RPC deadline to 1
// second. This helps us verify - a) If the server responded with a non-HTTP2
// response, the connect fails immediately resulting in
// GRPC_STATUS_UNAVAILABLE instead of GRPC_STATUS_DEADLINE_EXCEEDED. b) If the
// server does not send a HTTP2 SETTINGs frame, the RPC fails with a
// DEADLINE_EXCEEDED.
state.call = grpc_channel_create_call(
state.channel, nullptr, GRPC_PROPAGATE_DEFAULTS, state.cq,
grpc_slice_from_static_string("/Service/Method"), &host,
gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
n_sec_deadline(1), nullptr);
grpc_metadata_array_init(&initial_metadata_recv);
grpc_metadata_array_init(&trailing_metadata_recv);
@ -241,7 +274,7 @@ typedef struct {
static void actually_poll_server(void* arg) {
poll_args* pa = static_cast<poll_args*>(arg);
gpr_timespec deadline = n_sec_deadline(10);
gpr_timespec deadline = n_sec_deadline(1);
while (true) {
bool done = gpr_atm_acq_load(&state.done_atm) != 0;
gpr_timespec time_left =
@ -251,7 +284,7 @@ static void actually_poll_server(void* arg) {
if (done || gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) < 0) {
break;
}
test_tcp_server_poll(pa->server, 1000);
test_tcp_server_poll(pa->server, 100);
}
gpr_event_set(pa->signal_when_done, (void*)1);
gpr_free(pa);
@ -260,7 +293,7 @@ static void actually_poll_server(void* arg) {
static grpc_core::Thread* poll_server_until_read_done(
test_tcp_server* server, gpr_event* signal_when_done) {
gpr_atm_rel_store(&state.done_atm, 0);
state.write_done = 0;
state.connection_attempt_made = false;
poll_args* pa = static_cast<poll_args*>(gpr_malloc(sizeof(*pa)));
pa->server = server;
pa->signal_when_done = signal_when_done;
@ -270,7 +303,8 @@ static grpc_core::Thread* poll_server_until_read_done(
return th;
}
static void run_test(const char* response_payload,
static void run_test(bool http2_response, bool send_settings,
const char* response_payload,
size_t response_payload_length,
grpc_status_code expected_status,
const char* expected_detail) {
@ -283,6 +317,8 @@ static void run_test(const char* response_payload,
server_port = grpc_pick_unused_port_or_die();
test_tcp_server_init(&test_server, on_connect, &test_server);
test_tcp_server_start(&test_server, server_port);
state.http2_response = http2_response;
state.send_settings = send_settings;
state.response_payload = response_payload;
state.response_payload_length = response_payload_length;
@ -292,7 +328,8 @@ static void run_test(const char* response_payload,
start_rpc(server_port, expected_status, expected_detail);
gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME));
thdptr->Join();
/* Proof that the server accepted the TCP connection. */
GPR_ASSERT(state.connection_attempt_made == true);
/* clean up */
grpc_endpoint_shutdown(state.tcp,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
@ -309,43 +346,48 @@ int main(int argc, char** argv) {
grpc_init();
/* status defined in hpack static table */
run_test(HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(204));
run_test(HTTP2_RESP(206), sizeof(HTTP2_RESP(206)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(206));
run_test(HTTP2_RESP(304), sizeof(HTTP2_RESP(304)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(304));
run_test(HTTP2_RESP(400), sizeof(HTTP2_RESP(400)) - 1, GRPC_STATUS_INTERNAL,
HTTP2_DETAIL_MSG(400));
run_test(HTTP2_RESP(404), sizeof(HTTP2_RESP(404)) - 1,
run_test(true, true, HTTP2_RESP(204), sizeof(HTTP2_RESP(204)) - 1,
GRPC_STATUS_UNKNOWN, HTTP2_DETAIL_MSG(204));
run_test(true, true, HTTP2_RESP(206), sizeof(HTTP2_RESP(206)) - 1,
GRPC_STATUS_UNKNOWN, HTTP2_DETAIL_MSG(206));
run_test(true, true, HTTP2_RESP(304), sizeof(HTTP2_RESP(304)) - 1,
GRPC_STATUS_UNKNOWN, HTTP2_DETAIL_MSG(304));
run_test(true, true, HTTP2_RESP(400), sizeof(HTTP2_RESP(400)) - 1,
GRPC_STATUS_INTERNAL, HTTP2_DETAIL_MSG(400));
run_test(true, true, HTTP2_RESP(404), sizeof(HTTP2_RESP(404)) - 1,
GRPC_STATUS_UNIMPLEMENTED, HTTP2_DETAIL_MSG(404));
run_test(HTTP2_RESP(500), sizeof(HTTP2_RESP(500)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(500));
run_test(true, true, HTTP2_RESP(500), sizeof(HTTP2_RESP(500)) - 1,
GRPC_STATUS_UNKNOWN, HTTP2_DETAIL_MSG(500));
/* status not defined in hpack static table */
run_test(HTTP2_RESP(401), sizeof(HTTP2_RESP(401)) - 1,
run_test(true, true, HTTP2_RESP(401), sizeof(HTTP2_RESP(401)) - 1,
GRPC_STATUS_UNAUTHENTICATED, HTTP2_DETAIL_MSG(401));
run_test(HTTP2_RESP(403), sizeof(HTTP2_RESP(403)) - 1,
run_test(true, true, HTTP2_RESP(403), sizeof(HTTP2_RESP(403)) - 1,
GRPC_STATUS_PERMISSION_DENIED, HTTP2_DETAIL_MSG(403));
run_test(HTTP2_RESP(429), sizeof(HTTP2_RESP(429)) - 1,
run_test(true, true, HTTP2_RESP(429), sizeof(HTTP2_RESP(429)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(429));
run_test(HTTP2_RESP(499), sizeof(HTTP2_RESP(499)) - 1, GRPC_STATUS_UNKNOWN,
HTTP2_DETAIL_MSG(499));
run_test(HTTP2_RESP(502), sizeof(HTTP2_RESP(502)) - 1,
run_test(true, true, HTTP2_RESP(499), sizeof(HTTP2_RESP(499)) - 1,
GRPC_STATUS_UNKNOWN, HTTP2_DETAIL_MSG(499));
run_test(true, true, HTTP2_RESP(502), sizeof(HTTP2_RESP(502)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(502));
run_test(HTTP2_RESP(503), sizeof(HTTP2_RESP(503)) - 1,
run_test(true, true, HTTP2_RESP(503), sizeof(HTTP2_RESP(503)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(503));
run_test(HTTP2_RESP(504), sizeof(HTTP2_RESP(504)) - 1,
run_test(true, true, HTTP2_RESP(504), sizeof(HTTP2_RESP(504)) - 1,
GRPC_STATUS_UNAVAILABLE, HTTP2_DETAIL_MSG(504));
/* unparseable response */
run_test(UNPARSEABLE_RESP, sizeof(UNPARSEABLE_RESP) - 1, GRPC_STATUS_UNKNOWN,
nullptr);
/* http1 response */
run_test(HTTP1_RESP_400, sizeof(HTTP1_RESP_400) - 1, GRPC_STATUS_INTERNAL,
HTTP1_DETAIL_MSG);
/* unparseable response. RPC should fail immediately due to a connect failure.
*/
run_test(false, false, UNPARSEABLE_RESP, sizeof(UNPARSEABLE_RESP) - 1,
GRPC_STATUS_UNAVAILABLE, nullptr);
/* http1 response. RPC should fail immediately due to a connect failure. */
run_test(false, false, HTTP1_RESP_400, sizeof(HTTP1_RESP_400) - 1,
GRPC_STATUS_UNAVAILABLE, nullptr);
/* http2 response without sending a SETTINGs frame. RPC should fail with
* DEADLINE_EXCEEDED since the RPC deadline is lower than the connection
* attempt deadline. */
run_test(true, false, HTTP2_RESP(404), sizeof(HTTP2_RESP(404)) - 1,
GRPC_STATUS_DEADLINE_EXCEEDED, nullptr);
grpc_shutdown();
return 0;
}

@ -52,8 +52,8 @@ static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_core::ExecCtx exec_ctx;
grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data);
grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq));
grpc_server_setup_transport(f->server, transport, nullptr,
grpc_server_get_channel_args(f->server), nullptr);
f->server->core_server->SetupTransport(
transport, nullptr, f->server->core_server->channel_args(), nullptr);
}
typedef struct {

@ -46,8 +46,8 @@ static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_core::ExecCtx exec_ctx;
grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data);
grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq));
grpc_server_setup_transport(f->server, transport, nullptr,
grpc_server_get_channel_args(f->server), nullptr);
f->server->core_server->SetupTransport(
transport, nullptr, f->server->core_server->channel_args(), nullptr);
}
typedef struct {

@ -46,8 +46,8 @@ static void server_setup_transport(void* ts, grpc_transport* transport) {
grpc_core::ExecCtx exec_ctx;
grpc_endpoint_pair* sfd = static_cast<grpc_endpoint_pair*>(f->fixture_data);
grpc_endpoint_add_to_pollset(sfd->server, grpc_cq_pollset(f->cq));
grpc_server_setup_transport(f->server, transport, nullptr,
grpc_server_get_channel_args(f->server), nullptr);
f->server->core_server->SetupTransport(
transport, nullptr, f->server->core_server->channel_args(), nullptr);
}
typedef struct {

@ -58,7 +58,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
grpc_server_start(server);
grpc_transport* transport =
grpc_create_chttp2_transport(nullptr, mock_endpoint, false);
grpc_server_setup_transport(server, transport, nullptr, nullptr, nullptr);
server->core_server->SetupTransport(transport, nullptr, nullptr, nullptr);
grpc_chttp2_transport_start_reading(transport, nullptr, nullptr);
grpc_call* call1 = nullptr;

@ -214,7 +214,7 @@ static void test_channelz(grpc_end2end_test_config config) {
GPR_ASSERT(channelz_channel != nullptr);
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(f.server);
f.server->core_server->channelz_node();
GPR_ASSERT(channelz_server != nullptr);
std::string json = channelz_channel->RenderJsonString();
@ -275,7 +275,7 @@ static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
GPR_ASSERT(channelz_channel != nullptr);
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(f.server);
f.server->core_server->channelz_node();
GPR_ASSERT(channelz_server != nullptr);
run_one_request(config, f, true);

@ -198,6 +198,10 @@ static void server_thread(void* arg) {
gpr_log(GPR_INFO, "Handshake successful.");
}
// Send out the settings frame.
const char settings_frame[] = "\x00\x00\x00\x04\x00\x00\x00\x00\x00";
SSL_write(ssl, settings_frame, sizeof(settings_frame) - 1);
// Wait until the client drops its connection.
char buf;
while (SSL_read(ssl, &buf, sizeof(buf)) > 0)

@ -334,9 +334,17 @@ class FakeTcpServer {
CLOSE_SOCKET,
};
FakeTcpServer(
enum class AcceptMode {
kWaitForClientToSendFirstBytes, // useful for emulating ALTS based
// grpc servers
kEagerlySendSettings, // useful for emulating insecure grpc servers (e.g.
// ALTS handshake servers)
};
explicit FakeTcpServer(
AcceptMode accept_mode,
const std::function<ProcessReadResult(int, int, int)>& process_read_cb)
: process_read_cb_(process_read_cb) {
: accept_mode_(accept_mode), process_read_cb_(process_read_cb) {
port_ = grpc_pick_unused_port_or_die();
accept_socket_ = socket(AF_INET6, SOCK_STREAM, 0);
address_ = absl::StrCat("[::]:", port_);
@ -429,12 +437,51 @@ class FakeTcpServer {
return CONTINUE_READING;
}
class FakeTcpServerPeer {
public:
explicit FakeTcpServerPeer(int fd) : fd_(fd) {}
~FakeTcpServerPeer() { close(fd_); }
void MaybeContinueSendingSettings() {
// https://tools.ietf.org/html/rfc7540#section-4.1
const std::vector<uint8_t> kEmptyHttp2SettingsFrame = {
0x00, 0x00, 0x00, // length
0x04, // settings type
0x00, // flags
0x00, 0x00, 0x00, 0x00 // stream identifier
};
if (total_bytes_sent_ < kEmptyHttp2SettingsFrame.size()) {
int bytes_to_send = kEmptyHttp2SettingsFrame.size() - total_bytes_sent_;
int bytes_sent =
send(fd_, kEmptyHttp2SettingsFrame.data() + total_bytes_sent_,
bytes_to_send, 0);
if (bytes_sent < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
gpr_log(GPR_ERROR,
"Fake TCP server encountered unexpected error:%d |%s| "
"sending %d bytes on fd:%d",
errno, strerror(errno), bytes_to_send, fd_);
GPR_ASSERT(0);
} else if (bytes_sent > 0) {
total_bytes_sent_ += bytes_sent;
GPR_ASSERT(total_bytes_sent_ <= kEmptyHttp2SettingsFrame.size());
}
}
}
int fd() { return fd_; }
private:
int fd_;
int total_bytes_sent_ = 0;
};
// Run a loop that periodically, every 10 ms:
// 1) Checks if there are any new TCP connections to accept.
// 2) Checks if any data has arrived yet on established connections,
// and reads from them if so, processing the sockets as configured.
static void RunServerLoop(FakeTcpServer* self) {
std::set<int> peers;
std::set<std::unique_ptr<FakeTcpServerPeer>> peers;
while (!gpr_event_get(&self->stop_ev_)) {
int p = accept(self->accept_socket_, nullptr, nullptr);
if (p == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
@ -449,17 +496,19 @@ class FakeTcpServer {
errno);
abort();
}
peers.insert(p);
peers.insert(absl::make_unique<FakeTcpServerPeer>(p));
}
auto it = peers.begin();
while (it != peers.end()) {
int p = *it;
FakeTcpServerPeer* peer = (*it).get();
if (self->accept_mode_ == AcceptMode::kEagerlySendSettings) {
peer->MaybeContinueSendingSettings();
}
char buf[100];
int bytes_received_size = recv(p, buf, 100, 0);
int bytes_received_size = recv(peer->fd(), buf, 100, 0);
ProcessReadResult r =
self->process_read_cb_(bytes_received_size, errno, p);
self->process_read_cb_(bytes_received_size, errno, peer->fd());
if (r == CLOSE_SOCKET) {
close(p);
it = peers.erase(it);
} else {
GPR_ASSERT(r == CONTINUE_READING);
@ -469,9 +518,6 @@ class FakeTcpServer {
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_millis(10, GPR_TIMESPAN)));
}
for (auto it = peers.begin(); it != peers.end(); it++) {
close(*it);
}
close(self->accept_socket_);
}
@ -481,6 +527,7 @@ class FakeTcpServer {
gpr_event stop_ev_;
std::string address_;
std::unique_ptr<std::thread> run_server_loop_thd_;
const AcceptMode accept_mode_;
std::function<ProcessReadResult(int, int, int)> process_read_cb_;
};
@ -500,7 +547,10 @@ TEST(AltsConcurrentConnectivityTest,
// RPCs at the fake handshake server would be inherently racey.
FakeHandshakeServer fake_handshake_server(
false /* check num concurrent rpcs */);
FakeTcpServer fake_tcp_server(
// The fake_backend_server emulates a secure (ALTS based) gRPC backend. So
// it waits for the client to send the first bytes.
FakeTcpServer fake_backend_server(
FakeTcpServer::AcceptMode::kWaitForClientToSendFirstBytes,
FakeTcpServer::CloseSocketUponReceivingBytesFromPeer);
{
gpr_timespec test_deadline = grpc_timeout_seconds_to_deadline(20);
@ -510,7 +560,7 @@ TEST(AltsConcurrentConnectivityTest,
for (size_t i = 0; i < num_concurrent_connects; i++) {
connect_loop_runners.push_back(
std::unique_ptr<ConnectLoopRunner>(new ConnectLoopRunner(
fake_tcp_server.address(), fake_handshake_server.address(),
fake_backend_server.address(), fake_handshake_server.address(),
10 /* per connect deadline seconds */, 3 /* loops */,
GRPC_CHANNEL_TRANSIENT_FAILURE /* expected connectivity states */,
0 /* reconnect_backoff_ms unset */)));
@ -530,9 +580,16 @@ TEST(AltsConcurrentConnectivityTest,
* fail fast when the ALTS handshake server fails incoming handshakes fast. */
TEST(AltsConcurrentConnectivityTest,
TestHandshakeFailsFastWhenHandshakeServerClosesConnectionAfterAccepting) {
// The fake_handshake_server emulates a broken ALTS handshaker, which
// is an insecure server. So send settings to the client eagerly.
FakeTcpServer fake_handshake_server(
FakeTcpServer::AcceptMode::kEagerlySendSettings,
FakeTcpServer::CloseSocketUponReceivingBytesFromPeer);
FakeTcpServer fake_tcp_server(FakeTcpServer::CloseSocketUponCloseFromPeer);
// The fake_backend_server emulates a secure (ALTS based) server, so wait
// for the client to send the first bytes.
FakeTcpServer fake_backend_server(
FakeTcpServer::AcceptMode::kWaitForClientToSendFirstBytes,
FakeTcpServer::CloseSocketUponCloseFromPeer);
{
gpr_timespec test_deadline = grpc_timeout_seconds_to_deadline(20);
std::vector<std::unique_ptr<ConnectLoopRunner>> connect_loop_runners;
@ -541,7 +598,7 @@ TEST(AltsConcurrentConnectivityTest,
for (size_t i = 0; i < num_concurrent_connects; i++) {
connect_loop_runners.push_back(
std::unique_ptr<ConnectLoopRunner>(new ConnectLoopRunner(
fake_tcp_server.address(), fake_handshake_server.address(),
fake_backend_server.address(), fake_handshake_server.address(),
10 /* per connect deadline seconds */, 2 /* loops */,
GRPC_CHANNEL_TRANSIENT_FAILURE /* expected connectivity states */,
0 /* reconnect_backoff_ms unset */)));
@ -562,9 +619,16 @@ TEST(AltsConcurrentConnectivityTest,
* the overall connection deadline kicks in. */
TEST(AltsConcurrentConnectivityTest,
TestHandshakeFailsFastWhenHandshakeServerHangsAfterAccepting) {
// fake_handshake_server emulates an insecure server, so send settings first.
// It will be unresponsive for the rest of the connection, though.
FakeTcpServer fake_handshake_server(
FakeTcpServer::AcceptMode::kEagerlySendSettings,
FakeTcpServer::CloseSocketUponCloseFromPeer);
// fake_backend_server emulates an ALTS based server, so wait for the client
// to send the first bytes.
FakeTcpServer fake_backend_server(
FakeTcpServer::AcceptMode::kWaitForClientToSendFirstBytes,
FakeTcpServer::CloseSocketUponCloseFromPeer);
FakeTcpServer fake_tcp_server(FakeTcpServer::CloseSocketUponCloseFromPeer);
{
gpr_timespec test_deadline = grpc_timeout_seconds_to_deadline(20);
std::vector<std::unique_ptr<ConnectLoopRunner>> connect_loop_runners;
@ -573,7 +637,7 @@ TEST(AltsConcurrentConnectivityTest,
for (size_t i = 0; i < num_concurrent_connects; i++) {
connect_loop_runners.push_back(
std::unique_ptr<ConnectLoopRunner>(new ConnectLoopRunner(
fake_tcp_server.address(), fake_handshake_server.address(),
fake_backend_server.address(), fake_handshake_server.address(),
10 /* per connect deadline seconds */, 2 /* loops */,
GRPC_CHANNEL_TRANSIENT_FAILURE /* expected connectivity states */,
100 /* reconnect_backoff_ms */)));

@ -98,8 +98,12 @@ static void me_destroy(grpc_endpoint* ep) {
gpr_free(m);
}
static char* me_get_peer(grpc_endpoint* /*ep*/) {
return gpr_strdup("fake:mock_endpoint");
static absl::string_view me_get_peer(grpc_endpoint* /*ep*/) {
return "fake:mock_endpoint";
}
static absl::string_view me_get_local_address(grpc_endpoint* /*ep*/) {
return "fake:mock_endpoint";
}
static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) {
@ -120,6 +124,7 @@ static const grpc_endpoint_vtable vtable = {me_read,
me_destroy,
me_get_resource_user,
me_get_peer,
me_get_local_address,
me_get_fd,
me_can_track_err};

@ -152,11 +152,18 @@ static void me_destroy(grpc_endpoint* ep) {
}
}
static char* me_get_peer(grpc_endpoint* ep) {
static absl::string_view me_get_peer(grpc_endpoint* ep) {
passthru_endpoint* p = (reinterpret_cast<half*>(ep))->parent;
return (reinterpret_cast<half*>(ep)) == &p->client
? gpr_strdup("fake:mock_client_endpoint")
: gpr_strdup("fake:mock_server_endpoint");
? "fake:mock_client_endpoint"
: "fake:mock_server_endpoint";
}
static absl::string_view me_get_local_address(grpc_endpoint* ep) {
passthru_endpoint* p = (reinterpret_cast<half*>(ep))->parent;
return (reinterpret_cast<half*>(ep)) == &p->client
? "fake:mock_client_endpoint"
: "fake:mock_server_endpoint";
}
static int me_get_fd(grpc_endpoint* /*ep*/) { return -1; }
@ -178,6 +185,7 @@ static const grpc_endpoint_vtable vtable = {
me_destroy,
me_get_resource_user,
me_get_peer,
me_get_local_address,
me_get_fd,
me_can_track_err,
};

@ -21,10 +21,12 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <string.h>
#include "absl/strings/string_view.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/tcp_server.h"
@ -59,8 +61,8 @@ static void on_connect(void* arg, grpc_endpoint* tcp,
grpc_pollset* /*accepting_pollset*/,
grpc_tcp_server_acceptor* acceptor) {
gpr_free(acceptor);
char* peer;
char* last_colon;
absl::string_view peer;
int last_colon;
reconnect_server* server = static_cast<reconnect_server*>(arg);
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
timestamp_list* new_tail;
@ -68,18 +70,16 @@ static void on_connect(void* arg, grpc_endpoint* tcp,
grpc_endpoint_shutdown(tcp,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected"));
grpc_endpoint_destroy(tcp);
if (peer) {
last_colon = strrchr(peer, ':');
if (server->peer == nullptr) {
server->peer = peer;
} else {
if (last_colon == nullptr) {
gpr_log(GPR_ERROR, "peer does not contain a ':'");
} else if (strncmp(server->peer, peer,
static_cast<size_t>(last_colon - peer)) != 0) {
gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer, peer);
}
gpr_free(peer);
last_colon = peer.rfind(':');
if (server->peer == nullptr) {
server->peer = new std::string(peer);
} else {
if (last_colon == std::string::npos) {
gpr_log(GPR_ERROR, "peer does not contain a ':'");
} else if (peer.compare(0, static_cast<size_t>(last_colon),
*server->peer) != 0) {
gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer->c_str(),
std::string(peer).c_str());
}
}
new_tail = static_cast<timestamp_list*>(gpr_malloc(sizeof(timestamp_list)));
@ -119,7 +119,7 @@ void reconnect_server_clear_timestamps(reconnect_server* server) {
server->head = new_head;
}
server->tail = nullptr;
gpr_free(server->peer);
delete server->peer;
server->peer = nullptr;
}

@ -32,7 +32,7 @@ typedef struct reconnect_server {
test_tcp_server tcp_server;
timestamp_list* head;
timestamp_list* tail;
char* peer;
std::string* peer;
int max_reconnect_backoff_ms;
} reconnect_server;

@ -413,6 +413,15 @@ TestEnvironment::~TestEnvironment() {
break;
}
}
if (BuiltUnderMsan()) {
// This is a workaround for MSAN. MSAN doesn't like having shutdown thread
// running. Although the code above waits until shutdown is done, chances
// are that thread itself is still alive. To workaround this problem, this
// is going to wait for 0.5 sec to give a chance to the shutdown thread to
// exit. https://github.com/grpc/grpc/issues/23695
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_millis(500, GPR_TIMESPAN)));
}
gpr_log(GPR_INFO, "TestEnvironment ends");
}

@ -122,11 +122,16 @@ static grpc_resource_user* te_get_resource_user(grpc_endpoint* ep) {
return grpc_endpoint_get_resource_user(te->wrapped);
}
static char* te_get_peer(grpc_endpoint* ep) {
static absl::string_view te_get_peer(grpc_endpoint* ep) {
trickle_endpoint* te = reinterpret_cast<trickle_endpoint*>(ep);
return grpc_endpoint_get_peer(te->wrapped);
}
static absl::string_view te_get_local_address(grpc_endpoint* ep) {
trickle_endpoint* te = reinterpret_cast<trickle_endpoint*>(ep);
return grpc_endpoint_get_local_address(te->wrapped);
}
static int te_get_fd(grpc_endpoint* ep) {
trickle_endpoint* te = reinterpret_cast<trickle_endpoint*>(ep);
return grpc_endpoint_get_fd(te->wrapped);
@ -151,6 +156,7 @@ static const grpc_endpoint_vtable vtable = {te_read,
te_destroy,
te_get_resource_user,
te_get_peer,
te_get_local_address,
te_get_fd,
te_can_track_err};

@ -18,6 +18,7 @@
#include <memory>
#include <mutex>
#include <thread>
#include <grpc/grpc.h>
#include <grpc/support/time.h>
@ -184,6 +185,7 @@ class FilterEnd2endTest : public ::testing::Test {
// The string needs to be long enough to test heap-based slice.
send_request.set_message("Hello world. Hello world. Hello world.");
std::thread request_call([this]() { server_ok(4); });
std::unique_ptr<GenericClientAsyncReaderWriter> call =
generic_stub_->PrepareCall(&cli_ctx, kMethodName, &cli_cq_);
call->StartCall(tag(1));
@ -200,7 +202,7 @@ class FilterEnd2endTest : public ::testing::Test {
generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(),
srv_cq_.get(), tag(4));
verify_ok(srv_cq_.get(), 4, true);
request_call.join();
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
ByteBuffer recv_buffer;
@ -278,6 +280,7 @@ TEST_F(FilterEnd2endTest, SimpleBidiStreaming) {
cli_ctx.set_compression_algorithm(GRPC_COMPRESS_GZIP);
send_request.set_message("Hello");
std::thread request_call([this]() { server_ok(2); });
std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream =
generic_stub_->PrepareCall(&cli_ctx, kMethodName, &cli_cq_);
cli_stream->StartCall(tag(1));
@ -286,7 +289,7 @@ TEST_F(FilterEnd2endTest, SimpleBidiStreaming) {
generic_service_.RequestCall(&srv_ctx, &srv_stream, srv_cq_.get(),
srv_cq_.get(), tag(2));
verify_ok(srv_cq_.get(), 2, true);
request_call.join();
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());

@ -140,6 +140,7 @@ class GenericEnd2endTest : public ::testing::Test {
delete method_name; // Make sure that this is not needed after invocation
std::thread request_call([this]() { server_ok(4); });
call->StartCall(tag(1));
client_ok(1);
std::unique_ptr<ByteBuffer> send_buffer =
@ -154,7 +155,7 @@ class GenericEnd2endTest : public ::testing::Test {
generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(),
srv_cq_.get(), tag(4));
verify_ok(srv_cq_.get(), 4, true);
request_call.join();
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
@ -282,7 +283,7 @@ TEST_F(GenericEnd2endTest, SequentialUnaryRpcs) {
std::unique_ptr<ByteBuffer> cli_send_buffer =
SerializeToByteBuffer(&send_request);
// Use the same cq as server so that events can be polled in time.
std::thread request_call([this]() { server_ok(4); });
std::unique_ptr<GenericClientAsyncResponseReader> call =
generic_stub_->PrepareUnaryCall(&cli_ctx, kMethodName,
*cli_send_buffer.get(), &cli_cq_);
@ -293,8 +294,7 @@ TEST_F(GenericEnd2endTest, SequentialUnaryRpcs) {
generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(),
srv_cq_.get(), tag(4));
server_ok(4);
request_call.join();
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
@ -337,6 +337,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
cli_ctx.set_compression_algorithm(GRPC_COMPRESS_GZIP);
send_request.set_message("Hello");
std::thread request_call([this]() { server_ok(2); });
std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream =
generic_stub_->PrepareCall(&cli_ctx, kMethodName, &cli_cq_);
cli_stream->StartCall(tag(1));
@ -344,8 +345,8 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
generic_service_.RequestCall(&srv_ctx, &srv_stream, srv_cq_.get(),
srv_cq_.get(), tag(2));
request_call.join();
verify_ok(srv_cq_.get(), 2, true);
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());

@ -156,9 +156,8 @@ class TestTcpServer {
private:
void OnConnect(grpc_endpoint* tcp, grpc_pollset* /*accepting_pollset*/,
grpc_tcp_server_acceptor* acceptor) {
char* peer = grpc_endpoint_get_peer(tcp);
gpr_log(GPR_INFO, "Got incoming connection! from %s", peer);
gpr_free(peer);
std::string peer(grpc_endpoint_get_peer(tcp));
gpr_log(GPR_INFO, "Got incoming connection! from %s", peer.c_str());
EXPECT_FALSE(acceptor->external_connection);
listener_fd_ = grpc_tcp_server_port_fd(
acceptor->from_server, acceptor->port_index, acceptor->fd_index);

@ -536,6 +536,8 @@ TEST_F(ServerInterceptorsAsyncEnd2endTest, GenericRPCTest) {
send_request.set_message("Hello");
cli_ctx.AddMetadata("testkey", "testvalue");
CompletionQueue* cq = srv_cq.get();
std::thread request_call([cq]() { Verifier().Expect(4, true).Verify(cq); });
std::unique_ptr<GenericClientAsyncReaderWriter> call =
generic_stub.PrepareCall(&cli_ctx, kMethodName, &cli_cq);
call->StartCall(tag(1));
@ -551,7 +553,7 @@ TEST_F(ServerInterceptorsAsyncEnd2endTest, GenericRPCTest) {
service.RequestCall(&srv_ctx, &stream, srv_cq.get(), srv_cq.get(), tag(4));
Verifier().Expect(4, true).Verify(srv_cq.get());
request_call.join();
EXPECT_EQ(kMethodName, srv_ctx.method());
EXPECT_TRUE(CheckMetadata(srv_ctx.client_metadata(), "testkey", "testvalue"));
srv_ctx.AddTrailingMetadata("testkey", "testvalue");

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save