forked from I2P_Developers/i2p.i2p
* 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:
@ -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,9 +98,11 @@ 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);
|
||||||
if ((bitfield[index] & mask) == 0) {
|
synchronized(this) {
|
||||||
count++;
|
if ((bitfield[index] & mask) == 0) {
|
||||||
bitfield[index] |= mask;
|
count++;
|
||||||
|
bitfield[index] |= mask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,10 +649,15 @@ 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,11 +1173,24 @@ 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
|
||||||
skipped = true;
|
boolean nonSeeds = false;
|
||||||
break;
|
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;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
iter.remove();
|
iter.remove();
|
||||||
piece.setRequested(peer, true);
|
piece.setRequested(peer, true);
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
history.txt
10
history.txt
@ -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
|
||||||
|
@ -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 = "";
|
||||||
|
Reference in New Issue
Block a user