summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Tracker
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Tracker')
-rw-r--r--src/Network/BitTorrent/Tracker/Message.hs23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs
index 0d720471..d0be1c36 100644
--- a/src/Network/BitTorrent/Tracker/Message.hs
+++ b/src/Network/BitTorrent/Tracker/Message.hs
@@ -45,6 +45,7 @@ module Network.BitTorrent.Tracker.Message
45 45
46 -- ** Info 46 -- ** Info
47 , PeerList (..) 47 , PeerList (..)
48 , getPeerList
48 , AnnounceInfo(..) 49 , AnnounceInfo(..)
49 , defaultNumWant 50 , defaultNumWant
50 , defaultMaxNumWant 51 , defaultMaxNumWant
@@ -435,24 +436,22 @@ renderAnnounceRequest = queryToSimpleQuery . toQuery
435-- 436--
436-- For more info see: <http://www.bittorrent.org/beps/bep_0023.html> 437-- For more info see: <http://www.bittorrent.org/beps/bep_0023.html>
437-- 438--
438data PeerList a 439data PeerList ip
439 = PeerList { getPeerList :: [PeerAddr a] } 440 = PeerList [PeerAddr IP]
440 | CompactPeerList { getPeerList :: [PeerAddr a] } 441 | CompactPeerList [PeerAddr ip]
441 deriving (Show, Eq, Typeable, Functor) 442 deriving (Show, Eq, Typeable, Functor)
442 443
443putCompactPeerList :: (Serialize a) => S.Putter [PeerAddr a] 444getPeerList :: PeerList IP -> [PeerAddr IP]
444putCompactPeerList = mapM_ put 445getPeerList (PeerList xs) = xs
446getPeerList (CompactPeerList xs) = xs
445 447
446getCompactPeerList :: (Serialize a) => S.Get [PeerAddr a] 448instance Serialize a => BEncode (PeerList a) where
447getCompactPeerList = many get
448
449instance (Typeable a, BEncode a, Serialize a) => BEncode (PeerList a) where
450 toBEncode (PeerList xs) = toBEncode xs 449 toBEncode (PeerList xs) = toBEncode xs
451 toBEncode (CompactPeerList xs) = toBEncode $ runPut (putCompactPeerList xs) 450 toBEncode (CompactPeerList xs) = toBEncode $ runPut (mapM_ put xs)
452 451
453 fromBEncode (BList l ) = PeerList <$> fromBEncode (BList l) 452 fromBEncode (BList l ) = PeerList <$> fromBEncode (BList l)
454 fromBEncode (BString s ) = CompactPeerList <$> runGet getCompactPeerList s 453 fromBEncode (BString s ) = CompactPeerList <$> runGet (many get) s
455 fromBEncode _ = decodingError "Peer list" 454 fromBEncode _ = decodingError "PeerList: should be a BString or BList"
456 455
457-- | The tracker response includes a peer list that helps the client 456-- | The tracker response includes a peer list that helps the client
458-- participate in the torrent. The most important is 'respPeer' list 457-- participate in the torrent. The most important is 'respPeer' list