summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-08-17 21:43:22 +0400
committerSam T <pxqr.sta@gmail.com>2013-08-17 21:43:22 +0400
commitde48f6eee93a719c170ef68a0924db83ab0de12d (patch)
tree808a33d5f039e2f5dafd6e0557df43d3d6bfb017 /src/Network
parent455471d2f47f6cde21212a9bab14ee959a0a8fb2 (diff)
~ Remove transaction info in result.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Tracker/UDP.hs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/Network/BitTorrent/Tracker/UDP.hs b/src/Network/BitTorrent/Tracker/UDP.hs
index 7d413a9c..6143a1e1 100644
--- a/src/Network/BitTorrent/Tracker/UDP.hs
+++ b/src/Network/BitTorrent/Tracker/UDP.hs
@@ -19,6 +19,7 @@ module Network.BitTorrent.Tracker.UDP
19 , putTracker 19 , putTracker
20 , connectUDP 20 , connectUDP
21 , freshConnection 21 , freshConnection
22 , announceUDP
22 ) where 23 ) where
23 24
24import Control.Applicative 25import Control.Applicative
@@ -30,7 +31,7 @@ import Data.List as L
30import Data.Maybe 31import Data.Maybe
31import Data.Monoid 32import Data.Monoid
32import Data.Serialize 33import Data.Serialize
33import Data.Text 34import Data.Text as T
34import Data.Text.Encoding 35import Data.Text.Encoding
35import Data.Time 36import Data.Time
36import Data.Word 37import Data.Word
@@ -264,7 +265,7 @@ putTracker UDPTracker {..} = do
264 print trackerURI 265 print trackerURI
265 print =<< readIORef trackerConnection 266 print =<< readIORef trackerConnection
266 267
267transaction :: UDPTracker -> Request -> IO (Transaction Response) 268transaction :: UDPTracker -> Request -> IO Response
268transaction tracker @ UDPTracker {..} request = do 269transaction tracker @ UDPTracker {..} request = do
269 cid <- getConnectionId tracker 270 cid <- getConnectionId tracker
270 tid <- genTransactionId 271 tid <- genTransactionId
@@ -273,16 +274,18 @@ transaction tracker @ UDPTracker {..} request = do
273 addr <- getTrackerAddr trackerURI 274 addr <- getTrackerAddr trackerURI
274 res <- call addr (encode trans) 275 res <- call addr (encode trans)
275 case decode res of 276 case decode res of
276 Right (responseT @ TransactionR {..}) 277 Right (TransactionR {..})
277 | tid == transIdR -> return responseT 278 | tid == transIdR -> return response
278 | otherwise -> throwIO $ userError "transaction id mismatch" 279 | otherwise -> throwIO $ userError "transaction id mismatch"
279 Left msg -> throwIO $ userError msg 280 Left msg -> throwIO $ userError msg
280 281
281connectUDP :: UDPTracker -> IO ConnectionId 282connectUDP :: UDPTracker -> IO ConnectionId
282connectUDP tracker = do 283connectUDP tracker = do
283 TransactionR tid resp <- transaction tracker Connect 284 resp <- transaction tracker Connect
284 case resp of 285 case resp of
285 Connected cid -> return cid 286 Connected cid -> return cid
287 Failed msg -> throwIO $ userError $ T.unpack msg
288 _ -> throwIO $ userError "message type mismatch"
286 289
287initialTracker :: URI -> IO UDPTracker 290initialTracker :: URI -> IO UDPTracker
288initialTracker uri = do 291initialTracker uri = do
@@ -299,22 +302,19 @@ freshConnection tracker @ UDPTracker {..} = do
299 connId <- connectUDP tracker 302 connId <- connectUDP tracker
300 updateConnection connId tracker 303 updateConnection connId tracker
301 304
302{-
303
304announceUDP :: UDPTracker -> AnnounceQuery -> IO AnnounceInfo 305announceUDP :: UDPTracker -> AnnounceQuery -> IO AnnounceInfo
305announceUDP t query = do 306announceUDP tracker ann = do
306 Transaction tid cid resp <- call transaction (Announce query) 307 resp <- transaction tracker (Announce ann)
307 case resp of 308 case resp of
308 Announced info -> return info 309 Announced info -> return info
309 _ -> fail "response type mismatch" 310 _ -> fail "response type mismatch"
310 311
311scrapeUDP :: UDPTracker -> ScrapeQuery -> IO Scrape 312scrapeUDP :: UDPTracker -> ScrapeQuery -> IO Scrape
312scrapeUDP UDPTracker {..} query = do 313scrapeUDP tracker scr = do
313 resp <- call trackerURI $ Scrape query 314 resp <- transaction tracker (Scrape scr)
314 case resp of 315 case resp of
315 Scraped scrape -> return undefined 316 Scraped scrape -> return undefined
316 317
317instance Tracker UDPTracker where 318instance Tracker UDPTracker where
318 announce = announceUDP 319 announce = announceUDP
319 scrape_ = scrapeUDP 320 scrape_ = scrapeUDP
320-} \ No newline at end of file