From 241ba9a8c0d5ba7b7ecea205948d1d4b8d1a55fe Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Mon, 1 May 2023 14:58:09 -0400 Subject: [PATCH] minor cosmetic improvements --- src/Tahoe/Download.hs | 16 ++++++++++------ test/Spec.hs | 3 --- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Tahoe/Download.hs b/src/Tahoe/Download.hs index c136433..35d8718 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 0c4afea..f254790 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 -- GitLab