summaryrefslogtreecommitdiffhomepage
path: root/Storage.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-19 13:00:34 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-19 13:00:34 -0400
commit6261f7e58b764ae48293bee3b1863b518e9f0442 (patch)
treed9260d1beeced137e36c1ae1945c499d85e91608 /Storage.hs
parentd3323ab8e9e39bcb0a6493d33efa265073920a7d (diff)
downloadkeysafe-6261f7e58b764ae48293bee3b1863b518e9f0442.tar.gz
rename shard -> share
This makes it clearer that it's not a chunk of data, but a Shamir share.
Diffstat (limited to 'Storage.hs')
-rw-r--r--Storage.hs60
1 files changed, 30 insertions, 30 deletions
diff --git a/Storage.hs b/Storage.hs
index ff96a3d..56d68a8 100644
--- a/Storage.hs
+++ b/Storage.hs
@@ -7,7 +7,7 @@ module Storage (module Storage, module Types.Storage) where
import Types
import Types.Storage
-import Shard
+import Share
import Storage.Local
import Storage.Network
import Data.Monoid
@@ -28,60 +28,60 @@ localStorageLocations = StorageLocations $
type UpdateProgress = IO ()
--- | Stores the shards amoung the storage locations. Each location
--- gets at most one shard.
-storeShards :: StorageLocations -> ShardIdents -> [(UpdateProgress, Shard)] -> IO StoreResult
-storeShards (StorageLocations locs) sis shards = do
- (r, usedlocs) <- go locs [] Nothing (zip (getIdents sis) shards)
- _ <- mapM_ obscureShards usedlocs
+-- | Stores the shares amoung the storage locations. Each location
+-- gets at most one share.
+storeShares :: StorageLocations -> ShareIdents -> [(UpdateProgress, Share)] -> IO StoreResult
+storeShares (StorageLocations locs) sis shares = do
+ (r, usedlocs) <- go locs [] Nothing (zip (getIdents sis) shares)
+ _ <- mapM_ obscureShares usedlocs
return r
where
go _ usedlocs _ [] = return (StoreSuccess, usedlocs)
go [] usedlocs lasterr _ =
return (fromMaybe (StoreFailure "no storage locations") lasterr, usedlocs)
go (loc:otherlocs) usedlocs _ tostore@((i,(showprogress, s)):rest) = do
- r <- storeShard loc i s
+ r <- storeShare loc i s
case r of
StoreSuccess -> do
_ <- showprogress
go otherlocs (loc:usedlocs) Nothing rest
StoreFailure _ -> go otherlocs usedlocs (Just r) tostore
- -- Give up if any location complains a shard
+ -- Give up if any location complains a share
-- already exists, because we have a name conflict.
StoreAlreadyExists -> return (StoreAlreadyExists, usedlocs)
--- | Retrieves shards from among the storage locations, and returns all
--- the shards it can find, which may not be all that were requested.
+-- | Retrieves shares from among the storage locations, and returns all
+-- the shares it can find, which may not be all that were requested.
--
--- Assumes that each location only contains one shard. So, once a
--- shard has been found on a location, can avoid asking that location
--- for any other shards.
-retrieveShards :: StorageLocations -> [(UpdateProgress, (ShardNum, StorableObjectIdent))] -> IO [Shard]
-retrieveShards (StorageLocations locs) l = do
- (shards, usedlocs, _unusedlocs) <- go locs [] l []
- _ <- mapM_ obscureShards usedlocs
- return shards
+-- Assumes that each location only contains one share. So, once a
+-- share has been found on a location, can avoid asking that location
+-- for any other shares.
+retrieveShares :: StorageLocations -> [(UpdateProgress, (ShareNum, StorableObjectIdent))] -> IO [Share]
+retrieveShares (StorageLocations locs) l = do
+ (shares, usedlocs, _unusedlocs) <- go locs [] l []
+ _ <- mapM_ obscureShares usedlocs
+ return shares
where
- go unusedlocs usedlocs [] shards = return (shards, usedlocs, unusedlocs)
- go [] usedlocs _ shards = return (shards, usedlocs, [])
- go (loc:otherlocs) usedlocs (toretrieve@(updateprogress, (n, i)):rest) shards = do
- r <- retrieveShard loc n i
+ go unusedlocs usedlocs [] shares = return (shares, usedlocs, unusedlocs)
+ go [] usedlocs _ shares = return (shares, usedlocs, [])
+ go (loc:otherlocs) usedlocs (toretrieve@(updateprogress, (n, i)):rest) shares = do
+ r <- retrieveShare loc n i
case r of
RetrieveSuccess s -> do
_ <- updateprogress
- go otherlocs (loc:usedlocs) rest (s:shards)
+ go otherlocs (loc:usedlocs) rest (s:shares)
RetrieveFailure _ -> do
- (shards', usedlocs', unusedlocs) <-
- go otherlocs usedlocs [toretrieve] shards
+ (shares', usedlocs', unusedlocs) <-
+ go otherlocs usedlocs [toretrieve] shares
-- May need to ask the location that didn't
- -- have the shard for a later shard, but
+ -- have the share for a later share, but
-- ask it last. This way, the first
-- location on the list can't deny having
- -- all shards and so learn the idents of
+ -- all shares and so learn the idents of
-- all of them.
- go (unusedlocs++[loc]) usedlocs' rest shards'
+ go (unusedlocs++[loc]) usedlocs' rest shares'
uploadQueued :: IO ()
uploadQueued = do
servers <- networkServers
- forM_ servers $ \s -> moveShards (uploadQueue s) (networkStorage s)
+ forM_ servers $ \s -> moveShares (uploadQueue s) (networkStorage s)