aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-05-06 01:45:13 +0000
committerBart Polot <bart@net.in.tum.de>2011-05-06 01:45:13 +0000
commit3252ddd73ea1639aba2159e7cc91681730470cbf (patch)
tree4a3cb369b49edf9cae76a1469dbac7c44598851d
parent76dcc3351564146f788e8a354cb3c42025db21cc (diff)
downloadgnunet-3252ddd73ea1639aba2159e7cc91681730470cbf.tar.gz
gnunet-3252ddd73ea1639aba2159e7cc91681730470cbf.zip
WiP
-rw-r--r--src/mesh/Makefile.am26
-rw-r--r--src/mesh/mesh_api_new.c75
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) \
13 gnunet-service-mesh 13 gnunet-service-mesh
14 14
15lib_LTLIBRARIES = \ 15lib_LTLIBRARIES = \
16 libgnunetmesh.la 16 libgnunetmesh.la \
17 libgnunetmeshnew.la
17 18
18libgnunetmesh_la_SOURCES = \ 19libgnunetmesh_la_SOURCES = \
19 mesh_api.c 20 mesh_api.c
@@ -26,10 +27,31 @@ libgnunetmesh_la_LDFLAGS = \
26 -version-info 0:0:0 27 -version-info 0:0:0
27 28
28gnunet_service_mesh_SOURCES = \ 29gnunet_service_mesh_SOURCES = \
29 gnunet-service-mesh.c 30 gnunet-service-mesh.c
30 31
31gnunet_service_mesh_LDADD = \ 32gnunet_service_mesh_LDADD = \
32 $(top_builddir)/src/core/libgnunetcore.la\ 33 $(top_builddir)/src/core/libgnunetcore.la\
33 $(top_builddir)/src/dht/libgnunetdht.la \ 34 $(top_builddir)/src/dht/libgnunetdht.la \
34 $(top_builddir)/src/util/libgnunetutil.la 35 $(top_builddir)/src/util/libgnunetutil.la
35 36
37
38libgnunetmeshnew_la_SOURCES = \
39 mesh_api_new.c mesh.h
40libgnunetmeshnew_la_LIBADD = \
41 $(top_builddir)/src/util/libgnunetutil.la \
42 $(XLIB)
43libgnunetmeshnew_la_LDFLAGS = \
44 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
45 -version-info 0:0:0
46
47check_PROGRAMS = $(STUD_TESTS) \
48 test_mesh_api
49
50test_mesh_api_SOURCES = \
51 test_mesh_api.c
52test_mesh_api_LDADD = \
53 $(top_builddir)/src/util/libgnunetutil.la \
54 $(top_builddir)/src/mesh/libgnunetmeshnew.la
55test_mesh_api_DEPENDENCIES = \
56 libgnunetmeshnew.la
57
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"
34#endif 34#endif
35 35
36 36
37#include <stdint.h> 37#include "platform.h"
38#include "gnunet_mesh_service.h" 38#include "gnunet_common.h"
39#include "gnunet_client_lib.h"
40#include "gnunet_util_lib.h"
41#include "gnunet_mesh_service_new.h"
42#include "mesh.h"
39 43
40/** 44/**
41 * Opaque handle to the service. 45 * Opaque handle to the service.
42 */ 46 */
43struct GNUNET_MESH_Handle { 47struct GNUNET_MESH_Handle {
44 GNUNET_CLIENT_Connection *mesh; 48 struct GNUNET_CLIENT_Connection *mesh;
49 struct GNUNET_MESH_MessageHandler *message_handlers;
50 GNUNET_MESH_ApplicationType *applications;
45 struct GNUNET_MESH_Tunnel *head; 51 struct GNUNET_MESH_Tunnel *head;
46 struct GNUNET_MESH_Tunnel *tail; 52 struct GNUNET_MESH_Tunnel *tail;
47 GNUNET_MESH_TunnelEndHandler cleaner; 53 GNUNET_MESH_TunnelEndHandler *cleaner;
48 void *cls; 54 void *cls;
49}; 55};
50 56
@@ -62,6 +68,40 @@ struct GNUNET_MESH_Tunnel {
62 68
63 69
64/** 70/**
71 * Function called to notify a client about the socket
72 * begin ready to queue more data. "buf" will be
73 * NULL and "size" zero if the socket was closed for
74 * writing in the meantime.
75 *
76 * @param cls closure
77 * @param size number of bytes available in buf
78 * @param buf where the callee should write the message
79 * @return number of bytes written to buf
80 */
81size_t
82send_connect_packet (void *cls, size_t size, void *buf) {
83 struct GNUNET_MESH_Handle *h;
84 struct GNUNET_MESH_ClientConnect *msg;
85 int *types;
86 int ntypes;
87 int *applications;
88 int napplications;
89
90 msg = (struct GNUNET_MESH_ClientConnect *) buf;
91 h = (struct GNUNET_MESH_Handle *) cls;
92 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
93 for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
94 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
95 types[ntypes] = h->message_handlers[ntypes].type;
96 }
97 msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
98 sizeof(uint16_t) * ntypes +
99 sizeof(GNUNET_MESH_ApplicationType) * napplications;
100}
101
102
103
104/**
65 * Connect to the mesh service. 105 * Connect to the mesh service.
66 * 106 *
67 * @param cfg configuration to use 107 * @param cfg configuration to use
@@ -82,22 +122,26 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
82 GNUNET_MESH_TunnelEndHandler cleaner, 122 GNUNET_MESH_TunnelEndHandler cleaner,
83 const struct GNUNET_MESH_MessageHandler *handlers, 123 const struct GNUNET_MESH_MessageHandler *handlers,
84 const GNUNET_MESH_ApplicationType *stypes) { 124 const GNUNET_MESH_ApplicationType *stypes) {
85 GNUNET_MESH_Handle *h; 125 struct GNUNET_MESH_Handle *h;
86 struct GNUNET_MESH_MessageHandler *aux;
87 int i; 126 int i;
88 uint16_t *types; 127 uint16_t *types;
89 128
90 h = GNUNET_malloc(sizeof(GNUNET_MESH_Handle)); 129 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
91 130
92 h->cleaner = cleaner; 131 h->cleaner = cleaner;
93 h->mesh = GNUNET_CLIENT_connect("mesh", cfg); 132 h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
94 h->cls = cls; 133 h->cls = cls;
134 h->message_handlers = handlers;
135 h->applications = h->applications;
136
137 GNUNET_CLIENT_notify_transmit_ready(h->mesh,
138 sizeof(int),
139 GNUNET_TIME_relative_get_forever(),
140 GNUNET_YES,
141 &send_connect_packet,
142 (void *)h
143 );
95 144
96 aux = handlers;
97 for(i = 0; handlers[i].type; i++) {
98
99 }
100
101 return h; 145 return h;
102} 146}
103 147
@@ -130,8 +174,9 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
130 GNUNET_MESH_TunnelDisconnectHandler 174 GNUNET_MESH_TunnelDisconnectHandler
131 disconnect_handler, 175 disconnect_handler,
132 void *handler_cls) { 176 void *handler_cls) {
133 GNUNET_MESH_Tunnel *tunnel; 177 struct GNUNET_MESH_Tunnel *tunnel;
134 tunnel = GNUNET_malloc(sizeof(GNUNET_MESH_Tunnel)); 178
179 tunnel = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel));
135 180
136 tunnel->connect_handler = connect_handler; 181 tunnel->connect_handler = connect_handler;
137 tunnel->disconnect_handler = disconnect_handler; 182 tunnel->disconnect_handler = disconnect_handler;
@@ -234,7 +279,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel,
234 void *notify_cls) { 279 void *notify_cls) {
235 struct GNUNET_MESH_Handle *handle; 280 struct GNUNET_MESH_Handle *handle;
236 281
237 handle = GNUNET_malloc(sizeof(GNUNET_MESH_Handle)); 282 handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
238 283
239 return handle; 284 return handle;
240} 285}