diff --git a/core/src/main/groovy/com/muwire/core/Constants.groovy b/core/src/main/groovy/com/muwire/core/Constants.groovy index d09f572b..78437bfa 100644 --- a/core/src/main/groovy/com/muwire/core/Constants.groovy +++ b/core/src/main/groovy/com/muwire/core/Constants.groovy @@ -9,7 +9,5 @@ class Constants { public static final int MAX_HEADER_SIZE = 0x1 << 14 public static final int MAX_HEADERS = 16 - public static final float DOWNLOAD_SEQUENTIAL_RATIO = 0.8f - public static final String SPLIT_PATTERN = "[\\+\\-,\\.:;\\(\\)=_/\\\\\\!\\\"\\\'\\\$%\\|]" } diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 985bc78e..2a11b72b 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -173,7 +173,7 @@ public class Core { eventBus.register(SearchEvent.class, fileManager) log.info("initializing mesh manager") - MeshManager meshManager = new MeshManager(fileManager, home) + MeshManager meshManager = new MeshManager(fileManager, home, props) eventBus.register(SourceDiscoveredEvent.class, meshManager) log.info "initializing persistence service" diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 79202ce6..1225a7d1 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -18,6 +18,7 @@ class MuWireSettings { CrawlerResponse crawlerResponse boolean shareDownloadedFiles Set watchedDirectories + float downloadSequentialRatio MuWireSettings() { this(new Properties()) @@ -33,6 +34,7 @@ class MuWireSettings { downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","1")) updateCheckInterval = Integer.parseInt(props.getProperty("updateCheckInterval","24")) shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true")) + downloadSequentialRatio = Float.valueOf(props.getProperty("downloadSequentialRatio","0.8")) watchedDirectories = new HashSet<>() if (props.containsKey("watchedDirectories")) { @@ -52,6 +54,7 @@ class MuWireSettings { props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval)) props.setProperty("updateCheckInterval", String.valueOf(updateCheckInterval)) props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles)) + props.setProperty("downloadSequentialRatio", String.valueOf(downloadSequentialRatio)) if (!watchedDirectories.isEmpty()) { String encoded = watchedDirectories.stream(). diff --git a/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy b/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy index 5eb1d3ad..034a0905 100644 --- a/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy +++ b/core/src/main/groovy/com/muwire/core/mesh/MeshManager.groovy @@ -4,6 +4,7 @@ import java.util.stream.Collectors import com.muwire.core.Constants import com.muwire.core.InfoHash +import com.muwire.core.MuWireSettings import com.muwire.core.Persona import com.muwire.core.download.Pieces import com.muwire.core.download.SourceDiscoveredEvent @@ -21,10 +22,12 @@ class MeshManager { private final Map meshes = Collections.synchronizedMap(new HashMap<>()) private final FileManager fileManager private final File home + private final MuWireSettings settings - MeshManager(FileManager fileManager, File home) { + MeshManager(FileManager fileManager, File home, MuWireSettings settings) { this.fileManager = fileManager this.home = home + this.settings = settings load() } @@ -36,7 +39,7 @@ class MeshManager { synchronized(meshes) { if (meshes.containsKey(infoHash)) return meshes.get(infoHash) - Pieces pieces = new Pieces(nPieces, Constants.DOWNLOAD_SEQUENTIAL_RATIO) + Pieces pieces = new Pieces(nPieces, settings.downloadSequentialRatio) if (fileManager.rootToFiles.containsKey(infoHash)) { for (int i = 0; i < nPieces; i++) pieces.markDownloaded(i) @@ -83,7 +86,7 @@ class MeshManager { if (now - json.timestamp > EXPIRATION) return InfoHash infoHash = new InfoHash(Base64.decode(json.infoHash)) - Pieces pieces = new Pieces(json.nPieces, Constants.DOWNLOAD_SEQUENTIAL_RATIO) + Pieces pieces = new Pieces(json.nPieces, settings.downloadSequentialRatio) Mesh mesh = new Mesh(infoHash, pieces) json.sources.each { source ->