aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_clients.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-dht_clients.c')
-rw-r--r--src/dht/gnunet-service-dht_clients.c1395
1 files changed, 695 insertions, 700 deletions
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index 7e2440841..48017bfb4 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_clients.c 22 * @file dht/gnunet-service-dht_clients.c
@@ -38,9 +38,9 @@
38/** 38/**
39 * Should routing details be logged to stderr (for debugging)? 39 * Should routing details be logged to stderr (for debugging)?
40 */ 40 */
41#define LOG_TRAFFIC(kind,...) GNUNET_log_from (kind, "dht-traffic",__VA_ARGS__) 41#define LOG_TRAFFIC(kind, ...) GNUNET_log_from(kind, "dht-traffic", __VA_ARGS__)
42 42
43#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__) 43#define LOG(kind, ...) GNUNET_log_from(kind, "dht-clients", __VA_ARGS__)
44 44
45 45
46/** 46/**
@@ -54,9 +54,7 @@ struct ClientHandle;
54/** 54/**
55 * Entry in the local forwarding map for a client's GET request. 55 * Entry in the local forwarding map for a client's GET request.
56 */ 56 */
57struct ClientQueryRecord 57struct ClientQueryRecord {
58{
59
60 /** 58 /**
61 * The key this request was about 59 * The key this request was about
62 */ 60 */
@@ -132,16 +130,13 @@ struct ClientQueryRecord
132 * The type for the data for the GET request. 130 * The type for the data for the GET request.
133 */ 131 */
134 enum GNUNET_BLOCK_Type type; 132 enum GNUNET_BLOCK_Type type;
135
136}; 133};
137 134
138 135
139/** 136/**
140 * Struct containing paremeters of monitoring requests. 137 * Struct containing paremeters of monitoring requests.
141 */ 138 */
142struct ClientMonitorRecord 139struct ClientMonitorRecord {
143{
144
145 /** 140 /**
146 * Next element in DLL. 141 * Next element in DLL.
147 */ 142 */
@@ -189,8 +184,7 @@ struct ClientMonitorRecord
189 * handle to connect to it, and any pending messages 184 * handle to connect to it, and any pending messages
190 * that need to be sent to it. 185 * that need to be sent to it.
191 */ 186 */
192struct ClientHandle 187struct ClientHandle {
193{
194 /** 188 /**
195 * Linked list of active queries of this client. 189 * Linked list of active queries of this client.
196 */ 190 */
@@ -210,7 +204,6 @@ struct ClientHandle
210 * The message queue to this client 204 * The message queue to this client
211 */ 205 */
212 struct GNUNET_MQ_Handle *mq; 206 struct GNUNET_MQ_Handle *mq;
213
214}; 207};
215 208
216/** 209/**
@@ -265,23 +258,23 @@ static struct GNUNET_SCHEDULER_Task *retry_task;
265 * @param record record to remove 258 * @param record record to remove
266 */ 259 */
267static void 260static void
268remove_client_record (struct ClientQueryRecord *record) 261remove_client_record(struct ClientQueryRecord *record)
269{ 262{
270 struct ClientHandle *ch = record->ch; 263 struct ClientHandle *ch = record->ch;
271 264
272 GNUNET_CONTAINER_DLL_remove (ch->cqr_head, 265 GNUNET_CONTAINER_DLL_remove(ch->cqr_head,
273 ch->cqr_tail, 266 ch->cqr_tail,
274 record); 267 record);
275 GNUNET_assert (GNUNET_YES == 268 GNUNET_assert(GNUNET_YES ==
276 GNUNET_CONTAINER_multihashmap_remove (forward_map, 269 GNUNET_CONTAINER_multihashmap_remove(forward_map,
277 &record->key, 270 &record->key,
278 record)); 271 record));
279 if (NULL != record->hnode) 272 if (NULL != record->hnode)
280 GNUNET_CONTAINER_heap_remove_node (record->hnode); 273 GNUNET_CONTAINER_heap_remove_node(record->hnode);
281 GNUNET_array_grow (record->seen_replies, 274 GNUNET_array_grow(record->seen_replies,
282 record->seen_replies_count, 275 record->seen_replies_count,
283 0); 276 0);
284 GNUNET_free (record); 277 GNUNET_free(record);
285} 278}
286 279
287 280
@@ -295,13 +288,13 @@ remove_client_record (struct ClientQueryRecord *record)
295 * @return our `struct ClientHandle` for @a client 288 * @return our `struct ClientHandle` for @a client
296 */ 289 */
297static void * 290static void *
298client_connect_cb (void *cls, 291client_connect_cb(void *cls,
299 struct GNUNET_SERVICE_Client *client, 292 struct GNUNET_SERVICE_Client *client,
300 struct GNUNET_MQ_Handle *mq) 293 struct GNUNET_MQ_Handle *mq)
301{ 294{
302 struct ClientHandle *ch; 295 struct ClientHandle *ch;
303 296
304 ch = GNUNET_new (struct ClientHandle); 297 ch = GNUNET_new(struct ClientHandle);
305 ch->client = client; 298 ch->client = client;
306 ch->mq = mq; 299 ch->mq = mq;
307 return ch; 300 return ch;
@@ -317,40 +310,40 @@ client_connect_cb (void *cls,
317 * @param app_ctx our `struct ClientHandle` for @a client 310 * @param app_ctx our `struct ClientHandle` for @a client
318 */ 311 */
319static void 312static void
320client_disconnect_cb (void *cls, 313client_disconnect_cb(void *cls,
321 struct GNUNET_SERVICE_Client *client, 314 struct GNUNET_SERVICE_Client *client,
322 void *app_ctx) 315 void *app_ctx)
323{ 316{
324 struct ClientHandle *ch = app_ctx; 317 struct ClientHandle *ch = app_ctx;
325 struct ClientQueryRecord *cqr; 318 struct ClientQueryRecord *cqr;
326 struct ClientMonitorRecord *monitor; 319 struct ClientMonitorRecord *monitor;
327 320
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
329 "Local client %p disconnects\n", 322 "Local client %p disconnects\n",
330 ch); 323 ch);
331 monitor = monitor_head; 324 monitor = monitor_head;
332 while (NULL != monitor) 325 while (NULL != monitor)
333 {
334 if (monitor->ch == ch)
335 {
336 struct ClientMonitorRecord *next;
337
338 next = monitor->next;
339 GNUNET_free_non_null (monitor->key);
340 GNUNET_CONTAINER_DLL_remove (monitor_head,
341 monitor_tail,
342 monitor);
343 GNUNET_free (monitor);
344 monitor = next;
345 }
346 else
347 { 326 {
348 monitor = monitor->next; 327 if (monitor->ch == ch)
328 {
329 struct ClientMonitorRecord *next;
330
331 next = monitor->next;
332 GNUNET_free_non_null(monitor->key);
333 GNUNET_CONTAINER_DLL_remove(monitor_head,
334 monitor_tail,
335 monitor);
336 GNUNET_free(monitor);
337 monitor = next;
338 }
339 else
340 {
341 monitor = monitor->next;
342 }
349 } 343 }
350 }
351 while (NULL != (cqr = ch->cqr_head)) 344 while (NULL != (cqr = ch->cqr_head))
352 remove_client_record (cqr); 345 remove_client_record(cqr);
353 GNUNET_free (ch); 346 GNUNET_free(ch);
354} 347}
355 348
356 349
@@ -360,52 +353,52 @@ client_disconnect_cb (void *cls,
360 * message and initiating the routing operation. 353 * message and initiating the routing operation.
361 */ 354 */
362static void 355static void
363transmit_request (struct ClientQueryRecord *cqr) 356transmit_request(struct ClientQueryRecord *cqr)
364{ 357{
365 struct GNUNET_BLOCK_Group *bg; 358 struct GNUNET_BLOCK_Group *bg;
366 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 359 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
367 360
368 GNUNET_STATISTICS_update (GDS_stats, 361 GNUNET_STATISTICS_update(GDS_stats,
369 gettext_noop ("# GET requests from clients injected"), 362 gettext_noop("# GET requests from clients injected"),
370 1, 363 1,
371 GNUNET_NO); 364 GNUNET_NO);
372 bg = GNUNET_BLOCK_group_create (GDS_block_context, 365 bg = GNUNET_BLOCK_group_create(GDS_block_context,
373 cqr->type, 366 cqr->type,
374 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 367 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
375 UINT32_MAX), 368 UINT32_MAX),
376 NULL, 369 NULL,
377 0, 370 0,
378 "seen-set-size", 371 "seen-set-size",
379 cqr->seen_replies_count, 372 cqr->seen_replies_count,
380 NULL); 373 NULL);
381 GNUNET_BLOCK_group_set_seen (bg, 374 GNUNET_BLOCK_group_set_seen(bg,
382 cqr->seen_replies, 375 cqr->seen_replies,
383 cqr->seen_replies_count); 376 cqr->seen_replies_count);
384 peer_bf 377 peer_bf
385 = GNUNET_CONTAINER_bloomfilter_init (NULL, 378 = GNUNET_CONTAINER_bloomfilter_init(NULL,
386 DHT_BLOOM_SIZE, 379 DHT_BLOOM_SIZE,
387 GNUNET_CONSTANTS_BLOOMFILTER_K); 380 GNUNET_CONSTANTS_BLOOMFILTER_K);
388 LOG (GNUNET_ERROR_TYPE_DEBUG, 381 LOG(GNUNET_ERROR_TYPE_DEBUG,
389 "Initiating GET for %s, replication %u, already have %u replies\n", 382 "Initiating GET for %s, replication %u, already have %u replies\n",
390 GNUNET_h2s (&cqr->key), 383 GNUNET_h2s(&cqr->key),
391 cqr->replication, 384 cqr->replication,
392 cqr->seen_replies_count); 385 cqr->seen_replies_count);
393 GDS_NEIGHBOURS_handle_get (cqr->type, 386 GDS_NEIGHBOURS_handle_get(cqr->type,
394 cqr->msg_options, 387 cqr->msg_options,
395 cqr->replication, 388 cqr->replication,
396 0 /* hop count */ , 389 0 /* hop count */,
397 &cqr->key, 390 &cqr->key,
398 cqr->xquery, 391 cqr->xquery,
399 cqr->xquery_size, 392 cqr->xquery_size,
400 bg, 393 bg,
401 peer_bf); 394 peer_bf);
402 GNUNET_BLOCK_group_destroy (bg); 395 GNUNET_BLOCK_group_destroy(bg);
403 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 396 GNUNET_CONTAINER_bloomfilter_free(peer_bf);
404 397
405 /* exponential back-off for retries. 398 /* exponential back-off for retries.
406 * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ 399 * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
407 cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); 400 cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF(cqr->retry_frequency);
408 cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); 401 cqr->retry_time = GNUNET_TIME_relative_to_absolute(cqr->retry_frequency);
409} 402}
410 403
411 404
@@ -417,34 +410,34 @@ transmit_request (struct ClientQueryRecord *cqr)
417 * @param cls unused 410 * @param cls unused
418 */ 411 */
419static void 412static void
420transmit_next_request_task (void *cls) 413transmit_next_request_task(void *cls)
421{ 414{
422 struct ClientQueryRecord *cqr; 415 struct ClientQueryRecord *cqr;
423 struct GNUNET_TIME_Relative delay; 416 struct GNUNET_TIME_Relative delay;
424 417
425 retry_task = NULL; 418 retry_task = NULL;
426 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) 419 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root(retry_heap)))
427 {
428 cqr->hnode = NULL;
429 delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time);
430 if (delay.rel_value_us > 0)
431 { 420 {
421 cqr->hnode = NULL;
422 delay = GNUNET_TIME_absolute_get_remaining(cqr->retry_time);
423 if (delay.rel_value_us > 0)
424 {
425 cqr->hnode
426 = GNUNET_CONTAINER_heap_insert(retry_heap,
427 cqr,
428 cqr->retry_time.abs_value_us);
429 retry_task
430 = GNUNET_SCHEDULER_add_at(cqr->retry_time,
431 &transmit_next_request_task,
432 NULL);
433 return;
434 }
435 transmit_request(cqr);
432 cqr->hnode 436 cqr->hnode
433 = GNUNET_CONTAINER_heap_insert (retry_heap, 437 = GNUNET_CONTAINER_heap_insert(retry_heap,
434 cqr, 438 cqr,
435 cqr->retry_time.abs_value_us); 439 cqr->retry_time.abs_value_us);
436 retry_task
437 = GNUNET_SCHEDULER_add_at (cqr->retry_time,
438 &transmit_next_request_task,
439 NULL);
440 return;
441 } 440 }
442 transmit_request (cqr);
443 cqr->hnode
444 = GNUNET_CONTAINER_heap_insert (retry_heap,
445 cqr,
446 cqr->retry_time.abs_value_us);
447 }
448} 441}
449 442
450 443
@@ -456,8 +449,8 @@ transmit_next_request_task (void *cls)
456 * @return #GNUNET_OK (always) 449 * @return #GNUNET_OK (always)
457 */ 450 */
458static int 451static int
459check_dht_local_put (void *cls, 452check_dht_local_put(void *cls,
460 const struct GNUNET_DHT_ClientPutMessage *dht_msg) 453 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
461{ 454{
462 /* always well-formed */ 455 /* always well-formed */
463 return GNUNET_OK; 456 return GNUNET_OK;
@@ -471,71 +464,71 @@ check_dht_local_put (void *cls,
471 * @param dht_msg the actual message received 464 * @param dht_msg the actual message received
472 */ 465 */
473static void 466static void
474handle_dht_local_put (void *cls, 467handle_dht_local_put(void *cls,
475 const struct GNUNET_DHT_ClientPutMessage *dht_msg) 468 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
476{ 469{
477 struct ClientHandle *ch = cls; 470 struct ClientHandle *ch = cls;
478 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 471 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
479 uint16_t size; 472 uint16_t size;
480 473
481 size = ntohs (dht_msg->header.size); 474 size = ntohs(dht_msg->header.size);
482 GNUNET_STATISTICS_update (GDS_stats, 475 GNUNET_STATISTICS_update(GDS_stats,
483 gettext_noop ("# PUT requests received from clients"), 476 gettext_noop("# PUT requests received from clients"),
484 1, 477 1,
485 GNUNET_NO); 478 GNUNET_NO);
486 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 479 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
487 "CLIENT-PUT %s\n", 480 "CLIENT-PUT %s\n",
488 GNUNET_h2s_full (&dht_msg->key)); 481 GNUNET_h2s_full(&dht_msg->key));
489 /* give to local clients */ 482 /* give to local clients */
490 LOG (GNUNET_ERROR_TYPE_DEBUG, 483 LOG(GNUNET_ERROR_TYPE_DEBUG,
491 "Handling local PUT of %u-bytes for query %s\n", 484 "Handling local PUT of %u-bytes for query %s\n",
492 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 485 size - sizeof(struct GNUNET_DHT_ClientPutMessage),
493 GNUNET_h2s (&dht_msg->key)); 486 GNUNET_h2s(&dht_msg->key));
494 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 487 GDS_CLIENTS_handle_reply(GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
495 &dht_msg->key, 488 &dht_msg->key,
496 0, 489 0,
497 NULL, 490 NULL,
498 0, 491 0,
499 NULL, 492 NULL,
500 ntohl (dht_msg->type), 493 ntohl(dht_msg->type),
501 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 494 size - sizeof(struct GNUNET_DHT_ClientPutMessage),
502 &dht_msg[1]); 495 &dht_msg[1]);
503 /* store locally */ 496 /* store locally */
504 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 497 GDS_DATACACHE_handle_put(GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
498 &dht_msg->key,
499 0,
500 NULL,
501 ntohl(dht_msg->type),
502 size - sizeof(struct GNUNET_DHT_ClientPutMessage),
503 &dht_msg[1]);
504 /* route to other peers */
505 peer_bf
506 = GNUNET_CONTAINER_bloomfilter_init(NULL,
507 DHT_BLOOM_SIZE,
508 GNUNET_CONSTANTS_BLOOMFILTER_K);
509 GDS_NEIGHBOURS_handle_put(ntohl(dht_msg->type),
510 ntohl(dht_msg->options),
511 ntohl(dht_msg->desired_replication_level),
512 GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
513 0 /* hop count */,
514 peer_bf,
505 &dht_msg->key, 515 &dht_msg->key,
506 0, 516 0,
507 NULL, 517 NULL,
508 ntohl (dht_msg->type), 518 &dht_msg[1],
509 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 519 size - sizeof(struct GNUNET_DHT_ClientPutMessage));
510 &dht_msg[1]); 520 GDS_CLIENTS_process_put(ntohl(dht_msg->options),
511 /* route to other peers */ 521 ntohl(dht_msg->type),
512 peer_bf 522 0,
513 = GNUNET_CONTAINER_bloomfilter_init (NULL, 523 ntohl(dht_msg->desired_replication_level),
514 DHT_BLOOM_SIZE, 524 1,
515 GNUNET_CONSTANTS_BLOOMFILTER_K); 525 GDS_NEIGHBOURS_get_id(),
516 GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), 526 GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
517 ntohl (dht_msg->options), 527 &dht_msg->key,
518 ntohl (dht_msg->desired_replication_level), 528 &dht_msg[1],
519 GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 529 size - sizeof(struct GNUNET_DHT_ClientPutMessage));
520 0 /* hop count */, 530 GNUNET_CONTAINER_bloomfilter_free(peer_bf);
521 peer_bf, 531 GNUNET_SERVICE_client_continue(ch->client);
522 &dht_msg->key,
523 0,
524 NULL,
525 &dht_msg[1],
526 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
527 GDS_CLIENTS_process_put (ntohl (dht_msg->options),
528 ntohl (dht_msg->type),
529 0,
530 ntohl (dht_msg->desired_replication_level),
531 1,
532 GDS_NEIGHBOURS_get_id(),
533 GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
534 &dht_msg->key,
535 &dht_msg[1],
536 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
537 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
538 GNUNET_SERVICE_client_continue (ch->client);
539} 532}
540 533
541 534
@@ -547,8 +540,8 @@ handle_dht_local_put (void *cls,
547 * @return #GNUNET_OK (always) 540 * @return #GNUNET_OK (always)
548 */ 541 */
549static int 542static int
550check_dht_local_get (void *cls, 543check_dht_local_get(void *cls,
551 const struct GNUNET_DHT_ClientGetMessage *get) 544 const struct GNUNET_DHT_ClientGetMessage *get)
552{ 545{
553 /* always well-formed */ 546 /* always well-formed */
554 return GNUNET_OK; 547 return GNUNET_OK;
@@ -570,25 +563,25 @@ check_dht_local_get (void *cls,
570 * @param data_size number of bytes in @a data 563 * @param data_size number of bytes in @a data
571 */ 564 */
572static void 565static void
573handle_local_result (void *cls, 566handle_local_result(void *cls,
574 enum GNUNET_BLOCK_Type type, 567 enum GNUNET_BLOCK_Type type,
575 struct GNUNET_TIME_Absolute expiration_time, 568 struct GNUNET_TIME_Absolute expiration_time,
576 const struct GNUNET_HashCode *key, 569 const struct GNUNET_HashCode *key,
577 unsigned int put_path_length, 570 unsigned int put_path_length,
578 const struct GNUNET_PeerIdentity *put_path, 571 const struct GNUNET_PeerIdentity *put_path,
579 unsigned int get_path_length, 572 unsigned int get_path_length,
580 const struct GNUNET_PeerIdentity *get_path, 573 const struct GNUNET_PeerIdentity *get_path,
581 const void *data, 574 const void *data,
582 size_t data_size) 575 size_t data_size)
583{ 576{
584 // FIXME: this needs some clean up: inline the function, 577 // FIXME: this needs some clean up: inline the function,
585 // possibly avoid even looking up the client! 578 // possibly avoid even looking up the client!
586 GDS_CLIENTS_handle_reply (expiration_time, 579 GDS_CLIENTS_handle_reply(expiration_time,
587 key, 580 key,
588 0, NULL, 581 0, NULL,
589 put_path_length, put_path, 582 put_path_length, put_path,
590 type, 583 type,
591 data_size, data); 584 data_size, data);
592} 585}
593 586
594 587
@@ -599,8 +592,8 @@ handle_local_result (void *cls,
599 * @param message the actual message received 592 * @param message the actual message received
600 */ 593 */
601static void 594static void
602handle_dht_local_get (void *cls, 595handle_dht_local_get(void *cls,
603 const struct GNUNET_DHT_ClientGetMessage *get) 596 const struct GNUNET_DHT_ClientGetMessage *get)
604{ 597{
605 struct ClientHandle *ch = cls; 598 struct ClientHandle *ch = cls;
606 struct ClientQueryRecord *cqr; 599 struct ClientQueryRecord *cqr;
@@ -608,72 +601,71 @@ handle_dht_local_get (void *cls,
608 const char *xquery; 601 const char *xquery;
609 uint16_t size; 602 uint16_t size;
610 603
611 size = ntohs (get->header.size); 604 size = ntohs(get->header.size);
612 xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); 605 xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage);
613 xquery = (const char *) &get[1]; 606 xquery = (const char *)&get[1];
614 GNUNET_STATISTICS_update (GDS_stats, 607 GNUNET_STATISTICS_update(GDS_stats,
615 gettext_noop 608 gettext_noop
616 ("# GET requests received from clients"), 1, 609 ("# GET requests received from clients"), 1,
617 GNUNET_NO); 610 GNUNET_NO);
618 LOG (GNUNET_ERROR_TYPE_DEBUG, 611 LOG(GNUNET_ERROR_TYPE_DEBUG,
619 "Received GET request for %s from local client %p, xq: %.*s\n", 612 "Received GET request for %s from local client %p, xq: %.*s\n",
620 GNUNET_h2s (&get->key), 613 GNUNET_h2s(&get->key),
621 ch->client, 614 ch->client,
622 xquery_size, 615 xquery_size,
623 xquery); 616 xquery);
624 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 617 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
625 "CLIENT-GET %s\n", 618 "CLIENT-GET %s\n",
626 GNUNET_h2s_full (&get->key)); 619 GNUNET_h2s_full(&get->key));
627 620
628 cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); 621 cqr = GNUNET_malloc(sizeof(struct ClientQueryRecord) + xquery_size);
629 cqr->key = get->key; 622 cqr->key = get->key;
630 cqr->ch = ch; 623 cqr->ch = ch;
631 cqr->xquery = (void *) &cqr[1]; 624 cqr->xquery = (void *)&cqr[1];
632 GNUNET_memcpy (&cqr[1], xquery, xquery_size); 625 GNUNET_memcpy(&cqr[1], xquery, xquery_size);
633 cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); 626 cqr->hnode = GNUNET_CONTAINER_heap_insert(retry_heap, cqr, 0);
634 cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS; 627 cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS;
635 cqr->retry_time = GNUNET_TIME_absolute_get (); 628 cqr->retry_time = GNUNET_TIME_absolute_get();
636 cqr->unique_id = get->unique_id; 629 cqr->unique_id = get->unique_id;
637 cqr->xquery_size = xquery_size; 630 cqr->xquery_size = xquery_size;
638 cqr->replication = ntohl (get->desired_replication_level); 631 cqr->replication = ntohl(get->desired_replication_level);
639 cqr->msg_options = ntohl (get->options); 632 cqr->msg_options = ntohl(get->options);
640 cqr->type = ntohl (get->type); 633 cqr->type = ntohl(get->type);
641 GNUNET_CONTAINER_DLL_insert (ch->cqr_head, 634 GNUNET_CONTAINER_DLL_insert(ch->cqr_head,
642 ch->cqr_tail, 635 ch->cqr_tail,
643 cqr); 636 cqr);
644 GNUNET_CONTAINER_multihashmap_put (forward_map, 637 GNUNET_CONTAINER_multihashmap_put(forward_map,
645 &cqr->key, 638 &cqr->key,
646 cqr, 639 cqr,
647 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 640 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
648 GDS_CLIENTS_process_get (ntohl (get->options), 641 GDS_CLIENTS_process_get(ntohl(get->options),
649 ntohl (get->type), 642 ntohl(get->type),
650 0, 643 0,
651 ntohl (get->desired_replication_level), 644 ntohl(get->desired_replication_level),
652 1, 645 1,
653 GDS_NEIGHBOURS_get_id(), 646 GDS_NEIGHBOURS_get_id(),
654 &get->key); 647 &get->key);
655 /* start remote requests */ 648 /* start remote requests */
656 if (NULL != retry_task) 649 if (NULL != retry_task)
657 GNUNET_SCHEDULER_cancel (retry_task); 650 GNUNET_SCHEDULER_cancel(retry_task);
658 retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, 651 retry_task = GNUNET_SCHEDULER_add_now(&transmit_next_request_task,
659 NULL); 652 NULL);
660 /* perform local lookup */ 653 /* perform local lookup */
661 GDS_DATACACHE_handle_get (&get->key, 654 GDS_DATACACHE_handle_get(&get->key,
662 cqr->type, 655 cqr->type,
663 cqr->xquery, 656 cqr->xquery,
664 xquery_size, 657 xquery_size,
665 NULL, 658 NULL,
666 &handle_local_result, 659 &handle_local_result,
667 ch); 660 ch);
668 GNUNET_SERVICE_client_continue (ch->client); 661 GNUNET_SERVICE_client_continue(ch->client);
669} 662}
670 663
671 664
672/** 665/**
673 * Closure for #find_by_unique_id(). 666 * Closure for #find_by_unique_id().
674 */ 667 */
675struct FindByUniqueIdContext 668struct FindByUniqueIdContext {
676{
677 /** 669 /**
678 * Where to store the result, if found. 670 * Where to store the result, if found.
679 */ 671 */
@@ -694,9 +686,9 @@ struct FindByUniqueIdContext
694 * @return #GNUNET_YES to continue iteration (result not yet found) 686 * @return #GNUNET_YES to continue iteration (result not yet found)
695 */ 687 */
696static int 688static int
697find_by_unique_id (void *cls, 689find_by_unique_id(void *cls,
698 const struct GNUNET_HashCode *key, 690 const struct GNUNET_HashCode *key,
699 void *value) 691 void *value)
700{ 692{
701 struct FindByUniqueIdContext *fui_ctx = cls; 693 struct FindByUniqueIdContext *fui_ctx = cls;
702 struct ClientQueryRecord *cqr = value; 694 struct ClientQueryRecord *cqr = value;
@@ -716,19 +708,19 @@ find_by_unique_id (void *cls,
716 * @return #GNUNET_OK if @a seen is well-formed 708 * @return #GNUNET_OK if @a seen is well-formed
717 */ 709 */
718static int 710static int
719check_dht_local_get_result_seen (void *cls, 711check_dht_local_get_result_seen(void *cls,
720 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen) 712 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
721{ 713{
722 uint16_t size; 714 uint16_t size;
723 unsigned int hash_count; 715 unsigned int hash_count;
724 716
725 size = ntohs (seen->header.size); 717 size = ntohs(seen->header.size);
726 hash_count = (size - sizeof (struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof (struct GNUNET_HashCode); 718 hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof(struct GNUNET_HashCode);
727 if (size != sizeof (struct GNUNET_DHT_ClientGetResultSeenMessage) + hash_count * sizeof (struct GNUNET_HashCode)) 719 if (size != sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage) + hash_count * sizeof(struct GNUNET_HashCode))
728 { 720 {
729 GNUNET_break (0); 721 GNUNET_break(0);
730 return GNUNET_SYSERR; 722 return GNUNET_SYSERR;
731 } 723 }
732 return GNUNET_OK; 724 return GNUNET_OK;
733} 725}
734 726
@@ -740,8 +732,8 @@ check_dht_local_get_result_seen (void *cls,
740 * @param message the actual message received 732 * @param message the actual message received
741 */ 733 */
742static void 734static void
743handle_dht_local_get_result_seen (void *cls, 735handle_dht_local_get_result_seen(void *cls,
744 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen) 736 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
745{ 737{
746 struct ClientHandle *ch = cls; 738 struct ClientHandle *ch = cls;
747 uint16_t size; 739 uint16_t size;
@@ -751,37 +743,36 @@ handle_dht_local_get_result_seen (void *cls,
751 struct FindByUniqueIdContext fui_ctx; 743 struct FindByUniqueIdContext fui_ctx;
752 struct ClientQueryRecord *cqr; 744 struct ClientQueryRecord *cqr;
753 745
754 size = ntohs (seen->header.size); 746 size = ntohs(seen->header.size);
755 hash_count = (size - sizeof (struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof (struct GNUNET_HashCode); 747 hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof(struct GNUNET_HashCode);
756 hc = (const struct GNUNET_HashCode*) &seen[1]; 748 hc = (const struct GNUNET_HashCode*)&seen[1];
757 fui_ctx.unique_id = seen->unique_id; 749 fui_ctx.unique_id = seen->unique_id;
758 fui_ctx.cqr = NULL; 750 fui_ctx.cqr = NULL;
759 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 751 GNUNET_CONTAINER_multihashmap_get_multiple(forward_map,
760 &seen->key, 752 &seen->key,
761 &find_by_unique_id, 753 &find_by_unique_id,
762 &fui_ctx); 754 &fui_ctx);
763 if (NULL == (cqr = fui_ctx.cqr)) 755 if (NULL == (cqr = fui_ctx.cqr))
764 { 756 {
765 GNUNET_break (0); 757 GNUNET_break(0);
766 GNUNET_SERVICE_client_drop (ch->client); 758 GNUNET_SERVICE_client_drop(ch->client);
767 return; 759 return;
768 } 760 }
769 /* finally, update 'seen' list */ 761 /* finally, update 'seen' list */
770 old_count = cqr->seen_replies_count; 762 old_count = cqr->seen_replies_count;
771 GNUNET_array_grow (cqr->seen_replies, 763 GNUNET_array_grow(cqr->seen_replies,
772 cqr->seen_replies_count, 764 cqr->seen_replies_count,
773 cqr->seen_replies_count + hash_count); 765 cqr->seen_replies_count + hash_count);
774 GNUNET_memcpy (&cqr->seen_replies[old_count], 766 GNUNET_memcpy(&cqr->seen_replies[old_count],
775 hc, 767 hc,
776 sizeof (struct GNUNET_HashCode) * hash_count); 768 sizeof(struct GNUNET_HashCode) * hash_count);
777} 769}
778 770
779 771
780/** 772/**
781 * Closure for #remove_by_unique_id(). 773 * Closure for #remove_by_unique_id().
782 */ 774 */
783struct RemoveByUniqueIdContext 775struct RemoveByUniqueIdContext {
784{
785 /** 776 /**
786 * Client that issued the removal request. 777 * Client that issued the removal request.
787 */ 778 */
@@ -804,20 +795,20 @@ struct RemoveByUniqueIdContext
804 * @return #GNUNET_YES (we should continue to iterate) 795 * @return #GNUNET_YES (we should continue to iterate)
805 */ 796 */
806static int 797static int
807remove_by_unique_id (void *cls, 798remove_by_unique_id(void *cls,
808 const struct GNUNET_HashCode *key, 799 const struct GNUNET_HashCode *key,
809 void *value) 800 void *value)
810{ 801{
811 const struct RemoveByUniqueIdContext *ctx = cls; 802 const struct RemoveByUniqueIdContext *ctx = cls;
812 struct ClientQueryRecord *cqr = value; 803 struct ClientQueryRecord *cqr = value;
813 804
814 if (cqr->unique_id != ctx->unique_id) 805 if (cqr->unique_id != ctx->unique_id)
815 return GNUNET_YES; 806 return GNUNET_YES;
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
817 "Removing client %p's record for key %s (by unique id)\n", 808 "Removing client %p's record for key %s (by unique id)\n",
818 ctx->ch->client, 809 ctx->ch->client,
819 GNUNET_h2s (key)); 810 GNUNET_h2s(key));
820 remove_client_record (cqr); 811 remove_client_record(cqr);
821 return GNUNET_YES; 812 return GNUNET_YES;
822} 813}
823 814
@@ -831,27 +822,27 @@ remove_by_unique_id (void *cls,
831 * 822 *
832 */ 823 */
833static void 824static void
834handle_dht_local_get_stop (void *cls, 825handle_dht_local_get_stop(void *cls,
835 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg) 826 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg)
836{ 827{
837 struct ClientHandle *ch = cls; 828 struct ClientHandle *ch = cls;
838 struct RemoveByUniqueIdContext ctx; 829 struct RemoveByUniqueIdContext ctx;
839 830
840 GNUNET_STATISTICS_update (GDS_stats, 831 GNUNET_STATISTICS_update(GDS_stats,
841 gettext_noop 832 gettext_noop
842 ("# GET STOP requests received from clients"), 1, 833 ("# GET STOP requests received from clients"), 1,
843 GNUNET_NO); 834 GNUNET_NO);
844 LOG (GNUNET_ERROR_TYPE_DEBUG, 835 LOG(GNUNET_ERROR_TYPE_DEBUG,
845 "Received GET STOP request for %s from local client %p\n", 836 "Received GET STOP request for %s from local client %p\n",
846 GNUNET_h2s (&dht_stop_msg->key), 837 GNUNET_h2s(&dht_stop_msg->key),
847 ch->client); 838 ch->client);
848 ctx.ch = ch; 839 ctx.ch = ch;
849 ctx.unique_id = dht_stop_msg->unique_id; 840 ctx.unique_id = dht_stop_msg->unique_id;
850 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 841 GNUNET_CONTAINER_multihashmap_get_multiple(forward_map,
851 &dht_stop_msg->key, 842 &dht_stop_msg->key,
852 &remove_by_unique_id, 843 &remove_by_unique_id,
853 &ctx); 844 &ctx);
854 GNUNET_SERVICE_client_continue (ch->client); 845 GNUNET_SERVICE_client_continue(ch->client);
855} 846}
856 847
857 848
@@ -863,33 +854,33 @@ handle_dht_local_get_stop (void *cls,
863 * 854 *
864 */ 855 */
865static void 856static void
866handle_dht_local_monitor (void *cls, 857handle_dht_local_monitor(void *cls,
867 const struct GNUNET_DHT_MonitorStartStopMessage *msg) 858 const struct GNUNET_DHT_MonitorStartStopMessage *msg)
868{ 859{
869 struct ClientHandle *ch = cls; 860 struct ClientHandle *ch = cls;
870 struct ClientMonitorRecord *r; 861 struct ClientMonitorRecord *r;
871 862
872 r = GNUNET_new (struct ClientMonitorRecord); 863 r = GNUNET_new(struct ClientMonitorRecord);
873 r->ch = ch; 864 r->ch = ch;
874 r->type = ntohl (msg->type); 865 r->type = ntohl(msg->type);
875 r->get = ntohs (msg->get); 866 r->get = ntohs(msg->get);
876 r->get_resp = ntohs (msg->get_resp); 867 r->get_resp = ntohs(msg->get_resp);
877 r->put = ntohs (msg->put); 868 r->put = ntohs(msg->put);
878 if (0 == ntohs (msg->filter_key)) 869 if (0 == ntohs(msg->filter_key))
879 { 870 {
880 r->key = NULL; 871 r->key = NULL;
881 } 872 }
882 else 873 else
883 { 874 {
884 r->key = GNUNET_new (struct GNUNET_HashCode); 875 r->key = GNUNET_new(struct GNUNET_HashCode);
885 GNUNET_memcpy (r->key, 876 GNUNET_memcpy(r->key,
886 &msg->key, 877 &msg->key,
887 sizeof (struct GNUNET_HashCode)); 878 sizeof(struct GNUNET_HashCode));
888 } 879 }
889 GNUNET_CONTAINER_DLL_insert (monitor_head, 880 GNUNET_CONTAINER_DLL_insert(monitor_head,
890 monitor_tail, 881 monitor_tail,
891 r); 882 r);
892 GNUNET_SERVICE_client_continue (ch->client); 883 GNUNET_SERVICE_client_continue(ch->client);
893} 884}
894 885
895 886
@@ -900,51 +891,49 @@ handle_dht_local_monitor (void *cls,
900 * @param msg the actual message received 891 * @param msg the actual message received
901 */ 892 */
902static void 893static void
903handle_dht_local_monitor_stop (void *cls, 894handle_dht_local_monitor_stop(void *cls,
904 const struct GNUNET_DHT_MonitorStartStopMessage *msg) 895 const struct GNUNET_DHT_MonitorStartStopMessage *msg)
905{ 896{
906 struct ClientHandle *ch = cls; 897 struct ClientHandle *ch = cls;
907 struct ClientMonitorRecord *r; 898 struct ClientMonitorRecord *r;
908 int keys_match; 899 int keys_match;
909 900
910 GNUNET_SERVICE_client_continue (ch->client); 901 GNUNET_SERVICE_client_continue(ch->client);
911 for (r = monitor_head; NULL != r; r = r->next) 902 for (r = monitor_head; NULL != r; r = r->next)
912 {
913 if (NULL == r->key)
914 { 903 {
915 keys_match = (0 == ntohs(msg->filter_key)); 904 if (NULL == r->key)
905 {
906 keys_match = (0 == ntohs(msg->filter_key));
907 }
908 else
909 {
910 keys_match = ((0 != ntohs(msg->filter_key)) &&
911 (!memcmp(r->key,
912 &msg->key,
913 sizeof(struct GNUNET_HashCode))));
914 }
915 if ((ch == r->ch) &&
916 (ntohl(msg->type) == r->type) &&
917 (r->get == msg->get) &&
918 (r->get_resp == msg->get_resp) &&
919 (r->put == msg->put) &&
920 keys_match)
921 {
922 GNUNET_CONTAINER_DLL_remove(monitor_head,
923 monitor_tail,
924 r);
925 GNUNET_free_non_null(r->key);
926 GNUNET_free(r);
927 return; /* Delete only ONE entry */
928 }
916 } 929 }
917 else
918 {
919 keys_match = ( (0 != ntohs(msg->filter_key)) &&
920 (! memcmp (r->key,
921 &msg->key,
922 sizeof(struct GNUNET_HashCode))) );
923 }
924 if ( (ch == r->ch) &&
925 (ntohl(msg->type) == r->type) &&
926 (r->get == msg->get) &&
927 (r->get_resp == msg->get_resp) &&
928 (r->put == msg->put) &&
929 keys_match )
930 {
931 GNUNET_CONTAINER_DLL_remove (monitor_head,
932 monitor_tail,
933 r);
934 GNUNET_free_non_null (r->key);
935 GNUNET_free (r);
936 return; /* Delete only ONE entry */
937 }
938 }
939} 930}
940 931
941 932
942/** 933/**
943 * Closure for #forward_reply() 934 * Closure for #forward_reply()
944 */ 935 */
945struct ForwardReplyContext 936struct ForwardReplyContext {
946{
947
948 /** 937 /**
949 * Expiration time of the reply. 938 * Expiration time of the reply.
950 */ 939 */
@@ -984,7 +973,6 @@ struct ForwardReplyContext
984 * Type of the data. 973 * Type of the data.
985 */ 974 */
986 enum GNUNET_BLOCK_Type type; 975 enum GNUNET_BLOCK_Type type;
987
988}; 976};
989 977
990 978
@@ -1000,9 +988,9 @@ struct ForwardReplyContext
1000 * if the result is mal-formed, #GNUNET_NO 988 * if the result is mal-formed, #GNUNET_NO
1001 */ 989 */
1002static int 990static int
1003forward_reply (void *cls, 991forward_reply(void *cls,
1004 const struct GNUNET_HashCode *key, 992 const struct GNUNET_HashCode *key,
1005 void *value) 993 void *value)
1006{ 994{
1007 struct ForwardReplyContext *frc = cls; 995 struct ForwardReplyContext *frc = cls;
1008 struct ClientQueryRecord *record = value; 996 struct ClientQueryRecord *record = value;
@@ -1013,116 +1001,124 @@ forward_reply (void *cls,
1013 struct GNUNET_HashCode ch; 1001 struct GNUNET_HashCode ch;
1014 struct GNUNET_PeerIdentity *paths; 1002 struct GNUNET_PeerIdentity *paths;
1015 1003
1016 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 1004 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
1017 "CLIENT-RESULT %s\n", 1005 "CLIENT-RESULT %s\n",
1018 GNUNET_h2s_full (key)); 1006 GNUNET_h2s_full(key));
1019 if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && 1007 if ((record->type != GNUNET_BLOCK_TYPE_ANY) &&
1020 (record->type != frc->type)) 1008 (record->type != frc->type))
1021 {
1022 LOG (GNUNET_ERROR_TYPE_DEBUG,
1023 "Record type mismatch, not passing request for key %s to local client\n",
1024 GNUNET_h2s (key));
1025 GNUNET_STATISTICS_update (GDS_stats,
1026 gettext_noop
1027 ("# Key match, type mismatches in REPLY to CLIENT"),
1028 1, GNUNET_NO);
1029 return GNUNET_YES; /* type mismatch */
1030 }
1031 GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
1032 for (unsigned int i = 0; i < record->seen_replies_count; i++)
1033 if (0 == memcmp (&record->seen_replies[i],
1034 &ch,
1035 sizeof (struct GNUNET_HashCode)))
1036 { 1009 {
1037 LOG (GNUNET_ERROR_TYPE_DEBUG, 1010 LOG(GNUNET_ERROR_TYPE_DEBUG,
1038 "Duplicate reply, not passing request for key %s to local client\n", 1011 "Record type mismatch, not passing request for key %s to local client\n",
1039 GNUNET_h2s (key)); 1012 GNUNET_h2s(key));
1040 GNUNET_STATISTICS_update (GDS_stats, 1013 GNUNET_STATISTICS_update(GDS_stats,
1041 gettext_noop 1014 gettext_noop
1042 ("# Duplicate REPLIES to CLIENT request dropped"), 1015 ("# Key match, type mismatches in REPLY to CLIENT"),
1043 1, GNUNET_NO); 1016 1, GNUNET_NO);
1044 return GNUNET_YES; /* duplicate */ 1017 return GNUNET_YES; /* type mismatch */
1045 } 1018 }
1019 GNUNET_CRYPTO_hash(frc->data, frc->data_size, &ch);
1020 for (unsigned int i = 0; i < record->seen_replies_count; i++)
1021 if (0 == memcmp(&record->seen_replies[i],
1022 &ch,
1023 sizeof(struct GNUNET_HashCode)))
1024 {
1025 LOG(GNUNET_ERROR_TYPE_DEBUG,
1026 "Duplicate reply, not passing request for key %s to local client\n",
1027 GNUNET_h2s(key));
1028 GNUNET_STATISTICS_update(GDS_stats,
1029 gettext_noop
1030 ("# Duplicate REPLIES to CLIENT request dropped"),
1031 1, GNUNET_NO);
1032 return GNUNET_YES; /* duplicate */
1033 }
1046 eval 1034 eval
1047 = GNUNET_BLOCK_evaluate (GDS_block_context, 1035 = GNUNET_BLOCK_evaluate(GDS_block_context,
1048 record->type, 1036 record->type,
1049 NULL, 1037 NULL,
1050 GNUNET_BLOCK_EO_NONE, 1038 GNUNET_BLOCK_EO_NONE,
1051 key, 1039 key,
1052 record->xquery, 1040 record->xquery,
1053 record->xquery_size, 1041 record->xquery_size,
1054 frc->data, 1042 frc->data,
1055 frc->data_size); 1043 frc->data_size);
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, 1044 LOG(GNUNET_ERROR_TYPE_DEBUG,
1057 "Evaluation result is %d for key %s for local client's query\n", 1045 "Evaluation result is %d for key %s for local client's query\n",
1058 (int) eval, 1046 (int)eval,
1059 GNUNET_h2s (key)); 1047 GNUNET_h2s(key));
1060 switch (eval) 1048 switch (eval)
1061 { 1049 {
1062 case GNUNET_BLOCK_EVALUATION_OK_LAST: 1050 case GNUNET_BLOCK_EVALUATION_OK_LAST:
1063 do_free = GNUNET_YES; 1051 do_free = GNUNET_YES;
1064 break; 1052 break;
1065 case GNUNET_BLOCK_EVALUATION_OK_MORE: 1053
1066 GNUNET_array_append (record->seen_replies, 1054 case GNUNET_BLOCK_EVALUATION_OK_MORE:
1067 record->seen_replies_count, 1055 GNUNET_array_append(record->seen_replies,
1068 ch); 1056 record->seen_replies_count,
1069 do_free = GNUNET_NO; 1057 ch);
1070 break; 1058 do_free = GNUNET_NO;
1071 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 1059 break;
1072 /* should be impossible to encounter here */ 1060
1073 GNUNET_break (0); 1061 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
1074 return GNUNET_YES; 1062 /* should be impossible to encounter here */
1075 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 1063 GNUNET_break(0);
1076 GNUNET_break_op (0); 1064 return GNUNET_YES;
1077 return GNUNET_NO; 1065
1078 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 1066 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
1079 GNUNET_break (0); 1067 GNUNET_break_op(0);
1080 return GNUNET_NO; 1068 return GNUNET_NO;
1081 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 1069
1082 GNUNET_break (0); 1070 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
1083 return GNUNET_NO; 1071 GNUNET_break(0);
1084 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: 1072 return GNUNET_NO;
1085 return GNUNET_YES; 1073
1086 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 1074 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
1087 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1075 GNUNET_break(0);
1088 _("Unsupported block type (%u) in request!\n"), record->type); 1076 return GNUNET_NO;
1089 return GNUNET_NO; 1077
1090 default: 1078 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
1091 GNUNET_break (0); 1079 return GNUNET_YES;
1092 return GNUNET_NO; 1080
1093 } 1081 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
1094 GNUNET_STATISTICS_update (GDS_stats, 1082 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1095 gettext_noop ("# RESULTS queued for clients"), 1083 _("Unsupported block type (%u) in request!\n"), record->type);
1096 1, 1084 return GNUNET_NO;
1097 GNUNET_NO); 1085
1098 env = GNUNET_MQ_msg_extra (reply, 1086 default:
1099 frc->data_size + 1087 GNUNET_break(0);
1100 (frc->get_path_length + frc->put_path_length) * sizeof (struct GNUNET_PeerIdentity), 1088 return GNUNET_NO;
1101 GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); 1089 }
1102 reply->type = htonl (frc->type); 1090 GNUNET_STATISTICS_update(GDS_stats,
1103 reply->get_path_length = htonl (frc->get_path_length); 1091 gettext_noop("# RESULTS queued for clients"),
1104 reply->put_path_length = htonl (frc->put_path_length); 1092 1,
1093 GNUNET_NO);
1094 env = GNUNET_MQ_msg_extra(reply,
1095 frc->data_size +
1096 (frc->get_path_length + frc->put_path_length) * sizeof(struct GNUNET_PeerIdentity),
1097 GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT);
1098 reply->type = htonl(frc->type);
1099 reply->get_path_length = htonl(frc->get_path_length);
1100 reply->put_path_length = htonl(frc->put_path_length);
1105 reply->unique_id = record->unique_id; 1101 reply->unique_id = record->unique_id;
1106 reply->expiration = GNUNET_TIME_absolute_hton (frc->expiration); 1102 reply->expiration = GNUNET_TIME_absolute_hton(frc->expiration);
1107 reply->key = *key; 1103 reply->key = *key;
1108 paths = (struct GNUNET_PeerIdentity *) &reply[1]; 1104 paths = (struct GNUNET_PeerIdentity *)&reply[1];
1109 GNUNET_memcpy (paths, 1105 GNUNET_memcpy(paths,
1110 frc->put_path, 1106 frc->put_path,
1111 sizeof (struct GNUNET_PeerIdentity) * frc->put_path_length); 1107 sizeof(struct GNUNET_PeerIdentity) * frc->put_path_length);
1112 GNUNET_memcpy (&paths[frc->put_path_length], 1108 GNUNET_memcpy(&paths[frc->put_path_length],
1113 frc->get_path, 1109 frc->get_path,
1114 sizeof (struct GNUNET_PeerIdentity) * frc->get_path_length); 1110 sizeof(struct GNUNET_PeerIdentity) * frc->get_path_length);
1115 GNUNET_memcpy (&paths[frc->get_path_length + frc->put_path_length], 1111 GNUNET_memcpy(&paths[frc->get_path_length + frc->put_path_length],
1116 frc->data, 1112 frc->data,
1117 frc->data_size); 1113 frc->data_size);
1118 LOG (GNUNET_ERROR_TYPE_DEBUG, 1114 LOG(GNUNET_ERROR_TYPE_DEBUG,
1119 "Sending reply to query %s for client %p\n", 1115 "Sending reply to query %s for client %p\n",
1120 GNUNET_h2s (key), 1116 GNUNET_h2s(key),
1121 record->ch->client); 1117 record->ch->client);
1122 GNUNET_MQ_send (record->ch->mq, 1118 GNUNET_MQ_send(record->ch->mq,
1123 env); 1119 env);
1124 if (GNUNET_YES == do_free) 1120 if (GNUNET_YES == do_free)
1125 remove_client_record (record); 1121 remove_client_record(record);
1126 return GNUNET_YES; 1122 return GNUNET_YES;
1127} 1123}
1128 1124
@@ -1143,38 +1139,38 @@ forward_reply (void *cls,
1143 * @param data application payload data 1139 * @param data application payload data
1144 */ 1140 */
1145void 1141void
1146GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, 1142GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration,
1147 const struct GNUNET_HashCode *key, 1143 const struct GNUNET_HashCode *key,
1148 unsigned int get_path_length, 1144 unsigned int get_path_length,
1149 const struct GNUNET_PeerIdentity *get_path, 1145 const struct GNUNET_PeerIdentity *get_path,
1150 unsigned int put_path_length, 1146 unsigned int put_path_length,
1151 const struct GNUNET_PeerIdentity *put_path, 1147 const struct GNUNET_PeerIdentity *put_path,
1152 enum GNUNET_BLOCK_Type type, 1148 enum GNUNET_BLOCK_Type type,
1153 size_t data_size, 1149 size_t data_size,
1154 const void *data) 1150 const void *data)
1155{ 1151{
1156 struct ForwardReplyContext frc; 1152 struct ForwardReplyContext frc;
1157 size_t msize; 1153 size_t msize;
1158 1154
1159 msize = sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size + 1155 msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size +
1160 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); 1156 (get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity);
1161 if (msize >= GNUNET_MAX_MESSAGE_SIZE) 1157 if (msize >= GNUNET_MAX_MESSAGE_SIZE)
1162 { 1158 {
1163 GNUNET_break (0); 1159 GNUNET_break(0);
1164 return; 1160 return;
1165 } 1161 }
1166 if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, 1162 if (NULL == GNUNET_CONTAINER_multihashmap_get(forward_map,
1167 key)) 1163 key))
1168 { 1164 {
1169 LOG (GNUNET_ERROR_TYPE_DEBUG, 1165 LOG(GNUNET_ERROR_TYPE_DEBUG,
1170 "No matching client for reply for key %s\n", 1166 "No matching client for reply for key %s\n",
1171 GNUNET_h2s (key)); 1167 GNUNET_h2s(key));
1172 GNUNET_STATISTICS_update (GDS_stats, 1168 GNUNET_STATISTICS_update(GDS_stats,
1173 gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1169 gettext_noop("# REPLIES ignored for CLIENTS (no match)"),
1174 1, 1170 1,
1175 GNUNET_NO); 1171 GNUNET_NO);
1176 return; /* no matching request, fast exit! */ 1172 return; /* no matching request, fast exit! */
1177 } 1173 }
1178 frc.expiration = expiration; 1174 frc.expiration = expiration;
1179 frc.get_path = get_path; 1175 frc.get_path = get_path;
1180 frc.put_path = put_path; 1176 frc.put_path = put_path;
@@ -1183,14 +1179,13 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1183 frc.get_path_length = get_path_length; 1179 frc.get_path_length = get_path_length;
1184 frc.put_path_length = put_path_length; 1180 frc.put_path_length = put_path_length;
1185 frc.type = type; 1181 frc.type = type;
1186 LOG (GNUNET_ERROR_TYPE_DEBUG, 1182 LOG(GNUNET_ERROR_TYPE_DEBUG,
1187 "Forwarding reply for key %s to client\n", 1183 "Forwarding reply for key %s to client\n",
1188 GNUNET_h2s (key)); 1184 GNUNET_h2s(key));
1189 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 1185 GNUNET_CONTAINER_multihashmap_get_multiple(forward_map,
1190 key, 1186 key,
1191 &forward_reply, 1187 &forward_reply,
1192 &frc); 1188 &frc);
1193
1194} 1189}
1195 1190
1196 1191
@@ -1207,13 +1202,13 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1207 * @param key Key of the requested data. 1202 * @param key Key of the requested data.
1208 */ 1203 */
1209void 1204void
1210GDS_CLIENTS_process_get (uint32_t options, 1205GDS_CLIENTS_process_get(uint32_t options,
1211 enum GNUNET_BLOCK_Type type, 1206 enum GNUNET_BLOCK_Type type,
1212 uint32_t hop_count, 1207 uint32_t hop_count,
1213 uint32_t desired_replication_level, 1208 uint32_t desired_replication_level,
1214 unsigned int path_length, 1209 unsigned int path_length,
1215 const struct GNUNET_PeerIdentity *path, 1210 const struct GNUNET_PeerIdentity *path,
1216 const struct GNUNET_HashCode * key) 1211 const struct GNUNET_HashCode * key)
1217{ 1212{
1218 struct ClientMonitorRecord *m; 1213 struct ClientMonitorRecord *m;
1219 struct ClientHandle **cl; 1214 struct ClientHandle **cl;
@@ -1222,49 +1217,49 @@ GDS_CLIENTS_process_get (uint32_t options,
1222 cl = NULL; 1217 cl = NULL;
1223 cl_size = 0; 1218 cl_size = 0;
1224 for (m = monitor_head; NULL != m; m = m->next) 1219 for (m = monitor_head; NULL != m; m = m->next)
1225 {
1226 if ( ( (GNUNET_BLOCK_TYPE_ANY == m->type) ||
1227 (m->type == type) ) &&
1228 ( (NULL == m->key) ||
1229 (0 == memcmp (key,
1230 m->key,
1231 sizeof(struct GNUNET_HashCode))) ) )
1232 { 1220 {
1233 struct GNUNET_MQ_Envelope *env; 1221 if (((GNUNET_BLOCK_TYPE_ANY == m->type) ||
1234 struct GNUNET_DHT_MonitorGetMessage *mmsg; 1222 (m->type == type)) &&
1235 struct GNUNET_PeerIdentity *msg_path; 1223 ((NULL == m->key) ||
1236 size_t msize; 1224 (0 == memcmp(key,
1237 unsigned int i; 1225 m->key,
1238 1226 sizeof(struct GNUNET_HashCode)))))
1239 /* Don't send duplicates */ 1227 {
1240 for (i = 0; i < cl_size; i++) 1228 struct GNUNET_MQ_Envelope *env;
1241 if (cl[i] == m->ch) 1229 struct GNUNET_DHT_MonitorGetMessage *mmsg;
1242 break; 1230 struct GNUNET_PeerIdentity *msg_path;
1243 if (i < cl_size) 1231 size_t msize;
1244 continue; 1232 unsigned int i;
1245 GNUNET_array_append (cl, 1233
1246 cl_size, 1234 /* Don't send duplicates */
1247 m->ch); 1235 for (i = 0; i < cl_size; i++)
1248 1236 if (cl[i] == m->ch)
1249 msize = path_length * sizeof (struct GNUNET_PeerIdentity); 1237 break;
1250 env = GNUNET_MQ_msg_extra (mmsg, 1238 if (i < cl_size)
1251 msize, 1239 continue;
1252 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET); 1240 GNUNET_array_append(cl,
1253 mmsg->options = htonl(options); 1241 cl_size,
1254 mmsg->type = htonl(type); 1242 m->ch);
1255 mmsg->hop_count = htonl(hop_count); 1243
1256 mmsg->desired_replication_level = htonl(desired_replication_level); 1244 msize = path_length * sizeof(struct GNUNET_PeerIdentity);
1257 mmsg->get_path_length = htonl(path_length); 1245 env = GNUNET_MQ_msg_extra(mmsg,
1258 mmsg->key = *key; 1246 msize,
1259 msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1247 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET);
1260 GNUNET_memcpy (msg_path, 1248 mmsg->options = htonl(options);
1261 path, 1249 mmsg->type = htonl(type);
1262 path_length * sizeof (struct GNUNET_PeerIdentity)); 1250 mmsg->hop_count = htonl(hop_count);
1263 GNUNET_MQ_send (m->ch->mq, 1251 mmsg->desired_replication_level = htonl(desired_replication_level);
1264 env); 1252 mmsg->get_path_length = htonl(path_length);
1253 mmsg->key = *key;
1254 msg_path = (struct GNUNET_PeerIdentity *)&mmsg[1];
1255 GNUNET_memcpy(msg_path,
1256 path,
1257 path_length * sizeof(struct GNUNET_PeerIdentity));
1258 GNUNET_MQ_send(m->ch->mq,
1259 env);
1260 }
1265 } 1261 }
1266 } 1262 GNUNET_free_non_null(cl);
1267 GNUNET_free_non_null (cl);
1268} 1263}
1269 1264
1270 1265
@@ -1283,15 +1278,15 @@ GDS_CLIENTS_process_get (uint32_t options,
1283 * @param size Number of bytes in @a data. 1278 * @param size Number of bytes in @a data.
1284 */ 1279 */
1285void 1280void
1286GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, 1281GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type,
1287 const struct GNUNET_PeerIdentity *get_path, 1282 const struct GNUNET_PeerIdentity *get_path,
1288 unsigned int get_path_length, 1283 unsigned int get_path_length,
1289 const struct GNUNET_PeerIdentity *put_path, 1284 const struct GNUNET_PeerIdentity *put_path,
1290 unsigned int put_path_length, 1285 unsigned int put_path_length,
1291 struct GNUNET_TIME_Absolute exp, 1286 struct GNUNET_TIME_Absolute exp,
1292 const struct GNUNET_HashCode * key, 1287 const struct GNUNET_HashCode * key,
1293 const void *data, 1288 const void *data,
1294 size_t size) 1289 size_t size)
1295{ 1290{
1296 struct ClientMonitorRecord *m; 1291 struct ClientMonitorRecord *m;
1297 struct ClientHandle **cl; 1292 struct ClientHandle **cl;
@@ -1300,53 +1295,53 @@ GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
1300 cl = NULL; 1295 cl = NULL;
1301 cl_size = 0; 1296 cl_size = 0;
1302 for (m = monitor_head; NULL != m; m = m->next) 1297 for (m = monitor_head; NULL != m; m = m->next)
1303 {
1304 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1305 (NULL == m->key ||
1306 memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1307 { 1298 {
1308 struct GNUNET_MQ_Envelope *env; 1299 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1309 struct GNUNET_DHT_MonitorGetRespMessage *mmsg; 1300 (NULL == m->key ||
1310 struct GNUNET_PeerIdentity *path; 1301 memcmp(key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1311 size_t msize; 1302 {
1312 unsigned int i; 1303 struct GNUNET_MQ_Envelope *env;
1313 1304 struct GNUNET_DHT_MonitorGetRespMessage *mmsg;
1314 /* Don't send duplicates */ 1305 struct GNUNET_PeerIdentity *path;
1315 for (i = 0; i < cl_size; i++) 1306 size_t msize;
1316 if (cl[i] == m->ch) 1307 unsigned int i;
1317 break; 1308
1318 if (i < cl_size) 1309 /* Don't send duplicates */
1319 continue; 1310 for (i = 0; i < cl_size; i++)
1320 GNUNET_array_append (cl, 1311 if (cl[i] == m->ch)
1321 cl_size, 1312 break;
1322 m->ch); 1313 if (i < cl_size)
1323 1314 continue;
1324 msize = size; 1315 GNUNET_array_append(cl,
1325 msize += (get_path_length + put_path_length) 1316 cl_size,
1326 * sizeof (struct GNUNET_PeerIdentity); 1317 m->ch);
1327 env = GNUNET_MQ_msg_extra (mmsg, 1318
1328 msize, 1319 msize = size;
1329 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP); 1320 msize += (get_path_length + put_path_length)
1330 mmsg->type = htonl(type); 1321 * sizeof(struct GNUNET_PeerIdentity);
1331 mmsg->put_path_length = htonl(put_path_length); 1322 env = GNUNET_MQ_msg_extra(mmsg,
1332 mmsg->get_path_length = htonl(get_path_length); 1323 msize,
1333 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp); 1324 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP);
1334 mmsg->key = *key; 1325 mmsg->type = htonl(type);
1335 path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1326 mmsg->put_path_length = htonl(put_path_length);
1336 GNUNET_memcpy (path, 1327 mmsg->get_path_length = htonl(get_path_length);
1337 put_path, 1328 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
1338 put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1329 mmsg->key = *key;
1339 GNUNET_memcpy (path, 1330 path = (struct GNUNET_PeerIdentity *)&mmsg[1];
1340 get_path, 1331 GNUNET_memcpy(path,
1341 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1332 put_path,
1342 GNUNET_memcpy (&path[get_path_length], 1333 put_path_length * sizeof(struct GNUNET_PeerIdentity));
1343 data, 1334 GNUNET_memcpy(path,
1344 size); 1335 get_path,
1345 GNUNET_MQ_send (m->ch->mq, 1336 get_path_length * sizeof(struct GNUNET_PeerIdentity));
1346 env); 1337 GNUNET_memcpy(&path[get_path_length],
1338 data,
1339 size);
1340 GNUNET_MQ_send(m->ch->mq,
1341 env);
1342 }
1347 } 1343 }
1348 } 1344 GNUNET_free_non_null(cl);
1349 GNUNET_free_non_null (cl);
1350} 1345}
1351 1346
1352 1347
@@ -1366,16 +1361,16 @@ GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
1366 * @param size Number of bytes in data. 1361 * @param size Number of bytes in data.
1367 */ 1362 */
1368void 1363void
1369GDS_CLIENTS_process_put (uint32_t options, 1364GDS_CLIENTS_process_put(uint32_t options,
1370 enum GNUNET_BLOCK_Type type, 1365 enum GNUNET_BLOCK_Type type,
1371 uint32_t hop_count, 1366 uint32_t hop_count,
1372 uint32_t desired_replication_level, 1367 uint32_t desired_replication_level,
1373 unsigned int path_length, 1368 unsigned int path_length,
1374 const struct GNUNET_PeerIdentity *path, 1369 const struct GNUNET_PeerIdentity *path,
1375 struct GNUNET_TIME_Absolute exp, 1370 struct GNUNET_TIME_Absolute exp,
1376 const struct GNUNET_HashCode *key, 1371 const struct GNUNET_HashCode *key,
1377 const void *data, 1372 const void *data,
1378 size_t size) 1373 size_t size)
1379{ 1374{
1380 struct ClientMonitorRecord *m; 1375 struct ClientMonitorRecord *m;
1381 struct ClientHandle **cl; 1376 struct ClientHandle **cl;
@@ -1384,51 +1379,51 @@ GDS_CLIENTS_process_put (uint32_t options,
1384 cl = NULL; 1379 cl = NULL;
1385 cl_size = 0; 1380 cl_size = 0;
1386 for (m = monitor_head; NULL != m; m = m->next) 1381 for (m = monitor_head; NULL != m; m = m->next)
1387 {
1388 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1389 (NULL == m->key ||
1390 memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1391 { 1382 {
1392 struct GNUNET_MQ_Envelope *env; 1383 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1393 struct GNUNET_DHT_MonitorPutMessage *mmsg; 1384 (NULL == m->key ||
1394 struct GNUNET_PeerIdentity *msg_path; 1385 memcmp(key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1395 size_t msize; 1386 {
1396 unsigned int i; 1387 struct GNUNET_MQ_Envelope *env;
1397 1388 struct GNUNET_DHT_MonitorPutMessage *mmsg;
1398 /* Don't send duplicates */ 1389 struct GNUNET_PeerIdentity *msg_path;
1399 for (i = 0; i < cl_size; i++) 1390 size_t msize;
1400 if (cl[i] == m->ch) 1391 unsigned int i;
1401 break; 1392
1402 if (i < cl_size) 1393 /* Don't send duplicates */
1403 continue; 1394 for (i = 0; i < cl_size; i++)
1404 GNUNET_array_append (cl, 1395 if (cl[i] == m->ch)
1405 cl_size, 1396 break;
1406 m->ch); 1397 if (i < cl_size)
1407 1398 continue;
1408 msize = size; 1399 GNUNET_array_append(cl,
1409 msize += path_length * sizeof (struct GNUNET_PeerIdentity); 1400 cl_size,
1410 env = GNUNET_MQ_msg_extra (mmsg, 1401 m->ch);
1411 msize, 1402
1412 GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT); 1403 msize = size;
1413 mmsg->options = htonl(options); 1404 msize += path_length * sizeof(struct GNUNET_PeerIdentity);
1414 mmsg->type = htonl(type); 1405 env = GNUNET_MQ_msg_extra(mmsg,
1415 mmsg->hop_count = htonl(hop_count); 1406 msize,
1416 mmsg->desired_replication_level = htonl (desired_replication_level); 1407 GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT);
1417 mmsg->put_path_length = htonl (path_length); 1408 mmsg->options = htonl(options);
1418 mmsg->key = *key; 1409 mmsg->type = htonl(type);
1419 mmsg->expiration_time = GNUNET_TIME_absolute_hton (exp); 1410 mmsg->hop_count = htonl(hop_count);
1420 msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1411 mmsg->desired_replication_level = htonl(desired_replication_level);
1421 GNUNET_memcpy (msg_path, 1412 mmsg->put_path_length = htonl(path_length);
1422 path, 1413 mmsg->key = *key;
1423 path_length * sizeof (struct GNUNET_PeerIdentity)); 1414 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
1424 GNUNET_memcpy (&msg_path[path_length], 1415 msg_path = (struct GNUNET_PeerIdentity *)&mmsg[1];
1425 data, 1416 GNUNET_memcpy(msg_path,
1426 size); 1417 path,
1427 GNUNET_MQ_send (m->ch->mq, 1418 path_length * sizeof(struct GNUNET_PeerIdentity));
1428 env); 1419 GNUNET_memcpy(&msg_path[path_length],
1420 data,
1421 size);
1422 GNUNET_MQ_send(m->ch->mq,
1423 env);
1424 }
1429 } 1425 }
1430 } 1426 GNUNET_free_non_null(cl);
1431 GNUNET_free_non_null (cl);
1432} 1427}
1433 1428
1434 1429
@@ -1438,13 +1433,13 @@ GDS_CLIENTS_process_put (uint32_t options,
1438 * @param server the initialized server 1433 * @param server the initialized server
1439 */ 1434 */
1440static void 1435static void
1441GDS_CLIENTS_init () 1436GDS_CLIENTS_init()
1442{ 1437{
1443 forward_map 1438 forward_map
1444 = GNUNET_CONTAINER_multihashmap_create (1024, 1439 = GNUNET_CONTAINER_multihashmap_create(1024,
1445 GNUNET_YES); 1440 GNUNET_YES);
1446 retry_heap 1441 retry_heap
1447 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1442 = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
1448} 1443}
1449 1444
1450 1445
@@ -1452,13 +1447,13 @@ GDS_CLIENTS_init ()
1452 * Shutdown client subsystem. 1447 * Shutdown client subsystem.
1453 */ 1448 */
1454static void 1449static void
1455GDS_CLIENTS_stop () 1450GDS_CLIENTS_stop()
1456{ 1451{
1457 if (NULL != retry_task) 1452 if (NULL != retry_task)
1458 { 1453 {
1459 GNUNET_SCHEDULER_cancel (retry_task); 1454 GNUNET_SCHEDULER_cancel(retry_task);
1460 retry_task = NULL; 1455 retry_task = NULL;
1461 } 1456 }
1462} 1457}
1463 1458
1464 1459
@@ -1468,59 +1463,59 @@ GDS_CLIENTS_stop ()
1468 * @param name name of the service, i.e. "dht" or "xdht" 1463 * @param name name of the service, i.e. "dht" or "xdht"
1469 * @param run name of the initializaton method for the service 1464 * @param run name of the initializaton method for the service
1470 */ 1465 */
1471#define GDS_DHT_SERVICE_INIT(name,run) \ 1466#define GDS_DHT_SERVICE_INIT(name, run) \
1472 GNUNET_SERVICE_MAIN \ 1467 GNUNET_SERVICE_MAIN \
1473 (name, \ 1468 (name, \
1474 GNUNET_SERVICE_OPTION_NONE, \ 1469 GNUNET_SERVICE_OPTION_NONE, \
1475 run, \ 1470 run, \
1476 &client_connect_cb, \ 1471 &client_connect_cb, \
1477 &client_disconnect_cb, \ 1472 &client_disconnect_cb, \
1478 NULL, \ 1473 NULL, \
1479 GNUNET_MQ_hd_var_size (dht_local_put, \ 1474 GNUNET_MQ_hd_var_size(dht_local_put, \
1480 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \ 1475 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \
1481 struct GNUNET_DHT_ClientPutMessage, \ 1476 struct GNUNET_DHT_ClientPutMessage, \
1482 NULL), \ 1477 NULL), \
1483 GNUNET_MQ_hd_var_size (dht_local_get, \ 1478 GNUNET_MQ_hd_var_size(dht_local_get, \
1484 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \ 1479 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \
1485 struct GNUNET_DHT_ClientGetMessage, \ 1480 struct GNUNET_DHT_ClientGetMessage, \
1486 NULL), \
1487 GNUNET_MQ_hd_fixed_size (dht_local_get_stop, \
1488 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \
1489 struct GNUNET_DHT_ClientGetStopMessage, \
1490 NULL), \ 1481 NULL), \
1491 GNUNET_MQ_hd_fixed_size (dht_local_monitor, \ 1482 GNUNET_MQ_hd_fixed_size(dht_local_get_stop, \
1492 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \ 1483 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \
1493 struct GNUNET_DHT_MonitorStartStopMessage, \ 1484 struct GNUNET_DHT_ClientGetStopMessage, \
1494 NULL), \ 1485 NULL), \
1495 GNUNET_MQ_hd_fixed_size (dht_local_monitor_stop, \ 1486 GNUNET_MQ_hd_fixed_size(dht_local_monitor, \
1496 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \ 1487 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \
1497 struct GNUNET_DHT_MonitorStartStopMessage, \ 1488 struct GNUNET_DHT_MonitorStartStopMessage, \
1498 NULL), \ 1489 NULL), \
1499 GNUNET_MQ_hd_var_size (dht_local_get_result_seen, \ 1490 GNUNET_MQ_hd_fixed_size(dht_local_monitor_stop, \
1500 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \ 1491 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \
1501 struct GNUNET_DHT_ClientGetResultSeenMessage , \ 1492 struct GNUNET_DHT_MonitorStartStopMessage, \
1502 NULL), \ 1493 NULL), \
1503 GNUNET_MQ_handler_end ()) 1494 GNUNET_MQ_hd_var_size(dht_local_get_result_seen, \
1495 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \
1496 struct GNUNET_DHT_ClientGetResultSeenMessage, \
1497 NULL), \
1498 GNUNET_MQ_handler_end())
1504 1499
1505 1500
1506/** 1501/**
1507 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1502 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1508 */ 1503 */
1509void __attribute__ ((destructor)) 1504void __attribute__ ((destructor))
1510GDS_CLIENTS_done () 1505GDS_CLIENTS_done()
1511{ 1506{
1512 if (NULL != retry_heap) 1507 if (NULL != retry_heap)
1513 { 1508 {
1514 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); 1509 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(retry_heap));
1515 GNUNET_CONTAINER_heap_destroy (retry_heap); 1510 GNUNET_CONTAINER_heap_destroy(retry_heap);
1516 retry_heap = NULL; 1511 retry_heap = NULL;
1517 } 1512 }
1518 if (NULL != forward_map) 1513 if (NULL != forward_map)
1519 { 1514 {
1520 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (forward_map)); 1515 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(forward_map));
1521 GNUNET_CONTAINER_multihashmap_destroy (forward_map); 1516 GNUNET_CONTAINER_multihashmap_destroy(forward_map);
1522 forward_map = NULL; 1517 forward_map = NULL;
1523 } 1518 }
1524} 1519}
1525 1520
1526/* end of gnunet-service-dht_clients.c */ 1521/* end of gnunet-service-dht_clients.c */