Skip to content

Commit

Permalink
o-network integration
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodile-dentist committed Dec 5, 2024
1 parent 314e9af commit abd035b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
27 changes: 18 additions & 9 deletions cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ import Ouroboros.Network.Protocol.Handshake.Version (acceptableVersion
simpleSingletonVersions)
import Ouroboros.Network.Snocket (LocalAddress, LocalSocket, Snocket,
localAddressFromPath, localSnocket, makeLocalBearer)
import Ouroboros.Network.Socket (ConnectionId (..), HandshakeCallbacks (..),
connectToNode, nullNetworkConnectTracers)
import Ouroboros.Network.Socket (ConnectionId (..), ConnectToArgs (..),
HandshakeCallbacks (..), connectToNode, nullNetworkConnectTracers)

import Codec.CBOR.Term (Term)
import Control.Exception (throwIO)
import qualified Data.ByteString.Lazy as LBS
import Data.Void (Void)
import Data.Void (Void, absurd)
import Data.Word (Word32)
import qualified System.Metrics.Configuration as EKGF
import System.Metrics.Network.Acceptor (acceptEKGMetricsInit)
Expand Down Expand Up @@ -99,22 +100,30 @@ doConnectToForwarder
LBS.ByteString IO () Void
-> IO ()
doConnectToForwarder snocket address netMagic timeLimits app =
connectToNode
done <- connectToNode

Check failure on line 103 in cardano-tracer/src/Cardano/Tracer/Acceptors/Client.hs

View workflow job for this annotation

GitHub Actions / build

