• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from libcpp.string cimport string
16
17cimport libc.time
18
19ctypedef          ssize_t   intptr_t
20ctypedef          size_t    uintptr_t
21ctypedef   signed char      int8_t
22ctypedef   signed short     int16_t
23ctypedef   signed int       int32_t
24ctypedef   signed long long int64_t
25ctypedef unsigned char      uint8_t
26ctypedef unsigned short     uint16_t
27ctypedef unsigned int       uint32_t
28ctypedef unsigned long long uint64_t
29
30# C++ Utilities
31
32# NOTE(lidiz) Unfortunately, we can't use "cimport" here because Cython
33# links it with exception handling. It introduces new dependencies.
34cdef extern from "<queue>" namespace "std" nogil:
35    cdef cppclass queue[T]:
36        queue()
37        bint empty()
38        T& front()
39        T& back()
40        void pop()
41        void push(T&)
42        size_t size()
43
44
45cdef extern from "<mutex>" namespace "std" nogil:
46    cdef cppclass mutex:
47        mutex()
48        void lock()
49        void unlock()
50
51    cdef cppclass unique_lock[Mutex]:
52      unique_lock(Mutex&)
53
54cdef extern from "<condition_variable>" namespace "std" nogil:
55  cdef cppclass condition_variable:
56    condition_variable()
57    void notify_all()
58    void wait(unique_lock[mutex]&)
59
60# gRPC Core Declarations
61
62cdef extern from "src/core/lib/channel/call_tracer.h" namespace "grpc_core":
63    cdef cppclass ClientCallTracer:
64        pass
65
66    cdef cppclass ServerCallTracer:
67        string TraceId() nogil
68        string SpanId() nogil
69        bint IsSampled() nogil
70
71    cdef cppclass ServerCallTracerFactory:
72        @staticmethod
73        void RegisterGlobal(ServerCallTracerFactory* factory) nogil
74
75cdef extern from "src/core/lib/channel/context.h":
76  ctypedef enum grpc_context_index:
77    GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE
78
79cdef extern from "src/core/lib/surface/call.h":
80  void grpc_call_context_set(grpc_call* call, grpc_context_index elem,
81                             void* value, void (*destroy)(void* value)) nogil
82  void *grpc_call_context_get(grpc_call* call, grpc_context_index elem) nogil
83
84cdef extern from "grpc/support/alloc.h":
85
86  void *gpr_malloc(size_t size) nogil
87  void *gpr_zalloc(size_t size) nogil
88  void gpr_free(void *ptr) nogil
89  void *gpr_realloc(void *p, size_t size) nogil
90
91
92cdef extern from "grpc/byte_buffer_reader.h":
93
94  struct grpc_byte_buffer_reader:
95    # We don't care about the internals
96    pass
97
98
99cdef extern from "grpc/impl/codegen/grpc_types.h":
100    ctypedef struct grpc_completion_queue_functor:
101        void (*functor_run)(grpc_completion_queue_functor*, int);
102
103
104cdef extern from "grpc/grpc.h":
105
106  ctypedef struct grpc_slice:
107    # don't worry about writing out the members of grpc_slice; we never access
108    # them directly.
109    pass
110
111  grpc_slice grpc_slice_ref(grpc_slice s) nogil
112  void grpc_slice_unref(grpc_slice s) nogil
113  grpc_slice grpc_empty_slice() nogil
114  grpc_slice grpc_slice_new(void *p, size_t len, void (*destroy)(void *)) nogil
115  grpc_slice grpc_slice_new_with_len(
116      void *p, size_t len, void (*destroy)(void *, size_t)) nogil
117  grpc_slice grpc_slice_malloc(size_t length) nogil
118  grpc_slice grpc_slice_from_copied_string(const char *source) nogil
119  grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len) nogil
120  grpc_slice grpc_slice_copy(grpc_slice s) nogil
121
122  # Declare functions for function-like macros (because Cython)...
123  void *grpc_slice_start_ptr "GRPC_SLICE_START_PTR" (grpc_slice s) nogil
124  size_t grpc_slice_length "GRPC_SLICE_LENGTH" (grpc_slice s) nogil
125
126  const int GPR_MS_PER_SEC
127  const int GPR_US_PER_SEC
128  const int GPR_NS_PER_SEC
129
130  ctypedef enum gpr_clock_type:
131    GPR_CLOCK_MONOTONIC
132    GPR_CLOCK_REALTIME
133    GPR_CLOCK_PRECISE
134    GPR_TIMESPAN
135
136  ctypedef struct gpr_timespec:
137    int64_t seconds "tv_sec"
138    int32_t nanoseconds "tv_nsec"
139    gpr_clock_type clock_type
140
141  gpr_timespec gpr_time_0(gpr_clock_type type) nogil
142  gpr_timespec gpr_inf_future(gpr_clock_type type) nogil
143  gpr_timespec gpr_inf_past(gpr_clock_type type) nogil
144
145  gpr_timespec gpr_now(gpr_clock_type clock) nogil
146
147  gpr_timespec gpr_convert_clock_type(gpr_timespec t,
148                                      gpr_clock_type target_clock) nogil
149
150  gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type type) nogil
151  gpr_timespec gpr_time_from_nanos(int64_t ns, gpr_clock_type type) nogil
152  double gpr_timespec_to_micros(gpr_timespec t) nogil
153
154  gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) nogil
155
156  int gpr_time_cmp(gpr_timespec a, gpr_timespec b) nogil
157
158  ctypedef struct grpc_byte_buffer:
159    # We don't care about the internals.
160    pass
161
162  grpc_byte_buffer *grpc_raw_byte_buffer_create(grpc_slice *slices,
163                                                size_t nslices) nogil
164  size_t grpc_byte_buffer_length(grpc_byte_buffer *bb) nogil
165  void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer) nogil
166
167  int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader,
168                                   grpc_byte_buffer *buffer) nogil
169  int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader,
170                                   grpc_slice *slice) nogil
171  void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader) nogil
172
173  ctypedef enum grpc_status_code:
174    GRPC_STATUS_OK
175    GRPC_STATUS_CANCELLED
176    GRPC_STATUS_UNKNOWN
177    GRPC_STATUS_INVALID_ARGUMENT
178    GRPC_STATUS_DEADLINE_EXCEEDED
179    GRPC_STATUS_NOT_FOUND
180    GRPC_STATUS_ALREADY_EXISTS
181    GRPC_STATUS_PERMISSION_DENIED
182    GRPC_STATUS_UNAUTHENTICATED
183    GRPC_STATUS_RESOURCE_EXHAUSTED
184    GRPC_STATUS_FAILED_PRECONDITION
185    GRPC_STATUS_ABORTED
186    GRPC_STATUS_OUT_OF_RANGE
187    GRPC_STATUS_UNIMPLEMENTED
188    GRPC_STATUS_INTERNAL
189    GRPC_STATUS_UNAVAILABLE
190    GRPC_STATUS_DATA_LOSS
191    GRPC_STATUS__DO_NOT_USE
192
193  const char *GRPC_ARG_ENABLE_CENSUS
194  const char *GRPC_ARG_MAX_CONCURRENT_STREAMS
195  const char *GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH
196  const char *GRPC_ARG_MAX_SEND_MESSAGE_LENGTH
197  const char *GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER
198  const char *GRPC_ARG_DEFAULT_AUTHORITY
199  const char *GRPC_ARG_PRIMARY_USER_AGENT_STRING
200  const char *GRPC_ARG_SECONDARY_USER_AGENT_STRING
201  const char *GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
202  const char *GRPC_SSL_SESSION_CACHE_ARG
203  const char *_GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \
204    "GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM"
205  const char *GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL
206  const char *GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET
207
208  const int GRPC_WRITE_BUFFER_HINT
209  const int GRPC_WRITE_NO_COMPRESS
210  const int GRPC_WRITE_USED_MASK
211
212  const int GRPC_INITIAL_METADATA_WAIT_FOR_READY
213  const int GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET
214  const int GRPC_INITIAL_METADATA_USED_MASK
215
216  const int GRPC_MAX_COMPLETION_QUEUE_PLUCKERS
217
218  ctypedef struct grpc_completion_queue:
219    # We don't care about the internals (and in fact don't know them)
220    pass
221
222  ctypedef struct grpc_channel:
223    # We don't care about the internals (and in fact don't know them)
224    pass
225
226  ctypedef struct grpc_server:
227    # We don't care about the internals (and in fact don't know them)
228    pass
229
230  ctypedef struct grpc_call:
231    # We don't care about the internals (and in fact don't know them)
232    pass
233
234  ctypedef enum grpc_arg_type:
235    GRPC_ARG_STRING
236    GRPC_ARG_INTEGER
237    GRPC_ARG_POINTER
238
239  ctypedef struct grpc_arg_pointer_vtable:
240    void *(*copy)(void *)
241    void (*destroy)(void *)
242    int (*cmp)(void *, void *)
243
244  ctypedef struct grpc_arg_value_pointer:
245    void *address "p"
246    grpc_arg_pointer_vtable *vtable
247
248  union grpc_arg_value:
249    char *string
250    int integer
251    grpc_arg_value_pointer pointer
252
253  ctypedef struct grpc_arg:
254    grpc_arg_type type
255    char *key
256    grpc_arg_value value
257
258  ctypedef struct grpc_channel_args:
259    size_t arguments_length "num_args"
260    grpc_arg *arguments "args"
261
262  ctypedef enum grpc_stream_compression_level:
263    GRPC_STREAM_COMPRESS_LEVEL_NONE
264    GRPC_STREAM_COMPRESS_LEVEL_LOW
265    GRPC_STREAM_COMPRESS_LEVEL_MED
266    GRPC_STREAM_COMPRESS_LEVEL_HIGH
267
268  ctypedef enum grpc_call_error:
269    GRPC_CALL_OK
270    GRPC_CALL_ERROR
271    GRPC_CALL_ERROR_NOT_ON_SERVER
272    GRPC_CALL_ERROR_NOT_ON_CLIENT
273    GRPC_CALL_ERROR_ALREADY_ACCEPTED
274    GRPC_CALL_ERROR_ALREADY_INVOKED
275    GRPC_CALL_ERROR_NOT_INVOKED
276    GRPC_CALL_ERROR_ALREADY_FINISHED
277    GRPC_CALL_ERROR_TOO_MANY_OPERATIONS
278    GRPC_CALL_ERROR_INVALID_FLAGS
279    GRPC_CALL_ERROR_INVALID_METADATA
280
281  ctypedef enum grpc_cq_completion_type:
282    GRPC_CQ_NEXT
283    GRPC_CQ_PLUCK
284
285  ctypedef enum grpc_cq_polling_type:
286    GRPC_CQ_DEFAULT_POLLING
287    GRPC_CQ_NON_LISTENING
288    GRPC_CQ_NON_POLLING
289
290  ctypedef struct grpc_completion_queue_attributes:
291    int version
292    grpc_cq_completion_type cq_completion_type
293    grpc_cq_polling_type cq_polling_type
294    void* cq_shutdown_cb
295
296  ctypedef enum grpc_connectivity_state:
297    GRPC_CHANNEL_IDLE
298    GRPC_CHANNEL_CONNECTING
299    GRPC_CHANNEL_READY
300    GRPC_CHANNEL_TRANSIENT_FAILURE
301    GRPC_CHANNEL_SHUTDOWN
302
303  ctypedef struct grpc_metadata:
304    grpc_slice key
305    grpc_slice value
306    # ignore the 'internal_data.obfuscated' fields.
307
308  ctypedef enum grpc_completion_type:
309    GRPC_QUEUE_SHUTDOWN
310    GRPC_QUEUE_TIMEOUT
311    GRPC_OP_COMPLETE
312
313  ctypedef struct grpc_event:
314    grpc_completion_type type
315    int success
316    void *tag
317
318  ctypedef struct grpc_metadata_array:
319    size_t count
320    size_t capacity
321    grpc_metadata *metadata
322
323  void grpc_metadata_array_init(grpc_metadata_array *array) nogil
324  void grpc_metadata_array_destroy(grpc_metadata_array *array) nogil
325
326  ctypedef struct grpc_call_details:
327    grpc_slice method
328    grpc_slice host
329    gpr_timespec deadline
330
331  void grpc_call_details_init(grpc_call_details *details) nogil
332  void grpc_call_details_destroy(grpc_call_details *details) nogil
333
334  ctypedef enum grpc_op_type:
335    GRPC_OP_SEND_INITIAL_METADATA
336    GRPC_OP_SEND_MESSAGE
337    GRPC_OP_SEND_CLOSE_FROM_CLIENT
338    GRPC_OP_SEND_STATUS_FROM_SERVER
339    GRPC_OP_RECV_INITIAL_METADATA
340    GRPC_OP_RECV_MESSAGE
341    GRPC_OP_RECV_STATUS_ON_CLIENT
342    GRPC_OP_RECV_CLOSE_ON_SERVER
343
344  ctypedef struct grpc_op_send_initial_metadata_maybe_compression_level:
345    uint8_t is_set
346    grpc_compression_level level
347
348  ctypedef struct grpc_op_data_send_initial_metadata:
349    size_t count
350    grpc_metadata *metadata
351    grpc_op_send_initial_metadata_maybe_compression_level maybe_compression_level
352
353  ctypedef struct grpc_op_data_send_status_from_server:
354    size_t trailing_metadata_count
355    grpc_metadata *trailing_metadata
356    grpc_status_code status
357    grpc_slice *status_details
358
359  ctypedef struct grpc_op_data_recv_status_on_client:
360    grpc_metadata_array *trailing_metadata
361    grpc_status_code *status
362    grpc_slice *status_details
363    char** error_string
364
365  ctypedef struct grpc_op_data_recv_close_on_server:
366    int *cancelled
367
368  ctypedef struct grpc_op_data_send_message:
369    grpc_byte_buffer *send_message
370
371  ctypedef struct grpc_op_data_receive_message:
372    grpc_byte_buffer **receive_message "recv_message"
373
374  ctypedef struct grpc_op_data_receive_initial_metadata:
375    grpc_metadata_array *receive_initial_metadata "recv_initial_metadata"
376
377  union grpc_op_data:
378    grpc_op_data_send_initial_metadata send_initial_metadata
379    grpc_op_data_send_message send_message
380    grpc_op_data_send_status_from_server send_status_from_server
381    grpc_op_data_receive_initial_metadata receive_initial_metadata "recv_initial_metadata"
382    grpc_op_data_receive_message receive_message "recv_message"
383    grpc_op_data_recv_status_on_client receive_status_on_client "recv_status_on_client"
384    grpc_op_data_recv_close_on_server receive_close_on_server "recv_close_on_server"
385
386  ctypedef struct grpc_op:
387    grpc_op_type type "op"
388    uint32_t flags
389    void * reserved
390    grpc_op_data data
391
392  void grpc_init() nogil
393  void grpc_shutdown() nogil
394  void grpc_shutdown_blocking() nogil
395  int grpc_is_initialized() nogil
396
397  ctypedef struct grpc_completion_queue_factory:
398    pass
399
400  grpc_completion_queue_factory *grpc_completion_queue_factory_lookup(
401      const grpc_completion_queue_attributes* attributes) nogil
402  grpc_completion_queue *grpc_completion_queue_create(
403    const grpc_completion_queue_factory* factory,
404    const grpc_completion_queue_attributes* attr, void* reserved) nogil
405  grpc_completion_queue *grpc_completion_queue_create_for_next(void *reserved) nogil
406
407  grpc_event grpc_completion_queue_next(grpc_completion_queue *cq,
408                                        gpr_timespec deadline,
409                                        void *reserved) nogil
410  grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag,
411                                         gpr_timespec deadline,
412                                         void *reserved) nogil
413  void grpc_completion_queue_shutdown(grpc_completion_queue *cq) nogil
414  void grpc_completion_queue_destroy(grpc_completion_queue *cq) nogil
415
416  grpc_completion_queue *grpc_completion_queue_create_for_callback(
417    grpc_completion_queue_functor* shutdown_callback,
418    void *reserved) nogil
419
420  grpc_call_error grpc_call_start_batch(
421      grpc_call *call, const grpc_op *ops, size_t nops, void *tag,
422      void *reserved) nogil
423  const char* grpc_call_error_to_string(grpc_call_error error) nogil
424  grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) nogil
425  grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
426                                               grpc_status_code status,
427                                               const char *description,
428                                               void *reserved) nogil
429  char *grpc_call_get_peer(grpc_call *call) nogil
430  void grpc_call_unref(grpc_call *call) nogil
431
432  grpc_call *grpc_channel_create_call(
433    grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
434    grpc_completion_queue *completion_queue, grpc_slice method,
435    const grpc_slice *host, gpr_timespec deadline, void *reserved) nogil
436  void *grpc_channel_register_call(
437    grpc_channel *channel, const char *method, const char *host, void *reserved) nogil
438  grpc_call *grpc_channel_create_registered_call(
439    grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
440    grpc_completion_queue *completion_queue, void* registered_call_handle,
441    gpr_timespec deadline, void *reserved) nogil
442  grpc_connectivity_state grpc_channel_check_connectivity_state(
443      grpc_channel *channel, int try_to_connect) nogil
444  void grpc_channel_watch_connectivity_state(
445      grpc_channel *channel, grpc_connectivity_state last_observed_state,
446      gpr_timespec deadline, grpc_completion_queue *cq, void *tag) nogil
447  char *grpc_channel_get_target(grpc_channel *channel) nogil
448  void grpc_channel_destroy(grpc_channel *channel) nogil
449
450  grpc_server *grpc_server_create(
451      const grpc_channel_args *args, void *reserved) nogil
452  grpc_call_error grpc_server_request_call(
453      grpc_server *server, grpc_call **call, grpc_call_details *details,
454      grpc_metadata_array *request_metadata, grpc_completion_queue
455      *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void
456      *tag_new) nogil
457  void grpc_server_register_completion_queue(grpc_server *server,
458                                             grpc_completion_queue *cq,
459                                             void *reserved) nogil
460
461  ctypedef struct grpc_server_config_fetcher:
462    pass
463
464  void grpc_server_set_config_fetcher(
465       grpc_server* server, grpc_server_config_fetcher* config_fetcher) nogil
466
467  ctypedef struct grpc_server_xds_status_notifier:
468    void (*on_serving_status_update)(void* user_data, const char* uri,
469                                   grpc_status_code code,
470                                   const char* error_message)
471    void* user_data;
472
473  grpc_server_config_fetcher* grpc_server_config_fetcher_xds_create(
474       grpc_server_xds_status_notifier notifier,
475       const grpc_channel_args* args) nogil
476
477
478  void grpc_server_start(grpc_server *server) nogil
479  void grpc_server_shutdown_and_notify(
480      grpc_server *server, grpc_completion_queue *cq, void *tag) nogil
481  void grpc_server_cancel_all_calls(grpc_server *server) nogil
482  void grpc_server_destroy(grpc_server *server) nogil
483
484  char* grpc_channelz_get_top_channels(intptr_t start_channel_id)
485  char* grpc_channelz_get_servers(intptr_t start_server_id)
486  char* grpc_channelz_get_server(intptr_t server_id)
487  char* grpc_channelz_get_server_sockets(intptr_t server_id,
488                                         intptr_t start_socket_id,
489                                         intptr_t max_results)
490  char* grpc_channelz_get_channel(intptr_t channel_id)
491  char* grpc_channelz_get_subchannel(intptr_t subchannel_id)
492  char* grpc_channelz_get_socket(intptr_t socket_id)
493
494  grpc_slice grpc_dump_xds_configs() nogil
495
496
497cdef extern from "grpc/grpc_security.h":
498
499  # Declare this as an enum, this is the only way to make it a const in
500  # cython
501  enum: GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX
502
503  ctypedef enum grpc_ssl_roots_override_result:
504    GRPC_SSL_ROOTS_OVERRIDE_OK
505    GRPC_SSL_ROOTS_OVERRIDE_FAILED_PERMANENTLY
506    GRPC_SSL_ROOTS_OVERRIDE_FAILED
507
508  ctypedef enum grpc_ssl_client_certificate_request_type:
509    GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE,
510    GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
511    GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY
512    GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
513    GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
514
515  ctypedef enum grpc_security_level:
516    GRPC_SECURITY_MIN
517    GRPC_SECURITY_NONE = GRPC_SECURITY_MIN
518    GRPC_INTEGRITY_ONLY
519    GRPC_PRIVACY_AND_INTEGRITY
520    GRPC_SECURITY_MAX = GRPC_PRIVACY_AND_INTEGRITY
521
522  ctypedef enum grpc_ssl_certificate_config_reload_status:
523    GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED
524    GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_NEW
525    GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL
526
527  ctypedef struct grpc_ssl_server_certificate_config:
528    # We don't care about the internals
529    pass
530
531  ctypedef struct grpc_ssl_server_credentials_options:
532    # We don't care about the internals
533    pass
534
535  grpc_ssl_server_certificate_config * grpc_ssl_server_certificate_config_create(
536    const char *pem_root_certs,
537    const grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs,
538    size_t num_key_cert_pairs)
539
540  void grpc_ssl_server_certificate_config_destroy(grpc_ssl_server_certificate_config *config)
541
542  ctypedef grpc_ssl_certificate_config_reload_status (*grpc_ssl_server_certificate_config_callback)(
543    void *user_data,
544    grpc_ssl_server_certificate_config **config)
545
546  grpc_ssl_server_credentials_options *grpc_ssl_server_credentials_create_options_using_config(
547    grpc_ssl_client_certificate_request_type client_certificate_request,
548    grpc_ssl_server_certificate_config *certificate_config)
549
550  grpc_ssl_server_credentials_options* grpc_ssl_server_credentials_create_options_using_config_fetcher(
551    grpc_ssl_client_certificate_request_type client_certificate_request,
552    grpc_ssl_server_certificate_config_callback cb,
553    void *user_data)
554
555  grpc_server_credentials *grpc_ssl_server_credentials_create_with_options(
556      grpc_ssl_server_credentials_options *options)
557
558  ctypedef struct grpc_ssl_pem_key_cert_pair:
559    const char *private_key
560    const char *certificate_chain "cert_chain"
561
562  ctypedef struct grpc_channel_credentials:
563    # We don't care about the internals (and in fact don't know them)
564    pass
565
566  ctypedef struct grpc_call_credentials:
567    # We don't care about the internals (and in fact don't know them)
568    pass
569
570  ctypedef struct grpc_ssl_session_cache:
571    # We don't care about the internals (and in fact don't know them)
572    pass
573
574  ctypedef struct verify_peer_options:
575    # We don't care about the internals (and in fact don't know them)
576    pass
577
578  ctypedef void (*grpc_ssl_roots_override_callback)(char **pem_root_certs)
579
580  grpc_ssl_session_cache *grpc_ssl_session_cache_create_lru(size_t capacity)
581  void grpc_ssl_session_cache_destroy(grpc_ssl_session_cache* cache)
582
583  void grpc_set_ssl_roots_override_callback(
584      grpc_ssl_roots_override_callback cb) nogil
585
586  grpc_channel_credentials *grpc_google_default_credentials_create(grpc_call_credentials* call_credentials) nogil
587  grpc_channel_credentials *grpc_ssl_credentials_create(
588      const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair,
589      verify_peer_options *verify_options, void *reserved) nogil
590  grpc_channel_credentials *grpc_composite_channel_credentials_create(
591      grpc_channel_credentials *creds1, grpc_call_credentials *creds2,
592      void *reserved) nogil
593  void grpc_channel_credentials_release(grpc_channel_credentials *creds) nogil
594
595  grpc_channel_credentials *grpc_xds_credentials_create(
596      grpc_channel_credentials *fallback_creds) nogil
597
598  grpc_channel_credentials *grpc_insecure_credentials_create() nogil
599
600  grpc_server_credentials *grpc_xds_server_credentials_create(
601      grpc_server_credentials *fallback_creds) nogil
602
603  grpc_server_credentials *grpc_insecure_server_credentials_create() nogil
604
605  grpc_call_credentials *grpc_composite_call_credentials_create(
606      grpc_call_credentials *creds1, grpc_call_credentials *creds2,
607      void *reserved) nogil
608  grpc_call_credentials *grpc_google_compute_engine_credentials_create(
609      void *reserved) nogil
610  grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
611      const char *json_key,
612      gpr_timespec token_lifetime, void *reserved) nogil
613  grpc_call_credentials *grpc_google_refresh_token_credentials_create(
614      const char *json_refresh_token, void *reserved) nogil
615  grpc_call_credentials *grpc_google_iam_credentials_create(
616      const char *authorization_token, const char *authority_selector,
617      void *reserved) nogil
618  void grpc_call_credentials_release(grpc_call_credentials *creds) nogil
619
620  grpc_channel *grpc_channel_create(
621      const char *target, grpc_channel_credentials *creds,
622      const grpc_channel_args *args) nogil
623
624  ctypedef struct grpc_server_credentials:
625    # We don't care about the internals (and in fact don't know them)
626    pass
627
628  void grpc_server_credentials_release(grpc_server_credentials *creds) nogil
629
630  int grpc_server_add_http2_port(grpc_server *server, const char *addr,
631                                        grpc_server_credentials *creds) nogil
632
633  grpc_call_error grpc_call_set_credentials(grpc_call *call,
634                                            grpc_call_credentials *creds) nogil
635
636  ctypedef struct grpc_auth_context:
637    # We don't care about the internals (and in fact don't know them)
638    pass
639
640  ctypedef struct grpc_auth_metadata_context:
641    const char *service_url
642    const char *method_name
643    const grpc_auth_context *channel_auth_context
644
645  ctypedef void (*grpc_credentials_plugin_metadata_cb)(
646      void *user_data, const grpc_metadata *creds_md, size_t num_creds_md,
647      grpc_status_code status, const char *error_details) nogil
648
649  ctypedef struct grpc_metadata_credentials_plugin:
650    int (*get_metadata)(
651        void *state, grpc_auth_metadata_context context,
652        grpc_credentials_plugin_metadata_cb cb, void *user_data,
653        grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
654        size_t *num_creds_md, grpc_status_code *status,
655        const char **error_details) except *
656    void (*destroy)(void *state) except *
657    void *state
658    const char *type
659
660  grpc_call_credentials *grpc_metadata_credentials_create_from_plugin(
661      grpc_metadata_credentials_plugin plugin, grpc_security_level min_security_level, void *reserved) nogil
662
663  ctypedef struct grpc_auth_property_iterator:
664    pass
665
666  ctypedef struct grpc_auth_property:
667    char *name
668    char *value
669    size_t value_length
670
671  grpc_auth_property *grpc_auth_property_iterator_next(
672      grpc_auth_property_iterator *it)
673
674  grpc_auth_property_iterator grpc_auth_context_property_iterator(
675      const grpc_auth_context *ctx)
676
677  grpc_auth_property_iterator grpc_auth_context_peer_identity(
678      const grpc_auth_context *ctx)
679
680  char *grpc_auth_context_peer_identity_property_name(
681      const grpc_auth_context *ctx)
682
683  grpc_auth_property_iterator grpc_auth_context_find_properties_by_name(
684      const grpc_auth_context *ctx, const char *name)
685
686  grpc_auth_context_peer_is_authenticated(
687      const grpc_auth_context *ctx)
688
689  grpc_auth_context *grpc_call_auth_context(grpc_call *call)
690
691  void grpc_auth_context_release(grpc_auth_context *context)
692
693  grpc_channel_credentials *grpc_local_credentials_create(
694    grpc_local_connect_type type)
695  grpc_server_credentials *grpc_local_server_credentials_create(
696    grpc_local_connect_type type)
697
698  ctypedef struct grpc_alts_credentials_options:
699    # We don't care about the internals (and in fact don't know them)
700    pass
701
702  grpc_channel_credentials *grpc_alts_credentials_create(
703    const grpc_alts_credentials_options *options)
704  grpc_server_credentials *grpc_alts_server_credentials_create(
705    const grpc_alts_credentials_options *options)
706
707  grpc_alts_credentials_options* grpc_alts_credentials_client_options_create()
708  grpc_alts_credentials_options* grpc_alts_credentials_server_options_create()
709  void grpc_alts_credentials_options_destroy(grpc_alts_credentials_options *options)
710  void grpc_alts_credentials_client_options_add_target_service_account(grpc_alts_credentials_options *options, const char *service_account)
711
712
713
714cdef extern from "grpc/compression.h":
715
716  ctypedef enum grpc_compression_algorithm:
717    GRPC_COMPRESS_NONE
718    GRPC_COMPRESS_DEFLATE
719    GRPC_COMPRESS_GZIP
720    GRPC_COMPRESS_STREAM_GZIP
721    GRPC_COMPRESS_ALGORITHMS_COUNT
722
723  ctypedef enum grpc_compression_level:
724    GRPC_COMPRESS_LEVEL_NONE
725    GRPC_COMPRESS_LEVEL_LOW
726    GRPC_COMPRESS_LEVEL_MED
727    GRPC_COMPRESS_LEVEL_HIGH
728    GRPC_COMPRESS_LEVEL_COUNT
729
730  ctypedef struct grpc_compression_options:
731    uint32_t enabled_algorithms_bitset
732
733  int grpc_compression_algorithm_parse(
734      grpc_slice value, grpc_compression_algorithm *algorithm) nogil
735  int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm,
736                                      const char **name) nogil
737  grpc_compression_algorithm grpc_compression_algorithm_for_level(
738      grpc_compression_level level, uint32_t accepted_encodings) nogil
739  void grpc_compression_options_init(grpc_compression_options *opts) nogil
740  void grpc_compression_options_enable_algorithm(
741      grpc_compression_options *opts,
742      grpc_compression_algorithm algorithm) nogil
743  void grpc_compression_options_disable_algorithm(
744      grpc_compression_options *opts,
745      grpc_compression_algorithm algorithm) nogil
746  int grpc_compression_options_is_algorithm_enabled(
747      const grpc_compression_options *opts,
748      grpc_compression_algorithm algorithm) nogil
749
750cdef extern from "grpc/impl/codegen/compression_types.h":
751
752  const char *_GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \
753    "GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY"
754
755
756cdef extern from "grpc/grpc_security_constants.h":
757  ctypedef enum grpc_local_connect_type:
758    UDS
759    LOCAL_TCP
760
761cdef extern from "src/core/lib/config/config_vars.h" namespace "grpc_core":
762  cdef cppclass ConfigVars:
763    @staticmethod
764    void Reset()
765