summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-16 20:25:43 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-16 20:25:43 +0400
commit412919e88e1d60303f7a14134e37f27becf5f959 (patch)
tree89711599f2ca1101c1d905e65516b2778c50fd07 /src/Network/BitTorrent/Exchange.hs
parent8c6e5818ee6b901efd975392c54aff5cf2721ae4 (diff)
~ Move client bitfield to storage.
We localize bitfield mutation in storage module this way. Also fix some warnings.
Diffstat (limited to 'src/Network/BitTorrent/Exchange.hs')
-rw-r--r--src/Network/BitTorrent/Exchange.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/Exchange.hs b/src/Network/BitTorrent/Exchange.hs
index dc1b2752..71be3f88 100644
--- a/src/Network/BitTorrent/Exchange.hs
+++ b/src/Network/BitTorrent/Exchange.hs
@@ -71,6 +71,7 @@ module Network.BitTorrent.Exchange
71 ) where 71 ) where
72 72
73import Control.Applicative 73import Control.Applicative
74import Control.Concurrent.STM
74import Control.Exception 75import Control.Exception
75import Control.Lens 76import Control.Lens
76import Control.Monad.Reader 77import Control.Monad.Reader
@@ -80,7 +81,7 @@ import Control.Monad.Trans.Resource
80import Data.IORef 81import Data.IORef
81import Data.Conduit as C 82import Data.Conduit as C
82import Data.Conduit.Cereal as S 83import Data.Conduit.Cereal as S
83import Data.Conduit.Serialization.Binary as B 84--import Data.Conduit.Serialization.Binary as B
84import Data.Conduit.Network 85import Data.Conduit.Network
85import Data.Serialize as S 86import Data.Serialize as S
86import Text.PrettyPrint as PP hiding (($$)) 87import Text.PrettyPrint as PP hiding (($$))
@@ -100,11 +101,11 @@ import System.Torrent.Storage
100type PeerWire = ConduitM Message Message IO 101type PeerWire = ConduitM Message Message IO
101 102
102runPeerWire :: Socket -> PeerWire () -> IO () 103runPeerWire :: Socket -> PeerWire () -> IO ()
103runPeerWire sock p2p = 104runPeerWire sock action =
104 sourceSocket sock $= 105 sourceSocket sock $=
105 S.conduitGet S.get $= 106 S.conduitGet S.get $=
106-- B.conduitDecode $= 107-- B.conduitDecode $=
107 p2p $= 108 action $=
108 S.conduitPut S.put $$ 109 S.conduitPut S.put $$
109-- B.conduitEncode $$ 110-- B.conduitEncode $$
110 sinkSocket sock 111 sinkSocket sock
@@ -153,9 +154,9 @@ instance MonadState SessionState P2P where
153 {-# INLINE put #-} 154 {-# INLINE put #-}
154 155
155runP2P :: (Socket, PeerSession) -> P2P () -> IO () 156runP2P :: (Socket, PeerSession) -> P2P () -> IO ()
156runP2P (sock, ses) p2p = 157runP2P (sock, ses) action =
157 handle isIOException $ 158 handle isIOException $
158 runPeerWire sock (runReaderT (unP2P p2p) ses) 159 runPeerWire sock (runReaderT (unP2P action) ses)
159 where 160 where
160 isIOException :: IOException -> IO () 161 isIOException :: IOException -> IO ()
161 isIOException _ = return () 162 isIOException _ = return ()
@@ -428,7 +429,10 @@ yieldEvent e = {-# SCC yieldEvent #-} do
428 go e 429 go e
429 flushPending 430 flushPending
430 where 431 where
431 go (Available ixs) = asks swarmSession >>= liftIO . available ixs 432 go (Available ixs) = do
433 ses <- asks swarmSession
434 liftIO $ atomically $ available ixs ses
435
432 go (Want bix) = do 436 go (Want bix) = do
433 offer <- peerOffer 437 offer <- peerOffer
434 if ixPiece bix `BF.member` offer 438 if ixPiece bix `BF.member` offer