From b9ea0128cd709d1e125fafb82ffb40ba571cf270 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 8 Jun 2019 02:44:49 +0100 Subject: [PATCH] add oobInfohash flag, filter results by that flag --- .../com/muwire/core/connection/Connection.groovy | 7 ++++++- .../groovy/com/muwire/core/files/FileManager.groovy | 13 +++++++++++++ .../com/muwire/core/search/SearchEvent.groovy | 3 ++- .../com/muwire/gui/MainFrameController.groovy | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy index bea7e3ff..64963c99 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -127,6 +127,7 @@ abstract class Connection implements Closeable { query.uuid = e.searchEvent.getUuid() query.firstHop = e.firstHop query.keywords = e.searchEvent.getSearchTerms() + query.oobInfohash = e.searchEvent.oobInfohash if (e.searchEvent.searchHash != null) query.infohash = Base64.encode(e.searchEvent.searchHash) query.replyTo = e.replyTo.toBase64() @@ -183,10 +184,14 @@ abstract class Connection implements Closeable { } } + boolean oob = false + if (search.oobInfohash != null) + oob = search.oobInfohash SearchEvent searchEvent = new SearchEvent(searchTerms : search.keywords, searchHash : infohash, - uuid : uuid) + uuid : uuid, + oobInfohash : oob) QueryEvent event = new QueryEvent ( searchEvent : searchEvent, replyTo : replyTo, originator : originator, diff --git a/core/src/main/groovy/com/muwire/core/files/FileManager.groovy b/core/src/main/groovy/com/muwire/core/files/FileManager.groovy index 1d10312b..de3d79f4 100644 --- a/core/src/main/groovy/com/muwire/core/files/FileManager.groovy +++ b/core/src/main/groovy/com/muwire/core/files/FileManager.groovy @@ -105,6 +105,7 @@ class FileManager { if (e.searchHash != null) { Set found found = rootToFiles.get new InfoHash(e.searchHash) + found = filter(found, e.oobInfohash) if (found != null && !found.isEmpty()) re = new ResultsEvent(results: found.asList(), uuid: e.uuid) } else { @@ -113,6 +114,7 @@ class FileManager { names.each { files.addAll nameToFiles.getOrDefault(it, []) } Set sharedFiles = new HashSet<>() files.each { sharedFiles.add fileToSharedFile[it] } + files = filter(sharedFiles, e.oobInfohash) if (!sharedFiles.isEmpty()) re = new ResultsEvent(results: sharedFiles.asList(), uuid: e.uuid) @@ -121,4 +123,15 @@ class FileManager { if (re != null) eventBus.publish(re) } + + private static Set filter(Set files, boolean oob) { + if (!oob) + return files + Set rv = new HashSet<>() + files.each { + if (it.getPieceSize() != 0) + rv.add(it) + } + rv + } } diff --git a/core/src/main/groovy/com/muwire/core/search/SearchEvent.groovy b/core/src/main/groovy/com/muwire/core/search/SearchEvent.groovy index c8c121b9..aba43a5b 100644 --- a/core/src/main/groovy/com/muwire/core/search/SearchEvent.groovy +++ b/core/src/main/groovy/com/muwire/core/search/SearchEvent.groovy @@ -8,11 +8,12 @@ class SearchEvent extends Event { List searchTerms byte [] searchHash UUID uuid + boolean oobInfohash String toString() { def infoHash = null if (searchHash != null) infoHash = new InfoHash(searchHash) - "searchTerms: $searchTerms searchHash:$infoHash, uuid:$uuid" + "searchTerms: $searchTerms searchHash:$infoHash, uuid:$uuid oobInfohash:$oobInfohash" } } diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index 5d5c3e48..2087aecd 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -52,7 +52,7 @@ class MainFrameController { // this can be improved a lot def replaced = search.toLowerCase().trim().replaceAll(Constants.SPLIT_PATTERN, " ") def terms = replaced.split(" ") - searchEvent = new SearchEvent(searchTerms : terms, uuid : uuid) + searchEvent = new SearchEvent(searchTerms : terms, uuid : uuid, oobInfohash: true) } core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : true, replyTo: core.me.destination, receivedOn: core.me.destination,