summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Tracker/Message.hs52
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
164instance QueryValueLike PortNumber where
165 toQueryValue = toQueryValue . show . fromEnum
166
167instance QueryValueLike Word32 where
168 toQueryValue = toQueryValue . show
169
170instance QueryValueLike Int where
171 toQueryValue = toQueryValue . show
172
173-- | HTTP tracker protocol compatible encoding.
174instance 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.
186instance Serialize AnnounceQuery where 165instance 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
201instance QueryValueLike PortNumber where
202 toQueryValue = toQueryValue . show . fromEnum
203
204instance QueryValueLike Word32 where
205 toQueryValue = toQueryValue . show
206
207instance QueryValueLike Int where
208 toQueryValue = toQueryValue . show
209
210-- | HTTP tracker protocol compatible encoding.
211instance 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
247data 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
252paramName :: QueryParam -> BS.ByteString 247paramName :: QueryParam -> BS.ByteString
253paramName ParamInfoHash = "info_hash" 248paramName ParamInfoHash = "info_hash"
254paramName ParamPeerId = "peer_id" 249paramName 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
284data 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
289type Result = Either ParamParseFailure 289type Result = Either ParamParseFailure
290 290
291withError :: ParamParseFailure -> Maybe a -> Result a 291withError :: ParamParseFailure -> Maybe a -> Result a