From bc75f84f58aafaf7b69f20f1507df80dccc8023b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Sep 2016 11:19:35 -0400 Subject: Tor.hiddenServiceAvailable: The hidden service hostname file may not be available immedaitely after configuring tor; avoid ugly error in this case. --- src/Propellor/Property/Tor.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/Property/Tor.hs b/src/Propellor/Property/Tor.hs index 951084b4..2fe97e4e 100644 --- a/src/Propellor/Property/Tor.hs +++ b/src/Propellor/Property/Tor.hs @@ -120,6 +120,9 @@ bandwidthRate' s divby = case readSize dataUnits s of Nothing -> property ("unable to parse " ++ s) noChange -- | Enables a hidden service for a given port. +-- +-- If used without `hiddenServiceData`, tor will generate a new +-- private key. hiddenService :: HiddenServiceName -> Port -> Property DebianLike hiddenService hn (Port port) = ConfFile.adjustSection (unwords ["hidden service", hn, "available on port", show port]) @@ -140,11 +143,13 @@ hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port where hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do r <- satisfy - h <- liftIO $ readFile (varLib hn "hostname") - warningMessage $ unwords ["hidden service hostname:", h] + mh <- liftIO $ tryIO $ readFile (varLib hn "hostname") + case mh of + Right h -> warningMessage $ unwords ["hidden service hostname:", h] + Left _e -> warningMessage "hidden service hostname not available yet" return r --- | +-- | Load the private key for a hidden service from the privdata. hiddenServiceData :: IsContext c => HiddenServiceName -> c -> Property (HasInfo + DebianLike) hiddenServiceData hn context = combineProperties desc $ props & installonion "hostname" -- cgit v1.2.3