propagate from branch 'i2p.i2p' (head 2da3b585b42d058e25909bc303d72277ae2463b5)

to branch 'i2p.i2p.zzz.test' (head 2785f3832a7d1b8adb2f106d049949beb9b88838)
This commit is contained in:
zzz
2012-10-14 19:50:51 +00:00
14 changed files with 122 additions and 37 deletions

View File

@@ -215,7 +215,7 @@ class PeerCoordinator implements PeerListener
public Storage getStorage() { return storage; }
// for web page detailed stats
/** for web page detailed stats */
public List<Peer> peerList()
{
return new ArrayList(peers);
@@ -446,6 +446,12 @@ class PeerCoordinator implements PeerListener
synchronized (downloaded_old) {
Arrays.fill(downloaded_old, 0);
}
// failsafe
synchronized(wantedPieces) {
for (Piece pc : wantedPieces) {
pc.clear();
}
}
timer.schedule((CHECK_PERIOD / 2) + _random.nextInt((int) CHECK_PERIOD));
}
@@ -750,8 +756,12 @@ class PeerCoordinator implements PeerListener
// AND if there are almost no wanted pieces left (real end game).
// If we do end game all the time, we generate lots of extra traffic
// when the seeder is super-slow and all the peers are "caught up"
if (wantedSize > END_GAME_THRESHOLD)
if (wantedSize > END_GAME_THRESHOLD) {
if (_log.shouldLog(Log.INFO))
_log.info("Nothing to request, " + requested.size() + " being requested and " +
wantedSize + " still wanted");
return null; // nothing to request and not in end game
}
// let's not all get on the same piece
// Even better would be to sort by number of requests
if (record)
@@ -1078,10 +1088,11 @@ class PeerCoordinator implements PeerListener
/** Called when a peer is removed, to prevent it from being used in
* rarest-first calculations.
*/
public void removePeerFromPieces(Peer peer) {
private void removePeerFromPieces(Peer peer) {
synchronized(wantedPieces) {
for (Piece piece : wantedPieces) {
piece.removePeer(peer);
piece.setRequested(peer, false);
}
}
}

View File

@@ -682,6 +682,7 @@ class PeerState implements DataLoader
_log.debug(peer + " addRequest() we are choked, delaying requestNextPiece()");
return;
}
// huh? rv unused
more_pieces = requestNextPiece();
} else if (more_pieces) // We want something
{
@@ -711,6 +712,8 @@ class PeerState implements DataLoader
}
// failsafe
// However this is bad as it thrashes the peer when we change our mind
// Ticket 691 cause here?
if (interesting && lastRequest == null && outstandingRequests.isEmpty())
setInteresting(false);
@@ -784,6 +787,8 @@ class PeerState implements DataLoader
}
// failsafe
// However this is bad as it thrashes the peer when we change our mind
// Ticket 691 cause here?
if (outstandingRequests.isEmpty())
lastRequest = null;

View File

