summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-25 17:30:33 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-25 17:30:33 +0400
commitf6f4e61099065251ef77e43ff10bb98c8b2507be (patch)
treea5babe1eef0e926719c9e35e27b9440b5432a9fc /src/Network
parent22d6d17dc8b1d864ad0752f052bf89f622ada2de (diff)
Implement scheduleBlock function
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Exchange/Session/Metadata.hs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session/Metadata.hs b/src/Network/BitTorrent/Exchange/Session/Metadata.hs
index 174550fa..5d72172a 100644
--- a/src/Network/BitTorrent/Exchange/Session/Metadata.hs
+++ b/src/Network/BitTorrent/Exchange/Session/Metadata.hs
@@ -21,6 +21,7 @@ import Control.Monad.State
21import Data.ByteString as BS 21import Data.ByteString as BS
22import Data.ByteString.Lazy as BL 22import Data.ByteString.Lazy as BL
23import Data.List as L 23import Data.List as L
24import Data.Tuple
24 25
25import Data.BEncode as BE 26import Data.BEncode as BE
26import Data.Torrent 27import Data.Torrent
@@ -45,7 +46,7 @@ nullStatus ps = Status [] (Block.empty ps)
45type Updates a = State Status a 46type Updates a = State Status a
46 47
47runUpdates :: MVar Status -> Updates a -> IO a 48runUpdates :: MVar Status -> Updates a -> IO a
48runUpdates v m = undefined 49runUpdates v m = modifyMVar v (return . swap . runState m)
49 50
50scheduleBlock :: PeerAddr IP -> Updates (Maybe PieceIx) 51scheduleBlock :: PeerAddr IP -> Updates (Maybe PieceIx)
51scheduleBlock addr = do 52scheduleBlock addr = do
@@ -53,7 +54,7 @@ scheduleBlock addr = do
53 case spans metadataPieceSize bkt of 54 case spans metadataPieceSize bkt of
54 [] -> return Nothing 55 [] -> return Nothing
55 ((off, _ ) : _) -> do 56 ((off, _ ) : _) -> do
56 let pix = undefined 57 let pix = off `div` metadataPieceSize
57 pending %= ((addr, pix) :) 58 pending %= ((addr, pix) :)
58 return (Just pix) 59 return (Just pix)
59 60