network-anonymous-tor 0.10.0 → 0.11.0
raw patch · 4 files changed
+31/−17 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Network.Anonymous.Tor: accept :: MonadIO m => Socket -> Integer -> (Socket -> IO ()) -> m Base32String
+ Network.Anonymous.Tor: accept :: MonadIO m => Socket -> Integer -> Maybe ByteString -> (Socket -> IO ()) -> m Base32String
- Network.Anonymous.Tor: mapOnion :: MonadIO m => Socket -> Integer -> Integer -> m Base32String
+ Network.Anonymous.Tor: mapOnion :: MonadIO m => Socket -> Integer -> Integer -> Bool -> Maybe ByteString -> m Base32String
- Network.Anonymous.Tor.Protocol: mapOnion :: MonadIO m => Socket -> Integer -> Integer -> m Base32String
+ Network.Anonymous.Tor.Protocol: mapOnion :: MonadIO m => Socket -> Integer -> Integer -> Bool -> Maybe ByteString -> m Base32String
Files
- examples/Relay.lhs +1/−1
- network-anonymous-tor.cabal +1/−1
- src/Network/Anonymous/Tor.hs +10/−7
- src/Network/Anonymous/Tor/Protocol.hs +19/−8
examples/Relay.lhs view
@@ -60,7 +60,7 @@ connections to the 'newConnection' function. > withinSession (publicPort, privatePort) controlSock = do-> onion <- Tor.accept controlSock publicPort (newConnection privatePort)+> onion <- Tor.accept controlSock publicPort Nothing (newConnection privatePort) > putStrLn ("hidden service descriptor: " ++ show onion) If we would leave this function at this point, our connection with the Tor
network-anonymous-tor.cabal view
@@ -1,6 +1,6 @@ name: network-anonymous-tor category: Network-version: 0.10.0+version: 0.11.0 license: MIT license-file: LICENSE copyright: (c) 2014 Leon Mergen
src/Network/Anonymous/Tor.hs view
@@ -34,6 +34,7 @@ import Control.Monad.IO.Class import qualified Data.Base32String.Default as B32+import qualified Data.ByteString as BS import qualified Network.Simple.TCP as NST import qualified Network.Socket as Network@@ -162,12 +163,13 @@ -- connections for it. Note that this creates a new local server at the same -- port as the public port, so ensure that the port is not yet in use. accept :: MonadIO m- => Network.Socket -- ^ Connection with Tor control server- -> Integer -- ^ Port to listen at- -> (Network.Socket -> IO ()) -- ^ Callback function called for each incoming connection- -> m B32.Base32String -- ^ Returns the hidden service descriptor created- -- without the '.onion' part.-accept sock port callback = do+ => Network.Socket -- ^ Connection with Tor control server+ -> Integer -- ^ Port to listen at+ -> Maybe BS.ByteString -- ^ Optional private key to use to set up the hidden service+ -> (Network.Socket -> IO ()) -- ^ Callback function called for each incoming connection+ -> m B32.Base32String -- ^ Returns the hidden service descriptor created without+ -- the '.onion' part+accept sock port pkey callback = do -- First create local service _ <- liftIO $ forkIO $ NST.listen "*" (show port) (\(lsock, _) ->@@ -176,4 +178,5 @@ threadDelay 1000000 return ())) - P.mapOnion sock port port+ -- Do the onion mapping after that+ P.mapOnion sock port port False pkey
src/Network/Anonymous/Tor/Protocol.hs view
@@ -20,7 +20,7 @@ import Control.Concurrent.MVar -import Control.Monad (unless, void, when)+import Control.Monad (unless, void) import Control.Monad.Catch ( handle , handleIOError ) import Control.Monad.IO.Class@@ -235,13 +235,24 @@ -- | Creates a new hidden service and maps a public port to a local port. Useful -- for bridging a local service (e.g. a webserver or irc daemon) as a Tor--- hidden service.+-- hidden service. If a private key is supplied, it is used to instantiate the+-- service. mapOnion :: MonadIO m- => Network.Socket -- ^ Connection with tor Control port- -> Integer -- ^ Remote point of hidden service to listen at- -> Integer -- ^ Local port to map onion service to- -> m B32.Base32String -- ^ The address/service id of the Onion without the .onion aprt-mapOnion s rport lport = do- reply <- sendCommand s (BS8.concat ["ADD_ONION NEW:BEST Port=", BS8.pack (show rport), ",127.0.0.1:", BS8.pack(show lport), "\n"])+ => Network.Socket -- ^ Connection with tor Control port+ -> Integer -- ^ Remote point of hidden service to listen at+ -> Integer -- ^ Local port to map onion service to+ -> Bool -- ^ Wether to detach the hidden service from the current session+ -> Maybe BS.ByteString -- ^ Optional private key to use to set up the hidden service+ -> m B32.Base32String -- ^ The address/service id of the Onion without the .onion part+mapOnion s rport lport detach pkey = do+ reply <- sendCommand s $ BS8.concat+ [ "ADD_ONION "+ , maybe "NEW:BEST" (\pk -> "RSA1024:" `BS.append` pk) pkey+ , if detach then " Flags=Detach " else " "+ , "Port="+ , BS8.pack (show rport)+ , ",127.0.0.1:"+ , BS8.pack(show lport)+ , "\n"] return . B32.b32String' . fromJust . Ast.tokenValue . head . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "ServiceID") reply