Author: zothar
Date: 2006-05-29 19:39:44 +0000 (Mon, 29 May 2006)
New Revision: 8930
Modified:
trunk/freenet/src/freenet/io/comm/FreenetInetAddress.java
trunk/freenet/src/freenet/io/comm/Peer.java
trunk/freenet/src/freenet/node/FNPPacketMangler.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/PacketSender.java
trunk/freenet/src/freenet/node/PeerNode.java
Log:
Initial commit DNS requests from PacketSender (mostly). Lots of timing and
logging. Will continue to look into remaining issues (no more than before
anyway) until I'm happy with what I can chase down using this paradigm.
Modified: trunk/freenet/src/freenet/io/comm/FreenetInetAddress.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/FreenetInetAddress.java 2006-05-29
18:59:31 UTC (rev 8929)
+++ trunk/freenet/src/freenet/io/comm/FreenetInetAddress.java 2006-05-29
19:39:44 UTC (rev 8930)
@@ -149,9 +149,19 @@
* looked up before.
*/
public InetAddress getAddress() {
+ return getAddress(true);
+ }
+
+ /**
+ * Get the IP address. Look it up only if allowed to, but return the
last value if it
+ * has ever been looked up before; will not trigger a new lookup if it
has been
+ * looked up before.
+ */
+ public InetAddress getAddress(boolean doDNSRequest) {
if (_address != null) {
return _address;
} else {
+ if(doDNSRequest == false) return null;
InetAddress addr = getHandshakeAddress();
if( addr != null ) {
this._address = addr;
Modified: trunk/freenet/src/freenet/io/comm/Peer.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/Peer.java 2006-05-29 18:59:31 UTC (rev
8929)
+++ trunk/freenet/src/freenet/io/comm/Peer.java 2006-05-29 19:39:44 UTC (rev
8930)
@@ -137,8 +137,17 @@
* looked up before.
*/
public InetAddress getAddress() {
- return addr.getAddress();
+ return getAddress(true);
}
+
+ /**
+ * Get the IP address. Look it up if allowed to, but return the last
value if it
+ * has ever been looked up before; will not trigger a new lookup if it
has been
+ * looked up before.
+ */
+ public InetAddress getAddress(boolean doDNSRequest) {
+ return addr.getAddress(doDNSRequest);
+ }
/**
* Get the IP address, looking up the hostname if the hostname is
primary, even if
Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java 2006-05-29
18:59:31 UTC (rev 8929)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java 2006-05-29
19:39:44 UTC (rev 8930)
@@ -1292,24 +1292,35 @@
handshakeIPs = pn.getHandshakeIPs();
long secondTime = System.currentTimeMillis();
if((secondTime - firstTime) > 1000)
- Logger.normal(this, "getHandshakeIPs() took more than a second to
execute ("+(secondTime - firstTime)+")");
+ Logger.normal(this, "getHandshakeIPs() took more than a second to
execute ("+(secondTime - firstTime)+") working on "+pn.getName());
if(handshakeIPs.length == 0) {
pn.couldNotSendHandshake();
long thirdTime = System.currentTimeMillis();
if((thirdTime - secondTime) > 1000)
- Logger.normal(this, "couldNotSendHandshake() (after
getHandshakeIPs()) took more than a second to execute ("+(thirdTime -
secondTime)+")");
+ Logger.normal(this, "couldNotSendHandshake() (after
getHandshakeIPs()) took more than a second to execute ("+(thirdTime -
secondTime)+") working on "+pn.getName());
return;
} else {
+ long DHTime1 = System.currentTimeMillis();
ctx = DiffieHellman.generateContext();
+ long DHTime2 = System.currentTimeMillis();
+ if((DHTime2 - DHTime1) > 1000)
+ Logger.normal(this, "DHTime2 is more than a second after
DHTime1 ("+(DHTime2 - DHTime1)+") working on "+pn.getName());
pn.setDHContext(ctx);
+ long DHTime3 = System.currentTimeMillis();
+ if((DHTime3 - DHTime2) > 1000)
+ Logger.normal(this, "DHTime3 is more than a second after
DHTime2 ("+(DHTime3 - DHTime2)+") working on "+pn.getName());
}
int sentCount = 0;
+ long loopTime1 = System.currentTimeMillis();
for(int i=0;i<handshakeIPs.length;i++){
- if( handshakeIPs[i].getAddress() == null ) continue;
+ if(handshakeIPs[i].getAddress(false) == null) continue;
sendFirstHalfDHPacket(0, ctx.getOurExponential(), pn,
handshakeIPs[i]);
pn.sentHandshake();
sentCount += 1;
}
+ long loopTime2 = System.currentTimeMillis();
+ if((loopTime2 - loopTime1) > 1000)
+ Logger.normal(this, "loopTime2 is more than a second after loopTime1
("+(loopTime2 - loopTime1)+") working on "+pn.getName());
if(sentCount==0) {
pn.couldNotSendHandshake();
}
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-05-29 18:59:31 UTC (rev
8929)
+++ trunk/freenet/src/freenet/node/Node.java 2006-05-29 19:39:44 UTC (rev
8930)
@@ -504,6 +504,7 @@
public final RandomSource random; // strong RNG
final UdpSocketManager usm;
final FNPPacketMangler packetMangler;
+ final DNSRequester dnsr;
public final PacketSender ps;
final NodeDispatcher dispatcher;
final NodePinger nodePinger;
@@ -890,6 +891,7 @@
statusTooOldPeerNodes = new HashMap();
statusDisconnectedPeerNodes = new HashMap();
runningUIDs = new HashSet();
+ dnsr = new DNSRequester(this);
ps = new PacketSender(this);
// FIXME maybe these should persist? They need to be private though,
so after the node/peers split. (bug 51).
decrementAtMax = random.nextDouble() <= DECREMENT_AT_MAX_PROB;
@@ -1360,6 +1362,7 @@
void start(boolean noSwaps) throws NodeInitException {
if(!noSwaps)
lm.startSender(this, this.swapInterval);
+ dnsr.start();
ps.start();
usm.start();
Modified: trunk/freenet/src/freenet/node/PacketSender.java
===================================================================
--- trunk/freenet/src/freenet/node/PacketSender.java 2006-05-29 18:59:31 UTC
(rev 8929)
+++ trunk/freenet/src/freenet/node/PacketSender.java 2006-05-29 19:39:44 UTC
(rev 8930)
@@ -74,6 +74,7 @@
}
void start() {
+ Logger.normal(this,"Starting the PacketSender thread");
myThread.start();
}
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2006-05-29 18:59:31 UTC
(rev 8929)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2006-05-29 19:39:44 UTC
(rev 8930)
@@ -219,6 +219,12 @@
/** Holds a String-Long pair that shows which message types (as name) have
been received by this peer. */
private Hashtable localNodeReceivedMessageTypes = new Hashtable();
+ /** Hold collected IP addresses for handshake attempts, populated by
DNSRequestor */
+ private Peer[] handshakeIPs = null;
+
+ /** The last time we attempted to update handshakeIPs */
+ private long lastAttemptedHandshakeIPUpdateTime = 0;
+
/**
* Create a PeerNode from a SimpleFieldSet containing a
* node reference for one. This must contain the following
@@ -449,6 +455,16 @@
* Returns an array with the advertised addresses and the detected one
*/
public Peer[] getHandshakeIPs(){
+ return handshakeIPs;
+ }
+
+ public void maybeUpdateHandshakeIPs() {
+ if(handshakeIPs != null) return;
+ long now = System.currentTimeMillis();
+ if((now - lastAttemptedHandshakeIPUpdateTime) < 5000) return;
+ lastAttemptedHandshakeIPUpdateTime = now;
+ Logger.normal(this, "Updating handshake IPs for peer '"+getPeer()+"'
named '"+myName+"'");
+
Peer[] p=null;
Peer[] myNominalPeer;
@@ -458,10 +474,13 @@
myNominalPeer = (Peer[]) nominalPeer.toArray(new
Peer[nominalPeer.size()]);
if(myNominalPeer.length == 0) {
- if(detectedPeer == null) return new Peer[0];
- return new Peer[] { detectedPeer };
+ if(detectedPeer == null) {
+ handshakeIPs = null;
+ return;
+ }
+ handshakeIPs = new Peer[] { detectedPeer };
+ return;
}
-
}
if( detectedPeer != null && ! nominalPeer.contains(detectedPeer)){
@@ -490,7 +509,8 @@
newPeers[p.length] = extra;
p = newPeers;
}
- return p;
+ handshakeIPs = p;
+ return;
}
/**
@@ -665,6 +685,7 @@
public boolean shouldSendHandshake() {
long now = System.currentTimeMillis();
return (!isConnected) &&
+ (handshakeIPs != null) &&
(now > sendHandshakeTime) &&
!(hasLiveHandshake(now));
}
@@ -702,6 +723,7 @@
+
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_HANDSHAKE_SENDS);
}
firstHandshake = false;
+ handshakeIPs = null;
this.handshakeCount++;
// Don't fetch ARKs for peers we have verified (through handshake) to
be incompatible with us
if(handshakeCount == MAX_HANDSHAKE_COUNT &&
!(verifiedIncompatibleOlderVersion || verifiedIncompatibleNewerVersion)) {
@@ -731,6 +753,7 @@
+
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_HANDSHAKE_SENDS)
+
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_HANDSHAKE_SENDS);
}
+ handshakeIPs = null;
this.handshakeCount++;
// Don't fetch ARKs for peers we have verified (through handshake) to
be incompatible with us
if(handshakeCount == MAX_HANDSHAKE_COUNT &&
!(verifiedIncompatibleOlderVersion || verifiedIncompatibleNewerVersion)) {