dup stdio handles for P2P proxy
Special remotes might output to stdout, or read from stdin, which would mess up the P2P protocol. So dup the handles to avoid any such problem.
This commit is contained in:
parent
cecd151e23
commit
0dfdc9f951
3 changed files with 17 additions and 9 deletions
17
P2P/IO.hs
17
P2P/IO.hs
|
@ -1,6 +1,6 @@
|
|||
{- P2P protocol, IO implementation
|
||||
-
|
||||
- Copyright 2016-2018 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2016-2024 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -16,6 +16,7 @@ module P2P.IO
|
|||
, ConnIdent(..)
|
||||
, ClosableConnection(..)
|
||||
, stdioP2PConnection
|
||||
, stdioP2PConnectionDupped
|
||||
, connectPeer
|
||||
, closeConnection
|
||||
, serveUnixSocket
|
||||
|
@ -104,6 +105,20 @@ stdioP2PConnection g = P2PConnection
|
|||
, connIdent = ConnIdent Nothing
|
||||
}
|
||||
|
||||
-- P2PConnection using stdio, but with the handles first duplicated,
|
||||
-- to avoid anything that might output to stdio (eg a program run by a
|
||||
-- special remote) from interfering with the connection.
|
||||
stdioP2PConnectionDupped :: Maybe Git.Repo -> IO P2PConnection
|
||||
stdioP2PConnectionDupped g = do
|
||||
(readh, writeh) <- dupIoHandles
|
||||
return $ P2PConnection
|
||||
{ connRepo = g
|
||||
, connCheckAuth = const False
|
||||
, connIhdl = P2PHandle readh
|
||||
, connOhdl = P2PHandle writeh
|
||||
, connIdent = ConnIdent Nothing
|
||||
}
|
||||
|
||||
-- Opens a connection to a peer. Does not authenticate with it.
|
||||
connectPeer :: Maybe Git.Repo -> P2PAddress -> IO P2PConnection
|
||||
connectPeer g (TorAnnex onionaddress onionport) = do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue