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

Modified Files:
        StandardMessageHandler.java State.java StateChain.java 
Log Message:
6237:
If we close a trailer while still sending a trailer chunk, this is an error. Report it 
with a stack trace. This caused the send failed, valid key errors - this will help 
track down the real source.
Execute messages on states on the selector loop thread, if the message is going to run 
really fast (otherwise schedule it on the ticker anyway). Currently only used by 
SendFinished.


Index: StandardMessageHandler.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/StandardMessageHandler.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- StandardMessageHandler.java 9 Oct 2003 16:01:04 -0000       1.16
+++ StandardMessageHandler.java 14 Oct 2003 00:43:14 -0000      1.17
@@ -44,18 +44,18 @@
      * Handle a message
      * @param mo The message to handle
      */
-    public void handle(MessageObject mo) {
+    public boolean handle(MessageObject mo, boolean onlyIfCanRunFast) {
         
         if (!(mo instanceof NodeMessageObject)) { 
             node.logger.log(this,
                 "Received a MessageObject that the node cannot handle: "+mo,
                 Logger.ERROR);
-            return;
+            return true;
         }
         NodeMessageObject message = (NodeMessageObject) mo;
 
-               if(Core.logger.shouldLog(Logger.DEBUG,this))
-                       Core.logger.log(this, toString()+" handling "+mo,Logger.DEBUG);
+       if(Core.logger.shouldLog(Logger.DEBUG,this))
+           Core.logger.log(this, toString()+" handling "+mo,Logger.DEBUG);
         TicketIndex ti = new TicketIndex(message.id(), message.isExternal());
         Ticket ticket;
         
@@ -68,7 +68,7 @@
             }
         }
 
-        ticket.received(node, message);
+        return ticket.received(node, message, onlyIfCanRunFast);
 
     }
 
@@ -142,27 +142,40 @@
             workList = new DoublyLinkedListImpl();
         }
 
-        private final void received(Node node, NodeMessageObject mo) {
+        private final boolean received(Node node, NodeMessageObject mo,
+                                      boolean onlyRunIfFast) {
 
             boolean shouldrun = false;
             synchronized (workList) {
-                workList.push(new TicketEntry(node, mo));
 
                 if (!working) {
+                   // Don't run in-thread if other stuff queued
+                   if(onlyRunIfFast) {
+                       if(!workList.isEmpty()) return false;
+                   }
+                   // Don't run in-thread if not fast
+                   if(onlyRunIfFast && !chain.canRunFast(node, mo))
+                       return false;
+                   workList.push(new TicketEntry(node, mo));
                     // it cannot be forgotten while using it
                     synchronized (ticketTable) {
                         //ticketLadder.remove(this);
                         this.remove();
                     }
-
+                   
                     working = true;
                     //threadFactory.getThread(this, true).start();
                     shouldrun = true;
-                }
+                } else {
+                   workList.push(new TicketEntry(node, mo));
+                   // Don't run in-thread if somebody else is already running
+                   if(onlyRunIfFast) return false;
+               }
             }
 
             if (shouldrun)
                 run();
+           return true;
         }
 
         private final void stopWorking() {

Index: State.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/State.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- State.java  13 Jul 2002 19:43:15 -0000      1.3
+++ State.java  14 Oct 2003 00:43:14 -0000      1.4
@@ -148,7 +148,15 @@
         // b/c I want the MessageHandler to be able to distinguish that
         // case from an abnormal exit
     }
-
+    
+    /**
+     * Can a message run more or less instantly on this state if called right
+     * now?
+     */
+    public boolean canRunFast(Node node, MessageObject mo) {
+       return false;
+    }
+    
     /**
      * This gives the priority of the state.
      * @return By default, the method returns OPERATIONAL

Index: StateChain.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/StateChain.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- StateChain.java     18 Sep 2003 17:48:09 -0000      1.22
+++ StateChain.java     14 Oct 2003 00:43:14 -0000      1.23
@@ -79,7 +79,12 @@
                                                System.currentTimeMillis()));
         return state != null;
     }
-
+    
+    public synchronized boolean canRunFast(Node node, NodeMessageObject mo) {
+       if(state == null) return false;
+       return state.canRunFast(node, mo);
+    }
+    
     /**
      * Calls lost() for the active state on this chain and
      * updates the internal state to null.

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

Reply via email to