mirror of
https://github.com/google/cdc-file-transfer.git
synced 2026-09-13 01:10:44 +03:00
[cdc_rsync] Detect remote architecture (#86)
Improves ServerArch so that it can detect the remote architecture by running uname and checking %PROCESSOR_ARCHITECTURE%. So far, only x64 Linux and x64 Windows are supported, but in the future it is easy to add support for others, e.g. aarch64, as well. Before the detection is run, the remote architecture is guessed first based on the destination. For instance, if the destination directory starts with "C:\", it pretty much means Windows. If cdc_rsync_server exists and runs fine, there's no need for detection. Since also PortManager depends on the remote architecture, it has to be adjusted as well. So far, PortManager assumeed that "local" means Windows and "remote" means Linux. This is no longer the case for syncing to Windows devices, so this CL adds the necessary abstractions to PortManager. Also refactors ArchType into a separate class in common, since it is used now from several places. It is also expanded to handle future changes that add support for different processor architectures, e.g. aarch64.
This commit is contained in:
+15
-12
@@ -17,12 +17,12 @@
|
||||
#ifndef COMMON_PORT_MANAGER_H_
|
||||
#define COMMON_PORT_MANAGER_H_
|
||||
|
||||
#include <absl/status/statusor.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "absl/status/statusor.h"
|
||||
#include "common/arch_type.h"
|
||||
#include "common/clock.h"
|
||||
|
||||
namespace cdc_ft {
|
||||
@@ -53,9 +53,12 @@ class PortManager {
|
||||
// explicitly.
|
||||
// |remote_timeout_sec| is the timeout for finding available ports on the
|
||||
// remote instance.
|
||||
// Returns a DeadlineExceeded error if the timeout is exceeded.
|
||||
// Returns a ResourceExhausted error if no ports are available.
|
||||
absl::StatusOr<int> ReservePort(int remote_timeout_sec);
|
||||
// |remote_arch_type| is the architecture of the remote device.
|
||||
// Both |remote_timeout_sec| and |remote_arch_type| are ignored if
|
||||
// |remote_util| is nullptr. Returns a DeadlineExceeded error if the timeout
|
||||
// is exceeded. Returns a ResourceExhausted error if no ports are available.
|
||||
absl::StatusOr<int> ReservePort(int remote_timeout_sec,
|
||||
ArchType remote_arch_type);
|
||||
|
||||
// Releases a reserved port.
|
||||
absl::Status ReleasePort(int port);
|
||||
@@ -66,34 +69,34 @@ class PortManager {
|
||||
|
||||
// Finds available ports in the range [first_port, last_port] for port
|
||||
// forwarding on the local workstation.
|
||||
// |ip| is the IP address to filter by.
|
||||
// |arch_type| is the architecture of the local device.
|
||||
// |process_factory| is used to create a netstat process.
|
||||
// Returns ResourceExhaustedError if no port is available.
|
||||
static absl::StatusOr<std::unordered_set<int>> FindAvailableLocalPorts(
|
||||
int first_port, int last_port, const char* ip,
|
||||
int first_port, int last_port, ArchType arch_type,
|
||||
ProcessFactory* process_factory);
|
||||
|
||||
// Finds available ports in the range [first_port, last_port] for port
|
||||
// forwarding on the instance.
|
||||
// |ip| is the IP address to filter by.
|
||||
// |arch_type| is the architecture of the remote device.
|
||||
// |process_factory| is used to create a netstat process.
|
||||
// |remote_util| is used to connect to the instance.
|
||||
// |timeout_sec| is the connection timeout in seconds.
|
||||
// Returns a DeadlineExceeded error if the timeout is exceeded.
|
||||
// Returns ResourceExhaustedError if no port is available.
|
||||
static absl::StatusOr<std::unordered_set<int>> FindAvailableRemotePorts(
|
||||
int first_port, int last_port, const char* ip,
|
||||
int first_port, int last_port, ArchType arch_type,
|
||||
ProcessFactory* process_factory, RemoteUtil* remote_util, int timeout_sec,
|
||||
SteadyClock* steady_clock = DefaultSteadyClock::GetInstance());
|
||||
|
||||
private:
|
||||
// Returns a list of available ports in the range [|first_port|, |last_port|]
|
||||
// from the given |netstat_output|. |ip| is the IP address to look for, e.g.
|
||||
// "127.0.0.1".
|
||||
// from the given |netstat_output|.
|
||||
// |arch_type| is the architecture of the device where netstat was called.
|
||||
// Returns ResourceExhaustedError if no port is available.
|
||||
static absl::StatusOr<std::unordered_set<int>> FindAvailablePorts(
|
||||
int first_port, int last_port, const std::string& netstat_output,
|
||||
const char* ip);
|
||||
ArchType arch_type);
|
||||
|
||||
int first_port_;
|
||||
int last_port_;
|
||||
|
||||
Reference in New Issue
Block a user