diff options
-rw-r--r-- | src/gns/gnunet-service-gns.c | 12 | ||||
-rw-r--r-- | src/gns/plugin_block_gns.c | 57 | ||||
-rw-r--r-- | src/include/block_gns.h | 5 | ||||
-rw-r--r-- | src/namestore/namestore.h | 11 | ||||
-rw-r--r-- | 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 @@ | |||
39 | #include "block_gns.h" | 39 | #include "block_gns.h" |
40 | #include "gns.h" | 40 | #include "gns.h" |
41 | 41 | ||
42 | #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
43 | |||
42 | /* Ignore for now not used anyway and probably never will */ | 44 | /* Ignore for now not used anyway and probably never will */ |
43 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 | 45 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 |
44 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 | 46 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 |
@@ -443,11 +445,10 @@ process_name_dht_result(void* cls, | |||
443 | * @param rh the pending gns query context | 445 | * @param rh the pending gns query context |
444 | * @param name the name to query record | 446 | * @param name the name to query record |
445 | */ | 447 | */ |
446 | void | 448 | static void |
447 | resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) | 449 | resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) |
448 | { | 450 | { |
449 | uint32_t xquery; | 451 | uint32_t xquery; |
450 | struct GNUNET_TIME_Relative timeout; | ||
451 | GNUNET_HashCode name_hash; | 452 | GNUNET_HashCode name_hash; |
452 | GNUNET_HashCode lookup_key; | 453 | GNUNET_HashCode lookup_key; |
453 | struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; | 454 | struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; |
@@ -460,16 +461,15 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) | |||
460 | "starting dht lookup for %s with key: %s\n", | 461 | "starting dht lookup for %s with key: %s\n", |
461 | name, (char*)&lookup_key_string); | 462 | name, (char*)&lookup_key_string); |
462 | 463 | ||
463 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5); | ||
464 | |||
465 | xquery = htonl(rh->query->type); | 464 | xquery = htonl(rh->query->type); |
466 | //FIXME how long to wait for results? | 465 | //FIXME how long to wait for results? |
467 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout, | 466 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
467 | DHT_LOOKUP_TIMEOUT, | ||
468 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 468 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
469 | &lookup_key, | 469 | &lookup_key, |
470 | 5, //Replication level FIXME | 470 | 5, //Replication level FIXME |
471 | GNUNET_DHT_RO_NONE, | 471 | GNUNET_DHT_RO_NONE, |
472 | &xquery, //xquery FIXME is this bad? | 472 | &xquery, |
473 | sizeof(xquery), | 473 | sizeof(xquery), |
474 | &process_name_dht_result, | 474 | &process_name_dht_result, |
475 | rh); | 475 | 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, | |||
62 | size_t xquery_size, const void *reply_block, | 62 | size_t xquery_size, const void *reply_block, |
63 | size_t reply_block_size) | 63 | size_t reply_block_size) |
64 | { | 64 | { |
65 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
66 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
67 | if (reply_block_size == 0) | ||
68 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
69 | |||
70 | char* name; | 65 | char* name; |
71 | GNUNET_HashCode pkey_hash; | 66 | GNUNET_HashCode pkey_hash; |
72 | GNUNET_HashCode query_key; | 67 | GNUNET_HashCode query_key; |
@@ -76,7 +71,13 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
76 | struct GNSNameRecordBlock *nrb; | 71 | struct GNSNameRecordBlock *nrb; |
77 | struct GNSRecordBlock *rb; | 72 | struct GNSRecordBlock *rb; |
78 | uint32_t rd_count; | 73 | uint32_t rd_count; |
79 | 74 | unsigned int record_match; | |
75 | |||
76 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | ||
77 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | ||
78 | if (reply_block_size == 0) | ||
79 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
80 | |||
80 | nrb = (struct GNSNameRecordBlock *)reply_block; | 81 | nrb = (struct GNSNameRecordBlock *)reply_block; |
81 | name = (char*)&nrb[1]; | 82 | name = (char*)&nrb[1]; |
82 | GNUNET_CRYPTO_hash(&nrb->public_key, | 83 | GNUNET_CRYPTO_hash(&nrb->public_key, |
@@ -91,33 +92,31 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
91 | if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key)) | 92 | if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key)) |
92 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 93 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
93 | 94 | ||
95 | record_match = 0; | ||
94 | rd_count = ntohl(nrb->rd_count); | 96 | rd_count = ntohl(nrb->rd_count); |
95 | |||
96 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
97 | int i = 0; | ||
98 | int record_match = 0; | ||
99 | uint32_t record_xquery = ntohl(*((uint32_t*)xquery)); | ||
100 | rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]); | ||
101 | |||
102 | for (i=0; i<rd_count; i++) | ||
103 | { | 97 | { |
104 | rd[i].record_type = ntohl(rb->type); | 98 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; |
105 | rd[i].expiration = | 99 | unsigned int i; |
106 | GNUNET_TIME_absolute_ntoh(rb->expiration); | 100 | uint32_t record_xquery = ntohl(*((uint32_t*)xquery)); |
107 | rd[i].data_size = ntohl(rb->data_length); | 101 | |
108 | rd[i].flags = ntohl(rb->flags); | 102 | rb = (struct GNSRecordBlock*)(&name[strlen(name) + 1]); |
109 | rd[i].data = (char*)&rb[1]; | 103 | for (i=0; i<rd_count; i++) |
110 | rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size); | ||
111 | |||
112 | if (xquery_size == 0) | ||
113 | continue; | ||
114 | |||
115 | if (rd[i].record_type == record_xquery) | ||
116 | { | 104 | { |
117 | record_match++; | 105 | rd[i].record_type = ntohl(rb->type); |
106 | rd[i].expiration = | ||
107 | GNUNET_TIME_absolute_ntoh(rb->expiration); | ||
108 | rd[i].data_size = ntohl(rb->data_length); | ||
109 | rd[i].flags = ntohl(rb->flags); | ||
110 | rd[i].data = (char*)&rb[1]; | ||
111 | rb = (struct GNSRecordBlock *)((char*)&rb[1] + rd[i].data_size); | ||
112 | |||
113 | if (xquery_size == 0) | ||
114 | continue; | ||
115 | |||
116 | if (rd[i].record_type == record_xquery) | ||
117 | record_match++; | ||
118 | } | 118 | } |
119 | } | 119 | } |
120 | |||
121 | 120 | ||
122 | /*if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, | 121 | /*if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, |
123 | name, | 122 | 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 | |||
74 | */ | 74 | */ |
75 | struct GNUNET_CRYPTO_RsaSignature signature; | 75 | struct GNUNET_CRYPTO_RsaSignature signature; |
76 | 76 | ||
77 | /** | ||
78 | * What is being signed and why? | ||
79 | */ | ||
80 | struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; | ||
81 | |||
82 | /* number of records that follow */ | 77 | /* number of records that follow */ |
83 | uint32_t rd_count GNUNET_PACKED; | 78 | uint32_t rd_count GNUNET_PACKED; |
84 | 79 | ||
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 @@ | |||
43 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441 | 43 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441 |
44 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442 | 44 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442 |
45 | 45 | ||
46 | size_t | ||
47 | GNUNET_NAMESTORE_records_serialize (char ** dest, | ||
48 | unsigned int rd_count, | ||
49 | const struct GNUNET_NAMESTORE_RecordData *rd); | ||
50 | |||
51 | int | ||
52 | GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest, char *src, size_t len); | ||
53 | |||
54 | void | ||
55 | GNUNET_NAMESTORE_records_free (unsigned int rd_count, struct GNUNET_NAMESTORE_RecordData *rd); | ||
56 | |||
57 | 46 | ||
58 | GNUNET_NETWORK_STRUCT_BEGIN | 47 | GNUNET_NETWORK_STRUCT_BEGIN |
59 | /** | 48 | /** |
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 @@ | |||
34 | #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING | 34 | #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING |
35 | 35 | ||
36 | #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) | 36 | #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) |
37 | |||
38 | |||
39 | /** | ||
40 | * Internal format of a record in the serialized form. | ||
41 | */ | ||
42 | struct NetworkRecord | ||
43 | { | ||
44 | |||
45 | /** | ||
46 | * Expiration time for the DNS record. | ||
47 | */ | ||
48 | struct GNUNET_TIME_AbsoluteNBO expiration; | ||
49 | |||
50 | /** | ||
51 | * Number of bytes in 'data', network byte order. | ||
52 | */ | ||
53 | uint32_t data_size; | ||
54 | |||
55 | /** | ||
56 | * Type of the GNS/DNS record, network byte order. | ||
57 | */ | ||
58 | uint32_t record_type; | ||
59 | |||
60 | /** | ||
61 | * Flags for the record, network byte order. | ||
62 | */ | ||
63 | uint32_t flags; | ||
64 | |||
65 | }; | ||
66 | |||
67 | /** | ||
68 | * Calculate how many bytes we will need to serialize the given | ||
69 | * records. | ||
70 | */ | ||
71 | size_t | ||
72 | GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, | ||
73 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
74 | { | ||
75 | unsigned int i; | ||
76 | size_t ret; | ||
77 | |||
78 | ret = sizeof (struct NetworkRecord) * rd_count; | ||
79 | for (i=0;i<rd_count;i++) | ||
80 | { | ||
81 | GNUNET_assert (ret + rd[i].data_size >= ret); | ||
82 | ret += rd[i].data_size; | ||
83 | } | ||
84 | return ret; | ||
85 | } | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Serialize the given records to the given destination buffer. | ||
90 | */ | ||
91 | ssize_t | ||
92 | GNUNET_NAMESTORE_records_serialize (unsigned int rd_count, | ||
93 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
94 | size_t dest_size, | ||
95 | char *dest) | ||
96 | { | ||
97 | struct NetworkRecord rec; | ||
98 | unsigned int i; | ||
99 | size_t off; | ||
100 | |||
101 | off = 0; | ||
102 | for (i=0;i<rd_count;i++) | ||
103 | { | ||
104 | rec.expiration = GNUNET_TIME_absolute_hton (rd[i].expiration); | ||
105 | rec.data_size = htonl ((uint32_t) rd[i].data_size); | ||
106 | rec.record_type = htonl (rd[i].record_type); | ||
107 | rec.flags = htonl (rd[i].flags); | ||
108 | if (off + sizeof (rec) > dest_size) | ||
109 | return -1; | ||
110 | memcpy (&dest[off], &rec, sizeof (rec)); | ||
111 | off += sizeof (rec); | ||
112 | if (off + rd[i].data_size > dest_size) | ||
113 | return -1; | ||
114 | memcpy (&dest[off], rd[i].data, rd[i].data_size); | ||
115 | off += rd[i].data_size; | ||
116 | } | ||
117 | return off; | ||
118 | } | ||
119 | |||
120 | |||
121 | /** | ||
122 | * @param rd_count expected number of records in 'src' | ||
123 | * @param dest array of 'rd_count' entries for storing record data; | ||
124 | * 'data' values in 'dest' will point into 'src' and will thus | ||
125 | * become invalid if 'src' is modified | ||
126 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
127 | */ | ||
128 | int | ||
129 | GNUNET_NAMESTORE_records_deserialize (size_t len, | ||
130 | const char *src, | ||
131 | unsigned int rd_count, | ||
132 | struct GNUNET_NAMESTORE_RecordData *dest) | ||
133 | { | ||
134 | struct NetworkRecord rec; | ||
135 | unsigned int i; | ||
136 | size_t off; | ||
137 | |||
138 | off = 0; | ||
139 | for (i=0;i<rd_count;i++) | ||
140 | { | ||
141 | if (off + sizeof (rec) > len) | ||
142 | return GNUNET_SYSERR; | ||
143 | memcpy (&rec, &src[off], sizeof (rec)); | ||
144 | dest[i].expiration = GNUNET_TIME_absolute_ntoh (rec.expiration); | ||
145 | dest[i].data_size = ntohl ((uint32_t) rec.data_size); | ||
146 | dest[i].record_type = ntohl (rec.record_type); | ||
147 | dest[i].flags = ntohl (rec.flags); | ||
148 | off += sizeof (rec); | ||
149 | |||
150 | if (off + sizeof (dest[i].data_size) > len) | ||
151 | return GNUNET_SYSERR; | ||
152 | dest[i].data = &src[off]; | ||
153 | off += dest[i].data_size; | ||
154 | } | ||
155 | return GNUNET_OK; | ||
156 | } | ||
157 | |||
158 | |||
159 | |||
160 | #if 0 | ||
161 | |||
37 | /** | 162 | /** |
38 | * Serialize an array of GNUNET_NAMESTORE_RecordData *rd to transmit over the | 163 | * Serialize an array of GNUNET_NAMESTORE_RecordData *rd to transmit over the |
39 | * network | 164 | * network |
@@ -185,4 +310,6 @@ GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest | |||
185 | return elements; | 310 | return elements; |
186 | } | 311 | } |
187 | 312 | ||
313 | #endif | ||
314 | |||
188 | /* end of namestore_api.c */ | 315 | /* end of namestore_api.c */ |