summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r--src/Network/BitTorrent.hs40
1 files changed, 0 insertions, 40 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index ef144f1f..c72498d0 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -115,43 +115,3 @@ discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do
115 addr <- getPeerAddr tses 115 addr <- getPeerAddr tses
116 spawnP2P swarm addr $ do 116 spawnP2P swarm addr $ do
117 action 117 action
118
119-- Event translation table looks like:
120--
121-- Available -> Want
122-- Want -> Fragment
123-- Fragment -> Available
124--
125-- If we join the chain we get the event loop:
126--
127-- Available -> Want -> Fragment --\
128-- /|\ |
129-- \---------------------------/
130--
131
132
133-- | Default P2P action.
134exchange :: Storage -> P2P ()
135exchange storage = {-# SCC exchange #-} (awaitEvent >>= handler)
136 where
137 handler (Available bf) = do
138 liftIO (print (completeness bf))
139 ixs <- selBlk (findMin bf) storage
140 mapM_ (yieldEvent . Want) ixs -- TODO yield vectored
141
142 handler (Want bix) = do
143 blk <- liftIO $ getBlk bix storage
144 yieldEvent (Fragment blk)
145
146 handler (Fragment blk @ Block {..}) = do
147 liftIO $ print (ppBlock blk)
148 done <- liftIO $ putBlk blk storage
149 when done $ do
150 yieldEvent $ Available $ singleton blkPiece (succ blkPiece)
151
152 -- WARN this is not reliable: if peer do not return all piece
153 -- block we could slow don't until some other event occured
154 offer <- peerOffer
155 if BF.null offer
156 then return ()
157 else handler (Available offer)