diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-16 20:25:43 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-16 20:25:43 +0400 |
commit | 412919e88e1d60303f7a14134e37f27becf5f959 (patch) | |
tree | 89711599f2ca1101c1d905e65516b2778c50fd07 /src/Network/BitTorrent/Exchange.hs | |
parent | 8c6e5818ee6b901efd975392c54aff5cf2721ae4 (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.hs | 16 |
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 | ||
73 | import Control.Applicative | 73 | import Control.Applicative |
74 | import Control.Concurrent.STM | ||
74 | import Control.Exception | 75 | import Control.Exception |
75 | import Control.Lens | 76 | import Control.Lens |
76 | import Control.Monad.Reader | 77 | import Control.Monad.Reader |
@@ -80,7 +81,7 @@ import Control.Monad.Trans.Resource | |||
80 | import Data.IORef | 81 | import Data.IORef |
81 | import Data.Conduit as C | 82 | import Data.Conduit as C |
82 | import Data.Conduit.Cereal as S | 83 | import Data.Conduit.Cereal as S |
83 | import Data.Conduit.Serialization.Binary as B | 84 | --import Data.Conduit.Serialization.Binary as B |
84 | import Data.Conduit.Network | 85 | import Data.Conduit.Network |
85 | import Data.Serialize as S | 86 | import Data.Serialize as S |
86 | import Text.PrettyPrint as PP hiding (($$)) | 87 | import Text.PrettyPrint as PP hiding (($$)) |
@@ -100,11 +101,11 @@ import System.Torrent.Storage | |||
100 | type PeerWire = ConduitM Message Message IO | 101 | type PeerWire = ConduitM Message Message IO |
101 | 102 | ||
102 | runPeerWire :: Socket -> PeerWire () -> IO () | 103 | runPeerWire :: Socket -> PeerWire () -> IO () |
103 | runPeerWire sock p2p = | 104 | runPeerWire 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 | ||
155 | runP2P :: (Socket, PeerSession) -> P2P () -> IO () | 156 | runP2P :: (Socket, PeerSession) -> P2P () -> IO () |
156 | runP2P (sock, ses) p2p = | 157 | runP2P (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 |