* Console:

- Fix status to show a disconnected network error rather than
        clock skew or UDP error when disconnected
      - Use peer clock skew rather than clock offset for determining
        whether to display clock skew error, i.e. display what matters
    * Transport: Rework peer clock skew method to always return a value
      by falling back to router clock offset;
      Fix possible AIOOBE and divide by zero; remove logging;
      reduce min number of peers
This commit is contained in:
zzz
2009-12-19 16:47:18 +00:00
parent aaa7302e80
commit 8e656427d8
2 changed files with 24 additions and 21 deletions

View File

@ -77,31 +77,26 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
public boolean haveHighOutboundCapacity() { return (_manager == null ? false : _manager.haveHighOutboundCapacity()); }
/**
* Framed average clock skew of connected peers in seconds, or null if we cannot answer.
* Framed average clock skew of connected peers in seconds, or the clock offset if we cannot answer.
* Average is calculated over the middle "percentToInclude" peers.
*/
@Override
public Long getFramedAveragePeerClockSkew(int percentToInclude) {
if (_manager == null) {
if (_log.shouldLog(Log.INFO))
_log.info("Returning null for framed averege peer clock skew (no transport manager)!");
return null;
// round toward zero
return Long.valueOf(_context.clock().getOffset() / 1000);
}
Vector skews = _manager.getClockSkews();
if (skews == null) {
if (_log.shouldLog(Log.ERROR))
_log.error("Returning null for framed average peer clock skew (no data)!");
return null;
return Long.valueOf(_context.clock().getOffset() / 1000);
}
if (skews.size() < 20) {
if (_log.shouldLog(Log.WARN))
_log.warn("Returning null for framed average peer clock skew (only " + skews.size() + " peers)!");
return null;
if (skews.size() < 5) {
return Long.valueOf(_context.clock().getOffset() / 1000);
}
// Going to calculate, sort them
Collections.sort(skews);
// Calculate frame size
int frameSize = (skews.size() * percentToInclude / 100);
int frameSize = Math.min((skews.size() * percentToInclude / 100), 2);
int first = (skews.size() / 2) - (frameSize / 2);
int last = (skews.size() / 2) + (frameSize / 2);
// Sum skew values
@ -112,11 +107,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
_log.debug("Adding clock skew " + i + " valued " + value + " s.");
sum = sum + value;
}
// Calculate average
Long framedAverageClockSkew = new Long(sum / frameSize);
if (_log.shouldLog(Log.INFO))
_log.info("Our framed average peer clock skew is " + framedAverageClockSkew + " s.");
return framedAverageClockSkew;
// Calculate average (round toward zero)
return Long.valueOf(sum / frameSize);
}
public List getBids(OutNetMessage msg) {