From 03841eb1f2e8e0d38833b8855a55e393fb4d766a Mon Sep 17 00:00:00 2001 From: Sam T Date: Wed, 28 Aug 2013 04:56:52 +0400 Subject: ~ Adapt HTTP Tracker to new interface. --- src/Network/BitTorrent/Tracker/Protocol.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/Network/BitTorrent/Tracker/Protocol.hs') diff --git a/src/Network/BitTorrent/Tracker/Protocol.hs b/src/Network/BitTorrent/Tracker/Protocol.hs index 3f264aed..965f3480 100644 --- a/src/Network/BitTorrent/Tracker/Protocol.hs +++ b/src/Network/BitTorrent/Tracker/Protocol.hs @@ -39,12 +39,13 @@ module Network.BitTorrent.Tracker.Protocol -- * TODO , Tracker(..) + , scrapeOne ) where import Control.Applicative +import Control.Exception import Control.Monad - import Data.Aeson.TH import Data.Char as Char import Data.Map as M @@ -58,12 +59,11 @@ import Data.Text.Encoding import Data.Serialize hiding (Result) import Data.URLEncoded as URL import Data.Torrent.Metainfo - import Network +import Network.URI import Network.Socket import Network.BitTorrent.Peer -import Network.BitTorrent.Sessions.Types {----------------------------------------------------------------------- Announce messages @@ -365,5 +365,13 @@ instance Serialize ScrapeInfo where -- | Set of tracker RPCs. class Tracker s where + connect :: URI -> IO s announce :: s -> AnnounceQuery -> IO AnnounceInfo - scrape_ :: s -> ScrapeQuery -> IO Scrape + scrape :: s -> ScrapeQuery -> IO Scrape + +-- | More particular version of 'scrape', just for one torrent. +-- +scrapeOne :: Tracker t => t -> InfoHash -> IO ScrapeInfo +scrapeOne uri ih = scrape uri [ih] >>= maybe err return . M.lookup ih + where + err = throwIO $ userError "unable to find info hash in response dict" -- cgit v1.2.3