diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-25 17:59:46 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-25 17:59:46 +0400 |
commit | ec67f805e8f43e54ded11138bcc4aa4036dacc0b (patch) | |
tree | 5c43cd048109f5164bedeffd180c870acd25ca45 /src | |
parent | 4688e69dbb16899d898d06aa643f35c4d2fa2df8 (diff) |
Handle metadata completion
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 13 |
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 | ||
390 | metadataCompleted :: InfoDict -> Wire Session () | ||
391 | metadataCompleted dict = do | ||
392 | Session {..} <- asks connSession | ||
393 | liftIO $ putMVar infodict (cache dict) | ||
394 | |||
390 | handleMetadata :: Handler ExtendedMetadata | 395 | handleMetadata :: Handler ExtendedMetadata |
391 | handleMetadata (MetadataRequest pix) = | 396 | handleMetadata (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 | ||
397 | handleMetadata (MetadataData {..}) = do | 402 | handleMetadata (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 | ||
402 | handleMetadata (MetadataReject pix) = do | 409 | handleMetadata (MetadataReject pix) = do |
403 | lift $ withMetadataUpdates (Metadata.cancelPending pix) | 410 | lift $ withMetadataUpdates (Metadata.cancelPending pix) |