summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-03-24 05:21:21 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-03-24 05:21:21 +0400
commitc592e8e5a267ab4142f34e0ef023c797a99f8462 (patch)
tree8b3f2ab2126be3d3cdead8b7a184d7479a48c074 /src/Network/BitTorrent
parentc09681431dfff9522eec70dc20042183e6dde119 (diff)
Allow to inspect each tier from getSessionState
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/Tracker/List.hs5
-rw-r--r--src/Network/BitTorrent/Tracker/Session.hs8
2 files changed, 9 insertions, 4 deletions
diff --git a/src/Network/BitTorrent/Tracker/List.hs b/src/Network/BitTorrent/Tracker/List.hs
index d92dd4ba..0eb11641 100644
--- a/src/Network/BitTorrent/Tracker/List.hs
+++ b/src/Network/BitTorrent/Tracker/List.hs
@@ -19,6 +19,7 @@ module Network.BitTorrent.Tracker.List
19 , trackerList 19 , trackerList
20 , shuffleTiers 20 , shuffleTiers
21 , mapWithURI 21 , mapWithURI
22 , Network.BitTorrent.Tracker.List.toList
22 23
23 -- * Traversals 24 -- * Traversals
24 , traverseAll 25 , traverseAll
@@ -138,6 +139,10 @@ mapWithURI f (TierList xs ) = TierList (L.map (L.map mapEntry) xs)
138 where 139 where
139 mapEntry (uri, a) = (uri, f uri a) 140 mapEntry (uri, a) = (uri, f uri a)
140 141
142toList :: TrackerList a -> [[TierEntry a]]
143toList (Announce e) = [[e]]
144toList (TierList xxs) = xxs
145
141{----------------------------------------------------------------------- 146{-----------------------------------------------------------------------
142-- Special traversals (suppressed RPC exceptions) 147-- Special traversals (suppressed RPC exceptions)
143-----------------------------------------------------------------------} 148-----------------------------------------------------------------------}
diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs
index 74d854c5..e82501dd 100644
--- a/src/Network/BitTorrent/Tracker/Session.hs
+++ b/src/Network/BitTorrent/Tracker/Session.hs
@@ -66,7 +66,7 @@ import Data.Torrent.InfoHash
66import Data.Torrent.JSON 66import Data.Torrent.JSON
67import Network.BitTorrent.Core 67import Network.BitTorrent.Core
68import Network.BitTorrent.Internal.Cache 68import Network.BitTorrent.Internal.Cache
69import Network.BitTorrent.Tracker.List 69import Network.BitTorrent.Tracker.List as TL
70import Network.BitTorrent.Tracker.Message 70import Network.BitTorrent.Tracker.Message
71import Network.BitTorrent.Tracker.RPC as RPC 71import Network.BitTorrent.Tracker.RPC as RPC
72 72
@@ -248,8 +248,8 @@ withSession m ih uris = bracket (newSession ih uris) (closeSession m)
248getStatus :: Session -> IO Status 248getStatus :: Session -> IO Status
249getStatus Session {..} = readIORef sessionStatus 249getStatus Session {..} = readIORef sessionStatus
250 250
251getSessionState :: Session -> IO (TrackerList TrackerSession) 251getSessionState :: Session -> IO [[TierEntry TrackerSession]]
252getSessionState Session {..} = readMVar sessionTrackers 252getSessionState Session {..} = TL.toList <$> readMVar sessionTrackers
253 253
254-- | Do we need to sent this event to a first working tracker or to 254-- | Do we need to sent this event to a first working tracker or to
255-- the all known good trackers? 255-- the all known good trackers?
@@ -287,7 +287,7 @@ askPeers _mgr ses = do
287 L.concat <$> collect (tryTakeData . trackerPeers) list 287 L.concat <$> collect (tryTakeData . trackerPeers) list
288 288
289collect :: (a -> IO (Maybe b)) -> TrackerList a -> IO [b] 289collect :: (a -> IO (Maybe b)) -> TrackerList a -> IO [b]
290collect f lst =(catMaybes . toList) <$> traverse f lst 290collect f lst = (catMaybes . F.toList) <$> traverse f lst
291 291
292--sourcePeers :: Session -> Source (PeerAddr IP) 292--sourcePeers :: Session -> Source (PeerAddr IP)
293--sourcePeers 293--sourcePeers