From 3252ddd73ea1639aba2159e7cc91681730470cbf Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 6 May 2011 01:45:13 +0000 Subject: WiP --- src/mesh/Makefile.am | 26 +++++++++++++++-- src/mesh/mesh_api_new.c | 75 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 84 insertions(+), 17 deletions(-) diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 4bb972f8c..902ed95f9 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am @@ -13,7 +13,8 @@ bin_PROGRAMS = $(STUD_PROGS) \ gnunet-service-mesh lib_LTLIBRARIES = \ - libgnunetmesh.la + libgnunetmesh.la \ + libgnunetmeshnew.la libgnunetmesh_la_SOURCES = \ mesh_api.c @@ -26,10 +27,31 @@ libgnunetmesh_la_LDFLAGS = \ -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 + diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index f63b0a221..0c66ed4dd 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c @@ -34,17 +34,23 @@ extern "C" #endif -#include -#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; }; @@ -61,6 +67,40 @@ struct GNUNET_MESH_Tunnel { }; +/** + * 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. * @@ -82,22 +122,26 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 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; + + GNUNET_CLIENT_notify_transmit_ready(h->mesh, + sizeof(int), + GNUNET_TIME_relative_get_forever(), + GNUNET_YES, + &send_connect_packet, + (void *)h + ); - aux = handlers; - for(i = 0; handlers[i].type; i++) { - - } - return h; } @@ -130,8 +174,9 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, 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; @@ -234,7 +279,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, 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; } -- cgit v1.2.3