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.
This commit is contained in:
Joey Hess 2016-11-29 17:30:27 -04:00
parent 398345cb26
commit 38425fdc39
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
6 changed files with 106 additions and 26 deletions

View file

@ -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"