@@ -73,11 +73,13 @@ import Hydra.Prelude hiding (fromList, replicate)
73
73
74
74
import Control.Tracer (Tracer )
75
75
import Hydra.Crypto (HydraKey , SigningKey )
76
+ import Hydra.Ledger (IsTx )
76
77
import Hydra.Logging (traceWith )
77
78
import Hydra.Logging.Messages (HydraLog (.. ))
78
79
import Hydra.Network (Host (.. ), IP , NetworkComponent , NodeId , PortNumber )
79
- import Hydra.Network.Authenticate (Authenticated (Authenticated ), Signed , withAuthentication )
80
- import Hydra.Network.Heartbeat (ConnectionMessages , Heartbeat (.. ), withHeartbeat )
80
+ import Hydra.Network.Authenticate (Authenticated (.. ), Signed , withAuthentication )
81
+ import Hydra.Network.Heartbeat (Heartbeat (.. ), withHeartbeat )
82
+ import Hydra.Network.Message (Connectivity , Message , NetworkEvent (.. ))
81
83
import Hydra.Network.Ouroboros (TraceOuroborosNetwork , WithHost , withOuroborosNetwork )
82
84
import Hydra.Network.Reliability (MessagePersistence , ReliableMsg , mkMessagePersistence , withReliability )
83
85
import Hydra.Node (HydraNodeLog (.. ))
@@ -110,34 +112,36 @@ data NetworkConfiguration m = NetworkConfiguration
110
112
111
113
-- | Starts the network layer of a node, passing configured `Network` to its continuation.
112
114
withNetwork ::
113
- forall msg tx .
114
- ( ToCBOR msg , ToJSON msg , FromJSON msg , FromCBOR msg ) =>
115
+ forall tx .
116
+ IsTx tx =>
115
117
-- | Tracer to use for logging messages.
116
- Tracer IO (LogEntry tx msg ) ->
117
- -- | Callback/observer for connectivity changes in peers.
118
- ConnectionMessages IO ->
118
+ Tracer IO (LogEntry tx (Message tx )) ->
119
119
-- | The network configuration
120
120
NetworkConfiguration IO ->
121
121
-- | Produces a `NetworkComponent` that can send `msg` and consumes `Authenticated` @msg@.
122
- NetworkComponent IO (Authenticated msg ) msg ()
123
- withNetwork tracer connectionMessages configuration callback action = do
122
+ NetworkComponent IO (NetworkEvent ( Message tx )) ( Message tx ) ()
123
+ withNetwork tracer configuration callback action = do
124
124
let localhost = Host {hostname = show host, port}
125
125
me = deriveParty signingKey
126
126
numberOfParties = length $ me : otherParties
127
127
messagePersistence <- configureMessagePersistence (contramap Node tracer) persistenceDir numberOfParties
128
128
129
- let reliability :: NetworkComponent IO (Heartbeat (Authenticated msg )) (Heartbeat msg ) ()
130
- reliability =
129
+ let reliability =
131
130
withFlipHeartbeats $
132
131
withReliability (contramap Reliability tracer) messagePersistence me otherParties $
133
132
withAuthentication (contramap Authentication tracer) signingKey otherParties $
134
133
withOuroborosNetwork (contramap Network tracer) localhost peers
135
134
136
- withHeartbeat nodeId connectionMessages reliability callback $ \ network ->
135
+ withHeartbeat nodeId reliability ( callback . mapHeartbeat) $ \ network ->
137
136
action network
138
137
where
139
138
NetworkConfiguration {persistenceDir, signingKey, otherParties, host, port, peers, nodeId} = configuration
140
139
140
+ mapHeartbeat :: Either Connectivity (Authenticated (Message tx )) -> NetworkEvent (Message tx )
141
+ mapHeartbeat = \ case
142
+ Left connectivity -> ConnectivityEvent connectivity
143
+ Right (Authenticated {payload, party}) -> ReceivedMessage {sender = party, msg = payload}
144
+
141
145
-- | Create `MessagePersistence` handle to be used by `Reliability` network layer.
142
146
--
143
147
-- This function will `throw` a `ParameterMismatch` exception if:
0 commit comments