20 #include <condition_variable>
31 #include "absl/algorithm/container.h"
32 #include "absl/flags/flag.h"
33 #include "absl/strings/str_format.h"
34 #include "absl/strings/str_join.h"
35 #include "absl/strings/str_split.h"
50 #include "src/proto/grpc/testing/istio_echo.pb.h"
56 ABSL_FLAG(std::vector<std::string>,
grpc, std::vector<std::string>({
"7070"}),
58 ABSL_FLAG(std::vector<std::string>, tls, std::vector<std::string>({}),
59 "Ports that are using TLS. These must be defined as http/grpc/tcp.");
60 ABSL_FLAG(std::vector<std::string>, xds_grpc_server,
61 std::vector<std::string>({}),
62 "Ports that should rely on XDS configuration to serve");
66 "Forwarding address for unhandled protocols");
70 ABSL_FLAG(std::vector<std::string>,
port, std::vector<std::string>({
"8080"}),
72 ABSL_FLAG(std::vector<std::string>,
tcp, std::vector<std::string>({
"9090"}),
74 ABSL_FLAG(std::vector<std::string>, bind_ip, std::vector<std::string>({}),
75 "Ports that are bound to INSTANCE_IP rather than wildcard IP.");
76 ABSL_FLAG(std::vector<std::string>, bind_localhost,
77 std::vector<std::string>({}),
78 "Ports that are bound to localhost rather than wildcard IP.");
79 ABSL_FLAG(std::vector<std::string>, server_first, std::vector<std::string>({}),
80 "Ports that are server first. These must be defined as tcp.");
91 void RunServer(
const std::set<int>& grpc_ports,
const std::set<int>& xds_ports,
92 const std::set<int>& tls_ports) {
96 if (hostname_p ==
nullptr) {
99 hostname = hostname_p;
102 EchoTestServiceImpl echo_test_service(
105 XdsServerBuilder xds_builder;
106 bool has_xds_listeners =
false;
107 builder.RegisterService(&echo_test_service);
108 for (
int port : grpc_ports) {
110 if (xds_ports.find(
port) != xds_ports.end()) {
111 xds_builder.AddListeningPort(
115 has_xds_listeners =
true;
116 }
else if (tls_ports.find(
port) != tls_ports.end()) {
122 experimental::TlsServerCredentialsOptions
options(
123 std::make_shared<experimental::FileWatcherCertificateProvider>(
126 options.watch_identity_key_cert_pairs();
127 options.set_check_call_host(
false);
139 std::unique_ptr<Server> xds_server;
140 if (has_xds_listeners) {
141 xds_server = xds_builder.BuildAndStart();
151 int main(
int argc,
char** argv) {
158 std::map<std::string, std::vector<std::string>> argv_dict;
159 for (
int i = 0;
i < argc;
i++) {
161 size_t equal =
arg.find_first_of(
'=');
162 if (
equal != std::string::npos) {
164 if (
f ==
"--version") {
168 argv_dict[
f].push_back(
v);
171 std::vector<char*> new_argv_strs;
173 new_argv_strs.push_back(argv[0]);
174 for (
const auto& kv : argv_dict) {
176 for (
const auto& s : kv.second) {
182 std::replace(
f.begin() + 2,
f.end(),
'-',
'_');
184 char* writable =
new char[k_vs.size() + 1];
185 std::copy(k_vs.begin(), k_vs.end(), writable);
186 writable[k_vs.size()] =
'\0';
187 new_argv_strs.push_back(writable);
189 int new_argc = new_argv_strs.size();
190 char** new_argv = new_argv_strs.data();
194 std::set<int> grpc_ports;
196 int grpc_port = std::stoi(
p);
197 grpc_ports.insert(grpc_port);
200 std::set<int> xds_ports;
207 xds_ports.insert(
port);
209 if (grpc_ports.find(
port) == grpc_ports.end()) {
210 grpc_ports.insert(
port);
214 std::set<int> tls_ports;
221 tls_ports.insert(
port);