forked from I2P_Developers/i2p.i2p
* I2PSnark:
- Fix (again) partial piece avoidance for seeds - Fix several partial piece (temp file) leaks, some uncovered by previous rarest-first fixes, some in end game - Don't lose all DHT peers if we stop quickly (backport from update branch) - Explore a kbucket if it's less than 3/4 full (backport from update branch)
This commit is contained in:
@ -741,7 +741,19 @@ class PeerCoordinator implements PeerListener
|
||||
break;
|
||||
if (havePieces.get(p.getId()) && !p.isRequested())
|
||||
{
|
||||
piece = p;
|
||||
// never ever choose one that's in partialPieces, or we
|
||||
// will create a second one and leak
|
||||
boolean hasPartial = false;
|
||||
for (PartialPiece pp : partialPieces) {
|
||||
if (pp.getPiece() == p.getId()) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("wantPiece() skipping partial for " + peer + ": piece = " + pp);
|
||||
hasPartial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasPartial)
|
||||
piece = p;
|
||||
}
|
||||
else if (p.isRequested())
|
||||
{
|
||||
@ -943,11 +955,14 @@ class PeerCoordinator implements PeerListener
|
||||
*/
|
||||
public boolean gotPiece(Peer peer, PartialPiece pp)
|
||||
{
|
||||
if (metainfo == null || storage == null)
|
||||
if (metainfo == null || storage == null) {
|
||||
pp.release();
|
||||
return true;
|
||||
}
|
||||
int piece = pp.getPiece();
|
||||
if (halted) {
|
||||
_log.info("Got while-halted piece " + piece + "/" + metainfo.getPieces() +" from " + peer + " for " + metainfo.getName());
|
||||
pp.release();
|
||||
return true; // We don't actually care anymore.
|
||||
}
|
||||
|
||||
@ -962,8 +977,10 @@ class PeerCoordinator implements PeerListener
|
||||
// Assume we got a good piece, we don't really care anymore.
|
||||
// Well, this could be caused by a change in priorities, so
|
||||
// only return true if we already have it, otherwise might as well keep it.
|
||||
if (storage.getBitField().get(piece))
|
||||
if (storage.getBitField().get(piece)) {
|
||||
pp.release();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
@ -1277,6 +1294,7 @@ class PeerCoordinator implements PeerListener
|
||||
PartialPiece pp = iter.next();
|
||||
if (pp.getPiece() == piece) {
|
||||
iter.remove();
|
||||
pp.release();
|
||||
// there should be only one but keep going to be sure
|
||||
}
|
||||
}
|
||||
|
@ -592,6 +592,7 @@ class PeerState implements DataLoader
|
||||
// Send cancel even when we are choked to make sure that it is
|
||||
// really never ever send.
|
||||
out.sendCancel(req);
|
||||
req.getPartialPiece().release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -741,6 +742,10 @@ class PeerState implements DataLoader
|
||||
out.sendRequest(r);
|
||||
lastRequest = r;
|
||||
return true;
|
||||
} else {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Got dup from coord: " + pp);
|
||||
pp.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -572,7 +572,9 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
||||
_session.removeListener(I2PSession.PROTO_DATAGRAM_RAW, _rPort);
|
||||
// clear the DHT and tracker
|
||||
_tracker.stop();
|
||||
PersistDHT.saveDHT(_knownNodes, _dhtFile);
|
||||
// don't lose all our peers if we didn't have time to check them
|
||||
boolean saveAll = _context.clock().now() - _started < 20*60*1000;
|
||||
PersistDHT.saveDHT(_knownNodes, saveAll, _dhtFile);
|
||||
_knownNodes.stop();
|
||||
for (Iterator<ReplyWaiter> iter = _sentQueries.values().iterator(); iter.hasNext(); ) {
|
||||
ReplyWaiter waiter = iter.next();
|
||||
|
@ -56,12 +56,15 @@ abstract class PersistDHT {
|
||||
log.info("Loaded " + count + " nodes from " + file);
|
||||
}
|
||||
|
||||
public static synchronized void saveDHT(DHTNodes nodes, File file) {
|
||||
/**
|
||||
* @param saveAll if true, don't check last seen time
|
||||
*/
|
||||
public static synchronized void saveDHT(DHTNodes nodes, boolean saveAll, File file) {
|
||||
if (nodes.size() <= 0)
|
||||
return;
|
||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
|
||||
int count = 0;
|
||||
long maxAge = I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
|
||||
long maxAge = saveAll ? 0 : I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "ISO-8859-1")));
|
||||
|
Reference in New Issue
Block a user