1+ {-# LANGUAGE OverloadedRecordDot #-}
12{-# LANGUAGE DeriveAnyClass #-}
23{-# LANGUAGE DeriveGeneric #-}
34{-# LANGUAGE LambdaCase #-}
@@ -9,25 +10,41 @@ import Codec.CBOR.Term qualified as CBOR
910import Control.DeepSeq (NFData )
1011import Control.Monad ((>=>) )
1112import Data.Bits (Bits (.. ))
13+ import Data.ByteString.Lazy (ByteString )
1214import Data.Text (Text )
1315import Data.Text qualified as T
1416import GHC.Generics (Generic )
1517
18+ import Control.Monad.Class.MonadFork
1619import Control.Monad.Class.MonadST (MonadST )
20+ import Control.Monad.Class.MonadThrow
1721import Control.Tracer (Tracer , nullTracer )
1822
1923import Network.Mux qualified as Mx
2024
2125import Ouroboros.Network.CodecCBORTerm (CodecCBORTerm (.. ))
2226import Ouroboros.Network.ConnectionId (ConnectionId )
23- import Ouroboros.Network.Driver.Simple ( TraceSendRecv )
27+ import Ouroboros.Network.Driver.Simple
2428import Ouroboros.Network.Handshake.Acceptable (Acceptable (.. ))
2529import Ouroboros.Network.Handshake.Queryable (Queryable (.. ))
2630import Ouroboros.Network.Magic (NetworkMagic (.. ))
2731import Ouroboros.Network.Protocol.Handshake (Accept (.. ), Handshake ,
2832 HandshakeArguments (.. ))
2933import Ouroboros.Network.Protocol.Handshake.Codec (cborTermVersionDataCodec ,
3034 codecHandshake , noTimeLimitsHandshake )
35+ import DMQ.Diffusion.NodeKernel
36+ import Network.TypedProtocol.Codec
37+ import DMQ.Protocol.LocalMsgSubmission.Type
38+ import qualified Network.TypedProtocol.Codec.CBOR as CBOR
39+ import DMQ.Protocol.LocalMsgNotification.Type
40+ import DMQ.Protocol.LocalMsgNotification.Server
41+ import DMQ.Protocol.LocalMsgSubmission.Server
42+ import Ouroboros.Network.Context
43+ import DMQ.Protocol.SigSubmission.Type
44+ import qualified Ouroboros.Network.TxSubmission.Mempool.Simple as Mempool
45+ import Control.Concurrent.Class.MonadSTM
46+ import DMQ.NtC_Applications.LocalMsgSubmission
47+ import DMQ.NtC_Applications.LocalMsgNotification
3148
3249data NodeToClientVersion =
3350 NodeToClientV_1
@@ -106,6 +123,7 @@ nodeToClientCodecCBORTerm _v = CodecCBORTerm {encodeTerm, decodeTerm}
106123 decoder x query | x >= 0 && x <= 0xffffffff = Right (NodeToClientVersionData (NetworkMagic $ fromIntegral x) query)
107124 | otherwise = Left $ T. pack $ " networkMagic out of bound: " <> show x
108125
126+
109127data Protocols =
110128 Protocols {
111129 }
@@ -139,3 +157,74 @@ stdVersionDataNTC networkMagic =
139157 { networkMagic
140158 , query = False
141159 }
160+
161+ type LocalMsgSubmission' = LocalMsgSubmission Sig Int
162+ type LocalMsgNotification' = LocalMsgNotification Sig
163+
164+ data Codecs m =
165+ Codecs {
166+ msgSubmissionCodec
167+ :: Codec LocalMsgSubmission'
168+ CBOR.DeserialiseFailure m ByteString
169+ , msgNotificationCodec
170+ :: Codec LocalMsgNotification'
171+ CBOR.DeserialiseFailure m ByteString
172+ }
173+
174+
175+ -- | A node-to-client application
176+ --
177+ type App ctx m a =
178+ ctx
179+ -> Mx. Channel m ByteString
180+ -> m (a , Maybe ByteString )
181+
182+
183+ data Apps addr m a =
184+ Apps {
185+ -- | Start a sig-submission client
186+ aLocalMsgSubmission :: App addr m a
187+
188+ -- | Start a sig-submission server
189+ , aLocalMsgNotification :: App addr m a
190+ }
191+
192+
193+ -- | Construct applications for the node-to-client protocols
194+ --
195+ ntcApps
196+ :: (MonadThrow m , MonadThread m , MonadSTM m )
197+ => NodeKernel addr m
198+ -> Codecs m
199+ -> Apps addr m ()
200+ ntcApps NodeKernel { mempool } codecs =
201+ Apps {
202+ aLocalMsgSubmission
203+ , aLocalMsgNotification
204+ }
205+ where
206+ sigSize :: Sig -> SizeInBytes
207+ sigSize _ = 0 -- TODO
208+
209+ mempoolReader = Mempool. getReader sigId sigSize mempool
210+ mempoolWriter = Mempool. getWriter sigId (const True ) mempool
211+
212+ -- aLocalMsgSubmission :: _
213+ aLocalMsgSubmission _ctx channel = do
214+ labelThisThread " LocalMsgSubmissionServer"
215+ runPeer
216+ undefined
217+ codecs. msgSubmissionCodec
218+ channel
219+ (localMsgSubmissionServerPeer $
220+ localMsgSubmissionServer undefined mempoolWriter)
221+
222+ -- aLocalMsgNotification :: _
223+ aLocalMsgNotification _ctx channel = do
224+ labelThisThread " LocalMsgNotificationServer"
225+ runPeer
226+ undefined
227+ codecs. msgNotificationCodec
228+ channel
229+ (localMsgNotificationServerPeer $
230+ localMsgNotificationServer undefined )
0 commit comments