Add configurable WS port

This commit is contained in:
Dennis Schwerdel 2021-02-04 21:19:05 +01:00
parent a113b3ba22
commit bd0d102358
4 changed files with 14 additions and 8 deletions

View File

@ -499,7 +499,13 @@ pub enum Command {
#[structopt(name = "genkey", alias = "gen-key")]
GenKey,
WsProxy,
/// Run a websocket proxy
#[structopt(alias = "wsproxy")]
WsProxy {
/// Websocket listen address IP:PORT
#[structopt(long, short, default_value="3210")]
listen: String
},
/// Migrate an old config file
#[structopt(alias = "migrate")]

View File

@ -268,8 +268,8 @@ fn main() {
Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
return
}
Command::WsProxy => {
wsproxy::run_proxy();
Command::WsProxy { listen } => {
try_fail!(wsproxy::run_proxy(&listen), "Failed to run websocket proxy: {:?}");
}
}
return

View File

@ -35,7 +35,7 @@ pub trait Socket: AsRawFd + Sized {
fn create_port_forwarding(&self) -> Option<PortForwarding>;
}
fn parse_listen(addr: &str) -> SocketAddr {
pub fn parse_listen(addr: &str) -> SocketAddr {
if let Some(addr) = addr.strip_prefix("*:") {
let port = try_fail!(addr.parse::<u16>(), "Invalid port: {}");
SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port)

View File

@ -1,5 +1,5 @@
use super::{
net::{mapped_addr, get_ip, Socket},
net::{mapped_addr, get_ip, parse_listen, Socket},
poll::{WaitImpl, WaitResult},
port_forwarding::PortForwarding,
util::MsgBuffer
@ -87,9 +87,9 @@ fn serve_proxy_connection(stream: TcpStream) -> Result<(), io::Error> {
Ok(())
}
pub fn run_proxy() -> Result<(), io::Error> {
// TODO: configurable listen
let server = TcpListener::bind("127.0.0.1:9001")?;
pub fn run_proxy(listen: &str) -> Result<(), io::Error> {
let addr = parse_listen(listen);
let server = TcpListener::bind(addr)?;
for stream in server.incoming() {
let stream = stream?;
let peer = stream.peer_addr()?;