clean up protocol version for proxying

The proxy always checks the protocol version of a remote before talking
to it in a version-specific way, so the protocol version in the ProxyParams
is the client's protocol version. The remote will always be at the same or
an older protocol version than the client.

Note that in relayDATAFinish, when the client is at protocol version 0,
the remote must thus be as well, and that's why its version is not
checked in the case for that.

With that clarified, it's evident that, in P2P.Http.State, there's no
need to look at the proxied remote's protocol version at all.
This commit is contained in:
Joey Hess 2024-07-26 13:39:43 -04:00
parent de7730f51f
commit ad025b8e5e
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 17 additions and 23 deletions

View file

@ -51,9 +51,8 @@ proxyCluster clusteruuid proxydone servermode clientside protoerrhandler = do
-- known at this point, and would be too expensive to -- known at this point, and would be too expensive to
-- determine. Instead, pick the newest protocol version -- determine. Instead, pick the newest protocol version
-- that we and the client both speak. The proxy code -- that we and the client both speak. The proxy code
-- checks protocol versions when operating on multiple -- checks protocol versions of remotes, so nodes can
-- nodes, and allows nodes to have different protocol -- have different protocol versions.
-- versions.
let protocolversion = min maxProtocolVersion clientmaxversion let protocolversion = min maxProtocolVersion clientmaxversion
sendClientProtocolVersion clientside othermsg protocolversion sendClientProtocolVersion clientside othermsg protocolversion
(getclientbypass protocolversion) (protoerrhandler noop) (getclientbypass protocolversion) (protoerrhandler noop)
@ -76,7 +75,7 @@ proxyCluster clusteruuid proxydone servermode clientside protoerrhandler = do
, proxyUUID = fromClusterUUID clusteruuid , proxyUUID = fromClusterUUID clusteruuid
, proxySelector = selectnode , proxySelector = selectnode
, proxyConcurrencyConfig = concurrencyconfig , proxyConcurrencyConfig = concurrencyconfig
, proxyProtocolVersion = protocolversion , proxyClientProtocolVersion = protocolversion
} }
proxy proxydone proxyparams othermsg proxy proxydone proxyparams othermsg
(protoerrhandler closenodes) (protoerrhandler closenodes)

View file

@ -84,7 +84,7 @@ performProxy clientuuid servermode r = do
, proxyUUID = Remote.uuid r , proxyUUID = Remote.uuid r
, proxySelector = singleProxySelector remoteside , proxySelector = singleProxySelector remoteside
, proxyConcurrencyConfig = concurrencyconfig , proxyConcurrencyConfig = concurrencyconfig
, proxyProtocolVersion = protocolversion , proxyClientProtocolVersion = protocolversion
} }
let runproxy othermsg' = proxy closer proxyparams let runproxy othermsg' = proxy closer proxyparams
othermsg' errhandler othermsg' errhandler

View file

@ -346,9 +346,8 @@ proxyConnection relv connparams workerpool proxyconn = do
inAnnexWorker' workerpool $ do inAnnexWorker' workerpool $ do
proxystate <- liftIO Proxy.mkProxyState proxystate <- liftIO Proxy.mkProxyState
concurrencyconfig <- Proxy.noConcurrencyConfig concurrencyconfig <- Proxy.noConcurrencyConfig
-- TODO run remote protocol to get its version and let protocolversion = min remoteprotocolversion $
-- take minimum of that and connectionProtocolVersion connectionProtocolVersion connparams
let protocolversion = connectionProtocolVersion connparams
let proxyparams = Proxy.ProxyParams let proxyparams = Proxy.ProxyParams
{ Proxy.proxyMethods = mkProxyMethods { Proxy.proxyMethods = mkProxyMethods
, Proxy.proxyState = proxystate , Proxy.proxyState = proxystate
@ -358,7 +357,7 @@ proxyConnection relv connparams workerpool proxyconn = do
, Proxy.proxySelector = Proxy.singleProxySelector $ , Proxy.proxySelector = Proxy.singleProxySelector $
proxyConnectionRemoteSide proxyconn proxyConnectionRemoteSide proxyconn
, Proxy.proxyConcurrencyConfig = concurrencyconfig , Proxy.proxyConcurrencyConfig = concurrencyconfig
, Proxy.proxyProtocolVersion = protocolversion , Proxy.proxyClientProtocolVersion = protocolversion
} }
let proxy mrequestmessage = case mrequestmessage of let proxy mrequestmessage = case mrequestmessage of
Just requestmessage -> do Just requestmessage -> do
@ -516,8 +515,8 @@ openProxyConnectionToRemote
-> [UUID] -> [UUID]
-> Remote -> Remote
-> IO (Either SomeException ProxyConnection) -> IO (Either SomeException ProxyConnection)
openProxyConnectionToRemote workerpool protoversion bypass remote = openProxyConnectionToRemote workerpool clientmaxversion bypass remote =
inAnnexWorker' workerpool (proxyRemoteSide protoversion bypass' remote) >>= \case inAnnexWorker' workerpool (proxyRemoteSide clientmaxversion bypass' remote) >>= \case
Left ex -> return (Left ex) Left ex -> return (Left ex)
Right remoteside -> return $ Right $ Right remoteside -> return $ Right $
ProxyConnection (Remote.uuid remote) remoteside ProxyConnection (Remote.uuid remote) remoteside

