Class PEPieceImpl
java.lang.Object
com.biglybt.core.peer.impl.PEPieceImpl
- All Implemented Interfaces:
PEPiece
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final AEMonitorprivate longprivate final DiskManagerPieceprivate final boolean[]private booleanprivate booleanprivate static final LogIDsprivate final intprivate final PiecePickerprivate Objectprivate final String[]private Stringprivate intprivate intprivate longprivate final String[]private final List -
Constructor Summary
ConstructorsConstructorDescriptionPEPieceImpl(PiecePicker _picker, DiskManagerPiece _dm_piece, int _pieceSpeed) piece for tracking partially downloaded pieces -
Method Summary
Modifier and TypeMethodDescriptionvoidrecord details of a piece's blocks that have been completed for bad peer detection purposesprotected voidaddWrite(PEPieceWriteImpl write) voidThis will scan each block looking for requested blocks.voidclearDownloaded(int offset) This flags the block at the given offset as NOT having been downloaded and the whole piece as not having been fully downloadedvoidclearRequested(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 voidvoidgetAndMarkBlock(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.intintgetBlockNumber(int offset) intgetBlockSize(int blockNumber) longThe time the pePiece was [re]createdboolean[]longgetLastDownloadTime(long now) intintintintintThis support method returns how many blocks have already been written from the dmPieceintgetPieceWrites(int blockNumber) getPieceWrites(PEPeer peer) getPieceWrites(String ip) intintgetSpeed()longHow many ms since a write to the piece, or since the piece was created if no last write time is known.String[]boolean[]This support method returns the dmPiece's written arraybooleanbooleanbooleanbooleanisDownloaded(int blockNumber) Tells if a block has been downloadedbooleanbooleanbooleanisRequested(int blockNumber) Tells if a block has been requestedbooleanbooleanisWritten(int block) voidreDownloadBlock(int blockNumber) for a block that's already downloadedt, mark up the piece so that the block will get downloaded again.voidreDownloadBlocks(String address) finds all blocks downloaded by the given address and marks them up for re-downloadingvoidreset()voidsetDownloaded(int offset) This flags the block at the given offset as having been downloaded If all blocks are now downloaed, sets the dmPiece as downloadedvoidsetLastRequestedPeerSpeed(int peerSpeed) voidvoidvoidbooleansetRequested(PEPeer peer, int blockNumber) Assumption - single threaded with getAndMarkBlockvoidsetReservedBy(String peer) voidsetResumePriority(int p) voidsetSpeed(int newSpeed) voidsetWritten(String peer, int blockNumber) This marks a given block as having been written by the given peer
-
Field Details
-
LOGID
-
dmPiece
-
piecePicker
-
nbBlocks
private final int nbBlocks -
creationTime
private long creationTime -
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
-
writes
-
reservedBy
-
speed
private int speed -
resumePriority
private int resumePriority -
real_time_data
-
class_mon
-
-
Constructor Details
-
PEPieceImpl
piece for tracking partially downloaded pieces- Parameters:
_dm_piece- the backing dmPiece_pieceSpeed- the speed threshold for potential new requesters_manager- the PEPeerManager
-
-
Method Details
-
getDMPiece
- Specified by:
getDMPiecein interfacePEPiece
-
getCreationTime
public long getCreationTime()Description copied from interface:PEPieceThe time the pePiece was [re]created- Specified by:
getCreationTimein interfacePEPiece
-
getTimeSinceLastActivity
public long getTimeSinceLastActivity()Description copied from interface:PEPieceHow 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:
getTimeSinceLastActivityin interfacePEPiece- Returns:
- long
-
getLastDownloadTime
public long getLastDownloadTime(long now) - Specified by:
getLastDownloadTimein interfacePEPiece
-
isRequested
public boolean isRequested(int blockNumber) Tells if a block has been requested- Specified by:
isRequestedin 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:
isDownloadedin 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:
setDownloadedin 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:
clearDownloadedin interfacePEPiece- Parameters:
blockNumber-
-
isDownloaded
public boolean isDownloaded()- Specified by:
isDownloadedin interfacePEPiece
-
getDownloaded
public boolean[] getDownloaded()- Specified by:
getDownloadedin interfacePEPiece
-
hasUndownloadedBlock
public boolean hasUndownloadedBlock()- Specified by:
hasUndownloadedBlockin interfacePEPiece
-
setWritten
This marks a given block as having been written by the given peer- Specified by:
setWrittenin 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:
clearRequestedin interfacePEPiece
-
isRequested
public boolean isRequested()- Specified by:
isRequestedin interfacePEPiece
-
setRequested
public void setRequested()- Specified by:
setRequestedin 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:
hasUnrequestedBlockin interfacePEPiece- Returns:
- true if the piece has any blocks that are not; Downloaded, Requested, or Written
-
getAndMarkBlocks
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:
getAndMarkBlocksin interfacePEPiece
-
getAndMarkBlock
- Specified by:
getAndMarkBlockin interfacePEPiece
-
getNbRequests
public int getNbRequests()- Specified by:
getNbRequestsin interfacePEPiece
-
getNbUnrequested
public int getNbUnrequested()- Specified by:
getNbUnrequestedin interfacePEPiece
-
setRequested
Assumption - single threaded with getAndMarkBlock- Specified by:
setRequestedin interfacePEPiece
-
isRequestable
public boolean isRequestable()- Specified by:
isRequestablein interfacePEPiece
-
getBlockSize
public int getBlockSize(int blockNumber) - Specified by:
getBlockSizein interfacePEPiece
-
getBlockNumber
public int getBlockNumber(int offset) - Specified by:
getBlockNumberin interfacePEPiece- Parameters:
offset- int bytes into piece- Returns:
- block int number corresponding to given offset
-
getNbBlocks
public int getNbBlocks()- Specified by:
getNbBlocksin interfacePEPiece
-
getPieceWrites
-
getPieceWrites
-
getPieceWrites
-
getPieceWrites
-
fixupPadFile
private void fixupPadFile() -
reset
-
getRealTimeData
- Specified by:
getRealTimeDatain interfacePEPiece
-
setRealTimeData
- Specified by:
setRealTimeDatain interfacePEPiece
-
addWrite
-
addWrite
Description copied from interface:PEPiecerecord details of a piece's blocks that have been completed for bad peer detection purposes -
getWriters
- Specified by:
getWritersin interfacePEPiece
-
getSpeed
-
setSpeed
-
setLastRequestedPeerSpeed
public void setLastRequestedPeerSpeed(int peerSpeed) - Specified by:
setLastRequestedPeerSpeedin interfacePEPiece
-
getPiecePicker
- Specified by:
getPiecePickerin interfacePEPiece
-
getManager
- Specified by:
getManagerin interfacePEPiece- Returns:
- Returns the manager.
-
setReservedBy
- Specified by:
setReservedByin interfacePEPiece
-
getReservedBy
- Specified by:
getReservedByin 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
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:
setResumePriorityin interfacePEPiece- Parameters:
p- the Resume Priority to set, for display purposes
-
getResumePriority
public int getResumePriority()- Specified by:
getResumePriorityin interfacePEPiece- Returns:
- int ResumePriority (startPriority + resuming adjustments)
-
getAvailability
public int getAvailability()- Specified by:
getAvailabilityin 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:
getNbWrittenin interfacePEPiece- Returns:
- int from dmPiece.getNbWritten()
-
getWritten
public boolean[] getWritten()This support method returns the dmPiece's written array- Returns:
- boolean[] from the dmPiece
-
isWritten
-
isWritten
-
getPieceNumber
public int getPieceNumber()- Specified by:
getPieceNumberin interfacePEPiece
-
getLength
-
setRequestable
public void setRequestable() -
getString
-