diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-22 10:28:34 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-22 10:28:34 +0000 |
commit | 5db95e117a3b51fcbbec805e67052b66939efcbd (patch) | |
tree | 855f4d47ba4ba82f355d37ece58307d0f967b2c3 | |
parent | 9a95c9be3058fb417ca6848a8d8acbd09c7c08dd (diff) | |
download | gnunet-5db95e117a3b51fcbbec805e67052b66939efcbd.tar.gz gnunet-5db95e117a3b51fcbbec805e67052b66939efcbd.zip |
- changes
-rw-r--r-- | src/namestore/namestore_api.c | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index ad881f18d..28f304d08 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -146,6 +146,45 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh); | |||
146 | static void | 146 | static void |
147 | do_transmit (struct GNUNET_NAMESTORE_Handle *nsh); | 147 | do_transmit (struct GNUNET_NAMESTORE_Handle *nsh); |
148 | 148 | ||
149 | |||
150 | /** | ||
151 | * Type of a function to call when we receive a message | ||
152 | * from the service. | ||
153 | * | ||
154 | * @param cls the 'struct GNUNET_NAMESTORE_SchedulingHandle' | ||
155 | * @param msg message received, NULL on timeout or fatal error | ||
156 | */ | ||
157 | static void | ||
158 | process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) | ||
159 | { | ||
160 | struct GNUNET_NAMESTORE_Handle *nsh = cls; | ||
161 | uint16_t size; | ||
162 | uint16_t type; | ||
163 | |||
164 | if (NULL == msg) | ||
165 | { | ||
166 | force_reconnect (nsh); | ||
167 | return; | ||
168 | } | ||
169 | |||
170 | size = ntohs (msg->size); | ||
171 | type = ntohs (msg->type); | ||
172 | |||
173 | switch (type) { | ||
174 | case GNUNET_MESSAGE_TYPE_TEST: | ||
175 | /* handle message here */ | ||
176 | break; | ||
177 | default: | ||
178 | break; | ||
179 | } | ||
180 | |||
181 | GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh, | ||
182 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
183 | |||
184 | if (GNUNET_YES == nsh->reconnect) | ||
185 | force_reconnect (nsh); | ||
186 | } | ||
187 | |||
149 | /** | 188 | /** |
150 | * We can now transmit a message to NAMESTORE. Do it. | 189 | * We can now transmit a message to NAMESTORE. Do it. |
151 | * | 190 | * |
@@ -177,7 +216,7 @@ transmit_message_to_namestore (void *cls, size_t size, void *buf) | |||
177 | size -= p->size; | 216 | size -= p->size; |
178 | GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p); | 217 | GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p); |
179 | if (GNUNET_YES == p->is_init) | 218 | if (GNUNET_YES == p->is_init) |
180 | GNUNET_CLIENT_receive (nsh->client,/* &process_namestore_message*/ NULL, nsh, | 219 | GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh, |
181 | GNUNET_TIME_UNIT_FOREVER_REL); | 220 | GNUNET_TIME_UNIT_FOREVER_REL); |
182 | GNUNET_free (p); | 221 | GNUNET_free (p); |
183 | } | 222 | } |
@@ -267,8 +306,8 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh) | |||
267 | nsh->reconnect = GNUNET_NO; | 306 | nsh->reconnect = GNUNET_NO; |
268 | GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO); | 307 | GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO); |
269 | nsh->client = NULL; | 308 | nsh->client = NULL; |
270 | nsh->reconnect_task = | 309 | nsh->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
271 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, | 310 | &reconnect_task, |
272 | nsh); | 311 | nsh); |
273 | } | 312 | } |
274 | 313 | ||
@@ -298,9 +337,27 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
298 | * @param handle handle of the NAMESTORE connection to stop | 337 | * @param handle handle of the NAMESTORE connection to stop |
299 | */ | 338 | */ |
300 | void | 339 | void |
301 | GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *handle, int drop) | 340 | GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *nsh, int drop) |
302 | { | 341 | { |
303 | GNUNET_free(handle); | 342 | struct PendingMessage *p; |
343 | |||
344 | while (NULL != (p = nsh->pending_head)) | ||
345 | { | ||
346 | GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p); | ||
347 | GNUNET_free (p); | ||
348 | } | ||
349 | if (NULL != nsh->client) | ||
350 | { | ||
351 | GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO); | ||
352 | nsh->client = NULL; | ||
353 | } | ||
354 | if (GNUNET_SCHEDULER_NO_TASK != nsh->reconnect_task) | ||
355 | { | ||
356 | GNUNET_SCHEDULER_cancel (nsh->reconnect_task); | ||
357 | nsh->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
358 | } | ||
359 | GNUNET_free(nsh); | ||
360 | nsh = NULL; | ||
304 | } | 361 | } |
305 | 362 | ||
306 | /** | 363 | /** |