forked from I2P_Developers/i2p.i2p
i2psnark: Don't unchoke when we don't have pieces
Don't avoid partial pieces if there are several seeds
This commit is contained in:
@ -670,6 +670,9 @@ class PeerCoordinator implements PeerListener
|
|||||||
*/
|
*/
|
||||||
void unchokePeer()
|
void unchokePeer()
|
||||||
{
|
{
|
||||||
|
if (storage == null || storage.getBitField().size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
// linked list will contain all interested peers that we choke.
|
// linked list will contain all interested peers that we choke.
|
||||||
// At the start are the peers that have us unchoked at the end the
|
// At the start are the peers that have us unchoked at the end the
|
||||||
// other peer that are interested, but are choking us.
|
// other peer that are interested, but are choking us.
|
||||||
@ -1139,6 +1142,10 @@ class PeerCoordinator implements PeerListener
|
|||||||
{
|
{
|
||||||
if (interest)
|
if (interest)
|
||||||
{
|
{
|
||||||
|
if (storage == null || storage.getBitField().size() == 0) {
|
||||||
|
// XD bug #80
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (uploaders.get() < allowedUploaders())
|
if (uploaders.get() < allowedUploaders())
|
||||||
{
|
{
|
||||||
if(peer.isChoking())
|
if(peer.isChoking())
|
||||||
@ -1237,12 +1244,12 @@ class PeerCoordinator implements PeerListener
|
|||||||
}
|
}
|
||||||
int max = getMaxConnections();
|
int max = getMaxConnections();
|
||||||
if (partialPieces.size() > max) {
|
if (partialPieces.size() > max) {
|
||||||
// sorts by remaining bytes, least first
|
// sorts by preference, highest first
|
||||||
Collections.sort(partialPieces);
|
Collections.sort(partialPieces);
|
||||||
PartialPiece gone = partialPieces.remove(max);
|
PartialPiece gone = partialPieces.remove(partialPieces.size() - 1);
|
||||||
gone.release();
|
gone.release();
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("Discarding orphaned partial piece (list full)" + gone);
|
_log.info("Discarding orphaned partial piece (list full) " + gone);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// drop the empty partial piece
|
// drop the empty partial piece
|
||||||
@ -1269,7 +1276,7 @@ class PeerCoordinator implements PeerListener
|
|||||||
if (storage != null && storage.isChecking())
|
if (storage != null && storage.isChecking())
|
||||||
return null;
|
return null;
|
||||||
synchronized(wantedPieces) {
|
synchronized(wantedPieces) {
|
||||||
// sorts by remaining bytes, least first
|
// sorts by preference, highest first
|
||||||
Collections.sort(partialPieces);
|
Collections.sort(partialPieces);
|
||||||
for (Iterator<PartialPiece> iter = partialPieces.iterator(); iter.hasNext(); ) {
|
for (Iterator<PartialPiece> iter = partialPieces.iterator(); iter.hasNext(); ) {
|
||||||
PartialPiece pp = iter.next();
|
PartialPiece pp = iter.next();
|
||||||
@ -1277,6 +1284,7 @@ class PeerCoordinator implements PeerListener
|
|||||||
if (havePieces.get(savedPiece)) {
|
if (havePieces.get(savedPiece)) {
|
||||||
// this is just a double-check, it should be in there
|
// this is just a double-check, it should be in there
|
||||||
boolean skipped = false;
|
boolean skipped = false;
|
||||||
|
outer:
|
||||||
for(Piece piece : wantedPieces) {
|
for(Piece piece : wantedPieces) {
|
||||||
if (piece.getId() == savedPiece) {
|
if (piece.getId() == savedPiece) {
|
||||||
if (peer.isCompleted() && piece.getPeerCount() > 1 &&
|
if (peer.isCompleted() && piece.getPeerCount() > 1 &&
|
||||||
@ -1285,20 +1293,24 @@ class PeerCoordinator implements PeerListener
|
|||||||
// by not requesting a partial piece that at least two non-seeders also have
|
// by not requesting a partial piece that at least two non-seeders also have
|
||||||
// from a seeder
|
// from a seeder
|
||||||
int nonSeeds = 0;
|
int nonSeeds = 0;
|
||||||
|
int seeds = 0;
|
||||||
for (Peer pr : peers) {
|
for (Peer pr : peers) {
|
||||||
PeerState state = pr.state;
|
if (pr.isCompleted()) {
|
||||||
if (state == null) continue;
|
if (++seeds >= 4)
|
||||||
BitField bf = state.bitfield;
|
|
||||||
if (bf == null) continue;
|
|
||||||
if (bf.get(savedPiece) && !pr.isCompleted()) {
|
|
||||||
if (++nonSeeds > 1)
|
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
PeerState state = pr.state;
|
||||||
|
if (state == null) continue;
|
||||||
|
BitField bf = state.bitfield;
|
||||||
|
if (bf == null) continue;
|
||||||
|
if (bf.get(savedPiece)) {
|
||||||
|
if (++nonSeeds > 1) {
|
||||||
|
skipped = true;
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nonSeeds > 1) {
|
|
||||||
skipped = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
iter.remove();
|
iter.remove();
|
||||||
piece.setRequested(peer, true);
|
piece.setRequested(peer, true);
|
||||||
|
Reference in New Issue
Block a user