diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-14 14:16:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-14 14:16:08 +0000 |
commit | f96aac2ff4f49d1d7ee85061e2fa23ec5efdb950 (patch) | |
tree | 70bf60fe6cbd2eb1ef3f60038f66503f65119681 /src/dht/gnunet-service-dht.c | |
parent | 2eff3969428a953b0c587badd372585b2dbeb69a (diff) | |
download | gnunet-f96aac2ff4f49d1d7ee85061e2fa23ec5efdb950.tar.gz gnunet-f96aac2ff4f49d1d7ee85061e2fa23ec5efdb950.zip |
clean up
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r-- | src/dht/gnunet-service-dht.c | 51 |
1 files changed, 17 insertions, 34 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index d0fc06442..ab509eea4 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -27,6 +27,10 @@ | |||
27 | * TODO: | 27 | * TODO: |
28 | * - decide which 'benchmark'/test functions to keep (malicious code, kademlia, etc.) | 28 | * - decide which 'benchmark'/test functions to keep (malicious code, kademlia, etc.) |
29 | * - decide on 'stop_on_closest', 'stop_on_found', 'do_find_peer', 'paper_forwarding' | 29 | * - decide on 'stop_on_closest', 'stop_on_found', 'do_find_peer', 'paper_forwarding' |
30 | * - use OPTION_MULTIPLE instead of linked list ofr the forward_list.hashmap | ||
31 | * - use different 'struct DHT_MessageContext' for the different types of | ||
32 | * messages (currently rather confusing, especially with things like | ||
33 | * peer bloom filters occuring when processing replies). | ||
30 | */ | 34 | */ |
31 | 35 | ||
32 | #include "platform.h" | 36 | #include "platform.h" |
@@ -2667,7 +2671,7 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2667 | { | 2671 | { |
2668 | struct DHTRouteSource *pos; | 2672 | struct DHTRouteSource *pos; |
2669 | struct GNUNET_DHT_GetResultMessage *get_result; | 2673 | struct GNUNET_DHT_GetResultMessage *get_result; |
2670 | struct DHT_MessageContext *new_msg_ctx; | 2674 | struct DHT_MessageContext new_msg_ctx; |
2671 | size_t get_size; | 2675 | size_t get_size; |
2672 | 2676 | ||
2673 | pos = record->head; | 2677 | pos = record->head; |
@@ -2682,21 +2686,16 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2682 | continue; | 2686 | continue; |
2683 | } | 2687 | } |
2684 | 2688 | ||
2685 | /********** CODE ADAPTED FROM DATACHACHE_GET_ITERATOR BEGIN *************/ | 2689 | memcpy (&new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext)); |
2686 | new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext)); | ||
2687 | memcpy (new_msg_ctx, msg_ctx, sizeof (struct DHT_MessageContext)); | ||
2688 | if (GNUNET_DHT_RO_RECORD_ROUTE == | 2690 | if (GNUNET_DHT_RO_RECORD_ROUTE == |
2689 | (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) | 2691 | (msg_ctx->msg_options & GNUNET_DHT_RO_RECORD_ROUTE)) |
2690 | { | 2692 | { |
2691 | new_msg_ctx->msg_options = GNUNET_DHT_RO_RECORD_ROUTE; | 2693 | new_msg_ctx.msg_options = GNUNET_DHT_RO_RECORD_ROUTE; |
2692 | new_msg_ctx->path_history_len = msg_ctx->path_history_len; | ||
2693 | /* Assign to previous msg_ctx path history, caller should free after our return */ | ||
2694 | new_msg_ctx->path_history = msg_ctx->path_history; | ||
2695 | #if DEBUG_PATH | 2694 | #if DEBUG_PATH |
2696 | for (i = 0; i < new_msg_ctx->path_history_len; i++) | 2695 | for (i = 0; i < new_msg_ctx.path_history_len; i++) |
2697 | { | 2696 | { |
2698 | path_offset = | 2697 | path_offset = |
2699 | &new_msg_ctx->path_history[i * sizeof (struct GNUNET_PeerIdentity)]; | 2698 | &new_msg_ctx.path_history[i * sizeof (struct GNUNET_PeerIdentity)]; |
2700 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2699 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2701 | "(put for active get) Key %s Found peer %d:%s\n", | 2700 | "(put for active get) Key %s Found peer %d:%s\n", |
2702 | GNUNET_h2s (&msg_ctx->key), i, | 2701 | GNUNET_h2s (&msg_ctx->key), i, |
@@ -2714,38 +2713,22 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2714 | get_result->expiration = put_msg->expiration; | 2713 | get_result->expiration = put_msg->expiration; |
2715 | get_result->type = put_msg->type; | 2714 | get_result->type = put_msg->type; |
2716 | get_result->put_path_length = htons (msg_ctx->path_history_len); | 2715 | get_result->put_path_length = htons (msg_ctx->path_history_len); |
2717 | #if DEBUG_PATH | 2716 | |
2718 | path_offset = msg_ctx->path_history; | ||
2719 | for (i = 0; i < msg_ctx->path_history_len; i++) | ||
2720 | { | ||
2721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2722 | "(get_iterator PUT path) Key %s Found peer %d:%s\n", | ||
2723 | GNUNET_h2s (&msg_ctx->key), i, | ||
2724 | GNUNET_i2s ((struct GNUNET_PeerIdentity *) | ||
2725 | &path_offset[i * | ||
2726 | sizeof (struct | ||
2727 | GNUNET_PeerIdentity)])); | ||
2728 | } | ||
2729 | #endif | ||
2730 | /* Copy the actual data and the path_history to the end of the get result */ | 2717 | /* Copy the actual data and the path_history to the end of the get result */ |
2731 | memcpy (&get_result[1], &put_msg[1], data_size); | 2718 | memcpy (&get_result[1], &put_msg[1], data_size); |
2732 | path_offset = (char *) &get_result[1]; | 2719 | path_offset = (char *) &get_result[1]; |
2733 | path_offset += data_size; | 2720 | path_offset += data_size; |
2734 | memcpy (path_offset, msg_ctx->path_history, | 2721 | memcpy (path_offset, msg_ctx->path_history, |
2735 | msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity)); | 2722 | msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity)); |
2736 | new_msg_ctx->peer = &my_identity; | 2723 | new_msg_ctx.peer = &my_identity; |
2737 | new_msg_ctx->bloom = | 2724 | new_msg_ctx.bloom = NULL; |
2738 | GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); | 2725 | new_msg_ctx.hop_count = 0; |
2739 | new_msg_ctx->hop_count = 0; | ||
2740 | /* Make result routing a higher priority */ | 2726 | /* Make result routing a higher priority */ |
2741 | new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; | 2727 | new_msg_ctx.importance = DHT_DEFAULT_P2P_IMPORTANCE + 2; |
2742 | new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; | 2728 | new_msg_ctx.timeout = DHT_DEFAULT_P2P_TIMEOUT; |
2743 | new_msg_ctx->unique_id = pos->uid; | 2729 | new_msg_ctx.unique_id = pos->uid; |
2744 | send_reply_to_client(pos->client, &get_result->header, new_msg_ctx); | 2730 | send_reply_to_client(pos->client, &get_result->header, &new_msg_ctx); |
2745 | // GNUNET_CONTAINER_bloomfilter_free (new_msg_ctx->bloom); | ||
2746 | GNUNET_free (new_msg_ctx); | ||
2747 | GNUNET_free (get_result); | 2731 | GNUNET_free (get_result); |
2748 | /********** CODE ADAPTED FROM DATACHACHE_GET_ITERATOR END ***************/ | ||
2749 | pos = pos->next; | 2732 | pos = pos->next; |
2750 | } | 2733 | } |
2751 | } | 2734 | } |