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 1ac28275..a54c79b2 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -6,6 +6,7 @@ import java.util.concurrent.atomic.AtomicBoolean import java.util.logging.Level import com.muwire.core.EventBus +import com.muwire.core.Persona import com.muwire.core.hostcache.HostCache import com.muwire.core.hostcache.HostDiscoveredEvent import com.muwire.core.search.QueryEvent @@ -14,6 +15,7 @@ import com.muwire.core.trust.TrustLevel import com.muwire.core.trust.TrustService import groovy.util.logging.Log +import net.i2p.data.Base64 import net.i2p.data.Destination @Log @@ -122,6 +124,8 @@ abstract class Connection implements Closeable { query.firstHop = e.firstHop query.keywords = e.searchEvent.getSearchTerms() query.replyTo = e.replyTo.toBase64() + if (e.originator != null) + query.originator = e.originator.toBase64() messages.put(query) } @@ -157,11 +161,22 @@ abstract class Connection implements Closeable { } // TODO: add option to respond only to trusted peers + Persona originator = null + if (search.originator != null) { + originator = new Persona(new ByteArrayInputStream(Base64.decode(search.originator))) + if (originator.destination != replyTo) { + log.info("originator doesn't match destination") + return + } + } + + SearchEvent searchEvent = new SearchEvent(searchTerms : search.keywords, searchHash : search.infohash, uuid : uuid) QueryEvent event = new QueryEvent ( searchEvent : searchEvent, replyTo : replyTo, + originator : originator, receivedOn : endpoint.destination, firstHop : search.firstHop ) eventBus.publish(event) diff --git a/core/src/main/groovy/com/muwire/core/search/QueryEvent.groovy b/core/src/main/groovy/com/muwire/core/search/QueryEvent.groovy index d88d8171..378f5306 100644 --- a/core/src/main/groovy/com/muwire/core/search/QueryEvent.groovy +++ b/core/src/main/groovy/com/muwire/core/search/QueryEvent.groovy @@ -1,6 +1,7 @@ package com.muwire.core.search import com.muwire.core.Event +import com.muwire.core.Persona import net.i2p.data.Destination @@ -9,6 +10,7 @@ class QueryEvent extends Event { SearchEvent searchEvent boolean firstHop Destination replyTo + Persona originator Destination receivedOn } diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index c65796e8..e090cba5 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -47,7 +47,8 @@ class MainFrameController { def terms = search.toLowerCase().trim().split(Constants.SPLIT_PATTERN) def searchEvent = new SearchEvent(searchTerms : terms, uuid : uuid) core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : true, - replyTo: core.me.destination, receivedOn: core.me.destination)) + replyTo: core.me.destination, receivedOn: core.me.destination, + originator : core.me)) } private def selectedResult() { diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 22689d13..de54352b 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -8,6 +8,7 @@ import javax.swing.JTable import com.muwire.core.Core import com.muwire.core.InfoHash +import com.muwire.core.Persona import com.muwire.core.connection.ConnectionAttemptStatus import com.muwire.core.connection.ConnectionEvent import com.muwire.core.connection.DisconnectionEvent @@ -228,7 +229,7 @@ class MainFrameModel { if (search.trim().size() == 0) return runInsideUIAsync { - searches.addFirst(new IncomingSearch(search : search, replyTo : e.replyTo)) + searches.addFirst(new IncomingSearch(search : search, replyTo : e.replyTo, originator : e.originator)) while(searches.size() > 200) searches.removeLast() JTable table = builder.getVariable("searches-table") @@ -239,5 +240,6 @@ class MainFrameModel { class IncomingSearch { String search Destination replyTo + Persona originator } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index ad4c4a94..38132e3e 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -178,7 +178,13 @@ class MainFrameView { table(id : "searches-table") { tableModel(list : model.searches) { closureColumn(header : "Keywords", type : String, read : { it.search }) - closureColumn(header : "From", type : String, read : {it.replyTo.toBase32()}) + closureColumn(header : "From", type : String, read : { + if (it.originator != null) { + return it.originator.getHumanReadableName() + } else { + return it.replyTo.toBase32() + } + }) } } }