Author: cyberdo
Date: 2006-02-01 00:21:58 +0000 (Wed, 01 Feb 2006)
New Revision: 7982

Modified:
   trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/snmplib/BEREncoder.java
   trunk/freenet/src/snmplib/DataStatisticsInfo.java
   trunk/freenet/src/snmplib/SNMPAgent.java
Log:
425:
Fixed a fake rollover-bug in SNMP that sometimes gave negative values
Also added some basic stuff for Long-usage instead of Integer


Modified: trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java 2006-02-01 
00:19:07 UTC (rev 7981)
+++ trunk/freenet/src/freenet/io/comm/IOStatisticCollector.java 2006-02-01 
00:21:58 UTC (rev 7982)
@@ -52,9 +52,9 @@
                        entry = new StatisticEntry();
                        targets.put(key, entry);
                }
-               entry.addData(inbytes, outbytes);
-               totalbytesout += outbytes;
-               totalbytesin += outbytes;
+               entry.addData((inbytes>0)?inbytes:0, (outbytes>0)?outbytes:0);
+               totalbytesout += (outbytes>0)?outbytes:0;
+               totalbytesin += (inbytes>0)?inbytes:0;
        }

        public static void dumpInfo() {

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-01 00:19:07 UTC (rev 
7981)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-01 00:21:58 UTC (rev 
7982)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 424;
+       private static final int buildNumber = 425;

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 403;

Modified: trunk/freenet/src/snmplib/BEREncoder.java
===================================================================
--- trunk/freenet/src/snmplib/BEREncoder.java   2006-02-01 00:19:07 UTC (rev 
7981)
+++ trunk/freenet/src/snmplib/BEREncoder.java   2006-02-01 00:21:58 UTC (rev 
7982)
@@ -38,8 +38,10 @@
                int inoffset = offset;
                for (int i = v.size() - 1 ; i >= 0 ; i--) {
                        Object o = v.get(i); 
-                       if (o instanceof Integer) {
-                               int dlen = intToBytes(((Integer)o).intValue(), 
buf, offset);
+//                     if (o instanceof Integer) {
+//                             int dlen = intToBytes(((Integer)o).intValue(), 
buf, offset);
+                       if (o instanceof Long) {
+                               int dlen = intToBytes(((Long)o).longValue(), 
buf, offset);
                                offset += dlen;
                                offset += intToBERBytes(dlen, buf, offset);
                                buf[offset++] = 0x02;
@@ -64,7 +66,8 @@
        }


-       private int intToBytes(int i, byte[] buf, int offset) {
+       private int intToBytes(long i, byte[] buf, int offset) {
+               // TODO: handle negative numbers also!!!!
                int inoffset = offset;
                if (i == 0) {
                        buf[offset++] = 0;
@@ -74,6 +77,9 @@
                                offset++;
                        }
                }
+               // make the number unsigned
+               if (buf[offset-1]<0)
+                       buf[offset++] = 0;
                return (offset - inoffset);
        }

@@ -103,8 +109,12 @@



-       public void putInteger(int i) {
+       /*public void putInteger(int i) {
                addToTop(new Integer(i));
+       }*/
+       
+       public void putInteger(long i) {
+               addToTop(new Long(i));
        }

        public void putOctetString(byte buf[]) {

Modified: trunk/freenet/src/snmplib/DataStatisticsInfo.java
===================================================================
--- trunk/freenet/src/snmplib/DataStatisticsInfo.java   2006-02-01 00:19:07 UTC 
(rev 7981)
+++ trunk/freenet/src/snmplib/DataStatisticsInfo.java   2006-02-01 00:21:58 UTC 
(rev 7982)
@@ -22,7 +22,7 @@
        public Object getSNMPData() {
                if (blocks == 0) {
                        long io[] = IOStatisticCollector.getTotalIO();
-                       return new Integer((int)io[in?1:0]);
+                       return new Long(io[in?1:0]);
                }
                // else sum all fields up to <blocks>
                int res = 0;
@@ -30,6 +30,6 @@
                for (int i = 0 ; i < blocks ; i++)
                        res += stats[i][in?1:0];

-               return new Integer(res);
+               return new Long(res);
        }
 }

Modified: trunk/freenet/src/snmplib/SNMPAgent.java
===================================================================
--- trunk/freenet/src/snmplib/SNMPAgent.java    2006-02-01 00:19:07 UTC (rev 
7981)
+++ trunk/freenet/src/snmplib/SNMPAgent.java    2006-02-01 00:21:58 UTC (rev 
7982)
@@ -130,7 +130,8 @@
                 e.printStackTrace();
                 break;
             } catch (BadFormatException e) {
-               System.err.println(e.toString());
+               e.printStackTrace();
+               //System.err.println(e.toString());
             } catch (ArrayIndexOutOfBoundsException e) {
                e.printStackTrace();
                // not much to do.. ignore the request and it'll time out
@@ -155,6 +156,8 @@

        if (data instanceof Integer)
                be.putInteger(((Integer)data).intValue());
+       else if (data instanceof Long)
+               be.putInteger(((Long)data).longValue());
        else if (data instanceof String) {
                char[] charr = ((String)data).toCharArray();
                byte[] byarr = new byte[charr.length];


Reply via email to