Skip to content

Commit

Permalink
handshake: remove versioned application from HandshakeArguments
Browse files Browse the repository at this point in the history
This makes it easier to use HandshakeArguments in Diffusion
  • Loading branch information
coot committed Jul 20, 2021
1 parent ff4a8fd commit e6afc4e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
10 changes: 5 additions & 5 deletions ouroboros-network-framework/demo/connection-manager.hs
Expand Up @@ -245,14 +245,14 @@ withBidirectionalConnectionManager snocket socket
haHandshakeTracer = ("handshake",) `contramap` debugTracer,
haHandshakeCodec = unversionedHandshakeCodec,
haVersionDataCodec = cborTermVersionDataCodec unversionedProtocolDataCodec,
haVersions = unversionedProtocol
(serverApplication
hotRequestsVar
warmRequestsVar
establishedRequestsVar),
haAcceptVersion = acceptableVersion,
haTimeLimits = timeLimitsHandshake
}
(unversionedProtocol
(serverApplication
hotRequestsVar
warmRequestsVar
establishedRequestsVar))
(mainThreadId, debugMuxErrorRethrowPolicy
<> debugIOErrorRethrowPolicy))
(\_ -> HandshakeFailure)
Expand Down
Expand Up @@ -190,14 +190,16 @@ makeConnectionHandler
-- evidence that we can use mux with it.
-> MiniProtocolBundle muxMode
-> HandshakeArguments (ConnectionId peerAddr) versionNumber versionData m
(OuroborosBundle muxMode peerAddr ByteString m a b)
-> Versions versionNumber versionData
(OuroborosBundle muxMode peerAddr ByteString m a b)
-> (ThreadId m, RethrowPolicy)
-- ^ 'ThreadId' and rethrow policy. Rethrow policy might throw an async
-- exception to that thread, when trying to terminate the process.
-> MuxConnectionHandler muxMode socket peerAddr versionNumber versionData ByteString m a b
makeConnectionHandler muxTracer singMuxMode
miniProtocolBundle
handshakeArguments
versionedApplication
(mainThreadId, rethrowPolicy) =
ConnectionHandler {
connectionHandler =
Expand Down Expand Up @@ -263,7 +265,8 @@ makeConnectionHandler muxTracer singMuxMode
hsResult <-
unmask (runHandshakeClient handshakeBearer
connectionId
handshakeArguments)
handshakeArguments
versionedApplication)
-- 'runHandshakeClient' only deals with protocol limit errors or
-- handshake negotiation failures, but not with 'IOException's or
-- 'MuxError's.
Expand Down Expand Up @@ -329,7 +332,8 @@ makeConnectionHandler muxTracer singMuxMode
hsResult <-
unmask (runHandshakeServer handshakeBearer
connectionId
handshakeArguments)
handshakeArguments
versionedApplication)
-- 'runHandshakeServer' only deals with protocol limit errors or
-- handshake negotiation failures, but not with 'IOException's or
-- 'MuxError's.
Expand Down
Expand Up @@ -9,6 +9,7 @@ module Ouroboros.Network.Protocol.Handshake
( runHandshakeClient
, runHandshakeServer
, HandshakeArguments (..)
, Versions (..)
, HandshakeException (..)
, HandshakeProtocolError (..)
, RefuseReason (..)
Expand Down Expand Up @@ -79,7 +80,7 @@ tryHandshake doHandshake = do

-- | Common arguments for both 'Handshake' client & server.
--
data HandshakeArguments connectionId vNumber vData m application = HandshakeArguments {
data HandshakeArguments connectionId vNumber vData m = HandshakeArguments {
-- | 'Handshake' tracer
--
haHandshakeTracer :: Tracer m (WithMuxBearer connectionId
Expand All @@ -94,9 +95,6 @@ data HandshakeArguments connectionId vNumber vData m application = HandshakeArgu
haVersionDataCodec
:: VersionDataCodec CBOR.Term vNumber vData,

-- | versioned application aggreed upon with the 'Handshake' protocol.
haVersions :: Versions vNumber vData application,

-- | accept version, first argument is our version data the second
-- argument is the remote version data.
haAcceptVersion :: vData -> vData -> Accept vData,
Expand All @@ -121,7 +119,8 @@ runHandshakeClient
)
=> MuxBearer m
-> connectionId
-> HandshakeArguments connectionId vNumber vData m application
-> HandshakeArguments connectionId vNumber vData m
-> Versions vNumber vData application
-> m (Either (HandshakeException vNumber)
(application, vNumber, vData))
runHandshakeClient bearer
Expand All @@ -130,10 +129,10 @@ runHandshakeClient bearer
haHandshakeTracer,
haHandshakeCodec,
haVersionDataCodec,
haVersions,
haAcceptVersion,
haTimeLimits
} =
}
versions =
tryHandshake
(fst <$>
runPeerWithLimits
Expand All @@ -142,7 +141,7 @@ runHandshakeClient bearer
byteLimitsHandshake
haTimeLimits
(fromChannel (muxBearerAsChannel bearer handshakeProtocolNum InitiatorDir))
(handshakeClientPeer haVersionDataCodec haAcceptVersion haVersions))
(handshakeClientPeer haVersionDataCodec haAcceptVersion versions))


