summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-24 12:07:15 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-24 12:07:15 -0400
commiteb32db78ac832f38ba6d2bc1a8b1ddb6d038ab13 (patch)
tree1718cf2d32406547d3e56d96713a954d45fe14dd /Command
parent6c089cff615bc44ca94cc4ca77dc69f281dd2ab8 (diff)
Revert "close"
This reverts commit 6c089cff615bc44ca94cc4ca77dc69f281dd2ab8. Commit contained incomplete work.
Diffstat (limited to 'Command')
-rw-r--r--Command/EnableTor.hs36
1 files changed, 4 insertions, 32 deletions
diff --git a/Command/EnableTor.hs b/Command/EnableTor.hs
index 2b7d62635..c81968a55 100644
--- a/Command/EnableTor.hs
+++ b/Command/EnableTor.hs
@@ -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