cargo build --features disable-tls

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

@ -14,8 +14,8 @@ exclude = [
]
[features]
tls = []
default =["tls"]
disable-tls = []
default =[]
[profile.release]
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
to build without TLS support, build with the `no-tls` feature:
## screenies
![DOS Archive](./img/dos.png)

@ -7,7 +7,7 @@ use std::{
};
use termion::input::TermRead;
#[cfg(feature = "tls")]
#[cfg(not(feature = "disable-tls"))]
use native_tls::TlsConnector;
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")))?;
// attempt tls connection
if cfg!(feature = "tls") && try_tls {
if let Ok(connector) = TlsConnector::new() {
let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?;
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
if let Ok(mut stream) = connector.connect(host, stream) {
stream.write(format!("{}\r\n", selector).as_ref())?;
return Ok(Stream {
io: Box::new(stream),
tls: true,
});
#[cfg(not(feature = "disable-tls"))]
{
if try_tls {
if let Ok(connector) = TlsConnector::new() {
let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?;
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
if let Ok(mut stream) = connector.connect(host, stream) {
stream.write(format!("{}\r\n", selector).as_ref())?;
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 BUG_URL: &str = "https://github.com/dvkt/phetch/issues/new";
#[cfg(feature = "tls")]
#[cfg(not(feature = "disable-tls"))]
pub const TLS_SUPPORT: &str = "enabled";
#[cfg(not(feature = "tls"))]
#[cfg(feature = "disable-tls")]
pub const TLS_SUPPORT: &str = "not enabled";

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

Loading…
Cancel
Save