diff options
Diffstat (limited to 'src/Network/BitTorrent/Tracker/Message.hs')
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 53d7a946..3447a367 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -155,7 +155,7 @@ data AnnounceQuery = AnnounceQuery | |||
155 | 155 | ||
156 | -- | If not specified, the request is regular periodic request. | 156 | -- | If not specified, the request is regular periodic request. |
157 | , reqEvent :: Maybe Event | 157 | , reqEvent :: Maybe Event |
158 | } deriving (Show, Typeable) | 158 | } deriving (Show, Eq, Typeable) |
159 | 159 | ||
160 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) | 160 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) |
161 | 161 | ||
@@ -233,8 +233,9 @@ data QueryParam | |||
233 | deriving (Show, Eq, Ord, Enum) | 233 | deriving (Show, Eq, Ord, Enum) |
234 | 234 | ||
235 | data ParamParseFailure | 235 | data ParamParseFailure |
236 | = Missing QueryParam -- ^ param not found in query string; | 236 | = Missing QueryParam -- ^ param not found in query string; |
237 | | Invalid QueryParam -- ^ param present but not valid. | 237 | | Invalid QueryParam Text -- ^ param present but not valid. |
238 | deriving (Show, Eq) | ||
238 | 239 | ||
239 | type ParamResult = Either ParamParseFailure | 240 | type ParamResult = Either ParamParseFailure |
240 | 241 | ||
@@ -271,11 +272,11 @@ parseAnnounceQuery params = AnnounceQuery | |||
271 | where | 272 | where |
272 | withError e = maybe (Left e) Right | 273 | withError e = maybe (Left e) Right |
273 | reqParam param p = withError (Missing param) . L.lookup (paramName param) | 274 | reqParam param p = withError (Missing param) . L.lookup (paramName param) |
274 | >=> withError (Invalid param) . p | 275 | >=> \x -> withError (Invalid param x) (p x) |
275 | 276 | ||
276 | optParam param p ps | 277 | optParam param p ps |
277 | | Just x <- L.lookup (paramName param) ps | 278 | | Just x <- L.lookup (paramName param) ps |
278 | = pure <$> withError (Invalid param) (p x) | 279 | = pure <$> withError (Invalid param x) (p x) |
279 | | otherwise = pure Nothing | 280 | | otherwise = pure Nothing |
280 | 281 | ||
281 | progress = undefined | 282 | progress = undefined |
@@ -426,8 +427,8 @@ invalidOffset = 150 | |||
426 | -- <https://wiki.theory.org/BitTorrent_Tracker_Protocol#Response_Codes> | 427 | -- <https://wiki.theory.org/BitTorrent_Tracker_Protocol#Response_Codes> |
427 | -- | 428 | -- |
428 | paramFailureCode :: ParamParseFailure -> Int | 429 | paramFailureCode :: ParamParseFailure -> Int |
429 | paramFailureCode (Missing param) = missingOffset + fromEnum param | 430 | paramFailureCode (Missing param ) = missingOffset + fromEnum param |
430 | paramFailureCode (Invalid param) = invalidOffset + fromEnum param | 431 | paramFailureCode (Invalid param _) = invalidOffset + fromEnum param |
431 | 432 | ||
432 | {----------------------------------------------------------------------- | 433 | {----------------------------------------------------------------------- |
433 | Scrape message | 434 | Scrape message |