aboutsummaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-11-29 17:30:27 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-11-29 17:30:27 -0400
commit6fbf18025af8c697b515e83600f16de0c232a994 (patch)
tree75e4ce29ffeb2a66273c8402447ae4626ff87724 /Utility
parentec8d3f61bd4cd1432757fd8fe185ba8f35791755 (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 'Utility')
-rw-r--r--Utility/Tor.hs10
1 files changed, 5 insertions, 5 deletions
diff --git a/Utility/Tor.hs b/Utility/Tor.hs
index 3b9ddb6a6..e63bd82d4 100644
--- a/Utility/Tor.hs
+++ b/Utility/Tor.hs
@@ -21,7 +21,7 @@ import qualified System.Random as R
type OnionPort = Int
newtype OnionAddress = OnionAddress String
- deriving (Show)
+ deriving (Show, Eq)
type OnionSocket = FilePath
@@ -57,7 +57,7 @@ addHiddenService uid ident = do
case filter (\(_, s) -> s == sockfile) portssocks of
((p, _s):_) -> waithiddenservice 1 p
_ -> do
- highports <- R.getStdRandom highports
+ highports <- R.getStdRandom mkhighports
let newport = Prelude.head $
filter (`notElem` map fst portssocks) highports
writeFile torrc $ unlines $
@@ -74,7 +74,7 @@ addHiddenService uid ident = do
, ("sefvice", [Param "tor", Param "reload"])
]
unless reloaded $
- error "failed to reload tor, perhaps the tor service is not running"
+ giveup "failed to reload tor, perhaps the tor service is not running"
waithiddenservice 120 newport
where
parseportsock ("HiddenServicePort", l) = do
@@ -85,12 +85,12 @@ addHiddenService uid ident = do
sockfile = hiddenServiceSocketFile uid ident
-- An infinite random list of high ports.
- highports g =
+ mkhighports g =
let (g1, g2) = R.split g
in (R.randomRs (1025, 65534) g1, g2)
waithiddenservice :: Int -> OnionPort -> IO (OnionAddress, OnionPort)
- waithiddenservice 0 _ = error "tor failed to create hidden service, perhaps the tor service is not running"
+ waithiddenservice 0 _ = giveup "tor failed to create hidden service, perhaps the tor service is not running"
waithiddenservice n p = do
v <- tryIO $ readFile $ hiddenServiceHostnameFile uid ident
case v of