Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 1 | // |
| 2 | // |
| 3 | // Copyright 2016 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 | // |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 18 | |
Ivan Lozano | 86747a9 | 2023-06-21 14:25:47 +0000 | [diff] [blame] | 19 | #include <grpc/support/port_platform.h> |
| 20 | |
| 21 | #include "src/core/ext/transport/cronet/client/secure/cronet_channel_create.h" |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 22 | |
Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 23 | #include "absl/status/statusor.h" |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 24 | |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 25 | #include <grpc/support/log.h> |
| 26 | |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 27 | #include "src/core/ext/transport/cronet/transport/cronet_transport.h" |
Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 28 | #include "src/core/lib/channel/channel_args.h" |
| 29 | #include "src/core/lib/channel/channel_args_preconditioning.h" |
| 30 | #include "src/core/lib/config/core_configuration.h" |
| 31 | #include "src/core/lib/gprpp/ref_counted_ptr.h" |
| 32 | #include "src/core/lib/iomgr/exec_ctx.h" |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 33 | #include "src/core/lib/surface/channel.h" |
Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 34 | #include "src/core/lib/surface/channel_stack_type.h" |
| 35 | #include "src/core/lib/transport/transport_fwd.h" |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 36 | #include "src/core/lib/transport/transport_impl.h" |
| 37 | |
| 38 | // Cronet transport object |
| 39 | typedef struct cronet_transport { |
| 40 | grpc_transport base; // must be first element in this structure |
| 41 | void* engine; |
| 42 | char* host; |
| 43 | } cronet_transport; |
| 44 | |
| 45 | extern grpc_transport_vtable grpc_cronet_vtable; |
| 46 | |
| 47 | GRPCAPI grpc_channel* grpc_cronet_secure_channel_create( |
| 48 | void* engine, const char* target, const grpc_channel_args* args, |
| 49 | void* reserved) { |
| 50 | gpr_log(GPR_DEBUG, |
| 51 | "grpc_create_cronet_transport: stream_engine = %p, target=%s", engine, |
| 52 | target); |
| 53 | |
| 54 | // Disable client authority filter when using Cronet |
Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 55 | auto channel_args = grpc_core::CoreConfiguration::Get() |
| 56 | .channel_args_preconditioning() |
| 57 | .PreconditionChannelArgs(args) |
| 58 | .Set(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER, 1); |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 59 | |
Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 60 | grpc_transport* ct = grpc_create_cronet_transport( |
| 61 | engine, target, channel_args.ToC().get(), reserved); |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 62 | |
| 63 | grpc_core::ExecCtx exec_ctx; |
Shuo Wang Hsu | 67249fc | 2024-01-02 16:54:20 -0800 | [diff] [blame^] | 64 | auto channel = grpc_core::Channel::Create(target, channel_args, |
| 65 | GRPC_CLIENT_DIRECT_CHANNEL, ct); |
| 66 | return channel.ok() ? channel->release()->c_ptr() : nullptr; |
Jeff Vander Stoep | 3adfea8 | 2020-10-14 15:35:59 +0200 | [diff] [blame] | 67 | } |