forked from I2P_Developers/i2p.i2p
NTP: Enable IPv6 support (ticket #1896)
This commit is contained in:
@ -58,6 +58,19 @@ public abstract class Addresses {
|
||||
return !getAddresses(true, false, false).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we have any non-loop, non-wildcard IPv6 address at all?
|
||||
* @since 0.9.29
|
||||
*/
|
||||
public static boolean isConnectedIPv6() {
|
||||
// not as good as using a Java DBus implementation to talk to NetworkManager...
|
||||
for (String ip : getAddresses(false, true)) {
|
||||
if (ip.contains(":"))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @return the first non-local address IPv4 address it finds, or null */
|
||||
public static String getAnyAddress() {
|
||||
SortedSet<String> a = getAddresses();
|
||||
@ -599,6 +612,7 @@ public abstract class Addresses {
|
||||
} catch (UnknownHostException uhe) {}
|
||||
System.out.println(buf.toString());
|
||||
}
|
||||
System.out.println("\nIs connected? " + isConnected());
|
||||
System.out.println("\nIs connected? " + isConnected() +
|
||||
"\nHas IPv6? " + isConnectedIPv6());
|
||||
}
|
||||
}
|
||||
|
20
history.txt
20
history.txt
@ -1,3 +1,19 @@
|
||||
2017-02-04 zzz
|
||||
* NTP: Enable IPv6 support (ticket #1896)
|
||||
|
||||
2017-01-30 zzz
|
||||
* Router: Run shutdown tasks in parallel,
|
||||
increase max time for shutdown tasks (ticket #1893)
|
||||
i2psnark: Remove most delay between announces at shutdown
|
||||
|
||||
2017-01-29 zzz
|
||||
* i2ptunnel CONNECT proxy:
|
||||
- Add support for outproxy plugin (tickets #1364, #1895)
|
||||
- Add support for ports
|
||||
|
||||
2017-01-28 zzz
|
||||
* Utils: Detect when running as service on Gentoo
|
||||
|
||||
2017-01-26 zzz
|
||||
* Build: Set up translations for man pages
|
||||
* Javadoc: Fixes (ticket #1894)
|
||||
@ -41,8 +57,8 @@
|
||||
* NTP:
|
||||
- Verify source address and port
|
||||
- Add to command line
|
||||
- Add KoD support (ticket #1896)
|
||||
- Add initial IPv6 support (ticket #1897)
|
||||
- Add KoD support (ticket #1897)
|
||||
- Add initial IPv6 support (ticket #1896)
|
||||
|
||||
2016-12-20 zzz
|
||||
* Build: Fix installer compile failure
|
||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 4;
|
||||
public final static long BUILD = 5;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.time.Timestamper;
|
||||
import net.i2p.util.Addresses;
|
||||
import net.i2p.util.I2PThread;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
@ -173,6 +174,7 @@ public class RouterTimestamper extends Timestamper {
|
||||
while (_isRunning) {
|
||||
// NOTE: _log is null the first time through, to prevent problems and stack overflows
|
||||
updateConfig();
|
||||
boolean preferIPv6 = Addresses.isConnectedIPv6();
|
||||
if (!_disabled) {
|
||||
// first the servers for our country and continent, we know what country we're in...
|
||||
if (_priorityServers != null) {
|
||||
@ -180,7 +182,7 @@ public class RouterTimestamper extends Timestamper {
|
||||
if (_log != null && _log.shouldDebug())
|
||||
_log.debug("Querying servers " + servers);
|
||||
try {
|
||||
lastFailed = !queryTime(servers.toArray(new String[servers.size()]), SHORT_TIMEOUT);
|
||||
lastFailed = !queryTime(servers.toArray(new String[servers.size()]), SHORT_TIMEOUT, preferIPv6);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
if (!lastFailed && _log != null && _log.shouldWarn())
|
||||
_log.warn("Unable to reach any regional NTP servers: " + servers);
|
||||
@ -195,7 +197,10 @@ public class RouterTimestamper extends Timestamper {
|
||||
if (_log != null && _log.shouldDebug())
|
||||
_log.debug("Querying servers " + _servers);
|
||||
try {
|
||||
lastFailed = !queryTime(_servers.toArray(new String[_servers.size()]), DEFAULT_TIMEOUT);
|
||||
// If we failed, maybe it's because IPv6 is blocked, so try IPv4 only
|
||||
// also first time through, and randomly
|
||||
boolean prefIPv6 = preferIPv6 && !lastFailed && _log != null && _context.random().nextInt(4) != 0;
|
||||
lastFailed = !queryTime(_servers.toArray(new String[_servers.size()]), DEFAULT_TIMEOUT, prefIPv6);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
lastFailed = true;
|
||||
}
|
||||
@ -262,7 +267,7 @@ public class RouterTimestamper extends Timestamper {
|
||||
/**
|
||||
* True if the time was queried successfully, false if it couldn't be
|
||||
*/
|
||||
private boolean queryTime(String serverList[], int perServerTimeout) throws IllegalArgumentException {
|
||||
private boolean queryTime(String serverList[], int perServerTimeout, boolean preferIPv6) throws IllegalArgumentException {
|
||||
long found[] = new long[_concurringServers];
|
||||
long now = -1;
|
||||
int stratum = -1;
|
||||
@ -273,8 +278,7 @@ public class RouterTimestamper extends Timestamper {
|
||||
// // this delays startup when net is disconnected or the timeserver list is bad, don't make it too long
|
||||
// try { Thread.sleep(2*1000); } catch (InterruptedException ie) {}
|
||||
//}
|
||||
// IPv6 arg TODO
|
||||
long[] timeAndStratum = NtpClient.currentTimeAndStratum(serverList, perServerTimeout, false, _log);
|
||||
long[] timeAndStratum = NtpClient.currentTimeAndStratum(serverList, perServerTimeout, preferIPv6, _log);
|
||||
now = timeAndStratum[0];
|
||||
stratum = (int) timeAndStratum[1];
|
||||
long delta = now - _context.clock().now();
|
||||
|
Reference in New Issue
Block a user