Author: toad
Date: 2007-03-10 23:25:17 +0000 (Sat, 10 Mar 2007)
New Revision: 12093
Modified:
trunk/plugins/JSTUN/JSTUN.java
Log:
Keep detecting until have 2 likely outcomes or 2 unlikely + 1 likely or 4
unlikely
Modified: trunk/plugins/JSTUN/JSTUN.java
===================================================================
--- trunk/plugins/JSTUN/JSTUN.java 2007-03-10 23:14:44 UTC (rev 12092)
+++ trunk/plugins/JSTUN/JSTUN.java 2007-03-10 23:25:17 UTC (rev 12093)
@@ -34,9 +34,11 @@
"stun.xten.com"
};
- DetectedIP runTest(InetAddress iaddress) {
+ DetectedIP[] runTest(InetAddress iaddress) {
Random r = new Random(); // FIXME use something safer?
Vector v = new Vector(publicSTUNServers.length);
+ Vector out = new Vector();
+ int count = 0;
for(int i=0;i<publicSTUNServers.length;i++)
v.add(publicSTUNServers[i]);
while(!v.isEmpty()) {
@@ -53,7 +55,13 @@
}
System.out.println("Successful STUN discovery
from "+stunServer+"!:");
System.out.println(info);
- return convert(info);
+ DetectedIP ip = convert(info);
+ out.add(ip);
+ if(ip.natType == ip.NO_UDP || ip.natType ==
ip.NOT_SUPPORTED || ip.natType == ip.SYMMETRIC_NAT || ip.natType ==
ip.SYMMETRIC_NAT || ip.natType == ip.SYMMETRIC_UDP_FIREWALL)
+ count++; // unlikely outcomes
+ else
+ count += 2;
+ if(count >= 4 || v.isEmpty()) return
(DetectedIP[])out.toArray(new DetectedIP[out.size()]);
} catch (BindException be) {
System.err.println(iaddress.toString() + ": " +
be.getMessage());
} catch (UnknownHostException e) {
@@ -151,10 +159,11 @@
final InetAddress startAddress;
public void run() {
- DetectedIP ip;
+ DetectedIP[] ip;
try {
ip = runTest(startAddress);
- ip.mtu =
NetworkInterface.getByInetAddress(startAddress).getMTU();
+ int mtu =
NetworkInterface.getByInetAddress(startAddress).getMTU();
+ for(int i=0;i<ip.length;i++) ip[i].mtu = mtu;
} catch (Throwable t) {
ip = null;
System.err.println("Caught "+t);