gnunet-service-mesh
lib_LTLIBRARIES = \
- libgnunetmesh.la
+ libgnunetmesh.la \
+ libgnunetmeshnew.la
libgnunetmesh_la_SOURCES = \
mesh_api.c
-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
+
#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;
};
};
+/**
+ * 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.
*
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;
}
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;
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;
}