gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3219 - in freeway: . src/org/gnu/freeway src/org/gnu/freew


From: mdonoughe
Subject: [GNUnet-SVN] r3219 - in freeway: . src/org/gnu/freeway src/org/gnu/freeway/cwrappers src/org/gnu/freeway/protocol/stats src/org/gnu/freeway/server src/org/gnu/freeway/util src/org/gnu/freeway/util/crypto src/org/gnu/freeway/util/io src/org/gnu/freeway/util/net
Date: Sat, 12 Aug 2006 08:45:29 -0700 (PDT)

Author: mdonoughe
Date: 2006-08-12 08:45:04 -0700 (Sat, 12 Aug 2006)
New Revision: 3219

Added:
   freeway/src/org/gnu/freeway/cwrappers/CHostIdentity.java
   freeway/src/org/gnu/freeway/cwrappers/ConstCHostIdentity.java
   freeway/src/org/gnu/freeway/protocol/stats/CSGetMessageSupported.java
   freeway/src/org/gnu/freeway/server/NativeCallback.java
   freeway/src/org/gnu/freeway/util/crypto/HashCode512.java
   freeway/src/org/gnu/freeway/util/net/P2PNativeMessage.java
Removed:
   freeway/src/org/gnu/freeway/net/
   freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java
Modified:
   freeway/
   freeway/src/org/gnu/freeway/AbstractClient.java
   freeway/src/org/gnu/freeway/GNUNetStats.java
   freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
   freeway/src/org/gnu/freeway/cwrappers/ConstCLongPtr.java
   freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
   freeway/src/org/gnu/freeway/server/CPluginLoader.java
   freeway/src/org/gnu/freeway/server/ClientServer.java
   freeway/src/org/gnu/freeway/server/ConnectionService.java
   freeway/src/org/gnu/freeway/server/CoreAPI.java
   freeway/src/org/gnu/freeway/server/MessagesDispatcher.java
   freeway/src/org/gnu/freeway/util/OutputFilter.java
   freeway/src/org/gnu/freeway/util/Prefs.java
   freeway/src/org/gnu/freeway/util/Statistics.java
   freeway/src/org/gnu/freeway/util/io/DirLocation.java
   freeway/src/org/gnu/freeway/util/io/FileLocation.java
   freeway/src/org/gnu/freeway/util/net/CSMessage.java
   freeway/src/org/gnu/freeway/util/net/PersistentHelper.java
Log:

 started working on the freeway-stats client
 improved native callbacks
 implemented more of CoreAPI in Java(not accessible to C in this revision)
 Prefs no longer gives the working directory if the path is ""
 Folders are no longer deleted to make files
 Files are no longer deleted to make folders
 512 bit hashcodes(I think this was forgotten last revision)



Property changes on: freeway
___________________________________________________________________
Name: svk:merge
   - ca0d4bff-9018-0410-8ce9-c5d843b21c37:/local/freeway:71
   + ca0d4bff-9018-0410-8ce9-c5d843b21c37:/local/freeway:73

Modified: freeway/src/org/gnu/freeway/AbstractClient.java
===================================================================
--- freeway/src/org/gnu/freeway/AbstractClient.java     2006-08-08 20:25:41 UTC 
(rev 3218)
+++ freeway/src/org/gnu/freeway/AbstractClient.java     2006-08-12 15:45:04 UTC 
(rev 3219)
@@ -50,8 +50,8 @@
 
                prefs=getPreferences();
                host=prefs.getString("NETWORK","HOST","localhost");
-               port=prefs.getInt("NETWORK","PORT",0);
-
+               port=prefs.getInt("NETWORK","CLIENT-PORT",0);
+               System.err.println("Connecting to port " + port + " on " + host 
+ ".");
                try {
                        ip=InetAddress.getByName(host);
                        }

Modified: freeway/src/org/gnu/freeway/GNUNetStats.java
===================================================================
--- freeway/src/org/gnu/freeway/GNUNetStats.java        2006-08-08 20:25:41 UTC 
(rev 3218)
+++ freeway/src/org/gnu/freeway/GNUNetStats.java        2006-08-12 15:45:04 UTC 
(rev 3219)
@@ -4,12 +4,17 @@
 
 package org.gnu.freeway;
 
-import org.gnu.freeway.server.*;
-import org.gnu.freeway.util.*;
-import org.gnu.freeway.util.net.*;
+import java.io.PrintWriter;
+import java.util.logging.Level;
 
-import java.io.*;
-import java.util.logging.*;
+import org.gnu.freeway.protocol.stats.CSStatsMessage;
+import org.gnu.freeway.services.java.StatsService;
+import org.gnu.freeway.util.Option;
+import org.gnu.freeway.util.OptionsParser;
+import org.gnu.freeway.util.Scheduler;
+import org.gnu.freeway.util.Utils;
+import org.gnu.freeway.util.net.CSMessage;
+import org.gnu.freeway.util.net.CSSession;
 
 /**
  * Tool to obtain statistics from gnunetd.
@@ -18,14 +23,12 @@
 public class GNUNetStats extends AbstractClient
 {
        private boolean printProtocols;
-       private int             minLevel;
 
 
        public GNUNetStats()
        {
                super("gnunet-stats",Utils.makeVersion(2,0,1));
                printProtocols=false;
-               minLevel=Stat.NORMAL;
        }
 
        public String toString()
@@ -52,13 +55,6 @@
                                return true;
                        }
                        });
-               options.addOption(new Option("min-level|m|LEVEL","set minimum 
level of verbosity to LEVEL") {
-                       public boolean exec( Command c )
-                       {
-                               minLevel=getIntValue(Stat.NORMAL);
-                               return true;
-                       }
-                       });
                options.addOption(HELP_HOSTNAME);
                options.addOption(HELP_VERSION);
                return options;
@@ -69,7 +65,7 @@
                CSSession               sock;
                PrintWriter             out;
                boolean                 res;
-
+System.err.println("running");
                sock=connect();
                //todo: faire le test dans la superclasse!!!
                if (sock==null) {
@@ -99,12 +95,12 @@
 
        protected boolean requestAndPrintStatistics( PrintWriter out, CSSession 
sock )
        {
-               /*Stat[]                stats;
-               CSStatistics            statMsg;
+               StatsService.Entry[]            stats; // we get our stats from 
the Java version of the StatsMessage decoder
+               CSStatsMessage          statMsg;
                long                            t;
                int                             totalCounters,count,i;
 
-               if (!sock.send(new CSStatisticsRequest(minLevel))) {
+               if (!sock.send(new 
CSMessage(CSMessage.CS_PROTO_stats_GET_STATISTICS))) {
                        out.println("Error sending request for statistics to 
gnunetd.");
                        return false;
                        }
@@ -115,7 +111,7 @@
                totalCounters=1;
 
                while (count<totalCounters) {
-                       statMsg=(CSStatistics) sock.receive(CSStatistics.class);
+                       statMsg=(CSStatsMessage) 
sock.receive(CSStatsMessage.class);
                        if (statMsg==null) {
                                out.println("Error receiving reply for 
statistics from gnunetd.");
                                return false;
@@ -136,11 +132,11 @@
 
                        stats=statMsg.getStatistics();
                        for (i=0; i<stats.length; i++) {
-                               
out.println(Utils.alignRight(stats[i].getName()+" /"+stats[i].getLevel(),60)+" 
: "+Utils.alignLeft(stats[i].get(),16));
+                               out.println(Utils.alignRight(stats[i].key,60)+" 
: "+Utils.alignLeft(stats[i].value.getValue(),16));
                                }
                        count+=stats.length;
                        }
-               out.println();*/
+               out.println();
                return true;
        }
 
@@ -241,6 +237,6 @@
 
        public static void main( String[] args )
        {
-//             launch(GNUNetStats.class,args);
+               launch(GNUNetStats.class,args);
        }
 }

