From 971ea1accf6b699643b87662099baf62292704d4 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Sat, 9 Sep 2023 16:28:29 +0200 Subject: [PATCH] Always include the IPAddressHint in the noderef --- src/freenet/node/NodeIPDetector.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/freenet/node/NodeIPDetector.java b/src/freenet/node/NodeIPDetector.java index 6af35d128eb..1aefce37d7b 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; } }