Author: toad
Date: 2007-06-01 19:25:44 +0000 (Fri, 01 Jun 2007)
New Revision: 13452

Modified:
   trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java
   trunk/freenet/src/freenet/node/PeerNode.java
   trunk/freenet/src/freenet/support/BitArray.java
   trunk/freenet/src/freenet/support/ShortBuffer.java
   trunk/freenet/src/freenet/support/io/FileUtil.java
Log:
More bugfixes. Maybe working now...

Modified: trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java
===================================================================
--- trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java        
2007-06-01 18:25:12 UTC (rev 13451)
+++ trunk/freenet/src/freenet/io/xfer/PartiallyReceivedBulk.java        
2007-06-01 19:25:44 UTC (rev 13452)
@@ -160,7 +160,7 @@

        public byte[] getBlockData(int blockNum) {
                long fileOffset = (long)blockNum * (long)blockSize;
-               int bs = (int) Math.max(blockSize, size - fileOffset);
+               int bs = (int) Math.min(blockSize, size - fileOffset);
                byte[] data = new byte[bs];
                try {
                        raf.pread(fileOffset, data, 0, bs);

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2007-06-01 18:25:12 UTC 
(rev 13451)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2007-06-01 19:25:44 UTC 
(rev 13452)
@@ -3236,7 +3236,7 @@
                }

                public void accept() {
-                       File dest = new File(node.clientCore.downloadDir, 
"direct-"+FileUtil.sanitize(getName())+filename);
+                       File dest = new File(node.clientCore.downloadDir, 
"direct-"+FileUtil.sanitize(getName())+"-"+filename);
                        try {
                                data = new RandomAccessFileWrapper(dest, "rw");
                        } catch (FileNotFoundException e) {
@@ -3248,11 +3248,19 @@
                        // FIXME make this persistent
                        Thread t = new Thread(new Runnable() {
                                public void run() {
-                                       if(!receiver.receive()) {
-                                               String err = "Failed to receive 
"+this;
-                                               Logger.error(this, err);
-                                               System.err.println(err);
+                                       if(logMINOR)
+                                               Logger.minor(this, "Received 
file");
+                                       try {
+                                               if(!receiver.receive()) {
+                                                       String err = "Failed to 
receive "+this;
+                                                       Logger.error(this, err);
+                                                       System.err.println(err);
+                                               }
+                                       } catch (Throwable t) {
+                                               Logger.error(this, "Caught 
"+t+" receiving file", t);
                                        }
+                                       if(logMINOR)
+                                               Logger.minor(this, "Received 
file");
                                }
                        }, "Receiver for bulk transfer "+uid+":"+filename);
                        t.setDaemon(true);
@@ -3263,13 +3271,23 @@
                public void send() throws DisconnectedException {
                        prb = new PartiallyReceivedBulk(node.usm, size, 
Node.PACKET_SIZE, data, true);
                        transmitter = new BulkTransmitter(prb, PeerNode.this, 
uid, node.outputThrottle);
+                       if(logMINOR)
+                               Logger.minor(this, "Sending "+uid);
                        Thread t = new Thread(new Runnable() {
                                public void run() {
-                                       if(!transmitter.send()) {
-                                               String err = "Failed to send 
"+this;
-                                               Logger.error(this, err);
-                                               System.err.println(err);
+                                       if(logMINOR)
+                                               Logger.minor(this, "Sending 
file");
+                                       try {
+                                               if(!transmitter.send()) {
+                                                       String err = "Failed to 
send "+this;
+                                                       Logger.error(this, err);
+                                                       System.err.println(err);
+                                               }
+                                       } catch (Throwable t) {
+                                               Logger.error(this, "Caught 
"+t+" sending file", t);
                                        }
+                                       if(logMINOR)
+                                               Logger.minor(this, "Sent file");
                                }
                        }, "Sender for bulk transfer "+uid+":"+filename);
                        t.setDaemon(true);
@@ -3428,6 +3446,8 @@
                        Logger.error(this, "Could not parse offer accepted: 
"+e+" on "+this+" :\n"+fs, e);
                        return;
                }
+               if(logMINOR)
+                       Logger.minor(this, "Offer accepted for "+uid);
                Long u = new Long(uid);
                FileOffer fo;
                synchronized(this) {

Modified: trunk/freenet/src/freenet/support/BitArray.java
===================================================================
--- trunk/freenet/src/freenet/support/BitArray.java     2007-06-01 18:25:12 UTC 
(rev 13451)
+++ trunk/freenet/src/freenet/support/BitArray.java     2007-06-01 19:25:44 UTC 
(rev 13452)
@@ -43,8 +43,8 @@

        public BitArray(BitArray src) {
                this._size = src._size;
-               this._bits = new byte[src._size];
-               System.arraycopy(_bits, 0, src._bits, 0, _bits.length);
+               this._bits = new byte[src._bits.length];
+               System.arraycopy(src._bits, 0, _bits, 0, src._bits.length);
        }

        public void setBit(int pos, boolean f) {

Modified: trunk/freenet/src/freenet/support/ShortBuffer.java
===================================================================
--- trunk/freenet/src/freenet/support/ShortBuffer.java  2007-06-01 18:25:12 UTC 
(rev 13451)
+++ trunk/freenet/src/freenet/support/ShortBuffer.java  2007-06-01 19:25:44 UTC 
(rev 13452)
@@ -56,7 +56,7 @@
        public ShortBuffer(byte[] data) {
                _start = 0;
                if(data.length > Short.MAX_VALUE)
-                   throw new IllegalArgumentException();
+                   throw new IllegalArgumentException("Too big: "+data.length);
                _length = (short)data.length;
                _data = data;
        }

Modified: trunk/freenet/src/freenet/support/io/FileUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileUtil.java  2007-06-01 18:25:12 UTC 
(rev 13451)
+++ trunk/freenet/src/freenet/support/io/FileUtil.java  2007-06-01 19:25:44 UTC 
(rev 13452)
@@ -125,8 +125,10 @@
                if(filename.indexOf('.') >= 0) {
                        String oldExt = 
filename.substring(filename.lastIndexOf('.'));
                        if(DefaultMIMETypes.isValidExt(mimeType, oldExt)) 
return filename;
-               } 
-               return filename + '.' + DefaultMIMETypes.getExtension(filename);
+               }
+               String defaultExt = DefaultMIMETypes.getExtension(filename);
+               if(defaultExt == null) return filename;
+               else return filename + '.' + defaultExt;
        }

 }


Reply via email to