-- | Run server side of the 'Handshake' protocol.
Expand All @@ -158,7 +157,8 @@ runHandshakeServer
)
=> MuxBearer m
-> connectionId
-> HandshakeArguments connectionId vNumber vData m application
-> HandshakeArguments connectionId vNumber vData m
-> Versions vNumber vData application
-> m (Either
(HandshakeException vNumber)
(application, vNumber, vData))
Expand All @@ -168,10 +168,10 @@ runHandshakeServer bearer
haHandshakeTracer,
haHandshakeCodec,
haVersionDataCodec,
haVersions,
haAcceptVersion,
haTimeLimits
} =
}
versions =
tryHandshake
(fst <$>
runPeerWithLimits
Expand All @@ -180,4 +180,4 @@ runHandshakeServer bearer
byteLimitsHandshake
haTimeLimits
(fromChannel (muxBearerAsChannel bearer handshakeProtocolNum ResponderDir))
(handshakeServerPeer haVersionDataCodec haAcceptVersion haVersions))
(handshakeServerPeer haVersionDataCodec haAcceptVersion versions))
5 changes: 2 additions & 3 deletions ouroboros-network-framework/src/Ouroboros/Network/Socket.hs
Expand Up @@ -99,7 +99,6 @@ import Ouroboros.Network.ErrorPolicy
import Ouroboros.Network.Subscription.PeerState
import Ouroboros.Network.Protocol.Handshake
import Ouroboros.Network.Protocol.Handshake.Type
import Ouroboros.Network.Protocol.Handshake.Version
import Ouroboros.Network.Protocol.Handshake.Codec
import Ouroboros.Network.IOManager (IOManager)
import Ouroboros.Network.Snocket (Snocket)
Expand Down Expand Up @@ -256,10 +255,10 @@ connectToNode' sn handshakeCodec handshakeTimeLimits versionDataCodec NetworkCon
haHandshakeTracer = nctHandshakeTracer,
haHandshakeCodec = handshakeCodec,
haVersionDataCodec = versionDataCodec,
haVersions = versions,
haAcceptVersion = acceptVersion,
haTimeLimits = handshakeTimeLimits
}
versions
ts_end <- getMonotonicTime
case app_e of
Left (HandshakeProtocolLimit err) -> do
Expand Down Expand Up @@ -383,10 +382,10 @@ beginConnection sn muxTracer handshakeTracer handshakeCodec handshakeTimeLimits
haHandshakeTracer = handshakeTracer,
haHandshakeCodec = handshakeCodec,
haVersionDataCodec = versionDataCodec,
haVersions = versions,
haAcceptVersion = acceptVersion,
haTimeLimits = handshakeTimeLimits
}
versions

case app_e of
Left (HandshakeProtocolLimit err) -> do
Expand Down
Expand Up @@ -336,10 +336,10 @@ withInitiatorOnlyConnectionManager name timeouts trTracer snocket localAddr next
haHandshakeTracer = (name,) `contramap` nullTracer,
haHandshakeCodec = unversionedHandshakeCodec,
haVersionDataCodec = cborTermVersionDataCodec unversionedProtocolDataCodec,
haVersions = unversionedProtocol clientApplication,
haAcceptVersion = acceptableVersion,
haTimeLimits = noTimeLimitsHandshake
}
(unversionedProtocol clientApplication)
(mainThreadId, debugMuxErrorRethrowPolicy
<> debugMuxRuntimeErrorRethrowPolicy
<> debugIOErrorRethrowPolicy
Expand Down Expand Up @@ -510,10 +510,10 @@ withBidirectionalConnectionManager name timeouts trTracer snocket socket localAd
haHandshakeTracer = WithName name `contramap` nullTracer,
haHandshakeCodec = unversionedHandshakeCodec,
haVersionDataCodec = cborTermVersionDataCodec unversionedProtocolDataCodec,
haVersions = unversionedProtocol serverApplication,
haAcceptVersion = acceptableVersion,
haTimeLimits = noTimeLimitsHandshake
}
(unversionedProtocol serverApplication)
(mainThreadId, debugMuxErrorRethrowPolicy
<> debugMuxRuntimeErrorRethrowPolicy
<> debugIOErrorRethrowPolicy
Expand Down
17 changes: 8 additions & 9 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Expand Up @@ -629,16 +629,15 @@ runDataDiffusion tracers
haVersionDataCodec =
cborTermVersionDataCodec
NodeToClient.nodeToClientCodecCBORTerm,
haVersions =
(\(OuroborosApplication apps)
-> Bundle
(WithHot apps)
(WithWarm (\_ _ -> []))
(WithEstablished (\_ _ -> [])))
<$> daLocalResponderApplication,
haAcceptVersion = acceptableVersion,
haTimeLimits = noTimeLimitsHandshake
}
( ( \ (OuroborosApplication apps)
-> Bundle
(WithHot apps)
(WithWarm (\_ _ -> []))
(WithEstablished (\_ _ -> []))
) <$> daLocalResponderApplication )
(mainThreadId, rethrowPolicy <> daLocalRethrowPolicy)

localConnectionManagerArguments
Expand Down Expand Up @@ -754,10 +753,10 @@ runDataDiffusion tracers
haVersionDataCodec =
cborTermVersionDataCodec
NodeToNode.nodeToNodeCodecCBORTerm,
haVersions = daApplicationInitiatorMode,
haAcceptVersion = acceptableVersion,
haTimeLimits = timeLimitsHandshake
}
daApplicationInitiatorMode
(mainThreadId, rethrowPolicy <> daRethrowPolicy)

withConnectionManager
Expand Down Expand Up @@ -890,10 +889,10 @@ runDataDiffusion tracers
haVersionDataCodec =
cborTermVersionDataCodec
NodeToNode.nodeToNodeCodecCBORTerm,
haVersions = daApplicationInitiatorResponderMode,
haAcceptVersion = acceptableVersion,
haTimeLimits = timeLimitsHandshake
}
daApplicationInitiatorResponderMode
(mainThreadId, rethrowPolicy <> daRethrowPolicy)

withConnectionManager
Expand Down

0 comments on commit e6afc4e

Please sign in to comment.