diff options
-rw-r--r-- | src/gns/gns_api.c | 416 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 8 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 10 |
3 files changed, 133 insertions, 301 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index a1fe3680a..8f821f715 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -63,50 +63,20 @@ struct GNUNET_GNS_LookupRequest | |||
63 | GNUNET_GNS_LookupResultProcessor lookup_proc; | 63 | GNUNET_GNS_LookupResultProcessor lookup_proc; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * processor closure | 66 | * @e lookup_proc closure |
67 | */ | 67 | */ |
68 | void *proc_cls; | 68 | void *proc_cls; |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * request id | 71 | * Envelope with the message for this queue entry. |
72 | */ | ||
73 | uint32_t r_id; | ||
74 | |||
75 | }; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Entry in our list of messages to be (re-)transmitted. | ||
80 | */ | ||
81 | struct PendingMessage | ||
82 | { | ||
83 | /** | ||
84 | * This is a doubly-linked list. | ||
85 | */ | ||
86 | struct PendingMessage *prev; | ||
87 | |||
88 | /** | ||
89 | * This is a doubly-linked list. | ||
90 | */ | 72 | */ |
91 | struct PendingMessage *next; | 73 | struct GNUNET_MQ_Envelope *env; |
92 | |||
93 | /** | ||
94 | * Size of the message. | ||
95 | */ | ||
96 | size_t size; | ||
97 | 74 | ||
98 | /** | 75 | /** |
99 | * request id | 76 | * request id |
100 | */ | 77 | */ |
101 | uint32_t r_id; | 78 | uint32_t r_id; |
102 | 79 | ||
103 | /** | ||
104 | * This message has been transmitted. GNUNET_NO if the message is | ||
105 | * in the "pending" DLL, GNUNET_YES if it has been transmitted to | ||
106 | * the service via the current client connection. | ||
107 | */ | ||
108 | int transmitted; | ||
109 | |||
110 | }; | 80 | }; |
111 | 81 | ||
112 | 82 | ||
@@ -122,39 +92,24 @@ struct GNUNET_GNS_Handle | |||
122 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 92 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
123 | 93 | ||
124 | /** | 94 | /** |
125 | * Socket (if available). | 95 | * Connection to service (if available). |
126 | */ | ||
127 | struct GNUNET_CLIENT_Connection *client; | ||
128 | |||
129 | /** | ||
130 | * Currently pending transmission request (or NULL). | ||
131 | */ | ||
132 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
133 | |||
134 | /** | ||
135 | * Head of linked list of shorten messages we would like to transmit. | ||
136 | */ | ||
137 | struct PendingMessage *pending_head; | ||
138 | |||
139 | /** | ||
140 | * Tail of linked list of shorten messages we would like to transmit. | ||
141 | */ | 96 | */ |
142 | struct PendingMessage *pending_tail; | 97 | struct GNUNET_MQ_Handle *mq; |
143 | 98 | ||
144 | /** | 99 | /** |
145 | * Head of linked list of lookup messages we would like to transmit. | 100 | * Head of linked list of active lookup requests. |
146 | */ | 101 | */ |
147 | struct GNUNET_GNS_LookupRequest *lookup_head; | 102 | struct GNUNET_GNS_LookupRequest *lookup_head; |
148 | 103 | ||
149 | /** | 104 | /** |
150 | * Tail of linked list of lookup messages we would like to transmit. | 105 | * Tail of linked list of active lookup requests. |
151 | */ | 106 | */ |
152 | struct GNUNET_GNS_LookupRequest *lookup_tail; | 107 | struct GNUNET_GNS_LookupRequest *lookup_tail; |
153 | 108 | ||
154 | /** | 109 | /** |
155 | * Reconnect task | 110 | * Reconnect task |
156 | */ | 111 | */ |
157 | struct GNUNET_SCHEDULER_Task * reconnect_task; | 112 | struct GNUNET_SCHEDULER_Task *reconnect_task; |
158 | 113 | ||
159 | /** | 114 | /** |
160 | * How long do we wait until we try to reconnect? | 115 | * How long do we wait until we try to reconnect? |
@@ -166,37 +121,16 @@ struct GNUNET_GNS_Handle | |||
166 | */ | 121 | */ |
167 | uint32_t r_id_gen; | 122 | uint32_t r_id_gen; |
168 | 123 | ||
169 | /** | ||
170 | * Did we start our receive loop yet? | ||
171 | */ | ||
172 | int in_receive; | ||
173 | |||
174 | }; | 124 | }; |
175 | 125 | ||
176 | 126 | ||
177 | /** | 127 | /** |
178 | * Try to send messages from list of messages to send | ||
179 | * @param handle GNS_Handle | ||
180 | */ | ||
181 | static void | ||
182 | process_pending_messages (struct GNUNET_GNS_Handle *handle); | ||
183 | |||
184 | |||
185 | /** | ||
186 | * Reconnect to GNS service. | 128 | * Reconnect to GNS service. |
187 | * | 129 | * |
188 | * @param handle the handle to the GNS service | 130 | * @param handle the handle to the GNS service |
189 | */ | 131 | */ |
190 | static void | 132 | static void |
191 | reconnect (struct GNUNET_GNS_Handle *handle) | 133 | reconnect (struct GNUNET_GNS_Handle *handle); |
192 | { | ||
193 | GNUNET_assert (NULL == handle->client); | ||
194 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
195 | "Trying to connect to GNS\n"); | ||
196 | handle->client = GNUNET_CLIENT_connect ("gns", handle->cfg); | ||
197 | GNUNET_assert (NULL != handle->client); | ||
198 | process_pending_messages (handle); | ||
199 | } | ||
200 | 134 | ||
201 | 135 | ||
202 | /** | 136 | /** |
@@ -222,23 +156,10 @@ reconnect_task (void *cls) | |||
222 | static void | 156 | static void |
223 | force_reconnect (struct GNUNET_GNS_Handle *handle) | 157 | force_reconnect (struct GNUNET_GNS_Handle *handle) |
224 | { | 158 | { |
225 | struct GNUNET_GNS_LookupRequest *lh; | 159 | GNUNET_MQ_destroy (handle->mq); |
226 | struct PendingMessage *p; | 160 | handle->mq = NULL; |
227 | 161 | handle->reconnect_backoff | |
228 | GNUNET_CLIENT_disconnect (handle->client); | 162 | = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); |
229 | handle->client = NULL; | ||
230 | handle->in_receive = GNUNET_NO; | ||
231 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) | ||
232 | { | ||
233 | p = (struct PendingMessage *) &lh[1]; | ||
234 | if (GNUNET_NO == p->transmitted) | ||
235 | continue; | ||
236 | p->transmitted = GNUNET_NO; | ||
237 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, | ||
238 | handle->pending_tail, | ||
239 | p); | ||
240 | } | ||
241 | handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); | ||
242 | handle->reconnect_task | 163 | handle->reconnect_task |
243 | = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, | 164 | = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, |
244 | &reconnect_task, | 165 | &reconnect_task, |
@@ -247,209 +168,124 @@ force_reconnect (struct GNUNET_GNS_Handle *handle) | |||
247 | 168 | ||
248 | 169 | ||
249 | /** | 170 | /** |
250 | * Transmit the next pending message, called by notify_transmit_ready | 171 | * Generic error handler, called with the appropriate error code and |
251 | * | 172 | * the same closure specified at the creation of the message queue. |
252 | * @param cls the closure | 173 | * Not every message queue implementation supports an error handler. |
253 | * @param size size of pending data | ||
254 | * @param buf buffer with pending data | ||
255 | * @return size data transmitted | ||
256 | */ | ||
257 | static size_t | ||
258 | transmit_pending (void *cls, size_t size, void *buf); | ||
259 | |||
260 | |||
261 | /** | ||
262 | * Handler for messages received from the GNS service | ||
263 | * | ||
264 | * @param cls the 'struct GNUNET_GNS_Handle' | ||
265 | * @param msg the incoming message | ||
266 | */ | ||
267 | static void | ||
268 | process_message (void *cls, const struct GNUNET_MessageHeader *msg); | ||
269 | |||
270 | |||
271 | /** | ||
272 | * Try to send messages from list of messages to send | ||
273 | * | 174 | * |
274 | * @param handle the GNS handle | 175 | * @param cls closure with the `struct GNUNET_GNS_Handle *` |
176 | * @param error error code | ||
275 | */ | 177 | */ |
276 | static void | 178 | static void |
277 | process_pending_messages (struct GNUNET_GNS_Handle *handle) | 179 | mq_error_handler (void *cls, |
180 | enum GNUNET_MQ_Error error) | ||
278 | { | 181 | { |
279 | struct PendingMessage *p = handle->pending_head; | 182 | struct GNUNET_GNS_Handle *handle = cls; |
280 | |||
281 | if (NULL == handle->client) | ||
282 | return; /* wait for reconnect */ | ||
283 | if (NULL != handle->th) | ||
284 | return; /* transmission request already pending */ | ||
285 | |||
286 | while ((NULL != p) && (p->transmitted == GNUNET_YES)) | ||
287 | p = p->next; | ||
288 | if (NULL == p) | ||
289 | return; /* no messages pending */ | ||
290 | 183 | ||
291 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 184 | force_reconnect (handle); |
292 | "Trying to transmit %u bytes\n", | ||
293 | (unsigned int) p->size); | ||
294 | handle->th = | ||
295 | GNUNET_CLIENT_notify_transmit_ready (handle->client, | ||
296 | p->size, | ||
297 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
298 | GNUNET_NO, &transmit_pending, | ||
299 | handle); | ||
300 | GNUNET_break (NULL != handle->th); | ||
301 | } | 185 | } |
302 | 186 | ||
303 | 187 | ||
304 | /** | 188 | /** |
305 | * Transmit the next pending message, called by notify_transmit_ready | 189 | * Check validity of message received from the GNS service |
306 | * | 190 | * |
307 | * @param cls the closure | 191 | * @param cls the `struct GNUNET_GNS_Handle *` |
308 | * @param size size of pending data | 192 | * @param loookup_msg the incoming message |
309 | * @param buf buffer with pending data | ||
310 | * @return size data transmitted | ||
311 | */ | 193 | */ |
312 | static size_t | 194 | static int |
313 | transmit_pending (void *cls, size_t size, void *buf) | 195 | check_result (void *cls, |
196 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg) | ||
314 | { | 197 | { |
315 | struct GNUNET_GNS_Handle *handle = cls; | 198 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); |
316 | char *cbuf = buf; | 199 | uint32_t rd_count = ntohl (lookup_msg->rd_count); |
317 | struct PendingMessage *p; | 200 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
318 | size_t tsize; | ||
319 | |||
320 | handle->th = NULL; | ||
321 | if ((0 == size) || (NULL == buf)) | ||
322 | { | ||
323 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
324 | "Transmission to GNS service failed!\n"); | ||
325 | force_reconnect (handle); | ||
326 | return 0; | ||
327 | } | ||
328 | if (NULL == (p = handle->pending_head)) | ||
329 | return 0; | ||
330 | 201 | ||
331 | tsize = 0; | 202 | if (GNUNET_SYSERR == |
332 | while ((NULL != (p = handle->pending_head)) && (p->size <= size)) | 203 | GNUNET_GNSRECORD_records_deserialize (mlen, |
204 | (const char*) &lookup_msg[1], | ||
205 | rd_count, | ||
206 | rd)) | ||
333 | { | 207 | { |
334 | memcpy (&cbuf[tsize], &p[1], p->size); | 208 | GNUNET_break (0); |
335 | tsize += p->size; | 209 | return GNUNET_SYSERR; |
336 | size -= p->size; | ||
337 | p->transmitted = GNUNET_YES; | ||
338 | GNUNET_CONTAINER_DLL_remove (handle->pending_head, | ||
339 | handle->pending_tail, | ||
340 | p); | ||
341 | if (GNUNET_YES != handle->in_receive) | ||
342 | { | ||
343 | GNUNET_CLIENT_receive (handle->client, &process_message, handle, | ||
344 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
345 | handle->in_receive = GNUNET_YES; | ||
346 | } | ||
347 | } | 210 | } |
348 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 211 | return GNUNET_OK; |
349 | "Sending %u bytes\n", | ||
350 | (unsigned int) tsize); | ||
351 | process_pending_messages (handle); | ||
352 | return tsize; | ||
353 | } | 212 | } |
354 | 213 | ||
355 | 214 | ||
356 | /** | 215 | /** |
357 | * Process a given reply to the lookup request | 216 | * Handler for messages received from the GNS service |
358 | * | 217 | * |
359 | * @param qe a queue entry | 218 | * @param cls the `struct GNUNET_GNS_Handle *` |
360 | * @param msg the lookup message received | 219 | * @param loookup_msg the incoming message |
361 | */ | 220 | */ |
362 | static void | 221 | static void |
363 | process_lookup_reply (struct GNUNET_GNS_LookupRequest *qe, | 222 | handle_result (void *cls, |
364 | const struct GNUNET_GNS_ClientLookupResultMessage *msg) | 223 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg) |
365 | { | 224 | { |
366 | struct GNUNET_GNS_Handle *handle = qe->gns_handle; | 225 | struct GNUNET_GNS_Handle *handle = cls; |
367 | struct PendingMessage *p = (struct PendingMessage *) &qe[1]; | 226 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); |
227 | uint32_t rd_count = ntohl (lookup_msg->rd_count); | ||
228 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | ||
229 | uint32_t r_id = ntohl (lookup_msg->id); | ||
230 | struct GNUNET_GNS_LookupRequest *lr; | ||
368 | GNUNET_GNS_LookupResultProcessor proc; | 231 | GNUNET_GNS_LookupResultProcessor proc; |
369 | void *proc_cls; | 232 | void *proc_cls; |
370 | uint32_t rd_count = ntohl (msg->rd_count); | ||
371 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | ||
372 | size_t mlen; | ||
373 | 233 | ||
374 | if (GNUNET_YES != p->transmitted) | 234 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
375 | { | 235 | "Received lookup reply from GNS service (%u records)\n", |
376 | /* service send reply to query we never managed to send!? */ | 236 | (unsigned int) rd_count); |
377 | GNUNET_break (0); | 237 | for (lr = handle->lookup_head; NULL != lr; lr = lr->next) |
378 | force_reconnect (handle); | 238 | if (lr->r_id == r_id) |
239 | break; | ||
240 | if (NULL == lr) | ||
379 | return; | 241 | return; |
380 | } | 242 | proc = lr->lookup_proc; |
381 | mlen = ntohs (msg->header.size); | 243 | proc_cls = lr->proc_cls; |
382 | mlen -= sizeof (struct GNUNET_GNS_ClientLookupResultMessage); | 244 | GNUNET_CONTAINER_DLL_remove (handle->lookup_head, |
383 | proc = qe->lookup_proc; | 245 | handle->lookup_tail, |
384 | proc_cls = qe->proc_cls; | 246 | lr); |
385 | GNUNET_CONTAINER_DLL_remove (handle->lookup_head, handle->lookup_tail, qe); | 247 | GNUNET_free (lr); |
386 | GNUNET_free (qe); | 248 | GNUNET_assert (GNUNET_OK == |
387 | if (GNUNET_SYSERR == GNUNET_GNSRECORD_records_deserialize (mlen, | 249 | GNUNET_GNSRECORD_records_deserialize (mlen, |
388 | (const char*) &msg[1], | 250 | (const char*) &lookup_msg[1], |
389 | rd_count, | 251 | rd_count, |
390 | rd)) | 252 | rd)); |
391 | { | 253 | proc (proc_cls, |
392 | LOG (GNUNET_ERROR_TYPE_ERROR, | 254 | rd_count, |
393 | _("Failed to deserialize lookup reply from GNS service!\n")); | 255 | rd); |
394 | proc (proc_cls, 0, NULL); | ||
395 | } | ||
396 | else | ||
397 | { | ||
398 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
399 | "Received lookup reply from GNS service (%u records)\n", | ||
400 | (unsigned int) rd_count); | ||
401 | proc (proc_cls, rd_count, rd); | ||
402 | } | ||
403 | } | 256 | } |
404 | 257 | ||
405 | 258 | ||
406 | /** | 259 | /** |
407 | * Handler for messages received from the GNS service | 260 | * Reconnect to GNS service. |
408 | * | 261 | * |
409 | * @param cls the 'struct GNUNET_GNS_Handle' | 262 | * @param handle the handle to the GNS service |
410 | * @param msg the incoming message | ||
411 | */ | 263 | */ |
412 | static void | 264 | static void |
413 | process_message (void *cls, const struct GNUNET_MessageHeader *msg) | 265 | reconnect (struct GNUNET_GNS_Handle *handle) |
414 | { | 266 | { |
415 | struct GNUNET_GNS_Handle *handle = cls; | 267 | GNUNET_MQ_hd_var_size (result, |
416 | struct GNUNET_GNS_LookupRequest *lr; | 268 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, |
417 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; | 269 | struct GNUNET_GNS_ClientLookupResultMessage); |
418 | uint32_t r_id; | 270 | struct GNUNET_MQ_MessageHandler handlers[] = { |
419 | 271 | make_result_handler (handle), | |
420 | if (NULL == msg) | 272 | GNUNET_MQ_handler_end () |
421 | { | 273 | }; |
422 | force_reconnect (handle); | 274 | struct GNUNET_GNS_LookupRequest *lh; |
423 | return; | ||
424 | } | ||
425 | 275 | ||
426 | GNUNET_CLIENT_receive (handle->client, &process_message, handle, | 276 | GNUNET_assert (NULL == handle->mq); |
427 | GNUNET_TIME_UNIT_FOREVER_REL); | 277 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
428 | switch (ntohs (msg->type)) | 278 | "Trying to connect to GNS\n"); |
429 | { | 279 | handle->mq = GNUNET_CLIENT_connecT (handle->cfg, |
430 | case GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT: | 280 | "gns", |
431 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 281 | handlers, |
432 | "Got LOOKUP_RESULT msg\n"); | 282 | &mq_error_handler, |
433 | if (ntohs (msg->size) < sizeof (struct GNUNET_GNS_ClientLookupResultMessage)) | 283 | handle); |
434 | { | 284 | if (NULL == handle->mq) |
435 | GNUNET_break (0); | ||
436 | force_reconnect (handle); | ||
437 | return; | ||
438 | } | ||
439 | lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg; | ||
440 | r_id = ntohl (lookup_msg->id); | ||
441 | for (lr = handle->lookup_head; NULL != lr; lr = lr->next) | ||
442 | if (lr->r_id == r_id) | ||
443 | { | ||
444 | process_lookup_reply(lr, lookup_msg); | ||
445 | break; | ||
446 | } | ||
447 | break; | ||
448 | default: | ||
449 | GNUNET_break (0); | ||
450 | force_reconnect (handle); | ||
451 | return; | 285 | return; |
452 | } | 286 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) |
287 | GNUNET_MQ_send_copy (handle->mq, | ||
288 | lh->env); | ||
453 | } | 289 | } |
454 | 290 | ||
455 | 291 | ||
@@ -467,6 +303,11 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
467 | handle = GNUNET_new (struct GNUNET_GNS_Handle); | 303 | handle = GNUNET_new (struct GNUNET_GNS_Handle); |
468 | handle->cfg = cfg; | 304 | handle->cfg = cfg; |
469 | reconnect (handle); | 305 | reconnect (handle); |
306 | if (NULL == handle->mq) | ||
307 | { | ||
308 | GNUNET_free (handle); | ||
309 | return NULL; | ||
310 | } | ||
470 | return handle; | 311 | return handle; |
471 | } | 312 | } |
472 | 313 | ||
@@ -479,10 +320,10 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
479 | void | 320 | void |
480 | GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | 321 | GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) |
481 | { | 322 | { |
482 | if (NULL != handle->client) | 323 | if (NULL != handle->mq) |
483 | { | 324 | { |
484 | GNUNET_CLIENT_disconnect (handle->client); | 325 | GNUNET_MQ_destroy (handle->mq); |
485 | handle->client = NULL; | 326 | handle->mq = NULL; |
486 | } | 327 | } |
487 | if (NULL != handle->reconnect_task) | 328 | if (NULL != handle->reconnect_task) |
488 | { | 329 | { |
@@ -502,16 +343,12 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | |||
502 | void | 343 | void |
503 | GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) | 344 | GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) |
504 | { | 345 | { |
505 | struct PendingMessage *p = (struct PendingMessage*) &lr[1]; | 346 | struct GNUNET_GNS_Handle *handle = lr->gns_handle; |
506 | 347 | ||
507 | GNUNET_assert (NULL != lr->gns_handle); | 348 | GNUNET_CONTAINER_DLL_remove (handle->lookup_head, |
508 | if (GNUNET_NO == p->transmitted) | 349 | handle->lookup_tail, |
509 | GNUNET_CONTAINER_DLL_remove (lr->gns_handle->pending_head, | ||
510 | lr->gns_handle->pending_tail, | ||
511 | p); | ||
512 | GNUNET_CONTAINER_DLL_remove (lr->gns_handle->lookup_head, | ||
513 | lr->gns_handle->lookup_tail, | ||
514 | lr); | 350 | lr); |
351 | GNUNET_MQ_discard (lr->env); | ||
515 | GNUNET_free (lr); | 352 | GNUNET_free (lr); |
516 | } | 353 | } |
517 | 354 | ||
@@ -542,8 +379,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
542 | /* IPC to shorten gns names, return shorten_handle */ | 379 | /* IPC to shorten gns names, return shorten_handle */ |
543 | struct GNUNET_GNS_ClientLookupMessage *lookup_msg; | 380 | struct GNUNET_GNS_ClientLookupMessage *lookup_msg; |
544 | struct GNUNET_GNS_LookupRequest *lr; | 381 | struct GNUNET_GNS_LookupRequest *lr; |
545 | size_t msize; | 382 | size_t nlen; |
546 | struct PendingMessage *pending; | ||
547 | 383 | ||
548 | if (NULL == name) | 384 | if (NULL == name) |
549 | { | 385 | { |
@@ -553,28 +389,20 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
553 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 389 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
554 | "Trying to lookup `%s' in GNS\n", | 390 | "Trying to lookup `%s' in GNS\n", |
555 | name); | 391 | name); |
556 | msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) | 392 | nlen = strlen (name) + 1; |
557 | + strlen (name) + 1; | 393 | if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*lr)) |
558 | if (msize > UINT16_MAX) | ||
559 | { | 394 | { |
560 | GNUNET_break (0); | 395 | GNUNET_break (0); |
561 | return NULL; | 396 | return NULL; |
562 | } | 397 | } |
563 | lr = GNUNET_malloc (sizeof (struct GNUNET_GNS_LookupRequest) + | 398 | lr = GNUNET_new (struct GNUNET_GNS_LookupRequest); |
564 | sizeof (struct PendingMessage) + msize); | ||
565 | lr->gns_handle = handle; | 399 | lr->gns_handle = handle; |
566 | lr->lookup_proc = proc; | 400 | lr->lookup_proc = proc; |
567 | lr->proc_cls = proc_cls; | 401 | lr->proc_cls = proc_cls; |
568 | lr->r_id = handle->r_id_gen++; | 402 | lr->r_id = handle->r_id_gen++; |
569 | pending = (struct PendingMessage *)&lr[1]; | 403 | lr->env = GNUNET_MQ_msg_extra (lookup_msg, |
570 | pending->size = msize; | 404 | nlen, |
571 | pending->r_id = lr->r_id; | 405 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP); |
572 | GNUNET_CONTAINER_DLL_insert_tail (handle->lookup_head, | ||
573 | handle->lookup_tail, lr); | ||
574 | |||
575 | lookup_msg = (struct GNUNET_GNS_ClientLookupMessage *) &pending[1]; | ||
576 | lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP); | ||
577 | lookup_msg->header.size = htons (msize); | ||
578 | lookup_msg->id = htonl (lr->r_id); | 406 | lookup_msg->id = htonl (lr->r_id); |
579 | lookup_msg->options = htons ((uint16_t) options); | 407 | lookup_msg->options = htons ((uint16_t) options); |
580 | lookup_msg->zone = *zone; | 408 | lookup_msg->zone = *zone; |
@@ -584,11 +412,15 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
584 | lookup_msg->have_key = htons (GNUNET_YES); | 412 | lookup_msg->have_key = htons (GNUNET_YES); |
585 | lookup_msg->shorten_key = *shorten_zone_key; | 413 | lookup_msg->shorten_key = *shorten_zone_key; |
586 | } | 414 | } |
587 | memcpy (&lookup_msg[1], name, strlen (name) + 1); | 415 | memcpy (&lookup_msg[1], |
588 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, | 416 | name, |
589 | handle->pending_tail, | 417 | nlen); |
590 | pending); | 418 | GNUNET_CONTAINER_DLL_insert (handle->lookup_head, |
591 | process_pending_messages (handle); | 419 | handle->lookup_tail, |
420 | lr); | ||
421 | if (NULL != handle->mq) | ||
422 | GNUNET_MQ_send_copy (handle->mq, | ||
423 | lr->env); | ||
592 | return lr; | 424 | return lr; |
593 | } | 425 | } |
594 | 426 | ||
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 5e1b5830f..e2bb0ad8c 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -706,9 +706,8 @@ send_lookup_response (void* cls, | |||
706 | size_t len; | 706 | size_t len; |
707 | 707 | ||
708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
709 | "Sending `%s' message with %d results\n", | 709 | "Sending LOOKUP_RESULT message with %u results\n", |
710 | "LOOKUP_RESULT", | 710 | (unsigned int) rd_count); |
711 | rd_count); | ||
712 | 711 | ||
713 | len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 712 | len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); |
714 | rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage)); | 713 | rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage)); |
@@ -757,8 +756,7 @@ handle_lookup (void *cls, | |||
757 | const struct GNUNET_GNS_ClientLookupMessage *sh_msg; | 756 | const struct GNUNET_GNS_ClientLookupMessage *sh_msg; |
758 | 757 | ||
759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
760 | "Received `%s' message\n", | 759 | "Received LOOKUP message\n"); |
761 | "LOOKUP"); | ||
762 | msg_size = ntohs (message->size); | 760 | msg_size = ntohs (message->size); |
763 | if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | 761 | if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) |
764 | { | 762 | { |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index daae46ab7..2dec9a2af 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -2537,12 +2537,14 @@ GNS_resolver_init (struct GNUNET_NAMECACHE_Handle *nc, | |||
2537 | dht_lookup_heap = | 2537 | dht_lookup_heap = |
2538 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2538 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2539 | max_allowed_background_queries = max_bg_queries; | 2539 | max_allowed_background_queries = max_bg_queries; |
2540 | if (GNUNET_SYSERR == (use_cache = GNUNET_CONFIGURATION_get_value_yesno (c, | 2540 | if (GNUNET_SYSERR == (use_cache = |
2541 | "gns", | 2541 | GNUNET_CONFIGURATION_get_value_yesno (c, |
2542 | "USE_CACHE"))) | 2542 | "gns", |
2543 | "USE_CACHE"))) | ||
2543 | use_cache = GNUNET_YES; | 2544 | use_cache = GNUNET_YES; |
2544 | if (GNUNET_NO == use_cache) | 2545 | if (GNUNET_NO == use_cache) |
2545 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namecache disabled\n"); | 2546 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2547 | "Namecache disabled\n"); | ||
2546 | 2548 | ||
2547 | if (GNUNET_OK != | 2549 | if (GNUNET_OK != |
2548 | GNUNET_CONFIGURATION_get_value_string (c, | 2550 | GNUNET_CONFIGURATION_get_value_string (c, |