Skip to content

Commit

Permalink
Always include the IPAddressHint in the noderef
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Sep 9, 2023
1 parent 5bda2ac commit 3b52c1e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/freenet/node/NodeIPDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -341,7 +343,11 @@ private boolean innerDetect(List<FreenetInetAddress> 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.
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 3b52c1e

Please sign in to comment.