• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2018 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_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H
20 #define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <grpc/byte_buffer.h>
25 #include <grpc/byte_buffer_reader.h>
26 
27 #include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h"
28 #include "src/core/tsi/transport_security_interface.h"
29 
30 /**
31  * A ALTS TSI event interface. In asynchronous implementation of
32  * tsi_handshaker_next(), the function will exit after scheduling a handshaker
33  * request to ALTS handshaker service without waiting for response to return.
34  * The event is used to link the scheduled handshaker request with the
35  * corresponding response so that enough context information can be inferred
36  * from it to handle the response. All APIs in the header are thread-compatible.
37  */
38 
39 /**
40  * Main struct for ALTS TSI event. It retains ownership on send_buffer and
41  * recv_buffer, but not on handshaker.
42  */
43 typedef struct alts_tsi_event {
44   alts_tsi_handshaker* handshaker;
45   grpc_byte_buffer* send_buffer;
46   grpc_byte_buffer* recv_buffer;
47   grpc_status_code status;
48   grpc_slice details;
49   grpc_metadata_array initial_metadata;
50   grpc_metadata_array trailing_metadata;
51   tsi_handshaker_on_next_done_cb cb;
52   void* user_data;
53   grpc_alts_credentials_options* options;
54   grpc_slice target_name;
55 } alts_tsi_event;
56 
57 /**
58  * This method creates a ALTS TSI event.
59  *
60  * - handshaker: ALTS TSI handshaker instance associated with the event to be
61  *   created. The created event does not own the handshaker instance.
62  * - cb: callback function to be called when handling data received from ALTS
63  *   handshaker service.
64  * - user_data: argument to callback function.
65  * - options: ALTS credentials options.
66  * - target_name: name of endpoint used for secure naming check.
67  * - event: address of ALTS TSI event instance to be returned from the method.
68  *
69  * It returns TSI_OK on success and an error status code on failure.
70  */
71 tsi_result alts_tsi_event_create(alts_tsi_handshaker* handshaker,
72                                  tsi_handshaker_on_next_done_cb cb,
73                                  void* user_data,
74                                  grpc_alts_credentials_options* options,
75                                  grpc_slice target_name,
76                                  alts_tsi_event** event);
77 
78 /**
79  * This method dispatches a ALTS TSI event received from the handshaker service,
80  * and a boolean flag indicating if the event is valid to read to ALTS TSI
81  * handshaker to process. It is called by TSI thread.
82  *
83  * - event: ALTS TSI event instance.
84  * - is_ok: a boolean value indicating if the event is valid to read.
85  */
86 void alts_tsi_event_dispatch_to_handshaker(alts_tsi_event* event, bool is_ok);
87 
88 /**
89  * This method destroys the ALTS TSI event.
90  */
91 void alts_tsi_event_destroy(alts_tsi_event* event);
92 
93 #endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H */
94