diff options
Diffstat (limited to 'src/Network/Torrent/Tracker.hs')
-rw-r--r-- | src/Network/Torrent/Tracker.hs | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/src/Network/Torrent/Tracker.hs b/src/Network/Torrent/Tracker.hs index 5faa1dd9..ef2413f6 100644 --- a/src/Network/Torrent/Tracker.hs +++ b/src/Network/Torrent/Tracker.hs | |||
@@ -30,7 +30,6 @@ import Network.HTTP | |||
30 | import Network.URI | 30 | import Network.URI |
31 | import Network.Torrent.PeerID | 31 | import Network.Torrent.PeerID |
32 | 32 | ||
33 | import Numeric | ||
34 | 33 | ||
35 | data Peer = Peer { | 34 | data Peer = Peer { |
36 | peerID :: Maybe PeerID | 35 | peerID :: Maybe PeerID |
@@ -150,22 +149,9 @@ instance URLEncode TRequest where | |||
150 | where s :: String -> String; s = id; {-# INLINE s #-} | 149 | where s :: String -> String; s = id; {-# INLINE s #-} |
151 | 150 | ||
152 | encodeRequest :: TRequest -> URI | 151 | encodeRequest :: TRequest -> URI |
153 | encodeRequest req = URL.urlEncode req `addToURI` reqAnnounce req | 152 | encodeRequest req = URL.urlEncode req |
154 | `addHash` BC.unpack (getInfoHash (reqInfoHash req)) | 153 | `addToURI` reqAnnounce req |
155 | where | 154 | `addHashToURI` reqInfoHash req |
156 | addHash :: URI -> String -> URI | ||
157 | addHash uri s = uri { uriQuery = uriQuery uri ++ "&info_hash=" ++ rfc1738Encode s } | ||
158 | |||
159 | rfc1738Encode :: String -> String | ||
160 | rfc1738Encode = L.concatMap (\c -> if unreserved c then [c] else encode c) | ||
161 | where | ||
162 | unreserved = (`L.elem` chars) | ||
163 | chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_./" | ||
164 | encode :: Char -> String | ||
165 | encode c = '%' : pHex c | ||
166 | pHex c = | ||
167 | let p = (showHex . ord $ c) "" | ||
168 | in if L.length p == 1 then '0' : p else p | ||
169 | 155 | ||
170 | 156 | ||
171 | -- | Ports typically reserved for bittorrent. | 157 | -- | Ports typically reserved for bittorrent. |