Author: nextgens
Date: 2008-11-08 16:10:02 +0000 (Sat, 08 Nov 2008)
New Revision: 23429
Modified:
trunk/freenet/src/freenet/node/updater/NodeUpdater.java
trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
Log:
indent
Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2008-11-08
16:06:14 UTC (rev 23428)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2008-11-08
16:10:02 UTC (rev 23429)
@@ -26,6 +26,7 @@
import freenet.support.io.FileBucket;
public class NodeUpdater implements ClientCallback, USKCallback {
+
static private boolean logMINOR;
private FetchContext ctx;
private FetchResult result;
@@ -35,25 +36,22 @@
public final NodeClientCore core;
private final Node node;
public final NodeUpdateManager manager;
-
private final int currentVersion;
private int availableVersion;
private int fetchingVersion;
private int fetchedVersion;
private int writtenVersion;
-
private boolean isRunning;
private boolean isFetching;
-
public final boolean extUpdate;
private final String blobFilenamePrefix;
private File tempBlobFile;
-
+
NodeUpdater(NodeUpdateManager manager, FreenetURI URI, boolean
extUpdate, int current, String blobFilenamePrefix) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
this.manager = manager;
this.node = manager.node;
- this.URI = URI.setSuggestedEdition(Version.buildNumber()+1);
+ this.URI = URI.setSuggestedEdition(Version.buildNumber() + 1);
this.ticker = node.ps;
this.core = node.clientCore;
this.currentVersion = current;
@@ -63,104 +61,109 @@
this.isFetching = false;
this.extUpdate = extUpdate;
this.blobFilenamePrefix = blobFilenamePrefix;
-
- FetchContext tempContext = core.makeClient((short)0,
true).getFetchContext();
+
+ FetchContext tempContext = core.makeClient((short) 0,
true).getFetchContext();
tempContext.allowSplitfiles = true;
tempContext.dontEnterImplicitArchives = false;
this.ctx = tempContext;
-
+
}
void start() {
- try{
+ try {
// because of UoM, this version is actually worth
having as well
- USK
myUsk=USK.create(URI.setSuggestedEdition(currentVersion));
+ USK myUsk =
USK.create(URI.setSuggestedEdition(currentVersion));
ctx.uskManager.subscribe(myUsk, this, true, this);
- }catch(MalformedURLException e){
- Logger.error(this,"The auto-update URI isn't valid and
can't be used");
+ } 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");
}
}
-
- public void onFoundEdition(long l, USK key){
+
+ public void onFoundEdition(long l, USK key) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
- if(logMINOR) Logger.minor(this, "Found edition "+l);
- System.err.println("Found "+(extUpdate?"freenet-ext.jar " :
"")+"update edition "+l);
+ if(logMINOR)
+ Logger.minor(this, "Found edition " + l);
+ System.err.println("Found " + (extUpdate ? "freenet-ext.jar " :
"") + "update edition " + l);
int found;
synchronized(this) {
- if(!isRunning) return;
- found = (int)key.suggestedEdition;
-
- if(found <= availableVersion){
- return;
- }
+ if(!isRunning)
+ return;
+ found = (int) key.suggestedEdition;
+
+ if(found <= availableVersion)
+ return;
Logger.minor(this, "Updating availableVersion from " +
availableVersion + " to " + found + " and queueing an update");
this.availableVersion = found;
}
- ticker.queueTimedJob(new Runnable() {
+ ticker.queueTimedJob(new Runnable() {
- public void run() {
- maybeUpdate();
- }
- }, 60 * 1000); // leave some time in case we get later
editions
- // LOCKING: Always take the NodeUpdater lock *BEFORE*
the NodeUpdateManager lock
- if(found > currentVersion)
+ public void run() {
+ maybeUpdate();
+ }
+ }, 60 * 1000); // leave some time in case we get later editions
+ // LOCKING: Always take the NodeUpdater lock *BEFORE* the
NodeUpdateManager lock
+ if(found > currentVersion)
manager.onStartFetching(extUpdate);
}
- public void maybeUpdate(){
+ public void maybeUpdate() {
ClientGetter toStart = null;
- if(!manager.isEnabled()) return;
- if(manager.isBlown()) return;
+ if(!manager.isEnabled())
+ return;
+ if(manager.isBlown())
+ return;
synchronized(this) {
if(logMINOR)
- Logger.minor(this, "maybeUpdate:
isFetching="+isFetching+", isRunning="+isRunning+",
availableVersion="+availableVersion);
- if(isFetching || (!isRunning)) return;
- if(availableVersion <= fetchedVersion) return;
+ Logger.minor(this, "maybeUpdate: isFetching=" +
isFetching + ", isRunning=" + isRunning + ", availableVersion=" +
availableVersion);
+ if(isFetching || (!isRunning))
+ return;
+ if(availableVersion <= fetchedVersion)
+ return;
fetchingVersion = availableVersion;
-
+
if(availableVersion > currentVersion) {
- Logger.normal(this,"Starting the update process
("+availableVersion+ ')');
- System.err.println("Starting the update
process: found the update ("+availableVersion+"), now fetching it.");
+ Logger.normal(this, "Starting the update
process (" + availableVersion + ')');
+ System.err.println("Starting the update
process: found the update (" + availableVersion + "), now fetching it.");
}
if(logMINOR)
- Logger.minor(this,"Starting the update process
("+availableVersion+ ')');
+ Logger.minor(this, "Starting the update process
(" + availableVersion + ')');
// We fetch it
- try{
- if((cg==null)||cg.isCancelled()){
- if(logMINOR) Logger.minor(this,
"Scheduling request for "+URI.setSuggestedEdition(availableVersion));
+ try {
+ if((cg == null) || cg.isCancelled()) {
+ if(logMINOR)
+ Logger.minor(this, "Scheduling
request for " + URI.setSuggestedEdition(availableVersion));
if(availableVersion > currentVersion)
- System.err.println("Starting
"+(extUpdate?"freenet-ext.jar ":"")+"fetch for "+availableVersion);
- tempBlobFile =
-
File.createTempFile(blobFilenamePrefix+availableVersion+"-", ".fblob.tmp",
manager.node.clientCore.getPersistentTempDir());
- cg = new ClientGetter(this,
core.requestStarters.chkFetchScheduler, core.requestStarters.sskFetchScheduler,
-
URI.setSuggestedEdition(availableVersion), ctx,
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
- this, null, new
FileBucket(tempBlobFile, false, false, false, false, false));
+ System.err.println("Starting "
+ (extUpdate ? "freenet-ext.jar " : "") + "fetch for " + availableVersion);
+ tempBlobFile =
+
File.createTempFile(blobFilenamePrefix + availableVersion + "-", ".fblob.tmp",
manager.node.clientCore.getPersistentTempDir());
+ cg = new ClientGetter(this,
core.requestStarters.chkFetchScheduler, core.requestStarters.sskFetchScheduler,
+
URI.setSuggestedEdition(availableVersion), ctx,
RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
+ this, null, new
FileBucket(tempBlobFile, false, false, false, false, false));
toStart = cg;
}
isFetching = true;
- }catch (Exception e) {
- Logger.error(this, "Error while starting the
fetching: "+e, e);
- isFetching=false;
+ } catch(Exception e) {
+ Logger.error(this, "Error while starting the
fetching: " + e, e);
+ isFetching = false;
}
}
if(toStart != null)
try {
toStart.start();
- } catch (FetchException e) {
- Logger.error(this, "Error while starting the
fetching: "+e, e);
+ } catch(FetchException e) {
+ Logger.error(this, "Error while starting the
fetching: " + e, e);
synchronized(this) {
- isFetching=false;
+ isFetching = false;
}
}
}
-
+
File getBlobFile(int availableVersion) {
- return new File(node.clientCore.getPersistentTempDir(),
blobFilenamePrefix+availableVersion+".fblob");
+ return new File(node.clientCore.getPersistentTempDir(),
blobFilenamePrefix + availableVersion + ".fblob");
}
+ private final Object writeJarSync = new Object();
- private final Object writeJarSync = new Object();
-
public void writeJarTo(File fNew) throws IOException {
int fetched;
synchronized(this) {
@@ -168,25 +171,25 @@
}
synchronized(writeJarSync) {
fNew.delete();
-
+
FileOutputStream fos;
fos = new FileOutputStream(fNew);
-
+
BucketTools.copyTo(result.asBucket(), fos, -1);
-
+
fos.flush();
fos.close();
}
synchronized(this) {
writtenVersion = fetched;
}
- System.err.println("Written "+(extUpdate ? "ext" : "main")+"
jar to "+fNew);
+ System.err.println("Written " + (extUpdate ? "ext" : "main") +
" jar to " + fNew);
}
-
+
public void onSuccess(FetchResult result, ClientGetter state) {
onSuccess(result, state, tempBlobFile, fetchingVersion);
}
-
+
void onSuccess(FetchResult result, ClientGetter state, File
tempBlobFile, int fetchedVersion) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
synchronized(this) {
@@ -201,34 +204,35 @@
}
if(result == null || result.asBucket() == null ||
result.asBucket().size() == 0) {
tempBlobFile.delete();
- Logger.error(this, "Cannot update: result
either null or empty for "+availableVersion);
- System.err.println("Cannot update: result
either null or empty for "+availableVersion);
+ Logger.error(this, "Cannot update: result
either null or empty for " + availableVersion);
+ System.err.println("Cannot update: result
either null or empty for " + availableVersion);
// Try again
- if(result == null || result.asBucket() == null
|| availableVersion > fetchedVersion) {
+ if(result == null || result.asBucket() == null
|| availableVersion > fetchedVersion)
node.ps.queueTimedJob(new Runnable() {
- public void run() {
maybeUpdate(); }
+
+ public void run() {
+ maybeUpdate();
+ }
}, 0);
- }
return;
}
File blobFile = getBlobFile(fetchedVersion);
if(!tempBlobFile.renameTo(blobFile)) {
blobFile.delete();
- if(!tempBlobFile.renameTo(blobFile)) {
+ if(!tempBlobFile.renameTo(blobFile))
if(blobFile.exists() &&
tempBlobFile.exists() &&
- blobFile.length() ==
tempBlobFile.length())
- Logger.minor(this, "Can't
rename "+tempBlobFile+" over "+blobFile+" for "+fetchedVersion+" - probably not
a big deal though as the files are the same size");
+ blobFile.length() ==
tempBlobFile.length())
+ Logger.minor(this, "Can't
rename " + tempBlobFile + " over " + blobFile + " for " + fetchedVersion + " -
probably not a big deal though as the files are the same size");
else
- Logger.error(this, "Not able to
rename binary blob for node updater: "+tempBlobFile+" -> "+blobFile+" - may not
be able to tell other peers about this build");
- }
+ Logger.error(this, "Not able to
rename binary blob for node updater: " + tempBlobFile + " -> " + blobFile + " -
may not be able to tell other peers about this build");
}
this.fetchedVersion = fetchedVersion;
- System.out.println("Found "+fetchedVersion);
- if(fetchedVersion > currentVersion) {
+ System.out.println("Found " + fetchedVersion);
+ if(fetchedVersion > currentVersion)
Logger.normal(this, "Found version " +
fetchedVersion + ", setting up a new UpdatedVersionAvailableUserAlert");
- }
this.cg = null;
- if(this.result != null) this.result.asBucket().free();
+ if(this.result != null)
+ this.result.asBucket().free();
this.result = result;
}
manager.onDownloadedNewJar(extUpdate);
@@ -236,35 +240,38 @@
public void onFailure(FetchException e, ClientGetter state) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
- if(!isRunning) return;
+ if(!isRunning)
+ return;
int errorCode = e.getMode();
tempBlobFile.delete();
-
- if(logMINOR) Logger.minor(this, "onFailure("+e+ ',' +state+
')');
+
+ if(logMINOR)
+ Logger.minor(this, "onFailure(" + e + ',' + state +
')');
synchronized(this) {
this.cg = null;
- isFetching=false;
+ isFetching = false;
}
if(errorCode == FetchException.CANCELLED ||
- !e.isFatal()) {
+ !e.isFatal()) {
Logger.normal(this, "Rescheduling new request");
ticker.queueTimedJob(new Runnable() {
+
public void run() {
maybeUpdate();
}
}, 0);
} else {
- Logger.error(this, "Canceling fetch : "+
e.getMessage());
- System.err.println("Unexpected error fetching update:
"+e.getMessage());
+ Logger.error(this, "Canceling fetch : " +
e.getMessage());
+ System.err.println("Unexpected error fetching update: "
+ e.getMessage());
if(e.isFatal()) {
// Wait for the next version
- } else {
+ } else
ticker.queueTimedJob(new Runnable() {
+
public void run() {
maybeUpdate();
}
- }, 60*60*1000);
- }
+ }, 60 * 60 * 1000);
}
}
@@ -279,32 +286,32 @@
public void onGeneratedURI(FreenetURI uri, BaseClientPutter state) {
// Impossible
}
-
+
/** Called before kill(). Don't do anything that will involve taking
locks. */
public void preKill() {
isRunning = false;
}
-
- void kill(){
- try{
+
+ void kill() {
+ try {
ClientGetter c;
synchronized(this) {
isRunning = false;
- USK
myUsk=USK.create(URI.setSuggestedEdition(currentVersion));
- ctx.uskManager.unsubscribe(myUsk, this, true);
+ USK myUsk =
USK.create(URI.setSuggestedEdition(currentVersion));
+ ctx.uskManager.unsubscribe(myUsk, this, true);
c = cg;
cg = null;
}
c.cancel();
- }catch(Exception e){
+ } catch(Exception e) {
Logger.minor(this, "Cannot kill NodeUpdater", e);
}
}
-
- public FreenetURI getUpdateKey(){
+
+ public FreenetURI getUpdateKey() {
return URI;
}
-
+
public void onMajorProgress() {
// Ignore
}
@@ -312,7 +319,7 @@
public synchronized boolean canUpdateNow() {
return fetchedVersion > currentVersion;
}
-
+
public void onFetchable(BaseClientPutter state) {
// Ignore, we don't insert
}
@@ -339,8 +346,10 @@
public int fetchingVersion() {
// We will not deploy currentVersion...
- if(fetchingVersion <= currentVersion) return availableVersion;
- else return fetchingVersion;
+ if(fetchingVersion <= currentVersion)
+ return availableVersion;
+ else
+ return fetchingVersion;
}
public long getBlobSize() {
Modified: trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
2008-11-08 16:06:14 UTC (rev 23428)
+++ trunk/freenet/src/freenet/node/updater/UpdateOverMandatoryManager.java
2008-11-08 16:10:02 UTC (rev 23429)
@@ -61,7 +61,6 @@
public class UpdateOverMandatoryManager {
final NodeUpdateManager updateManager;
-
/** Set of PeerNode's which say (or said before they disconnected)
* the key has been revoked */
private final HashSet<PeerNode> nodesSayKeyRevoked;
@@ -77,15 +76,14 @@
// 2 for reliability, no more as gets very slow/wasteful
static final int MAX_NODES_SENDING_MAIN_JAR = 2;
/** Maximum time between asking for the main jar and it starting to
transfer */
- static final int REQUEST_MAIN_JAR_TIMEOUT = 60*1000;
+ static final int REQUEST_MAIN_JAR_TIMEOUT = 60 * 1000;
//** Grace time before we use UoM to update */
- public static final int GRACE_TIME = 3*60*60*1000; // 3h
+ public static final int GRACE_TIME = 3 * 60 * 60 * 1000; // 3h
private boolean logMINOR;
-
private UserAlert alert;
private static final Pattern extBuildNumberPattern =
Pattern.compile("^ext(?:-jar)?-(\\d+)\\.fblob(\\.tmp)*$");
private static final Pattern mainBuildNumberPattern =
Pattern.compile("^main(?:-jar)?-(\\d+)\\.fblob(\\.tmp)*$");
-
+
public UpdateOverMandatoryManager(NodeUpdateManager manager) {
this.updateManager = manager;
nodesSayKeyRevoked = new HashSet<PeerNode>();
@@ -117,223 +115,244 @@
long extraJarFileLength = m.getLong(DMT.EXTRA_JAR_FILE_LENGTH);
int pingTime = m.getInt(DMT.PING_TIME);
int delayTime = m.getInt(DMT.BWLIMIT_DELAY_TIME);
-
+
// Log it
-
+
logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR) {
- Logger.minor(this, "Update Over Mandatory offer from
node "+source.getPeer()+" : "+source.userToString()+":");
- Logger.minor(this, "Main jar key: "+jarKey+"
version="+mainJarVersion+" length="+mainJarFileLength);
- Logger.minor(this, "Extra jar key: "+extraJarKey+"
version="+extraJarVersion+" length="+extraJarFileLength);
- Logger.minor(this, "Revocation key: "+revocationKey+"
found="+haveRevocationKey+" length="+revocationKeyFileLength+" last had 3 DNFs
"+revocationKeyLastTried+" ms ago, "+revocationKeyDNFs+" DNFs so far");
- Logger.minor(this, "Load stats: "+pingTime+"ms ping,
"+delayTime+"ms bwlimit delay time");
+ Logger.minor(this, "Update Over Mandatory offer from
node " + source.getPeer() + " : " + source.userToString() + ":");
+ Logger.minor(this, "Main jar key: " + jarKey + "
version=" + mainJarVersion + " length=" + mainJarFileLength);
+ Logger.minor(this, "Extra jar key: " + extraJarKey + "
version=" + extraJarVersion + " length=" + extraJarFileLength);
+ Logger.minor(this, "Revocation key: " + revocationKey +
" found=" + haveRevocationKey + " length=" + revocationKeyFileLength + " last
had 3 DNFs " + revocationKeyLastTried + " ms ago, " + revocationKeyDNFs + "
DNFs so far");
+ Logger.minor(this, "Load stats: " + pingTime + "ms
ping, " + delayTime + "ms bwlimit delay time");
}
-
+
// Now the core logic
-
+
// First off, if a node says it has the revocation key, and its
key is the same as ours,
// we should 1) suspend any auto-updates and tell the user, 2)
try to download it, and
// 3) if the download fails, move the notification; if the
download succeeds, process it
-
+
if(haveRevocationKey) {
-
- if(updateManager.isBlown()) return true; // We already
know
-
+
+ if(updateManager.isBlown())
+ return true; // We already know
+
// First, is the key the same as ours?
try {
FreenetURI revocationURI = new
FreenetURI(revocationKey);
if(revocationURI.equals(updateManager.revocationURI)) {
-
+
// Uh oh...
-
+
// Have to do this first to avoid race
condition
synchronized(this) {
nodesSayKeyRevoked.add(source);
}
-
+
// Disable the update
updateManager.peerClaimsKeyBlown(source);
-
+
// Tell the user
alertUser();
-
- System.err.println("Your peer
"+source.userToString()+" says that the auto-update key is blown!");
+
+ System.err.println("Your peer " +
source.userToString() + " says that the auto-update key is blown!");
System.err.println("Attempting to fetch
it...");
-
+
// Try to transfer it.
-
+
Message msg =
DMT.createUOMRequestRevocation(updateManager.node.random.nextLong());
source.sendAsync(msg, new
AsyncMessageCallback() {
+
public void acknowledged() {
// Ok
}
+
public void disconnected() {
// :(
-
System.err.println("Failed to send request for revocation key to
"+source.userToString()+" because it disconnected!");
+
System.err.println("Failed to send request for revocation key to " +
source.userToString() + " because it disconnected!");
synchronized(UpdateOverMandatoryManager.this) {
nodesSayKeyRevokedFailedTransfer.add(source);
}
}
+
public void fatalError() {
// Not good!
-
System.err.println("Failed to send request for revocation key to
"+source.userToString()+" because of a fatal error.");
+
System.err.println("Failed to send request for revocation key to " +
source.userToString() + " because of a fatal error.");
}
+
public void sent() {
// Cool
}
}, updateManager.ctr);
-
- // The reply message will start the
transfer. It includes the revocation URI
- // so we can tell if anything wierd is
happening.
-
+
+ // The reply message will start the transfer.
It includes the revocation URI
+ // so we can tell if anything wierd is
happening.
+
} else {
// Should probably also be a useralert?
- Logger.normal(this, "Node "+source+"
sent us a UOM claiming that the auto-update key was blown, but it used a
different key to us: \nour key="+updateManager.revocationURI+"\nhis
key="+revocationURI);
- System.err.println("Node
"+source.userToString()+" sent us a UOM claiming that the revocation key was
blown, but it used a different key to us: \nour
key="+updateManager.revocationURI+"\nhis key="+revocationURI);
+ Logger.normal(this, "Node " + source +
" sent us a UOM claiming that the auto-update key was blown, but it used a
different key to us: \nour key=" + updateManager.revocationURI + "\nhis key=" +
revocationURI);
+ System.err.println("Node " +
source.userToString() + " sent us a UOM claiming that the revocation key was
blown, but it used a different key to us: \nour key=" +
updateManager.revocationURI + "\nhis key=" + revocationURI);
}
- } catch (MalformedURLException e) {
+ } catch(MalformedURLException e) {
// Should maybe be a useralert?
- Logger.error(this, "Node "+source+" sent us a
UOMAnnounce claiming that the auto-update key was blown, but it had an invalid
revocation URI: "+revocationKey+" : "+e, e);
- System.err.println("Node
"+source.userToString()+" sent us a UOMAnnounce claiming that the revocation
key was blown, but it had an invalid revocation URI: "+revocationKey+" : "+e);
- } catch (NotConnectedException e) {
- System.err.println("Node "+source+" says that
the auto-update key was blown, but has now gone offline! Something bad may be
happening!");
- Logger.error(this, "Node "+source+" says that
the auto-update key was blown, but has now gone offline! Something bad may be
happening!");
+ Logger.error(this, "Node " + source + " sent us
a UOMAnnounce claiming that the auto-update key was blown, but it had an
invalid revocation URI: " + revocationKey + " : " + e, e);
+ System.err.println("Node " +
source.userToString() + " sent us a UOMAnnounce claiming that the revocation
key was blown, but it had an invalid revocation URI: " + revocationKey + " : "
+ e);
+ } catch(NotConnectedException e) {
+ System.err.println("Node " + source + " says
that the auto-update key was blown, but has now gone offline! Something bad may
be happening!");
+ Logger.error(this, "Node " + source + " says
that the auto-update key was blown, but has now gone offline! Something bad may
be happening!");
synchronized(UpdateOverMandatoryManager.this) {
nodesSayKeyRevokedFailedTransfer.add(source);
}
}
-
+
}
-
- if(updateManager.isBlown()) return true; // We already know
-
- if(!updateManager.isEnabled()) return true; // Don't care if
not enabled, except for the revocation URI
-
+
+ if(updateManager.isBlown())
+ return true; // We already know
+
+ if(!updateManager.isEnabled())
+ return true; // Don't care if not enabled, except for
the revocation URI
+
long now = System.currentTimeMillis();
long started =
updateManager.getStartedFetchingNextMainJarTimestamp();
long whenToTakeOverTheNormalUpdater;
- if(started > 0) whenToTakeOverTheNormalUpdater = started +
GRACE_TIME;
- else whenToTakeOverTheNormalUpdater =
System.currentTimeMillis() + GRACE_TIME;
+ if(started > 0)
+ whenToTakeOverTheNormalUpdater = started + GRACE_TIME;
+ else
+ whenToTakeOverTheNormalUpdater =
System.currentTimeMillis() + GRACE_TIME;
boolean isOutdated = updateManager.node.isOudated();
// if the new build is self-mandatory or if the "normal"
updater has been trying to update for more than one hour
- Logger.normal(this, "We received a valid UOMAnnounce :
(isOutdated="+isOutdated+" version="+mainJarVersion +"
whenToTakeOverTheNormalUpdater="+TimeUtil.formatTime(whenToTakeOverTheNormalUpdater-now)+")
file length "+mainJarFileLength+" updateManager version
"+updateManager.newMainJarVersion());
+ Logger.normal(this, "We received a valid UOMAnnounce :
(isOutdated=" + isOutdated + " version=" + mainJarVersion + "
whenToTakeOverTheNormalUpdater=" +
TimeUtil.formatTime(whenToTakeOverTheNormalUpdater - now) + ") file length " +
mainJarFileLength + " updateManager version " +
updateManager.newMainJarVersion());
if(mainJarVersion > Version.buildNumber() && mainJarFileLength
> 0 &&
- mainJarVersion >
updateManager.newMainJarVersion()) {
+ mainJarVersion > updateManager.newMainJarVersion()) {
source.setMainJarOfferedVersion(mainJarVersion);
// Offer is valid.
- if(logMINOR) Logger.minor(this, "Offer is valid");
+ if(logMINOR)
+ Logger.minor(this, "Offer is valid");
if((isOutdated) || whenToTakeOverTheNormalUpdater <
now) {
// Take up the offer, subject to limits on
number of simultaneous downloads.
// If we have fetches running already, then
sendUOMRequestMain() will add the offer to nodesOfferedMainJar,
// so that if all our fetches fail, we can
fetch from this node.
- if(!isOutdated) {
- String howLong =
TimeUtil.formatTime(now - started);
- Logger.error(this, "The update
process seems to have been stuck for "+ howLong +"; let's switch to UoM! SHOULD
NOT HAPPEN! (1)");
- System.out.println("The update
process seems to have been stuck for "+ howLong +"; let's switch to UoM! SHOULD
NOT HAPPEN! (1)");
- } else
- if(logMINOR) Logger.minor(this,
"Fetching via UOM as our build is deprecated");
- // Fetch it
- try {
- FreenetURI mainJarURI = new
FreenetURI(jarKey).setSuggestedEdition(mainJarVersion);
-
if(mainJarURI.equals(updateManager.updateURI.setSuggestedEdition(mainJarVersion)))
-
sendUOMRequestMain(source, true);
- else
-
System.err.println("Node " + source.userToString() + " offered us a new main
jar (version " + mainJarVersion + ") but his key was different to ours:\n" +
- "our
key: " + updateManager.updateURI + "\nhis key:" + mainJarURI);
- } catch(MalformedURLException e) {
- // Should maybe be a useralert?
- Logger.error(this, "Node " +
source + " sent us a UOMAnnounce claiming to have a new jar, but it had an
invalid URI: " + revocationKey + " : " + e, e);
- System.err.println("Node " +
source.userToString() + " sent us a UOMAnnounce claiming to have a new jar, but
it had an invalid URI: " + revocationKey + " : " + e);
- }
+ if(!isOutdated) {
+ String howLong =
TimeUtil.formatTime(now - started);
+ Logger.error(this, "The update process
seems to have been stuck for " + howLong + "; let's switch to UoM! SHOULD NOT
HAPPEN! (1)");
+ System.out.println("The update process
seems to have been stuck for " + howLong + "; let's switch to UoM! SHOULD NOT
HAPPEN! (1)");
+ } else if(logMINOR)
+ Logger.minor(this, "Fetching via UOM as
our build is deprecated");
+ // Fetch it
+ try {
+ FreenetURI mainJarURI = new
FreenetURI(jarKey).setSuggestedEdition(mainJarVersion);
+
if(mainJarURI.equals(updateManager.updateURI.setSuggestedEdition(mainJarVersion)))
+ sendUOMRequestMain(source,
true);
+ else
+ System.err.println("Node " +
source.userToString() + " offered us a new main jar (version " + mainJarVersion
+ ") but his key was different to ours:\n" +
+ "our key: " +
updateManager.updateURI + "\nhis key:" + mainJarURI);
+ } catch(MalformedURLException e) {
+ // Should maybe be a useralert?
+ Logger.error(this, "Node " + source + "
sent us a UOMAnnounce claiming to have a new jar, but it had an invalid URI: "
+ revocationKey + " : " + e, e);
+ System.err.println("Node " +
source.userToString() + " sent us a UOMAnnounce claiming to have a new jar, but
it had an invalid URI: " + revocationKey + " : " + e);
+ }
} else {
// Don't take up the offer. Add to
nodesOfferedMainJar, so that we know where to fetch it from when we need it.
synchronized(this) {
nodesOfferedMainJar.add(source);
}
updateManager.node.getTicker().queueTimedJob(new Runnable() {
-
+
public void run() {
- if(updateManager.isBlown())
return;
- if(!updateManager.isEnabled())
return;
-
if(updateManager.hasNewMainJar()) return;
+ if(updateManager.isBlown())
+ return;
+ if(!updateManager.isEnabled())
+ return;
+
if(updateManager.hasNewMainJar())
+ return;
if(!updateManager.node.isOudated()) {
Logger.error(this, "The
update process seems to have been stuck for too long; let's switch to UoM!
SHOULD NOT HAPPEN! (2)");
System.out.println("The
update process seems to have been stuck for too long; let's switch to UoM!
SHOULD NOT HAPPEN! (2)");
}
maybeRequestMainJar();
}
-
}, whenToTakeOverTheNormalUpdater - now);
}
}
-
+
return true;
}
private void sendUOMRequestMain(final PeerNode source, boolean
addOnFail) {
if(logMINOR)
- Logger.minor(this,
"sendUOMRequestMain("+source+","+addOnFail+")");
- if(!source.isConnected()) return;
+ Logger.minor(this, "sendUOMRequestMain(" + source + ","
+ addOnFail + ")");
+ if(!source.isConnected())
+ return;
synchronized(this) {
long offeredVersion = source.getMainJarOfferedVersion();
if(offeredVersion < updateManager.newMainJarVersion()) {
if(offeredVersion <= 0)
- Logger.error(this, "Not sending UOM
request to "+source+" because it hasn't offered anything!");
- else {
- if(logMINOR) Logger.minor(this, "Not
sending UOM request to "+source+" because we already have its offered version
"+offeredVersion);
- }
+ Logger.error(this, "Not sending UOM
request to " + source + " because it hasn't offered anything!");
+ else
+ if(logMINOR)
+ Logger.minor(this, "Not sending
UOM request to " + source + " because we already have its offered version " +
offeredVersion);
return;
}
if(updateManager.getMainVersion() >= offeredVersion) {
- if(logMINOR) Logger.minor(this, "Not fetching
from "+source+" because current jar version "+updateManager.getMainVersion()+"
is more recent than "+source.getMainJarOfferedVersion());
+ if(logMINOR)
+ Logger.minor(this, "Not fetching from "
+ source + " because current jar version " + updateManager.getMainVersion() + "
is more recent than " + source.getMainJarOfferedVersion());
return;
}
if(nodesAskedSendMainJar.contains(source)) {
- if(logMINOR) Logger.minor(this, "Recently asked
node "+source+" so not re-asking yet.");
+ if(logMINOR)
+ Logger.minor(this, "Recently asked node
" + source + " so not re-asking yet.");
return;
}
if(addOnFail && nodesAskedSendMainJar.size() +
nodesSendingMainJar.size() >= MAX_NODES_SENDING_MAIN_JAR) {
- if(nodesOfferedMainJar.add(source)) {
- System.err.println("Offered main jar by
"+source.userToString()+" (already fetching from
"+nodesSendingMainJar.size()+"), but will use this offer if our current fetches
fail).");
- }
+ if(nodesOfferedMainJar.add(source))
+ System.err.println("Offered main jar by
" + source.userToString() + " (already fetching from " +
nodesSendingMainJar.size() + "), but will use this offer if our current fetches
fail).");
return;
} else {
if(nodesSendingMainJar.contains(source)) {
- if(logMINOR) Logger.minor(this, "Not
fetching main jar from "+source.userToString()+" because already fetching from
that node");
+ if(logMINOR)
+ Logger.minor(this, "Not
fetching main jar from " + source.userToString() + " because already fetching
from that node");
return;
}
nodesAskedSendMainJar.add(source);
}
}
-
+
Message msg =
DMT.createUOMRequestMain(updateManager.node.random.nextLong());
-
+
try {
- System.err.println("Fetching main jar from
"+source.userToString());
+ System.err.println("Fetching main jar from " +
source.userToString());
source.sendAsync(msg, new AsyncMessageCallback() {
+
public void acknowledged() {
// Cool! Wait for the actual transfer.
}
+
public void disconnected() {
- Logger.normal(this, "Disconnected from
"+source.userToString()+" after sending UOMRequestMain");
+ Logger.normal(this, "Disconnected from
" + source.userToString() + " after sending UOMRequestMain");
synchronized(UpdateOverMandatoryManager.this) {
nodesAskedSendMainJar.remove(source);
}
maybeRequestMainJar();
}
+
public void fatalError() {
- Logger.normal(this, "Fatal error from
"+source.userToString()+" after sending UOMRequestMain");
+ Logger.normal(this, "Fatal error from "
+ source.userToString() + " after sending UOMRequestMain");
synchronized(UpdateOverMandatoryManager.this) {
nodesAskedSendMainJar.remove(source);
}
maybeRequestMainJar();
}
+
public void sent() {
// Timeout...
updateManager.node.ps.queueTimedJob(new
Runnable() {
+
public void run() {
synchronized(UpdateOverMandatoryManager.this) {
-
if(!nodesAskedSendMainJar.contains(source)) return;
+
if(!nodesAskedSendMainJar.contains(source))
+ return;
nodesAskedSendMainJar.remove(source); // free up a slot
}
maybeRequestMainJar();
@@ -341,40 +360,42 @@
}, REQUEST_MAIN_JAR_TIMEOUT);
}
}, updateManager.ctr);
- } catch (NotConnectedException e) {
+ } catch(NotConnectedException e) {
synchronized(this) {
nodesAskedSendMainJar.remove(source);
}
maybeRequestMainJar();
}
}
-
-
+
protected void maybeRequestMainJar() {
- PeerNode[] offers;
+ PeerNode[] offers;
+ synchronized(this) {
+ if(nodesAskedSendMainJar.size() +
nodesSendingMainJar.size() >= MAX_NODES_SENDING_MAIN_JAR)
+ return;
+ if(nodesOfferedMainJar.isEmpty())
+ return;
+ offers = nodesOfferedMainJar.toArray(new
PeerNode[nodesOfferedMainJar.size()]);
+ }
+ for(int i = 0; i < offers.length; i++) {
+ if(offers[i].isConnected())
+ continue;
synchronized(this) {
- if(nodesAskedSendMainJar.size() +
nodesSendingMainJar.size()
- >= MAX_NODES_SENDING_MAIN_JAR)
+ if(nodesAskedSendMainJar.size() +
nodesSendingMainJar.size() >= MAX_NODES_SENDING_MAIN_JAR)
return;
- if(nodesOfferedMainJar.isEmpty()) return;
- offers = nodesOfferedMainJar.toArray(new
PeerNode[nodesOfferedMainJar.size()]);
+ if(nodesSendingMainJar.contains(offers[i]))
+ continue;
+ if(nodesAskedSendMainJar.contains(offers[i]))
+ continue;
}
- for(int i=0;i<offers.length;i++) {
- if(offers[i].isConnected()) continue;
- synchronized(this) {
- if(nodesAskedSendMainJar.size() +
nodesSendingMainJar.size()
- >=
MAX_NODES_SENDING_MAIN_JAR)
- return;
-
if(nodesSendingMainJar.contains(offers[i])) continue;
-
if(nodesAskedSendMainJar.contains(offers[i])) continue;
- }
- sendUOMRequestMain(offers[i], false);
- }
+ sendUOMRequestMain(offers[i], false);
+ }
}
private void alertUser() {
synchronized(this) {
- if(alert != null) return;
+ if(alert != null)
+ return;
alert = new PeersSayKeyBlownAlert();
}
updateManager.node.clientCore.alerts.register(alert);
@@ -385,59 +406,58 @@
public PeersSayKeyBlownAlert() {
super(false, null, null, null, null,
UserAlert.CRITICAL_ERROR, true, null, false, null);
}
-
+
@Override
public HTMLNode getHTMLText() {
HTMLNode div = new HTMLNode("div");
-
+
div.addChild("p").addChild("#", l10n("intro"));
-
+
PeerNode[][] nodes = getNodesSayBlown();
PeerNode[] nodesSayBlownConnected = nodes[0];
PeerNode[] nodesSayBlownDisconnected = nodes[1];
PeerNode[] nodesSayBlownFailedTransfer = nodes[2];
-
- if(nodesSayBlownConnected.length > 0) {
+
+ if(nodesSayBlownConnected.length > 0)
div.addChild("p").addChild("#",
l10n("fetching"));
- } else {
+ else
div.addChild("p").addChild("#",
l10n("failedFetch"));
- }
-
+
if(nodesSayBlownConnected.length > 0) {
div.addChild("p").addChild("#",
l10n("connectedSayBlownLabel"));
HTMLNode list = div.addChild("ul");
- for(int
i=0;i<nodesSayBlownConnected.length;i++) {
- list.addChild("li",
nodesSayBlownConnected[i].userToString()+"
("+nodesSayBlownConnected[i].getPeer()+")");
+ for(int i = 0; i <
nodesSayBlownConnected.length; i++) {
+ list.addChild("li",
nodesSayBlownConnected[i].userToString() + " (" +
nodesSayBlownConnected[i].getPeer() + ")");
}
}
-
+
if(nodesSayBlownDisconnected.length > 0) {
div.addChild("p").addChild("#",
l10n("disconnectedSayBlownLabel"));
HTMLNode list = div.addChild("ul");
- for(int
i=0;i<nodesSayBlownDisconnected.length;i++) {
- list.addChild("li",
nodesSayBlownDisconnected[i].userToString()+"
("+nodesSayBlownDisconnected[i].getPeer()+")");
+ for(int i = 0; i <
nodesSayBlownDisconnected.length; i++) {
+ list.addChild("li",
nodesSayBlownDisconnected[i].userToString() + " (" +
nodesSayBlownDisconnected[i].getPeer() + ")");
}
}
-
+
if(nodesSayBlownFailedTransfer.length > 0) {
div.addChild("p").addChild("#",
l10n("failedTransferSayBlownLabel"));
HTMLNode list = div.addChild("ul");
- for(int
i=0;i<nodesSayBlownFailedTransfer.length;i++) {
- list.addChild("li",
nodesSayBlownFailedTransfer[i].userToString()+"
("+nodesSayBlownFailedTransfer[i].getPeer()+")");
+ for(int i = 0; i <
nodesSayBlownFailedTransfer.length; i++) {
+ list.addChild("li",
nodesSayBlownFailedTransfer[i].userToString() + " (" +
nodesSayBlownFailedTransfer[i].getPeer() + ")");
}
}
-
+
return div;
}
private String l10n(String key) {
- return L10n.getString("PeersSayKeyBlownAlert."+key);
+ return L10n.getString("PeersSayKeyBlownAlert." + key);
}
-
+
private String l10n(String key, String pattern, String value) {
- return L10n.getString("PeersSayKeyBlownAlert."+key,
pattern, value);
+ return L10n.getString("PeersSayKeyBlownAlert." + key,
pattern, value);
}
-
+
@Override
public String getText() {
StringBuilder sb = new StringBuilder();
@@ -446,39 +466,38 @@
PeerNode[] nodesSayBlownConnected = nodes[0];
PeerNode[] nodesSayBlownDisconnected = nodes[1];
PeerNode[] nodesSayBlownFailedTransfer = nodes[2];
-
- if(nodesSayBlownConnected.length > 0) {
+
+ if(nodesSayBlownConnected.length > 0)
sb.append(l10n("fetching")).append("\n\n");
- } else {
+ else
sb.append(l10n("failedFetch")).append("\n\n");
- }
-
+
if(nodesSayBlownConnected.length > 0) {
sb.append(l10n("connectedSayBlownLabel")).append("\n\n");
- for(int
i=0;i<nodesSayBlownConnected.length;i++) {
-
sb.append(nodesSayBlownConnected[i].userToString()+"
("+nodesSayBlownConnected[i].getPeer()+")").append("\n");
+ for(int i = 0; i <
nodesSayBlownConnected.length; i++) {
+
sb.append(nodesSayBlownConnected[i].userToString() + " (" +
nodesSayBlownConnected[i].getPeer() + ")").append("\n");
}
sb.append("\n");
}
-
+
if(nodesSayBlownDisconnected.length > 0) {
sb.append(l10n("disconnectedSayBlownLabel"));
-
- for(int
i=0;i<nodesSayBlownDisconnected.length;i++) {
-
sb.append(nodesSayBlownDisconnected[i].userToString()+"
("+nodesSayBlownDisconnected[i].getPeer()+")").append("\n");
+
+ for(int i = 0; i <
nodesSayBlownDisconnected.length; i++) {
+
sb.append(nodesSayBlownDisconnected[i].userToString() + " (" +
nodesSayBlownDisconnected[i].getPeer() + ")").append("\n");
}
sb.append("\n");
}
-
+
if(nodesSayBlownFailedTransfer.length > 0) {
sb.append(l10n("failedTransferSayBlownLabel"));
-
- for(int
i=0;i<nodesSayBlownFailedTransfer.length;i++) {
-
sb.append(nodesSayBlownFailedTransfer[i].userToString()+"
("+nodesSayBlownFailedTransfer[i].getPeer()+")").append('\n');
+
+ for(int i = 0; i <
nodesSayBlownFailedTransfer.length; i++) {
+
sb.append(nodesSayBlownFailedTransfer[i].userToString() + " (" +
nodesSayBlownFailedTransfer[i].getPeer() + ")").append('\n');
}
sb.append("\n");
}
-
+
return sb.toString();
}
@@ -496,7 +515,6 @@
public String getShortText() {
return l10n("short");
}
-
}
public PeerNode[][] getNodesSayBlown() {
@@ -505,7 +523,7 @@
Vector<PeerNode> nodesFailedSayRevoked = new Vector<PeerNode>();
synchronized(this) {
PeerNode[] nodesSayRevoked =
nodesSayKeyRevoked.toArray(new PeerNode[nodesSayKeyRevoked.size()]);
- for(int i=0;i<nodesSayRevoked.length;i++) {
+ for(int i = 0; i < nodesSayRevoked.length; i++) {
PeerNode pn = nodesSayRevoked[i];
if(nodesSayKeyRevokedFailedTransfer.contains(pn))
nodesFailedSayRevoked.add(pn);
@@ -513,7 +531,7 @@
nodesConnectedSayRevoked.add(pn);
}
}
- for(int i=0;i<nodesConnectedSayRevoked.size();i++) {
+ for(int i = 0; i < nodesConnectedSayRevoked.size(); i++) {
PeerNode pn = nodesConnectedSayRevoked.get(i);
if(!pn.isConnected()) {
nodesDisconnectedSayRevoked.add(pn);
@@ -522,11 +540,11 @@
continue;
}
}
- return new PeerNode[][] {
+ return new PeerNode[][]{
nodesConnectedSayRevoked.toArray(new
PeerNode[nodesConnectedSayRevoked.size()]),
- nodesDisconnectedSayRevoked.toArray(new
PeerNode[nodesDisconnectedSayRevoked.size()]),
- nodesFailedSayRevoked.toArray(new
PeerNode[nodesFailedSayRevoked.size()]),
- };
+ nodesDisconnectedSayRevoked.toArray(new
PeerNode[nodesDisconnectedSayRevoked.size()]),
+ nodesFailedSayRevoked.toArray(new
PeerNode[nodesFailedSayRevoked.size()]),
+ };
}
/**
@@ -537,91 +555,91 @@
*/
public boolean handleRequestRevocation(Message m, final PeerNode
source) {
// Do we have the data?
-
+
File data = updateManager.revocationChecker.getBlobFile();
-
+
if(data == null) {
- Logger.normal(this, "Peer "+source+" asked us for the
blob file for the revocation key but we don't have it!");
+ Logger.normal(this, "Peer " + source + " asked us for
the blob file for the revocation key but we don't have it!");
// Probably a race condition on reconnect, hopefully
we'll be asked again
return true;
}
-
+
final long uid = m.getLong(DMT.UID);
-
- RandomAccessFileWrapper raf;
+
+ RandomAccessFileWrapper raf;
try {
raf = new RandomAccessFileWrapper(data, "r");
- } catch (FileNotFoundException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the revocation key, we have downloaded it but don't have the file
even though we did have it when we checked!: "+e, e);
+ } catch(FileNotFoundException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the revocation key, we have downloaded it but don't have the
file even though we did have it when we checked!: " + e, e);
return true;
}
-
+
final PartiallyReceivedBulk prb;
long length;
try {
length = raf.size();
- prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
- Node.PACKET_SIZE, raf, true);
- } catch (IOException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the revocation key, we have downloaded it but we can't determine
the file size: "+e, e);
+ prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
+ Node.PACKET_SIZE, raf, true);
+ } catch(IOException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the revocation key, we have downloaded it but we can't
determine the file size: " + e, e);
return true;
}
-
+
final BulkTransmitter bt;
try {
bt = new BulkTransmitter(prb, source, uid, false,
updateManager.ctr);
- } catch (DisconnectedException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the revocation key, then disconnected: "+e, e);
+ } catch(DisconnectedException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the revocation key, then disconnected: " + e, e);
return true;
}
-
+
final Runnable r = new Runnable() {
+
public void run() {
- if(!bt.send()) {
- Logger.error(this, "Failed to send
revocation key blob to "+source.userToString()+" : "+bt.getCancelReason());
- } else {
- Logger.normal(this, "Sent revocation
key blob to "+source.userToString());
- }
+ if(!bt.send())
+ Logger.error(this, "Failed to send
revocation key blob to " + source.userToString() + " : " +
bt.getCancelReason());
+ else
+ Logger.normal(this, "Sent revocation
key blob to " + source.userToString());
}
-
};
-
+
Message msg = DMT.createUOMSendingRevocation(uid, length,
updateManager.revocationURI.toString());
-
+
try {
source.sendAsync(msg, new AsyncMessageCallback() {
+
public void acknowledged() {
if(logMINOR)
Logger.minor(this, "Sending
data...");
// Send the data
- updateManager.node.executor.execute(r,
"Revocation key send for "+uid+" to "+source.userToString());
+ updateManager.node.executor.execute(r,
"Revocation key send for " + uid + " to " + source.userToString());
}
+
public void disconnected() {
// Argh
- Logger.error(this, "Peer "+source+"
asked us for the blob file for the revocation key, then disconnected when we
tried to send the UOMSendingRevocation");
+ Logger.error(this, "Peer " + source + "
asked us for the blob file for the revocation key, then disconnected when we
tried to send the UOMSendingRevocation");
}
public void fatalError() {
// Argh
- Logger.error(this, "Peer "+source+"
asked us for the blob file for the revocation key, then got a fatal error when
we tried to send the UOMSendingRevocation");
+ Logger.error(this, "Peer " + source + "
asked us for the blob file for the revocation key, then got a fatal error when
we tried to send the UOMSendingRevocation");
}
public void sent() {
if(logMINOR)
Logger.minor(this, "Message
sent, data soon");
}
-
+
@Override
public String toString() {
- return super.toString() +
"("+uid+":"+source.getPeer()+")";
+ return super.toString() + "(" + uid +
":" + source.getPeer() + ")";
}
-
}, updateManager.ctr);
- } catch (NotConnectedException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the revocation key, then disconnected when we tried to send the
UOMSendingRevocation: "+e, e);
+ } catch(NotConnectedException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the revocation key, then disconnected when we tried to send
the UOMSendingRevocation: " + e, e);
return true;
}
-
+
return true;
}
@@ -632,9 +650,9 @@
FreenetURI revocationURI;
try {
revocationURI = new FreenetURI(key);
- } catch (MalformedURLException e) {
- Logger.error(this, "Failed receiving recovation because
URI not parsable: "+e+" for "+key, e);
- System.err.println("Failed receiving recovation because
URI not parsable: "+e+" for "+key);
+ } catch(MalformedURLException e) {
+ Logger.error(this, "Failed receiving recovation because
URI not parsable: " + e + " for " + key, e);
+ System.err.println("Failed receiving recovation because
URI not parsable: " + e + " for " + key);
e.printStackTrace();
synchronized(this) {
// Wierd case of a failed transfer
@@ -643,12 +661,12 @@
cancelSend(source, uid);
return true;
}
-
+
if(!revocationURI.equals(updateManager.revocationURI)) {
- System.err.println("Node sending us a revocation
certificate from the wrong URI:\n"+
- "Node: "+source.userToString()+"\n"+
- "Our URI:
"+updateManager.revocationURI+"\n"+
- "Their URI: "+revocationURI);
+ System.err.println("Node sending us a revocation
certificate from the wrong URI:\n" +
+ "Node: " + source.userToString() + "\n" +
+ "Our URI: " + updateManager.revocationURI +
"\n" +
+ "Their URI: " + revocationURI);
synchronized(this) {
// Wierd case of a failed transfer
nodesSayKeyRevokedFailedTransfer.add(source);
@@ -656,69 +674,68 @@
cancelSend(source, uid);
return true;
}
-
+
if(updateManager.isBlown()) {
if(logMINOR)
- Logger.minor(this, "Already blown, so not
receiving from "+source+ "("+uid+")");
+ Logger.minor(this, "Already blown, so not
receiving from " + source + "(" + uid + ")");
cancelSend(source, uid);
return true;
}
-
+
if(length > NodeUpdateManager.MAX_REVOCATION_KEY_LENGTH) {
- System.err.println("Node "+source.userToString()+"
offered us a revocation certificate "+SizeUtil.formatSize(length)+" long. This
is unacceptably long so we have refused the transfer.");
- Logger.error(this, "Node "+source.userToString()+"
offered us a revocation certificate "+SizeUtil.formatSize(length)+" long. This
is unacceptably long so we have refused the transfer.");
+ System.err.println("Node " + source.userToString() + "
offered us a revocation certificate " + SizeUtil.formatSize(length) + " long.
This is unacceptably long so we have refused the transfer.");
+ Logger.error(this, "Node " + source.userToString() + "
offered us a revocation certificate " + SizeUtil.formatSize(length) + " long.
This is unacceptably long so we have refused the transfer.");
synchronized(UpdateOverMandatoryManager.this) {
nodesSayKeyRevokedFailedTransfer.add(source);
}
cancelSend(source, uid);
return true;
}
-
+
// Okay, we can receive it
-
+
final File temp;
-
+
try {
temp = File.createTempFile("revocation-", ".fblob.tmp",
updateManager.node.clientCore.getPersistentTempDir());
temp.deleteOnExit();
- } catch (IOException e) {
- System.err.println("Cannot save revocation certificate
to disk and therefore cannot fetch it from our peer!: "+e);
+ } catch(IOException e) {
+ System.err.println("Cannot save revocation certificate
to disk and therefore cannot fetch it from our peer!: " + e);
e.printStackTrace();
- updateManager.blow("Cannot fetch the revocation
certificate from our peer because we cannot write it to disk: "+e);
+ updateManager.blow("Cannot fetch the revocation
certificate from our peer because we cannot write it to disk: " + e);
cancelSend(source, uid);
return true;
}
-
- RandomAccessFileWrapper raf;
+
+ RandomAccessFileWrapper raf;
try {
raf = new RandomAccessFileWrapper(temp, "rw");
- } catch (FileNotFoundException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the revocation key, we have downloaded it but don't have the file
even though we did have it when we checked!: "+e, e);
+ } catch(FileNotFoundException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the revocation key, we have downloaded it but don't have the
file even though we did have it when we checked!: " + e, e);
return true;
}
-
- PartiallyReceivedBulk prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
- Node.PACKET_SIZE, raf, false);
-
+
+ PartiallyReceivedBulk prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
+ Node.PACKET_SIZE, raf, false);
+
final BulkReceiver br = new BulkReceiver(prb, source, uid,
updateManager.ctr);
-
+
updateManager.node.executor.execute(new Runnable() {
public void run() {
- if(br.receive()) {
+ if(br.receive())
// Success!
processRevocationBlob(temp, source);
- } else {
- Logger.error(this, "Failed to transfer
revocation certificate from "+source);
- System.err.println("Failed to transfer
revocation certificate from "+source);
+ else {
+ Logger.error(this, "Failed to transfer
revocation certificate from " + source);
+ System.err.println("Failed to transfer
revocation certificate from " + source);
synchronized(UpdateOverMandatoryManager.this) {
nodesSayKeyRevokedFailedTransfer.add(source);
}
}
}
-
- }, "Revocation key receive for "+uid+" from
"+source.userToString());
-
+ }, "Revocation key receive for " + uid + " from " +
source.userToString());
+
return true;
}
@@ -727,27 +744,27 @@
* @param temp The file it was written to.
*/
protected void processRevocationBlob(final File temp, final PeerNode
source) {
-
+
SimpleBlockSet blocks = new SimpleBlockSet();
-
+
DataInputStream dis = null;
try {
dis = new DataInputStream(new BufferedInputStream(new
FileInputStream(temp)));
BinaryBlob.readBinaryBlob(dis, blocks, true);
- } catch (FileNotFoundException e) {
- Logger.error(this, "Somebody deleted "+temp+" ? We lost
the revocation certificate from "+source.userToString()+"!");
- System.err.println("Somebody deleted "+temp+" ? We lost
the revocation certificate from "+source.userToString()+"!");
- updateManager.blow("Somebody deleted "+temp+" ? We lost
the revocation certificate from "+source.userToString()+"!");
+ } catch(FileNotFoundException e) {
+ Logger.error(this, "Somebody deleted " + temp + " ? We
lost the revocation certificate from " + source.userToString() + "!");
+ System.err.println("Somebody deleted " + temp + " ? We
lost the revocation certificate from " + source.userToString() + "!");
+ updateManager.blow("Somebody deleted " + temp + " ? We
lost the revocation certificate from " + source.userToString() + "!");
return;
- } catch (IOException e) {
- Logger.error(this, "Could not read revocation cert from
temp file "+temp+" from node "+source.userToString()+" !");
- System.err.println("Could not read revocation cert from
temp file "+temp+" from node "+source.userToString()+" !");
- updateManager.blow("Could not read revocation cert from
temp file "+temp+" from node "+source.userToString()+" !");
+ } catch(IOException e) {
+ Logger.error(this, "Could not read revocation cert from
temp file " + temp + " from node " + source.userToString() + " !");
+ System.err.println("Could not read revocation cert from
temp file " + temp + " from node " + source.userToString() + " !");
+ updateManager.blow("Could not read revocation cert from
temp file " + temp + " from node " + source.userToString() + " !");
// FIXME will be kept until exit for debugging purposes
return;
- } catch (BinaryBlobFormatException e) {
- Logger.error(this, "Peer "+source.userToString()+" sent
us an invalid revocation certificate!: "+e+" (data in "+temp+")", e);
- System.err.println("Peer "+source.userToString()+" sent
us an invalid revocation certificate!: "+e+" (data in "+temp+")");
+ } catch(BinaryBlobFormatException e) {
+ Logger.error(this, "Peer " + source.userToString() + "
sent us an invalid revocation certificate!: " + e + " (data in " + temp + ")",
e);
+ System.err.println("Peer " + source.userToString() + "
sent us an invalid revocation certificate!: " + e + " (data in " + temp + ")");
// Probably malicious, might just be buggy, either way,
it's not blown
e.printStackTrace();
synchronized(UpdateOverMandatoryManager.this) {
@@ -759,54 +776,54 @@
if(dis != null)
try {
dis.close();
- } catch (IOException e) {
+ } catch(IOException e) {
// Ignore
}
}
-
+
// Fetch our revocation key from the datastore plus the binary
blob
-
- FetchContext tempContext =
updateManager.node.clientCore.makeClient((short)0, true).getFetchContext();
+
+ FetchContext tempContext =
updateManager.node.clientCore.makeClient((short) 0, true).getFetchContext();
tempContext.localRequestOnly = true;
tempContext.blocks = blocks;
-
+
File f;
FileBucket b = null;
try {
f = File.createTempFile("revocation-", ".fblob.tmp",
updateManager.node.clientCore.getPersistentTempDir());
b = new FileBucket(f, false, false, true, true, true);
- } catch (IOException e) {
- Logger.error(this, "Cannot share revocation key from
"+source.userToString()+" with our peers because cannot write the cleaned
version to disk: "+e, e);
- System.err.println("Cannot share revocation key from
"+source.userToString()+" with our peers because cannot write the cleaned
version to disk: "+e);
+ } catch(IOException e) {
+ Logger.error(this, "Cannot share revocation key from "
+ source.userToString() + " with our peers because cannot write the cleaned
version to disk: " + e, e);
+ System.err.println("Cannot share revocation key from "
+ source.userToString() + " with our peers because cannot write the cleaned
version to disk: " + e);
e.printStackTrace();
b = null;
f = null;
}
final FileBucket cleanedBlob = b;
final File cleanedBlobFile = f;
-
+
ClientCallback myCallback = new ClientCallback() {
public void onFailure(FetchException e, ClientGetter
state) {
if(e.mode == FetchException.CANCELLED) {
// Eh?
- Logger.error(this, "Cancelled fetch
from store/blob of revocation certificate from "+source.userToString());
- System.err.println("Cancelled fetch
from store/blob of revocation certificate from "+source.userToString()+" to
"+temp+" - please report to developers");
- // Probably best to keep files around
for now.
+ Logger.error(this, "Cancelled fetch
from store/blob of revocation certificate from " + source.userToString());
+ System.err.println("Cancelled fetch
from store/blob of revocation certificate from " + source.userToString() + " to
" + temp + " - please report to developers");
+ // Probably best to keep files around for now.
} else if(e.isFatal()) {
// Blown: somebody inserted a
revocation message, but it was corrupt as inserted
// However it had valid signatures etc.
-
- System.err.println("Got revocation
certificate from "+source.userToString()+" (fatal error i.e. someone with the
key inserted bad data)");
+
+ System.err.println("Got revocation
certificate from " + source.userToString() + " (fatal error i.e. someone with
the key inserted bad data)");
// Blow the update, and propagate the
revocation certificate.
updateManager.revocationChecker.onFailure(e, state, cleanedBlobFile);
temp.delete();
-
+
insertBlob(updateManager.revocationChecker.getBlobFile());
-
+
} else {
- Logger.error(this, "Failed to fetch
revocation certificate from blob from "+source.userToString());
- System.err.println("Failed to fetch
revocation certificate from blob from "+source.userToString());
+ Logger.error(this, "Failed to fetch
revocation certificate from blob from " + source.userToString());
+ System.err.println("Failed to fetch
revocation certificate from blob from " + source.userToString());
synchronized(UpdateOverMandatoryManager.this) {
nodesSayKeyRevokedFailedTransfer.add(source);
}
@@ -830,7 +847,7 @@
}
public void onSuccess(FetchResult result, ClientGetter
state) {
- System.err.println("Got revocation certificate
from "+source.userToString());
+ System.err.println("Got revocation certificate
from " + source.userToString());
updateManager.revocationChecker.onSuccess(result, state, cleanedBlobFile);
temp.delete();
insertBlob(updateManager.revocationChecker.getBlobFile());
@@ -839,44 +856,50 @@
public void onSuccess(BaseClientPutter state) {
// Ignore, not possible
}
-
};
-
- ClientGetter cg = new ClientGetter(myCallback,
-
updateManager.node.clientCore.requestStarters.chkFetchScheduler,
-
updateManager.node.clientCore.requestStarters.sskFetchScheduler,
- updateManager.revocationURI, tempContext,
(short)0, this, null, cleanedBlob);
-
+
+ ClientGetter cg = new ClientGetter(myCallback,
+
updateManager.node.clientCore.requestStarters.chkFetchScheduler,
+
updateManager.node.clientCore.requestStarters.sskFetchScheduler,
+ updateManager.revocationURI, tempContext, (short) 0,
this, null, cleanedBlob);
+
try {
cg.start();
- } catch (FetchException e1) {
- System.err.println("Failed to decode UOM blob: "+e1);
+ } catch(FetchException e1) {
+ System.err.println("Failed to decode UOM blob: " + e1);
e1.printStackTrace();
myCallback.onFailure(e1, cg);
}
-
+
}
protected void insertBlob(final File blob) {
ClientCallback callback = new ClientCallback() {
+
public void onFailure(FetchException e, ClientGetter
state) {
// Ignore, can't happen
}
+
public void onFailure(InsertException e,
BaseClientPutter state) {
- Logger.error(this, "Failed to insert revocation
key binary blob: "+e, e);
+ Logger.error(this, "Failed to insert revocation
key binary blob: " + e, e);
}
+
public void onFetchable(BaseClientPutter state) {
// Ignore
}
+
public void onGeneratedURI(FreenetURI uri,
BaseClientPutter state) {
// Ignore
}
+
public void onMajorProgress() {
// Ignore
}
+
public void onSuccess(FetchResult result, ClientGetter
state) {
// Ignore, can't happen
}
+
public void onSuccess(BaseClientPutter state) {
// All done. Cool.
Logger.normal(this, "Inserted binary blob for
revocation key");
@@ -884,14 +907,14 @@
};
FileBucket bucket = new FileBucket(blob, true, false, false,
false, false);
ClientPutter putter = new ClientPutter(callback, bucket,
- FreenetURI.EMPTY_CHK_URI, null,
updateManager.node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS).getInsertContext(true),
-
updateManager.node.clientCore.requestStarters.chkPutScheduler,
-
updateManager.node.clientCore.requestStarters.sskPutScheduler,
- RequestStarter.INTERACTIVE_PRIORITY_CLASS,
false, false, this, null, null, true);
+ FreenetURI.EMPTY_CHK_URI, null,
updateManager.node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS).getInsertContext(true),
+
updateManager.node.clientCore.requestStarters.chkPutScheduler,
+
updateManager.node.clientCore.requestStarters.sskPutScheduler,
+ RequestStarter.INTERACTIVE_PRIORITY_CLASS, false,
false, this, null, null, true);
try {
putter.start(false);
- } catch (InsertException e1) {
- Logger.error(this, "Failed to start insert of
revocation key binary blob: "+e1, e1);
+ } catch(InsertException e1) {
+ Logger.error(this, "Failed to start insert of
revocation key binary blob: " + e1, e1);
}
}
@@ -899,7 +922,7 @@
Message msg = DMT.createFNPBulkReceiveAborted(uid);
try {
source.sendAsync(msg, null, updateManager.ctr);
- } catch (NotConnectedException e1) {
+ } catch(NotConnectedException e1) {
// Ignore
}
}
@@ -910,93 +933,93 @@
public boolean handleRequestMain(Message m, final PeerNode source) {
// Do we have the data?
-
+
int version = updateManager.newMainJarVersion();
File data = updateManager.getMainBlob(version);
-
+
if(data == null) {
- Logger.normal(this, "Peer "+source+" asked us for the
blob file for the revocation key for the main jar but we don't have it!");
+ Logger.normal(this, "Peer " + source + " asked us for
the blob file for the revocation key for the main jar but we don't have it!");
// Probably a race condition on reconnect, hopefully
we'll be asked again
return true;
}
-
+
final long uid = m.getLong(DMT.UID);
-
- RandomAccessFileWrapper raf;
+
+ RandomAccessFileWrapper raf;
try {
raf = new RandomAccessFileWrapper(data, "r");
- } catch (FileNotFoundException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the main jar, we have downloaded it but don't have the file even
though we did have it when we checked!: "+e, e);
+ } catch(FileNotFoundException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, we have downloaded it but don't have the file
even though we did have it when we checked!: " + e, e);
return true;
}
-
+
final PartiallyReceivedBulk prb;
long length;
try {
length = raf.size();
- prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
- Node.PACKET_SIZE, raf, true);
- } catch (IOException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the main jar, we have downloaded it but we can't determine the
file size: "+e, e);
+ prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
+ Node.PACKET_SIZE, raf, true);
+ } catch(IOException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, we have downloaded it but we can't determine
the file size: " + e, e);
return true;
}
-
+
final BulkTransmitter bt;
try {
bt = new BulkTransmitter(prb, source, uid, false,
updateManager.ctr);
- } catch (DisconnectedException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the main jar, then disconnected: "+e, e);
+ } catch(DisconnectedException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, then disconnected: " + e, e);
return true;
}
-
+
final Runnable r = new Runnable() {
+
public void run() {
- if(!bt.send()) {
- Logger.error(this, "Failed to send main
jar blob to "+source.userToString()+" : "+bt.getCancelReason());
- } else {
- Logger.normal(this, "Sent main jar blob
to "+source.userToString());
- }
+ if(!bt.send())
+ Logger.error(this, "Failed to send main
jar blob to " + source.userToString() + " : " + bt.getCancelReason());
+ else
+ Logger.normal(this, "Sent main jar blob
to " + source.userToString());
}
-
};
-
+
Message msg = DMT.createUOMSendingMain(uid, length,
updateManager.updateURI.toString(), version);
-
+
try {
source.sendAsync(msg, new AsyncMessageCallback() {
+
public void acknowledged() {
if(logMINOR)
Logger.minor(this, "Sending
data...");
// Send the data
-
- updateManager.node.executor.execute(r,
"Main jar send for "+uid+" to "+source.userToString());
+
+ updateManager.node.executor.execute(r,
"Main jar send for " + uid + " to " + source.userToString());
}
+
public void disconnected() {
// Argh
- Logger.error(this, "Peer "+source+"
asked us for the blob file for the main jar, then disconnected when we tried to
send the UOMSendingMain");
+ Logger.error(this, "Peer " + source + "
asked us for the blob file for the main jar, then disconnected when we tried to
send the UOMSendingMain");
}
public void fatalError() {
// Argh
- Logger.error(this, "Peer "+source+"
asked us for the blob file for the main jar, then got a fatal error when we
tried to send the UOMSendingMain");
+ Logger.error(this, "Peer " + source + "
asked us for the blob file for the main jar, then got a fatal error when we
tried to send the UOMSendingMain");
}
public void sent() {
if(logMINOR)
Logger.minor(this, "Message
sent, data soon");
}
-
+
@Override
public String toString() {
- return super.toString() +
"("+uid+":"+source.getPeer()+")";
+ return super.toString() + "(" + uid +
":" + source.getPeer() + ")";
}
-
}, updateManager.ctr);
- } catch (NotConnectedException e) {
- Logger.error(this, "Peer "+source+" asked us for the
blob file for the main jar, then disconnected when we tried to send the
UOMSendingMain: "+e, e);
+ } catch(NotConnectedException e) {
+ Logger.error(this, "Peer " + source + " asked us for
the blob file for the main jar, then disconnected when we tried to send the
UOMSendingMain: " + e, e);
return true;
}
-
+
return true;
}
@@ -1008,9 +1031,9 @@
final FreenetURI jarURI;
try {
jarURI = new
FreenetURI(key).setSuggestedEdition(version);
- } catch (MalformedURLException e) {
- Logger.error(this, "Failed receiving main jar
"+version+" because URI not parsable: "+e+" for "+key, e);
- System.err.println("Failed receiving main jar
"+version+" because URI not parsable: "+e+" for "+key);
+ } catch(MalformedURLException e) {
+ Logger.error(this, "Failed receiving main jar " +
version + " because URI not parsable: " + e + " for " + key, e);
+ System.err.println("Failed receiving main jar " +
version + " because URI not parsable: " + e + " for " + key);
e.printStackTrace();
cancelSend(source, uid);
synchronized(this) {
@@ -1018,32 +1041,32 @@
}
return true;
}
-
+
if(!jarURI.equals(updateManager.updateURI.setSuggestedEdition(version))) {
- System.err.println("Node sending us a main jar update
("+version+") from the wrong URI:\n"+
- "Node: "+source.userToString()+"\n"+
- "Our URI:
"+updateManager.updateURI+"\n"+
- "Their URI: "+jarURI);
+ System.err.println("Node sending us a main jar update
(" + version + ") from the wrong URI:\n" +
+ "Node: " + source.userToString() + "\n" +
+ "Our URI: " + updateManager.updateURI + "\n" +
+ "Their URI: " + jarURI);
cancelSend(source, uid);
synchronized(this) {
this.nodesAskedSendMainJar.remove(source);
}
return true;
}
-
+
if(updateManager.isBlown()) {
if(logMINOR)
- Logger.minor(this, "Key blown, so not receiving
main jar from "+source+ "("+uid+")");
+ Logger.minor(this, "Key blown, so not receiving
main jar from " + source + "(" + uid + ")");
cancelSend(source, uid);
synchronized(this) {
this.nodesAskedSendMainJar.remove(source);
}
return true;
}
-
+
if(length > NodeUpdateManager.MAX_MAIN_JAR_LENGTH) {
- System.err.println("Node "+source.userToString()+"
offered us a main jar ("+version+") "+SizeUtil.formatSize(length)+" long. This
is unacceptably long so we have refused the transfer.");
- Logger.error(this, "Node "+source.userToString()+"
offered us a main jar ("+version+") "+SizeUtil.formatSize(length)+" long. This
is unacceptably long so we have refused the transfer.");
+ System.err.println("Node " + source.userToString() + "
offered us a main jar (" + version + ") " + SizeUtil.formatSize(length) + "
long. This is unacceptably long so we have refused the transfer.");
+ Logger.error(this, "Node " + source.userToString() + "
offered us a main jar (" + version + ") " + SizeUtil.formatSize(length) + "
long. This is unacceptably long so we have refused the transfer.");
// If the transfer fails, we don't try again.
cancelSend(source, uid);
synchronized(this) {
@@ -1051,16 +1074,16 @@
}
return true;
}
-
+
// Okay, we can receive it
-
+
final File temp;
-
+
try {
temp = File.createTempFile("main-", ".fblob.tmp",
updateManager.node.clientCore.getPersistentTempDir());
temp.deleteOnExit();
- } catch (IOException e) {
- System.err.println("Cannot save new main jar to disk
and therefore cannot fetch it from our peer!: "+e);
+ } catch(IOException e) {
+ System.err.println("Cannot save new main jar to disk
and therefore cannot fetch it from our peer!: " + e);
e.printStackTrace();
cancelSend(source, uid);
synchronized(this) {
@@ -1068,23 +1091,23 @@
}
return true;
}
-
- RandomAccessFileWrapper raf;
+
+ RandomAccessFileWrapper raf;
try {
raf = new RandomAccessFileWrapper(temp, "rw");
- } catch (FileNotFoundException e) {
- Logger.error(this, "Peer "+source+" sending us a main
jar binary blob, but we lost the temp file "+temp+" : "+e, e);
+ } catch(FileNotFoundException e) {
+ Logger.error(this, "Peer " + source + " sending us a
main jar binary blob, but we lost the temp file " + temp + " : " + e, e);
synchronized(this) {
this.nodesAskedSendMainJar.remove(source);
}
return true;
}
-
- PartiallyReceivedBulk prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
- Node.PACKET_SIZE, raf, false);
-
+
+ PartiallyReceivedBulk prb = new
PartiallyReceivedBulk(updateManager.node.getUSM(), length,
+ Node.PACKET_SIZE, raf, false);
+
final BulkReceiver br = new BulkReceiver(prb, source, uid,
updateManager.ctr);
-
+
updateManager.node.executor.execute(new Runnable() {
public void run() {
@@ -1093,12 +1116,12 @@
nodesAskedSendMainJar.remove(source);
nodesSendingMainJar.add(source);
}
- if(br.receive()) {
+ if(br.receive())
// Success!
processMainJarBlob(temp,
source, version, jarURI);
- } else {
- Logger.error(this, "Failed to
transfer main jar "+version+" from "+source);
- System.err.println("Failed to
transfer main jar "+version+" from "+source);
+ else {
+ Logger.error(this, "Failed to
transfer main jar " + version + " from " + source);
+ System.err.println("Failed to
transfer main jar " + version + " from " + source);
}
} finally {
synchronized(UpdateOverMandatoryManager.class) {
@@ -1106,31 +1129,30 @@
}
}
}
-
- }, "Main jar ("+version+") receive for "+uid+" from
"+source.userToString());
-
+ }, "Main jar (" + version + ") receive for " + uid + " from " +
source.userToString());
+
return true;
}
protected void processMainJarBlob(final File temp, final PeerNode
source, final int version, FreenetURI uri) {
SimpleBlockSet blocks = new SimpleBlockSet();
-
+
DataInputStream dis = null;
try {
dis = new DataInputStream(new BufferedInputStream(new
FileInputStream(temp)));
BinaryBlob.readBinaryBlob(dis, blocks, true);
- } catch (FileNotFoundException e) {
- Logger.error(this, "Somebody deleted "+temp+" ? We lost
the main jar ("+version+") from "+source.userToString()+"!");
- System.err.println("Somebody deleted "+temp+" ? We lost
the main jar ("+version+") from "+source.userToString()+"!");
+ } catch(FileNotFoundException e) {
+ Logger.error(this, "Somebody deleted " + temp + " ? We
lost the main jar (" + version + ") from " + source.userToString() + "!");
+ System.err.println("Somebody deleted " + temp + " ? We
lost the main jar (" + version + ") from " + source.userToString() + "!");
return;
- } catch (IOException e) {
- Logger.error(this, "Could not read main jar
("+version+") from temp file "+temp+" from node "+source.userToString()+" !");
- System.err.println("Could not read main jar
("+version+") from temp file "+temp+" from node "+source.userToString()+" !");
+ } catch(IOException e) {
+ Logger.error(this, "Could not read main jar (" +
version + ") from temp file " + temp + " from node " + source.userToString() +
" !");
+ System.err.println("Could not read main jar (" +
version + ") from temp file " + temp + " from node " + source.userToString() +
" !");
// FIXME will be kept until exit for debugging purposes
return;
- } catch (BinaryBlobFormatException e) {
- Logger.error(this, "Peer "+source.userToString()+" sent
us an invalid main jar ("+version+")!: "+e, e);
- System.err.println("Peer "+source.userToString()+" sent
us an invalid main jar ("+version+")!: "+e);
+ } catch(BinaryBlobFormatException e) {
+ Logger.error(this, "Peer " + source.userToString() + "
sent us an invalid main jar (" + version + ")!: " + e, e);
+ System.err.println("Peer " + source.userToString() + "
sent us an invalid main jar (" + version + ")!: " + e);
e.printStackTrace();
// FIXME will be kept until exit for debugging purposes
return;
@@ -1138,48 +1160,48 @@
if(dis != null)
try {
dis.close();
- } catch (IOException e) {
+ } catch(IOException e) {
// Ignore
}
}
-
+
// Fetch the jar from the datastore plus the binary blob
-
- FetchContext tempContext =
updateManager.node.clientCore.makeClient((short)0, true).getFetchContext();
+
+ FetchContext tempContext =
updateManager.node.clientCore.makeClient((short) 0, true).getFetchContext();
tempContext.localRequestOnly = true;
tempContext.blocks = blocks;
-
+
File f;
FileBucket b = null;
try {
f = File.createTempFile("main-", ".fblob.tmp",
updateManager.node.clientCore.getPersistentTempDir());
b = new FileBucket(f, false, false, true, true, true);
- } catch (IOException e) {
- Logger.error(this, "Cannot share main jar from
"+source.userToString()+" with our peers because cannot write the cleaned
version to disk: "+e, e);
- System.err.println("Cannot share main jar from
"+source.userToString()+" with our peers because cannot write the cleaned
version to disk: "+e);
+ } catch(IOException e) {
+ Logger.error(this, "Cannot share main jar from " +
source.userToString() + " with our peers because cannot write the cleaned
version to disk: " + e, e);
+ System.err.println("Cannot share main jar from " +
source.userToString() + " with our peers because cannot write the cleaned
version to disk: " + e);
e.printStackTrace();
b = null;
f = null;
}
final FileBucket cleanedBlob = b;
final File cleanedBlobFile = f;
-
+
ClientCallback myCallback = new ClientCallback() {
public void onFailure(FetchException e, ClientGetter
state) {
if(e.mode == FetchException.CANCELLED) {
// Eh?
- Logger.error(this, "Cancelled fetch
from store/blob of main jar ("+version+") from "+source.userToString());
- System.err.println("Cancelled fetch
from store/blob of main jar ("+version+") from "+source.userToString()+" to
"+temp+" - please report to developers");
- // Probably best to keep files around
for now.
+ Logger.error(this, "Cancelled fetch
from store/blob of main jar (" + version + ") from " + source.userToString());
+ System.err.println("Cancelled fetch
from store/blob of main jar (" + version + ") from " + source.userToString() +
" to " + temp + " - please report to developers");
+ // Probably best to keep files around for now.
} else if(e.isFatal()) {
// Bogus as inserted. Ignore.
temp.delete();
- Logger.error(this, "Failed to fetch
main jar "+version+" from "+source.userToString()+" : fatal error (update was
probably inserted badly): "+e, e);
- System.err.println("Failed to fetch
main jar "+version+" from "+source.userToString()+" : fatal error (update was
probably inserted badly): "+e);
+ Logger.error(this, "Failed to fetch
main jar " + version + " from " + source.userToString() + " : fatal error
(update was probably inserted badly): " + e, e);
+ System.err.println("Failed to fetch
main jar " + version + " from " + source.userToString() + " : fatal error
(update was probably inserted badly): " + e);
} else {
- Logger.error(this, "Failed to fetch
main jar "+version+" from blob from "+source.userToString());
- System.err.println("Failed to fetch
main jar "+version+" from blob from "+source.userToString());
+ Logger.error(this, "Failed to fetch
main jar " + version + " from blob from " + source.userToString());
+ System.err.println("Failed to fetch
main jar " + version + " from blob from " + source.userToString());
}
}
@@ -1200,12 +1222,12 @@
}
public void onSuccess(FetchResult result, ClientGetter
state) {
- System.err.println("Got main jar version
"+version+" from "+source.userToString());
+ System.err.println("Got main jar version " +
version + " from " + source.userToString());
if(result.size() == 0) {
System.err.println("Ignoring because 0
bytes long");
return;
}
-
+
NodeUpdater mainUpdater =
updateManager.mainUpdater;
if(mainUpdater == null) {
System.err.println("Not updating
because updater is disabled!");
@@ -1219,62 +1241,59 @@
public void onSuccess(BaseClientPutter state) {
// Ignore, not possible
}
-
};
-
- ClientGetter cg = new ClientGetter(myCallback,
-
updateManager.node.clientCore.requestStarters.chkFetchScheduler,
-
updateManager.node.clientCore.requestStarters.sskFetchScheduler,
- uri, tempContext, (short)0, this, null,
cleanedBlob);
-
+
+ ClientGetter cg = new ClientGetter(myCallback,
+
updateManager.node.clientCore.requestStarters.chkFetchScheduler,
+
updateManager.node.clientCore.requestStarters.sskFetchScheduler,
+ uri, tempContext, (short) 0, this, null, cleanedBlob);
+
try {
cg.start();
- } catch (FetchException e1) {
+ } catch(FetchException e1) {
myCallback.onFailure(e1, cg);
}
-
+
}
-
+
protected boolean removeOldTempFiles() {
File oldTempFilesPeerDir =
updateManager.node.clientCore.getPersistentTempDir();
- if(!oldTempFilesPeerDir.exists()) {
- return false;
- }
- if(!oldTempFilesPeerDir.isDirectory()) {
- Logger.error(this, "Persistent temporary files location
is not a directory: "+oldTempFilesPeerDir.getPath());
- return false;
- }
-
+ if(!oldTempFilesPeerDir.exists())
+ return false;
+ if(!oldTempFilesPeerDir.isDirectory()) {
+ Logger.error(this, "Persistent temporary files location
is not a directory: " + oldTempFilesPeerDir.getPath());
+ return false;
+ }
+
boolean gotError = false;
- File[] oldTempFiles = oldTempFilesPeerDir.listFiles(new
FileFilter() {
+ File[] oldTempFiles = oldTempFilesPeerDir.listFiles(new
FileFilter() {
+
private final int lastGoodMainBuildNumber =
Version.lastGoodBuild();
private final int recommendedExtBuildNumber =
NodeStarter.RECOMMENDED_EXT_BUILD_NUMBER;
-
+
public boolean accept(File file) {
String fileName = file.getName();
-
+
if(fileName.startsWith("revocation-") &&
fileName.endsWith(".fblob.tmp"))
return true;
-
+
String buildNumberStr;
int buildNumber;
Matcher extBuildNumberMatcher =
extBuildNumberPattern.matcher(fileName);
Matcher mainBuildNumberMatcher =
mainBuildNumberPattern.matcher(fileName);
-
+
if(mainBuildNumberMatcher.matches()) {
buildNumberStr =
mainBuildNumberMatcher.group(1);
buildNumber =
Integer.parseInt(buildNumberStr);
- if(buildNumber <
lastGoodMainBuildNumber) {
+ if(buildNumber <
lastGoodMainBuildNumber)
return true;
- }
} else if(extBuildNumberMatcher.matches()) {
buildNumberStr =
extBuildNumberMatcher.group(1);
buildNumber =
Integer.parseInt(buildNumberStr);
- if(buildNumber <
recommendedExtBuildNumber) {
+ if(buildNumber <
recommendedExtBuildNumber)
return true;
- }
}
-
+
return false;
}
});
@@ -1286,10 +1305,10 @@
Logger.error(this, "Cannot delete
temporary persistent file " + fileToDeleteName + " even though it exists: must
be TOO persistent :)");
else
Logger.normal(this, "Temporary
persistent file does not exist when deleting: " + fileToDeleteName);
- gotError =true;
+ gotError = true;
}
}
-
+
return !gotError;
}
}