View file

@ -208,10 +208,9 @@ data ProxyParams = ProxyParams
, proxyUUID :: UUID , proxyUUID :: UUID
, proxySelector :: ProxySelector , proxySelector :: ProxySelector
, proxyConcurrencyConfig :: ConcurrencyConfig , proxyConcurrencyConfig :: ConcurrencyConfig
, proxyProtocolVersion :: ProtocolVersion , proxyClientProtocolVersion :: ProtocolVersion
-- ^ Protocol version being spoken between the proxy and the -- ^ The remote(s) may speak an earlier version, or the same
-- client. When there are multiple remotes, some may speak an -- version, but not a later version.
-- earlier version.
} }
{- Proxy between the client and the remote. This picks up after {- Proxy between the client and the remote. This picks up after
@ -452,7 +451,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
protoerrhandler requestcomplete $ protoerrhandler requestcomplete $
client $ net $ sendMessage $ client $ net $ sendMessage $
let nonplussed = all (== proxyUUID proxyparams) us let nonplussed = all (== proxyUUID proxyparams) us
|| proxyProtocolVersion proxyparams < ProtocolVersion 2 || proxyClientProtocolVersion proxyparams < ProtocolVersion 2
in if all (maybe False (fst . fst)) v' in if all (maybe False (fst . fst)) v'
then if nonplussed then if nonplussed
then SUCCESS then SUCCESS
@ -496,7 +495,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
relayDATAFinish (runRemoteSide remoteside) client $ relayDATAFinish (runRemoteSide remoteside) client $
relayonemessage client (runRemoteSide remoteside) $ relayonemessage client (runRemoteSide remoteside) $
const requestcomplete const requestcomplete
relayPUT remoteside k len = relayDATAStart (runRemoteSide remoteside) $ relayPUT remoteside k len = relayDATAStart (runRemoteSide remoteside) $
relayDATACore len client (runRemoteSide remoteside) $ relayDATACore len client (runRemoteSide remoteside) $
relayDATAFinish client (runRemoteSide remoteside) $ relayDATAFinish client (runRemoteSide remoteside) $
@ -536,7 +535,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
_ -> False _ -> False
l <- forMC (proxyConcurrencyConfig proxyparams) remotesides initiate l <- forMC (proxyConcurrencyConfig proxyparams) remotesides initiate
if all alreadyhave l if all alreadyhave l
then if proxyProtocolVersion proxyparams < ProtocolVersion 2 then if proxyClientProtocolVersion proxyparams < ProtocolVersion 2
then protoerrhandler requestcomplete $ then protoerrhandler requestcomplete $
client $ net $ sendMessage ALREADY_HAVE client $ net $ sendMessage ALREADY_HAVE
else protoerrhandler requestcomplete $ else protoerrhandler requestcomplete $
@ -621,7 +620,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
| otherwise = relayonemessage x y (\_ () -> sendsuccessfailure) | otherwise = relayonemessage x y (\_ () -> sendsuccessfailure)
relayDATAFinishMulti k rs relayDATAFinishMulti k rs
| proxyProtocolVersion proxyparams == ProtocolVersion 0 = | proxyProtocolVersion proxyparams == ProtocolVersion 0 =
finish $ net receiveMessage finish $ net receiveMessage
| otherwise = | otherwise =
flip protoerrhandler (client $ net $ receiveMessage) $ flip protoerrhandler (client $ net $ receiveMessage) $
@ -646,7 +645,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
case concat (catMaybes storeduuids) of case concat (catMaybes storeduuids) of
[] -> FAILURE [] -> FAILURE
us us
| proxyProtocolVersion proxyparams < ProtocolVersion 2 -> SUCCESS | proxyClientProtocolVersion proxyparams < ProtocolVersion 2 -> SUCCESS
| otherwise -> SUCCESS_PLUS us | otherwise -> SUCCESS_PLUS us
-- The associated file received from the P2P protocol -- The associated file received from the P2P protocol

View file

@ -30,9 +30,6 @@ Planned schedule of work:
* http server proxying hangs on git-annex copy --to it * http server proxying hangs on git-annex copy --to it
* http server proxying needs to get the version negotiated with the proxied
remote and feed that into the proxy function.
* test http server proxying with special remotes * test http server proxying with special remotes
* http server proxying needs to reuse connections to special remotes, * http server proxying needs to reuse connections to special remotes,