make speed smoothing interval configurable

This commit is contained in:
Zlatin Balevsky
2019-10-20 20:09:24 +01:00
parent 3e10d497b1
commit 1dc88cb96b
5 changed files with 22 additions and 6 deletions

View File

@@ -32,6 +32,7 @@ class MuWireSettings {
float downloadSequentialRatio float downloadSequentialRatio
int hostClearInterval, hostHopelessInterval, hostRejectInterval int hostClearInterval, hostHopelessInterval, hostRejectInterval
int meshExpiration int meshExpiration
int speedSmoothSeconds
boolean embeddedRouter boolean embeddedRouter
int inBw, outBw int inBw, outBw
Set<String> watchedKeywords Set<String> watchedKeywords
@@ -70,6 +71,7 @@ class MuWireSettings {
outBw = Integer.valueOf(props.getProperty("outBw","128")) outBw = Integer.valueOf(props.getProperty("outBw","128"))
searchComments = Boolean.valueOf(props.getProperty("searchComments","true")) searchComments = Boolean.valueOf(props.getProperty("searchComments","true"))
browseFiles = Boolean.valueOf(props.getProperty("browseFiles","true")) browseFiles = Boolean.valueOf(props.getProperty("browseFiles","true"))
speedSmoothSeconds = Integer.valueOf(props.getProperty("speedSmoothSeconds","60"))
watchedDirectories = readEncodedSet(props, "watchedDirectories") watchedDirectories = readEncodedSet(props, "watchedDirectories")
watchedKeywords = readEncodedSet(props, "watchedKeywords") watchedKeywords = readEncodedSet(props, "watchedKeywords")
@@ -113,6 +115,7 @@ class MuWireSettings {
props.setProperty("outBw", String.valueOf(outBw)) props.setProperty("outBw", String.valueOf(outBw))
props.setProperty("searchComments", String.valueOf(searchComments)) props.setProperty("searchComments", String.valueOf(searchComments))
props.setProperty("browseFiles", String.valueOf(browseFiles)) props.setProperty("browseFiles", String.valueOf(browseFiles))
props.setProperty("speedSmoothSeconds", String.valueOf(speedSmoothSeconds))
writeEncodedSet(watchedDirectories, "watchedDirectories", props) writeEncodedSet(watchedDirectories, "watchedDirectories", props)
writeEncodedSet(watchedKeywords, "watchedKeywords", props) writeEncodedSet(watchedKeywords, "watchedKeywords", props)

View File

@@ -27,6 +27,7 @@ import net.i2p.util.ConcurrentHashSet
@Log @Log
public class Downloader { public class Downloader {
public enum DownloadState { CONNECTING, HASHLIST, DOWNLOADING, FAILED, CANCELLED, PAUSED, FINISHED } public enum DownloadState { CONNECTING, HASHLIST, DOWNLOADING, FAILED, CANCELLED, PAUSED, FINISHED }
private enum WorkerState { CONNECTING, HASHLIST, DOWNLOADING, FINISHED} private enum WorkerState { CONNECTING, HASHLIST, DOWNLOADING, FINISHED}
@@ -84,10 +85,6 @@ public class Downloader {
this.pieceSize = 1 << pieceSizePow2 this.pieceSize = 1 << pieceSizePow2
this.pieces = pieces this.pieces = pieces
this.nPieces = pieces.nPieces this.nPieces = pieces.nPieces
// default size suitable for an average of 5 seconds / 5 elements / 5 interval units
// it's easily adjustable by resizing the size of speedArr
this.speedArr = [ 0, 0, 0, 0, 0 ]
} }
public synchronized InfoHash getInfoHash() { public synchronized InfoHash getInfoHash() {
@@ -148,6 +145,12 @@ public class Downloader {
} }
} }
if (speedArr.size() != downloadManager.muSettings.speedSmoothSeconds) {
speedArr.clear()
downloadManager.muSettings.speedSmoothSeconds.times { speedArr.add(0) }
speedPos = 0
}
// normalize to speedArr.size // normalize to speedArr.size
currSpeed /= speedArr.size() currSpeed /= speedArr.size()

View File

@@ -91,6 +91,10 @@ class OptionsController {
model.browseFiles = browseFiles model.browseFiles = browseFiles
settings.browseFiles = browseFiles settings.browseFiles = browseFiles
text = view.speedSmoothSecondsField.text
model.speedSmoothSeconds = Integer.valueOf(text)
settings.speedSmoothSeconds = Integer.valueOf(text)
String downloadLocation = model.downloadLocation String downloadLocation = model.downloadLocation
settings.downloadLocation = new File(downloadLocation) settings.downloadLocation = new File(downloadLocation)

View File

@@ -18,6 +18,7 @@ class OptionsModel {
@Observable String incompleteLocation @Observable String incompleteLocation
@Observable boolean searchComments @Observable boolean searchComments
@Observable boolean browseFiles @Observable boolean browseFiles
@Observable int speedSmoothSeconds
// i2p options // i2p options
@Observable String inboundLength @Observable String inboundLength
@@ -60,6 +61,7 @@ class OptionsModel {
incompleteLocation = settings.incompleteLocation.getAbsolutePath() incompleteLocation = settings.incompleteLocation.getAbsolutePath()
searchComments = settings.searchComments searchComments = settings.searchComments
browseFiles = settings.browseFiles browseFiles = settings.browseFiles
speedSmoothSeconds = settings.speedSmoothSeconds
Core core = application.context.get("core") Core core = application.context.get("core")
inboundLength = core.i2pOptions["inbound.length"] inboundLength = core.i2pOptions["inbound.length"]

View File

@@ -39,6 +39,7 @@ class OptionsView {
def shareHiddenCheckbox def shareHiddenCheckbox
def searchCommentsCheckbox def searchCommentsCheckbox
def browseFilesCheckbox def browseFilesCheckbox
def speedSmoothSecondsField
def inboundLengthField def inboundLengthField
def inboundQuantityField def inboundQuantityField
@@ -149,9 +150,12 @@ class OptionsView {
label(text : "Automatically Clear Finished Downloads", constraints: gbc(gridx: 0, gridy:6)) label(text : "Automatically Clear Finished Downloads", constraints: gbc(gridx: 0, gridy:6))
clearFinishedDownloadsCheckbox = checkBox(selected : bind {model.clearFinishedDownloads}, clearFinishedDownloadsCheckbox = checkBox(selected : bind {model.clearFinishedDownloads},
constraints : gbc(gridx : 1, gridy:6, anchor : GridBagConstraints.LINE_START)) constraints : gbc(gridx : 1, gridy:6, anchor : GridBagConstraints.LINE_START))
label(text : "Exclude Local Files From Results", constraints: gbc(gridx:0, gridy:7)) label(text : "Smooth Download Speed Over (seconds)", constraints : gbc(gridx: 0, gridy : 7))
speedSmoothSecondsField = textField(text : bind {model.speedSmoothSeconds},
constraints : gbc(gridx:1, gridy: 7, anchor : GridBagConstraints.LINE_START))
label(text : "Exclude Local Files From Results", constraints: gbc(gridx:0, gridy:8))
excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult}, excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult},
constraints : gbc(gridx: 1, gridy : 7, anchor : GridBagConstraints.LINE_START)) constraints : gbc(gridx: 1, gridy : 8, anchor : GridBagConstraints.LINE_START))
} }
bandwidth = builder.panel { bandwidth = builder.panel {