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 #include <grpc/support/log.h>
19 #include <grpcpp/impl/codegen/service_type.h>
20 #include <grpcpp/server_builder.h>
21 
22 #include <sstream>
23 
24 #include "absl/flags/flag.h"
25 #include "test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h"
26 #include "test/core/util/test_config.h"
27 #include "test/cpp/util/test_config.h"
28 
29 ABSL_FLAG(int32_t, handshaker_port, 55056,
30           "TCP port on which the fake handshaker server listens to.");
31 
RunFakeHandshakerServer(const std::string & server_address)32 static void RunFakeHandshakerServer(const std::string& server_address) {
33   std::unique_ptr<grpc::Service> service =
34       grpc::gcp::CreateFakeHandshakerService(
35           0 /* expected max concurrent rpcs unset */);
36   grpc::ServerBuilder builder;
37   builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
38   builder.RegisterService(service.get());
39   gpr_log(GPR_INFO, "Fake handshaker server listening on %s",
40           server_address.c_str());
41   std::unique_ptr<grpc::Server> server = builder.BuildAndStart();
42   server->Wait();
43 }
44 
main(int argc,char ** argv)45 int main(int argc, char** argv) {
46   grpc::testing::TestEnvironment env(argc, argv);
47   grpc::testing::InitTest(&argc, &argv, true);
48 
49   GPR_ASSERT(absl::GetFlag(FLAGS_handshaker_port) != 0);
50   std::ostringstream server_address;
51   server_address << "[::1]:" << absl::GetFlag(FLAGS_handshaker_port);
52 
53   RunFakeHandshakerServer(server_address.str());
54   return 0;
55 }
56