include tor-annex in hidden service directory names
To make it easier to manage/delete them etc. Backwards compatablity is preserved for existing tor configs.
This commit is contained in:
parent
872064e4a6
commit
405fbd25e1
4 changed files with 20 additions and 14 deletions
|
@ -56,6 +56,6 @@ start os = do
|
||||||
where
|
where
|
||||||
go uuid userid = do
|
go uuid userid = do
|
||||||
(onionaddr, onionport) <- liftIO $
|
(onionaddr, onionport) <- liftIO $
|
||||||
addHiddenService "tor-annex" userid (fromUUID uuid)
|
addHiddenService torAppName userid (fromUUID uuid)
|
||||||
storeP2PAddress $ TorAnnex onionaddr onionport
|
storeP2PAddress $ TorAnnex onionaddr onionport
|
||||||
stop
|
stop
|
||||||
|
|
|
@ -90,3 +90,6 @@ storeP2PAddress addr = do
|
||||||
|
|
||||||
p2pAddressCredsFile :: FilePath
|
p2pAddressCredsFile :: FilePath
|
||||||
p2pAddressCredsFile = "p2paddrs"
|
p2pAddressCredsFile = "p2paddrs"
|
||||||
|
|
||||||
|
torAppName :: AppName
|
||||||
|
torAppName = "tor-annex"
|
||||||
|
|
|
@ -41,7 +41,7 @@ server th@(TransportHandle (LocalRepo r) _) = do
|
||||||
u <- liftAnnex th getUUID
|
u <- liftAnnex th getUUID
|
||||||
uid <- getRealUserID
|
uid <- getRealUserID
|
||||||
let ident = fromUUID u
|
let ident = fromUUID u
|
||||||
go u =<< getHiddenServiceSocketFile uid ident
|
go u =<< getHiddenServiceSocketFile torAppName uid ident
|
||||||
where
|
where
|
||||||
go u (Just sock) = do
|
go u (Just sock) = do
|
||||||
q <- newTBMQueueIO maxConnections
|
q <- newTBMQueueIO maxConnections
|
||||||
|
|
|
@ -66,7 +66,7 @@ addHiddenService appname uid ident = do
|
||||||
writeFile torrc $ unlines $
|
writeFile torrc $ unlines $
|
||||||
ls ++
|
ls ++
|
||||||
[ ""
|
[ ""
|
||||||
, "HiddenServiceDir " ++ hiddenServiceDir uid ident
|
, "HiddenServiceDir " ++ hiddenServiceDir appname uid ident
|
||||||
, "HiddenServicePort " ++ show newport ++
|
, "HiddenServicePort " ++ show newport ++
|
||||||
" unix:" ++ sockfile
|
" unix:" ++ sockfile
|
||||||
]
|
]
|
||||||
|
@ -95,7 +95,7 @@ addHiddenService appname uid ident = do
|
||||||
waithiddenservice :: Int -> OnionPort -> IO (OnionAddress, OnionPort)
|
waithiddenservice :: Int -> OnionPort -> IO (OnionAddress, OnionPort)
|
||||||
waithiddenservice 0 _ = giveup "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
|
waithiddenservice n p = do
|
||||||
v <- tryIO $ readFile $ hiddenServiceHostnameFile uid ident
|
v <- tryIO $ readFile $ hiddenServiceHostnameFile appname uid ident
|
||||||
case v of
|
case v of
|
||||||
Right s | ".onion\n" `isSuffixOf` s ->
|
Right s | ".onion\n" `isSuffixOf` s ->
|
||||||
return (OnionAddress (takeWhile (/= '\n') s), p)
|
return (OnionAddress (takeWhile (/= '\n') s), p)
|
||||||
|
@ -105,13 +105,14 @@ addHiddenService appname uid ident = do
|
||||||
|
|
||||||
-- | A hidden service directory to use.
|
-- | A hidden service directory to use.
|
||||||
--
|
--
|
||||||
-- The "hs" is used in the name to prevent too long a path name,
|
-- Has to be inside the torLibDir so tor can create it.
|
||||||
-- which could present problems for socketFile.
|
--
|
||||||
hiddenServiceDir :: UserID -> UniqueIdent -> FilePath
|
-- Has to end with "uid_ident" so getHiddenServiceSocketFile can find it.
|
||||||
hiddenServiceDir uid ident = torLibDir </> "hs_" ++ show uid ++ "_" ++ ident
|
hiddenServiceDir :: AppName -> UserID -> UniqueIdent -> FilePath
|
||||||
|
hiddenServiceDir appname uid ident = torLibDir </> appname ++ "_" ++ show uid ++ "_" ++ ident
|
||||||
|
|
||||||
hiddenServiceHostnameFile :: UserID -> UniqueIdent -> FilePath
|
hiddenServiceHostnameFile :: AppName -> UserID -> UniqueIdent -> FilePath
|
||||||
hiddenServiceHostnameFile uid ident = hiddenServiceDir uid ident </> "hostname"
|
hiddenServiceHostnameFile appname uid ident = hiddenServiceDir appname uid ident </> "hostname"
|
||||||
|
|
||||||
-- | Location of the socket for a hidden service.
|
-- | Location of the socket for a hidden service.
|
||||||
--
|
--
|
||||||
|
@ -126,18 +127,20 @@ hiddenServiceSocketFile appname uid ident = varLibDir </> appname </> show uid +
|
||||||
|
|
||||||
-- | Parse torrc, to get the socket file used for a hidden service with
|
-- | Parse torrc, to get the socket file used for a hidden service with
|
||||||
-- the specified UniqueIdent.
|
-- the specified UniqueIdent.
|
||||||
getHiddenServiceSocketFile :: UserID -> UniqueIdent -> IO (Maybe FilePath)
|
getHiddenServiceSocketFile :: AppName -> UserID -> UniqueIdent -> IO (Maybe FilePath)
|
||||||
getHiddenServiceSocketFile uid ident =
|
getHiddenServiceSocketFile _appname uid ident =
|
||||||
parse . map words . lines <$> catchDefaultIO "" (readFile torrc)
|
parse . map words . lines <$> catchDefaultIO "" (readFile torrc)
|
||||||
where
|
where
|
||||||
parse [] = Nothing
|
parse [] = Nothing
|
||||||
parse (("HiddenServiceDir":hsdir:[]):("HiddenServicePort":_hsport:hsaddr:[]):rest)
|
parse (("HiddenServiceDir":hsdir:[]):("HiddenServicePort":_hsport:hsaddr:[]):rest)
|
||||||
| "unix:" `isPrefixOf` hsaddr && hsdir == hsdir_want =
|
| "unix:" `isPrefixOf` hsaddr && hasident hsdir =
|
||||||
Just (drop (length "unix:") hsaddr)
|
Just (drop (length "unix:") hsaddr)
|
||||||
| otherwise = parse rest
|
| otherwise = parse rest
|
||||||
parse (_:rest) = parse rest
|
parse (_:rest) = parse rest
|
||||||
|
|
||||||
hsdir_want = hiddenServiceDir uid ident
|
-- Don't look for AppName in the hsdir, because it didn't used to
|
||||||
|
-- be included.
|
||||||
|
hasident hsdir = (show uid ++ "_" ++ ident) `isSuffixOf` takeFileName hsdir
|
||||||
|
|
||||||
-- | Sets up the directory for the socketFile, with appropriate
|
-- | Sets up the directory for the socketFile, with appropriate
|
||||||
-- permissions. Must run as root.
|
-- permissions. Must run as root.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue