From f0aaa83b7f96f016bd449108f0a8a53e865f22ba Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 1 Jun 2020 13:14:33 +0100 Subject: [PATCH] clean up most of noise on console when running without a log file --- core/build.gradle | 2 +- .../main/groovy/com/muwire/core/Core.groovy | 24 +++++++++++-------- .../connection/ConnectionEstablisher.groovy | 9 +++++++ .../UltrapeerConnectionManager.groovy | 4 ++-- .../muwire/core/hostcache/CacheClient.groovy | 3 ++- .../core/tracker/TrackerResponder.groovy | 6 ++++- .../muwire/core/update/UpdateClient.groovy | 5 +++- gui/griffon-app/lifecycle/Initialize.groovy | 9 ------- .../groovy/com/muwire/gui/Launcher.groovy | 16 ++++++++++++- 9 files changed, 52 insertions(+), 26 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 68245bb7..3f083f1e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -7,7 +7,7 @@ plugins { dependencies { api "net.i2p:i2p:${i2pVersion}" api "net.i2p:router:${i2pVersion}" - implementation "net.i2p.client:mstreaming:${i2pVersion}" + api "net.i2p.client:mstreaming:${i2pVersion}" implementation "net.i2p.client:streaming:${i2pVersion}" testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2' diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 82fc59b0..258f1fcb 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -114,6 +114,7 @@ public class Core { final MuWireSettings muOptions final I2PSession i2pSession; + private I2PSocketManager i2pSocketManager final TrustService trustService final TrustSubscriber trustSubscriber private final PersisterService persisterService @@ -220,14 +221,13 @@ public class Core { // options like tunnel length and quantity - I2PSocketManager socketManager keyDat.withInputStream { - socketManager = new I2PSocketManagerFactory().createDisconnectedManager(it, i2pOptions["i2cp.tcp.host"], i2pOptions["i2cp.tcp.port"].toInteger(), i2pOptions) + i2pSocketManager = new I2PSocketManagerFactory().createDisconnectedManager(it, i2pOptions["i2cp.tcp.host"], i2pOptions["i2cp.tcp.port"].toInteger(), i2pOptions) } - socketManager.getDefaultOptions().setReadTimeout(60000) - socketManager.getDefaultOptions().setConnectTimeout(30000) - socketManager.addDisconnectListener({eventBus.publish(new RouterDisconnectedEvent())} as DisconnectListener) - i2pSession = socketManager.getSession() + i2pSocketManager.getDefaultOptions().setReadTimeout(60000) + i2pSocketManager.getDefaultOptions().setConnectTimeout(30000) + i2pSocketManager.addDisconnectListener({eventBus.publish(new RouterDisconnectedEvent())} as DisconnectListener) + i2pSession = i2pSocketManager.getSession() def destination = new Destination() spk = new SigningPrivateKey(Constants.SIG_TYPE) @@ -327,7 +327,7 @@ public class Core { log.info("running as plugin, not initializing update client") log.info("initializing connector") - I2PConnector i2pConnector = new I2PConnector(socketManager) + I2PConnector i2pConnector = new I2PConnector(i2pSocketManager) log.info("initializing certificate client") CertificateClient certificateClient = new CertificateClient(eventBus, i2pConnector) @@ -393,7 +393,7 @@ public class Core { } log.info("initializing acceptor") - I2PAcceptor i2pAcceptor = new I2PAcceptor(socketManager) + I2PAcceptor i2pAcceptor = new I2PAcceptor(i2pSocketManager) connectionAcceptor = new ConnectionAcceptor(eventBus, connectionManager, props, i2pAcceptor, hostCache, trustService, searchManager, uploadManager, fileManager, connectionEstablisher, certificateManager, chatServer) @@ -501,8 +501,12 @@ public class Core { trackerResponder.stop() log.info("shutting down connection manager") connectionManager.shutdown() - log.info("killing i2p session") - i2pSession.destroySession() + if (updateClient != null) { + log.info("shutting down update client") + updateClient.stop() + } + log.info("killing socket manager") + i2pSocketManager.destroySocketManager() if (router != null) { log.info("shutting down embedded router") router.shutdown(0) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy index f61cbc3b..da5e51d4 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionEstablisher.groovy @@ -34,6 +34,8 @@ class ConnectionEstablisher { final ExecutorService executor, closer final Set inProgress = new ConcurrentHashSet() + + private volatile boolean shutdown ConnectionEstablisher(){} @@ -60,12 +62,15 @@ class ConnectionEstablisher { } void stop() { + shutdown = true timer.cancel() executor.shutdownNow() closer.shutdownNow() } private void connectIfNeeded() { + if (shutdown) + return if (!connectionManager.needsConnections()) return if (inProgress.size() >= CONCURRENT) @@ -89,6 +94,8 @@ class ConnectionEstablisher { } private void connect(Destination toTry) { + if (shutdown) + return log.info("starting connect to ${toTry.toBase32()}") try { def endpoint = i2pConnector.connect(toTry) @@ -123,6 +130,8 @@ class ConnectionEstablisher { } private void fail(Endpoint endpoint) { + if (shutdown) + return if (!closer.isShutdown()) { closer.execute { endpoint.close() 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 4aaa405b..ef9736f6 100644 --- a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy @@ -105,8 +105,8 @@ class UltrapeerConnectionManager extends ConnectionManager { @Override void shutdown() { super.shutdown() - peerConnections.values().stream().parallel().forEach({v -> v.close()}) - leafConnections.values().stream().parallel().forEach({v -> v.close()}) + peerConnections.values().stream().forEach({v -> v.close()}) + leafConnections.values().stream().forEach({v -> v.close()}) peerConnections.clear() leafConnections.clear() } diff --git a/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy b/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy index 64056486..83d03e06 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy @@ -127,7 +127,8 @@ class CacheClient { @Override public void disconnected(I2PSession session) { - log.severe "I2P session disconnected" + if (!stopped.get()) + log.severe "Cache client I2P session disconnected" } @Override diff --git a/core/src/main/groovy/com/muwire/core/tracker/TrackerResponder.groovy b/core/src/main/groovy/com/muwire/core/tracker/TrackerResponder.groovy index c33c2e70..f006a8b1 100644 --- a/core/src/main/groovy/com/muwire/core/tracker/TrackerResponder.groovy +++ b/core/src/main/groovy/com/muwire/core/tracker/TrackerResponder.groovy @@ -42,6 +42,8 @@ class TrackerResponder { private static final long UUID_LIFETIME = 10 * 60 * 1000 + private volatile boolean shutdown + TrackerResponder(I2PSession i2pSession, MuWireSettings muSettings, FileManager fileManager, DownloadManager downloadManager, MeshManager meshManager, TrustService trustService, @@ -61,6 +63,7 @@ class TrackerResponder { } void stop() { + shutdown = true expireTimer.cancel() } @@ -200,7 +203,8 @@ class TrackerResponder { @Override public void disconnected(I2PSession session) { - log.severe("session disconnected") + if (!shutdown) + log.severe("Tracker Responder session disconnected") } @Override diff --git a/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy b/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy index 87f62c82..b0305c75 100644 --- a/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy +++ b/core/src/main/groovy/com/muwire/core/update/UpdateClient.groovy @@ -49,6 +49,7 @@ class UpdateClient { private volatile boolean updateDownloading private volatile String text + private volatile boolean shutdown UpdateClient(EventBus eventBus, I2PSession session, String myVersion, MuWireSettings settings, FileManager fileManager, Persona me, SigningPrivateKey spk) { @@ -69,6 +70,7 @@ class UpdateClient { } void stop() { + shutdown = true timer.cancel() } @@ -199,7 +201,8 @@ class UpdateClient { @Override public void disconnected(I2PSession session) { - log.severe("I2P session disconnected") + if (!shutdown) + log.severe("I2P session disconnected") } @Override diff --git a/gui/griffon-app/lifecycle/Initialize.groovy b/gui/griffon-app/lifecycle/Initialize.groovy index 1963971b..a21173c8 100644 --- a/gui/griffon-app/lifecycle/Initialize.groovy +++ b/gui/griffon-app/lifecycle/Initialize.groovy @@ -40,15 +40,6 @@ class Initialize extends AbstractLifecycleHandler { @Override void execute() { - if (System.getProperty("java.util.logging.config.file") == null) { - log.info("No config file specified, so turning off most logging") - def names = LogManager.getLogManager().getLoggerNames() - while(names.hasMoreElements()) { - def name = names.nextElement() - LogManager.getLogManager().getLogger(name).setLevel(Level.SEVERE) - } - } - System.setProperty("apple.eawt.quitStrategy", "CLOSE_ALL_WINDOWS"); if (SystemTray.isSupported() && (SystemVersion.isMac() || SystemVersion.isWindows())) { diff --git a/gui/src/main/groovy/com/muwire/gui/Launcher.groovy b/gui/src/main/groovy/com/muwire/gui/Launcher.groovy index 6661434f..049509e4 100644 --- a/gui/src/main/groovy/com/muwire/gui/Launcher.groovy +++ b/gui/src/main/groovy/com/muwire/gui/Launcher.groovy @@ -1,10 +1,24 @@ package com.muwire.gui -import griffon.swing.SwingGriffonApplication +import java.util.logging.Level +import java.util.logging.LogManager +import griffon.swing.SwingGriffonApplication +import groovy.util.logging.Log + +@Log class Launcher { public static void main(String[] args) { + if (System.getProperty("java.util.logging.config.file") == null) { + log.info("No config file specified, so turning off most logging") + def names = LogManager.getLogManager().getLoggerNames() + while(names.hasMoreElements()) { + def name = names.nextElement() + LogManager.getLogManager().getLogger(name).setLevel(Level.SEVERE) + } + } + SwingGriffonApplication.main(args) } }