summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-03-18 17:56:51 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-03-18 17:56:51 +0400
commitcab485585f87f73274026106235edae7765dd72e (patch)
tree7c9d46109ab276ac425144564586ee43c1aac1b2
parent5b55381a4b1d7715df0cfdfcde45d04d0ad42bcd (diff)
Allow to traverseTiers with empty tracker list
-rw-r--r--src/Network/BitTorrent/Tracker/List.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Tracker/List.hs b/src/Network/BitTorrent/Tracker/List.hs
index 5ab43c86..1e22f7ec 100644
--- a/src/Network/BitTorrent/Tracker/List.hs
+++ b/src/Network/BitTorrent/Tracker/List.hs
@@ -135,11 +135,14 @@ traverseAll action = traverse (action $?)
135 135
136-- | Like 'traverse' but put working trackers to the head of tiers. 136-- | Like 'traverse' but put working trackers to the head of tiers.
137-- This can help to avoid exceessive requests to not available 137-- This can help to avoid exceessive requests to not available
138-- trackers at each reannounce. 138-- trackers at each reannounce. If no one action succeed then original
139-- list is returned.
139traverseTiers :: (a -> IO a) -> TrackerList a -> IO (TrackerList a) 140traverseTiers :: (a -> IO a) -> TrackerList a -> IO (TrackerList a)
140traverseTiers action (Announce a) = Announce <$> action a 141traverseTiers action ts = catchRPC (goList ts) (return ts)
141traverseTiers action (TierList tiers) = TierList <$> goTiers (goTier []) tiers
142 where 142 where
143 goList (Announce a) = Announce <$> action a
144 goList (TierList tiers) = TierList <$> goTiers (goTier []) tiers
145
143 goTiers _ [] = throwRPC "traverseTiers: no tiers" 146 goTiers _ [] = throwRPC "traverseTiers: no tiers"
144 goTiers f (x : xs) = catchRPC shortcut failback 147 goTiers f (x : xs) = catchRPC shortcut failback
145 where 148 where