remote: replace protoVersion, use new toys

This commit is contained in:
sorki 2023-11-29 19:11:15 +01:00
parent 69135ed504
commit 5ebe47db03
5 changed files with 26 additions and 15 deletions

View File

@ -2,7 +2,6 @@ module System.Nix.Store.Remote.MonadStore
( MonadStore
, mapStoreDir
, getStoreDir
, getStoreDir'
, getLog
, flushLog
, gotError
@ -26,8 +25,8 @@ import System.Nix.Store.Remote.Types.Logger (Logger, isError)
import System.Nix.Store.Remote.Types.StoreConfig (StoreConfig(..))
-- | Ask for a @StoreDir@
getStoreDir' :: (HasStoreDir r, MonadReader r m) => m StoreDir
getStoreDir' = asks hasStoreDir
getStoreDir :: (HasStoreDir r, MonadReader r m) => m StoreDir
getStoreDir = asks hasStoreDir
type MonadStore a
= ExceptT
@ -57,6 +56,3 @@ setData x = modify (\(_, b) -> (Just x, b))
clearData :: MonadStore ()
clearData = modify (\(_, b) -> (Nothing, b))
getStoreDir :: MonadStore StoreDir
getStoreDir = asks storeConfig_dir

View File

@ -36,13 +36,9 @@ import System.Nix.Store.Remote.Serialize.Prim
import System.Nix.Store.Remote.Logger
import System.Nix.Store.Remote.MonadStore
import System.Nix.Store.Remote.Socket
import System.Nix.Store.Remote.Serializer (protoVersion)
import System.Nix.Store.Remote.Types
protoVersion :: Int
protoVersion = 0x115
-- major protoVersion & 0xFF00
-- minor .. & 0x00FF
ourProtoVersion :: ProtoVersion
ourProtoVersion = ProtoVersion
{ protoVersion_major = 1
@ -130,7 +126,7 @@ runStoreOpts' sockFamily sockAddr storeRootDir code =
greet = do
sockPut $ putInt workerMagic1
soc <- asks storeConfig_socket
soc <- asks hasStoreSocket
vermagic <- liftIO $ recv soc 16
let
eres =
@ -144,7 +140,8 @@ runStoreOpts' sockFamily sockAddr storeRootDir code =
Right (magic2, _daemonProtoVersion) -> do
Control.Monad.unless (magic2 == workerMagic2) $ error "Worker magic 2 mismatch"
sockPut $ putInt protoVersion -- clientVersion
pv <- asks hasProtoVersion
sockPutS @() protoVersion pv -- clientVersion
sockPut $ putInt (0 :: Int) -- affinity
sockPut $ putInt (0 :: Int) -- obsolete reserveSpace

View File

@ -63,6 +63,8 @@ instance Serialize BuildResult where
-- * ProtoVersion
-- protoVersion_major & 0xFF00
-- protoVersion_minor & 0x00FF
instance Serialize ProtoVersion where
get = do
v <- getInt @Word32

View File

@ -319,6 +319,8 @@ vector =
-- * ProtoVersion
-- protoVersion_major & 0xFF00
-- protoVersion_minor & 0x00FF
protoVersion :: NixSerializer r e ProtoVersion
protoVersion = Serializer
{ getS = do

View File

@ -10,6 +10,7 @@ import Data.Serialize.Put
import Network.Socket.ByteString (recv, sendAll)
import System.Nix.StorePath (StorePath)
import System.Nix.Store.Remote.MonadStore
import System.Nix.Store.Remote.Serializer (NixSerializer, runP)
import System.Nix.Store.Remote.Serialize.Prim
import System.Nix.Store.Remote.Types
@ -35,14 +36,27 @@ getSocketIncremental = genericIncremental sockGet8
sockGet8 :: MonadStore ByteString
sockGet8 = do
soc <- asks storeConfig_socket
soc <- asks hasStoreSocket
liftIO $ recv soc 8
sockPut :: Put -> MonadStore ()
sockPut p = do
soc <- asks storeConfig_socket
soc <- asks hasStoreSocket
liftIO $ sendAll soc $ runPut p
sockPutS
:: Show e
=> NixSerializer ProtoVersion e a
-> a
-> MonadStore ()
sockPutS s a = do
soc <- asks hasStoreSocket
pv <- asks hasProtoVersion
case runP s pv a of
Right x -> liftIO $ sendAll soc x
-- TODO: errors
Left e -> throwError $ show e
sockGet :: Get a -> MonadStore a
sockGet = getSocketIncremental