From 7101c7640375621a91860fa9e95dfd9ddf9dc762 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Fri, 10 May 2024 22:30:43 +0200 Subject: [PATCH 1/7] When the update key is changed, subscribe to the new key. --- src/freenet/node/updater/NodeUpdater.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index 20e43dde20..dcc89d537a 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -511,8 +511,14 @@ public synchronized boolean canUpdateNow() { /** Called when the fetch URI has changed. No major locks are held by caller. * @param uri The new URI. */ public void onChangeURI(FreenetURI uri) { - kill(); + kill(); // unsubscribes from the old uri this.URI = uri; + try { + USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion)); + core.getUskManager().subscribe(myUsk, this, true, getRequestClient()); + } catch(MalformedURLException e) { + Logger.minor(this, "Cannot create update USK for correct version", e); + } maybeUpdate(); } From dce7e1b4ae52d3c8d214143d4e42323910318844 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Mon, 17 Jun 2024 00:13:52 +0200 Subject: [PATCH 2/7] Fix: factor out subscribe() from start() instead of duplicating code --- src/freenet/node/updater/NodeUpdater.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index dcc89d537a..de1f1d1351 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -91,15 +91,23 @@ public abstract class NodeUpdater implements ClientGetCallback, USKCallback, Req } void start() { + try { + this.subscribe(); + } catch(MalformedURLException e) { + manager.blow("The auto-update URI isn't valid and can't be used", true); + } + } + + void subscribe() throws MalformedURLException { try { // because of UoM, this version is actually worth having as well USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion)); core.getUskManager().subscribe(myUsk, this, true, getRequestClient()); } catch(MalformedURLException e) { Logger.error(this, "The auto-update URI isn't valid and can't be used"); - manager.blow("The auto-update URI isn't valid and can't be used", true); + throw e; } - } + } protected void maybeProcessOldBlob() { File oldBlob = getBlobFile(currentVersion); @@ -513,11 +521,10 @@ public synchronized boolean canUpdateNow() { public void onChangeURI(FreenetURI uri) { kill(); // unsubscribes from the old uri this.URI = uri; - try { - USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion)); - core.getUskManager().subscribe(myUsk, this, true, getRequestClient()); - } catch(MalformedURLException e) { - Logger.minor(this, "Cannot create update USK for correct version", e); + try { + this.subscribe(); + } catch (MalformedURLException e) { + // does not need this handling } maybeUpdate(); } From ca269b38cac5ad1c8b852de6338705e7473ff5f9 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 23 Jul 2024 19:38:52 +0200 Subject: [PATCH 3/7] make method private --- src/freenet/node/updater/NodeUpdater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index de1f1d1351..d6dac9e7c5 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -98,7 +98,7 @@ void start() { } } - void subscribe() throws MalformedURLException { + private void subscribe() throws MalformedURLException { try { // because of UoM, this version is actually worth having as well USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion)); From 02b7ea30d006c648ec60d516b9f9b5d405fcf1f3 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 23 Jul 2024 19:39:53 +0200 Subject: [PATCH 4/7] Remove useless this --- src/freenet/node/updater/NodeUpdater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index d6dac9e7c5..9c3cba5f3a 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -92,7 +92,7 @@ public abstract class NodeUpdater implements ClientGetCallback, USKCallback, Req void start() { try { - this.subscribe(); + subscribe(); } catch(MalformedURLException e) { manager.blow("The auto-update URI isn't valid and can't be used", true); } From dc13510d576f8392b6854ea3fa7df8bd4e005d49 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 23 Jul 2024 19:43:52 +0200 Subject: [PATCH 5/7] Remove useless this --- src/freenet/node/updater/NodeUpdater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index 9c3cba5f3a..e83db81d72 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -522,7 +522,7 @@ public void onChangeURI(FreenetURI uri) { kill(); // unsubscribes from the old uri this.URI = uri; try { - this.subscribe(); + subscribe(); } catch (MalformedURLException e) { // does not need this handling } From 30899ba078ef4de6878f154b2cf3e72c2db2b4dc Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 23 Jul 2024 19:44:33 +0200 Subject: [PATCH 6/7] Fix false formatting --- src/freenet/node/updater/NodeUpdater.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index e83db81d72..3e898d0a33 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -91,23 +91,23 @@ public abstract class NodeUpdater implements ClientGetCallback, USKCallback, Req } void start() { - try { - subscribe(); - } catch(MalformedURLException e) { - manager.blow("The auto-update URI isn't valid and can't be used", true); - } + try { + subscribe(); + } catch (MalformedURLException e) { + manager.blow("The auto-update URI isn't valid and can't be used", true); + } } - private void subscribe() throws MalformedURLException { + private void subscribe() throws MalformedURLException { try { // because of UoM, this version is actually worth having as well USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion)); core.getUskManager().subscribe(myUsk, this, true, getRequestClient()); - } catch(MalformedURLException e) { + } catch (MalformedURLException e) { Logger.error(this, "The auto-update URI isn't valid and can't be used"); - throw e; + throw e; } - } + } protected void maybeProcessOldBlob() { File oldBlob = getBlobFile(currentVersion); From 7f9f0b0494b0419d306b2cc21de026bc7aac4196 Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Tue, 23 Jul 2024 19:52:37 +0200 Subject: [PATCH 7/7] Pass subscribe an onError runnable --- src/freenet/node/updater/NodeUpdater.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/freenet/node/updater/NodeUpdater.java b/src/freenet/node/updater/NodeUpdater.java index 3e898d0a33..46a25d97af 100644 --- a/src/freenet/node/updater/NodeUpdater.java +++ b/src/freenet/node/updater/NodeUpdater.java @@ -91,21 +91,17 @@ public abstract class NodeUpdater implements ClientGetCallback, USKCallback, Req } void start() { - try { - subscribe(); - } catch (MalformedURLException e) { - manager.blow("The auto-update URI isn't valid and can't be used", true); - } + subscribe(() -> manager.blow("The auto-update URI isn't valid and can't be used", true)); } - private void subscribe() throws MalformedURLException { + private void subscribe(Runnable onError) { try { // because of UoM, this version is actually worth having as well USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion)); core.getUskManager().subscribe(myUsk, this, true, getRequestClient()); } catch (MalformedURLException e) { Logger.error(this, "The auto-update URI isn't valid and can't be used"); - throw e; + onError.run(); } } @@ -521,11 +517,7 @@ public synchronized boolean canUpdateNow() { public void onChangeURI(FreenetURI uri) { kill(); // unsubscribes from the old uri this.URI = uri; - try { - subscribe(); - } catch (MalformedURLException e) { - // does not need this handling - } + subscribe(() -> {}); maybeUpdate(); }