diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC.hs | 9 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC/HTTP.hs | 10 |
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 | ||
26 | import Control.Exception | 26 | import Control.Exception |
27 | import Control.Monad.Trans.Resource | ||
28 | import Data.Default | 27 | import Data.Default |
29 | import Network | 28 | import Network |
30 | import Network.URI | 29 | import Network.URI |
@@ -130,13 +129,13 @@ dispatch URI {..} http udp | |||
130 | announce :: Manager -> URI -> SAnnounceQuery -> IO AnnounceInfo | 129 | announce :: Manager -> URI -> SAnnounceQuery -> IO AnnounceInfo |
131 | announce Manager {..} uri simpleQuery | 130 | announce 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 | ||
138 | scrape :: Manager -> URI -> ScrapeQuery -> IO ScrapeInfo | 137 | scrape :: Manager -> URI -> ScrapeQuery -> IO ScrapeInfo |
139 | scrape Manager {..} uri q | 138 | scrape 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 | ||
109 | httpTracker :: BEncode a => Manager -> URI -> SimpleQuery -> ResourceT IO a | 109 | httpTracker :: BEncode a => Manager -> URI -> SimpleQuery -> IO a |
110 | httpTracker Manager {..} uri q = do | 110 | httpTracker 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 | -- |
124 | announce :: Manager -> URI -> AnnounceQuery -> ResourceT IO AnnounceInfo | 124 | announce :: Manager -> URI -> AnnounceQuery -> IO AnnounceInfo |
125 | announce mgr uri q = httpTracker mgr uri (renderAnnounceRequest uriQ) | 125 | announce 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 | -- |
151 | scrape :: Manager -> URI -> ScrapeQuery -> ResourceT IO ScrapeInfo | 151 | scrape :: Manager -> URI -> ScrapeQuery -> IO ScrapeInfo |
152 | scrape m u q = do | 152 | scrape 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 | -- |
159 | scrapeOne :: Manager -> URI -> InfoHash -> ResourceT IO ScrapeEntry | 159 | scrapeOne :: Manager -> URI -> InfoHash -> IO ScrapeEntry |
160 | scrapeOne m uri ih = do | 160 | scrapeOne 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 |