summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Tracker/RPC.hs9
-rw-r--r--src/Network/BitTorrent/Tracker/RPC/HTTP.hs10
2 files changed, 9 insertions, 10 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC.hs b/src/Network/BitTorrent/Tracker/RPC.hs
index 45bd62d8..bd8da02b 100644
--- a/src/Network/BitTorrent/Tracker/RPC.hs
+++ b/src/Network/BitTorrent/Tracker/RPC.hs
@@ -24,7 +24,6 @@ module Network.BitTorrent.Tracker.RPC
24 ) where 24 ) where
25 25
26import Control.Exception 26import Control.Exception
27import Control.Monad.Trans.Resource
28import Data.Default 27import Data.Default
29import Network 28import Network
30import Network.URI 29import Network.URI
@@ -130,13 +129,13 @@ dispatch URI {..} http udp
130announce :: Manager -> URI -> SAnnounceQuery -> IO AnnounceInfo 129announce :: Manager -> URI -> SAnnounceQuery -> IO AnnounceInfo
131announce Manager {..} uri simpleQuery 130announce Manager {..} uri simpleQuery
132 = dispatch uri 131 = dispatch uri
133 (runResourceT (HTTP.announce httpMgr uri annQ)) 132 (HTTP.announce httpMgr uri annQ)
134 (UDP.announce udpMgr uri annQ) 133 ( UDP.announce udpMgr uri annQ)
135 where 134 where
136 annQ = fillAnnounceQuery peerInfo simpleQuery 135 annQ = fillAnnounceQuery peerInfo simpleQuery
137 136
138scrape :: Manager -> URI -> ScrapeQuery -> IO ScrapeInfo 137scrape :: Manager -> URI -> ScrapeQuery -> IO ScrapeInfo
139scrape Manager {..} uri q 138scrape Manager {..} uri q
140 = dispatch uri 139 = dispatch uri
141 (runResourceT (HTTP.scrape httpMgr uri q)) 140 (HTTP.scrape httpMgr uri q)
142 (UDP.scrape udpMgr uri q) 141 ( UDP.scrape udpMgr uri q)
diff --git a/src/Network/BitTorrent/Tracker/RPC/HTTP.hs b/src/Network/BitTorrent/Tracker/RPC/HTTP.hs
index 7d69df1a..0a7e9a08 100644
--- a/src/Network/BitTorrent/Tracker/RPC/HTTP.hs
+++ b/src/Network/BitTorrent/Tracker/RPC/HTTP.hs
@@ -106,10 +106,10 @@ fillRequest Options {..} q r = r
106 | BS.null a = b 106 | BS.null a = b
107 | otherwise = a <> "&" <> b 107 | otherwise = a <> "&" <> b
108 108
109httpTracker :: BEncode a => Manager -> URI -> SimpleQuery -> ResourceT IO a 109httpTracker :: BEncode a => Manager -> URI -> SimpleQuery -> IO a
110httpTracker Manager {..} uri q = do 110httpTracker Manager {..} uri q = do
111 request <- fillRequest options q <$> setUri def uri 111 request <- fillRequest options q <$> setUri def uri
112 response <- httpLbs request httpMgr 112 response <- runResourceT $ httpLbs request httpMgr
113 case BE.decode $ BL.toStrict $ responseBody response of 113 case BE.decode $ BL.toStrict $ responseBody response of
114 Left msg -> error $ "httpTracker: " ++ msg 114 Left msg -> error $ "httpTracker: " ++ msg
115 Right info -> return info 115 Right info -> return info
@@ -121,7 +121,7 @@ httpTracker Manager {..} uri q = do
121-- | Send request and receive response from the tracker specified in 121-- | Send request and receive response from the tracker specified in
122-- announce list. 122-- announce list.
123-- 123--
124announce :: Manager -> URI -> AnnounceQuery -> ResourceT IO AnnounceInfo 124announce :: Manager -> URI -> AnnounceQuery -> IO AnnounceInfo
125announce mgr uri q = httpTracker mgr uri (renderAnnounceRequest uriQ) 125announce mgr uri q = httpTracker mgr uri (renderAnnounceRequest uriQ)
126 where 126 where
127 uriQ = AnnounceRequest 127 uriQ = AnnounceRequest
@@ -148,7 +148,7 @@ scrapeURL uri = do
148-- However if the info hash list is 'null', the tracker should list 148-- However if the info hash list is 'null', the tracker should list
149-- all available torrents. 149-- all available torrents.
150-- 150--
151scrape :: Manager -> URI -> ScrapeQuery -> ResourceT IO ScrapeInfo 151scrape :: Manager -> URI -> ScrapeQuery -> IO ScrapeInfo
152scrape m u q = do 152scrape m u q = do
153 case scrapeURL u of 153 case scrapeURL u of
154 Nothing -> error "Tracker do not support scraping" 154 Nothing -> error "Tracker do not support scraping"
@@ -156,7 +156,7 @@ scrape m u q = do
156 156
157-- | More particular version of 'scrape', just for one torrent. 157-- | More particular version of 'scrape', just for one torrent.
158-- 158--
159scrapeOne :: Manager -> URI -> InfoHash -> ResourceT IO ScrapeEntry 159scrapeOne :: Manager -> URI -> InfoHash -> IO ScrapeEntry
160scrapeOne m uri ih = do 160scrapeOne m uri ih = do
161 xs <- scrape m uri [ih] 161 xs <- scrape m uri [ih]
162 case L.lookup ih xs of 162 case L.lookup ih xs of