forked from I2P_Developers/i2p.i2p
i2psnark: Fix IOOBE when stopping torrent that is allocating (ticket #2273)
more sync in PartialPiece
This commit is contained in:
@ -112,7 +112,7 @@ class PartialPiece implements Comparable<PartialPiece> {
|
|||||||
* as set by setDownloaded() or read().
|
* as set by setDownloaded() or read().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Request getRequest() {
|
public synchronized Request getRequest() {
|
||||||
return new Request(this, this.off, Math.min(this.pclen - this.off, PeerState.PARTSIZE));
|
return new Request(this, this.off, Math.min(this.pclen - this.off, PeerState.PARTSIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ class PartialPiece implements Comparable<PartialPiece> {
|
|||||||
/**
|
/**
|
||||||
* How many bytes are good - as set by setDownloaded() or read()
|
* How many bytes are good - as set by setDownloaded() or read()
|
||||||
*/
|
*/
|
||||||
public int getDownloaded() {
|
public synchronized int getDownloaded() {
|
||||||
return this.off;
|
return this.off;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ class PartialPiece implements Comparable<PartialPiece> {
|
|||||||
* Any chunks after a 'hole' will be lost.
|
* Any chunks after a 'hole' will be lost.
|
||||||
* @since 0.9.1
|
* @since 0.9.1
|
||||||
*/
|
*/
|
||||||
public void setDownloaded(int offset) {
|
public synchronized void setDownloaded(int offset) {
|
||||||
this.off = offset;
|
this.off = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,7 +546,7 @@ class PeerState implements DataLoader
|
|||||||
synchronized(pp) {
|
synchronized(pp) {
|
||||||
int dl = pp.getDownloaded();
|
int dl = pp.getDownloaded();
|
||||||
if (req.off != dl)
|
if (req.off != dl)
|
||||||
req = new Request(pp, dl, 1);
|
req = new Request(pp, dl);
|
||||||
}
|
}
|
||||||
rv.add(req);
|
rv.add(req);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,25 @@ class Request
|
|||||||
throw new IndexOutOfBoundsException("Illegal Request " + toString());
|
throw new IndexOutOfBoundsException("Illegal Request " + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy Request for PeerState.returnPartialPieces().
|
||||||
|
* len will be zero.
|
||||||
|
*
|
||||||
|
* @param piece Piece number requested.
|
||||||
|
* @param off the offset in the array.
|
||||||
|
* @since 0.9.36
|
||||||
|
*/
|
||||||
|
Request(PartialPiece piece, int off)
|
||||||
|
{
|
||||||
|
this.piece = piece;
|
||||||
|
this.off = off;
|
||||||
|
this.len = 0;
|
||||||
|
|
||||||
|
// Sanity check
|
||||||
|
if (off < 0 || off > piece.getLength())
|
||||||
|
throw new IndexOutOfBoundsException("Illegal Request " + toString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 0.9.1
|
* @since 0.9.1
|
||||||
*/
|
*/
|
||||||
|
@ -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 = 4;
|
public final static long BUILD = 5;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "";
|
||||||
|
Reference in New Issue
Block a user