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