blob: f5e602fc89cbee354071b6e238ba2440651117df [file] [log] [blame]
Shuo Wang Hsu67249fc2024-01-02 16:54:20 -08001//
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 Stoep3adfea82020-10-14 15:35:59 +020018
Ivan Lozano86747a92023-06-21 14:25:47 +000019#include <grpc/support/port_platform.h>
20
21#include "src/core/ext/transport/cronet/client/secure/cronet_channel_create.h"
Jeff Vander Stoep3adfea82020-10-14 15:35:59 +020022
Shuo Wang Hsu67249fc2024-01-02 16:54:20 -080023#include "absl/status/statusor.h"
Jeff Vander Stoep3adfea82020-10-14 15:35:59 +020024
Jeff Vander Stoep3adfea82020-10-14 15:35:59 +020025#include <grpc/support/log.h>
26
Jeff Vander Stoep3adfea82020-10-14 15:35:59 +020027#include "src/core/ext/transport/cronet/transport/cronet_transport.h"
Shuo Wang Hsu67249fc2024-01-02 16:54:20 -080028#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 Stoep3adfea82020-10-14 15:35:59 +020033#include "src/core/lib/surface/channel.h"
Shuo Wang Hsu67249fc2024-01-02 16:54:20 -080034#include "src/core/lib/surface/channel_stack_type.h"
35#include "src/core/lib/transport/transport_fwd.h"
Jeff Vander Stoep3adfea82020-10-14 15:35:59 +020036#include "src/core/lib/transport/transport_impl.h"
37
38// Cronet transport object
39typedef struct cronet_transport {
40 grpc_transport base; // must be first element in this structure
41 void* engine;
42 char* host;
43} cronet_transport;
44
45extern grpc_transport_vtable grpc_cronet_vtable;
46
47GRPCAPI 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 Hsu67249fc2024-01-02 16:54:20 -080055 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 Stoep3adfea82020-10-14 15:35:59 +020059
Shuo Wang Hsu67249fc2024-01-02 16:54:20 -080060 grpc_transport* ct = grpc_create_cronet_transport(
61 engine, target, channel_args.ToC().get(), reserved);
Jeff Vander Stoep3adfea82020-10-14 15:35:59 +020062
63 grpc_core::ExecCtx exec_ctx;
Shuo Wang Hsu67249fc2024-01-02 16:54:20 -080064 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 Stoep3adfea82020-10-14 15:35:59 +020067}