diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-02-15 14:01:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-02-15 14:01:44 +0000 |
commit | 0ad72d359ab3ea5f232f4a8a0eb04700e8c84b49 (patch) | |
tree | 6a08051f08ff896ed9d61e80c8b74a1d282f8539 /src/fs/gnunet-service-fs_cp.c | |
parent | e3d12cb6fa5ddfb181dcade2e06888619f384457 (diff) | |
download | gnunet-0ad72d359ab3ea5f232f4a8a0eb04700e8c84b49.tar.gz gnunet-0ad72d359ab3ea5f232f4a8a0eb04700e8c84b49.zip |
stuff
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r-- | src/fs/gnunet-service-fs_cp.c | 136 |
1 files changed, 78 insertions, 58 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index f9a642199..d88598be7 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -32,6 +32,11 @@ | |||
32 | */ | 32 | */ |
33 | #define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 33 | #define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
34 | 34 | ||
35 | /** | ||
36 | * After how long do we discard a reply? | ||
37 | */ | ||
38 | #define REPLY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | ||
39 | |||
35 | 40 | ||
36 | /** | 41 | /** |
37 | * Handle to cancel a transmission request. | 42 | * Handle to cancel a transmission request. |
@@ -445,6 +450,43 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
445 | 450 | ||
446 | 451 | ||
447 | /** | 452 | /** |
453 | * Copy reply and free put message. | ||
454 | * | ||
455 | * @param cls the 'struct PutMessage' | ||
456 | * @param buf_size number of bytes available in buf | ||
457 | * @param buf where to copy the message, NULL on error (peer disconnect) | ||
458 | * @return number of bytes copied to 'buf', can be 0 (without indicating an error) | ||
459 | */ | ||
460 | static size_t | ||
461 | copy_reply (void *cls, | ||
462 | size_t buf_size, | ||
463 | void *buf) | ||
464 | { | ||
465 | struct PutMessage *pm = cls; | ||
466 | |||
467 | if (buf != NULL) | ||
468 | { | ||
469 | GNUNET_assert (size >= ntohs (pm->header.size)); | ||
470 | size = ntohs (pm->header.size); | ||
471 | memcpy (buf, pm, size); | ||
472 | GNUNET_STATISTICS_update (stats, | ||
473 | gettext_noop ("# replies transmitted to other peers"), | ||
474 | 1, | ||
475 | GNUNET_NO); | ||
476 | } | ||
477 | else | ||
478 | { | ||
479 | GNUNET_STATISTICS_update (stats, | ||
480 | gettext_noop ("# replies dropped"), | ||
481 | 1, | ||
482 | GNUNET_NO); | ||
483 | } | ||
484 | GNUNET_free (pm); | ||
485 | return size; | ||
486 | } | ||
487 | |||
488 | |||
489 | /** | ||
448 | * Handle a reply to a pending request. Also called if a request | 490 | * Handle a reply to a pending request. Also called if a request |
449 | * expires (then with data == NULL). The handler may be called | 491 | * expires (then with data == NULL). The handler may be called |
450 | * many times (depending on the request type), but will not be | 492 | * many times (depending on the request type), but will not be |
@@ -455,84 +497,62 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
455 | * @param cls 'struct GSF_ConnectedPeer' of the peer that would | 497 | * @param cls 'struct GSF_ConnectedPeer' of the peer that would |
456 | * have liked an answer to the request | 498 | * have liked an answer to the request |
457 | * @param pr handle to the original pending request | 499 | * @param pr handle to the original pending request |
500 | * @param expiration when does 'data' expire? | ||
458 | * @param data response data, NULL on request expiration | 501 | * @param data response data, NULL on request expiration |
459 | * @param data_len number of bytes in data | 502 | * @param data_len number of bytes in data |
503 | * @param more GNUNET_YES if the request remains active (may call | ||
504 | * this function again), GNUNET_NO if the request is | ||
505 | * finished (client must not call GSF_pending_request_cancel_) | ||
460 | */ | 506 | */ |
461 | static void | 507 | static void |
462 | handle_p2p_reply (void *cls, | 508 | handle_p2p_reply (void *cls, |
463 | struct GSF_PendingRequest *pr, | 509 | struct GSF_PendingRequest *pr, |
510 | struct GNUNET_TIME_Absolute expiration, | ||
464 | const void *data, | 511 | const void *data, |
465 | size_t data_len) | 512 | size_t data_len, |
513 | int more) | ||
466 | { | 514 | { |
467 | struct GSF_ConnectedPeer *cp = cls; | 515 | struct GSF_ConnectedPeer *cp = cls; |
516 | struct GSF_PendingRequest *prd; | ||
517 | struct PutMessage *pm; | ||
518 | size_t msize; | ||
468 | 519 | ||
469 | #if SUPPORT_DELAYS | 520 | prd = GSF_pending_request_get_data_ (pr); |
470 | struct GNUNET_TIME_Relative art_delay; | ||
471 | #endif | ||
472 | |||
473 | /* FIXME: adapt code fragments below to new API! */ | ||
474 | if (NULL == data) | 521 | if (NULL == data) |
475 | { | 522 | { |
476 | /* FIXME: request expired! clean up! */ | 523 | GNUNET_assert (GNUNET_NO == more); |
477 | GNUNET_STATISTICS_update (stats, | 524 | GNUNET_STATISTICS_update (stats, |
478 | gettext_noop ("# P2P searches active"), | 525 | gettext_noop ("# P2P searches active"), |
479 | -1, | 526 | -1, |
480 | GNUNET_NO); | 527 | GNUNET_NO); |
528 | GNUNET_break (GNUNET_OK == | ||
529 | GNUNET_CONTAINER_multihashmap_remove (cp->request_map, | ||
530 | &prd->query, | ||
531 | pr)); | ||
481 | return; | 532 | return; |
482 | } | 533 | } |
483 | |||
484 | /* reply will go over the network, check for cover traffic */ | ||
485 | if ( (prq->anonymity_level > 1) && | ||
486 | (cover_content_count < prq->anonymity_level - 1) ) | ||
487 | { | ||
488 | /* insufficient cover traffic, skip */ | ||
489 | GNUNET_STATISTICS_update (stats, | ||
490 | gettext_noop ("# replies suppressed due to lack of cover traffic"), | ||
491 | 1, | ||
492 | GNUNET_NO); | ||
493 | return GNUNET_YES; | ||
494 | } | ||
495 | if (prq->anonymity_level > 1) | ||
496 | cover_content_count -= prq->anonymity_level - 1; | ||
497 | |||
498 | |||
499 | cp = pr->cp; | ||
500 | #if DEBUG_FS | 534 | #if DEBUG_FS |
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
502 | "Transmitting result for query `%s' to other peer (PID=%u)\n", | 536 | "Transmitting result for query `%s'\n", |
503 | GNUNET_h2s (key), | 537 | GNUNET_h2s (key)); |
504 | (unsigned int) cp->pid); | ||
505 | #endif | 538 | #endif |
506 | GNUNET_STATISTICS_update (stats, | 539 | GNUNET_STATISTICS_update (stats, |
507 | gettext_noop ("# replies received for other peers"), | 540 | gettext_noop ("# replies received for other peers"), |
508 | 1, | 541 | 1, |
509 | GNUNET_NO); | 542 | GNUNET_NO); |
510 | msize = sizeof (struct PutMessage) + prq->size; | 543 | msize = sizeof (struct PutMessage) + data_len; |
511 | reply = GNUNET_malloc (msize + sizeof (struct PendingMessage)); | 544 | pm = GNUNET_malloc (sizeof (msize)); |
512 | reply->cont = &transmit_reply_continuation; | 545 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT); |
513 | reply->cont_cls = pr; | 546 | pm->header.size = htons (msize); |
514 | #if SUPPORT_DELAYS | 547 | pm->type = htonl (prd->type); |
515 | art_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 548 | pm->expiration = GNUNET_TIME_absolute_hton (expiration); |
516 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 549 | memcpy (&pm[1], data, data_len); |
517 | TTL_DECREMENT)); | 550 | (void) GSF_peer_transmit_ (cp, GNUNET_NO, |
518 | reply->delay_until | 551 | UINT32_MAX, |
519 | = GNUNET_TIME_relative_to_absolute (art_delay); | 552 | REPLY_TIMEOUT, |
520 | GNUNET_STATISTICS_update (stats, | 553 | msize, |
521 | gettext_noop ("cummulative artificial delay introduced (ms)"), | 554 | ©_reply, |
522 | art_delay.abs_value, | 555 | pm); |
523 | GNUNET_NO); | ||
524 | #endif | ||
525 | reply->msize = msize; | ||
526 | reply->priority = UINT32_MAX; /* send replies first! */ | ||
527 | pm = (struct PutMessage*) &reply[1]; | ||
528 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT); | ||
529 | pm->header.size = htons (msize); | ||
530 | pm->type = htonl (prq->type); | ||
531 | pm->expiration = GNUNET_TIME_absolute_hton (prq->expiration); | ||
532 | memcpy (&pm[1], prq->data, prq->size); | ||
533 | add_to_pending_messages_for_peer (cp, reply, pr); | ||
534 | |||
535 | |||
536 | } | 556 | } |
537 | 557 | ||
538 | 558 | ||