propagate from branch 'i2p.i2p.zzz.test' (head ff7193c72f9811a641627eb08d5183b3f7af9306)

to branch 'i2p.i2p' (head b71194946fd76128f523e88f918a5c3a9b2c12e1)
This commit is contained in:
zzz
2009-02-01 01:31:24 +00:00
63 changed files with 482 additions and 436 deletions

View File

@ -256,7 +256,7 @@ public class Blocklist {
}
}
private class Entry {
private static class Entry {
String comment;
byte ip1[];
byte ip2[];

View File

@ -43,6 +43,7 @@ import net.i2p.stat.StatManager;
import net.i2p.util.FileUtil;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -257,7 +258,7 @@ public class Router {
_context.inNetMessagePool().startup();
startupQueue();
//_context.jobQueue().addJob(new CoalesceStatsJob(_context));
SimpleTimer.getInstance().addEvent(new CoalesceStatsEvent(_context), 0);
SimpleScheduler.getInstance().addPeriodicEvent(new CoalesceStatsEvent(_context), 20*1000);
_context.jobQueue().addJob(new UpdateRoutingKeyModifierJob(_context));
warmupCrypto();
_sessionKeyPersistenceHelper.startup();
@ -346,7 +347,7 @@ public class Router {
if (blockingRebuild)
r.timeReached();
else
SimpleTimer.getInstance().addEvent(r, 0);
SimpleScheduler.getInstance().addEvent(r, 0);
} catch (DataFormatException dfe) {
_log.log(Log.CRIT, "Internal error - unable to sign our own address?!", dfe);
}
@ -1261,8 +1262,6 @@ class CoalesceStatsEvent implements SimpleTimer.TimedEvent {
getContext().statManager().addRateData("bw.sendBps", (long)KBps, 60*1000);
}
}
SimpleTimer.getInstance().addEvent(this, 20*1000);
}
}

View File

