diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-08-17 19:43:31 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-08-17 19:43:31 +0400 |
commit | ca2e04725e3fa9adf7f9f1acac8588dde6d95cde (patch) | |
tree | 70fb7e90b3e6fe73367cb468e8027b665b24958f /src/Network/BitTorrent/Tracker/HTTP.hs | |
parent | ec3d89b295a004e992dec3ba03a7efe9a1b62fe2 (diff) |
~ Cosmetic changes.
Diffstat (limited to 'src/Network/BitTorrent/Tracker/HTTP.hs')
-rw-r--r-- | src/Network/BitTorrent/Tracker/HTTP.hs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Tracker/HTTP.hs b/src/Network/BitTorrent/Tracker/HTTP.hs index 4fef5e56..8d3a6412 100644 --- a/src/Network/BitTorrent/Tracker/HTTP.hs +++ b/src/Network/BitTorrent/Tracker/HTTP.hs | |||
@@ -33,6 +33,17 @@ import Network.HTTP | |||
33 | import Data.Torrent.Metainfo hiding (announce) | 33 | import Data.Torrent.Metainfo hiding (announce) |
34 | import Network.BitTorrent.Tracker.Protocol | 34 | import Network.BitTorrent.Tracker.Protocol |
35 | 35 | ||
36 | |||
37 | data HTTPTracker = HTTPTracker URI | ||
38 | |||
39 | instance Tracker URI where | ||
40 | announce = askTracker | ||
41 | scrape_ uri ihs = do | ||
42 | e <- scrape uri ihs | ||
43 | case e of | ||
44 | Left str -> error str | ||
45 | Right si -> return si | ||
46 | |||
36 | {----------------------------------------------------------------------- | 47 | {----------------------------------------------------------------------- |
37 | Announce | 48 | Announce |
38 | -----------------------------------------------------------------------} | 49 | -----------------------------------------------------------------------} |
@@ -42,8 +53,8 @@ encodeRequest announce req = URL.urlEncode req | |||
42 | `addToURI` announce | 53 | `addToURI` announce |
43 | `addHashToURI` reqInfoHash req | 54 | `addHashToURI` reqInfoHash req |
44 | 55 | ||
45 | mkHTTPRequest :: URI -> Request ByteString | 56 | mkGET :: URI -> Request ByteString |
46 | mkHTTPRequest uri = Request uri GET [] "" | 57 | mkGET uri = Request uri GET [] "" |
47 | 58 | ||
48 | -- TODO rename to something like "announceBlahBlah" | 59 | -- TODO rename to something like "announceBlahBlah" |
49 | 60 | ||
@@ -53,7 +64,7 @@ mkHTTPRequest uri = Request uri GET [] "" | |||
53 | -- | 64 | -- |
54 | askTracker :: URI -> AnnounceQuery -> IO AnnounceInfo | 65 | askTracker :: URI -> AnnounceQuery -> IO AnnounceInfo |
55 | askTracker announce req = do | 66 | askTracker announce req = do |
56 | let r = mkHTTPRequest (encodeRequest announce req) | 67 | let r = mkGET (encodeRequest announce req) |
57 | 68 | ||
58 | rawResp <- simpleHTTP r | 69 | rawResp <- simpleHTTP r |
59 | respBody <- getResponseBody rawResp | 70 | respBody <- getResponseBody rawResp |
@@ -69,16 +80,13 @@ askTracker announce req = do | |||
69 | -- conjunction with 'Stopped'. | 80 | -- conjunction with 'Stopped'. |
70 | leaveTracker :: URI -> AnnounceQuery -> IO () | 81 | leaveTracker :: URI -> AnnounceQuery -> IO () |
71 | leaveTracker announce req = do | 82 | leaveTracker announce req = do |
72 | let r = mkHTTPRequest (encodeRequest announce req) | 83 | let r = mkGET (encodeRequest announce req) |
73 | void $ simpleHTTP r >>= getResponseBody | 84 | void $ simpleHTTP r >>= getResponseBody |
74 | 85 | ||
75 | {----------------------------------------------------------------------- | 86 | {----------------------------------------------------------------------- |
76 | Scrape | 87 | Scrape |
77 | -----------------------------------------------------------------------} | 88 | -----------------------------------------------------------------------} |
78 | 89 | ||
79 | -- | Scrape info about a set of torrents. | ||
80 | type Scrape = Map InfoHash ScrapeInfo | ||
81 | |||
82 | -- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL' | 90 | -- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL' |
83 | -- gives 'Nothing' then tracker do not support scraping. The info hash | 91 | -- gives 'Nothing' then tracker do not support scraping. The info hash |
84 | -- list is used to restrict the tracker's report to that particular | 92 | -- list is used to restrict the tracker's report to that particular |