Skip to content

Commit

Permalink
Allow configuration of outbound substream in OneShotHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
sireliah committed Mar 25, 2020
1 parent 28ea62d commit c2e9397
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions swarm/src/protocols_handler/one_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ where
keep_alive: KeepAlive,
/// After the given duration has elapsed, an inactive connection will shutdown.
inactive_timeout: Duration,
/// Timeout duration for each newly opened outbound substream.
substream_timeout: Duration,
}

impl<TInProto, TOutProto, TOutEvent>
Expand All @@ -67,7 +69,8 @@ where
#[inline]
pub fn new(
listen_protocol: SubstreamProtocol<TInProto>,
inactive_timeout: Duration
inactive_timeout: Duration,
substream_timeout: Duration
) -> Self {
OneShotHandler {
listen_protocol,
Expand All @@ -78,6 +81,7 @@ where
max_dial_negotiated: 8,
keep_alive: KeepAlive::Yes,
inactive_timeout,
substream_timeout,
}
}

Expand Down Expand Up @@ -121,7 +125,13 @@ where
{
#[inline]
fn default() -> Self {
OneShotHandler::new(SubstreamProtocol::new(Default::default()), Duration::from_secs(10))
let inactive_timeout = Duration::from_secs(10);
let substream_timeout = Duration::from_secs(10);
OneShotHandler::new(
SubstreamProtocol::new(Default::default()),
inactive_timeout,
substream_timeout,
)
}
}

Expand Down Expand Up @@ -224,7 +234,8 @@ where
self.dial_negotiated += 1;
return Poll::Ready(
ProtocolsHandlerEvent::OutboundSubstreamRequest {
protocol: SubstreamProtocol::new(self.dial_queue.remove(0)),
protocol: SubstreamProtocol::new(self.dial_queue.remove(0))
.with_timeout(self.substream_timeout),
info: (),
},
);
Expand Down

0 comments on commit c2e9397

Please sign in to comment.