summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Tracker/RPC/Message.hs37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/Message.hs b/src/Network/BitTorrent/Tracker/RPC/Message.hs
index 26868ead..cec68169 100644
--- a/src/Network/BitTorrent/Tracker/RPC/Message.hs
+++ b/src/Network/BitTorrent/Tracker/RPC/Message.hs
@@ -223,16 +223,15 @@ instance QueryLike AnnounceQuery where
223 , ("event" , toQueryValue reqEvent) 223 , ("event" , toQueryValue reqEvent)
224 ] 224 ]
225 225
226filterMaybes :: [(a, Maybe b)] -> [(a, b)]
227filterMaybes = catMaybes . L.map f
228 where
229 f (_, Nothing) = Nothing
230 f (a, Just b ) = Just (a, b)
226 231
227-- | Encode announce query and add it to the base tracker URL. 232-- | Encode announce query and add it to the base tracker URL.
228renderAnnounceQuery :: AnnounceQuery -> SimpleQuery 233renderAnnounceQuery :: AnnounceQuery -> SimpleQuery
229renderAnnounceQuery = filterMaybes . toQuery 234renderAnnounceQuery = filterMaybes . toQuery
230 where
231 filterMaybes :: [(a, Maybe b)] -> [(a, b)]
232 filterMaybes = catMaybes . L.map f
233 where
234 f (_, Nothing) = Nothing
235 f (a, Just b ) = Just (a, b)
236 235
237data QueryParam 236data QueryParam
238 = ParamInfoHash 237 = ParamInfoHash
@@ -481,11 +480,33 @@ parseFailureStatus = mkStatus <$> parseFailureCode <*> parseFailureMessage
481 480
482type ScrapeQuery = [InfoHash] 481type ScrapeQuery = [InfoHash]
483 482
483-- TODO
484-- data ScrapeQuery
485-- = ScrapeAll
486-- | ScrapeSingle InfoHash
487-- | ScrapeMulti (HashSet InfoHash)
488-- deriving (Show)
489--
490-- data ScrapeInfo
491-- = ScrapeAll (HashMap InfoHash ScrapeEntry)
492-- | ScrapeSingle InfoHash ScrapeEntry
493-- | ScrapeMulti (HashMap InfoHash ScrapeEntry)
494--
495
496scrapeParam :: BS.ByteString
497scrapeParam = "info_hash"
498
499isScrapeParam :: BS.ByteString -> Bool
500isScrapeParam = (==) scrapeParam
501
484renderScrapeQuery :: ScrapeQuery -> SimpleQuery 502renderScrapeQuery :: ScrapeQuery -> SimpleQuery
485renderScrapeQuery = undefined 503renderScrapeQuery = filterMaybes . L.map mkPair
504 where
505 mkPair ih = (scrapeParam, toQueryValue ih)
486 506
487parseScrapeQuery :: SimpleQuery -> ScrapeQuery 507parseScrapeQuery :: SimpleQuery -> ScrapeQuery
488parseScrapeQuery = undefined 508parseScrapeQuery
509 = catMaybes . L.map (fromParam . snd) . L.filter (isScrapeParam . fst)
489 510
490-- | Overall information about particular torrent. 511-- | Overall information about particular torrent.
491data ScrapeEntry = ScrapeEntry { 512data ScrapeEntry = ScrapeEntry {