grpc 1.39.0 → 1.40.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +20 -4
  3. data/include/grpc/event_engine/event_engine.h +10 -14
  4. data/include/grpc/event_engine/slice_allocator.h +8 -33
  5. data/include/grpc/impl/codegen/grpc_types.h +18 -8
  6. data/include/grpc/impl/codegen/port_platform.h +24 -0
  7. data/src/core/ext/filters/client_channel/client_channel.cc +413 -247
  8. data/src/core/ext/filters/client_channel/client_channel.h +42 -18
  9. data/src/core/ext/filters/client_channel/config_selector.h +19 -6
  10. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +7 -8
  11. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -21
  12. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +3 -5
  13. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +17 -38
  14. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -15
  15. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -6
  16. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -12
  17. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +14 -22
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +2 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +5 -8
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -15
  21. data/src/core/ext/filters/client_channel/lb_policy.h +70 -46
  22. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +101 -73
  23. data/src/core/ext/filters/client_channel/retry_filter.cc +392 -243
  24. data/src/core/ext/filters/client_channel/retry_service_config.cc +36 -26
  25. data/src/core/ext/filters/client_channel/retry_service_config.h +1 -1
  26. data/src/core/ext/filters/client_channel/service_config_call_data.h +45 -5
  27. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +0 -6
  28. data/src/core/ext/filters/http/client/http_client_filter.cc +5 -2
  29. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +5 -1
  30. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +1 -1
  31. data/src/core/{lib/event_engine/slice_allocator.cc → ext/transport/chttp2/transport/chttp2_slice_allocator.cc} +15 -38
  32. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +74 -0
  33. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -6
  34. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  35. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -4
  36. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +8 -8
  37. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +5 -5
  38. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +639 -752
  39. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +190 -69
  40. data/src/core/ext/transport/chttp2/transport/internal.h +1 -1
  41. data/src/core/ext/transport/chttp2/transport/parsing.cc +70 -54
  42. data/src/core/ext/transport/chttp2/transport/varint.cc +6 -4
  43. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +56 -35
  44. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +180 -76
  45. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +35 -27
  46. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +97 -48
  47. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +45 -9
  48. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +67 -7
  49. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +66 -9
  50. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +227 -0
  51. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +46 -0
  52. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +121 -0
  53. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -0
  54. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +35 -0
  55. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +90 -0
  56. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +32 -24
  57. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +120 -73
  58. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +4 -2
  59. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +15 -0
  60. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +48 -0
  61. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +171 -0
  62. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +8 -6
  63. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +27 -19
  64. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +1 -0
  65. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +24 -7
  66. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +57 -0
  67. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +29 -17
  68. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +72 -0
  69. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +3 -2
  70. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +4 -0
  71. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +6 -5
  72. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +15 -11
  73. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +85 -43
  74. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +274 -91
  75. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +11 -8
  76. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +30 -13
  77. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +33 -5
  78. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +115 -0
  79. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +60 -0
  80. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +181 -0
  81. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +1 -0
  82. data/src/core/ext/upb-generated/validate/validate.upb.c +82 -66
  83. data/src/core/ext/upb-generated/validate/validate.upb.h +220 -124
  84. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +15 -7
  85. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +53 -52
  86. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +318 -277
  87. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +5 -0
  88. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +437 -410
  89. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +198 -170
  90. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +10 -0
  91. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +9 -8
  92. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +219 -163
  93. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +15 -0
  94. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.c +59 -0
  95. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.h +40 -0
  96. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +29 -25
  97. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.c +52 -0
  98. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.h +35 -0
  99. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +135 -125
  100. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +5 -0
  101. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +131 -123
  102. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.c +90 -0
  103. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.h +35 -0
  104. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +32 -24
  105. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +69 -55
  106. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +5 -0
  107. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +684 -664
  108. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  109. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +13 -10
  110. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +13 -10
  111. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +441 -375
  112. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +10 -0
  113. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +122 -114
  114. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +1 -1
  115. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c +112 -79
  116. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.h +5 -0
  117. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.c +64 -0
  118. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.h +50 -0
  119. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +35 -32
  120. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +4 -4
  121. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +182 -160
  122. data/src/core/ext/xds/certificate_provider_store.h +1 -1
  123. data/src/core/ext/xds/xds_api.cc +320 -121
  124. data/src/core/ext/xds/xds_api.h +31 -2
  125. data/src/core/ext/xds/xds_bootstrap.cc +4 -1
  126. data/src/core/ext/xds/xds_client.cc +66 -43
  127. data/src/core/ext/xds/xds_client.h +0 -4
  128. data/src/core/ext/xds/xds_http_filters.cc +3 -2
  129. data/src/core/ext/xds/xds_http_filters.h +3 -0
  130. data/src/core/lib/channel/call_tracer.h +85 -0
  131. data/src/core/lib/channel/channel_stack.h +1 -1
  132. data/src/core/lib/channel/context.h +3 -0
  133. data/src/core/lib/channel/status_util.h +4 -0
  134. data/src/core/lib/compression/stream_compression.h +1 -1
  135. data/src/core/lib/compression/stream_compression_gzip.h +1 -1
  136. data/src/core/lib/compression/stream_compression_identity.h +1 -1
  137. data/src/core/lib/debug/stats.h +1 -1
  138. data/src/core/lib/gpr/murmur_hash.cc +4 -2
  139. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  140. data/src/core/lib/gprpp/orphanable.h +3 -3
  141. data/src/core/lib/gprpp/sync.h +2 -30
  142. data/src/core/lib/iomgr/buffer_list.cc +1 -1
  143. data/src/core/lib/iomgr/ev_apple.h +1 -1
  144. data/src/core/lib/iomgr/event_engine/endpoint.cc +6 -8
  145. data/src/core/lib/iomgr/event_engine/tcp.cc +30 -10
  146. data/src/core/lib/iomgr/python_util.h +1 -1
  147. data/src/core/lib/iomgr/resource_quota.cc +2 -0
  148. data/src/core/lib/iomgr/tcp_client_windows.cc +2 -0
  149. data/src/core/lib/iomgr/tcp_server_posix.cc +1 -0
  150. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  151. data/src/core/lib/json/json_reader.cc +1 -2
  152. data/src/core/lib/matchers/matchers.cc +8 -20
  153. data/src/core/lib/matchers/matchers.h +2 -1
  154. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +49 -0
  155. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +7 -0
  156. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +6 -18
  157. data/src/core/lib/security/transport/security_handshaker.cc +12 -4
  158. data/src/core/lib/security/transport/server_auth_filter.cc +0 -7
  159. data/src/core/lib/slice/slice_internal.h +1 -0
  160. data/src/core/lib/surface/call.cc +5 -6
  161. data/src/core/lib/surface/server.cc +3 -1
  162. data/src/core/lib/surface/server.h +3 -3
  163. data/src/core/lib/surface/version.cc +1 -3
  164. data/src/ruby/ext/grpc/extconf.rb +1 -1
  165. data/src/ruby/lib/grpc/version.rb +1 -1
  166. data/third_party/xxhash/xxhash.h +77 -195
  167. metadata +52 -35
  168. data/src/core/lib/gpr/arena.h +0 -47
@@ -210,4 +210,4 @@ class ManualConstructor {
210
210
 
211
211
  } // namespace grpc_core
212
212
 
213
- #endif
213
+ #endif // GRPC_CORE_LIB_GPRPP_MANUAL_CONSTRUCTOR_H
@@ -72,7 +72,7 @@ inline OrphanablePtr<T> MakeOrphanable(Args&&... args) {
72
72
  }
73
73
 
74
74
  // A type of Orphanable with internal ref-counting.
75
- template <typename Child>
75
+ template <typename Child, UnrefBehavior UnrefBehaviorArg = kUnrefDelete>
76
76
  class InternallyRefCounted : public Orphanable {
77
77
  public:
78
78
  // Not copyable nor movable.
@@ -102,12 +102,12 @@ class InternallyRefCounted : public Orphanable {
102
102
 
103
103
  void Unref() {
104
104
  if (GPR_UNLIKELY(refs_.Unref())) {
105
- delete this;
105
+ internal::Delete<Child, UnrefBehaviorArg>(static_cast<Child*>(this));
106
106
  }
107
107
  }
108
108
  void Unref(const DebugLocation& location, const char* reason) {
109
109
  if (GPR_UNLIKELY(refs_.Unref(location, reason))) {
110
- delete this;
110
+ internal::Delete<Child, UnrefBehaviorArg>(static_cast<Child*>(this));
111
111
  }
112
112
  }
113
113
 
@@ -19,10 +19,9 @@
19
19
  #ifndef GRPC_CORE_LIB_GPRPP_SYNC_H
20
20
  #define GRPC_CORE_LIB_GPRPP_SYNC_H
21
21
 
22
- #include <grpc/impl/codegen/port_platform.h>
22
+ #include <grpc/support/port_platform.h>
23
23
 
24
- #include <grpc/impl/codegen/log.h>
25
- #include <grpc/impl/codegen/sync.h>
24
+ #include <grpc/support/log.h>
26
25
  #include <grpc/support/sync.h>
27
26
  #include <grpc/support/time.h>
28
27
 
@@ -145,33 +144,6 @@ class CondVar {
145
144
 
146
145
  #endif // GPR_ABSEIL_SYNC
147
146
 
148
- template <typename Predicate>
149
- static void WaitUntil(CondVar* cv, Mutex* mu, Predicate pred) {
150
- while (!pred()) {
151
- cv->Wait(mu);
152
- }
153
- }
154
-
155
- // Returns true iff we timed-out
156
- template <typename Predicate>
157
- static bool WaitUntilWithTimeout(CondVar* cv, Mutex* mu, Predicate pred,
158
- absl::Duration timeout) {
159
- while (!pred()) {
160
- if (cv->WaitWithTimeout(mu, timeout)) return true;
161
- }
162
- return false;
163
- }
164
-
165
- // Returns true iff we timed-out
166
- template <typename Predicate>
167
- static bool WaitUntilWithDeadline(CondVar* cv, Mutex* mu, Predicate pred,
168
- absl::Time deadline) {
169
- while (!pred()) {
170
- if (cv->WaitWithDeadline(mu, deadline)) return true;
171
- }
172
- return false;
173
- }
174
-
175
147
  // Deprecated. Prefer MutexLock
176
148
  class MutexLockForGprMu {
177
149
  public:
@@ -190,7 +190,7 @@ void extract_opt_stats_from_cmsg(ConnectionMetrics* metrics,
190
190
 
191
191
  static int get_socket_tcp_info(grpc_core::tcp_info* info, int fd) {
192
192
  memset(info, 0, sizeof(*info));
193
- info->length = sizeof(*info) - sizeof(socklen_t);
193
+ info->length = offsetof(grpc_core::tcp_info, length);
194
194
  return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &(info->length));
195
195
  }
196
196
  } /* namespace */
@@ -40,4 +40,4 @@ extern grpc_pollset_set_vtable grpc_apple_pollset_set_vtable;
40
40
 
41
41
  #endif
42
42
 
43
- #endif
43
+ #endif // GRPC_CORE_LIB_IOMGR_EV_APPLE_H
@@ -59,7 +59,7 @@ void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices,
59
59
  exec_ctx.Flush();
60
60
  grpc_pollset_ee_broadcast_event();
61
61
  },
62
- read_buffer, absl::InfiniteFuture());
62
+ read_buffer);
63
63
  }
