searches by hash

pull/24/head
Zlatin Balevsky 2019-10-26 05:14:04 +01:00
parent 9cdabb51d1
commit b308ac2f37
2 changed files with 32 additions and 5 deletions

View File

@ -25,6 +25,8 @@ import com.muwire.core.files.FileLoadedEvent
import com.muwire.core.files.FileUnsharedEvent
import com.muwire.core.hostcache.HostDiscoveredEvent
import net.i2p.data.Base64
class MainWindowView extends BasicWindow {
private final Core core
@ -191,6 +193,12 @@ class MainWindowView extends BasicWindow {
private void search() {
String query = searchTextBox.getText()
query = query.trim()
if (query.length() == 0)
return
if (query.length() > 128)
query = query.substring(0, 128)
SearchModel model = new SearchModel(query, core, textGUI.getGUIThread())
textGUI.addWindowAndWait(new SearchView(model,core, textGUI, sizeForTables()))
}

View File

@ -7,6 +7,9 @@ import com.muwire.core.search.QueryEvent
import com.muwire.core.search.SearchEvent
import com.muwire.core.search.UIResultBatchEvent
import com.muwire.core.search.UIResultEvent
import net.i2p.data.Base64
import com.googlecode.lanterna.gui2.TextGUIThread
import com.googlecode.lanterna.gui2.table.TableModel
class SearchModel {
@ -25,12 +28,28 @@ class SearchModel {
core.eventBus.register(UIResultBatchEvent.class, this)
def replaced = query.toLowerCase().trim().replaceAll(SplitPattern.SPLIT_PATTERN, " ")
def terms = replaced.split(" ")
def nonEmpty = []
terms.each { if (it.length() > 0) nonEmpty << it }
def searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : UUID.randomUUID(), oobInfohash: true,
boolean hashSearch = false
byte [] root = null
if (query.length() == 44 && query.indexOf(" ") < 0) {
try {
root = Base64.decode(query)
hashSearch = true
} catch (Exception e) {
// not hash search
}
}
def searchEvent
if (hashSearch) {
searchEvent = new SearchEvent(searchHash : root, uuid : UUID.randomUUID(), oobInfohash : true, compressedResults : true)
} else {
def replaced = query.toLowerCase().trim().replaceAll(SplitPattern.SPLIT_PATTERN, " ")
def terms = replaced.split(" ")
def nonEmpty = []
terms.each { if (it.length() > 0) nonEmpty << it }
searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : UUID.randomUUID(), oobInfohash: true,
searchComments : core.muOptions.searchComments, compressedResults : true)
}
boolean firstHop = core.muOptions.allowUntrusted || core.muOptions.searchExtraHop
core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : firstHop,
replyTo: core.me.destination, receivedOn: core.me.destination,