summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/Progress.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent/Progress.hs')
-rw-r--r--src/Data/Torrent/Progress.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Data/Torrent/Progress.hs b/src/Data/Torrent/Progress.hs
index bbfe6e47..c42af248 100644
--- a/src/Data/Torrent/Progress.hs
+++ b/src/Data/Torrent/Progress.hs
@@ -27,6 +27,10 @@ module Data.Torrent.Progress
27 , enqueuedProgress 27 , enqueuedProgress
28 , uploadedProgress 28 , uploadedProgress
29 , dequeuedProgress 29 , dequeuedProgress
30
31 -- * Query
32 , canDownload
33 , canUpload
30 ) where 34 ) where
31 35
32import Control.Applicative 36import Control.Applicative
@@ -36,6 +40,7 @@ import Data.Default
36import Data.List as L 40import Data.List as L
37import Data.Monoid 41import Data.Monoid
38import Data.Serialize as S 42import Data.Serialize as S
43import Data.Ratio
39import Data.Word 44import Data.Word
40 45
41 46
@@ -111,3 +116,14 @@ enqueuedProgress amount = left +~ fromIntegral amount
111dequeuedProgress :: Integer -> Progress -> Progress 116dequeuedProgress :: Integer -> Progress -> Progress
112dequeuedProgress amount = left -~ fromIntegral amount 117dequeuedProgress amount = left -~ fromIntegral amount
113{-# INLINE dequeuedProgress #-} 118{-# INLINE dequeuedProgress #-}
119
120ri2rw64 :: Ratio Int -> Ratio Word64
121ri2rw64 x = fromIntegral (numerator x) % fromIntegral (denominator x)
122
123-- | Check global /download/ limit by uploaded \/ downloaded ratio.
124canDownload :: Ratio Int -> Progress -> Bool
125canDownload limit Progress {..} = _uploaded % _downloaded > ri2rw64 limit
126
127-- | Check global /upload/ limit by downloaded \/ uploaded ratio.
128canUpload :: Ratio Int -> Progress -> Bool
129canUpload limit Progress {..} = _downloaded % _uploaded > ri2rw64 limit