merge of 'b12b7f42f59f400abd7032f3f2bffba289f3ec7a'

and 'b5a86744c2877d9d738a2fdd2b99970a0160e062'
This commit is contained in:
zzz
2010-04-10 16:06:14 +00:00
13 changed files with 88 additions and 26 deletions

View File

@@ -240,15 +240,19 @@ public class PeerCoordinator implements PeerListener
}
}
/** reduce max if huge pieces to keep from ooming */
/**
* Reduce max if huge pieces to keep from ooming
* Todo: should we only reduce when leeching?
* @return 512K: 16; 1M: 11; 2M: 8
*/
private int getMaxConnections() {
int size = metainfo.getPieceLength(0);
int max = _util.getMaxConnections();
if (size <= 1024*1024)
if (size <= 512*1024)
return max;
if (size <= 2*1024*1024)
return (max + 1) / 2;
return (max + 3) / 4;
if (size <= 1024*1024)
return (max + max + 2) / 3;
return (max + 1) / 2;
}
public boolean halted() { return halted; }

View File

@@ -152,7 +152,16 @@ class PeerState
// XXX - Check for weird bitfield and disconnect?
bitfield = new BitField(bitmap, metainfo.getPieces());
}
setInteresting(listener.gotBitField(peer, bitfield));
boolean interest = listener.gotBitField(peer, bitfield);
setInteresting(interest);
if (bitfield.complete() && !interest) {
// They are seeding and we are seeding,
// why did they contact us? (robert)
// Dump them quick before we send our whole bitmap
if (_log.shouldLog(Log.WARN))
_log.warn("Disconnecting seed that connects to seeds" + peer);
peer.disconnect(true);
}
}
void requestMessage(int piece, int begin, int length)

View File

@@ -259,8 +259,7 @@ public class PluginStarter implements Runnable {
String current = ctx.getProperty(CSSHelper.PROP_THEME_NAME);
for (int i = 0; i < tfiles.length; i++) {
String name = tfiles[i].getName();
if (tfiles[i].isDirectory() && (!name.equals("images")) && (!name.equals("classic")) &&
(!name.equals("dark")) && (!name.equals("light")) && (!name.equals("midnight"))) {
if (tfiles[i].isDirectory() && (!Arrays.asList(STANDARD_THEMES).contains(tfiles[i]))) {
ctx.router().removeConfigSetting(ConfigUIHelper.PROP_THEME_PFX + name);
if (name.equals(current))
ctx.router().setConfigSetting(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);

View File

@@ -386,8 +386,10 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
private static final double RTT_DAMPENING = 0.875;
public void updateRTT(int measuredValue) {
// the rttDev calculation matches that recommended in RFC 2988 (beta = 1/4)
_rttDev = _rttDev + (int)(0.25d*(Math.abs(measuredValue-_rtt)-_rttDev));
int smoothed = (int)(RTT_DAMPENING*_rtt + (1-RTT_DAMPENING)*measuredValue);
// K = 4
_rto = smoothed + (_rttDev<<2);
if (_rto < Connection.MIN_RESEND_DELAY)
_rto = (int)Connection.MIN_RESEND_DELAY;

View File

@@ -328,7 +328,19 @@ public class ConnectionPacketHandler {
}
long lowest = con.getHighestAckedThrough();
if (lowest >= con.getCongestionWindowEnd()) {
// RFC 2581
// Why wait until we get a whole cwin to start updating the window?
// That means we don't start increasing the window until after 1 RTT.
// And whether we increase the window or not (probably not since 1/N),
// we reset the CongestionWindowEnd and have to wait another RTT.
// So we add the acked > 1 and UnackedPacketsSent > 0 cases,
// so we almost always go through the window adjustment code,
// unless we're just sending a single packet now and then.
// This keeps the window size from going sky-high from ping traffic alone.
// Since we don't adjust the window down after idle? (RFC 2581 sec. 4.1)
if (lowest >= con.getCongestionWindowEnd() ||
acked > 1 ||
con.getUnackedPacketsSent() > 0) {
// new packet that ack'ed uncongested data, or an empty ack
int oldWindow = con.getOptions().getWindowSize();
int newWindowSize = oldWindow;
@@ -352,11 +364,12 @@ public class ConnectionPacketHandler {
newWindowSize += acked / factor;
if (_log.shouldLog(Log.DEBUG))
_log.debug("slow start acks = " + acked + " for " + con);
} else if (trend < 0) {
// rtt is shrinking, so lets increment the cwin
newWindowSize++;
if (_log.shouldLog(Log.DEBUG))
_log.debug("trend < 0 for " + con);
// this is too fast since we mostly disabled the CongestionWindowEnd test above
//} else if (trend < 0) {
// // rtt is shrinking, so lets increment the cwin
// newWindowSize++;
// if (_log.shouldLog(Log.DEBUG))
// _log.debug("trend < 0 for " + con);
} else {
// congestion avoidance
// linear growth - increase window 1/N per RTT
@@ -368,6 +381,10 @@ public class ConnectionPacketHandler {
if (_log.shouldLog(Log.DEBUG))
_log.debug("cong. avoid acks = " + acked + " for " + con);
}
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("No change to window: " + con.getOptions().getWindowSize() +
" congested? " + congested + " acked: " + acked + " resends: " + numResends);
}
if (newWindowSize <= 0)
@@ -380,6 +397,11 @@ public class ConnectionPacketHandler {
_log.debug("New window size " + newWindowSize + "/" + oldWindow + "/" + con.getOptions().getWindowSize() + " congestionSeenAt: "
+ con.getLastCongestionSeenAt() + " (#resends: " + numResends
+ ") for " + con);
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("No change to window: " + con.getOptions().getWindowSize() +
" highestAckedThrough: " + lowest + " congestionWindowEnd: " + con.getCongestionWindowEnd() +
" acked: " + acked + " unacked: " + con.getUnackedPacketsSent());
}
con.windowAdjusted();