Revert "close"

This reverts commit 3aaabc906b.

Commit contained incomplete work.
This commit is contained in:
Joey Hess 2016-12-24 12:07:15 -04:00
parent 3aaabc906b
commit 22252e8e4c
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
6 changed files with 20 additions and 67 deletions

View file

@ -10,19 +10,18 @@
module Command.EnableTor where
import Command
import qualified Annex
import P2P.Address
import Utility.Tor
import Annex.UUID
import Config.Files
import P2P.IO
import Utility.ThreadScheduler
#ifndef mingw32_HOST_OS
import Utility.Su
import System.Posix.User
#endif
-- This runs as root, so avoid making any commits or initializing
-- git-annex, or doing other things that create root-owned files.
cmd :: Command
cmd = noCommit $ dontCheck repoExists $
command "enable-tor" SectionSetup "enable tor hidden service"
@ -31,8 +30,6 @@ cmd = noCommit $ dontCheck repoExists $
seek :: CmdParams -> CommandSeek
seek = withWords start
-- This runs as root, so avoid making any commits or initializing
-- git-annex, or doing other things that create root-owned files.
start :: [String] -> CommandStart
start os = do
uuid <- getUUID
@ -45,12 +42,11 @@ start os = do
Nothing -> giveup "Need user-id parameter."
Just userid -> go uuid userid
else do
showStart "enable-tor" ""
showLongNote "Need root access to enable tor..."
liftIO $ putStrLn "Need root access to enable tor..."
gitannex <- liftIO readProgramFile
let ps = [Param (cmdname cmd), Param (show curruserid)]
ifM (liftIO $ runAsRoot gitannex ps)
( next $ next checkHiddenService
( stop
, giveup $ unwords $
[ "Failed to run as root:" , gitannex ] ++ toCommand ps
)
@ -63,27 +59,3 @@ start os = do
addHiddenService torAppName userid (fromUUID uuid)
storeP2PAddress $ TorAnnex onionaddr onionport
stop
checkHiddenService :: CommandCleanup
checkHiddenService = do
showLongNote "Tor hidden service is configured. Checking connection to it. This may take a few minutes."
go (150 :: Int) =<< filter istoraddr <$> loadP2PAddresses
where
istoraddr (TorAnnex _ _) = True
go 0 _ = giveup "Still unable to connect to hidden service. It might not yet be usable by others. Please check Tor's logs for details."
go _ [] = giveup "Somehow didn't get an onion address."
go n addrs@(addr:_) = do
g <- Annex.gitRepo
-- Connect to ourselves; don't bother trying to auth,
-- we just want to know if the circuit works.
cv <- liftIO $ tryNonAsync $ connectPeer g addr
case cv of
Left e -> do
warning $ "Unable to connect to hidden service. It may not yet have propigated to the Tor network. (" ++ show e ++ ") Will retry.."
liftIO $ threadDelaySeconds (Seconds 2)
go (n-1) addrs
Right conn -> do
liftIO $ closeConnection conn
showLongNote "Tor hidden service is working."
return True