summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-11-14 16:35:45 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-11-14 16:47:56 -0400
commita5584e1a61861dff0835f7ea4e366e393c0fd294 (patch)
tree5e9b46f0404cad2380708418ef250b1cb8ac9368 /Command
parentfbaf45d0f22aa74df19f5d765a8b0ee4d3526a20 (diff)
use socket for tor hidden service
This avoids needing to bind to the right port before something else does. The socket is in /var/run/user/$uid/ which ought to be writable by only that uid. At least it is on linux systems using systemd. For Windows, may need to revisit this and use ports or something. The first version of tor to support sockets for hidden services was 0.2.6.3. That is not in Debian stable, but is available in backports. This commit was sponsored by andrea rota.
Diffstat (limited to 'Command')
-rw-r--r--Command/EnableTor.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/Command/EnableTor.hs b/Command/EnableTor.hs
index 8d9dd6f0a..1a54c6c5d 100644
--- a/Command/EnableTor.hs
+++ b/Command/EnableTor.hs
@@ -10,19 +10,25 @@ module Command.EnableTor where
import Command
import Utility.Tor
+-- This runs as root, so avoid making any commits or initializing
+-- git-annex, as that would create root-owned files.
cmd :: Command
cmd = noCommit $ dontCheck repoExists $
command "enable-tor" SectionPlumbing ""
- paramNumber (withParams seek)
+ "userid uuid" (withParams seek)
seek :: CmdParams -> CommandSeek
seek = withWords start
start :: CmdParams -> CommandStart
-start (localport:[]) = case readish localport of
- Nothing -> error "Bad localport"
- Just lp -> do
- (onionaddr, onionport) <- liftIO $ addHiddenService lp
- liftIO $ putStrLn (onionaddr ++ ":" ++ show onionport)
+start (suserid:uuid:[]) = case readish suserid of
+ Nothing -> error "Bad userid"
+ Just userid -> do
+ (onionaddr, onionport, onionsocket) <- liftIO $
+ addHiddenService userid uuid
+ liftIO $ putStrLn $
+ onionaddr ++ ":" ++
+ show onionport ++ " " ++
+ show onionsocket
stop
-start _ = error "Need 1 localport parameter"
+start _ = error "Bad params"