diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-05-12 14:01:29 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-05-12 14:01:29 +0000 |
commit | d75e6e4273b1bb43b5ca9f6b207c10fc824efbae (patch) | |
tree | 4b2548eabb82b8a00df676558125640fe72eac3c /src/mesh/mesh_api_new.c | |
parent | d95d14541ab481ad4697a432b5598535af07804c (diff) | |
download | gnunet-d75e6e4273b1bb43b5ca9f6b207c10fc824efbae.tar.gz gnunet-d75e6e4273b1bb43b5ca9f6b207c10fc824efbae.zip |
fixes
Diffstat (limited to 'src/mesh/mesh_api_new.c')
-rw-r--r-- | src/mesh/mesh_api_new.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index ca68279ed..989b526ae 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -76,6 +76,9 @@ struct GNUNET_MESH_Handle { | |||
76 | */ | 76 | */ |
77 | GNUNET_MESH_TunnelEndHandler *cleaner; | 77 | GNUNET_MESH_TunnelEndHandler *cleaner; |
78 | 78 | ||
79 | |||
80 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
81 | |||
79 | /** | 82 | /** |
80 | * Closure for all the handlers given by the client | 83 | * Closure for all the handlers given by the client |
81 | */ | 84 | */ |
@@ -127,26 +130,28 @@ struct GNUNET_MESH_TransmitHandle { | |||
127 | * @param buf where the callee should write the message | 130 | * @param buf where the callee should write the message |
128 | * @return number of bytes written to buf | 131 | * @return number of bytes written to buf |
129 | */ | 132 | */ |
130 | size_t | 133 | static size_t |
131 | send_connect_packet (void *cls, size_t size, void *buf) { | 134 | send_connect_packet (void *cls, size_t size, void *buf) { |
132 | struct GNUNET_MESH_Handle *h; | 135 | struct GNUNET_MESH_Handle *h = cls; |
133 | struct GNUNET_MESH_ClientConnect *msg; | 136 | struct GNUNET_MESH_ClientConnect *msg; |
134 | uint16_t *types; | 137 | uint16_t *types; |
135 | int ntypes; | 138 | int ntypes; |
136 | GNUNET_MESH_ApplicationType *apps; | 139 | GNUNET_MESH_ApplicationType *apps; |
137 | int napps; | 140 | int napps; |
138 | 141 | ||
139 | if(0 == size || buf == NULL) { | 142 | h->th = NULL; |
143 | if (0 == size || buf == NULL) { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n"); | 144 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n"); |
145 | // FIXME: disconnect, reconnect, retry! | ||
141 | return 0; | 146 | return 0; |
142 | } | 147 | } |
143 | if(sizeof(struct GNUNET_MessageHeader) > size) { | 148 | if (sizeof(struct GNUNET_MessageHeader) > size) { |
144 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n"); | 149 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n"); |
150 | // FIXME: disconnect, reconnect, retry! | ||
145 | return 0; | 151 | return 0; |
146 | } | 152 | } |
147 | 153 | ||
148 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | 154 | msg = (struct GNUNET_MESH_ClientConnect *) buf; |
149 | h = (struct GNUNET_MESH_Handle *) cls; | ||
150 | msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; | 155 | msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; |
151 | 156 | ||
152 | for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { | 157 | for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { |
@@ -219,7 +224,8 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
219 | void *cls, | 224 | void *cls, |
220 | GNUNET_MESH_TunnelEndHandler cleaner, | 225 | GNUNET_MESH_TunnelEndHandler cleaner, |
221 | const struct GNUNET_MESH_MessageHandler *handlers, | 226 | const struct GNUNET_MESH_MessageHandler *handlers, |
222 | const GNUNET_MESH_ApplicationType *stypes) { | 227 | const GNUNET_MESH_ApplicationType *stypes) |
228 | { | ||
223 | struct GNUNET_MESH_Handle *h; | 229 | struct GNUNET_MESH_Handle *h; |
224 | size_t size; | 230 | size_t size; |
225 | 231 | ||
@@ -247,12 +253,12 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
247 | size += h->n_handlers * sizeof(uint16_t); | 253 | size += h->n_handlers * sizeof(uint16_t); |
248 | size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType); | 254 | size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType); |
249 | 255 | ||
250 | GNUNET_CLIENT_notify_transmit_ready(h->mesh, | 256 | h->th = GNUNET_CLIENT_notify_transmit_ready(h->mesh, |
251 | size, | 257 | size, |
252 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 258 | GNUNET_TIME_UNIT_FOREVER_REL, |
253 | GNUNET_NO, | 259 | GNUNET_YES, |
254 | &send_connect_packet, | 260 | &send_connect_packet, |
255 | (void *)h); | 261 | (void *)h); |
256 | 262 | ||
257 | return h; | 263 | return h; |
258 | } | 264 | } |
@@ -263,10 +269,14 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
263 | * | 269 | * |
264 | * @param handle connection to mesh to disconnect | 270 | * @param handle connection to mesh to disconnect |
265 | */ | 271 | */ |
266 | void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) { | 272 | void |
267 | 273 | GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |
268 | GNUNET_free(handle); | 274 | { |
269 | return; | 275 | if (NULL != handle->th) |
276 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); | ||
277 | if (NULL != handle->mesh) | ||
278 | GNUNET_CLIENT_disconnect (handle->mesh, GNUNET_NO); | ||
279 | GNUNET_free(handle); | ||
270 | } | 280 | } |
271 | 281 | ||
272 | 282 | ||