From c73a821c67a436e1af681081596b749becaebb8a Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 23 Sep 2020 11:30:20 +0100 Subject: [PATCH] put verified sources in the responder cache as well --- core/src/main/groovy/com/muwire/core/Core.groovy | 1 + .../muwire/core/connection/UltrapeerConnectionManager.groovy | 2 +- .../main/groovy/com/muwire/core/search/ResponderCache.groovy | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index d72bd471..a9eefa12 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -313,6 +313,7 @@ public class Core { log.info("initializing responder cache") ResponderCache responderCache = new ResponderCache(props.responderCacheSize) eventBus.register(UIResultBatchEvent.class, responderCache) + eventBus.register(SourceVerifiedEvent.class, responderCache) log.info("initializing connection manager") diff --git a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy index d7759b31..d3cc9e26 100644 --- a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy @@ -56,7 +56,7 @@ class UltrapeerConnectionManager extends ConnectionManager { peerConnections.values().each { // 1. do not send query back to originator // 2. if firstHop forward to everyone - // 3. otherwise to everyone who has recently responded to us + randomized sqrt of neighbors + // 3. otherwise to everyone who has recently responded/transferred to us + randomized sqrt of neighbors if (e.getReceivedOn() != it.getEndpoint().getDestination() && (e.firstHop || responderCache.hasResponded(it.endpoint.destination) || diff --git a/core/src/main/groovy/com/muwire/core/search/ResponderCache.groovy b/core/src/main/groovy/com/muwire/core/search/ResponderCache.groovy index 1d5deeca..c3ef2d45 100644 --- a/core/src/main/groovy/com/muwire/core/search/ResponderCache.groovy +++ b/core/src/main/groovy/com/muwire/core/search/ResponderCache.groovy @@ -1,5 +1,6 @@ package com.muwire.core.search +import com.muwire.core.download.SourceVerifiedEvent import com.muwire.core.util.FixedSizeFIFOSet import net.i2p.data.Destination @@ -19,6 +20,10 @@ class ResponderCache { cache.add(e.results[0].sender.destination) } + synchronized void onSourceVerifiedEvent(SourceVerifiedEvent e) { + cache.add(e.source) + } + synchronized boolean hasResponded(Destination d) { cache.contains(d) }