gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3009 - in freeway: native src/org/gnu/freeway src/org/gnu/


From: mdonoughe
Subject: [GNUnet-SVN] r3009 - in freeway: native src/org/gnu/freeway src/org/gnu/freeway/protocol src/org/gnu/freeway/protocol/stats src/org/gnu/freeway/server src/org/gnu/freeway/util src/org/gnu/freeway/util/net
Date: Wed, 14 Jun 2006 23:13:20 -0700 (PDT)

Author: mdonoughe
Date: 2006-06-14 23:13:11 -0700 (Wed, 14 Jun 2006)
New Revision: 3009

Added:
   freeway/src/org/gnu/freeway/protocol/stats/
   freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
   freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java
Modified:
   freeway/native/org_gnu_freeway_server_CPluginLoader.c
   freeway/native/org_gnu_freeway_server_CPluginLoader.h
   freeway/src/org/gnu/freeway/GNUNetDaemon.java
   freeway/src/org/gnu/freeway/protocol/AbstractProtocol.java
   freeway/src/org/gnu/freeway/server/CPluginLoader.java
   freeway/src/org/gnu/freeway/server/CSGetCSMessageSupported.java
   freeway/src/org/gnu/freeway/server/CSGetP2PMessageSupported.java
   freeway/src/org/gnu/freeway/server/CSStatistics.java
   freeway/src/org/gnu/freeway/server/CSStatisticsRequest.java
   freeway/src/org/gnu/freeway/server/ClientServer.java
   freeway/src/org/gnu/freeway/server/CoreAPI.java
   freeway/src/org/gnu/freeway/server/CoreService.java
   freeway/src/org/gnu/freeway/util/AbstractService.java
   freeway/src/org/gnu/freeway/util/NativeService.java
   freeway/src/org/gnu/freeway/util/net/CSMessage.java
Log:
implemented registerClientHandler in the C api.
added support for loading native protocols
changed the names of the stats message types to match the C version to 
avoid confusion

This doesn't work
crashes on 'setConfigurationString("ABOUT","stats",gettext...' of 
statistics.c
I wasn't sure how to get data from CSMessage, so all the handler does 
currently is print the class name of CSMessage(once the program executes 
to this point)


Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.c
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.c       2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.c       2006-06-15 
06:13:11 UTC (rev 3009)
@@ -300,45 +300,89 @@
   return convCIntToInt(ret, env);
 }
 
+static int jregisterClientHandler(unsigned short type, CSHandler callback) {
+fprintf(stderr, "in jregisterClientHandler\n");
+  ModuleList * pos;
+  JNIEnv * env;
+  jclass capiClazz;
+  jclass handleClazz;
+  jobject jtype;
+  jobject jcallback;
+  jmethodID newHandle;
+  jmethodID method;
+  jobject jret;
 
+  pos = modules;
+  while (pos != NULL) {
+    if (PTHREAD_SELF_TEST(&pos->thread))
+      break;
+    pos = pos->next;
+  }
+  if (pos == NULL) 
+    errexit(_("Thread creation in C modules not supported by Freeway.\n"));
+  env = pos->env;
+  GNUNET_ASSERT(env != NULL);
+  capiClazz = (*env)->GetObjectClass(env, pos->jcapi);
+  GNUNET_ASSERT(capiClazz != NULL);
+  handleClazz = (*env)->FindClass(env, 
"org/gnu/freeway/server/CPluginLoader$Handle");
+       //if((*env)->ExceptionOccurred(env))
+               
+  GNUNET_ASSERT(handleClazz != NULL);
+  newHandle = (*env)->GetMethodID(env, handleClazz, "<init>", "(J)V");
+  GNUNET_ASSERT(newHandle != NULL);
+  method = (*env)->GetMethodID(env, capiClazz, "registerClientHandler", 
"(Lorg/gnu/freeway/cwrappers/CInt;Lorg/gnu/freeway/server/CPluginLoader$Handle;)Lorg/gnu/freeway/cwrappers/CInt;");
+  GNUNET_ASSERT(method != NULL);
+  jtype = convIntToCInt((int) type, env);
+  jcallback = (*env)->NewObject(env, handleClazz, newHandle, (jlong) (long) 
callback);
+(*env)->ExceptionDescribe(env);
+  GNUNET_ASSERT(jcallback != NULL);
+  jret = (*env)->CallObjectMethod(env, pos->jcapi, method, jtype, jcallback);
+  GNUNET_ASSERT(jret != NULL);
+fprintf(stderr, "leaving jregisterClientHandler\n");
+  return convCIntToInt(jret, env);
+}
 
