Commit 06400d84 authored by afreyssin's avatar afreyssin

Adds verification of the clock synchronization between the client and the server.

A bad clock synchronization can cause issues when using messages TTL or receive with timeout.
parent b358331b
......@@ -84,31 +84,27 @@ public class ReliableTcpClient {
private Timer timer;
/**
* Name of the boolean property allowing the verification of the synchronization
* between the client and server clock. When true a warning is generated if there
* is more than one second between the two clocks. This property allows the protocol
* compatibility in 5.2 versions, this verification will be enabled by default in 5.3
* version.
* Name of the property allowing to change the threshold of warning for the
* verification of the synchronization between the client and server clock.
* A warning is generated if there is more than this value in milliseconds
* between the two clocks.
* <p>
* This property can be fixed either from <code>java</code> launching command, or
* in <code>a3servers.xml</code> configuration file. By default the value is false.
* By default the value is 1000 milliseconds.
*/
public static final String VERIFY_CLOCK_SYNCHRO = "org.objectweb.joram.TcpConnection.verifyClockSynchro";
public static final String CLOCK_SYNCHRO_THRESHOLD = "org.objectweb.joram.TcpConnection.ClockSynchro.Threshold";
/**
* Boolean value allowing the verification of the synchronization between the
* client and server clock. When true a warning is generated if there is more
* than one second between the two clocks. This property allows the protocol
* compatibility in 5.2 versions, this verification will be enabled by default
* in 5.3 version.
* Value of the threshold of warning for the verification of the synchronization
* between the client and server clock.
* A warning is generated if there is more than this value in milliseconds between
* the two clocks.
* <p>
* This property can be fixed either from <code>java</code> launching command, or
* in <code>a3servers.xml</code> configuration file. By default the value is false.
* By default the value is 1000 milliseconds.
*/
private final boolean verifyClockSynchro;
private long clockSynchroThreshold = 1000L;
public ReliableTcpClient() {
this.verifyClockSynchro = Configuration.getBoolean("VERIFY_CLOCK_SYNCHRO");
this.clockSynchroThreshold = Configuration.getLong(CLOCK_SYNCHRO_THRESHOLD, clockSynchroThreshold).longValue();
}
public void setTimer(Timer timer2) {
......@@ -280,10 +276,8 @@ public class ReliableTcpClient {
// Writes the Joram magic number
baos.write(MetaData.joramMagic);
if (verifyClockSynchro) {
// Writes the current date
StreamUtil.writeTo(System.currentTimeMillis(), baos);
}
// Writes the current date
StreamUtil.writeTo(System.currentTimeMillis(), baos);
// Writes the user identity
if (logger.isLoggable(BasicLevel.DEBUG))
......@@ -302,12 +296,10 @@ public class ReliableTcpClient {
os.flush();
int len = StreamUtil.readIntFrom(is);
if (verifyClockSynchro) {
long dt = StreamUtil.readLongFrom(is);
if (dt > 1000)
logger.log(BasicLevel.WARN, " -> clock synchronization between client and server: " + dt);
}
long dt = StreamUtil.readLongFrom(is);
if (dt > clockSynchroThreshold)
logger.log(BasicLevel.WARN, " -> bad clock synchronization between client and server: " + dt);
int res = StreamUtil.readIntFrom(is);
if (res > 0) {
String info = StreamUtil.readStringFrom(is);
......
......@@ -66,29 +66,24 @@ public class TcpConnectionListener extends Daemon {
private int timeout;
/**
* Name of the boolean property allowing the verification of the synchronization
* between the client and server clock. When true a warning is generated if there
* is more than one second between the two clocks. This property allows the protocol
* compatibility in 5.2 versions, this verification will be enabled by default in 5.3
* version.
* Name of the property allowing to change the threshold of warning for the
* verification of the synchronization between the client and server clock.
* A warning is generated if there is more than this value in milliseconds
* between the two clocks.
* <p>
* This property can be fixed either from <code>java</code> launching command, or
* in <code>a3servers.xml</code> configuration file. By default the value is false.
* By default the value is 1000 milliseconds.
*/
public static final String VERIFY_CLOCK_SYNCHRO =
"org.objectweb.joram.TcpConnection.verifyClockSynchro";
public static final String CLOCK_SYNCHRO_THRESHOLD = "org.objectweb.joram.TcpConnection.ClockSynchro.Threshold";
/**
* Boolean value allowing the verification of the synchronization between the
* client and server clock. When true a warning is generated if there is more
* than one second between the two clocks. This property allows the protocol
* compatibility in 5.2 versions, this verification will be enabled by default
* in 5.3 version.
* Value of the threshold of warning for the verification of the synchronization
* between the client and server clock.
* A warning is generated if there is more than this value in milliseconds between
* the two clocks.
* <p>
* This property can be fixed either from <code>java</code> launching command, or
* in <code>a3servers.xml</code> configuration file. By default the value is false.
* By default the value is 1000 milliseconds.
*/
private final boolean verifyClockSynchro;
private long clockSynchroThreshold = 1000L;
/**
* Number of times this connection listener has encountered an erroneous
......@@ -117,7 +112,7 @@ public class TcpConnectionListener extends Daemon {
super("TcpConnectionListener");
this.proxyService = proxyService;
this.timeout = timeout;
this.verifyClockSynchro = Configuration.getBoolean(VERIFY_CLOCK_SYNCHRO);
this.clockSynchroThreshold = Configuration.getLong(CLOCK_SYNCHRO_THRESHOLD, clockSynchroThreshold).longValue();
}
public void run() {
......@@ -214,14 +209,12 @@ public class TcpConnectionListener extends Daemon {
logger.log(BasicLevel.WARN,
"Wildcard protocol version number: from stream = " + magic[7] + ", from MetaData = " + MetaData.joramMagic[7]);
}
if (verifyClockSynchro) {
long dt = Math.abs(StreamUtil.readLongFrom(is) - System.currentTimeMillis());
if (dt > 1000)
logger.log(BasicLevel.WARN, " -> clock synchronization between client and server: " + dt);
StreamUtil.writeTo(dt, nos);
}
long dt = Math.abs(StreamUtil.readLongFrom(is) - System.currentTimeMillis());
if (dt > clockSynchroThreshold)
logger.log(BasicLevel.WARN, " -> bad clock synchronization between client and server: " + dt);
StreamUtil.writeTo(dt, nos);
Identity identity = Identity.read(is);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, " -> read identity = " + identity);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment