grpc 1.74.0.pre2-x86-linux-musl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +19 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +269 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +347 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +32 -0
- data/src/ruby/ext/grpc/rb_channel.c +391 -0
- data/src/ruby/ext/grpc/rb_channel.h +32 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +174 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +36 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +95 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +469 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +167 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +500 -0
- data/src/ruby/ext/grpc/rb_grpc.h +88 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +597 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +902 -0
- data/src/ruby/ext/grpc/rb_loader.c +57 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +406 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +36 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +679 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +57 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +21 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +19 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +50 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +19 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +174 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +193 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +209 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +317 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/core_spec.rb +22 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +670 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1079 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +773 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/logconfig_spec.rb +30 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +163 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +411 -0
@@ -0,0 +1,285 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_channel_credentials.h"
|
22
|
+
|
23
|
+
#include <grpc/credentials.h>
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
#include <grpc/grpc_security.h>
|
26
|
+
#include <grpc/support/alloc.h>
|
27
|
+
#include <grpc/support/log.h>
|
28
|
+
#include <string.h>
|
29
|
+
|
30
|
+
#include "rb_call_credentials.h"
|
31
|
+
#include "rb_grpc.h"
|
32
|
+
#include "rb_grpc_imports.generated.h"
|
33
|
+
|
34
|
+
/* grpc_rb_cChannelCredentials is the ruby class that proxies
|
35
|
+
grpc_channel_credentials. */
|
36
|
+
static VALUE grpc_rb_cChannelCredentials = Qnil;
|
37
|
+
|
38
|
+
static char* pem_root_certs = NULL;
|
39
|
+
|
40
|
+
/* grpc_rb_channel_credentials wraps a grpc_channel_credentials. It provides a
|
41
|
+
* mark object that is used to hold references to any objects used to create
|
42
|
+
* the credentials. */
|
43
|
+
typedef struct grpc_rb_channel_credentials {
|
44
|
+
/* Holder of ruby objects involved in constructing the credentials */
|
45
|
+
VALUE mark;
|
46
|
+
|
47
|
+
/* The actual credentials */
|
48
|
+
grpc_channel_credentials* wrapped;
|
49
|
+
} grpc_rb_channel_credentials;
|
50
|
+
|
51
|
+
static void grpc_rb_channel_credentials_free_internal(void* p) {
|
52
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
53
|
+
if (p == NULL) {
|
54
|
+
return;
|
55
|
+
};
|
56
|
+
wrapper = (grpc_rb_channel_credentials*)p;
|
57
|
+
grpc_channel_credentials_release(wrapper->wrapped);
|
58
|
+
wrapper->wrapped = NULL;
|
59
|
+
|
60
|
+
xfree(p);
|
61
|
+
}
|
62
|
+
|
63
|
+
/* Destroys the credentials instances. */
|
64
|
+
static void grpc_rb_channel_credentials_free(void* p) {
|
65
|
+
grpc_rb_channel_credentials_free_internal(p);
|
66
|
+
}
|
67
|
+
|
68
|
+
/* Protects the mark object from GC */
|
69
|
+
static void grpc_rb_channel_credentials_mark(void* p) {
|
70
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
71
|
+
if (p == NULL) {
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
wrapper = (grpc_rb_channel_credentials*)p;
|
75
|
+
|
76
|
+
if (wrapper->mark != Qnil) {
|
77
|
+
rb_gc_mark(wrapper->mark);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
static rb_data_type_t grpc_rb_channel_credentials_data_type = {
|
82
|
+
"grpc_channel_credentials",
|
83
|
+
{grpc_rb_channel_credentials_mark,
|
84
|
+
grpc_rb_channel_credentials_free,
|
85
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
86
|
+
{NULL, NULL}},
|
87
|
+
NULL,
|
88
|
+
NULL,
|
89
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
90
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
91
|
+
#endif
|
92
|
+
};
|
93
|
+
|
94
|
+
/* Allocates ChannelCredential instances.
|
95
|
+
Provides safe initial defaults for the instance fields. */
|
96
|
+
static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) {
|
97
|
+
grpc_ruby_init();
|
98
|
+
grpc_rb_channel_credentials* wrapper = ALLOC(grpc_rb_channel_credentials);
|
99
|
+
wrapper->wrapped = NULL;
|
100
|
+
wrapper->mark = Qnil;
|
101
|
+
return TypedData_Wrap_Struct(cls, &grpc_rb_channel_credentials_data_type,
|
102
|
+
wrapper);
|
103
|
+
}
|
104
|
+
|
105
|
+
/* Creates a wrapping object for a given channel credentials. This should only
|
106
|
+
* be called with grpc_channel_credentials objects that are not already
|
107
|
+
* associated with any Ruby object. */
|
108
|
+
VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials* c,
|
109
|
+
VALUE mark) {
|
110
|
+
VALUE rb_wrapper;
|
111
|
+
grpc_rb_channel_credentials* wrapper;
|
112
|
+
if (c == NULL) {
|
113
|
+
return Qnil;
|
114
|
+
}
|
115
|
+
rb_wrapper = grpc_rb_channel_credentials_alloc(grpc_rb_cChannelCredentials);
|
116
|
+
TypedData_Get_Struct(rb_wrapper, grpc_rb_channel_credentials,
|
117
|
+
&grpc_rb_channel_credentials_data_type, wrapper);
|
118
|
+
wrapper->wrapped = c;
|
119
|
+
wrapper->mark = mark;
|
120
|
+
return rb_wrapper;
|
121
|
+
}
|
122
|
+
|
123
|
+
/* The attribute used on the mark object to hold the pem_root_certs. */
|
124
|
+
static ID id_pem_root_certs;
|
125
|
+
|
126
|
+
/* The attribute used on the mark object to hold the pem_private_key. */
|
127
|
+
static ID id_pem_private_key;
|
128
|
+
|
129
|
+
/* The attribute used on the mark object to hold the pem_private_key. */
|
130
|
+
static ID id_pem_cert_chain;
|
131
|
+
|
132
|
+
/*
|
133
|
+
call-seq:
|
134
|
+
creds1 = Credentials.new()
|
135
|
+
...
|
136
|
+
creds2 = Credentials.new(pem_root_certs)
|
137
|
+
...
|
138
|
+
creds3 = Credentials.new(pem_root_certs, pem_private_key,
|
139
|
+
pem_cert_chain)
|
140
|
+
pem_root_certs: (optional) PEM encoding of the server root certificate
|
141
|
+
pem_private_key: (optional) PEM encoding of the client's private key
|
142
|
+
pem_cert_chain: (optional) PEM encoding of the client's cert chain
|
143
|
+
Initializes Credential instances. */
|
144
|
+
static VALUE grpc_rb_channel_credentials_init(int argc, VALUE* argv,
|
145
|
+
VALUE self) {
|
146
|
+
VALUE pem_root_certs = Qnil;
|
147
|
+
VALUE pem_private_key = Qnil;
|
148
|
+
VALUE pem_cert_chain = Qnil;
|
149
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
150
|
+
grpc_channel_credentials* creds = NULL;
|
151
|
+
grpc_ssl_pem_key_cert_pair key_cert_pair;
|
152
|
+
const char* pem_root_certs_cstr = NULL;
|
153
|
+
MEMZERO(&key_cert_pair, grpc_ssl_pem_key_cert_pair, 1);
|
154
|
+
|
155
|
+
/* "03" == no mandatory arg, 3 optional */
|
156
|
+
rb_scan_args(argc, argv, "03", &pem_root_certs, &pem_private_key,
|
157
|
+
&pem_cert_chain);
|
158
|
+
|
159
|
+
TypedData_Get_Struct(self, grpc_rb_channel_credentials,
|
160
|
+
&grpc_rb_channel_credentials_data_type, wrapper);
|
161
|
+
if (pem_root_certs != Qnil) {
|
162
|
+
pem_root_certs_cstr = RSTRING_PTR(pem_root_certs);
|
163
|
+
}
|
164
|
+
if (pem_private_key == Qnil && pem_cert_chain == Qnil) {
|
165
|
+
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL, NULL);
|
166
|
+
} else {
|
167
|
+
if (pem_private_key == Qnil) {
|
168
|
+
rb_raise(
|
169
|
+
rb_eRuntimeError,
|
170
|
+
"could not create a credentials because pem_private_key is NULL");
|
171
|
+
}
|
172
|
+
if (pem_cert_chain == Qnil) {
|
173
|
+
rb_raise(rb_eRuntimeError,
|
174
|
+
"could not create a credentials because pem_cert_chain is NULL");
|
175
|
+
}
|
176
|
+
key_cert_pair.private_key = RSTRING_PTR(pem_private_key);
|
177
|
+
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain);
|
178
|
+
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, &key_cert_pair,
|
179
|
+
NULL, NULL);
|
180
|
+
}
|
181
|
+
if (creds == NULL) {
|
182
|
+
rb_raise(rb_eRuntimeError,
|
183
|
+
"the call to grpc_ssl_credentials_create() failed, could not "
|
184
|
+
"create a credentials, see "
|
185
|
+
"https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
|
186
|
+
"debugging tips");
|
187
|
+
return Qnil;
|
188
|
+
}
|
189
|
+
wrapper->wrapped = creds;
|
190
|
+
|
191
|
+
/* Add the input objects as hidden fields to preserve them. */
|
192
|
+
rb_ivar_set(self, id_pem_cert_chain, pem_cert_chain);
|
193
|
+
rb_ivar_set(self, id_pem_private_key, pem_private_key);
|
194
|
+
rb_ivar_set(self, id_pem_root_certs, pem_root_certs);
|
195
|
+
|
196
|
+
return self;
|
197
|
+
}
|
198
|
+
|
199
|
+
static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE* argv,
|
200
|
+
VALUE self) {
|
201
|
+
grpc_channel_credentials* creds;
|
202
|
+
grpc_call_credentials* other;
|
203
|
+
grpc_channel_credentials* prev = NULL;
|
204
|
+
VALUE mark;
|
205
|
+
if (argc == 0) {
|
206
|
+
return self;
|
207
|
+
}
|
208
|
+
mark = rb_ary_new();
|
209
|
+
rb_ary_push(mark, self);
|
210
|
+
creds = grpc_rb_get_wrapped_channel_credentials(self);
|
211
|
+
for (int i = 0; i < argc; i++) {
|
212
|
+
rb_ary_push(mark, argv[i]);
|
213
|
+
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
|
214
|
+
creds = grpc_composite_channel_credentials_create(creds, other, NULL);
|
215
|
+
if (prev != NULL) {
|
216
|
+
grpc_channel_credentials_release(prev);
|
217
|
+
}
|
218
|
+
prev = creds;
|
219
|
+
|
220
|
+
if (creds == NULL) {
|
221
|
+
rb_raise(rb_eRuntimeError,
|
222
|
+
"Failed to compose channel and call credentials");
|
223
|
+
}
|
224
|
+
}
|
225
|
+
return grpc_rb_wrap_channel_credentials(creds, mark);
|
226
|
+
}
|
227
|
+
|
228
|
+
static grpc_ssl_roots_override_result get_ssl_roots_override(
|
229
|
+
char** pem_root_certs_ptr) {
|
230
|
+
*pem_root_certs_ptr = pem_root_certs;
|
231
|
+
if (pem_root_certs == NULL) {
|
232
|
+
return GRPC_SSL_ROOTS_OVERRIDE_FAIL;
|
233
|
+
} else {
|
234
|
+
return GRPC_SSL_ROOTS_OVERRIDE_OK;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
static VALUE grpc_rb_set_default_roots_pem(VALUE self, VALUE roots) {
|
239
|
+
char* roots_ptr = StringValueCStr(roots);
|
240
|
+
size_t length = strlen(roots_ptr);
|
241
|
+
(void)self;
|
242
|
+
pem_root_certs = gpr_malloc((length + 1) * sizeof(char));
|
243
|
+
memcpy(pem_root_certs, roots_ptr, length + 1);
|
244
|
+
return Qnil;
|
245
|
+
}
|
246
|
+
|
247
|
+
void Init_grpc_channel_credentials() {
|
248
|
+
grpc_rb_cChannelCredentials = rb_define_class_under(
|
249
|
+
grpc_rb_mGrpcCore, "ChannelCredentials", rb_cObject);
|
250
|
+
|
251
|
+
/* Allocates an object managed by the ruby runtime */
|
252
|
+
rb_define_alloc_func(grpc_rb_cChannelCredentials,
|
253
|
+
grpc_rb_channel_credentials_alloc);
|
254
|
+
|
255
|
+
/* Provides a ruby constructor and support for dup/clone. */
|
256
|
+
rb_define_method(grpc_rb_cChannelCredentials, "initialize",
|
257
|
+
grpc_rb_channel_credentials_init, -1);
|
258
|
+
rb_define_method(grpc_rb_cChannelCredentials, "initialize_copy",
|
259
|
+
grpc_rb_cannot_init_copy, 1);
|
260
|
+
rb_define_method(grpc_rb_cChannelCredentials, "compose",
|
261
|
+
grpc_rb_channel_credentials_compose, -1);
|
262
|
+
rb_define_module_function(grpc_rb_cChannelCredentials,
|
263
|
+
"set_default_roots_pem",
|
264
|
+
grpc_rb_set_default_roots_pem, 1);
|
265
|
+
|
266
|
+
grpc_set_ssl_roots_override_callback(get_ssl_roots_override);
|
267
|
+
|
268
|
+
id_pem_cert_chain = rb_intern("__pem_cert_chain");
|
269
|
+
id_pem_private_key = rb_intern("__pem_private_key");
|
270
|
+
id_pem_root_certs = rb_intern("__pem_root_certs");
|
271
|
+
}
|
272
|
+
|
273
|
+
/* Gets the wrapped grpc_channel_credentials from the ruby wrapper */
|
274
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_channel_credentials(VALUE v) {
|
275
|
+
grpc_rb_channel_credentials* wrapper = NULL;
|
276
|
+
Check_TypedStruct(v, &grpc_rb_channel_credentials_data_type);
|
277
|
+
TypedData_Get_Struct(v, grpc_rb_channel_credentials,
|
278
|
+
&grpc_rb_channel_credentials_data_type, wrapper);
|
279
|
+
return wrapper->wrapped;
|
280
|
+
}
|
281
|
+
|
282
|
+
/* Check if v is kind of ChannelCredentials */
|
283
|
+
bool grpc_rb_is_channel_credentials(VALUE v) {
|
284
|
+
return rb_typeddata_is_kind_of(v, &grpc_rb_channel_credentials_data_type);
|
285
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_RB_CREDENTIALS_H_
|
20
|
+
#define GRPC_RB_CREDENTIALS_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc_security.h>
|
25
|
+
#include <stdbool.h>
|
26
|
+
|
27
|
+
/* Initializes the ruby ChannelCredentials class. */
|
28
|
+
void Init_grpc_channel_credentials();
|
29
|
+
|
30
|
+
/* Gets the wrapped credentials from the ruby wrapper */
|
31
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_channel_credentials(VALUE v);
|
32
|
+
|
33
|
+
/* Check if v is kind of ChannelCredentials */
|
34
|
+
bool grpc_rb_is_channel_credentials(VALUE v);
|
35
|
+
|
36
|
+
#endif /* GRPC_RB_CREDENTIALS_H_ */
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby/ruby.h>
|
20
|
+
|
21
|
+
#include "rb_completion_queue.h"
|
22
|
+
|
23
|
+
#include <grpc/grpc.h>
|
24
|
+
#include <grpc/support/log.h>
|
25
|
+
#include <grpc/support/time.h>
|
26
|
+
#include <ruby/thread.h>
|
27
|
+
|
28
|
+
#include "rb_grpc.h"
|
29
|
+
#include "rb_grpc_imports.generated.h"
|
30
|
+
|
31
|
+
/* Used to allow grpc_completion_queue_next call to release the GIL */
|
32
|
+
typedef struct next_call_stack {
|
33
|
+
grpc_completion_queue* cq;
|
34
|
+
grpc_event event;
|
35
|
+
gpr_timespec timeout;
|
36
|
+
void* tag;
|
37
|
+
volatile int interrupted;
|
38
|
+
} next_call_stack;
|
39
|
+
|
40
|
+
/* Calls grpc_completion_queue_pluck without holding the ruby GIL */
|
41
|
+
static void* grpc_rb_completion_queue_pluck_no_gil(void* param) {
|
42
|
+
next_call_stack* const next_call = (next_call_stack*)param;
|
43
|
+
gpr_timespec increment = gpr_time_from_millis(200, GPR_TIMESPAN);
|
44
|
+
gpr_timespec deadline;
|
45
|
+
for (;;) {
|
46
|
+
deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), increment);
|
47
|
+
next_call->event = grpc_completion_queue_pluck(
|
48
|
+
next_call->cq, next_call->tag, deadline, NULL);
|
49
|
+
if (next_call->event.type != GRPC_QUEUE_TIMEOUT) break;
|
50
|
+
if (gpr_time_cmp(deadline, next_call->timeout) > 0) break;
|
51
|
+
if (next_call->interrupted) break;
|
52
|
+
}
|
53
|
+
return NULL;
|
54
|
+
}
|
55
|
+
|
56
|
+
/* Helper function to free a completion queue. */
|
57
|
+
void grpc_rb_completion_queue_destroy(grpc_completion_queue* cq) {
|
58
|
+
/* Every function that adds an event to a queue also synchronously plucks
|
59
|
+
that event from the queue, and holds a reference to the Ruby object that
|
60
|
+
holds the queue, so we only get to this point if all of those functions
|
61
|
+
have completed, and the queue is empty */
|
62
|
+
grpc_completion_queue_shutdown(cq);
|
63
|
+
grpc_completion_queue_destroy(cq);
|
64
|
+
}
|
65
|
+
|
66
|
+
static void unblock_func(void* param) {
|
67
|
+
next_call_stack* const next_call = (next_call_stack*)param;
|
68
|
+
next_call->interrupted = 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
/* Does the same thing as grpc_completion_queue_pluck, while properly releasing
|
72
|
+
the GVL and handling interrupts */
|
73
|
+
grpc_event rb_completion_queue_pluck(grpc_completion_queue* queue, void* tag,
|
74
|
+
gpr_timespec deadline,
|
75
|
+
const char* reason) {
|
76
|
+
next_call_stack next_call;
|
77
|
+
MEMZERO(&next_call, next_call_stack, 1);
|
78
|
+
next_call.cq = queue;
|
79
|
+
next_call.timeout = deadline;
|
80
|
+
next_call.tag = tag;
|
81
|
+
next_call.event.type = GRPC_QUEUE_TIMEOUT;
|
82
|
+
/* Loop until we finish a pluck without an interruption. See
|
83
|
+
* https://github.com/grpc/grpc/issues/38210 for an example of why
|
84
|
+
* this is necessary. */
|
85
|
+
grpc_absl_log_str(GPR_DEBUG, "CQ pluck loop begin: ", reason);
|
86
|
+
do {
|
87
|
+
next_call.interrupted = 0;
|
88
|
+
rb_thread_call_without_gvl(grpc_rb_completion_queue_pluck_no_gil,
|
89
|
+
(void*)&next_call, unblock_func,
|
90
|
+
(void*)&next_call);
|
91
|
+
if (next_call.event.type != GRPC_QUEUE_TIMEOUT) break;
|
92
|
+
} while (next_call.interrupted);
|
93
|
+
grpc_absl_log_str(GPR_DEBUG, "CQ pluck loop done: ", reason);
|
94
|
+
return next_call.event;
|
95
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_RB_COMPLETION_QUEUE_H_
|
20
|
+
#define GRPC_RB_COMPLETION_QUEUE_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
void grpc_rb_completion_queue_destroy(grpc_completion_queue* cq);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Makes the implementation of CompletionQueue#pluck available in other files
|
30
|
+
*
|
31
|
+
* This avoids having code that holds the GIL repeated at multiple sites.
|
32
|
+
*/
|
33
|
+
grpc_event rb_completion_queue_pluck(grpc_completion_queue* queue, void* tag,
|
34
|
+
gpr_timespec deadline, const char* reason);
|
35
|
+
|
36
|
+
#endif /* GRPC_RB_COMPLETION_QUEUE_H_ */
|