summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange/Bus.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Bus.hs')
-rw-r--r--src/Network/BitTorrent/Exchange/Bus.hs66
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 @@
1module Network.BitTorrent.Exchange.Bus ( ) where
2
3type PeerWire = ConduitM Message Message IO
4
5runPeerWire :: Socket -> PeerWire () -> IO ()
6runPeerWire 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
15awaitMessage :: P2P Message
16awaitMessage = P2P $ ReaderT $ const $ {-# SCC awaitMessage #-} go
17 where
18 go = await >>= maybe (monadThrow PeerDisconnected) return
19{-# INLINE awaitMessage #-}
20
21yieldMessage :: Message -> P2P ()
22yieldMessage msg = P2P $ ReaderT $ const $ {-# SCC yieldMessage #-} do
23 C.yield msg
24{-# INLINE yieldMessage #-}
25
26-- TODO send vectored
27flushPending :: P2P ()
28flushPending = {-# SCC flushPending #-} do
29 session <- ask
30 queue <- liftIO (getPending session)
31 mapM_ yieldMessage queue
32
33{-----------------------------------------------------------------------
34 P2P monad
35-----------------------------------------------------------------------}
36
37filterMeaninless :: P2P Message Message
38filterMeaninless = 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--
47newtype P2P a = P2P {
48 unP2P :: ReaderT PeerSession PeerWire a
49 } deriving ( Functor, Applicative, Monad
50 , MonadIO, MonadThrow, MonadActive
51 , MonadReader PeerSession
52 )
53
54instance 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
60runP2P :: (Socket, PeerSession) -> P2P () -> IO ()
61runP2P (sock, ses) action =
62 handle isIOException $
63 runPeerWire sock (runReaderT (unP2P action) ses)
64 where
65 isIOException :: IOException -> IO ()
66 isIOException _ = return ()