@@ -12,7 +12,7 @@ class Piece implements Comparable {
private final int id;
private final Set<PeerID> peers;
/** @since 0.8.3 */
private Set<PeerID> requests;
private volatile Set<PeerID> requests;
/** @since 0.8.1 */
private int priority;
@@ -54,7 +54,10 @@ class Piece implements Comparable {
/** caller must synchronize */
public boolean addPeer(Peer peer) { return this.peers.add(peer.getPeerID()); }
/** caller must synchronize */
/**
* Caller must synchronize.
* @return true if removed
*/
public boolean removePeer(Peer peer) { return this.peers.remove(peer.getPeerID()); }
/**
@@ -104,6 +107,17 @@ class Piece implements Comparable {
public int getRequestCount() {
return this.requests == null ? 0 : this.requests.size();
}
/**
* Clear all knowledge of peers
* Caller must synchronize
* @since 0.9.3
*/
public void clear() {
peers.clear();
if (requests != null)
requests.clear();
}
/** @return default 0 @since 0.8.1 */
public int getPriority() { return this.priority; }

View File

@@ -38,11 +38,14 @@ import net.i2p.util.PortMapper;
import net.i2p.util.SecureDirectory;
import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.ShellCommand;
import net.i2p.util.SystemVersion;
import net.i2p.util.VersionComparator;
import org.mortbay.jetty.AbstractConnector;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.NCSARequestLog;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.handler.HandlerCollection;
@@ -54,6 +57,7 @@ import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.Constraint;
import org.mortbay.jetty.security.ConstraintMapping;
import org.mortbay.jetty.security.SecurityHandler;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.security.SslSelectChannelConnector;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
@@ -240,8 +244,7 @@ public class RouterConsoleRunner implements RouterApp {
try {
//TODO: move away from routerconsole into a separate application.
//ApplicationManager?
VersionComparator v = new VersionComparator();
boolean recentJava = v.compare(System.getProperty("java.runtime.version"), "1.6") >= 0;
boolean recentJava = SystemVersion.isJava6();
// default false for now
boolean desktopguiEnabled = ctx.getBooleanProperty("desktopgui.enabled");
if (recentJava && desktopguiEnabled) {
@@ -397,12 +400,22 @@ public class RouterConsoleRunner implements RouterApp {
// _server.addListener('[' + host + "]:" + _listenPort);
//else
// _server.addListener(host + ':' + _listenPort);
SelectChannelConnector lsnr = new SelectChannelConnector();
AbstractConnector lsnr;
if (SystemVersion.isJava6() && !SystemVersion.isGNU()) {
SelectChannelConnector slsnr = new SelectChannelConnector();
slsnr.setUseDirectBuffers(false); // default true seems to be leaky
lsnr = slsnr;
} else {
// Jetty 6 and NIO on Java 5 don't get along that well
// Also: http://jira.codehaus.org/browse/JETTY-1238
// "Do not use GCJ with Jetty, it will not work."
// Actually it does if you don't use NIO
lsnr = new SocketConnector();
}
lsnr.setHost(host);
lsnr.setPort(lport);
lsnr.setMaxIdleTime(90*1000); // default 10 sec
lsnr.setName("ConsoleSocket"); // all with same name will use the same thread pool
lsnr.setUseDirectBuffers(false); // default true seems to be leaky
//_server.addConnector(lsnr);
connectors.add(lsnr);
boundAddresses++;
@@ -451,22 +464,37 @@ public class RouterConsoleRunner implements RouterApp {
}
// TODO if class not found use SslChannelConnector
// Sadly there's no common base class with the ssl methods in it
SslSelectChannelConnector ssll = new SslSelectChannelConnector();
AbstractConnector ssll;
if (SystemVersion.isJava6() && !SystemVersion.isGNU()) {
SslSelectChannelConnector sssll = new SslSelectChannelConnector();
// the keystore path and password
sssll.setKeystore(keyStore.getAbsolutePath());
sssll.setPassword(ctx.getProperty(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD));
// the X.509 cert password (if not present, verifyKeyStore() returned false)
sssll.setKeyPassword(ctx.getProperty(PROP_KEY_PASSWORD, "thisWontWork"));
sssll.setUseDirectBuffers(false); // default true seems to be leaky
ssll = sssll;
} else {
// Jetty 6 and NIO on Java 5 don't get along that well
SslSocketConnector sssll = new SslSocketConnector();
// the keystore path and password
sssll.setKeystore(keyStore.getAbsolutePath());
sssll.setPassword(ctx.getProperty(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD));
// the X.509 cert password (if not present, verifyKeyStore() returned false)
sssll.setKeyPassword(ctx.getProperty(PROP_KEY_PASSWORD, "thisWontWork"));
ssll = sssll;
}
ssll.setHost(host);
ssll.setPort(sslPort);
// the keystore path and password
ssll.setKeystore(keyStore.getAbsolutePath());
ssll.setPassword(_context.getProperty(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD));
// the X.509 cert password (if not present, verifyKeyStore() returned false)
ssll.setKeyPassword(_context.getProperty(PROP_KEY_PASSWORD, "thisWontWork"));
ssll.setMaxIdleTime(90*1000); // default 10 sec
ssll.setName("ConsoleSocket"); // all with same name will use the same thread pool
ssll.setUseDirectBuffers(false); // default true seems to be leaky
//_server.addConnector(ssll);
connectors.add(ssll);
boundAddresses++;
} catch (Exception e) {
System.err.println("Unable to bind routerconsole to " + host + " port " + sslPort + " for SSL: " + e);
if (SystemVersion.isGNU())
System.err.println("Probably because GNU classpath does not support Sun keystores");
System.err.println("You may ignore this warning if the console is still available at https://localhost:" + sslPort);
}
}

View File

@@ -67,12 +67,10 @@ public class StatSummarizer implements Runnable {
public void run() {
// JRobin 1.5.9 crashes these JVMs
String vendor = System.getProperty("java.vendor");
if (vendor.startsWith("Apache") || // Harmony
vendor.startsWith("GNU Classpath") || // JamVM
vendor.startsWith("Free Software Foundation")) { // gij
if (SystemVersion.isApache() || // Harmony
SystemVersion.isGNU()) { // JamVM or gij
_log.logAlways(Log.WARN, "Graphing not supported with this JVM: " +
vendor + ' ' +
System.getProperty("java.vendor") + ' ' +
System.getProperty("java.version") + " (" +
System.getProperty("java.runtime.name") + ' ' +
System.getProperty("java.runtime.version") + ')');

View File

@@ -456,10 +456,11 @@ public class SummaryHelper extends HelperBase {
/** compare translated nicknames - put "shared clients" first in the sort */
private class AlphaComparator implements Comparator<Destination> {
private final String xsc = _("shared clients");
public int compare(Destination lhs, Destination rhs) {
String lname = getName(lhs);
String rname = getName(rhs);
String xsc = _("shared clients");
if (lname.equals(xsc))
return -1;
if (rname.equals(xsc))