diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-04-05 13:07:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-04-05 13:07:27 +0000 |
commit | acd08b65a860450488d5e6b5403e43bed3748dc9 (patch) | |
tree | 20fc809a1d307b07993c4b2d80f14594e53938e1 /src/fs/fs_search.c | |
parent | 4a8a0bbb94a087d697092bad031261c0ee51a8cc (diff) | |
download | gnunet-acd08b65a860450488d5e6b5403e43bed3748dc9.tar.gz gnunet-acd08b65a860450488d5e6b5403e43bed3748dc9.zip |
nblock support done
Diffstat (limited to 'src/fs/fs_search.c')
-rw-r--r-- | src/fs/fs_search.c | 99 |
1 files changed, 94 insertions, 5 deletions
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index ce4af43fc..8674f824c 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -24,9 +24,6 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | 25 | * |
26 | * TODO: | 26 | * TODO: |
27 | * - handle namespace advertisements (NBlocks, see FIXME; | ||
28 | * note that we currently use KBLOCK instead of ANY when | ||
29 | * searching => NBLOCKS would not fit! FIX this as well!) | ||
30 | * - add support for pushing "already seen" information | 27 | * - add support for pushing "already seen" information |
31 | * to FS service for bloomfilter (can wait) | 28 | * to FS service for bloomfilter (can wait) |
32 | * - handle availability probes (can wait) | 29 | * - handle availability probes (can wait) |
@@ -412,6 +409,88 @@ process_kblock (struct GNUNET_FS_SearchContext *sc, | |||
412 | 409 | ||
413 | 410 | ||
414 | /** | 411 | /** |
412 | * Process a keyword-search result with a namespace advertisment. | ||
413 | * | ||
414 | * @param sc our search context | ||
415 | * @param nb the nblock | ||
416 | * @param size size of nb | ||
417 | */ | ||
418 | static void | ||
419 | process_nblock (struct GNUNET_FS_SearchContext *sc, | ||
420 | const struct NBlock *nb, | ||
421 | size_t size) | ||
422 | { | ||
423 | unsigned int i; | ||
424 | size_t j; | ||
425 | GNUNET_HashCode q; | ||
426 | char pt[size - sizeof (struct NBlock)]; | ||
427 | struct GNUNET_CRYPTO_AesSessionKey skey; | ||
428 | struct GNUNET_CRYPTO_AesInitializationVector iv; | ||
429 | const char *eos; | ||
430 | struct GNUNET_CONTAINER_MetaData *meta; | ||
431 | struct GNUNET_FS_Uri *uri; | ||
432 | |||
433 | GNUNET_CRYPTO_hash (&nb->keyspace, | ||
434 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
435 | &q); | ||
436 | /* find key */ | ||
437 | for (i=0;i<sc->uri->data.ksk.keywordCount;i++) | ||
438 | if (0 == memcmp (&q, | ||
439 | &sc->requests[i].query, | ||
440 | sizeof (GNUNET_HashCode))) | ||
441 | break; | ||
442 | if (i == sc->uri->data.ksk.keywordCount) | ||
443 | { | ||
444 | /* oops, does not match any of our keywords!? */ | ||
445 | GNUNET_break (0); | ||
446 | return; | ||
447 | } | ||
448 | /* decrypt */ | ||
449 | GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); | ||
450 | GNUNET_CRYPTO_aes_decrypt (&nb[1], | ||
451 | size - sizeof (struct NBlock), | ||
452 | &skey, | ||
453 | &iv, | ||
454 | pt); | ||
455 | /* parse */ | ||
456 | eos = memchr (pt, 0, sizeof (pt)); | ||
457 | if (NULL == eos) | ||
458 | { | ||
459 | GNUNET_break_op (0); | ||
460 | return; | ||
461 | } | ||
462 | j = eos - pt + 1; | ||
463 | if (sizeof (pt) == j) | ||
464 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
465 | else | ||
466 | meta = GNUNET_CONTAINER_meta_data_deserialize (&pt[j], | ||
467 | sizeof (pt) - j); | ||
468 | if (meta == NULL) | ||
469 | { | ||
470 | GNUNET_break_op (0); /* nblock malformed */ | ||
471 | return; | ||
472 | } | ||
473 | |||
474 | uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | ||
475 | uri->type = sks; | ||
476 | uri->data.sks.identifier = GNUNET_strdup (pt); | ||
477 | GNUNET_CRYPTO_hash (&nb->subspace, | ||
478 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
479 | &uri->data.sks.namespace); | ||
480 | /* FIXME: should store 'root' in meta? */ | ||
481 | GNUNET_PSEUDONYM_add (sc->h->cfg, | ||
482 | &uri->data.sks.namespace, | ||
483 | meta); | ||
484 | /* process */ | ||
485 | process_ksk_result (sc, &sc->requests[i], uri, meta); | ||
486 | |||
487 | /* clean up */ | ||
488 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
489 | GNUNET_FS_uri_destroy (uri); | ||
490 | } | ||
491 | |||
492 | |||
493 | /** | ||
415 | * Process a namespace-search result. | 494 | * Process a namespace-search result. |
416 | * | 495 | * |
417 | * @param sc our search context | 496 | * @param sc our search context |
@@ -535,7 +614,17 @@ process_result (struct GNUNET_FS_SearchContext *sc, | |||
535 | process_sblock (sc, data, size); | 614 | process_sblock (sc, data, size); |
536 | break; | 615 | break; |
537 | case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: | 616 | case GNUNET_DATASTORE_BLOCKTYPE_NBLOCK: |
538 | GNUNET_break (0); // FIXME: not implemented! | 617 | if (! GNUNET_FS_uri_test_ksk (sc->uri)) |
618 | { | ||
619 | GNUNET_break (0); | ||
620 | return; | ||
621 | } | ||
622 | if (sizeof (struct NBlock) > size) | ||
623 | { | ||
624 | GNUNET_break_op (0); | ||
625 | return; | ||
626 | } | ||
627 | process_nblock (sc, data, size); | ||
539 | break; | 628 | break; |
540 | case GNUNET_DATASTORE_BLOCKTYPE_ANY: | 629 | case GNUNET_DATASTORE_BLOCKTYPE_ANY: |
541 | case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: | 630 | case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK: |
@@ -640,7 +729,7 @@ transmit_search_request (void *cls, | |||
640 | { | 729 | { |
641 | sm[i].header.size = htons (sizeof (struct SearchMessage)); | 730 | sm[i].header.size = htons (sizeof (struct SearchMessage)); |
642 | sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 731 | sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
643 | sm[i].type = htonl (GNUNET_DATASTORE_BLOCKTYPE_KBLOCK); | 732 | sm[i].type = htonl (GNUNET_DATASTORE_BLOCKTYPE_ANY); |
644 | sm[i].anonymity_level = htonl (sc->anonymity); | 733 | sm[i].anonymity_level = htonl (sc->anonymity); |
645 | sm[i].query = sc->requests[i].query; | 734 | sm[i].query = sc->requests[i].query; |
646 | } | 735 | } |