diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.c | 1244 |
1 files changed, 620 insertions, 624 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index d6cc6f914..23eb6b225 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file cadet/gnunet-service-cadet_peer.c | 22 | * @file cadet/gnunet-service-cadet_peer.c |
@@ -46,7 +46,7 @@ | |||
46 | #include "gnunet-service-cadet_tunnels.h" | 46 | #include "gnunet-service-cadet_tunnels.h" |
47 | 47 | ||
48 | 48 | ||
49 | #define LOG(level, ...) GNUNET_log_from(level,"cadet-per",__VA_ARGS__) | 49 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-per", __VA_ARGS__) |
50 | 50 | ||
51 | 51 | ||
52 | /** | 52 | /** |
@@ -69,9 +69,7 @@ | |||
69 | * Data structure used to track whom we have to notify about changes | 69 | * Data structure used to track whom we have to notify about changes |
70 | * to our message queue. | 70 | * to our message queue. |
71 | */ | 71 | */ |
72 | struct GCP_MessageQueueManager | 72 | struct GCP_MessageQueueManager { |
73 | { | ||
74 | |||
75 | /** | 73 | /** |
76 | * Kept in a DLL. | 74 | * Kept in a DLL. |
77 | */ | 75 | */ |
@@ -101,15 +99,13 @@ struct GCP_MessageQueueManager | |||
101 | * Envelope this manager would like to transmit once it is its turn. | 99 | * Envelope this manager would like to transmit once it is its turn. |
102 | */ | 100 | */ |
103 | struct GNUNET_MQ_Envelope *env; | 101 | struct GNUNET_MQ_Envelope *env; |
104 | |||
105 | }; | 102 | }; |
106 | 103 | ||
107 | 104 | ||
108 | /** | 105 | /** |
109 | * Struct containing all information regarding a given peer | 106 | * Struct containing all information regarding a given peer |
110 | */ | 107 | */ |
111 | struct CadetPeer | 108 | struct CadetPeer { |
112 | { | ||
113 | /** | 109 | /** |
114 | * ID of the peer | 110 | * ID of the peer |
115 | */ | 111 | */ |
@@ -229,7 +225,6 @@ struct CadetPeer | |||
229 | * The arrays should be grown as needed. | 225 | * The arrays should be grown as needed. |
230 | */ | 226 | */ |
231 | unsigned int path_dll_length; | 227 | unsigned int path_dll_length; |
232 | |||
233 | }; | 228 | }; |
234 | 229 | ||
235 | 230 | ||
@@ -240,23 +235,23 @@ struct CadetPeer | |||
240 | * @return Static string for it's ID. | 235 | * @return Static string for it's ID. |
241 | */ | 236 | */ |
242 | const char * | 237 | const char * |
243 | GCP_2s (const struct CadetPeer *cp) | 238 | GCP_2s(const struct CadetPeer *cp) |
244 | { | 239 | { |
245 | static char buf[5]; | 240 | static char buf[5]; |
246 | char *ret; | 241 | char *ret; |
247 | 242 | ||
248 | if ((NULL == cp) || | 243 | if ((NULL == cp) || |
249 | (0 == GNUNET_is_zero (&cp->pid.public_key))) | 244 | (0 == GNUNET_is_zero(&cp->pid.public_key))) |
250 | return "NULL"; | 245 | return "NULL"; |
251 | 246 | ||
252 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key); | 247 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&cp->pid.public_key); |
253 | if (NULL == ret) | 248 | if (NULL == ret) |
254 | return "NULL"; | 249 | return "NULL"; |
255 | 250 | ||
256 | GNUNET_strlcpy (buf, | 251 | GNUNET_strlcpy(buf, |
257 | ret, | 252 | ret, |
258 | sizeof (buf)); | 253 | sizeof(buf)); |
259 | GNUNET_free (ret); | 254 | GNUNET_free(ret); |
260 | return buf; | 255 | return buf; |
261 | } | 256 | } |
262 | 257 | ||
@@ -277,8 +272,8 @@ GCP_2s (const struct CadetPeer *cp) | |||
277 | * positive scores mean path is more desirable | 272 | * positive scores mean path is more desirable |
278 | */ | 273 | */ |
279 | double | 274 | double |
280 | GCP_get_desirability_of_path (struct CadetPeer *cp, | 275 | GCP_get_desirability_of_path(struct CadetPeer *cp, |
281 | unsigned int off) | 276 | unsigned int off) |
282 | { | 277 | { |
283 | unsigned int num_alts = cp->num_paths; | 278 | unsigned int num_alts = cp->num_paths; |
284 | unsigned int off_sum; | 279 | unsigned int off_sum; |
@@ -286,20 +281,20 @@ GCP_get_desirability_of_path (struct CadetPeer *cp, | |||
286 | double path_delta; | 281 | double path_delta; |
287 | double weight_alts; | 282 | double weight_alts; |
288 | 283 | ||
289 | GNUNET_assert (num_alts >= 1); /* 'path' should be in there! */ | 284 | GNUNET_assert(num_alts >= 1); /* 'path' should be in there! */ |
290 | GNUNET_assert (0 != cp->path_dll_length); | 285 | GNUNET_assert(0 != cp->path_dll_length); |
291 | 286 | ||
292 | /* We maintain 'off_sum' in 'peer' and thereby | 287 | /* We maintain 'off_sum' in 'peer' and thereby |
293 | avoid the SLOW recalculation each time. Kept here | 288 | avoid the SLOW recalculation each time. Kept here |
294 | just to document what is going on. */ | 289 | just to document what is going on. */ |
295 | #if SLOW | 290 | #if SLOW |
296 | off_sum = 0; | 291 | off_sum = 0; |
297 | for (unsigned int j=0;j<cp->path_dll_length;j++) | 292 | for (unsigned int j = 0; j < cp->path_dll_length; j++) |
298 | for (struct CadetPeerPathEntry *pe = cp->path_heads[j]; | 293 | for (struct CadetPeerPathEntry *pe = cp->path_heads[j]; |
299 | NULL != pe; | 294 | NULL != pe; |
300 | pe = pe->next) | 295 | pe = pe->next) |
301 | off_sum += j; | 296 | off_sum += j; |
302 | GNUNET_assert (off_sum == cp->off_sum); | 297 | GNUNET_assert(off_sum == cp->off_sum); |
303 | #else | 298 | #else |
304 | off_sum = cp->off_sum; | 299 | off_sum = cp->off_sum; |
305 | #endif | 300 | #endif |
@@ -307,8 +302,8 @@ GCP_get_desirability_of_path (struct CadetPeer *cp, | |||
307 | path_delta = off - avg_sum; | 302 | path_delta = off - avg_sum; |
308 | /* path_delta positiv: path off of peer above average (bad path for peer), | 303 | /* path_delta positiv: path off of peer above average (bad path for peer), |
309 | path_delta negativ: path off of peer below average (good path for peer) */ | 304 | path_delta negativ: path off of peer below average (good path for peer) */ |
310 | if (path_delta <= - 1.0) | 305 | if (path_delta <= -1.0) |
311 | weight_alts = - num_alts / path_delta; /* discount alternative paths */ | 306 | weight_alts = -num_alts / path_delta; /* discount alternative paths */ |
312 | else if (path_delta >= 1.0) | 307 | else if (path_delta >= 1.0) |
313 | weight_alts = num_alts * path_delta; /* overcount alternative paths */ | 308 | weight_alts = num_alts * path_delta; /* overcount alternative paths */ |
314 | else | 309 | else |
@@ -328,63 +323,63 @@ GCP_get_desirability_of_path (struct CadetPeer *cp, | |||
328 | * @param cls peer to clean up | 323 | * @param cls peer to clean up |
329 | */ | 324 | */ |
330 | static void | 325 | static void |
331 | destroy_peer (void *cls) | 326 | destroy_peer(void *cls) |
332 | { | 327 | { |
333 | struct CadetPeer *cp = cls; | 328 | struct CadetPeer *cp = cls; |
334 | 329 | ||
335 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 330 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
336 | "Destroying state about peer %s\n", | 331 | "Destroying state about peer %s\n", |
337 | GCP_2s (cp)); | 332 | GCP_2s(cp)); |
338 | cp->destroy_task = NULL; | 333 | cp->destroy_task = NULL; |
339 | GNUNET_assert (NULL == cp->t); | 334 | GNUNET_assert(NULL == cp->t); |
340 | GNUNET_assert (NULL == cp->core_mq); | 335 | GNUNET_assert(NULL == cp->core_mq); |
341 | GNUNET_assert (0 == cp->num_paths); | 336 | GNUNET_assert(0 == cp->num_paths); |
342 | for (unsigned int i=0;i<cp->path_dll_length;i++) | 337 | for (unsigned int i = 0; i < cp->path_dll_length; i++) |
343 | GNUNET_assert (NULL == cp->path_heads[i]); | 338 | GNUNET_assert(NULL == cp->path_heads[i]); |
344 | GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)); | 339 | GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)); |
345 | GNUNET_assert (GNUNET_YES == | 340 | GNUNET_assert(GNUNET_YES == |
346 | GNUNET_CONTAINER_multipeermap_remove (peers, | 341 | GNUNET_CONTAINER_multipeermap_remove(peers, |
347 | &cp->pid, | 342 | &cp->pid, |
348 | cp)); | 343 | cp)); |
349 | GNUNET_free_non_null (cp->path_heads); | 344 | GNUNET_free_non_null(cp->path_heads); |
350 | GNUNET_free_non_null (cp->path_tails); | 345 | GNUNET_free_non_null(cp->path_tails); |
351 | cp->path_dll_length = 0; | 346 | cp->path_dll_length = 0; |
352 | if (NULL != cp->search_h) | 347 | if (NULL != cp->search_h) |
353 | { | 348 | { |
354 | GCD_search_stop (cp->search_h); | 349 | GCD_search_stop(cp->search_h); |
355 | cp->search_h = NULL; | 350 | cp->search_h = NULL; |
356 | } | 351 | } |
357 | /* FIXME: clean up search_delayedXXX! */ | 352 | /* FIXME: clean up search_delayedXXX! */ |
358 | 353 | ||
359 | if (NULL != cp->hello_offer) | 354 | if (NULL != cp->hello_offer) |
360 | { | 355 | { |
361 | GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer); | 356 | GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer); |
362 | cp->hello_offer = NULL; | 357 | cp->hello_offer = NULL; |
363 | } | 358 | } |
364 | if (NULL != cp->connectivity_suggestion) | 359 | if (NULL != cp->connectivity_suggestion) |
365 | { | 360 | { |
366 | GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); | 361 | GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); |
367 | cp->connectivity_suggestion = NULL; | 362 | cp->connectivity_suggestion = NULL; |
368 | } | 363 | } |
369 | GNUNET_CONTAINER_multishortmap_destroy (cp->connections); | 364 | GNUNET_CONTAINER_multishortmap_destroy(cp->connections); |
370 | if (NULL != cp->path_heap) | 365 | if (NULL != cp->path_heap) |
371 | { | 366 | { |
372 | GNUNET_CONTAINER_heap_destroy (cp->path_heap); | 367 | GNUNET_CONTAINER_heap_destroy(cp->path_heap); |
373 | cp->path_heap = NULL; | 368 | cp->path_heap = NULL; |
374 | } | 369 | } |
375 | if (NULL != cp->heap_cleanup_task) | 370 | if (NULL != cp->heap_cleanup_task) |
376 | { | 371 | { |
377 | GNUNET_SCHEDULER_cancel (cp->heap_cleanup_task); | 372 | GNUNET_SCHEDULER_cancel(cp->heap_cleanup_task); |
378 | cp->heap_cleanup_task = NULL; | 373 | cp->heap_cleanup_task = NULL; |
379 | } | 374 | } |
380 | GNUNET_free_non_null (cp->hello); | 375 | GNUNET_free_non_null(cp->hello); |
381 | /* Peer should not be freed if paths exist; if there are no paths, | 376 | /* Peer should not be freed if paths exist; if there are no paths, |
382 | there ought to be no connections, and without connections, no | 377 | there ought to be no connections, and without connections, no |
383 | notifications. Thus we can assert that mqm_head is empty at this | 378 | notifications. Thus we can assert that mqm_head is empty at this |
384 | point. */ | 379 | point. */ |
385 | GNUNET_assert (NULL == cp->mqm_head); | 380 | GNUNET_assert(NULL == cp->mqm_head); |
386 | GNUNET_assert (NULL == cp->mqm_ready_ptr); | 381 | GNUNET_assert(NULL == cp->mqm_ready_ptr); |
387 | GNUNET_free (cp); | 382 | GNUNET_free(cp); |
388 | } | 383 | } |
389 | 384 | ||
390 | 385 | ||
@@ -394,64 +389,64 @@ destroy_peer (void *cls) | |||
394 | * @param cp the more-active peer | 389 | * @param cp the more-active peer |
395 | */ | 390 | */ |
396 | static void | 391 | static void |
397 | consider_peer_activate (struct CadetPeer *cp) | 392 | consider_peer_activate(struct CadetPeer *cp) |
398 | { | 393 | { |
399 | uint32_t strength; | 394 | uint32_t strength; |
400 | 395 | ||
401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 396 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
402 | "Updating peer %s activation state (%u connections)%s%s\n", | 397 | "Updating peer %s activation state (%u connections)%s%s\n", |
403 | GCP_2s (cp), | 398 | GCP_2s(cp), |
404 | GNUNET_CONTAINER_multishortmap_size (cp->connections), | 399 | GNUNET_CONTAINER_multishortmap_size(cp->connections), |
405 | (NULL == cp->t) ? "" : " with tunnel", | 400 | (NULL == cp->t) ? "" : " with tunnel", |
406 | (NULL == cp->core_mq) ? "" : " with CORE link"); | 401 | (NULL == cp->core_mq) ? "" : " with CORE link"); |
407 | if (NULL != cp->destroy_task) | 402 | if (NULL != cp->destroy_task) |
408 | { | ||
409 | /* It's active, do not destory! */ | ||
410 | GNUNET_SCHEDULER_cancel (cp->destroy_task); | ||
411 | cp->destroy_task = NULL; | ||
412 | } | ||
413 | if ( (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)) && | ||
414 | (NULL == cp->t) ) | ||
415 | { | ||
416 | /* We're just on a path or directly connected; don't bother too much */ | ||
417 | if (NULL != cp->connectivity_suggestion) | ||
418 | { | 403 | { |
419 | GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); | 404 | /* It's active, do not destory! */ |
420 | cp->connectivity_suggestion = NULL; | 405 | GNUNET_SCHEDULER_cancel(cp->destroy_task); |
406 | cp->destroy_task = NULL; | ||
421 | } | 407 | } |
422 | if (NULL != cp->search_h) | 408 | if ((0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)) && |
409 | (NULL == cp->t)) | ||
423 | { | 410 | { |
424 | GCD_search_stop (cp->search_h); | 411 | /* We're just on a path or directly connected; don't bother too much */ |
425 | cp->search_h = NULL; | 412 | if (NULL != cp->connectivity_suggestion) |
413 | { | ||
414 | GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); | ||
415 | cp->connectivity_suggestion = NULL; | ||
416 | } | ||
417 | if (NULL != cp->search_h) | ||
418 | { | ||
419 | GCD_search_stop(cp->search_h); | ||
420 | cp->search_h = NULL; | ||
421 | } | ||
422 | return; | ||
426 | } | 423 | } |
427 | return; | ||
428 | } | ||
429 | if (NULL == cp->core_mq) | 424 | if (NULL == cp->core_mq) |
430 | { | 425 | { |
431 | /* Lacks direct connection, try to create one by querying the DHT */ | 426 | /* Lacks direct connection, try to create one by querying the DHT */ |
432 | if ( (NULL == cp->search_h) && | 427 | if ((NULL == cp->search_h) && |
433 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) ) | 428 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) |
434 | cp->search_h | 429 | cp->search_h |
435 | = GCD_search (&cp->pid); | 430 | = GCD_search(&cp->pid); |
436 | } | 431 | } |
437 | else | 432 | else |
438 | { | ||
439 | /* Have direct connection, stop DHT search if active */ | ||
440 | if (NULL != cp->search_h) | ||
441 | { | 433 | { |
442 | GCD_search_stop (cp->search_h); | 434 | /* Have direct connection, stop DHT search if active */ |
443 | cp->search_h = NULL; | 435 | if (NULL != cp->search_h) |
436 | { | ||
437 | GCD_search_stop(cp->search_h); | ||
438 | cp->search_h = NULL; | ||
439 | } | ||
444 | } | 440 | } |
445 | } | ||
446 | 441 | ||
447 | /* If we have a tunnel, our urge for connections is much bigger */ | 442 | /* If we have a tunnel, our urge for connections is much bigger */ |
448 | strength = (NULL != cp->t) ? 32 : 1; | 443 | strength = (NULL != cp->t) ? 32 : 1; |
449 | if (NULL != cp->connectivity_suggestion) | 444 | if (NULL != cp->connectivity_suggestion) |
450 | GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion); | 445 | GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion); |
451 | cp->connectivity_suggestion | 446 | cp->connectivity_suggestion |
452 | = GNUNET_ATS_connectivity_suggest (ats_ch, | 447 | = GNUNET_ATS_connectivity_suggest(ats_ch, |
453 | &cp->pid, | 448 | &cp->pid, |
454 | strength); | 449 | strength); |
455 | } | 450 | } |
456 | 451 | ||
457 | 452 | ||
@@ -461,7 +456,7 @@ consider_peer_activate (struct CadetPeer *cp) | |||
461 | * @param cp peer to clean up | 456 | * @param cp peer to clean up |
462 | */ | 457 | */ |
463 | static void | 458 | static void |
464 | consider_peer_destroy (struct CadetPeer *cp); | 459 | consider_peer_destroy(struct CadetPeer *cp); |
465 | 460 | ||
466 | 461 | ||
467 | /** | 462 | /** |
@@ -471,15 +466,15 @@ consider_peer_destroy (struct CadetPeer *cp); | |||
471 | * @param cls a `struct CadetPeer`. | 466 | * @param cls a `struct CadetPeer`. |
472 | */ | 467 | */ |
473 | static void | 468 | static void |
474 | drop_paths (void *cls) | 469 | drop_paths(void *cls) |
475 | { | 470 | { |
476 | struct CadetPeer *cp = cls; | 471 | struct CadetPeer *cp = cls; |
477 | struct CadetPeerPath *path; | 472 | struct CadetPeerPath *path; |
478 | 473 | ||
479 | cp->destroy_task = NULL; | 474 | cp->destroy_task = NULL; |
480 | while (NULL != (path = GNUNET_CONTAINER_heap_remove_root (cp->path_heap))) | 475 | while (NULL != (path = GNUNET_CONTAINER_heap_remove_root(cp->path_heap))) |
481 | GCPP_release (path); | 476 | GCPP_release(path); |
482 | consider_peer_destroy (cp); | 477 | consider_peer_destroy(cp); |
483 | } | 478 | } |
484 | 479 | ||
485 | 480 | ||
@@ -489,43 +484,43 @@ drop_paths (void *cls) | |||
489 | * @param cp peer to clean up | 484 | * @param cp peer to clean up |
490 | */ | 485 | */ |
491 | static void | 486 | static void |
492 | consider_peer_destroy (struct CadetPeer *cp) | 487 | consider_peer_destroy(struct CadetPeer *cp) |
493 | { | 488 | { |
494 | struct GNUNET_TIME_Relative exp; | 489 | struct GNUNET_TIME_Relative exp; |
495 | 490 | ||
496 | if (NULL != cp->destroy_task) | 491 | if (NULL != cp->destroy_task) |
497 | { | 492 | { |
498 | GNUNET_SCHEDULER_cancel (cp->destroy_task); | 493 | GNUNET_SCHEDULER_cancel(cp->destroy_task); |
499 | cp->destroy_task = NULL; | 494 | cp->destroy_task = NULL; |
500 | } | 495 | } |
501 | if (NULL != cp->t) | 496 | if (NULL != cp->t) |
502 | return; /* still relevant! */ | 497 | return; /* still relevant! */ |
503 | if (NULL != cp->core_mq) | 498 | if (NULL != cp->core_mq) |
504 | return; /* still relevant! */ | 499 | return; /* still relevant! */ |
505 | if (0 != GNUNET_CONTAINER_multishortmap_size (cp->connections)) | 500 | if (0 != GNUNET_CONTAINER_multishortmap_size(cp->connections)) |
506 | return; /* still relevant! */ | 501 | return; /* still relevant! */ |
507 | if ( (NULL != cp->path_heap) && | 502 | if ((NULL != cp->path_heap) && |
508 | (0 < GNUNET_CONTAINER_heap_get_size (cp->path_heap)) ) | 503 | (0 < GNUNET_CONTAINER_heap_get_size(cp->path_heap))) |
509 | { | 504 | { |
510 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PATH_TIMEOUT, | 505 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PATH_TIMEOUT, |
511 | &drop_paths, | 506 | &drop_paths, |
512 | cp); | 507 | cp); |
513 | return; | 508 | return; |
514 | } | 509 | } |
515 | if (0 != cp->num_paths) | 510 | if (0 != cp->num_paths) |
516 | return; /* still relevant! */ | 511 | return; /* still relevant! */ |
517 | if (NULL != cp->hello) | 512 | if (NULL != cp->hello) |
518 | { | 513 | { |
519 | /* relevant only until HELLO expires */ | 514 | /* relevant only until HELLO expires */ |
520 | exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration (cp->hello)); | 515 | exp = GNUNET_TIME_absolute_get_remaining(GNUNET_HELLO_get_last_expiration(cp->hello)); |
521 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp, | 516 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed(exp, |
522 | &destroy_peer, | 517 | &destroy_peer, |
523 | cp); | 518 | cp); |
524 | return; | 519 | return; |
525 | } | 520 | } |
526 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT, | 521 | cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PEER_TIMEOUT, |
527 | &destroy_peer, | 522 | &destroy_peer, |
528 | cp); | 523 | cp); |
529 | } | 524 | } |
530 | 525 | ||
531 | 526 | ||
@@ -536,60 +531,60 @@ consider_peer_destroy (struct CadetPeer *cp) | |||
536 | * @param mq message queue to set (can be NULL) | 531 | * @param mq message queue to set (can be NULL) |
537 | */ | 532 | */ |
538 | void | 533 | void |
539 | GCP_set_mq (struct CadetPeer *cp, | 534 | GCP_set_mq(struct CadetPeer *cp, |
540 | struct GNUNET_MQ_Handle *mq) | 535 | struct GNUNET_MQ_Handle *mq) |
541 | { | 536 | { |
542 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 537 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
543 | "Message queue for peer %s is now %p\n", | 538 | "Message queue for peer %s is now %p\n", |
544 | GCP_2s (cp), | 539 | GCP_2s(cp), |
545 | mq); | 540 | mq); |
546 | cp->core_mq = mq; | 541 | cp->core_mq = mq; |
547 | for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next; | 542 | for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next; |
548 | NULL != mqm; | 543 | NULL != mqm; |
549 | mqm = next) | 544 | mqm = next) |
550 | { | ||
551 | /* Save next pointer in case mqm gets freed by the callback */ | ||
552 | next = mqm->next; | ||
553 | if (NULL == mq) | ||
554 | { | 545 | { |
555 | if (NULL != mqm->env) | 546 | /* Save next pointer in case mqm gets freed by the callback */ |
556 | { | 547 | next = mqm->next; |
557 | GNUNET_MQ_discard (mqm->env); | 548 | if (NULL == mq) |
558 | mqm->env = NULL; | 549 | { |
559 | mqm->cb (mqm->cb_cls, | 550 | if (NULL != mqm->env) |
560 | GNUNET_SYSERR); | 551 | { |
561 | } | 552 | GNUNET_MQ_discard(mqm->env); |
553 | mqm->env = NULL; | ||
554 | mqm->cb(mqm->cb_cls, | ||
555 | GNUNET_SYSERR); | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | mqm->cb(mqm->cb_cls, | ||
560 | GNUNET_NO); | ||
561 | } | ||
562 | } | ||
562 | else | 563 | else |
563 | { | 564 | { |
564 | mqm->cb (mqm->cb_cls, | 565 | GNUNET_assert(NULL == mqm->env); |
565 | GNUNET_NO); | 566 | mqm->cb(mqm->cb_cls, |
566 | } | 567 | GNUNET_YES); |
568 | } | ||
567 | } | 569 | } |
568 | else | 570 | if ((NULL != mq) || |
571 | (NULL != cp->t)) | ||
572 | consider_peer_activate(cp); | ||
573 | else | ||
574 | consider_peer_destroy(cp); | ||
575 | |||
576 | if ((NULL != mq) && | ||
577 | (NULL != cp->t)) | ||
569 | { | 578 | { |
570 | GNUNET_assert (NULL == mqm->env); | 579 | /* have a new, direct path to the target, notify tunnel */ |
571 | mqm->cb (mqm->cb_cls, | 580 | struct CadetPeerPath *path; |
572 | GNUNET_YES); | 581 | |
582 | path = GCPP_get_path_from_route(1, | ||
583 | &cp->pid); | ||
584 | GCT_consider_path(cp->t, | ||
585 | path, | ||
586 | 0); | ||
573 | } | 587 | } |
574 | } | ||
575 | if ( (NULL != mq) || | ||
576 | (NULL != cp->t) ) | ||
577 | consider_peer_activate (cp); | ||
578 | else | ||
579 | consider_peer_destroy (cp); | ||
580 | |||
581 | if ( (NULL != mq) && | ||
582 | (NULL != cp->t) ) | ||
583 | { | ||
584 | /* have a new, direct path to the target, notify tunnel */ | ||
585 | struct CadetPeerPath *path; | ||
586 | |||
587 | path = GCPP_get_path_from_route (1, | ||
588 | &cp->pid); | ||
589 | GCT_consider_path (cp->t, | ||
590 | path, | ||
591 | 0); | ||
592 | } | ||
593 | } | 588 | } |
594 | 589 | ||
595 | 590 | ||
@@ -600,12 +595,12 @@ GCP_set_mq (struct CadetPeer *cp, | |||
600 | * @return #GNUNET_YES or #GNUNET_NO with the decision to drop. | 595 | * @return #GNUNET_YES or #GNUNET_NO with the decision to drop. |
601 | */ | 596 | */ |
602 | static int | 597 | static int |
603 | should_I_drop (void) | 598 | should_I_drop(void) |
604 | { | 599 | { |
605 | if (0 == drop_percent) | 600 | if (0 == drop_percent) |
606 | return GNUNET_NO; | 601 | return GNUNET_NO; |
607 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 602 | if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
608 | 101) < drop_percent) | 603 | 101) < drop_percent) |
609 | return GNUNET_YES; | 604 | return GNUNET_YES; |
610 | return GNUNET_NO; | 605 | return GNUNET_NO; |
611 | } | 606 | } |
@@ -618,7 +613,7 @@ should_I_drop (void) | |||
618 | * @param cls the `struct CadetPeeer` where we made progress | 613 | * @param cls the `struct CadetPeeer` where we made progress |
619 | */ | 614 | */ |
620 | static void | 615 | static void |
621 | mqm_send_done (void *cls); | 616 | mqm_send_done(void *cls); |
622 | 617 | ||
623 | 618 | ||
624 | /** | 619 | /** |
@@ -627,68 +622,69 @@ mqm_send_done (void *cls); | |||
627 | * @param mqm mqm to transmit message for now | 622 | * @param mqm mqm to transmit message for now |
628 | */ | 623 | */ |
629 | static void | 624 | static void |
630 | mqm_execute (struct GCP_MessageQueueManager *mqm) | 625 | mqm_execute(struct GCP_MessageQueueManager *mqm) |
631 | { | 626 | { |
632 | struct CadetPeer *cp = mqm->cp; | 627 | struct CadetPeer *cp = mqm->cp; |
633 | 628 | ||
634 | /* Move ready pointer to the next entry that might be ready. */ | 629 | /* Move ready pointer to the next entry that might be ready. */ |
635 | if ( (mqm == cp->mqm_ready_ptr) && | 630 | if ((mqm == cp->mqm_ready_ptr) && |
636 | (NULL != mqm->next) ) | 631 | (NULL != mqm->next)) |
637 | cp->mqm_ready_ptr = mqm->next; | 632 | cp->mqm_ready_ptr = mqm->next; |
638 | /* Move entry to the end of the DLL, to be fair. */ | 633 | /* Move entry to the end of the DLL, to be fair. */ |
639 | if (mqm != cp->mqm_tail) | 634 | if (mqm != cp->mqm_tail) |
640 | { | 635 | { |
641 | GNUNET_CONTAINER_DLL_remove (cp->mqm_head, | 636 | GNUNET_CONTAINER_DLL_remove(cp->mqm_head, |
642 | cp->mqm_tail, | 637 | cp->mqm_tail, |
643 | mqm); | 638 | mqm); |
644 | GNUNET_CONTAINER_DLL_insert_tail (cp->mqm_head, | 639 | GNUNET_CONTAINER_DLL_insert_tail(cp->mqm_head, |
645 | cp->mqm_tail, | 640 | cp->mqm_tail, |
646 | mqm); | 641 | mqm); |
647 | } | 642 | } |
648 | cp->mqm_ready_counter--; | 643 | cp->mqm_ready_counter--; |
649 | if (GNUNET_YES == should_I_drop ()) | 644 | if (GNUNET_YES == should_I_drop()) |
650 | { | 645 | { |
651 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 646 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
652 | "DROPPING message to peer %s from MQM %p\n", | 647 | "DROPPING message to peer %s from MQM %p\n", |
653 | GCP_2s (cp), | 648 | GCP_2s(cp), |
654 | mqm); | 649 | mqm); |
655 | GNUNET_MQ_discard (mqm->env); | 650 | GNUNET_MQ_discard(mqm->env); |
656 | mqm->env = NULL; | 651 | mqm->env = NULL; |
657 | mqm_send_done (cp); | 652 | mqm_send_done(cp); |
658 | } | 653 | } |
659 | else | 654 | else |
660 | { | ||
661 | { | 655 | { |
662 | const struct GNUNET_MessageHeader *mh; | ||
663 | |||
664 | mh = GNUNET_MQ_env_get_msg (mqm->env); | ||
665 | switch (ntohs (mh->type)) | ||
666 | { | 656 | { |
667 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: | 657 | const struct GNUNET_MessageHeader *mh; |
668 | { | 658 | |
669 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg | 659 | mh = GNUNET_MQ_env_get_msg(mqm->env); |
670 | = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *) mh; | 660 | switch (ntohs(mh->type)) |
671 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 661 | { |
672 | "P2P forwarding KX with ephemeral %s to %s on CID %s\n", | 662 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: |
673 | GNUNET_e2s (&msg->ephemeral_key), | 663 | { |
674 | GCP_2s (cp), | 664 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg |
675 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | 665 | = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *)mh; |
676 | } | 666 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
677 | break; | 667 | "P2P forwarding KX with ephemeral %s to %s on CID %s\n", |
678 | default: | 668 | GNUNET_e2s(&msg->ephemeral_key), |
679 | break; | 669 | GCP_2s(cp), |
670 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | ||
671 | } | ||
672 | break; | ||
673 | |||
674 | default: | ||
675 | break; | ||
676 | } | ||
680 | } | 677 | } |
678 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
679 | "Sending to peer %s from MQM %p\n", | ||
680 | GCP_2s(cp), | ||
681 | mqm); | ||
682 | GNUNET_MQ_send(cp->core_mq, | ||
683 | mqm->env); | ||
684 | mqm->env = NULL; | ||
681 | } | 685 | } |
682 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 686 | mqm->cb(mqm->cb_cls, |
683 | "Sending to peer %s from MQM %p\n", | 687 | GNUNET_YES); |
684 | GCP_2s (cp), | ||
685 | mqm); | ||
686 | GNUNET_MQ_send (cp->core_mq, | ||
687 | mqm->env); | ||
688 | mqm->env = NULL; | ||
689 | } | ||
690 | mqm->cb (mqm->cb_cls, | ||
691 | GNUNET_YES); | ||
692 | } | 688 | } |
693 | 689 | ||
694 | 690 | ||
@@ -700,18 +696,18 @@ mqm_execute (struct GCP_MessageQueueManager *mqm) | |||
700 | * @param cp peer to try to send the next ready message to | 696 | * @param cp peer to try to send the next ready message to |
701 | */ | 697 | */ |
702 | static void | 698 | static void |
703 | send_next_ready (struct CadetPeer *cp) | 699 | send_next_ready(struct CadetPeer *cp) |
704 | { | 700 | { |
705 | struct GCP_MessageQueueManager *mqm; | 701 | struct GCP_MessageQueueManager *mqm; |
706 | 702 | ||
707 | if (0 == cp->mqm_ready_counter) | 703 | if (0 == cp->mqm_ready_counter) |
708 | return; | 704 | return; |
709 | while ( (NULL != (mqm = cp->mqm_ready_ptr)) && | 705 | while ((NULL != (mqm = cp->mqm_ready_ptr)) && |
710 | (NULL == mqm->env) ) | 706 | (NULL == mqm->env)) |
711 | cp->mqm_ready_ptr = mqm->next; | 707 | cp->mqm_ready_ptr = mqm->next; |
712 | if (NULL == mqm) | 708 | if (NULL == mqm) |
713 | return; /* nothing to do */ | 709 | return; /* nothing to do */ |
714 | mqm_execute (mqm); | 710 | mqm_execute(mqm); |
715 | } | 711 | } |
716 | 712 | ||
717 | 713 | ||
@@ -722,14 +718,14 @@ send_next_ready (struct CadetPeer *cp) | |||
722 | * @param cls the `struct CadetPeeer` where we made progress | 718 | * @param cls the `struct CadetPeeer` where we made progress |
723 | */ | 719 | */ |
724 | static void | 720 | static void |
725 | mqm_send_done (void *cls) | 721 | mqm_send_done(void *cls) |
726 | { | 722 | { |
727 | struct CadetPeer *cp = cls; | 723 | struct CadetPeer *cp = cls; |
728 | 724 | ||
729 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 725 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
730 | "Sending to peer %s completed\n", | 726 | "Sending to peer %s completed\n", |
731 | GCP_2s (cp)); | 727 | GCP_2s(cp)); |
732 | send_next_ready (cp); | 728 | send_next_ready(cp); |
733 | } | 729 | } |
734 | 730 | ||
735 | 731 | ||
@@ -741,30 +737,30 @@ mqm_send_done (void *cls) | |||
741 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it | 737 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it |
742 | */ | 738 | */ |
743 | void | 739 | void |
744 | GCP_send (struct GCP_MessageQueueManager *mqm, | 740 | GCP_send(struct GCP_MessageQueueManager *mqm, |
745 | struct GNUNET_MQ_Envelope *env) | 741 | struct GNUNET_MQ_Envelope *env) |
746 | { | 742 | { |
747 | struct CadetPeer *cp = mqm->cp; | 743 | struct CadetPeer *cp = mqm->cp; |
748 | 744 | ||
749 | GNUNET_assert (NULL != env); | 745 | GNUNET_assert(NULL != env); |
750 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 746 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
751 | "Queueing message to peer %s in MQM %p\n", | 747 | "Queueing message to peer %s in MQM %p\n", |
752 | GCP_2s (cp), | 748 | GCP_2s(cp), |
753 | mqm); | 749 | mqm); |
754 | GNUNET_assert (NULL != cp->core_mq); | 750 | GNUNET_assert(NULL != cp->core_mq); |
755 | GNUNET_assert (NULL == mqm->env); | 751 | GNUNET_assert(NULL == mqm->env); |
756 | GNUNET_MQ_notify_sent (env, | 752 | GNUNET_MQ_notify_sent(env, |
757 | &mqm_send_done, | 753 | &mqm_send_done, |
758 | cp); | 754 | cp); |
759 | mqm->env = env; | 755 | mqm->env = env; |
760 | cp->mqm_ready_counter++; | 756 | cp->mqm_ready_counter++; |
761 | if (mqm != cp->mqm_ready_ptr) | 757 | if (mqm != cp->mqm_ready_ptr) |
762 | cp->mqm_ready_ptr = cp->mqm_head; | 758 | cp->mqm_ready_ptr = cp->mqm_head; |
763 | if (1 == cp->mqm_ready_counter) | 759 | if (1 == cp->mqm_ready_counter) |
764 | cp->mqm_ready_ptr = mqm; | 760 | cp->mqm_ready_ptr = mqm; |
765 | if (0 != GNUNET_MQ_get_length (cp->core_mq)) | 761 | if (0 != GNUNET_MQ_get_length(cp->core_mq)) |
766 | return; | 762 | return; |
767 | send_next_ready (cp); | 763 | send_next_ready(cp); |
768 | } | 764 | } |
769 | 765 | ||
770 | 766 | ||
@@ -777,18 +773,18 @@ GCP_send (struct GCP_MessageQueueManager *mqm, | |||
777 | * @return #GNUNET_OK (continue to iterate) | 773 | * @return #GNUNET_OK (continue to iterate) |
778 | */ | 774 | */ |
779 | static int | 775 | static int |
780 | destroy_iterator_cb (void *cls, | 776 | destroy_iterator_cb(void *cls, |
781 | const struct GNUNET_PeerIdentity *pid, | 777 | const struct GNUNET_PeerIdentity *pid, |
782 | void *value) | 778 | void *value) |
783 | { | 779 | { |
784 | struct CadetPeer *cp = value; | 780 | struct CadetPeer *cp = value; |
785 | 781 | ||
786 | if (NULL != cp->destroy_task) | 782 | if (NULL != cp->destroy_task) |
787 | { | 783 | { |
788 | GNUNET_SCHEDULER_cancel (cp->destroy_task); | 784 | GNUNET_SCHEDULER_cancel(cp->destroy_task); |
789 | cp->destroy_task = NULL; | 785 | cp->destroy_task = NULL; |
790 | } | 786 | } |
791 | destroy_peer (cp); | 787 | destroy_peer(cp); |
792 | return GNUNET_OK; | 788 | return GNUNET_OK; |
793 | } | 789 | } |
794 | 790 | ||
@@ -799,13 +795,13 @@ destroy_iterator_cb (void *cls, | |||
799 | * connections are down. | 795 | * connections are down. |
800 | */ | 796 | */ |
801 | void | 797 | void |
802 | GCP_destroy_all_peers () | 798 | GCP_destroy_all_peers() |
803 | { | 799 | { |
804 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 800 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
805 | "Destroying all peers now\n"); | 801 | "Destroying all peers now\n"); |
806 | GNUNET_CONTAINER_multipeermap_iterate (peers, | 802 | GNUNET_CONTAINER_multipeermap_iterate(peers, |
807 | &destroy_iterator_cb, | 803 | &destroy_iterator_cb, |
808 | NULL); | 804 | NULL); |
809 | } | 805 | } |
810 | 806 | ||
811 | 807 | ||
@@ -816,17 +812,17 @@ GCP_destroy_all_peers () | |||
816 | * @param cp peer to drop paths to | 812 | * @param cp peer to drop paths to |
817 | */ | 813 | */ |
818 | void | 814 | void |
819 | GCP_drop_owned_paths (struct CadetPeer *cp) | 815 | GCP_drop_owned_paths(struct CadetPeer *cp) |
820 | { | 816 | { |
821 | struct CadetPeerPath *path; | 817 | struct CadetPeerPath *path; |
822 | 818 | ||
823 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 819 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
824 | "Destroying all paths to %s\n", | 820 | "Destroying all paths to %s\n", |
825 | GCP_2s (cp)); | 821 | GCP_2s(cp)); |
826 | while (NULL != (path = | 822 | while (NULL != (path = |
827 | GNUNET_CONTAINER_heap_remove_root (cp->path_heap))) | 823 | GNUNET_CONTAINER_heap_remove_root(cp->path_heap))) |
828 | GCPP_release (path); | 824 | GCPP_release(path); |
829 | GNUNET_CONTAINER_heap_destroy (cp->path_heap); | 825 | GNUNET_CONTAINER_heap_destroy(cp->path_heap); |
830 | cp->path_heap = NULL; | 826 | cp->path_heap = NULL; |
831 | } | 827 | } |
832 | 828 | ||
@@ -839,55 +835,55 @@ GCP_drop_owned_paths (struct CadetPeer *cp) | |||
839 | * @param off offset of this peer on the path | 835 | * @param off offset of this peer on the path |
840 | */ | 836 | */ |
841 | void | 837 | void |
842 | GCP_path_entry_add (struct CadetPeer *cp, | 838 | GCP_path_entry_add(struct CadetPeer *cp, |
843 | struct CadetPeerPathEntry *entry, | 839 | struct CadetPeerPathEntry *entry, |
844 | unsigned int off) | 840 | unsigned int off) |
845 | { | 841 | { |
846 | GNUNET_assert (cp == GCPP_get_peer_at_offset (entry->path, | 842 | GNUNET_assert(cp == GCPP_get_peer_at_offset(entry->path, |
847 | off)); | 843 | off)); |
848 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 844 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
849 | "Discovered that peer %s is on path %s at offset %u\n", | 845 | "Discovered that peer %s is on path %s at offset %u\n", |
850 | GCP_2s (cp), | 846 | GCP_2s(cp), |
851 | GCPP_2s (entry->path), | 847 | GCPP_2s(entry->path), |
852 | off); | 848 | off); |
853 | if (off >= cp->path_dll_length) | 849 | if (off >= cp->path_dll_length) |
854 | { | 850 | { |
855 | unsigned int len = cp->path_dll_length; | 851 | unsigned int len = cp->path_dll_length; |
856 | 852 | ||
857 | GNUNET_array_grow (cp->path_heads, | 853 | GNUNET_array_grow(cp->path_heads, |
858 | len, | 854 | len, |
859 | off + 4); | 855 | off + 4); |
860 | GNUNET_array_grow (cp->path_tails, | 856 | GNUNET_array_grow(cp->path_tails, |
861 | cp->path_dll_length, | 857 | cp->path_dll_length, |
862 | off + 4); | 858 | off + 4); |
863 | } | 859 | } |
864 | GNUNET_CONTAINER_DLL_insert (cp->path_heads[off], | 860 | GNUNET_CONTAINER_DLL_insert(cp->path_heads[off], |
865 | cp->path_tails[off], | 861 | cp->path_tails[off], |
866 | entry); | 862 | entry); |
867 | cp->off_sum += off; | 863 | cp->off_sum += off; |
868 | cp->num_paths++; | 864 | cp->num_paths++; |
869 | 865 | ||
870 | /* If we have a tunnel to this peer, tell the tunnel that there is a | 866 | /* If we have a tunnel to this peer, tell the tunnel that there is a |
871 | new path available. */ | 867 | new path available. */ |
872 | if (NULL != cp->t) | 868 | if (NULL != cp->t) |
873 | GCT_consider_path (cp->t, | 869 | GCT_consider_path(cp->t, |
874 | entry->path, | 870 | entry->path, |
875 | off); | 871 | off); |
876 | 872 | ||
877 | if ( (NULL != cp->search_h) && | 873 | if ((NULL != cp->search_h) && |
878 | (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths) ) | 874 | (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths)) |
879 | { | 875 | { |
880 | /* Now I have enough paths, stop search */ | 876 | /* Now I have enough paths, stop search */ |
881 | GCD_search_stop (cp->search_h); | 877 | GCD_search_stop(cp->search_h); |
882 | cp->search_h = NULL; | 878 | cp->search_h = NULL; |
883 | } | 879 | } |
884 | if (NULL != cp->destroy_task) | 880 | if (NULL != cp->destroy_task) |
885 | { | 881 | { |
886 | /* paths changed, this resets the destroy timeout counter | 882 | /* paths changed, this resets the destroy timeout counter |
887 | and aborts a destroy task that may no longer be valid | 883 | and aborts a destroy task that may no longer be valid |
888 | to have (as we now have more paths via this peer). */ | 884 | to have (as we now have more paths via this peer). */ |
889 | consider_peer_destroy (cp); | 885 | consider_peer_destroy(cp); |
890 | } | 886 | } |
891 | } | 887 | } |
892 | 888 | ||
893 | 889 | ||
@@ -899,32 +895,32 @@ GCP_path_entry_add (struct CadetPeer *cp, | |||
899 | * @param off offset of this peer on the path | 895 | * @param off offset of this peer on the path |
900 | */ | 896 | */ |
901 | void | 897 | void |
902 | GCP_path_entry_remove (struct CadetPeer *cp, | 898 | GCP_path_entry_remove(struct CadetPeer *cp, |
903 | struct CadetPeerPathEntry *entry, | 899 | struct CadetPeerPathEntry *entry, |
904 | unsigned int off) | 900 | unsigned int off) |
905 | { | 901 | { |
906 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 902 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
907 | "Removing knowledge about peer %s beging on path %s at offset %u\n", | 903 | "Removing knowledge about peer %s beging on path %s at offset %u\n", |
908 | GCP_2s (cp), | 904 | GCP_2s(cp), |
909 | GCPP_2s (entry->path), | 905 | GCPP_2s(entry->path), |
910 | off); | 906 | off); |
911 | GNUNET_CONTAINER_DLL_remove (cp->path_heads[off], | 907 | GNUNET_CONTAINER_DLL_remove(cp->path_heads[off], |
912 | cp->path_tails[off], | 908 | cp->path_tails[off], |
913 | entry); | 909 | entry); |
914 | GNUNET_assert (0 < cp->num_paths); | 910 | GNUNET_assert(0 < cp->num_paths); |
915 | cp->off_sum -= off; | 911 | cp->off_sum -= off; |
916 | cp->num_paths--; | 912 | cp->num_paths--; |
917 | if ( (NULL == cp->core_mq) && | 913 | if ((NULL == cp->core_mq) && |
918 | (NULL != cp->t) && | 914 | (NULL != cp->t) && |
919 | (NULL == cp->search_h) && | 915 | (NULL == cp->search_h) && |
920 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) ) | 916 | (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths)) |
921 | cp->search_h | 917 | cp->search_h |
922 | = GCD_search (&cp->pid); | 918 | = GCD_search(&cp->pid); |
923 | if (NULL == cp->destroy_task) | 919 | if (NULL == cp->destroy_task) |
924 | { | 920 | { |
925 | /* paths changed, we might now be ready for destruction, check again */ | 921 | /* paths changed, we might now be ready for destruction, check again */ |
926 | consider_peer_destroy (cp); | 922 | consider_peer_destroy(cp); |
927 | } | 923 | } |
928 | } | 924 | } |
929 | 925 | ||
930 | 926 | ||
@@ -935,32 +931,32 @@ GCP_path_entry_remove (struct CadetPeer *cp, | |||
935 | * @param cls the `struct CadetPeer` to maintain the path heap for | 931 | * @param cls the `struct CadetPeer` to maintain the path heap for |
936 | */ | 932 | */ |
937 | static void | 933 | static void |
938 | path_heap_cleanup (void *cls) | 934 | path_heap_cleanup(void *cls) |
939 | { | 935 | { |
940 | struct CadetPeer *cp = cls; | 936 | struct CadetPeer *cp = cls; |
941 | struct CadetPeerPath *root; | 937 | struct CadetPeerPath *root; |
942 | 938 | ||
943 | cp->heap_cleanup_task = NULL; | 939 | cp->heap_cleanup_task = NULL; |
944 | while (GNUNET_CONTAINER_heap_get_size (cp->path_heap) >= | 940 | while (GNUNET_CONTAINER_heap_get_size(cp->path_heap) >= |
945 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) | 941 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) |
946 | { | 942 | { |
947 | /* Now we have way too many, drop least desirable UNLESS it is in use! | 943 | /* Now we have way too many, drop least desirable UNLESS it is in use! |
948 | (Note that this intentionally keeps highly desireable, but currently | 944 | (Note that this intentionally keeps highly desireable, but currently |
949 | unused paths around in the hope that we might be able to switch, even | 945 | unused paths around in the hope that we might be able to switch, even |
950 | if the number of paths exceeds the threshold.) */ | 946 | if the number of paths exceeds the threshold.) */ |
951 | root = GNUNET_CONTAINER_heap_peek (cp->path_heap); | 947 | root = GNUNET_CONTAINER_heap_peek(cp->path_heap); |
952 | GNUNET_assert (NULL != root); | 948 | GNUNET_assert(NULL != root); |
953 | if (NULL != | 949 | if (NULL != |
954 | GCPP_get_connection (root, | 950 | GCPP_get_connection(root, |
955 | cp, | 951 | cp, |
956 | GCPP_get_length (root) - 1)) | 952 | GCPP_get_length(root) - 1)) |
957 | break; /* can't fix */ | 953 | break; /* can't fix */ |
958 | /* Got plenty of paths to this destination, and this is a low-quality | 954 | /* Got plenty of paths to this destination, and this is a low-quality |
959 | one that we don't care about. Allow it to die. */ | 955 | one that we don't care about. Allow it to die. */ |
960 | GNUNET_assert (root == | 956 | GNUNET_assert(root == |
961 | GNUNET_CONTAINER_heap_remove_root (cp->path_heap)); | 957 | GNUNET_CONTAINER_heap_remove_root(cp->path_heap)); |
962 | GCPP_release (root); | 958 | GCPP_release(root); |
963 | } | 959 | } |
964 | } | 960 | } |
965 | 961 | ||
966 | 962 | ||
@@ -976,66 +972,66 @@ path_heap_cleanup (void *cls) | |||
976 | * otherwise the node in the peer's path heap for the @a path. | 972 | * otherwise the node in the peer's path heap for the @a path. |
977 | */ | 973 | */ |
978 | struct GNUNET_CONTAINER_HeapNode * | 974 | struct GNUNET_CONTAINER_HeapNode * |
979 | GCP_attach_path (struct CadetPeer *cp, | 975 | GCP_attach_path(struct CadetPeer *cp, |
980 | struct CadetPeerPath *path, | 976 | struct CadetPeerPath *path, |
981 | unsigned int off, | 977 | unsigned int off, |
982 | int force) | 978 | int force) |
983 | { | 979 | { |
984 | GNUNET_CONTAINER_HeapCostType desirability; | 980 | GNUNET_CONTAINER_HeapCostType desirability; |
985 | struct CadetPeerPath *root; | 981 | struct CadetPeerPath *root; |
986 | GNUNET_CONTAINER_HeapCostType root_desirability; | 982 | GNUNET_CONTAINER_HeapCostType root_desirability; |
987 | struct GNUNET_CONTAINER_HeapNode *hn; | 983 | struct GNUNET_CONTAINER_HeapNode *hn; |
988 | 984 | ||
989 | GNUNET_assert (off == GCPP_get_length (path) - 1); | 985 | GNUNET_assert(off == GCPP_get_length(path) - 1); |
990 | GNUNET_assert (cp == GCPP_get_peer_at_offset (path, | 986 | GNUNET_assert(cp == GCPP_get_peer_at_offset(path, |
991 | off)); | 987 | off)); |
992 | if (NULL == cp->path_heap) | 988 | if (NULL == cp->path_heap) |
993 | { | ||
994 | /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */ | ||
995 | GNUNET_assert (GNUNET_NO == force); | ||
996 | return NULL; | ||
997 | } | ||
998 | desirability = GCPP_get_desirability (path); | ||
999 | if (GNUNET_NO == force) | ||
1000 | { | ||
1001 | /* FIXME: desirability is not yet initialized; tricky! */ | ||
1002 | if (GNUNET_NO == | ||
1003 | GNUNET_CONTAINER_heap_peek2 (cp->path_heap, | ||
1004 | (void **) &root, | ||
1005 | &root_desirability)) | ||
1006 | { | 989 | { |
1007 | root = NULL; | 990 | /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */ |
1008 | root_desirability = 0; | 991 | GNUNET_assert(GNUNET_NO == force); |
992 | return NULL; | ||
1009 | } | 993 | } |
1010 | 994 | desirability = GCPP_get_desirability(path); | |
1011 | if ( (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) && | 995 | if (GNUNET_NO == force) |
1012 | (desirability < root_desirability) ) | ||
1013 | { | 996 | { |
1014 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 997 | /* FIXME: desirability is not yet initialized; tricky! */ |
1015 | "Decided to not attach path %s to peer %s due to undesirability\n", | 998 | if (GNUNET_NO == |
1016 | GCPP_2s (path), | 999 | GNUNET_CONTAINER_heap_peek2(cp->path_heap, |
1017 | GCP_2s (cp)); | 1000 | (void **)&root, |
1018 | return NULL; | 1001 | &root_desirability)) |
1002 | { | ||
1003 | root = NULL; | ||
1004 | root_desirability = 0; | ||
1005 | } | ||
1006 | |||
1007 | if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) && | ||
1008 | (desirability < root_desirability)) | ||
1009 | { | ||
1010 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1011 | "Decided to not attach path %s to peer %s due to undesirability\n", | ||
1012 | GCPP_2s(path), | ||
1013 | GCP_2s(cp)); | ||
1014 | return NULL; | ||
1015 | } | ||
1019 | } | 1016 | } |
1020 | } | ||
1021 | 1017 | ||
1022 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1018 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1023 | "Attaching path %s to peer %s (%s)\n", | 1019 | "Attaching path %s to peer %s (%s)\n", |
1024 | GCPP_2s (path), | 1020 | GCPP_2s(path), |
1025 | GCP_2s (cp), | 1021 | GCP_2s(cp), |
1026 | (GNUNET_NO == force) ? "desirable" : "forced"); | 1022 | (GNUNET_NO == force) ? "desirable" : "forced"); |
1027 | 1023 | ||
1028 | /* Yes, we'd like to add this path, add to our heap */ | 1024 | /* Yes, we'd like to add this path, add to our heap */ |
1029 | hn = GNUNET_CONTAINER_heap_insert (cp->path_heap, | 1025 | hn = GNUNET_CONTAINER_heap_insert(cp->path_heap, |
1030 | path, | 1026 | path, |
1031 | desirability); | 1027 | desirability); |
1032 | 1028 | ||
1033 | /* Consider maybe dropping other paths because of the new one */ | 1029 | /* Consider maybe dropping other paths because of the new one */ |
1034 | if ( (GNUNET_CONTAINER_heap_get_size (cp->path_heap) >= | 1030 | if ((GNUNET_CONTAINER_heap_get_size(cp->path_heap) >= |
1035 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) && | 1031 | 2 * DESIRED_CONNECTIONS_PER_TUNNEL) && |
1036 | (NULL != cp->heap_cleanup_task) ) | 1032 | (NULL != cp->heap_cleanup_task)) |
1037 | cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now (&path_heap_cleanup, | 1033 | cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now(&path_heap_cleanup, |
1038 | cp); | 1034 | cp); |
1039 | return hn; | 1035 | return hn; |
1040 | } | 1036 | } |
1041 | 1037 | ||
@@ -1050,16 +1046,16 @@ GCP_attach_path (struct CadetPeer *cp, | |||
1050 | * @param hn note in @a cp's path heap that must be deleted | 1046 | * @param hn note in @a cp's path heap that must be deleted |
1051 | */ | 1047 | */ |
1052 | void | 1048 | void |
1053 | GCP_detach_path (struct CadetPeer *cp, | 1049 | GCP_detach_path(struct CadetPeer *cp, |
1054 | struct CadetPeerPath *path, | 1050 | struct CadetPeerPath *path, |
1055 | struct GNUNET_CONTAINER_HeapNode *hn) | 1051 | struct GNUNET_CONTAINER_HeapNode *hn) |
1056 | { | 1052 | { |
1057 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1053 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1058 | "Detatching path %s from peer %s\n", | 1054 | "Detatching path %s from peer %s\n", |
1059 | GCPP_2s (path), | 1055 | GCPP_2s(path), |
1060 | GCP_2s (cp)); | 1056 | GCP_2s(cp)); |
1061 | GNUNET_assert (path == | 1057 | GNUNET_assert(path == |
1062 | GNUNET_CONTAINER_heap_remove_node (hn)); | 1058 | GNUNET_CONTAINER_heap_remove_node(hn)); |
1063 | } | 1059 | } |
1064 | 1060 | ||
1065 | 1061 | ||
@@ -1070,23 +1066,23 @@ GCP_detach_path (struct CadetPeer *cp, | |||
1070 | * @param cc the connection to add | 1066 | * @param cc the connection to add |
1071 | */ | 1067 | */ |
1072 | void | 1068 | void |
1073 | GCP_add_connection (struct CadetPeer *cp, | 1069 | GCP_add_connection(struct CadetPeer *cp, |
1074 | struct CadetConnection *cc) | 1070 | struct CadetConnection *cc) |
1075 | { | 1071 | { |
1076 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1072 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1077 | "Adding %s to peer %s\n", | 1073 | "Adding %s to peer %s\n", |
1078 | GCC_2s (cc), | 1074 | GCC_2s(cc), |
1079 | GCP_2s (cp)); | 1075 | GCP_2s(cp)); |
1080 | GNUNET_assert (GNUNET_OK == | 1076 | GNUNET_assert(GNUNET_OK == |
1081 | GNUNET_CONTAINER_multishortmap_put (cp->connections, | 1077 | GNUNET_CONTAINER_multishortmap_put(cp->connections, |
1082 | &GCC_get_id (cc)->connection_of_tunnel, | 1078 | &GCC_get_id(cc)->connection_of_tunnel, |
1083 | cc, | 1079 | cc, |
1084 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1080 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1085 | if (NULL != cp->destroy_task) | 1081 | if (NULL != cp->destroy_task) |
1086 | { | 1082 | { |
1087 | GNUNET_SCHEDULER_cancel (cp->destroy_task); | 1083 | GNUNET_SCHEDULER_cancel(cp->destroy_task); |
1088 | cp->destroy_task = NULL; | 1084 | cp->destroy_task = NULL; |
1089 | } | 1085 | } |
1090 | } | 1086 | } |
1091 | 1087 | ||
1092 | 1088 | ||
@@ -1097,18 +1093,18 @@ GCP_add_connection (struct CadetPeer *cp, | |||
1097 | * @param cc the connection to remove | 1093 | * @param cc the connection to remove |
1098 | */ | 1094 | */ |
1099 | void | 1095 | void |
1100 | GCP_remove_connection (struct CadetPeer *cp, | 1096 | GCP_remove_connection(struct CadetPeer *cp, |
1101 | struct CadetConnection *cc) | 1097 | struct CadetConnection *cc) |
1102 | { | 1098 | { |
1103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1099 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1104 | "Removing connection %s from peer %s\n", | 1100 | "Removing connection %s from peer %s\n", |
1105 | GCC_2s (cc), | 1101 | GCC_2s(cc), |
1106 | GCP_2s (cp)); | 1102 | GCP_2s(cp)); |
1107 | GNUNET_assert (GNUNET_YES == | 1103 | GNUNET_assert(GNUNET_YES == |
1108 | GNUNET_CONTAINER_multishortmap_remove (cp->connections, | 1104 | GNUNET_CONTAINER_multishortmap_remove(cp->connections, |
1109 | &GCC_get_id (cc)->connection_of_tunnel, | 1105 | &GCC_get_id(cc)->connection_of_tunnel, |
1110 | cc)); | 1106 | cc)); |
1111 | consider_peer_destroy (cp); | 1107 | consider_peer_destroy(cp); |
1112 | } | 1108 | } |
1113 | 1109 | ||
1114 | 1110 | ||
@@ -1124,30 +1120,30 @@ GCP_remove_connection (struct CadetPeer *cp, | |||
1124 | * NULL if unknown and not requested @a create | 1120 | * NULL if unknown and not requested @a create |
1125 | */ | 1121 | */ |
1126 | struct CadetPeer * | 1122 | struct CadetPeer * |
1127 | GCP_get (const struct GNUNET_PeerIdentity *peer_id, | 1123 | GCP_get(const struct GNUNET_PeerIdentity *peer_id, |
1128 | int create) | 1124 | int create) |
1129 | { | 1125 | { |
1130 | struct CadetPeer *cp; | 1126 | struct CadetPeer *cp; |
1131 | 1127 | ||
1132 | cp = GNUNET_CONTAINER_multipeermap_get (peers, | 1128 | cp = GNUNET_CONTAINER_multipeermap_get(peers, |
1133 | peer_id); | 1129 | peer_id); |
1134 | if (NULL != cp) | 1130 | if (NULL != cp) |
1135 | return cp; | 1131 | return cp; |
1136 | if (GNUNET_NO == create) | 1132 | if (GNUNET_NO == create) |
1137 | return NULL; | 1133 | return NULL; |
1138 | cp = GNUNET_new (struct CadetPeer); | 1134 | cp = GNUNET_new(struct CadetPeer); |
1139 | cp->pid = *peer_id; | 1135 | cp->pid = *peer_id; |
1140 | cp->connections = GNUNET_CONTAINER_multishortmap_create (32, | 1136 | cp->connections = GNUNET_CONTAINER_multishortmap_create(32, |
1141 | GNUNET_YES); | 1137 | GNUNET_YES); |
1142 | cp->path_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1138 | cp->path_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1143 | GNUNET_assert (GNUNET_YES == | 1139 | GNUNET_assert(GNUNET_YES == |
1144 | GNUNET_CONTAINER_multipeermap_put (peers, | 1140 | GNUNET_CONTAINER_multipeermap_put(peers, |
1145 | &cp->pid, | 1141 | &cp->pid, |
1146 | cp, | 1142 | cp, |
1147 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1143 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1148 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1144 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1149 | "Creating peer %s\n", | 1145 | "Creating peer %s\n", |
1150 | GCP_2s (cp)); | 1146 | GCP_2s(cp)); |
1151 | return cp; | 1147 | return cp; |
1152 | } | 1148 | } |
1153 | 1149 | ||
@@ -1159,7 +1155,7 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id, | |||
1159 | * @return the peer identity | 1155 | * @return the peer identity |
1160 | */ | 1156 | */ |
1161 | const struct GNUNET_PeerIdentity * | 1157 | const struct GNUNET_PeerIdentity * |
1162 | GCP_get_id (struct CadetPeer *cp) | 1158 | GCP_get_id(struct CadetPeer *cp) |
1163 | { | 1159 | { |
1164 | return &cp->pid; | 1160 | return &cp->pid; |
1165 | } | 1161 | } |
@@ -1172,12 +1168,12 @@ GCP_get_id (struct CadetPeer *cp) | |||
1172 | * @param cls Closure for @c iter. | 1168 | * @param cls Closure for @c iter. |
1173 | */ | 1169 | */ |
1174 | void | 1170 | void |
1175 | GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, | 1171 | GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter, |
1176 | void *cls) | 1172 | void *cls) |
1177 | { | 1173 | { |
1178 | GNUNET_CONTAINER_multipeermap_iterate (peers, | 1174 | GNUNET_CONTAINER_multipeermap_iterate(peers, |
1179 | iter, | 1175 | iter, |
1180 | cls); | 1176 | cls); |
1181 | } | 1177 | } |
1182 | 1178 | ||
1183 | 1179 | ||
@@ -1188,7 +1184,7 @@ GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, | |||
1188 | * @return Number of known paths. | 1184 | * @return Number of known paths. |
1189 | */ | 1185 | */ |
1190 | unsigned int | 1186 | unsigned int |
1191 | GCP_count_paths (const struct CadetPeer *cp) | 1187 | GCP_count_paths(const struct CadetPeer *cp) |
1192 | { | 1188 | { |
1193 | return cp->num_paths; | 1189 | return cp->num_paths; |
1194 | } | 1190 | } |
@@ -1203,45 +1199,45 @@ GCP_count_paths (const struct CadetPeer *cp) | |||
1203 | * @return Number of iterated paths. | 1199 | * @return Number of iterated paths. |
1204 | */ | 1200 | */ |
1205 | unsigned int | 1201 | unsigned int |
1206 | GCP_iterate_paths (struct CadetPeer *cp, | 1202 | GCP_iterate_paths(struct CadetPeer *cp, |
1207 | GCP_PathIterator callback, | 1203 | GCP_PathIterator callback, |
1208 | void *callback_cls) | 1204 | void *callback_cls) |
1209 | { | 1205 | { |
1210 | unsigned int ret = 0; | 1206 | unsigned int ret = 0; |
1211 | 1207 | ||
1212 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1208 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1213 | "Iterating over paths to peer %s%s\n", | 1209 | "Iterating over paths to peer %s%s\n", |
1214 | GCP_2s (cp), | 1210 | GCP_2s(cp), |
1215 | (NULL == cp->core_mq) ? "" : " including direct link"); | 1211 | (NULL == cp->core_mq) ? "" : " including direct link"); |
1216 | if (NULL != cp->core_mq) | 1212 | if (NULL != cp->core_mq) |
1217 | { | ||
1218 | /* FIXME: this branch seems to duplicate the | ||
1219 | i=0 case below (direct link). Leave out!??? -CG */ | ||
1220 | struct CadetPeerPath *path; | ||
1221 | |||
1222 | path = GCPP_get_path_from_route (1, | ||
1223 | &cp->pid); | ||
1224 | ret++; | ||
1225 | if (GNUNET_NO == | ||
1226 | callback (callback_cls, | ||
1227 | path, | ||
1228 | 0)) | ||
1229 | return ret; | ||
1230 | } | ||
1231 | for (unsigned int i=0;i<cp->path_dll_length;i++) | ||
1232 | { | ||
1233 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1234 | NULL != pe; | ||
1235 | pe = pe->next) | ||
1236 | { | 1213 | { |
1214 | /* FIXME: this branch seems to duplicate the | ||
1215 | i=0 case below (direct link). Leave out!??? -CG */ | ||
1216 | struct CadetPeerPath *path; | ||
1217 | |||
1218 | path = GCPP_get_path_from_route(1, | ||
1219 | &cp->pid); | ||
1237 | ret++; | 1220 | ret++; |
1238 | if (GNUNET_NO == | 1221 | if (GNUNET_NO == |
1239 | callback (callback_cls, | 1222 | callback(callback_cls, |
1240 | pe->path, | 1223 | path, |
1241 | i)) | 1224 | 0)) |
1242 | return ret; | 1225 | return ret; |
1243 | } | 1226 | } |
1244 | } | 1227 | for (unsigned int i = 0; i < cp->path_dll_length; i++) |
1228 | { | ||
1229 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1230 | NULL != pe; | ||
1231 | pe = pe->next) | ||
1232 | { | ||
1233 | ret++; | ||
1234 | if (GNUNET_NO == | ||
1235 | callback(callback_cls, | ||
1236 | pe->path, | ||
1237 | i)) | ||
1238 | return ret; | ||
1239 | } | ||
1240 | } | ||
1245 | return ret; | 1241 | return ret; |
1246 | } | 1242 | } |
1247 | 1243 | ||
@@ -1254,29 +1250,29 @@ GCP_iterate_paths (struct CadetPeer *cp, | |||
1254 | * @return Number of iterated paths. | 1250 | * @return Number of iterated paths. |
1255 | */ | 1251 | */ |
1256 | unsigned int | 1252 | unsigned int |
1257 | GCP_iterate_indirect_paths (struct CadetPeer *cp, | 1253 | GCP_iterate_indirect_paths(struct CadetPeer *cp, |
1258 | GCP_PathIterator callback, | 1254 | GCP_PathIterator callback, |
1259 | void *callback_cls) | 1255 | void *callback_cls) |
1260 | { | 1256 | { |
1261 | unsigned int ret = 0; | 1257 | unsigned int ret = 0; |
1262 | 1258 | ||
1263 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1259 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1264 | "Iterating over paths to peer %s without direct link\n", | 1260 | "Iterating over paths to peer %s without direct link\n", |
1265 | GCP_2s (cp)); | 1261 | GCP_2s(cp)); |
1266 | for (unsigned int i=1;i<cp->path_dll_length;i++) | 1262 | for (unsigned int i = 1; i < cp->path_dll_length; i++) |
1267 | { | ||
1268 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; | ||
1269 | NULL != pe; | ||
1270 | pe = pe->next) | ||
1271 | { | 1263 | { |
1272 | ret++; | 1264 | for (struct CadetPeerPathEntry *pe = cp->path_heads[i]; |
1273 | if (GNUNET_NO == | 1265 | NULL != pe; |
1274 | callback (callback_cls, | 1266 | pe = pe->next) |
1275 | pe->path, | 1267 | { |
1276 | i)) | 1268 | ret++; |
1277 | return ret; | 1269 | if (GNUNET_NO == |
1270 | callback(callback_cls, | ||
1271 | pe->path, | ||
1272 | i)) | ||
1273 | return ret; | ||
1274 | } | ||
1278 | } | 1275 | } |
1279 | } | ||
1280 | return ret; | 1276 | return ret; |
1281 | } | 1277 | } |
1282 | 1278 | ||
@@ -1292,32 +1288,32 @@ GCP_iterate_indirect_paths (struct CadetPeer *cp, | |||
1292 | * @return Number of iterated paths. | 1288 | * @return Number of iterated paths. |
1293 | */ | 1289 | */ |
1294 | unsigned int | 1290 | unsigned int |
1295 | GCP_iterate_paths_at (struct CadetPeer *cp, | 1291 | GCP_iterate_paths_at(struct CadetPeer *cp, |
1296 | unsigned int dist, | 1292 | unsigned int dist, |
1297 | GCP_PathIterator callback, | 1293 | GCP_PathIterator callback, |
1298 | void *callback_cls) | 1294 | void *callback_cls) |
1299 | { | 1295 | { |
1300 | unsigned int ret = 0; | 1296 | unsigned int ret = 0; |
1301 | 1297 | ||
1302 | if (dist >= cp->path_dll_length) | 1298 | if (dist >= cp->path_dll_length) |
1303 | { | 1299 | { |
1304 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1300 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1305 | "Asked to look for paths at distance %u, but maximum for me is < %u\n", | 1301 | "Asked to look for paths at distance %u, but maximum for me is < %u\n", |
1306 | dist, | 1302 | dist, |
1307 | cp->path_dll_length); | 1303 | cp->path_dll_length); |
1308 | return 0; | 1304 | return 0; |
1309 | } | 1305 | } |
1310 | for (struct CadetPeerPathEntry *pe = cp->path_heads[dist]; | 1306 | for (struct CadetPeerPathEntry *pe = cp->path_heads[dist]; |
1311 | NULL != pe; | 1307 | NULL != pe; |
1312 | pe = pe->next) | 1308 | pe = pe->next) |
1313 | { | 1309 | { |
1314 | if (GNUNET_NO == | 1310 | if (GNUNET_NO == |
1315 | callback (callback_cls, | 1311 | callback(callback_cls, |
1316 | pe->path, | 1312 | pe->path, |
1317 | dist)) | 1313 | dist)) |
1318 | return ret; | 1314 | return ret; |
1319 | ret++; | 1315 | ret++; |
1320 | } | 1316 | } |
1321 | return ret; | 1317 | return ret; |
1322 | } | 1318 | } |
1323 | 1319 | ||
@@ -1330,16 +1326,16 @@ GCP_iterate_paths_at (struct CadetPeer *cp, | |||
1330 | * @return Tunnel towards peer. | 1326 | * @return Tunnel towards peer. |
1331 | */ | 1327 | */ |
1332 | struct CadetTunnel * | 1328 | struct CadetTunnel * |
1333 | GCP_get_tunnel (struct CadetPeer *cp, | 1329 | GCP_get_tunnel(struct CadetPeer *cp, |
1334 | int create) | 1330 | int create) |
1335 | { | 1331 | { |
1336 | if (NULL == cp) | 1332 | if (NULL == cp) |
1337 | return NULL; | 1333 | return NULL; |
1338 | if ( (NULL != cp->t) || | 1334 | if ((NULL != cp->t) || |
1339 | (GNUNET_NO == create) ) | 1335 | (GNUNET_NO == create)) |
1340 | return cp->t; | 1336 | return cp->t; |
1341 | cp->t = GCT_create_tunnel (cp); | 1337 | cp->t = GCT_create_tunnel(cp); |
1342 | consider_peer_activate (cp); | 1338 | consider_peer_activate(cp); |
1343 | return cp->t; | 1339 | return cp->t; |
1344 | } | 1340 | } |
1345 | 1341 | ||
@@ -1351,7 +1347,7 @@ GCP_get_tunnel (struct CadetPeer *cp, | |||
1351 | * @param cls the `struct CadetPeer` where the offer completed | 1347 | * @param cls the `struct CadetPeer` where the offer completed |
1352 | */ | 1348 | */ |
1353 | static void | 1349 | static void |
1354 | hello_offer_done (void *cls) | 1350 | hello_offer_done(void *cls) |
1355 | { | 1351 | { |
1356 | struct CadetPeer *cp = cls; | 1352 | struct CadetPeer *cp = cls; |
1357 | 1353 | ||
@@ -1367,39 +1363,39 @@ hello_offer_done (void *cls) | |||
1367 | * @param hello the HELLO to remember | 1363 | * @param hello the HELLO to remember |
1368 | */ | 1364 | */ |
1369 | void | 1365 | void |
1370 | GCP_set_hello (struct CadetPeer *cp, | 1366 | GCP_set_hello(struct CadetPeer *cp, |
1371 | const struct GNUNET_HELLO_Message *hello) | 1367 | const struct GNUNET_HELLO_Message *hello) |
1372 | { | 1368 | { |
1373 | struct GNUNET_HELLO_Message *mrg; | 1369 | struct GNUNET_HELLO_Message *mrg; |
1374 | 1370 | ||
1375 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1371 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1376 | "Got %u byte HELLO for peer %s\n", | 1372 | "Got %u byte HELLO for peer %s\n", |
1377 | (unsigned int) GNUNET_HELLO_size (hello), | 1373 | (unsigned int)GNUNET_HELLO_size(hello), |
1378 | GCP_2s (cp)); | 1374 | GCP_2s(cp)); |
1379 | if (NULL != cp->hello_offer) | 1375 | if (NULL != cp->hello_offer) |
1380 | { | 1376 | { |
1381 | GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer); | 1377 | GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer); |
1382 | cp->hello_offer = NULL; | 1378 | cp->hello_offer = NULL; |
1383 | } | 1379 | } |
1384 | if (NULL != cp->hello) | 1380 | if (NULL != cp->hello) |
1385 | { | 1381 | { |
1386 | mrg = GNUNET_HELLO_merge (hello, | 1382 | mrg = GNUNET_HELLO_merge(hello, |
1387 | cp->hello); | 1383 | cp->hello); |
1388 | GNUNET_free (cp->hello); | 1384 | GNUNET_free(cp->hello); |
1389 | cp->hello = mrg; | 1385 | cp->hello = mrg; |
1390 | } | 1386 | } |
1391 | else | 1387 | else |
1392 | { | 1388 | { |
1393 | cp->hello = GNUNET_memdup (hello, | 1389 | cp->hello = GNUNET_memdup(hello, |
1394 | GNUNET_HELLO_size (hello)); | 1390 | GNUNET_HELLO_size(hello)); |
1395 | } | 1391 | } |
1396 | cp->hello_offer | 1392 | cp->hello_offer |
1397 | = GNUNET_TRANSPORT_offer_hello (cfg, | 1393 | = GNUNET_TRANSPORT_offer_hello(cfg, |
1398 | GNUNET_HELLO_get_header (cp->hello) , | 1394 | GNUNET_HELLO_get_header(cp->hello), |
1399 | &hello_offer_done, | 1395 | &hello_offer_done, |
1400 | cp); | 1396 | cp); |
1401 | /* New HELLO means cp's destruction time may change... */ | 1397 | /* New HELLO means cp's destruction time may change... */ |
1402 | consider_peer_destroy (cp); | 1398 | consider_peer_destroy(cp); |
1403 | } | 1399 | } |
1404 | 1400 | ||
1405 | 1401 | ||
@@ -1411,16 +1407,16 @@ GCP_set_hello (struct CadetPeer *cp, | |||
1411 | * @param t the dead tunnel | 1407 | * @param t the dead tunnel |
1412 | */ | 1408 | */ |
1413 | void | 1409 | void |
1414 | GCP_drop_tunnel (struct CadetPeer *cp, | 1410 | GCP_drop_tunnel(struct CadetPeer *cp, |
1415 | struct CadetTunnel *t) | 1411 | struct CadetTunnel *t) |
1416 | { | 1412 | { |
1417 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1413 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1418 | "Dropping tunnel %s to peer %s\n", | 1414 | "Dropping tunnel %s to peer %s\n", |
1419 | GCT_2s (t), | 1415 | GCT_2s(t), |
1420 | GCP_2s (cp)); | 1416 | GCP_2s(cp)); |
1421 | GNUNET_assert (cp->t == t); | 1417 | GNUNET_assert(cp->t == t); |
1422 | cp->t = NULL; | 1418 | cp->t = NULL; |
1423 | consider_peer_destroy (cp); | 1419 | consider_peer_destroy(cp); |
1424 | } | 1420 | } |
1425 | 1421 | ||
1426 | 1422 | ||
@@ -1431,7 +1427,7 @@ GCP_drop_tunnel (struct CadetPeer *cp, | |||
1431 | * @return #GNUNET_YES if @a cp has a core-level connection | 1427 | * @return #GNUNET_YES if @a cp has a core-level connection |
1432 | */ | 1428 | */ |
1433 | int | 1429 | int |
1434 | GCP_has_core_connection (struct CadetPeer *cp) | 1430 | GCP_has_core_connection(struct CadetPeer *cp) |
1435 | { | 1431 | { |
1436 | return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO; | 1432 | return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO; |
1437 | } | 1433 | } |
@@ -1446,26 +1442,26 @@ GCP_has_core_connection (struct CadetPeer *cp) | |||
1446 | * @return handle to cancel request | 1442 | * @return handle to cancel request |
1447 | */ | 1443 | */ |
1448 | struct GCP_MessageQueueManager * | 1444 | struct GCP_MessageQueueManager * |
1449 | GCP_request_mq (struct CadetPeer *cp, | 1445 | GCP_request_mq(struct CadetPeer *cp, |
1450 | GCP_MessageQueueNotificationCallback cb, | 1446 | GCP_MessageQueueNotificationCallback cb, |
1451 | void *cb_cls) | 1447 | void *cb_cls) |
1452 | { | 1448 | { |
1453 | struct GCP_MessageQueueManager *mqm; | 1449 | struct GCP_MessageQueueManager *mqm; |
1454 | 1450 | ||
1455 | mqm = GNUNET_new (struct GCP_MessageQueueManager); | 1451 | mqm = GNUNET_new(struct GCP_MessageQueueManager); |
1456 | mqm->cb = cb; | 1452 | mqm->cb = cb; |
1457 | mqm->cb_cls = cb_cls; | 1453 | mqm->cb_cls = cb_cls; |
1458 | mqm->cp = cp; | 1454 | mqm->cp = cp; |
1459 | GNUNET_CONTAINER_DLL_insert (cp->mqm_head, | 1455 | GNUNET_CONTAINER_DLL_insert(cp->mqm_head, |
1460 | cp->mqm_tail, | 1456 | cp->mqm_tail, |
1461 | mqm); | 1457 | mqm); |
1462 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1458 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1463 | "Creating MQM %p for peer %s\n", | 1459 | "Creating MQM %p for peer %s\n", |
1464 | mqm, | 1460 | mqm, |
1465 | GCP_2s (cp)); | 1461 | GCP_2s(cp)); |
1466 | if (NULL != cp->core_mq) | 1462 | if (NULL != cp->core_mq) |
1467 | cb (cb_cls, | 1463 | cb(cb_cls, |
1468 | GNUNET_YES); | 1464 | GNUNET_YES); |
1469 | return mqm; | 1465 | return mqm; |
1470 | } | 1466 | } |
1471 | 1467 | ||
@@ -1477,39 +1473,39 @@ GCP_request_mq (struct CadetPeer *cp, | |||
1477 | * @param last_env final message to transmit, or NULL | 1473 | * @param last_env final message to transmit, or NULL |
1478 | */ | 1474 | */ |
1479 | void | 1475 | void |
1480 | GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm, | 1476 | GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm, |
1481 | struct GNUNET_MQ_Envelope *last_env) | 1477 | struct GNUNET_MQ_Envelope *last_env) |
1482 | { | 1478 | { |
1483 | struct CadetPeer *cp = mqm->cp; | 1479 | struct CadetPeer *cp = mqm->cp; |
1484 | 1480 | ||
1485 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1481 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1486 | "Destroying MQM %p for peer %s%s\n", | 1482 | "Destroying MQM %p for peer %s%s\n", |
1487 | mqm, | 1483 | mqm, |
1488 | GCP_2s (cp), | 1484 | GCP_2s(cp), |
1489 | (NULL == last_env) ? "" : " with last ditch transmission"); | 1485 | (NULL == last_env) ? "" : " with last ditch transmission"); |
1490 | if (NULL != mqm->env) | 1486 | if (NULL != mqm->env) |
1491 | GNUNET_MQ_discard (mqm->env); | 1487 | GNUNET_MQ_discard(mqm->env); |
1492 | if (NULL != last_env) | 1488 | if (NULL != last_env) |
1493 | { | ||
1494 | if (NULL != cp->core_mq) | ||
1495 | { | ||
1496 | GNUNET_MQ_notify_sent (last_env, | ||
1497 | &mqm_send_done, | ||
1498 | cp); | ||
1499 | GNUNET_MQ_send (cp->core_mq, | ||
1500 | last_env); | ||
1501 | } | ||
1502 | else | ||
1503 | { | 1489 | { |
1504 | GNUNET_MQ_discard (last_env); | 1490 | if (NULL != cp->core_mq) |
1491 | { | ||
1492 | GNUNET_MQ_notify_sent(last_env, | ||
1493 | &mqm_send_done, | ||
1494 | cp); | ||
1495 | GNUNET_MQ_send(cp->core_mq, | ||
1496 | last_env); | ||
1497 | } | ||
1498 | else | ||
1499 | { | ||
1500 | GNUNET_MQ_discard(last_env); | ||
1501 | } | ||
1505 | } | 1502 | } |
1506 | } | ||
1507 | if (cp->mqm_ready_ptr == mqm) | 1503 | if (cp->mqm_ready_ptr == mqm) |
1508 | cp->mqm_ready_ptr = mqm->next; | 1504 | cp->mqm_ready_ptr = mqm->next; |
1509 | GNUNET_CONTAINER_DLL_remove (cp->mqm_head, | 1505 | GNUNET_CONTAINER_DLL_remove(cp->mqm_head, |
1510 | cp->mqm_tail, | 1506 | cp->mqm_tail, |
1511 | mqm); | 1507 | mqm); |
1512 | GNUNET_free (mqm); | 1508 | GNUNET_free(mqm); |
1513 | } | 1509 | } |
1514 | 1510 | ||
1515 | 1511 | ||
@@ -1523,27 +1519,27 @@ GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm, | |||
1523 | * @param env envelope with the message to send | 1519 | * @param env envelope with the message to send |
1524 | */ | 1520 | */ |
1525 | void | 1521 | void |
1526 | GCP_send_ooo (struct CadetPeer *cp, | 1522 | GCP_send_ooo(struct CadetPeer *cp, |
1527 | struct GNUNET_MQ_Envelope *env) | 1523 | struct GNUNET_MQ_Envelope *env) |
1528 | { | 1524 | { |
1529 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1525 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1530 | "Sending message to %s out of management\n", | 1526 | "Sending message to %s out of management\n", |
1531 | GCP_2s (cp)); | 1527 | GCP_2s(cp)); |
1532 | if (NULL == cp->core_mq) | 1528 | if (NULL == cp->core_mq) |
1533 | { | 1529 | { |
1534 | GNUNET_MQ_discard (env); | 1530 | GNUNET_MQ_discard(env); |
1535 | return; | 1531 | return; |
1536 | } | 1532 | } |
1537 | if (GNUNET_MQ_get_length (cp->core_mq) > MAX_OOO_QUEUE_SIZE) | 1533 | if (GNUNET_MQ_get_length(cp->core_mq) > MAX_OOO_QUEUE_SIZE) |
1538 | { | 1534 | { |
1539 | GNUNET_MQ_discard (env); | 1535 | GNUNET_MQ_discard(env); |
1540 | return; | 1536 | return; |
1541 | } | 1537 | } |
1542 | GNUNET_MQ_notify_sent (env, | 1538 | GNUNET_MQ_notify_sent(env, |
1543 | &mqm_send_done, | 1539 | &mqm_send_done, |
1544 | cp); | 1540 | cp); |
1545 | GNUNET_MQ_send (cp->core_mq, | 1541 | GNUNET_MQ_send(cp->core_mq, |
1546 | env); | 1542 | env); |
1547 | } | 1543 | } |
1548 | 1544 | ||
1549 | 1545 | ||