diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-06 01:45:13 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-06 01:45:13 +0000 |
commit | 3252ddd73ea1639aba2159e7cc91681730470cbf (patch) | |
tree | 4a3cb369b49edf9cae76a1469dbac7c44598851d /src/mesh/mesh_api_new.c | |
parent | 76dcc3351564146f788e8a354cb3c42025db21cc (diff) | |
download | gnunet-3252ddd73ea1639aba2159e7cc91681730470cbf.tar.gz gnunet-3252ddd73ea1639aba2159e7cc91681730470cbf.zip |
WiP
Diffstat (limited to 'src/mesh/mesh_api_new.c')
-rw-r--r-- | src/mesh/mesh_api_new.c | 75 |
1 files changed, 60 insertions, 15 deletions
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 | */ |
43 | struct GNUNET_MESH_Handle { | 47 | struct 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 | */ | ||
81 | size_t | ||
82 | send_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 | } |