64
64
 
65
65
  void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices,
@@ -83,7 +83,7 @@ void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices,
83
83
  exec_ctx.Flush();
84
84
  grpc_pollset_ee_broadcast_event();
85
85
  },
86
- write_buffer, absl::InfiniteFuture());
86
+ write_buffer);
87
87
  }
88
88
  void endpoint_add_to_pollset(grpc_endpoint* /* ep */,
89
89
  grpc_pollset* /* pollset */) {}
@@ -123,9 +123,8 @@ absl::string_view endpoint_get_peer(grpc_endpoint* ep) {
123
123
  return "";
124
124
  }
125
125
  if (eeep->peer_address.empty()) {
126
- const EventEngine::ResolvedAddress* addr = eeep->endpoint->GetPeerAddress();
127
- GPR_ASSERT(addr != nullptr);
128
- eeep->peer_address = ResolvedAddressToURI(*addr);
126
+ const EventEngine::ResolvedAddress& addr = eeep->endpoint->GetPeerAddress();
127
+ eeep->peer_address = ResolvedAddressToURI(addr);
129
128
  }
130
129
  return eeep->peer_address;
131
130
  }
@@ -136,10 +135,9 @@ absl::string_view endpoint_get_local_address(grpc_endpoint* ep) {
136
135
  return "";
137
136
  }
