From 9df28552ad80e7829e89ace13248ce28583c5a9f Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 5 Jun 2019 00:22:36 +0100 Subject: [PATCH] try to load persisted files before hashing new ones --- cli/src/main/groovy/com/muwire/cli/Cli.groovy | 1 + core/src/main/groovy/com/muwire/core/Core.groovy | 2 +- .../main/groovy/com/muwire/core/files/HasherService.groovy | 6 +++++- .../groovy/com/muwire/core/files/PersisterService.groovy | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cli/src/main/groovy/com/muwire/cli/Cli.groovy b/cli/src/main/groovy/com/muwire/cli/Cli.groovy index 963d1c5c..7ce0fa22 100644 --- a/cli/src/main/groovy/com/muwire/cli/Cli.groovy +++ b/cli/src/main/groovy/com/muwire/cli/Cli.groovy @@ -45,6 +45,7 @@ class Cli { } else filesList = args[0] + Thread.sleep(1000) println "loading shared files from $filesList" core.eventBus.register(FileHashedEvent.class, new Object() { diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 11367a54..1e790155 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -199,7 +199,7 @@ public class Core { connectionEstablisher = new ConnectionEstablisher(eventBus, i2pConnector, props, connectionManager, hostCache) log.info("initializing hasher service") - hasherService = new HasherService(new FileHasher(), eventBus) + hasherService = new HasherService(new FileHasher(), eventBus, fileManager) eventBus.register(FileSharedEvent.class, hasherService) } diff --git a/core/src/main/groovy/com/muwire/core/files/HasherService.groovy b/core/src/main/groovy/com/muwire/core/files/HasherService.groovy index e5829086..96328909 100644 --- a/core/src/main/groovy/com/muwire/core/files/HasherService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/HasherService.groovy @@ -10,11 +10,13 @@ class HasherService { final FileHasher hasher final EventBus eventBus + final FileManager fileManager Executor executor - HasherService(FileHasher hasher, EventBus eventBus) { + HasherService(FileHasher hasher, EventBus eventBus, FileManager fileManager) { this.hasher = hasher this.eventBus = eventBus + this.fileManager = fileManager } void start() { @@ -22,6 +24,8 @@ class HasherService { } void onFileSharedEvent(FileSharedEvent evt) { + if (fileManager.fileToSharedFile.containsKey(evt.file)) + return executor.execute( { -> process(evt.file) } as Runnable) } diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy index 536291fc..7028d32b 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy @@ -34,7 +34,7 @@ class PersisterService extends Service { } void start() { - timer.schedule({load()} as TimerTask, 1000) + timer.schedule({load()} as TimerTask, 1) } void stop() {