* in the multirouter (sim), give each router a randomly distributed clock skew (within the acceptable period)

* in the multirouter (sim), disable the timestamper (so the clock skew 'sticks')
* logging
This commit is contained in:
jrandom
2004-08-30 22:28:15 +00:00
committed by zzz
parent 8690d4d7a9
commit 8c4c72c8b5
6 changed files with 27 additions and 7 deletions

View File

@ -51,9 +51,12 @@ public class MultiRouter {
return;
}
_defaultContext = new I2PAppContext(getEnv(args[0]));
_log = _defaultContext.logManager().getLog(MultiRouter.class);
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
_defaultContext.clock().setOffset(0);
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
Thread.currentThread().setName("Router* Shutdown");
@ -71,8 +74,13 @@ public class MultiRouter {
}
for (int i = 0; i < _routers.size(); i++) {
((Router)_routers.get(i)).runRouter();
_log.info("Router " + i + " started");
Router r = (Router)_routers.get(i);
long offset = r.getContext().random().nextLong(Router.CLOCK_FUDGE_FACTOR/2);
if (r.getContext().random().nextBoolean())
offset = 0 - offset;
r.getContext().clock().setOffset(offset, true);
r.runRouter();
_log.info("Router " + i + " started with clock offset " + offset);
try { Thread.sleep(2*1000 + new java.util.Random().nextInt(2)*1000); } catch (InterruptedException ie) {}
}
_log.info("All " + _routers.size() + " routers started up");
@ -83,6 +91,7 @@ public class MultiRouter {
Properties props = new Properties();
try {
props.load(new FileInputStream(filename));
props.setProperty("time.disabled", "true");
return props;
} catch (IOException ioe) {
ioe.printStackTrace();

View File

@ -152,6 +152,8 @@ public class Router {
/** wall clock uptime */
public long getUptime() { return _context.clock().now() - _context.clock().getOffset() - _started; }
public RouterContext getContext() { return _context; }
void runRouter() {
_isAlive = true;
_started = _context.clock().now();

View File

@ -187,7 +187,7 @@ public class ClientManager {
public void requestLeaseSet(Destination dest, LeaseSet set, long timeout, Job onCreateJob, Job onFailedJob) {
ClientConnectionRunner runner = getRunner(dest);
if (runner == null) {
if (_log.shouldLog(Log.WARN))
if (_log.shouldLog(Log.ERROR))
_log.warn("Cannot request the lease set, as we can't find a client runner for "
+ dest.calculateHash().toBase64() + ". disconnected?");
_context.jobQueue().addJob(onFailedJob);

View File

@ -462,7 +462,12 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
public void publish(LeaseSet localLeaseSet) {
if (!_initialized) return;
Hash h = localLeaseSet.getDestination().calculateHash();
try {
store(h, localLeaseSet);
} catch (IllegalArgumentException iae) {
_log.error("wtf, locally published leaseSet is not valid?", iae);
return;
}
synchronized (_explicitSendKeys) {
_explicitSendKeys.add(h);
}

View File

@ -117,7 +117,10 @@ class RestrictiveTCPConnection extends TCPConnection {
long diff = now.getTime() - theirNow.getTime();
if ( (diff > Router.CLOCK_FUDGE_FACTOR) || (diff < (0-Router.CLOCK_FUDGE_FACTOR)) ) {
if (_log.shouldLog(Log.ERROR))
_log.error("Peer is out of time sync! They think it is " + theirNow + ": " + _remoteIdentity.getHash(), new Exception("Time sync error - please make sure your clock is correct!"));
_log.error("Peer is out of time sync by " + DataHelper.formatDuration(diff)
+ "! They think it is " + theirNow + ", we think it is "
+ new Date(_context.clock().now()) + ": " + _remoteIdentity.getHash(),
new Exception("Time sync error - please make sure your clock is correct!"));
return false;
} else {
if (_log.shouldLog(Log.DEBUG))

View File

@ -216,7 +216,8 @@ class ClientLeaseSetManagerJob extends JobImpl {
_lastCreated = ctx.clock().now();
_currentLeaseSet = ls;
} else {
_log.error("New lease set created, but not found locally? wtf?!");
_log.error("New lease set created, but not found locally? wtf?! client="
+ _pool.getDestination().calculateHash().toBase64());
}
}
}