Package com.biglybt.core.peer.impl
Class PEPieceImpl
- java.lang.Object
-
- com.biglybt.core.peer.impl.PEPieceImpl
-
-
Field Summary
Fields Modifier and Type Field Description protected static AEMonitor
class_mon
private long
creationTime
private DiskManagerPiece
dmPiece
private boolean[]
downloaded
private boolean
fully_downloaded
private boolean
fully_requested
private static LogIDs
LOGID
private int
nbBlocks
private PiecePicker
piecePicker
private java.lang.Object
real_time_data
private java.lang.String[]
requested
private java.lang.String
reservedBy
private int
resumePriority
private int
speed
private long
time_last_download
private java.lang.String[]
writers
private java.util.List
writes
-
Constructor Summary
Constructors Constructor Description PEPieceImpl(PiecePicker _picker, DiskManagerPiece _dm_piece, int _pieceSpeed)
piece for tracking partially downloaded pieces
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWrite(int blockNumber, java.lang.String sender, byte[] hash, boolean correct)
record details of a piece's blocks that have been completed for bad peer detection purposesprotected void
addWrite(PEPieceWriteImpl write)
void
checkRequests()
This will scan each block looking for requested blocks.void
clearDownloaded(int offset)
This flags the block at the given offset as NOT having been downloaded and the whole piece as not having been fully downloadedvoid
clearRequested(int blockNumber)
This method clears the requested information for the given block unless the block has already been downloaded, in which case the writer's IP is recorded as a request for the block.private void
fixupPadFile()
void
getAndMarkBlock(PEPeer peer, int index)
int[]
getAndMarkBlocks(PEPeer peer, int nbWanted, int[] request_hint, boolean reverse_order)
This method scans a piece for the first unrequested block.int
getAvailability()
int
getBlockNumber(int offset)
int
getBlockSize(int blockNumber)
long
getCreationTime()
The time the pePiece was [re]createdDiskManagerPiece
getDMPiece()
boolean[]
getDownloaded()
long
getLastDownloadTime(long now)
int
getLength()
PEPeerManager
getManager()
int
getNbBlocks()
int
getNbRequests()
int
getNbUnrequested()
int
getNbWritten()
This support method returns how many blocks have already been written from the dmPieceint
getPieceNumber()
PiecePicker
getPiecePicker()
java.util.List
getPieceWrites()
java.util.List
getPieceWrites(int blockNumber)
java.util.List
getPieceWrites(PEPeer peer)
java.util.List
getPieceWrites(java.lang.String ip)
java.lang.Object
getRealTimeData()
java.lang.String
getReservedBy()
int
getResumePriority()
int
getSpeed()
java.lang.String
getString()
long
getTimeSinceLastActivity()
How many ms since a write to the piece, or since the piece was created if no last write time is known.java.lang.String[]
getWriters()
boolean[]
getWritten()
This support method returns the dmPiece's written arrayboolean
hasUndownloadedBlock()
boolean
hasUnrequestedBlock()
boolean
isDownloaded()
boolean
isDownloaded(int blockNumber)
Tells if a block has been downloadedboolean
isRequestable()
boolean
isRequested()
boolean
isRequested(int blockNumber)
Tells if a block has been requestedboolean
isWritten()
boolean
isWritten(int block)
void
reDownloadBlock(int blockNumber)
for a block that's already downloadedt, mark up the piece so that the block will get downloaded again.void
reDownloadBlocks(java.lang.String address)
finds all blocks downloaded by the given address and marks them up for re-downloadingvoid
reset()
void
setDownloaded(int offset)
This flags the block at the given offset as having been downloaded If all blocks are now downloaed, sets the dmPiece as downloadedvoid
setLastRequestedPeerSpeed(int peerSpeed)
void
setRealTimeData(java.lang.Object o)
void
setRequestable()
void
setRequested()
boolean
setRequested(PEPeer peer, int blockNumber)
Assumption - single threaded with getAndMarkBlockvoid
setReservedBy(java.lang.String peer)
void
setResumePriority(int p)
void
setSpeed(int newSpeed)
void
setWritten(java.lang.String peer, int blockNumber)
This marks a given block as having been written by the given peer
-
-
-
Field Detail
-
LOGID
private static final LogIDs LOGID
-
dmPiece
private final DiskManagerPiece dmPiece
-
piecePicker
private final PiecePicker piecePicker
-
nbBlocks
private final int nbBlocks
-
creationTime
private long creationTime
-
requested
private final java.lang.String[] requested
-
fully_requested
private boolean fully_requested
-
downloaded
private final boolean[] downloaded
-
fully_downloaded
private boolean fully_downloaded
-
time_last_download
private long time_last_download
-
writers
private final java.lang.String[] writers
-
writes
private final java.util.List writes
-
reservedBy
private java.lang.String reservedBy
-
speed
private int speed
-
resumePriority
private int resumePriority
-
real_time_data
private java.lang.Object real_time_data
-
class_mon
protected static final AEMonitor class_mon
-
-
Constructor Detail
-
PEPieceImpl
public PEPieceImpl(PiecePicker _picker, DiskManagerPiece _dm_piece, int _pieceSpeed)
piece for tracking partially downloaded pieces- Parameters:
_manager
- the PEPeerManager_dm_piece
- the backing dmPiece_pieceSpeed
- the speed threshold for potential new requesters
-
-
Method Detail
-
getDMPiece
public DiskManagerPiece getDMPiece()
- Specified by:
getDMPiece
in interfacePEPiece
-
getCreationTime
public long getCreationTime()
Description copied from interface:PEPiece
The time the pePiece was [re]created- Specified by:
getCreationTime
in interfacePEPiece
-
getTimeSinceLastActivity
public long getTimeSinceLastActivity()
Description copied from interface:PEPiece
How many ms since a write to the piece, or since the piece was created if no last write time is known. The return value will be 0 when there's no writes and the piece is new.- Specified by:
getTimeSinceLastActivity
in interfacePEPiece
- Returns:
- long
-
getLastDownloadTime
public long getLastDownloadTime(long now)
- Specified by:
getLastDownloadTime
in interfacePEPiece
-
isRequested
public boolean isRequested(int blockNumber)
Tells if a block has been requested- Specified by:
isRequested
in interfacePEPiece
- Parameters:
blockNumber
- the block in question- Returns:
- true if the block is Requested already
-
isDownloaded
public boolean isDownloaded(int blockNumber)
Tells if a block has been downloaded- Specified by:
isDownloaded
in interfacePEPiece
- Parameters:
blockNumber
- the block in question- Returns:
- true if the block is downloaded already
-
setDownloaded
public void setDownloaded(int offset)
This flags the block at the given offset as having been downloaded If all blocks are now downloaed, sets the dmPiece as downloaded- Specified by:
setDownloaded
in interfacePEPiece
- Parameters:
blockNumber
-
-
clearDownloaded
public void clearDownloaded(int offset)
This flags the block at the given offset as NOT having been downloaded and the whole piece as not having been fully downloaded- Specified by:
clearDownloaded
in interfacePEPiece
- Parameters:
blockNumber
-
-
isDownloaded
public boolean isDownloaded()
- Specified by:
isDownloaded
in interfacePEPiece
-
getDownloaded
public boolean[] getDownloaded()
- Specified by:
getDownloaded
in interfacePEPiece
-
hasUndownloadedBlock
public boolean hasUndownloadedBlock()
- Specified by:
hasUndownloadedBlock
in interfacePEPiece
-
setWritten
public void setWritten(java.lang.String peer, int blockNumber)
This marks a given block as having been written by the given peer- Specified by:
setWritten
in interfacePEPiece
- Parameters:
peer
- the peer that sent the datablockNumber
- the block we're operating on
-
clearRequested
public void clearRequested(int blockNumber)
This method clears the requested information for the given block unless the block has already been downloaded, in which case the writer's IP is recorded as a request for the block.- Specified by:
clearRequested
in interfacePEPiece
-
isRequested
public boolean isRequested()
- Specified by:
isRequested
in interfacePEPiece
-
setRequested
public void setRequested()
- Specified by:
setRequested
in interfacePEPiece
-
checkRequests
public void checkRequests()
This will scan each block looking for requested blocks. For each one, it'll verify if the PEPeer for it still exists and is still willing and able to upload data. If not, it'll unmark the block as requested.
-
hasUnrequestedBlock
public boolean hasUnrequestedBlock()
- Specified by:
hasUnrequestedBlock
in interfacePEPiece
- Returns:
- true if the piece has any blocks that are not; Downloaded, Requested, or Written
-
getAndMarkBlocks
public int[] getAndMarkBlocks(PEPeer peer, int nbWanted, int[] request_hint, boolean reverse_order)
This method scans a piece for the first unrequested block. Upon finding it, it counts how many are unrequested up to nbWanted. The blocks are marked as requested by the PEPeer Assumption - single threaded access to this TODO: this should return the largest span equal or smaller than nbWanted OR, probably a different method should do that, so this one can support 'more sequential' picking- Specified by:
getAndMarkBlocks
in interfacePEPiece
-
getAndMarkBlock
public void getAndMarkBlock(PEPeer peer, int index)
- Specified by:
getAndMarkBlock
in interfacePEPiece
-
getNbRequests
public int getNbRequests()
- Specified by:
getNbRequests
in interfacePEPiece
-
getNbUnrequested
public int getNbUnrequested()
- Specified by:
getNbUnrequested
in interfacePEPiece
-
setRequested
public boolean setRequested(PEPeer peer, int blockNumber)
Assumption - single threaded with getAndMarkBlock- Specified by:
setRequested
in interfacePEPiece
-
isRequestable
public boolean isRequestable()
- Specified by:
isRequestable
in interfacePEPiece
-
getBlockSize
public int getBlockSize(int blockNumber)
- Specified by:
getBlockSize
in interfacePEPiece
-
getBlockNumber
public int getBlockNumber(int offset)
- Specified by:
getBlockNumber
in interfacePEPiece
- Parameters:
offset
- int bytes into piece- Returns:
- block int number corresponding to given offset
-
getNbBlocks
public int getNbBlocks()
- Specified by:
getNbBlocks
in interfacePEPiece
-
getPieceWrites
public java.util.List getPieceWrites()
-
getPieceWrites
public java.util.List getPieceWrites(int blockNumber)
-
getPieceWrites
public java.util.List getPieceWrites(PEPeer peer)
-
getPieceWrites
public java.util.List getPieceWrites(java.lang.String ip)
-
fixupPadFile
private void fixupPadFile()
-
getRealTimeData
public java.lang.Object getRealTimeData()
- Specified by:
getRealTimeData
in interfacePEPiece
-
setRealTimeData
public void setRealTimeData(java.lang.Object o)
- Specified by:
setRealTimeData
in interfacePEPiece
-
addWrite
protected void addWrite(PEPieceWriteImpl write)
-
addWrite
public void addWrite(int blockNumber, java.lang.String sender, byte[] hash, boolean correct)
Description copied from interface:PEPiece
record details of a piece's blocks that have been completed for bad peer detection purposes
-
getWriters
public java.lang.String[] getWriters()
- Specified by:
getWriters
in interfacePEPiece
-
setLastRequestedPeerSpeed
public void setLastRequestedPeerSpeed(int peerSpeed)
- Specified by:
setLastRequestedPeerSpeed
in interfacePEPiece
-
getPiecePicker
public PiecePicker getPiecePicker()
- Specified by:
getPiecePicker
in interfacePEPiece
-
getManager
public PEPeerManager getManager()
- Specified by:
getManager
in interfacePEPiece
- Returns:
- Returns the manager.
-
setReservedBy
public void setReservedBy(java.lang.String peer)
- Specified by:
setReservedBy
in interfacePEPiece
-
getReservedBy
public java.lang.String getReservedBy()
- Specified by:
getReservedBy
in interfacePEPiece
-
reDownloadBlock
public void reDownloadBlock(int blockNumber)
for a block that's already downloadedt, mark up the piece so that the block will get downloaded again. This is used when the piece fails hash-checking.
-
reDownloadBlocks
public void reDownloadBlocks(java.lang.String address)
finds all blocks downloaded by the given address and marks them up for re-downloading- Parameters:
address
- String
-
setResumePriority
public void setResumePriority(int p)
- Specified by:
setResumePriority
in interfacePEPiece
- Parameters:
p
- the Resume Priority to set, for display purposes
-
getResumePriority
public int getResumePriority()
- Specified by:
getResumePriority
in interfacePEPiece
- Returns:
- int ResumePriority (startPriority + resuming adjustments)
-
getAvailability
public int getAvailability()
- Specified by:
getAvailability
in interfacePEPiece
- Returns:
- int of availability in the swarm for this piece
-
getNbWritten
public int getNbWritten()
This support method returns how many blocks have already been written from the dmPiece- Specified by:
getNbWritten
in interfacePEPiece
- Returns:
- int from dmPiece.getNbWritten()
-
getWritten
public boolean[] getWritten()
This support method returns the dmPiece's written array- Returns:
- boolean[] from the dmPiece
-
getPieceNumber
public int getPieceNumber()
- Specified by:
getPieceNumber
in interfacePEPiece
-
setRequestable
public void setRequestable()
-
-