Author: zothar
Date: 2006-10-29 21:17:40 +0000 (Sun, 29 Oct 2006)
New Revision: 10741
Added:
trunk/freenet/src/freenet/node/fcp/GetNode.java
trunk/freenet/src/freenet/node/fcp/NodeData.java
Modified:
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/fcp/FCPMessage.java
Log:
Added FCP client to server GetNode message for getting details about the node
such as the noderef and stats.
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-10-29 20:13:29 UTC (rev
10740)
+++ trunk/freenet/src/freenet/node/Node.java 2006-10-29 21:17:40 UTC (rev
10741)
@@ -1684,6 +1684,32 @@
}
/**
+ * Export volatile data about the node as a SimpleFieldSet
+ */
+ public SimpleFieldSet exportVolatileFieldSet() {
+ SimpleFieldSet fs = new SimpleFieldSet();
+ long now = System.currentTimeMillis();
+ long nodeUptimeSeconds = 0;
+ synchronized(this) {
+ fs.put("startupTime", Long.toString(startupTime));
+ nodeUptimeSeconds = (now - startupTime) / 1000;
+ fs.put("uptimeSeconds",
Long.toString(nodeUptimeSeconds));
+ }
+ fs.put("averagePingTime",
Double.toString(getNodeAveragePingTime()));
+ fs.put("bwlimitDelayTime",
Double.toString(getBwlimitDelayTime()));
+ fs.put("networkSizeEstimateSession",
Integer.toString(getNetworkSizeEstimate(-1)));
+ int networkSizeEstimateRecent = 0;
+ if(nodeUptimeSeconds > (48*60*60)) { // 48 hours
+ networkSizeEstimateRecent = getNetworkSizeEstimate(now
- (48*60*60*1000)); // 48 hours
+ }
+ fs.put("networkSizeEstimateRecent",
Integer.toString(networkSizeEstimateRecent));
+ fs.put("missRoutingDistance",
Double.toString(missRoutingDistance.currentValue()));
+ fs.put("backedoffPercent",
Double.toString(backedoffPercent.currentValue()));
+ fs.put("pInstantReject",
Double.toString(pRejectIncomingInstantly()));
+ return fs;
+ }
+
+ /**
* Do a routed ping of another node on the network by its location.
* @param loc2 The location of the other node to ping. It must match
* exactly.
Modified: trunk/freenet/src/freenet/node/fcp/FCPMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPMessage.java 2006-10-29 20:13:29 UTC
(rev 10740)
+++ trunk/freenet/src/freenet/node/fcp/FCPMessage.java 2006-10-29 21:17:40 UTC
(rev 10741)
@@ -44,6 +44,8 @@
return new ClientPutMessage(fs);
if(name.equals(GenerateSSKMessage.name))
return new GenerateSSKMessage(fs);
+ if(name.equals(GetNode.name))
+ return new GetNode(fs);
if(name.equals(GetRequestStatusMessage.name))
return new GetRequestStatusMessage(fs);
if(name.equals(ListPeersMessage.name))
Added: trunk/freenet/src/freenet/node/fcp/GetNode.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/GetNode.java 2006-10-29 20:13:29 UTC
(rev 10740)
+++ trunk/freenet/src/freenet/node/fcp/GetNode.java 2006-10-29 21:17:40 UTC
(rev 10741)
@@ -0,0 +1,35 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.node.fcp;
+
+import freenet.node.Node;
+import freenet.node.PeerNode;
+import freenet.support.Fields;
+import freenet.support.SimpleFieldSet;
+
+public class GetNode extends FCPMessage {
+
+ final boolean withPrivate;
+ final boolean withVolatile;
+ static final String name = "GetNode";
+
+ public GetNode(SimpleFieldSet fs) {
+ withPrivate = Fields.stringToBool(fs.get("WithPrivate"), false);
+ withVolatile = Fields.stringToBool(fs.get("WithVolatile"),
false);
+ }
+
+ public SimpleFieldSet getFieldSet() {
+ return new SimpleFieldSet();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void run(FCPConnectionHandler handler, Node node)
+ throws MessageInvalidException {
+ handler.outputHandler.queue(new NodeData(node, withPrivate,
withVolatile));
+ }
+
+}
Added: trunk/freenet/src/freenet/node/fcp/NodeData.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/NodeData.java 2006-10-29 20:13:29 UTC
(rev 10740)
+++ trunk/freenet/src/freenet/node/fcp/NodeData.java 2006-10-29 21:17:40 UTC
(rev 10741)
@@ -0,0 +1,48 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.node.fcp;
+
+import freenet.node.Node;
+import freenet.node.PeerNode;
+import freenet.support.SimpleFieldSet;
+
+public class NodeData extends FCPMessage {
+ static final String name = "NodeData";
+
+ final Node node;
+ final boolean withPrivate;
+ final boolean withVolatile;
+
+ public NodeData(Node node, boolean withPrivate, boolean withVolatile) {
+ this.node = node;
+ this.withPrivate = withPrivate;
+ this.withVolatile = withVolatile;
+ }
+
+ public SimpleFieldSet getFieldSet() {
+ SimpleFieldSet fs = new SimpleFieldSet();
+ if(withPrivate) {
+ fs = node.exportPrivateFieldSet();
+ } else {
+ fs = node.exportPublicFieldSet();
+ }
+ if(withVolatile) {
+ SimpleFieldSet vol = node.exportVolatileFieldSet();
+ if(!vol.isEmpty()) {
+ fs.put("volatile", vol);
+ }
+ }
+ return fs;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void run(FCPConnectionHandler handler, Node node)
+ throws MessageInvalidException {
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "NodeData goes
from server to client not the other way around", null);
+ }
+
+}