mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-05 17:27:52 +00:00
Correct poor synchronization on NTP offset, potentially fixing issue #22
This commit is contained in:
parent
84dba739d9
commit
3e19516f62
@ -28,7 +28,8 @@ public class NTP implements Runnable {
|
|||||||
private static volatile boolean isStopping = false;
|
private static volatile boolean isStopping = false;
|
||||||
private static ExecutorService instanceExecutor;
|
private static ExecutorService instanceExecutor;
|
||||||
private static NTP instance;
|
private static NTP instance;
|
||||||
private static volatile Long offset = null;
|
private static volatile boolean isOffsetSet = false;
|
||||||
|
private static volatile long offset = 0;
|
||||||
|
|
||||||
static class NTPServer {
|
static class NTPServer {
|
||||||
private static final int MIN_POLL = 64;
|
private static final int MIN_POLL = 64;
|
||||||
@ -136,6 +137,7 @@ public class NTP implements Runnable {
|
|||||||
public static synchronized void setFixedOffset(Long offset) {
|
public static synchronized void setFixedOffset(Long offset) {
|
||||||
// Fix offset, e.g. for testing
|
// Fix offset, e.g. for testing
|
||||||
NTP.offset = offset;
|
NTP.offset = offset;
|
||||||
|
isOffsetSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +146,7 @@ public class NTP implements Runnable {
|
|||||||
* @return internet time (ms), or null if unsynchronized.
|
* @return internet time (ms), or null if unsynchronized.
|
||||||
*/
|
*/
|
||||||
public static Long getTime() {
|
public static Long getTime() {
|
||||||
if (NTP.offset == null)
|
if (!isOffsetSet)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return System.currentTimeMillis() + NTP.offset;
|
return System.currentTimeMillis() + NTP.offset;
|
||||||
@ -248,6 +250,7 @@ public class NTP implements Runnable {
|
|||||||
thresholdStddev, filteredMean, filteredStddev, numberValues, ntpServers.size()));
|
thresholdStddev, filteredMean, filteredStddev, numberValues, ntpServers.size()));
|
||||||
|
|
||||||
NTP.offset = (long) filteredMean;
|
NTP.offset = (long) filteredMean;
|
||||||
|
isOffsetSet = true;
|
||||||
LOGGER.debug(() -> String.format("New NTP offset: %d", NTP.offset));
|
LOGGER.debug(() -> String.format("New NTP offset: %d", NTP.offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user