+
 static CoreAPIForApplication jcapi = {
-  0,
-  NULL, /* FIXME... */
-  &jloadApplicationModule,
-  NULL, /* FIXME... */
-  &jrequestService,
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
-  NULL, /* FIXME... */
+  0, // version
+  NULL, /* FIXME... */ // myIdentity
+  &jloadApplicationModule, // loadApplicationModule
+  NULL, /* FIXME... */ // unloadApplicationModule
+  &jrequestService, // requestService
+  NULL, /* FIXME... */ // releaseService
+  NULL, /* FIXME... */ // sendPlaintext
+  NULL, /* FIXME... */ // unicast
+  NULL, /* FIXME... */ // unicastCallback
+  NULL, /* FIXME... */ // forAllConnectedNodes
+  NULL, /* FIXME... */ // registerSendCallback
+  NULL, /* FIXME... */ // unregisterSendCallback
+  NULL, /* FIXME... */ // registerSendNotify
+  NULL, /* FIXME... */ // unregisterSendNotify
+  NULL, /* FIXME... */ // registerHandler
+  NULL, /* FIXME... */ // unregisterHandler
+  NULL, /* FIXME... */ // isHandlerRegistered
+  NULL, /* FIXME... */ // registerPlaintextHandler
+  NULL, /* FIXME... */ // unregisterPlaintextHandler
+  NULL, /* FIXME... */ // offerTSessionFor
+  NULL, /* FIXME... */ // assignSessionKey
+  NULL, /* FIXME... */ // getCurrentSessionKey
+  NULL, /* FIXME... */ // confirmSessionUp
+  NULL, /* FIXME... */ // preferTrafficFrom
+  NULL, /* FIXME... */ // queryBPMfromPeer
+  NULL, /* FIXME... */ // disconnectFromPeer
+  NULL, /* FIXME... */ // sendValueToClient
+  NULL, /* FIXME... */ // sendToClient
+  &jregisterClientHandler, // registerClientHandler
+  NULL, /* FIXME... */ // unregisterClientHandler
+  NULL, /* FIXME... */ // registerClientExitHandler
+  NULL, /* FIXME... */ // unregisterClientExitHandler
+  NULL, /* FIXME... */ // terminateClientConnection
+  NULL, /* FIXME... */ // injectMessage
+  NULL, /* FIXME... */ // computeIndex
+  NULL, /* FIXME... */ // getConnectionModuleLock
+  NULL, /* FIXME... */ // getSlotCount
+  NULL, /* FIXME... */ // isSlotUsed
+  NULL  /* FIXME... */ // getLastActivityOf
 };
 
 
@@ -388,13 +432,66 @@
        (*env)->ReleaseStringUTFChars(env, serviceName, strServiceName);
        return (jlong) (long) m;
 ULE:        
-       (*env)->ReleaseStringUTFChars(env, serviceName, strServiceName);
         UnsatisfiedLinkError = (*env)->FindClass(env, 
"java/lang/UnsatisfiedLinkError");
         if(UnsatisfiedLinkError)
                (*env)->ThrowNew(env, UnsatisfiedLinkError, strServiceName);
+       (*env)->ReleaseStringUTFChars(env, serviceName, strServiceName);
         return 0;
 }
 