Error: Parse error: on input `<-' ▫︎ Found: " -> IO ()\n doConnectToForwarder snocket address netMagic timeLimits app =\n> done <- connectToNode\n snocket\n makeLocalBearer\n"
snocket
makeLocalBearer
args
mempty -- LocalSocket does not require to be configured
(codecHandshake forwardingVersionCodec)
timeLimits
(cborTermVersionDataCodec forwardingCodecCBORTerm)
nullNetworkConnectTracers
(HandshakeCallbacks acceptableVersion queryVersion)
(simpleSingletonVersions
ForwardingV_1
(ForwardingVersionData $ NetworkMagic netMagic)
app
)
Nothing
address
case done of
Left err -> throwIO err
Right choice -> case choice of
Left () -> return ()
Right void -> absurd void
where
args = ConnectToArgs {
ctaHandshakeCodec = codecHandshake forwardingVersionCodec,
ctaHandshakeTimeLimits = timeLimits,
ctaVersionDataCodec = cborTermVersionDataCodec forwardingCodecCBORTerm,
ctaConnectTracers = nullNetworkConnectTracers,
ctaHandshakeCallbacks = HandshakeCallbacks acceptableVersion queryVersion }

runEKGAcceptorInit
:: TracerEnv
Expand Down
30 changes: 19 additions & 11 deletions cardano-tracer/test/Cardano/Tracer/Test/Forwarder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ import Ouroboros.Network.Protocol.Handshake.Version (acceptableVersion
simpleSingletonVersions)
import Ouroboros.Network.Snocket (MakeBearer, Snocket, localAddressFromPath, localSnocket,
makeLocalBearer)
import Ouroboros.Network.Socket (AcceptedConnectionsLimit (..), HandshakeCallbacks (..),
SomeResponderApplication (..), cleanNetworkMutableState, connectToNode,
newNetworkMutableState, nullNetworkConnectTracers, nullNetworkServerTracers,
withServerNode)
import Ouroboros.Network.Socket (AcceptedConnectionsLimit (..), ConnectToArgs (..),
HandshakeCallbacks (..), SomeResponderApplication (..), cleanNetworkMutableState,
connectToNode, newNetworkMutableState, nullNetworkConnectTracers,
nullNetworkServerTracers, withServerNode)

import Codec.CBOR.Term (Term)
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async
import Control.DeepSeq (NFData)
import Control.Exception (throwIO)
import Control.Monad (forever)
import "contra-tracer" Control.Tracer (contramap, nullTracer, stdoutTracer)
import Data.Aeson (FromJSON, ToJSON)
import qualified Data.ByteString.Lazy as LBS
import Data.Time.Clock (getCurrentTime)
import Data.Void (Void)
import Data.Void (Void, absurd)
import Data.Word (Word16)
import GHC.Generics
import System.Directory
Expand Down Expand Up @@ -157,15 +158,11 @@ doConnectToAcceptor TestSetup{..} snocket muxBearer address timeLimits (ekgConfi
dpStore <- initDataPointStore
writeToStore dpStore "test.data.point" $ DataPoint mkTestDataPoint
withAsync (traceObjectsWriter sink) $ \_ -> do
connectToNode
done <- connectToNode
snocket
muxBearer
args
mempty
(codecHandshake forwardingVersionCodec)
timeLimits
(cborTermVersionDataCodec forwardingCodecCBORTerm)
nullNetworkConnectTracers
(HandshakeCallbacks acceptableVersion queryVersion)
(simpleSingletonVersions
ForwardingV_1
(ForwardingVersionData $ unI tsNetworkMagic)
Expand All @@ -177,7 +174,18 @@ doConnectToAcceptor TestSetup{..} snocket muxBearer address timeLimits (ekgConfi
)
Nothing
address
case done of
Left err -> throwIO err
Right choice -> case choice of
Left () -> return ()
Right void -> absurd void
where
args = ConnectToArgs {
ctaHandshakeCodec = codecHandshake forwardingVersionCodec,
ctaHandshakeTimeLimits = timeLimits,
ctaVersionDataCodec = cborTermVersionDataCodec forwardingCodecCBORTerm,
ctaConnectTracers = nullNetworkConnectTracers,
ctaHandshakeCallbacks = HandshakeCallbacks acceptableVersion queryVersion }
forwarderApp
:: [(RunMiniProtocol 'InitiatorMode initCtx respCtx LBS.ByteString IO () Void, Word16)]
-> OuroborosApplication 'InitiatorMode initCtx respCtx LBS.ByteString IO () Void
Expand Down
30 changes: 19 additions & 11 deletions trace-dispatcher/src/Cardano/Logging/Forwarding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ import Ouroboros.Network.Protocol.Handshake.Version (acceptableVersion
simpleSingletonVersions)
import Ouroboros.Network.Snocket (MakeBearer, Snocket, localAddressFromPath, localSnocket,
makeLocalBearer)
import Ouroboros.Network.Socket (AcceptedConnectionsLimit (..), HandshakeCallbacks (..),
SomeResponderApplication (..), cleanNetworkMutableState, connectToNode,
newNetworkMutableState, nullNetworkConnectTracers, nullNetworkServerTracers,
withServerNode)
import Ouroboros.Network.Socket (AcceptedConnectionsLimit (..), ConnectToArgs (..),
HandshakeCallbacks (..), SomeResponderApplication (..), cleanNetworkMutableState,
connectToNode, newNetworkMutableState, nullNetworkConnectTracers,
nullNetworkServerTracers, withServerNode)

import Codec.CBOR.Term (Term)
import Control.Concurrent.Async (async, race_, wait)
import Control.Monad (void)
import Control.Exception (throwIO)
import Control.Monad.IO.Class
import "contra-tracer" Control.Tracer (Tracer, contramap, nullTracer, stdoutTracer)
import qualified Data.ByteString.Lazy as LBS
import Data.Void (Void)
import Data.Void (Void, absurd)
import Data.Word (Word16)
import System.IO (hPutStrLn, stderr)
import qualified System.Metrics as EKG
Expand Down Expand Up @@ -197,15 +198,11 @@ doConnectToAcceptor
-> IO ()
doConnectToAcceptor magic snocket makeBearer configureSocket address timeLimits
ekgConfig tfConfig dpfConfig sink ekgStore dpStore = do
connectToNode
done <- connectToNode
snocket
makeBearer
args
configureSocket
(codecHandshake forwardingVersionCodec)
timeLimits
(cborTermVersionDataCodec forwardingCodecCBORTerm)
nullNetworkConnectTracers
(HandshakeCallbacks acceptableVersion queryVersion)
(simpleSingletonVersions
ForwardingV_1
(ForwardingVersionData magic)
Expand All @@ -217,7 +214,18 @@ doConnectToAcceptor magic snocket makeBearer configureSocket address timeLimits
)
Nothing
address
case done of
Left err -> throwIO err
Right choice -> case choice of
Left () -> return ()
Right void -> absurd void
where
args = ConnectToArgs {
ctaHandshakeCodec = codecHandshake forwardingVersionCodec,
ctaHandshakeTimeLimits = timeLimits,
ctaVersionDataCodec = cborTermVersionDataCodec forwardingCodecCBORTerm,
ctaConnectTracers = nullNetworkConnectTracers,
ctaHandshakeCallbacks = HandshakeCallbacks acceptableVersion queryVersion }
forwarderApp
:: [(RunMiniProtocol 'Mux.InitiatorMode initiatorCtx responderCtx LBS.ByteString IO () Void, Word16)]
-> OuroborosApplication 'Mux.InitiatorMode initiatorCtx responderCtx LBS.ByteString IO () Void
Expand Down

0 comments on commit abd035b

Please sign in to comment.