mirror of
https://github.com/ekzhang/bore.git
synced 2025-12-15 19:37:47 +01:00
Minor API changes
This commit is contained in:
@@ -93,14 +93,14 @@ Starts a local proxy to the remote server
|
|||||||
Usage: bore local [OPTIONS] --to <TO> <LOCAL_PORT>
|
Usage: bore local [OPTIONS] --to <TO> <LOCAL_PORT>
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
<LOCAL_PORT> The local port to expose
|
<LOCAL_PORT> The local port to expose [env: BORE_LOCAL_PORT=]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-l, --local-host <HOST> The local host to expose [default: localhost]
|
-l, --local-host <HOST> The local host to expose [default: localhost]
|
||||||
-t, --to <TO> Address of the remote server to expose local ports to [env: BORE_SERVER=]
|
-t, --to <TO> Address of the remote server to expose local ports to [env: BORE_SERVER=]
|
||||||
-p, --port <PORT> Optional port on the remote server to select [default: 0]
|
-p, --port <PORT> Optional port on the remote server to select [default: 0]
|
||||||
-s, --secret <SECRET> Optional secret for authentication [env: BORE_SECRET]
|
-s, --secret <SECRET> Optional secret for authentication [env: BORE_SECRET]
|
||||||
-h, --help Print help information
|
-h, --help Print help
|
||||||
```
|
```
|
||||||
|
|
||||||
### Self-Hosting
|
### Self-Hosting
|
||||||
@@ -126,10 +126,9 @@ Options:
|
|||||||
--min-port <MIN_PORT> Minimum accepted TCP port number [env: BORE_MIN_PORT=] [default: 1024]
|
--min-port <MIN_PORT> Minimum accepted TCP port number [env: BORE_MIN_PORT=] [default: 1024]
|
||||||
--max-port <MAX_PORT> Maximum accepted TCP port number [env: BORE_MAX_PORT=] [default: 65535]
|
--max-port <MAX_PORT> Maximum accepted TCP port number [env: BORE_MAX_PORT=] [default: 65535]
|
||||||
-s, --secret <SECRET> Optional secret for authentication [env: BORE_SECRET]
|
-s, --secret <SECRET> Optional secret for authentication [env: BORE_SECRET]
|
||||||
--control-addr <CONTROL_ADDR> IP address for the control server. Bore clients must reach this address [default: 0.0.0.0]
|
--bind-addr <BIND_ADDR> IP address to bind to, clients must reach this [default: 0.0.0.0]
|
||||||
--tunnels-addr <TUNNELS_ADDR> IP address where tunnels will listen on [default: 0.0.0.0]
|
--bind-tunnels <BIND_TUNNELS> IP address where tunnels will listen on, defaults to --bind-addr
|
||||||
-h, --help Print help
|
-h, --help Print help
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Protocol
|
## Protocol
|
||||||
|
|||||||
31
src/main.rs
31
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bore_cli::{client::Client, server::Server};
|
use bore_cli::{client::Client, server::Server};
|
||||||
use clap::{error::ErrorKind, CommandFactory, Parser, Subcommand};
|
use clap::{error::ErrorKind, CommandFactory, Parser, Subcommand};
|
||||||
@@ -49,13 +50,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 to bind to. Bore clients must reach this.
|
/// IP address to bind to, clients must reach this.
|
||||||
#[clap(long, default_value = "0.0.0.0")]
|
#[clap(long, default_value = "0.0.0.0")]
|
||||||
bind_addr: String,
|
bind_addr: IpAddr,
|
||||||
|
|
||||||
/// IP address where tunnels will listen on. Defaults to --bind-addr.
|
/// IP address where tunnels will listen on, defaults to --bind-addr.
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
bind_tunnels: Option<String>,
|
bind_tunnels: Option<IpAddr>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,24 +86,10 @@ async fn run(command: Command) -> Result<()> {
|
|||||||
.error(ErrorKind::InvalidValue, "port range is empty")
|
.error(ErrorKind::InvalidValue, "port range is empty")
|
||||||
.exit();
|
.exit();
|
||||||
}
|
}
|
||||||
|
let mut server = Server::new(port_range, secret.as_deref());
|
||||||
let ipaddr_control = bind_addr.parse::<IpAddr>();
|
server.set_bind_addr(bind_addr);
|
||||||
if ipaddr_control.is_err() {
|
server.set_bind_tunnels(bind_tunnels.unwrap_or(bind_addr));
|
||||||
Args::command()
|
server.listen().await?;
|
||||||
.error(ErrorKind::InvalidValue, "invalid ip address for control server")
|
|
||||||
.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
let ipaddr_tunnels = bind_tunnels.unwrap_or(bind_addr).parse::<IpAddr>();
|
|
||||||
if ipaddr_tunnels.is_err() {
|
|
||||||
Args::command()
|
|
||||||
.error(ErrorKind::InvalidValue, "invalid ip address for tunnel connections")
|
|
||||||
.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
Server::new(port_range, secret.as_deref(), ipaddr_control.unwrap(), ipaddr_tunnels.unwrap())
|
|
||||||
.listen()
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Server implementation for the `bore` service.
|
//! Server implementation for the `bore` service.
|
||||||
|
|
||||||
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
use std::{io, ops::RangeInclusive, sync::Arc, time::Duration};
|
use std::{io, ops::RangeInclusive, sync::Arc, time::Duration};
|
||||||
use std::net::IpAddr;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -25,7 +25,7 @@ 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 where the control server will bind to. Bore clients must reach this.
|
/// IP address where the control server will bind to.
|
||||||
bind_addr: IpAddr,
|
bind_addr: IpAddr,
|
||||||
|
|
||||||
/// IP address where tunnels will listen on.
|
/// IP address where tunnels will listen on.
|
||||||
@@ -34,27 +34,32 @@ pub struct Server {
|
|||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
/// Create a new server with a specified minimum port number.
|
/// Create a new server with a specified minimum port number.
|
||||||
pub fn new(
|
pub fn new(port_range: RangeInclusive<u16>, secret: Option<&str>) -> Self {
|
||||||
port_range: RangeInclusive<u16>,
|
|
||||||
secret: Option<&str>,
|
|
||||||
bind_addr: IpAddr,
|
|
||||||
bind_tunnels: IpAddr,
|
|
||||||
) -> 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),
|
||||||
bind_addr,
|
bind_addr: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
bind_tunnels,
|
bind_tunnels: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the IP address where tunnels will listen on.
|
||||||
|
pub fn set_bind_addr(&mut self, bind_addr: IpAddr) {
|
||||||
|
self.bind_addr = bind_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the IP address where the control server will bind to.
|
||||||
|
pub fn set_bind_tunnels(&mut self, bind_tunnels: IpAddr) {
|
||||||
|
self.bind_tunnels = 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.bind_addr, CONTROL_PORT)).await?;
|
let listener = TcpListener::bind((this.bind_addr, CONTROL_PORT)).await?;
|
||||||
info!(addr = ?this.bind_addr, port = CONTROL_PORT, "server listening");
|
info!(addr = ?this.bind_addr, "server listening");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (stream, addr) = listener.accept().await?;
|
let (stream, addr) = listener.accept().await?;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#![allow(clippy::items_after_test_module)]
|
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::net::IpAddr;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
@@ -20,15 +17,7 @@ lazy_static! {
|
|||||||
|
|
||||||
/// Spawn the server, giving some time for the control port TcpListener to start.
|
/// Spawn the server, giving some time for the control port TcpListener to start.
|
||||||
async fn spawn_server(secret: Option<&str>) {
|
async fn spawn_server(secret: Option<&str>) {
|
||||||
tokio::spawn(
|
tokio::spawn(Server::new(1024..=65535, secret).listen());
|
||||||
Server::new(
|
|
||||||
1024..=65535,
|
|
||||||
secret,
|
|
||||||
"0.0.0.0".parse::<IpAddr>().unwrap(),
|
|
||||||
"0.0.0.0".parse::<IpAddr>().unwrap(),
|
|
||||||
)
|
|
||||||
.listen(),
|
|
||||||
);
|
|
||||||
time::sleep(Duration::from_millis(50)).await;
|
time::sleep(Duration::from_millis(50)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,10 +123,5 @@ async fn very_long_frame() -> Result<()> {
|
|||||||
fn empty_port_range() {
|
fn empty_port_range() {
|
||||||
let min_port = 5000;
|
let min_port = 5000;
|
||||||
let max_port = 3000;
|
let max_port = 3000;
|
||||||
let _ = Server::new(
|
let _ = Server::new(min_port..=max_port, None);
|
||||||
min_port..=max_port,
|
|
||||||
None,
|
|
||||||
"0.0.0.0".parse::<IpAddr>().unwrap(),
|
|
||||||
"0.0.0.0".parse::<IpAddr>().unwrap(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user