mirror of https://github.com/zlatinb/muwire
make download sequential ratio a property
parent
b2eb2d2755
commit
f11d461ec0
|
@ -9,7 +9,5 @@ class Constants {
|
||||||
public static final int MAX_HEADER_SIZE = 0x1 << 14
|
public static final int MAX_HEADER_SIZE = 0x1 << 14
|
||||||
public static final int MAX_HEADERS = 16
|
public static final int MAX_HEADERS = 16
|
||||||
|
|
||||||
public static final float DOWNLOAD_SEQUENTIAL_RATIO = 0.8f
|
|
||||||
|
|
||||||
public static final String SPLIT_PATTERN = "[\\+\\-,\\.:;\\(\\)=_/\\\\\\!\\\"\\\'\\\$%\\|]"
|
public static final String SPLIT_PATTERN = "[\\+\\-,\\.:;\\(\\)=_/\\\\\\!\\\"\\\'\\\$%\\|]"
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class Core {
|
||||||
eventBus.register(SearchEvent.class, fileManager)
|
eventBus.register(SearchEvent.class, fileManager)
|
||||||
|
|
||||||
log.info("initializing mesh manager")
|
log.info("initializing mesh manager")
|
||||||
MeshManager meshManager = new MeshManager(fileManager, home)
|
MeshManager meshManager = new MeshManager(fileManager, home, props)
|
||||||
eventBus.register(SourceDiscoveredEvent.class, meshManager)
|
eventBus.register(SourceDiscoveredEvent.class, meshManager)
|
||||||
|
|
||||||
log.info "initializing persistence service"
|
log.info "initializing persistence service"
|
||||||
|
|
|
@ -18,6 +18,7 @@ class MuWireSettings {
|
||||||
CrawlerResponse crawlerResponse
|
CrawlerResponse crawlerResponse
|
||||||
boolean shareDownloadedFiles
|
boolean shareDownloadedFiles
|
||||||
Set<String> watchedDirectories
|
Set<String> watchedDirectories
|
||||||
|
float downloadSequentialRatio
|
||||||
|
|
||||||
MuWireSettings() {
|
MuWireSettings() {
|
||||||
this(new Properties())
|
this(new Properties())
|
||||||
|
@ -33,6 +34,7 @@ class MuWireSettings {
|
||||||
downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","1"))
|
downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","1"))
|
||||||
updateCheckInterval = Integer.parseInt(props.getProperty("updateCheckInterval","24"))
|
updateCheckInterval = Integer.parseInt(props.getProperty("updateCheckInterval","24"))
|
||||||
shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true"))
|
shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true"))
|
||||||
|
downloadSequentialRatio = Float.valueOf(props.getProperty("downloadSequentialRatio","0.8"))
|
||||||
|
|
||||||
watchedDirectories = new HashSet<>()
|
watchedDirectories = new HashSet<>()
|
||||||
if (props.containsKey("watchedDirectories")) {
|
if (props.containsKey("watchedDirectories")) {
|
||||||
|
@ -52,6 +54,7 @@ class MuWireSettings {
|
||||||
props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval))
|
props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval))
|
||||||
props.setProperty("updateCheckInterval", String.valueOf(updateCheckInterval))
|
props.setProperty("updateCheckInterval", String.valueOf(updateCheckInterval))
|
||||||
props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles))
|
props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles))
|
||||||
|
props.setProperty("downloadSequentialRatio", String.valueOf(downloadSequentialRatio))
|
||||||
|
|
||||||
if (!watchedDirectories.isEmpty()) {
|
if (!watchedDirectories.isEmpty()) {
|
||||||
String encoded = watchedDirectories.stream().
|
String encoded = watchedDirectories.stream().
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.stream.Collectors
|
||||||
|
|
||||||
import com.muwire.core.Constants
|
import com.muwire.core.Constants
|
||||||
import com.muwire.core.InfoHash
|
import com.muwire.core.InfoHash
|
||||||
|
import com.muwire.core.MuWireSettings
|
||||||
import com.muwire.core.Persona
|
import com.muwire.core.Persona
|
||||||
import com.muwire.core.download.Pieces
|
import com.muwire.core.download.Pieces
|
||||||
import com.muwire.core.download.SourceDiscoveredEvent
|
import com.muwire.core.download.SourceDiscoveredEvent
|
||||||
|
@ -21,10 +22,12 @@ class MeshManager {
|
||||||
private final Map<InfoHash, Mesh> meshes = Collections.synchronizedMap(new HashMap<>())
|
private final Map<InfoHash, Mesh> meshes = Collections.synchronizedMap(new HashMap<>())
|
||||||
private final FileManager fileManager
|
private final FileManager fileManager
|
||||||
private final File home
|
private final File home
|
||||||
|
private final MuWireSettings settings
|
||||||
|
|
||||||
MeshManager(FileManager fileManager, File home) {
|
MeshManager(FileManager fileManager, File home, MuWireSettings settings) {
|
||||||
this.fileManager = fileManager
|
this.fileManager = fileManager
|
||||||
this.home = home
|
this.home = home
|
||||||
|
this.settings = settings
|
||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +39,7 @@ class MeshManager {
|
||||||
synchronized(meshes) {
|
synchronized(meshes) {
|
||||||
if (meshes.containsKey(infoHash))
|
if (meshes.containsKey(infoHash))
|
||||||
return meshes.get(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)) {
|
if (fileManager.rootToFiles.containsKey(infoHash)) {
|
||||||
for (int i = 0; i < nPieces; i++)
|
for (int i = 0; i < nPieces; i++)
|
||||||
pieces.markDownloaded(i)
|
pieces.markDownloaded(i)
|
||||||
|
@ -83,7 +86,7 @@ class MeshManager {
|
||||||
if (now - json.timestamp > EXPIRATION)
|
if (now - json.timestamp > EXPIRATION)
|
||||||
return
|
return
|
||||||
InfoHash infoHash = new InfoHash(Base64.decode(json.infoHash))
|
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)
|
Mesh mesh = new Mesh(infoHash, pieces)
|
||||||
json.sources.each { source ->
|
json.sources.each { source ->
|
||||||
|
|
Loading…
Reference in New Issue