Create message digest in core and hash fetched URLs.
[arachne.git] / src / net / pterodactylus / arachne / core / Core.java
index ad438b1..f6b050d 100644 (file)
@@ -5,6 +5,7 @@ package net.pterodactylus.arachne.core;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Executor;
@@ -47,6 +48,20 @@ public class Core extends AbstractService {
        private final List<Page> pages = new ArrayList<Page>();
 
        //
+       // ACCESSORS
+       //
+
+       /**
+        * Sets the host name of the node.
+        *
+        * @param nodeHost
+        *            The node’s host name
+        */
+       public void setNodeHost(String nodeHost) {
+               this.nodeHost = nodeHost;
+       }
+
+       //
        // ACTIONS
        //
 
@@ -150,8 +165,14 @@ public class Core extends AbstractService {
                                logger.log(Level.INFO, "Skipping “" + nextPage + "”.");
                                continue;
                        }
-                       URLFetcher urlFetcher = new URLFetcher(this, nextURL);
-                       urlFetcherExecutor.execute(urlFetcher);
+                       URLFetcher urlFetcher;
+                       try {
+                               logger.log(Level.INFO, "Fetching “" + nextURL + "”...");
+                               urlFetcher = new URLFetcher(this, nextURL);
+                               urlFetcherExecutor.execute(urlFetcher);
+                       } catch (NoSuchAlgorithmException nsae1) {
+                               logger.log(Level.SEVERE, "Could not get “SHA-256” message digest!", nsae1);
+                       }
                }
        }
 
@@ -171,7 +192,7 @@ public class Core extends AbstractService {
         * @return The joined path
         */
        private String createPath(String[] pathComponents, int index) {
-               Validation.begin().isNotNull("pathComponents", pathComponents).check().isLess("index", index, pathComponents.length).check();
+               Validation.begin().isNotNull("pathComponents", pathComponents).check().isLessOrEqual("index", index, pathComponents.length).check();
                StringBuilder path = new StringBuilder();
                for (int pathComponentIndex = index; pathComponentIndex < pathComponents.length; pathComponentIndex++) {
                        if (path.length() > 0) {
@@ -192,7 +213,7 @@ public class Core extends AbstractService {
         */
        private URL createURL(Page page) {
                try {
-                       return new URL("http://" + nodeHost + ":" + nodePort + "/");
+                       return new URL("http://" + nodeHost + ":" + nodePort + "/SSK@" + page.getEdition().getSite().getKey() + "/" + page.getEdition().getSite().getBasename() + "-" + page.getEdition().getNumber() + "/" + page.getPath());
                } catch (MalformedURLException mue1) {
                        /* nearly impossible. */
                }