Skip to content
Open
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
21 changes: 20 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ enum Command {
#[clap(short, long, default_value_t = 0)]
port: u16,

/// Optional if you fallback to different port if selected port is occupied
#[clap(long, default_value_t = false)]
port_fallback: bool,

/// Optional secret for authentication.
#[clap(short, long, env = "BORE_SECRET", hide_env_values = true)]
secret: Option<String>,
Expand Down Expand Up @@ -58,9 +62,24 @@ async fn run(command: Command) -> Result<()> {
local_port,
to,
port,
port_fallback,
secret,
} => {
let client = Client::new(&local_host, local_port, &to, port, secret.as_deref()).await?;
let client =
match Client::new(&local_host, local_port, &to, port, secret.as_deref()).await {
Ok(client) => client,
Err(e) => {
if e.to_string().eq("server error: port already in use")
&& port != 0
&& port_fallback
{
Client::new(&local_host, local_port, &to, 0, secret.as_deref()).await?
} else {
return Err(e);
}
}
};

client.listen().await?;
}
Command::Server {
Expand Down