forked from I2P_Developers/i2p.i2p
* 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:
@ -62,6 +62,9 @@ public class SummaryHelper extends HelperBase {
|
|||||||
return DataHelper.formatDuration(router.getUptime());
|
return DataHelper.formatDuration(router.getUptime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
this displayed offset, not skew - now handled in reachability()
|
||||||
|
|
||||||
private String timeSkew() {
|
private String timeSkew() {
|
||||||
if (_context == null) return "";
|
if (_context == null) return "";
|
||||||
//if (!_context.clock().getUpdatedSuccessfully())
|
//if (!_context.clock().getUpdatedSuccessfully())
|
||||||
@ -72,6 +75,7 @@ public class SummaryHelper extends HelperBase {
|
|||||||
return "";
|
return "";
|
||||||
return " (" + DataHelper.formatDuration(diff) + " " + _("skew") + ")";
|
return " (" + DataHelper.formatDuration(diff) + " " + _("skew") + ")";
|
||||||
}
|
}
|
||||||
|
**/
|
||||||
|
|
||||||
public boolean allowReseed() {
|
public boolean allowReseed() {
|
||||||
return _context.netDb().isInitialized() &&
|
return _context.netDb().isInitialized() &&
|
||||||
@ -83,15 +87,20 @@ public class SummaryHelper extends HelperBase {
|
|||||||
public int getAllPeers() { return Math.max(_context.netDb().getKnownRouters() - 1, 0); }
|
public int getAllPeers() { return Math.max(_context.netDb().getKnownRouters() - 1, 0); }
|
||||||
|
|
||||||
public String getReachability() {
|
public String getReachability() {
|
||||||
return reachability() + timeSkew();
|
return reachability(); // + timeSkew();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String reachability() {
|
private String reachability() {
|
||||||
if (_context.router().getUptime() > 60*1000 && (!_context.router().gracefulShutdownInProgress()) &&
|
if (_context.router().getUptime() > 60*1000 && (!_context.router().gracefulShutdownInProgress()) &&
|
||||||
!_context.clientManager().isAlive())
|
!_context.clientManager().isAlive())
|
||||||
return _("ERR-Client Manager I2CP Error - check logs"); // not a router problem but the user should know
|
return _("ERR-Client Manager I2CP Error - check logs"); // not a router problem but the user should know
|
||||||
if (!_context.clock().getUpdatedSuccessfully())
|
// Warn based on actual skew from peers, not update status, so if we successfully offset
|
||||||
return _("ERR-ClockSkew");
|
// the clock, we don't complain.
|
||||||
|
//if (!_context.clock().getUpdatedSuccessfully())
|
||||||
|
Long skew = _context.commSystem().getFramedAveragePeerClockSkew(33);
|
||||||
|
// Display the actual skew, not the offset
|
||||||
|
if (skew != null && Math.abs(skew.longValue()) > 45)
|
||||||
|
return _("ERR-Clock Skew of {0}", DataHelper.formatDuration(Math.abs(skew.longValue()) * 1000));
|
||||||
if (_context.router().isHidden())
|
if (_context.router().isHidden())
|
||||||
return _("Hidden");
|
return _("Hidden");
|
||||||
|
|
||||||
@ -118,7 +127,9 @@ public class SummaryHelper extends HelperBase {
|
|||||||
default:
|
default:
|
||||||
ra = _context.router().getRouterInfo().getTargetAddress("SSU");
|
ra = _context.router().getRouterInfo().getTargetAddress("SSU");
|
||||||
if (ra == null && _context.router().getUptime() > 5*60*1000) {
|
if (ra == null && _context.router().getUptime() > 5*60*1000) {
|
||||||
if (_context.getProperty(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME) == null ||
|
if (getActivePeers() <= 0)
|
||||||
|
return _("ERR-No Active Peers, Check Network Connection and Firewall");
|
||||||
|
else if (_context.getProperty(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME) == null ||
|
||||||
_context.getProperty(ConfigNetHelper.PROP_I2NP_NTCP_PORT) == null)
|
_context.getProperty(ConfigNetHelper.PROP_I2NP_NTCP_PORT) == null)
|
||||||
return _("ERR-UDP Disabled and Inbound TCP host/port not set");
|
return _("ERR-UDP Disabled and Inbound TCP host/port not set");
|
||||||
else
|
else
|
||||||
|
@ -77,31 +77,26 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
|||||||
public boolean haveHighOutboundCapacity() { return (_manager == null ? false : _manager.haveHighOutboundCapacity()); }
|
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.
|
* Average is calculated over the middle "percentToInclude" peers.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long getFramedAveragePeerClockSkew(int percentToInclude) {
|
public Long getFramedAveragePeerClockSkew(int percentToInclude) {
|
||||||
if (_manager == null) {
|
if (_manager == null) {
|
||||||
if (_log.shouldLog(Log.INFO))
|
// round toward zero
|
||||||
_log.info("Returning null for framed averege peer clock skew (no transport manager)!");
|
return Long.valueOf(_context.clock().getOffset() / 1000);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
Vector skews = _manager.getClockSkews();
|
Vector skews = _manager.getClockSkews();
|
||||||
if (skews == null) {
|
if (skews == null) {
|
||||||
if (_log.shouldLog(Log.ERROR))
|
return Long.valueOf(_context.clock().getOffset() / 1000);
|
||||||
_log.error("Returning null for framed average peer clock skew (no data)!");
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
if (skews.size() < 20) {
|
if (skews.size() < 5) {
|
||||||
if (_log.shouldLog(Log.WARN))
|
return Long.valueOf(_context.clock().getOffset() / 1000);
|
||||||
_log.warn("Returning null for framed average peer clock skew (only " + skews.size() + " peers)!");
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
// Going to calculate, sort them
|
// Going to calculate, sort them
|
||||||
Collections.sort(skews);
|
Collections.sort(skews);
|
||||||
// Calculate frame size
|
// 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 first = (skews.size() / 2) - (frameSize / 2);
|
||||||
int last = (skews.size() / 2) + (frameSize / 2);
|
int last = (skews.size() / 2) + (frameSize / 2);
|
||||||
// Sum skew values
|
// Sum skew values
|
||||||
@ -112,11 +107,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
|||||||
_log.debug("Adding clock skew " + i + " valued " + value + " s.");
|
_log.debug("Adding clock skew " + i + " valued " + value + " s.");
|
||||||
sum = sum + value;
|
sum = sum + value;
|
||||||
}
|
}
|
||||||
// Calculate average
|
// Calculate average (round toward zero)
|
||||||
Long framedAverageClockSkew = new Long(sum / frameSize);
|
return Long.valueOf(sum / frameSize);
|
||||||
if (_log.shouldLog(Log.INFO))
|
|
||||||
_log.info("Our framed average peer clock skew is " + framedAverageClockSkew + " s.");
|
|
||||||
return framedAverageClockSkew;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getBids(OutNetMessage msg) {
|
public List getBids(OutNetMessage msg) {
|
||||||
|
Reference in New Issue
Block a user