mirror of
https://github.com/ekzhang/bore.git
synced 2025-12-15 03:17:47 +01:00
rename flags to bind_addr and bind_tunnels
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -49,13 +49,13 @@ enum Command {
|
||||
#[clap(short, long, env = "BORE_SECRET", hide_env_values = true)]
|
||||
secret: Option<String>,
|
||||
|
||||
/// IP address for the control server. Bore clients must reach this address.
|
||||
/// IP address where the control server will bind to. Bore clients must reach this.
|
||||
#[clap(long, default_value = "0.0.0.0")]
|
||||
control_addr: String,
|
||||
bind_addr: String,
|
||||
|
||||
/// IP address where tunnels will listen on.
|
||||
#[clap(long, default_value = "0.0.0.0")]
|
||||
tunnels_addr: String,
|
||||
bind_tunnels: String,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ async fn run(command: Command) -> Result<()> {
|
||||
min_port,
|
||||
max_port,
|
||||
secret,
|
||||
control_addr,
|
||||
tunnels_addr,
|
||||
bind_addr,
|
||||
bind_tunnels,
|
||||
} => {
|
||||
let port_range = min_port..=max_port;
|
||||
if port_range.is_empty() {
|
||||
@@ -86,14 +86,14 @@ async fn run(command: Command) -> Result<()> {
|
||||
.exit();
|
||||
}
|
||||
|
||||
let ipaddr_control = control_addr.parse::<IpAddr>();
|
||||
let ipaddr_control = bind_addr.parse::<IpAddr>();
|
||||
if ipaddr_control.is_err() {
|
||||
Args::command()
|
||||
.error(ErrorKind::InvalidValue, "invalid ip address for control server")
|
||||
.exit();
|
||||
}
|
||||
|
||||
let ipaddr_tunnels = tunnels_addr.parse::<IpAddr>();
|
||||
let ipaddr_tunnels = bind_tunnels.parse::<IpAddr>();
|
||||
if ipaddr_tunnels.is_err() {
|
||||
Args::command()
|
||||
.error(ErrorKind::InvalidValue, "invalid ip address for tunnel connections")
|
||||
|
||||
@@ -25,11 +25,11 @@ pub struct Server {
|
||||
/// Concurrent map of IDs to incoming connections.
|
||||
conns: Arc<DashMap<Uuid, TcpStream>>,
|
||||
|
||||
/// IP address for the control server. Bore clients must reach this address.
|
||||
control_addr: IpAddr,
|
||||
/// IP address where the control server will bind to. Bore clients must reach this.
|
||||
bind_addr: IpAddr,
|
||||
|
||||
/// IP address where tunnels will listen on.
|
||||
tunnels_addr: IpAddr,
|
||||
bind_tunnels: IpAddr,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
@@ -37,24 +37,24 @@ impl Server {
|
||||
pub fn new(
|
||||
port_range: RangeInclusive<u16>,
|
||||
secret: Option<&str>,
|
||||
control_addr: IpAddr,
|
||||
tunnels_addr: IpAddr,
|
||||
bind_addr: IpAddr,
|
||||
bind_tunnels: IpAddr,
|
||||
) -> Self {
|
||||
assert!(!port_range.is_empty(), "must provide at least one port");
|
||||
Server {
|
||||
port_range,
|
||||
conns: Arc::new(DashMap::new()),
|
||||
auth: secret.map(Authenticator::new),
|
||||
control_addr,
|
||||
tunnels_addr,
|
||||
bind_addr,
|
||||
bind_tunnels,
|
||||
}
|
||||
}
|
||||
|
||||
/// Start the server, listening for new connections.
|
||||
pub async fn listen(self) -> Result<()> {
|
||||
let this = Arc::new(self);
|
||||
let listener = TcpListener::bind((this.control_addr, CONTROL_PORT)).await?;
|
||||
info!(?this.control_addr, "server listening");
|
||||
let listener = TcpListener::bind((this.bind_addr, CONTROL_PORT)).await?;
|
||||
info!(addr = ?this.bind_addr, "server listening");
|
||||
|
||||
loop {
|
||||
let (stream, addr) = listener.accept().await?;
|
||||
@@ -75,7 +75,7 @@ impl Server {
|
||||
|
||||
async fn create_listener(&self, port: u16) -> Result<TcpListener, &'static str> {
|
||||
let try_bind = |port: u16| async move {
|
||||
TcpListener::bind((self.tunnels_addr, port))
|
||||
TcpListener::bind((self.bind_tunnels, port))
|
||||
.await
|
||||
.map_err(|err| match err.kind() {
|
||||
io::ErrorKind::AddrInUse => "port already in use",
|
||||
|
||||
Reference in New Issue
Block a user