assert(detectedAddrs != null);
synchronized(this) {
hasDetectedIAD = true;
}
for(InetAddress detectedAddr: detectedAddrs) {
FreenetInetAddress addr = new FreenetInetAddress(detectedAddr);
if(!addresses.contains(addr)) {
Logger.normal(this, "Detected IP address: "+addr);
addresses.add(addr);
if(addr.isRealInternetAddress(false, false, false))
addedValidIP = true;
}
}
if((pluginDetectedIPs != null) && (pluginDetectedIPs.length > 0)) {
for(DetectedIP pluginDetectedIP: pluginDetectedIPs) {
InetAddress addr = pluginDetectedIP.publicAddress;
if(addr == null) continue;
FreenetInetAddress a = new FreenetInetAddress(addr);
if(!addresses.contains(a)) {
Logger.normal(this, "Plugin detected IP address: "+a);
addresses.add(a);
if(a.isRealInternetAddress(false, false, false))
addedValidIP = true;
}
}
}
boolean hadAddedValidIP = addedValidIP;
int confidence = 0;
// Try to pick it up from our connections
if(node.peers != null) {
PeerNode[] peerList = node.peers.myPeers();
HashMap<FreenetInetAddress,Integer> countsByPeer = new HashMap<FreenetInetAddress,Integer>();
// FIXME use a standard mutable int object, we have one somewhere
for(PeerNode pn: peerList) {
if(!pn.isConnected()) {
if(logDEBUG) Logger.minor(this, "Not connected");
continue;
}
if(!pn.isRealConnection()) {
// Only let seed server connections through.
// We have to trust them anyway.
if(!(pn instanceof SeedServerPeerNode)) continue;
if(logMINOR) Logger.minor(this, "Not a real connection and not a seed node: "+pn);
}
if(logMINOR) Logger.minor(this, "Maybe a usable connection for IP: "+pn);
Peer p = pn.getRemoteDetectedPeer();
if(logMINOR) Logger.minor(this, "Remote detected peer: "+p);
if(p == null || p.isNull()) continue;
FreenetInetAddress addr = p.getFreenetAddress();
if(logMINOR) Logger.minor(this, "Address: "+addr);
if(addr == null) continue;
if(!IPUtil.isValidAddress(addr.getAddress(false), false)) {
if(logMINOR) Logger.minor(this, "Address not valid");
continue;
}
if(logMINOR)
Logger.minor(this, "Peer "+pn.getPeer()+" thinks we are "+addr);
if(countsByPeer.containsKey(addr)) {
countsByPeer.put(addr, countsByPeer.get(addr) + 1);
} else {
countsByPeer.put(addr, 1);
}
}
if(countsByPeer.size() == 1) {
Entry<FreenetInetAddress, Integer> countByPeer = countsByPeer.entrySet().iterator().next();
FreenetInetAddress addr = countByPeer.getKey();
confidence = countByPeer.getValue();
Logger.minor(this, "Everyone agrees we are "+addr);
if(!addresses.contains(addr)) {
if(addr.isRealInternetAddress(false, false, false))
addedValidIP = true;
addresses.add(addr);
}
} else if(countsByPeer.size() > 1) {
// Take two most popular addresses.
FreenetInetAddress best = null;
FreenetInetAddress secondBest = null;
int bestPopularity = 0;
int secondBestPopularity = 0;
for(Map.Entry<FreenetInetAddress,Integer> entry : countsByPeer.entrySet()) {
FreenetInetAddress cur = entry.getKey();
int curPop = entry.getValue();
Logger.minor(this, "Detected peer: "+cur+" popularity "+curPop);
if(curPop >= bestPopularity) {
secondBestPopularity = bestPopularity;
bestPopularity = curPop;