@ -36,7 +36,7 @@ public class Shitlist {
private RouterContext _context;
private Map _entries;
private class Entry {
private static class Entry {
/** when it should expire, per the i2p clock */
long expireOn;
/** why they were shitlisted */

View File

@ -38,6 +38,7 @@ import net.i2p.router.RouterContext;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.RandomSource;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -419,7 +420,7 @@ public class ClientConnectionRunner {
// theirs is newer
} else {
// ours is newer, so wait a few secs and retry
SimpleTimer.getInstance().addEvent(new Rerequest(set, expirationTime, onCreateJob, onFailedJob), 3*1000);
SimpleScheduler.getInstance().addEvent(new Rerequest(set, expirationTime, onCreateJob, onFailedJob), 3*1000);
}
// fire onCreated?
return; // already requesting

View File

@ -24,6 +24,7 @@ import net.i2p.router.PeerSelectionCriteria;
import net.i2p.router.RouterContext;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -50,7 +51,7 @@ class PeerManager {
_peersByCapability[i] = new ArrayList(64);
loadProfiles();
////_context.jobQueue().addJob(new EvaluateProfilesJob(_context));
SimpleTimer.getInstance().addEvent(new Reorg(), 0);
SimpleScheduler.getInstance().addPeriodicEvent(new Reorg(), 0, 30*1000);
//_context.jobQueue().addJob(new PersistProfilesJob(_context, this));
}
@ -60,8 +61,6 @@ class PeerManager {
_organizer.reorganize(true);
} catch (Throwable t) {
_log.log(Log.CRIT, "Error evaluating profiles", t);
} finally {
SimpleTimer.getInstance().addEvent(Reorg.this, 30*1000);
}
}
}

View File

@ -0,0 +1,89 @@
package net.i2p.router.transport.ntcp;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ThreadFactory;
import net.i2p.I2PAppContext;
import net.i2p.router.OutNetMessage;
import net.i2p.util.Log;
/**
* Previously, NTCP was using SimpleTimer with a delay of 0, which
* was a real abuse.
*
* Here we use the non-scheduled, lockless ThreadPoolExecutor with
* a fixed pool size and an unbounded queue.
*
* The old implementation was having problems with lock contention;
* this should work a lot better - and not clog up the SimpleTimer queue.
*
* @author zzz
*/
public class NTCPSendFinisher {
private static final int THREADS = 4;
private I2PAppContext _context;
private NTCPTransport _transport;
private Log _log;
private int _count;
private ThreadPoolExecutor _executor;
public NTCPSendFinisher(I2PAppContext context, NTCPTransport transport) {
_context = context;
_log = _context.logManager().getLog(NTCPSendFinisher.class);
_transport = transport;
}
public void start() {
_count = 0;
_executor = new CustomThreadPoolExecutor();
}
public void stop() {
_executor.shutdownNow();
}
public void add(OutNetMessage msg) {
_executor.execute(new RunnableEvent(msg));
}
// not really needed for now but in case we want to add some hooks like afterExecute()
private class CustomThreadPoolExecutor extends ThreadPoolExecutor {
public CustomThreadPoolExecutor() {
// use unbounded queue, so maximumPoolSize and keepAliveTime have no effect
super(THREADS, THREADS, 1000, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue(), new CustomThreadFactory());
}
}
private class CustomThreadFactory implements ThreadFactory {
public Thread newThread(Runnable r) {
Thread rv = Executors.defaultThreadFactory().newThread(r);
rv.setName("NTCPSendFinisher " + (++_count) + '/' + THREADS);
rv.setDaemon(true);
return rv;
}
}
/**
* Call afterSend() for the message
*/
private class RunnableEvent implements Runnable {
private OutNetMessage _msg;
public RunnableEvent(OutNetMessage msg) {
_msg = msg;
}
public void run() {
try {
_transport.afterSend(_msg, true, false, _msg.getSendTime());
} catch (Throwable t) {
_log.log(Log.CRIT, " wtf, afterSend borked", t);
}
}
}
}

View File

@ -27,7 +27,6 @@ import net.i2p.router.transport.Transport;
import net.i2p.router.transport.TransportBid;
import net.i2p.router.transport.TransportImpl;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer;
/**
*
@ -50,7 +49,7 @@ public class NTCPTransport extends TransportImpl {
private List _establishing;
private List _sent;
private SendFinisher _finisher;
private NTCPSendFinisher _finisher;
public NTCPTransport(RouterContext ctx) {
super(ctx);
@ -124,7 +123,7 @@ public class NTCPTransport extends TransportImpl {
_conByIdent = new HashMap(64);
_sent = new ArrayList(4);
_finisher = new SendFinisher();
_finisher = new NTCPSendFinisher(ctx, this);
_pumper = new EventPumper(ctx, this);
_reader = new Reader(ctx);
@ -310,27 +309,8 @@ public class NTCPTransport extends TransportImpl {
return countActivePeers() < getMaxConnections() * 4 / 5;
}
/** queue up afterSend call, which can take some time w/ jobs, etc */
void sendComplete(OutNetMessage msg) { _finisher.add(msg); }
/** async afterSend call, which can take some time w/ jobs, etc */
private class SendFinisher implements SimpleTimer.TimedEvent {
public void add(OutNetMessage msg) {
synchronized (_sent) { _sent.add(msg); }
SimpleTimer.getInstance().addEvent(SendFinisher.this, 0);
}
public void timeReached() {
int pending = 0;
OutNetMessage msg = null;
synchronized (_sent) {
pending = _sent.size()-1;
if (pending >= 0)
msg = (OutNetMessage)_sent.remove(0);
}
if (msg != null)
afterSend(msg, true, false, msg.getSendTime());
if (pending > 0)
SimpleTimer.getInstance().addEvent(SendFinisher.this, 0);
}
}
private boolean isEstablished(RouterIdentity peer) {
return isEstablished(peer.calculateHash());
@ -412,6 +392,7 @@ public class NTCPTransport extends TransportImpl {
public RouterAddress startListening() {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Starting ntcp transport listening");
_finisher.start();
_pumper.startPumping();
_reader.startReading(NUM_CONCURRENT_READERS);
@ -423,6 +404,7 @@ public class NTCPTransport extends TransportImpl {
public RouterAddress restartListening(RouterAddress addr) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Restarting ntcp transport listening");
_finisher.start();
_pumper.startPumping();
_reader.startReading(NUM_CONCURRENT_READERS);
@ -551,6 +533,7 @@ public class NTCPTransport extends TransportImpl {
_pumper.stopPumping();
_writer.stopWriting();
_reader.stopReading();
_finisher.stop();
Map cons = null;
synchronized (_conLock) {
cons = new HashMap(_conByIdent);

View File

@ -22,6 +22,7 @@ import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -184,7 +185,7 @@ public class EstablishmentManager {
msg.getTarget().getIdentity(),
new SessionKey(addr.getIntroKey()), addr);
_outboundStates.put(to, state);
SimpleTimer.getInstance().addEvent(new Expire(to, state), 10*1000);
SimpleScheduler.getInstance().addEvent(new Expire(to, state), 10*1000);
}
}
if (state != null) {
@ -394,7 +395,7 @@ public class EstablishmentManager {
msg.getTarget().getIdentity(),
new SessionKey(addr.getIntroKey()), addr);
_outboundStates.put(to, qstate);
SimpleTimer.getInstance().addEvent(new Expire(to, qstate), 10*1000);
SimpleScheduler.getInstance().addEvent(new Expire(to, qstate), 10*1000);
for (int i = 0; i < queued.size(); i++) {
OutNetMessage m = (OutNetMessage)queued.get(i);
@ -477,7 +478,7 @@ public class EstablishmentManager {
dsm.setMessageExpiration(_context.clock().now()+10*1000);
dsm.setMessageId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
_transport.send(dsm, peer);
SimpleTimer.getInstance().addEvent(new PublishToNewInbound(peer), 0);
SimpleScheduler.getInstance().addEvent(new PublishToNewInbound(peer), 0);
}
private class PublishToNewInbound implements SimpleTimer.TimedEvent {
private PeerState _peer;
@ -629,7 +630,7 @@ public class EstablishmentManager {
}
}
}
SimpleTimer.getInstance().addEvent(new FailIntroduction(state, nonce), INTRO_ATTEMPT_TIMEOUT);
SimpleScheduler.getInstance().addEvent(new FailIntroduction(state, nonce), INTRO_ATTEMPT_TIMEOUT);
state.setIntroNonce(nonce);
_context.statManager().addRateData("udp.sendIntroRelayRequest", 1, 0);
UDPPacket requests[] = _builder.buildRelayRequest(_transport, state, _transport.getIntroKey());

View File

@ -15,6 +15,7 @@ import net.i2p.data.SessionKey;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -79,7 +80,7 @@ class PeerTestManager {
sendTestToBob();
SimpleTimer.getInstance().addEvent(new ContinueTest(), RESEND_TIMEOUT);
SimpleScheduler.getInstance().addEvent(new ContinueTest(), RESEND_TIMEOUT);
}
private class ContinueTest implements SimpleTimer.TimedEvent {
@ -103,7 +104,7 @@ class PeerTestManager {
// second message from Charlie yet
sendTestToCharlie();
}
SimpleTimer.getInstance().addEvent(ContinueTest.this, RESEND_TIMEOUT);
SimpleScheduler.getInstance().addEvent(ContinueTest.this, RESEND_TIMEOUT);
}
}
}
@ -430,7 +431,7 @@ class PeerTestManager {
synchronized (_activeTests) {
_activeTests.put(new Long(nonce), state);
}
SimpleTimer.getInstance().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
SimpleScheduler.getInstance().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
}
UDPPacket packet = _packetBuilder.buildPeerTestToBob(bobIP, from.getPort(), aliceIP, alicePort, aliceIntroKey, nonce, state.getBobCipherKey(), state.getBobMACKey());
@ -511,7 +512,7 @@ class PeerTestManager {
synchronized (_activeTests) {
_activeTests.put(new Long(nonce), state);
}
SimpleTimer.getInstance().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
SimpleScheduler.getInstance().addEvent(new RemoveTest(nonce), MAX_CHARLIE_LIFETIME);
}
UDPPacket packet = _packetBuilder.buildPeerTestToCharlie(aliceIP, from.getPort(), aliceIntroKey, nonce,

View File

@ -9,6 +9,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -115,7 +116,7 @@ public class UDPReceiver {
long delay = ARTIFICIAL_DELAY_BASE + _context.random().nextInt(ARTIFICIAL_DELAY);
if (_log.shouldLog(Log.INFO))
_log.info("Delay packet " + packet + " for " + delay);
SimpleTimer.getInstance().addEvent(new ArtificiallyDelayedReceive(packet), delay);
SimpleScheduler.getInstance().addEvent(new ArtificiallyDelayedReceive(packet), delay);
return -1;
}

View File

@ -33,6 +33,7 @@ import net.i2p.router.transport.Transport;
import net.i2p.router.transport.TransportBid;
import net.i2p.router.transport.TransportImpl;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**
@ -631,7 +632,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
if (added) {
_context.statManager().addRateData("udp.dropPeerDroplist", droplistSize, 0);
SimpleTimer.getInstance().addEvent(new RemoveDropList(remote), DROPLIST_PERIOD);
SimpleScheduler.getInstance().addEvent(new RemoveDropList(remote), DROPLIST_PERIOD);
}
}
markUnreachable(peerHash);

View File

@ -46,6 +46,7 @@ class BuildExecutor implements Runnable {
_context.statManager().createRateStat("tunnel.buildRequestTime", "How long it takes to build a tunnel request", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildRequestZeroHopTime", "How long it takes to build a zero hop tunnel", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.pendingRemaining", "How many inbound requests are pending after a pass (period is how long the pass takes)?", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.buildFailFirstHop", "How often we fail to build a OB tunnel because we can't contact the first hop", "Tunnels", new long[] { 60*1000, 10*60*1000 });
// Get stat manager, get recognized bandwidth tiers
StatManager statMgr = _context.statManager();

View File

@ -61,6 +61,7 @@ class BuildHandler {
_context.statManager().createRateStat("tunnel.decryptRequestTime", "How long it takes to decrypt a new tunnel build request", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.rejectTimeout", "How often we reject a tunnel because we can't find the next hop", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.rejectTimeout2", "How often we fail a tunnel because we can't contact the next hop", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.rejectOverloaded", "How long we had to wait before processing the request (when it was rejected)", "Tunnels", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("tunnel.acceptLoad", "Delay before processing the accepted request", "Tunnels", new long[] { 60*1000, 10*60*1000 });
@ -413,7 +414,7 @@ class BuildHandler {
}
}
private class TimeoutReq extends JobImpl {
private static class TimeoutReq extends JobImpl {
private BuildMessageState _state;
private BuildRequestRecord _req;
private Hash _nextPeer;
@ -425,10 +426,12 @@ class BuildHandler {
}
public String getName() { return "Timeout looking for next peer for tunnel join"; }
public void runJob() {
getContext().statManager().addRateData("tunnel.rejectTimeout", 1, 1);
if (_log.shouldLog(Log.WARN))
_log.warn("Request " + _state.msg.getUniqueId()
+ " could no be satisfied, as the next peer could not be found: " + _nextPeer.toBase64());
getContext().statManager().addRateData("tunnel.rejectTimeout", 1, 0);
// logging commented out so class can be static
//if (_log.shouldLog(Log.WARN))
// _log.warn("Request " + _state.msg.getUniqueId()
// + " could no be satisfied, as the next peer could not be found: " + _nextPeer.toBase64());
// ??? should we blame the peer here? getContext().profileManager().tunnelTimedOut(_nextPeer);
getContext().messageHistory().tunnelRejected(_state.fromHash, new TunnelId(_req.readReceiveTunnelId()), _nextPeer,
"rejected because we couldn't find " + _nextPeer.toBase64() + ": " +
@ -516,8 +519,9 @@ class BuildHandler {
+ " from " + (state.fromHash != null ? state.fromHash.toBase64() :
state.from != null ? state.from.calculateHash().toBase64() : "tunnel"));
HopConfig cfg = null;
if (response == 0) {
HopConfig cfg = new HopConfig();
cfg = new HopConfig();
cfg.setCreation(_context.clock().now());
cfg.setExpiration(_context.clock().now() + 10*60*1000);
cfg.setIVKey(req.readIVKey());
@ -593,6 +597,8 @@ class BuildHandler {
msg.setExpiration(state.msg.getMessageExpiration());
msg.setPriority(300);
msg.setTarget(nextPeerInfo);
if (response == 0)
msg.setOnFailedSendJob(new TunnelBuildNextHopFailJob(_context, cfg));
_context.outNetMessagePool().add(msg);
} else {
// send it to the reply tunnel on the reply peer within a new TunnelBuildReplyMessage
@ -619,6 +625,8 @@ class BuildHandler {
outMsg.setMessage(m);
outMsg.setPriority(300);
outMsg.setTarget(nextPeerInfo);
if (response == 0)
outMsg.setOnFailedSendJob(new TunnelBuildNextHopFailJob(_context, cfg));
_context.outNetMessagePool().add(outMsg);
}
}
@ -762,7 +770,7 @@ class BuildHandler {
}
/** normal inbound requests from other people */
private class BuildMessageState {
private static class BuildMessageState {
TunnelBuildMessage msg;
RouterIdentity from;
Hash fromHash;
@ -775,7 +783,7 @@ class BuildHandler {
}
}
/** replies for outbound tunnels that we have created */
private class BuildReplyMessageState {
private static class BuildReplyMessageState {
TunnelBuildReplyMessage msg;
long recvTime;
public BuildReplyMessageState(I2NPMessage m) {
@ -784,7 +792,7 @@ class BuildHandler {
}
}
/** replies for inbound tunnels we have created */
private class BuildEndMessageState {
private static class BuildEndMessageState {
TunnelBuildMessage msg;
PooledTunnelCreatorConfig cfg;
long recvTime;
@ -796,15 +804,35 @@ class BuildHandler {
}
// noop
private class TunnelBuildMessageHandlerJob extends JobImpl {
private static class TunnelBuildMessageHandlerJob extends JobImpl {
private TunnelBuildMessageHandlerJob(RouterContext ctx) { super(ctx); }
public void runJob() {}
public String getName() { return "Receive tunnel build message"; }
}
// noop
private class TunnelBuildReplyMessageHandlerJob extends JobImpl {
private static class TunnelBuildReplyMessageHandlerJob extends JobImpl {
private TunnelBuildReplyMessageHandlerJob(RouterContext ctx) { super(ctx); }
public void runJob() {}
public String getName() { return "Receive tunnel build reply message"; }
}
/**
* Remove the participating tunnel if we can't contact the next hop
* Not strictly necessary, as the entry doesn't use that much space,
* but it affects capacity calculations
*/
private static class TunnelBuildNextHopFailJob extends JobImpl {
HopConfig _cfg;
private TunnelBuildNextHopFailJob(RouterContext ctx, HopConfig cfg) {
super(ctx);
_cfg = cfg;
}
public String getName() { return "Timeout contacting next peer for tunnel join"; }
public void runJob() {
getContext().tunnelDispatcher().remove(_cfg);
getContext().statManager().addRateData("tunnel.rejectTimeout2", 1, 0);
// static, no _log
//_log.error("Cant contact next hop for " + _cfg);
}
}
}

View File

@ -12,6 +12,7 @@ import net.i2p.data.RouterInfo;
import net.i2p.data.TunnelId;
import net.i2p.data.i2np.I2NPMessage;
import net.i2p.data.i2np.TunnelBuildMessage;
import net.i2p.router.JobImpl;
import net.i2p.router.OutNetMessage;
import net.i2p.router.RouterContext;
import net.i2p.router.TunnelInfo;
@ -136,6 +137,7 @@ class BuildRequestor {
return;
}
outMsg.setTarget(peer);
outMsg.setOnFailedSendJob(new TunnelBuildFirstHopFailJob(ctx, pool, cfg, exec));
ctx.outNetMessagePool().add(outMsg);
}
if (log.shouldLog(Log.DEBUG))
@ -213,4 +215,33 @@ class BuildRequestor {
ctx.jobQueue().addJob(expireJob);
// can it get much easier?
}
/**
* Do two important things if we can't get the build msg to the
* first hop on an outbound tunnel -
* - Call buildComplete() so we can get started on the next build
* without waiting for the full expire time
* - Blame the first hop in the profile
* Most likely to happen on an exploratory tunnel, obviously.
* Can't do this for inbound tunnels since the msg goes out an expl. tunnel.
*/
private static class TunnelBuildFirstHopFailJob extends JobImpl {
TunnelPool _pool;
PooledTunnelCreatorConfig _cfg;
BuildExecutor _exec;
private TunnelBuildFirstHopFailJob(RouterContext ctx, TunnelPool pool, PooledTunnelCreatorConfig cfg, BuildExecutor exec) {
super(ctx);
_cfg = cfg;
_exec = exec;
_pool = pool;
}
public String getName() { return "Timeout contacting first peer for OB tunnel"; }
public void runJob() {
_exec.buildComplete(_cfg, _pool);
getContext().profileManager().tunnelTimedOut(_cfg.getPeer(1));
getContext().statManager().addRateData("tunnel.buildFailFirstHop", 1, 0);
// static, no _log
//System.err.println("Cant contact first hop for " + _cfg);
}
}
}

View File

@ -376,7 +376,7 @@ public class TunnelPoolManager implements TunnelManagerFacade {
_context.jobQueue().addJob(new BootstrapPool(_context, _outboundExploratory));
}
private class BootstrapPool extends JobImpl {
private static class BootstrapPool extends JobImpl {
private TunnelPool _pool;
public BootstrapPool(RouterContext ctx, TunnelPool pool) {
super(ctx);