grpc 1.60.0.pre1-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-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 +40 -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 +270 -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 +340 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +875 -0
- data/src/ruby/ext/grpc/rb_channel.h +35 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +172 -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 +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -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 +161 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +496 -0
- data/src/ruby/ext/grpc/rb_grpc.h +83 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +603 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +910 -0
- data/src/ruby/ext/grpc/rb_loader.c +61 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +405 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -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 +37 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -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/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 +670 -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 +44 -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 +42 -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 +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +71 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -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 +180 -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 +207 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +676 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -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 +692 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -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 +748 -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/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 +160 -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 +405 -0
@@ -0,0 +1,35 @@
|
|
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_CHANNEL_H_
|
20
|
+
#define GRPC_RB_CHANNEL_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
/* Initializes the Channel class. */
|
27
|
+
void Init_grpc_channel();
|
28
|
+
|
29
|
+
void grpc_rb_channel_polling_thread_start();
|
30
|
+
void grpc_rb_channel_polling_thread_stop();
|
31
|
+
|
32
|
+
/* Gets the wrapped channel from the ruby wrapper */
|
33
|
+
grpc_channel* grpc_rb_get_wrapped_channel(VALUE v);
|
34
|
+
|
35
|
+
#endif /* GRPC_RB_CHANNEL_H_ */
|
@@ -0,0 +1,172 @@
|
|
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_args.h"
|
22
|
+
|
23
|
+
#include "rb_grpc.h"
|
24
|
+
#include "rb_grpc_imports.generated.h"
|
25
|
+
|
26
|
+
#include <grpc/grpc.h>
|
27
|
+
#include <grpc/support/alloc.h>
|
28
|
+
#include <grpc/support/log.h>
|
29
|
+
#include <grpc/support/string_util.h>
|
30
|
+
|
31
|
+
static rb_data_type_t grpc_rb_channel_args_data_type = {
|
32
|
+
"grpc_channel_args",
|
33
|
+
{GRPC_RB_GC_NOT_MARKED,
|
34
|
+
GRPC_RB_GC_DONT_FREE,
|
35
|
+
GRPC_RB_MEMSIZE_UNAVAILABLE,
|
36
|
+
{NULL, NULL}},
|
37
|
+
NULL,
|
38
|
+
NULL,
|
39
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
40
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
41
|
+
#endif
|
42
|
+
};
|
43
|
+
|
44
|
+
/* A callback the processes the hash key values in channel_args hash */
|
45
|
+
static int grpc_rb_channel_create_in_process_add_args_hash_cb(VALUE key,
|
46
|
+
VALUE val,
|
47
|
+
VALUE args_obj) {
|
48
|
+
const char* the_key;
|
49
|
+
grpc_channel_args* args;
|
50
|
+
|
51
|
+
switch (TYPE(key)) {
|
52
|
+
case T_STRING:
|
53
|
+
the_key = StringValuePtr(key);
|
54
|
+
break;
|
55
|
+
|
56
|
+
case T_SYMBOL:
|
57
|
+
the_key = rb_id2name(SYM2ID(key));
|
58
|
+
break;
|
59
|
+
|
60
|
+
default:
|
61
|
+
rb_raise(rb_eTypeError, "bad chan arg: got <%s>, want <String|Symbol>",
|
62
|
+
rb_obj_classname(key));
|
63
|
+
return ST_STOP;
|
64
|
+
}
|
65
|
+
|
66
|
+
TypedData_Get_Struct(args_obj, grpc_channel_args,
|
67
|
+
&grpc_rb_channel_args_data_type, args);
|
68
|
+
if (args->num_args <= 0) {
|
69
|
+
rb_raise(rb_eRuntimeError, "hash_cb bug: num_args is %lu for key:%s",
|
70
|
+
args->num_args, StringValueCStr(key));
|
71
|
+
return ST_STOP;
|
72
|
+
}
|
73
|
+
|
74
|
+
args->args[args->num_args - 1].key = (char*)the_key;
|
75
|
+
switch (TYPE(val)) {
|
76
|
+
case T_SYMBOL:
|
77
|
+
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
|
78
|
+
args->args[args->num_args - 1].value.string =
|
79
|
+
gpr_strdup(rb_id2name(SYM2ID(val)));
|
80
|
+
--args->num_args;
|
81
|
+
return ST_CONTINUE;
|
82
|
+
|
83
|
+
case T_STRING:
|
84
|
+
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
|
85
|
+
args->args[args->num_args - 1].value.string =
|
86
|
+
gpr_strdup(StringValueCStr(val));
|
87
|
+
--args->num_args;
|
88
|
+
return ST_CONTINUE;
|
89
|
+
|
90
|
+
case T_FIXNUM:
|
91
|
+
args->args[args->num_args - 1].type = GRPC_ARG_INTEGER;
|
92
|
+
args->args[args->num_args - 1].value.integer = NUM2INT(val);
|
93
|
+
--args->num_args;
|
94
|
+
return ST_CONTINUE;
|
95
|
+
|
96
|
+
default:
|
97
|
+
rb_raise(rb_eTypeError, "%s: bad value: got <%s>, want <String|Fixnum>",
|
98
|
+
StringValueCStr(key), rb_obj_classname(val));
|
99
|
+
return ST_STOP;
|
100
|
+
}
|
101
|
+
rb_raise(rb_eRuntimeError, "impl bug: hash_cb reached to far while on key:%s",
|
102
|
+
StringValueCStr(key));
|
103
|
+
return ST_STOP;
|
104
|
+
}
|
105
|
+
|
106
|
+
/* channel_convert_params allows the call to
|
107
|
+
grpc_rb_hash_convert_to_channel_args to be made within an rb_protect
|
108
|
+
exception-handler. This allows any allocated memory to be freed before
|
109
|
+
propagating any exception that occurs */
|
110
|
+
typedef struct channel_convert_params {
|
111
|
+
VALUE src_hash;
|
112
|
+
grpc_channel_args* dst;
|
113
|
+
} channel_convert_params;
|
114
|
+
|
115
|
+
static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
|
116
|
+
ID id_size = rb_intern("size");
|
117
|
+
VALUE grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
|
118
|
+
rb_undef_alloc_func(grpc_rb_cChannelArgs);
|
119
|
+
channel_convert_params* params = (channel_convert_params*)as_value;
|
120
|
+
size_t num_args = 0;
|
121
|
+
|
122
|
+
if (!NIL_P(params->src_hash) && TYPE(params->src_hash) != T_HASH) {
|
123
|
+
rb_raise(rb_eTypeError, "bad channel args: got:<%s> want: a hash or nil",
|
124
|
+
rb_obj_classname(params->src_hash));
|
125
|
+
return Qnil;
|
126
|
+
}
|
127
|
+
|
128
|
+
if (TYPE(params->src_hash) == T_HASH) {
|
129
|
+
num_args = NUM2INT(rb_funcall(params->src_hash, id_size, 0));
|
130
|
+
params->dst->num_args = num_args;
|
131
|
+
params->dst->args = ALLOC_N(grpc_arg, num_args);
|
132
|
+
MEMZERO(params->dst->args, grpc_arg, num_args);
|
133
|
+
rb_hash_foreach(
|
134
|
+
params->src_hash, grpc_rb_channel_create_in_process_add_args_hash_cb,
|
135
|
+
TypedData_Wrap_Struct(grpc_rb_cChannelArgs,
|
136
|
+
&grpc_rb_channel_args_data_type, params->dst));
|
137
|
+
/* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
|
138
|
+
* decrements it during has processing */
|
139
|
+
params->dst->num_args = num_args;
|
140
|
+
}
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
|
144
|
+
void grpc_rb_hash_convert_to_channel_args(VALUE src_hash,
|
145
|
+
grpc_channel_args* dst) {
|
146
|
+
channel_convert_params params;
|
147
|
+
int status = 0;
|
148
|
+
|
149
|
+
/* Make a protected call to grpc_rb_hash_convert_channel_args */
|
150
|
+
params.src_hash = src_hash;
|
151
|
+
params.dst = dst;
|
152
|
+
rb_protect(grpc_rb_hash_convert_to_channel_args0, (VALUE)¶ms, &status);
|
153
|
+
if (status != 0) {
|
154
|
+
if (dst->args != NULL) {
|
155
|
+
/* Free any allocated memory before propagating the error */
|
156
|
+
xfree(dst->args);
|
157
|
+
}
|
158
|
+
rb_jump_tag(status);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
void grpc_rb_channel_args_destroy(grpc_channel_args* args) {
|
163
|
+
GPR_ASSERT(args != NULL);
|
164
|
+
if (args->args == NULL) return;
|
165
|
+
for (int i = 0; i < args->num_args; i++) {
|
166
|
+
if (args->args[i].type == GRPC_ARG_STRING) {
|
167
|
+
// we own string pointers, which were created with gpr_strdup
|
168
|
+
gpr_free(args->args[i].value.string);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
xfree(args->args);
|
172
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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_CHANNEL_ARGS_H_
|
20
|
+
#define GRPC_RB_CHANNEL_ARGS_H_
|
21
|
+
|
22
|
+
#include <ruby/ruby.h>
|
23
|
+
|
24
|
+
#include <grpc/grpc.h>
|
25
|
+
|
26
|
+
/* Converts a hash object containing channel args to a channel args instance.
|
27
|
+
*
|
28
|
+
* This func ALLOCs args->args. The caller is responsible for freeing it. If
|
29
|
+
* a ruby error is raised during processing of the hash values, the func takes
|
30
|
+
* care to deallocate any memory allocated so far, and propagate the error.
|
31
|
+
*
|
32
|
+
* @param src_hash A ruby hash
|
33
|
+
* @param dst the grpc_channel_args that the hash entries will be added to.
|
34
|
+
*/
|
35
|
+
void grpc_rb_hash_convert_to_channel_args(VALUE src_hash,
|
36
|
+
grpc_channel_args* dst);
|
37
|
+
|
38
|
+
/* Destroys inner fields of args (does not deallocate the args pointer itself)
|
39
|
+
*/
|
40
|
+
void grpc_rb_channel_args_destroy(grpc_channel_args* args);
|
41
|
+
|
42
|
+
#endif /* GRPC_RB_CHANNEL_ARGS_H_ */
|
@@ -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 <string.h>
|
24
|
+
|
25
|
+
#include "rb_call_credentials.h"
|
26
|
+
#include "rb_grpc.h"
|
27
|
+
#include "rb_grpc_imports.generated.h"
|
28
|
+
|
29
|
+
#include <grpc/grpc.h>
|
30
|
+
#include <grpc/grpc_security.h>
|
31
|
+
#include <grpc/support/alloc.h>
|
32
|
+
#include <grpc/support/log.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,37 @@
|
|
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 <stdbool.h>
|
25
|
+
|
26
|
+
#include <grpc/grpc_security.h>
|
27
|
+
|
28
|
+
/* Initializes the ruby ChannelCredentials class. */
|
29
|
+
void Init_grpc_channel_credentials();
|
30
|
+
|
31
|
+
/* Gets the wrapped credentials from the ruby wrapper */
|
32
|
+
grpc_channel_credentials* grpc_rb_get_wrapped_channel_credentials(VALUE v);
|
33
|
+
|
34
|
+
/* Check if v is kind of ChannelCredentials */
|
35
|
+
bool grpc_rb_is_channel_credentials(VALUE v);
|
36
|
+
|
37
|
+
#endif /* GRPC_RB_CREDENTIALS_H_ */
|
@@ -0,0 +1,101 @@
|
|
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 <ruby/thread.h>
|
24
|
+
|
25
|
+
#include "rb_grpc.h"
|
26
|
+
#include "rb_grpc_imports.generated.h"
|
27
|
+
|
28
|
+
#include <grpc/grpc.h>
|
29
|
+
#include <grpc/support/log.h>
|
30
|
+
#include <grpc/support/time.h>
|
31
|
+
|
32
|
+
/* Used to allow grpc_completion_queue_next call to release the GIL */
|
33
|
+
typedef struct next_call_stack {
|
34
|
+
grpc_completion_queue* cq;
|
35
|
+
grpc_event event;
|
36
|
+
gpr_timespec timeout;
|
37
|
+
void* tag;
|
38
|
+
volatile int interrupted;
|
39
|
+
} next_call_stack;
|
40
|
+
|
41
|
+
/* Calls grpc_completion_queue_pluck without holding the ruby GIL */
|
42
|
+
static void* grpc_rb_completion_queue_pluck_no_gil(void* param) {
|
43
|
+
next_call_stack* const next_call = (next_call_stack*)param;
|
44
|
+
gpr_timespec increment = gpr_time_from_millis(20, GPR_TIMESPAN);
|
45
|
+
gpr_timespec deadline;
|
46
|
+
do {
|
47
|
+
deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), increment);
|
48
|
+
next_call->event = grpc_completion_queue_pluck(
|
49
|
+
next_call->cq, next_call->tag, deadline, NULL);
|
50
|
+
if (next_call->event.type != GRPC_QUEUE_TIMEOUT ||
|
51
|
+
gpr_time_cmp(deadline, next_call->timeout) > 0) {
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
} while (!next_call->interrupted);
|
55
|
+
return NULL;
|
56
|
+
}
|
57
|
+
|
58
|
+
/* Helper function to free a completion queue. */
|
59
|
+
void grpc_rb_completion_queue_destroy(grpc_completion_queue* cq) {
|
60
|
+
/* Every function that adds an event to a queue also synchronously plucks
|
61
|
+
that event from the queue, and holds a reference to the Ruby object that
|
62
|
+
holds the queue, so we only get to this point if all of those functions
|
63
|
+
have completed, and the queue is empty */
|
64
|
+
grpc_completion_queue_shutdown(cq);
|
65
|
+
grpc_completion_queue_destroy(cq);
|
66
|
+
}
|
67
|
+
|
68
|
+
static void unblock_func(void* param) {
|
69
|
+
next_call_stack* const next_call = (next_call_stack*)param;
|
70
|
+
next_call->interrupted = 1;
|
71
|
+
}
|
72
|
+
|
73
|
+
/* Does the same thing as grpc_completion_queue_pluck, while properly releasing
|
74
|
+
the GVL and handling interrupts */
|
75
|
+
grpc_event rb_completion_queue_pluck(grpc_completion_queue* queue, void* tag,
|
76
|
+
gpr_timespec deadline, void* reserved) {
|
77
|
+
next_call_stack next_call;
|
78
|
+
MEMZERO(&next_call, next_call_stack, 1);
|
79
|
+
next_call.cq = queue;
|
80
|
+
next_call.timeout = deadline;
|
81
|
+
next_call.tag = tag;
|
82
|
+
next_call.event.type = GRPC_QUEUE_TIMEOUT;
|
83
|
+
(void)reserved;
|
84
|
+
/* Loop until we finish a pluck without an interruption. The internal
|
85
|
+
pluck function runs either until it is interrupted or it gets an
|
86
|
+
event, or time runs out.
|
87
|
+
|
88
|
+
The basic reason we need this relatively complicated construction is that
|
89
|
+
we need to re-acquire the GVL when an interrupt comes in, so that the ruby
|
90
|
+
interpreter can do what it needs to do with the interrupt. But we also need
|
91
|
+
to get back to plucking when the interrupt has been handled. */
|
92
|
+
do {
|
93
|
+
next_call.interrupted = 0;
|
94
|
+
rb_thread_call_without_gvl(grpc_rb_completion_queue_pluck_no_gil,
|
95
|
+
(void*)&next_call, unblock_func,
|
96
|
+
(void*)&next_call);
|
97
|
+
/* If an interrupt prevented pluck from returning useful information, then
|
98
|
+
any plucks that did complete must have timed out */
|
99
|
+
} while (next_call.interrupted && next_call.event.type == GRPC_QUEUE_TIMEOUT);
|
100
|
+
return next_call.event;
|
101
|
+
}
|