Commit 5a210032 authored by Moritz Angermann's avatar Moritz Angermann Committed by Ben Gamari
Browse files

[iserv] drop cryptonite dependency.

Reviewers: bgamari, austin

Reviewed By: bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3462
parent 1cc82d38
......@@ -85,8 +85,7 @@ Library
bytestring >= 0.10 && < 0.11,
containers >= 0.5 && < 0.6,
deepseq >= 1.4 && < 1.5,
cryptonite >= 0.22,
ghci == 8.1,
ghci == 8.3,
network >= 2.6 && < 2.7,
directory >= 1.3 && < 1.4,
filepath >= 1.4 && < 1.5
......@@ -134,6 +133,6 @@ Executable iserv-proxy
bytestring >= 0.10 && < 0.11,
containers >= 0.5 && < 0.6,
deepseq >= 1.4 && < 1.5,
ghci == 8.1,
ghci == 8.3,
network >= 2.6,
iserv-bin
......@@ -58,6 +58,7 @@ import Control.Monad
import System.Environment
import System.Exit
import Text.Printf
import GHC.Fingerprint (getFileHash)
import Data.Binary
import qualified Data.ByteString as BS
......@@ -182,7 +183,7 @@ fwdLoadCall verbose _ remote msg = do
reply =<< BS.readFile path
loopLoad
Have path remoteHash -> do
localHash <- sha256sum path
localHash <- getFileHash path
reply =<< if localHash == remoteHash
then return Nothing
else Just <$> BS.readFile path
......
......@@ -3,29 +3,19 @@
module Remote.Message
( SlaveMessage(..)
, SlaveMsg(..)
, sha256sum
, putSlaveMessage
, getSlaveMessage )
where
import GHC.Fingerprint (Fingerprint)
import Data.Binary
import Data.ByteString as BS (ByteString, readFile)
import Crypto.Hash
type Sha256Hash = String
sha256 :: ByteString -> Digest SHA256
sha256 = hash
sha256sum :: FilePath -> IO Sha256Hash
sha256sum path = (show . sha256) <$> BS.readFile path
import Data.ByteString (ByteString)
-- | A @SlaveMessage a@ is message from the iserv process on the
-- target, requesting something from the Proxy of with result type @a@.
data SlaveMessage a where
-- sends either a new file, or nothing if the file is acceptable.
Have :: FilePath -> Sha256Hash -> SlaveMessage (Maybe ByteString)
Have :: FilePath -> Fingerprint -> SlaveMessage (Maybe ByteString)
Missing :: FilePath -> SlaveMessage ByteString
Done :: SlaveMessage ()
......
......@@ -19,6 +19,7 @@ import GHCi.Message (Pipe(..), Msg(..), Message(..), readPipe, writePipe)
import Foreign.C.String
import Data.Binary
import GHC.Fingerprint (getFileHash)
import qualified Data.ByteString as BS
......@@ -59,16 +60,16 @@ startSlave' verbose base_path port = do
--
-- If we however already have the requested file we need to make
-- sure that this file is the same one ghc sees. Hence we
-- calculate the sha256sum of the file and send it back to the
-- calculate the Fingerprint of the file and send it back to the
-- host for comparison. The proxy will then send back either @Nothing@
-- indicating that the file on the host has the same sha256sum, or
-- indicating that the file on the host has the same Fingerprint, or
-- Maybe ByteString containing the payload to replace the existing
-- file with.
handleLoad :: Pipe -> FilePath -> FilePath -> IO ()
handleLoad pipe path localPath = do
exists <- doesFileExist localPath
if exists
then sha256sum localPath >>= \hash -> proxyCall (Have path hash) >>= \case
then getFileHash localPath >>= \hash -> proxyCall (Have path hash) >>= \case
Nothing -> return ()
Just bs -> BS.writeFile localPath bs
else do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment