Author: toad
Date: 2006-06-10 15:25:49 +0000 (Sat, 10 Jun 2006)
New Revision: 9129
Modified:
trunk/freenet/src/freenet/node/ARKFetcher.java
trunk/freenet/src/freenet/node/DNSRequester.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/Version.java
Log:
796: Don't fetch the same ARK continually!
Modified: trunk/freenet/src/freenet/node/ARKFetcher.java
===================================================================
--- trunk/freenet/src/freenet/node/ARKFetcher.java 2006-06-10 14:05:20 UTC
(rev 9128)
+++ trunk/freenet/src/freenet/node/ARKFetcher.java 2006-06-10 15:25:49 UTC
(rev 9129)
@@ -31,6 +31,7 @@
private String identity;
private boolean isFetching = false;
private boolean started = false;
+ private long startedEdition;
public ARKFetcher(PeerNode peer, Node node) {
this.peer = peer;
@@ -50,6 +51,7 @@
if(started) { // We only need one ARKFetcher per PeerNode
return;
}
+ Logger.minor(this, "Starting ... for "+peer+" on "+this);
started = true;
// Start fetch
shouldRun = true;
@@ -59,6 +61,8 @@
return;
}
FreenetURI uri = ark.getURI();
+ uri =
uri.setSuggestedEdition(uri.getSuggestedEdition());
+ startedEdition = uri.getSuggestedEdition();
fetchingURI = uri;
Logger.minor(this, "Fetching ARK: "+uri+" for "+peer);
cg = new ClientGetter(this, node.chkFetchScheduler,
node.sskFetchScheduler,
@@ -69,11 +73,13 @@
if(cg != null)
try {
+ synchronized(this) {
+ if(!isFetching) {
+
node.addARKFetcher(identity,this);
+ isFetching = true;
+ }
+ }
cg.start();
- if(!isFetching) {
- node.addARKFetcher(identity,this);
- isFetching = true;
- }
} catch (FetchException e) {
onFailure(e, cg);
}
@@ -123,7 +129,8 @@
SimpleFieldSet fs;
try {
fs = new SimpleFieldSet(ref, true);
- peer.gotARK(fs);
+ Logger.minor(this, "Got ARK for "+peer);
+ peer.gotARK(fs, startedEdition);
} catch (IOException e) {
// Corrupt ref.
Logger.error(this, "Corrupt ARK reference? Fetched
"+fetchingURI+" got while parsing: "+e+" from:\n"+ref, e);
Modified: trunk/freenet/src/freenet/node/DNSRequester.java
===================================================================
--- trunk/freenet/src/freenet/node/DNSRequester.java 2006-06-10 14:05:20 UTC
(rev 9128)
+++ trunk/freenet/src/freenet/node/DNSRequester.java 2006-06-10 15:25:49 UTC
(rev 9129)
@@ -20,8 +20,8 @@
}
void start() {
- Logger.normal(this, "Starting DNSRequester");
- System.out.println("Starting DNSRequester");
+ Logger.normal(this, "Starting DNSRequester");
+ System.out.println("Starting DNSRequester");
myThread.start();
}
@@ -58,11 +58,11 @@
}
for(int i=0;i<nodes.length;i++) {
PeerNode pn = nodes[i];
- Logger.minor(this, "Node: "+pn);
+ //Logger.minor(this, "Node: "+pn);
if(!pn.isConnected()) {
// Not connected
// Try new DNS lookup
- Logger.minor(this, "Doing lookup on "+pn);
+ //Logger.minor(this, "Doing lookup on "+pn);
pn.maybeUpdateHandshakeIPs(false);
}
}
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2006-06-10 14:05:20 UTC
(rev 9128)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2006-06-10 15:25:49 UTC
(rev 9129)
@@ -305,8 +305,9 @@
if(nominalPeer.isEmpty()) {
Logger.normal(this, "No IP addresses found for identity
'"+Base64.encode(identity)+"', possibly at location
'"+Double.toString(currentLocation.getValue())+"' with name '"+myName+"'");
detectedPeer = null;
- } else
- detectedPeer=(Peer) nominalPeer.firstElement();
+ } else {
+ detectedPeer = (Peer) nominalPeer.firstElement();
+ }
String name = fs.get("myName");
if(name == null) throw new FSParseException("No name");
@@ -557,7 +558,7 @@
public void maybeUpdateHandshakeIPs(boolean ignoreHostnames) {
long now = System.currentTimeMillis();
if((now - lastAttemptedHandshakeIPUpdateTime) < (5*60*1000)) {
- Logger.minor(this, "Looked up recently");
+ //Logger.minor(this, "Looked up recently (detectedPeer =
"+detectedPeer + " : "+((detectedPeer == null) ? "" :
detectedPeer.getAddress(false).toString()));
return; // 5 minutes FIXME
}
// We want to come back right away for DNS requesting if this is our
first time through
@@ -874,7 +875,7 @@
* sent.
*/
public void sentHandshake() {
- Logger.debug(this, "sentHandshake(): "+this);
+ Logger.minor(this, "sentHandshake(): "+this);
calcNextHandshake(true);
}
@@ -977,10 +978,17 @@
* @param newPeer The new address of the peer.
*/
public void changedIP(Peer newPeer) {
- this.detectedPeer=newPeer;
+ setDetectedPeer(newPeer);
}
- /**
+ private void setDetectedPeer(Peer newPeer) {
+ if(!detectedPeer.equals(newPeer)) {
+ this.detectedPeer=newPeer;
+ this.lastAttemptedHandshakeIPUpdateTime = 0;
+ }
+ }
+
+ /**
* @return The current primary KeyTracker, or null if we
* don't have one.
*/
@@ -1286,7 +1294,7 @@
* Process a new nodereference, as a SimpleFieldSet.
*/
private void processNewNoderef(SimpleFieldSet fs, boolean forARK) throws
FSParseException {
- Logger.minor(this, "Parsing: "+fs);
+ Logger.minor(this, "Parsing: \n"+fs);
boolean changedAnything = false;
String identityString = fs.get("identity");
try {
@@ -1322,6 +1330,8 @@
currentLocation = loc;
}
+ Vector oldNominalPeer = nominalPeer;
+
if(nominalPeer==null)
nominalPeer=new Vector();
nominalPeer.removeAllElements();
@@ -1338,10 +1348,17 @@
}else{
for(int i=0;i<physical.length;i++){
Peer p = new Peer(physical[i], true);
- if(!nominalPeer.contains(p))
+ if(!nominalPeer.contains(p)) {
+ if(oldNominalPeer.contains(p)) {
+ // Do nothing
+ // .contains() will .equals()
on each, and equals() will propagate the looked-up IP if necessary.
+ // This is obviously O(n^2),
but it doesn't matter, there will be very few peers.
+ }
nominalPeer.addElement(p);
+ }
}
}
+ this.lastAttemptedHandshakeIPUpdateTime = 0;
} catch (Exception e1) {
throw new FSParseException(e1);
}
@@ -1354,12 +1371,15 @@
// detectedPeer stays as it is
} else {
/* yes, we pick up a random one : it will be updated on handshake
*/
- detectedPeer=(Peer) nominalPeer.firstElement();
+ this.setDetectedPeer((Peer) nominalPeer.firstElement());
}
String name = fs.get("myName");
if(name == null) throw new FSParseException("No name");
// In future, ARKs may support automatic transition when the ARK key
is changed.
// So parse it anyway. If it fails, no big loss; it won't even log an
error.
+
+ Logger.minor(this, "Parsed successfully; changedAnything =
"+changedAnything);
+
if(parseARK(fs))
changedAnything = true;
if(!name.equals(myName)) changedAnything = true;
@@ -1777,24 +1797,33 @@
try {
USK usk = USK.create(newURI);
if(!myARK.equals(usk, false)) {
- Logger.error(this, "Changing ARK not supported
(and shouldn't be possible): from "+myARK+" to "+usk);
+ Logger.error(this, "Changing ARK not supported
(and shouldn't be possible): from "+myARK+" to "+usk+" for "+this);
} else if(myARK.suggestedEdition >
usk.suggestedEdition) {
- Logger.minor(this, "Ignoring ARK edition
decrease: "+myARK.suggestedEdition+" to "+usk.suggestedEdition);
- } else
+ Logger.minor(this, "Ignoring ARK edition
decrease: "+myARK.suggestedEdition+" to "+usk.suggestedEdition+" for "+this);
+ } else if(myARK == null) {
+ Logger.minor(this, "Setting ARK to "+usk+" was
null on "+this);
myARK = usk;
+ }
} catch (MalformedURLException e) {
Logger.error(this, "ARK update failed: Could not parse
permanent redirect (from USK): "+newURI+" : "+e, e);
}
}
- public void gotARK(SimpleFieldSet fs) {
+ public void gotARK(SimpleFieldSet fs, long fetchedEdition) {
try {
+ synchronized(this) {
+ handshakeCount = 0;
+ if(myARK.suggestedEdition < fetchedEdition)
+ myARK = myARK.copy(fetchedEdition);
+ }
processNewNoderef(fs, true);
- this.handshakeCount = 0;
} catch (FSParseException e) {
Logger.error(this, "Invalid ARK update: "+e, e);
// This is ok as ARKs are limited to 4K anyway.
Logger.error(this, "Data was: \n"+fs.toString());
+ synchronized(this) {
+ handshakeCount = PeerNode.MAX_HANDSHAKE_COUNT;
+ }
}
}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-06-10 14:05:20 UTC (rev
9128)
+++ trunk/freenet/src/freenet/node/Version.java 2006-06-10 15:25:49 UTC (rev
9129)
@@ -18,7 +18,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 795;
+ private static final int buildNumber = 796;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 765;