diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-22 17:28:45 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-22 17:28:45 +0100 |
commit | 984f1197d28560346e5cf4951ac9d6bbef08053e (patch) | |
tree | 551ef0aaa7dbc27bdc113a578aa80836d9f4239c /src/cadet/gnunet-service-cadet-new_paths.c | |
parent | 970d06eab7013f243d62c2d349a7c1dd89fea9d4 (diff) | |
download | gnunet-984f1197d28560346e5cf4951ac9d6bbef08053e.tar.gz gnunet-984f1197d28560346e5cf4951ac9d6bbef08053e.zip |
initialize new path fully before trying to attach it
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_paths.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet-new_paths.c | 90 |
1 files changed, 59 insertions, 31 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_paths.c b/src/cadet/gnunet-service-cadet-new_paths.c index 39658d4e8..c9fdbcb3a 100644 --- a/src/cadet/gnunet-service-cadet-new_paths.c +++ b/src/cadet/gnunet-service-cadet-new_paths.c | |||
@@ -25,7 +25,6 @@ | |||
25 | * | 25 | * |
26 | * TODO: | 26 | * TODO: |
27 | * - path desirability score calculations are not done | 27 | * - path desirability score calculations are not done |
28 | * (and will be tricky to have during path changes) | ||
29 | */ | 28 | */ |
30 | #include "platform.h" | 29 | #include "platform.h" |
31 | #include "gnunet-service-cadet-new_connection.h" | 30 | #include "gnunet-service-cadet-new_connection.h" |
@@ -359,11 +358,30 @@ extend_path (struct CadetPeerPath *path, | |||
359 | struct GNUNET_CONTAINER_HeapNode *hn; | 358 | struct GNUNET_CONTAINER_HeapNode *hn; |
360 | int i; | 359 | int i; |
361 | 360 | ||
361 | /* Expand path */ | ||
362 | GNUNET_array_grow (path->entries, | ||
363 | path->entries_length, | ||
364 | old_len + num_peers); | ||
365 | for (i=num_peers-1;i >= 0;i--) | ||
366 | { | ||
367 | struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry); | ||
368 | |||
369 | path->entries[old_len + i] = entry; | ||
370 | entry->peer = peers[i]; | ||
371 | entry->path = path; | ||
372 | GCP_path_entry_add (entry->peer, | ||
373 | entry, | ||
374 | old_len + i); | ||
375 | } | ||
376 | |||
362 | /* If we extend an existing path, detach it from the | 377 | /* If we extend an existing path, detach it from the |
363 | old owner and re-attach to the new one */ | 378 | old owner and re-attach to the new one */ |
364 | hn = NULL; | 379 | hn = NULL; |
365 | for (i=num_peers-1;i>=0;i--) | 380 | for (i=num_peers-1;i>=0;i--) |
366 | { | 381 | { |
382 | struct CadetPeerPathEntry *entry = path->entries[old_len + i]; | ||
383 | |||
384 | path->entries_length = old_len + i + 1; | ||
367 | /* FIXME: note that path->desirability is used, but not yet updated here! */ | 385 | /* FIXME: note that path->desirability is used, but not yet updated here! */ |
368 | hn = GCP_attach_path (peers[i], | 386 | hn = GCP_attach_path (peers[i], |
369 | path, | 387 | path, |
@@ -371,27 +389,25 @@ extend_path (struct CadetPeerPath *path, | |||
371 | GNUNET_YES); | 389 | GNUNET_YES); |
372 | if (NULL != hn) | 390 | if (NULL != hn) |
373 | break; | 391 | break; |
392 | GCP_path_entry_remove (entry->peer, | ||
393 | entry, | ||
394 | old_len + i); | ||
395 | GNUNET_free (entry); | ||
396 | path->entries[old_len + i] = NULL; | ||
374 | } | 397 | } |
375 | if (NULL == hn) | 398 | if (NULL == hn) |
376 | return; /* none of the peers is interested in this path */ | 399 | { |
400 | /* none of the peers is interested in this path; | ||
401 | shrink path back */ | ||
402 | GNUNET_array_grow (path->entries, | ||
403 | path->entries_length, | ||
404 | old_len); | ||
405 | return; | ||
406 | } | ||
377 | GCP_detach_path (path->entries[old_len-1]->peer, | 407 | GCP_detach_path (path->entries[old_len-1]->peer, |
378 | path, | 408 | path, |
379 | path->hn); | 409 | path->hn); |
380 | path->hn = hn; | 410 | path->hn = hn; |
381 | GNUNET_array_grow (path->entries, | ||
382 | path->entries_length, | ||
383 | old_len + i); | ||
384 | for (;i >= 0;i--) | ||
385 | { | ||
386 | struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry); | ||
387 | |||
388 | path->entries[old_len + i] = entry; | ||
389 | entry->peer = peers[i]; | ||
390 | entry->path = path; | ||
391 | GCP_path_entry_add (entry->peer, | ||
392 | entry, | ||
393 | old_len + i); | ||
394 | } | ||
395 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
396 | "Extended path %s\n", | 412 | "Extended path %s\n", |
397 | GCPP_2s (path)); | 413 | GCPP_2s (path)); |
@@ -471,11 +487,27 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
471 | 487 | ||
472 | /* No match at all, create completely new path */ | 488 | /* No match at all, create completely new path */ |
473 | path = GNUNET_new (struct CadetPeerPath); | 489 | path = GNUNET_new (struct CadetPeerPath); |
490 | path->entries_length = get_path_length + put_path_length; | ||
491 | path->entries = GNUNET_new_array (path->entries_length, | ||
492 | struct CadetPeerPathEntry *); | ||
493 | for (i=path->entries_length-1;i>=0;i--) | ||
494 | { | ||
495 | struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry); | ||
496 | |||
497 | path->entries[i] = entry; | ||
498 | entry->peer = cpath[i]; | ||
499 | entry->path = path; | ||
500 | GCP_path_entry_add (entry->peer, | ||
501 | entry, | ||
502 | i); | ||
503 | } | ||
474 | 504 | ||
475 | /* First, try to attach it */ | 505 | /* Finally, try to attach it */ |
476 | hn = NULL; | 506 | hn = NULL; |
477 | for (i=get_path_length + put_path_length-1;i>=0;i--) | 507 | for (i=get_path_length + put_path_length-1;i>=0;i--) |
478 | { | 508 | { |
509 | struct CadetPeerPathEntry *entry = path->entries[i]; | ||
510 | |||
479 | path->entries_length = i + 1; | 511 | path->entries_length = i + 1; |
480 | /* FIXME: note that path->desirability is used, but not yet initialized here! */ | 512 | /* FIXME: note that path->desirability is used, but not yet initialized here! */ |
481 | hn = GCP_attach_path (cpath[i], | 513 | hn = GCP_attach_path (cpath[i], |
@@ -484,30 +516,26 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
484 | GNUNET_NO); | 516 | GNUNET_NO); |
485 | if (NULL != hn) | 517 | if (NULL != hn) |
486 | break; | 518 | break; |
519 | GCP_path_entry_remove (entry->peer, | ||
520 | entry, | ||
521 | i); | ||
522 | GNUNET_free (entry); | ||
523 | path->entries[i] = NULL; | ||
487 | } | 524 | } |
488 | if (NULL == hn) | 525 | if (NULL == hn) |
489 | { | 526 | { |
490 | /* None of the peers on the path care about it. */ | 527 | /* None of the peers on the path care about it. */ |
491 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 528 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
492 | "Path discovered from DHT is not interesting to us\n"); | 529 | "Path discovered from DHT is not interesting to us\n"); |
530 | GNUNET_free (path->entries); | ||
493 | GNUNET_free (path); | 531 | GNUNET_free (path); |
494 | return; | 532 | return; |
495 | } | 533 | } |
496 | path->hn = hn; | 534 | path->hn = hn; |
497 | path->entries_length = i + 1; | 535 | /* Shrink path to actual useful length */ |
498 | path->entries = GNUNET_new_array (path->entries_length, | 536 | GNUNET_array_grow (path->entries, |
499 | struct CadetPeerPathEntry *); | 537 | path->entries_length, |
500 | for (;i>=0;i--) | 538 | i); |
501 | { | ||
502 | struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry); | ||
503 | |||
504 | path->entries[i] = entry; | ||
505 | entry->peer = cpath[i]; | ||
506 | entry->path = path; | ||
507 | GCP_path_entry_add (entry->peer, | ||
508 | entry, | ||
509 | i); | ||
510 | } | ||
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 539 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
512 | "Created new path %s based on information from DHT\n", | 540 | "Created new path %s based on information from DHT\n", |
513 | GCPP_2s (path)); | 541 | GCPP_2s (path)); |