diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-16 14:32:07 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-16 14:32:07 +0000 |
commit | 00da095d9d83afea982baa79b8075a35d41be834 (patch) | |
tree | f4b26258b5184695b3bc31b2bbd9d1057903e430 | |
parent | 2364b11771c64de0fb120d44f7cf41290f503cbc (diff) | |
download | gnunet-00da095d9d83afea982baa79b8075a35d41be834.tar.gz gnunet-00da095d9d83afea982baa79b8075a35d41be834.zip |
-pseu caching + test
-rw-r--r-- | src/gns/Makefile.am | 18 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 3 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_interceptor.c | 21 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_interceptor.h | 1 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 338 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.h | 33 | ||||
-rw-r--r-- | src/gns/plugin_block_gns.c | 4 | ||||
-rw-r--r-- | src/gns/test_gns_pseu_shorten.c | 610 |
8 files changed, 1011 insertions, 17 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 61bf54f80..d31d5c4b1 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -35,7 +35,8 @@ check_PROGRAMS = \ | |||
35 | test_gns_simple_get_authority \ | 35 | test_gns_simple_get_authority \ |
36 | test_gns_simple_lookup \ | 36 | test_gns_simple_lookup \ |
37 | test_gns_simple_delegated_lookup \ | 37 | test_gns_simple_delegated_lookup \ |
38 | test_gns_dht_delegated_lookup | 38 | test_gns_dht_delegated_lookup \ |
39 | test_gns_pseu_shorten | ||
39 | 40 | ||
40 | 41 | ||
41 | # test_gns_simple_lookup | 42 | # test_gns_simple_lookup |
@@ -125,6 +126,21 @@ test_gns_simple_get_authority_DEPENDENCIES = \ | |||
125 | $(top_builddir)/src/testing/libgnunettesting.la | 126 | $(top_builddir)/src/testing/libgnunettesting.la |
126 | 127 | ||
127 | 128 | ||
129 | test_gns_pseu_shorten_SOURCES = \ | ||
130 | test_gns_pseu_shorten.c | ||
131 | test_gns_pseu_shorten_LDADD = \ | ||
132 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
133 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
134 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
135 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
136 | $(top_builddir)/src/testing/libgnunettesting.la | ||
137 | test_gns_pseu_shorten_DEPENDENCIES = \ | ||
138 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
139 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
140 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
141 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
142 | $(top_builddir)/src/testing/libgnunettesting.la | ||
143 | |||
128 | gnunet_gns_SOURCES = \ | 144 | gnunet_gns_SOURCES = \ |
129 | gnunet-gns.c | 145 | gnunet-gns.c |
130 | gnunet_gns_LDADD = \ | 146 | gnunet_gns_LDADD = \ |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 182655005..9332eba93 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -713,6 +713,7 @@ handle_lookup(void *cls, | |||
713 | clh->type = ntohl(sh_msg->type); | 713 | clh->type = ntohl(sh_msg->type); |
714 | 714 | ||
715 | gns_resolver_lookup_record(zone_hash, clh->type, name, | 715 | gns_resolver_lookup_record(zone_hash, clh->type, name, |
716 | zone_key, | ||
716 | &send_lookup_response, clh); | 717 | &send_lookup_response, clh); |
717 | } | 718 | } |
718 | 719 | ||
@@ -799,7 +800,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
799 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 800 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
800 | "DNS hijacking enabled... connecting to service.\n"); | 801 | "DNS hijacking enabled... connecting to service.\n"); |
801 | 802 | ||
802 | if (gns_interceptor_init(zone_hash, c) == GNUNET_SYSERR) | 803 | if (gns_interceptor_init(zone_hash, zone_key, c) == GNUNET_SYSERR) |
803 | { | 804 | { |
804 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 805 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
805 | "Failed to enable the dns interceptor!\n"); | 806 | "Failed to enable the dns interceptor!\n"); |
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 069975fc9..25cad7ead 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -54,7 +54,7 @@ struct InterceptLookupHandle | |||
54 | /** | 54 | /** |
55 | * Our handle to the DNS handler library | 55 | * Our handle to the DNS handler library |
56 | */ | 56 | */ |
57 | struct GNUNET_DNS_Handle *dns_handle; | 57 | static struct GNUNET_DNS_Handle *dns_handle; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * The root zone for this interceptor | 60 | * The root zone for this interceptor |
@@ -62,6 +62,11 @@ struct GNUNET_DNS_Handle *dns_handle; | |||
62 | static GNUNET_HashCode our_zone; | 62 | static GNUNET_HashCode our_zone; |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Our priv key | ||
66 | */ | ||
67 | static struct GNUNET_CRYPTO_RsaPrivateKey *our_key; | ||
68 | |||
69 | /** | ||
65 | * Reply to dns request with the result from our lookup. | 70 | * Reply to dns request with the result from our lookup. |
66 | * | 71 | * |
67 | * @param cls the closure to the request (an InterceptLookupHandle) | 72 | * @param cls the closure to the request (an InterceptLookupHandle) |
@@ -203,7 +208,9 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request, | |||
203 | ilh->request_handle = request; | 208 | ilh->request_handle = request; |
204 | 209 | ||
205 | /* Start resolution in our zone */ | 210 | /* Start resolution in our zone */ |
206 | gns_resolver_lookup_record(our_zone, q->type, q->name, &reply_to_dns, ilh); | 211 | gns_resolver_lookup_record(our_zone, q->type, q->name, |
212 | our_key, | ||
213 | &reply_to_dns, ilh); | ||
207 | } | 214 | } |
208 | 215 | ||
209 | 216 | ||
@@ -300,14 +307,24 @@ handle_dns_request(void *cls, | |||
300 | } | 307 | } |
301 | 308 | ||
302 | 309 | ||
310 | /** | ||
311 | * Initialized the interceptor | ||
312 | * | ||
313 | * @param zone the zone to work in | ||
314 | * @param the prov key of the zone (can be null, needed for caching) | ||
315 | * @param c the configuration | ||
316 | * @return GNUNET_OK on success | ||
317 | */ | ||
303 | int | 318 | int |
304 | gns_interceptor_init(GNUNET_HashCode zone, | 319 | gns_interceptor_init(GNUNET_HashCode zone, |
320 | struct GNUNET_CRYPTO_RsaPrivateKey *key, | ||
305 | const struct GNUNET_CONFIGURATION_Handle *c) | 321 | const struct GNUNET_CONFIGURATION_Handle *c) |
306 | { | 322 | { |
307 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 323 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
308 | "DNS hijacking enabled... connecting to service.\n"); | 324 | "DNS hijacking enabled... connecting to service.\n"); |
309 | 325 | ||
310 | our_zone = zone; | 326 | our_zone = zone; |
327 | our_key = key; | ||
311 | /** | 328 | /** |
312 | * Do gnunet dns init here | 329 | * Do gnunet dns init here |
313 | */ | 330 | */ |
diff --git a/src/gns/gnunet-service-gns_interceptor.h b/src/gns/gnunet-service-gns_interceptor.h index 03b91856e..855b034b1 100644 --- a/src/gns/gnunet-service-gns_interceptor.h +++ b/src/gns/gnunet-service-gns_interceptor.h | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | int | 11 | int |
12 | gns_interceptor_init(GNUNET_HashCode zone, | 12 | gns_interceptor_init(GNUNET_HashCode zone, |
13 | struct GNUNET_CRYPTO_RsaPrivateKey *key, | ||
13 | const struct GNUNET_CONFIGURATION_Handle *c); | 14 | const struct GNUNET_CONFIGURATION_Handle *c); |
14 | 15 | ||
15 | void | 16 | void |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 0b11e980f..41c2c0de0 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -55,6 +55,324 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle; | |||
55 | static struct GNUNET_DHT_Handle *dht_handle; | 55 | static struct GNUNET_DHT_Handle *dht_handle; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Namestore calls this function if we have record for this name. | ||
59 | * (or with rd_count=0 to indicate no matches) | ||
60 | * | ||
61 | * @param cls the pending query | ||
62 | * @param key the key of the zone we did the lookup | ||
63 | * @param expiration expiration date of the namestore entry | ||
64 | * @param name the name for which we need an authority | ||
65 | * @param rd_count the number of records with 'name' | ||
66 | * @param rd the record data | ||
67 | * @param signature the signature of the authority for the record data | ||
68 | */ | ||
69 | static void | ||
70 | process_pseu_lookup_ns(void* cls, | ||
71 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, | ||
72 | struct GNUNET_TIME_Absolute expiration, | ||
73 | const char *name, unsigned int rd_count, | ||
74 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
75 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
76 | { | ||
77 | struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; | ||
78 | struct GNUNET_NAMESTORE_RecordData new_pkey; | ||
79 | |||
80 | if (rd_count > 0) | ||
81 | { | ||
82 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
83 | "Name %s already taken in NS!\n", name); | ||
84 | if (0 == strcmp(gph->name, name)) | ||
85 | { | ||
86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
87 | "Intelligent replacement not implemented\n", name); | ||
88 | GNUNET_free(gph->new_name); | ||
89 | GNUNET_free(gph->name); | ||
90 | GNUNET_free(gph); | ||
91 | return; | ||
92 | } | ||
93 | |||
94 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
95 | "Trying delegated name %s\n", gph->name); | ||
96 | gph->new_name = gph->name; | ||
97 | GNUNET_NAMESTORE_lookup_record(namestore_handle, | ||
98 | &gph->zone, | ||
99 | gph->new_name, | ||
100 | GNUNET_GNS_RECORD_PSEU, | ||
101 | &process_pseu_lookup_ns, | ||
102 | gph); | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | /** name is free */ | ||
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
108 | "Name %s not taken in NS! Adding\n", gph->new_name); | ||
109 | |||
110 | new_pkey.expiration = GNUNET_TIME_absolute_get_forever (); | ||
111 | new_pkey.data_size = sizeof(GNUNET_HashCode); | ||
112 | new_pkey.data = &gph->new_zone; | ||
113 | new_pkey.record_type = GNUNET_GNS_RECORD_PKEY; | ||
114 | GNUNET_NAMESTORE_record_create (namestore_handle, | ||
115 | gph->key, | ||
116 | gph->new_name, | ||
117 | &new_pkey, | ||
118 | NULL, //cont | ||
119 | NULL); //cls | ||
120 | GNUNET_free(gph->new_name); | ||
121 | GNUNET_free(gph->name); | ||
122 | GNUNET_free(gph); | ||
123 | |||
124 | } | ||
125 | |||
126 | /** | ||
127 | * process result of a dht pseu lookup | ||
128 | * | ||
129 | * @param gph the handle | ||
130 | * @param name the pseu result or NULL | ||
131 | */ | ||
132 | static void | ||
133 | process_pseu_result(struct GetPseuAuthorityHandle* gph, char* name) | ||
134 | { | ||
135 | if (NULL == name) | ||
136 | { | ||
137 | gph->new_name = GNUNET_malloc(strlen(gph->name)+1); | ||
138 | memcpy(gph->new_name, name, strlen(gph->name)+1); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | gph->new_name = GNUNET_malloc(strlen(name)+1); | ||
143 | memcpy(gph->new_name, name, strlen(name)+1); | ||
144 | } | ||
145 | |||
146 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
147 | "Checking %s for collision in NS\n", gph->new_name); | ||
148 | |||
149 | /** | ||
150 | * Check for collision | ||
151 | */ | ||
152 | GNUNET_NAMESTORE_lookup_record(namestore_handle, | ||
153 | &gph->zone, | ||
154 | gph->new_name, | ||
155 | GNUNET_GNS_RECORD_PSEU, | ||
156 | &process_pseu_lookup_ns, | ||
157 | gph); | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * Handle timeout for dht request | ||
162 | * | ||
163 | * @param cls the request handle as closure | ||
164 | * @param tc the task context | ||
165 | */ | ||
166 | static void | ||
167 | handle_auth_discovery_timeout(void *cls, | ||
168 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
169 | { | ||
170 | struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; | ||
171 | |||
172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
173 | "dht lookup for query PSEU timed out.\n"); | ||
174 | GNUNET_DHT_get_stop (gph->get_handle); | ||
175 | process_pseu_result(gph, NULL); | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Function called when we find a PSEU entry in the DHT | ||
180 | * | ||
181 | * @param cls the request handle | ||
182 | * @param exp lifetime | ||
183 | * @param key the key the record was stored under | ||
184 | * @param get_path get path | ||
185 | * @param get_path_length get path length | ||
186 | * @param put_path put path | ||
187 | * @param put_path_length put path length | ||
188 | * @param type the block type | ||
189 | * @param size the size of the record | ||
190 | * @param data the record data | ||
191 | */ | ||
192 | static void | ||
193 | process_auth_discovery_dht_result(void* cls, | ||
194 | struct GNUNET_TIME_Absolute exp, | ||
195 | const GNUNET_HashCode * key, | ||
196 | const struct GNUNET_PeerIdentity *get_path, | ||
197 | unsigned int get_path_length, | ||
198 | const struct GNUNET_PeerIdentity *put_path, | ||
199 | unsigned int put_path_length, | ||
200 | enum GNUNET_BLOCK_Type type, | ||
201 | size_t size, const void *data) | ||
202 | { | ||
203 | struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; | ||
204 | struct GNSNameRecordBlock *nrb; | ||
205 | char* rd_data = (char*)data; | ||
206 | char* name; | ||
207 | int num_records; | ||
208 | size_t rd_size; | ||
209 | int i; | ||
210 | |||
211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got dht result (size=%d)\n", size); | ||
212 | |||
213 | if (data == NULL) | ||
214 | { | ||
215 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "got dht result null!\n", size); | ||
216 | GNUNET_break(0); | ||
217 | GNUNET_free(gph->new_name); | ||
218 | GNUNET_free(gph->name); | ||
219 | GNUNET_free(gph); | ||
220 | return; | ||
221 | } | ||
222 | |||
223 | nrb = (struct GNSNameRecordBlock*)data; | ||
224 | |||
225 | /* stop lookup and timeout task */ | ||
226 | GNUNET_DHT_get_stop (gph->get_handle); | ||
227 | GNUNET_SCHEDULER_cancel(gph->dht_timeout); | ||
228 | |||
229 | gph->get_handle = NULL; | ||
230 | |||
231 | nrb = (struct GNSNameRecordBlock*)data; | ||
232 | |||
233 | name = (char*)&nrb[1]; | ||
234 | num_records = ntohl(nrb->rd_count); | ||
235 | { | ||
236 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | ||
237 | |||
238 | rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); | ||
239 | rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock); | ||
240 | |||
241 | if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, | ||
242 | rd_data, | ||
243 | num_records, | ||
244 | rd)) | ||
245 | { | ||
246 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error deserializing data!\n"); | ||
247 | GNUNET_break(0); | ||
248 | GNUNET_free(gph->new_name); | ||
249 | GNUNET_free(gph->name); | ||
250 | GNUNET_free(gph); | ||
251 | return; | ||
252 | } | ||
253 | |||
254 | for (i=0; i<num_records; i++) | ||
255 | { | ||
256 | if ((strcmp(name, "+") == 0) && | ||
257 | (rd[i].record_type == GNUNET_GNS_RECORD_PSEU)) | ||
258 | { | ||
259 | /* found pseu */ | ||
260 | process_pseu_result(gph, (char*)rd[i].data); | ||
261 | return; | ||
262 | } | ||
263 | } | ||
264 | } | ||
265 | |||
266 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "no pseu in dht!\n"); | ||
267 | process_pseu_result(gph, NULL); | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * Callback called by namestore for a zone to name | ||
272 | * result | ||
273 | * | ||
274 | * @param cls the closure | ||
275 | * @param zone_key the zone we queried | ||
276 | * @param expire the expiration time of the name | ||
277 | * @param name the name found or NULL | ||
278 | * @param rd_len number of records for the name | ||
279 | * @param rd the record data (PKEY) for the name | ||
280 | * @param signature the signature for the record data | ||
281 | */ | ||
282 | static void | ||
283 | process_zone_to_name_discover(void *cls, | ||
284 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
285 | struct GNUNET_TIME_Absolute expire, | ||
286 | const char *name, | ||
287 | unsigned int rd_len, | ||
288 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
289 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
290 | { | ||
291 | struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; | ||
292 | |||
293 | /* we found a match in our own zone */ | ||
294 | if (rd_len != 0) | ||
295 | { | ||
296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
297 | "name for zone in our root %d\n", strlen(name)); | ||
298 | GNUNET_free(gph->new_name); | ||
299 | GNUNET_free(gph->name); | ||
300 | GNUNET_free(gph); | ||
301 | } | ||
302 | else | ||
303 | { | ||
304 | /** | ||
305 | * No name found. | ||
306 | * check dht | ||
307 | */ | ||
308 | uint32_t xquery; | ||
309 | GNUNET_HashCode name_hash; | ||
310 | GNUNET_HashCode lookup_key; | ||
311 | struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string; | ||
312 | |||
313 | GNUNET_CRYPTO_hash("+", strlen("+"), &name_hash); | ||
314 | GNUNET_CRYPTO_hash_xor(&name_hash, &gph->new_zone, &lookup_key); | ||
315 | GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); | ||
316 | |||
317 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
318 | "starting dht lookup for %s with key: %s\n", | ||
319 | "+", (char*)&lookup_key_string); | ||
320 | |||
321 | gph->dht_timeout = GNUNET_SCHEDULER_add_delayed(DHT_LOOKUP_TIMEOUT, | ||
322 | &handle_auth_discovery_timeout, gph); | ||
323 | |||
324 | xquery = htonl(GNUNET_GNS_RECORD_PSEU); | ||
325 | |||
326 | gph->get_handle = GNUNET_DHT_get_start(dht_handle, | ||
327 | DHT_OPERATION_TIMEOUT, | ||
328 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
329 | &lookup_key, | ||
330 | DHT_GNS_REPLICATION_LEVEL, | ||
331 | GNUNET_DHT_RO_NONE, | ||
332 | &xquery, | ||
333 | sizeof(xquery), | ||
334 | &process_auth_discovery_dht_result, | ||
335 | gph); | ||
336 | |||
337 | } | ||
338 | } | ||
339 | |||
340 | |||
341 | /** | ||
342 | * Callback for new authories | ||
343 | * | ||
344 | * @param name the name given by delegation | ||
345 | * @param zone the authority | ||
346 | * @param the private key of our authority | ||
347 | */ | ||
348 | static void process_discovered_authority(char* name, GNUNET_HashCode zone, | ||
349 | GNUNET_HashCode our_zone, | ||
350 | struct GNUNET_CRYPTO_RsaPrivateKey *key) | ||
351 | { | ||
352 | struct GetPseuAuthorityHandle *gph; | ||
353 | size_t namelen; | ||
354 | |||
355 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New authority %s discovered\n", | ||
356 | name); | ||
357 | |||
358 | gph = GNUNET_malloc(sizeof(struct GetPseuAuthorityHandle)); | ||
359 | namelen = strlen(name) + 1; | ||
360 | gph->name = GNUNET_malloc(namelen); | ||
361 | memcpy(gph->name, name, namelen); | ||
362 | |||
363 | gph->new_zone = zone; | ||
364 | gph->zone = our_zone; | ||
365 | gph->key = key; | ||
366 | |||
367 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
368 | &our_zone, | ||
369 | &gph->new_zone, | ||
370 | &process_zone_to_name_discover, | ||
371 | gph); | ||
372 | |||
373 | } | ||
374 | |||
375 | /** | ||
58 | * Initialize the resolver | 376 | * Initialize the resolver |
59 | * | 377 | * |
60 | * @param nh the namestore handle | 378 | * @param nh the namestore handle |
@@ -74,18 +392,6 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | |||
74 | return GNUNET_SYSERR; | 392 | return GNUNET_SYSERR; |
75 | } | 393 | } |
76 | 394 | ||
77 | /** | ||
78 | * Set the callback to call when we discover a | ||
79 | * new authority via the DHT | ||
80 | * | ||
81 | * @param adb the callback to set | ||
82 | * | ||
83 | void | ||
84 | gns_resolver_set_auth_discovered_cb(AuthorityDiscoveredProcessor adb) | ||
85 | { | ||
86 | auth_discovered = adb; | ||
87 | } | ||
88 | */ | ||
89 | 395 | ||
90 | /** | 396 | /** |
91 | * Helper function to free resolver handle | 397 | * Helper function to free resolver handle |
@@ -584,6 +890,12 @@ process_delegation_result_dht(void* cls, | |||
584 | GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, | 890 | GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, |
585 | rh->authority_chain_tail, | 891 | rh->authority_chain_tail, |
586 | auth); | 892 | auth); |
893 | |||
894 | /** call process new authority */ | ||
895 | if (rh->priv_key) | ||
896 | process_discovered_authority(name, auth->zone, | ||
897 | rh->authority_chain_tail->zone, | ||
898 | rh->priv_key); | ||
587 | } | 899 | } |
588 | 900 | ||
589 | } | 901 | } |
@@ -1107,6 +1419,7 @@ void | |||
1107 | gns_resolver_lookup_record(GNUNET_HashCode zone, | 1419 | gns_resolver_lookup_record(GNUNET_HashCode zone, |
1108 | uint32_t record_type, | 1420 | uint32_t record_type, |
1109 | const char* name, | 1421 | const char* name, |
1422 | struct GNUNET_CRYPTO_RsaPrivateKey *key, | ||
1110 | RecordLookupProcessor proc, | 1423 | RecordLookupProcessor proc, |
1111 | void* cls) | 1424 | void* cls) |
1112 | { | 1425 | { |
@@ -1131,6 +1444,7 @@ gns_resolver_lookup_record(GNUNET_HashCode zone, | |||
1131 | 1444 | ||
1132 | rh->authority = zone; | 1445 | rh->authority = zone; |
1133 | rh->proc_cls = rlh; | 1446 | rh->proc_cls = rlh; |
1447 | rh->priv_key = key; | ||
1134 | 1448 | ||
1135 | if (strcmp(GNUNET_GNS_TLD, name) == 0) | 1449 | if (strcmp(GNUNET_GNS_TLD, name) == 0) |
1136 | { | 1450 | { |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 79e916015..a7f86a2d7 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -32,6 +32,7 @@ struct AuthorityChain | |||
32 | /* handle to a resolution process */ | 32 | /* handle to a resolution process */ |
33 | struct ResolverHandle; | 33 | struct ResolverHandle; |
34 | 34 | ||
35 | |||
35 | /** | 36 | /** |
36 | * processor for a resultion result | 37 | * processor for a resultion result |
37 | * | 38 | * |
@@ -131,6 +132,8 @@ struct ResolverHandle | |||
131 | /* status of the resolution result */ | 132 | /* status of the resolution result */ |
132 | enum ResolutionStatus status; | 133 | enum ResolutionStatus status; |
133 | 134 | ||
135 | struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; | ||
136 | |||
134 | }; | 137 | }; |
135 | 138 | ||
136 | 139 | ||
@@ -187,6 +190,33 @@ struct GetNameAuthorityHandle | |||
187 | }; | 190 | }; |
188 | 191 | ||
189 | /** | 192 | /** |
193 | * Handle to a pseu lookup | ||
194 | */ | ||
195 | struct GetPseuAuthorityHandle | ||
196 | { | ||
197 | /* the name given from delegation */ | ||
198 | char* name; | ||
199 | |||
200 | /* name to store the pseu under */ | ||
201 | char* new_name; | ||
202 | |||
203 | /* the zone of discovered authority */ | ||
204 | GNUNET_HashCode new_zone; | ||
205 | |||
206 | /* the zone of our authority */ | ||
207 | GNUNET_HashCode zone; | ||
208 | |||
209 | /* the private key of the zone to store the pseu in */ | ||
210 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | ||
211 | |||
212 | /* a handle for dht lookups. should be NULL if no lookups are in progress */ | ||
213 | struct GNUNET_DHT_GetHandle *get_handle; | ||
214 | |||
215 | /* timeout task for dht lookups */ | ||
216 | GNUNET_SCHEDULER_TaskIdentifier dht_timeout; | ||
217 | }; | ||
218 | |||
219 | /** | ||
190 | * Initialize the resolver | 220 | * Initialize the resolver |
191 | * | 221 | * |
192 | * @param nh handle to the namestore | 222 | * @param nh handle to the namestore |
@@ -203,6 +233,8 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, | |||
203 | * | 233 | * |
204 | * @param zone the root zone | 234 | * @param zone the root zone |
205 | * @param record_type the record type to look up | 235 | * @param record_type the record type to look up |
236 | * @param name the name to look up | ||
237 | * @param key optional private key for authority caching | ||
206 | * @param proc the processor to call | 238 | * @param proc the processor to call |
207 | * @param cls the closure to pass to proc | 239 | * @param cls the closure to pass to proc |
208 | */ | 240 | */ |
@@ -210,6 +242,7 @@ void | |||
210 | gns_resolver_lookup_record(GNUNET_HashCode zone, | 242 | gns_resolver_lookup_record(GNUNET_HashCode zone, |
211 | uint32_t record_type, | 243 | uint32_t record_type, |
212 | const char* name, | 244 | const char* name, |
245 | struct GNUNET_CRYPTO_RsaPrivateKey *key, | ||
213 | RecordLookupProcessor proc, | 246 | RecordLookupProcessor proc, |
214 | void* cls); | 247 | void* cls); |
215 | 248 | ||
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 46db6a22a..19495f243 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -74,6 +74,8 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
74 | int rd_len; | 74 | int rd_len; |
75 | uint32_t record_xquery; | 75 | uint32_t record_xquery; |
76 | unsigned int record_match; | 76 | unsigned int record_match; |
77 | |||
78 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RB SIZE %d\n", reply_block_size); | ||
77 | 79 | ||
78 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 80 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
79 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 81 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
@@ -166,7 +168,7 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type, | |||
166 | rd, | 168 | rd, |
167 | &nrb->signature)) | 169 | &nrb->signature)) |
168 | { | 170 | { |
169 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid\n"); | 171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Signature invalid for name %s\n"); |
170 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 172 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
171 | } | 173 | } |
172 | } | 174 | } |
diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c new file mode 100644 index 000000000..a7f01de2c --- /dev/null +++ b/src/gns/test_gns_pseu_shorten.c | |||
@@ -0,0 +1,610 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file gns/test_gns_pseu_shorten.c | ||
22 | * @brief base testcase for testing on the fly pseu import and shorten | ||
23 | * | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | #include "gnunet_core_service.h" | ||
28 | #include "block_gns.h" | ||
29 | #include "gnunet_signatures.h" | ||
30 | #include "gnunet_namestore_service.h" | ||
31 | #include "../namestore/namestore.h" | ||
32 | #include "gnunet_dnsparser_lib.h" | ||
33 | #include "gnunet_dht_service.h" | ||
34 | #include "gnunet_gns_service.h" | ||
35 | |||
36 | /* DEFINES */ | ||
37 | #define VERBOSE GNUNET_YES | ||
38 | |||
39 | /* Timeout for entire testcase */ | ||
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | ||
41 | |||
42 | /* If number of peers not in config file, use this number */ | ||
43 | #define DEFAULT_NUM_PEERS 2 | ||
44 | |||
45 | /* test records to resolve */ | ||
46 | #define TEST_DOMAIN "www.alice.bob.gnunet" | ||
47 | #define TEST_IP "127.0.0.1" | ||
48 | #define TEST_RECORD_NAME "www" | ||
49 | |||
50 | #define TEST_AUTHORITY_BOB "bob" | ||
51 | #define TEST_AUTHORITY_ALICE "alice" | ||
52 | #define TEST_PSEU_ALICE "carol" | ||
53 | #define TEST_EXPECTED_RESULT "www.carol.gnunet" | ||
54 | |||
55 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
56 | |||
57 | /* Globals */ | ||
58 | |||
59 | /** | ||
60 | * Directory to store temp data in, defined in config file | ||
61 | */ | ||
62 | static char *test_directory; | ||
63 | |||
64 | struct GNUNET_TESTING_Daemon *d1; | ||
65 | |||
66 | |||
67 | /* Task handle to use to schedule test failure */ | ||
68 | GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
69 | |||
70 | /* Global return value (0 for success, anything else for failure) */ | ||
71 | static int ok; | ||
72 | |||
73 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
74 | |||
75 | static struct GNUNET_GNS_Handle *gns_handle; | ||
76 | |||
77 | static struct GNUNET_DHT_Handle *dht_handle; | ||
78 | |||
79 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
80 | |||
81 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; | ||
82 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; | ||
83 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; | ||
84 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; | ||
85 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; | ||
86 | struct GNUNET_CRYPTO_RsaPrivateKey *our_key; | ||
87 | GNUNET_HashCode alice_hash; | ||
88 | GNUNET_HashCode bob_hash; | ||
89 | |||
90 | /** | ||
91 | * Check whether peers successfully shut down. | ||
92 | */ | ||
93 | void | ||
94 | shutdown_callback (void *cls, const char *emsg) | ||
95 | { | ||
96 | if (emsg != NULL) | ||
97 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); | ||
99 | if (ok == 0) | ||
100 | ok = 2; | ||
101 | } | ||
102 | |||
103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Called when gns shorten finishes | ||
108 | */ | ||
109 | static void | ||
110 | process_shorten_result(void* cls, const char* sname) | ||
111 | { | ||
112 | GNUNET_GNS_disconnect(gns_handle); | ||
113 | ok = 0; | ||
114 | |||
115 | if (sname == NULL) | ||
116 | { | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
118 | "shorten test failed!\n"); | ||
119 | ok = 1; | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
124 | "%s shortened to %s\n", (char*)cls, sname); | ||
125 | if (0 != strcmp(sname, TEST_EXPECTED_RESULT)) | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
128 | "shorten test failed! (wanted: %s got: %s\n", | ||
129 | (char*)cls, sname); | ||
130 | ok = 1; | ||
131 | } | ||
132 | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shorten test succeeded!\n"); | ||
134 | } | ||
135 | |||
136 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); | ||
137 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL, | ||
138 | GNUNET_YES, GNUNET_NO); | ||
139 | } | ||
140 | |||
141 | static void | ||
142 | do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
143 | { | ||
144 | GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result, | ||
145 | TEST_DOMAIN); | ||
146 | } | ||
147 | |||
148 | static void | ||
149 | on_lookup_result(void *cls, uint32_t rd_count, | ||
150 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
151 | { | ||
152 | struct in_addr a; | ||
153 | int i; | ||
154 | char* addr; | ||
155 | |||
156 | if (rd_count == 0) | ||
157 | { | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
159 | "Lookup failed, rp_filtering?\n"); | ||
160 | ok = 2; | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | ok = 1; | ||
165 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); | ||
166 | for (i=0; i<rd_count; i++) | ||
167 | { | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); | ||
169 | if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A) | ||
170 | { | ||
171 | memcpy(&a, rd[i].data, sizeof(a)); | ||
172 | addr = inet_ntoa(a); | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | ||
174 | if (0 == strcmp(addr, TEST_IP)) | ||
175 | { | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
177 | "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); | ||
178 | ok = 0; | ||
179 | } | ||
180 | } | ||
181 | else | ||
182 | { | ||
183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | |||
188 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &do_shorten, NULL); | ||
189 | } | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Function scheduled to be run on the successful start of services | ||
194 | * tries to look up the dns record for TEST_DOMAIN | ||
195 | */ | ||
196 | static void | ||
197 | commence_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
198 | { | ||
199 | GNUNET_DHT_disconnect(dht_handle); | ||
200 | |||
201 | GNUNET_CRYPTO_rsa_key_free(our_key); | ||
202 | GNUNET_CRYPTO_rsa_key_free(bob_key); | ||
203 | GNUNET_CRYPTO_rsa_key_free(alice_key); | ||
204 | |||
205 | gns_handle = GNUNET_GNS_connect(cfg); | ||
206 | |||
207 | if (NULL == gns_handle) | ||
208 | { | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
210 | "Failed to connect to GNS!\n"); | ||
211 | } | ||
212 | |||
213 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A, | ||
214 | &on_lookup_result, TEST_DOMAIN); | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut | ||
219 | * down the peers without freeing memory associated with GET request. | ||
220 | */ | ||
221 | static void | ||
222 | end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
223 | { | ||
224 | |||
225 | if (d1 != NULL) | ||
226 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL, | ||
227 | GNUNET_YES, GNUNET_NO); | ||
228 | GNUNET_SCHEDULER_cancel (die_task); | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Check if the get_handle is being used, if so stop the request. Either | ||
233 | * way, schedule the end_badly_cont function which actually shuts down the | ||
234 | * test. | ||
235 | */ | ||
236 | static void | ||
237 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
238 | { | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n", | ||
240 | (char *) cls); | ||
241 | GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL); | ||
242 | ok = 1; | ||
243 | } | ||
244 | |||
245 | static void | ||
246 | put_pseu_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
247 | { | ||
248 | struct GNSNameRecordBlock *nrb; | ||
249 | GNUNET_HashCode name_hash; | ||
250 | GNUNET_HashCode xor_hash; | ||
251 | GNUNET_HashCode zone_hash; | ||
252 | uint32_t rd_payload_length; | ||
253 | char* nrb_data = NULL; | ||
254 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
255 | struct GNUNET_NAMESTORE_RecordData rd; | ||
256 | |||
257 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
258 | rd.data_size = strlen(TEST_PSEU_ALICE); | ||
259 | rd.data = TEST_PSEU_ALICE; | ||
260 | rd.record_type = GNUNET_GNS_RECORD_PSEU; | ||
261 | |||
262 | sig = GNUNET_NAMESTORE_create_signature(alice_key, | ||
263 | GNUNET_TIME_absolute_get_forever(), | ||
264 | "+", | ||
265 | &rd, 1); | ||
266 | rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd); | ||
267 | nrb = GNUNET_malloc(rd_payload_length + strlen("+") + 1 | ||
268 | + sizeof(struct GNSNameRecordBlock)); | ||
269 | nrb->signature = *sig; | ||
270 | nrb->public_key = alice_pkey; | ||
271 | nrb->rd_count = htonl(1); | ||
272 | memset(&nrb[1], 0, strlen("+") + 1); | ||
273 | strcpy((char*)&nrb[1], "+"); | ||
274 | nrb_data = (char*)&nrb[1]; | ||
275 | nrb_data += strlen("+") + 1; | ||
276 | |||
277 | if (-1 == GNUNET_NAMESTORE_records_serialize (1, | ||
278 | &rd, | ||
279 | rd_payload_length, | ||
280 | nrb_data)) | ||
281 | { | ||
282 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n"); | ||
283 | ok = 3; | ||
284 | GNUNET_DHT_disconnect(dht_handle); | ||
285 | |||
286 | |||
287 | GNUNET_CRYPTO_rsa_key_free(our_key); | ||
288 | GNUNET_CRYPTO_rsa_key_free(bob_key); | ||
289 | GNUNET_CRYPTO_rsa_key_free(alice_key); | ||
290 | GNUNET_free(sig); | ||
291 | GNUNET_free (nrb); | ||
292 | return; | ||
293 | } | ||
294 | GNUNET_CRYPTO_hash("+", strlen("+"), &name_hash); | ||
295 | GNUNET_CRYPTO_hash(&alice_pkey, | ||
296 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
297 | &zone_hash); | ||
298 | GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); | ||
299 | |||
300 | rd_payload_length += sizeof(struct GNSNameRecordBlock) + | ||
301 | strlen("+") + 1; | ||
302 | |||
303 | GNUNET_DHT_put (dht_handle, &xor_hash, | ||
304 | 0, | ||
305 | GNUNET_DHT_RO_NONE, | ||
306 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
307 | rd_payload_length, | ||
308 | (char*)nrb, | ||
309 | rd.expiration, | ||
310 | DHT_OPERATION_TIMEOUT, | ||
311 | &commence_testing, | ||
312 | NULL); | ||
313 | |||
314 | GNUNET_free(sig); | ||
315 | GNUNET_free (nrb); | ||
316 | } | ||
317 | |||
318 | static void | ||
319 | put_www_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
320 | { | ||
321 | struct GNSNameRecordBlock *nrb; | ||
322 | GNUNET_HashCode name_hash; | ||
323 | GNUNET_HashCode xor_hash; | ||
324 | GNUNET_HashCode zone_hash; | ||
325 | uint32_t rd_payload_length; | ||
326 | char* nrb_data = NULL; | ||
327 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
328 | struct GNUNET_NAMESTORE_RecordData rd; | ||
329 | char* ip = TEST_IP; | ||
330 | struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); | ||
331 | |||
332 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
333 | GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); | ||
334 | rd.data_size = sizeof(struct in_addr); | ||
335 | rd.data = web; | ||
336 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
337 | |||
338 | sig = GNUNET_NAMESTORE_create_signature(alice_key, | ||
339 | GNUNET_TIME_absolute_get_forever(), | ||
340 | TEST_RECORD_NAME, | ||
341 | &rd, 1); | ||
342 | rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd); | ||
343 | nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_RECORD_NAME) + 1 | ||
344 | + sizeof(struct GNSNameRecordBlock)); | ||
345 | nrb->signature = *sig; | ||
346 | nrb->public_key = alice_pkey; | ||
347 | nrb->rd_count = htonl(1); | ||
348 | memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1); | ||
349 | strcpy((char*)&nrb[1], TEST_RECORD_NAME); | ||
350 | nrb_data = (char*)&nrb[1]; | ||
351 | nrb_data += strlen(TEST_RECORD_NAME) + 1; | ||
352 | |||
353 | if (-1 == GNUNET_NAMESTORE_records_serialize (1, | ||
354 | &rd, | ||
355 | rd_payload_length, | ||
356 | nrb_data)) | ||
357 | { | ||
358 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n"); | ||
359 | ok = 3; | ||
360 | GNUNET_DHT_disconnect(dht_handle); | ||
361 | |||
362 | GNUNET_CRYPTO_rsa_key_free(our_key); | ||
363 | GNUNET_CRYPTO_rsa_key_free(bob_key); | ||
364 | GNUNET_CRYPTO_rsa_key_free(alice_key); | ||
365 | GNUNET_free(web); | ||
366 | GNUNET_free (nrb); | ||
367 | return; | ||
368 | } | ||
369 | GNUNET_CRYPTO_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); | ||
370 | GNUNET_CRYPTO_hash(&alice_pkey, | ||
371 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
372 | &zone_hash); | ||
373 | GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); | ||
374 | |||
375 | rd_payload_length += sizeof(struct GNSNameRecordBlock) + | ||
376 | strlen(TEST_RECORD_NAME) + 1; | ||
377 | |||
378 | GNUNET_DHT_put (dht_handle, &xor_hash, | ||
379 | 0, | ||
380 | GNUNET_DHT_RO_NONE, | ||
381 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
382 | rd_payload_length, | ||
383 | (char*)nrb, | ||
384 | rd.expiration, | ||
385 | DHT_OPERATION_TIMEOUT, | ||
386 | &put_pseu_dht, | ||
387 | NULL); | ||
388 | |||
389 | GNUNET_free(web); | ||
390 | GNUNET_free (nrb); | ||
391 | } | ||
392 | |||
393 | |||
394 | static void | ||
395 | put_pkey_dht(void *cls, int32_t success, const char *emsg) | ||
396 | { | ||
397 | struct GNSNameRecordBlock *nrb; | ||
398 | GNUNET_HashCode name_hash; | ||
399 | GNUNET_HashCode xor_hash; | ||
400 | GNUNET_HashCode zone_hash; | ||
401 | uint32_t rd_payload_length; | ||
402 | char* nrb_data = NULL; | ||
403 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
404 | struct GNUNET_NAMESTORE_RecordData rd; | ||
405 | |||
406 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
407 | rd.data_size = sizeof(GNUNET_HashCode); | ||
408 | rd.data = &alice_hash; | ||
409 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | ||
410 | |||
411 | sig = GNUNET_NAMESTORE_create_signature(bob_key, | ||
412 | GNUNET_TIME_absolute_get_forever(), | ||
413 | TEST_AUTHORITY_ALICE, | ||
414 | &rd, | ||
415 | 1); | ||
416 | |||
417 | rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd); | ||
418 | nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_AUTHORITY_ALICE) + 1 | ||
419 | + sizeof(struct GNSNameRecordBlock)); | ||
420 | nrb->signature = *sig; | ||
421 | nrb->public_key = bob_pkey; | ||
422 | nrb->rd_count = htonl(1); | ||
423 | memset(&nrb[1], 0, strlen(TEST_AUTHORITY_ALICE) + 1); | ||
424 | strcpy((char*)&nrb[1], TEST_AUTHORITY_ALICE); | ||
425 | nrb_data = (char*)&nrb[1]; | ||
426 | nrb_data += strlen(TEST_AUTHORITY_ALICE) + 1; | ||
427 | |||
428 | if (-1 == GNUNET_NAMESTORE_records_serialize (1, | ||
429 | &rd, | ||
430 | rd_payload_length, | ||
431 | nrb_data)) | ||
432 | { | ||
433 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n"); | ||
434 | ok = 3; | ||
435 | |||
436 | GNUNET_CRYPTO_rsa_key_free(our_key); | ||
437 | GNUNET_CRYPTO_rsa_key_free(bob_key); | ||
438 | GNUNET_CRYPTO_rsa_key_free(alice_key); | ||
439 | GNUNET_free(sig); | ||
440 | GNUNET_free (nrb); | ||
441 | return; | ||
442 | } | ||
443 | |||
444 | |||
445 | GNUNET_CRYPTO_hash(TEST_AUTHORITY_ALICE, | ||
446 | strlen(TEST_AUTHORITY_ALICE), &name_hash); | ||
447 | GNUNET_CRYPTO_hash(&bob_pkey, | ||
448 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
449 | &zone_hash); | ||
450 | GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); | ||
451 | |||
452 | rd_payload_length += sizeof(struct GNSNameRecordBlock) + | ||
453 | strlen(TEST_AUTHORITY_ALICE) + 1; | ||
454 | GNUNET_DHT_put (dht_handle, &xor_hash, | ||
455 | 0, | ||
456 | GNUNET_DHT_RO_NONE, | ||
457 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
458 | rd_payload_length, | ||
459 | (char*)nrb, | ||
460 | rd.expiration, | ||
461 | DHT_OPERATION_TIMEOUT, | ||
462 | &put_www_dht, | ||
463 | NULL); | ||
464 | GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_NO); | ||
465 | GNUNET_free (nrb); | ||
466 | } | ||
467 | |||
468 | static void | ||
469 | do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | ||
470 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
471 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
472 | { | ||
473 | |||
474 | |||
475 | char* our_keyfile; | ||
476 | |||
477 | |||
478 | GNUNET_SCHEDULER_cancel (die_task); | ||
479 | |||
480 | /* put records into namestore */ | ||
481 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | ||
482 | if (NULL == namestore_handle) | ||
483 | { | ||
484 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); | ||
485 | ok = -1; | ||
486 | return; | ||
487 | } | ||
488 | |||
489 | /* dht */ | ||
490 | dht_handle = GNUNET_DHT_connect(cfg, 1); | ||
491 | if (NULL == dht_handle) | ||
492 | { | ||
493 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n"); | ||
494 | ok = -1; | ||
495 | return; | ||
496 | } | ||
497 | |||
498 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
499 | "ZONEKEY", | ||
500 | &our_keyfile)) | ||
501 | { | ||
502 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | ||
503 | ok = -1; | ||
504 | return; | ||
505 | } | ||
506 | |||
507 | our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile); | ||
508 | bob_key = GNUNET_CRYPTO_rsa_key_create (); | ||
509 | alice_key = GNUNET_CRYPTO_rsa_key_create (); | ||
510 | |||
511 | GNUNET_free(our_keyfile); | ||
512 | |||
513 | GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey); | ||
514 | GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); | ||
515 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); | ||
516 | GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); | ||
517 | GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); | ||
518 | |||
519 | struct GNUNET_NAMESTORE_RecordData rd; | ||
520 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
521 | rd.data_size = sizeof(GNUNET_HashCode); | ||
522 | rd.data = &bob_hash; | ||
523 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | ||
524 | |||
525 | GNUNET_NAMESTORE_record_create (namestore_handle, | ||
526 | our_key, | ||
527 | TEST_AUTHORITY_BOB, | ||
528 | &rd, | ||
529 | &put_pkey_dht, | ||
530 | NULL); | ||
531 | |||
532 | |||
533 | } | ||
534 | |||
535 | static void | ||
536 | run (void *cls, char *const *args, const char *cfgfile, | ||
537 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
538 | { | ||
539 | cfg = c; | ||
540 | /* Get path from configuration file */ | ||
541 | if (GNUNET_YES != | ||
542 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | ||
543 | &test_directory)) | ||
544 | { | ||
545 | ok = 404; | ||
546 | return; | ||
547 | } | ||
548 | |||
549 | |||
550 | /* Set up a task to end testing if peer start fails */ | ||
551 | die_task = | ||
552 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, | ||
553 | "didn't start all daemons in reasonable amount of time!!!"); | ||
554 | |||
555 | /* Start alice */ | ||
556 | d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, | ||
557 | NULL, NULL, NULL, &do_lookup, NULL); | ||
558 | } | ||
559 | |||
560 | static int | ||
561 | check () | ||
562 | { | ||
563 | int ret; | ||
564 | |||
565 | /* Arguments for GNUNET_PROGRAM_run */ | ||
566 | char *const argv[] = { "test-gns-dht-delegated-lookup", /* Name to give running binary */ | ||
567 | "-c", | ||
568 | "test_gns_simple_lookup.conf", /* Config file to use */ | ||
569 | #if VERBOSE | ||
570 | "-L", "DEBUG", | ||
571 | #endif | ||
572 | NULL | ||
573 | }; | ||
574 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
575 | GNUNET_GETOPT_OPTION_END | ||
576 | }; | ||
577 | /* Run the run function as a new program */ | ||
578 | ret = | ||
579 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | ||
580 | "test-gns-dht-delegated-lookup", "nohelp", options, &run, | ||
581 | &ok); | ||
582 | if (ret != GNUNET_OK) | ||
583 | { | ||
584 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
585 | "`test-gns-dht-delegated-lookup': Failed with error code %d\n", ret); | ||
586 | } | ||
587 | return ok; | ||
588 | } | ||
589 | |||
590 | int | ||
591 | main (int argc, char *argv[]) | ||
592 | { | ||
593 | int ret; | ||
594 | |||
595 | GNUNET_log_setup ("test-gns-simple-lookup", | ||
596 | #if VERBOSE | ||
597 | "DEBUG", | ||
598 | #else | ||
599 | "WARNING", | ||
600 | #endif | ||
601 | NULL); | ||
602 | ret = check (); | ||
603 | /** | ||
604 | * Need to remove base directory, subdirectories taken care | ||
605 | * of by the testing framework. | ||
606 | */ | ||
607 | return ret; | ||
608 | } | ||
609 | |||
610 | /* end of test_gns_twopeer.c */ | ||