diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 9999d128..dde13155 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -161,27 +161,6 @@ data AnnounceQuery = AnnounceQuery | |||
161 | 161 | ||
162 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) | 162 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) |
163 | 163 | ||
164 | instance QueryValueLike PortNumber where | ||
165 | toQueryValue = toQueryValue . show . fromEnum | ||
166 | |||
167 | instance QueryValueLike Word32 where | ||
168 | toQueryValue = toQueryValue . show | ||
169 | |||
170 | instance QueryValueLike Int where | ||
171 | toQueryValue = toQueryValue . show | ||
172 | |||
173 | -- | HTTP tracker protocol compatible encoding. | ||
174 | instance QueryLike AnnounceQuery where | ||
175 | toQuery AnnounceQuery {..} = | ||
176 | toQuery reqProgress ++ | ||
177 | [ ("info_hash", toQueryValue reqInfoHash) | ||
178 | , ("peer_id" , toQueryValue reqPeerId) | ||
179 | , ("port" , toQueryValue reqPort) | ||
180 | , ("ip" , toQueryValue reqIP) | ||
181 | , ("numwant" , toQueryValue reqNumWant) | ||
182 | , ("event" , toQueryValue reqEvent) | ||
183 | ] | ||
184 | |||
185 | -- | UDP tracker protocol compatible encoding. | 164 | -- | UDP tracker protocol compatible encoding. |
186 | instance Serialize AnnounceQuery where | 165 | instance Serialize AnnounceQuery where |
187 | put AnnounceQuery {..} = do | 166 | put AnnounceQuery {..} = do |
@@ -219,6 +198,27 @@ instance Serialize AnnounceQuery where | |||
219 | , reqEvent = ev | 198 | , reqEvent = ev |
220 | } | 199 | } |
221 | 200 | ||
201 | instance QueryValueLike PortNumber where | ||
202 | toQueryValue = toQueryValue . show . fromEnum | ||
203 | |||
204 | instance QueryValueLike Word32 where | ||
205 | toQueryValue = toQueryValue . show | ||
206 | |||
207 | instance QueryValueLike Int where | ||
208 | toQueryValue = toQueryValue . show | ||
209 | |||
210 | -- | HTTP tracker protocol compatible encoding. | ||
211 | instance QueryLike AnnounceQuery where | ||
212 | toQuery AnnounceQuery {..} = | ||
213 | toQuery reqProgress ++ | ||
214 | [ ("info_hash", toQueryValue reqInfoHash) | ||
215 | , ("peer_id" , toQueryValue reqPeerId) | ||
216 | , ("port" , toQueryValue reqPort) | ||
217 | , ("ip" , toQueryValue reqIP) | ||
218 | , ("numwant" , toQueryValue reqNumWant) | ||
219 | , ("event" , toQueryValue reqEvent) | ||
220 | ] | ||
221 | |||
222 | --renderAnnounceQueryBuilder :: AnnounceQuery -> BS.Builder | 222 | --renderAnnounceQueryBuilder :: AnnounceQuery -> BS.Builder |
223 | --renderAnnounceQueryBuilder = undefined | 223 | --renderAnnounceQueryBuilder = undefined |
224 | 224 | ||
@@ -244,11 +244,6 @@ data QueryParam | |||
244 | | ParamEvent | 244 | | ParamEvent |
245 | deriving (Show, Eq, Ord, Enum) | 245 | deriving (Show, Eq, Ord, Enum) |
246 | 246 | ||
247 | data ParamParseFailure | ||
248 | = Missing QueryParam -- ^ param not found in query string; | ||
249 | | Invalid QueryParam BS.ByteString -- ^ param present but not valid. | ||
250 | deriving (Show, Eq) | ||
251 | |||
252 | paramName :: QueryParam -> BS.ByteString | 247 | paramName :: QueryParam -> BS.ByteString |
253 | paramName ParamInfoHash = "info_hash" | 248 | paramName ParamInfoHash = "info_hash" |
254 | paramName ParamPeerId = "peer_id" | 249 | paramName ParamPeerId = "peer_id" |
@@ -286,6 +281,11 @@ instance FromParam Event where | |||
286 | (x, xs) <- BC.uncons bs | 281 | (x, xs) <- BC.uncons bs |
287 | readMaybe $ BC.unpack $ BC.cons (Char.toUpper x) xs | 282 | readMaybe $ BC.unpack $ BC.cons (Char.toUpper x) xs |
288 | 283 | ||
284 | data ParamParseFailure | ||
285 | = Missing QueryParam -- ^ param not found in query string; | ||
286 | | Invalid QueryParam BS.ByteString -- ^ param present but not valid. | ||
287 | deriving (Show, Eq) | ||
288 | |||
289 | type Result = Either ParamParseFailure | 289 | type Result = Either ParamParseFailure |
290 | 290 | ||
291 | withError :: ParamParseFailure -> Maybe a -> Result a | 291 | withError :: ParamParseFailure -> Maybe a -> Result a |