diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index aef4f24f..3c5e9e55 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -32,6 +32,7 @@ class MuWireSettings { float downloadSequentialRatio int hostClearInterval, hostHopelessInterval, hostRejectInterval int meshExpiration + int speedSmoothSeconds boolean embeddedRouter int inBw, outBw Set watchedKeywords @@ -70,6 +71,7 @@ class MuWireSettings { outBw = Integer.valueOf(props.getProperty("outBw","128")) searchComments = Boolean.valueOf(props.getProperty("searchComments","true")) browseFiles = Boolean.valueOf(props.getProperty("browseFiles","true")) + speedSmoothSeconds = Integer.valueOf(props.getProperty("speedSmoothSeconds","60")) watchedDirectories = readEncodedSet(props, "watchedDirectories") watchedKeywords = readEncodedSet(props, "watchedKeywords") @@ -113,6 +115,7 @@ class MuWireSettings { props.setProperty("outBw", String.valueOf(outBw)) props.setProperty("searchComments", String.valueOf(searchComments)) props.setProperty("browseFiles", String.valueOf(browseFiles)) + props.setProperty("speedSmoothSeconds", String.valueOf(speedSmoothSeconds)) writeEncodedSet(watchedDirectories, "watchedDirectories", props) writeEncodedSet(watchedKeywords, "watchedKeywords", props) diff --git a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy index 7e73a7fc..e6d2ff7e 100644 --- a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy +++ b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy @@ -27,6 +27,7 @@ import net.i2p.util.ConcurrentHashSet @Log public class Downloader { + public enum DownloadState { CONNECTING, HASHLIST, DOWNLOADING, FAILED, CANCELLED, PAUSED, FINISHED } private enum WorkerState { CONNECTING, HASHLIST, DOWNLOADING, FINISHED} @@ -84,10 +85,6 @@ public class Downloader { this.pieceSize = 1 << pieceSizePow2 this.pieces = pieces 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() { @@ -147,6 +144,12 @@ public class Downloader { currSpeed += it.speed() } } + + if (speedArr.size() != downloadManager.muSettings.speedSmoothSeconds) { + speedArr.clear() + downloadManager.muSettings.speedSmoothSeconds.times { speedArr.add(0) } + speedPos = 0 + } // normalize to speedArr.size currSpeed /= speedArr.size() diff --git a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy index a06345ad..d5901db1 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy @@ -91,6 +91,10 @@ class OptionsController { model.browseFiles = browseFiles settings.browseFiles = browseFiles + text = view.speedSmoothSecondsField.text + model.speedSmoothSeconds = Integer.valueOf(text) + settings.speedSmoothSeconds = Integer.valueOf(text) + String downloadLocation = model.downloadLocation settings.downloadLocation = new File(downloadLocation) diff --git a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy index 23f9274f..dbdd7057 100644 --- a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy @@ -18,6 +18,7 @@ class OptionsModel { @Observable String incompleteLocation @Observable boolean searchComments @Observable boolean browseFiles + @Observable int speedSmoothSeconds // i2p options @Observable String inboundLength @@ -60,6 +61,7 @@ class OptionsModel { incompleteLocation = settings.incompleteLocation.getAbsolutePath() searchComments = settings.searchComments browseFiles = settings.browseFiles + speedSmoothSeconds = settings.speedSmoothSeconds Core core = application.context.get("core") inboundLength = core.i2pOptions["inbound.length"] diff --git a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy index da23b83f..9c5f0605 100644 --- a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy @@ -39,6 +39,7 @@ class OptionsView { def shareHiddenCheckbox def searchCommentsCheckbox def browseFilesCheckbox + def speedSmoothSecondsField def inboundLengthField def inboundQuantityField @@ -149,9 +150,12 @@ class OptionsView { label(text : "Automatically Clear Finished Downloads", constraints: gbc(gridx: 0, gridy:6)) clearFinishedDownloadsCheckbox = checkBox(selected : bind {model.clearFinishedDownloads}, 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}, - constraints : gbc(gridx: 1, gridy : 7, anchor : GridBagConstraints.LINE_START)) + constraints : gbc(gridx: 1, gridy : 8, anchor : GridBagConstraints.LINE_START)) } bandwidth = builder.panel {