summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange/Session.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-12 22:00:55 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-12 22:00:55 +0400
commitd0cf97873e8b60b113bd2a3686b4868d1988c6c7 (patch)
treefcacd80998b1178fe3f18fea6d3a1619e3c78f08 /src/Network/BitTorrent/Exchange/Session.hs
parenta220935e3d83cf6d96e767baa04c71a2f174f1ef (diff)
Implement CANCEL message handling
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Session.hs')
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs
index dce2572f..565ef7ab 100644
--- a/src/Network/BitTorrent/Exchange/Session.hs
+++ b/src/Network/BitTorrent/Exchange/Session.hs
@@ -128,21 +128,8 @@ readBlock bix @ BlockIx {..} s = do
128 else throwIO $ InvalidRequest bix (InvalidSize ixLength) 128 else throwIO $ InvalidRequest bix (InvalidSize ixLength)
129-} 129-}
130 130
131handleMessage :: Message -> Wire Session () 131handleTransfer :: Transfer -> Wire Session ()
132handleMessage KeepAlive = return () 132handleTransfer (Request bix) = do
133handleMessage (Status s) = undefined
134handleMessage (Available msg) = do
135 thisBf <- getThisBitfield
136 case msg of
137 Have ix
138 | ix `BF.member` thisBf -> return ()
139 | otherwise -> undefined
140 Bitfield bf
141 | bf `BF.isSubsetOf` thisBf -> return ()
142 | otherwise -> undefined
143
144handleMessage (Transfer msg) = case msg of
145 Request bix -> do
146-- Session {..} <- getSession 133-- Session {..} <- getSession
147-- addr <- getRemoteAddr 134-- addr <- getRemoteAddr
148-- when (addr `elem` unchoked && ixPiece bix `BF.member` bitfield) $ do 135-- when (addr `elem` unchoked && ixPiece bix `BF.member` bitfield) $ do
@@ -150,7 +137,7 @@ handleMessage (Transfer msg) = case msg of
150-- sendMsg (Piece blk) 137-- sendMsg (Piece blk)
151 return () 138 return ()
152 139
153 Piece blk -> do 140handleTransfer (Piece blk) = do
154{- 141{-
155 Session {..} <- getSession 142 Session {..} <- getSession
156 when (blockIx blk `PS.member` pendingSet) $ do 143 when (blockIx blk `PS.member` pendingSet) $ do
@@ -160,14 +147,28 @@ handleMessage (Transfer msg) = case msg of
160-} 147-}
161 return () 148 return ()
162 149
163 Cancel bix -> filterQueue (not . (transferResponse bix)) 150handleTransfer (Cancel bix) = filterQueue (not . (transferResponse bix))
164 where 151 where
165 transferResponse bix (Transfer (Piece blk)) = blockIx blk == bix 152 transferResponse bix (Transfer (Piece blk)) = blockIx blk == bix
166 transferResponse _ _ = False 153 transferResponse _ _ = False
154
155handleMessage :: Message -> Wire Session ()
156handleMessage KeepAlive = return ()
157handleMessage (Status s) = undefined
158handleMessage (Available msg) = do
159 thisBf <- getThisBitfield
160 case msg of
161 Have ix
162 | ix `BF.member` thisBf -> return ()
163 | otherwise -> undefined
164 Bitfield bf
165 | bf `BF.isSubsetOf` thisBf -> return ()
166 | otherwise -> undefined
167 167
168handleMessage (Port n) = undefined 168handleMessage (Transfer msg) = handleTransfer msg
169handleMessage (Fast _) = undefined 169handleMessage (Port n) = undefined
170handleMessage (Extended _) = undefined 170handleMessage (Fast _) = undefined
171handleMessage (Extended _) = undefined
171 172
172exchange :: Wire Session () 173exchange :: Wire Session ()
173exchange = do 174exchange = do