The logic that updates the AverageSpeed executes when data is sent or received; if a transfer has stalled or is going incredibly slowly, the transfer's speed will report an incorrect speed.
There are two dictionaries in SoulseekClient, one named UploadDictionary and the other DownloadDictionary. These dictionaries hold the reference to the TransferInternal of every transfer that's currently being tracked.
A timer inside of SoulseekClient can be added that periodically searches these dictionaries to find transfers that are InProgress and that haven't had an update in some arbitrary time span, and call UpdateProgress with the current value of BytesTransferred. This will cause the AverageSpeed to trend towards zero.
Couple of things:
- The
lastProgressTime property needs to be surfaced so we can limit these nudges to only 'stuck' transfers
- There's a potential for a concurrency issue if
UpdateProgress is called with a stale BytesTransferred value (if the transfer is updated between the time of check), probably not a big deal but if we can find a way to make it thread safe, or just provide an overload of UpdateProgress that takes no parameters. Or maybe make bytesTransferred nullable and coalesce it with the property value? Lots to think about!
- The
progressUpdateLimit is hard coded to 1000 (1 second), so there's no point in doing this any faster than that.
- This has the potential to beat up memory if someone has thousands of transfers. But if they do this is likely a drop in the bucket
The logic that updates the AverageSpeed executes when data is sent or received; if a transfer has stalled or is going incredibly slowly, the transfer's speed will report an incorrect speed.
There are two dictionaries in
SoulseekClient, one namedUploadDictionaryand the otherDownloadDictionary. These dictionaries hold the reference to theTransferInternalof every transfer that's currently being tracked.A timer inside of
SoulseekClientcan be added that periodically searches these dictionaries to find transfers that areInProgressand that haven't had an update in some arbitrary time span, and callUpdateProgresswith the current value ofBytesTransferred. This will cause theAverageSpeedto trend towards zero.Couple of things:
lastProgressTimeproperty needs to be surfaced so we can limit these nudges to only 'stuck' transfersUpdateProgressis called with a staleBytesTransferredvalue (if the transfer is updated between the time of check), probably not a big deal but if we can find a way to make it thread safe, or just provide an overload of UpdateProgress that takes no parameters. Or maybe makebytesTransferrednullable and coalesce it with the property value? Lots to think about!progressUpdateLimitis hard coded to 1000 (1 second), so there's no point in doing this any faster than that.