diff options
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Bus.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Bus.hs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/Network/BitTorrent/Exchange/Bus.hs b/src/Network/BitTorrent/Exchange/Bus.hs deleted file mode 100644 index 7de91180..00000000 --- a/src/Network/BitTorrent/Exchange/Bus.hs +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | module Network.BitTorrent.Exchange.Bus ( ) where | ||
2 | |||
3 | type PeerWire = ConduitM Message Message IO | ||
4 | |||
5 | runPeerWire :: Socket -> PeerWire () -> IO () | ||
6 | runPeerWire sock action = | ||
7 | sourceSocket sock $= | ||
8 | S.conduitGet S.get $= | ||
9 | -- B.conduitDecode $= | ||
10 | action $= | ||
11 | S.conduitPut S.put $$ | ||
12 | -- B.conduitEncode $$ | ||
13 | sinkSocket sock | ||
14 | |||
15 | awaitMessage :: P2P Message | ||
16 | awaitMessage = P2P $ ReaderT $ const $ {-# SCC awaitMessage #-} go | ||
17 | where | ||
18 | go = await >>= maybe (monadThrow PeerDisconnected) return | ||
19 | {-# INLINE awaitMessage #-} | ||
20 | |||
21 | yieldMessage :: Message -> P2P () | ||
22 | yieldMessage msg = P2P $ ReaderT $ const $ {-# SCC yieldMessage #-} do | ||
23 | C.yield msg | ||
24 | {-# INLINE yieldMessage #-} | ||
25 | |||
26 | -- TODO send vectored | ||
27 | flushPending :: P2P () | ||
28 | flushPending = {-# SCC flushPending #-} do | ||
29 | session <- ask | ||
30 | queue <- liftIO (getPending session) | ||
31 | mapM_ yieldMessage queue | ||
32 | |||
33 | {----------------------------------------------------------------------- | ||
34 | P2P monad | ||
35 | -----------------------------------------------------------------------} | ||
36 | |||
37 | filterMeaninless :: P2P Message Message | ||
38 | filterMeaninless = undefined | ||
39 | |||
40 | -- | | ||
41 | -- Exceptions: | ||
42 | -- | ||
43 | -- * SessionException: is visible only within one peer | ||
44 | -- session. Use this exception to terminate P2P session, but not | ||
45 | -- the swarm session. | ||
46 | -- | ||
47 | newtype P2P a = P2P { | ||
48 | unP2P :: ReaderT PeerSession PeerWire a | ||
49 | } deriving ( Functor, Applicative, Monad | ||
50 | , MonadIO, MonadThrow, MonadActive | ||
51 | , MonadReader PeerSession | ||
52 | ) | ||
53 | |||
54 | instance MonadState SessionState P2P where | ||
55 | get = asks sessionState >>= liftIO . readIORef | ||
56 | {-# INLINE get #-} | ||
57 | put !s = asks sessionState >>= \ref -> liftIO $ writeIORef ref s | ||
58 | {-# INLINE put #-} | ||
59 | |||
60 | runP2P :: (Socket, PeerSession) -> P2P () -> IO () | ||
61 | runP2P (sock, ses) action = | ||
62 | handle isIOException $ | ||
63 | runPeerWire sock (runReaderT (unP2P action) ses) | ||
64 | where | ||
65 | isIOException :: IOException -> IO () | ||
66 | isIOException _ = return () | ||