wip
This commit is contained in:
parent
6ef6ad808f
commit
96ad0ccc5b
2 changed files with 52 additions and 27 deletions
|
@ -28,6 +28,7 @@ import CmdLine.Action (startConcurrency)
|
||||||
import Utility.ThreadScheduler
|
import Utility.ThreadScheduler
|
||||||
import Utility.HumanTime
|
import Utility.HumanTime
|
||||||
import Annex.Proxy
|
import Annex.Proxy
|
||||||
|
import qualified P2P.Proxy as Proxy
|
||||||
import Types.Cluster
|
import Types.Cluster
|
||||||
|
|
||||||
import Servant
|
import Servant
|
||||||
|
@ -213,8 +214,8 @@ withP2PConnections workerpool a = do
|
||||||
| connectionServerUUID connparams == myuuid =
|
| connectionServerUUID connparams == myuuid =
|
||||||
localConnection relv connparams workerpool
|
localConnection relv connparams workerpool
|
||||||
| otherwise =
|
| otherwise =
|
||||||
atomically (getProxyConnection proxypool connparams) >>= \case
|
atomically (getProxyConnectionFromPool proxypool connparams) >>= \case
|
||||||
Just conn -> proxyConnection relv connparams proxypool conn
|
Just conn -> proxyConnection relv connparams workerpool conn
|
||||||
Nothing -> checkcanproxy myuuid proxypool relv connparams
|
Nothing -> checkcanproxy myuuid proxypool relv connparams
|
||||||
|
|
||||||
checkcanproxy myuuid proxypool relv connparams =
|
checkcanproxy myuuid proxypool relv connparams =
|
||||||
|
@ -226,33 +227,46 @@ withP2PConnections workerpool a = do
|
||||||
fromMaybe "unknown uuid" reason
|
fromMaybe "unknown uuid" reason
|
||||||
Right (Right (Right proxyremote)) -> do
|
Right (Right (Right proxyremote)) -> do
|
||||||
openProxyConnectionToRemote proxyremote
|
openProxyConnectionToRemote proxyremote
|
||||||
>>= proxyConnection relv connparams proxypool
|
>>= proxyConnection relv connparams workerpool
|
||||||
Right (Right (Left cluster)) -> do
|
Right (Right (Left cluster)) -> do
|
||||||
openProxyConnectionToCluster cluster
|
openProxyConnectionToCluster cluster
|
||||||
>>= proxyConnection relv connparams proxypool
|
>>= proxyConnection relv connparams workerpool
|
||||||
Left ex -> return $ Left $
|
Left ex -> return $ Left $
|
||||||
ConnectionFailed $ show ex
|
ConnectionFailed $ show ex
|
||||||
|
|
||||||
|
proxyConnection
|
||||||
|
:: TMVar (IO ())
|
||||||
|
-> ConnectionParams
|
||||||
|
-> AnnexWorkerPool
|
||||||
|
-> ProxyConnection
|
||||||
|
-> IO (Either ConnectionProblem P2PConnectionPair)
|
||||||
|
proxyConnection relv connparams workerpool proxyconn =
|
||||||
|
-- XXX fixme mkP2PConnectionPair is not quite right for this
|
||||||
|
mkP2PConnectionPair connparams relv $ \serverrunst serverconn ->
|
||||||
|
inAnnexWorker' workerpool $ do
|
||||||
|
let proxyparams = undefined -- XXX
|
||||||
|
let remoteside = undefined -- XXX
|
||||||
|
let requestmessage = undefined -- XXX
|
||||||
|
let proxydone = return ()
|
||||||
|
let requestcomplete = \() -> return ()
|
||||||
|
let protoerrhandler = \a -> \case
|
||||||
|
Left err -> giveup err
|
||||||
|
Right v -> return v
|
||||||
|
Proxy.proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandler
|
||||||
|
|
||||||
localConnection
|
localConnection
|
||||||
:: TMVar (IO ())
|
:: TMVar (IO ())
|
||||||
-> ConnectionParams
|
-> ConnectionParams
|
||||||
-> AnnexWorkerPool
|
-> AnnexWorkerPool
|
||||||
-> IO (Either ConnectionProblem P2PConnectionPair)
|
-> IO (Either ConnectionProblem P2PConnectionPair)
|
||||||
localConnection relv connparams workerpool = mkP2PConnectionPair connparams relv $
|
localConnection relv connparams workerpool =
|
||||||
\serverrunst serverconn -> inAnnexWorker' workerpool $
|
mkP2PConnectionPair connparams relv $ \serverrunst serverconn ->
|
||||||
|
inAnnexWorker' workerpool $
|
||||||
void $ runFullProto serverrunst serverconn $
|
void $ runFullProto serverrunst serverconn $
|
||||||
P2P.serveOneCommandAuthed
|
P2P.serveOneCommandAuthed
|
||||||
(connectionServerMode connparams)
|
(connectionServerMode connparams)
|
||||||
(connectionServerUUID connparams)
|
(connectionServerUUID connparams)
|
||||||
|
|
||||||
proxyConnection
|
|
||||||
:: TMVar (IO ())
|
|
||||||
-> ConnectionParams
|
|
||||||
-> TMVar (M.Map UUID [ProxyConnection])
|
|
||||||
-> ProxyConnection
|
|
||||||
-> IO (Either ConnectionProblem P2PConnectionPair)
|
|
||||||
proxyConnection relv connparams proxypool conn = error "XXX" -- TODO
|
|
||||||
|
|
||||||
|
|
||||||
data P2PConnectionPair = P2PConnectionPair
|
data P2PConnectionPair = P2PConnectionPair
|
||||||
{ clientRunState :: RunState
|
{ clientRunState :: RunState
|
||||||
, clientP2PConnection :: P2PConnection
|
, clientP2PConnection :: P2PConnection
|
||||||
|
@ -427,25 +441,34 @@ inAnnexWorker' poolv annexaction = do
|
||||||
return res
|
return res
|
||||||
|
|
||||||
data ProxyConnection = ProxyConnection
|
data ProxyConnection = ProxyConnection
|
||||||
|
{ proxyP2PConnectionPair :: P2PConnectionPair
|
||||||
|
}
|
||||||
|
|
||||||
getProxyConnection
|
type ProxyConnectionPool =
|
||||||
:: TMVar (M.Map UUID [ProxyConnection])
|
M.Map (UUID, UUID, P2P.ProtocolVersion) [ProxyConnection]
|
||||||
|
|
||||||
|
getProxyConnectionFromPool
|
||||||
|
:: TMVar ProxyConnectionPool
|
||||||
-> ConnectionParams
|
-> ConnectionParams
|
||||||
-> STM (Maybe ProxyConnection)
|
-> STM (Maybe ProxyConnection)
|
||||||
getProxyConnection proxypool connparams = do
|
getProxyConnectionFromPool proxypool connparams = do
|
||||||
m <- takeTMVar proxypool
|
m <- takeTMVar proxypool
|
||||||
case M.lookup (connectionServerUUID connparams) m of
|
case M.lookup k m of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
putTMVar proxypool m
|
putTMVar proxypool m
|
||||||
return Nothing
|
return Nothing
|
||||||
Just [] -> do
|
Just [] -> do
|
||||||
putTMVar proxypool $
|
putTMVar proxypool $ M.insert k [] m
|
||||||
M.insert (connectionServerUUID connparams) [] m
|
|
||||||
return Nothing
|
return Nothing
|
||||||
Just (c:cs) -> do
|
Just (c:cs) -> do
|
||||||
putTMVar proxypool $
|
putTMVar proxypool $ M.insert k cs m
|
||||||
M.insert (connectionServerUUID connparams) cs m
|
|
||||||
return (Just c)
|
return (Just c)
|
||||||
|
where
|
||||||
|
k =
|
||||||
|
( connectionServerUUID connparams
|
||||||
|
, connectionClientUUID connparams
|
||||||
|
, connectionProtocolVersion connparams
|
||||||
|
)
|
||||||
|
|
||||||
openProxyConnectionToRemote :: Remote -> IO ProxyConnection
|
openProxyConnectionToRemote :: Remote -> IO ProxyConnection
|
||||||
openProxyConnectionToRemote remote = error "XXX" -- TODO
|
openProxyConnectionToRemote remote = error "XXX" -- TODO
|
||||||
|
|
|
@ -30,6 +30,8 @@ Planned schedule of work:
|
||||||
|
|
||||||
* Make http server support proxies and clusters.
|
* Make http server support proxies and clusters.
|
||||||
|
|
||||||
|
Current status: laying the keystone
|
||||||
|
|
||||||
* Support proxying to git remotes using annex+http urls.
|
* Support proxying to git remotes using annex+http urls.
|
||||||
(Current documentation says proxying only works with ssh remotes,
|
(Current documentation says proxying only works with ssh remotes,
|
||||||
so current state is not confusing, but this still needs to be done
|
so current state is not confusing, but this still needs to be done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue