Update of /cvsroot/freenet/freenet/src/freenet
In directory sc8-pr-cvs1:/tmp/cvs-serv19987/src/freenet

Modified Files:
        OpenConnectionManager.java 
Log Message:
Added ability for Color to render itself to a hex string.
Made some doubles (routing probabilities) show up with only two decimals instead of 
many in various HTML views.
Made the OCM PeerHandler mode routing information section useable.

Index: OpenConnectionManager.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/OpenConnectionManager.java,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -w -r1.154 -r1.155
--- OpenConnectionManager.java  30 Oct 2003 04:29:37 -0000      1.154
+++ OpenConnectionManager.java  30 Oct 2003 13:09:59 -0000      1.155
@@ -1680,6 +1680,7 @@
     }
     private class PeerHTMLRenderer extends HTMLRenderer
     {
+       private Hashtable rtColors = new Hashtable();
         protected class Value{
             String subLabel;
             String data;
@@ -1743,6 +1744,13 @@
                 outboundConnectionSuccessRatio = 
p.getOutboundConnectionSuccessRatio();
             }
         }
+        PeerHTMLRenderer()
+        {
+                       rtColors.put("tSuccessSearch", new Color(255,0,0));
+                       rtColors.put("tTransferRate", new Color(100,100,0));
+                       rtColors.put("pDNF", new Color(0,180,0));
+                       rtColors.put("tDNF", new Color(0,0,255));
+        }
         protected void doRenderBody(PrintWriter pw, HttpServletRequest req) {
             pw.println(renderViewLevelSelectorLink(req.getRequestURI()));
             
@@ -1801,7 +1809,9 @@
             
             pw.println("<TABLE BORDER = 1 BORDERCOLOR = #91A7DE cellspacing = 0 
cellpadding=0><TR><TD>");
             pw.println("<TABLE border=0 cellspacing = 0><TR BGCOLOR = #E7EDFE>");
-            boolean inRoutingTable = freenet.node.Main.node.rt.references(p.identity);
+            
+            NodeEstimator e = ((NGRoutingTable)Main.origRT).getEstimator(p.identity);
+                       boolean inRoutingTable = e != null;
             
                        int colsUsed = 0;
                        
@@ -1865,7 +1875,21 @@
                 v1 = new 
Value("out",sendQueue,"7810D0",calculateBarLength(p.sendQueue,normalizeTo.sendQueue,normalizeTo.receiveQueue));
                 v2 = new 
Value("in",receiveQueue,"252597",calculateBarLength(0,normalizeTo.sendQueue,normalizeTo.sendQueue));
             }
-            renderPeerHandlerCell(pw,req,"Data 
queued",v1,v2,inRoutingTable?p.identity:null);
+                       Value vG1,vG2;
+                       String gLabel;
+                       Identity id;
+            if(!inRoutingTable){
+                               vG1=vG2=null;
+                               gLabel=null;
+                               id=null;
+            }else{
+               vG1 = new 
Value("min",e.getHTMLReportingTool().getEstimator("pDNF").getHTMLReportingTool().lowestString(TimeEstimator.PROBABILITY),((Color)rtColors.get("pDNF")).toHexString(),-1);
+               vG2 = new 
Value("max",e.getHTMLReportingTool().getEstimator("pDNF").getHTMLReportingTool().highestString(TimeEstimator.PROBABILITY),((Color)rtColors.get("pDNF")).toHexString(),-1);
+               gLabel = e.getHTMLReportingTool().graphNiceName("pDNF");
+               id = null;
+            }
+
+            renderPeerHandlerCell(pw,req,"Data queued",v1,v2,id,vG1,vG2,gLabel);
             
             
             //Data Transfered
@@ -1878,7 +1902,26 @@
                 v1 = new 
Value("sent",dataSent,"7810D0",calculateBarLength(p.dataSent,normalizeTo.dataSent,normalizeTo.dataReceived));
                 v2 = new 
Value("received",dataReceived,"252597",calculateBarLength(p.dataReceived,normalizeTo.dataReceived,normalizeTo.dataSent));
             }
-            renderPeerHandlerCell(pw,req,"Data transfered",v1,v2,null);
+                       if (!inRoutingTable) {
+                               vG1 = vG2 = null;
+                               gLabel = null;
+                               id = null;
+                       } else {
+                               if (viewLevel == 0) {
+                                       vG1 = null;
+                                       vG2 = null;
+                                       gLabel = null;
+                                       id = p.identity;
+                               } else {
+                                       vG1 = new Value("min", 
e.getHTMLReportingTool().getEstimator("tDNF").getHTMLReportingTool().lowestString(TimeEstimator.TIME),
 ((Color) rtColors.get("tDNF")).toHexString(), -1);
+                                       vG2 = new Value("max", 
e.getHTMLReportingTool().getEstimator("tDNF").getHTMLReportingTool().highestString(TimeEstimator.TIME),
 ((Color) rtColors.get("tDNF")).toHexString(), -1);
+                                       gLabel = 
e.getHTMLReportingTool().graphNiceName("tDNF");
+                                       ;
+                                       id = null;
+                               }
+                       }
+                       
+            renderPeerHandlerCell(pw,req,"Data transfered",v1,v2,id,vG1,vG2,gLabel);
 
             //MessageQueue
             if(viewLevel ==0){
@@ -1888,7 +1931,42 @@
                 v1 = new 
Value("small",String.valueOf(p.nonTrailerMessagesQueued),"7810D0",calculateBarLength(p.nonTrailerMessagesQueued,normalizeTo.nonTrailerMessagesQueued,normalizeTo.trailerMessagesQueued));
                 v2 = new 
Value("large",String.valueOf(p.trailerMessagesQueued),"252597",calculateBarLength(p.trailerMessagesQueued,normalizeTo.trailerMessagesQueued,normalizeTo.nonTrailerMessagesQueued));
             }
-            renderPeerHandlerCell(pw,req,"Messages queued",v1,v2,null);
+                       if (!inRoutingTable) {
+                               vG1 = vG2 = null;
+                               gLabel = null;
+                               id = null;
+                       } else {
+                               if (viewLevel == 0) {
+                                       vG1 = null;
+                                       vG2 = null;
+                                       gLabel = null;
+                                       id = null;
+                               } else {
+                                       vG1 = new Value("min", 
e.getHTMLReportingTool().getEstimator("tSuccessSearch").getHTMLReportingTool().lowestString(TimeEstimator.TIME),
 ((Color) rtColors.get("tSuccessSearch")).toHexString(), -1);
+                                       vG2 = new Value("max", 
e.getHTMLReportingTool().getEstimator("tSuccessSearch").getHTMLReportingTool().highestString(TimeEstimator.TIME),
 ((Color) rtColors.get("tSuccessSearch")).toHexString(), -1);
+                                       gLabel = 
e.getHTMLReportingTool().graphNiceName("tSuccessSearch");
+                                       id = null;
+                               }
+                       }
+            renderPeerHandlerCell(pw,req,"Messages queued",v1,v2,id,vG1,vG2,gLabel);
+                       if (!inRoutingTable) {
+                               vG1 = vG2 = null;
+                               gLabel = null;
+                               id = null;
+                       } else {
+                               if (viewLevel == 0) {
+                                       vG1 = null;
+                                       vG2 = null;
+                                       gLabel = null;
+                                       id = null;
+                               } else {
+                                       vG1 = new Value("min", 
e.getHTMLReportingTool().getEstimator("tTransferRate").getHTMLReportingTool().lowestString(TimeEstimator.TRANSFER_RATE),
 ((Color) rtColors.get("tTransferRate")).toHexString(), -1);
+                                       vG2 = new Value("max", 
e.getHTMLReportingTool().getEstimator("tTransferRate").getHTMLReportingTool().highestString(TimeEstimator.TRANSFER_RATE),
 ((Color) rtColors.get("tTransferRate")).toHexString(), -1);
+                                       gLabel = 
e.getHTMLReportingTool().graphNiceName("tTransferRate");
+                                       ;
+                                       id = null;
+                               }
+                       }
 
             //Messages transfered
             if(viewLevel < 2){
@@ -1899,14 +1977,14 @@
                     v1 = new 
Value("sent",String.valueOf(p.messagesSent),"7810D0",calculateBarLength(p.messagesSent,normalizeTo.messagesSent,normalizeTo.messagesReceived));
                     v2 = new 
Value("received",String.valueOf(p.messagesReceived),"252597",calculateBarLength(p.messagesReceived,normalizeTo.messagesReceived,normalizeTo.messagesSent));
                 }
-                renderPeerHandlerCell(pw,req,"Messages handled",v1,v2,null);
+                renderPeerHandlerCell(pw,req,"Messages 
handled",v1,v2,id,vG1,vG2,gLabel);
             }else{
                 v1 = new 
Value("sucesses",String.valueOf(p.messagesSent),"7810D0",calculateBarLength(p.messagesSent,normalizeTo.messagesSent,normalizeTo.messagesSendFailed));
                 v2 = new 
Value("failures",String.valueOf(p.messagesSendFailed),"252597",calculateBarLength(p.messagesSendFailed,normalizeTo.messagesSendFailed,normalizeTo.messagesSent));
-                renderPeerHandlerCell(pw,req,"Messages sent",v1,v2,null);
+                renderPeerHandlerCell(pw,req,"Messages sent",v1,v2,id,vG1,vG2,gLabel);
                 v1 = new 
Value("sucesses",String.valueOf(p.messagesReceived),"7810D0",calculateBarLength(p.messagesReceived,normalizeTo.messagesReceived,normalizeTo.messagesReceiveFailed));
                 v2 = new 
Value("failures",String.valueOf(p.messagesReceiveFailed),"252597",calculateBarLength(p.messagesReceiveFailed,normalizeTo.messagesReceiveFailed,normalizeTo.messagesReceived));
-                renderPeerHandlerCell(pw,req,"Messages received",v1,v2,null);
+                renderPeerHandlerCell(pw,req,"Messages 
received",v1,v2,id,vG1,vG2,gLabel);
             }
 
             
@@ -1918,7 +1996,24 @@
             //Idle time
             v1 = new 
Value("idle",timeFromMillis(p.idleTime,true,true),"7810D0",calculateBarLength(p.idleTime,normalizeTo.idleTime,normalizeTo.lifeTime));
             v2 = new 
Value("life",timeFromMillis(p.lifeTime,true,true),"252597",calculateBarLength(p.lifeTime,normalizeTo.lifeTime,normalizeTo.idleTime));
-            renderPeerHandlerCell(pw,req,"Time",v1,v2,null);
+                       if (!inRoutingTable) {
+                               vG1 = vG2 = null;
+                               gLabel = null;
+                               id = null;
+                       } else {
+                               if (viewLevel == 0) {
+                                       vG1 = null;
+                                       vG2 = null;
+                                       gLabel = null;
+                                       id = null;
+                               } else {
+                                       vG1 = null;
+                                       vG2 = null;
+                                       gLabel = null;
+                                       id = p.identity;
+                               }
+                       }
+            renderPeerHandlerCell(pw,req,"Time",v1,v2,id,vG1,vG2,gLabel);
                     
             //Open Connections
             if (viewLevel == 0) {
@@ -1928,15 +2023,23 @@
                 v1 = new 
Value("out",String.valueOf(p.outboundConnectionsCount),"7810D0",calculateBarLength(p.outboundConnectionsCount,normalizeTo.outboundConnectionsCount,normalizeTo.inboundConnectionsCount));
                 v2 = new 
Value("in",String.valueOf(p.inboundConnectionsCount),"252597",calculateBarLength(p.inboundConnectionsCount,normalizeTo.inboundConnectionsCount,normalizeTo.outboundConnectionsCount));
             }
-            renderPeerHandlerCell(pw,req,"Open connections",v1,v2,null);
+                       vG1 = null;
+                       vG2 = null;
+                       gLabel = null;
+                       id = null;
+            renderPeerHandlerCell(pw,req,"Open connections",v1,v2,id,vG1,vG2,gLabel);
             
             //Connection Attempts
+                       vG1 = null;
+                       vG2 = null;
+                       gLabel = null;
+                       id = null;
             if(viewLevel == 1)
                 renderPeerHandlerCell(pw,req,"Outbound connection success ratio",new  
java.text.DecimalFormat("0.00").format(p.outboundConnectionSuccessRatio),"252597",calculateBarLength(p.outboundConnectionSuccessRatio,normalizeTo.outboundConnectionSuccessRatio));
             else if (viewLevel > 1) {
                 v1 = new 
Value("total",String.valueOf(p.connectionAttempts),"7810D0",calculateBarLength(p.connectionAttempts,normalizeTo.connectionAttempts,normalizeTo.connectionSuccesses));
                 v2 = new 
Value("successes",String.valueOf(p.connectionSuccesses),"252597",calculateBarLength(p.connectionSuccesses,normalizeTo.connectionSuccesses,normalizeTo.inboundConnectionsCount));
-                renderPeerHandlerCell(pw,req,"Connection attempts",v1,v2,null);
+                renderPeerHandlerCell(pw,req,"Connection 
attempts",v1,v2,id,vG1,vG2,gLabel);
             }
             
             pw.println("</TABLE></TD></TR></TABLE>");
@@ -1944,10 +2047,10 @@
         }
         
         protected void renderPeerHandlerCell(PrintWriter pw, HttpServletRequest req, 
String label,String data,String barColor, long barLength) {
-            renderPeerHandlerCell(pw,req,label,new 
Value(null,data,barColor,barLength),null,null);
+            renderPeerHandlerCell(pw,req,label,new 
Value(null,data,barColor,barLength),null,null,null,null,null);
         }
         
-        protected void renderPeerHandlerCell(PrintWriter pw, HttpServletRequest req, 
String label, Value v1, Value v2,Identity id) {
+        protected void renderPeerHandlerCell(PrintWriter pw, HttpServletRequest req, 
String label, Value v1, Value v2,Identity idGraph,Value vGraphValue1,Value 
vGraphValue2,String vGraphValueLabelString) {
             String labelString,dataString;
             if(v2 == null){
                 labelString = "<font size = 2>"+label.replaceAll(" 
","&nbsp;")+"</font>";
@@ -1958,18 +2061,32 @@
             }
                        int rtGraphRowSpan=3*6;
                        if(viewLevel == 0)
-                               rtGraphRowSpan = 3*6;
+                               rtGraphRowSpan = 3*5;
                        else if(viewLevel == 1)
-                               rtGraphRowSpan = 3*7;
+                               rtGraphRowSpan = 3*3;
                        else if(viewLevel == 2)
-                               rtGraphRowSpan = 3*8;
+                               rtGraphRowSpan = 3*4;
                        String rtGraphString;
-                       if(id != null)
-                               rtGraphString = "<TD ROWSPAN ="+rtGraphRowSpan+"><IMG 
height = 180 width=240 
SRC='"+req.getRequestURI()+"/all?identity="+((DSAIdentity)id).getYAsHexString()+"'></IMG></TD>";
+                       if(idGraph != null){
+                               String graph;
+                               if(viewLevel==0)
+                                       graph = "pDNF";
                        else
+                                       graph = "all";
+                               rtGraphString = "<TD COLSPAN = 2 ROWSPAN 
="+rtGraphRowSpan+"><IMG height = 180 width=300 
SRC='"+req.getRequestURI()+"/"+graph+"?identity="+((DSAIdentity)idGraph).getYAsHexString()+"'></IMG></TD>";
+                       }else
                                rtGraphString = "";     
+                       
+                       String fullString ="";
+                       if(vGraphValue1 != null)
+                       {
+                               String rtGraphValueLabelString,rtGraphValueDataString;
+                               rtGraphValueLabelString = "<font size = 
2>"+vGraphValueLabelString.replaceAll(" ","&nbsp;") +"&nbsp;(</FONT><font size = 2 
color="+vGraphValue1.barColor+">"+vGraphValue1.subLabel+"</font><font size = 2 
>/</font><font size = 2 color="+vGraphValue2.barColor+">"+vGraphValue2.subLabel+ 
"</font><font size = 2>)</font>";
+                               rtGraphValueDataString = "<font size = 2 
color="+vGraphValue1.barColor+">"+vGraphValue1.data.replaceAll(" 
","&nbsp;")+"</font><font size = 2 >/</font><font size = 2 
color="+vGraphValue2.barColor+">"+vGraphValue2.data.replaceAll(" ","&nbsp;")+ 
"</font>";
+                               fullString = 
"<TD>"+rtGraphValueLabelString+"</TD><TD>" + rtGraphValueDataString+ "</TD>";
+                       }
             pw.println("<TR><TD>"+labelString+"</TD><TD>" + dataString+ "</TD>");
-            pw.println("<TD ROWSPAN = "+(v2==null?"2":"3")+">&nbsp;</TD><TD ROWSPAN = 
"+(v2==null?"2":"3")+">[History&nbsp;graph&nbsp;here]</TD>"+rtGraphString+"</TR>");
+            pw.println("<TD ROWSPAN = "+(v2==null?"2":"3")+">&nbsp;</TD><TD ROWSPAN = 
"+(v2==null?"2":"3")+">[History&nbsp;graph&nbsp;here]</TD>"+fullString+rtGraphString+"</TR>");
             pw.println("<TR height = 3px><TD COLSPAN=2><IMG height = 4 
width="+v1.barLength+" 
SRC='/servlet/coloredpixel?color="+v1.barColor+"'></IMG></TD></TR>");
             if(v2 != null)
                 pw.println("<TR height = 3px><TD COLSPAN=2><IMG height = 4 
width="+v2.barLength+" 
SRC='/servlet/coloredpixel?color="+v2.barColor+"'></IMG></TD></TR>");
@@ -2063,7 +2180,7 @@
                        }
                                NGRoutingTable ngrt = (NGRoutingTable) rt;
                                
-                               int width = 240;
+                               int width = 300;
                                String pwidth = req.getParameter("width");
                                if (pwidth != null) {
                                        try {
@@ -2083,27 +2200,22 @@
                                Bitmap bmp = new Bitmap(width, height);
                                
                                if (graph.equalsIgnoreCase("all")){
-                                       Hashtable colors = new Hashtable();
                                        //TODO: Figure out how the heck to do this 
drawing stuff better..
                                        //we cannot really know the names graphs in 
the subtype of the NodeEstimator..
                                        //should we maybe have the NodeEstimator 
itself draw the required HTML AND the graphs?
-                                       colors.put("tSuccessSearch", new 
Color(255,0,0));
-                                       colors.put("tTransferRate", new 
Color(255,255,0));
-                                       colors.put("pDNF", new Color(0,255,0));
-                                       colors.put("tDNF", new Color(0,0,255));
                     NodeEstimator est = ngrt.getEstimator(i);
                     if(est == null){
                         resp.sendError(404, "Invalid graph '"+graph+"' specified");
                         return true;
                     }
-                    est.getHTMLReportingTool().drapGraphOnImage(false,bmp,colors);
+                    est.getHTMLReportingTool().drapGraphOnImage(false,bmp,rtColors);
                 }else{
                                        TimeEstimator e =ngrt.getEstimator(i, graph);
                                        if(e == null) {
                                                resp.sendError(404, "Invalid graph 
'"+graph+"' specified");
                                                return true;
                                        }
-                                       
e.getHTMLReportingTool().drapGraphOnImage(false,bmp,new Color(0,0,0),null);
+                                       
e.getHTMLReportingTool().drapGraphOnImage(false,bmp,(Color)rtColors.get(graph),null);
                                }
                                
                                BitmapEncoder enc = new DibEncoder();

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to