summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Internal
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-03-20 03:19:14 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-03-20 03:19:14 +0400
commit95f519df298c98d966c6408cac33cdd57b8e8a03 (patch)
treee6b0fb3ba6dafd6771cfc5084fcb3f7b1a7e26da /src/Network/BitTorrent/Internal
parent17949276fbd32ab75bcb18016210b6947df54ed1 (diff)
Add instance ToJSON TrackerEntry
Diffstat (limited to 'src/Network/BitTorrent/Internal')
-rw-r--r--src/Network/BitTorrent/Internal/Cache.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Internal/Cache.hs b/src/Network/BitTorrent/Internal/Cache.hs
index 8c74467a..b77e5e82 100644
--- a/src/Network/BitTorrent/Internal/Cache.hs
+++ b/src/Network/BitTorrent/Internal/Cache.hs
@@ -32,6 +32,7 @@ module Network.BitTorrent.Internal.Cache
32 ) where 32 ) where
33 33
34import Control.Applicative 34import Control.Applicative
35import Data.Aeson
35import Data.Monoid 36import Data.Monoid
36import Data.Default 37import Data.Default
37import Data.Time 38import Data.Time
@@ -55,6 +56,19 @@ data Cached a = Cached
55 56
56-- INVARIANT: minUpdateInterval <= updateInterval 57-- INVARIANT: minUpdateInterval <= updateInterval
57 58
59-- | TODO exsample
60instance ToJSON a => ToJSON (Cached a) where
61 toJSON Cached {..}
62 | currentTime < expireTime = object
63 [ "observed" .= posixSecondsToUTCTime lastUpdated
64 , "expired" .= posixSecondsToUTCTime expireTime
65 , "data" .= cachedData
66 ]
67 | otherwise = String "cached data expired"
68 where
69 expireTime = currentTime + updateInterval
70 currentTime = unsafePerformIO getPOSIXTime
71
58instance Default (Cached a) where 72instance Default (Cached a) where
59 def = mempty 73 def = mempty
60 74