aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-10-05 14:45:38 +0000
committerChristian Grothoff <christian@grothoff.org>2010-10-05 14:45:38 +0000
commitc8a23b6fce4dfadda4485492f10a4accc954b111 (patch)
treea897718d30d668304723052329510953490bf510 /src
parentb3cdbf13244b4c1b3ac84464209dedb4d3ee59c7 (diff)
downloadgnunet-c8a23b6fce4dfadda4485492f10a4accc954b111.tar.gz
gnunet-c8a23b6fce4dfadda4485492f10a4accc954b111.zip
mess
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-dht.c179
-rw-r--r--src/dht/test_dht_api.c2
-rw-r--r--src/dht/test_dht_api_peer1.conf1
-rw-r--r--src/dht/test_dht_multipeer.c2
-rw-r--r--src/dht/test_dht_twopeer_put_get.c2
5 files changed, 126 insertions, 60 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 577519268..9431ad20a 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -159,10 +159,6 @@
159 */ 159 */
160#define DEFAULT_MALICIOUS_PUT_FREQUENCY 1000 /* Default is in milliseconds */ 160#define DEFAULT_MALICIOUS_PUT_FREQUENCY 1000 /* Default is in milliseconds */
161 161
162/**
163 * Type for a malicious request, so we can ignore it during testing
164 */
165#define DHT_MALICIOUS_MESSAGE_TYPE 42
166 162
167#define DHT_DEFAULT_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) 163#define DHT_DEFAULT_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1)
168 164
@@ -419,6 +415,16 @@ struct DHT_MessageContext
419 struct GNUNET_CONTAINER_BloomFilter *bloom; 415 struct GNUNET_CONTAINER_BloomFilter *bloom;
420 416
421 /** 417 /**
418 * extended query (see gnunet_block_lib.h).
419 */
420 const void *xquery;
421
422 /**
423 * Bloomfilter to filter out duplicate replies.
424 */
425 struct GNUNET_CONTAINER_BloomFilter *reply_bf;
426
427 /**
422 * The key this request was about 428 * The key this request was about
423 */ 429 */
424 GNUNET_HashCode key; 430 GNUNET_HashCode key;
@@ -434,6 +440,16 @@ struct DHT_MessageContext
434 uint64_t unique_id; 440 uint64_t unique_id;
435 441
436 /** 442 /**
443 * Number of bytes in xquery.
444 */
445 size_t xquery_size;
446
447 /**
448 * Mutator value for the reply_bf, see gnunet_block_lib.h
449 */
450 uint32_t reply_bf_mutator;
451
452 /**
437 * Desired replication level 453 * Desired replication level
438 */ 454 */
439 uint32_t replication; 455 uint32_t replication;
@@ -461,6 +477,11 @@ struct DHT_MessageContext
461 unsigned int importance; 477 unsigned int importance;
462 478
463 /** 479 /**
480 * Should we (still) forward the request on to other peers?
481 */
482 int do_forward;
483
484 /**
464 * Did we forward this message? (may need to remember it!) 485 * Did we forward this message? (may need to remember it!)
465 */ 486 */
466 int forwarded; 487 int forwarded;
@@ -2119,36 +2140,67 @@ static int
2119datacache_get_iterator (void *cls, 2140datacache_get_iterator (void *cls,
2120 struct GNUNET_TIME_Absolute exp, 2141 struct GNUNET_TIME_Absolute exp,
2121 const GNUNET_HashCode * key, 2142 const GNUNET_HashCode * key,
2122 uint32_t size, const char *data, uint32_t type) 2143 uint32_t size, const char *data,
2144 enum GNUNET_BLOCK_Type type)
2123{ 2145{
2124 struct DHT_MessageContext *msg_ctx = cls; 2146 struct DHT_MessageContext *msg_ctx = cls;
2125 struct DHT_MessageContext *new_msg_ctx; 2147 struct DHT_MessageContext *new_msg_ctx;
2126 struct GNUNET_DHT_GetResultMessage *get_result; 2148 struct GNUNET_DHT_GetResultMessage *get_result;
2149 enum GNUNET_BLOCK_EvaluationResult eval;
2150
2127#if DEBUG_DHT 2151#if DEBUG_DHT
2128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2129 "`%s:%s': Received `%s' response from datacache\n", my_short_id, "DHT", "GET"); 2153 "`%s:%s': Received `%s' response from datacache\n", my_short_id, "DHT", "GET");
2130#endif 2154#endif
2131 new_msg_ctx = GNUNET_malloc(sizeof(struct DHT_MessageContext)); 2155 eval = GNUNET_BLOCK_evaluate (block_context,
2132 memcpy(new_msg_ctx, msg_ctx, sizeof(struct DHT_MessageContext)); 2156 type,
2133 get_result = 2157 key,
2134 GNUNET_malloc (sizeof (struct GNUNET_DHT_GetResultMessage) + size); 2158 &msg_ctx->reply_bf,
2135 get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT); 2159 msg_ctx->reply_bf_mutator,
2136 get_result->header.size = 2160 msg_ctx->xquery,
2137 htons (sizeof (struct GNUNET_DHT_GetResultMessage) + size); 2161 msg_ctx->xquery_size,
2138 get_result->expiration = GNUNET_TIME_absolute_hton(exp); 2162 data,
2139 get_result->type = htons (type); 2163 size);
2140 memcpy (&get_result[1], data, size); 2164 switch (eval)
2141 new_msg_ctx->peer = &my_identity; 2165 {
2142 new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 2166 case GNUNET_BLOCK_EVALUATION_OK_LAST:
2143 new_msg_ctx->hop_count = 0; 2167 msg_ctx->do_forward = GNUNET_NO;
2144 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make result routing a higher priority */ 2168 case GNUNET_BLOCK_EVALUATION_OK_MORE:
2145 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT; 2169 new_msg_ctx = GNUNET_malloc(sizeof(struct DHT_MessageContext));
2146 increment_stats(STAT_GET_RESPONSE_START); 2170 memcpy(new_msg_ctx, msg_ctx, sizeof(struct DHT_MessageContext));
2147 route_result_message(cls, &get_result->header, new_msg_ctx); 2171 get_result =
2148 GNUNET_free(new_msg_ctx); 2172 GNUNET_malloc (sizeof (struct GNUNET_DHT_GetResultMessage) + size);
2149 //send_reply_to_client (datacache_get_ctx->client, &get_result->header, 2173 get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT);
2150 // datacache_get_ctx->unique_id); 2174 get_result->header.size =
2151 GNUNET_free (get_result); 2175 htons (sizeof (struct GNUNET_DHT_GetResultMessage) + size);
2176 get_result->expiration = GNUNET_TIME_absolute_hton(exp);
2177 get_result->type = htons (type);
2178 memcpy (&get_result[1], data, size);
2179 new_msg_ctx->peer = &my_identity;
2180 new_msg_ctx->bloom = GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
2181 new_msg_ctx->hop_count = 0;
2182 new_msg_ctx->importance = DHT_DEFAULT_P2P_IMPORTANCE * 2; /* Make result routing a higher priority */
2183 new_msg_ctx->timeout = DHT_DEFAULT_P2P_TIMEOUT;
2184 increment_stats(STAT_GET_RESPONSE_START);
2185 route_result_message(cls, &get_result->header, new_msg_ctx);
2186 GNUNET_free(new_msg_ctx);
2187 GNUNET_free (get_result);
2188 break;
2189 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
2190 break;
2191 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
2192 break;
2193 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
2194 GNUNET_break (0);
2195 break;
2196 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
2197 GNUNET_break_op (0);
2198 msg_ctx->do_forward = GNUNET_NO;
2199 break;
2200 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
2201 /* msg_ctx->do_forward = GNUNET_NO; // not sure... */
2202 break;
2203 }
2152 return GNUNET_OK; 2204 return GNUNET_OK;
2153} 2205}
2154 2206
@@ -2181,14 +2233,11 @@ handle_dht_get (void *cls,
2181 struct DHT_MessageContext *message_context) 2233 struct DHT_MessageContext *message_context)
2182{ 2234{
2183 const struct GNUNET_DHT_GetMessage *get_msg; 2235 const struct GNUNET_DHT_GetMessage *get_msg;
2184 uint16_t get_type;
2185 uint16_t bf_size;
2186 uint16_t msize; 2236 uint16_t msize;
2187 uint16_t xquery_size; 2237 uint16_t bf_size;
2188 unsigned int results; 2238 unsigned int results;
2189 struct GNUNET_CONTAINER_BloomFilter *bf;
2190 const void *xquery;
2191 const char *end; 2239 const char *end;
2240 enum GNUNET_BLOCK_Type type;
2192 2241
2193 msize = ntohs (msg->size); 2242 msize = ntohs (msg->size);
2194 if (msize < sizeof (struct GNUNET_DHT_GetMessage)) 2243 if (msize < sizeof (struct GNUNET_DHT_GetMessage))
@@ -2198,34 +2247,34 @@ handle_dht_get (void *cls,
2198 } 2247 }
2199 get_msg = (const struct GNUNET_DHT_GetMessage *) msg; 2248 get_msg = (const struct GNUNET_DHT_GetMessage *) msg;
2200 bf_size = ntohs (get_msg->bf_size); 2249 bf_size = ntohs (get_msg->bf_size);
2201 xquery_size = ntohs (get_msg->xquery_size); 2250 message_context->xquery_size = ntohs (get_msg->xquery_size);
2202 if (msize != sizeof (struct GNUNET_DHT_GetMessage) + bf_size + xquery_size) 2251 message_context->reply_bf_mutator = get_msg->bf_mutator; /* FIXME: ntohl? */
2252 if (msize != sizeof (struct GNUNET_DHT_GetMessage) + bf_size + message_context->xquery_size)
2203 { 2253 {
2204 GNUNET_break (0); 2254 GNUNET_break (0);
2205 return 0; 2255 return 0;
2206 } 2256 }
2207 end = (const char*) &get_msg[1]; 2257 end = (const char*) &get_msg[1];
2208 if (xquery_size == 0) 2258 if (message_context->xquery_size == 0)
2209 { 2259 {
2210 xquery = NULL; 2260 message_context->xquery = NULL;
2211 } 2261 }
2212 else 2262 else
2213 { 2263 {
2214 xquery = (const void*) end; 2264 message_context->xquery = (const void*) end;
2215 end += xquery_size; 2265 end += message_context->xquery_size;
2216 } 2266 }
2217 if (bf_size == 0) 2267 if (bf_size == 0)
2218 { 2268 {
2219 bf = NULL; 2269 message_context->reply_bf = NULL;
2220 } 2270 }
2221 else 2271 else
2222 { 2272 {
2223 bf = GNUNET_CONTAINER_bloomfilter_init (end, 2273 message_context->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end,
2224 bf_size, 2274 bf_size,
2225 GNUNET_DHT_GET_BLOOMFILTER_K); 2275 GNUNET_DHT_GET_BLOOMFILTER_K);
2226 } 2276 }
2227 2277 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type);
2228 get_type = ntohs (get_msg->type);
2229#if DEBUG_DHT 2278#if DEBUG_DHT
2230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2231 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", 2280 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n",
@@ -2238,21 +2287,19 @@ handle_dht_get (void *cls,
2238 increment_stats(STAT_GETS); 2287 increment_stats(STAT_GETS);
2239 results = 0; 2288 results = 0;
2240#if HAVE_MALICIOUS 2289#if HAVE_MALICIOUS
2241 if (get_type == DHT_MALICIOUS_MESSAGE_TYPE) 2290 if (type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
2242 { 2291 {
2243 GNUNET_CONTAINER_bloomfilter_free (bf); 2292 GNUNET_CONTAINER_bloomfilter_free (message_context->reply_bf);
2244 return results; 2293 return results;
2245 } 2294 }
2246#endif 2295#endif
2247 /* FIXME: put xquery / bf into message_context and use 2296 message_context->do_forward = GNUNET_YES;
2248 them for processing! */
2249 if (datacache != NULL) 2297 if (datacache != NULL)
2250 results 2298 results
2251 = GNUNET_DATACACHE_get (datacache, 2299 = GNUNET_DATACACHE_get (datacache,
2252 &message_context->key, get_type, 2300 &message_context->key, type,
2253 &datacache_get_iterator, 2301 &datacache_get_iterator,
2254 message_context); 2302 message_context);
2255
2256 if (results >= 1) 2303 if (results >= 1)
2257 { 2304 {
2258#if DEBUG_DHT 2305#if DEBUG_DHT
@@ -2277,6 +2324,23 @@ handle_dht_get (void *cls,
2277 } 2324 }
2278#endif 2325#endif
2279 } 2326 }
2327 else
2328 {
2329 /* check query valid */
2330 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID
2331 == GNUNET_BLOCK_evaluate (block_context,
2332 type,
2333 &message_context->key,
2334 &message_context->reply_bf,
2335 message_context->reply_bf_mutator,
2336 message_context->xquery,
2337 message_context->xquery_size,
2338 NULL, 0))
2339 {
2340 GNUNET_break_op (0);
2341 message_context->do_forward = GNUNET_NO;
2342 }
2343 }
2280 2344
2281 if (message_context->hop_count == 0) /* Locally initiated request */ 2345 if (message_context->hop_count == 0) /* Locally initiated request */
2282 { 2346 {
@@ -2289,8 +2353,9 @@ handle_dht_get (void *cls,
2289 } 2353 }
2290#endif 2354#endif
2291 } 2355 }
2292 route_message2 (msg, message_context); 2356 if (message_context->do_forward == GNUNET_YES)
2293 GNUNET_CONTAINER_bloomfilter_free (bf); 2357 route_message2 (msg, message_context);
2358 GNUNET_CONTAINER_bloomfilter_free (message_context->reply_bf);
2294 return results; 2359 return results;
2295} 2360}
2296 2361
@@ -2495,7 +2560,7 @@ handle_dht_put (void *cls,
2495 struct DHT_MessageContext *message_context) 2560 struct DHT_MessageContext *message_context)
2496{ 2561{
2497 struct GNUNET_DHT_PutMessage *put_msg; 2562 struct GNUNET_DHT_PutMessage *put_msg;
2498 size_t put_type; 2563 enum GNUNET_BLOCK_Type put_type;
2499 size_t data_size; 2564 size_t data_size;
2500 int ret; 2565 int ret;
2501 struct RepublishContext *put_context; 2566 struct RepublishContext *put_context;
@@ -2505,9 +2570,9 @@ handle_dht_put (void *cls,
2505 2570
2506 2571
2507 put_msg = (struct GNUNET_DHT_PutMessage *)msg; 2572 put_msg = (struct GNUNET_DHT_PutMessage *)msg;
2508 put_type = ntohs (put_msg->type); 2573 put_type = (enum GNUNET_BLOCK_Type) ntohl (put_msg->type);
2509 2574
2510 if (put_type == DHT_MALICIOUS_MESSAGE_TYPE) 2575 if (put_type == GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE)
2511 return; 2576 return;
2512 2577
2513 data_size = ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage); 2578 data_size = ntohs (put_msg->header.size) - sizeof (struct GNUNET_DHT_PutMessage);
@@ -3756,7 +3821,7 @@ malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3756 3821
3757 put_message.header.size = htons(sizeof(struct GNUNET_DHT_PutMessage)); 3822 put_message.header.size = htons(sizeof(struct GNUNET_DHT_PutMessage));
3758 put_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_PUT); 3823 put_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_PUT);
3759 put_message.type = htons(DHT_MALICIOUS_MESSAGE_TYPE); 3824 put_message.type = htonl(GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE);
3760 put_message.expiration = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_forever()); 3825 put_message.expiration = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_forever());
3761 memset(&message_context, 0, sizeof(struct DHT_MessageContext)); 3826 memset(&message_context, 0, sizeof(struct DHT_MessageContext));
3762 message_context.client = NULL; 3827 message_context.client = NULL;
@@ -3800,7 +3865,7 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3800 3865
3801 get_message.header.size = htons(sizeof(struct GNUNET_DHT_GetMessage)); 3866 get_message.header.size = htons(sizeof(struct GNUNET_DHT_GetMessage));
3802 get_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_GET); 3867 get_message.header.type = htons(GNUNET_MESSAGE_TYPE_DHT_GET);
3803 get_message.type = htons(DHT_MALICIOUS_MESSAGE_TYPE); 3868 get_message.type = htonl(GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE);
3804 memset(&message_context, 0, sizeof(struct DHT_MessageContext)); 3869 memset(&message_context, 0, sizeof(struct DHT_MessageContext));
3805 message_context.client = NULL; 3870 message_context.client = NULL;
3806 random_key = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1); 3871 random_key = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t)-1);
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index b4014a92c..6650e43ab 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -362,7 +362,7 @@ test_get_iterator (void *cls,
362 const struct GNUNET_PeerIdentity * const *get_path, 362 const struct GNUNET_PeerIdentity * const *get_path,
363 const struct GNUNET_PeerIdentity * const *put_path, 363 const struct GNUNET_PeerIdentity * const *put_path,
364 enum GNUNET_BLOCK_Type type, 364 enum GNUNET_BLOCK_Type type,
365 uint32_t size, const void *data) 365 size_t size, const void *data)
366{ 366{
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "test_get_iterator called (we got a result), stopping get request!\n"); 368 "test_get_iterator called (we got a result), stopping get request!\n");
diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf
index 50cbe7138..06bf9e533 100644
--- a/src/dht/test_dht_api_peer1.conf
+++ b/src/dht/test_dht_api_peer1.conf
@@ -8,6 +8,7 @@ ACCEPT_FROM6 = ::1;
8ACCEPT_FROM = 127.0.0.1; 8ACCEPT_FROM = 127.0.0.1;
9HOSTNAME = localhost 9HOSTNAME = localhost
10PORT = 2100 10PORT = 2100
11PREFIX = valgrind
11 12
12[dhtcache] 13[dhtcache]
13QUOTA = 1000000 14QUOTA = 1000000
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c
index bc7db2302..293829bc7 100644
--- a/src/dht/test_dht_multipeer.c
+++ b/src/dht/test_dht_multipeer.c
@@ -394,7 +394,7 @@ void get_result_iterator (void *cls,
394 const struct GNUNET_PeerIdentity * const *get_path, 394 const struct GNUNET_PeerIdentity * const *get_path,
395 const struct GNUNET_PeerIdentity * const *put_path, 395 const struct GNUNET_PeerIdentity * const *put_path,
396 enum GNUNET_BLOCK_Type type, 396 enum GNUNET_BLOCK_Type type,
397 uint32_t size, 397 size_t size,
398 const void *data) 398 const void *data)
399{ 399{
400 struct TestGetContext *test_get = cls; 400 struct TestGetContext *test_get = cls;
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 4d0496db2..9ff2ae18e 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -210,7 +210,7 @@ void get_result_iterator (void *cls,
210 const struct GNUNET_PeerIdentity * const *get_path, 210 const struct GNUNET_PeerIdentity * const *get_path,
211 const struct GNUNET_PeerIdentity * const *put_path, 211 const struct GNUNET_PeerIdentity * const *put_path,
212 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
213 uint32_t size, 213 size_t size,
214 const void *data) 214 const void *data)
215{ 215{
216 GNUNET_HashCode original_key; /* Key data was stored data under */ 216 GNUNET_HashCode original_key; /* Key data was stored data under */