mirror of
https://github.com/CompeyDev/ruck.git
synced 2025-01-07 11:29:10 +00:00
feat: custom port support for relay
This commit is contained in:
parent
a45cfc1889
commit
8bce588246
3 changed files with 15 additions and 6 deletions
|
@ -29,5 +29,8 @@ pub enum Commands {
|
||||||
password: String,
|
password: String,
|
||||||
},
|
},
|
||||||
/// Start relay server
|
/// Start relay server
|
||||||
Relay {},
|
Relay {
|
||||||
|
#[clap(value_parser, required = false)]
|
||||||
|
port: Option<u16>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
println!("Receiving password {}", password);
|
println!("Receiving password {}", password);
|
||||||
receive(password).await?
|
receive(password).await?
|
||||||
}
|
}
|
||||||
Commands::Relay {} => {
|
Commands::Relay { port } => {
|
||||||
serve().await?;
|
serve(port.to_owned()).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::handshake::Handshake;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::{copy, AsyncWriteExt};
|
use tokio::io::{copy, AsyncWriteExt};
|
||||||
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
|
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
|
||||||
|
@ -87,9 +88,14 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn serve() -> Result<()> {
|
pub async fn serve(port: Option<u16>) -> Result<()> {
|
||||||
let addr = "127.0.0.1:8080".to_string();
|
let port: u16 = match port {
|
||||||
let listener = TcpListener::bind(&addr).await?;
|
Some(port) => port,
|
||||||
|
None => 8080u16,
|
||||||
|
};
|
||||||
|
|
||||||
|
let addr = SocketAddr::from(([127, 0, 0, 1], port));
|
||||||
|
let listener = TcpListener::bind(addr).await?;
|
||||||
let state = Arc::new(Mutex::new(Shared::new()));
|
let state = Arc::new(Mutex::new(Shared::new()));
|
||||||
let (tx, _rx) = broadcast::channel::<Bytes>(100);
|
let (tx, _rx) = broadcast::channel::<Bytes>(100);
|
||||||
println!("Listening on: {}", addr);
|
println!("Listening on: {}", addr);
|
||||||
|
|
Loading…
Reference in a new issue