gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r15168 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r15168 - gnunet/src/mesh
Date: Fri, 6 May 2011 03:45:13 +0200

Author: bartpolot
Date: 2011-05-06 03:45:13 +0200 (Fri, 06 May 2011)
New Revision: 15168

Modified:
   gnunet/src/mesh/Makefile.am
   gnunet/src/mesh/mesh_api_new.c
Log:
WiP


Modified: gnunet/src/mesh/Makefile.am
===================================================================
--- gnunet/src/mesh/Makefile.am 2011-05-05 22:21:31 UTC (rev 15167)
+++ gnunet/src/mesh/Makefile.am 2011-05-06 01:45:13 UTC (rev 15168)
@@ -13,7 +13,8 @@
  gnunet-service-mesh
 
 lib_LTLIBRARIES = \
-  libgnunetmesh.la
+  libgnunetmesh.la \
+  libgnunetmeshnew.la
 
 libgnunetmesh_la_SOURCES = \
   mesh_api.c
@@ -26,10 +27,31 @@
   -version-info 0:0:0
 
 gnunet_service_mesh_SOURCES = \
- gnunet-service-mesh.c         
+ gnunet-service-mesh.c
 
 gnunet_service_mesh_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.la\
   $(top_builddir)/src/dht/libgnunetdht.la \
   $(top_builddir)/src/util/libgnunetutil.la
 
+
+libgnunetmeshnew_la_SOURCES = \
+  mesh_api_new.c mesh.h
+libgnunetmeshnew_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(XLIB)
+libgnunetmeshnew_la_LDFLAGS = \
+  $(GN_LIB_LDFLAGS) $(WINFLAGS) \
+  -version-info 0:0:0
+
+check_PROGRAMS = $(STUD_TESTS) \
+ test_mesh_api
+
+test_mesh_api_SOURCES = \
+ test_mesh_api.c
+test_mesh_api_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/mesh/libgnunetmeshnew.la
+test_mesh_api_DEPENDENCIES = \
+  libgnunetmeshnew.la
+

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-05-05 22:21:31 UTC (rev 15167)
+++ gnunet/src/mesh/mesh_api_new.c      2011-05-06 01:45:13 UTC (rev 15168)
@@ -34,17 +34,23 @@
 #endif
 
 
-#include <stdint.h>
-#include "gnunet_mesh_service.h"
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_client_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_mesh_service_new.h"
+#include "mesh.h"
 
 /**
  * Opaque handle to the service.
  */
 struct GNUNET_MESH_Handle {
-    GNUNET_CLIENT_Connection            *mesh;
+    struct GNUNET_CLIENT_Connection     *mesh;
+    struct GNUNET_MESH_MessageHandler   *message_handlers;
+    GNUNET_MESH_ApplicationType         *applications;
     struct GNUNET_MESH_Tunnel           *head;
     struct GNUNET_MESH_Tunnel           *tail;
-    GNUNET_MESH_TunnelEndHandler        cleaner;
+    GNUNET_MESH_TunnelEndHandler        *cleaner;
     void                                *cls;
 };
 
@@ -62,6 +68,40 @@
 
 
 /**
+ * Function called to notify a client about the socket
+ * begin ready to queue more data.  "buf" will be
+ * NULL and "size" zero if the socket was closed for
+ * writing in the meantime.
+ *
+ * @param cls closure
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to buf
+ */
+size_t 
+send_connect_packet (void *cls, size_t size, void *buf) {
+    struct GNUNET_MESH_Handle           *h;
+    struct GNUNET_MESH_ClientConnect    *msg;
+    int                                 *types;
+    int                                 ntypes;
+    int                                 *applications;
+    int                                 napplications;
+
+    msg = (struct GNUNET_MESH_ClientConnect *) buf;
+    h = (struct GNUNET_MESH_Handle *) cls;
+    msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
+    for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
+        types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
+        types[ntypes] = h->message_handlers[ntypes].type;
+    }
+    msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
+                        sizeof(uint16_t) * ntypes +
+                        sizeof(GNUNET_MESH_ApplicationType) * napplications;
+}
+
+
+
+/**
  * Connect to the mesh service.
  *
  * @param cfg configuration to use
@@ -82,22 +122,26 @@
                      GNUNET_MESH_TunnelEndHandler cleaner,
                      const struct GNUNET_MESH_MessageHandler *handlers,
                      const GNUNET_MESH_ApplicationType *stypes) {
-    GNUNET_MESH_Handle                  *h;
-    struct GNUNET_MESH_MessageHandler   *aux;
+    struct GNUNET_MESH_Handle           *h;
     int                                 i;
     uint16_t                            *types;
 
-    h = GNUNET_malloc(sizeof(GNUNET_MESH_Handle));
+    h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
 
     h->cleaner = cleaner;
     h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
     h->cls = cls;
+    h->message_handlers = handlers;
+    h->applications = h->applications;
 
-    aux = handlers;
-    for(i = 0; handlers[i].type; i++) {
-        
-    }
-    
+    GNUNET_CLIENT_notify_transmit_ready(h->mesh,
+                                        sizeof(int),
+                                        GNUNET_TIME_relative_get_forever(),
+                                        GNUNET_YES,
+                                        &send_connect_packet,
+                                        (void *)h
+                                       );
+
     return h;
 }
 
@@ -130,9 +174,10 @@
                            GNUNET_MESH_TunnelDisconnectHandler
                            disconnect_handler,
                            void *handler_cls) {
-    GNUNET_MESH_Tunnel *tunnel;
-    tunnel = GNUNET_malloc(sizeof(GNUNET_MESH_Tunnel));
+    struct GNUNET_MESH_Tunnel           *tunnel;
 
+    tunnel = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel));
+
     tunnel->connect_handler = connect_handler;
     tunnel->disconnect_handler = disconnect_handler;
     tunnel->peers = NULL;
@@ -234,7 +279,7 @@
                                    void *notify_cls) {
     struct GNUNET_MESH_Handle   *handle;
 
-    handle = GNUNET_malloc(sizeof(GNUNET_MESH_Handle));
+    handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
 
     return handle;
 }




reply via email to

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