From d34326ab76c3227aa7715e8e60a2aabb8eae9316 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Jun 2024 10:51:37 -0400 Subject: [PATCH] factor out Annex.Proxy --- Annex/Proxy.hs | 27 +++++++++++++++++++++++++++ Command/P2PStdIO.hs | 14 +------------- git-annex.cabal | 1 + 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 Annex/Proxy.hs diff --git a/Annex/Proxy.hs b/Annex/Proxy.hs new file mode 100644 index 0000000000..6eacc04df8 --- /dev/null +++ b/Annex/Proxy.hs @@ -0,0 +1,27 @@ +{- proxying + - + - Copyright 2024 Joey Hess + - + - Licensed under the GNU AGPL version 3 or higher. + -} + +module Annex.Proxy where + +import Annex.Common +import P2P.Proxy +import P2P.Protocol +import P2P.IO +import qualified Remote +import Remote.Helper.Ssh (openP2PShellConnection', closeP2PShellConnection) + +-- FIXME: Support special remotes. +proxySshRemoteSide :: ProtocolVersion -> Remote -> Annex RemoteSide +proxySshRemoteSide clientmaxversion remote = mkRemoteSide (Remote.uuid remote) $ + openP2PShellConnection' remote clientmaxversion >>= \case + Just conn@(OpenConnection (remoterunst, remoteconn, _)) -> + return $ Just + ( remoterunst + , remoteconn + , void $ liftIO $ closeP2PShellConnection conn + ) + _ -> return Nothing diff --git a/Command/P2PStdIO.hs b/Command/P2PStdIO.hs index 2123781318..eea5ca3340 100644 --- a/Command/P2PStdIO.hs +++ b/Command/P2PStdIO.hs @@ -13,9 +13,9 @@ import P2P.Annex import P2P.Proxy import qualified P2P.Protocol as P2P import qualified Annex +import Annex.Proxy import Annex.UUID import qualified CmdLine.GitAnnexShell.Checks as Checks -import Remote.Helper.Ssh (openP2PShellConnection', closeP2PShellConnection) import Logs.Location import Logs.Cluster import Annex.Cluster @@ -94,18 +94,6 @@ proxyClientSide clientuuid = do clientrunst <- liftIO (mkRunState $ Serving clientuuid Nothing) return $ ClientSide clientrunst (stdioP2PConnection Nothing) --- FIXME: Support special remotes. -proxySshRemoteSide :: P2P.ProtocolVersion -> Remote -> Annex RemoteSide -proxySshRemoteSide clientmaxversion remote = mkRemoteSide (Remote.uuid remote) $ - openP2PShellConnection' remote clientmaxversion >>= \case - Just conn@(P2P.IO.OpenConnection (remoterunst, remoteconn, _)) -> - return $ Just - ( remoterunst - , remoteconn - , void $ liftIO $ closeP2PShellConnection conn - ) - _ -> return Nothing - p2pErrHandler :: (a -> CommandPerform) -> Annex (Either ProtoFailure a) -> CommandPerform p2pErrHandler cont a = a >>= \case -- Avoid displaying an error when the client hung up on us. diff --git a/git-annex.cabal b/git-annex.cabal index d04848b7a3..51ef9a0f44 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -550,6 +550,7 @@ Executable git-annex Annex.Path Annex.Perms Annex.PidLock + Annex.Proxy Annex.Queue Annex.ReplaceFile Annex.RemoteTrackingBranch -- 2.39.5