Added: freeway/src/org/gnu/freeway/cwrappers/CHostIdentity.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CHostIdentity.java    2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/cwrappers/CHostIdentity.java    2006-08-12 
15:45:04 UTC (rev 3219)
@@ -0,0 +1,57 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import java.nio.ByteBuffer;
+
+import org.gnu.freeway.cwrappers.ConstCHostIdentity;
+import org.gnu.freeway.cwrappers.util.CWrapper;
+import org.gnu.freeway.util.crypto.HostIdentity;
+import org.gnu.freeway.util.net.PersistentHelper;
+
+/**
+ * @file CHostIdentity.java
+ * @brief 
+ * @author mdonoughe
+ */
+public class CHostIdentity extends ConstCHostIdentity implements CWrapper {
+
+       private static final int KIND = CWrapper.PTR_KIND;
+       
+       public CHostIdentity(byte[] serializedData) {
+               super(null);
+               deserializeFromByteArray(serializedData);
+       }
+       
+       public CHostIdentity(HostIdentity value) {
+               super(value);
+       }
+       /* (non-Javadoc)
+        * @see 
org.gnu.freeway.cwrappers.util.CWrapper#deserializeFromByteArray(byte[])
+        */
+       public void deserializeFromByteArray(byte[] serializedData) {
+               value = (HostIdentity) 
PersistentHelper.readFully(HostIdentity.class, ByteBuffer.wrap(serializedData));
+       }
+       
+       public void setValue(HostIdentity value) {
+               this.value = value;
+       }
+
+}

Added: freeway/src/org/gnu/freeway/cwrappers/ConstCHostIdentity.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCHostIdentity.java       
2006-08-08 20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCHostIdentity.java       
2006-08-12 15:45:04 UTC (rev 3219)
@@ -0,0 +1,59 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.CWrapper;
+import org.gnu.freeway.cwrappers.util.ConstCWrapper;
+import org.gnu.freeway.util.crypto.HostIdentity;
+import org.gnu.freeway.util.net.PersistentHelper;
+
+/**
+ * @file ConstCHostIdentity.java
+ * @brief 
+ * @author mdonoughe
+ */
+public class ConstCHostIdentity implements ConstCWrapper {
+       
+       private static final int KIND = CWrapper.PTR_KIND;
+       
+       protected HostIdentity value;
+       
+       public ConstCHostIdentity(HostIdentity value) {
+               this.value = value;
+       }
+       
+       /* (non-Javadoc)
+        * @see org.gnu.freeway.cwrappers.util.ConstCWrapper#getSerializedSize()
+        */
+       public int getSerializedSize() {
+               return 64;
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.gnu.freeway.cwrappers.util.ConstCWrapper#serializeToByteArray()
+        */
+       public byte[] serializeToByteArray() {
+               return PersistentHelper.toBytes(value);
+       }
+
+       public HostIdentity getValue() {
+               return value;
+       }
+}

Modified: freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java        2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java        2006-08-12 
15:45:04 UTC (rev 3219)
@@ -52,4 +52,16 @@
        public int getSerializedSize() {
                return 4;
        }
+       
+       public boolean equals(Object c) {
+               if(c == null)
+                       return false;
+               if(c == this)
+                       return true;
+               if(c instanceof ConstCInt)
+                       return ((ConstCInt) c).getValue() == value;
+               if(c instanceof Integer)
+                       return ((Integer) c).intValue() == value;
+               return false;
+       }
 }

Modified: freeway/src/org/gnu/freeway/cwrappers/ConstCLongPtr.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCLongPtr.java    2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCLongPtr.java    2006-08-12 
15:45:04 UTC (rev 3219)
@@ -21,6 +21,7 @@
 
 import org.gnu.freeway.cwrappers.util.CWrapper;
 import org.gnu.freeway.cwrappers.util.ConstCWrapper;
