Author: toad
Date: 2006-09-02 17:55:37 +0000 (Sat, 02 Sep 2006)
New Revision: 10366

Modified:
   trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
   trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
   trunk/freenet/src/freenet/node/ByteCounter.java
   trunk/freenet/src/freenet/node/CHKInsertSender.java
   trunk/freenet/src/freenet/node/InsertHandler.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/RequestHandler.java
   trunk/freenet/src/freenet/node/RequestSender.java
   trunk/freenet/src/freenet/node/SSKInsertHandler.java
   trunk/freenet/src/freenet/node/SSKInsertSender.java
Log:
Calculate payload % on output bandwidth, and display on /darknet/.
Also possibly fix transfers not being accounted for on requests ???

Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2006-09-02 17:42:43 UTC (rev 10365)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java       
2006-09-02 17:55:37 UTC (rev 10366)
@@ -198,7 +198,8 @@
                                        long[] total = 
IOStatisticCollector.getTotalIO();
                                        long total_output_rate = (total[0]) / 
nodeUptimeSeconds;
                                        long total_input_rate = (total[1]) / 
nodeUptimeSeconds;
-                                       activityList.addChild("li", "Total 
Output:\u00a0" + SizeUtil.formatSize(total[0]) + "\u00a0(" + 
SizeUtil.formatSize(total_output_rate) + "ps)");
+                                       long totalPayload = 
node.getTotalPayloadSent();
+                                       activityList.addChild("li", "Total 
Output:\u00a0" + SizeUtil.formatSize(total[0]) + "\u00a0(" + 
SizeUtil.formatSize(total_output_rate) + "ps) ("+(totalPayload*100 / 
total[0])+"% payload)");
                                        activityList.addChild("li", "Total 
Input:\u00a0" + SizeUtil.formatSize(total[1]) + "\u00a0(" + 
SizeUtil.formatSize(total_input_rate) + "ps)");
                                        long[] rate = node.getNodeIOStats();
                                        long delta = (rate[5] - rate[2]) / 1000;

Modified: trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java     2006-09-02 
17:42:43 UTC (rev 10365)
+++ trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java     2006-09-02 
17:55:37 UTC (rev 10366)
@@ -118,6 +118,7 @@
                                                _sentPackets.setBit(packetNo, 
true);
                                                try {
                                                        
((PeerNode)_destination).sendAsync(DMT.createPacketTransmit(_uid, packetNo, 
_sentPackets, _prb.getPacket(packetNo)), null, PACKET_SIZE, _ctr);
+                                                       
_ctr.sentPayload(PACKET_SIZE);
                                                // We accelerate the ping rate 
during the transfer to keep a closer eye on round-trip-time
                                                sentSinceLastPing++;
                                                if (sentSinceLastPing >= 
PING_EVERY) {

Modified: trunk/freenet/src/freenet/node/ByteCounter.java
===================================================================
--- trunk/freenet/src/freenet/node/ByteCounter.java     2006-09-02 17:42:43 UTC 
(rev 10365)
+++ trunk/freenet/src/freenet/node/ByteCounter.java     2006-09-02 17:55:37 UTC 
(rev 10366)
@@ -8,5 +8,8 @@
        public void sentBytes(int x);

        public void receivedBytes(int x);
+       
+       /** Sent payload - only include the number of bytes of actual payload 
i.e. data from the user's point of view, as opposed to overhead */
+       public void sentPayload(int x);

 }

Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertSender.java 2006-09-02 17:42:43 UTC 
(rev 10365)
+++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2006-09-02 17:55:37 UTC 
(rev 10366)
@@ -870,4 +870,8 @@
                        return totalBytesReceived;
                }
        }
+
+       public void sentPayload(int x) {
+               node.sentPayload(x);
+       }
 }

Modified: trunk/freenet/src/freenet/node/InsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/InsertHandler.java   2006-09-02 17:42:43 UTC 
(rev 10365)
+++ trunk/freenet/src/freenet/node/InsertHandler.java   2006-09-02 17:55:37 UTC 
(rev 10366)
@@ -427,4 +427,8 @@
        public int getTotalReceivedBytes() {
                return totalReceivedBytes;
        }
+
+       public void sentPayload(int x) {
+               node.sentPayload(x);
+       }
 }

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-09-02 17:42:43 UTC (rev 
10365)
+++ trunk/freenet/src/freenet/node/Node.java    2006-09-02 17:55:37 UTC (rev 
10366)
@@ -2962,4 +2962,21 @@
                }
                return x;
        }
+       
+       // FIXME put this somewhere else
+       private final Object statsSync = new Object();
+       /** The total number of bytes of real data i.e. payload sent by the 
node */
+       private long totalPayloadSent;
+       
+       public void sentPayload(int len) {
+               synchronized(statsSync) {
+                       totalPayloadSent += len;
+               }
+       }
+       
+       public long getTotalPayloadSent() {
+               synchronized(statsSync) {
+                       return totalPayloadSent;
+               }
+       }
 }

