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

Modified Files:
        ConnectionHandler.java PeerPacket.java Ticker.java 
        Version.java 
Added Files:
        AlreadySendingTrailerChunkException.java 
        OutputStreamTrailerWriter.java TrailerException.java 
        TrailerSendFinishedException.java TrailerWriteCallback.java 
        TrailerWriter.java TrailerWriterOutputStream.java 
        UnknownTrailerSendIDException.java 
Log Message:
6195: (mostly) asynchronous trailer writing, lots of logging improvements (most code 
supports selective logging now), bugfixes


--- NEW FILE: AlreadySendingTrailerChunkException.java ---
package freenet;

public class AlreadySendingTrailerChunkException extends TrailerException {
}

--- NEW FILE: OutputStreamTrailerWriter.java ---
package freenet;

import java.io.*;

public class OutputStreamTrailerWriter implements TrailerWriter {
    OutputStream os;
    
    public OutputStreamTrailerWriter(OutputStream os) {
        this.os = os;
    }
    
    public void writeTrailing(byte[] block, int offset, int length,
                              TrailerWriteCallback cb) throws IOException {
        try {
            os.write(block, offset, length);
            try {
                cb.written();
            } catch (Throwable t) {};
        } catch (IOException e) {
            close();
            throw e;
        }
    }
    
    public void close() {
        try {
            os.close();
        } catch (IOException e) {};
    }
}

--- NEW FILE: TrailerException.java ---
package freenet;

public class TrailerException extends Exception {
}

--- NEW FILE: TrailerSendFinishedException.java ---
package freenet;

public class TrailerSendFinishedException extends TrailerException {
}

--- NEW FILE: TrailerWriteCallback.java ---
package freenet;

public interface TrailerWriteCallback {
    /**
     * Indicates that the write failed and the connection closed
     */
    void closed();
    
    /**
     * Indicates that the write succeeded and the caller should send another one
     */
    void written();
}

--- NEW FILE: TrailerWriter.java ---
package freenet;

import java.io.IOException;

public interface TrailerWriter {
    /**
     * Write a block of a trailing field
     * @param block the byte[] containing the actual data. Will be encrypted in-place.
     * @param offset the offset within block that the data starts at
     * @param length the length of the data to write
     * @param cb the write callback to call when the write is completed
     *
     * @throws UnknownTrailerSendIDException if the ID is not currently sending
     * @throws TrailerSendFinishedException if the trailer has already finished sending
     * @throws AlreadySendingTrailerException if we are already sending a trailer chunk
     * @throws IOException if the send fails immediately for some reason
     * @throws IllegalArgumentException if the length is 0 or less
     */
    public void writeTrailing(byte[] block, int offset, int length,
                              TrailerWriteCallback cb)
        throws UnknownTrailerSendIDException, TrailerSendFinishedException, 
AlreadySendingTrailerChunkException, IOException;
    
    public void close();
}

--- NEW FILE: TrailerWriterOutputStream.java ---
package freenet;

import java.io.OutputStream;
import java.io.IOException;

public class TrailerWriterOutputStream extends OutputStream implements 
TrailerWriteCallback {
    TrailerWriter tw;
    volatile boolean finishedSend = false;
    volatile boolean succeeded = false;
    Object overallSync = new Object();
    
    public TrailerWriterOutputStream(TrailerWriter tw) {
        this.tw = tw;
    }
    
    public void close() {
        synchronized(overallSync) {
            tw.close();
        }
    }
    
    public void flush() {
    }
    
    public void write(byte[] b, int offset, int length) throws IOException {
        synchronized(overallSync) {
            finishedSend = false;
            try {
                tw.writeTrailing(b, offset, length, this);
            } catch (TrailerException e) {
                IOException ioe = new IOException(e.toString());
                ioe.initCause(e);
                throw ioe;
            }
            synchronized(this) {
                while(!finishedSend) {
                    try {
                        this.wait(200);
                    } catch (InterruptedException e) {};
                }
            }
            if(!succeeded) throw new IOException("Trailed send failed");
        }
    }
    
    byte myByte = (byte)0;
    byte[] oneByteBuf = new byte[] { myByte };
    public void write(int b) throws IOException {
        myByte = (byte)(b & 0xff);
        write(oneByteBuf, 0, 1);
    }
    
    public void write(byte[] buf) throws IOException {
        write(buf, 0, buf.length);
    }
    
    public void closed() {
        succeeded = false;
        finishedSend = true;
        synchronized(this) {
            this.notify();
        }
    }
    
    public void written() {
        succeeded = true;
        finishedSend = true;
        synchronized(this) {
            this.notify();
        }
    }
}

