Author: toad
Date: 2007-06-11 19:05:58 +0000 (Mon, 11 Jun 2007)
New Revision: 13518
Modified:
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
trunk/freenet/src/freenet/node/updater/NodeUpdater.java
trunk/freenet/src/freenet/node/updater/RevocationChecker.java
Log:
Send UOMAnnounce at appropriate times. Not broadcast on startup, but is sent on
connect if there is anything interesting to say. Is also sent when major
developments occur i.e. when we find the jar, when we have 3 consecutive DNFs
on the revocation fetch, etc.
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2007-06-11 18:43:31 UTC
(rev 13517)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2007-06-11 19:05:58 UTC
(rev 13518)
@@ -1650,6 +1650,9 @@
} catch (NotConnectedException e) {
Logger.error(this, "Completed handshake with "+getPeer()+" but
disconnected ("+isConnected+ ':' +currentTracker+"!!!: "+e, e);
}
+
+ if(node.nodeUpdater != null)
+ node.nodeUpdater.maybeSendUOMAnnounce(this);
}
private void sendIPAddressMessage() {
Modified: trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
2007-06-11 18:43:31 UTC (rev 13517)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdateManager.java
2007-06-11 19:05:58 UTC (rev 13518)
@@ -11,10 +11,12 @@
import freenet.config.SubConfig;
import freenet.io.comm.DMT;
import freenet.io.comm.Message;
+import freenet.io.comm.NotConnectedException;
import freenet.keys.FreenetURI;
import freenet.l10n.L10n;
import freenet.node.Node;
import freenet.node.NodeStarter;
+import freenet.node.PeerNode;
import freenet.node.Version;
import freenet.node.updater.UpdateDeployContext.UpdateCatastropheException;
import freenet.node.useralerts.RevocationKeyFoundUserAlert;
@@ -53,7 +55,8 @@
final boolean shouldUpdateExt;
/** Currently deploying an update? */
boolean isDeployingUpdate;
- boolean started;
+ final Object broadcastUOMAnnouncesSync = new Object();
+ boolean broadcastUOMAnnounces = false;
Node node;
@@ -136,18 +139,19 @@
public void start() throws InvalidConfigValueException {
- Message msg = getUOMAnnouncement();
- node.peers.localBroadcast(msg, true);
-
- synchronized(this) {
- started = true;
- }
-
node.clientCore.alerts.register(alert);
enable(wasEnabledOnStartup);
}
+ void broadcastUOMAnnounces() {
+ synchronized(broadcastUOMAnnouncesSync) {
+ Message msg = getUOMAnnouncement();
+ node.peers.localBroadcast(msg, true);
+ broadcastUOMAnnounces = true;
+ }
+ }
+
private Message getUOMAnnouncement() {
return DMT.createUOMAnnounce(updateURI.toString(),
extURI.toString(), revocationURI.toString(), hasBeenBlown,
mainUpdater == null ? -1 :
mainUpdater.getFetchedVersion(),
@@ -159,6 +163,20 @@
(int)node.nodeStats.getNodeAveragePingTime(),
(int)node.nodeStats.getBwlimitDelayTime());
}
+ public void maybeSendUOMAnnounce(PeerNode peer) {
+ synchronized(broadcastUOMAnnouncesSync) {
+ if(!broadcastUOMAnnounces) return; // because of sync
object, haven't entered block yet, so will send to this peer
+ }
+ synchronized(this) {
+ if((!hasBeenBlown) && (mainUpdater == null ||
mainUpdater.getFetchedVersion() <= 0)) return;
+ }
+ try {
+ peer.sendAsync(getUOMAnnouncement(), null, 0, null);
+ } catch (NotConnectedException e) {
+ // Sad, but ignore it
+ }
+ }
+
/**
* Is auto-update enabled?
*/
@@ -518,7 +536,7 @@
* Called when a new jar has been downloaded.
* @param isExt If true, the new jar is the ext jar; if false, it is
the main jar.
*/
- void onDownloadedNewJar(boolean isExt) {
+ void onDownloadedNewJar(boolean isExt, boolean isNew) {
synchronized(this) {
if(isExt) {
hasNewExtJar = true;
@@ -529,6 +547,8 @@
}
}
revocationChecker.start(true);
+ if(!isAutoUpdateAllowed)
+ broadcastUOMAnnounces();
}
/**
@@ -580,6 +600,7 @@
// we don't need to advertize updates : we are not
going to do them
killUpdateAlerts();
}
+ broadcastUOMAnnounces();
}
/**
@@ -593,6 +614,7 @@
public void noRevocationFound() {
deployUpdate(); // May have been waiting for the revocation.
// If we're still here, we didn't update.
+ broadcastUOMAnnounces();
node.ps.queueTimedJob(new Runnable() {
public void run() {
revocationChecker.start(false);
Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2007-06-11
18:43:31 UTC (rev 13517)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2007-06-11
19:05:58 UTC (rev 13518)
@@ -178,6 +178,7 @@
public void onSuccess(FetchResult result, ClientGetter state) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ boolean isNew;
synchronized(this) {
if(result == null || result.asBucket() == null ||
result.asBucket().size() == 0) {
tempBlobFile.delete();
@@ -206,9 +207,9 @@
this.cg = null;
if(this.result != null) this.result.asBucket().free();
this.result = result;
- if(fetchedVersion <= currentVersion) return;
+ isNew = (fetchedVersion > currentVersion);
}
- manager.onDownloadedNewJar(extUpdate);
+ manager.onDownloadedNewJar(extUpdate, isNew);
}
public void onFailure(FetchException e, ClientGetter state) {
Modified: trunk/freenet/src/freenet/node/updater/RevocationChecker.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/RevocationChecker.java
2007-06-11 18:43:31 UTC (rev 13517)
+++ trunk/freenet/src/freenet/node/updater/RevocationChecker.java
2007-06-11 19:05:58 UTC (rev 13518)
@@ -131,15 +131,7 @@
public void onSuccess(FetchResult result, ClientGetter state) {
// The key has been blown !
// FIXME: maybe we need a bigger warning message.
- if(!tmpBlobFile.renameTo(blobFile)) {
- blobFile.delete();
- if(!tmpBlobFile.renameTo(blobFile)) {
- Logger.error(this, "Not able to rename binary
blob for revocation fetcher: "+tmpBlobFile+" -> "+blobFile+" - may not be able
to tell other peers about this revocation");
- System.err.println("Not able to rename binary
blob for revocation fetcher: "+tmpBlobFile+" -> "+blobFile+" - may not be able
to tell other peers about this revocation");
- }
- }
- if(tmpBlobFile != null)
- tmpBlobFile.renameTo(blobFile);
+ moveBlob();
String msg = null;
try {
byte[] buf = result.asByteArray();
@@ -157,6 +149,18 @@
manager.blow(msg);
}
+ private void moveBlob() {
+ if(!tmpBlobFile.renameTo(blobFile)) {
+ blobFile.delete();
+ if(!tmpBlobFile.renameTo(blobFile)) {
+ Logger.error(this, "Not able to rename binary
blob for revocation fetcher: "+tmpBlobFile+" -> "+blobFile+" - may not be able
to tell other peers about this revocation");
+ System.err.println("Not able to rename binary
blob for revocation fetcher: "+tmpBlobFile+" -> "+blobFile+" - may not be able
to tell other peers about this revocation");
+ }
+ }
+ if(tmpBlobFile != null)
+ tmpBlobFile.renameTo(blobFile);
+ }
+
public void onFailure(FetchException e, ClientGetter state) {
Logger.minor(this, "Revocation fetch failed: "+e);
if(tmpBlobFile != null) tmpBlobFile.delete();
@@ -167,6 +171,7 @@
if(errorCode == FetchException.CANCELLED) return; // cancelled
by us above, or killed; either way irrelevant and doesn't need to be restarted
if(e.isFatal()) {
manager.blow("Permanent error fetching revocation
(error inserting the revocation key?): "+e.toString());
+ moveBlob(); // other peers need to know
return;
}
if(e.newURI != null) {