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