arc: Move platform2/arc/network/ to platform2/patchpanel

Next step in the arc-networkd -> patchpanel rename, this patch moves the
location of the code.

BUG=b:151879931
TEST=units,flashed image to atlas
TEST=tasts arc.PlayStore, crostini.LaunchTerminal.download

Change-Id: I1b5cf8d670e1631d46f6449b725395157bf88dde
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2115863
Tested-by: Garrick Evans <garrick@chromium.org>
Commit-Queue: Garrick Evans <garrick@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Hugo Benichi <hugobenichi@google.com>
diff --git a/patchpanel/adb_proxy.h b/patchpanel/adb_proxy.h
new file mode 100644
index 0000000..b808448
--- /dev/null
+++ b/patchpanel/adb_proxy.h
@@ -0,0 +1,60 @@
+// Copyright 2019 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PATCHPANEL_ADB_PROXY_H_
+#define PATCHPANEL_ADB_PROXY_H_
+
+#include <deque>
+#include <memory>
+
+#include <base/files/file_descriptor_watcher_posix.h>
+#include <base/files/scoped_file.h>
+#include <base/memory/weak_ptr.h>
+#include <brillo/daemons/daemon.h>
+
+#include "patchpanel/message_dispatcher.h"
+#include "patchpanel/socket.h"
+#include "patchpanel/socket_forwarder.h"
+
+namespace patchpanel {
+
+// ADB gets confused if we listen on 5555 and thinks there is an emulator
+// running, which in turn ends up confusing our integration test libraries
+// because multiple devices show up.
+constexpr uint16_t kAdbProxyTcpListenPort = 5550;
+
+// Subprocess for proxying ADB traffic.
+class AdbProxy : public brillo::Daemon {
+ public:
+  explicit AdbProxy(base::ScopedFD control_fd);
+  virtual ~AdbProxy();
+
+ protected:
+  int OnInit() override;
+
+  void OnParentProcessExit();
+  void OnGuestMessage(const GuestMessage& msg);
+
+ private:
+  void Reset();
+  void OnFileCanReadWithoutBlocking();
+
+  // Attempts to establish a connection to ADB at well-known destinations.
+  std::unique_ptr<Socket> Connect() const;
+
+  MessageDispatcher msg_dispatcher_;
+  std::unique_ptr<Socket> src_;
+  std::deque<std::unique_ptr<SocketForwarder>> fwd_;
+  std::unique_ptr<base::FileDescriptorWatcher::Controller> src_watcher_;
+
+  GuestMessage::GuestType arc_type_;
+  uint32_t arcvm_vsock_cid_;
+
+  base::WeakPtrFactory<AdbProxy> weak_factory_{this};
+  DISALLOW_COPY_AND_ASSIGN(AdbProxy);
+};
+
+}  // namespace patchpanel
+
+#endif  // PATCHPANEL_ADB_PROXY_H_