aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-service-fs.c')
-rw-r--r--src/fs/gnunet-service-fs.c257
1 files changed, 158 insertions, 99 deletions
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index d40cdb744..9fce6478c 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -24,8 +24,9 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * TODO: 26 * TODO:
27 * - track per-peer request latency (using new load API)
28 * - consider more precise latency estimation (per-peer & request) -- again load API?
27 * - implement test_load_too_high, make decision priority-based, implement forwarding, etc. 29 * - implement test_load_too_high, make decision priority-based, implement forwarding, etc.
28 * - consider more precise latency estimation (per-peer & request)
29 * - introduce random latency in processing 30 * - introduce random latency in processing
30 * - tell other peers to stop migration if our PUTs fail (or if 31 * - tell other peers to stop migration if our PUTs fail (or if
31 * we don't support migration per configuration?) 32 * we don't support migration per configuration?)
@@ -35,7 +36,9 @@
35#include <float.h> 36#include <float.h>
36#include "gnunet_constants.h" 37#include "gnunet_constants.h"
37#include "gnunet_core_service.h" 38#include "gnunet_core_service.h"
39#include "gnunet_dht_service.h"
38#include "gnunet_datastore_service.h" 40#include "gnunet_datastore_service.h"
41#include "gnunet_load_lib.h"
39#include "gnunet_peer_lib.h" 42#include "gnunet_peer_lib.h"
40#include "gnunet_protocols.h" 43#include "gnunet_protocols.h"
41#include "gnunet_signatures.h" 44#include "gnunet_signatures.h"
@@ -52,6 +55,13 @@
52#define MAX_QUEUE_PER_PEER 16 55#define MAX_QUEUE_PER_PEER 16
53 56
54/** 57/**
58 * Size for the hash map for DHT requests from the FS
59 * service. Should be about the number of concurrent
60 * DHT requests we plan to make.
61 */
62#define FS_DHT_HT_SIZE 1024
63
64/**
55 * How often do we flush trust values to disk? 65 * How often do we flush trust values to disk?
56 */ 66 */
57#define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 67#define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
@@ -174,6 +184,12 @@ struct ConnectedPeer
174 struct GNUNET_TIME_Relative avg_delay; 184 struct GNUNET_TIME_Relative avg_delay;
175 185
176 /** 186 /**
187 * Point in time until which this peer does not want us to migrate content
188 * to it.
189 */
190 struct GNUNET_TIME_Absolute migration_blocked;
191
192 /**
177 * Handle for an active request for transmission to this 193 * Handle for an active request for transmission to this
178 * peer, or NULL. 194 * peer, or NULL.
179 */ 195 */
@@ -709,6 +725,11 @@ static GNUNET_SCHEDULER_TaskIdentifier mig_task;
709static struct GNUNET_TIME_Relative min_migration_delay; 725static struct GNUNET_TIME_Relative min_migration_delay;
710 726
711/** 727/**
728 * Handle for DHT operations.
729 */
730static struct GNUNET_DHT_Handle *dht_handle;
731
732/**
712 * Size of the doubly-linked list of migration blocks. 733 * Size of the doubly-linked list of migration blocks.
713 */ 734 */
714static unsigned int mig_size; 735static unsigned int mig_size;
@@ -731,6 +752,29 @@ static int active_migration;
731static double current_priorities; 752static double current_priorities;
732 753
733/** 754/**
755 * Datastore load tracking.
756 */
757static struct GNUNET_LOAD_Value *datastore_load;
758
759
760/**
761 * We've just now completed a datastore request. Update our
762 * datastore load calculations.
763 *
764 * @param start time when the datastore request was issued
765 */
766static void
767update_datastore_delays (struct GNUNET_TIME_Absolute start)
768{
769 struct GNUNET_TIME_Relative delay;
770
771 delay = GNUNET_TIME_absolute_get_duration (start);
772 GNUNET_LOAD_update (datastore_load,
773 delay.value);
774}
775
776
777/**
734 * Get the filename under which we would store the GNUNET_HELLO_Message 778 * Get the filename under which we would store the GNUNET_HELLO_Message
735 * for the given host and protocol. 779 * for the given host and protocol.
736 * @return filename of the form DIRECTORY/HOSTID 780 * @return filename of the form DIRECTORY/HOSTID
@@ -768,7 +812,6 @@ transmit_to_peer (void *cls,
768 812
769/* ******************* clean up functions ************************ */ 813/* ******************* clean up functions ************************ */
770 814
771
772/** 815/**
773 * Delete the given migration block. 816 * Delete the given migration block.
774 * 817 *
@@ -831,6 +874,8 @@ consider_migration (void *cls,
831 unsigned int repl; 874 unsigned int repl;
832 875
833 /* consider 'cp' as a migration target for mb */ 876 /* consider 'cp' as a migration target for mb */
877 if (GNUNET_TIME_absolute_get_remaining (cp->migration_blocked).value > 0)
878 return GNUNET_YES; /* peer has requested no migration! */
834 if (mb != NULL) 879 if (mb != NULL)
835 { 880 {
836 GNUNET_PEER_resolve (cp->pid, 881 GNUNET_PEER_resolve (cp->pid,
@@ -986,7 +1031,7 @@ process_migration_content (void *cls,
986 consider_migration_gathering (); 1031 consider_migration_gathering ();
987 return; 1032 return;
988 } 1033 }
989 if (type == GNUNET_BLOCK_TYPE_ONDEMAND) 1034 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
990 { 1035 {
991 if (GNUNET_OK != 1036 if (GNUNET_OK !=
992 GNUNET_FS_handle_on_demand_block (key, size, data, 1037 GNUNET_FS_handle_on_demand_block (key, size, data,
@@ -994,7 +1039,9 @@ process_migration_content (void *cls,
994 expiration, uid, 1039 expiration, uid,
995 &process_migration_content, 1040 &process_migration_content,
996 NULL)) 1041 NULL))
997 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES); 1042 {
1043 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1044 }
998 return; 1045 return;
999 } 1046 }
1000#if DEBUG_FS 1047#if DEBUG_FS
@@ -1587,6 +1634,10 @@ shutdown_task (void *cls,
1587 while (mig_head != NULL) 1634 while (mig_head != NULL)
1588 delete_migration_block (mig_head); 1635 delete_migration_block (mig_head);
1589 GNUNET_assert (0 == mig_size); 1636 GNUNET_assert (0 == mig_size);
1637 GNUNET_DHT_disconnect (dht_handle);
1638 dht_handle = NULL;
1639 GNUNET_LOAD_value_free (datastore_load);
1640 datastore_load = NULL;
1590 GNUNET_BLOCK_context_destroy (block_ctx); 1641 GNUNET_BLOCK_context_destroy (block_ctx);
1591 block_ctx = NULL; 1642 block_ctx = NULL;
1592 GNUNET_CONFIGURATION_destroy (block_cfg); 1643 GNUNET_CONFIGURATION_destroy (block_cfg);
@@ -2297,6 +2348,21 @@ forward_request_task (void *cls,
2297 } 2348 }
2298 if (GNUNET_YES == pr->local_only) 2349 if (GNUNET_YES == pr->local_only)
2299 return; /* configured to not do P2P search */ 2350 return; /* configured to not do P2P search */
2351 /* (0) try DHT */
2352 if (0 == pr->anonymity_level)
2353 {
2354#if 0
2355 /* DHT API needs fixing... */
2356 pr->dht_get = GNUNET_DHT_get_start (dht_handle,
2357 GNUNET_TIME_UNIT_FOREVER_REL,
2358 pr->type,
2359 &pr->query,
2360 &process_dht_reply,
2361 pr,
2362 FIXME,
2363 FIXME);
2364#endif
2365 }
2300 /* (1) select target */ 2366 /* (1) select target */
2301 psc.pr = pr; 2367 psc.pr = pr;
2302 psc.target_score = -DBL_MAX; 2368 psc.target_score = -DBL_MAX;
@@ -2376,14 +2442,14 @@ transmit_reply_continuation (void *cls,
2376 2442
2377 switch (pr->type) 2443 switch (pr->type)
2378 { 2444 {
2379 case GNUNET_BLOCK_TYPE_DBLOCK: 2445 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
2380 case GNUNET_BLOCK_TYPE_IBLOCK: 2446 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
2381 /* only one reply expected, done with the request! */ 2447 /* only one reply expected, done with the request! */
2382 destroy_pending_request (pr); 2448 destroy_pending_request (pr);
2383 break; 2449 break;
2384 case GNUNET_BLOCK_TYPE_ANY: 2450 case GNUNET_BLOCK_TYPE_ANY:
2385 case GNUNET_BLOCK_TYPE_KBLOCK: 2451 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
2386 case GNUNET_BLOCK_TYPE_SBLOCK: 2452 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
2387 break; 2453 break;
2388 default: 2454 default:
2389 GNUNET_break (0); 2455 GNUNET_break (0);
@@ -2476,12 +2542,6 @@ struct ProcessReplyClosure
2476 size_t size; 2542 size_t size;
2477 2543
2478 /** 2544 /**
2479 * Namespace that this reply belongs to
2480 * (if it is of type SBLOCK).
2481 */
2482 GNUNET_HashCode namespace;
2483
2484 /**
2485 * Type of the block. 2545 * Type of the block.
2486 */ 2546 */
2487 enum GNUNET_BLOCK_Type type; 2547 enum GNUNET_BLOCK_Type type;
@@ -2492,6 +2552,11 @@ struct ProcessReplyClosure
2492 uint32_t priority; 2552 uint32_t priority;
2493 2553
2494 /** 2554 /**
2555 * Evaluation result (returned).
2556 */
2557 enum GNUNET_BLOCK_EvaluationResult eval;
2558
2559 /**
2495 * Did we finish processing the associated request? 2560 * Did we finish processing the associated request?
2496 */ 2561 */
2497 int finished; 2562 int finished;
@@ -2519,7 +2584,6 @@ process_reply (void *cls,
2519 struct PutMessage *pm; 2584 struct PutMessage *pm;
2520 struct ConnectedPeer *cp; 2585 struct ConnectedPeer *cp;
2521 struct GNUNET_TIME_Relative cur_delay; 2586 struct GNUNET_TIME_Relative cur_delay;
2522 enum GNUNET_BLOCK_EvaluationResult eval;
2523 size_t msize; 2587 size_t msize;
2524 2588
2525#if DEBUG_FS 2589#if DEBUG_FS
@@ -2565,15 +2629,15 @@ process_reply (void *cls,
2565 GNUNET_SERVER_client_keep (pr->client_request_list->client_list->client); 2629 GNUNET_SERVER_client_keep (pr->client_request_list->client_list->client);
2566 } 2630 }
2567 } 2631 }
2568 eval = GNUNET_BLOCK_evaluate (block_ctx, 2632 prq->eval = GNUNET_BLOCK_evaluate (block_ctx,
2569 prq->type, 2633 prq->type,
2570 key, 2634 key,
2571 &pr->bf, 2635 &pr->bf,
2572 pr->mingle, 2636 pr->mingle,
2573 pr->namespace, (pr->namespace != NULL) ? sizeof (GNUNET_HashCode) : 0, 2637 pr->namespace, (pr->namespace != NULL) ? sizeof (GNUNET_HashCode) : 0,
2574 prq->data, 2638 prq->data,
2575 prq->size); 2639 prq->size);
2576 switch (eval) 2640 switch (prq->eval)
2577 { 2641 {
2578 case GNUNET_BLOCK_EVALUATION_OK_MORE: 2642 case GNUNET_BLOCK_EVALUATION_OK_MORE:
2579 break; 2643 break;
@@ -2636,8 +2700,21 @@ process_reply (void *cls,
2636 &pr->replies_seen[pr->replies_seen_off++]); 2700 &pr->replies_seen[pr->replies_seen_off++]);
2637 refresh_bloomfilter (pr); 2701 refresh_bloomfilter (pr);
2638 } 2702 }
2703 if (NULL == prq->sender)
2704 {
2705#if DEBUG_FS
2706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2707 "Found result for query `%s' in local datastore\n",
2708 GNUNET_h2s (key));
2709#endif
2710 GNUNET_STATISTICS_update (stats,
2711 gettext_noop ("# results found locally"),
2712 1,
2713 GNUNET_NO);
2714 }
2639 prq->priority += pr->remaining_priority; 2715 prq->priority += pr->remaining_priority;
2640 pr->remaining_priority = 0; 2716 pr->remaining_priority = 0;
2717 pr->results_found++;
2641 if (NULL != pr->client_request_list) 2718 if (NULL != pr->client_request_list)
2642 { 2719 {
2643 GNUNET_STATISTICS_update (stats, 2720 GNUNET_STATISTICS_update (stats,
@@ -2753,7 +2830,6 @@ handle_p2p_put (void *cls,
2753 struct GNUNET_TIME_Absolute expiration; 2830 struct GNUNET_TIME_Absolute expiration;
2754 GNUNET_HashCode query; 2831 GNUNET_HashCode query;
2755 struct ProcessReplyClosure prq; 2832 struct ProcessReplyClosure prq;
2756 const struct SBlock *sb;
2757 2833
2758 msize = ntohs (message->size); 2834 msize = ntohs (message->size);
2759 if (msize < sizeof (struct PutMessage)) 2835 if (msize < sizeof (struct PutMessage))
@@ -2766,7 +2842,7 @@ handle_p2p_put (void *cls,
2766 type = ntohl (put->type); 2842 type = ntohl (put->type);
2767 expiration = GNUNET_TIME_absolute_ntoh (put->expiration); 2843 expiration = GNUNET_TIME_absolute_ntoh (put->expiration);
2768 2844
2769 if (type == GNUNET_BLOCK_TYPE_ONDEMAND) 2845 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
2770 return GNUNET_SYSERR; 2846 return GNUNET_SYSERR;
2771 if (GNUNET_OK != 2847 if (GNUNET_OK !=
2772 GNUNET_BLOCK_get_key (block_ctx, 2848 GNUNET_BLOCK_get_key (block_ctx,
@@ -2778,14 +2854,6 @@ handle_p2p_put (void *cls,
2778 GNUNET_break_op (0); 2854 GNUNET_break_op (0);
2779 return GNUNET_SYSERR; 2855 return GNUNET_SYSERR;
2780 } 2856 }
2781 if (GNUNET_BLOCK_TYPE_SBLOCK == type)
2782 {
2783 sb = (const struct SBlock*) &put[1];
2784 GNUNET_CRYPTO_hash (&sb->subspace,
2785 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
2786 &prq.namespace);
2787 }
2788
2789#if DEBUG_FS 2857#if DEBUG_FS
2790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2791 "Received result for query `%s' from peer `%4s'\n", 2859 "Received result for query `%s' from peer `%4s'\n",
@@ -2838,6 +2906,30 @@ handle_p2p_put (void *cls,
2838} 2906}
2839 2907
2840 2908
2909/**
2910 * Handle P2P "MIGRATION_STOP" message.
2911 *
2912 * @param cls closure, always NULL
2913 * @param other the other peer involved (sender or receiver, NULL
2914 * for loopback messages where we are both sender and receiver)
2915 * @param message the actual message
2916 * @param latency reported latency of the connection with 'other'
2917 * @param distance reported distance (DV) to 'other'
2918 * @return GNUNET_OK to keep the connection open,
2919 * GNUNET_SYSERR to close it (signal serious error)
2920 */
2921static int
2922handle_p2p_migration_stop (void *cls,
2923 const struct GNUNET_PeerIdentity *other,
2924 const struct GNUNET_MessageHeader *message,
2925 struct GNUNET_TIME_Relative latency,
2926 uint32_t distance)
2927{
2928 // FIXME!
2929}
2930
2931
2932
2841/* **************************** P2P GET Handling ************************ */ 2933/* **************************** P2P GET Handling ************************ */
2842 2934
2843 2935
@@ -2923,10 +3015,8 @@ process_local_reply (void *cls,
2923 struct PendingRequest *pr = cls; 3015 struct PendingRequest *pr = cls;
2924 struct ProcessReplyClosure prq; 3016 struct ProcessReplyClosure prq;
2925 struct CheckDuplicateRequestClosure cdrc; 3017 struct CheckDuplicateRequestClosure cdrc;
2926 const struct SBlock *sb;
2927 GNUNET_HashCode dhash;
2928 GNUNET_HashCode mhash;
2929 GNUNET_HashCode query; 3018 GNUNET_HashCode query;
3019 unsigned int old_rf;
2930 3020
2931 if (NULL == key) 3021 if (NULL == key)
2932 { 3022 {
@@ -2973,7 +3063,7 @@ process_local_reply (void *cls,
2973 GNUNET_h2s (key), 3063 GNUNET_h2s (key),
2974 type); 3064 type);
2975#endif 3065#endif
2976 if (type == GNUNET_BLOCK_TYPE_ONDEMAND) 3066 if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND)
2977 { 3067 {
2978#if DEBUG_FS 3068#if DEBUG_FS
2979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2989,54 +3079,16 @@ process_local_reply (void *cls,
2989 &process_local_reply, 3079 &process_local_reply,
2990 pr)) 3080 pr))
2991 if (pr->qe != NULL) 3081 if (pr->qe != NULL)
2992 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES); 3082 {
2993 return; 3083 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
2994 } 3084 }
2995
2996 /* FIXME: use block lib here! */
2997 /* check for duplicates */
2998 GNUNET_CRYPTO_hash (data, size, &dhash);
2999 GNUNET_BLOCK_mingle_hash (&dhash,
3000 pr->mingle,
3001 &mhash);
3002 if ( (pr->bf != NULL) &&
3003 (GNUNET_YES ==
3004 GNUNET_CONTAINER_bloomfilter_test (pr->bf,
3005 &mhash)) )
3006 {
3007#if DEBUG_FS
3008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3009 "Result from datastore filtered by bloomfilter (duplicate).\n");
3010#endif
3011 GNUNET_STATISTICS_update (stats,
3012 gettext_noop ("# results filtered by query bloomfilter"),
3013 1,
3014 GNUNET_NO);
3015 if (pr->qe != NULL)
3016 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
3017 return; 3085 return;
3018 } 3086 }
3019#if DEBUG_FS 3087 old_rf = pr->results_found;
3020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3021 "Found result for query `%s' in local datastore\n",
3022 GNUNET_h2s (key));
3023#endif
3024 GNUNET_STATISTICS_update (stats,
3025 gettext_noop ("# results found locally"),
3026 1,
3027 GNUNET_NO);
3028 pr->results_found++;
3029 memset (&prq, 0, sizeof (prq)); 3088 memset (&prq, 0, sizeof (prq));
3030 prq.data = data; 3089 prq.data = data;
3031 prq.expiration = expiration; 3090 prq.expiration = expiration;
3032 prq.size = size; 3091 prq.size = size;
3033 if (GNUNET_BLOCK_TYPE_SBLOCK == type)
3034 {
3035 sb = (const struct SBlock*) data;
3036 GNUNET_CRYPTO_hash (&sb->subspace,
3037 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
3038 &prq.namespace);
3039 }
3040 if (GNUNET_OK != 3092 if (GNUNET_OK !=
3041 GNUNET_BLOCK_get_key (block_ctx, 3093 GNUNET_BLOCK_get_key (block_ctx,
3042 type, 3094 type,
@@ -3058,12 +3110,14 @@ process_local_reply (void *cls,
3058 prq.priority = priority; 3110 prq.priority = priority;
3059 prq.finished = GNUNET_NO; 3111 prq.finished = GNUNET_NO;
3060 process_reply (&prq, key, pr); 3112 process_reply (&prq, key, pr);
3113 if ( (old_rf == 0) &&
3114 (pr->results_found == 1) )
3115 update_datastore_delays (pr->start_time);
3061 if (prq.finished == GNUNET_YES) 3116 if (prq.finished == GNUNET_YES)
3062 return; 3117 return;
3063 if (pr->qe == NULL) 3118 if (pr->qe == NULL)
3064 return; /* done here */ 3119 return; /* done here */
3065 if ( (type == GNUNET_BLOCK_TYPE_DBLOCK) || 3120 if (prq.eval == GNUNET_BLOCK_EVALUATION_OK_LAST)
3066 (type == GNUNET_BLOCK_TYPE_IBLOCK) )
3067 { 3121 {
3068 GNUNET_DATASTORE_get_next (dsh, GNUNET_NO); 3122 GNUNET_DATASTORE_get_next (dsh, GNUNET_NO);
3069 return; 3123 return;
@@ -3211,12 +3265,6 @@ handle_p2p_get (void *cls,
3211 opt = (const GNUNET_HashCode*) &gm[1]; 3265 opt = (const GNUNET_HashCode*) &gm[1];
3212 bfsize = msize - sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode); 3266 bfsize = msize - sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode);
3213 bm = ntohl (gm->hash_bitmap); 3267 bm = ntohl (gm->hash_bitmap);
3214 if ( (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) &&
3215 (type != GNUNET_BLOCK_TYPE_SBLOCK) )
3216 {
3217 GNUNET_break_op (0);
3218 return GNUNET_SYSERR;
3219 }
3220 bits = 0; 3268 bits = 0;
3221 cps = GNUNET_CONTAINER_multihashmap_get (connected_peers, 3269 cps = GNUNET_CONTAINER_multihashmap_get (connected_peers,
3222 &other->hashPubKey); 3270 &other->hashPubKey);
@@ -3297,7 +3345,6 @@ handle_p2p_get (void *cls,
3297 pr->mingle = ntohl (gm->filter_mutator); 3345 pr->mingle = ntohl (gm->filter_mutator);
3298 if (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) 3346 if (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO))
3299 pr->target_pid = GNUNET_PEER_intern ((const struct GNUNET_PeerIdentity*) &opt[bits++]); 3347 pr->target_pid = GNUNET_PEER_intern ((const struct GNUNET_PeerIdentity*) &opt[bits++]);
3300
3301 pr->anonymity_level = 1; 3348 pr->anonymity_level = 1;
3302 pr->priority = bound_priority (ntohl (gm->priority), cps); 3349 pr->priority = bound_priority (ntohl (gm->priority), cps);
3303 pr->ttl = bound_ttl (ntohl (gm->ttl), pr->priority); 3350 pr->ttl = bound_ttl (ntohl (gm->ttl), pr->priority);
@@ -3402,7 +3449,7 @@ handle_p2p_get (void *cls,
3402 /* calculate change in traffic preference */ 3449 /* calculate change in traffic preference */
3403 cps->inc_preference += pr->priority * 1000 + QUERY_BANDWIDTH_VALUE; 3450 cps->inc_preference += pr->priority * 1000 + QUERY_BANDWIDTH_VALUE;
3404 /* process locally */ 3451 /* process locally */
3405 if (type == GNUNET_BLOCK_TYPE_DBLOCK) 3452 if (type == GNUNET_BLOCK_TYPE_FS_DBLOCK)
3406 type = GNUNET_BLOCK_TYPE_ANY; /* to get on-demand as well */ 3453 type = GNUNET_BLOCK_TYPE_ANY; /* to get on-demand as well */
3407 timeout = GNUNET_TIME_relative_multiply (BASIC_DATASTORE_REQUEST_DELAY, 3454 timeout = GNUNET_TIME_relative_multiply (BASIC_DATASTORE_REQUEST_DELAY,
3408 (pr->priority + 1)); 3455 (pr->priority + 1));
@@ -3418,8 +3465,8 @@ handle_p2p_get (void *cls,
3418 /* Are multiple results possible? If so, start processing remotely now! */ 3465 /* Are multiple results possible? If so, start processing remotely now! */
3419 switch (pr->type) 3466 switch (pr->type)
3420 { 3467 {
3421 case GNUNET_BLOCK_TYPE_DBLOCK: 3468 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
3422 case GNUNET_BLOCK_TYPE_IBLOCK: 3469 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
3423 /* only one result, wait for datastore */ 3470 /* only one result, wait for datastore */
3424 break; 3471 break;
3425 default: 3472 default:
@@ -3499,8 +3546,8 @@ handle_start_search (void *cls,
3499 client_list = cl; 3546 client_list = cl;
3500 } 3547 }
3501 /* detect duplicate KBLOCK requests */ 3548 /* detect duplicate KBLOCK requests */
3502 if ( (type == GNUNET_BLOCK_TYPE_KBLOCK) || 3549 if ( (type == GNUNET_BLOCK_TYPE_FS_KBLOCK) ||
3503 (type == GNUNET_BLOCK_TYPE_NBLOCK) || 3550 (type == GNUNET_BLOCK_TYPE_FS_NBLOCK) ||
3504 (type == GNUNET_BLOCK_TYPE_ANY) ) 3551 (type == GNUNET_BLOCK_TYPE_ANY) )
3505 { 3552 {
3506 crl = cl->rl_head; 3553 crl = cl->rl_head;
@@ -3542,7 +3589,7 @@ handle_start_search (void *cls,
3542 1, 3589 1,
3543 GNUNET_NO); 3590 GNUNET_NO);
3544 pr = GNUNET_malloc (sizeof (struct PendingRequest) + 3591 pr = GNUNET_malloc (sizeof (struct PendingRequest) +
3545 ((type == GNUNET_BLOCK_TYPE_SBLOCK) ? sizeof(GNUNET_HashCode) : 0)); 3592 ((type == GNUNET_BLOCK_TYPE_FS_SBLOCK) ? sizeof(GNUNET_HashCode) : 0));
3546 crl = GNUNET_malloc (sizeof (struct ClientRequestList)); 3593 crl = GNUNET_malloc (sizeof (struct ClientRequestList));
3547 memset (crl, 0, sizeof (struct ClientRequestList)); 3594 memset (crl, 0, sizeof (struct ClientRequestList));
3548 crl->client_list = cl; 3595 crl->client_list = cl;
@@ -3560,6 +3607,7 @@ handle_start_search (void *cls,
3560 sc * sizeof (GNUNET_HashCode)); 3607 sc * sizeof (GNUNET_HashCode));
3561 pr->replies_seen_off = sc; 3608 pr->replies_seen_off = sc;
3562 pr->anonymity_level = ntohl (sm->anonymity_level); 3609 pr->anonymity_level = ntohl (sm->anonymity_level);
3610 pr->start_time = GNUNET_TIME_absolute_get ();
3563 refresh_bloomfilter (pr); 3611 refresh_bloomfilter (pr);
3564 pr->query = sm->query; 3612 pr->query = sm->query;
3565 if (0 == (1 & ntohl (sm->options))) 3613 if (0 == (1 & ntohl (sm->options)))
@@ -3568,14 +3616,14 @@ handle_start_search (void *cls,
3568 pr->local_only = GNUNET_YES; 3616 pr->local_only = GNUNET_YES;
3569 switch (type) 3617 switch (type)
3570 { 3618 {
3571 case GNUNET_BLOCK_TYPE_DBLOCK: 3619 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
3572 case GNUNET_BLOCK_TYPE_IBLOCK: 3620 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
3573 if (0 != memcmp (&sm->target, 3621 if (0 != memcmp (&sm->target,
3574 &all_zeros, 3622 &all_zeros,
3575 sizeof (GNUNET_HashCode))) 3623 sizeof (GNUNET_HashCode)))
3576 pr->target_pid = GNUNET_PEER_intern ((const struct GNUNET_PeerIdentity*) &sm->target); 3624 pr->target_pid = GNUNET_PEER_intern ((const struct GNUNET_PeerIdentity*) &sm->target);
3577 break; 3625 break;
3578 case GNUNET_BLOCK_TYPE_SBLOCK: 3626 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
3579 pr->namespace = (GNUNET_HashCode*) &pr[1]; 3627 pr->namespace = (GNUNET_HashCode*) &pr[1];
3580 memcpy (&pr[1], &sm->target, sizeof (GNUNET_HashCode)); 3628 memcpy (&pr[1], &sm->target, sizeof (GNUNET_HashCode));
3581 break; 3629 break;
@@ -3587,7 +3635,7 @@ handle_start_search (void *cls,
3587 &sm->query, 3635 &sm->query,
3588 pr, 3636 pr,
3589 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 3637 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
3590 if (type == GNUNET_BLOCK_TYPE_DBLOCK) 3638 if (type == GNUNET_BLOCK_TYPE_FS_DBLOCK)
3591 type = GNUNET_BLOCK_TYPE_ANY; /* get on-demand blocks too! */ 3639 type = GNUNET_BLOCK_TYPE_ANY; /* get on-demand blocks too! */
3592 pr->qe = GNUNET_DATASTORE_get (dsh, 3640 pr->qe = GNUNET_DATASTORE_get (dsh,
3593 &sm->query, 3641 &sm->query,
@@ -3619,6 +3667,9 @@ main_init (struct GNUNET_SCHEDULER_Handle *s,
3619 GNUNET_MESSAGE_TYPE_FS_GET, 0 }, 3667 GNUNET_MESSAGE_TYPE_FS_GET, 0 },
3620 { &handle_p2p_put, 3668 { &handle_p2p_put,
3621 GNUNET_MESSAGE_TYPE_FS_PUT, 0 }, 3669 GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
3670 { &handle_p2p_migration_stop,
3671 GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
3672 sizeof (struct MigrationStopMessage) },
3622 { NULL, 0, 0 } 3673 { NULL, 0, 0 }
3623 }; 3674 };
3624 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 3675 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -3746,6 +3797,7 @@ run (void *cls,
3746 GNUNET_SCHEDULER_shutdown (sched); 3797 GNUNET_SCHEDULER_shutdown (sched);
3747 return; 3798 return;
3748 } 3799 }
3800 datastore_load = GNUNET_LOAD_value_init ();
3749 block_cfg = GNUNET_CONFIGURATION_create (); 3801 block_cfg = GNUNET_CONFIGURATION_create ();
3750 GNUNET_CONFIGURATION_set_value_string (block_cfg, 3802 GNUNET_CONFIGURATION_set_value_string (block_cfg,
3751 "block", 3803 "block",
@@ -3753,16 +3805,23 @@ run (void *cls,
3753 "fs"); 3805 "fs");
3754 block_ctx = GNUNET_BLOCK_context_create (block_cfg); 3806 block_ctx = GNUNET_BLOCK_context_create (block_cfg);
3755 GNUNET_assert (NULL != block_ctx); 3807 GNUNET_assert (NULL != block_ctx);
3808 dht_handle = GNUNET_DHT_connect (sched,
3809 cfg,
3810 FS_DHT_HT_SIZE);
3756 if ( (GNUNET_OK != GNUNET_FS_indexing_init (sched, cfg, dsh)) || 3811 if ( (GNUNET_OK != GNUNET_FS_indexing_init (sched, cfg, dsh)) ||
3757 (GNUNET_OK != main_init (sched, server, cfg)) ) 3812 (GNUNET_OK != main_init (sched, server, cfg)) )
3758 { 3813 {
3759 GNUNET_SCHEDULER_shutdown (sched); 3814 GNUNET_SCHEDULER_shutdown (sched);
3760 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO); 3815 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO);
3761 dsh = NULL; 3816 dsh = NULL;
3817 GNUNET_DHT_disconnect (dht_handle);
3818 dht_handle = NULL;
3762 GNUNET_BLOCK_context_destroy (block_ctx); 3819 GNUNET_BLOCK_context_destroy (block_ctx);
3763 block_ctx = NULL; 3820 block_ctx = NULL;
3764 GNUNET_CONFIGURATION_destroy (block_cfg); 3821 GNUNET_CONFIGURATION_destroy (block_cfg);
3765 block_cfg = NULL; 3822 block_cfg = NULL;
3823 GNUNET_LOAD_value_free (datastore_load);
3824 datastore_load = NULL;
3766 return; 3825 return;
3767 } 3826 }
3768} 3827}