1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <signal.h>
18 
19 #include <android-base/logging.h>
20 #include <gflags/gflags.h>
21 
22 #include "common/libs/fs/shared_fd.h"
23 #include "common/libs/utils/socket2socket_proxy.h"
24 #include "host/libs/config/logging.h"
25 
26 DEFINE_int32(server_port, 8443, "The port for the proxy server");
27 DEFINE_int32(operator_port, 1443, "The port of the operator server to proxy");
28 
OpenConnection()29 cuttlefish::SharedFD OpenConnection() {
30   auto conn =
31       cuttlefish::SharedFD::SocketLocalClient(FLAGS_operator_port, SOCK_STREAM);
32   if (!conn->IsOpen()) {
33     LOG(ERROR) << "Failed to connect to operator: " << conn->StrError();
34   }
35   return conn;
36 }
37 
main(int argc,char ** argv)38 int main(int argc, char** argv) {
39   cuttlefish::DefaultSubprocessLogging(argv);
40   ::gflags::ParseCommandLineFlags(&argc, &argv, true);
41 
42   auto server =
43       cuttlefish::SharedFD::SocketLocalServer(FLAGS_server_port, SOCK_STREAM);
44   CHECK(server->IsOpen()) << "Error Creating proxy server: "
45                           << server->StrError();
46 
47   signal(SIGPIPE, SIG_IGN);
48 
49   cuttlefish::Proxy(server, OpenConnection);
50 
51   return 0;
52 }
53