forked from I2P_Developers/i2p.i2p
Profiles: Don't allow creation of our own profile
TunnelCreatorConfig: - locking - comment out unused code - don't set bandwidth stats in profile for ourselves TunnelDispatcher: - don't set tunnel stats in profile for ourselves BuildHandler, TunnelPool: Minor optimizations
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user