+import java.nio.ByteOrder;
 
 /**
  * @file freeway/src/org/gnu/freeway/cwrappers/ConstCLong.java
@@ -42,7 +43,10 @@
         * Returns a byte array containing the long in big endian format
         */
        public byte[] serializeToByteArray() {
-               return new byte[] {(byte) (value >> 56), (byte) (value >> 48), 
(byte) (value >> 40), (byte) (value >> 32), (byte) (value >> 24), (byte) (value 
>> 16), (byte) (value >> 8), (byte) value};
+               if(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
+                       return new byte[] {(byte) (value >> 56), (byte) (value 
>> 48), (byte) (value >> 40), (byte) (value >> 32), (byte) (value >> 24), 
(byte) (value >> 16), (byte) (value >> 8), (byte) value};
+               else
+                       return new byte[] {(byte) (value), (byte) (value >> 8), 
(byte) (value >> 16), (byte) (value >> 24), (byte) (value >> 32), (byte) (value 
>> 40), (byte) (value >> 48), (byte) (value >> 56)};
        }
 
        public long getValue() {

Added: freeway/src/org/gnu/freeway/protocol/stats/CSGetMessageSupported.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/stats/CSGetMessageSupported.java       
2006-08-08 20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/protocol/stats/CSGetMessageSupported.java       
2006-08-12 15:45:04 UTC (rev 3219)
@@ -0,0 +1,81 @@
+/**
+ * @PROJECT_INFO@
+ */
+
+package org.gnu.freeway.protocol.stats;
+
+import org.gnu.freeway.util.net.*;
+
+import java.nio.*;
+
+/**
+ * Query protocol supported message. Contains the type of the message we are 
requesting the status of.
+ */
+
+public class CSGetMessageSupported extends CSMessage
+{
+       public static final int SIZE    =       8;
+
+       /** The type of the message we want to know the status of. */
+       private int     mType;
+       /** The handler type */
+       private int     hType;
+
+       public CSGetMessageSupported()
+       {
+               super(CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED);
+               mType = 0;
+               hType = 0;
+       }
+
+       public CSGetMessageSupported( int mtype, int htype )
+       {
+               this();
+               mType = mtype;
+               hType = htype;
+       }
+
+       public String toString()
+       {
+               return "CS get message supported [mType="+mType+" 
hType="+hType+"]";
+       }
+
+
+       
////////////////////////////////////////////////////////////////////////////////////////////////
+
+       public int getMType()
+       {
+               return mType;
+       }
+       
+       public int getHType()
+       {
+               return hType;
+       }
+
+       public int getByteSize()
+       {
+               return SIZE;
+       }
+
+       public void readBytes( ByteBuffer buf, ErrorReporter err )
+       {
+               int     reserved,size,type;
+
+               size=buf.getShort() & 0x0000ffff;
+               type=buf.getShort() & 0x0000ffff;
+               mType=buf.getShort() & 0x0000ffff;
+               hType=buf.getShort() & 0x0000ffff;
+
+               err.reportIf(size!=SIZE,"Bad size !");
+               
err.reportIf(type!=CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,"Bad type !");
+       }
+
+       public void writeBytes( ByteBuffer buf )
+       {
+               buf.putShort((short) SIZE);
+               buf.putShort((short) CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED);
+               buf.putShort((short) mType);
+               buf.putShort((short) hType);
+       }
+}

Modified: freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java       
2006-08-08 20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java       
2006-08-12 15:45:04 UTC (rev 3219)
@@ -19,39 +19,27 @@
 
 package org.gnu.freeway.protocol.stats;
 
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.util.logging.Level;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.ArrayList;
 
 import org.gnu.freeway.Server;
+import org.gnu.freeway.cwrappers.CInt;
+import org.gnu.freeway.cwrappers.CString;
+import org.gnu.freeway.protocol.AbstractProtocol;
 import org.gnu.freeway.protocol.Protocol;
-import org.gnu.freeway.server.CPluginLoader;
-import org.gnu.freeway.server.ClientExitHandler;
+import org.gnu.freeway.server.CoreAPI;
 import org.gnu.freeway.server.CoreForProtocol;
-import org.gnu.freeway.util.Prefs;
+import org.gnu.freeway.services.java.StatsService;
 import org.gnu.freeway.util.crypto.HostIdentity;
 import org.gnu.freeway.util.net.CSHandler;
 import org.gnu.freeway.util.net.CSMessage;
 import org.gnu.freeway.util.net.CSNativeMessage;
 import org.gnu.freeway.util.net.CSResult;
 import org.gnu.freeway.util.net.CSSession;
-import org.gnu.freeway.util.net.ErrorReporter;
-import org.gnu.freeway.util.net.NativeCSHandler;
 import org.gnu.freeway.util.net.P2PMessage;
 import org.gnu.freeway.util.net.P2PNativeMessage;
-import org.gnu.freeway.util.net.Persistent;
 import org.gnu.freeway.util.net.PersistentDecoder;
-import org.gnu.freeway.util.net.PersistentHelper;
-import org.gnu.freeway.protocol.AbstractProtocol;
-import org.gnu.freeway.protocol.chat.CSChatMessage;
-import org.gnu.freeway.protocol.tbench.CSBenchRequest;
-import org.gnu.freeway.server.CoreAPI;
-import org.gnu.freeway.services.java.StatsService;
-import org.gnu.freeway.cwrappers.*;
-import org.gnu.freeway.util.Scheduler;
 
 /**
  * @file StatsProtocol.java

Modified: freeway/src/org/gnu/freeway/server/CPluginLoader.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoader.java       2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/server/CPluginLoader.java       2006-08-12 
15:45:04 UTC (rev 3219)
@@ -21,6 +21,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -114,6 +115,9 @@
        
        private static native int cCallCSHandle(CoreAPI capi, long fptr, 
CSSession session, byte[] arr);
        private static native int cCallP2PHandle(CoreAPI capi, long fptr, 
byte[] identity, byte[] arr);
+       private static native void cCallPerNodeCallback(CoreAPI capi, long 
fptr, byte[] identity, long data);
+       private static native int cCallBufferFillCallback(CoreAPI capi, long 
fptr, byte[] receiver, byte[] buf);
+       private static native void cCallClientExitHandler(CoreAPI capi, long 
handle, CSSession client);
 
        /**
         * This method is used by the generated "services.impl"
@@ -124,14 +128,14 @@
         */
        public Handle loadService(String serviceName) {
                assert (serviceName != null);
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        return Handle.NULL;
                return new Handle(cLoadService(serviceName, CoreAPI._));
        }
        
        public int loadApplicationModule(String protocolName) {
                assert (protocolName != null);
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        return CoreAPI.SYSERR.getValue();
                long ptr = cLoadApplicationModule(protocolName, CoreAPI._);
                if(ptr == 0) {
@@ -149,7 +153,7 @@
        
        public int initUtil(String[] args) {
                assert(args != null);
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        return CoreAPI.SYSERR.getValue();
                return cInitUtil(args, CoreAPI._);
        }
@@ -168,7 +172,7 @@
                                    int offset,
                                    int functionType,
                                    Object[] arguments) {
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        throw new Error("Native code loading was not 
initialized!");
                return cCallC(modulePtr._, CoreAPI._, offset, functionType, 
arguments);
        }
@@ -181,14 +185,14 @@
         */
        public void unloadService(Handle modulePtr) {
                assert modulePtr != null;
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        return;
                cUnloadService(modulePtr._, CoreAPI._);
        }
        
        public void unloadApplicationModule(String protocolName) {
                assert protocolName != null;
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        return;
                Handle modulePtr = (Handle) protocols.get(protocolName);
                assert modulePtr != null;
@@ -215,7 +219,7 @@
        public boolean hasModule(String dsoprefix, String name) {
                assert dsoprefix != null;
                assert name != null;
-               if(!loaded)
+               if(!loaded || !CoreAPI._.isReady())
                        return false;
                return cHasModule(dsoprefix, name, CoreAPI._);
        }
@@ -269,4 +273,17 @@
        public boolean callP2PHandle(Handle handle, HostIdentity identity, 
P2PNativeMessage message) {
                return CoreAPI.OK.getValue() == cCallP2PHandle(CoreAPI._, 
handle._, PersistentHelper.toBytes(identity), message.arr);
        }
+
+       public void callPerNodeCallback(Handle handle, HostIdentity identity, 
Handle data) {
+               cCallPerNodeCallback(CoreAPI._, handle._, 
PersistentHelper.toBytes(identity), data != null ? data._ : 0);
+       }
+
+       public int callBufferFillCallback(Handle handle, HostIdentity receiver, 
ByteBuffer buf) {
+               return cCallBufferFillCallback(CoreAPI._, handle._, 
PersistentHelper.toBytes(receiver), buf.array());
+       }
+
+       public void callClientExitHandler(Handle handle, CSSession client) {
+               cCallClientExitHandler(CoreAPI._, handle._, client);
+       }
+
 }

Modified: freeway/src/org/gnu/freeway/server/ClientServer.java
===================================================================
--- freeway/src/org/gnu/freeway/server/ClientServer.java        2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/server/ClientServer.java        2006-08-12 
15:45:04 UTC (rev 3219)
@@ -280,14 +280,13 @@
                                return false;
                                }
 
-                       if (!(hd instanceof NativeCSHandler && 
handlers.get(type) instanceof NativeCSHandler && ((NativeCSHandler) 
handlers.get(type)).ptr._ == ((NativeCSHandler) hd).ptr._)&& 
handlers.get(type)!=hd) {
-                               log(Level.WARNING,"Another handler present at 
slot #"+type+".");
-                               return false;
-                               }
-
-                       handlers.set(type,null);
-                       return true;
+                       if (handlers.get(type)!=hd || (hd instanceof 
NativeCallback && ((NativeCallback) hd).equals(handlers.get(type)))) {
+                               handlers.set(type,null);
+                               return true;
                        }
+                       log(Level.WARNING,"Another handler present at slot 
#"+type+".");
+                       return false;
+                       }
        }
 
        public boolean registerClientExitHandler( ClientExitHandler hd )
@@ -301,13 +300,25 @@
        public boolean unregisterClientExitHandler( ClientExitHandler hd )
        {
                synchronized(exitHandlers) {
-                       if (!exitHandlers.contains(hd)) {
-                               log(Level.WARNING,"Client exit handler not 
found ("+hd+") !");
-                               return false;
+                       if (exitHandlers.contains(hd)) {
+                               exitHandlers.remove(hd);
+                               return true;
+                       }
+                       if(hd instanceof NativeCallback) {
+                               NativeCallback nc = (NativeCallback) hd;
+                               ClientExitHandler ceh = null;
+                               Iterator i = exitHandlers.iterator();
+                               while(i.hasNext()) {
+                                       ceh = (ClientExitHandler) i.next();
+                                       if(nc.equals(ceh)) {
+                                               i.remove();
+                                               return true;
+                                       }
                                }
-                       exitHandlers.remove(hd);
-                       return true;
                        }
+                       log(Level.WARNING,"Client exit handler not found 
("+hd+") !");
+                       return false;
+                       }
        }
 
 

Modified: freeway/src/org/gnu/freeway/server/ConnectionService.java
===================================================================
--- freeway/src/org/gnu/freeway/server/ConnectionService.java   2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/server/ConnectionService.java   2006-08-12 
15:45:04 UTC (rev 3219)
@@ -1917,12 +1917,15 @@
 
                synchronized(lock) {
                        for (i=0; i<sendCallbacks.length; i++) {
-                               if (sendCallbacks[i].callback==callback && 
sendCallbacks[i].minimumPadding==minimumPadding) {
+                               if ((sendCallbacks[i].callback==callback && 
sendCallbacks[i].minimumPadding==minimumPadding)
+                                               || (callback instanceof 
NativeCallback && ((NativeCallback) 
callback).equals(sendCallbacks[i].callback))) {
                                        
sendCallbacks[i]=sendCallbacks[sendCallbacks.length-1];
 
                                        old=sendCallbacks;
                                        sendCallbacks=new 
SendCallbackEntry[sendCallbacks.length-1];
-                                       
System.arraycopy(old,0,sendCallbacks,0,old.length-1);
+                                       
System.arraycopy(old,0,sendCallbacks,0,i);
+                                       if(i<old.length-1)
+                                               
System.arraycopy(old,i+1,sendCallbacks,i,old.length-i-1);
                                        return true;
                                        }
                                }

Modified: freeway/src/org/gnu/freeway/server/CoreAPI.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreAPI.java     2006-08-08 20:25:41 UTC 
(rev 3218)
+++ freeway/src/org/gnu/freeway/server/CoreAPI.java     2006-08-12 15:45:04 UTC 
(rev 3219)
@@ -20,17 +20,19 @@
 package org.gnu.freeway.server;
 
 import org.gnu.freeway.cwrappers.*;
+
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import org.gnu.freeway.Server;
+import org.gnu.freeway.transport.MessagePack;
+import org.gnu.freeway.transport.Session;
 import org.gnu.freeway.util.NativeService;
 import org.gnu.freeway.util.ServiceManager;
 import org.gnu.freeway.util.net.CSMessage;
 import org.gnu.freeway.util.net.CSNativeMessage;
 import org.gnu.freeway.util.net.CSResult;
 import org.gnu.freeway.util.net.CSSession;
-import org.gnu.freeway.util.net.NativeCSHandler;
-import org.gnu.freeway.util.net.NativeP2PHandler;
 import org.gnu.freeway.util.net.P2PNativeMessage;
 
 /**
@@ -43,6 +45,10 @@
        private CoreForTransport transportCore = null;
        private CoreService serviceCore = null;
        
+       public boolean isReady() {
+               return protocolCore != null && transportCore != null && 
serviceCore != null;
+       }
+       
        public void setProtocolCore(CoreForProtocol cfp) {
                if(protocolCore == null)
                        this.protocolCore = cfp;
@@ -67,7 +73,7 @@
        private final static String DSO_PREFIX = "libgnunet";
        
        public CUnsignedInt version;
-       public CPeerIdentity myIdentity;
+       public CHostIdentity myIdentity;
        
        private ArrayList shutdownList;
        
@@ -81,8 +87,7 @@
        }
        
        private String getConfigurationString(String section, String option) {
-               return null;
-               //TODO: write this and put it where it belongs
+               return 
serviceCore.getApplication().getPreferences().getString(section, option, null);
        }
        
        public CPluginLoader.Handle requestService(CString iname) {
@@ -111,44 +116,46 @@
                return OK;
        }
        
-       public CInt sendPlaintext(CTSession session, CString msg, CUnsignedInt 
size) {
-               return SYSERR;
+       public CInt sendPlaintext(Session session, CString msg, CUnsignedInt 
size) {
+               return SYSERR; //TODO
        }
        
-       public void unicast(ConstCPeerIdentity receiver, ConstCP2PMessageHeader 
msg, CUnsignedInt importance, CUnsignedInt maxdelay) {
-               
+       public void unicast(CHostIdentity receiver, P2PNativeMessage msg, CInt 
importance, CInt maxdelay) {
+               protocolCore.sendToNode(receiver.getValue(), msg, 
importance.getValue(), maxdelay.getValue());
        }
        
-       public void unicastCallback(ConstCPeerIdentity receiver, 
CBuildMessageCallback callback, CPluginLoader.Handle closure) {
-               
+       public void unicastCallback(CHostIdentity receiver, 
CPluginLoader.Handle callback, CPluginLoader.Handle closure) {
+               // TODO later
        }
        
        public CInt forAllConnectedNodes(CPluginLoader.Handle method, 
CPluginLoader.Handle arg) {
-               return new CInt(protocolCore.forAllConnectedNodes(null, null));
+               return new CInt(protocolCore.forAllConnectedNodes(new 
NativeCallback(method), arg));
        }
        
-       public CInt registerSendCallback(ConstCUnsignedInt minimumPadding, 
CBufferFillCallback callback) {
-               return SYSERR;
+       public CInt registerSendCallback(ConstCInt minimumPadding, 
CPluginLoader.Handle callback) {
+               return 
protocolCore.registerSendCallback(minimumPadding.getValue(), new 
NativeCallback(callback)) ? OK : SYSERR;
        }
        
-       public CInt unregisterSendCallback(ConstCUnsignedInt minimumPadding, 
CBufferFillCallback callback) {
-               return SYSERR;
+       public CInt unregisterSendCallback(ConstCInt minimumPadding, 
CPluginLoader.Handle callback) {
+               return 
protocolCore.unregisterSendCallback(minimumPadding.getValue(), new 
NativeCallback(callback)) ? OK : SYSERR;
        }
        
-       public CInt registerSendNotify(CMessagePartHandler callback) {
+       public CInt registerSendNotify(CPluginLoader.Handle callback) {
+               //FIXME not in Freeway?
                return SYSERR;
        }
        
-       public CInt unregisterSendNotify(CMessagePartHandler callback) {
+       public CInt unregisterSendNotify(CPluginLoader.Handle callback) {
+//             FIXME not in Freeway?
                return SYSERR;
        }
        
        public CInt registerHandler(CInt type, CPluginLoader.Handle callback) {
-               return ((Server) 
protocolCore.getApplication()).getDispatcher().registerP2PHandler(type.getValue(),
 P2PNativeMessage.class, new NativeP2PHandler(callback)) ? CoreAPI.OK : 
CoreAPI.SYSERR;
+               return ((Server) 
protocolCore.getApplication()).getDispatcher().registerP2PHandler(type.getValue(),
 P2PNativeMessage.class, new NativeCallback(callback)) ? CoreAPI.OK : 
CoreAPI.SYSERR;
        }
        
        public CInt unregisterHandler(CInt type, CPluginLoader.Handle callback) 
{
-               return ((Server) 
protocolCore.getApplication()).getDispatcher().unregisterP2PHandler(type.getValue(),
 new NativeP2PHandler(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
+               return ((Server) 
protocolCore.getApplication()).getDispatcher().unregisterP2PHandler(type.getValue(),
 new NativeCallback(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
        }
        
        public CInt isHandlerRegistered(CInt type, CInt handlerType) {
@@ -164,39 +171,41 @@
        }
        
        public CInt registerPlainTextHandler(CInt type, CPluginLoader.Handle 
callback) {
-               return ((Server) 
protocolCore.getApplication()).getDispatcher().registerPlaintextHandler(type.getValue(),
 P2PNativeMessage.class, new NativeP2PHandler(callback)) ? CoreAPI.OK : 
CoreAPI.SYSERR;
+               return ((Server) 
protocolCore.getApplication()).getDispatcher().registerPlaintextHandler(type.getValue(),
 P2PNativeMessage.class, new NativeCallback(callback)) ? CoreAPI.OK : 
CoreAPI.SYSERR;
        }
        
        public CInt unregisterPlaintextHandler(CInt type, CPluginLoader.Handle 
callback) {
-               return ((Server) 
protocolCore.getApplication()).getDispatcher().unregisterPlaintextHandler(type.getValue(),
 new NativeP2PHandler(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
+               return ((Server) 
protocolCore.getApplication()).getDispatcher().unregisterPlaintextHandler(type.getValue(),
 new NativeCallback(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
        }
        
-       public void offerTSessionFor(ConstCPeerIdentity peer, CTSession 
session) {
-               
-       }
+       /*public void offerTSessionFor(ConstCPeerIdentity peer, CTSession 
session) {
+               //internal
+               throw new Error("not implemented");
+       }*/
        
-       public void assignSessionKey(ConstCSessionKey key, ConstCPeerIdentity 
peer, CTime_T age, CInt forSending) {
-               
-       }
+       /*public void assignSessionKey(ConstCSessionKey key, ConstCPeerIdentity 
peer, CTime_T age, CInt forSending) {
+               //internal
+               throw new Error("not implemented");
+       }*/
        
-       public CInt getCurrentSessionKey(ConstCPeerIdentity peer, CSessionKey 
key, CTime_TPtr age, CInt forSending) {
-               return SYSERR;
-       }
+       /*public CInt getCurrentSessionKey(ConstCPeerIdentity peer, CSessionKey 
key, CTime_TPtr age, CInt forSending) {
+               //internal
+       }*/
        
-       public void confirmSessionUp(ConstCPeerIdentity peer) {
-               
-       }
+       /*public void confirmSessionUp(ConstCPeerIdentity peer) {
+               // internal
+       }*/
        
-       public void preferTrafficFrom(ConstCPeerIdentity node, CDouble 
preference) {
-               
-       }
+       /*public void preferTrafficFrom(ConstCPeerIdentity node, CDouble 
preference) {
+               //internal
+       }*/
        
-       public CUnsignedInt queryBPMfromPeer(ConstCPeerIdentity node) {
-               return new CUnsignedInt(SYSERR.getValue());
+       public CUnsignedInt queryBPMfromPeer(CHostIdentity node) {
+               return new 
CUnsignedInt(protocolCore.queryBPMfromPeer(node.getValue()));
        }
        
-       public void disconnectFromPeer(ConstCPeerIdentity peer) {
-               
+       public void disconnectFromPeer(CHostIdentity peer) {
+               protocolCore.disconnectFromPeer(peer.getValue());
        }
        
        public CInt sendValueToClient(CSSession handle, CInt value) {
@@ -209,48 +218,49 @@
        
        public CInt registerClientHandler(CInt type, CPluginLoader.Handle 
callback) {
                CPluginLoader._.registerDecoder(type.getValue());
-               return ((Server) 
protocolCore.getApplication()).registerCSHandler(type.getValue(), 
CSMessage.class, new NativeCSHandler(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
+               return ((Server) 
protocolCore.getApplication()).registerCSHandler(type.getValue(), 
CSMessage.class, new NativeCallback(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
        }
        
        public CInt unregisterClientHandler(CInt type, CPluginLoader.Handle 
callback) {
                CPluginLoader._.unregisterDecoder(type.getValue());
-               return ((Server) 
protocolCore.getApplication()).unregisterCSHandler(type.getValue(), new 
NativeCSHandler(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
+               return ((Server) 
protocolCore.getApplication()).unregisterCSHandler(type.getValue(), new 
NativeCallback(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
        }
        
-       public CInt registerClientExitHandler(CClientExitHandler callback) {
-               return SYSERR;
+       public CInt registerClientExitHandler(CPluginLoader.Handle callback) {
+               return ((Server) 
protocolCore.getApplication()).registerCSExitHandler(new 
NativeCallback(callback)) ? OK : SYSERR;
        }
        
-       public CInt unregisterClientExitHandler(CClientExitHandler callback) {
-               return SYSERR;
+       public CInt unregisterClientExitHandler(CPluginLoader.Handle callback) {
+               return ((Server) 
protocolCore.getApplication()).unregisterCSExitHandler(new 
NativeCallback(callback)) ? OK : SYSERR;
        }
        
-       public void terminateClientConnection(CClientHandle handle) {
-               
+       public void terminateClientConnection(CSSession handle) {
+               handle.disconnect();
        }
        
-       public void injectMessage(ConstCPeerIdentity sender, ConstCString msg, 
CUnsignedInt size, CInt wasEncrypted, CTSession session) {
-               
+       public void injectMessage(CHostIdentity sender, byte[] msg, CInt size, 
CInt wasEncrypted, Session session) {
+               ((Server) 
protocolCore.getApplication()).getDispatcher().injectMessage(sender.getValue(), 
ByteBuffer.wrap(msg), size.getValue(), YES.equals(wasEncrypted), session);
        }
        
-       public CUnsignedInt computeIndex(ConstCPeerIdentity hostId) {
-               return new CUnsignedInt(0);
+       public CUnsignedInt computeIndex(CHostIdentity hostId) {
+               return new CUnsignedInt(hostId.getValue().hashCode());
        }
        
-       public CMutexPtr getConnectionModuleLock() {
-               return new CMutexPtr();
+       public CPluginLoader.Handle getConnectionModuleLock() {
+               return CPluginLoader.Handle.NULL; //TODO ???
        }
        
        public CInt getSlotCount() {
-               return new CInt(0);
+               return new CInt(0); // TODO
        }
        
        public CInt isSlotUsed(CInt slot) {
-               return new CInt(0);
+               return new CInt(0); //TODO
        }
        
-       public CInt getLastActivityOf(ConstCPeerIdentity peer, CCron_TPtr time) 
{
-               return SYSERR;
+       public CInt getLastActivityOf(CHostIdentity peer, CLongPtr time) {
+               time.setValue(0); //TODO
+               return OK;
        }
        
        
@@ -258,95 +268,4 @@
        private CoreAPI() {
                shutdownList = new ArrayList();
        }
-       
-       private class CPeerIdentity {
-               //TODO: write CPeerIdentity
-       }
-       
-       private class ConstCPeerIdentity {
-               //TODO: write CConstPeerIdentity
-       }
-       
-       private class CTSession {
-               //TODO: write CTSession
-       }
-       
-       private class CP2PMessageHeader {
-               //TODO: write CP2PMessageHeader
-       }
-       
-       private class ConstCP2PMessageHeader {
-               //TODO: write CP2PMessageHeader
-       }
-       
-       private class CBuildMessageCallback {
-               //TODO: write CBuildMessageCallback
-       }
-       
-       private class CPerNodeCallback {
-               //TODO: write CPerNodeCallback
-       }
-       
-       private class CBufferFillCallback {
-               //TODO: write CPerNodeCallback
-       }
-       
-       private class CMessagePartHandler {
-               //TODO: write this
-       }
-       
-       private class CUnsignedShort {
-               //TODO: write this
-       }
-       
-       private class CMutexPtr {
-               //TODO: write this
-               public CMutexPtr() {
-                       
-               }
-       }
-       
-       private class CCron_TPtr {
-               //TODO: write this
-       }
-       
-       private class CClientHandle {
-               //TODO: write this
-       }
-       
-       private class CClientExitHandler {
-               //TODO: write this
-       }
-       
-       private class CCSHandler {
-               //TODO: write this
-       }
-       
-       private class CSendToClientCallback {
-               //TODO: write this
-       }
-       
-       private class CDouble {
-               //TODO: write this
-       }
-       
-       private class CTime_TPtr {
-               //TODO: write this
-       }
-       
-       private class CSessionKey {
-               //TODO: write this
-       }
-       
-       private class ConstCSessionKey {
-               //TODO: write this
-       }
-       
-       private class CTime_T {
-               //TODO: write this
-       }
-       
-       private class CPlaintextMessagePartHandler {
-               //TODO: write this
-       }
 }

Modified: freeway/src/org/gnu/freeway/server/MessagesDispatcher.java
===================================================================
--- freeway/src/org/gnu/freeway/server/MessagesDispatcher.java  2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/server/MessagesDispatcher.java  2006-08-12 
15:45:04 UTC (rev 3219)
@@ -296,6 +296,44 @@
        }
 
 
+       public void injectMessage(HostIdentity sender, ByteBuffer buf, int 
size, boolean wasEncrypted, Session tsession) {
+               PersistentReader        queue;
+               P2PMessage              p;
+               P2PHandler      handler;
+               boolean cont;
+               TrafficService  traffic;
+
+               cont=true;
+
+               queue=new PersistentReader(buf);
+               while (queue.canConsume() && cont) {
+                       p=(P2PMessage) queue.consume(wasEncrypted ? decoder : 
plaintextDecoder);
+                       if (p==null) {
+                               continue;
+                               }
+
+                       // one call for all types...
+                       traffic=(TrafficService) 
application.service(TrafficService.class);
+                       traffic.updateTrafficReceiveCounter(p);
+
+                       handler=getP2PHandler(p.getType(), wasEncrypted);
+                       if (handler!=null) {
+                               if(!handler.handle(tsession,p,wasEncrypted)) {
+                                       break;
+                                       }
+                               }
+                       else {
+                               log(Level.WARNING,"Unsupported *injected* 
message : "+p);
+                               }
+                       }
+
+               if (queue.getNotConsumed()>0) {
+                       trace("Not all bytes have been consumed, data 
corruption ?");
+                       }
+
+               queue.clear();
+       }
+       
        
////////////////////////////////////////////////////////////////////////////////////////////////
 
        /**
@@ -374,7 +412,7 @@
 
                synchronized(handlers) {
                        if (type<handlers.length) {
-                               if (handlers[type]!=handler) {
+                               if (handlers[type]!=handler && !(handler 
instanceof NativeCallback && ((NativeCallback) 
handler).equals(handlers[type]))) {
                                        return false;
                                        }
 
@@ -439,7 +477,7 @@
 
                synchronized(plaintextHandlers) {
                        if (type<plaintextHandlers.length) {
-                               if (plaintextHandlers[type]!=handler) {
+                               if (plaintextHandlers[type]!=handler && 
!(handler instanceof NativeCallback && ((NativeCallback) 
handler).equals(plaintextHandlers[type]))) {
                                        return false;
                                        }
 

Added: freeway/src/org/gnu/freeway/server/NativeCallback.java
===================================================================
--- freeway/src/org/gnu/freeway/server/NativeCallback.java      2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/server/NativeCallback.java      2006-08-12 
15:45:04 UTC (rev 3219)
@@ -0,0 +1,90 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.server;
+
+import java.nio.ByteBuffer;
+
+import org.gnu.freeway.transport.Session;
+import org.gnu.freeway.util.crypto.HostIdentity;
+import org.gnu.freeway.util.net.CSHandler;
+import org.gnu.freeway.util.net.CSMessage;
+import org.gnu.freeway.util.net.CSNativeMessage;
+import org.gnu.freeway.util.net.CSSession;
+import org.gnu.freeway.util.net.P2PHandler;
+import org.gnu.freeway.util.net.P2PMessage;
+import org.gnu.freeway.util.net.P2PNativeMessage;
+
+/**
+ * @file NativeBufferFillCallback.java
+ * @brief 
+ * @author mdonoughe
+ */
+public class NativeCallback implements BufferFillCallback, PerNodeCallback, 
ClientExitHandler, CSHandler, P2PHandler {
+
+       private CPluginLoader.Handle handle;
+       
+       public NativeCallback(CPluginLoader.Handle handle) {
+               this.handle = handle;
+       }
+       
+       public boolean equals(Object c) {
+               if(c == null || !(c instanceof NativeCallback) || ( 
((NativeCallback) c).handle == null && this.handle != null ) || 
((NativeCallback) c).handle._ != this.handle._)
+                       return false;
+               return true;
+       }
+       
+       //BufferFillCallback
+       public boolean fillBuffer(HostIdentity receiver, ByteBuffer buf) {
+               if(handle == null || handle._ == 0)
+                       return false;
+               return CPluginLoader._.callBufferFillCallback(handle, receiver, 
buf) == CoreAPI.OK.getValue() ? true : false;
+       }
+       
+       //PerNodeCallback
+       public void callback(HostIdentity identity, Object data) {
+               assert data == null || data instanceof CPluginLoader.Handle;
+               if(handle == null || handle._ == 0)
+                       return;
+               CPluginLoader._.callPerNodeCallback(handle, identity, 
(CPluginLoader.Handle) data);
+       }
+
+       //ClientExitHandler
+       public void handle(CSSession client) {
+               if(handle == null || handle._ == 0)
+                       return;
+               CPluginLoader._.callClientExitHandler(handle, client);
+       }
+       
+       //CSHandler
+       public boolean handle(CSSession session, CSMessage message) {
+               assert(message instanceof CSNativeMessage);
+               if(handle == null || handle._ == 0)
+                       return false;
+               return CPluginLoader._.callCSHandle(handle, session, 
(CSNativeMessage) message);
+       }
+       
+       //P2PHandler
+       public boolean handle(Session session, P2PMessage message, boolean 
encrypted) {
+               assert(message instanceof P2PNativeMessage);
+               if(handle == null || handle._ == 0)
+                       return false;
+               return CPluginLoader._.callP2PHandle(handle, 
session.getRemote(), (P2PNativeMessage) message);
+       }
+}

Modified: freeway/src/org/gnu/freeway/util/OutputFilter.java
===================================================================
--- freeway/src/org/gnu/freeway/util/OutputFilter.java  2006-08-08 20:25:41 UTC 
(rev 3218)
+++ freeway/src/org/gnu/freeway/util/OutputFilter.java  2006-08-12 15:45:04 UTC 
(rev 3219)
@@ -42,17 +42,16 @@
 
        public Iterator filter( String cmd )
        {
-               Process p;
+               Process p = null;
 
                debug(Level.INFO,"Process : "+cmd);
 
                try {
                        p=Runtime.getRuntime().exec(cmd);
                        return filter(new 
InputStreamReader(p.getInputStream()),true);
-                       }
-               catch( IOException x ) {
+               } catch( IOException x ) {
                        err("I/O exception !",x);
-                       }
+               }
                return null;
        }
 

Modified: freeway/src/org/gnu/freeway/util/Prefs.java
===================================================================
--- freeway/src/org/gnu/freeway/util/Prefs.java 2006-08-08 20:25:41 UTC (rev 
3218)
+++ freeway/src/org/gnu/freeway/util/Prefs.java 2006-08-12 15:45:04 UTC (rev 
3219)
@@ -558,7 +558,7 @@
                assert(section!=null && option!=null);
 
                str=getString(section,option,null);
-               return (str!=null ? new FileLocation(str) : null);
+               return (str!=null && !"".equals(str) ? new FileLocation(str) : 
null);
        }
 
        public String[] getArray( String section, String option )

Modified: freeway/src/org/gnu/freeway/util/Statistics.java
===================================================================
--- freeway/src/org/gnu/freeway/util/Statistics.java    2006-08-08 20:25:41 UTC 
(rev 3218)
+++ freeway/src/org/gnu/freeway/util/Statistics.java    2006-08-12 15:45:04 UTC 
(rev 3219)
@@ -45,70 +45,4 @@
        {
                return new Stat(name);
        }
-
-       /**
-        * Create statistics message(s) to be sent over a TCP socket.
-        * May create multiple messages if the overall size would be too big.
-        * @param minLevel
-        * @return
-        */
-
-       /*public CSStatistics[] createMessages( int minLevel )
-       {
-               List                            list;
-               CSStatistics            msg;
-               Stat            stat;
-               int                             total,i;
-
-               lockAll();
-
-               list=new ArrayList();
-
-               for (i=total=0; i<stats.size(); i++) {
-                       stat=(Stat) stats.get(i++);
-                       if (stat.getLevel()>=minLevel) {
-                               total++;
-                               }
-                       }
-
-               i=0;
-               while (i<stats.size()) {
-                       msg=new CSStatistics((int) 
Scheduler.toSeconds(startTime));
-                       msg.setTotalCounters(total);
-
-                       // how many statistic numbers and their descriptions we 
can send in one message ?
-                       while (i<stats.size() && 
msg.getByteSize()<CSMessage.MAX_MESSAGE_SIZE) {
-                               stat=(Stat) stats.get(i++);
-                               if (stat.getLevel()>=minLevel) {
-                                       msg.add(stat);
-                                       }
-                               }
-
-                       if (msg.getByteSize()>=CSMessage.MAX_MESSAGE_SIZE) {
-                               msg.removeLast();
-                               i--;
-                               }
-
-                       list.add(msg);
-                       }
-
-               unlockAll();
-
-               return (CSStatistics[]) list.toArray(new 
CSStatistics[list.size()]);
-       } */
-
-       /*public void dump()
-       {
-               int     i;
-
-               lockAll();
-
-               System.out.println("Statistics service started at 
"+Utils.formatMoment(startTime));
-               System.out.println("Handles count : "+stats.size());
-               for (i=0; i<stats.size(); i++) {
-                       ((Stat) stats.get(i)).dump();
-                       }
-
-               unlockAll();
-       }*/
 }

Added: freeway/src/org/gnu/freeway/util/crypto/HashCode512.java
===================================================================
--- freeway/src/org/gnu/freeway/util/crypto/HashCode512.java    2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/util/crypto/HashCode512.java    2006-08-12 
15:45:04 UTC (rev 3219)
@@ -0,0 +1,461 @@
+/*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.util.crypto;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.security.GeneralSecurityException;
+import java.security.MessageDigest;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.gnu.freeway.util.io.FileLocation;
+import org.gnu.freeway.util.io.MappedFile;
+import org.gnu.freeway.util.net.ErrorReporter;
+import org.gnu.freeway.util.net.Persistent;
+
+/**
+ * @file HashCode512.java
+ * @brief A SHA-512 hash
+ */
+
+public class HashCode512 extends Object implements Persistent
+{
+       private static final char[]     HEX_DIGITS      =       {
+               '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 
'C', 'D', 'E', 'F'
+               };
+       
+       private static final byte[] ENCTABLE = {'0', '1', '2', '3', '4', '5', 
'6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V'};
+
+       public static final int SIZE    =       64;
+
+       //16 ints
+       private int hash[];
+
+
+       public HashCode512()
+       {
+               hash = new int[16];
+       }
+
+       public HashCode512( HashCode512 h )
+       {
+               hash = new int[16];
+               System.arraycopy(h.hash, 0, hash, 0, 16);
+       }
+
+       public HashCode512( int[] hash )
+       {
+               assert hash.length == 16;
+               this.hash = hash;
+       }
+
+       public String toString()
+       {
+               return "HashCode 512bits [toHex="+toHex()+"]";
+       }
+
+
+       
////////////////////////////////////////////////////////////////////////////////////////////////
+
+       public int hashCode()
+       {
+               return hash.hashCode();
+       }
+
+       public boolean equals( Object obj )
+       {
+               HashCode512     h;
+
+               if (!(obj instanceof HashCode512)) {
+                       return false;
+                       }
+               h=(HashCode512) obj;
+               return (hash.equals(h.hash));
+       }
+       
+       /**
+        * Compute the distance with the given hashcode <code>h</code>.
+        * The computation must be fast, not involve a.a or a.e (they're used 
elsewhere), and be somewhat consistent.
+        * And of course, the result should be a positive number.
+        *
+        * @param h     hashcode the distance will be computed with
+        * @return      a positive number which is a measure for hashcode 
proximity.
+        */
+
+       public int distance( HashCode512 h )
+       {
+               int x = (hash[1] - h.hash[1])>>16;
+               return ((x*x)>>16);
+       }
+
+       /**
+        * compute result(b) = a + delta
+        * @param h     hashcode to add
+        */
+
+       public void add( HashCode512 h )
+       {
+               for(int i = 0; i <= Math.min(hash.length, h.hash.length); i++)
+                       hash[i]+=h.hash[i];
+       }
+
+       /**
+        * compute result(delta) = b - a
+        * @param h     hashcode to substract
+        */
+
+       public void sub( HashCode512 h )
+       {
+               for(int i = 0; i <= Math.min(hash.length, h.hash.length); i++)
+                       hash[i]-=h.hash[i];
+       }
+
+       /**
+        * compute result = a ^ b
+        * @param h
+        */
+
+       public void xor( HashCode512 h )
+       {
+               for(int i = 0; i <= Math.min(hash.length, h.hash.length); i++)
+                       hash[i]^=h.hash[i];
+       }
+
+       /**
+        * Convert a hashcode into a key.
+        * @param iv
+        * @return
+        */
+
+       public SessionKey extractKey( byte[] iv )
+       {
+               byte[]  buf;
+               int             i;
+
+               buf=new byte[16];
+               for (i=0; i<4; i++) {
+                       buf[i*4]=(byte) ((hash[i]>>24) & 0x000000ff);
+                       buf[i*4+1]=(byte) ((hash[i]>>16) & 0x000000ff);
+                       buf[i*4+2]=(byte) ((hash[i]>>8) & 0x000000ff);
+                       buf[i*4+3]=(byte) (hash[i] & 0x000000ff);
+                       }
+
+               if (iv!=null) {
+                       iv[0]=iv[4]=(byte) ((hash[5]>>24) & 0x000000ff);
+                       iv[1]=iv[5]=(byte) ((hash[5]>>16) & 0x000000ff);
+                       iv[2]=iv[6]=(byte) ((hash[5]>>8) & 0x000000ff);
+                       iv[3]=iv[7]=(byte) (hash[5] & 0x000000ff);
+                       }
+               return new SessionKey(buf);
+       }
+
+       /**
+        * Convert (hash) block to hex
+        * @return
+        */
+
+       public String toHex()
+       {
+               StringBuffer    buf;
+               int                             i,n;
+
+               buf=new StringBuffer();
+               for (i=0; i<64; i++) {
+                       // use each index 4 times
+                       // shift 3 - (i mod 4) bytes off
+                       n = (hash[i >> 2]>>((3 - (i & 3)) * 8) & 0xff);
+                       buf.append(HEX_DIGITS[n & 0x0000000f]);         // get 
lower nibble
+                       buf.append(HEX_DIGITS[n>>4]);   // get higher nibble
+                       }
+               return buf.toString();
+       }
+
+       public int getByteSize()
+       {
+               return SIZE;
+       }
+
+       public void readBytes( ByteBuffer buf, ErrorReporter err )
+       {
+               for(int i = 0; i < hash.length; i++)
+                       hash[i]=buf.getInt();
+       }
+
+       public void writeBytes( ByteBuffer buf )
+       {
+               for(int i = 0; i < hash.length; i++)
+                       buf.putInt(hash[i]);
+       }
+
+
+       
////////////////////////////////////////////////////////////////////////////////////////////////
+
+       /**
+        * Generate a random hashcode.
+        * @return
+        */
+
+       public static HashCode512 random()
+       {
+               HashCode512     h;
+
+               h=new HashCode512();
+               for(int i = 0; i < h.hash.length; i++)
+                       h.hash[i] = Crypto.nextInt();
+               return h;
+       }
+
+       public static HashCode512 create( String str )
+       {
+               return create(str.getBytes());
+       }
+
+       public static HashCode512 create( byte[] block )
+       {
+               return create(block,0,block.length);
+       }
+
+       /**
+        * Hash block of given size.
+        *
+        * @param block the data to hash
+        * @param offset offset
+        * @param size the length of the data to hash
+        * @return
+        */
+
+       public static HashCode512 create( byte[] block, int offset, int size )
+       {
+               MessageDigest   md;
+               HashCode512             h;
+               Logger                  logger;
+
+               try {
+                       md=MessageDigest.getInstance("SHA-512");
+                       md.update(block,offset,size);
+                       h=fromBytes(md.digest());
+                       }
+               catch( GeneralSecurityException x ) {
+                       x.printStackTrace();
+                       logger=Logger.getLogger(HashCode512.class.getName());
+                       logger.log(Level.SEVERE,"Could not compute digest of 
message !",x);
+                       h=null;
+                       }
+               catch( Throwable x ) {
+                       x.printStackTrace();
+                       // catch *all* other exceptions, whatever they are
+                       logger=Logger.getLogger(HashCode512.class.getName());
+                       logger.log(Level.SEVERE,"Could not compute digest of 
message (unexpected exception) !",x);
+                       h=null;
+                       }
+               return h;
+       }
+
+       /**
+        * Compute the hash of an entire file. Does <em>not</em> load the 
entire file
+        * into memory but instead processes it in blocks. Very important for 
large files.
+        *
+        * @param f     the file to hash
+        *
+        * @return      the computed hashcode on success, null on error
+        */
+
+       public static HashCode512 create( FileLocation f )
+       {
+               byte[]                  b;
+               MessageDigest   md;
+               MappedFile              file;
+               HashCode512             h;
+               Logger                  logger;
+               long                            size,pos;
+               int                             len;
+
+               logger=Logger.getLogger(HashCode512.class.getName());
+
+               if (!f.exists()) {
+                       return null;
+                       }
+
+               try {
+                       md=MessageDigest.getInstance("SHA-512");
+
+                       b=new byte[65536];
+
+                       size=f.getSize();
+
+                       file=f.open();
+                       try {
+                               for (pos=0; pos<size; pos+=len) {
+                                       len=(int) Math.min(b.length,size-pos);
+
+                                       if (!file.readBytes(b,0,len)) {
+                                               logger.log(Level.SEVERE,"Could 
not compute digest of file \""+f.getLabel()+"\", failed to read bytes !");
+                                               return null;
+                                               }
+                                       md.update(b,0,len);
+                                       }
+                               }
+                       finally {
+                               file.close();
+                               }
+
+                       h=fromBytes(md.digest());
+                       }
+               catch( GeneralSecurityException x ) {
+                       logger.log(Level.SEVERE,"Could not compute digest of 
file \""+f.getLabel()+"\" !",x);
+                       h=null;
+                       }
+               catch( Throwable x ) {
+                       // catch *all* other exceptions, whatever they are
+                       logger.log(Level.SEVERE,"Could not compute digest of 
file \""+f.getLabel()+"\" (unexpected exception) !",x);
+                       h=null;
+                       }
+               return h;
+       }
+
+       private static HashCode512 fromBytes( byte[] b )
+       {
+               HashCode512     h;
+               int                     i,j,k,n;
+
+               h=new HashCode512();
+
+               k=0;
+               for (j=0; j<16; j++) {
+                       n=0;
+                       for (i=0; i<4; i++) {
+                               n<<=8;
+                               n|=(b[k++] & 0x000000ff);
+                               }
+                       h.hash[j] = n;
+                       }
+               return h;
+       }
+
+       /**
+        * Convert hex to the hostIdentity
+        * @param hex the filename
+        * @return
+        */
+
+       public static HashCode512 parse( String hex )
+       {
+               HashCode512     h;
+               int                     i,j,n;
+               char            c;
+
+               if (hex==null || !hex.matches("[0-9A-Za-z]{128}")) {
+                       return null;
+                       }
+
+               h=new HashCode512();
+               for (i=0; i<16; i++) {
+                       n=0;
+                       for (j=0; j<8; j++) {
+                               n<<=4;
+
+                               c=hex.charAt(i*8+j+((j & 1)==0 ? 1 : -1));      
// take care of reversed nibble ( 0xA7 -> 0x7, 0xA )
+                               if (c>='a' && c<='f') {
+                                       n+=c-'a'+10;
+                                       }
+                               else if (c>='A' && c<='F') {
+                                       n+=c-'A'+10;
+                                       }
+                               else {
+                                       n+=c-'0';
+                                       }
+                               }
+
+                       h.hash[i] = n;
+                       }
+               return h;
+       }
+       
+       public String encode() {
+               int wpos = 0, rpos = 0, bits = 0, vbit = 0;
+               byte[] encoding = new byte[103];
+               while(rpos < 64 || vbit > 0) {
+                       if(rpos < 64 && vbit < 5) {
+                               bits = (bits << 8) | (hash[rpos >> 2] >> ((3 - 
(rpos++ & 3)) * 8) & 0xff);
+                               vbit += 8;
+                       }
+                       if(vbit < 5) {
+                               bits = bits << (5 - vbit);
+                               assert vbit == 2;
+                               vbit = 5;
+                       }
+                       assert wpos < 103;
+                       encoding[wpos++] = ENCTABLE[(bits >> (vbit -5)) & 31];
+                       vbit -= 5;
+               }
+               assert wpos == 103;
+               assert vbit == 0;
+               return new String(encoding);
+       }
+       
+       private static int getValue(byte a) {
+               if((a >= '0') && (a <= '9'))
+                       return a - '0';
+               if((a >= 'A') && (a <= 'V'))
+                       return a - 'A' + 10;
+               return -1;
+       }
+       
+       public static HashCode512 decode(String encstr) {
+               int rpos, wpos, bits, vbit;
+               byte[] enc;
+               HashCode512 h;
+               
+               try {
+                       enc = encstr.getBytes("UTF-8");
+               } catch (UnsupportedEncodingException e) {
+                       throw new Error(e);
+               }
+               
+               if(enc.length != 103)
+                       throw new IllegalArgumentException();
+               
+               vbit = 2;
+               wpos = 64;
+               rpos = 103;
+               bits = getValue(enc[--rpos]) >> 3;
+               h = new HashCode512();
+               while(wpos > 0) {
+                       assert rpos > 0;
+                       bits = (getValue(enc[--rpos]) << vbit) | bits;
+                       vbit += 5;
+                       if(vbit >= 8) {
+                               h.hash[--wpos >> 2] |= (bits & 0xff) << ((wpos 
& 3) * 8);
+                               bits = bits >> 8;
+                               vbit -= 8;
+                       }
+               }
+               assert rpos == 0;
+               assert vbit == 0;
+               return h;
+       }
+       
+       public int getInt(int index) {
+               assert index >= 0;
+               assert index < hash.length;
+               return hash[index];
+       }
+}

Modified: freeway/src/org/gnu/freeway/util/io/DirLocation.java
===================================================================
--- freeway/src/org/gnu/freeway/util/io/DirLocation.java        2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/util/io/DirLocation.java        2006-08-12 
15:45:04 UTC (rev 3219)
@@ -90,7 +90,7 @@
        public boolean create()
        {
                if (file.exists() && !file.isDirectory()) {
-                       file.delete();
+                       return false;
                        }
                if (!file.exists()) {
                        return file.mkdirs();

Modified: freeway/src/org/gnu/freeway/util/io/FileLocation.java
===================================================================
--- freeway/src/org/gnu/freeway/util/io/FileLocation.java       2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/util/io/FileLocation.java       2006-08-12 
15:45:04 UTC (rev 3219)
@@ -60,9 +60,7 @@
                                        }
                                }
                        else if (file.isDirectory()) {
-                               if (!new DirLocation(file.getPath()).delete()) {
-                                       return false;
-                                       }
+                               return false;
                                }
                        }
                else if (!getParent().create()) {

Modified: freeway/src/org/gnu/freeway/util/net/CSMessage.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/CSMessage.java 2006-08-08 20:25:41 UTC 
(rev 3218)
+++ freeway/src/org/gnu/freeway/util/net/CSMessage.java 2006-08-12 15:45:04 UTC 
(rev 3219)
@@ -5,12 +5,13 @@
 package org.gnu.freeway.util.net;
 
 import java.util.*;
+import java.nio.ByteBuffer;
 
 /**
  * Client-Server message.
  */
 
-public abstract class CSMessage extends Object implements Persistent
+public class CSMessage extends Object implements Persistent
 {
        /** Maximum size of a message. */
        public static final int MAX_MESSAGE_SIZE                        =       
65536;
@@ -188,11 +189,17 @@
        private int     type;
 
 
-       protected CSMessage( int t )
+       public CSMessage( int t )
        {
                super();
                type=t;
        }
+       
+       public CSMessage( )
+       {
+               super();
+               type=0;
+       }
 
        public String toString()
        {
@@ -202,6 +209,26 @@
 
        
////////////////////////////////////////////////////////////////////////////////////////////////
 
+       public int getByteSize() {
+               return 4;
+       }
+       
+       public void readBytes( ByteBuffer buf, ErrorReporter err )
+       {
+               int     size;
+
+               size=buf.getShort() & 0x0000ffff;
+               err.reportIf(size!=4,"bad size !");
+
+               type=buf.getShort() & 0x0000ffff;
+       }
+
+       public void writeBytes( ByteBuffer buf )
+       {
+               buf.putShort((short) 4);
+               buf.putShort((short) type);
+       }
+
        public int getType()
        {
                return type;

Deleted: freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java   2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java   2006-08-12 
15:45:04 UTC (rev 3219)
@@ -1,45 +0,0 @@
- /*
-      This file is part of Freeway
-
-      Freeway is free software; you can redistribute it and/or modify
-      it under the terms of the GNU General Public License as published
-      by the Free Software Foundation; either version 2, or (at your
-      option) any later version.
-
-      Freeway is distributed in the hope that it will be useful, but
-      WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-      General Public License for more details.
-
-      You should have received a copy of the GNU General Public License
-      along with Freeway; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
- */
-
-package org.gnu.freeway.util.net;
-
-import org.gnu.freeway.server.CPluginLoader;
-
-/**
- * @file NativeCSHandler.java
- * @brief 
- * @author mdonoughe
- */
-public class NativeCSHandler implements CSHandler {
-       
-       public CPluginLoader.Handle ptr;
-       
-       public NativeCSHandler(CPluginLoader.Handle handle) {
-               ptr = handle;
-       }
-
-       /* (non-Javadoc)
-        * @see 
org.gnu.freeway.util.net.CSHandler#handle(org.gnu.freeway.util.net.CSSession, 
org.gnu.freeway.util.net.CSMessage)
-        */
-       public boolean handle(CSSession session, CSMessage message) {
-               assert(message instanceof CSNativeMessage);
-               return CPluginLoader._.callCSHandle(ptr, session, 
(CSNativeMessage) message);
-       }
-
-}

Added: freeway/src/org/gnu/freeway/util/net/P2PNativeMessage.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/P2PNativeMessage.java  2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/util/net/P2PNativeMessage.java  2006-08-12 
15:45:04 UTC (rev 3219)
@@ -0,0 +1,84 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.util.net;
+
+import org.gnu.freeway.util.net.*;
+
+import java.nio.*;
+import java.util.*;
+
+/**
+ * @file P2PNativeMessage.java
+ * @brief 
+ * @author mdonoughe
+ */
+public class P2PNativeMessage extends P2PMessage
+{
+       public byte[] arr;
+
+       public P2PNativeMessage()
+       {
+               super( 0 );
+               throw new Error();
+       }
+       
+       public P2PNativeMessage(int type)
+       {
+               super( type );
+       }
+
+       public P2PNativeMessage(byte[] data) {
+               super( ((data[2] & 0xff) << 8) + (data[3] & 0xff) );
+               arr = data;
+       }
+
+       public String toString()
+       {
+               return "P2PNativeMessage";
+       }
+
+
+       
////////////////////////////////////////////////////////////////////////////////////////////////
+
+       public int getByteSize()
+       {
+               if(arr == null)
+                       return 4;
+               return arr.length;
+       }
+
+       public void readBytes( ByteBuffer buf, ErrorReporter err )
+       {
+               int     size,type;
+
+               buf.mark();
+               size=buf.getShort() & 0x0000ffff;
+               type=buf.getShort() & 0x0000ffff;
+               buf.reset();
+               
+               arr = new byte[size];
+               buf.get(arr);
+       }
+
+       public void writeBytes( ByteBuffer buf )
+       {
+               buf.put(arr);
+       }
+}

Modified: freeway/src/org/gnu/freeway/util/net/PersistentHelper.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/PersistentHelper.java  2006-08-08 
20:25:41 UTC (rev 3218)
+++ freeway/src/org/gnu/freeway/util/net/PersistentHelper.java  2006-08-12 
15:45:04 UTC (rev 3219)
@@ -123,9 +123,11 @@
                                p=readFully(p.getClass(),buf);
                                }
                        else {
+                               System.err.println("Could not write message!");
                                p=null;
                                }
-                       }
+                       } else
+                               System.err.println("p == null");
                return p;
        }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]