diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-29 22:14:58 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-29 22:14:58 +0100 |
| commit | 1bddb95affde7882fd6b5ae2e5bf5f798c20e9fc (patch) | |
| tree | bc2b6b3a0f85ae1a1d87f72adead8e16f0d4ccd5 | |
| parent | v2.3.2: group hosts by certificate fingerprint (diff) | |
| download | zagan-bet-1bddb95affde7882fd6b5ae2e5bf5f798c20e9fc.tar.gz zagan-bet-1bddb95affde7882fd6b5ae2e5bf5f798c20e9fc.zip | |
initial connection timeout set to 10s
| -rw-r--r-- | src/bin/client/connection.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/bin/client/connection.rs b/src/bin/client/connection.rs index 363a2a9..44cfea9 100644 --- a/src/bin/client/connection.rs +++ b/src/bin/client/connection.rs | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | use zagan_bet::client::database; | ||
| 2 | use zagan_bet::client::ui::first_contact_lines; | ||
| 3 | use crate::tls::TlsConnector; | 1 | use crate::tls::TlsConnector; |
| 2 | use parking_lot::Mutex; | ||
| 4 | use rusqlite::Connection; | 3 | use rusqlite::Connection; |
| 5 | use std::io::{Read, Write}; | 4 | use std::io::{Read, Write}; |
| 6 | use std::net::TcpStream; | 5 | use std::net::TcpStream; |
| 7 | use std::sync::mpsc; | 6 | use std::sync::mpsc; |
| 8 | use parking_lot::Mutex; | ||
| 9 | use std::thread; | 7 | use std::thread; |
| 10 | use std::time::{Duration, Instant}; | 8 | use std::time::{Duration, Instant}; |
| 9 | use zagan_bet::client::database; | ||
| 10 | use zagan_bet::client::ui::first_contact_lines; | ||
| 11 | 11 | ||
| 12 | static UNSAFE_MODE: Mutex<bool> = Mutex::new(false); | 12 | static UNSAFE_MODE: Mutex<bool> = Mutex::new(false); |
| 13 | 13 | ||
| @@ -35,7 +35,8 @@ pub fn connect( | |||
| 35 | thread::spawn(move || { | 35 | thread::spawn(move || { |
| 36 | let outcome = (|| -> ConnectResult { | 36 | let outcome = (|| -> ConnectResult { |
| 37 | let tcp = TcpStream::connect(&addr_str)?; | 37 | let tcp = TcpStream::connect(&addr_str)?; |
| 38 | let connector = TlsConnector::new(&server_name, stored_fingerprint.clone(), unsafe_mode)?; | 38 | let connector = |
| 39 | TlsConnector::new(&server_name, stored_fingerprint.clone(), unsafe_mode)?; | ||
| 39 | let tls_stream = connector.connect(tcp)?; | 40 | let tls_stream = connector.connect(tcp)?; |
| 40 | let fp = connector.observed_fingerprint(); | 41 | let fp = connector.observed_fingerprint(); |
| 41 | Ok((TlsStream { inner: tls_stream }, fp)) | 42 | Ok((TlsStream { inner: tls_stream }, fp)) |
| @@ -44,11 +45,11 @@ pub fn connect( | |||
| 44 | }); | 45 | }); |
| 45 | 46 | ||
| 46 | // Channel carries (stream, observed fingerprint). | 47 | // Channel carries (stream, observed fingerprint). |
| 47 | let (tls, observed) = match rx.recv_timeout(Duration::from_secs(3)) { | 48 | let (tls, observed) = match rx.recv_timeout(Duration::from_secs(10)) { |
| 48 | Ok(Ok((tls, fp))) => (tls, fp), | 49 | Ok(Ok((tls, fp))) => (tls, fp), |
| 49 | Ok(Err(e)) => return Err(Box::new(TrustError(format!("{e}")))), | 50 | Ok(Err(e)) => return Err(Box::new(TrustError(format!("{e}")))), |
| 50 | Err(mpsc::RecvTimeoutError::Timeout) => { | 51 | Err(mpsc::RecvTimeoutError::Timeout) => { |
| 51 | return Err("Connection timed out after 3 seconds".into()) | 52 | return Err("Connection timed out after 3 seconds".into()); |
| 52 | } | 53 | } |
| 53 | Err(_) => return Err("Connection attempt failed".into()), | 54 | Err(_) => return Err("Connection attempt failed".into()), |
| 54 | }; | 55 | }; |
| @@ -130,10 +131,7 @@ impl TlsStream { | |||
| 130 | self.inner.read_available_line() | 131 | self.inner.read_available_line() |
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | pub fn set_read_timeout( | 134 | pub fn set_read_timeout(&self, duration: Option<std::time::Duration>) -> std::io::Result<()> { |
| 134 | &self, | ||
| 135 | duration: Option<std::time::Duration>, | ||
| 136 | ) -> std::io::Result<()> { | ||
| 137 | self.inner.set_read_timeout(duration) | 135 | self.inner.set_read_timeout(duration) |
| 138 | } | 136 | } |
| 139 | } | 137 | } |
