ibc / em-udns

An async DNS resolver for EventMachine based on the udns C library
http://ibc.github.com/em-udns/
GNU Lesser General Public License v2.1
37 stars 12 forks source link

How about something like em-resolve-replace? #9

Open royaltm opened 12 years ago

royaltm commented 12 years ago

Have you thought about solution like em-resolve-replace using em-udns? Or perhaps it is already done, but I couldn't find it.

ibc commented 12 years ago

AFAIK em-resolve-replace provides nothing that em-udns provides (in fact em-udns is MUCH more powerful).

If I'm not wrong, using em-resolve-replace you still need to set callbacks for the DNS query.

royaltm commented 12 years ago

By "em-resolve-replace" i meant the philosophy not the implementation. My question was rather about: is there a fiber-aware monkeypatch for ruby Resolv class to use em-udns internally?

So i could do:

  Resolv.getaddresses('google.com')

and Resolv will use em-udns internally if EM reactor is running.

ibc commented 12 years ago

There is not. Maybe I could include a code for integrating em-udns with em-synchrony?

royaltm commented 12 years ago

What do you mean by integrating? It would be great to make a patch to callbacks like EM.connect or EM.bind_connect so host parameter is resolved before passing it to EM internals. Eventmachine by default uses system-specific gethostbyaddr to resolve host string which is not aware of a reactor and could block your whole reactor-aware process. I'm thinking of a solution so any existing code could use em-udns "magically". Just

  require 'em-resolve-udns'

should be enough.

ibc commented 12 years ago

Is that what em-resolve-replace do?

royaltm commented 12 years ago

Not it doesn't. It only patches Resolv class from stdlib's "resolv.rb".

I'm thinking of some kind of "em-smart-resolve" which probably should be a separate project. This "em-smart-resolve" would patch EM connecting methods, Resolv and other possible interfaces which implicitly resolve hostnames and handle the cases in which more than one asynchronous task tries to resolve the same hostname and use any backend for actually resolving names, in a way that the em-udns would be one of possible backends available.

But before i write the first line of the code i would like to know if there is a solution like this available. I've only found so far "em-resolve-replace" which is a good idea, but quite poor implementation (missing IPV6 and so) and your em-udns which looks technically great but has little practical use for average project.

ibc commented 12 years ago

Hi, the problem of em-udns is that it requires a recursive name server, and this is something lot of people does not understand. You cannot (probably) use em-udns with your ADSL provider DNS server... IMHO em-udns is specially designed for EM servers rather than clients than run in personal computers.

What you mean for EM is possible but requires an extra API (i.e. a new callback EM::Connection#dns_failed(error)) or perhaps the DNS error should be exposed in the unbind(cause) callback, no idea...

I'm very busy rigth now and honestly never thought in em-udns for basic DNS replacement in EM, but for building complex EM servers with good and complete DNS support (i.e. A, AAAA, NAPTR, SRV...). However if I get some time I can start with it.