138
137
  if (eeep->local_address.empty()) {
139
- const EventEngine::ResolvedAddress* addr =
138
+ const EventEngine::ResolvedAddress& addr =
140
139
  eeep->endpoint->GetLocalAddress();
141
- GPR_ASSERT(addr != nullptr);
142
- eeep->local_address = ResolvedAddressToURI(*addr);
140
+ eeep->local_address = ResolvedAddressToURI(addr);
143
141
  }
144
142
  return eeep->local_address;
145
143
  }
@@ -38,20 +38,36 @@ using ::grpc_event_engine::experimental::EventEngine;
38
38
  using ::grpc_event_engine::experimental::GrpcClosureToCallback;
39
39
  using ::grpc_event_engine::experimental::SliceAllocator;
40
40
  using ::grpc_event_engine::experimental::SliceAllocatorFactory;
41
+ using ::grpc_event_engine::experimental::SliceBuffer;
41
42
  } // namespace
42
43
 
44
+ // TODO(hork): remove these classes in PR #26643, when the iomgr APIs change to
45
+ // accept SliceAllocators and SliceAllocatorFactory(ie)s. In the meantime, the
46
+ // libuv work has temporary implementations as well.
47
+ class NoopSliceAllocator : public SliceAllocator {
48
+ public:
49
+ absl::Status Allocate(size_t size, SliceBuffer* dest,
50
+ SliceAllocator::AllocateCallback cb) {
51
+ return absl::OkStatus();
52
+ }
53
+ };
54
+
55
+ class NoopSliceAllocatorFactory : public SliceAllocatorFactory {
56
+ public:
57
+ std::unique_ptr<SliceAllocator> CreateSliceAllocator(
58
+ absl::string_view peer_name) {
59
+ return absl::make_unique<NoopSliceAllocator>();
60
+ };
61
+ };
62
+
43
63
  struct grpc_tcp_server {
44
- grpc_tcp_server(std::unique_ptr<EventEngine::Listener> listener,
45
- grpc_resource_quota* rq)
64
+ explicit grpc_tcp_server(std::unique_ptr<EventEngine::Listener> listener)
46
65
  : refcount(1, GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace) ? "tcp" : nullptr),
47
- listener(std::move(listener)),
48
- resource_quota(rq) {
66
+ listener(std::move(listener)) {
49
67
  shutdown_starting.head = nullptr;
50
68
  shutdown_starting.tail = nullptr;
51
69
  };
52
70
  ~grpc_tcp_server() {
53
- // TODO(nnoble): see if we can handle this in ~SliceAllocatorFactory
54
- grpc_resource_quota_unref_internal(resource_quota);
55
71
  grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &shutdown_starting);
56
72
  grpc_core::ExecCtx::Get()->Flush();
57
73
  }
@@ -59,7 +75,6 @@ struct grpc_tcp_server {
59
75
  grpc_core::Mutex mu;
60
76
  std::unique_ptr<EventEngine::Listener> listener;
61
77
  grpc_closure_list shutdown_starting ABSL_GUARDED_BY(mu);
62
- grpc_resource_quota* resource_quota;
63
78
  grpc_tcp_server_cb on_accept_internal;
64
79
  void* on_accept_internal_arg;
65
80
  };
@@ -99,7 +114,9 @@ void tcp_connect(grpc_closure* on_connect, grpc_endpoint** endpoint,
99
114
  *endpoint = &ee_endpoint->base;
100
115
  EventEngine::OnConnectCallback ee_on_connect =
101
116
  GrpcClosureToOnConnectCallback(on_connect, endpoint);
102
- SliceAllocator sa(ee_endpoint->ru);
117
+ // TODO(hork): tcp_connect will change to accept a SliceAllocator. This is
118
+ // temporary.
119
+ auto sa = absl::make_unique<NoopSliceAllocator>();
103
120
  EventEngine::ResolvedAddress ra(reinterpret_cast<const sockaddr*>(addr->addr),
104
121
  addr->len);
105
122
  absl::Time ee_deadline = grpc_core::ToAbslTime(
@@ -124,6 +141,9 @@ grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
124
141
  if (rq == nullptr) {
125
142
  rq = grpc_resource_quota_create(nullptr);
126
143
  }
144
+ // TODO(hork): tcp_server_create will change to accept a
145
+ // SliceAllocatorFactory. This is temporary.
146
+ auto saf = absl::make_unique<NoopSliceAllocatorFactory>();
127
147
  EventEngine* event_engine = grpc_iomgr_event_engine();
128
148
  absl::StatusOr<std::unique_ptr<EventEngine::Listener>> listener =
129
149
  event_engine->CreateListener(
@@ -144,11 +164,11 @@ grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
144
164
  grpc_pollset_ee_broadcast_event();
145
165
  },
146
166
  GrpcClosureToCallback(shutdown_complete, GRPC_ERROR_NONE),
147
- endpoint_config, SliceAllocatorFactory(rq));
167
+ endpoint_config, std::move(saf));
148
168
  if (!listener.ok()) {
149
169
  return absl_status_to_grpc_error(listener.status());
150
170
  }
151
- *server = new grpc_tcp_server(std::move(*listener), rq);
171
+ *server = new grpc_tcp_server(std::move(*listener));
152
172
  return GRPC_ERROR_NONE;
153
173
  }
154
174
 
@@ -43,4 +43,4 @@ inline int grpc_slice_buffer_length(grpc_slice_buffer* buffer, int i) {
43
43
  return GRPC_SLICE_LENGTH(buffer->slices[i]);
44
44
  }
45
45
 
46
- #endif
46
+ #endif // GRPC_CORE_LIB_IOMGR_PYTHON_UTIL_H
@@ -805,6 +805,8 @@ grpc_resource_user* grpc_resource_user_create(
805
805
  for (int i = 0; i < GRPC_RULIST_COUNT; i++) {
806
806
  resource_user->links[i].next = resource_user->links[i].prev = nullptr;
807
807
  }
808
+ // TODO(hork): the RU should own a copy of the name. See Craig's comments on
809
+ // the EventEngine gRFC for justification.
808
810
  if (name != nullptr) {
809
811
  resource_user->name = name;
810
812
  } else {
@@ -206,8 +206,10 @@ static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint,
206
206
  GRPC_CLOSURE_INIT(&ac->on_connect, on_connect, ac, grpc_schedule_on_exec_ctx);
207
207
 
208
208
  GRPC_CLOSURE_INIT(&ac->on_alarm, on_alarm, ac, grpc_schedule_on_exec_ctx);
209
+ gpr_mu_lock(&ac->mu);
209
210
  grpc_timer_init(&ac->alarm, deadline, &ac->on_alarm);
210
211
  grpc_socket_notify_on_write(socket, &ac->on_connect);
212
+ gpr_mu_unlock(&ac->mu);
211
213
  return;
212
214
 
213
215
  failure:
@@ -405,6 +405,7 @@ static grpc_error_handle clone_port(grpc_tcp_listener* listener,
405
405
  static grpc_error_handle tcp_server_add_port(grpc_tcp_server* s,
406
406
  const grpc_resolved_address* addr,
407
407
  int* out_port) {
408
+ GPR_ASSERT(addr->len <= GRPC_MAX_SOCKADDR_SIZE);
408
409
  grpc_tcp_listener* sp;
409
410
  grpc_resolved_address sockname_temp;
410
411
  grpc_resolved_address addr6_v4mapped;
@@ -250,7 +250,7 @@ static void timer_main_loop() {
250
250
  gpr_log(GPR_INFO, "timers not checked: expect another thread to");
251
251
  }
252
252
  next = GRPC_MILLIS_INF_FUTURE;
253
- // fallthrough
253
+ ABSL_FALLTHROUGH_INTENDED;
254
254
  case GRPC_TIMERS_CHECKED_AND_EMPTY:
255
255
  if (!wait_until(next)) {
256
256
  return;
@@ -347,8 +347,7 @@ JsonReader::Status JsonReader::Run() {
347
347
  }
348
348
  if (!SetNumber()) return Status::GRPC_JSON_PARSE_ERROR;
349
349
  state_ = State::GRPC_JSON_STATE_VALUE_END;
350
- /* The missing break here is intentional. */
351
- /* fallthrough */
350
+ ABSL_FALLTHROUGH_INTENDED;
352
351
 
353
352
  case State::GRPC_JSON_STATE_VALUE_END:
354
353
  case State::GRPC_JSON_STATE_OBJECT_KEY_BEGIN:
@@ -32,14 +32,12 @@ absl::StatusOr<StringMatcher> StringMatcher::Create(Type type,
32
32
  absl::string_view matcher,
33
33
  bool case_sensitive) {
34
34
  if (type == Type::kSafeRegex) {
35
- RE2::Options options;
36
- options.set_case_sensitive(case_sensitive);
37
- auto regex_matcher = absl::make_unique<RE2>(std::string(matcher), options);
35
+ auto regex_matcher = absl::make_unique<RE2>(std::string(matcher));
38
36
  if (!regex_matcher->ok()) {
39
37
  return absl::InvalidArgumentError(
40
38
  "Invalid regex string specified in matcher.");
41
39
  }
42
- return StringMatcher(std::move(regex_matcher), case_sensitive);
40
+ return StringMatcher(std::move(regex_matcher));
43
41
  } else {
44
42
  return StringMatcher(type, matcher, case_sensitive);
45
43
  }
@@ -49,19 +47,13 @@ StringMatcher::StringMatcher(Type type, absl::string_view matcher,
49
47
  bool case_sensitive)
50
48
  : type_(type), string_matcher_(matcher), case_sensitive_(case_sensitive) {}
51
49
 
52
- StringMatcher::StringMatcher(std::unique_ptr<RE2> regex_matcher,
53
- bool case_sensitive)
54
- : type_(Type::kSafeRegex),
55
- regex_matcher_(std::move(regex_matcher)),
56
- case_sensitive_(case_sensitive) {}
50
+ StringMatcher::StringMatcher(std::unique_ptr<RE2> regex_matcher)
51
+ : type_(Type::kSafeRegex), regex_matcher_(std::move(regex_matcher)) {}
57
52
 
58
53
  StringMatcher::StringMatcher(const StringMatcher& other)
59
54
  : type_(other.type_), case_sensitive_(other.case_sensitive_) {
60
55
  if (type_ == Type::kSafeRegex) {
61
- RE2::Options options;
62
- options.set_case_sensitive(other.case_sensitive_);
63
- regex_matcher_ =
64
- absl::make_unique<RE2>(other.regex_matcher_->pattern(), options);
56
+ regex_matcher_ = absl::make_unique<RE2>(other.regex_matcher_->pattern());
65
57
  } else {
66
58
  string_matcher_ = other.string_matcher_;
67
59
  }
@@ -70,10 +62,7 @@ StringMatcher::StringMatcher(const StringMatcher& other)
70
62
  StringMatcher& StringMatcher::operator=(const StringMatcher& other) {
71
63
  type_ = other.type_;
72
64
  if (type_ == Type::kSafeRegex) {
73
- RE2::Options options;
74
- options.set_case_sensitive(other.case_sensitive_);
75
- regex_matcher_ =
76
- absl::make_unique<RE2>(other.regex_matcher_->pattern(), options);
65
+ regex_matcher_ = absl::make_unique<RE2>(other.regex_matcher_->pattern());
77
66
  } else {
78
67
  string_matcher_ = other.string_matcher_;
79
68
  }
@@ -151,9 +140,8 @@ std::string StringMatcher::ToString() const {
151
140
  return absl::StrFormat("StringMatcher{contains=%s%s}", string_matcher_,
152
141
  case_sensitive_ ? "" : ", case_sensitive=false");
153
142
  case Type::kSafeRegex:
154
- return absl::StrFormat("StringMatcher{safe_regex=%s%s}",
155
- regex_matcher_->pattern(),
156
- case_sensitive_ ? "" : ", case_sensitive=false");
143
+ return absl::StrFormat("StringMatcher{safe_regex=%s}",
144
+ regex_matcher_->pattern());
157
145
  default:
158
146
  return "";
159
147
  }
@@ -39,6 +39,7 @@ class StringMatcher {
39
39
  };
40
40
 
41
41
  // Creates StringMatcher instance. Returns error status on failure.
42
+ // Note: case_sensitive is ignored for type kSafeRegex.
42
43
  static absl::StatusOr<StringMatcher> Create(Type type,
43
44
  absl::string_view matcher,
44
45
  bool case_sensitive = true);
@@ -66,7 +67,7 @@ class StringMatcher {
66
67
 
67
68
  private:
68
69
  StringMatcher(Type type, absl::string_view matcher, bool case_sensitive);
69
- StringMatcher(std::unique_ptr<RE2> regex_matcher, bool case_sensitive);
70
+ explicit StringMatcher(std::unique_ptr<RE2> regex_matcher);
70
71
 
71
72
  Type type_ = Type::kExact;
72
73
  std::string string_matcher_;
@@ -21,6 +21,7 @@
21
21
  #include <grpc/support/alloc.h>
22
22
  #include <grpc/support/log.h>
23
23
  #include <grpc/support/string_util.h>
24
+ #include <openssl/ssl.h>
24
25
 
25
26
  #include "src/core/lib/gprpp/stat.h"
26
27
  #include "src/core/lib/slice/slice_internal.h"
@@ -364,6 +365,54 @@ FileWatcherCertificateProvider::ReadIdentityKeyCertPairFromFiles(
364
365
  return absl::nullopt;
365
366
  }
366
367
 
368
+ absl::StatusOr<bool> PrivateKeyAndCertificateMatch(
369
+ absl::string_view private_key, absl::string_view cert_chain) {
370
+ if (private_key.empty()) {
371
+ return absl::InvalidArgumentError("Private key string is empty.");
372
+ }
373
+ if (cert_chain.empty()) {
374
+ return absl::InvalidArgumentError("Certificate string is empty.");
375
+ }
376
+ BIO* cert_bio = BIO_new_mem_buf(cert_chain.data(), cert_chain.size());
377
+ if (cert_bio == nullptr) {
378
+ return absl::InvalidArgumentError(
379
+ "Conversion from certificate string to BIO failed.");
380
+ }
381
+ // Reads the first cert from the cert_chain which is expected to be the leaf
382
+ // cert
383
+ X509* x509 = PEM_read_bio_X509(cert_bio, nullptr, nullptr, nullptr);
384
+ BIO_free(cert_bio);
385
+ if (x509 == nullptr) {
386
+ return absl::InvalidArgumentError(
387
+ "Conversion from PEM string to X509 failed.");
388
+ }
389
+ EVP_PKEY* public_evp_pkey = X509_get_pubkey(x509);
390
+ X509_free(x509);
391
+ if (public_evp_pkey == nullptr) {
392
+ return absl::InvalidArgumentError(
393
+ "Extraction of public key from x.509 certificate failed.");
394
+ }
395
+ BIO* private_key_bio =
396
+ BIO_new_mem_buf(private_key.data(), private_key.size());
397
+ if (private_key_bio == nullptr) {
398
+ EVP_PKEY_free(public_evp_pkey);
399
+ return absl::InvalidArgumentError(
400
+ "Conversion from private key string to BIO failed.");
401
+ }
402
+ EVP_PKEY* private_evp_pkey =
403
+ PEM_read_bio_PrivateKey(private_key_bio, nullptr, nullptr, nullptr);
404
+ BIO_free(private_key_bio);
405
+ if (private_evp_pkey == nullptr) {
406
+ EVP_PKEY_free(public_evp_pkey);
407
+ return absl::InvalidArgumentError(
408
+ "Conversion from PEM string to EVP_PKEY failed.");
409
+ }
410
+ bool result = EVP_PKEY_cmp(private_evp_pkey, public_evp_pkey) == 1;
411
+ EVP_PKEY_free(private_evp_pkey);
412
+ EVP_PKEY_free(public_evp_pkey);
413
+ return result;
414
+ }
415
+
367
416
  } // namespace grpc_core
368
417
 
369
418
  /** -- Wrapper APIs declared in grpc_security.h -- **/
@@ -23,6 +23,7 @@
23
23
  #include <string.h>
24
24
 
25
25
  #include "absl/container/inlined_vector.h"
26
+ #include "absl/status/statusor.h"
26
27
 
27
28
  #include "src/core/lib/gprpp/ref_counted.h"
28
29
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
@@ -133,6 +134,12 @@ class FileWatcherCertificateProvider final
133
134
  std::map<std::string, WatcherInfo> watcher_info_;
134
135
  };
135
136
 
137
+ // Checks if the private key matches the certificate's public key.
138
+ // Returns a not-OK status on failure, or a bool indicating
139
+ // whether the key/cert pair matches.
140
+ absl::StatusOr<bool> PrivateKeyAndCertificateMatch(
141
+ absl::string_view private_key, absl::string_view cert_chain);
142
+
136
143
  } // namespace grpc_core
137
144
 
138
145
  #endif // GRPC_CORE_LIB_SECURITY_CREDENTIALS_TLS_GRPC_TLS_CERTIFICATE_PROVIDER_H