Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stable API for makeConnection or socketConnection #223

Closed
joeyh opened this issue Aug 29, 2016 · 4 comments
Closed

stable API for makeConnection or socketConnection #223

joeyh opened this issue Aug 29, 2016 · 4 comments

Comments

@joeyh
Copy link
Contributor

joeyh commented Aug 29, 2016

To talk to a tor hidden service using servant-client, I implemented my own managerRawConnection. It simply uses socks to open the tor socket, and then needs to turn the Socket into a Connection.

There's a function to do that, socketConnection, but it's not exported from http-client at all. That leaves Network.HTTP.Client.makeConnection, which has no api stability. So, it would be great to get either of these promoted to the stable API to allow for this and other use cases for using socks.


Here's the code I wrote to talk to tor hidden services. I could see making a http-client-socks or a http-client-tor library out of this eventually, but not today.

torableManager :: ManagerSettings
torableManager = defaultManagerSettings
    { managerRawConnection = return conn
    }
 where
    conn addr host port
            | ".onion" `isSuffixOf` (map toLower host) = torConnection host port
            | otherwise = do
                    regular <- managerRawConnection defaultManagerSettings
                    regular addr host port

torConnection :: HostName -> Port -> IO Connection
torConnection onionaddress p = do
    (socket, _) <- socksConnect torsockconf socksaddr
    socketConnection socket 8192
 where
    torsocksport = 9050
    torsockconf = defaultSocksConf "127.0.0.1" torsocksport
    socksdomain = SocksAddrDomainName (BU8.fromString onionaddress)
    socksaddr = SocksAddress socksdomain (fromIntegral p)

-- copied from http-client
socketConnection :: Network.Socket.Socket -> Int -> IO Connection
socketConnection socket chunksize = makeConnection
    (recv socket chunksize)
    (sendAll socket)
    (Network.Socket.close socket)
@snoyberg
Copy link
Owner

I have no problem with both of these functions being promoted to the stable module.

@snoyberg
Copy link
Owner

Just to confirm, is 91d161d what you had in mind?

@joeyh
Copy link
Contributor Author

joeyh commented Aug 31, 2016

Perfect thank you.

see shy jo

@snoyberg
Copy link
Owner

Awesome, released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants