diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-12 22:00:55 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-12 22:00:55 +0400 |
commit | d0cf97873e8b60b113bd2a3686b4868d1988c6c7 (patch) | |
tree | fcacd80998b1178fe3f18fea6d3a1619e3c78f08 /src/Network/BitTorrent/Exchange/Session.hs | |
parent | a220935e3d83cf6d96e767baa04c71a2f174f1ef (diff) |
Implement CANCEL message handling
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Session.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 47 |
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 | ||
131 | handleMessage :: Message -> Wire Session () | 131 | handleTransfer :: Transfer -> Wire Session () |
132 | handleMessage KeepAlive = return () | 132 | handleTransfer (Request bix) = do |
133 | handleMessage (Status s) = undefined | ||
134 | handleMessage (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 | |||
144 | handleMessage (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 | 140 | handleTransfer (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)) | 150 | handleTransfer (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 | |||
155 | handleMessage :: Message -> Wire Session () | ||
156 | handleMessage KeepAlive = return () | ||
157 | handleMessage (Status s) = undefined | ||
158 | handleMessage (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 | ||
168 | handleMessage (Port n) = undefined | 168 | handleMessage (Transfer msg) = handleTransfer msg |
169 | handleMessage (Fast _) = undefined | 169 | handleMessage (Port n) = undefined |
170 | handleMessage (Extended _) = undefined | 170 | handleMessage (Fast _) = undefined |
171 | handleMessage (Extended _) = undefined | ||
171 | 172 | ||
172 | exchange :: Wire Session () | 173 | exchange :: Wire Session () |
173 | exchange = do | 174 | exchange = do |