diff --git a/src/freenet/node/NodeIPDetector.java b/src/freenet/node/NodeIPDetector.java index 6af35d128e..1aefce37d7 100644 --- a/src/freenet/node/NodeIPDetector.java +++ b/src/freenet/node/NodeIPDetector.java @@ -62,6 +62,8 @@ public void shouldUpdate(){ String overrideIPAddressString; /** IP address from last time */ FreenetInetAddress oldIPAddress; + /** Whether the oldIPAddress comes from an address hint */ + boolean hasIPAddressHint = false; /** Detected IP's and their NAT status from plugins */ DetectedIP[] pluginDetectedIPs; /** Last detected IP address */ @@ -341,7 +343,11 @@ private boolean innerDetect(List addresses) { } // Add the old address only if we have no choice, or if we only have the word of two peers to go on. - if((!(hadAddedValidIP || confidence > 2)) && (oldIPAddress != null) && !oldIPAddress.equals(overrideIPAddress)) { + // except if it is the ip address hint + if((!hadAddedValidIP || confidence <= 2 || hasIPAddressHint) + && oldIPAddress != null + && !oldIPAddress.equals(overrideIPAddress) + && !addresses.contains(oldIPAddress)) { addresses.add(oldIPAddress); // Don't set addedValidIP. // There is an excellent chance that this is out of date. @@ -508,7 +514,9 @@ public void set(String val) throws InvalidConfigValueException { if(overrideIPAddress != null) return; try { oldIPAddress = new FreenetInetAddress(val, false); + hasIPAddressHint = true; } catch (UnknownHostException e) { + hasIPAddressHint = false; throw new InvalidConfigValueException("Unknown host: "+e.getMessage()); } redetectAddress(); @@ -519,11 +527,13 @@ public void set(String val) throws InvalidConfigValueException { if(ipHintString.length() > 0) { try { oldIPAddress = new FreenetInetAddress(ipHintString, false); + hasIPAddressHint = true; } catch (UnknownHostException e) { String msg = "Unknown host: "+ipHintString+" in config: "+e.getMessage(); Logger.error(this, msg); System.err.println(msg); oldIPAddress = null; + hasIPAddressHint = false; } }