| Have
deriving (Show, Eq)
--- todo - map with index to a new data structure (peers who have that piece amd state)
+-- todo - map with index to a new data structure (peers who have that piece and state)
data PieceData = PieceData { peers :: [Peer] -- ^ list of peers who have this piece
, dlstate :: PieceDlState -- ^ state of the piece from download perspective.
, hash :: ByteString -- ^ piece hash
pickPiece =
(fst `liftM`) . headMay . toList . filter (\v -> dlstate v == Pending)
+bytesDownloaded :: PieceMap -> Integer
+bytesDownloaded =
+ sum . (map (len . snd)) . toList . filter (\v -> dlstate v == Have)
+
updatePieceAvailability :: PieceMap -> Peer -> [Integer] -> PieceMap
updatePieceAvailability pieceStatus p pieceList =
mapWithKey (\k pd -> if k `elem` pieceList