* i2psnark:

- Fix bugs in rarest-first tracking
   - Fix requesting of partial piece when there are multiple seeds
   - Synch fix in BitField
This commit is contained in:
zzz
2012-09-28 19:25:31 +00:00
parent f58bf3028a
commit a71e8fae00
5 changed files with 51 additions and 26 deletions

View File

@ -39,7 +39,6 @@ public class BitField
this.size = size; this.size = size;
int arraysize = ((size-1)/8)+1; int arraysize = ((size-1)/8)+1;
bitfield = new byte[arraysize]; bitfield = new byte[arraysize];
this.count = 0;
} }
/** /**
@ -99,11 +98,13 @@ public class BitField
throw new IndexOutOfBoundsException(Integer.toString(bit)); throw new IndexOutOfBoundsException(Integer.toString(bit));
int index = bit/8; int index = bit/8;
int mask = 128 >> (bit % 8); int mask = 128 >> (bit % 8);
synchronized(this) {
if ((bitfield[index] & mask) == 0) { if ((bitfield[index] & mask) == 0) {
count++; count++;
bitfield[index] |= mask; bitfield[index] |= mask;
} }
} }
}
/** /**
* Return true if the bit is set or false if it is not. * Return true if the bit is set or false if it is not.

View File

@ -649,9 +649,14 @@ class PeerCoordinator implements PeerListener
if (listener != null) if (listener != null)
listener.peerChange(this, peer); listener.peerChange(this, peer);
synchronized(wantedPieces) synchronized(wantedPieces) {
{ for (Piece pc : wantedPieces) {
return wantedPieces.contains(new Piece(piece)); if (pc.getId() == piece) {
pc.addPeer(peer);
return true;
}
}
return false;
} }
} }
@ -664,20 +669,17 @@ class PeerCoordinator implements PeerListener
if (listener != null) if (listener != null)
listener.peerChange(this, peer); listener.peerChange(this, peer);
synchronized(wantedPieces) boolean rv = false;
{ synchronized(wantedPieces) {
Iterator<Piece> it = wantedPieces.iterator(); for (Piece p : wantedPieces) {
while (it.hasNext())
{
Piece p = it.next();
int i = p.getId(); int i = p.getId();
if (bitfield.get(i)) { if (bitfield.get(i)) {
p.addPeer(peer); p.addPeer(peer);
return true; rv = true;
} }
} }
} }
return false; return rv;
} }
/** /**
@ -1077,8 +1079,7 @@ class PeerCoordinator implements PeerListener
*/ */
public void removePeerFromPieces(Peer peer) { public void removePeerFromPieces(Peer peer) {
synchronized(wantedPieces) { synchronized(wantedPieces) {
for(Iterator<Piece> iter = wantedPieces.iterator(); iter.hasNext(); ) { for (Piece piece : wantedPieces) {
Piece piece = iter.next();
piece.removePeer(peer); piece.removePeer(peer);
} }
} }
@ -1172,12 +1173,25 @@ class PeerCoordinator implements PeerListener
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) {
// Try to preserve rarest-first when we have only one seeder // Try to preserve rarest-first
// by not preferring a partial piece that others have too // by not requesting a partial piece that non-seeders also have
// from a seeder // from a seeder
boolean nonSeeds = false;
for (Peer pr : peers) {
PeerState state = pr.state;
if (state == null) continue;
BitField bf = state.bitfield;
if (bf == null) continue;
if (bf.get(savedPiece) && !pr.isCompleted()) {
nonSeeds = true;
break;
}
}
if (nonSeeds) {
skipped = true; skipped = true;
break; break;
} }
}
iter.remove(); iter.remove();
piece.setRequested(peer, true); piece.setRequested(peer, true);
if (_log.shouldLog(Log.INFO)) { if (_log.shouldLog(Log.INFO)) {

View File

@ -18,7 +18,7 @@ class Piece implements Comparable {
public Piece(int id) { public Piece(int id) {
this.id = id; this.id = id;
this.peers = new HashSet(I2PSnarkUtil.MAX_CONNECTIONS); this.peers = new HashSet(I2PSnarkUtil.MAX_CONNECTIONS / 2);
// defer creating requests to save memory // defer creating requests to save memory
} }

View File

@ -1,3 +1,13 @@
2012-09-28 zzz
* i2psnark:
- Fix bugs in rarest-first tracking
- Fix requesting of partial piece when there are multiple seeds
- Synch fix in BitField
* i2ptunnel: Fix wrong server IP in log message
* peers.jsp: Remove SSU "Dev" column
* SessionKeyManager: Store original tagset size for debugging
* Streaming: Don't send RST on globally-blackisted conns
2012-09-26 zzz 2012-09-26 zzz
* Addresses: Reject numeric IPs of the form n, n.n, and n.n.n * Addresses: Reject numeric IPs of the form n, n.n, and n.n.n
* Console, i2ptunnel: More validation of address and port in forms * Console, i2ptunnel: More validation of address and port in forms

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 3; public final static long BUILD = 4;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";