summaryrefslogtreecommitdiff
path: root/bittorrent/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'bittorrent/src/Network')
-rw-r--r--bittorrent/src/Network/BitTorrent/Exchange/Bitfield.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/bittorrent/src/Network/BitTorrent/Exchange/Bitfield.hs b/bittorrent/src/Network/BitTorrent/Exchange/Bitfield.hs
index 7bae3475..1be9f970 100644
--- a/bittorrent/src/Network/BitTorrent/Exchange/Bitfield.hs
+++ b/bittorrent/src/Network/BitTorrent/Exchange/Bitfield.hs
@@ -9,7 +9,7 @@
9-- bitfields. Bitfields are used to keep track indices of complete 9-- bitfields. Bitfields are used to keep track indices of complete
10-- pieces either this peer have or remote peer have. 10-- pieces either this peer have or remote peer have.
11-- 11--
12-- There are also commonly used piece seletion algorithms 12-- There are also commonly used piece selection algorithms
13-- which used to find out which one next piece to download. 13-- which used to find out which one next piece to download.
14-- Selectors considered to be used in the following order: 14-- Selectors considered to be used in the following order:
15-- 15--
@@ -108,12 +108,17 @@ import Data.Torrent
108 108
109-- TODO cache some operations 109-- TODO cache some operations
110 110
111-- | Bitfields are represented just as integer sets but with 111-- | Bitfields are represented just as integer sets but with a restriction:
112-- restriction: the each set should be within given interval (or 112-- each integer in the set should be within the given interval. The greatest
113-- subset of the specified interval). Size is used to specify 113-- lower bound of the interval must be zero, so intervals may be specified by
114-- interval, so bitfield of size 10 might contain only indices in 114-- providing a maximum set size. For example, a bitfield of size 10 might
115-- interval [0..9]. 115-- contain only indices in interval [0..9].
116-- 116--
117-- By convention, we use the following aliases for Int:
118--
119-- [ PieceIx ] an Int member of the Bitfield.
120--
121-- [ PieceCount ] maximum set size for a Bitfield.
117data Bitfield = Bitfield { 122data Bitfield = Bitfield {
118 bfSize :: !PieceCount 123 bfSize :: !PieceCount
119 , bfSet :: !IntSet 124 , bfSet :: !IntSet
@@ -257,6 +262,7 @@ rarest xs
257 = Just $ fst $ V.ifoldr' minIx (0, freqMap V.! 0) freqMap 262 = Just $ fst $ V.ifoldr' minIx (0, freqMap V.! 0) freqMap
258 where 263 where
259 freqMap = frequencies xs 264 freqMap = frequencies xs
265 {-# NOINLINE freqMap #-}
260 266
261 minIx :: PieceIx -> Frequency 267 minIx :: PieceIx -> Frequency
262 -> (PieceIx, Frequency) 268 -> (PieceIx, Frequency)
@@ -393,7 +399,7 @@ rarestFirst h a xs = rarest (map (intersection want) xs)
393randomFirst :: Selector 399randomFirst :: Selector
394randomFirst = do 400randomFirst = do
395-- randomIO 401-- randomIO
396 error "randomFirst" 402 error "TODO: randomFirst"
397 403
398endGame :: Selector 404endGame :: Selector
399endGame = strictLast 405endGame = strictLast