diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java index 87f751bdcb725ceb2ba8786f3f5a245c01f2124f..ea800858bc93bfe779cd6825ea5fb87268ee8868 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java +++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java @@ -156,6 +156,11 @@ public class ProfileOrganizer { * Blocking if a reorganize is happening. */ public PeerProfile getProfile(Hash peer) { + if (peer.equals(_us)) { + if (_log.shouldWarn()) + _log.warn("Who wanted our own profile?", new Exception("I did")); + return null; + } getReadLock(); try { return locked_getProfile(peer); @@ -168,6 +173,11 @@ public class ProfileOrganizer { * @since 0.8.12 */ public PeerProfile getProfileNonblocking(Hash peer) { + if (peer.equals(_us)) { + if (_log.shouldWarn()) + _log.warn("Who wanted our own profile?", new Exception("I did")); + return null; + } if (tryReadLock()) { try { return locked_getProfile(peer); @@ -184,6 +194,11 @@ public class ProfileOrganizer { if (profile == null) return null; Hash peer = profile.getPeer(); + if (peer.equals(_us)) { + if (_log.shouldWarn()) + _log.warn("Who added our own profile?", new Exception("I did")); + return null; + } if (_log.shouldLog(Log.DEBUG)) _log.debug("New profile created for " + peer); diff --git a/router/java/src/net/i2p/router/tunnel/HopConfig.java b/router/java/src/net/i2p/router/tunnel/HopConfig.java index 447f6a0834aaeb216de0d0182f3e63d0436a4fc9..133c6484a4d9a9faedfeba47338173832293f102 100644 --- a/router/java/src/net/i2p/router/tunnel/HopConfig.java +++ b/router/java/src/net/i2p/router/tunnel/HopConfig.java @@ -50,12 +50,14 @@ public class HopConfig { public void setReceiveTunnelId(byte id[]) { _receiveTunnelId = id; } public void setReceiveTunnelId(TunnelId id) { _receiveTunnelId = DataHelper.toLong(4, id.getTunnelId()); } - /** what is the previous peer in the tunnel (if any)? */ + /** what is the previous peer in the tunnel (null if gateway) */ public Hash getReceiveFrom() { return _receiveFrom; } public void setReceiveFrom(Hash from) { _receiveFrom = from; } - /** what is the next tunnel ID we are sending to? */ + /** what is the next tunnel ID we are sending to? (null if endpoint) */ public byte[] getSendTunnelId() { return _sendTunnelId; } + + /** what is the next tunnel we are sending to? (null if endpoint) */ public TunnelId getSendTunnel() { if (_sendTunnel == null) _sendTunnel = getTunnel(_sendTunnelId); @@ -70,7 +72,7 @@ public class HopConfig { return new TunnelId(DataHelper.fromLong(id, 0, id.length)); } - /** what is the next peer in the tunnel (if any)? */ + /** what is the next peer in the tunnel (null if endpoint) */ public Hash getSendTo() { return _sendTo; } public void setSendTo(Hash to) { _sendTo = to; } diff --git a/router/java/src/net/i2p/router/tunnel/TunnelCreatorConfig.java b/router/java/src/net/i2p/router/tunnel/TunnelCreatorConfig.java index 9340477c6f4efb37d15e63ff17e3318cc9f20c57..758d2096b99a5042f0201577c772075239207ff0 100644 --- a/router/java/src/net/i2p/router/tunnel/TunnelCreatorConfig.java +++ b/router/java/src/net/i2p/router/tunnel/TunnelCreatorConfig.java @@ -30,16 +30,32 @@ public class TunnelCreatorConfig implements TunnelInfo { private long _replyMessageId; private final boolean _isInbound; private int _messagesProcessed; - private volatile long _verifiedBytesTransferred; + private long _verifiedBytesTransferred; private boolean _failed; private int _failures; private boolean _reused; private int _priority; + //private static final int THROUGHPUT_COUNT = 3; + // Fastest 1 minute throughput, in bytes per minute, ordered with fastest first. + //private final double _peakThroughput[] = new double[THROUGHPUT_COUNT]; + private long _peakThroughputCurrentTotal; + private long _peakThroughputLastCoallesce = System.currentTimeMillis(); + // Make configurable? - but can't easily get to pool options from here + private static final int MAX_CONSECUTIVE_TEST_FAILURES = 3; + private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss", Locale.UK); + /** + * For exploratory only (null destination) + * @param length 1 minimum (0 hop is length 1) + */ public TunnelCreatorConfig(RouterContext ctx, int length, boolean isInbound) { this(ctx, length, isInbound, null); } + /** + * @param length 1 minimum (0 hop is length 1) + * @param destination null for exploratory + */ public TunnelCreatorConfig(RouterContext ctx, int length, boolean isInbound, Hash destination) { _context = ctx; if (length <= 0) @@ -131,10 +147,14 @@ public class TunnelCreatorConfig implements TunnelInfo { public void setReplyMessageId(long id) { _replyMessageId = id; } /** take note of a message being pumped through this tunnel */ - public void incrementProcessedMessages() { _messagesProcessed++; } - public int getProcessedMessagesCount() { return _messagesProcessed; } + public synchronized void incrementProcessedMessages() { _messagesProcessed++; } + public synchronized int getProcessedMessagesCount() { return _messagesProcessed; } - public void incrementVerifiedBytesTransferred(int bytes) { + /** + * This calls profile manager tunnelDataPushed1m() for each peer + * @return null for exploratory + */ + public synchronized void incrementVerifiedBytesTransferred(int bytes) { _verifiedBytesTransferred += bytes; _peakThroughputCurrentTotal += bytes; long now = System.currentTimeMillis(); @@ -144,38 +164,34 @@ public class TunnelCreatorConfig implements TunnelInfo { double normalized = tot * 60d*1000d / timeSince; _peakThroughputLastCoallesce = now; _peakThroughputCurrentTotal = 0; - if (_context != null) - for (int i = 0; i < _peers.length; i++) + if (_context != null) { + // skip ourselves + int start = _isInbound ? 0 : 1; + int end = _isInbound ? _peers.length - 1 : _peers.length; + for (int i = start; i < end; i++) { _context.profileManager().tunnelDataPushed1m(_peers[i], (int)normalized); + } + } } } - public long getVerifiedBytesTransferred() { return _verifiedBytesTransferred; } + public synchronized long getVerifiedBytesTransferred() { return _verifiedBytesTransferred; } - private static final int THROUGHPUT_COUNT = 3; - /** - * fastest 1 minute throughput, in bytes per minute, ordered with fastest - * first. - */ - private final double _peakThroughput[] = new double[THROUGHPUT_COUNT]; - private volatile long _peakThroughputCurrentTotal; - private volatile long _peakThroughputLastCoallesce = System.currentTimeMillis(); - public double getPeakThroughputKBps() { +/**** unused + public synchronized double getPeakThroughputKBps() { double rv = 0; for (int i = 0; i < THROUGHPUT_COUNT; i++) rv += _peakThroughput[i]; rv /= (60d*1024d*THROUGHPUT_COUNT); return rv; } - public void setPeakThroughputKBps(double kBps) { + + public synchronized void setPeakThroughputKBps(double kBps) { _peakThroughput[0] = kBps*60*1024; //for (int i = 0; i < THROUGHPUT_COUNT; i++) // _peakThroughput[i] = kBps*60; } - - - // Make configurable? - but can't easily get to pool options from here - private static final int MAX_CONSECUTIVE_TEST_FAILURES = 3; +****/ /** * The tunnel failed a test, so (maybe) stop using it @@ -264,11 +280,10 @@ public class TunnelCreatorConfig implements TunnelInfo { return buf.toString(); } - private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss", Locale.UK); - private String getExpirationString() { return format(_expiration); } + static String format(long date) { Date d = new Date(date); synchronized (_fmt) { diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java index d4985ab5115c54859e84f95a3ed9810b1821f35d..0848bbe1bbe251fa116a814f677e6b93c7737edd 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java @@ -795,7 +795,8 @@ class BuildHandler implements Runnable { cfg.setIVKey(req.readIVKey()); cfg.setLayerKey(req.readLayerKey()); if (isInGW) { - cfg.setReceiveFrom(null); + // default + //cfg.setReceiveFrom(null); } else { if (state.fromHash != null) { cfg.setReceiveFrom(state.fromHash); @@ -808,8 +809,9 @@ class BuildHandler implements Runnable { } cfg.setReceiveTunnelId(DataHelper.toLong(4, ourId)); if (isOutEnd) { - cfg.setSendTo(null); - cfg.setSendTunnelId(null); + // default + //cfg.setSendTo(null); + //cfg.setSendTunnelId(null); } else { cfg.setSendTo(nextPeer); cfg.setSendTunnelId(DataHelper.toLong(4, nextId)); diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java index a1dae253c88a97260ac93a8cb764b3b8a61e963b..aaf24387cc738bfb6ea8819180175f442332e7dd 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java @@ -1168,7 +1168,7 @@ public class TunnelPool { int j = peers.size() - 1 - i; cfg.setPeer(j, peers.get(i)); HopConfig hop = cfg.getConfig(j); - hop.setCreation(_context.clock().now()); + hop.setCreation(now); hop.setExpiration(expiration); hop.setIVKey(_context.keyGenerator().generateSessionKey()); hop.setLayerKey(_context.keyGenerator().generateSessionKey());