🔊 Log how much trust-all would reduce identity amount
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / freenet / wot / IdentityManagerImpl.kt
index b7a48dd..5f087c7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - IdentityManagerImpl.java - Copyright Â© 2010–2019 David Roden
+ * Sone - IdentityManagerImpl.kt - Copyright Â© 2010–2020 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@ package net.pterodactylus.sone.freenet.wot
 import com.google.common.eventbus.*
 import com.google.inject.*
 import net.pterodactylus.util.service.*
+import java.util.concurrent.TimeUnit.*
 import java.util.logging.*
 import java.util.logging.Logger.*
 
@@ -57,6 +58,13 @@ class IdentityManagerImpl @Inject constructor(
                        try {
                                val currentIdentities = identityLoader.loadIdentities()
 
+                               val onlyTrustedByAll = currentIdentities.mapValues { (ownIdentity, trustedIdentities) ->
+                                       trustedIdentities.filter { trustedIdentity ->
+                                               currentIdentities.all { trustedIdentity in it.value }
+                                       }
+                               }
+                               logger.log(Level.FINE, "Reduced (${currentIdentities.size},(${currentIdentities.values.joinToString { it.size.toString() }})) identities to (${onlyTrustedByAll.size},(${onlyTrustedByAll.values.joinToString { it.size.toString() }})).")
+
                                val identityChangeEventSender = IdentityChangeEventSender(eventBus, oldIdentities)
                                identityChangeEventSender.detectChanges(currentIdentities)
 
@@ -68,10 +76,12 @@ class IdentityManagerImpl @Inject constructor(
                                }
                        } catch (wote1: WebOfTrustException) {
                                logger.log(Level.WARNING, "WoT has disappeared!", wote1)
+                       } catch (e: Exception) {
+                               logger.log(Level.SEVERE, "Uncaught exception in IdentityManager thread!", e)
                        }
 
                        /* wait a minute before checking again. */
-                       sleep((60 * 1000).toLong())
+                       sleep(SECONDS.toMillis(60))
                }
        }