diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-28 16:58:25 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-28 16:58:25 +0400 |
commit | fd44b038069fceeb454db082c71d5abd280c72ae (patch) | |
tree | c8d783f4542be427a657e5831e2404c706665bbf /src/Network/BitTorrent | |
parent | 183a9ac68444d49aa4dfcc690a50b683a3154874 (diff) |
Implement new AnnounceQuery to query string encoding
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 4b09d367..9ce2e67b 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -164,30 +164,25 @@ data AnnounceQuery = AnnounceQuery | |||
164 | 164 | ||
165 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) | 165 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) |
166 | 166 | ||
167 | -- instance URLShow PortNumber where | 167 | instance QueryValueLike PortNumber where |
168 | -- urlShow = urlShow . fromEnum | 168 | toQueryValue = toQueryValue . show . fromEnum |
169 | 169 | ||
170 | -- instance URLShow Word32 where | 170 | instance QueryValueLike Word32 where |
171 | -- urlShow = show | 171 | toQueryValue = toQueryValue . show |
172 | -- {-# INLINE urlShow #-} | ||
173 | 172 | ||
174 | 173 | instance QueryValueLike Int where | |
175 | --instance URLEncode AnnounceQuery where | 174 | toQueryValue = toQueryValue . show |
176 | -- urlEncode AnnounceQuery {..} = mconcat | ||
177 | -- [ -- s "peer_id" %= reqPeerId | ||
178 | -- s "port" %= reqPort | ||
179 | -- , urlEncode reqProgress | ||
180 | -- , s "ip" %=? reqIP | ||
181 | -- , s "numwant" %=? reqNumWant | ||
182 | -- , s "event" %=? reqEvent | ||
183 | -- ] | ||
184 | -- where s :: String -> String; s = id; {-# INLINE s #-} | ||
185 | 175 | ||
186 | -- | HTTP tracker protocol compatible encoding. | 176 | -- | HTTP tracker protocol compatible encoding. |
187 | instance QueryLike AnnounceQuery where | 177 | instance QueryLike AnnounceQuery where |
188 | toQuery AnnounceQuery {..} = | 178 | toQuery AnnounceQuery {..} = |
179 | toQuery reqProgress ++ | ||
189 | [ ("info_hash", toQueryValue reqInfoHash) | 180 | [ ("info_hash", toQueryValue reqInfoHash) |
190 | , ("peer_id" , toQueryValue reqPeerId) | 181 | , ("peer_id" , toQueryValue reqPeerId) |
182 | , ("port" , toQueryValue reqPort) | ||
183 | , ("ip" , toQueryValue reqIP) | ||
184 | , ("numwant" , toQueryValue reqNumWant) | ||
185 | , ("event" , toQueryValue reqEvent) | ||
191 | ] | 186 | ] |
192 | 187 | ||
193 | -- | UDP tracker protocol compatible encoding. | 188 | -- | UDP tracker protocol compatible encoding. |
@@ -232,7 +227,7 @@ instance Serialize AnnounceQuery where | |||
232 | 227 | ||
233 | -- | Encode announce query and add it to the base tracker URL. | 228 | -- | Encode announce query and add it to the base tracker URL. |
234 | renderAnnounceQuery :: AnnounceQuery -> SimpleQuery | 229 | renderAnnounceQuery :: AnnounceQuery -> SimpleQuery |
235 | renderAnnounceQuery req = undefined | 230 | renderAnnounceQuery = filterMaybes . toQuery |
236 | where | 231 | where |
237 | filterMaybes :: [(a, Maybe b)] -> [(a, b)] | 232 | filterMaybes :: [(a, Maybe b)] -> [(a, b)] |
238 | filterMaybes = catMaybes . L.map f | 233 | filterMaybes = catMaybes . L.map f |