--- NEW FILE: UnknownTrailerSendIDException.java ---
package freenet;

public class UnknownTrailerSendIDException extends TrailerException {
}

Index: ConnectionHandler.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/ConnectionHandler.java,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -r1.156 -r1.157
--- ConnectionHandler.java      12 Sep 2003 18:03:48 -0000      1.156
+++ ConnectionHandler.java      18 Sep 2003 17:48:03 -0000      1.157
@@ -103,8 +103,18 @@
     private volatile long sendQueueSize    = 0;
     private volatile long totalDataSent =0;
        private volatile long receiveQueueSize    = 0;
-       private volatile long totalDataReceived =0;
-       private volatile SendOutputStream currentSOS = null;
+       private volatile long totalDataReceived = 0;
+//     private volatile SendOutputStream currentSOS = null;
+       private static Object trailerSendIDCounterLock = new Object();
+       private static int trailerSendIDCounter = 0;
+       private volatile int trailerSendID = -1;
+       private volatile long trailerSendLength = 0;
+       private volatile int trailerSentBytes = 0;
+       private volatile boolean sendingTrailerChunk = false;
+       private final Object trailerSendLock = new Object();
+       private int sendingTrailerChunkBytes = 0;
+       private TrailerWriteCallback twcb;
+       
     //private Thread exec_instance; // execution thread
     private static    EntropySource          sendTimer        = new EntropySource(),
         recvTimer        = new EntropySource();
@@ -244,7 +254,7 @@
                        
                        peer  = new Peer(identity, link.getPeerAddress(),
                                                         link.getManager(), p);
