Author: toad
Date: 2008-04-11 18:22:17 +0000 (Fri, 11 Apr 2008)
New Revision: 19197
Modified:
trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java
trunk/freenet/src/freenet/io/comm/DMT.java
trunk/freenet/src/freenet/node/NodeDispatcher.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/PeerNodeStatus.java
Log:
Tell other nodes our uptime on connect, and display this on the connections
page in advanced mode.
Modified: trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java
2008-04-11 18:05:25 UTC (rev 19196)
+++ trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java
2008-04-11 18:22:17 UTC (rev 19197)
@@ -440,6 +440,7 @@
peerTableHeaderRow.addChild("th",
"Total\u00a0Traffic\u00a0(in/out/resent)");
peerTableHeaderRow.addChild("th",
"Congestion\u00a0Control");
peerTableHeaderRow.addChild("th",
"Time\u00a0Delta");
+ peerTableHeaderRow.addChild("th",
"Reported\u00a0Uptime");
}
SimpleColumn[] endCols =
endColumnHeaders(advancedModeEnabled);
@@ -815,6 +816,7 @@
peerRow.addChild("td", "class", "peer-idle" /* FIXME
*/).addChild("#", val);
// time delta
peerRow.addChild("td", "class", "peer-idle" /* FIXME
*/).addChild("#", TimeUtil.formatTime(peerNodeStatus.getClockDelta()));
+ peerRow.addChild("td", "class", "peer-idle" /* FIXME
*/).addChild("#", peerNodeStatus.getReportedUptimePercentage()+"%");
}
if(endCols != null) {
Modified: trunk/freenet/src/freenet/io/comm/DMT.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/DMT.java 2008-04-11 18:05:25 UTC (rev
19196)
+++ trunk/freenet/src/freenet/io/comm/DMT.java 2008-04-11 18:22:17 UTC (rev
19197)
@@ -130,6 +130,7 @@
public static final String DAWN_HTL = "dawnHtl";
public static final String SECRET = "secret";
public static final String NODE_IDENTITY = "nodeIdentity";
+ public static final String UPTIME_PERCENT_48H = "uptimePercent48H";
/** Very urgent */
public static final short PRIORITY_NOW=-2;
@@ -1345,6 +1346,16 @@
return msg;
}
+ public static final MessageType FNPUptime = new
MessageType("FNPUptime", PRIORITY_LOW) {{
+ addField(UPTIME_PERCENT_48H, Byte.class);
+ }};
+
+ public static final Message createFNPUptime(byte uptimePercent) {
+ Message msg = new Message(FNPUptime);
+ msg.set(UPTIME_PERCENT_48H, uptimePercent);
+ return msg;
+ }
+
public static final MessageType FNPSentPackets = new
MessageType("FNPSentPackets", PRIORITY_HIGH) {{
addField(TIME_DELTAS, ShortBuffer.class);
addField(HASHES, ShortBuffer.class);
Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java 2008-04-11 18:05:25 UTC
(rev 19196)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java 2008-04-11 18:22:17 UTC
(rev 19197)
@@ -118,6 +118,8 @@
return true;
} else if(spec == DMT.FNPTime) {
return handleTime(m, source);
+ } else if(spec == DMT.FNPUptime) {
+ return handleUptime(m, source);
} else if(spec == DMT.FNPSentPackets) {
source.handleSentPackets(m);
return true;
@@ -210,6 +212,12 @@
return false;
}
+ private boolean handleUptime(Message m, PeerNode source) {
+ byte uptime = m.getByte(DMT.UPTIME_PERCENT_48H);
+ source.setUptime(uptime);
+ return true;
+ }
+
private boolean handleOfferKey(Message m, PeerNode source) {
Key key = (Key) m.getObject(DMT.KEY);
byte[] authenticator = ((ShortBuffer)
m.getObject(DMT.OFFER_AUTHENTICATOR)).getData();
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2008-04-11 18:05:25 UTC
(rev 19196)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2008-04-11 18:22:17 UTC
(rev 19197)
@@ -292,6 +292,8 @@
private long routableConnectionCheckCount;
/** Delta between our clock and his clock (positive = his clock is
fast, negative = our clock is fast) */
private long clockDelta;
+ /** Percentage uptime of this node, 0 if they haven't said */
+ private byte uptime;
/** If the clock delta is more than this constant, we don't talk to the
node. Reason: It may not be up to date,
* it will have difficulty resolving date-based content etc. */
@@ -2028,6 +2030,7 @@
Message timeMsg = DMT.createFNPTime(System.currentTimeMillis());
Message packetsMsg = createSentPacketsMessage();
Message dRouting =
DMT.createRoutingStatus(!disableRoutingHasBeenSetLocally);
+ Message uptime =
DMT.createFNPUptime((byte)(int)(100*node.uptime.getUptime()));
try {
if(isRealConnection())
@@ -2036,6 +2039,7 @@
sendAsync(timeMsg, null, 0,
node.nodeStats.initialMessagesCtr);
sendAsync(packetsMsg, null, 0,
node.nodeStats.initialMessagesCtr);
sendAsync(dRouting, null, 0,
node.nodeStats.initialMessagesCtr);
+ sendAsync(uptime, null, 0,
node.nodeStats.initialMessagesCtr);
} catch(NotConnectedException e) {
Logger.error(this, "Completed handshake with " +
getPeer() + " but disconnected (" + isConnected + ':' + currentTracker + "!!!:
" + e, e);
}
@@ -3891,4 +3895,12 @@
public boolean shouldDisconnectAndRemoveNow() {
return false;
}
+
+ public void setUptime(byte uptime2) {
+ this.uptime = uptime2;
+ }
+
+ public short getUptime() {
+ return (short)(((int)uptime) & 0xFF);
+ }
}
Modified: trunk/freenet/src/freenet/node/PeerNodeStatus.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNodeStatus.java 2008-04-11 18:05:25 UTC
(rev 19196)
+++ trunk/freenet/src/freenet/node/PeerNodeStatus.java 2008-04-11 18:22:17 UTC
(rev 19197)
@@ -90,6 +90,8 @@
private final boolean isSearchable;
private final long resendBytesSent;
+
+ private final int reportedUptimePercentage;
PeerNodeStatus(PeerNode peerNode, boolean noHeavy) {
if(Logger.shouldLog(Logger.MINOR, this)) {
@@ -142,6 +144,7 @@
this.isSeedServer = peerNode instanceof SeedServerPeerNode;
this.isSearchable = peerNode.isRealConnection();
this.resendBytesSent = peerNode.getResendBytesSent();
+ this.reportedUptimePercentage = peerNode.getUptime();
}
/**
@@ -381,4 +384,8 @@
return resendBytesSent;
}
+ public int getReportedUptimePercentage() {
+ return reportedUptimePercentage;
+ }
+
}