From e333a779338ff8bccdc4225fc953d6f4f0226db0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Sep 2016 22:59:03 -0400 Subject: add proof of work to countobjects In this case, an empty string is hashed to generate the PoW. --- Storage/Network.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Storage') diff --git a/Storage/Network.hs b/Storage/Network.hs index 6053ff3..9739f2f 100644 --- a/Storage/Network.hs +++ b/Storage/Network.hs @@ -74,20 +74,21 @@ obscure :: Server -> IO ObscureResult obscure _ = return ObscureSuccess count :: Server -> IO CountResult -count srv = either CountFailure id <$> serverRequest' srv countObjects +count srv = serverRequest srv CountFailure id NoPOWIdent countObjects -- | Not needed for servers. move :: Server -> Storage -> IO () move _ _ = error "move is not implemented for servers" serverRequest - :: Server + :: POWIdent p + => Server -> (String -> a) -> (r -> a) - -> StorableObjectIdent + -> p -> (Maybe ProofOfWork -> Manager -> BaseUrl -> ExceptT ServantError IO (POWGuarded r)) -> IO a -serverRequest srv onerr onsuccess i a = go Nothing maxProofOfWork +serverRequest srv onerr onsuccess p a = go Nothing maxProofOfWork where go pow (Seconds timeleft) | timeleft <= 0 = return $ onerr "server asked for too much proof of work; gave up" @@ -97,7 +98,7 @@ serverRequest srv onerr onsuccess i a = go Nothing maxProofOfWork Left err -> return $ onerr err Right (Result r) -> return $ onsuccess r Right (NeedProofOfWork req) -> go - (Just $ genProofOfWork req i) + (Just $ genProofOfWork req p) (Seconds timeleft - generationTime req) serverRequest' -- cgit v1.2.3