Skip to content

Commit 6eaefc4

Browse files
committed
refactor(simulation): restrict Chan API
1 parent 1b915ab commit 6eaefc4

File tree

7 files changed

+17
-25
lines changed

7 files changed

+17
-25
lines changed

simulation/src/Chan/Driver.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
{-# LANGUAGE TypeApplications #-}
88
{-# LANGUAGE TypeOperators #-}
99
{-# LANGUAGE UndecidableInstances #-}
10-
{-# OPTIONS_GHC -Wno-name-shadowing #-}
1110

12-
module Chan.Driver where
11+
module Chan.Driver (
12+
ProtocolMessage (..),
13+
protocolMessage,
14+
chanDriver,
15+
) where
1316

14-
import Chan.Core
15-
import Chan.TCP
16-
import Data.Type.Equality
17+
import Chan.Core (Chan (readChan, writeChan))
18+
import Chan.TCP (MessageSize (..))
19+
import Data.Type.Equality (type (:~:) (..))
1720
import Network.TypedProtocol (
1821
ActiveState,
1922
Driver (..),
@@ -49,27 +52,27 @@ chanDriver ::
4952
Driver ps pr () m
5053
chanDriver cmp ch =
5154
Driver
52-
{ sendMessage = sendMessage
53-
, recvMessage = recvMessage
55+
{ sendMessage = sendMessage'
56+
, recvMessage = recvMessage'
5457
, initialDState = ()
5558
}
5659
where
57-
sendMessage ::
60+
sendMessage' ::
5861
forall (st :: ps) (st' :: ps).
5962
(StateTokenI st, StateTokenI st', ActiveState st) =>
6063
WeHaveAgencyProof pr st ->
6164
Message ps st st' ->
6265
m ()
63-
sendMessage _prf msg =
66+
sendMessage' _prf msg =
6467
writeChan ch (ProtocolMessage (SomeMessage msg))
6568

66-
recvMessage ::
69+
recvMessage' ::
6770
forall (st :: ps).
6871
(StateTokenI st, ActiveState st) =>
6972
TheyHaveAgencyProof pr st ->
7073
() ->
7174
m (SomeMessage st, ())
72-
recvMessage _prf () = do
75+
recvMessage' _prf () = do
7376
ProtocolMessage smsg <- readChan ch
7477
case smsg of
7578
SomeMessage (msg :: Message ps st' st1) -> case cmp @st @st' of

simulation/src/Chan/Mux.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@
1010
{-# LANGUAGE TypeFamilies #-}
1111

1212
module Chan.Mux (
13-
newMuxChan,
14-
Chan (..),
1513
ToFromMuxMsg (..),
16-
dynToFromMuxMsg,
1714
MuxBundle (..),
18-
BearerMsg,
19-
fromBearerMsg,
2015
newConnectionBundleTCP,
2116
) where
2217

simulation/src/LeiosProtocol/Relay.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
module LeiosProtocol.Relay where
2626

2727
import Chan
28-
import Chan.Driver (ProtocolMessage, chanDriver)
2928
import Control.DeepSeq (NFData)
3029
import Control.Exception (Exception, assert, throw)
3130
import Control.Monad (forM_, join, unless, void, when)

simulation/src/LeiosProtocol/Short/Node.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
module LeiosProtocol.Short.Node where
1515

16-
import Chan.Mux
16+
import Chan
1717
import Control.Category ((>>>))
1818
import Control.Concurrent.Class.MonadMVar
1919
import Control.Concurrent.Class.MonadSTM.TSem

simulation/src/LeiosProtocol/Short/Sim.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
module LeiosProtocol.Short.Sim where
1414

15-
import Chan.Driver
16-
import Chan.Mux
17-
import Chan.TCP
15+
import Chan
1816
import Control.Exception (assert)
1917
import Control.Monad (forever)
2018
import Control.Monad.Class.MonadFork (MonadFork (forkIO))

simulation/src/LeiosProtocol/SimTestRelay.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
module LeiosProtocol.SimTestRelay where
1212

1313
import Chan
14-
import Chan.Mux
15-
import Chan.TCP
1614
import Control.Category ((>>>))
1715
import Control.Exception (assert)
1816
import Control.Monad (forever, when)

simulation/src/PraosProtocol/PraosNode.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ module PraosProtocol.PraosNode (
1010
)
1111
where
1212

13-
import Chan.Driver (protocolMessage)
14-
import Chan.Mux
13+
import Chan
1514
import Control.Exception (assert)
1615
import Control.Monad.Class.MonadAsync (Concurrently (..), MonadAsync (..))
1716
import Control.Monad.Class.MonadFork

0 commit comments

Comments
 (0)