public int registerConfigs(SubConfig nodeConfig, int sortOrder) {
// IP address override
nodeConfig.register("ipAddressOverride", "", sortOrder++, true, false, "NodeIPDectector.ipOverride",
"NodeIPDectector.ipOverrideLong",
new StringCallback() {
@Override
public String get() {
if(overrideIPAddressString == null) return "";
else return overrideIPAddressString;
}
@Override
public void set(String val) throws InvalidConfigValueException {
boolean hadValidAddressOverride = hasValidAddressOverride();
// FIXME do we need to tell anyone?
if(val.length() == 0) {
// Set to null
overrideIPAddressString = val;
overrideIPAddress = null;
lastIPAddress = null;
redetectAddress();
return;
}
FreenetInetAddress addr;
try {
addr = new FreenetInetAddress(val, false, true);
} catch (HostnameSyntaxException e) {
throw new InvalidConfigValueException(l10n("unknownHostErrorInIPOverride", "error", "hostname or IP address syntax error"));
} catch (UnknownHostException e) {
throw new InvalidConfigValueException(l10n("unknownHostErrorInIPOverride", "error", e.getMessage()));
}
// Compare as IPs.
if(addr.equals(overrideIPAddress)) return;
overrideIPAddressString = val;
overrideIPAddress = addr;
lastIPAddress = null;
synchronized(this) {
hasValidAddressOverride = true;
}
if(!hadValidAddressOverride) {
onGetValidAddressOverride();
}
redetectAddress();
}
});
hasValidAddressOverride = true;
overrideIPAddressString = nodeConfig.getString("ipAddressOverride");
if(overrideIPAddressString.length() == 0)
overrideIPAddress = null;
else {
try {
overrideIPAddress = new FreenetInetAddress(overrideIPAddressString, false, true);
} catch (HostnameSyntaxException e) {
synchronized(this) {
hasValidAddressOverride = false;
}
String msg = "Invalid IP override syntax: "+overrideIPAddressString+" in config: "+e.getMessage();
Logger.error(this, msg);
System.err.println(msg+" but starting up anyway, ignoring the configured IP override");
overrideIPAddress = null;
} catch (UnknownHostException e) {
// **FIXME** This never happens for this reason with current FreenetInetAddress(String, boolean, boolean) code; perhaps it needs review?
String msg = "Unknown host: "+overrideIPAddressString+" in config: "+e.getMessage();
Logger.error(this, msg);
System.err.println(msg+" but starting up anyway with no IP override");
overrideIPAddress = null;
}
}
// Temporary IP address hint
nodeConfig.register("tempIPAddressHint", "", sortOrder++, true, false, "NodeIPDectector.tempAddressHint", "NodeIPDectector.tempAddressHintLong", new StringCallback() {
@Override
public String get() {
return "";
}