From d4c71f70fc4fa669b418adabf5d5e8dd3677042d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:13:33 +0200 Subject: [PATCH 01/16] Implement page deletion. --- src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java b/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java index 4cccc63..4e63278 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.template.Template; /** @@ -50,6 +52,13 @@ public class DeleteSonePage extends SoneTemplatePage { @Override protected void processTemplate(Request request, Template template) throws RedirectException { super.processTemplate(request, template); + if (request.getMethod() == Method.POST) { + if (request.getHttpRequest().isPartSet("deleteSone")) { + Sone currentSone = getCurrentSone(request.getToadletContext()); + webInterface.core().deleteSone(currentSone); + } + throw new RedirectException("index.html"); + } } // -- 2.7.4 From d6dd6065facc2201c5c29830cd5207a7fb9169fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:14:25 +0200 Subject: [PATCH 02/16] Flesh out Sone deletion HTML. --- src/main/resources/i18n/sone.en.properties | 5 +++++ src/main/resources/templates/deleteSone.html | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 2756f48..d578084 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -34,6 +34,11 @@ Page.CreateSone.Title=Create Sone - Sone Page.DeleteSone.Title=Delete Sone - Sone Page.DeleteSone.Page.Title=Delete Sone “{zone}”? +Page.DeleteSone.Page.Description=This will not delete the Sone from Freenet (because that is impossible), it will merely remove all references to this Sone from this plugin instance. You can write down the insert and request keys and reload your Sone from a different plugin instance or computer. +Page.DeleteSone.Label.RequestURI=Request URI: +Page.DeleteSone.Label.InsertURI=Insert URI: +Page.DeleteSone.Button.Yes=Yes, delete. +Page.DeleteSone.Button.No=No, do not delete. Page.Index.Title=Your Sone - Sone diff --git a/src/main/resources/templates/deleteSone.html b/src/main/resources/templates/deleteSone.html index 4e10f67..f370233 100644 --- a/src/main/resources/templates/deleteSone.html +++ b/src/main/resources/templates/deleteSone.html @@ -2,4 +2,24 @@

<%= Page.DeleteSone.Page.Title|l10n|replace needle="{zone}" replacementKey=currentSone.name|html>

+
<%= Page.DeleteSone.Page.Description|l10n|html>
+ +
+ +
+ + +
+
+ + +
+
+ +
+
+ +
+
+ -- 2.7.4 From c87911369ba505171e19dfa2f88129a209ee389b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:17:31 +0200 Subject: [PATCH 03/16] Remove warning about parameter assignment. --- src/main/java/net/pterodactylus/sone/core/Core.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 7498356..ddca79f 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -137,15 +137,20 @@ public class Core extends AbstractService { if ((name == null) || (name.trim().length() == 0)) { throw new SoneException(Type.INVALID_SONE_NAME); } + String finalRequestUri; + String finalInsertUri; if ((requestUri == null) || (insertUri == null)) { String[] keyPair = freenetInterface.generateKeyPair(); - requestUri = keyPair[0]; - insertUri = keyPair[1]; + finalRequestUri = keyPair[0]; + finalInsertUri = keyPair[1]; + } else { + finalRequestUri = requestUri; + finalInsertUri = insertUri; } Sone sone; try { - logger.log(Level.FINEST, "Creating new Sone “%s” at %s (%s)…", new Object[] { name, requestUri, insertUri }); - sone = new Sone(UUID.randomUUID(), name, new FreenetURI(requestUri), new FreenetURI(insertUri)); + logger.log(Level.FINEST, "Creating new Sone “%s” at %s (%s)…", new Object[] { name, finalRequestUri, finalInsertUri }); + sone = new Sone(UUID.randomUUID(), name, new FreenetURI(finalRequestUri), new FreenetURI(finalInsertUri)); } catch (MalformedURLException mue1) { throw new SoneException(Type.INVALID_URI); } -- 2.7.4 From 76374e3b89fafa5681a2821ad903f29caf1c1349 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:20:25 +0200 Subject: [PATCH 04/16] Return an unmodifiable copy of the Sones. --- src/main/java/net/pterodactylus/sone/core/Core.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index ddca79f..31e2680 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -96,7 +96,7 @@ public class Core extends AbstractService { * @return The local Sones */ public Set localSones() { - return localSones; + return Collections.unmodifiableSet(localSones); } // -- 2.7.4 From fcd011a16b119966906b3137513e9432ab86c3a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:21:03 +0200 Subject: [PATCH 05/16] =?utf8?q?Rename=20=E2=80=9ClocalSones=E2=80=9D=20me?= =?utf8?q?thod=20to=20a=20more=20traditional=20=E2=80=9CgetSones=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 2 +- src/main/java/net/pterodactylus/sone/web/LoginPage.java | 4 ++-- src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 31e2680..7ddc247 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -95,7 +95,7 @@ public class Core extends AbstractService { * * @return The local Sones */ - public Set localSones() { + public Set getSones() { return Collections.unmodifiableSet(localSones); } diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index a72fd02..39c3cdc 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -53,12 +53,12 @@ public class LoginPage extends SoneTemplatePage { @Override protected void processTemplate(Request request, Template template) throws RedirectException { super.processTemplate(request, template); - Set localSones = webInterface.core().localSones(); + Set localSones = webInterface.core().getSones(); template.set("sones", localSones); if (request.getMethod() == Method.POST) { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100); Sone selectedSone = null; - for (Sone sone : webInterface.core().localSones()) { + for (Sone sone : webInterface.core().getSones()) { if (sone.getId().equals(soneId)) { selectedSone = sone; break; diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index c271024..6afc3b7 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -111,7 +111,7 @@ public class SoneTemplatePage extends TemplatePage { return null; } String soneId = (String) session.getAttribute("Sone.CurrentSone"); - for (Sone sone : webInterface.core().localSones()) { + for (Sone sone : webInterface.core().getSones()) { if (sone.getId().equals(soneId)) { return sone; } -- 2.7.4 From d0760125c528fb41d49a7eb9d8833ded0f3b6656 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:24:17 +0200 Subject: [PATCH 06/16] Add stub of Sone inserter. --- .../net/pterodactylus/sone/core/SoneInserter.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/core/SoneInserter.java diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java new file mode 100644 index 0000000..75fda7c --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -0,0 +1,55 @@ +/* + * FreenetSone - SoneInserter.java - Copyright © 2010 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.core; + +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.service.AbstractService; + +/** + * A Sone inserter is responsible for inserting a Sone if it has changed. + * + * @author David ‘Bombe’ Roden + */ +public class SoneInserter extends AbstractService { + + /** The Sone to insert. */ + private final Sone sone; + + /** + * Creates a new Sone inserter. + * + * @param sone + * The Sone to insert + */ + public SoneInserter(Sone sone) { + super("Sone Inserter for “" + sone.getName() + "”"); + this.sone = sone; + } + + // + // SERVICE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void serviceRun() { + } + +} -- 2.7.4 From a2b84c58896a768553f41b633829ab5d28e0c7b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:24:38 +0200 Subject: [PATCH 07/16] Start Sone inserters when Sone is added. --- .../java/net/pterodactylus/sone/core/Core.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 7ddc247..913355a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -19,8 +19,10 @@ package net.pterodactylus.sone.core; import java.net.MalformedURLException; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.logging.Level; @@ -55,6 +57,9 @@ public class Core extends AbstractService { /** The local Sones. */ private final Set localSones = new HashSet(); + /** Sone inserters. */ + private final Map soneInserters = new HashMap(); + /** * Creates a new core. */ @@ -104,6 +109,20 @@ public class Core extends AbstractService { // /** + * Adds the given Sone. + * + * @param sone + * The Sone to add + */ + public void addSone(Sone sone) { + if (localSones.add(sone)) { + SoneInserter soneInserter = new SoneInserter(sone); + soneInserter.start(); + soneInserters.put(sone, soneInserter); + } + } + + /** * Creates a new Sone at a random location. * * @param name @@ -151,6 +170,7 @@ public class Core extends AbstractService { try { logger.log(Level.FINEST, "Creating new Sone “%s” at %s (%s)…", new Object[] { name, finalRequestUri, finalInsertUri }); sone = new Sone(UUID.randomUUID(), name, new FreenetURI(finalRequestUri), new FreenetURI(finalInsertUri)); + addSone(sone); } catch (MalformedURLException mue1) { throw new SoneException(Type.INVALID_URI); } @@ -165,6 +185,8 @@ public class Core extends AbstractService { * The sone to delete */ public void deleteSone(Sone sone) { + SoneInserter soneInserter = soneInserters.remove(sone); + soneInserter.stop(); localSones.remove(sone); } @@ -218,7 +240,7 @@ public class Core extends AbstractService { String insertUri = configuration.getStringValue("Sone/Name." + soneName + "/InsertURI").getValue(null); String requestUri = configuration.getStringValue("Sone/Name." + soneName + "/RequestURI").getValue(null); try { - localSones.add(new Sone(UUID.fromString(id), soneName, new FreenetURI(requestUri), new FreenetURI(insertUri))); + addSone(new Sone(UUID.fromString(id), soneName, new FreenetURI(requestUri), new FreenetURI(insertUri))); } catch (MalformedURLException mue1) { logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + requestUri + "”) and insertUri (“" + insertUri + "”)!", mue1); } -- 2.7.4 From 8b9c6e55b8509e4651ceca3b052f201739623213 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:27:01 +0200 Subject: [PATCH 08/16] Stop all Sone inserters when stopping the core. --- src/main/java/net/pterodactylus/sone/core/Core.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 913355a..4be02f6 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -207,6 +207,10 @@ public class Core extends AbstractService { */ @Override protected void serviceStop() { + /* stop all Sone inserters. */ + for (SoneInserter soneInserter : soneInserters.values()) { + soneInserter.stop(); + } saveConfiguration(); } -- 2.7.4 From 87386f93e655178eed6024babd50bf236ab882ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:41:51 +0200 Subject: [PATCH 09/16] Add modification counter to Sone. --- .../java/net/pterodactylus/sone/core/Core.java | 6 +++- .../java/net/pterodactylus/sone/data/Sone.java | 34 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 4be02f6..6213e05 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -243,8 +243,11 @@ public class Core extends AbstractService { String id = configuration.getStringValue("Sone/Name." + soneName + "/ID").getValue(null); String insertUri = configuration.getStringValue("Sone/Name." + soneName + "/InsertURI").getValue(null); String requestUri = configuration.getStringValue("Sone/Name." + soneName + "/RequestURI").getValue(null); + long modificationCounter = configuration.getLongValue("Sone/Name." + soneName + "/ModificationCounter").getValue((long) 0); try { - addSone(new Sone(UUID.fromString(id), soneName, new FreenetURI(requestUri), new FreenetURI(insertUri))); + Sone sone = new Sone(UUID.fromString(id), soneName, new FreenetURI(requestUri), new FreenetURI(insertUri)); + sone.setModificationCounter(modificationCounter); + addSone(sone); } catch (MalformedURLException mue1) { logger.log(Level.WARNING, "Could not create Sone from requestUri (“" + requestUri + "”) and insertUri (“" + insertUri + "”)!", mue1); } @@ -275,6 +278,7 @@ public class Core extends AbstractService { configuration.getStringValue("Sone/Name." + sone.getName() + "/ID").setValue(sone.getId()); configuration.getStringValue("Sone/Name." + sone.getName() + "/RequestURI").setValue(sone.getRequestUri().toString()); configuration.getStringValue("Sone/Name." + sone.getName() + "/InsertURI").setValue(sone.getInsertUri().toString()); + configuration.getLongValue("Sone/Name." + sone.getName() + "/ModificationCounter").setValue(sone.getModificationCounter()); } } catch (ConfigurationException ce1) { logger.log(Level.WARNING, "Could not store configuration!", ce1); diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 4a73470..bb36a9c 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -48,6 +48,9 @@ public class Sone { /** All friend Sones. */ private final Set friendSones = new HashSet(); + /** Modification count. */ + private volatile long modificationCounter = 0; + /** * Creates a new Sone. * @@ -149,8 +152,10 @@ public class Sone { * The friend Sone to add * @return This Sone (for method chaining) */ - public Sone addFriendSone(Sone friendSone) { - friendSones.add(friendSone); + public synchronized Sone addFriendSone(Sone friendSone) { + if (friendSones.add(friendSone)) { + modificationCounter++; + } return this; } @@ -161,11 +166,32 @@ public class Sone { * The friend Sone to remove * @return This Sone (for method chaining) */ - public Sone removeFriendSone(Sone friendSone) { - friendSones.remove(friendSone); + public synchronized Sone removeFriendSone(Sone friendSone) { + if (friendSones.remove(friendSone)) { + modificationCounter++; + } return this; } + /** + * Returns the modification counter. + * + * @return The modification counter + */ + public synchronized long getModificationCounter() { + return modificationCounter; + } + + /** + * Sets the modification counter. + * + * @param modificationCounter + * The new modification counter + */ + public synchronized void setModificationCounter(long modificationCounter) { + this.modificationCounter = modificationCounter; + } + // // OBJECT METHODS // -- 2.7.4 From 66771252598821e86477e5c98392c444fce05569 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:42:06 +0200 Subject: [PATCH 10/16] Hand in freenet interface to Sone inserter. --- src/main/java/net/pterodactylus/sone/core/Core.java | 2 +- src/main/java/net/pterodactylus/sone/core/SoneInserter.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 6213e05..ddd3524 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -116,7 +116,7 @@ public class Core extends AbstractService { */ public void addSone(Sone sone) { if (localSones.add(sone)) { - SoneInserter soneInserter = new SoneInserter(sone); + SoneInserter soneInserter = new SoneInserter(freenetInterface, sone); soneInserter.start(); soneInserters.put(sone, soneInserter); } diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 75fda7c..b779b2e 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -33,10 +33,12 @@ public class SoneInserter extends AbstractService { /** * Creates a new Sone inserter. * + * @param freenetInterface + * The freenet interface * @param sone * The Sone to insert */ - public SoneInserter(Sone sone) { + public SoneInserter(FreenetInterface freenetInterface, Sone sone) { super("Sone Inserter for “" + sone.getName() + "”"); this.sone = sone; } -- 2.7.4 From 8ab964453124b2ae38adce3a65b7faac9c5a0245 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 16:42:18 +0200 Subject: [PATCH 11/16] Stub of Sone inserter main loop. --- .../java/net/pterodactylus/sone/core/SoneInserter.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index b779b2e..a8f9951 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -17,7 +17,11 @@ package net.pterodactylus.sone.core; +import java.util.logging.Level; +import java.util.logging.Logger; + import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.service.AbstractService; /** @@ -27,6 +31,9 @@ import net.pterodactylus.util.service.AbstractService; */ public class SoneInserter extends AbstractService { + /** The logger. */ + private static final Logger logger = Logging.getLogger(SoneInserter.class); + /** The Sone to insert. */ private final Sone sone; @@ -52,6 +59,15 @@ public class SoneInserter extends AbstractService { */ @Override protected void serviceRun() { + while (!shouldStop()) { + synchronized (sone) { + if (sone.getModificationCounter() > 0) { + sone.setModificationCounter(0); + } + } + logger.log(Level.FINEST, "Waiting 60 seconds before checking Sone “" + sone.getName() + "” again."); + sleep(60 * 1000); + } } } -- 2.7.4 From 8d8182f05bd30c3f4d3e12b5df06b18451fe1472 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 19:39:10 +0200 Subject: [PATCH 12/16] Override Object.equals(). --- src/main/java/net/pterodactylus/sone/data/Sone.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index bb36a9c..b5e3b08 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -204,4 +204,15 @@ public class Sone { return id.hashCode(); } + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object object) { + if (!(object instanceof Sone)) { + return false; + } + return ((Sone) object).id.equals(id); + } + } -- 2.7.4 From 1f6a99de95988a0299faff512ab457ae1172dc46 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 19:42:12 +0200 Subject: [PATCH 13/16] Add synchronization note. --- src/main/java/net/pterodactylus/sone/data/Sone.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index b5e3b08..8b2367b 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -27,6 +27,8 @@ import freenet.keys.FreenetURI; /** * A Sone defines everything about a user: the {@link User} itself, her profile, * her status updates. + *

