diff --git a/src/Tahoe/Download.hs b/src/Tahoe/Download.hs index c1364336a673e45c1ddcee8001b2bc5950884d9f..35d87188f5fb56222b3472f4d82df21e24d8d83f 100644 --- a/src/Tahoe/Download.hs +++ b/src/Tahoe/Download.hs @@ -1,4 +1,7 @@ -module Tahoe.Download (LookupServer, DownloadError (..), discoverOnce, download) where +{- | A high-level interface to downloading share data as bytes from storage + servers. +-} +module Tahoe.Download (LookupServer, DownloadError (..), discoverShares, download) where import Data.Binary (decodeOrFail) import qualified Data.ByteString.Lazy as LB @@ -76,7 +79,7 @@ download servers cap@Reader{readKey, verifier = Verifier{..}} lookupServer = [] -> pure . Left $ NoConfiguredServers serverList -> do -- Ask each server for all shares it has. - discovered <- rights <$> mapM (discoverOnce lookupServer storageIndex) serverList :: IO [(StorageServer, Set.Set ShareNum)] + discovered <- rights <$> mapM (discoverShares lookupServer storageIndex) serverList :: IO [(StorageServer, Set.Set ShareNum)] if null discovered then pure $ Left NoReachableServers else @@ -107,10 +110,11 @@ download servers cap@Reader{readKey, verifier = Verifier{..}} lookupServer = countDistinctShares :: Ord b => [(a, Set.Set b)] -> Int countDistinctShares = Set.size . foldl' Set.union mempty . map snd --- Ask one server which shares it has related to the storage index in --- question. -discoverOnce :: LookupServer -> StorageIndex -> (StorageServerID, StorageServerAnnouncement) -> IO (Either DiscoverError (StorageServer, Set.Set ShareNum)) -discoverOnce lookupServer storageIndex (_sid, sann) = do +{- | Ask one server which shares it has related to the storage index in + question. +-} +discoverShares :: LookupServer -> StorageIndex -> (StorageServerID, StorageServerAnnouncement) -> IO (Either DiscoverError (StorageServer, Set.Set ShareNum)) +discoverShares lookupServer storageIndex (_sid, sann) = do case storageServerAnnouncementFURL sann of Nothing -> pure $ Left StorageServerLocationUnknown Just url -> do diff --git a/test/Spec.hs b/test/Spec.hs index 0c4afeaf07810e2ac11f73864103d5079996e16d..f2547908dc60bdaab1ccc29623c844c2f6a05fe1 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -193,9 +193,6 @@ tests = lookupServer = someServers serverMap serverAnnouncements = Map.fromSet makeAnn serverIDs' - -- discovered <- liftIO $ mapM (discoverOnce lookupServer . storageIndex . verifier $ cap) (Map.toList serverAnnouncements) - -- liftIO $ print (rights discovered) - -- Recover the plaintext from the servers. result <- liftIO $ download serverAnnouncements cap lookupServer diff (Right plaintext) (==) result