@@ -27,7 +27,7 @@ import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion(..), ProtoVer
2727import System.Nix.Store.Remote.Types.Logger (BasicError (.. ), ErrorInfo , Logger (.. ))
2828
2929import System.Nix.Store.Remote.MonadStore (WorkerError (.. ), WorkerException (.. ), RemoteStoreError (.. ), RemoteStoreT , runRemoteStoreT , mapStoreConfig )
30- import System.Nix.Store.Remote.Types.Handshake (Handshake (.. ))
30+ import System.Nix.Store.Remote.Types.Handshake (ServerHandshakeInput ( .. ), ServerHandshakeOutput (.. ))
3131import System.Nix.Store.Remote.Types.ProtoVersion (ourProtoVersion )
3232import System.Nix.Store.Remote.Types.WorkerMagic (WorkerMagic (.. ))
3333
@@ -79,28 +79,26 @@ processConnection
7979 -> PreStoreConfig
8080 -> m ()
8181processConnection workerHelper preStoreConfig = do
82- let handshake = Handshake
83- { handshakeNixVersion = Just " nixVersion (hnix-store-remote)"
84- , handshakeTrust = Nothing
85- -- TODO: doesn't make sense for server
86- , handshakeProtoVersion = ourProtoVersion
87- -- TODO: doesn't make sense for server
88- , handshakeRemoteProtoVersion = ourProtoVersion
89- }
90-
9182 ~ () <- void $ runRemoteStoreT preStoreConfig $ do
9283
93- minimumCommonVersion <- greet handshake
84+ ServerHandshakeOutput {.. }
85+ <- greet
86+ ServerHandshakeInput
87+ { serverHandshakeInputNixVersion = " nixVersion (hnix-store-remote)"
88+ , serverHandshakeInputOurVersion= ourProtoVersion
89+ , serverHandshakeInputTrust = Nothing
90+ }
9491
9592 mapStoreConfig
96- (preStoreConfigToStoreConfig minimumCommonVersion)
93+ (preStoreConfigToStoreConfig
94+ serverHandshakeOutputLeastCommonVersion)
9795 $ do
9896
9997 tunnelLogger <- liftIO $ newTunnelLogger
10098 -- Send startup error messages to the client.
10199 startWork tunnelLogger
102100
103- -- TODO: do we need auth at all? probably?
101+ -- TODO: do we need auth at all? probably?
104102 -- If we can't accept clientVersion, then throw an error *here* (not above).
105103 -- authHook(*store);
106104 stopWork tunnelLogger
@@ -124,9 +122,9 @@ processConnection workerHelper preStoreConfig = do
124122 -- Exchange the greeting.
125123 greet
126124 :: MonadIO m
127- => Handshake
128- -> RemoteStoreT PreStoreConfig m ProtoVersion
129- greet Handshake {.. } = do
125+ => ServerHandshakeInput
126+ -> RemoteStoreT PreStoreConfig m ServerHandshakeOutput
127+ greet ServerHandshakeInput {.. } = do
130128 magic <-
131129 sockGetS
132130 $ mapErrorS
@@ -135,7 +133,9 @@ processConnection workerHelper preStoreConfig = do
135133
136134 liftIO $ print (" magic" :: Text , magic )
137135 when (magic /= WorkerMagic_One )
138- $ throwError $ RemoteStoreError_WorkerException WorkerException_ProtocolMismatch
136+ $ throwError
137+ $ RemoteStoreError_WorkerException
138+ WorkerException_ProtocolMismatch
139139
140140 sockPutS
141141 (mapErrorS
@@ -144,13 +144,13 @@ processConnection workerHelper preStoreConfig = do
144144 )
145145 WorkerMagic_Two
146146
147- sockPutS protoVersion ourProtoVersion
147+ sockPutS protoVersion serverHandshakeInputOurVersion
148148
149149 clientVersion <- sockGetS protoVersion
150150
151- let minimumCommonVersion = min clientVersion ourProtoVersion
151+ let leastCommonVersion = min clientVersion ourProtoVersion
152152
153- liftIO $ print (" Versions client, min" :: Text , clientVersion , minimumCommonVersion )
153+ liftIO $ print (" Versions client, min" :: Text , clientVersion , leastCommonVersion )
154154
155155 when (clientVersion < ProtoVersion 1 10 )
156156 $ throwError
@@ -174,18 +174,20 @@ processConnection workerHelper preStoreConfig = do
174174 RemoteStoreError_SerializerPut
175175 text
176176 )
177- -- TODO
178- (maybe undefined id handshakeNixVersion)
177+ serverHandshakeInputNixVersion
179178
180179 when (clientVersion >= ProtoVersion 1 35 ) $ do
181180 sockPutS
182181 (mapErrorS
183182 RemoteStoreError_SerializerHandshake
184183 trustedFlag
185184 )
186- handshakeTrust
185+ serverHandshakeInputTrust
187186
188- pure minimumCommonVersion
187+ pure ServerHandshakeOutput
188+ { serverHandshakeOutputLeastCommonVersion = leastCommonVersion
189+ , serverHandshakeOutputClientVersion = clientVersion
190+ }
189191
190192simpleOp
191193 :: ( MonadIO m
0 commit comments