-                       this.logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+                       this.logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                        if(logDEBUG) logDEBUG("New connectionhandler with "+peer, 
true);
                        
                        synchronized(bufferPool) {
@@ -304,7 +314,7 @@
        
        private void logDEBUG(String s, boolean trace) {
                String out = logString(s);
-               if(!Core.logger.shouldLog(Logger.DEBUG)) return;
+               if(!Core.logger.shouldLog(Logger.DEBUG,this)) return;
                if(trace) Core.logger.log(this, out, new Exception("debug"),
                                                                  Logger.DEBUG);
                else Core.logger.log(this, out, Logger.DEBUG);
@@ -424,7 +434,7 @@
      * ONLY called by ReadSelectorLoop
      */
     public int process(ByteBuffer b) {
-               logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                synchronized(receiveClosed) {
                        if(receiveClosed.state()) {
                                logDEBUG("receiveClosed, not processing any more 
bytes");
@@ -469,7 +479,7 @@
                        decrypted = link.makeInputStream(is);
                        
                        if(decrypted == null)
-                               throw new IllegalStateException("null decrypt 
stream!");
+                               return -1; // already closed
                        
                        if((!sentHeader) && is.available() < link.headerBytes()) 
                                return 1; // Need more bytes for IV
@@ -703,6 +713,7 @@
                                                ++receivingCount;
                                                
//incReceiveQueue(m.trailingFieldLength); //Handled in ReceiveInputStream
                                                if(logDEBUG) logDEBUG("Starting to 
transfer trailing fields");
+                                               
                                                CHInputStream is = new CHInputStream();
                                                m.trailingFieldStream = 
currentInputStream =
                                                        new ReceiveInputStream(is, 
m.trailingFieldLength, 
@@ -941,7 +952,7 @@
                                                return;
                                        }
                                }
-                               if(currentSOS != null) {
+                               if(trailerSendID != -1) {
                                        Core.logger.log(this, "We have a sender",
                                                                        Logger.DEBUG);
                                        return;
@@ -981,7 +992,7 @@
                        //not sure exactly how to do that.
                        return;
                }
-               if (currentSOS != null) {
+               if (sendingTrailerChunk) {
                        //if not trailing, continue and get next message from queue
                        if (sendingQueue.size() > 0 && isFNP) {
                                Core.logger.log(this,"something got enqueued on a 
connection after a trailer."+
@@ -1000,17 +1011,38 @@
                                
                        }
                        
-                       synchronized(CHOutputStreamLock) {
-                               if(logDEBUG)logDEBUG("CH.jobDone("+size+","+status+
-                                                                        ") doing 
CHOSL for "+this);
-                               CHOSsent = size;
-                               /*if (!CHOSwaitingForNotification){
-                                 Core.logger.log(this,"scheduler put CH.jobDone 
before CHOS.wait()!!!",Logger.MINOR);
-                                 CHOSalreadyNotified=true;
-                                 }*/
-                               CHOutputStreamLock.notifyAll();
-                               if(logDEBUG)logDEBUG("CH.jobDone("+size+","+status+") 
done CHOSL for "+this);
-                       }
+                       if(size == sendingTrailerChunkBytes) {
+                               synchronized(trailerSendLock) {
+                                       trailerSentBytes += size;
+                                       sendingTrailerChunk = false;
+                                       sendingTrailerChunkBytes = 0;
+                               }
+                               if(twcb != null) twcb.written();
+                       } else {
+                               Core.logger.log(this, "Trailer chunk send failed for 
"+this+
+                                                               ", closing", 
Logger.MINOR);
+                               sendClosed.change(true);
+                               sendingCount = 0;
+                               synchronized(trailerSendLock) {
+                                       sendingTrailerChunk = false;
+                                       sendingTrailerChunkBytes = 0;
+                                       trailerSentBytes = 0;
+                                       trailerSendID = -1;
+                               }
+                               if(twcb != null) twcb.closed();
+                       }
+                       
+//                     synchronized(CHOutputStreamLock) {
+//                             if(logDEBUG)logDEBUG("CH.jobDone("+size+","+status+
+//                                                                      ") doing 
CHOSL for "+this);
+//                             CHOSsent = size;
+//                             /*if (!CHOSwaitingForNotification){
+//                               Core.logger.log(this,"scheduler put CH.jobDone 
before CHOS.wait()!!!",Logger.MINOR);
+//                               CHOSalreadyNotified=true;
+//                               }*/
+//                             CHOutputStreamLock.notifyAll();
+//                             if(logDEBUG)logDEBUG("CH.jobDone("+size+","+status+") 
done CHOSL for "+this);
+//                     }
                } else if(sentMessages.size() > 0) {
                        synchronized(sendLock) { // avoid deadlock
                                synchronized(sentMessages) {
@@ -1187,13 +1219,19 @@
                                                                          " 
trailingPresent "+trailingPresent,
                                                                          
Logger.DEBUG);
                
+               // Open new conn if necessary
+               if(identity != null && 
+                  ocm.findFreeConnection(identity) == null)
+                       Main.node.scheduleConnectionOpener(identity);  //this is an 
overkill 
+                                                               //shouldn't it also 
happen _after_ reducing the counters? --zab
+                       
        }
     
     /**
      * uh, what do we do here?
      */
     public void closed() {
-               logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                if(logDEBUG) logDEBUG("ConnectionHandler closed() called", true);
                //this shouldn't be here but I want to test it
                synchronized(CHOutputStreamLock) {
@@ -1206,15 +1244,94 @@
     }
     
        public void queuedClose() {
-               logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                if(logDEBUG) logDEBUG("Queued close", true);
                terminate();
                if(logDEBUG) logDEBUG("Terminated in queuedClose()");
        }
        
+       protected class MyTrailerWriter implements TrailerWriter {
+               int id;
+               
+               MyTrailerWriter(int id) {
+                       this.id = id;
+               }
+               
+               public void writeTrailing(byte[] block, int offset, int length,
+                                                                 TrailerWriteCallback 
cb)
+                       throws UnknownTrailerSendIDException, 
TrailerSendFinishedException, AlreadySendingTrailerChunkException, IOException {
+                       ConnectionHandler.this.writeTrailing(id, block, offset, 
length, cb);
+               }
+               
+               public void close() {
+                       closeTrailer(id);
+               }
+       }
+       
+       public void writeTrailing(int id, byte[] block, int offset, int length,
+                                                         TrailerWriteCallback cb) 
+               throws UnknownTrailerSendIDException, TrailerSendFinishedException, 
AlreadySendingTrailerChunkException, IOException {
+               synchronized(trailerSendLock) {
+                       if(finalized.state() || sendClosed.state())
+                               throw new IOException("Closed");
+                       if(trailerSendID != id)
+                               throw new UnknownTrailerSendIDException();
+                       if(trailerSentBytes >= trailerSendLength) {
+                               trailerSendID = -1;
+                               throw new TrailerSendFinishedException();
+                       }
+                       if(sendingTrailerChunk) {
+                               throw new AlreadySendingTrailerChunkException();
+                       }
+                       if(length <= 0)
+                               throw new IllegalArgumentException();
+                       sendingTrailerChunkBytes = length;
+                       sendingTrailerChunk = true;
+                       // Encrypt the data
+                       Link l = link;
+                       if(l != null)
+                               l.encryptBytes(block, offset, length);
+                       else {
+                               IOException e = 
+                                       new IOException("Connection closed in trailer 
send!");
+                               Core.logger.log(this, "Oops: "+e+" ("+this+")", e, 
+                                                               Logger.NORMAL);
+                               closeTrailer(id);
+                       }
+                       twcb = cb;
+                       // Send the data
+                       sendBytes(block, offset, length, wsl.TRAILER);
+               }
+       }
+       
+       public void closeTrailer(int id) {
+               // Inspired by SOS.done()
+               synchronized(sendLock) {
+                       --sendingCount;
+                       trailingPresent = false;
+               }
+               synchronized(trailerSendLock) {
+                       if(trailerSendID == id) {
+                               if(trailerSentBytes != trailerSendLength) {
+                                       Core.logger.log(this, "Called closeTrailer, 
when only sent "+
+                                                                       
trailerSentBytes+" of "+trailerSendLength+
+                                                                       " ("+this+")", 
new Exception("hrrm"), 
+                                                                       Logger.MINOR);
+                               }
+                               trailerSendID = -1;
+                               trailerSentBytes = 0;
+                               trailerSendLength = 0;
+                       } else if (trailerSendID != -1) {
+                               Core.logger.log(this, "Closing trailer "+id+" when 
handling "+
+                                                               trailerSendID+"! 
("+this+")", 
+                                                               new Exception("hrrm"), 
Logger.ERROR);
+                       }
+               }
+       }
+       
     private Object CHOutputStreamLock = new Object();
     
-   final class CHOutputStream extends OutputStream {
+       final class CHOutputStream extends OutputStream {
        protected boolean dead = false;
        
                private long waitTime=0;
@@ -1225,7 +1342,7 @@
                
                public CHOutputStream() throws IOException {
                        
-                       logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+                       logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                        
                        tcpConnection c = conn;
                        if(c == null) {
@@ -1693,7 +1810,7 @@
         * TODO: find out why
         */
        private void innerClose() {
-               logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                if(logDEBUG) logDEBUG("Closing CHIS", true);
                dead = true;
                doneMovingTrailingFields = true;
@@ -1874,7 +1991,7 @@
                         
 //                         Core.randSource.acceptTimerEntropy(recvTimer);
                         
-//                         if (Core.logger.shouldLog(Logger.DEBUG))
+//                         if (Core.logger.shouldLog(Logger.DEBUG,this))
 //                             Core.logger.log(this, "Receiving RawMessage: " + m,
 //                                             Logger.DEBUG);
                         
@@ -2122,7 +2239,7 @@
                }
                
                void closed() {
-                       logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+                       logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                        if(logDEBUG) logDEBUG("MessageSend closed(): "+this);
                        if(!done) jobDone(0, false);
                }
@@ -2178,7 +2295,7 @@
                }
                
                void jobDone(int size, boolean status) {
-                       logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+                       logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                        try {
                                if(size == toSend.length) {
                                        success = true;
@@ -2336,7 +2453,7 @@
                                                                                       
         MessageSendCallback cb) 
                //no other way really
                throws SendFailedException {
-               logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                try {
                        if (sendClosed.state())
                                throw new SendFailedException(peer.getAddress(), 
false);
@@ -2348,14 +2465,16 @@
                                if (sendClosed.state())
                                // check again when synced
                                        throw new 
SendFailedException(peer.getAddress(), false);
-                               if(currentSOS != null)
+                               if(trailerSendID != -1)
                                        throw new 
SendFailedException(peer.getAddress(), false);
                                MessageSend ms = null;
                                try {
                                        sendingCount++;
                                        if (raw.trailingFieldLength > 0) {
                                                trailingPresent=true;
-                                               if (logDEBUG)Core.logger.log(this, 
"enqueing trailer, queue size " + sendingQueue.size()+" on "+this,Logger.DEBUG);
+                                               if (logDEBUG)Core.logger.log(this, 
"enqueing trailer, queue size " + 
+                                                                                      
                  sendingQueue.size()+" on "+this,
+                                                                                      
                  Logger.DEBUG);
                                        }
                                        if(identity != null && 
                                           ocm.findFreeConnection(identity) == null)
@@ -2373,8 +2492,7 @@
                                        }
                                        if(logDEBUG) logDEBUG(sendingCount + " 
messages in sendqueue");
                                        
-                                       if (Core.logger.shouldLog(Logger.DEBUG))
-                                               if(logDEBUG) logDEBUG("Sending 
RawMessage: " + raw, true);
+                                       if(logDEBUG) logDEBUG("Sending RawMessage: " + 
raw, true);
                                        
                                        // WATCHME
                                        if (Main.watchme != null) {
@@ -2382,7 +2500,7 @@
                                        }
                                        
                                        // users are fond of this log entry
-                                       if (Core.logger.shouldLog(Logger.MINOR))
+                                       if (Core.logger.shouldLog(Logger.MINOR,this))
                                                Core.logger.log(this,
                                                                                
raw.messageType + " @ " +
                                                                                
Long.toHexString(m.id())
@@ -2498,11 +2616,15 @@
                }
        }
        
-       public OutputStream sendMessage(Message m) 
+       /** Blocking send of a message
+        * @return a TrailerWriter for the attached trailing field if there is one, 
null otherwise
+        */
+       public TrailerWriter sendMessage(Message m) 
                throws SendFailedException {
                MessageSend ms;
                RawMessage raw;
                long startedsend=0;
+               TrailerWriter send = null;
                synchronized(this) { //extend locking even further
                        if (conn == null || trailingPresent)  //this should not be set 
when entering new message
                                throw new SendFailedException(peer.getAddress(), 
false);
@@ -2526,7 +2648,7 @@
                        }
                        if(logDEBUG) logDEBUG("Waited for MessageSend");
                }
-               OutputStream send = null;
+               int sendId = -1;
                if(ms.sfe != null) {
                        Core.logger.log(this, "MessageSend produced 
SendFailedException "+
                                                        " for "+this+": "+ms.sfe, 
ms.sfe, Logger.MINOR);
@@ -2540,13 +2662,23 @@
                                        // has trailing
                                        knowAboutTrailing = true;
                                        if(logDEBUG) logDEBUG("Has trailing");
-                                       OutputStream os = new CHOutputStream();
+//                                     OutputStream os = new CHOutputStream();
                                        Link l = link;
                                        if(l == null) throw new IOException("Closed in 
middle of send");
-                                       os = l.makeOutputStream(os);
-                                       send = currentSOS =
-                                               new SendOutputStream(os, 
raw.trailingFieldLength);
-                                       if(logDEBUG) logDEBUG("Started 
SendOutputStream");
+                                       
+//                                     os = l.makeOutputStream(os);
+                                       synchronized(trailerSendIDCounterLock) {
+                                               trailerSendIDCounter++;
+                                               if(trailerSendIDCounter < 0) 
trailerSendIDCounter = 0;
+                                               sendId = trailerSendIDCounter;
+                                       }
+                                       synchronized(trailerSendLock) {
+                                               trailerSendID = sendId;
+                                               trailerSendLength = 
ms.raw.trailingFieldLength;
+                                               trailerSentBytes = 0;
+                                       }
+                                       send = new MyTrailerWriter(sendId);
+                                       if(logDEBUG) logDEBUG("Started 
MyTrailerWriter("+sendId+"): "+send);
                                } else {
                                        if(logDEBUG) logDEBUG("Does not have 
trailing");
                                        // does not
@@ -2601,31 +2733,25 @@
        Message  m  = p.getCloseMessage();
        if (m != null)
            try {
-               OutputStream  out  = sendMessage(m);
-               if (out != null)
-                   // wtf...
-                   out.close();
-           }
-       catch (IOException e) {
-               Core.logger.log(this, "Impossible exception in "+this+".close(): "+e,
-                                               e, Logger.NORMAL);
-           // wtf wtf...
-       }
-       catch (SendFailedException e) {
-           Core.logger.log(this,
-                           "Failed to send connection close message for "
-                           + this + ": " + m, e, Core.logger.MINOR);
-               terminate(); 
-       }
+                       TrailerWriter out  = sendMessage(m);
+                       if (out != null)
+                               // wtf...
+                               out.close();
+               } catch (SendFailedException e) {
+                       Core.logger.log(this,
+                                                       "Failed to send connection 
close message for "
+                                                       + this + ": " + m, e, 
Core.logger.MINOR);
+                       terminate(); 
+               }
        /*finally{
-               terminate();
-       }*/
+         terminate();
+         }*/
     }
        
     /**  Closes the connection utterly and finally. */
     public void terminate() {
                //              if(unregisteredFromOCM) decOpenButNotOnOCM();
-               logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+               logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                if(logDEBUG) logDEBUG("Terminating", true);
                // Unconditionally remove the connection handler
                // from the OCM
@@ -2728,6 +2854,13 @@
                if(logDEBUG) logDEBUG("Closed CHIS in terminate()");
                link = null;
                conn = null;
+               synchronized(trailerSendLock) {
+                       sendingTrailerChunk = false;
+                       sendingTrailerChunkBytes = 0;
+                       trailerSentBytes = 0;
+                       trailerSendID = -1;
+               }
+               if(twcb != null) twcb.closed();
                if(logDEBUG) logDEBUG("terminate()d");
        }
        
@@ -3144,130 +3277,130 @@
      *  An OutputStream that only allows writing of so many bytes, and that
      *  releases the sendLock that many bytes are written or it closed.
      */
-    private final class SendOutputStream extends FilterOutputStream {
+//     private final class SendOutputStream extends FilterOutputStream {
 
-        private        long     written  = 0;
-        private final  long     toWrite;
-        private        boolean  done     = false;
+//         private        long     written  = 0;
+//         private final  long     toWrite;
+//         private        boolean  done     = false;
        
 
 
-        public SendOutputStream(OutputStream out, long toWrite) {
-            super(out);
-            this.toWrite = toWrite;
-                       //profiling
-                       //WARNING:remove before release
-                       synchronized(profLockSOS) {
-                               SOSinstances++;
-                       }
-        }
+//         public SendOutputStream(OutputStream out, long toWrite) {
+//             super(out);
+//             this.toWrite = toWrite;
+//                     //profiling
+//                     //WARNING:remove before release
+//                     synchronized(profLockSOS) {
+//                             SOSinstances++;
+//                     }
+//         }
 
 
-        public void write(int i)
-            throws IOException {
-            try {
-                if (written >= toWrite)
-                    throw new IOException("Overwriting: " + written +
-                                          " + 1 > " + toWrite);
-                out.write(i);
-                written++;
-                               decSendQueue(1);
-                if (toWrite == written)
-                    done();
-            }
-            catch (IOException e) {
-                close();
-                throw (IOException) e.fillInStackTrace();
-            }
-        }
+//         public void write(int i)
+//             throws IOException {
+//             try {
+//                 if (written >= toWrite)
+//                     throw new IOException("Overwriting: " + written +
+//                                           " + 1 > " + toWrite);
+//                 out.write(i);
+//                 written++;
+//                             decSendQueue(1);
+//                 if (toWrite == written)
+//                     done();
+//             }
+//             catch (IOException e) {
+//                 close();
+//                 throw (IOException) e.fillInStackTrace();
+//             }
+//         }
 
 
-        public void write(byte[] b, int off, int length)
-            throws IOException {
-            try {
-                if (written + length > toWrite)
-                    throw new IOException("Overwriting: " + written + " + " + length
-                                          + " > " + toWrite);
-                out.write(b, off, length);
-                written += length;
-                               decSendQueue(length);
-                if (written == toWrite)
-                    done();
-            }
-            catch (IOException e) {
-                close();
-                throw (IOException) e.fillInStackTrace();
-            }
-        }
+//         public void write(byte[] b, int off, int length)
+//             throws IOException {
+//             try {
+//                 if (written + length > toWrite)
+//                     throw new IOException("Overwriting: " + written + " + " + 
length
+//                                           + " > " + toWrite);
+//                 out.write(b, off, length);
+//                 written += length;
+//                             decSendQueue(length);
+//                 if (written == toWrite)
+//                     done();
+//             }
+//             catch (IOException e) {
+//                 close();
+//                 throw (IOException) e.fillInStackTrace();
+//             }
+//         }
 
 
-        public void close()
-            throws IOException {
-            if (!done && written < toWrite)
-                Core.logger.log(ConnectionHandler.this,
-                                "Close after " + written + " of " + toWrite + " bytes 
on: " + this,
-                                Logger.MINOR);
+//         public void close()
+//             throws IOException {
+//             if (!done && written < toWrite)
+//                 Core.logger.log(ConnectionHandler.this,
+//                                 "Close after " + written + " of " + toWrite + " 
bytes on: " + this,
+//                                 Logger.MINOR);
 
             
-            decSendQueue(toWrite - written);
+//             decSendQueue(toWrite - written);
             
-            written = toWrite;
-            done();
-        }
+//             written = toWrite;
+//             done();
+//         }
 
 
-        public void done() {
-            if (!done) {
-                done = true;
-                synchronized (sendLock) {
+//         public void done() {
+//             if (!done) {
+//                 done = true;
+//                 synchronized (sendLock) {
                     
-                    --sendingCount;
+//                     --sendingCount;
                                        
-                    //reset the trailing flag, since we can have only one trailer at 
a time
-                                       if(!trailingPresent) {
-                                               Exception e = new Exception("duh");
-                                               Core.logger.log(this, "Called 
SOS.done() with "+
-                                                                               
"trailingPresent == false!!", e,
-                                                                               
Logger.ERROR);
-                                       }
-                                       trailingPresent=false;
-                                       currentSOS = null;
+//                     //reset the trailing flag, since we can have only one trailer 
at a time
+//                                     if(!trailingPresent) {
+//                                             Exception e = new Exception("duh");
+//                                             Core.logger.log(this, "Called 
SOS.done() with "+
+//                                                                             
"trailingPresent == false!!", e,
+//                                                                             
Logger.ERROR);
+//                                     }
+//                                     trailingPresent=false;
+//                                     currentSOS = null;
                                        
-                    if (receiveClosed.state() && receivingCount == 0
-                        && sendClosed.state() && sendingCount == 0) {
-                        terminate();
-                    }
+//                     if (receiveClosed.state() && receivingCount == 0
+//                         && sendClosed.state() && sendingCount == 0) {
+//                         terminate();
+//                     }
 
-                                       logDEBUG("Message and trailing field sent.");
+//                                     logDEBUG("Message and trailing field sent.");
 
-                    Core.randSource.acceptTimerEntropy(sendTimer);
+//                     Core.randSource.acceptTimerEntropy(sendTimer);
 
-                    lastActiveTime = System.currentTimeMillis();
-                    sendLock.notify();
-                    // wake a possible waiting thread.
-                }
-            }
-        }
+//                     lastActiveTime = System.currentTimeMillis();
+//                     sendLock.notify();
+//                     // wake a possible waiting thread.
+//                 }
+//             }
+//         }
 
-        /*
-         *  Removed because it prevents early GCing of these objects. - someone
-         *  Restored because it prevents an eternal lock on sending, and I'm
-         *  pretty sure we were seeing that. - oskar
-         */
-        protected void finalize() throws Throwable {
-            if (!done) {
-                Core.logger.log( ConnectionHandler.this,
-                                 "I was finalized without being " + 
-                                 "properly deallocated: "+this,
-                                 Logger.ERROR);
-                done();
-            }
-                       synchronized(profLockSOS) {
-                               SOSinstances--;
-                       }
-            super.finalize();
-        }
-    }
+//         /*
+//          *  Removed because it prevents early GCing of these objects. - someone
+//          *  Restored because it prevents an eternal lock on sending, and I'm
+//          *  pretty sure we were seeing that. - oskar
+//          */
+//         protected void finalize() throws Throwable {
+//             if (!done) {
+//                 Core.logger.log( ConnectionHandler.this,
+//                                  "I was finalized without being " + 
+//                                  "properly deallocated: "+this,
+//                                  Logger.ERROR);
+//                 done();
+//             }
+//                     synchronized(profLockSOS) {
+//                             SOSinstances--;
+//                     }
+//             super.finalize();
+//         }
+//     }
        
        public String toString() {
                return super.toString()+" for "+conn+","+link+", sending 
"+sentMessagesCount;

Index: PeerPacket.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/PeerPacket.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PeerPacket.java     8 Sep 2003 17:03:03 -0000       1.1
+++ PeerPacket.java     18 Sep 2003 17:48:04 -0000      1.2
@@ -25,7 +25,7 @@
            System.arraycopy(msgBytes, 0, encryptedData, x, msgBytes.length);
            x += msgBytes.length;
        }
-       l.encryptBytes(encryptedData);
+       l.encryptBytes(encryptedData,0,encryptedData.length);
     }
     
     public int getLength() {

Index: Ticker.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Ticker.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Ticker.java 11 Sep 2003 01:17:15 -0000      1.19
+++ Ticker.java 18 Sep 2003 17:48:04 -0000      1.20
@@ -93,7 +93,7 @@
        
                Event evt = new Event(mo, time);
        
-               if(Core.logger.shouldLog(Core.logger.DEBUG))
+               if(Core.logger.shouldLog(Logger.DEBUG,this))
                        Core.logger.log(this, "scheduling " + evt + 
                                                        " to run at " + time + " at " 
+ x, 
                                                        new Exception("debug"), 
Logger.DEBUG);
@@ -110,7 +110,7 @@
     public void run() {
         Vector jobs = new Vector();
         while (true) {
-                       boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
+                       boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG,this);
                        if(logDEBUG) timeLog("Running Ticker loop");
             synchronized (this) {
                                if(logDEBUG) timeLog("Synchronized in Ticker loop");
@@ -189,7 +189,7 @@
     }
     
     protected void timeLog(String s) {
-               if(Core.logger.shouldLog(Logger.DEBUG))
+               if(Core.logger.shouldLog(Logger.DEBUG,this))
                        Core.logger.log(this, s+" at "+System.currentTimeMillis(),
                                                        Logger.DEBUG);
     }
@@ -240,7 +240,7 @@
                        synchronized(eventCounterSync) {
                                id = eventCounter++;
                        }
-                       //          if(Core.logger.shouldLog(Core.logger.DEBUG))
+                       //          if(Core.logger.shouldLog(Logger.DEBUG))
                        //              initException = new Exception("debug");
         }
 
@@ -253,7 +253,7 @@
             synchronized (Ticker.this) {
                 ret = heapElement.remove();
             }
-                       if(Core.logger.shouldLog(Core.logger.DEBUG))
+                       if(Core.logger.shouldLog(Logger.DEBUG,this))
                                Core.logger.log(Ticker.this,
                                                                (ret ? "cancelled " : 
"failed to cancel ") + 
                                                                this, new 
Exception("debug"),
@@ -269,14 +269,14 @@
                        long now = System.currentTimeMillis();
                        long delay = now - time;
             Core.diagnostics.occurrenceContinuous("tickerDelay", delay);
-                       if(delay > 500 && Core.logger.shouldLog(Core.logger.DEBUG)) {
+                       if(delay > 500 && Core.logger.shouldLog(Logger.DEBUG,this)) {
                                Core.logger.log(this, "Long tickerDelay ("+delay+
                                                                "), for event for 
"+time+" at "+now,
-                                                               new 
Exception("debug"), Core.logger.DEBUG);
+                                                               new 
Exception("debug"), Logger.DEBUG);
                                //              Core.logger.log(this, "Delay 
started:", initException,
-                               //                              Core.logger.DEBUG);
+                               //                              Logger.DEBUG);
                        }
-                       if(Core.logger.shouldLog(Core.logger.DEBUG))
+                       if(Core.logger.shouldLog(Logger.DEBUG,this))
                                Core.logger.log(Ticker.this, "running " + this 
                                                                + " at "+ now + " for 
"+time, 
                                                                Logger.DEBUG);

Index: Version.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Version.java,v
retrieving revision 1.387
retrieving revision 1.388
diff -u -r1.387 -r1.388
--- Version.java        12 Sep 2003 18:03:49 -0000      1.387
+++ Version.java        18 Sep 2003 17:48:04 -0000      1.388
@@ -18,7 +18,7 @@
     public static String protocolVersion = "1.46";
     
     /** The build number of the current revision */
-    public static final int buildNumber = 6194;
+    public static final int buildNumber = 6195;
     // 6028: may 3; ARK retrieval fix
 
     public static final int ignoreBuildsAfter = 6500;

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

Reply via email to