summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-04 03:42:37 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-04 03:42:37 +0400
commit5120f62b06f8b337ee885ff61bd1e07b34c47581 (patch)
tree0f1d289b8454b69e8135548af1117f8bdea62c49 /src/Network
parent3b76aa644cffbfb36953146663930b69ced0d18c (diff)
+ Add JSON instance for ScrapeInfo.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent.hs2
-rw-r--r--src/Network/BitTorrent/Tracker.hs19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index 95a4c4e3..4f6eaf16 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -151,6 +151,8 @@ exchange storage = {-# SCC exchange #-} (awaitEvent >>= handler)
151 when done $ do 151 when done $ do
152 yieldEvent $ Available $ singleton blkPiece (succ blkPiece) 152 yieldEvent $ Available $ singleton blkPiece (succ blkPiece)
153 153
154 -- WARN this is not reliable: if peer do not return all piece
155 -- block we could slow don't until some other event occured
154 offer <- peerOffer 156 offer <- peerOffer
155 if BF.null offer 157 if BF.null offer
156 then return () 158 then return ()
diff --git a/src/Network/BitTorrent/Tracker.hs b/src/Network/BitTorrent/Tracker.hs
index bfe4182d..01e61025 100644
--- a/src/Network/BitTorrent/Tracker.hs
+++ b/src/Network/BitTorrent/Tracker.hs
@@ -42,6 +42,8 @@ import Control.Concurrent.BoundedChan as BC
42import Control.Concurrent.STM 42import Control.Concurrent.STM
43import Control.Exception 43import Control.Exception
44import Control.Monad 44import Control.Monad
45
46import Data.Aeson hiding (Result)
45import Data.BEncode 47import Data.BEncode
46import Data.ByteString (ByteString) 48import Data.ByteString (ByteString)
47import qualified Data.ByteString as B 49import qualified Data.ByteString as B
@@ -287,6 +289,23 @@ instance BEncodable ScrapeInfo where
287 <*> d >--? "name" 289 <*> d >--? "name"
288 fromBEncode _ = decodingError "ScrapeInfo" 290 fromBEncode _ = decodingError "ScrapeInfo"
289 291
292instance ToJSON ScrapeInfo where
293 toJSON ScrapeInfo {..} = object
294 [ "complete" .= siComplete
295 , "downloaded" .= siDownloaded
296 , "incomplete" .= siIncomplete
297 , "name" .= siName
298 ]
299
300instance FromJSON ScrapeInfo where
301 parseJSON (Object obj) = do
302 ScrapeInfo <$> obj .: "complete"
303 <*> obj .: "downloaded"
304 <*> obj .: "incomplete"
305 <*> obj .:? "name"
306
307 parseJSON _ = fail "ScrapeInfo"
308
290-- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL' 309-- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL'
291-- gives 'Nothing' then tracker do not support scraping. The info hash 310-- gives 'Nothing' then tracker do not support scraping. The info hash
292-- list is used to restrict the tracker's report to that particular 311-- list is used to restrict the tracker's report to that particular