diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC/Message.hs | 37 |
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 | ||
226 | filterMaybes :: [(a, Maybe b)] -> [(a, b)] | ||
227 | filterMaybes = 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. |
228 | renderAnnounceQuery :: AnnounceQuery -> SimpleQuery | 233 | renderAnnounceQuery :: AnnounceQuery -> SimpleQuery |
229 | renderAnnounceQuery = filterMaybes . toQuery | 234 | renderAnnounceQuery = 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 | ||
237 | data QueryParam | 236 | data QueryParam |
238 | = ParamInfoHash | 237 | = ParamInfoHash |
@@ -481,11 +480,33 @@ parseFailureStatus = mkStatus <$> parseFailureCode <*> parseFailureMessage | |||
481 | 480 | ||
482 | type ScrapeQuery = [InfoHash] | 481 | type 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 | |||
496 | scrapeParam :: BS.ByteString | ||
497 | scrapeParam = "info_hash" | ||
498 | |||
499 | isScrapeParam :: BS.ByteString -> Bool | ||
500 | isScrapeParam = (==) scrapeParam | ||
501 | |||
484 | renderScrapeQuery :: ScrapeQuery -> SimpleQuery | 502 | renderScrapeQuery :: ScrapeQuery -> SimpleQuery |
485 | renderScrapeQuery = undefined | 503 | renderScrapeQuery = filterMaybes . L.map mkPair |
504 | where | ||
505 | mkPair ih = (scrapeParam, toQueryValue ih) | ||
486 | 506 | ||
487 | parseScrapeQuery :: SimpleQuery -> ScrapeQuery | 507 | parseScrapeQuery :: SimpleQuery -> ScrapeQuery |
488 | parseScrapeQuery = undefined | 508 | parseScrapeQuery |
509 | = catMaybes . L.map (fromParam . snd) . L.filter (isScrapeParam . fst) | ||
489 | 510 | ||
490 | -- | Overall information about particular torrent. | 511 | -- | Overall information about particular torrent. |
491 | data ScrapeEntry = ScrapeEntry { | 512 | data ScrapeEntry = ScrapeEntry { |