Class PiecePickerImpl
java.lang.Object
com.biglybt.core.peermanager.piecepicker.impl.PiecePickerImpl
- All Implemented Interfaces:
PiecePicker
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classAn instance of this listener is registered with peerControlprivate classAn instance of this listener is registered with each peerprivate classAn instance of this listener is registered with peerControl Through this, we learn of peers joining and leaving and attach/detach listeners to themprotected static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprotected int[]periodically updated consistent view of availability for calculatingprotected int[]asynchronously updated availabilityprotected longprivate longprotected longindicates availability needs to be recomputed due to detected driftprotected final AEMonitorprivate longprotected static booleanprivate final DiskManagerprivate final PiecePickerImpl.DiskManagerListenerImplprivate final SpeedTokenDispenserprivate final DiskManagerPiece[]private static final booleanprivate static booleanprivate static final longprivate static final longprivate static final longprivate static final longprivate static final longprivate booleanA flag to indicate when we're in endgame modeprivate booleanprivate final Objectprivate Map<Long, EndGameModeChunk> private LinkedList<EndGameModeChunk> The list of chunks needing to be downloaded (the mechanism change when entering end-game mode)private float[]private longprotected longevent # of user file priority settings changesprivate static final longmin # pieces in file for first/last prioritizationprotected static booleanprotected static booleanprotected static longprivate CopyOnWriteSet<Integer> private int[]private floatprivate floatprivate intprivate intprivate intThe rarest availability level of pieces that we affirmatively want to try to request from others soonest ie; our prime targets for requesting rarest piecesprotected booleanprivate static booleanprivate longprivate final CopyOnWriteList<PiecePickerListener> private static final booleanprivate static final LogIDsprivate intprivate intprivate final intprotected intprivate intprotected longprivate static final intprivate static final intprotected static longevent # of user settings controlling priority changesprivate final PEPeerControlprotected final Mapprivate final PEPeerManagerListenerprivate final PEPiece[]private final intprivate static final intms a block is expected to complete inprivate static final intms since last writeprivate static final intprivate static final intcurrently webseeds + other explicit priorities are around 10000 or more - at this point we ignore rarityprivate final CopyOnWriteListprivate static final intpriority at and above which pieces require real-time schedulingprivate static final intprivate static final intprivate static final intpriority boost due to being too oldprivate static final intAdditional boost for more completed High priorityprivate static final intuser sets file as "High"private static final intprivate static final intuser select prioritize first/lastprivate static final intfinish pieces already almost doneprivate static final intkeep working on same pieceprivate longlast availability event # when priority bases were calculatedprivate longlast user priority event # when priority bases were calculatedprivate longlast user parameter settings event # when priority bases were calculatedprivate booleanprivate long[]private long[](package private) static final Randomprivate static final intMax number of request sent to a peerprivate static final intprivate static final intMin number of requests sent to a peerprivate booleanprivate static final longprivate static final longprivate final CopyOnWriteListprotected intprivate static final intDefault number of requests sent to a peer, (for each X B/s another request will be used)private int[]the priority for starting each piece/base priority for resumingprivate static final longmin ms for forced availability rebuildprivate longprivate longprivate static final longmin ms for recalculating availability - reducing this has serious ramificationsprivate static final longprivate static final longmin ms for recalculating base prioritiesprivate longprivate longprivate longprivate longtime that base priorities were last computedFields inherited from interface PiecePicker
REQUEST_HINT_MAX_LIFE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidfinal voidaddEndGameChunks(PEPiece pePiece) adds every block from the piece to the list of chuncks to be selected for egm requestingfinal voidaddHavePiece(PEPeer peer, int pieceNumber) voidaddListener(PiecePickerListener listener) voidaddPriorityProvider(PiecePriorityProvider provider) voidaddRTAProvider(PieceRTAProvider provider) final voidone reason requests don't stem from the individual peers is so the connections can be sorted by best uploaders, providing some ooprtunity to download the most important (ie; rarest and/or highest priority) pieces faster and more reliablyprivate intCount current global min avail pieces in progress (not counting non-rarest pieces but keep them to compensate high churn, remove completed ones, ignore idle ones)protected final voidEarly-outs when finds a downloadable piece Either way sets hasNeededUndonePiece and neededUndonePieceChange if necessaryprivate voidfinal voidvoidprivate voidThis computes the base priority for all pieces that need requesting if there's been any availability change or user priority setting changes since the last call, which will be most of the time since availability changes so dynamically It will change startPriorities[] (unless there was nothing to do)private voidprivate booleanvoiddestroy()protected final intfindPieceInEndGameMode(PEPeerTransport pt, int wants) protected final intfindPieceToDownload(PEPeerTransport pt, int nbWanted) protected final booleanfindRTAPieceToDownload(PEPeerTransport pt, boolean best_uploader, long best_uploader_next_block_eta) voidgenerateEvidence(IndentWriter writer) final int[]final intgetAvailability(int pieceNumber) final longfinal floatfinal longintgetEGMRequestCount(int piece_number, int block_number) int[]final intfinal floatfloatgetMinAvailability(int fileIndex) intfinal longprotected intintgetPieceString(int piece_number) protected final intgetPieceToStart(BitFlags startCandidates) private intThis method is the downloading core.booleanintfinal booleanbooleanbooleanisForcePiece(int pieceNumber) final booleanprotected voidprivate int[]final voidremoveFromEndGameModeChunks(int pieceNumber, int offset) voidremoveListener(PiecePickerListener listener) voidremovePriorityProvider(PiecePriorityProvider provider) voidremoveRTAProvider(PieceRTAProvider provider) voidsetForcePiece(int pieceNumber, boolean forced) voidsetGlobalRequestHint(int piece_number, int start_bytes, int byte_count) voidsetReverseBlockOrder(boolean is_reverse) voidsetSequentialAscendingFrom(int start_piece) voidsetSequentialDescendingFrom(int start_piece) private voidsetSequentialDownload(int val) private voidfinal voidThis method will compute the pieces' overall availability (including ourself) and the _globalMinOthers invalid input: '&' _globalAvail
-
Field Details
-
LOG_RTA
private static final boolean LOG_RTA- See Also:
-
EGM_IS_BLOCK_BASED
private static final boolean EGM_IS_BLOCK_BASED- See Also:
-
LOGID
-
TIME_MIN_AVAILABILITY
private static final long TIME_MIN_AVAILABILITYmin ms for recalculating availability - reducing this has serious ramifications- See Also:
-
TIME_MIN_FILE_AVAILABILITY
private static final long TIME_MIN_FILE_AVAILABILITY- See Also:
-
TIME_MIN_PRIORITIES
private static final long TIME_MIN_PRIORITIESmin ms for recalculating base priorities- See Also:
-
TIME_AVAIL_REBUILD
private static final long TIME_AVAIL_REBUILDmin ms for forced availability rebuild- See Also:
-
PRIORITY_W_FIRSTLAST
private static final int PRIORITY_W_FIRSTLASTuser select prioritize first/last- See Also:
-
FIRST_PIECE_MIN_NB
private static final long FIRST_PIECE_MIN_NBmin # pieces in file for first/last prioritization- See Also:
-
PRIORITY_W_FILE_BASE
private static final int PRIORITY_W_FILE_BASEuser sets file as "High"- See Also:
-
PRIORITY_W_FILE_RANGE
private static final int PRIORITY_W_FILE_RANGE- See Also:
-
PRIORITY_W_COMPLETION
private static final int PRIORITY_W_COMPLETIONAdditional boost for more completed High priority- See Also:
-
PRIORITY_W_AGE
private static final int PRIORITY_W_AGEpriority boost due to being too old- See Also:
-
PRIORITY_DW_AGE
private static final int PRIORITY_DW_AGEms a block is expected to complete in- See Also:
-
PRIORITY_DW_STALE
private static final int PRIORITY_DW_STALEms since last write- See Also:
-
PRIORITY_W_PIECE_DONE
private static final int PRIORITY_W_PIECE_DONEfinish pieces already almost done- See Also:
-
PRIORITY_W_SAME_PIECE
private static final int PRIORITY_W_SAME_PIECEkeep working on same piece- See Also:
-
PRIORITY_OVERRIDES_RAREST
private static final int PRIORITY_OVERRIDES_RARESTcurrently webseeds + other explicit priorities are around 10000 or more - at this point we ignore rarity- See Also:
-
PRIORITY_REQUEST_HINT
private static final int PRIORITY_REQUEST_HINT- See Also:
-
PRIORITY_SEQUENTIAL_START
private static final int PRIORITY_SEQUENTIAL_START- See Also:
-
PRIORITY_REALTIME
private static final int PRIORITY_REALTIMEpriority at and above which pieces require real-time scheduling- See Also:
-
PRIORITY_FORCED
private static final int PRIORITY_FORCED- See Also:
-
REQUESTS_MIN_MIN
private static final int REQUESTS_MIN_MINMin number of requests sent to a peer- See Also:
-
REQUESTS_MIN_MAX
private static final int REQUESTS_MIN_MAX- See Also:
-
REQUESTS_MAX
private static final int REQUESTS_MAXMax number of request sent to a peer- See Also:
-
SLOPE_REQUESTS
private static final int SLOPE_REQUESTSDefault number of requests sent to a peer, (for each X B/s another request will be used)- See Also:
-
RTA_END_GAME_MODE_SIZE_TRIGGER
private static final long RTA_END_GAME_MODE_SIZE_TRIGGER- See Also:
-
END_GAME_MODE_RESERVED_TRIGGER
private static final long END_GAME_MODE_RESERVED_TRIGGER- See Also:
-
END_GAME_MODE_SIZE_TRIGGER
private static final long END_GAME_MODE_SIZE_TRIGGER- See Also:
-
RTA_END_GAME_MODE_SIZE_TRIGGER_BLOCKS
private static final long RTA_END_GAME_MODE_SIZE_TRIGGER_BLOCKS- See Also:
-
END_GAME_MODE_RESERVED_TRIGGER_BLOCKS
private static final long END_GAME_MODE_RESERVED_TRIGGER_BLOCKS- See Also:
-
END_GAME_MODE_SIZE_TRIGGER_BLOCKS
private static final long END_GAME_MODE_SIZE_TRIGGER_BLOCKS- See Also:
-
END_GAME_MODE_TIMEOUT
private static final long END_GAME_MODE_TIMEOUT- See Also:
-
NO_REQUEST_BACKOFF_MAX_MILLIS
private static final int NO_REQUEST_BACKOFF_MAX_MILLIS- See Also:
-
NO_REQUEST_BACKOFF_MAX_LOOPS
private static final int NO_REQUEST_BACKOFF_MAX_LOOPS -
random
-
diskManager
-
peerControl
-
diskManagerListener
-
peerListeners
-
peerManagerListener
-
nbPieces
private final int nbPieces -
dmPieces
-
pePieces
-
pieceSize
private final int pieceSize -
rarestStartedPieces
-
availabilityMon
-
endGameModeChunkLock
-
nbPiecesDone
protected volatile int nbPiecesDone -
availabilityAsynch
protected volatile int[] availabilityAsynchasynchronously updated availability -
availabilityDrift
protected volatile long availabilityDriftindicates availability needs to be recomputed due to detected drift -
timeAvailRebuild
private long timeAvailRebuild -
availability
protected volatile int[] availabilityperiodically updated consistent view of availability for calculating -
time_last_avail
private long time_last_avail -
availabilityChange
protected volatile long availabilityChange -
availabilityComputeChange
private volatile long availabilityComputeChange -
time_last_rebuild
private long time_last_rebuild -
timeAvailLessThanOne
private long timeAvailLessThanOne -
globalAvail
private float globalAvail -
globalAvgAvail
private float globalAvgAvail -
nbRarestActive
private int nbRarestActive -
globalMin
private int globalMin -
globalMax
private int globalMax -
globalMinOthers
private volatile int globalMinOthersThe rarest availability level of pieces that we affirmatively want to try to request from others soonest ie; our prime targets for requesting rarest pieces -
filePriorityChange
protected volatile long filePriorityChangeevent # of user file priority settings changes -
sequentialDownload
protected volatile int sequentialDownload -
priorityParamChange
private volatile long priorityParamChangelast user parameter settings event # when priority bases were calculated -
priorityFileChange
private volatile long priorityFileChangelast user priority event # when priority bases were calculated -
priorityAvailChange
private volatile long priorityAvailChangelast availability event # when priority bases were calculated -
priorityRTAexists
private boolean priorityRTAexists -
timeLastPriorities
private long timeLastPrioritiestime that base priorities were last computed -
startPriorities
private int[] startPrioritiesthe priority for starting each piece/base priority for resuming -
hasNeededUndonePiece
protected volatile boolean hasNeededUndonePiece -
neededUndonePieceChange
protected volatile long neededUndonePieceChange -
endGameMode
private volatile boolean endGameModeA flag to indicate when we're in endgame mode -
endGameModeAbandoned
private volatile boolean endGameModeAbandoned -
timeEndGameModeEntered
private volatile long timeEndGameModeEntered -
endGameModeChunks
The list of chunks needing to be downloaded (the mechanism change when entering end-game mode) -
endGameModeChunkMap
-
lastProviderRecalcTime
private long lastProviderRecalcTime -
rta_providers
-
provider_piece_rtas
private long[] provider_piece_rtas -
priority_providers
-
provider_piece_priorities
private long[] provider_piece_priorities -
allocate_request_loop_count
private int allocate_request_loop_count -
max_file_priority
private int max_file_priority -
min_file_priority
private int min_file_priority -
reverse_block_order
private boolean reverse_block_order -
global_request_hint
private int[] global_request_hint -
enable_request_hints
private static boolean enable_request_hints -
includeLanPeersInReqLimiting
private static boolean includeLanPeersInReqLimiting -
listeners
-
fileAvailabilities
private volatile float[] fileAvailabilities -
fileAvailabilitiesCalcTime
private volatile long fileAvailabilitiesCalcTime -
forced_pieces
-
firstPiecePriority
protected static volatile boolean firstPiecePriority -
firstPriorityBytes
protected static volatile long firstPriorityBytes -
firstPiecePriorityForce
protected static volatile boolean firstPiecePriorityForce -
completionPriority
protected static volatile boolean completionPriority -
paramPriorityChange
protected static volatile long paramPriorityChangeevent # of user settings controlling priority changes -
dispenser
-
-
Constructor Details
-
PiecePickerImpl
-
-
Method Details
-
getPeerManager
- Specified by:
getPeerManagerin interfacePiecePicker
-
addHavePiece
- Specified by:
addHavePiecein interfacePiecePicker
-
updateAvailability
public final void updateAvailability()This method will compute the pieces' overall availability (including ourself) and the _globalMinOthers invalid input: '&' _globalAvail- Specified by:
updateAvailabilityin interfacePiecePicker
-
recomputeAvailability
private int[] recomputeAvailability() -
getNumberOfPieces
public int getNumberOfPieces()- Specified by:
getNumberOfPiecesin interfacePiecePicker
-
getAvailability
public final int[] getAvailability()- Specified by:
getAvailabilityin interfacePiecePicker
-
getAvailability
public final int getAvailability(int pieceNumber) - Specified by:
getAvailabilityin interfacePiecePicker
-
getMinAvailability
public final float getMinAvailability()- Specified by:
getMinAvailabilityin interfacePiecePicker
-
getMinAvailability
public float getMinAvailability(int fileIndex) - Specified by:
getMinAvailabilityin interfacePiecePicker
-
getAvailWentBadTime
public final long getAvailWentBadTime()- Specified by:
getAvailWentBadTimein interfacePiecePicker
-
getMaxAvailability
public final int getMaxAvailability()- Specified by:
getMaxAvailabilityin interfacePiecePicker
-
getAvgAvail
public final float getAvgAvail()- Specified by:
getAvgAvailin interfacePiecePicker
-
getNbPiecesDone
public int getNbPiecesDone()- Specified by:
getNbPiecesDonein interfacePiecePicker
-
checkDownloadablePiece
protected final void checkDownloadablePiece()Early-outs when finds a downloadable piece Either way sets hasNeededUndonePiece and neededUndonePieceChange if necessary -
allocateRequests
public final void allocateRequests()one reason requests don't stem from the individual peers is so the connections can be sorted by best uploaders, providing some ooprtunity to download the most important (ie; rarest and/or highest priority) pieces faster and more reliably- Specified by:
allocateRequestsin interfacePiecePicker
-
getNextBlockETAFromNow
-
calcRarestAllowed
private int calcRarestAllowed()Count current global min avail pieces in progress (not counting non-rarest pieces but keep them to compensate high churn, remove completed ones, ignore idle ones)- Returns:
- number of pieces that may be started due to the "rarest first" picking rule
-
syncFilePriorities
private void syncFilePriorities() -
computeBasePriorities
private void computeBasePriorities()This computes the base priority for all pieces that need requesting if there's been any availability change or user priority setting changes since the last call, which will be most of the time since availability changes so dynamically It will change startPriorities[] (unless there was nothing to do) -
findPieceToDownload
- Parameters:
pt- the PEPeerTransport we're working on- Returns:
- int # of blocks that were requested (0 if no requests were made)
-
findRTAPieceToDownload
protected final boolean findRTAPieceToDownload(PEPeerTransport pt, boolean best_uploader, long best_uploader_next_block_eta) -
getRequestCandidate
This method is the downloading core. It decides, for a given peer, which block should be requested. Here is the overall algorithm : 0. If there a FORCED_PIECE or reserved piece, that will be started/resumed if possible 1. Scan all the active pieces and find the rarest piece (and highest priority among equally rarest) that can possibly be continued by this peer, if any 2. While scanning the active pieces, develop a list of equally highest priority pieces (and equally rarest among those) as candidates for starting a new piece 3. If it can't find any piece, this means all pieces are already downloaded/full requested 4. Returns int[] pieceNumber, blockNumber if a request to be made is found, or null if none could be found- Parameters:
pc- PEPeerTransport to work with- Returns:
- int with pieceNumberto be requested or -1 if no request could be found
-
getPieceToStart
- Parameters:
startCandidates- BitFlags of potential candidates to choose from- Returns:
- int the piece number that was chosen to be started. Note it's possible for the chosen piece to have been started already (by another thread). This method considers that potential to not be relevant.
-
hasDownloadablePiece
public final boolean hasDownloadablePiece()- Specified by:
hasDownloadablePiecein interfacePiecePicker
-
getNeededUndonePieceChange
public final long getNeededUndonePieceChange()- Specified by:
getNeededUndonePieceChangein interfacePiecePicker- Returns:
- long value indicated serial number of current count of changes to hasNeededUndonePiece. A method interesting in tracking changes can compare this with a locally stored value to determine if the hasNeededUndonePiece status has changed since the last check.
-
checkEndGameMode
private void checkEndGameMode() -
computeEndGameModeChunks
private void computeEndGameModeChunks() -
isInEndGameMode
public final boolean isInEndGameMode()- Specified by:
isInEndGameModein interfacePiecePicker
-
hasEndGameModeBeenAbandoned
public boolean hasEndGameModeBeenAbandoned()- Specified by:
hasEndGameModeBeenAbandonedin interfacePiecePicker
-
addEndGameChunks
adds every block from the piece to the list of chuncks to be selected for egm requesting- Specified by:
addEndGameChunksin interfacePiecePicker- Parameters:
pePiece-
-
findPieceInEndGameMode
-
removeFromEndGameModeChunks
public final void removeFromEndGameModeChunks(int pieceNumber, int offset) - Specified by:
removeFromEndGameModeChunksin interfacePiecePicker
-
clearEndGameChunks
public final void clearEndGameChunks()- Specified by:
clearEndGameChunksin interfacePiecePicker
-
leaveEndGameMode
protected void leaveEndGameMode() -
abandonEndGameMode
protected void abandonEndGameMode() -
computeProviderPriorities
private boolean computeProviderPriorities() -
addRTAProvider
- Specified by:
addRTAProviderin interfacePiecePicker
-
removeRTAProvider
- Specified by:
removeRTAProviderin interfacePiecePicker
-
getRTAProviders
- Specified by:
getRTAProvidersin interfacePiecePicker
-
addPriorityProvider
- Specified by:
addPriorityProviderin interfacePiecePicker
-
removePriorityProvider
- Specified by:
removePriorityProviderin interfacePiecePicker
-
getPriorityProviders
- Specified by:
getPriorityProvidersin interfacePiecePicker
-
addListener
- Specified by:
addListenerin interfacePiecePicker
-
removeListener
- Specified by:
removeListenerin interfacePiecePicker
-
setForcePiece
public void setForcePiece(int pieceNumber, boolean forced) - Specified by:
setForcePiecein interfacePiecePicker
-
isForcePiece
public boolean isForcePiece(int pieceNumber) - Specified by:
isForcePiecein interfacePiecePicker
-
setSequentialDownload
private void setSequentialDownload(int val) -
setSequentialAscendingFrom
public void setSequentialAscendingFrom(int start_piece) - Specified by:
setSequentialAscendingFromin interfacePiecePicker
-
setSequentialDescendingFrom
public void setSequentialDescendingFrom(int start_piece) - Specified by:
setSequentialDescendingFromin interfacePiecePicker
-
clearSequential
public void clearSequential()- Specified by:
clearSequentialin interfacePiecePicker
-
getSequentialInfo
public int getSequentialInfo()- Specified by:
getSequentialInfoin interfacePiecePicker- Returns:
- 0 - inactive; +ve -> ascending from (n-1) -ve -> descending from (-n+1)
-
getEGMInfo
- Specified by:
getEGMInfoin interfacePiecePicker
-
getEGMRequestCount
public int getEGMRequestCount(int piece_number, int block_number) - Specified by:
getEGMRequestCountin interfacePiecePicker
-
setGlobalRequestHint
public void setGlobalRequestHint(int piece_number, int start_bytes, int byte_count) - Specified by:
setGlobalRequestHintin interfacePiecePicker
-
getGlobalRequestHint
public int[] getGlobalRequestHint()- Specified by:
getGlobalRequestHintin interfacePiecePicker
-
setReverseBlockOrder
public void setReverseBlockOrder(boolean is_reverse) - Specified by:
setReverseBlockOrderin interfacePiecePicker
-
getReverseBlockOrder
public boolean getReverseBlockOrder()- Specified by:
getReverseBlockOrderin interfacePiecePicker
-
destroy
public void destroy()- Specified by:
destroyin interfacePiecePicker
-
getPieceString
- Specified by:
getPieceStringin interfacePiecePicker
-
generateEvidence
- Specified by:
generateEvidencein interfacePiecePicker
-