From c93c582dfed6b36d507308a2b677753f37b1d31b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 1 Mar 2012 10:37:47 +0000 Subject: [PATCH] -stuff --- src/gns/gnunet-service-gns.c | 12 +-- src/gns/plugin_block_gns.c | 57 +++++++------- src/include/block_gns.h | 5 -- src/namestore/namestore.h | 11 --- src/namestore/namestore_common.c | 127 +++++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+), 51 deletions(-) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index b5649f35c..7eaf603d9 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -39,6 +39,8 @@ #include "block_gns.h" #include "gns.h" +#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) + /* Ignore for now not used anyway and probably never will */ #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 @@ -443,11 +445,10 @@ process_name_dht_result(void* cls, * @param rh the pending gns query context * @param name the name to query record */ -void +static void resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) { uint32_t xquery; - struct GNUNET_TIME_Relative timeout; GNUNET_HashCode name_hash; GNUNET_HashCode lookup_key; struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; @@ -460,16 +461,15 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) "starting dht lookup for %s with key: %s\n", name, (char*)&lookup_key_string); - timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5); - xquery = htonl(rh->query->type); //FIXME how long to wait for results? - rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout, + rh->get_handle = GNUNET_DHT_get_start(dht_handle, + DHT_LOOKUP_TIMEOUT, GNUNET_BLOCK_TYPE_GNS_NAMERECORD, &lookup_key, 5, //Replication level FIXME GNUNET_DHT_RO_NONE, - &xquery, //xquery FIXME is this bad? + &xquery, sizeof(xquery), &process_name_dht_result, rh); diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index a4d6ad9c8..e1677b35b 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c @@ -62,11 +62,6 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, size_t xquery_size, const void *reply_block, size_t reply_block_size) { - if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) - return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; - if (reply_block_size == 0) - return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; - char* name; GNUNET_HashCode pkey_hash; GNUNET_HashCode query_key; @@ -76,7 +71,13 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, struct GNSNameRecordBlock *nrb; struct GNSRecordBlock *rb; uint32_t rd_count; - + unsigned int record_match; + + if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) + return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; + if (reply_block_size == 0) + return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + nrb = (struct GNSNameRecordBlock *)reply_block; name = (char*)&nrb[1]; GNUNET_CRYPTO_hash(&nrb->public_key, @@ -91,33 +92,31 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key)) return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; + record_match = 0; rd_count = ntohl(nrb->rd_count); - - struct GNUNET_NAMESTORE_RecordData rd[rd_count]; - int i = 0; - int record_match = 0; - uint32_t record_xquery = ntohl(*((uint32_t*)xquery)); - rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]); - - for (i=0; itype); - rd[i].expiration = - GNUNET_TIME_absolute_ntoh(rb->expiration); - rd[i].data_size = ntohl(rb->data_length); - rd[i].flags = ntohl(rb->flags); - rd[i].data = (char*)&rb[1]; - rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size); - - if (xquery_size == 0) - continue; - - if (rd[i].record_type == record_xquery) + struct GNUNET_NAMESTORE_RecordData rd[rd_count]; + unsigned int i; + uint32_t record_xquery = ntohl(*((uint32_t*)xquery)); + + rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]); + for (i=0; itype); + rd[i].expiration = + GNUNET_TIME_absolute_ntoh(rb->expiration); + rd[i].data_size = ntohl(rb->data_length); + rd[i].flags = ntohl(rb->flags); + rd[i].data = (char*)&rb[1]; + rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size); + + if (xquery_size == 0) + continue; + + if (rd[i].record_type == record_xquery) + record_match++; } - } - + } /*if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, name, diff --git a/src/include/block_gns.h b/src/include/block_gns.h index 04dcac3bc..ffdb294ae 100644 --- a/src/include/block_gns.h +++ b/src/include/block_gns.h @@ -74,11 +74,6 @@ struct GNSNameRecordBlock */ struct GNUNET_CRYPTO_RsaSignature signature; - /** - * What is being signed and why? - */ - struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; - /* number of records that follow */ uint32_t rd_count GNUNET_PACKED; diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 67d86cea6..ab0da6126 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h @@ -43,17 +43,6 @@ #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441 #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442 -size_t -GNUNET_NAMESTORE_records_serialize (char ** dest, - unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd); - -int -GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest, char *src, size_t len); - -void -GNUNET_NAMESTORE_records_free (unsigned int rd_count, struct GNUNET_NAMESTORE_RecordData *rd); - GNUNET_NETWORK_STRUCT_BEGIN /** diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c index 22a4e7736..8827183d4 100644 --- a/src/namestore/namestore_common.c +++ b/src/namestore/namestore_common.c @@ -34,6 +34,131 @@ #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) + + +/** + * Internal format of a record in the serialized form. + */ +struct NetworkRecord +{ + + /** + * Expiration time for the DNS record. + */ + struct GNUNET_TIME_AbsoluteNBO expiration; + + /** + * Number of bytes in 'data', network byte order. + */ + uint32_t data_size; + + /** + * Type of the GNS/DNS record, network byte order. + */ + uint32_t record_type; + + /** + * Flags for the record, network byte order. + */ + uint32_t flags; + +}; + +/** + * Calculate how many bytes we will need to serialize the given + * records. + */ +size_t +GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) +{ + unsigned int i; + size_t ret; + + ret = sizeof (struct NetworkRecord) * rd_count; + for (i=0;i= ret); + ret += rd[i].data_size; + } + return ret; +} + + +/** + * Serialize the given records to the given destination buffer. + */ +ssize_t +GNUNET_NAMESTORE_records_serialize (unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + size_t dest_size, + char *dest) +{ + struct NetworkRecord rec; + unsigned int i; + size_t off; + + off = 0; + for (i=0;i dest_size) + return -1; + memcpy (&dest[off], &rec, sizeof (rec)); + off += sizeof (rec); + if (off + rd[i].data_size > dest_size) + return -1; + memcpy (&dest[off], rd[i].data, rd[i].data_size); + off += rd[i].data_size; + } + return off; +} + + +/** + * @param rd_count expected number of records in 'src' + * @param dest array of 'rd_count' entries for storing record data; + * 'data' values in 'dest' will point into 'src' and will thus + * become invalid if 'src' is modified + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_NAMESTORE_records_deserialize (size_t len, + const char *src, + unsigned int rd_count, + struct GNUNET_NAMESTORE_RecordData *dest) +{ + struct NetworkRecord rec; + unsigned int i; + size_t off; + + off = 0; + for (i=0;i len) + return GNUNET_SYSERR; + memcpy (&rec, &src[off], sizeof (rec)); + dest[i].expiration = GNUNET_TIME_absolute_ntoh (rec.expiration); + dest[i].data_size = ntohl ((uint32_t) rec.data_size); + dest[i].record_type = ntohl (rec.record_type); + dest[i].flags = ntohl (rec.flags); + off += sizeof (rec); + + if (off + sizeof (dest[i].data_size) > len) + return GNUNET_SYSERR; + dest[i].data = &src[off]; + off += dest[i].data_size; + } + return GNUNET_OK; +} + + + +#if 0 + /** * Serialize an array of GNUNET_NAMESTORE_RecordData *rd to transmit over the * network @@ -185,4 +310,6 @@ GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest return elements; } +#endif + /* end of namestore_api.c */ -- 2.25.1