Biases port numbers.

The port passed to launch_cvd will still be the same, the
socket_forward_proxy process will bias the port numbers. I don't know if
or how this will affect treehugger's current use.

Bug: 75465725
Change-Id: I3795911d62ec26028db227bea985dee3bc1550d8
diff --git a/common/frontend/socket_forward_proxy/main.cpp b/common/frontend/socket_forward_proxy/main.cpp
index 6022d41..05e600c 100644
--- a/common/frontend/socket_forward_proxy/main.cpp
+++ b/common/frontend/socket_forward_proxy/main.cpp
@@ -162,15 +162,17 @@
   if (index + 1 < ports.size()) {
     std::thread(host_impl, shm, ports, index + 1).detach();
   }
-  auto port = ports[index];
-  LOG(INFO) << "starting server on " << port;
-  auto server = cvd::SharedFD::SocketLocalServer(port, SOCK_STREAM);
-  CHECK(server->IsOpen()) << "Could not start server on port " << port;
+  auto remote_port = ports[index];
+  auto local_port = vsoc::GetPerInstanceDefault(remote_port);
+  LOG(INFO) << "starting server on " << local_port
+            << " for guest port " << remote_port;
+  auto server = cvd::SharedFD::SocketLocalServer(local_port, SOCK_STREAM);
+  CHECK(server->IsOpen()) << "Could not start server on port " << local_port;
   while (true) {
     auto client_socket = cvd::SharedFD::Accept(*server);
     CHECK(client_socket->IsOpen()) << "error creating client socket";
     LOG(INFO) << "client socket accepted";
-    auto conn = shm->OpenConnection(port);
+    auto conn = shm->OpenConnection(remote_port);
     LOG(INFO) << "shm connection opened";
     LaunchWorkers(std::move(conn), std::move(client_socket));
   }
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index eb172b5..053c391 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -114,14 +114,15 @@
               "Location of the vnc server binary.");
 DEFINE_int32(vnc_server_port, vsoc::GetPerInstanceDefault(6444),
              "The port on which the vnc server should listen");
-// TODO(haining) bias the port number in a way that still goes to 5555 on the
-// guest-side
 DEFINE_string(socket_forward_proxy_binary,
               StringFromEnv("ANDROID_HOST_OUT", StringFromEnv("HOME", ".")) +
                   "/bin/socket_forward_proxy",
               "Location of the socket_forward_proxy binary.");
 DEFINE_string(socket_forward_proxy_ports, "5555", "Comma-separated list of "
-              "ports on which to run the socket_forward_proxy server");
+              "ports on which to run the socket_forward_proxy server. These "
+              "are the port numbers of the guest-side process. The "
+              "host-side socket_forward_proxy process will bias the port "
+              "numbers.");
 
 DECLARE_string(uuid);