From 01ba7540b1d0d80f391411b806799bf0ec2da3b7 Mon Sep 17 00:00:00 2001 From: emcho Date: Sun, 28 Feb 2010 16:15:14 +0000 Subject: [PATCH] Prevents us from attempting to reach Global IPv6 addresses from link local ones. The assumption is not always valid (which is why the behaviour is configurable), but it probably would be in 99% of the cases and for those cases it allows us to drop candidate gathering for the Ice sample test from 4 seconds to 396 ms. --- src/org/ice4j/TransportAddress.java | 40 +++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/org/ice4j/TransportAddress.java b/src/org/ice4j/TransportAddress.java index 4d8f1ef..e1f626b 100644 --- a/src/org/ice4j/TransportAddress.java +++ b/src/org/ice4j/TransportAddress.java @@ -24,6 +24,13 @@ public class TransportAddress */ private static final long serialVersionUID = 5076001401234631237L; + /** + * A property that allows us to specify whether we would expect link local + * IPv6 addresses to be able to reach globally routable ones. + */ + public static final String PNAME_ALLOW_LINK_TO_GLOBAL_REACHABILITY + = "org.ice4j.ALLOW_LINK_TO_GLOBAL_REACHABILITY"; + /** * The variable that we are using to store the transport that this address * is pertaining to. @@ -232,7 +239,36 @@ public class TransportAddress */ public boolean canReach(TransportAddress dst) { - return (getTransport() == dst.getTransport()) - && (isIPv6() == dst.isIPv6()); + if( getTransport() != dst.getTransport() ) + return false; + + if (isIPv6() != dst.isIPv6()) + return false; + + if (isIPv6()) + { + Inet6Address srcAddr = (Inet6Address)getAddress(); + Inet6Address dstAddr = (Inet6Address)dst.getAddress(); + + if(srcAddr.isLinkLocalAddress() != dstAddr.isLinkLocalAddress()) + { + //this one may actually work if for example we are contacting + //the public address of someone in our local network. however + //in most cases we would also be able to reach the same address + //via a global address of our own and the probability of the + //opposite is considerably lower than the probability of us + //trying to reach a distant global address through one of our + //own. Therefore we would return false here by default. + + if(Boolean.getBoolean(PNAME_ALLOW_LINK_TO_GLOBAL_REACHABILITY)) + return true; + else + return false; + } + } + + //may add more unreachability condition here in the future; + + return true; } }