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 //
18 
19 #include <grpc/support/port_platform.h>
20 
21 #include "src/core/ext/transport/cronet/client/secure/cronet_channel_create.h"
22 
23 #include "absl/status/statusor.h"
24 
25 #include <grpc/support/log.h>
26 
27 #include "src/core/ext/transport/cronet/transport/cronet_transport.h"
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"
33 #include "src/core/lib/surface/channel.h"
34 #include "src/core/lib/surface/channel_stack_type.h"
35 #include "src/core/lib/transport/transport_fwd.h"
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 
grpc_cronet_secure_channel_create(void * engine,const char * target,const grpc_channel_args * args,void * reserved)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
55   auto channel_args = grpc_core::CoreConfiguration::Get()
56                           .channel_args_preconditioning()
57                           .PreconditionChannelArgs(args)
58                           .Set(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER, 1);
59 
60   grpc_transport* ct = grpc_create_cronet_transport(
61       engine, target, channel_args.ToC().get(), reserved);
62 
63   grpc_core::ExecCtx exec_ctx;
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;
67 }
68