Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef ARC_NETWORK_ADB_PROXY_H_ |
| 6 | #define ARC_NETWORK_ADB_PROXY_H_ |
| 7 | |
| 8 | #include <deque> |
| 9 | #include <memory> |
| 10 | |
Hidehiko Abe | de12922 | 2019-08-16 00:55:04 +0900 | [diff] [blame^] | 11 | #include <base/files/file_descriptor_watcher_posix.h> |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 12 | #include <base/files/scoped_file.h> |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 13 | #include <base/memory/weak_ptr.h> |
| 14 | #include <brillo/daemons/daemon.h> |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 15 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 16 | #include "arc/network/message_dispatcher.h" |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 17 | #include "arc/network/socket.h" |
| 18 | #include "arc/network/socket_forwarder.h" |
| 19 | |
| 20 | namespace arc_networkd { |
| 21 | |
| 22 | // Subprocess for proxying ADB traffic. |
Hidehiko Abe | de12922 | 2019-08-16 00:55:04 +0900 | [diff] [blame^] | 23 | class AdbProxy : public brillo::Daemon { |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 24 | public: |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 25 | explicit AdbProxy(base::ScopedFD control_fd); |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 26 | virtual ~AdbProxy(); |
| 27 | |
| 28 | protected: |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 29 | int OnInit() override; |
| 30 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 31 | void OnParentProcessExit(); |
| 32 | void OnGuestMessage(const GuestMessage& msg); |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 33 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 34 | private: |
Garrick Evans | bdf1f98 | 2019-06-07 09:46:49 +0900 | [diff] [blame] | 35 | void Reset(); |
Hidehiko Abe | de12922 | 2019-08-16 00:55:04 +0900 | [diff] [blame^] | 36 | void OnFileCanReadWithoutBlocking(); |
Garrick Evans | bdf1f98 | 2019-06-07 09:46:49 +0900 | [diff] [blame] | 37 | |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 38 | // Attempts to establish a connection to ADB at well-known destinations. |
| 39 | std::unique_ptr<Socket> Connect() const; |
| 40 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame] | 41 | MessageDispatcher msg_dispatcher_; |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 42 | std::unique_ptr<Socket> src_; |
| 43 | std::deque<std::unique_ptr<SocketForwarder>> fwd_; |
Hidehiko Abe | de12922 | 2019-08-16 00:55:04 +0900 | [diff] [blame^] | 44 | std::unique_ptr<base::FileDescriptorWatcher::Controller> src_watcher_; |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 45 | |
Garrick Evans | bdf1f98 | 2019-06-07 09:46:49 +0900 | [diff] [blame] | 46 | GuestMessage::GuestType arc_type_; |
Garrick Evans | 1cce71a | 2019-06-21 10:43:14 +0900 | [diff] [blame] | 47 | uint32_t arcvm_vsock_cid_; |
Garrick Evans | bdf1f98 | 2019-06-07 09:46:49 +0900 | [diff] [blame] | 48 | |
Garrick Evans | 3cbac7c | 2019-04-18 15:31:31 +0900 | [diff] [blame] | 49 | base::WeakPtrFactory<AdbProxy> weak_factory_{this}; |
| 50 | DISALLOW_COPY_AND_ASSIGN(AdbProxy); |
| 51 | }; |
| 52 | |
| 53 | } // namespace arc_networkd |
| 54 | |
| 55 | #endif // ARC_NETWORK_ADB_PROXY_H_ |