+JNIEXPORT jint JNICALL Java_org_gnu_freeway_server_CPluginLoader_cLoadProtocol
+  (JNIEnv *env, jobject cls, jstring protocolName, jobject capi) {
+       const char *strProtocolName;
+       void * modulePtr;
+       int ok;
+        ModuleList * m;
+        ApplicationInitMethod mptr;
+       jclass UnsatisfiedLinkError;
+       strProtocolName = (*env)->GetStringUTFChars(env, protocolName, NULL);
+       if (! strProtocolName)
+               return 0;
+       modulePtr = loadDynamicLibrary(DSO_PREFIX, strProtocolName);
+       if (! modulePtr)
+               goto ULE;
+       mptr = bindDynamicMethod(modulePtr,
+                                 "initialize_",
+                                strProtocolName);
+       if (mptr == NULL)
+               goto ULE;
+       m = MALLOC(sizeof(ModuleList));
+       PTHREAD_GET_SELF(&m->thread);
+        m->modulePtr = modulePtr;
+       m->moduleFptrStruct = NULL;
+        m->name = STRDUP(strProtocolName);
+       m->env = env;
+       m->jcapi = capi;
+       m->next = modules;
+       modules = m;
+        ok = mptr(&jcapi);
+fprintf(stderr, ">XXXXXXXXXXXXXXXX\n");
+       /* by JNI API definition, these are no longer valid
+          after we return! */
+       PTHREAD_REL_SELF(&m->thread);
+       m->env = NULL;
+       m->jcapi = 0;
+       m->moduleFptrStruct = NULL;
+       if (ok == SYSERR) {
+         FREE(m->name);
+         /* FIXME: concurrent modification of modules... */
+         modules = m->next;
+         FREE(m);
+       }
+       (*env)->ReleaseStringUTFChars(env, protocolName, strProtocolName);
+fprintf(stderr, ">YYYYYYYYYYYYYYYYY\n");
+       return (jint) ok;
+ULE:
+        UnsatisfiedLinkError = (*env)->FindClass(env, 
"java/lang/UnsatisfiedLinkError");
+        if(UnsatisfiedLinkError)
+               (*env)->ThrowNew(env, UnsatisfiedLinkError, strProtocolName);
+       (*env)->ReleaseStringUTFChars(env, protocolName, strProtocolName);
+        return SYSERR;
+}
+
 JNIEXPORT jobject JNICALL Java_org_gnu_freeway_server_CPluginLoader_cCallC
 (JNIEnv *env, jobject cls, jlong modulePtr, jobject capi, jint functionOffset, 
jint functionType, jobjectArray arguments) {
   ModuleList * m = (ModuleList*) (long) modulePtr;

Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.h
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.h       2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.h       2006-06-15 
06:13:11 UTC (rev 3009)
@@ -17,6 +17,14 @@
 
 /*
  * Class:     org_gnu_freeway_server_CPluginLoader
+ * Method:    cLoadProtocol
+ * Signature: (Ljava/lang/String;Lorg/gnu/freeway/server/CoreAPI;)I
+ */
+JNIEXPORT jint JNICALL Java_org_gnu_freeway_server_CPluginLoader_cLoadProtocol
+  (JNIEnv *, jclass, jstring, jobject);
+
+/*
+ * Class:     org_gnu_freeway_server_CPluginLoader
  * Method:    cCallC
  * Signature: 
(JLorg/gnu/freeway/server/CoreAPI;II[Ljava/lang/Object;)Ljava/lang/Object;
  */

Modified: freeway/src/org/gnu/freeway/GNUNetDaemon.java
===================================================================
--- freeway/src/org/gnu/freeway/GNUNetDaemon.java       2006-06-13 04:48:52 UTC 
(rev 3008)
+++ freeway/src/org/gnu/freeway/GNUNetDaemon.java       2006-06-15 06:13:11 UTC 
(rev 3009)
@@ -137,10 +137,10 @@
                /* init 3b: load application services */
                beurk1();
 
-               service(CoreService.class);
-               service(HelloExchangeService.class);
-               service(PingPongService.class);
-               service(ConnectionService.class);
+               //service(CoreService.class);
+               //service(HelloExchangeService.class);
+               //service(PingPongService.class);
+               //service(ConnectionService.class);
                service(StatsService.class);
 
                ((CoreService) service(CoreService.class)).loadProtocols();

Modified: freeway/src/org/gnu/freeway/protocol/AbstractProtocol.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/AbstractProtocol.java  2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/protocol/AbstractProtocol.java  2006-06-15 
06:13:11 UTC (rev 3009)
@@ -34,10 +34,20 @@
        protected AbstractProtocol( String str )
        {
                super(true);
+               name=str;
+               construct();
+       }
+       
+       public AbstractProtocol()
+       {
+               super(true);
+               name=this.toString();
+               construct();
+       }
+       
+       private void construct() {
                coreAPI=null;
 
-               name=str;
-
                csHandler=new CSHandler() {
                        public boolean handle( CSSession client, CSMessage 
message )
                        {

Added: freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java       
2006-06-13 04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java       
2006-06-15 06:13:11 UTC (rev 3009)
@@ -0,0 +1,85 @@
+ /*
+      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.protocol.stats;
+
+import java.util.logging.Level;
+
+import org.gnu.freeway.Server;
+import org.gnu.freeway.protocol.Protocol;
+import org.gnu.freeway.server.CPluginLoader;
+import org.gnu.freeway.server.ClientExitHandler;
+import org.gnu.freeway.server.CoreForProtocol;
+import org.gnu.freeway.util.net.CSHandler;
+import org.gnu.freeway.util.net.CSMessage;
+import org.gnu.freeway.util.net.CSSession;
+import org.gnu.freeway.util.net.P2PMessage;
+import org.gnu.freeway.util.net.PersistentDecoder;
+import org.gnu.freeway.protocol.AbstractProtocol;
+import org.gnu.freeway.protocol.chat.CSChatMessage;
+import org.gnu.freeway.server.CoreAPI;
+
+/**
+ * @file StatsProtocol.java
+ * @brief 
+ * @author mdonoughe
+ */
+public class StatsProtocol extends AbstractProtocol implements Protocol {
+
+       private CPluginLoader loader;
+       
+       public StatsProtocol() {
+               super();
+               loader = new CPluginLoader();
+       }
+       
+       /* (non-Javadoc)
+        * @see 
org.gnu.freeway.protocol.Protocol#init(org.gnu.freeway.server.CoreForProtocol)
+        */
+       public boolean init(CoreForProtocol api) {
+               boolean ok = super.init(api);
+               CoreAPI._.setProtocolCore(api);
+               ok &= CoreAPI.OK.getValue() == 
loader.loadProtocol(CPluginLoader.classToLibraryName(getName()));
+               return ok;
+       }
+       
+       /* (non-Javadoc)
+        * @see org.gnu.freeway.protocol.Protocol#done()
+        */
+       public void done() {
+               // TODO Auto-generated method stub
+               super.done();
+       }
+       
+       public String toString() {
+               String ret = this.getClass().getSimpleName();
+               if(ret.endsWith("Protocol"))
+                       ret = ret.substring(0, ret.length() - 8);
+               return ret.toLowerCase();
+       }
+
+       /* (non-Javadoc)
+        * @see org.gnu.freeway.protocol.Protocol#createCSDecoder()
+        */
+       public PersistentDecoder createCSDecoder() {
+               // TODO Auto-generated method stub
+               return super.createCSDecoder();
+       }
+
+}

Modified: freeway/src/org/gnu/freeway/server/CPluginLoader.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoader.java       2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/server/CPluginLoader.java       2006-06-15 
06:13:11 UTC (rev 3009)
@@ -23,6 +23,8 @@
 import java.lang.reflect.Method;
 
 import org.gnu.freeway.cwrappers.util.SwitchTableGenerator;
+import org.gnu.freeway.util.net.CSMessage;
+import org.gnu.freeway.util.net.CSSession;
 
 /**
  * @file CPluginLoader.java
@@ -36,6 +38,8 @@
        }
 
        private static native long cLoadService(String serviceName, CoreAPI 
capi);
+       
+       private static native int cLoadProtocol(String protocolName, CoreAPI 
capi);
 
        private static native Object cCallC(long modulePtr, CoreAPI capi,
                        int functionOffset, int functionType, Object[] 
arguments);
@@ -91,14 +95,16 @@
                assert (serviceName != null);
                return new Handle(cLoadService(serviceName, CoreAPI._));
        }
+       
+       public int loadProtocol(String protocolName) {
+               assert (protocolName != null);
+               return cLoadProtocol(protocolName, CoreAPI._);
+       }
 
        /**
         * This method is used by the generated "services.impl"
         * methods to invoke the respective C code.  
         * 
-        * Internally, callC will determine the method signature
-        * and method index and then use cCallC to do the actual call.
-        * 
         * @param modulePtr the handle obtained when loading the module
         * @param offset the position of the method to call
         * @param functionType the type of function to call
@@ -161,4 +167,12 @@
                        assert value != 0;
                }
        }
+
+
+       public static boolean callCSHandle(Handle handle, CSSession session, 
CSMessage message) {
+               // TODO Auto-generated method stub
+               // ._, session, 
+               System.err.println("!!!" + 
message.getClass().getCanonicalName());
+               return false;
+       }
 }

Modified: freeway/src/org/gnu/freeway/server/CSGetCSMessageSupported.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CSGetCSMessageSupported.java     
2006-06-13 04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/server/CSGetCSMessageSupported.java     
2006-06-15 06:13:11 UTC (rev 3009)
@@ -22,7 +22,7 @@
 
        public CSGetCSMessageSupported()
        {
-               super(IS_CS_MESSAGE_SUPPORTED);
+               super(CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED);
                csType=0;
        }
 
@@ -61,13 +61,13 @@
                csType=buf.getShort() & 0x0000ffff;
 
                err.reportIf(size!=SIZE,"Bad size !");
-               err.reportIf(type!=IS_CS_MESSAGE_SUPPORTED,"Bad type !");
+               err.reportIf(type!=CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,"Bad 
type !");
        }
 
        public void writeBytes( ByteBuffer buf )
        {
                buf.putShort((short) SIZE);
-               buf.putShort((short) IS_CS_MESSAGE_SUPPORTED);
+               buf.putShort((short) CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED);
                buf.putInt(0);
                buf.putShort((short) csType);
        }

Modified: freeway/src/org/gnu/freeway/server/CSGetP2PMessageSupported.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CSGetP2PMessageSupported.java    
2006-06-13 04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/server/CSGetP2PMessageSupported.java    
2006-06-15 06:13:11 UTC (rev 3009)
@@ -22,7 +22,7 @@
 
        public CSGetP2PMessageSupported()
        {
-               super(IS_P2P_MESSAGE_SUPPORTED);
+               super(CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED);
                p2pType=0;
        }
 
@@ -61,13 +61,13 @@
                p2pType=buf.getShort() & 0x0000ffff;
 
                err.reportIf(size!=SIZE,"Bad size !");
-               err.reportIf(type!=IS_P2P_MESSAGE_SUPPORTED,"Bad type !");
+               
err.reportIf(type!=CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,"Bad type !");
        }
 
        public void writeBytes( ByteBuffer buf )
        {
                buf.putShort((short) SIZE);
-               buf.putShort((short) IS_P2P_MESSAGE_SUPPORTED);
+               buf.putShort((short) CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED);
                buf.putInt(0);
                buf.putShort((short) p2pType);
        }

Modified: freeway/src/org/gnu/freeway/server/CSStatistics.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CSStatistics.java        2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/server/CSStatistics.java        2006-06-15 
06:13:11 UTC (rev 3009)
@@ -38,7 +38,7 @@
 
        public CSStatistics()
        {
-               super(IS_STATISTICS);
+               super(CS_PROTO_stats_STATISTICS);
                size=SIZE;
                startTime=(int) Scheduler.toSeconds(Scheduler.now());
                totalCounters=0;
@@ -131,7 +131,7 @@
                        n+=stat.getByteSize();
                        }
 
-               err.reportIf(type!=CSMessage.IS_STATISTICS,"bad type !");
+               err.reportIf(type!=CSMessage.CS_PROTO_stats_STATISTICS,"bad 
type !");
                err.reportIf(startTime<=0,"Invalid start time !");
                err.reportIf(totalCounters<0,"Invalid total counter !");
                err.reportIf(statCounters<0,"Invalid stat counter !");
@@ -144,7 +144,7 @@
                int                     i;
 
                buf.putShort((short) size);
-               buf.putShort((short) IS_STATISTICS);
+               buf.putShort((short) CS_PROTO_stats_STATISTICS);
                buf.putInt(0);
                buf.putInt(startTime);
                buf.putInt(totalCounters);

Modified: freeway/src/org/gnu/freeway/server/CSStatisticsRequest.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CSStatisticsRequest.java 2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/server/CSStatisticsRequest.java 2006-06-15 
06:13:11 UTC (rev 3009)
@@ -21,7 +21,7 @@
 
        public CSStatisticsRequest()
        {
-               super(IS_GET_STATISTICS);
+               super(CS_PROTO_stats_GET_STATISTICS);
                minLevel=Stat.NORMAL;
        }
 
@@ -57,7 +57,7 @@
                type=buf.getShort() & 0x0000ffff;
 
                err.reportIf(size!=SIZE,"Invalid size !");
-               err.reportIf(type!=IS_GET_STATISTICS,"Invalid type !");
+               err.reportIf(type!=CS_PROTO_stats_GET_STATISTICS,"Invalid type 
!");
 
                minLevel=buf.getShort() & 0x0000ffff;
        }
@@ -65,7 +65,7 @@
        public void writeBytes( ByteBuffer buf )
        {
                buf.putShort((short) SIZE);
-               buf.putShort((short) IS_GET_STATISTICS);
+               buf.putShort((short) CS_PROTO_stats_GET_STATISTICS);
                buf.putShort((short) minLevel);
        }
 }

Modified: freeway/src/org/gnu/freeway/server/ClientServer.java
===================================================================
--- freeway/src/org/gnu/freeway/server/ClientServer.java        2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/server/ClientServer.java        2006-06-15 
06:13:11 UTC (rev 3009)
@@ -86,9 +86,9 @@
                prefs=app.getPreferences();
 
                // register default handlers
-               registerCSHandler(CSMessage.IS_GET_STATISTICS,this);
-               registerCSHandler(CSMessage.IS_CS_MESSAGE_SUPPORTED,this);
-               registerCSHandler(CSMessage.IS_P2P_MESSAGE_SUPPORTED,this);
+               
/*registerCSHandler(CSMessage.CS_PROTO_stats_GET_STATISTICS,this);
+               
registerCSHandler(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,this);
+               
registerCSHandler(CSMessage.CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,this);*/
                registerCSHandler(CSMessage.IS_GET_OPTION_REQUEST,this);
 
                port=prefs.getInt("NETWORK","PORT",0);
@@ -111,10 +111,10 @@
                        }
 
                // unregister default handlers
-               unregisterCSHandler(CSMessage.IS_GET_OPTION_REQUEST,this);
-               unregisterCSHandler(CSMessage.IS_P2P_MESSAGE_SUPPORTED,this);
-               unregisterCSHandler(CSMessage.IS_CS_MESSAGE_SUPPORTED,this);
-               unregisterCSHandler(CSMessage.IS_GET_STATISTICS,this);
+               /*unregisterCSHandler(CSMessage.IS_GET_OPTION_REQUEST,this);
+               
unregisterCSHandler(CSMessage.CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,this);
+               
unregisterCSHandler(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,this);*/
+               
unregisterCSHandler(CSMessage.CS_PROTO_stats_GET_STATISTICS,this);
 
                synchronized(handlers) {
                        if (exitHandlers.size()>0) {
@@ -323,7 +323,7 @@
 
        public boolean handle( CSSession client, CSMessage msg )
        {
-               if (msg instanceof CSStatisticsRequest) {
+               /*if (msg instanceof CSStatisticsRequest) {
                        return handleStatistics(client,(CSStatisticsRequest) 
msg);
                        }
                if (msg instanceof CSGetCSMessageSupported) {
@@ -331,14 +331,14 @@
                        }
                if (msg instanceof CSGetP2PMessageSupported) {
                        return 
handleP2PSupported(client,(CSGetP2PMessageSupported) msg);
-                       }
+                       }*/
                if (msg instanceof CSGetOptionRequest) {
                        return handleGetOption(client,(CSGetOptionRequest) msg);
                        }
                return false;
        }
 
-       protected boolean handleStatistics( CSSession client, 
CSStatisticsRequest msg )
+       /* protected boolean handleStatistics( CSSession client, 
CSStatisticsRequest msg )
        {
                CSStatistics[]  resp;
                int                             i;
@@ -346,7 +346,7 @@
                resp=stats.createMessages(msg.getMinLevel());
                for (i=0; i<resp.length && client.send(resp[i]); i++) {}
                return (i==resp.length);
-       }
+       }*/
 
        /**
         * Handle a request to see if a particular client server message is 
supported.
@@ -355,13 +355,13 @@
         * @return
         */
 
-       protected boolean handleCSSupported( CSSession client, 
CSGetCSMessageSupported msg )
+       /*protected boolean handleCSSupported( CSSession client, 
CSGetCSMessageSupported msg )
        {
                int     type;
 
                type=msg.getCSType();
                return client.send(new CSResult(isCSHandlerRegistered(type)));
-       }
+       }*/
 
        /**
         * Handle a request to see if a particular p2p message is supported.
@@ -370,7 +370,7 @@
         * @return
         */
 
-       protected boolean handleP2PSupported( CSSession client, 
CSGetP2PMessageSupported msg )
+       /*protected boolean handleP2PSupported( CSSession client, 
CSGetP2PMessageSupported msg )
        {
                MessagesDispatcher      dispatcher;
                int     type;
@@ -379,7 +379,7 @@
 
                dispatcher=((Server) appp).getDispatcher();
                return client.send(new 
CSResult(dispatcher.isP2PHandlerRegistered(type)));
-       }
+       } */
 
        /**
         * @param sock

Modified: freeway/src/org/gnu/freeway/server/CoreAPI.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreAPI.java     2006-06-13 04:48:52 UTC 
(rev 3008)
+++ freeway/src/org/gnu/freeway/server/CoreAPI.java     2006-06-15 06:13:11 UTC 
(rev 3009)
@@ -22,6 +22,9 @@
 import org.gnu.freeway.cwrappers.*;
 import java.util.ArrayList;
 import java.util.Iterator;
+import org.gnu.freeway.Server;
+import org.gnu.freeway.util.net.CSMessage;
+import org.gnu.freeway.util.net.NativeCSHandler;
 
 /**
  * @file CoreAPI.java
@@ -29,6 +32,26 @@
  * @author mdonoughe
  */
 public class CoreAPI {
+       private CoreForProtocol protocolCore = null;
+       private CoreForTransport transportCore = null;
+       private CoreService serviceCore = null;
+       
+       public void setProtocolCore(CoreForProtocol cfp) {
+               if(protocolCore == null)
+                       this.protocolCore = cfp;
+       }
+       
+       public void setTramsportCore(CoreForTransport cft) {
+               if(transportCore == null)
+                       this.transportCore = cft;
+       }
+       
+       public void setServiceCore(CoreService cs) {
+               if(serviceCore == null)
+                       this.serviceCore = cs;
+       }
+       
+       
        public final static CInt OK = new CInt(1);
        public final static CInt SYSERR = new CInt(-1);
        public final static CInt YES = new CInt(1);
@@ -240,8 +263,8 @@
        
        public CSendToClientCallback sendToClient;
        
-       public CInt registerClientHandler(CUnsignedShort type, CCSHandler 
callback) {
-               return SYSERR;
+       public CInt registerClientHandler(CInt type, CPluginLoader.Handle 
callback) {
+               return ((Server) 
protocolCore.getApplication()).registerCSHandler(type.getValue(), 
CSMessage.class, new NativeCSHandler(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
        }
        
        public CInt unregisterClientHandler(CUnsignedShort type, CCSHandler 
callback) {

Modified: freeway/src/org/gnu/freeway/server/CoreService.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreService.java 2006-06-13 04:48:52 UTC 
(rev 3008)
+++ freeway/src/org/gnu/freeway/server/CoreService.java 2006-06-15 06:13:11 UTC 
(rev 3009)
@@ -107,9 +107,9 @@
                int     i;
 
                super.start();
-               knownHosts=(KnownHostsService) 
getManager().service(KnownHostsService.class);
+               /*knownHosts=(KnownHostsService) 
getManager().service(KnownHostsService.class);
                connection=(ConnectionService) 
getManager().service(ConnectionService.class);
-               traffic=(TrafficService) 
getManager().service(TrafficService.class);
+               traffic=(TrafficService) 
getManager().service(TrafficService.class);*/
 
                log(Level.FINE,"Start #"+threads.length+" message handling 
threads.");
                for (i=0; i<threads.length; i++) {
@@ -441,7 +441,7 @@
                PersistentDecoder       dec;
 
                dec=new PersistentDecoder();
-               
dec.add(CSMessage.IS_CS_MESSAGE_SUPPORTED,CSGetCSMessageSupported.class);
+               
/*dec.add(CSMessage.IS_CS_MESSAGE_SUPPORTED,CSGetCSMessageSupported.class);
                dec.add(CSMessage.IS_RESULT,CSResult.class);
                dec.add(CSMessage.IS_STATISTICS,CSStatistics.class);
                dec.add(CSMessage.IS_TRAFFIC_INFO,CSTrafficInfo.class);
@@ -450,7 +450,7 @@
                
dec.add(CSMessage.IS_P2P_MESSAGE_SUPPORTED,CSGetP2PMessageSupported.class);
                dec.add(CSMessage.IS_SHUTDOWN,CSShutdownRequest.class);
                dec.add(CSMessage.IS_CLIENT_COUNT,CSGetClientCount.class);
-               dec.add(CSMessage.IS_GET_HOST_INFO,CSGetHostInfo.class);
+               dec.add(CSMessage.IS_GET_HOST_INFO,CSGetHostInfo.class);*/
 
                dec.merge(createCSDecoderForProtocols());
                return dec;

Modified: freeway/src/org/gnu/freeway/util/AbstractService.java
===================================================================
--- freeway/src/org/gnu/freeway/util/AbstractService.java       2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/util/AbstractService.java       2006-06-15 
06:13:11 UTC (rev 3009)
@@ -36,7 +36,7 @@
        {
                super(true);
                manager=null;
-               name=this.getName();
+               name=this.toString();
                state=0;
        }
 

Modified: freeway/src/org/gnu/freeway/util/NativeService.java
===================================================================
--- freeway/src/org/gnu/freeway/util/NativeService.java 2006-06-13 04:48:52 UTC 
(rev 3008)
+++ freeway/src/org/gnu/freeway/util/NativeService.java 2006-06-15 06:13:11 UTC 
(rev 3009)
@@ -45,7 +45,7 @@
        /* (non-Javadoc)
         * @see org.gnu.freeway.util.Service#getName()
         */
-       public String getName() {
+       public String toString() {
                String ret = this.getClass().getSimpleName();
                if(ret.endsWith("Service")) {
                        ret = ret.substring(0, ret.length() - 7);

Modified: freeway/src/org/gnu/freeway/util/net/CSMessage.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/CSMessage.java 2006-06-13 04:48:52 UTC 
(rev 3008)
+++ freeway/src/org/gnu/freeway/util/net/CSMessage.java 2006-06-15 06:13:11 UTC 
(rev 3009)
@@ -28,16 +28,16 @@
        public static final int IS_TRAFFIC_INFO                 =       34;
 
        /** core: client to gnunetd: request statistics */
-       public static final int IS_GET_STATISTICS               =       36;
+       public static final int CS_PROTO_stats_GET_STATISTICS = 36;
 
        /** core: gnunetd to client: statistics */
-       public static final int IS_STATISTICS                   =       37;
+       public static final int CS_PROTO_stats_STATISTICS = 37;
 
        /** core: client to gnunetd: is client server message supported */
-       public static final int IS_CS_MESSAGE_SUPPORTED =       38;
+       public static final int CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED = 38;
 
        /** core: client to gnunetd: is p2p message supported */
-       public static final int IS_P2P_MESSAGE_SUPPORTED        =       39;
+       public static final int CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED = 39;
 
        /** afs : client to gnunetd: send queries */
        public static final int IS_QUERY                                        
=       8;
@@ -219,10 +219,10 @@
                names[IS_CLIENT_COUNT]="IS_CLIENT_COUNT";
                names[IS_TRAFFIC_QUERY]="IS_TRAFFIC_QUERY";
                names[IS_TRAFFIC_INFO]="IS_TRAFFIC_INFO";
-               names[IS_GET_STATISTICS]="IS_GET_STATISTICS";
-               names[IS_STATISTICS]="IS_STATISTICS";
-               names[IS_CS_MESSAGE_SUPPORTED]="IS_CS_MESSAGE_SUPPORTED";
-               names[IS_P2P_MESSAGE_SUPPORTED]="IS_P2P_MESSAGE_SUPPORTED";
+               
names[CS_PROTO_stats_GET_STATISTICS]="CS_PROTO_stats_GET_STATISTICS";
+               names[CS_PROTO_stats_STATISTICS]="CS_PROTO_stats_STATISTICS";
+               
names[CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED]="CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED";
+               
names[CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED]="CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED";
                names[IS_QUERY]="IS_QUERY";
                names[IS_RESULT_3HASH]="IS_RESULT_3HASH";
                names[IS_RESULT_CHK]="IS_RESULT_CHK";

Added: freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java   2006-06-13 
04:48:52 UTC (rev 3008)
+++ freeway/src/org/gnu/freeway/util/net/NativeCSHandler.java   2006-06-15 
06:13:11 UTC (rev 3009)
@@ -0,0 +1,44 @@
+ /*
+      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 {
+       
+       private CPluginLoader.Handle handle;
+       
+       public NativeCSHandler(CPluginLoader.Handle handle) {
+               this.handle = 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) {
+               return CPluginLoader.callCSHandle(handle, session, message);
+       }
+
+}





reply via email to

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