Author: toad
Date: 2006-05-29 18:54:01 +0000 (Mon, 29 May 2006)
New Revision: 8928
Modified:
trunk/freenet/src/freenet/client/async/ClientGetter.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/PeerManager.java
trunk/freenet/src/freenet/node/updater/NodeUpdater.java
Log:
Mostly improvements to the updater.
Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java 2006-05-29
18:27:12 UTC (rev 8927)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java 2006-05-29
18:54:01 UTC (rev 8928)
@@ -41,7 +41,8 @@
* write the data directly to the bucket, or copy it and free the
original temporary bucket. Preferably the
* former, obviously!
*/
- public ClientGetter(ClientCallback client, ClientRequestScheduler
chkSched, ClientRequestScheduler sskSched, FreenetURI uri, FetcherContext ctx,
short priorityClass, Object clientContext, Bucket returnBucket) {
+ public ClientGetter(ClientCallback client, ClientRequestScheduler
chkSched, ClientRequestScheduler sskSched,
+ FreenetURI uri, FetcherContext ctx, short
priorityClass, Object clientContext, Bucket returnBucket) {
super(priorityClass, chkSched, sskSched, clientContext);
this.client = client;
this.returnBucket = returnBucket;
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-05-29 18:27:12 UTC (rev
8927)
+++ trunk/freenet/src/freenet/node/Node.java 2006-05-29 18:54:01 UTC (rev
8928)
@@ -504,7 +504,7 @@
public final RandomSource random; // strong RNG
final UdpSocketManager usm;
final FNPPacketMangler packetMangler;
- final PacketSender ps;
+ public final PacketSender ps;
final NodeDispatcher dispatcher;
final NodePinger nodePinger;
final FilenameGenerator tempFilenameGenerator;
@@ -1450,6 +1450,8 @@
// Check the environment.
String assumeKernel;
try {
+ // It is essential to check the environment.
+ // Make an alternative way to do it if you like.
assumeKernel =
System.getenv("LD_ASSUME_KERNEL");
} catch (Error e) {
assumeKernel = null;
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2006-05-29 18:27:12 UTC
(rev 8927)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2006-05-29 18:54:01 UTC
(rev 8928)
@@ -374,6 +374,7 @@
*/
public PeerNode closerPeer(PeerNode pn, HashSet routedTo, HashSet
notIgnored, double loc, boolean ignoreSelf) {
PeerNode[] peers = connectedPeers;
+ // No locking necessary. We won't modify it, and if another method
does, it will copy-and-assign.
Logger.minor(this, "Choosing closest peer:
connectedPeers="+peers.length);
double bestDiff = Double.MAX_VALUE;
double maxDiff = 0.0;
Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2006-05-29
18:27:12 UTC (rev 8927)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2006-05-29
18:54:01 UTC (rev 8928)
@@ -30,6 +30,7 @@
private FetcherContext ctxRevocation;
private FetchResult result;
private ClientGetter cg;
+ private boolean finalCheck = false;
private final FreenetURI URI;
private final FreenetURI revocationURI;
private final Node node;
@@ -74,24 +75,29 @@
ctx.dontEnterImplicitArchives = false;
this.ctx = ctx;
- FetcherContext ctx2 =
n.makeClient((short)0).getFetcherContext();
- ctx2.allowSplitfiles = false;
- ctx2.cacheLocalRequests = false;
- ctx2.followRedirects = false;
- ctx2.maxArchiveLevels = 1;
+ ctxRevocation = n.makeClient((short)0).getFetcherContext();
+ ctxRevocation.allowSplitfiles = false;
+ ctxRevocation.cacheLocalRequests = false;
+ ctxRevocation.followRedirects = false;
+ ctxRevocation.maxArchiveLevels = 1;
// big enough ?
- ctx2.maxOutputLength = 4096;
- ctx2.maxTempLength = 4096;
- this.ctxRevocation = ctx2;
+ ctxRevocation.maxOutputLength = 4096;
+ ctxRevocation.maxTempLength = 4096;
try{
USK myUsk=USK.create(URI);
ctx.uskManager.subscribe(myUsk, this, true);
ctx.uskManager.startTemporaryBackgroundFetcher(myUsk);
+ ClientGetter cg = new ClientGetter(this,
node.chkFetchScheduler, node.sskFetchScheduler, revocationURI, ctxRevocation,
RequestStarter.UPDATE_PRIORITY_CLASS, this, null);
+ cg.start();
+
}catch(MalformedURLException e){
Logger.error(this,"The auto-update URI isn't valid and
can't be used");
blow("The auto-update URI isn't valid and can't be
used");
+ } catch (FetchException e) {
+ Logger.error(this, "Not able to start the revocation
fetcher.");
+ blow("Cannot fetch the auto-update URI");
}
}
@@ -147,12 +153,28 @@
/**
* We try to update the node :p
- *
+ * Must run on its own thread.
*/
public synchronized void Update(){
if((result == null) || !isAutoUpdateAllowed || hasBeenBlown)
return;
+
+ this.revocationDNFCounter = 0;
+ this.finalCheck = true;
+ this.queueFetchRevocation(100);
+ while(revocationDNFCounter < 3) {
+ if(this.hasBeenBlown) {
+ Logger.error(this, "The revocation key has been
found on the network : blocking auto-update");
+ return;
+ }
+ try {
+ wait(100*1000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+
// FIXME: maybe we need a higher throshold
if(revocationDNFCounter<1){
Logger.normal(this, "We don't have checked if the
revocation key has been inserted or not yet : delaying update");
@@ -201,7 +223,7 @@
synchronized(this){
this.cg = state;
this.result = result;
- Update();
+ scheduleUpdate();
}
}else{
// The key has been blown !
@@ -239,10 +261,46 @@
if(errorCode == FetchException.DATA_NOT_FOUND){
revocationDNFCounter++;
}
- // FIXME: else ? what do we do ?
+ // Start it again
+ if(this.finalCheck) {
+ if(revocationDNFCounter < 3)
+ queueFetchRevocation(1000);
+ else
+ notifyAll();
+ } else {
+ boolean pause = (revocationDNFCounter == 3);
+ if(pause) revocationDNFCounter = 0;
+ queueFetchRevocation(pause ? 60*60*1000 : 5000);
+ }
}
}
+ private void queueFetchRevocation(long delay) {
+ node.ps.queueTimedJob(new Runnable() { // maybe a FastRunnable?
FIXME
+
+ public void run() {
+ try {
+ ClientGetter cg = new
ClientGetter(NodeUpdater.this, node.chkFetchScheduler, node.sskFetchScheduler,
revocationURI, ctxRevocation, RequestStarter.UPDATE_PRIORITY_CLASS,
NodeUpdater.this, null);
+ cg.start();
+ } catch (FetchException e) {
+ Logger.error(this, "Not able to start
the revocation fetcher.");
+ blow("Cannot fetch the auto-update
URI");
+ }
+ }
+
+ }, delay);
+ }
+
+ private void scheduleUpdate() {
+ node.ps.queueTimedJob(new Runnable() { // definitely needs its
own thread
+
+ public void run() {
+ Update();
+ }
+
+ }, 50);
+ }
+
public void onSuccess(BaseClientPutter state) {
// Impossible
}