{- Copyright 2016 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Types.Storage where import Types -- | All known locations where shards can be stored, ordered with -- preferred locations first. newtype StorageLocations = StorageLocations [Storage] deriving (Monoid) -- | Storage interface. This can be used both for local storage, -- an upload queue, or a remote server. -- -- Note that there is no interface to enumerate shards. -- This is intentional; servers should not allow that. data Storage = Storage { storeShard :: StorableObjectIdent -> Shard -> IO StoreResult , retrieveShard :: ShardNum -> StorableObjectIdent -> IO RetrieveResult , obscureShards :: IO ObscureResult -- ^ Run after making some calls to storeShard/retrieveShard, -- to avoid correlation attacks. , countShards :: IO CountResult , moveShards :: Storage -> IO () -- ^ Tries to move all shards from this storage to another one. } data StoreResult = StoreSuccess | StoreAlreadyExists | StoreFailure String deriving (Show) data RetrieveResult = RetrieveSuccess Shard | RetrieveFailure String data ObscureResult = ObscureSuccess | ObscureFailure String deriving (Show) data CountResult = CountResult Integer | CountFailure String deriving (Show)