Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always include the IPAddressHint in the noderef WIP #859

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent :)

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