From: Martin Schanzenbach Date: Sun, 26 Feb 2012 17:51:46 +0000 (+0000) Subject: -block compiles and added to makefile X-Git-Tag: initial-import-from-subversion-38251~14632 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8be6916ef54f9952b099276d63ef1ebe4b88d4d6;p=oweals%2Fgnunet.git -block compiles and added to makefile --- diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 9f947b2c1..52776993e 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -27,6 +27,9 @@ bin_PROGRAMS = \ check_SCRIPTS = \ test_gnunet_gns.sh +plugin_LTLIBRARIES = \ + libgnunet_plugin_block_gns.la + #gnunet_gns_lookup_SOURCES = \ # gnunet-gns-lookup.c #gnunet_gns_lookup_LDADD = \ @@ -56,6 +59,13 @@ libgnunetgns_la_LIBADD = \ libgnunetgns_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) +libgnunet_plugin_block_gns_la_SOURCES = \ + plugin_block_gns.c +libgnunet_plugin_block_gns_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la +libgnunet_plugin_block_gns_la_LDFLAGS = \ + $(top_builddir)/src/block/$(GN_PLUGIN_LDFLAGS) + #Build stub api libgnunetnamestore_la_SOURCES = \ namestore_stub_api.c diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 7bf4e29cd..f31b9a9c4 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -26,6 +26,7 @@ #include "platform.h" #include "gnunet_block_plugin.h" +#include "gnunet_namestore_service.h" #include "block_gns.h" #include "gnunet_signatures.h" @@ -35,6 +36,9 @@ */ #define BLOOMFILTER_K 16 +//Not taken until now +#define GNUNET_BLOCK_TYPE_GNS_NAMERECORD 11 + /** * Function called to validate a reply or a request. For * request evaluation, simply pass "NULL" for the reply_block. @@ -63,27 +67,20 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, { if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; - - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; + char* name; GNUNET_HashCode pkey_hash; GNUNET_HashCode query_pkey; GNUNET_HashCode name_hash; struct GNSNameRecordBlock *nrb; struct GNSRecordBlock *rb; + uint32_t rd_count; - uint32_t rd_num; - uint32_t type; - struct GNUNET_TIME_AbsoluteNBO; - uint32_t data_length; - uint32_t flags; + nrb = (struct GNSNameRecordBlock *)reply_block; - char* pos = (char*) reply_block; - nrb = reply_block; + name = (char*)&nrb[1]; - name = &nrb[1]; - - GNUNET_CRYPTO_hash(nrb->public_key, + GNUNET_CRYPTO_hash(&nrb->public_key, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pkey_hash); @@ -95,35 +92,35 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, if (0 != GNUNET_CRYPTO_hash_cmp(&query_pkey, &pkey_hash)) return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; - rd_count = ntohl(nrb->rd_num); + rd_count = ntohl(nrb->rd_count); struct GNUNET_NAMESTORE_RecordData rd[rd_count]; int i = 0; - rb = &nrb[1] + strlen(name); + rb = (struct GNSRecordBlock*)(&nrb[1] + strlen(name)); for (i=0; itype); + rd[i].record_type = ntohl(rb->type); rd[i].expiration = - GNUNET_TIME_relative_ntoh(rb->expiration); - rd[i].data_length = ntohl(rb->data_length); + GNUNET_TIME_absolute_ntoh(rb->expiration); + rd[i].data_size = ntohl(rb->data_length); rd[i].flags = ntohl(rb->flags); - rd[i].data = rb[1]; - rb = &rb[1] + rd[i].data_length; + rd[i].data = (char*)&rb[1]; + rb = &rb[1] + rd[i].data_size; } - if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (nrb->public_key, + if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, name, nrb->rd_count, rd, - nrb->signature)) + &nrb->signature)) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; } - //Cache - GNUNET_NAMESTORE_record_put (handle, //FIXME where do i get this from? + //Cache FIXME we need a static function here to namestore? + /*GNUNET_NAMESTORE_record_put (handle, //FIXME where do i get this from? &pkey_hash, name, expiration, //FIXME uh where do i get this from? @@ -131,7 +128,7 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, rd, signature, NULL, //cont - NULL); //cls + NULL); //cls*/ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; } @@ -152,8 +149,19 @@ block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, GNUNET_HashCode * key) { - if (type != GNUNET_BLOCK_TYPE_GNS_RECORD) + if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) return GNUNET_NO; + GNUNET_HashCode name_hash; + GNUNET_HashCode pkey_hash; + struct GNSNameRecordBlock *nrb = (struct GNSNameRecordBlock *)block; + + GNUNET_CRYPTO_hash(&nrb[1], strlen((char*)&nrb[1]), &name_hash); + GNUNET_CRYPTO_hash(&nrb->public_key, + sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &pkey_hash); + + GNUNET_CRYPTO_hash_xor(&name_hash, &pkey_hash, key); + //FIXME calculate key from name and hash(pkey) here return GNUNET_OK; } @@ -167,7 +175,7 @@ libgnunet_plugin_block_gns_init (void *cls) { static enum GNUNET_BLOCK_Type types[] = { - GNUNET_BLOCK_TYPE_GNS_RECORD, + GNUNET_BLOCK_TYPE_GNS_NAMERECORD, GNUNET_BLOCK_TYPE_ANY /* end of list */ }; struct GNUNET_BLOCK_PluginFunctions *api; diff --git a/src/include/block_gns.h b/src/include/block_gns.h index 99f019a11..4514acf6b 100644 --- a/src/include/block_gns.h +++ b/src/include/block_gns.h @@ -56,7 +56,7 @@ struct GNSRecordBlock //Class of the record? /* followed by the record data */ -} +}; /** * @brief a record block for a given name of a single authority @@ -80,7 +80,7 @@ struct GNSNameRecordBlock struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; /* number of records that follow */ - uint32_t rd_num GNUNET_PACKED; + uint32_t rd_count GNUNET_PACKED; /* 0-terminated name here */