aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-12 21:43:31 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-12 21:43:31 +0000
commit1489edfdd05db78cbe2d66be4d274e7f69af48b0 (patch)
tree1013a3cdf68edbdf40efdbdc4f22465f9628f6c1
parentde41512448a75b512977da6bca0809b7743bc323 (diff)
downloadgnunet-1489edfdd05db78cbe2d66be4d274e7f69af48b0.tar.gz
gnunet-1489edfdd05db78cbe2d66be4d274e7f69af48b0.zip
-big shorten algorithm change, hopefully fixed conflict
-rw-r--r--src/gns/gnunet-service-gns_resolver.c385
-rw-r--r--src/gns/gnunet-service-gns_resolver.h14
2 files changed, 286 insertions, 113 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 965f995a5..71f42e941 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -106,6 +106,18 @@ is_canonical(char* name)
106 106
107 107
108/** 108/**
109 * Callback that shortens authorities
110 *
111 * @param name the name given by delegation
112 * @param zone the authority
113 * @param our_zone our local zone
114 * @param key the private key of our authority
115 */
116static void
117shorten_authority_chain (struct GetPseuAuthorityHandle *gph);
118
119
120/**
109 * Namestore calls this function if we have record for this name. 121 * Namestore calls this function if we have record for this name.
110 * (or with rd_count=0 to indicate no matches) 122 * (or with rd_count=0 to indicate no matches)
111 * 123 *
@@ -118,7 +130,7 @@ is_canonical(char* name)
118 * @param signature the signature of the authority for the record data 130 * @param signature the signature of the authority for the record data
119 */ 131 */
120static void 132static void
121process_pseu_lookup_ns(void* cls, 133process_pseu_lookup_ns (void* cls,
122 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 134 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
123 struct GNUNET_TIME_Absolute expiration, 135 struct GNUNET_TIME_Absolute expiration,
124 const char *name, unsigned int rd_count, 136 const char *name, unsigned int rd_count,
@@ -127,49 +139,76 @@ process_pseu_lookup_ns(void* cls,
127{ 139{
128 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 140 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls;
129 struct GNUNET_NAMESTORE_RecordData new_pkey; 141 struct GNUNET_NAMESTORE_RecordData new_pkey;
142 struct AuthorityChain *iter;
130 143
131 if (rd_count > 0) 144 if (rd_count > 0)
132 { 145 {
133 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
134 "GNS_AUTO_PSEU: Name %s already taken in NS!\n", name); 147 "GNS_AUTO_PSEU: Name %s already taken in NS!\n", name);
135 if (0 == strcmp(gph->name, name)) 148 if (0 == strcmp (gph->name, name))
136 { 149 {
137 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 150 if (gph->ahead->next != NULL)
138 "GNS_AUTO_PSEU: Intelligent replacement not implemented\n", 151 {
139 name); 152 if (GNUNET_CRYPTO_short_hash_cmp (&gph->ahead->next->zone,
140 GNUNET_free(gph); 153 &gph->our_zone))
154 {
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: trying next!\n");
156 iter = gph->ahead->next;
157 GNUNET_free (gph->ahead);
158 gph->ahead = iter;
159 shorten_authority_chain (gph);
160 return;
161 }
162 }
163
164 /* Clean up */
165 do
166 {
167 iter = gph->ahead->next;
168 GNUNET_free (gph->ahead);
169 gph->ahead = iter;
170 } while (iter != NULL);
171
172 GNUNET_free (gph);
141 return; 173 return;
142 } 174 }
143 175
144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "GNS_AUTO_PSEU: Trying delegated name %s\n", gph->name); 177 "GNS_AUTO_PSEU: Trying delegated name %s\n", gph->name);
146 memcpy(gph->new_name, gph->name, strlen(gph->name)+1); 178 memcpy (gph->test_name, gph->name, strlen (gph->name)+1);
147 GNUNET_NAMESTORE_lookup_record(namestore_handle, 179 GNUNET_NAMESTORE_lookup_record (namestore_handle,
148 &gph->zone, 180 &gph->our_zone,
149 gph->new_name, 181 gph->test_name,
150 GNUNET_NAMESTORE_TYPE_ANY, 182 GNUNET_NAMESTORE_TYPE_ANY,
151 &process_pseu_lookup_ns, 183 &process_pseu_lookup_ns,
152 gph); 184 gph);
153 return; 185 return;
154 } 186 }
155 187
156 /** name is free */ 188 /** name is free */
157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n", gph->new_name); 190 "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n", gph->test_name);
159 191
160 new_pkey.expiration = GNUNET_TIME_UNIT_FOREVER_ABS; 192 new_pkey.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
161 new_pkey.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); 193 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
162 new_pkey.data = &gph->new_zone; 194 new_pkey.data = &gph->ahead->zone;
163 new_pkey.record_type = GNUNET_GNS_RECORD_PKEY; 195 new_pkey.record_type = GNUNET_GNS_RECORD_PKEY;
164 new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY 196 new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY
165 | GNUNET_NAMESTORE_RF_PRIVATE 197 | GNUNET_NAMESTORE_RF_PRIVATE
166 | GNUNET_NAMESTORE_RF_PENDING; 198 | GNUNET_NAMESTORE_RF_PENDING;
167 GNUNET_NAMESTORE_record_create (namestore_handle, 199 GNUNET_NAMESTORE_record_create (namestore_handle,
168 gph->key, 200 gph->key,
169 gph->new_name, 201 gph->test_name,
170 &new_pkey, 202 &new_pkey,
171 NULL, //cont 203 NULL, //cont
172 NULL); //cls 204 NULL); //cls
205 do
206 {
207 iter = gph->ahead->next;
208 GNUNET_free (gph->ahead);
209 gph->ahead = iter;
210 } while (iter != NULL);
211
173 GNUNET_free(gph); 212 GNUNET_free(gph);
174 213
175} 214}
@@ -181,29 +220,30 @@ process_pseu_lookup_ns(void* cls,
181 * @param name the pseu result or NULL 220 * @param name the pseu result or NULL
182 */ 221 */
183static void 222static void
184process_pseu_result(struct GetPseuAuthorityHandle* gph, char* name) 223process_pseu_result (struct GetPseuAuthorityHandle* gph, char* name)
185{ 224{
186 if (NULL == name) 225 if (NULL == name)
187 { 226 {
188 memcpy(gph->new_name, gph->name, strlen(gph->name)+1); 227 memcpy (gph->test_name, gph->ahead->name, strlen (gph->ahead->name)+1);
189 } 228 }
190 else 229 else
191 { 230 {
192 memcpy(gph->new_name, name, strlen(name)+1); 231 memcpy (gph->test_name, name, strlen(name)+1);
193 } 232 }
194 233
195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
196 "GNS_AUTO_PSEU: Checking %s for collision in NS\n", gph->new_name); 235 "GNS_AUTO_PSEU: Checking %s for collision in NS\n",
236 gph->test_name);
197 237
198 /** 238 /**
199 * Check for collision 239 * Check for collision
200 */ 240 */
201 GNUNET_NAMESTORE_lookup_record(namestore_handle, 241 GNUNET_NAMESTORE_lookup_record (namestore_handle,
202 &gph->zone, 242 &gph->our_zone,
203 gph->new_name, 243 gph->test_name,
204 GNUNET_NAMESTORE_TYPE_ANY, 244 GNUNET_NAMESTORE_TYPE_ANY,
205 &process_pseu_lookup_ns, 245 &process_pseu_lookup_ns,
206 gph); 246 gph);
207} 247}
208 248
209/** 249/**
@@ -217,12 +257,28 @@ handle_auth_discovery_timeout(void *cls,
217 const struct GNUNET_SCHEDULER_TaskContext *tc) 257 const struct GNUNET_SCHEDULER_TaskContext *tc)
218{ 258{
219 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 259 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls;
260 struct AuthorityChain *iter;
220 261
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "GNS_GET_AUTH: dht lookup for query PSEU timed out.\n"); 263 "GNS_GET_AUTH: dht lookup for query PSEU timed out.\n");
223 GNUNET_DHT_get_stop (gph->get_handle); 264 GNUNET_DHT_get_stop (gph->get_handle);
224 gph->get_handle = NULL; 265 gph->get_handle = NULL;
225 process_pseu_result(gph, NULL); 266
267 if (gph->ahead->next != NULL)
268 {
269 if (GNUNET_CRYPTO_short_hash_cmp (&gph->ahead->next->zone,
270 &gph->our_zone))
271 {
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: trying next!\n");
273 iter = gph->ahead->next;
274 GNUNET_free (gph->ahead);
275 gph->ahead = iter;
276 shorten_authority_chain (gph);
277 return;
278 }
279 }
280
281 process_pseu_result (gph, NULL);
226} 282}
227 283
228/** 284/**
@@ -251,6 +307,7 @@ process_auth_discovery_dht_result(void* cls,
251 size_t size, const void *data) 307 size_t size, const void *data)
252{ 308{
253 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 309 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls;
310 struct AuthorityChain *iter;
254 struct GNSNameRecordBlock *nrb; 311 struct GNSNameRecordBlock *nrb;
255 char* rd_data = (char*)data; 312 char* rd_data = (char*)data;
256 char* name; 313 char* name;
@@ -258,15 +315,22 @@ process_auth_discovery_dht_result(void* cls,
258 size_t rd_size; 315 size_t rd_size;
259 int i; 316 int i;
260 317
261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "GNS_GET_AUTH: got dht result (size=%d)\n", size); 319 "GNS_GET_AUTH: got dht result (size=%d)\n", size);
263 320
264 if (data == NULL) 321 if (data == NULL)
265 { 322 {
266 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
267 "GNS_GET_AUTH: got dht result null!\n", size); 324 "GNS_GET_AUTH: got dht result null!\n", size);
268 GNUNET_break(0); 325
269 GNUNET_free(gph); 326 do
327 {
328 iter = gph->ahead->next;
329 GNUNET_free (gph->ahead);
330 gph->ahead = iter;
331 } while (iter != NULL);
332
333 GNUNET_free (gph);
270 return; 334 return;
271 } 335 }
272 336
@@ -275,53 +339,80 @@ process_auth_discovery_dht_result(void* cls,
275 /* stop lookup and timeout task */ 339 /* stop lookup and timeout task */
276 GNUNET_DHT_get_stop (gph->get_handle); 340 GNUNET_DHT_get_stop (gph->get_handle);
277 gph->get_handle = NULL; 341 gph->get_handle = NULL;
278 GNUNET_SCHEDULER_cancel(gph->timeout); 342 GNUNET_SCHEDULER_cancel (gph->timeout);
279 343
280 gph->get_handle = NULL; 344 gph->get_handle = NULL;
281 345
282 nrb = (struct GNSNameRecordBlock*)data; 346 nrb = (struct GNSNameRecordBlock*)data;
283 347
284 name = (char*)&nrb[1]; 348 name = (char*)&nrb[1];
285 num_records = ntohl(nrb->rd_count); 349 num_records = ntohl (nrb->rd_count);
286 { 350 {
287 struct GNUNET_NAMESTORE_RecordData rd[num_records]; 351 struct GNUNET_NAMESTORE_RecordData rd[num_records];
288 352
289 rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); 353 rd_data += strlen (name) + 1 + sizeof (struct GNSNameRecordBlock);
290 rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock); 354 rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock);
291 355
292 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, 356 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
293 rd_data, 357 rd_data,
294 num_records, 358 num_records,
295 rd)) 359 rd))
296 { 360 {
297 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
298 "GNS_GET_AUTH: Error deserializing data!\n"); 362 "GNS_GET_AUTH: Error deserializing data!\n");
299 GNUNET_break(0);
300 GNUNET_free(gph);
301 return;
302 } 363 }
303 364 else
304 for (i=0; i<num_records; i++)
305 { 365 {
306 if ((strcmp(name, "+") == 0) && 366 for (i=0; i < num_records; i++)
307 (rd[i].record_type == GNUNET_GNS_RECORD_PSEU))
308 { 367 {
309 /* found pseu */ 368 if ((strcmp (name, "+") == 0) &&
310 process_pseu_result(gph, (char*)rd[i].data); 369 (rd[i].record_type == GNUNET_GNS_RECORD_PSEU))
311 return; 370 {
371 /* found pseu */
372 process_pseu_result (gph, (char*)rd[i].data);
373 return;
374 }
312 } 375 }
313 } 376 }
314 } 377 }
315 378
316 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: no pseu in dht!\n"); 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: no pseu in dht!\n");
317 process_pseu_result(gph, NULL); 380
381 if (gph->ahead->next != NULL)
382 {
383 if (GNUNET_CRYPTO_short_hash_cmp (&gph->ahead->next->zone,
384 &gph->our_zone))
385 {
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: trying next!\n");
387 iter = gph->ahead->next;
388 GNUNET_free (gph->ahead);
389 gph->ahead = iter;
390 shorten_authority_chain (gph);
391 return;
392 }
393 }
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "GNS_GET_AUTH: finished shorten, no results!\n");
396 process_pseu_result (gph, NULL);
318} 397}
319 398
399/**
400 * Process PSEU discovery for shorten via namestore
401 *
402 * @param cls the GetPseuAuthorityHandle
403 * @param key the public key
404 * @param expiration recorddata expiration
405 * @param name the looked up name
406 * @param rd_count number of records in set
407 * @param rd record data
408 * @param signature the signature
409 */
320static void 410static void
321process_auth_discovery_ns_result(void* cls, 411process_auth_discovery_ns_result(void* cls,
322 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 412 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
323 struct GNUNET_TIME_Absolute expiration, 413 struct GNUNET_TIME_Absolute expiration,
324 const char *name, unsigned int rd_count, 414 const char *name,
415 unsigned int rd_count,
325 const struct GNUNET_NAMESTORE_RecordData *rd, 416 const struct GNUNET_NAMESTORE_RecordData *rd,
326 const struct GNUNET_CRYPTO_RsaSignature *signature) 417 const struct GNUNET_CRYPTO_RsaSignature *signature)
327{ 418{
@@ -333,6 +424,7 @@ process_auth_discovery_ns_result(void* cls,
333 struct GNUNET_HashCode zone_hash_double; 424 struct GNUNET_HashCode zone_hash_double;
334 int i; 425 int i;
335 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 426 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls;
427 struct AuthorityChain *iter;
336 428
337 /* no pseu found */ 429 /* no pseu found */
338 if (rd_count == 0) 430 if (rd_count == 0)
@@ -340,22 +432,23 @@ process_auth_discovery_ns_result(void* cls,
340 /** 432 /**
341 * check dht 433 * check dht
342 */ 434 */
343 GNUNET_CRYPTO_short_hash("+", strlen("+"), &name_hash); 435 GNUNET_CRYPTO_short_hash ("+", strlen ("+"), &name_hash);
344 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double); 436 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
345 GNUNET_CRYPTO_short_hash_double (&gph->new_zone, &zone_hash_double); 437 GNUNET_CRYPTO_short_hash_double (&gph->ahead->zone, &zone_hash_double);
346 GNUNET_CRYPTO_hash_xor(&name_hash_double, &zone_hash_double, &lookup_key); 438 GNUNET_CRYPTO_hash_xor (&name_hash_double, &zone_hash_double, &lookup_key);
347 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string); 439 GNUNET_CRYPTO_hash_to_enc (&lookup_key, &lookup_key_string);
348 440
349 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "GNS_AUTO_PSEU: starting dht lookup for %s with key: %s\n", 442 "GNS_AUTO_PSEU: starting dht lookup for %s with key: %s\n",
351 "+", (char*)&lookup_key_string); 443 "+", (char*)&lookup_key_string);
352 444
353 gph->timeout = GNUNET_SCHEDULER_add_delayed(DHT_LOOKUP_TIMEOUT, 445 gph->timeout = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
354 &handle_auth_discovery_timeout, gph); 446 &handle_auth_discovery_timeout, gph);
355 447
356 xquery = htonl(GNUNET_GNS_RECORD_PSEU); 448 xquery = htonl (GNUNET_GNS_RECORD_PSEU);
357 449
358 GNUNET_assert(gph->get_handle == NULL); 450 GNUNET_assert (gph->get_handle == NULL);
451
359 gph->get_handle = GNUNET_DHT_get_start(dht_handle, 452 gph->get_handle = GNUNET_DHT_get_start(dht_handle,
360 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 453 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
361 &lookup_key, 454 &lookup_key,
@@ -367,16 +460,35 @@ process_auth_discovery_ns_result(void* cls,
367 gph); 460 gph);
368 return; 461 return;
369 } 462 }
370 for (i=0; i<rd_count; i++) 463
464 for (i=0; i < rd_count; i++)
371 { 465 {
372 if ((strcmp(name, "+") == 0) && 466 if ((strcmp (name, "+") == 0) &&
373 (rd[i].record_type == GNUNET_GNS_RECORD_PSEU)) 467 (rd[i].record_type == GNUNET_GNS_RECORD_PSEU))
374 { 468 {
375 /* found pseu */ 469 /* found pseu */
376 process_pseu_result(gph, (char*)rd[i].data); 470 process_pseu_result (gph, (char*)rd[i].data);
377 return; 471 return;
378 } 472 }
379 } 473 }
474
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: no pseu in namestore!\n");
476
477 if (gph->ahead->next != NULL)
478 {
479 if (GNUNET_CRYPTO_short_hash_cmp (&gph->ahead->next->zone,
480 &gph->our_zone))
481 {
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS_GET_AUTH: trying next!\n");
483 iter = gph->ahead->next;
484 GNUNET_free (gph->ahead);
485 gph->ahead = iter;
486 shorten_authority_chain (gph);
487 return;
488 }
489 }
490
491 process_pseu_result (gph, NULL);
380} 492}
381 493
382/** 494/**
@@ -392,7 +504,7 @@ process_auth_discovery_ns_result(void* cls,
392 * @param signature the signature for the record data 504 * @param signature the signature for the record data
393 */ 505 */
394static void 506static void
395process_zone_to_name_discover(void *cls, 507process_zone_to_name_discover (void *cls,
396 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 508 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
397 struct GNUNET_TIME_Absolute expire, 509 struct GNUNET_TIME_Absolute expire,
398 const char *name, 510 const char *name,
@@ -401,65 +513,97 @@ process_zone_to_name_discover(void *cls,
401 const struct GNUNET_CRYPTO_RsaSignature *signature) 513 const struct GNUNET_CRYPTO_RsaSignature *signature)
402{ 514{
403 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls; 515 struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls;
516 struct AuthorityChain *iter;
404 517
405 /* we found a match in our own zone */ 518 /* we found a match in our own zone */
406 if (rd_len != 0) 519 if (rd_len != 0)
407 { 520 {
408 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
409 "GNS_AUTO_PSEU: name for zone in our root %s\n", name); 522 "GNS_AUTO_PSEU: name for zone in our root %s\n", name);
410 GNUNET_free(gph); 523
524 iter = gph->ahead;
525 do
526 {
527 iter = gph->ahead->next;
528 GNUNET_free (gph->ahead);
529 gph->ahead = iter;
530 } while (iter != NULL);
531
532 GNUNET_free (gph);
411 } 533 }
412 else 534 else
413 { 535 {
414 536
415 GNUNET_NAMESTORE_lookup_record(namestore_handle, 537 GNUNET_NAMESTORE_lookup_record (namestore_handle,
416 &gph->new_zone, 538 &gph->ahead->zone,
417 "+", 539 "+",
418 GNUNET_GNS_RECORD_PSEU, 540 GNUNET_GNS_RECORD_PSEU,
419 &process_auth_discovery_ns_result, 541 &process_auth_discovery_ns_result,
420 gph); 542 gph);
421 } 543 }
422
423 544
424} 545}
425 546
426 547
427/** 548/**
428 * Callback for new authories 549 * Callback that shortens authorities
429 * 550 *
430 * @param name the name given by delegation 551 * @param name the name given by delegation
431 * @param zone the authority 552 * @param zone the authority
432 * @param our_zone our local zone 553 * @param our_zone our local zone
433 * @param key the private key of our authority 554 * @param key the private key of our authority
434 */ 555 */
435static void process_discovered_authority(char* name, 556static void
436 struct GNUNET_CRYPTO_ShortHashCode zone, 557shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
437 struct GNUNET_CRYPTO_ShortHashCode our_zone,
438 struct GNUNET_CRYPTO_RsaPrivateKey *key)
439{ 558{
440 struct GetPseuAuthorityHandle *gph;
441 size_t namelen;
442 559
443 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "GNS_AUTO_PSEU: New authority %s discovered\n", 561 "GNS_AUTO_PSEU: New authority %s discovered\n",
445 name); 562 gph->ahead->name);
446
447 gph = GNUNET_malloc(sizeof(struct GetPseuAuthorityHandle));
448 namelen = strlen(name) + 1;
449 memcpy(gph->name, name, namelen);
450
451 gph->new_zone = zone;
452 gph->zone = our_zone;
453 gph->key = key;
454 563
455 GNUNET_NAMESTORE_zone_to_name (namestore_handle, 564 GNUNET_NAMESTORE_zone_to_name (namestore_handle,
456 &our_zone, 565 &gph->our_zone,
457 &gph->new_zone, 566 &gph->ahead->zone,
458 &process_zone_to_name_discover, 567 &process_zone_to_name_discover,
459 gph); 568 gph);
460 569
461} 570}
462 571
572static void
573start_shorten (struct AuthorityChain *atail,
574 struct GNUNET_CRYPTO_RsaPrivateKey *key)
575{
576 struct AuthorityChain *new_head = NULL;
577 struct AuthorityChain *new_tail = NULL;
578 struct AuthorityChain *iter;
579 struct AuthorityChain *acopy;
580 struct GetPseuAuthorityHandle *gph;
581 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
582
583 /* First copy the authority chain in reverse order */
584 for (iter = atail; iter != NULL; iter = iter->prev)
585 {
586 acopy = GNUNET_malloc (sizeof (struct AuthorityChain));
587 memcpy (acopy, iter, sizeof (struct AuthorityChain));
588 acopy->next = NULL;
589 acopy->prev = NULL;
590 GNUNET_CONTAINER_DLL_insert (new_head, new_tail, acopy);
591 }
592
593 gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle));
594
595 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
596 gph->key = key;//GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
597 //memcpy (gph->key, key, sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
598
599 GNUNET_CRYPTO_short_hash (&pkey,
600 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
601 &gph->our_zone);
602 gph->ahead = new_head;
603
604 shorten_authority_chain (gph);
605}
606
463/** 607/**
464 * Initialize the resolver 608 * Initialize the resolver
465 * 609 *
@@ -1038,6 +1182,15 @@ resolve_record_ns(struct ResolverHandle *rh)
1038 GNUNET_SCHEDULER_cancel(rh->timeout_task); 1182 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1039 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1183 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1040 } 1184 }
1185 /* Start shortening */
1186 if ((rh->priv_key != NULL) && is_canonical (rh->name))
1187 {
1188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1189 "GNS_PHASE_REC-%llu: Trying to shorten authority chain\n",
1190 rh->id);
1191 start_shorten (rh->authority_chain_tail,
1192 rh->priv_key);
1193 }
1041 1194
1042 /** 1195 /**
1043 * Try to resolve this record in our namestore. 1196 * Try to resolve this record in our namestore.
@@ -1253,10 +1406,10 @@ process_delegation_result_dht(void* cls,
1253 auth); 1406 auth);
1254 1407
1255 /** try to import pkey if private key available */ 1408 /** try to import pkey if private key available */
1256 if (rh->priv_key && is_canonical (rh->name)) 1409 //if (rh->priv_key && is_canonical (rh->name))
1257 process_discovered_authority(name, auth->zone, 1410 // process_discovered_authority(name, auth->zone,
1258 rh->authority_chain_tail->zone, 1411 // rh->authority_chain_tail->zone,
1259 rh->priv_key); 1412 // rh->priv_key);
1260 } 1413 }
1261 1414
1262 } 1415 }
@@ -1293,8 +1446,19 @@ process_delegation_result_dht(void* cls,
1293 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1446 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1294 "GNS_PHASE_DELEGATE_DHT-%llu: Answer from DHT for %s. Yet to resolve: %s\n", 1447 "GNS_PHASE_DELEGATE_DHT-%llu: Answer from DHT for %s. Yet to resolve: %s\n",
1295 rh->id, rh->authority_name, rh->name); 1448 rh->id, rh->authority_name, rh->name);
1449
1296 if (strcmp(rh->name, "") == 0) 1450 if (strcmp(rh->name, "") == 0)
1297 { 1451 {
1452 /* Start shortening */
1453 if ((rh->priv_key != NULL) && is_canonical (rh->name))
1454 {
1455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1456 "GNS_PHASE_DELEGATE_DHT-%llu: Trying to shorten authority chain\n",
1457 rh->id);
1458 start_shorten (rh->authority_chain_tail,
1459 rh->priv_key);
1460 }
1461
1298 rh->proc(rh->proc_cls, rh, 0, NULL); 1462 rh->proc(rh->proc_cls, rh, 0, NULL);
1299 } 1463 }
1300 else 1464 else
@@ -2003,10 +2167,10 @@ process_delegation_result_ns(void* cls,
2003 /** try to import pkey if private key available 2167 /** try to import pkey if private key available
2004 * TODO: Only import last one? 2168 * TODO: Only import last one?
2005 */ 2169 */
2006 if (rh->priv_key && (name != NULL) && is_canonical (rh->name)) 2170 //if (rh->priv_key && (name != NULL) && is_canonical (rh->name))
2007 process_discovered_authority((char*)name, auth->zone, 2171 // process_discovered_authority((char*)name, auth->zone,
2008 rh->authority_chain_tail->zone, 2172 // rh->authority_chain_tail->zone,
2009 rh->priv_key); 2173 // rh->priv_key);
2010 /** 2174 /**
2011 * We are done with PKEY resolution if name is empty 2175 * We are done with PKEY resolution if name is empty
2012 * else resolve again with new authority 2176 * else resolve again with new authority
@@ -2029,6 +2193,15 @@ process_delegation_result_ns(void* cls,
2029 */ 2193 */
2030 if (strcmp(rh->name, "") == 0) 2194 if (strcmp(rh->name, "") == 0)
2031 { 2195 {
2196 /* Start shortening */
2197 if ((rh->priv_key != NULL) && is_canonical (rh->name))
2198 {
2199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2200 "GNS_PHASE_DELEGATE_NS-%llu: Trying to shorten authority chain\n",
2201 rh->id);
2202 start_shorten (rh->authority_chain_tail,
2203 rh->priv_key);
2204 }
2032 /* simply promote back */ 2205 /* simply promote back */
2033 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2034 "GNS_PHASE_DELEGATE_NS-%llu: Promoting %s back to name\n", 2207 "GNS_PHASE_DELEGATE_NS-%llu: Promoting %s back to name\n",
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index f1f25a5c1..2a2c341d3 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -228,17 +228,14 @@ struct GetNameAuthorityHandle
228 */ 228 */
229struct GetPseuAuthorityHandle 229struct GetPseuAuthorityHandle
230{ 230{
231 /* the name given from delegation */ 231 /* the name to store the zone under */
232 char name[MAX_DNS_LABEL_LENGTH]; 232 char name[MAX_DNS_LABEL_LENGTH];
233 233
234 /* name to store the pseu under */ 234 /* test name to store the zone under */
235 char new_name[MAX_DNS_LABEL_LENGTH]; 235 char test_name[MAX_DNS_LABEL_LENGTH];
236 236
237 /* the zone of discovered authority */
238 struct GNUNET_CRYPTO_ShortHashCode new_zone;
239
240 /* the zone of our authority */ 237 /* the zone of our authority */
241 struct GNUNET_CRYPTO_ShortHashCode zone; 238 struct GNUNET_CRYPTO_ShortHashCode our_zone;
242 239
243 /* the private key of the zone to store the pseu in */ 240 /* the private key of the zone to store the pseu in */
244 struct GNUNET_CRYPTO_RsaPrivateKey *key; 241 struct GNUNET_CRYPTO_RsaPrivateKey *key;
@@ -248,6 +245,9 @@ struct GetPseuAuthorityHandle
248 245
249 /* timeout task for lookup */ 246 /* timeout task for lookup */
250 GNUNET_SCHEDULER_TaskIdentifier timeout; 247 GNUNET_SCHEDULER_TaskIdentifier timeout;
248
249 /* Head of the authority list */
250 struct AuthorityChain *ahead;
251}; 251};
252 252
253/** 253/**