📄 Update year in copyright line
[jSite.git] / src / main / java / de / todesbaum / jsite / application / UpdateChecker.java
index c49f166..eec0bcc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jSite - UpdateChecker.java - Copyright Â© 2008–2012 David Roden
+ * jSite - UpdateChecker.java - Copyright Â© 2008–2019 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
@@ -26,7 +26,7 @@ import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import de.todesbaum.jsite.main.Main;
+import net.pterodactylus.util.io.Closer;
 import de.todesbaum.jsite.main.Version;
 import de.todesbaum.util.freenet.fcp2.Client;
 import de.todesbaum.util.freenet.fcp2.ClientGet;
@@ -35,7 +35,6 @@ import de.todesbaum.util.freenet.fcp2.Message;
 import de.todesbaum.util.freenet.fcp2.Persistence;
 import de.todesbaum.util.freenet.fcp2.ReturnType;
 import de.todesbaum.util.freenet.fcp2.Verbosity;
-import de.todesbaum.util.io.Closer;
 
 /**
  * Checks for newer versions of jSite.
@@ -51,10 +50,10 @@ public class UpdateChecker implements Runnable {
        private static int counter = 0;
 
        /** The edition for the update check URL. */
-       private static final int UPDATE_EDITION = 17;
+       private static final int UPDATE_EDITION = 12;
 
        /** The URL for update checks. */
-       private static final String UPDATE_KEY = "USK@e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE";
+       private static final String UPDATE_KEY = "USK@1waTsw46L9-JEQ8yX1khjkfHcn--g0MlMsTlYHax9zQ,oYyxr5jyFnaTsVGDQWk9e3ddOWGKnqEASxAk08MHT2Y,AQACAAE";
 
        /** Object used for synchronization. */
        private final Object syncObject = new Object();
@@ -69,7 +68,7 @@ public class UpdateChecker implements Runnable {
        private int lastUpdateEdition = UPDATE_EDITION;
 
        /** Last found version. */
-       private Version lastVersion = Main.getVersion();
+       private Version lastVersion;
 
        /** The freenet interface. */
        private final Freenet7Interface freenetInterface;
@@ -81,8 +80,9 @@ public class UpdateChecker implements Runnable {
         * @param freenetInterface
         *            The freenet interface
         */
-       public UpdateChecker(Freenet7Interface freenetInterface) {
+       public UpdateChecker(Freenet7Interface freenetInterface, Version currentVersion) {
                this.freenetInterface = freenetInterface;
+               this.lastVersion = currentVersion;
        }
 
        //
@@ -180,7 +180,7 @@ public class UpdateChecker implements Runnable {
         *            The edition number
         * @return The URI for the update file for the given edition
         */
-       private String constructUpdateKey(int edition) {
+       private static String constructUpdateKey(int edition) {
                return UPDATE_KEY + "/jSite/" + edition + "/jSite.properties";
        }
 
@@ -191,18 +191,33 @@ public class UpdateChecker implements Runnable {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void run() {
-               Connection connection = freenetInterface.getConnection("jSite-" + ++counter + "-UpdateChecker");
-               try {
-                       connection.connect();
-               } catch (IOException e1) {
-                       e1.printStackTrace();
-               }
-               Client client = new Client(connection);
-               boolean checkNow = false;
                int currentEdition = lastUpdateEdition;
                while (!shouldStop()) {
-                       checkNow = false;
+
+                       /* try to connect. */
+                       Client client;
+                       while (true) {
+                               Connection connection = freenetInterface.getConnection("jSite-" + ++counter + "-UpdateChecker");
+                               try {
+                                       connection.connect();
+                                       logger.log(Level.INFO, "Connected to " + freenetInterface.getNode() + ".");
+                                       client = new Client(connection);
+                                       break;
+                               } catch (IOException ioe1) {
+                                       logger.log(Level.INFO, "Could not connect to " + freenetInterface.getNode() + ".", ioe1);
+                               }
+                               if (!connection.isConnected()) {
+                                       try {
+                                               Thread.sleep(60 * 1000);
+                                       } catch (InterruptedException ie1) {
+                                               /* ignore, we’re looping. */
+                                       }
+                               }
+                       }
+
+                       boolean checkNow = false;
                        logger.log(Level.FINE, "Trying " + constructUpdateKey(currentEdition));
                        ClientGet clientGet = new ClientGet("get-update-key");
                        clientGet.setUri(constructUpdateKey(currentEdition));