Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ libc = "0.2"
pelite = "0.10"
regex = "1.10"
structopt = "0.3.26"
url-builder = "0.1.1"

[build-dependencies]
tonic-build = "0.12.3"
Expand Down
22 changes: 8 additions & 14 deletions src/bin/feos_cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod feos_grpc {
#[structopt(name = "feos-cli")]
pub struct Opt {
#[structopt(short, long, default_value = "::1")]
pub server_ip: String,
pub server: String,
#[structopt(short, long, default_value = "1337")]
pub port: u16,
#[structopt(subcommand)]
Expand Down Expand Up @@ -67,18 +67,12 @@ pub enum Command {
IsolatedContainer(IsolatedContainerCommand),
}

fn format_address(ip: &str, port: u16) -> String {
if ip.contains(':') {
// IPv6 address
format!("http://[{}]:{}", ip, port)
} else {
// IPv4 address
format!("http://{}:{}", ip, port)
}
}

pub async fn run_client(opt: Opt) -> Result<(), Box<dyn std::error::Error>> {
let address = format_address(&opt.server_ip, opt.port);
let mut ub = URLBuilder::new();
ub.set_protocol("http")
.set_host(server.as_str())
.set_port(port);
let address = ub.build();
let endpoint = Endpoint::from_shared(address)?
.keep_alive_while_idle(true)
.keep_alive_timeout(Duration::from_secs(20));
Expand All @@ -88,12 +82,12 @@ pub async fn run_client(opt: Opt) -> Result<(), Box<dyn std::error::Error>> {

match opt.cmd {
Command::Container(container_cmd) => {
crate::client_container::run_container_client(opt.server_ip, opt.port, container_cmd)
crate::client_container::run_container_client(opt.server, opt.port, container_cmd)
.await?;
}
Command::IsolatedContainer(container_cmd) => {
crate::client_isolated_container::run_isolated_container_client(
opt.server_ip,
opt.server,
opt.port,
container_cmd,
)
Expand Down
9 changes: 7 additions & 2 deletions src/bin/feos_cli/client_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tonic::Request;

use container_grpc::container_service_client::ContainerServiceClient;
use container_grpc::*;
use url_builder::URLBuilder;

pub mod container_grpc {
tonic::include_proto!("container");
Expand Down Expand Up @@ -33,11 +34,15 @@ pub enum ContainerCommand {
}

pub async fn run_container_client(
server_ip: String,
server: String,
port: u16,
cmd: ContainerCommand,
) -> Result<(), Box<dyn std::error::Error>> {
let address = format!("http://{}:{}", server_ip, port);
let mut ub = URLBuilder::new();
ub.set_protocol("http")
.set_host(server.as_str())
.set_port(port);
let address = ub.build();
let channel = Endpoint::from_shared(address)?.connect().await?;
let mut client = ContainerServiceClient::new(channel);

Expand Down
9 changes: 7 additions & 2 deletions src/bin/feos_cli/client_isolated_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tonic::Request;

use isolated_container_grpc::isolated_container_service_client::IsolatedContainerServiceClient;
use isolated_container_grpc::*;
use url_builder::URLBuilder;

pub mod isolated_container_grpc {
tonic::include_proto!("isolated_container");
Expand All @@ -30,11 +31,15 @@ pub enum IsolatedContainerCommand {
}

pub async fn run_isolated_container_client(
server_ip: String,
server: String,
port: u16,
cmd: IsolatedContainerCommand,
) -> Result<(), Box<dyn std::error::Error>> {
let address = format!("http://{}:{}", server_ip, port);
let mut ub = URLBuilder::new();
ub.set_protocol("http")
.set_host(server.as_str())
.set_port(port);
let address = ub.build();
let channel = Endpoint::from_shared(address)?.connect().await?;
let mut client = IsolatedContainerServiceClient::new(channel);

Expand Down