Skip to content

Commit a68deef

Browse files
committed
Let onion_dial use onion_timeout
Signed-off-by: Eval EXEC <execvy@gmail.com>
1 parent a982098 commit a68deef

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

tentacle/src/builder.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{io, sync::Arc, time::Duration};
22

3-
use crate::service::config::{ServiceTimeout, TransformerContext};
3+
use crate::service::config::TransformerContext;
44
use nohash_hasher::IntMap;
55
use tokio_util::codec::LengthDelimitedCodec;
66

@@ -83,12 +83,17 @@ where
8383

8484
/// Timeout for handshake and connect
8585
///
86-
/// Default timeout is 10 second, default onion_timeout is 120 second
87-
pub fn timeout(mut self, timeout: Duration, onion_timeout: Duration) -> Self {
88-
self.config.timeout = ServiceTimeout {
89-
timeout,
90-
onion_timeout,
91-
};
86+
/// Default timeout is 10 second
87+
pub fn timeout(mut self, timeout: Duration) -> Self {
88+
self.config.timeout.timeout = timeout;
89+
self
90+
}
91+
92+
/// Onion Timeout for handshake and connect
93+
///
94+
/// Default onion_timeout is 120 second
95+
pub fn onion_timeout(mut self, onion_timeout: Duration) -> Self {
96+
self.config.timeout.onion_timeout = onion_timeout;
9297
self
9398
}
9499

tentacle/src/service.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ where
170170
handshake_type,
171171
multi_transport: {
172172
#[cfg(target_family = "wasm")]
173-
let transport = MultiTransport::new(config.timeout);
173+
let transport = MultiTransport::new(config.timeout.timeout);
174174
#[allow(clippy::let_and_return)]
175175
#[cfg(not(target_family = "wasm"))]
176176
let transport = MultiTransport::new(config.timeout, config.tcp_config.clone());
@@ -309,7 +309,7 @@ where
309309
handshake_type: self.handshake_type.clone(),
310310
event_sender: self.session_event_sender.clone(),
311311
max_frame_length: self.config.max_frame_length,
312-
timeout: self.config.timeout,
312+
timeout: self.config.timeout.timeout,
313313
listen_addr: listen_address,
314314
future_task_sender: self.future_task_sender.clone(),
315315
};
@@ -362,7 +362,7 @@ where
362362
self.dial_protocols.insert(address.clone(), target);
363363

364364
let handshake_type = self.handshake_type.clone();
365-
let timeout = self.config.timeout;
365+
let timeout = self.config.timeout.timeout;
366366
let max_frame_length = self.config.max_frame_length;
367367

368368
let mut sender = self.session_event_sender.clone();
@@ -542,7 +542,7 @@ where
542542
handshake_type: self.handshake_type.clone(),
543543
event_sender: self.session_event_sender.clone(),
544544
max_frame_length: self.config.max_frame_length,
545-
timeout: self.config.timeout,
545+
timeout: self.config.timeout.timeout,
546546
}
547547
.handshake(socket);
548548

@@ -681,7 +681,7 @@ where
681681
});
682682

683683
let meta = SessionMeta::new(
684-
self.config.timeout,
684+
self.config.timeout.timeout,
685685
session_context.clone(),
686686
service_event_sender,
687687
self.service_context.control().clone(),

tentacle/src/service/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ use tokio_rustls::rustls::{ClientConfig, ServerConfig};
2020
/// Default max buffer size
2121
const MAX_BUF_SIZE: usize = 24 * 1024 * 1024;
2222

23+
#[derive(Clone, Copy)]
2324
pub(crate) struct ServiceTimeout {
24-
timeout: Duration,
25-
onion_timeout: Duration,
25+
pub timeout: Duration,
26+
pub onion_timeout: Duration,
2627
}
2728

2829
impl Default for ServiceTimeout {

tentacle/src/transports/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mod os {
9393

9494
use crate::{
9595
runtime::{TcpListener, TcpStream},
96-
service::config::TcpConfig,
96+
service::config::{ServiceTimeout, TcpConfig},
9797
};
9898

9999
use futures::{FutureExt, StreamExt, prelude::Stream};
@@ -136,15 +136,15 @@ mod os {
136136

137137
#[derive(Clone)]
138138
pub(crate) struct MultiTransport {
139-
pub(crate) timeout: Duration,
139+
pub(crate) timeout: ServiceTimeout,
140140
pub(crate) tcp_config: TcpConfig,
141141
pub(crate) listens_upgrade_modes: Arc<crate::lock::Mutex<HashMap<SocketAddr, UpgradeMode>>>,
142142
#[cfg(feature = "tls")]
143143
pub(crate) tls_config: Option<TlsConfig>,
144144
}
145145

146146
impl MultiTransport {
147-
pub fn new(timeout: Duration, tcp_config: TcpConfig) -> Self {
147+
pub fn new(timeout: ServiceTimeout, tcp_config: TcpConfig) -> Self {
148148
MultiTransport {
149149
timeout,
150150
tcp_config,
@@ -217,20 +217,23 @@ mod os {
217217
fn dial(self, address: Multiaddr) -> Result<Self::DialFuture> {
218218
match find_type(&address) {
219219
TransportType::Tcp => {
220-
match TcpTransport::new(self.timeout, self.tcp_config.tcp).dial(address) {
220+
match TcpTransport::new(self.timeout.timeout, self.tcp_config.tcp).dial(address)
221+
{
221222
Ok(res) => Ok(MultiDialFuture::Tcp(res)),
222223
Err(e) => Err(e),
223224
}
224225
}
225226
TransportType::Onion => {
226-
match OnionTransport::new(self.timeout, self.tcp_config.tcp).dial(address) {
227+
match OnionTransport::new(self.timeout.onion_timeout, self.tcp_config.tcp)
228+
.dial(address)
229+
{
227230
Ok(res) => Ok(MultiDialFuture::Tcp(res)),
228231
Err(e) => Err(e),
229232
}
230233
}
231234
#[cfg(feature = "ws")]
232235
TransportType::Ws => {
233-
match WsTransport::new(self.timeout, self.tcp_config.ws).dial(address) {
236+
match WsTransport::new(self.timeout.timeout, self.tcp_config.ws).dial(address) {
234237
Ok(future) => Ok(MultiDialFuture::Ws(future)),
235238
Err(e) => Err(e),
236239
}
@@ -247,7 +250,7 @@ mod os {
247250
let tls_config = self.tls_config.ok_or_else(|| {
248251
TransportErrorKind::TlsError("tls config is not set".to_string())
249252
})?;
250-
TlsTransport::new(self.timeout, tls_config, self.tcp_config.tls)
253+
TlsTransport::new(self.timeout.timeout, tls_config, self.tcp_config.tls)
251254
.dial(address)
252255
.map(MultiDialFuture::Tls)
253256
}

tentacle/src/transports/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl TcpTransport {
6262
listen_mode: TcpListenMode,
6363
) -> Self {
6464
Self {
65-
timeout: multi_transport.timeout,
65+
timeout: multi_transport.timeout.timeout,
6666
tcp_config: match listen_mode {
6767
TcpListenMode::Tcp => multi_transport.tcp_config.tcp,
6868
#[cfg(feature = "ws")]

0 commit comments

Comments
 (0)