cargo build --features disable-tls

pull/14/head
dvkt 4 years ago
parent 28091c03aa
commit 5688e8c4bb

@ -14,8 +14,8 @@ exclude = [
] ]
[features] [features]
tls = [] disable-tls = []
default =["tls"] default =[]
[profile.release] [profile.release]
lto = true lto = true

@ -65,6 +65,10 @@ to build with TLS support on **linux**, you need `openssl` and
sudo apt install -y pkg-config libssl-dev sudo apt install -y pkg-config libssl-dev
to build without TLS support, build with the `no-tls` feature:
## screenies ## screenies
![DOS Archive](./img/dos.png) ![DOS Archive](./img/dos.png)

@ -7,7 +7,7 @@ use std::{
}; };
use termion::input::TermRead; use termion::input::TermRead;
#[cfg(feature = "tls")] #[cfg(not(feature = "disable-tls"))]
use native_tls::TlsConnector; use native_tls::TlsConnector;
mod r#type; mod r#type;
@ -113,16 +113,19 @@ pub fn request(host: &str, port: &str, selector: &str, try_tls: bool) -> Result<
.and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))?; .and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))?;
// attempt tls connection // attempt tls connection
if cfg!(feature = "tls") && try_tls { #[cfg(not(feature = "disable-tls"))]
if let Ok(connector) = TlsConnector::new() { {
let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?; if try_tls {
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?; if let Ok(connector) = TlsConnector::new() {
if let Ok(mut stream) = connector.connect(host, stream) { let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?;
stream.write(format!("{}\r\n", selector).as_ref())?; stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
return Ok(Stream { if let Ok(mut stream) = connector.connect(host, stream) {
io: Box::new(stream), stream.write(format!("{}\r\n", selector).as_ref())?;
tls: true, return Ok(Stream {
}); io: Box::new(stream),
tls: true,
});
}
} }
} }
} }

@ -17,7 +17,7 @@ pub const GIT_REF: &str = env!("GIT_REF");
pub const BUILD_DATE: &str = env!("BUILD_DATE"); pub const BUILD_DATE: &str = env!("BUILD_DATE");
pub const BUG_URL: &str = "https://github.com/dvkt/phetch/issues/new"; pub const BUG_URL: &str = "https://github.com/dvkt/phetch/issues/new";
#[cfg(feature = "tls")] #[cfg(not(feature = "disable-tls"))]
pub const TLS_SUPPORT: &str = "enabled"; pub const TLS_SUPPORT: &str = "enabled";
#[cfg(not(feature = "tls"))] #[cfg(feature = "disable-tls")]
pub const TLS_SUPPORT: &str = "not enabled"; pub const TLS_SUPPORT: &str = "not enabled";

@ -32,7 +32,7 @@ fn run() -> i32 {
"-l" | "--local" | "-local" => url = "gopher://127.0.0.1:7070", "-l" | "--local" | "-local" => url = "gopher://127.0.0.1:7070",
"-t" | "--tls" | "-tls" => { "-t" | "--tls" | "-tls" => {
tls = true; tls = true;
if !cfg!(feature = "tls") { if cfg!(feature = "disable-tls") {
eprintln!("phetch was compiled without TLS support"); eprintln!("phetch was compiled without TLS support");
return 1; return 1;
} }

Loading…
Cancel
Save