+ * Operations that modify the Sone need to synchronize on the Sone in question. * * @author David ‘Bombe’ Roden */ -- 2.7.4 From 24b467bb6e2ebf8d11fe15fa976e0a25f30242de Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 21:27:27 +0200 Subject: [PATCH 14/16] Add fred-ext dependency. --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 94d63d5..c82a15f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,12 @@ 0.7.5.1292-SNAPSHOT provided + + org.freenetproject + fred-ext + 26 + provided + UTF-8 -- 2.7.4 From 351ac6b0a5da732e79495cc1643295b4d6a4f233 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 21:27:39 +0200 Subject: [PATCH 15/16] Set modification counter of new Sones to 1 so that it is inserted automatically. --- src/main/java/net/pterodactylus/sone/core/Core.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index ddd3524..e59c8e6 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -170,6 +170,8 @@ public class Core extends AbstractService { try { logger.log(Level.FINEST, "Creating new Sone “%s” at %s (%s)…", new Object[] { name, finalRequestUri, finalInsertUri }); sone = new Sone(UUID.randomUUID(), name, new FreenetURI(finalRequestUri), new FreenetURI(finalInsertUri)); + /* set modification counter to 1 so it is inserted immediately. */ + sone.setModificationCounter(1); addSone(sone); } catch (MalformedURLException mue1) { throw new SoneException(Type.INVALID_URI); -- 2.7.4 From 80b69bbf2b53e5587088a1e8b8764aeb92e1c1ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 21:27:50 +0200 Subject: [PATCH 16/16] Add method to insert a directory into Freenet. --- .../pterodactylus/sone/core/FreenetInterface.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 1098069..aa46f93 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.core; +import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -25,6 +26,7 @@ import net.pterodactylus.util.service.AbstractService; import freenet.client.FetchException; import freenet.client.FetchResult; import freenet.client.HighLevelSimpleClient; +import freenet.client.InsertException; import freenet.keys.FreenetURI; import freenet.node.Node; @@ -92,4 +94,25 @@ public class FreenetInterface extends AbstractService { return new String[] { keyPair[1].toString(), keyPair[0].toString() }; } + /** + * Inserts a directory into Freenet. + * + * @param insertUri + * The insert URI + * @param manifestEntries + * The directory entries + * @param defaultFile + * The name of the default file + * @return The generated URI + * @throws SoneException + * if an insert error occurs + */ + public FreenetURI insertDirectory(FreenetURI insertUri, HashMap manifestEntries, String defaultFile) throws SoneException { + try { + return client.insertManifest(insertUri, manifestEntries, defaultFile); + } catch (InsertException ie1) { + throw new SoneException(null, ie1); + } + } + } -- 2.7.4