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

Choosing outgoing IP #14

Closed
barbolo opened this issue Jul 29, 2011 · 4 comments
Closed

Choosing outgoing IP #14

barbolo opened this issue Jul 29, 2011 · 4 comments

Comments

@barbolo
Copy link

barbolo commented Jul 29, 2011

My machine has a pool of IPs. Is it possible to choose the outgoing IP the proxy will use to make the requests? Would it be possible to randomly use more than one IP?

Thanks

@igrigorik
Copy link
Owner

Hmm, that's a great question. Assuming your box has multiple IP's assigned to it... I'm not sure if EventMachine has any API's for picking a specific interface to initiate an outgoing connection.

@tmm1: any thought on this?

Equivalent for curl: http://stackoverflow.com/questions/2425651/select-outgoing-ip-for-curl-request

@tmm1
Copy link

tmm1 commented Jul 30, 2011

Use EM.bind_connect

@igrigorik
Copy link
Owner

Ah, figures.. Never used that API before. Thanks!

@barbolo, so the answer is: yes it is possible, but it would require some patching to support this use case :-)

@barbolo
Copy link
Author

barbolo commented Jul 31, 2011

Thanks @tmm1 and @igrigorik!

I tryed patching the em-proxy gem and believe I got it working. One new problem is that EM.bind_connect (as well as EM.connect) seems not to work correctly with IPv6. The IP addresses attached to my machine are all IPv6.

I replaced the following line of lib/em-proxy/connection.rb:

srv = EventMachine::connect(opts[:host], opts[:port], EventMachine::ProxyServer::Backend, @debug) do |c|

with:

ipv6 = Socket.ip_address_list.sample # choose a random ipv6 attached to the machine
srv = EventMachine::bind_connect(ipv6, nil, opts[:host], opts[:port], EventMachine::ProxyServer::Backend, @debug) do |c|

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

3 participants