The following code:
Security.setProperty("networkaddress.cache.ttl", "1");
Core.logger.log(Main.class, "Reset current DNS cache TTL to 5 seconds",
                                Core.logger.DEBUG);

long t = System.currentTimeMillis();
for(int x=0;x<100000;x++) {
        Thread.sleep(2000);
        long c = System.currentTimeMillis();
        InetAddress addr = InetAddress.getByName("amphibian.var.cx");
        long ct = System.currentTimeMillis();
        Core.logger.log(Main.class, "Address: "+addr.getHostAddress()+
                        " at "+(c-t)+" ms - lookup took "+
                        (ct-c)+" ms", Core.logger.DEBUG);
}

run on sun jdk 1.4.1r01 and 1.3.1, gives results like this:
SEC Feb 21, 2003 7:15:35 PM (freenet.node.Main, main, DEBUG): Address:
22.22.22.22 at 316442 ms - lookup took 1 ms
SEC Feb 21, 2003 7:15:37 PM (freenet.node.Main, main, DEBUG): Address:
22.22.22.22 at 318492 ms - lookup took 0 ms
SEC Feb 21, 2003 7:15:39 PM (freenet.node.Main, main, DEBUG): Address:
22.22.22.22 at 320502 ms - lookup took 0 ms
SEC Feb 21, 2003 7:15:41 PM (freenet.node.Main, main, DEBUG): Address:
22.22.22.22 at 322623 ms - lookup took 0 ms

The address never changes, even when the DNS is changed (and verified
with the host command).

The only reasonable conclusion seems to be that Java's DNS handling is
completely fucked and does not work with dyndns nodes. The docs say that
changing the security property that we change should work in 1.4. It
doesn't. This is presumably a bug. Furthermore, the 1.3.1 JDK does not
provide these methods but appears to cache positive DNS lookups forever.

There is a serious compatibility problem between java and dynamic DNS.

Possible solutions:

* Get Sun to fix it in 1.4, wait for 1.4.1r03 or 1.4.2 or whatever to be
  available for all supported platforms, detect previous JVMs and
  grumble loudly on startup if one is detected. As I said, this not only
  does not work even with the documented workaround with 1.4.1r02, it
  also seems experimentally that 1.3.1 caches successful DNS lookups
  indefinitely.
* Provide a way for nodes behind a firewall to detect their IP address,
  and deprecate use of DNS in freenet.
* Use an external, platform-specific helper to lookup DNS.
* Include our own DNS resolver - see http://www.buzzsurf.com/java/dns/
  (note that these are designed primarily for performance so we may need
  to hack their caching code...)
* Rewrite in C :)

--
Matthew Toseland
[EMAIL PROTECTED]/[EMAIL PROTECTED]
Full time freenet hacker.
http://freenetproject.org/
Freenet Distribution Node (temporary) at http://80.192.4.23:8889/SPmjEh6sH3Y/
ICTHUS.

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to