Skip to content

Commit

Permalink
make tls optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrchien committed Aug 20, 2022
1 parent 7c225bb commit 24a44fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kaminari-cmd"
version = "0.5.6"
version = "0.5.7"
edition = "2021"
authors = ["zephyr <[email protected]>"]
repository = "https://github.com/zephyrchien/kaminari/cmd"
Expand All @@ -11,7 +11,7 @@ license = "GPL-3.0"
[dependencies]
anyhow = "1"
realm_io = "0.3.2"
kaminari = { version = "0.9.2", features = ["ws", "tls"] }
kaminari = { version = "0.9.2", features = ["ws"] }
tokio = { version = "1.9", features = ["rt", "net", "macros"] }

[[bin]]
Expand All @@ -21,3 +21,8 @@ path = "src/client.rs"
[[bin]]
name = "kaminaris"
path = "src/server.rs"

[features]
default = ["tls-rustls"]
tls-rustls = ["kaminari/tls"]
tls-openssl = []
15 changes: 14 additions & 1 deletion cmd/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use tokio::net::{TcpListener, TcpStream};
use realm_io::{CopyBuffer, bidi_copy_buf};

use kaminari::opt;
use kaminari::trick::Ref;
use kaminari::AsyncConnect;
use kaminari::nop::NopConnect;
use kaminari::ws::WsConnect;
#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
use kaminari::tls::TlsConnect;
use kaminari::trick::Ref;

use kaminari_cmd::{Endpoint, parse_cmd, parse_env};

Expand All @@ -18,6 +19,7 @@ async fn main() -> Result<()> {
let (Endpoint { local, remote }, options) = parse_env().or_else(|_| parse_cmd())?;

let ws = opt::get_ws_conf(&options);
#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
let tls = opt::get_tls_client_conf(&options);

eprintln!("listen: {}", &local);
Expand All @@ -27,6 +29,7 @@ async fn main() -> Result<()> {
eprintln!("ws: {}", ws)
}

#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
if let Some(tls) = &tls {
eprintln!("tls: {}", &tls);
}
Expand Down Expand Up @@ -72,6 +75,7 @@ async fn main() -> Result<()> {
}
}

#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
match (ws, tls) {
(None, None) => {
let client = NopConnect {};
Expand All @@ -91,6 +95,15 @@ async fn main() -> Result<()> {
}
};

#[cfg(not(any(feature="tls-rustls", feature="tls-openssl")))]
if let Some(ws) = ws {
let client = WsConnect::new(NopConnect {}, ws);
run_ws_each!(client);
} else {
let client = NopConnect {};
run!(Ref::new(&client));
}

Ok(())
}

Expand Down
16 changes: 15 additions & 1 deletion cmd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use tokio::net::{TcpListener, TcpStream};
use realm_io::{CopyBuffer, bidi_copy_buf};

use kaminari::opt;
use kaminari::trick::Ref;
use kaminari::AsyncAccept;
use kaminari::nop::NopAccept;
use kaminari::ws::WsAccept;
#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
use kaminari::tls::TlsAccept;
use kaminari::trick::Ref;

use kaminari_cmd::{Endpoint, parse_cmd, parse_env};

Expand All @@ -28,6 +29,8 @@ async fn main() -> Result<()> {
.or_else(|_| parse_cmd())?;

let ws = opt::get_ws_conf(&options);

#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
let tls = opt::get_tls_server_conf(&options);

eprintln!("listen: {}", &local);
Expand All @@ -37,6 +40,7 @@ async fn main() -> Result<()> {
eprintln!("ws: {}", ws)
}

#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
if let Some(tls) = &tls {
eprintln!("tls: {}", &tls);
}
Expand All @@ -60,6 +64,7 @@ async fn main() -> Result<()> {
};
}

#[cfg(any(feature="tls-rustls", feature="tls-openssl"))]
match (ws, tls) {
(None, None) => {
let server = NopAccept {};
Expand All @@ -79,6 +84,15 @@ async fn main() -> Result<()> {
}
};

#[cfg(not(any(feature="tls-rustls", feature="tls-openssl")))]
if let Some(ws) = ws {
let server = WsAccept::new(NopAccept {}, ws);
run!(Ref::new(&server));
} else {
let server = NopAccept {};
run!(Ref::new(&server));
}

Ok(())
}

Expand Down

0 comments on commit 24a44fa

Please sign in to comment.