diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-05 12:10:58 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-05 12:10:58 +0000 |
commit | 92e7053ff3b21507b8b385c558bfb51c45f6e365 (patch) | |
tree | e8d242982db00c92d5cbaf9bbc358a029074dd24 /src/dht | |
parent | d4c2d46ce0ebf0003b1383c4bf7e62e28abaf85f (diff) | |
download | gnunet-92e7053ff3b21507b8b385c558bfb51c45f6e365.tar.gz gnunet-92e7053ff3b21507b8b385c558bfb51c45f6e365.zip |
fix for block libraries so they don't need to understand dht struct
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/Makefile.am | 2 | ||||
-rw-r--r-- | src/dht/gnunet-dht-driver.c | 6 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 16 | ||||
-rw-r--r-- | src/dht/test_dht_twopeer_data.conf | 2 | ||||
-rw-r--r-- | src/dht/test_dht_twopeer_put_get.c | 92 |
5 files changed, 97 insertions, 21 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index c0d9bab13..8fa84d2fa 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -84,7 +84,7 @@ bin_PROGRAMS = $(STUD_PROGS) \ | |||
84 | gnunet-service-dht \ | 84 | gnunet-service-dht \ |
85 | gnunet-dht-get \ | 85 | gnunet-dht-get \ |
86 | gnunet-dht-get-peer \ | 86 | gnunet-dht-get-peer \ |
87 | gnunet-dht-put | 87 | gnunet-dht-put |
88 | 88 | ||
89 | if HAVE_MALICIOUS | 89 | if HAVE_MALICIOUS |
90 | noinst_PROGRAMS = \ | 90 | noinst_PROGRAMS = \ |
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index ec97c7a05..97c8ed660 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c | |||
@@ -1850,9 +1850,9 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1850 | GNUNET_BLOCK_TYPE_TEST, | 1850 | GNUNET_BLOCK_TYPE_TEST, |
1851 | &known_keys[test_get->uid], | 1851 | &known_keys[test_get->uid], |
1852 | get_replication, | 1852 | get_replication, |
1853 | GNUNET_DHT_RO_NONE, | 1853 | GNUNET_DHT_RO_NONE, |
1854 | NULL, 0, | 1854 | NULL, 0, |
1855 | NULL, 0, | 1855 | NULL, 0, |
1856 | &get_result_iterator, | 1856 | &get_result_iterator, |
1857 | test_get); | 1857 | test_get); |
1858 | 1858 | ||
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index fa2b9551b..bb7b74404 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -2365,13 +2365,6 @@ datacache_get_iterator (void *cls, | |||
2365 | "`%s:%s': Received `%s' response from datacache\n", my_short_id, | 2365 | "`%s:%s': Received `%s' response from datacache\n", my_short_id, |
2366 | "DHT", "GET"); | 2366 | "DHT", "GET"); |
2367 | #endif | 2367 | #endif |
2368 | eval = GNUNET_BLOCK_evaluate (block_context, | ||
2369 | type, | ||
2370 | key, | ||
2371 | &msg_ctx->reply_bf, | ||
2372 | msg_ctx->reply_bf_mutator, | ||
2373 | msg_ctx->xquery, | ||
2374 | msg_ctx->xquery_size, data, size); | ||
2375 | 2368 | ||
2376 | put_entry = (const struct DHTPutEntry *)data; | 2369 | put_entry = (const struct DHTPutEntry *)data; |
2377 | 2370 | ||
@@ -2390,6 +2383,14 @@ datacache_get_iterator (void *cls, | |||
2390 | return GNUNET_OK; | 2383 | return GNUNET_OK; |
2391 | } | 2384 | } |
2392 | 2385 | ||
2386 | eval = GNUNET_BLOCK_evaluate (block_context, | ||
2387 | type, | ||
2388 | key, | ||
2389 | &msg_ctx->reply_bf, | ||
2390 | msg_ctx->reply_bf_mutator, | ||
2391 | msg_ctx->xquery, | ||
2392 | msg_ctx->xquery_size, &put_entry[1], put_entry->data_size); | ||
2393 | |||
2393 | switch (eval) | 2394 | switch (eval) |
2394 | { | 2395 | { |
2395 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 2396 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
@@ -2994,6 +2995,7 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg, | |||
2994 | path_offset += data_size; | 2995 | path_offset += data_size; |
2995 | memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); | 2996 | memcpy(path_offset, msg_ctx->path_history, msg_ctx->path_history_len * sizeof(struct GNUNET_PeerIdentity)); |
2996 | } | 2997 | } |
2998 | |||
2997 | ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size, | 2999 | ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size, |
2998 | (char *) put_entry, put_type, | 3000 | (char *) put_entry, put_type, |
2999 | GNUNET_TIME_absolute_ntoh | 3001 | GNUNET_TIME_absolute_ntoh |
diff --git a/src/dht/test_dht_twopeer_data.conf b/src/dht/test_dht_twopeer_data.conf index 491c10c7a..f81cad221 100644 --- a/src/dht/test_dht_twopeer_data.conf +++ b/src/dht/test_dht_twopeer_data.conf | |||
@@ -12,7 +12,7 @@ PORT = 2100 | |||
12 | DISABLE_SOCKET_FORWARDING = YES | 12 | DISABLE_SOCKET_FORWARDING = YES |
13 | 13 | ||
14 | [block] | 14 | [block] |
15 | plugins = test dht | 15 | plugins = test dht dns |
16 | 16 | ||
17 | [dhtcache] | 17 | [dhtcache] |
18 | QUOTA = 1000000 | 18 | QUOTA = 1000000 |
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c index 8e10eea6b..1d0af082b 100644 --- a/src/dht/test_dht_twopeer_put_get.c +++ b/src/dht/test_dht_twopeer_put_get.c | |||
@@ -40,6 +40,8 @@ | |||
40 | #include "gnunet_testing_lib.h" | 40 | #include "gnunet_testing_lib.h" |
41 | #include "gnunet_core_service.h" | 41 | #include "gnunet_core_service.h" |
42 | #include "gnunet_dht_service.h" | 42 | #include "gnunet_dht_service.h" |
43 | #include "block_dns.h" | ||
44 | #include "gnunet_signatures.h" | ||
43 | 45 | ||
44 | /* DEFINES */ | 46 | /* DEFINES */ |
45 | #define VERBOSE GNUNET_NO | 47 | #define VERBOSE GNUNET_NO |
@@ -53,6 +55,8 @@ | |||
53 | /* If number of peers not in config file, use this number */ | 55 | /* If number of peers not in config file, use this number */ |
54 | #define DEFAULT_NUM_PEERS 2 | 56 | #define DEFAULT_NUM_PEERS 2 |
55 | 57 | ||
58 | #define DNS GNUNET_NO | ||
59 | |||
56 | /* Globals */ | 60 | /* Globals */ |
57 | 61 | ||
58 | /** | 62 | /** |
@@ -106,6 +110,10 @@ GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
106 | /* Global return value (0 for success, anything else for failure) */ | 110 | /* Global return value (0 for success, anything else for failure) */ |
107 | static int ok; | 111 | static int ok; |
108 | 112 | ||
113 | #if DNS | ||
114 | struct GNUNET_DNS_Record data; | ||
115 | #endif | ||
116 | |||
109 | /** | 117 | /** |
110 | * Peer identity of the first peer started. | 118 | * Peer identity of the first peer started. |
111 | */ | 119 | */ |
@@ -222,7 +230,6 @@ void get_result_iterator (void *cls, | |||
222 | return; | 230 | return; |
223 | } | 231 | } |
224 | 232 | ||
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); | ||
226 | GNUNET_SCHEDULER_cancel(die_task); | 233 | GNUNET_SCHEDULER_cancel(die_task); |
227 | GNUNET_DHT_get_stop(global_get_handle); | 234 | GNUNET_DHT_get_stop(global_get_handle); |
228 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 235 | GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
@@ -235,15 +242,23 @@ static void | |||
235 | do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 242 | do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
236 | { | 243 | { |
237 | GNUNET_HashCode key; /* Key for data lookup */ | 244 | GNUNET_HashCode key; /* Key for data lookup */ |
245 | #if DNS | ||
246 | memcpy(&key, &data.service_descriptor, sizeof(GNUNET_HashCode)); | ||
247 | #else | ||
238 | memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ | 248 | memset(&key, 42, sizeof(GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */ |
249 | #endif | ||
239 | global_get_handle = GNUNET_DHT_get_start(peer2dht, GNUNET_TIME_relative_get_forever(), | 250 | global_get_handle = GNUNET_DHT_get_start(peer2dht, GNUNET_TIME_relative_get_forever(), |
240 | GNUNET_BLOCK_TYPE_TEST, | 251 | #if DNS |
241 | &key, | 252 | GNUNET_BLOCK_TYPE_DNS, |
242 | DEFAULT_GET_REPLICATION, | 253 | #else |
243 | GNUNET_DHT_RO_NONE, | 254 | GNUNET_BLOCK_TYPE_TEST, |
244 | NULL, 0, | 255 | #endif |
245 | NULL, 0, | 256 | &key, |
246 | &get_result_iterator, NULL); | 257 | DEFAULT_GET_REPLICATION, |
258 | GNUNET_DHT_RO_NONE, | ||
259 | NULL, 0, | ||
260 | NULL, 0, | ||
261 | &get_result_iterator, NULL); | ||
247 | } | 262 | } |
248 | 263 | ||
249 | /** | 264 | /** |
@@ -259,6 +274,8 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
259 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); | 274 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); |
260 | } | 275 | } |
261 | 276 | ||
277 | |||
278 | #if !DNS | ||
262 | /** | 279 | /** |
263 | * Set up some data, and call API PUT function | 280 | * Set up some data, and call API PUT function |
264 | */ | 281 | */ |
@@ -274,13 +291,70 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
274 | GNUNET_DHT_put(peer1dht, | 291 | GNUNET_DHT_put(peer1dht, |
275 | &key, | 292 | &key, |
276 | DEFAULT_PUT_REPLICATION, | 293 | DEFAULT_PUT_REPLICATION, |
277 | GNUNET_DHT_RO_NONE, | 294 | GNUNET_DHT_RO_NONE, |
278 | GNUNET_BLOCK_TYPE_TEST, | 295 | GNUNET_BLOCK_TYPE_TEST, |
279 | sizeof(data), data, | 296 | sizeof(data), data, |
280 | GNUNET_TIME_UNIT_FOREVER_ABS, | 297 | GNUNET_TIME_UNIT_FOREVER_ABS, |
281 | GNUNET_TIME_UNIT_FOREVER_REL, | 298 | GNUNET_TIME_UNIT_FOREVER_REL, |
282 | &put_finished, NULL); | 299 | &put_finished, NULL); |
283 | } | 300 | } |
301 | #else | ||
302 | |||
303 | /** | ||
304 | * Set up some data, and call API PUT function | ||
305 | */ | ||
306 | static void | ||
307 | do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
308 | { | ||
309 | char* name = "philipptoelke.gnunet."; | ||
310 | size_t size = sizeof(struct GNUNET_DNS_Record); | ||
311 | memset(&data, 0, size); | ||
312 | |||
313 | data.purpose.size = htonl(size - sizeof(struct GNUNET_CRYPTO_RsaSignature)); | ||
314 | data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD; | ||
315 | |||
316 | GNUNET_CRYPTO_hash(name, strlen(name)+1, &data.service_descriptor); | ||
317 | |||
318 | data.service_type = htonl(GNUNET_DNS_SERVICE_TYPE_UDP); | ||
319 | data.ports = htons(69); | ||
320 | |||
321 | char* keyfile; | ||
322 | GNUNET_asprintf(&keyfile, "/tmp/test_dns_data_key"); | ||
323 | struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file(keyfile); | ||
324 | GNUNET_free(keyfile); | ||
325 | GNUNET_assert(my_private_key != NULL); | ||
326 | |||
327 | GNUNET_CRYPTO_rsa_key_get_public(my_private_key, &data.peer); | ||
328 | |||
329 | data.expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS); | ||
330 | |||
331 | /* Sign the block */ | ||
332 | if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign(my_private_key, | ||
333 | &data.purpose, | ||
334 | &data.signature)) | ||
335 | { | ||
336 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); | ||
337 | return; | ||
338 | } | ||
339 | GNUNET_CRYPTO_rsa_key_free(my_private_key); | ||
340 | |||
341 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
342 | "Putting with key %08x\n", | ||
343 | *((unsigned int*)&data.service_descriptor)); | ||
344 | |||
345 | GNUNET_DHT_put(peer1dht, | ||
346 | &data.service_descriptor, | ||
347 | DEFAULT_PUT_REPLICATION, | ||
348 | GNUNET_DHT_RO_NONE, | ||
349 | GNUNET_BLOCK_TYPE_DNS, | ||
350 | size, | ||
351 | (char*)&data, | ||
352 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), | ||
353 | GNUNET_TIME_UNIT_MINUTES, | ||
354 | &put_finished, | ||
355 | NULL); | ||
356 | } | ||
357 | #endif | ||
284 | 358 | ||
285 | /** | 359 | /** |
286 | * This function is called whenever a connection attempt is finished between two of | 360 | * This function is called whenever a connection attempt is finished between two of |