Skip to content

Commit

Permalink
diffusion: daProtocolIdleTimeout
Browse files Browse the repository at this point in the history
daProtocolIdleTimeout is passed to connection manager
('cmOutboundIdleTimeout') and inbound governor
('serverInboundIdleTimeout')
  • Loading branch information
coot committed Jun 8, 2021
1 parent c4dfb0f commit 51a7e03
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
Expand Up @@ -94,7 +94,7 @@ inboundGovernor :: forall (muxMode :: MuxMode) socket peerAddr versionNumber m a
versionNumber ByteString m a b
-> StrictTVar m InboundGovernorObservableState
-> m Void
inboundGovernor tracer serverControlChannel protocolIdleTimeout
inboundGovernor tracer serverControlChannel inboundIdleTimeout
connectionManager observableStateVar = do
let state = InboundGovernorState {
igsConnections = Map.empty,
Expand Down Expand Up @@ -198,7 +198,7 @@ inboundGovernor tracer serverControlChannel protocolIdleTimeout
Nothing -> return Nothing

Just csCompletionMap -> do
v <- registerDelay protocolIdleTimeout
v <- registerDelay inboundIdleTimeout
let -- initial state is 'RemoteIdle', if the remote end will not
-- start any responders this will unregister the inbound side.
csRemoteState :: RemoteState m
Expand Down Expand Up @@ -298,7 +298,7 @@ inboundGovernor tracer serverControlChannel protocolIdleTimeout
res <- demotedToColdRemote connectionManager
(remoteAddress connId)
traceWith tracer (TrWaitIdleRemote connId res)
v <- registerDelay protocolIdleTimeout
v <- registerDelay inboundIdleTimeout
let timeoutSTM :: STM m ()
!timeoutSTM = LazySTM.readTVar v >>= check

Expand Down
6 changes: 3 additions & 3 deletions ouroboros-network-framework/src/Ouroboros/Network/Server2.hs
Expand Up @@ -75,7 +75,7 @@ data ServerArguments (muxMode :: MuxMode) socket peerAddr versionNumber bytes m
-- | Time for which all protocols need to be idle to trigger
-- 'DemotedToCold' transition.
--
serverProtocolIdleTimeout :: DiffTime,
serverInboundIdleTimeout :: DiffTime,

-- | Server control var is passed as an argument; this allows to use the
-- server to run and manage responders which needs to be started on
Expand Down Expand Up @@ -120,7 +120,7 @@ run ServerArguments {
serverTracer = tracer,
serverInboundGovernorTracer = inboundGovernorTracer,
serverConnectionLimits,
serverProtocolIdleTimeout,
serverInboundIdleTimeout,
serverConnectionManager,
serverControlChannel,
serverObservableStateVar
Expand All @@ -130,7 +130,7 @@ run ServerArguments {
traceWith tracer (TrServerStarted localAddresses)
let threads = inboundGovernor inboundGovernorTracer
serverControlChannel
serverProtocolIdleTimeout
serverInboundIdleTimeout
serverConnectionManager
serverObservableStateVar
: [ acceptLoop . accept serverSnocket
Expand Down
Expand Up @@ -544,7 +544,7 @@ withBidirectionalConnectionManager name snocket socket localAddress
serverInboundGovernorTracer = (name,) `contramap` nullTracer, -- InboundGovernorTrace
serverConnectionLimits = AcceptedConnectionsLimit maxBound maxBound 0,
serverConnectionManager = connectionManager,
serverProtocolIdleTimeout = protocolIdleTimeout,
serverInboundIdleTimeout = protocolIdleTimeout,
serverControlChannel = inbgovControlChannel,
serverObservableStateVar = observableStateVar
}
Expand Down
32 changes: 21 additions & 11 deletions ouroboros-network/src/Ouroboros/Network/Diffusion.hs
Expand Up @@ -306,14 +306,21 @@ data DiffusionArguments m = DiffusionArguments {
-- ^ run in initiator only mode

, daProtocolIdleTimeout :: DiffTime
-- ^ Timeout which starts once all responder protocols are idle. If the
-- responders stay idle for duration of the timeout, the connection will
-- be demoted, if it wasn't used by the p2p-governor it will be closed.
-- ^ Configures timeout which starts when initiator and responder
-- mini-protocols bacme idle. If the initiators \/ responders stay idle
-- for duration of the timeout, the connection will be closed (reset).
--
-- Applies to 'Unidirectional' as well as 'Duplex' /node-to-node/
-- connections.
-- This timeout should be be long enough to allow the application to read
-- from ingress buffers. The recommended value is @5s@ for nodes facing
-- public network.
--
-- See 'serverProtocolIdleTimeout'.
--
-- Implementation detail
--
-- We use two timeouts that are started in either of the situation:
--
-- * if all initiator protocols are idle and responders become idle
-- * if all responders protocols are idle and initiators become idle

, daTimeWaitTimeout :: DiffTime
-- ^ Time for which /node-to-node/ connections are kept in
Expand Down Expand Up @@ -739,7 +746,8 @@ runDataDiffusion tracers
connectionDataFlow = uncurry localDataFlow,
cmPrunePolicy = Server.randomPrunePolicy localServerStateVar,
cmConnectionsLimits = localConnectionLimits,
cmTimeWaitTimeout = local_TIME_WAIT_TIMEOUT
cmTimeWaitTimeout = local_TIME_WAIT_TIMEOUT,
cmOutboundIdleTimeout = local_PROTOCOL_IDLE_TIMEOUT
}

withConnectionManager
Expand Down Expand Up @@ -767,7 +775,7 @@ runDataDiffusion tracers
serverConnectionLimits = localConnectionLimits,
serverConnectionManager = localConnectionManager,
serverObservableStateVar = localServerStateVar,
serverProtocolIdleTimeout = local_PROTOCOL_IDLE_TIMEOUT
serverInboundIdleTimeout = local_PROTOCOL_IDLE_TIMEOUT
}) Async.wait

--
Expand Down Expand Up @@ -817,7 +825,8 @@ runDataDiffusion tracers
-- than limits imposed by 'cmConnectionsLimits'.
simplePrunePolicy,
cmConnectionsLimits = daAcceptedConnectionsLimit,
cmTimeWaitTimeout = daTimeWaitTimeout
cmTimeWaitTimeout = daTimeWaitTimeout,
cmOutboundIdleTimeout = daProtocolIdleTimeout
}

connectionHandler :: NodeToNodeConnectionHandler InitiatorMode Void
Expand Down Expand Up @@ -940,7 +949,8 @@ runDataDiffusion tracers
HasInitiatorResponder (CMDInInitiatorResponderMode _ serverStateVar) ->
Server.randomPrunePolicy serverStateVar,
cmConnectionsLimits = daAcceptedConnectionsLimit,
cmTimeWaitTimeout = daTimeWaitTimeout
cmTimeWaitTimeout = daTimeWaitTimeout,
cmOutboundIdleTimeout = daProtocolIdleTimeout
}

connectionHandler :: NodeToNodeConnectionHandler InitiatorResponderMode ()
Expand Down Expand Up @@ -1049,7 +1059,7 @@ runDataDiffusion tracers
serverControlChannel = controlChannel,
serverConnectionLimits = daAcceptedConnectionsLimit,
serverConnectionManager = connectionManager,
serverProtocolIdleTimeout = daProtocolIdleTimeout,
serverInboundIdleTimeout = daProtocolIdleTimeout,
serverObservableStateVar = observableStateVar
})
$ \serverThread ->
Expand Down

0 comments on commit 51a7e03

Please sign in to comment.