From e2d8d422a6f03ad94221f6540846e61adf731b0c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 28 Aug 2016 21:09:28 -0400 Subject: refactor --- HTTP/Server.hs | 6 ++++++ Tunables.hs | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/HTTP/Server.hs b/HTTP/Server.hs index 816cf47..f599c31 100644 --- a/HTTP/Server.hs +++ b/HTTP/Server.hs @@ -19,6 +19,7 @@ import Network.Wai.Handler.Warp import Control.Monad.IO.Class import Control.Concurrent import Control.Concurrent.STM +import qualified Data.ByteString as B data ServerState = ServerState { obscurerRequest :: TMVar () @@ -69,6 +70,11 @@ putObject st i _pow o = do return $ Result r else return $ Result $ StoreFailure "invalid object size" +validObjectsize :: StorableObject -> Bool +validObjectsize o = any (sz ==) knownObjectSizes + where + sz = B.length (fromStorableObject o) + countObjects :: ServerState -> Maybe ProofOfWork -> Handler (ProofOfWorkRequirement CountResult) countObjects _st _pow = liftIO $ Result <$> countShares serverStorage diff --git a/Tunables.hs b/Tunables.hs index 3fa700a..07b4c61 100644 --- a/Tunables.hs +++ b/Tunables.hs @@ -7,10 +7,8 @@ module Tunables where -import Types import Cost import qualified Crypto.Argon2 as Argon2 -import qualified Data.ByteString as B -- | To determine the tunables used for a key name the expensive hash of the -- name is calculated, using a particular configuration, and if the @@ -134,9 +132,7 @@ testModeTunables = Tunables where weakargon2 c = UseArgon2 c Argon2.defaultHashOptions -validObjectsize :: StorableObject -> Bool -validObjectsize o = any (sz ==) knownsizes +knownObjectSizes :: [Int] +knownObjectSizes = map (calc . snd) knownTunings where - sz = B.length (fromStorableObject o) - knownsizes = map (\t -> objectSize t * shareOverhead t) - (map snd knownTunings) + calc t = objectSize t * shareOverhead t -- cgit v1.2.3