Hi,
as I've said in another mail, I've done some work on building an
asyncronous DNS client because I needed in building a HTTP caching
proxy.
Now I've done some API refactoring and there is a module that uses an
API like the one proposed by Trustin.
DnsResolver resolver = new DnsResolver(); // This istance will be shared
DnsFuture f = resolver.resolve( "www.google.com" );
f.addListener(new IoFutureListener<DnsFuture>() {
public void operationComplete(DnsFuture future) {
if ( ! future.isNameError() )
{
InetAddress address = future.get();
.......
}
}
});
or:
f.await();
f.getAll(); // Returns a List<InetAddress> with all the addresses for the host
The implementations is not complete yes as :
* Only uses first DNS server (primary), as read from /etc/resolv.conf
* Does not work on Windows ( I don't know how to get the nameservers list )
* Can cache DNS addresses, but.. caches forever as no expiration is applied
* Does not use (cache) aliases
The code can be found here:
http://alijo.googlecode.com/svn/trunk/protocol-dns/
The codecs are based on ApacheDirectory DNS codecs.
I would be happy if this code will be useful, and accept any comment
on API and implementation.
Regards,
Matteo
On Feb 18, 2008 5:57 AM, 이희승 (Trustin Lee) <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I thought about incorporating asynchronous DNS query feature into MINA
> core, and reached to the temporary conclusion that it might be a better
> idea to keep it as a separate submodule.
>
> The reasoning behind this idea is that InetSocketAddress() doesn't query
> DNS server at all if an IP address is specified. For example, new
> InetSocketAddress("gleamynode.net", 8080) causes a DNS lookup, but new
> InetSocketAddress("123.123.123.123", 8080) doesn't, which means that we
> can still keep SocketAddress as a standard interface to represent an
> endpoint.
>
> In the separate module, user could request asynchronous DNS query like
> the following:
>
> DnsResolver resolver = ...;
> Future<InetAddress> f = resolver.query("gleamynode.net");
> // returns an InetAddress with an IP address rather than with host name.
> InetAddress address = f.get();
>
> By providing this submodule rather than changing the core:
>
> 1) Most users are happy that they don't need to change anything.
> 2) Some users who needs asynchronous domain name resolution can use the
> submodule for better simultaneous, asynchronous, complicated domain
> resolution.
>
> We could provide it as a subproject, but in this case, providing it as a
> submodule will make MINA more complete network application framework.
> On the other point, it's also the implementation of DNS protocol, so it
> might be a better idea to provide it as a subproject.
>
> WDYT?
>
> --
> Trustin Lee - Principal Software Engineer, JBoss, Red Hat
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
>
--
Matteo Merli
<[EMAIL PROTECTED]>