summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-25 17:59:46 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-25 17:59:46 +0400
commitec67f805e8f43e54ded11138bcc4aa4036dacc0b (patch)
tree5c43cd048109f5164bedeffd180c870acd25ca45 /src
parent4688e69dbb16899d898d06aa643f35c4d2fa2df8 (diff)
Handle metadata completion
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs
index 6e5d94d6..5be7513a 100644
--- a/src/Network/BitTorrent/Exchange/Session.hs
+++ b/src/Network/BitTorrent/Exchange/Session.hs
@@ -387,6 +387,11 @@ tryRequestMetadataBlock = do
387 Nothing -> undefined 387 Nothing -> undefined
388 Just pix -> sendMessage (MetadataRequest pix) 388 Just pix -> sendMessage (MetadataRequest pix)
389 389
390metadataCompleted :: InfoDict -> Wire Session ()
391metadataCompleted dict = do
392 Session {..} <- asks connSession
393 liftIO $ putMVar infodict (cache dict)
394
390handleMetadata :: Handler ExtendedMetadata 395handleMetadata :: Handler ExtendedMetadata
391handleMetadata (MetadataRequest pix) = 396handleMetadata (MetadataRequest pix) =
392 lift (tryReadMetadataBlock pix) >>= sendMessage . mkResponse 397 lift (tryReadMetadataBlock pix) >>= sendMessage . mkResponse
@@ -395,9 +400,11 @@ handleMetadata (MetadataRequest pix) =
395 mkResponse (Just (piece, total)) = MetadataData piece total 400 mkResponse (Just (piece, total)) = MetadataData piece total
396 401
397handleMetadata (MetadataData {..}) = do 402handleMetadata (MetadataData {..}) = do
398 ih <- asks connTopic 403 ih <- asks connTopic
399 lift $ withMetadataUpdates (Metadata.pushBlock piece ih) 404 mdict <- lift $ withMetadataUpdates (Metadata.pushBlock piece ih)
400 tryRequestMetadataBlock 405 case mdict of
406 Nothing -> tryRequestMetadataBlock -- not completed, need all blocks
407 Just dict -> metadataCompleted dict -- complete, wake up payload fetch
401 408
402handleMetadata (MetadataReject pix) = do 409handleMetadata (MetadataReject pix) = do
403 lift $ withMetadataUpdates (Metadata.cancelPending pix) 410 lift $ withMetadataUpdates (Metadata.cancelPending pix)