Modified: trunk/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestHandler.java  2006-09-02 17:42:43 UTC 
(rev 10365)
+++ trunk/freenet/src/freenet/node/RequestHandler.java  2006-09-02 17:55:37 UTC 
(rev 10366)
@@ -84,7 +84,7 @@
                PartiallyReceivedBlock prb =
                        new PartiallyReceivedBlock(Node.PACKETS_IN_BLOCK, 
Node.PACKET_SIZE, block.getRawData());
                BlockTransmitter bt =
-                       new BlockTransmitter(node.usm, source, uid, prb, 
node.outputThrottle, null);
+                       new BlockTransmitter(node.usm, source, uid, prb, 
node.outputThrottle, this);
                if(bt.send())
                        status = RequestSender.SUCCESS; // for byte logging
             }
@@ -115,7 +115,7 @@
                 source.send(df, null);
                 PartiallyReceivedBlock prb = rs.getPRB();
                BlockTransmitter bt =
-                   new BlockTransmitter(node.usm, source, uid, prb, 
node.outputThrottle, null);
+                   new BlockTransmitter(node.usm, source, uid, prb, 
node.outputThrottle, this);
                if(!bt.send());
                        finalTransferFailed = true;
                    return;
@@ -148,6 +148,7 @@
                        if(key instanceof NodeSSK) {
                         Message df = DMT.createFNPSSKDataFound(uid, 
rs.getHeaders(), rs.getSSKData());
                         source.send(df, this);
+                        node.sentPayload(rs.getSSKData().length);
                         if(needsPubKey) {
                                Message pk = DMT.createFNPSSKPubKey(uid, 
((NodeSSK)rs.getSSKBlock().getKey()).getPubKey().asBytes());
                                source.send(pk, this);
@@ -204,9 +205,10 @@
        private Message createDataFound(KeyBlock block) {
                if(block instanceof CHKBlock)
                        return DMT.createFNPCHKDataFound(uid, 
block.getRawHeaders());
-               else if(block instanceof SSKBlock)
+               else if(block instanceof SSKBlock) {
+                       node.sentPayload(block.getRawData().length);
                        return DMT.createFNPSSKDataFound(uid, 
block.getRawHeaders(), block.getRawData());
-               else
+               } else
                        throw new IllegalStateException("Unknown key block 
type: "+block.getClass());
        }

@@ -226,4 +228,8 @@
                }
        }

+       public void sentPayload(int x) {
+               node.sentPayload(x);
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/RequestSender.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestSender.java   2006-09-02 17:42:43 UTC 
(rev 10365)
+++ trunk/freenet/src/freenet/node/RequestSender.java   2006-09-02 17:55:37 UTC 
(rev 10366)
@@ -579,4 +579,8 @@
        synchronized boolean hasForwarded() {
                return hasForwarded;
        }
+
+       public void sentPayload(int x) {
+               node.sentPayload(x);
+       }
 }

Modified: trunk/freenet/src/freenet/node/SSKInsertHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/SSKInsertHandler.java        2006-09-02 
17:42:43 UTC (rev 10365)
+++ trunk/freenet/src/freenet/node/SSKInsertHandler.java        2006-09-02 
17:55:37 UTC (rev 10366)
@@ -149,6 +149,7 @@
                        Message msg = DMT.createFNPSSKDataFound(uid, 
storedBlock.getRawHeaders(), storedBlock.getRawData());
                        try {
                                source.send(msg, this);
+                               
node.sentPayload(storedBlock.getRawData().length);
                        } catch (NotConnectedException e) {
                                if(logMINOR) Logger.minor(this, "Lost 
connection to source on "+uid);
                        }
@@ -209,6 +210,7 @@
                Message msg = DMT.createFNPSSKDataFound(uid, headers, data);
                try {
                        source.send(msg, this);
+                               node.sentPayload(data.length);
                } catch (NotConnectedException e) {
                        if(logMINOR) Logger.minor(this, "Lost connection to 
source");
                        return;
@@ -334,5 +336,9 @@
        public int getTotalReceivedBytes() {
                return totalBytesReceived;
        }
+
+       public void sentPayload(int x) {
+               node.sentPayload(x);
+       }

 }

Modified: trunk/freenet/src/freenet/node/SSKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/SSKInsertSender.java 2006-09-02 17:42:43 UTC 
(rev 10365)
+++ trunk/freenet/src/freenet/node/SSKInsertSender.java 2006-09-02 17:55:37 UTC 
(rev 10366)
@@ -172,6 +172,7 @@

             try {
                                next.sendAsync(req, null, 0, this);
+                               node.sentPayload(data.length);
                        } catch (NotConnectedException e1) {
                                if(logMINOR) Logger.minor(this, "Not connected 
to "+next);
                                continue;
@@ -548,4 +549,8 @@
                }
        }

+       public void sentPayload(int x) {
+               node.sentPayload(x);
+       }
+
 }


Reply via email to