From 5407aa8616cb3afbdd6753dcb6e5808c470b3c70 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 22 Jul 2018 16:41:09 +0100 Subject: [PATCH] skeleton of hostcache client --- .../com/muwire/core/MuWireSettings.groovy | 7 +++ .../core/connection/ConnectionManager.groovy | 4 +- .../connection/LeafConnectionManager.groovy | 5 ++ .../UltrapeerConnectionManager.groovy | 5 ++ .../muwire/core/hostcache/CacheClient.groovy | 47 +++++++++++++++++++ .../core/hostcache/CrawlerResponse.java | 10 ++++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy create mode 100644 core/src/main/java/com/muwire/core/hostcache/CrawlerResponse.java diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index cfb883a4..2ae2e1fa 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -1,5 +1,7 @@ package com.muwire.core +import com.muwire.core.hostcache.CrawlerResponse + class MuWireSettings { boolean isLeaf() { @@ -11,4 +13,9 @@ class MuWireSettings { // TODO: implement true } + + CrawlerResponse getCrawlerResponse() { + // TODO: implement + CrawlerResponse.REGISTERED + } } diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy index 1ba49ace..0f9d6144 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy @@ -19,5 +19,7 @@ abstract class ConnectionManager { drop(e.destination) } - abstract void drop(Destination d); + abstract void drop(Destination d) + + abstract boolean hasConnection() } diff --git a/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy index f972dae5..6ce4babc 100644 --- a/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy @@ -19,4 +19,9 @@ class LeafConnectionManager extends ConnectionManager { } + @Override + public boolean hasConnection() { + // TODO implement + false + } } 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 ae33493e..cc760f20 100644 --- a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy @@ -19,4 +19,9 @@ class UltrapeerConnectionManager extends ConnectionManager { } + @Override + public boolean hasConnection() { + // TODO: implement + false + } } diff --git a/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy b/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy new file mode 100644 index 00000000..4ca583d8 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy @@ -0,0 +1,47 @@ +package com.muwire.core.hostcache + +import com.muwire.core.EventBus +import com.muwire.core.MuWireSettings +import com.muwire.core.connection.ConnectionManager + +import net.i2p.client.I2PSession + +class CacheClient { + + final EventBus eventBus + final HostCache cache + final ConnectionManager manager + final I2PSession session + final long interval + final MuWireSettings settings + final Timer timer + + public CacheClient(EventBus eventBus, HostCache cache, + ConnectionManager manager, I2PSession session, + MuWireSettings settings, long interval) { + this.eventBus = eventBus + this.cache = cache + this.manager = manager + this.session = session + this.settings = settings + this.timer = new Timer("hostcache-client",true) + } + + void start() { + timer.schedule({queryIfNeeded()} as TimerTask, 1, interval) + } + + void stop() { + timer.cancel() + } + + private void queryIfNeeded() { + if (manager.hasConnection()) + return + if (!cache.getHosts(1).isEmpty()) + return + + + } + +} diff --git a/core/src/main/java/com/muwire/core/hostcache/CrawlerResponse.java b/core/src/main/java/com/muwire/core/hostcache/CrawlerResponse.java new file mode 100644 index 00000000..9a08eccb --- /dev/null +++ b/core/src/main/java/com/muwire/core/hostcache/CrawlerResponse.java @@ -0,0 +1,10 @@ +package com.muwire.core.hostcache; + +/** + * Whether this host should answer to crawler queries + * @author zab + * + */ +public enum CrawlerResponse { + ALL, REGISTERED, NONE +}