summaryrefslogtreecommitdiffhomepage
path: root/HTTP
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-15 22:49:38 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-15 22:49:38 -0400
commit845fb2d60585be5567ac10aa0a53ab45c628648c (patch)
treee58456868911cd16451f4695ff7d076a701a78bb /HTTP
parent4fc681f78b2e659d3db3da99fe7c640416fb3b43 (diff)
downloadkeysafe-845fb2d60585be5567ac10aa0a53ab45c628648c.tar.gz
Added --backup-server and --restore-server
To aid in backing up keysafe servers with minimal information leakage. This commit was sponsored by Andrea Rota.
Diffstat (limited to 'HTTP')
-rw-r--r--HTTP/Server.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/HTTP/Server.hs b/HTTP/Server.hs
index e2165eb..c667601 100644
--- a/HTTP/Server.hs
+++ b/HTTP/Server.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
-module HTTP.Server (runServer) where
+module HTTP.Server (runServer, serverStorage) where
import HTTP
import HTTP.ProofOfWork
@@ -29,7 +29,7 @@ import qualified Data.ByteString as B
data ServerState = ServerState
{ obscurerRequest :: TMVar ()
- , storageDirectory :: Maybe LocalStorageDirectory
+ , storage :: Storage
, rateLimiter :: RateLimiter
, logger :: Logger
}
@@ -39,7 +39,7 @@ newServerState d cfg = do
l <- newLogger
ServerState
<$> newEmptyTMVarIO
- <*> pure d
+ <*> pure (serverStorage d)
<*> newRateLimiter cfg d l
<*> pure l
@@ -52,8 +52,8 @@ runServer d cfg = do
settings = setHost host $ setPort (serverPort cfg) $ defaultSettings
host = fromString (serverAddress cfg)
-serverStorage :: ServerState -> Storage
-serverStorage st = localStorage (storageDir $ storageDirectory st) "server"
+serverStorage :: Maybe LocalStorageDirectory -> Storage
+serverStorage d = localStorage (storageDir d) "server"
app :: ServerState -> Application
app st = serve userAPI (server st)
@@ -72,7 +72,7 @@ motd = return $ Motd "Hello World!"
getObject :: ServerState -> StorableObjectIdent -> Maybe ProofOfWork -> Handler (POWGuarded StorableObject)
getObject st i pow = rateLimit (rateLimiter st) (logger st) pow i $ do
- r <- liftIO $ retrieveShare (serverStorage st) dummyShareNum i
+ r <- liftIO $ retrieveShare (storage st) dummyShareNum i
liftIO $ requestObscure st
case r of
RetrieveSuccess (Share _n o) -> return o
@@ -82,7 +82,7 @@ putObject :: ServerState -> StorableObjectIdent -> Maybe ProofOfWork -> Storable
putObject st i pow o = rateLimit (rateLimiter st) (logger st) pow i $ do
if validObjectsize o
then do
- r <- liftIO $ storeShare (serverStorage st) i (Share dummyShareNum o)
+ r <- liftIO $ storeShare (storage st) i (Share dummyShareNum o)
liftIO $ requestObscure st
return r
else return $ StoreFailure "invalid object size"
@@ -94,7 +94,7 @@ validObjectsize o = any (sz ==) knownObjectSizes
countObjects :: ServerState -> Maybe ProofOfWork -> Handler (POWGuarded CountResult)
countObjects st pow = rateLimit (rateLimiter st) (logger st) pow NoPOWIdent $
- liftIO $ countShares $ serverStorage st
+ liftIO $ countShares $ storage st
-- | 1 is a dummy value; the server does not know the actual share numbers.
dummyShareNum :: ShareNum
@@ -105,7 +105,7 @@ dummyShareNum = 1
-- the thread runs a maximum of once per half-hour.
obscurerThread :: ServerState -> IO ()
obscurerThread st = do
- _ <- obscureShares (serverStorage st)
+ _ <- obscureShares (storage st)
logStdout (logger st) "obscured shares"
delay (1000000*60*30)
_ <- atomically $ takeTMVar (obscurerRequest st)