mirror of https://github.com/dswd/vpncloud.git
Add configurable WS port
This commit is contained in:
parent
a113b3ba22
commit
bd0d102358
|
@ -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")]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()?;
|
||||
|
|
Loading…
Reference in New Issue