improve types
This commit is contained in:
parent
e2fd2ee2bd
commit
b72ccc6f0c
2 changed files with 12 additions and 17 deletions
|
@ -61,9 +61,10 @@ performLocal theiruuid servermode = do
|
|||
|
||||
performProxy :: UUID -> P2P.ServerMode -> Remote -> CommandPerform
|
||||
performProxy clientuuid servermode remote = do
|
||||
clientside <- ClientSide
|
||||
<$> liftIO (mkRunState $ Serving clientuuid Nothing)
|
||||
<*> pure (stdioP2PConnection Nothing)
|
||||
clientrunst <- liftIO (mkRunState $ Serving clientuuid Nothing)
|
||||
let clientside = ClientSide $
|
||||
liftIO . runNetProto clientrunst
|
||||
(stdioP2PConnection Nothing)
|
||||
getClientProtocolVersion remote clientside
|
||||
(withclientversion clientside)
|
||||
protoerrhandler
|
||||
|
@ -83,7 +84,7 @@ performProxy clientuuid servermode remote = do
|
|||
connectremote clientmaxversion cont =
|
||||
openP2PShellConnection' remote clientmaxversion >>= \case
|
||||
Just conn@(P2P.IO.OpenConnection (remoterunst, remoteconn, _)) ->
|
||||
cont (RemoteSide remoterunst remoteconn (Remote.uuid remote))
|
||||
cont (RemoteSide (liftIO . runNetProto remoterunst remoteconn) (Remote.uuid remote))
|
||||
`finally` liftIO (closeP2PShellConnection conn)
|
||||
_ -> giveup "Unable to connect to remote."
|
||||
|
||||
|
|
20
P2P/Proxy.hs
20
P2P/Proxy.hs
|
@ -15,8 +15,10 @@ import P2P.IO
|
|||
import qualified Remote
|
||||
import Utility.Metered (nullMeterUpdate)
|
||||
|
||||
data ClientSide = ClientSide RunState P2PConnection
|
||||
data RemoteSide = RemoteSide RunState P2PConnection UUID
|
||||
type ProtoRunner = forall a. Proto a -> Annex (Either ProtoFailure a)
|
||||
|
||||
data ClientSide = ClientSide ProtoRunner
|
||||
data RemoteSide = RemoteSide ProtoRunner UUID
|
||||
|
||||
{- To keep this module limited to P2P protocol actions,
|
||||
- all other actions that a proxy needs to do are provided
|
||||
|
@ -49,10 +51,8 @@ getClientProtocolVersion
|
|||
-> ClientSide
|
||||
-> (Maybe (ProtocolVersion, Maybe Message) -> Annex r)
|
||||
-> ProtoErrorHandled Annex r
|
||||
getClientProtocolVersion remote (ClientSide clientrunst clientconn) cont protoerrhandler =
|
||||
protoerrhandler cont $
|
||||
liftIO $ runNetProto clientrunst clientconn $
|
||||
getClientProtocolVersion' remote
|
||||
getClientProtocolVersion remote (ClientSide client) cont protoerrhandler =
|
||||
protoerrhandler cont $ client $ getClientProtocolVersion' remote
|
||||
|
||||
getClientProtocolVersion'
|
||||
:: Remote
|
||||
|
@ -87,7 +87,7 @@ proxy
|
|||
-- ^ non-VERSION message that was received from the client when
|
||||
-- negotiating protocol version, and has not been responded to yet
|
||||
-> ProtoErrorHandled Annex r
|
||||
proxy proxydone proxymethods servermode clientside remoteside othermessage protoerrhandler = do
|
||||
proxy proxydone proxymethods servermode (ClientSide client) (RemoteSide remote remoteuuid) othermessage protoerrhandler = do
|
||||
case othermessage of
|
||||
Just message -> proxyclientmessage (Just message)
|
||||
Nothing -> do
|
||||
|
@ -95,12 +95,6 @@ proxy proxydone proxymethods servermode clientside remoteside othermessage proto
|
|||
protoerrhandler proxynextclientmessage $
|
||||
client $ net $ sendMessage $ VERSION v
|
||||
where
|
||||
ClientSide clientrunst clientconn = clientside
|
||||
RemoteSide remoterunst remoteconn remoteuuid = remoteside
|
||||
|
||||
remote = liftIO . runNetProto remoterunst remoteconn
|
||||
client = liftIO . runNetProto clientrunst clientconn
|
||||
|
||||
protocolversion = either (const defaultProtocolVersion) id
|
||||
<$> remote (net getProtocolVersion)
|
||||
|
||||
|
|
Loading…
Reference in a new issue