ProxySelector data type

This commit is contained in:
Joey Hess 2024-06-17 19:19:15 -04:00
parent 7a839a983a
commit ef26470810
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 34 additions and 12 deletions

View file

@ -74,7 +74,7 @@ performProxy clientuuid servermode remote = do
closeRemoteSide remoteside closeRemoteSide remoteside
p2pDone p2pDone
proxy closer proxyMethods servermode clientside proxy closer proxyMethods servermode clientside
(const $ return remoteside) (singleProxySelector remoteside)
protocolversion othermsg p2pErrHandler protocolversion othermsg p2pErrHandler
withclientversion _ Nothing = p2pDone withclientversion _ Nothing = p2pDone

View file

@ -50,6 +50,28 @@ closeRemoteSide remoteside =
Just (_, _, closer) -> closer Just (_, _, closer) -> closer
Nothing -> return () Nothing -> return ()
{- Selects what remotes to proxy to for top-level P2P protocol
- actions.
- -}
data ProxySelector = ProxySelector
{ proxyCHECKPRESENT :: Key -> Annex RemoteSide
, proxyLOCKCONTENT :: Key -> Annex RemoteSide
, proxyUNLOCKCONTENT :: Annex RemoteSide
, proxyREMOVE :: Key -> Annex RemoteSide
, proxyGET :: Key -> Annex RemoteSide
, proxyPUT :: Key -> Annex RemoteSide
}
singleProxySelector :: RemoteSide -> ProxySelector
singleProxySelector r = ProxySelector
{ proxyCHECKPRESENT = const (pure r)
, proxyLOCKCONTENT = const (pure r)
, proxyUNLOCKCONTENT = pure r
, proxyREMOVE = const (pure r)
, proxyGET = const (pure r)
, proxyPUT = const (pure r)
}
{- To keep this module limited to P2P protocol actions, {- To keep this module limited to P2P protocol actions,
- all other actions that a proxy needs to do are provided - all other actions that a proxy needs to do are provided
- here. -} - here. -}
@ -113,13 +135,13 @@ proxy
-> ProxyMethods -> ProxyMethods
-> ServerMode -> ServerMode
-> ClientSide -> ClientSide
-> (Message -> Annex RemoteSide) -> ProxySelector
-> ProtocolVersion -> ProtocolVersion
-> Maybe Message -> Maybe Message
-- ^ non-VERSION message that was received from the client when -- ^ non-VERSION message that was received from the client when
-- negotiating protocol version, and has not been responded to yet -- negotiating protocol version, and has not been responded to yet
-> ProtoErrorHandled r -> ProtoErrorHandled r
proxy proxydone proxymethods servermode (ClientSide clientrunst clientconn) getremoteside protocolversion othermessage protoerrhandler = do proxy proxydone proxymethods servermode (ClientSide clientrunst clientconn) proxyselector protocolversion othermessage protoerrhandler = do
case othermessage of case othermessage of
Nothing -> protoerrhandler proxynextclientmessage $ Nothing -> protoerrhandler proxynextclientmessage $
client $ net $ sendMessage $ VERSION protocolversion client $ net $ sendMessage $ VERSION protocolversion
@ -138,24 +160,24 @@ proxy proxydone proxymethods servermode (ClientSide clientrunst clientconn) getr
proxyclientmessage Nothing = proxydone proxyclientmessage Nothing = proxydone
proxyclientmessage (Just message) = case message of proxyclientmessage (Just message) = case message of
CHECKPRESENT _ -> do CHECKPRESENT k -> do
remoteside <- getremoteside message remoteside <- proxyCHECKPRESENT proxyselector k
proxyresponse remoteside message (const proxynextclientmessage) proxyresponse remoteside message (const proxynextclientmessage)
LOCKCONTENT _ -> do LOCKCONTENT k -> do
remoteside <- getremoteside message remoteside <- proxyLOCKCONTENT proxyselector k
proxyresponse remoteside message (const proxynextclientmessage) proxyresponse remoteside message (const proxynextclientmessage)
UNLOCKCONTENT -> do UNLOCKCONTENT -> do
remoteside <- getremoteside message remoteside <- proxyUNLOCKCONTENT proxyselector
proxynoresponse remoteside message proxynextclientmessage proxynoresponse remoteside message proxynextclientmessage
REMOVE k -> do REMOVE k -> do
remoteside <- getremoteside message remoteside <- proxyREMOVE proxyselector k
servermodechecker checkREMOVEServerMode $ servermodechecker checkREMOVEServerMode $
handleREMOVE remoteside k message handleREMOVE remoteside k message
GET _ _ _ -> do GET _ _ k -> do
remoteside <- getremoteside message remoteside <- proxyGET proxyselector k
handleGET remoteside message handleGET remoteside message
PUT _ k -> do PUT _ k -> do
remoteside <- getremoteside message remoteside <- proxyPUT proxyselector k
servermodechecker checkPUTServerMode $ servermodechecker checkPUTServerMode $
handlePUT remoteside k message handlePUT remoteside k message
-- These messages involve the git repository, not the -- These messages involve the git repository, not the