diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-11-29 17:30:27 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-11-29 17:30:27 -0400 |
commit | 6fbf18025af8c697b515e83600f16de0c232a994 (patch) | |
tree | 75e4ce29ffeb2a66273c8402447ae4626ff87724 /Command/EnableTor.hs | |
parent | ec8d3f61bd4cd1432757fd8fe185ba8f35791755 (diff) |
finish git-annex enable-tor
Make it stash the address away for git-annex p2p to use later, rather
than outputting it. And, look up the UUID itself.
Diffstat (limited to 'Command/EnableTor.hs')
-rw-r--r-- | Command/EnableTor.hs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/Command/EnableTor.hs b/Command/EnableTor.hs index c581fa1d4..d24ecb2dc 100644 --- a/Command/EnableTor.hs +++ b/Command/EnableTor.hs @@ -8,27 +8,28 @@ module Command.EnableTor where import Command +import P2P.Address import Utility.Tor +import Annex.UUID -- This runs as root, so avoid making any commits or initializing --- git-annex, as that would create root-owned files. +-- git-annex, or doing other things that create root-owned files. cmd :: Command cmd = noCommit $ dontCheck repoExists $ - command "enable-tor" SectionSetup "" - "userid uuid" (withParams seek) + command "enable-tor" SectionSetup "enable tor hidden service" + "uid" (withParams seek) seek :: CmdParams -> CommandSeek seek = withWords start -start :: CmdParams -> CommandStart -start (suserid:uuid:[]) = case readish suserid of - Nothing -> error "Bad userid" +start :: [String] -> CommandStart +start ps = case readish =<< headMaybe ps of + Nothing -> giveup "Bad params" Just userid -> do - (OnionAddress onionaddr, onionport) <- liftIO $ - addHiddenService userid uuid - liftIO $ putStrLn $ - "tor-annex::" ++ - onionaddr ++ ":" ++ - show onionport ++ " " + uuid <- getUUID + when (uuid == NoUUID) $ + giveup "This can only be run in a git-annex repository." + (onionaddr, onionport) <- liftIO $ + addHiddenService userid (fromUUID uuid) + storeP2PAddress $ TorAnnex onionaddr onionport stop -start _ = error "Bad params" |