mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 12:15:36 +02:00
[cdc_stream] [cdc_rsync] Add --forward-port flag (#45)
Adds a flag to set the SSH forwarding port or port range used for 'cdc_stream start-service' and 'cdc_rsync'. If a single number is passed, e.g. --forward-port 12345, then this port is used without checking availability of local and remote ports. If the port is taken, this results in an error when trying to connect. Note that this restricts the number of connections that stream can make to one. If a range is passed, e.g. --forward-port 45000-46000, the tools search for available ports locally and remotely in that range. This is more robust, but a bit slower due to the extra overhead. Optimizes port_manager_win as it was very slow for a large port range. It's still not optimal, but the time needed to scan 30k ports is << 1 seconds now. Fixes #12
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
#include "cdc_stream/base_command.h"
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_split.h"
|
||||
#include "absl_helper/jedec_size_flag.h"
|
||||
#include "common/port_range_parser.h"
|
||||
#include "lyra/lyra.hpp"
|
||||
|
||||
namespace cdc_ft {
|
||||
@@ -44,8 +46,7 @@ void BaseCommand::Register(lyra::cli& cli) {
|
||||
|
||||
std::function<void(const std::string&)> BaseCommand::JedecParser(
|
||||
const char* flag_name, uint64_t* bytes) {
|
||||
return [flag_name, bytes,
|
||||
error = &jedec_parse_error_](const std::string& value) {
|
||||
return [flag_name, bytes, error = &parse_error_](const std::string& value) {
|
||||
JedecSize size;
|
||||
if (AbslParseFlag(value, &size, error)) {
|
||||
*bytes = size.Size();
|
||||
@@ -56,6 +57,18 @@ std::function<void(const std::string&)> BaseCommand::JedecParser(
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(const std::string&)> BaseCommand::PortRangeParser(
|
||||
const char* flag_name, uint16_t* first, uint16_t* last) {
|
||||
return [flag_name, first, last,
|
||||
error = &parse_error_](const std::string& value) {
|
||||
if (!port_range::Parse(value.c_str(), first, last)) {
|
||||
*error = absl::StrFormat(
|
||||
"Failed to parse %s=%s, expected <port> or <port1>-<port2>",
|
||||
flag_name, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void(const std::string&)> BaseCommand::PosArgValidator(
|
||||
std::string* str) {
|
||||
return [str, invalid_arg = &invalid_arg_](const std::string& value) {
|
||||
@@ -83,8 +96,8 @@ void BaseCommand::CommandHandler(const lyra::group& g) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!jedec_parse_error_.empty()) {
|
||||
std::cerr << "Error: " << jedec_parse_error_ << std::endl;
|
||||
if (!parse_error_.empty()) {
|
||||
std::cerr << "Error: " << parse_error_ << std::endl;
|
||||
*exit_code_ = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user