Skip to content
Snippets Groups Projects
Commit 65feba9b authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Split upload into separate encoding and uploading operations

Still provide a helper that does it all, though - `store`
parent e6350847
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ import Upload ...@@ -45,7 +45,7 @@ import Upload
, filesystemUploadableRandomConvergence , filesystemUploadableRandomConvergence
, filesystemUploadableWithConvergence , filesystemUploadableWithConvergence
, filesystemStorageServer , filesystemStorageServer
, upload , store
, prettyFormatSharemap , prettyFormatSharemap
) )
...@@ -99,10 +99,12 @@ main = do ...@@ -99,10 +99,12 @@ main = do
Right bytesSecret -> Right bytesSecret ->
filesystemUploadableWithConvergence bytesSecret path params filesystemUploadableWithConvergence bytesSecret path params
servers >>= upload uploadable >>= report_upload servers <- getServers
result <- store servers uploadable
report_upload result
where where
servers = mapM filesystemStorageServer getServers = mapM filesystemStorageServer
[ "storage001" [ "storage001"
, "storage002" , "storage002"
, "storage003" , "storage003"
......
...@@ -9,6 +9,7 @@ module Upload ...@@ -9,6 +9,7 @@ module Upload
, filesystemStorageServer , filesystemStorageServer
, getConvergentKey , getConvergentKey
, upload , upload
, store
, prettyFormatSharemap , prettyFormatSharemap
, adjustSegmentSize , adjustSegmentSize
...@@ -204,23 +205,48 @@ uploadImmutableShares storageIndex uploads = do ...@@ -204,23 +205,48 @@ uploadImmutableShares storageIndex uploads = do
uploadOneChunk offset storageIndex (shareNum, server, shareData) = uploadOneChunk offset storageIndex (shareNum, server, shareData) =
storageServerWrite server storageIndex shareNum offset shareData storageServerWrite server storageIndex shareNum offset shareData
-- Given some cleartext, some encoding parameters, and some servers: encrypt,
-- encode, and upload some shares that can later be used to reconstruct the -- | Encrypt and encode some application data to some ZFEC shares and upload
-- cleartext. -- them to some servers.
store ::
-- | The servers to consider using.
[StorageServer] ->
-- | The application data to operate on.
Uploadable ->
-- | The result of the attempt.
IO UploadResult
store servers uploadable@(Uploadable key _ params _) =
encryptAndEncode uploadable >>= upload servers key params
-- | Given some cleartext and some encoding parameters: encrypt and encode some
-- shares that can later be used to reconstruct the cleartext.
encryptAndEncode ::
-- | The application data to encrypt and encode.
Uploadable ->
-- | An action to get an action that can be repeatedly evaluated to get
-- share data. As long as there is more share data, it evaluates to Left.
-- When shares are done, it evaluates to Right.
IO (IO (Either [B.ByteString] (AESKey128 -> Capability)))
encryptAndEncode (Uploadable key size params read) =
chkEncrypt key read >>= makeChkEncoder params size
-- | Given some cleartext, some encoding parameters, and some servers:
-- encrypt, encode, and upload some shares that can later be used to
-- reconstruct the cleartext.
-- --
-- This replaces allmydata.immutable.upload.Uploader.upload. -- This replaces allmydata.immutable.upload.Uploader.upload.
upload :: Uploadable -> [StorageServer] -> IO UploadResult upload ::
upload Uploadable -- | The servers to consider uploading shares to.
{ uploadableKey = key [StorageServer] ->
, uploadableSize = size -- | The encryption key (to derive the storage index).
, uploadableParameters = params AESKey128 ->
, uploadableReadCleartext = readCleartext -- | The encoding parameters (XXX only for happy, right?)
} servers = do Parameters ->
-- | An action to repeatedly evaluate to get share data or the cap.
-- Prepare the share data (IO (Either [B.ByteString] (AESKey128 -> Capability))) ->
readCiphertext <- chkEncrypt key readCleartext -- | Describe the outcome of the upload.
streams <- makeChkEncoder params size readCiphertext IO UploadResult
upload servers key params streams = do
-- Decide where to put it -- Decide where to put it
existingShares <- locateAllShareholders storageIndex servers existingShares <- locateAllShareholders storageIndex servers
let targets = targetServers params existingShares let targets = targetServers params existingShares
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment