mewo
This commit is contained in:
parent
40af253450
commit
17fb7ed120
14
src/main.rs
14
src/main.rs
|
|
@ -76,7 +76,7 @@ fn get_config_file_source() -> impl Source {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
@ -88,13 +88,16 @@ async fn main() {
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
Commands::CliClient => {
|
Commands::CliClient => {
|
||||||
let ip_addr_str = config().get_string("remote_endpoint").unwrap();
|
let ip_addr_str = config().get_string("remote_endpoint")?;
|
||||||
let ip_sock = SocketAddr::from_str(&ip_addr_str).unwrap();
|
let ip_sock = SocketAddr::from_str(&ip_addr_str)?;
|
||||||
|
let client_endpoint = quic::client::make_client_endpoint(ip_sock.clone(), None)?;
|
||||||
|
let client = client_endpoint.connect(ip_sock, "localhost")?.await?;
|
||||||
|
println!("[client] connected: addr={}", client.remote_address());
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Shadow => {
|
Commands::Shadow => {
|
||||||
bininfo::print_info();
|
bininfo::print_info();
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::GuiClient => {
|
Commands::GuiClient => {
|
||||||
|
|
@ -102,7 +105,7 @@ async fn main() {
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
}
|
}
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Devtest => {
|
Commands::Devtest => {
|
||||||
|
|
@ -121,4 +124,5 @@ async fn main() {
|
||||||
|
|
||||||
//handling anything here for gui wont work
|
//handling anything here for gui wont work
|
||||||
println!("exit");
|
println!("exit");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,18 @@ use rustls::pki_types::CertificateDer;
|
||||||
///
|
///
|
||||||
/// - server_certs: a list of trusted certificates in DER format.
|
/// - server_certs: a list of trusted certificates in DER format.
|
||||||
fn configure_client(
|
fn configure_client(
|
||||||
server_certs: &[&[u8]],
|
server_certs: Option<&[&[u8]]>,
|
||||||
) -> Result<ClientConfig, Box<dyn Error + Send + Sync + 'static>> {
|
) -> Result<ClientConfig, Box<dyn Error + Send + Sync + 'static>> {
|
||||||
let mut certs = rustls::RootCertStore::empty();
|
if let Some(server_certs) = server_certs {
|
||||||
for cert in server_certs {
|
let mut certs = rustls::RootCertStore::empty();
|
||||||
certs.add(CertificateDer::from(*cert))?;
|
for cert in server_certs {
|
||||||
}
|
certs.add(CertificateDer::from(*cert))?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(ClientConfig::with_root_certificates(Arc::new(certs))?)
|
Ok(ClientConfig::with_root_certificates(Arc::new(certs))?)
|
||||||
|
} else {
|
||||||
|
Ok(ClientConfig::with_platform_verifier())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a QUIC endpoint configured for use a client only.
|
/// Constructs a QUIC endpoint configured for use a client only.
|
||||||
|
|
@ -28,7 +32,7 @@ fn configure_client(
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn make_client_endpoint(
|
pub fn make_client_endpoint(
|
||||||
bind_addr: SocketAddr,
|
bind_addr: SocketAddr,
|
||||||
server_certs: &[&[u8]],
|
server_certs: Option<&[&[u8]]>,
|
||||||
) -> Result<Endpoint, Box<dyn Error + Send + Sync + 'static>> {
|
) -> Result<Endpoint, Box<dyn Error + Send + Sync + 'static>> {
|
||||||
let client_cfg = configure_client(server_certs)?;
|
let client_cfg = configure_client(server_certs)?;
|
||||||
let mut endpoint = Endpoint::client(bind_addr)?;
|
let mut endpoint = Endpoint::client(bind_addr)?;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
mod server;
|
pub(crate) mod server;
|
||||||
mod client;
|
pub(crate) mod client;
|
||||||
Loading…
Reference in a new issue