Skip to content

Commit 62e472f

Browse files
committed
remote: add Types.Handshake, use as a greeting result
1 parent 0c186a0 commit 62e472f

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ library
8686
, System.Nix.Store.Remote.Types.Activity
8787
, System.Nix.Store.Remote.Types.CheckMode
8888
, System.Nix.Store.Remote.Types.GC
89+
, System.Nix.Store.Remote.Types.Handshake
8990
, System.Nix.Store.Remote.Types.Logger
9091
, System.Nix.Store.Remote.Types.ProtoVersion
9192
, System.Nix.Store.Remote.Types.StoreConfig

hnix-store-remote/src/System/Nix/Store/Remote/Client.hs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import System.Nix.Store.Remote.Logger (processOutput)
2424
import System.Nix.Store.Remote.MonadStore
2525
import System.Nix.Store.Remote.Socket (sockPutS, sockGetS)
2626
import System.Nix.Store.Remote.Serializer (bool, enum, int, mapErrorS, protoVersion, text, trustedFlag, workerMagic)
27+
import System.Nix.Store.Remote.Types.Handshake (Handshake(..))
2728
import System.Nix.Store.Remote.Types.Logger (Logger)
2829
import System.Nix.Store.Remote.Types.ProtoVersion (ProtoVersion(..), ourProtoVersion)
2930
import System.Nix.Store.Remote.Types.StoreConfig (PreStoreConfig, preStoreConfigToStoreConfig)
@@ -81,13 +82,13 @@ runStoreSocket
8182
-> Run a
8283
runStoreSocket preStoreConfig code =
8384
runRemoteStoreT preStoreConfig $ do
84-
pv <- greet
85+
Handshake{..} <- greet
8586
mapStoreConfig
86-
(preStoreConfigToStoreConfig pv)
87+
(preStoreConfigToStoreConfig handshakeProtoVersion)
8788
code
8889

8990
where
90-
greet :: MonadRemoteStoreHandshake ProtoVersion
91+
greet :: MonadRemoteStoreHandshake Handshake
9192
greet = do
9293

9394
sockPutS
@@ -124,25 +125,32 @@ runStoreSocket preStoreConfig code =
124125
(mapErrorS RemoteStoreError_SerializerPut bool)
125126
False -- reserveSpace, obsolete
126127

127-
when (minimumCommonVersion >= ProtoVersion 1 33) $ do
128-
-- If we were buffering I/O, we would flush the output here.
129-
_daemonNixVersion <-
130-
sockGetS
131-
$ mapErrorS
132-
RemoteStoreError_SerializerGet
133-
text
134-
return ()
135-
136-
_remoteTrustsUs <- if minimumCommonVersion >= ProtoVersion 1 35
128+
daemonNixVersion <- if minimumCommonVersion >= ProtoVersion 1 33
129+
then do
130+
-- If we were buffering I/O, we would flush the output here.
131+
txtVer <-
132+
sockGetS
133+
$ mapErrorS
134+
RemoteStoreError_SerializerGet
135+
text
136+
pure $ Just txtVer
137+
else pure Nothing
138+
139+
remoteTrustsUs <- if minimumCommonVersion >= ProtoVersion 1 35
137140
then do
138141
sockGetS
139142
$ mapErrorS RemoteStoreError_SerializerHandshake trustedFlag
140-
else do
141-
return Nothing
142-
143-
-- TODO do something with it
144-
_ <- mapStoreConfig
145-
(preStoreConfigToStoreConfig minimumCommonVersion)
146-
processOutput
147-
148-
pure minimumCommonVersion
143+
else pure Nothing
144+
145+
logs <-
146+
mapStoreConfig
147+
(preStoreConfigToStoreConfig minimumCommonVersion)
148+
processOutput
149+
150+
pure Handshake
151+
{ handshakeNixVersion = daemonNixVersion
152+
, handshakeTrust = remoteTrustsUs
153+
, handshakeProtoVersion = minimumCommonVersion
154+
, handshakeRemoteProtoVersion = daemonVersion
155+
, handshakeLogs = logs
156+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module System.Nix.Store.Remote.Types.Handshake
2+
( Handshake(..)
3+
) where
4+
5+
import Data.Text (Text)
6+
import GHC.Generics (Generic)
7+
import System.Nix.Store.Remote.Types.Logger (Logger)
8+
import System.Nix.Store.Remote.Types.ProtoVersion (ProtoVersion)
9+
import System.Nix.Store.Remote.Types.TrustedFlag (TrustedFlag)
10+
11+
-- | Data for initial protocol handshake
12+
data Handshake = Handshake
13+
{ handshakeNixVersion :: Maybe Text -- ^ Textual version, since 1.33
14+
, handshakeTrust :: Maybe TrustedFlag -- ^ Whether remote side trusts us
15+
, handshakeProtoVersion :: ProtoVersion -- ^ Minimum protocol supported by both sides
16+
, handshakeRemoteProtoVersion :: ProtoVersion -- ^ Protocol supported by remote side
17+
, handshakeLogs :: [Logger] -- ^ Logs produced right after greeting exchange
18+
}
19+
deriving (Eq, Generic, Ord, Show)

0 commit comments

Comments
 (0)