summaryrefslogtreecommitdiffhomepage
path: root/Storage.hs
blob: d1a3ad812014a0cc50dceca54428a53521ac6298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{- Copyright 2016 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module Storage where

import Types
import Shard

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
	} -- Note that there is no interface to enumerate shards.

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)

storeShards :: Storage -> ShardIdents -> [(IO (), Shard)] -> IO StoreResult
storeShards storage sis shards = do
	r <- go (zip (getIdents sis) shards)
	_ <- obscureShards storage
	return r
  where
	go [] = return StoreSuccess
	go ((i,(showprogress, s)):rest) = do
		r <- storeShard storage i s
		_ <- showprogress
		case r of
			StoreSuccess -> go rest
			_ -> return r