diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/core | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/core_api.c | 1640 | ||||
-rw-r--r-- | src/core/core_api_iterate_peers.c | 135 | ||||
-rw-r--r-- | src/core/gnunet-core-list-connections.c | 84 | ||||
-rw-r--r-- | src/core/gnunet-service-core.c | 3685 | ||||
-rw-r--r-- | src/core/test_core_api.c | 205 | ||||
-rw-r--r-- | src/core/test_core_api_preferences.c | 328 | ||||
-rw-r--r-- | src/core/test_core_api_reliability.c | 339 | ||||
-rw-r--r-- | src/core/test_core_api_send_to_self.c | 123 | ||||
-rw-r--r-- | src/core/test_core_api_start_only.c | 107 | ||||
-rw-r--r-- | src/core/test_core_quota_compliance.c | 551 |
10 files changed, 3440 insertions, 3757 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c index 7f7928fd3..c6fcc0b47 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c | |||
@@ -116,7 +116,7 @@ struct PeerRecord | |||
116 | * SendMessageRequest ID generator for this peer. | 116 | * SendMessageRequest ID generator for this peer. |
117 | */ | 117 | */ |
118 | uint16_t smr_id_gen; | 118 | uint16_t smr_id_gen; |
119 | 119 | ||
120 | }; | 120 | }; |
121 | 121 | ||
122 | 122 | ||
@@ -143,7 +143,7 @@ struct ControlMessage | |||
143 | * Function to run after transmission failed/succeeded. | 143 | * Function to run after transmission failed/succeeded. |
144 | */ | 144 | */ |
145 | GNUNET_CORE_ControlContinuation cont; | 145 | GNUNET_CORE_ControlContinuation cont; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Closure for 'cont'. | 148 | * Closure for 'cont'. |
149 | */ | 149 | */ |
@@ -190,9 +190,9 @@ struct GNUNET_CORE_Handle | |||
190 | 190 | ||
191 | /** | 191 | /** |
192 | * Function to call whenever we're notified about a peer changing status. | 192 | * Function to call whenever we're notified about a peer changing status. |
193 | */ | 193 | */ |
194 | GNUNET_CORE_PeerStatusEventHandler status_events; | 194 | GNUNET_CORE_PeerStatusEventHandler status_events; |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * Function to call whenever we receive an inbound message. | 197 | * Function to call whenever we receive an inbound message. |
198 | */ | 198 | */ |
@@ -371,8 +371,7 @@ struct GNUNET_CORE_TransmitHandle | |||
371 | * | 371 | * |
372 | * @param h our handle to the core service | 372 | * @param h our handle to the core service |
373 | */ | 373 | */ |
374 | static void | 374 | static void reconnect (struct GNUNET_CORE_Handle *h); |
375 | reconnect (struct GNUNET_CORE_Handle *h); | ||
376 | 375 | ||
377 | 376 | ||
378 | /** | 377 | /** |
@@ -382,15 +381,14 @@ reconnect (struct GNUNET_CORE_Handle *h); | |||
382 | * @param tc task context | 381 | * @param tc task context |
383 | */ | 382 | */ |
384 | static void | 383 | static void |
385 | reconnect_task (void *cls, | 384 | reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
386 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
387 | { | 385 | { |
388 | struct GNUNET_CORE_Handle *h = cls; | 386 | struct GNUNET_CORE_Handle *h = cls; |
389 | 387 | ||
390 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 388 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
391 | #if DEBUG_CORE | 389 | #if DEBUG_CORE |
392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
393 | "Connecting to CORE service after delay\n"); | 391 | "Connecting to CORE service after delay\n"); |
394 | #endif | 392 | #endif |
395 | reconnect (h); | 393 | reconnect (h); |
396 | } | 394 | } |
@@ -407,8 +405,7 @@ reconnect_task (void *cls, | |||
407 | */ | 405 | */ |
408 | static int | 406 | static int |
409 | disconnect_and_free_peer_entry (void *cls, | 407 | disconnect_and_free_peer_entry (void *cls, |
410 | const GNUNET_HashCode *key, | 408 | const GNUNET_HashCode * key, void *value) |
411 | void *value) | ||
412 | { | 409 | { |
413 | static struct GNUNET_BANDWIDTH_Value32NBO zero; | 410 | static struct GNUNET_BANDWIDTH_Value32NBO zero; |
414 | struct GNUNET_CORE_Handle *h = cls; | 411 | struct GNUNET_CORE_Handle *h = cls; |
@@ -418,61 +415,47 @@ disconnect_and_free_peer_entry (void *cls, | |||
418 | void *pcic_cls; | 415 | void *pcic_cls; |
419 | 416 | ||
420 | if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 417 | if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
421 | { | 418 | { |
422 | GNUNET_SCHEDULER_cancel (pr->timeout_task); | 419 | GNUNET_SCHEDULER_cancel (pr->timeout_task); |
423 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 420 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
424 | } | 421 | } |
425 | if (pr->ntr_task != GNUNET_SCHEDULER_NO_TASK) | 422 | if (pr->ntr_task != GNUNET_SCHEDULER_NO_TASK) |
426 | { | 423 | { |
427 | GNUNET_SCHEDULER_cancel (pr->ntr_task); | 424 | GNUNET_SCHEDULER_cancel (pr->ntr_task); |
428 | pr->ntr_task = GNUNET_SCHEDULER_NO_TASK; | 425 | pr->ntr_task = GNUNET_SCHEDULER_NO_TASK; |
429 | } | 426 | } |
430 | if ( (pr->prev != NULL) || | 427 | if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr)) |
431 | (pr->next != NULL) || | 428 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); |
432 | (h->ready_peer_head == pr) ) | ||
433 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, | ||
434 | h->ready_peer_tail, | ||
435 | pr); | ||
436 | if (h->disconnects != NULL) | 429 | if (h->disconnects != NULL) |
437 | h->disconnects (h->cls, | 430 | h->disconnects (h->cls, &pr->peer); |
438 | &pr->peer); | ||
439 | /* all requests should have been cancelled, clean up anyway, just in case */ | 431 | /* all requests should have been cancelled, clean up anyway, just in case */ |
440 | GNUNET_break (pr->queue_size == 0); | 432 | GNUNET_break (pr->queue_size == 0); |
441 | if (NULL != (pcic = pr->pcic)) | 433 | if (NULL != (pcic = pr->pcic)) |
442 | { | 434 | { |
443 | GNUNET_break (0); | 435 | GNUNET_break (0); |
444 | pcic_cls = pr->pcic_cls; | 436 | pcic_cls = pr->pcic_cls; |
445 | GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr); | 437 | GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr); |
446 | pcic (pcic_cls, | 438 | pcic (pcic_cls, &pr->peer, zero, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0); |
447 | &pr->peer, | 439 | } |
448 | zero, | ||
449 | 0, | ||
450 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
451 | 0); | ||
452 | } | ||
453 | while (NULL != (th = pr->pending_head)) | 440 | while (NULL != (th = pr->pending_head)) |
454 | { | 441 | { |
455 | GNUNET_break (0); | 442 | GNUNET_break (0); |
456 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, | 443 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th); |
457 | pr->pending_tail, | 444 | pr->queue_size--; |
458 | th); | 445 | if (th->cm != NULL) |
459 | pr->queue_size--; | 446 | th->cm->th = NULL; |
460 | if (th->cm != NULL) | 447 | GNUNET_free (th); |
461 | th->cm->th = NULL; | 448 | } |
462 | GNUNET_free (th); | ||
463 | } | ||
464 | /* done with 'voluntary' cleanups, now on to normal freeing */ | 449 | /* done with 'voluntary' cleanups, now on to normal freeing */ |
465 | GNUNET_assert (GNUNET_YES == | 450 | GNUNET_assert (GNUNET_YES == |
466 | GNUNET_CONTAINER_multihashmap_remove (h->peers, | 451 | GNUNET_CONTAINER_multihashmap_remove (h->peers, key, pr)); |
467 | key, | ||
468 | pr)); | ||
469 | GNUNET_assert (pr->pending_head == NULL); | 452 | GNUNET_assert (pr->pending_head == NULL); |
470 | GNUNET_assert (pr->pending_tail == NULL); | 453 | GNUNET_assert (pr->pending_tail == NULL); |
471 | GNUNET_assert (pr->ch = h); | 454 | GNUNET_assert (pr->ch = h); |
472 | GNUNET_assert (pr->queue_size == 0); | 455 | GNUNET_assert (pr->queue_size == 0); |
473 | GNUNET_assert (pr->timeout_task == GNUNET_SCHEDULER_NO_TASK); | 456 | GNUNET_assert (pr->timeout_task == GNUNET_SCHEDULER_NO_TASK); |
474 | GNUNET_assert (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK); | 457 | GNUNET_assert (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK); |
475 | GNUNET_free (pr); | 458 | GNUNET_free (pr); |
476 | return GNUNET_YES; | 459 | return GNUNET_YES; |
477 | } | 460 | } |
478 | 461 | ||
@@ -491,41 +474,36 @@ reconnect_later (struct GNUNET_CORE_Handle *h) | |||
491 | 474 | ||
492 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); | 475 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); |
493 | if (NULL != h->cth) | 476 | if (NULL != h->cth) |
494 | { | 477 | { |
495 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth); | 478 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth); |
496 | h->cth = NULL; | 479 | h->cth = NULL; |
497 | } | 480 | } |
498 | if (h->client != NULL) | 481 | if (h->client != NULL) |
499 | { | 482 | { |
500 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | 483 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
501 | h->client = NULL; | 484 | h->client = NULL; |
502 | } | 485 | } |
503 | h->currently_down = GNUNET_YES; | 486 | h->currently_down = GNUNET_YES; |
504 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); | 487 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); |
505 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 488 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, |
506 | &reconnect_task, | 489 | &reconnect_task, h); |
507 | h); | ||
508 | while (NULL != (cm = h->control_pending_head)) | 490 | while (NULL != (cm = h->control_pending_head)) |
509 | { | 491 | { |
510 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | 492 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, |
511 | h->control_pending_tail, | 493 | h->control_pending_tail, cm); |
512 | cm); | 494 | if (cm->th != NULL) |
513 | if (cm->th != NULL) | 495 | cm->th->cm = NULL; |
514 | cm->th->cm = NULL; | 496 | if (cm->cont != NULL) |
515 | if (cm->cont != NULL) | 497 | cm->cont (cm->cont_cls, GNUNET_NO); |
516 | cm->cont (cm->cont_cls, GNUNET_NO); | 498 | GNUNET_free (cm); |
517 | GNUNET_free (cm); | 499 | } |
518 | } | ||
519 | GNUNET_CONTAINER_multihashmap_iterate (h->peers, | 500 | GNUNET_CONTAINER_multihashmap_iterate (h->peers, |
520 | &disconnect_and_free_peer_entry, | 501 | &disconnect_and_free_peer_entry, h); |
521 | h); | 502 | while (NULL != (pr = h->ready_peer_head)) |
522 | while (NULL != (pr = h->ready_peer_head)) | 503 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); |
523 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, | ||
524 | h->ready_peer_tail, | ||
525 | pr); | ||
526 | GNUNET_assert (h->control_pending_head == NULL); | 504 | GNUNET_assert (h->control_pending_head == NULL); |
527 | h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | 505 | h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, |
528 | h->retry_backoff); | 506 | h->retry_backoff); |
529 | h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2); | 507 | h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2); |
530 | } | 508 | } |
531 | 509 | ||
@@ -538,8 +516,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h) | |||
538 | * @param ignore_currently_down transmit message even if not initialized? | 516 | * @param ignore_currently_down transmit message even if not initialized? |
539 | */ | 517 | */ |
540 | static void | 518 | static void |
541 | trigger_next_request (struct GNUNET_CORE_Handle *h, | 519 | trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down); |
542 | int ignore_currently_down); | ||
543 | 520 | ||
544 | 521 | ||
545 | /** | 522 | /** |
@@ -550,8 +527,7 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, | |||
550 | * @param tc context, can be NULL (!) | 527 | * @param tc context, can be NULL (!) |
551 | */ | 528 | */ |
552 | static void | 529 | static void |
553 | transmission_timeout (void *cls, | 530 | transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
554 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
555 | 531 | ||
556 | 532 | ||
557 | /** | 533 | /** |
@@ -569,27 +545,27 @@ request_next_transmission (struct PeerRecord *pr) | |||
569 | struct GNUNET_CORE_TransmitHandle *th; | 545 | struct GNUNET_CORE_TransmitHandle *th; |
570 | 546 | ||
571 | if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 547 | if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
572 | { | 548 | { |
573 | GNUNET_SCHEDULER_cancel (pr->timeout_task); | 549 | GNUNET_SCHEDULER_cancel (pr->timeout_task); |
574 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 550 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
575 | } | 551 | } |
576 | if (NULL == (th = pr->pending_head)) | 552 | if (NULL == (th = pr->pending_head)) |
577 | { | 553 | { |
578 | trigger_next_request (h, GNUNET_NO); | 554 | trigger_next_request (h, GNUNET_NO); |
579 | return; | 555 | return; |
580 | } | 556 | } |
581 | if (th->cm != NULL) | 557 | if (th->cm != NULL) |
582 | return; /* already done */ | 558 | return; /* already done */ |
583 | GNUNET_assert (pr->prev == NULL); | 559 | GNUNET_assert (pr->prev == NULL); |
584 | GNUNET_assert (pr->next == NULL); | 560 | GNUNET_assert (pr->next == NULL); |
585 | pr->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (th->timeout), | 561 | pr->timeout_task = |
586 | &transmission_timeout, | 562 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
587 | pr); | 563 | (th->timeout), &transmission_timeout, pr); |
588 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + | 564 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + |
589 | sizeof (struct SendMessageRequest)); | 565 | sizeof (struct SendMessageRequest)); |
590 | th->cm = cm; | 566 | th->cm = cm; |
591 | cm->th = th; | 567 | cm->th = th; |
592 | smr = (struct SendMessageRequest*) &cm[1]; | 568 | smr = (struct SendMessageRequest *) &cm[1]; |
593 | smr->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST); | 569 | smr->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST); |
594 | smr->header.size = htons (sizeof (struct SendMessageRequest)); | 570 | smr->header.size = htons (sizeof (struct SendMessageRequest)); |
595 | smr->priority = htonl (th->priority); | 571 | smr->priority = htonl (th->priority); |
@@ -599,12 +575,11 @@ request_next_transmission (struct PeerRecord *pr) | |||
599 | smr->size = htons (th->msize); | 575 | smr->size = htons (th->msize); |
600 | smr->smr_id = htons (th->smr_id = pr->smr_id_gen++); | 576 | smr->smr_id = htons (th->smr_id = pr->smr_id_gen++); |
601 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, | 577 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, |
602 | h->control_pending_tail, | 578 | h->control_pending_tail, cm); |
603 | cm); | ||
604 | #if DEBUG_CORE | 579 | #if DEBUG_CORE |
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
606 | "Adding SEND REQUEST for peer `%s' to message queue\n", | 581 | "Adding SEND REQUEST for peer `%s' to message queue\n", |
607 | GNUNET_i2s (&pr->peer)); | 582 | GNUNET_i2s (&pr->peer)); |
608 | #endif | 583 | #endif |
609 | trigger_next_request (h, GNUNET_NO); | 584 | trigger_next_request (h, GNUNET_NO); |
610 | } | 585 | } |
@@ -618,33 +593,26 @@ request_next_transmission (struct PeerRecord *pr) | |||
618 | * @param tc context, can be NULL (!) | 593 | * @param tc context, can be NULL (!) |
619 | */ | 594 | */ |
620 | static void | 595 | static void |
621 | transmission_timeout (void *cls, | 596 | transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
622 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
623 | { | 597 | { |
624 | struct PeerRecord *pr = cls; | 598 | struct PeerRecord *pr = cls; |
625 | struct GNUNET_CORE_Handle *h = pr->ch; | 599 | struct GNUNET_CORE_Handle *h = pr->ch; |
626 | struct GNUNET_CORE_TransmitHandle *th; | 600 | struct GNUNET_CORE_TransmitHandle *th; |
627 | 601 | ||
628 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 602 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
629 | th = pr->pending_head; | 603 | th = pr->pending_head; |
630 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, | 604 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th); |
631 | pr->pending_tail, | ||
632 | th); | ||
633 | pr->queue_size--; | 605 | pr->queue_size--; |
634 | if ( (pr->prev != NULL) || | 606 | if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head)) |
635 | (pr->next != NULL) || | 607 | { |
636 | (pr == h->ready_peer_head) ) | 608 | /* the request that was 'approved' by core was |
637 | { | 609 | * canceled before it could be transmitted; remove |
638 | /* the request that was 'approved' by core was | 610 | * us from the 'ready' list */ |
639 | canceled before it could be transmitted; remove | 611 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); |
640 | us from the 'ready' list */ | 612 | } |
641 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, | ||
642 | h->ready_peer_tail, | ||
643 | pr); | ||
644 | } | ||
645 | #if DEBUG_CORE | 613 | #if DEBUG_CORE |
646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
647 | "Signalling timeout of request for transmission to CORE service\n"); | 615 | "Signalling timeout of request for transmission to CORE service\n"); |
648 | #endif | 616 | #endif |
649 | request_next_transmission (pr); | 617 | request_next_transmission (pr); |
650 | GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); | 618 | GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); |
@@ -656,9 +624,7 @@ transmission_timeout (void *cls, | |||
656 | * Transmit the next message to the core service. | 624 | * Transmit the next message to the core service. |
657 | */ | 625 | */ |
658 | static size_t | 626 | static size_t |
659 | transmit_message (void *cls, | 627 | transmit_message (void *cls, size_t size, void *buf) |
660 | size_t size, | ||
661 | void *buf) | ||
662 | { | 628 | { |
663 | struct GNUNET_CORE_Handle *h = cls; | 629 | struct GNUNET_CORE_Handle *h = cls; |
664 | struct ControlMessage *cm; | 630 | struct ControlMessage *cm; |
@@ -672,117 +638,108 @@ transmit_message (void *cls, | |||
672 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); | 638 | GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); |
673 | h->cth = NULL; | 639 | h->cth = NULL; |
674 | if (buf == NULL) | 640 | if (buf == NULL) |
675 | { | 641 | { |
676 | #if DEBUG_CORE | 642 | #if DEBUG_CORE |
677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 643 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
678 | "Transmission failed, initiating reconnect\n"); | 644 | "Transmission failed, initiating reconnect\n"); |
679 | #endif | 645 | #endif |
680 | reconnect_later (h); | 646 | reconnect_later (h); |
681 | return 0; | 647 | return 0; |
682 | } | 648 | } |
683 | /* first check for control messages */ | 649 | /* first check for control messages */ |
684 | if (NULL != (cm = h->control_pending_head)) | 650 | if (NULL != (cm = h->control_pending_head)) |
651 | { | ||
652 | hdr = (const struct GNUNET_MessageHeader *) &cm[1]; | ||
653 | msize = ntohs (hdr->size); | ||
654 | if (size < msize) | ||
685 | { | 655 | { |
686 | hdr = (const struct GNUNET_MessageHeader*) &cm[1]; | ||
687 | msize = ntohs (hdr->size); | ||
688 | if (size < msize) | ||
689 | { | ||
690 | trigger_next_request (h, GNUNET_NO); | ||
691 | return 0; | ||
692 | } | ||
693 | #if DEBUG_CORE | ||
694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
695 | "Transmitting control message with %u bytes of type %u to core.\n", | ||
696 | (unsigned int) msize, | ||
697 | (unsigned int) ntohs (hdr->type)); | ||
698 | #endif | ||
699 | memcpy (buf, hdr, msize); | ||
700 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | ||
701 | h->control_pending_tail, | ||
702 | cm); | ||
703 | if (cm->th != NULL) | ||
704 | cm->th->cm = NULL; | ||
705 | if (NULL != cm->cont) | ||
706 | cm->cont (cm->cont_cls, GNUNET_OK); | ||
707 | GNUNET_free (cm); | ||
708 | trigger_next_request (h, GNUNET_NO); | 656 | trigger_next_request (h, GNUNET_NO); |
709 | return msize; | 657 | return 0; |
710 | } | 658 | } |
659 | #if DEBUG_CORE | ||
660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
661 | "Transmitting control message with %u bytes of type %u to core.\n", | ||
662 | (unsigned int) msize, (unsigned int) ntohs (hdr->type)); | ||
663 | #endif | ||
664 | memcpy (buf, hdr, msize); | ||
665 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | ||
666 | h->control_pending_tail, cm); | ||
667 | if (cm->th != NULL) | ||
668 | cm->th->cm = NULL; | ||
669 | if (NULL != cm->cont) | ||
670 | cm->cont (cm->cont_cls, GNUNET_OK); | ||
671 | GNUNET_free (cm); | ||
672 | trigger_next_request (h, GNUNET_NO); | ||
673 | return msize; | ||
674 | } | ||
711 | /* now check for 'ready' P2P messages */ | 675 | /* now check for 'ready' P2P messages */ |
712 | if (NULL != (pr = h->ready_peer_head)) | 676 | if (NULL != (pr = h->ready_peer_head)) |
677 | { | ||
678 | GNUNET_assert (pr->pending_head != NULL); | ||
679 | th = pr->pending_head; | ||
680 | if (size < th->msize + sizeof (struct SendMessage)) | ||
681 | { | ||
682 | trigger_next_request (h, GNUNET_NO); | ||
683 | return 0; | ||
684 | } | ||
685 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); | ||
686 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th); | ||
687 | pr->queue_size--; | ||
688 | if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
713 | { | 689 | { |
714 | GNUNET_assert (pr->pending_head != NULL); | 690 | GNUNET_SCHEDULER_cancel (pr->timeout_task); |
715 | th = pr->pending_head; | 691 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
716 | if (size < th->msize + sizeof (struct SendMessage)) | 692 | } |
717 | { | ||
718 | trigger_next_request (h, GNUNET_NO); | ||
719 | return 0; | ||
720 | } | ||
721 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, | ||
722 | h->ready_peer_tail, | ||
723 | pr); | ||
724 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, | ||
725 | pr->pending_tail, | ||
726 | th); | ||
727 | pr->queue_size--; | ||
728 | if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
729 | { | ||
730 | GNUNET_SCHEDULER_cancel (pr->timeout_task); | ||
731 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
732 | } | ||
733 | #if DEBUG_CORE | 693 | #if DEBUG_CORE |
734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
735 | "Transmitting SEND request to `%s' with %u bytes.\n", | 695 | "Transmitting SEND request to `%s' with %u bytes.\n", |
736 | GNUNET_i2s (&pr->peer), | 696 | GNUNET_i2s (&pr->peer), (unsigned int) th->msize); |
737 | (unsigned int) th->msize); | ||
738 | #endif | 697 | #endif |
739 | sm = (struct SendMessage *) buf; | 698 | sm = (struct SendMessage *) buf; |
740 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); | 699 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); |
741 | sm->priority = htonl (th->priority); | 700 | sm->priority = htonl (th->priority); |
742 | sm->deadline = GNUNET_TIME_absolute_hton (th->timeout); | 701 | sm->deadline = GNUNET_TIME_absolute_hton (th->timeout); |
743 | sm->peer = pr->peer; | 702 | sm->peer = pr->peer; |
744 | sm->cork = htonl ((uint32_t) th->cork); | 703 | sm->cork = htonl ((uint32_t) th->cork); |
745 | sm->reserved = htonl (0); | 704 | sm->reserved = htonl (0); |
746 | ret = th->get_message (th->get_message_cls, | 705 | ret = th->get_message (th->get_message_cls, |
747 | size - sizeof (struct SendMessage), | 706 | size - sizeof (struct SendMessage), &sm[1]); |
748 | &sm[1]); | 707 | |
749 | |||
750 | #if DEBUG_CORE | 708 | #if DEBUG_CORE |
751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
752 | "Transmitting SEND request to `%s' yielded %u bytes.\n", | 710 | "Transmitting SEND request to `%s' yielded %u bytes.\n", |
753 | GNUNET_i2s (&pr->peer), | 711 | GNUNET_i2s (&pr->peer), ret); |
754 | ret); | ||
755 | #endif | 712 | #endif |
756 | GNUNET_free (th); | 713 | GNUNET_free (th); |
757 | if (0 == ret) | 714 | if (0 == ret) |
758 | { | 715 | { |
759 | #if DEBUG_CORE | 716 | #if DEBUG_CORE |
760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
761 | "Size of clients message to peer %s is 0!\n", | 718 | "Size of clients message to peer %s is 0!\n", |
762 | GNUNET_i2s(&pr->peer)); | 719 | GNUNET_i2s (&pr->peer)); |
763 | #endif | 720 | #endif |
764 | /* client decided to send nothing! */ | 721 | /* client decided to send nothing! */ |
765 | request_next_transmission (pr); | 722 | request_next_transmission (pr); |
766 | return 0; | 723 | return 0; |
767 | } | 724 | } |
768 | #if DEBUG_CORE | 725 | #if DEBUG_CORE |
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 726 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
770 | "Produced SEND message to core with %u bytes payload\n", | 727 | "Produced SEND message to core with %u bytes payload\n", |
771 | (unsigned int) ret); | 728 | (unsigned int) ret); |
772 | #endif | 729 | #endif |
773 | GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader)); | 730 | GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader)); |
774 | if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 731 | if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
775 | { | 732 | { |
776 | GNUNET_break (0); | 733 | GNUNET_break (0); |
777 | request_next_transmission (pr); | ||
778 | return 0; | ||
779 | } | ||
780 | ret += sizeof (struct SendMessage); | ||
781 | sm->header.size = htons (ret); | ||
782 | GNUNET_assert (ret <= size); | ||
783 | request_next_transmission (pr); | 734 | request_next_transmission (pr); |
784 | return ret; | 735 | return 0; |
785 | } | 736 | } |
737 | ret += sizeof (struct SendMessage); | ||
738 | sm->header.size = htons (ret); | ||
739 | GNUNET_assert (ret <= size); | ||
740 | request_next_transmission (pr); | ||
741 | return ret; | ||
742 | } | ||
786 | return 0; | 743 | return 0; |
787 | } | 744 | } |
788 | 745 | ||
@@ -795,45 +752,46 @@ transmit_message (void *cls, | |||
795 | * @param ignore_currently_down transmit message even if not initialized? | 752 | * @param ignore_currently_down transmit message even if not initialized? |
796 | */ | 753 | */ |
797 | static void | 754 | static void |
798 | trigger_next_request (struct GNUNET_CORE_Handle *h, | 755 | trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down) |
799 | int ignore_currently_down) | ||
800 | { | 756 | { |
801 | uint16_t msize; | 757 | uint16_t msize; |
802 | 758 | ||
803 | if ( (GNUNET_YES == h->currently_down) && | 759 | if ((GNUNET_YES == h->currently_down) && (ignore_currently_down == GNUNET_NO)) |
804 | (ignore_currently_down == GNUNET_NO) ) | 760 | { |
805 | { | ||
806 | #if DEBUG_CORE | 761 | #if DEBUG_CORE |
807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 762 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
808 | "Core connection down, not processing queue\n"); | 763 | "Core connection down, not processing queue\n"); |
809 | #endif | 764 | #endif |
810 | return; | 765 | return; |
811 | } | 766 | } |
812 | if (NULL != h->cth) | 767 | if (NULL != h->cth) |
813 | { | 768 | { |
814 | #if DEBUG_CORE | 769 | #if DEBUG_CORE |
815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
816 | "Request pending, not processing queue\n"); | 771 | "Request pending, not processing queue\n"); |
817 | #endif | 772 | #endif |
818 | return; | 773 | return; |
819 | } | 774 | } |
820 | if (h->control_pending_head != NULL) | 775 | if (h->control_pending_head != NULL) |
821 | msize = ntohs (((struct GNUNET_MessageHeader*) &h->control_pending_head[1])->size); | 776 | msize = |
822 | else if (h->ready_peer_head != NULL) | 777 | ntohs (((struct GNUNET_MessageHeader *) &h-> |
823 | msize = h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); | 778 | control_pending_head[1])->size); |
779 | else if (h->ready_peer_head != NULL) | ||
780 | msize = | ||
781 | h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); | ||
824 | else | 782 | else |
825 | { | 783 | { |
826 | #if DEBUG_CORE | 784 | #if DEBUG_CORE |
827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
828 | "Request queue empty, not processing queue\n"); | 786 | "Request queue empty, not processing queue\n"); |
829 | #endif | 787 | #endif |
830 | return; /* no pending message */ | 788 | return; /* no pending message */ |
831 | } | 789 | } |
832 | h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client, | 790 | h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client, |
833 | msize, | 791 | msize, |
834 | GNUNET_TIME_UNIT_FOREVER_REL, | 792 | GNUNET_TIME_UNIT_FOREVER_REL, |
835 | GNUNET_NO, | 793 | GNUNET_NO, |
836 | &transmit_message, h); | 794 | &transmit_message, h); |
837 | } | 795 | } |
838 | 796 | ||
839 | 797 | ||
@@ -844,8 +802,7 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, | |||
844 | * @param msg the message received from the core service | 802 | * @param msg the message received from the core service |
845 | */ | 803 | */ |
846 | static void | 804 | static void |
847 | main_notify_handler (void *cls, | 805 | main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
848 | const struct GNUNET_MessageHeader *msg) | ||
849 | { | 806 | { |
850 | struct GNUNET_CORE_Handle *h = cls; | 807 | struct GNUNET_CORE_Handle *h = cls; |
851 | const struct InitReplyMessage *m; | 808 | const struct InitReplyMessage *m; |
@@ -868,13 +825,13 @@ main_notify_handler (void *cls, | |||
868 | uint32_t ats_count; | 825 | uint32_t ats_count; |
869 | 826 | ||
870 | if (msg == NULL) | 827 | if (msg == NULL) |
871 | { | 828 | { |
872 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 829 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
873 | _ | 830 | _ |
874 | ("Client was disconnected from core service, trying to reconnect.\n")); | 831 | ("Client was disconnected from core service, trying to reconnect.\n")); |
875 | reconnect_later (h); | 832 | reconnect_later (h); |
876 | return; | 833 | return; |
877 | } | 834 | } |
878 | msize = ntohs (msg->size); | 835 | msize = ntohs (msg->size); |
879 | #if DEBUG_CORE > 2 | 836 | #if DEBUG_CORE > 2 |
880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -882,425 +839,401 @@ main_notify_handler (void *cls, | |||
882 | ntohs (msg->type), msize); | 839 | ntohs (msg->type), msize); |
883 | #endif | 840 | #endif |
884 | switch (ntohs (msg->type)) | 841 | switch (ntohs (msg->type)) |
842 | { | ||
843 | case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY: | ||
844 | if (ntohs (msg->size) != sizeof (struct InitReplyMessage)) | ||
885 | { | 845 | { |
886 | case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY: | 846 | GNUNET_break (0); |
887 | if (ntohs (msg->size) != sizeof (struct InitReplyMessage)) | 847 | reconnect_later (h); |
888 | { | 848 | return; |
889 | GNUNET_break (0); | 849 | } |
890 | reconnect_later (h); | 850 | m = (const struct InitReplyMessage *) msg; |
891 | return; | 851 | GNUNET_break (0 == ntohl (m->reserved)); |
892 | } | 852 | /* start our message processing loop */ |
893 | m = (const struct InitReplyMessage *) msg; | 853 | if (GNUNET_YES == h->currently_down) |
894 | GNUNET_break (0 == ntohl (m->reserved)); | 854 | { |
895 | /* start our message processing loop */ | 855 | h->currently_down = GNUNET_NO; |
896 | if (GNUNET_YES == h->currently_down) | 856 | trigger_next_request (h, GNUNET_NO); |
897 | { | 857 | } |
898 | h->currently_down = GNUNET_NO; | 858 | h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
899 | trigger_next_request (h, GNUNET_NO); | 859 | GNUNET_CRYPTO_hash (&m->publicKey, |
900 | } | 860 | sizeof (struct |
901 | h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 861 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
902 | GNUNET_CRYPTO_hash (&m->publicKey, | 862 | &h->me.hashPubKey); |
903 | sizeof (struct | 863 | if (NULL != (init = h->init)) |
904 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 864 | { |
905 | &h->me.hashPubKey); | 865 | /* mark so we don't call init on reconnect */ |
906 | if (NULL != (init = h->init)) | 866 | h->init = NULL; |
907 | { | ||
908 | /* mark so we don't call init on reconnect */ | ||
909 | h->init = NULL; | ||
910 | #if DEBUG_CORE | 867 | #if DEBUG_CORE |
911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
912 | "Connected to core service of peer `%s'.\n", | 869 | "Connected to core service of peer `%s'.\n", |
913 | GNUNET_i2s (&h->me)); | 870 | GNUNET_i2s (&h->me)); |
914 | #endif | 871 | #endif |
915 | init (h->cls, h, &h->me, &m->publicKey); | 872 | init (h->cls, h, &h->me, &m->publicKey); |
916 | } | 873 | } |
917 | else | 874 | else |
918 | { | 875 | { |
919 | #if DEBUG_CORE | 876 | #if DEBUG_CORE |
920 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 877 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
921 | "Successfully reconnected to core service.\n"); | 878 | "Successfully reconnected to core service.\n"); |
922 | #endif | 879 | #endif |
923 | } | 880 | } |
924 | /* fake 'connect to self' */ | 881 | /* fake 'connect to self' */ |
925 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 882 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &h->me.hashPubKey); |
926 | &h->me.hashPubKey); | 883 | GNUNET_assert (pr == NULL); |
927 | GNUNET_assert (pr == NULL); | 884 | pr = GNUNET_malloc (sizeof (struct PeerRecord)); |
928 | pr = GNUNET_malloc (sizeof (struct PeerRecord)); | 885 | pr->peer = h->me; |
929 | pr->peer = h->me; | 886 | pr->ch = h; |
930 | pr->ch = h; | 887 | GNUNET_assert (GNUNET_YES == |
931 | GNUNET_assert (GNUNET_YES == | 888 | GNUNET_CONTAINER_multihashmap_put (h->peers, |
932 | GNUNET_CONTAINER_multihashmap_put (h->peers, | 889 | &h->me.hashPubKey, |
933 | &h->me.hashPubKey, | 890 | pr, |
934 | pr, | 891 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
935 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 892 | if (NULL != h->connects) |
936 | if (NULL != h->connects) | 893 | h->connects (h->cls, &h->me, NULL); |
937 | h->connects (h->cls, | 894 | break; |
938 | &h->me, | 895 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT: |
939 | NULL); | 896 | if (msize < sizeof (struct ConnectNotifyMessage)) |
940 | break; | 897 | { |
941 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT: | 898 | GNUNET_break (0); |
942 | if (msize < sizeof (struct ConnectNotifyMessage)) | 899 | reconnect_later (h); |
943 | { | 900 | return; |
944 | GNUNET_break (0); | 901 | } |
945 | reconnect_later (h); | 902 | cnm = (const struct ConnectNotifyMessage *) msg; |
946 | return; | 903 | ats_count = ntohl (cnm->ats_count); |
947 | } | 904 | if ((msize != |
948 | cnm = (const struct ConnectNotifyMessage *) msg; | 905 | sizeof (struct ConnectNotifyMessage) + |
949 | ats_count = ntohl (cnm->ats_count); | 906 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || |
950 | if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || | 907 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != |
951 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&cnm->ats)[ats_count].type)) ) | 908 | ntohl ((&cnm->ats)[ats_count].type))) |
952 | { | 909 | { |
953 | GNUNET_break (0); | 910 | GNUNET_break (0); |
954 | reconnect_later (h); | 911 | reconnect_later (h); |
955 | return; | 912 | return; |
956 | } | 913 | } |
957 | #if DEBUG_CORE | 914 | #if DEBUG_CORE |
958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
959 | "Received notification about connection from `%s'.\n", | 916 | "Received notification about connection from `%s'.\n", |
960 | GNUNET_i2s (&cnm->peer)); | 917 | GNUNET_i2s (&cnm->peer)); |
961 | #endif | 918 | #endif |
962 | if (0 == memcmp (&h->me, | 919 | if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity))) |
963 | &cnm->peer, | 920 | { |
964 | sizeof (struct GNUNET_PeerIdentity))) | 921 | /* connect to self!? */ |
965 | { | 922 | GNUNET_break (0); |
966 | /* connect to self!? */ | 923 | return; |
967 | GNUNET_break (0); | 924 | } |
968 | return; | 925 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cnm->peer.hashPubKey); |
969 | } | 926 | if (pr != NULL) |
970 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 927 | { |
971 | &cnm->peer.hashPubKey); | 928 | GNUNET_break (0); |
972 | if (pr != NULL) | 929 | reconnect_later (h); |
973 | { | 930 | return; |
974 | GNUNET_break (0); | 931 | } |
975 | reconnect_later (h); | 932 | pr = GNUNET_malloc (sizeof (struct PeerRecord)); |
976 | return; | 933 | pr->peer = cnm->peer; |
977 | } | 934 | pr->ch = h; |
978 | pr = GNUNET_malloc (sizeof (struct PeerRecord)); | 935 | GNUNET_assert (GNUNET_YES == |
979 | pr->peer = cnm->peer; | 936 | GNUNET_CONTAINER_multihashmap_put (h->peers, |
980 | pr->ch = h; | 937 | &cnm->peer.hashPubKey, |
981 | GNUNET_assert (GNUNET_YES == | 938 | pr, |
982 | GNUNET_CONTAINER_multihashmap_put (h->peers, | 939 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
983 | &cnm->peer.hashPubKey, | 940 | if (NULL != h->connects) |
984 | pr, | 941 | h->connects (h->cls, &cnm->peer, &cnm->ats); |
985 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 942 | break; |
986 | if (NULL != h->connects) | 943 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT: |
987 | h->connects (h->cls, | 944 | if (msize != sizeof (struct DisconnectNotifyMessage)) |
988 | &cnm->peer, | 945 | { |
989 | &cnm->ats); | 946 | GNUNET_break (0); |
990 | break; | 947 | reconnect_later (h); |
991 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT: | 948 | return; |
992 | if (msize != sizeof (struct DisconnectNotifyMessage)) | 949 | } |
993 | { | 950 | dnm = (const struct DisconnectNotifyMessage *) msg; |
994 | GNUNET_break (0); | 951 | if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity))) |
995 | reconnect_later (h); | 952 | { |
996 | return; | 953 | /* connection to self!? */ |
997 | } | 954 | GNUNET_break (0); |
998 | dnm = (const struct DisconnectNotifyMessage *) msg; | 955 | return; |
999 | if (0 == memcmp (&h->me, | 956 | } |
1000 | &dnm->peer, | 957 | GNUNET_break (0 == ntohl (dnm->reserved)); |
1001 | sizeof (struct GNUNET_PeerIdentity))) | ||
1002 | { | ||
1003 | /* connection to self!? */ | ||
1004 | GNUNET_break (0); | ||
1005 | return; | ||
1006 | } | ||
1007 | GNUNET_break (0 == ntohl (dnm->reserved)); | ||
1008 | #if DEBUG_CORE | 958 | #if DEBUG_CORE |
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1010 | "Received notification about disconnect from `%s'.\n", | 960 | "Received notification about disconnect from `%s'.\n", |
1011 | GNUNET_i2s (&dnm->peer)); | 961 | GNUNET_i2s (&dnm->peer)); |
1012 | #endif | 962 | #endif |
1013 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 963 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &dnm->peer.hashPubKey); |
1014 | &dnm->peer.hashPubKey); | 964 | if (pr == NULL) |
1015 | if (pr == NULL) | 965 | { |
1016 | { | 966 | GNUNET_break (0); |
1017 | GNUNET_break (0); | 967 | reconnect_later (h); |
1018 | reconnect_later (h); | 968 | return; |
1019 | return; | 969 | } |
1020 | } | 970 | trigger = ((pr->prev != NULL) || |
1021 | trigger = ( (pr->prev != NULL) || | 971 | (pr->next != NULL) || (h->ready_peer_head == pr)); |
1022 | (pr->next != NULL) || | 972 | disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr); |
1023 | (h->ready_peer_head == pr) ); | 973 | if (trigger) |
1024 | disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr); | 974 | trigger_next_request (h, GNUNET_NO); |
1025 | if (trigger) | 975 | break; |
1026 | trigger_next_request (h, GNUNET_NO); | 976 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE: |
1027 | break; | 977 | if (NULL == h->status_events) |
1028 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE: | 978 | { |
1029 | if (NULL == h->status_events) | 979 | GNUNET_break (0); |
1030 | { | 980 | return; |
1031 | GNUNET_break (0); | 981 | } |
1032 | return; | 982 | if (msize < sizeof (struct PeerStatusNotifyMessage)) |
1033 | } | 983 | { |
1034 | if (msize < sizeof (struct PeerStatusNotifyMessage)) | 984 | GNUNET_break (0); |
1035 | { | 985 | reconnect_later (h); |
1036 | GNUNET_break (0); | 986 | return; |
1037 | reconnect_later (h); | 987 | } |
1038 | return; | 988 | psnm = (const struct PeerStatusNotifyMessage *) msg; |
1039 | } | 989 | if (0 == memcmp (&h->me, &psnm->peer, sizeof (struct GNUNET_PeerIdentity))) |
1040 | psnm = (const struct PeerStatusNotifyMessage *) msg; | 990 | { |
1041 | if (0 == memcmp (&h->me, | 991 | /* self-change!? */ |
1042 | &psnm->peer, | 992 | GNUNET_break (0); |
1043 | sizeof (struct GNUNET_PeerIdentity))) | 993 | return; |
1044 | { | 994 | } |
1045 | /* self-change!? */ | 995 | ats_count = ntohl (psnm->ats_count); |
1046 | GNUNET_break (0); | 996 | if ((msize != |
1047 | return; | 997 | sizeof (struct PeerStatusNotifyMessage) + |
1048 | } | 998 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || |
1049 | ats_count = ntohl (psnm->ats_count); | 999 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != |
1050 | if ( (msize != sizeof (struct PeerStatusNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || | 1000 | ntohl ((&psnm->ats)[ats_count].type))) |
1051 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&psnm->ats)[ats_count].type)) ) | 1001 | { |
1052 | { | 1002 | GNUNET_break (0); |
1053 | GNUNET_break (0); | 1003 | reconnect_later (h); |
1054 | reconnect_later (h); | 1004 | return; |
1055 | return; | 1005 | } |
1056 | } | ||
1057 | #if DEBUG_CORE > 1 | 1006 | #if DEBUG_CORE > 1 |
1058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1059 | "Received notification about status change by `%s'.\n", | 1008 | "Received notification about status change by `%s'.\n", |
1060 | GNUNET_i2s (&psnm->peer)); | 1009 | GNUNET_i2s (&psnm->peer)); |
1061 | #endif | 1010 | #endif |
1062 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 1011 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &psnm->peer.hashPubKey); |
1063 | &psnm->peer.hashPubKey); | 1012 | if (pr == NULL) |
1064 | if (pr == NULL) | 1013 | { |
1065 | { | 1014 | GNUNET_break (0); |
1066 | GNUNET_break (0); | 1015 | reconnect_later (h); |
1067 | reconnect_later (h); | 1016 | return; |
1068 | return; | 1017 | } |
1069 | } | 1018 | h->status_events (h->cls, |
1070 | h->status_events (h->cls, | 1019 | &psnm->peer, |
1071 | &psnm->peer, | 1020 | psnm->bandwidth_in, |
1072 | psnm->bandwidth_in, | 1021 | psnm->bandwidth_out, |
1073 | psnm->bandwidth_out, | 1022 | GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats); |
1074 | GNUNET_TIME_absolute_ntoh (psnm->timeout), | 1023 | break; |
1075 | &psnm->ats); | 1024 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND: |
1076 | break; | 1025 | if (msize < sizeof (struct NotifyTrafficMessage)) |
1077 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND: | 1026 | { |
1078 | if (msize < sizeof (struct NotifyTrafficMessage)) | 1027 | GNUNET_break (0); |
1079 | { | 1028 | reconnect_later (h); |
1080 | GNUNET_break (0); | 1029 | return; |
1081 | reconnect_later (h); | 1030 | } |
1082 | return; | 1031 | ntm = (const struct NotifyTrafficMessage *) msg; |
1083 | } | 1032 | |
1084 | ntm = (const struct NotifyTrafficMessage *) msg; | 1033 | ats_count = ntohl (ntm->ats_count); |
1085 | 1034 | if ((msize < | |
1086 | ats_count = ntohl (ntm->ats_count); | 1035 | sizeof (struct NotifyTrafficMessage) + |
1087 | if ( (msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) | 1036 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + |
1088 | + sizeof (struct GNUNET_MessageHeader)) || | 1037 | sizeof (struct GNUNET_MessageHeader)) || |
1089 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)) ) | 1038 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != |
1090 | { | 1039 | ntohl ((&ntm->ats)[ats_count].type))) |
1091 | GNUNET_break (0); | 1040 | { |
1092 | reconnect_later (h); | 1041 | GNUNET_break (0); |
1093 | return; | 1042 | reconnect_later (h); |
1094 | } | 1043 | return; |
1095 | em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count+1]; | 1044 | } |
1045 | em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1]; | ||
1096 | #if DEBUG_CORE | 1046 | #if DEBUG_CORE |
1097 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1047 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1098 | "Received message of type %u and size %u from peer `%4s'\n", | 1048 | "Received message of type %u and size %u from peer `%4s'\n", |
1099 | ntohs (em->type), | 1049 | ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer)); |
1100 | ntohs (em->size), | ||
1101 | GNUNET_i2s (&ntm->peer)); | ||
1102 | #endif | 1050 | #endif |
1103 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 1051 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); |
1104 | &ntm->peer.hashPubKey); | 1052 | if (pr == NULL) |
1105 | if (pr == NULL) | 1053 | { |
1106 | { | 1054 | GNUNET_break (0); |
1107 | GNUNET_break (0); | 1055 | reconnect_later (h); |
1108 | reconnect_later (h); | 1056 | return; |
1109 | return; | 1057 | } |
1110 | } | 1058 | if ((GNUNET_NO == h->inbound_hdr_only) && |
1111 | if ((GNUNET_NO == h->inbound_hdr_only) && | 1059 | (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + |
1112 | (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + | 1060 | +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))) |
1113 | + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ) | 1061 | { |
1114 | { | 1062 | GNUNET_break (0); |
1115 | GNUNET_break (0); | 1063 | reconnect_later (h); |
1116 | reconnect_later (h); | 1064 | return; |
1117 | return; | 1065 | } |
1118 | } | 1066 | et = ntohs (em->type); |
1119 | et = ntohs (em->type); | 1067 | for (hpos = 0; hpos < h->hcnt; hpos++) |
1120 | for (hpos = 0; hpos < h->hcnt; hpos++) | 1068 | { |
1121 | { | 1069 | mh = &h->handlers[hpos]; |
1122 | mh = &h->handlers[hpos]; | 1070 | if (mh->type != et) |
1123 | if (mh->type != et) | 1071 | continue; |
1124 | continue; | 1072 | if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0)) |
1125 | if ((mh->expected_size != ntohs (em->size)) && | 1073 | { |
1126 | (mh->expected_size != 0)) | 1074 | GNUNET_break (0); |
1127 | { | 1075 | continue; |
1128 | GNUNET_break (0); | 1076 | } |
1129 | continue; | 1077 | if (GNUNET_OK != |
1130 | } | 1078 | h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats)) |
1131 | if (GNUNET_OK != | 1079 | { |
1132 | h->handlers[hpos].callback (h->cls, &ntm->peer, em, | 1080 | /* error in processing, do not process other messages! */ |
1133 | &ntm->ats)) | 1081 | break; |
1134 | { | 1082 | } |
1135 | /* error in processing, do not process other messages! */ | 1083 | } |
1136 | break; | 1084 | if (NULL != h->inbound_notify) |
1137 | } | 1085 | h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats); |
1138 | } | 1086 | break; |
1139 | if (NULL != h->inbound_notify) | 1087 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND: |
1140 | h->inbound_notify (h->cls, &ntm->peer, em, | 1088 | if (msize < sizeof (struct NotifyTrafficMessage)) |
1141 | &ntm->ats); | 1089 | { |
1142 | break; | 1090 | GNUNET_break (0); |
1143 | case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND: | 1091 | reconnect_later (h); |
1144 | if (msize < sizeof (struct NotifyTrafficMessage)) | 1092 | return; |
1145 | { | 1093 | } |
1146 | GNUNET_break (0); | 1094 | ntm = (const struct NotifyTrafficMessage *) msg; |
1147 | reconnect_later (h); | 1095 | if (0 == memcmp (&h->me, &ntm->peer, sizeof (struct GNUNET_PeerIdentity))) |
1148 | return; | 1096 | { |
1149 | } | 1097 | /* self-change!? */ |
1150 | ntm = (const struct NotifyTrafficMessage *) msg; | 1098 | GNUNET_break (0); |
1151 | if (0 == memcmp (&h->me, | 1099 | return; |
1152 | &ntm->peer, | 1100 | } |
1153 | sizeof (struct GNUNET_PeerIdentity))) | 1101 | ats_count = ntohl (ntm->ats_count); |
1154 | { | 1102 | if ((msize < |
1155 | /* self-change!? */ | 1103 | sizeof (struct NotifyTrafficMessage) + |
1156 | GNUNET_break (0); | 1104 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + |
1157 | return; | 1105 | sizeof (struct GNUNET_MessageHeader)) || |
1158 | } | 1106 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != |
1159 | ats_count = ntohl (ntm->ats_count); | 1107 | ntohl ((&ntm->ats)[ats_count].type))) |
1160 | if ( (msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) | 1108 | { |
1161 | + sizeof (struct GNUNET_MessageHeader)) || | 1109 | GNUNET_break (0); |
1162 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)) ) | 1110 | reconnect_later (h); |
1163 | { | 1111 | return; |
1164 | GNUNET_break (0); | 1112 | } |
1165 | reconnect_later (h); | 1113 | em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1]; |
1166 | return; | 1114 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); |
1167 | } | 1115 | if (pr == NULL) |
1168 | em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count+1]; | 1116 | { |
1169 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 1117 | GNUNET_break (0); |
1170 | &ntm->peer.hashPubKey); | 1118 | reconnect_later (h); |
1171 | if (pr == NULL) | 1119 | return; |
1172 | { | 1120 | } |
1173 | GNUNET_break (0); | ||
1174 | reconnect_later (h); | ||
1175 | return; | ||
1176 | } | ||
1177 | #if DEBUG_CORE | 1121 | #if DEBUG_CORE |
1178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1179 | "Received notification about transmission to `%s'.\n", | 1123 | "Received notification about transmission to `%s'.\n", |
1180 | GNUNET_i2s (&ntm->peer)); | 1124 | GNUNET_i2s (&ntm->peer)); |
1181 | #endif | 1125 | #endif |
1182 | if ((GNUNET_NO == h->outbound_hdr_only) && | 1126 | if ((GNUNET_NO == h->outbound_hdr_only) && |
1183 | (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) | 1127 | (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) |
1184 | + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ) | 1128 | + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))) |
1185 | { | 1129 | { |
1186 | GNUNET_break (0); | 1130 | GNUNET_break (0); |
1187 | reconnect_later (h); | 1131 | reconnect_later (h); |
1188 | return; | 1132 | return; |
1189 | } | 1133 | } |
1190 | if (NULL == h->outbound_notify) | 1134 | if (NULL == h->outbound_notify) |
1191 | { | 1135 | { |
1192 | GNUNET_break (0); | 1136 | GNUNET_break (0); |
1193 | break; | ||
1194 | } | ||
1195 | h->outbound_notify (h->cls, &ntm->peer, em, | ||
1196 | &ntm->ats); | ||
1197 | break; | 1137 | break; |
1198 | case GNUNET_MESSAGE_TYPE_CORE_SEND_READY: | 1138 | } |
1199 | if (msize != sizeof (struct SendMessageReady)) | 1139 | h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats); |
1200 | { | 1140 | break; |
1201 | GNUNET_break (0); | 1141 | case GNUNET_MESSAGE_TYPE_CORE_SEND_READY: |
1202 | reconnect_later (h); | 1142 | if (msize != sizeof (struct SendMessageReady)) |
1203 | return; | 1143 | { |
1204 | } | 1144 | GNUNET_break (0); |
1205 | smr = (const struct SendMessageReady *) msg; | 1145 | reconnect_later (h); |
1206 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 1146 | return; |
1207 | &smr->peer.hashPubKey); | 1147 | } |
1208 | if (pr == NULL) | 1148 | smr = (const struct SendMessageReady *) msg; |
1209 | { | 1149 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &smr->peer.hashPubKey); |
1210 | GNUNET_break (0); | 1150 | if (pr == NULL) |
1211 | reconnect_later (h); | 1151 | { |
1212 | return; | 1152 | GNUNET_break (0); |
1213 | } | 1153 | reconnect_later (h); |
1154 | return; | ||
1155 | } | ||
1214 | #if DEBUG_CORE | 1156 | #if DEBUG_CORE |
1215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1216 | "Received notification about transmission readiness to `%s'.\n", | 1158 | "Received notification about transmission readiness to `%s'.\n", |
1217 | GNUNET_i2s (&smr->peer)); | 1159 | GNUNET_i2s (&smr->peer)); |
1218 | #endif | 1160 | #endif |
1219 | if (pr->pending_head == NULL) | 1161 | if (pr->pending_head == NULL) |
1220 | { | 1162 | { |
1221 | /* request must have been cancelled between the original request | 1163 | /* request must have been cancelled between the original request |
1222 | and the response from core, ignore core's readiness */ | 1164 | * and the response from core, ignore core's readiness */ |
1223 | break; | 1165 | break; |
1224 | } | 1166 | } |
1225 | 1167 | ||
1226 | th = pr->pending_head; | 1168 | th = pr->pending_head; |
1227 | if (ntohs (smr->smr_id) != th->smr_id) | 1169 | if (ntohs (smr->smr_id) != th->smr_id) |
1228 | { | 1170 | { |
1229 | /* READY message is for expired or cancelled message, | 1171 | /* READY message is for expired or cancelled message, |
1230 | ignore! (we should have already sent another request) */ | 1172 | * ignore! (we should have already sent another request) */ |
1231 | break; | ||
1232 | } | ||
1233 | if ( (pr->prev != NULL) || | ||
1234 | (pr->next != NULL) || | ||
1235 | (h->ready_peer_head == pr) ) | ||
1236 | { | ||
1237 | /* we should not already be on the ready list... */ | ||
1238 | GNUNET_break (0); | ||
1239 | reconnect_later (h); | ||
1240 | return; | ||
1241 | } | ||
1242 | GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, | ||
1243 | h->ready_peer_tail, | ||
1244 | pr); | ||
1245 | trigger_next_request (h, GNUNET_NO); | ||
1246 | break; | 1173 | break; |
1247 | case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO: | 1174 | } |
1248 | if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage)) | 1175 | if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr)) |
1249 | { | 1176 | { |
1250 | GNUNET_break (0); | 1177 | /* we should not already be on the ready list... */ |
1251 | reconnect_later (h); | 1178 | GNUNET_break (0); |
1252 | return; | 1179 | reconnect_later (h); |
1253 | } | 1180 | return; |
1254 | cim = (const struct ConfigurationInfoMessage*) msg; | 1181 | } |
1255 | if (0 == memcmp (&h->me, | 1182 | GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, h->ready_peer_tail, pr); |
1256 | &cim->peer, | 1183 | trigger_next_request (h, GNUNET_NO); |
1257 | sizeof (struct GNUNET_PeerIdentity))) | 1184 | break; |
1258 | { | 1185 | case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO: |
1259 | /* self-change!? */ | 1186 | if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage)) |
1260 | GNUNET_break (0); | 1187 | { |
1261 | return; | 1188 | GNUNET_break (0); |
1262 | } | 1189 | reconnect_later (h); |
1190 | return; | ||
1191 | } | ||
1192 | cim = (const struct ConfigurationInfoMessage *) msg; | ||
1193 | if (0 == memcmp (&h->me, &cim->peer, sizeof (struct GNUNET_PeerIdentity))) | ||
1194 | { | ||
1195 | /* self-change!? */ | ||
1196 | GNUNET_break (0); | ||
1197 | return; | ||
1198 | } | ||
1263 | #if DEBUG_CORE | 1199 | #if DEBUG_CORE |
1264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1265 | "Received notification about configuration update for `%s' with RIM %u.\n", | 1201 | "Received notification about configuration update for `%s' with RIM %u.\n", |
1266 | GNUNET_i2s (&cim->peer), | 1202 | GNUNET_i2s (&cim->peer), (unsigned int) ntohl (cim->rim_id)); |
1267 | (unsigned int) ntohl (cim->rim_id)); | ||
1268 | #endif | 1203 | #endif |
1269 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 1204 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cim->peer.hashPubKey); |
1270 | &cim->peer.hashPubKey); | 1205 | if (pr == NULL) |
1271 | if (pr == NULL) | 1206 | { |
1272 | { | 1207 | GNUNET_break (0); |
1273 | GNUNET_break (0); | 1208 | reconnect_later (h); |
1274 | reconnect_later (h); | 1209 | return; |
1275 | return; | 1210 | } |
1276 | } | 1211 | if (pr->rim_id != ntohl (cim->rim_id)) |
1277 | if (pr->rim_id != ntohl (cim->rim_id)) | 1212 | { |
1278 | { | ||
1279 | #if DEBUG_CORE | 1213 | #if DEBUG_CORE |
1280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1281 | "Reservation ID mismatch in notification...\n"); | 1215 | "Reservation ID mismatch in notification...\n"); |
1282 | #endif | 1216 | #endif |
1283 | break; | ||
1284 | } | ||
1285 | pcic = pr->pcic; | ||
1286 | pr->pcic = NULL; | ||
1287 | GNUNET_free_non_null (pr->pcic_ptr); | ||
1288 | pr->pcic_ptr = NULL; | ||
1289 | if (pcic != NULL) | ||
1290 | pcic (pr->pcic_cls, | ||
1291 | &pr->peer, | ||
1292 | cim->bw_out, | ||
1293 | ntohl (cim->reserved_amount), | ||
1294 | GNUNET_TIME_relative_ntoh (cim->reserve_delay), | ||
1295 | GNUNET_ntohll (cim->preference)); | ||
1296 | break; | 1217 | break; |
1297 | default: | ||
1298 | reconnect_later (h); | ||
1299 | return; | ||
1300 | } | 1218 | } |
1219 | pcic = pr->pcic; | ||
1220 | pr->pcic = NULL; | ||
1221 | GNUNET_free_non_null (pr->pcic_ptr); | ||
1222 | pr->pcic_ptr = NULL; | ||
1223 | if (pcic != NULL) | ||
1224 | pcic (pr->pcic_cls, | ||
1225 | &pr->peer, | ||
1226 | cim->bw_out, | ||
1227 | ntohl (cim->reserved_amount), | ||
1228 | GNUNET_TIME_relative_ntoh (cim->reserve_delay), | ||
1229 | GNUNET_ntohll (cim->preference)); | ||
1230 | break; | ||
1231 | default: | ||
1232 | reconnect_later (h); | ||
1233 | return; | ||
1234 | } | ||
1301 | GNUNET_CLIENT_receive (h->client, | 1235 | GNUNET_CLIENT_receive (h->client, |
1302 | &main_notify_handler, h, | 1236 | &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); |
1303 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1304 | } | 1237 | } |
1305 | 1238 | ||
1306 | 1239 | ||
@@ -1312,27 +1245,24 @@ main_notify_handler (void *cls, | |||
1312 | * @param success were we successful | 1245 | * @param success were we successful |
1313 | */ | 1246 | */ |
1314 | static void | 1247 | static void |
1315 | init_done_task (void *cls, | 1248 | init_done_task (void *cls, int success) |
1316 | int success) | ||
1317 | { | 1249 | { |
1318 | struct GNUNET_CORE_Handle *h = cls; | 1250 | struct GNUNET_CORE_Handle *h = cls; |
1319 | 1251 | ||
1320 | if (success == GNUNET_SYSERR) | 1252 | if (success == GNUNET_SYSERR) |
1321 | return; /* shutdown */ | 1253 | return; /* shutdown */ |
1322 | if (success == GNUNET_NO) | 1254 | if (success == GNUNET_NO) |
1323 | { | 1255 | { |
1324 | #if DEBUG_CORE | 1256 | #if DEBUG_CORE |
1325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1326 | "Failed to exchange INIT with core, retrying\n"); | 1258 | "Failed to exchange INIT with core, retrying\n"); |
1327 | #endif | 1259 | #endif |
1328 | if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK) | 1260 | if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK) |
1329 | reconnect_later (h); | 1261 | reconnect_later (h); |
1330 | return; | 1262 | return; |
1331 | } | 1263 | } |
1332 | GNUNET_CLIENT_receive (h->client, | 1264 | GNUNET_CLIENT_receive (h->client, |
1333 | &main_notify_handler, | 1265 | &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); |
1334 | h, | ||
1335 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1336 | } | 1266 | } |
1337 | 1267 | ||
1338 | 1268 | ||
@@ -1353,49 +1283,46 @@ reconnect (struct GNUNET_CORE_Handle *h) | |||
1353 | unsigned int hpos; | 1283 | unsigned int hpos; |
1354 | 1284 | ||
1355 | #if DEBUG_CORE | 1285 | #if DEBUG_CORE |
1356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to CORE service\n"); |
1357 | "Reconnecting to CORE service\n"); | ||
1358 | #endif | 1287 | #endif |
1359 | GNUNET_assert (h->client == NULL); | 1288 | GNUNET_assert (h->client == NULL); |
1360 | GNUNET_assert (h->currently_down == GNUNET_YES); | 1289 | GNUNET_assert (h->currently_down == GNUNET_YES); |
1361 | h->client = GNUNET_CLIENT_connect ("core", h->cfg); | 1290 | h->client = GNUNET_CLIENT_connect ("core", h->cfg); |
1362 | if (h->client == NULL) | 1291 | if (h->client == NULL) |
1363 | { | 1292 | { |
1364 | reconnect_later (h); | 1293 | reconnect_later (h); |
1365 | return; | 1294 | return; |
1366 | } | 1295 | } |
1367 | msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage); | 1296 | msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage); |
1368 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + | 1297 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + msize); |
1369 | msize); | ||
1370 | cm->cont = &init_done_task; | 1298 | cm->cont = &init_done_task; |
1371 | cm->cont_cls = h; | 1299 | cm->cont_cls = h; |
1372 | init = (struct InitMessage*) &cm[1]; | 1300 | init = (struct InitMessage *) &cm[1]; |
1373 | init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT); | 1301 | init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT); |
1374 | init->header.size = htons (msize); | 1302 | init->header.size = htons (msize); |
1375 | opt = GNUNET_CORE_OPTION_SEND_CONNECT | GNUNET_CORE_OPTION_SEND_DISCONNECT; | 1303 | opt = GNUNET_CORE_OPTION_SEND_CONNECT | GNUNET_CORE_OPTION_SEND_DISCONNECT; |
1376 | if (h->status_events != NULL) | 1304 | if (h->status_events != NULL) |
1377 | opt |= GNUNET_CORE_OPTION_SEND_STATUS_CHANGE; | 1305 | opt |= GNUNET_CORE_OPTION_SEND_STATUS_CHANGE; |
1378 | if (h->inbound_notify != NULL) | 1306 | if (h->inbound_notify != NULL) |
1379 | { | 1307 | { |
1380 | if (h->inbound_hdr_only) | 1308 | if (h->inbound_hdr_only) |
1381 | opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND; | 1309 | opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND; |
1382 | else | 1310 | else |
1383 | opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND; | 1311 | opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND; |
1384 | } | 1312 | } |
1385 | if (h->outbound_notify != NULL) | 1313 | if (h->outbound_notify != NULL) |
1386 | { | 1314 | { |
1387 | if (h->outbound_hdr_only) | 1315 | if (h->outbound_hdr_only) |
1388 | opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND; | 1316 | opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND; |
1389 | else | 1317 | else |
1390 | opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND; | 1318 | opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND; |
1391 | } | 1319 | } |
1392 | init->options = htonl (opt); | 1320 | init->options = htonl (opt); |
1393 | ts = (uint16_t *) &init[1]; | 1321 | ts = (uint16_t *) & init[1]; |
1394 | for (hpos = 0; hpos < h->hcnt; hpos++) | 1322 | for (hpos = 0; hpos < h->hcnt; hpos++) |
1395 | ts[hpos] = htons (h->handlers[hpos].type); | 1323 | ts[hpos] = htons (h->handlers[hpos].type); |
1396 | GNUNET_CONTAINER_DLL_insert (h->control_pending_head, | 1324 | GNUNET_CONTAINER_DLL_insert (h->control_pending_head, |
1397 | h->control_pending_tail, | 1325 | h->control_pending_tail, cm); |
1398 | cm); | ||
1399 | trigger_next_request (h, GNUNET_YES); | 1326 | trigger_next_request (h, GNUNET_YES); |
1400 | } | 1327 | } |
1401 | 1328 | ||
@@ -1427,12 +1354,12 @@ reconnect (struct GNUNET_CORE_Handle *h) | |||
1427 | */ | 1354 | */ |
1428 | struct GNUNET_CORE_Handle * | 1355 | struct GNUNET_CORE_Handle * |
1429 | GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1356 | GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1430 | unsigned int queue_size, | 1357 | unsigned int queue_size, |
1431 | void *cls, | 1358 | void *cls, |
1432 | GNUNET_CORE_StartupCallback init, | 1359 | GNUNET_CORE_StartupCallback init, |
1433 | GNUNET_CORE_ConnectEventHandler connects, | 1360 | GNUNET_CORE_ConnectEventHandler connects, |
1434 | GNUNET_CORE_DisconnectEventHandler disconnects, | 1361 | GNUNET_CORE_DisconnectEventHandler disconnects, |
1435 | GNUNET_CORE_PeerStatusEventHandler status_events, | 1362 | GNUNET_CORE_PeerStatusEventHandler status_events, |
1436 | GNUNET_CORE_MessageCallback inbound_notify, | 1363 | GNUNET_CORE_MessageCallback inbound_notify, |
1437 | int inbound_hdr_only, | 1364 | int inbound_hdr_only, |
1438 | GNUNET_CORE_MessageCallback outbound_notify, | 1365 | GNUNET_CORE_MessageCallback outbound_notify, |
@@ -1464,8 +1391,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1464 | (GNUNET_SERVER_MAX_MESSAGE_SIZE - | 1391 | (GNUNET_SERVER_MAX_MESSAGE_SIZE - |
1465 | sizeof (struct InitMessage)) / sizeof (uint16_t)); | 1392 | sizeof (struct InitMessage)) / sizeof (uint16_t)); |
1466 | #if DEBUG_CORE | 1393 | #if DEBUG_CORE |
1467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n"); |
1468 | "Connecting to CORE service\n"); | ||
1469 | #endif | 1395 | #endif |
1470 | reconnect (h); | 1396 | reconnect (h); |
1471 | return h; | 1397 | return h; |
@@ -1483,40 +1409,38 @@ void | |||
1483 | GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) | 1409 | GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) |
1484 | { | 1410 | { |
1485 | struct ControlMessage *cm; | 1411 | struct ControlMessage *cm; |
1486 | 1412 | ||
1487 | #if DEBUG_CORE | 1413 | #if DEBUG_CORE |
1488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n"); |
1489 | "Disconnecting from CORE service\n"); | ||
1490 | #endif | 1415 | #endif |
1491 | if (handle->cth != NULL) | 1416 | if (handle->cth != NULL) |
1492 | { | 1417 | { |
1493 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth); | 1418 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth); |
1494 | handle->cth = NULL; | 1419 | handle->cth = NULL; |
1495 | } | 1420 | } |
1496 | while (NULL != (cm = handle->control_pending_head)) | 1421 | while (NULL != (cm = handle->control_pending_head)) |
1497 | { | 1422 | { |
1498 | GNUNET_CONTAINER_DLL_remove (handle->control_pending_head, | 1423 | GNUNET_CONTAINER_DLL_remove (handle->control_pending_head, |
1499 | handle->control_pending_tail, | 1424 | handle->control_pending_tail, cm); |
1500 | cm); | 1425 | if (cm->th != NULL) |
1501 | if (cm->th != NULL) | 1426 | cm->th->cm = NULL; |
1502 | cm->th->cm = NULL; | 1427 | if (cm->cont != NULL) |
1503 | if (cm->cont != NULL) | 1428 | cm->cont (cm->cont_cls, GNUNET_SYSERR); |
1504 | cm->cont (cm->cont_cls, GNUNET_SYSERR); | 1429 | GNUNET_free (cm); |
1505 | GNUNET_free (cm); | 1430 | } |
1506 | } | ||
1507 | if (handle->client != NULL) | 1431 | if (handle->client != NULL) |
1508 | { | 1432 | { |
1509 | GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); | 1433 | GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); |
1510 | handle->client = NULL; | 1434 | handle->client = NULL; |
1511 | } | 1435 | } |
1512 | GNUNET_CONTAINER_multihashmap_iterate (handle->peers, | 1436 | GNUNET_CONTAINER_multihashmap_iterate (handle->peers, |
1513 | &disconnect_and_free_peer_entry, | 1437 | &disconnect_and_free_peer_entry, |
1514 | handle); | 1438 | handle); |
1515 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | 1439 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) |
1516 | { | 1440 | { |
1517 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 1441 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
1518 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1442 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
1519 | } | 1443 | } |
1520 | GNUNET_CONTAINER_multihashmap_destroy (handle->peers); | 1444 | GNUNET_CONTAINER_multihashmap_destroy (handle->peers); |
1521 | handle->peers = NULL; | 1445 | handle->peers = NULL; |
1522 | GNUNET_break (handle->ready_peer_head == NULL); | 1446 | GNUNET_break (handle->ready_peer_head == NULL); |
@@ -1532,7 +1456,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) | |||
1532 | */ | 1456 | */ |
1533 | static void | 1457 | static void |
1534 | run_request_next_transmission (void *cls, | 1458 | run_request_next_transmission (void *cls, |
1535 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1459 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1536 | { | 1460 | { |
1537 | struct PeerRecord *pr = cls; | 1461 | struct PeerRecord *pr = cls; |
1538 | 1462 | ||
@@ -1562,7 +1486,7 @@ run_request_next_transmission (void *cls, | |||
1562 | */ | 1486 | */ |
1563 | struct GNUNET_CORE_TransmitHandle * | 1487 | struct GNUNET_CORE_TransmitHandle * |
1564 | GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, | 1488 | GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, |
1565 | int cork, | 1489 | int cork, |
1566 | uint32_t priority, | 1490 | uint32_t priority, |
1567 | struct GNUNET_TIME_Relative maxdelay, | 1491 | struct GNUNET_TIME_Relative maxdelay, |
1568 | const struct GNUNET_PeerIdentity *target, | 1492 | const struct GNUNET_PeerIdentity *target, |
@@ -1576,22 +1500,21 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, | |||
1576 | struct GNUNET_CORE_TransmitHandle *prev; | 1500 | struct GNUNET_CORE_TransmitHandle *prev; |
1577 | struct GNUNET_CORE_TransmitHandle *minp; | 1501 | struct GNUNET_CORE_TransmitHandle *minp; |
1578 | 1502 | ||
1579 | pr = GNUNET_CONTAINER_multihashmap_get (handle->peers, | 1503 | pr = GNUNET_CONTAINER_multihashmap_get (handle->peers, &target->hashPubKey); |
1580 | &target->hashPubKey); | ||
1581 | if (NULL == pr) | 1504 | if (NULL == pr) |
1582 | { | 1505 | { |
1583 | /* attempt to send to peer that is not connected */ | 1506 | /* attempt to send to peer that is not connected */ |
1584 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1507 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1585 | "Attempting to send to peer `%s' from peer `%s', but not connected!\n", | 1508 | "Attempting to send to peer `%s' from peer `%s', but not connected!\n", |
1586 | GNUNET_i2s(target), GNUNET_h2s(&handle->me.hashPubKey)); | 1509 | GNUNET_i2s (target), GNUNET_h2s (&handle->me.hashPubKey)); |
1587 | GNUNET_break (0); | 1510 | GNUNET_break (0); |
1588 | return NULL; | 1511 | return NULL; |
1589 | } | 1512 | } |
1590 | GNUNET_assert (notify_size + sizeof (struct SendMessage) < | 1513 | GNUNET_assert (notify_size + sizeof (struct SendMessage) < |
1591 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | 1514 | GNUNET_SERVER_MAX_MESSAGE_SIZE); |
1592 | th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle)); | 1515 | th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle)); |
1593 | th->peer = pr; | 1516 | th->peer = pr; |
1594 | GNUNET_assert(NULL != notify); | 1517 | GNUNET_assert (NULL != notify); |
1595 | th->get_message = notify; | 1518 | th->get_message = notify; |
1596 | th->get_message_cls = notify_cls; | 1519 | th->get_message_cls = notify_cls; |
1597 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); | 1520 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); |
@@ -1600,81 +1523,72 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, | |||
1600 | th->cork = cork; | 1523 | th->cork = cork; |
1601 | /* bound queue size */ | 1524 | /* bound queue size */ |
1602 | if (pr->queue_size == handle->queue_size) | 1525 | if (pr->queue_size == handle->queue_size) |
1526 | { | ||
1527 | /* find lowest-priority entry, but skip the head of the list */ | ||
1528 | minp = pr->pending_head->next; | ||
1529 | prev = minp; | ||
1530 | while (prev != NULL) | ||
1531 | { | ||
1532 | if (prev->priority < minp->priority) | ||
1533 | minp = prev; | ||
1534 | prev = prev->next; | ||
1535 | } | ||
1536 | if (minp == NULL) | ||
1603 | { | 1537 | { |
1604 | /* find lowest-priority entry, but skip the head of the list */ | 1538 | GNUNET_break (handle->queue_size != 0); |
1605 | minp = pr->pending_head->next; | 1539 | GNUNET_break (pr->queue_size == 1); |
1606 | prev = minp; | 1540 | GNUNET_free (th); |
1607 | while (prev != NULL) | ||
1608 | { | ||
1609 | if (prev->priority < minp->priority) | ||
1610 | minp = prev; | ||
1611 | prev = prev->next; | ||
1612 | } | ||
1613 | if (minp == NULL) | ||
1614 | { | ||
1615 | GNUNET_break (handle->queue_size != 0); | ||
1616 | GNUNET_break (pr->queue_size == 1); | ||
1617 | GNUNET_free(th); | ||
1618 | #if DEBUG_CORE | 1541 | #if DEBUG_CORE |
1619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1620 | "Dropping transmission request: cannot drop queue head and limit is one\n"); | 1543 | "Dropping transmission request: cannot drop queue head and limit is one\n"); |
1621 | #endif | 1544 | #endif |
1622 | return NULL; | 1545 | return NULL; |
1623 | } | 1546 | } |
1624 | if (priority <= minp->priority) | 1547 | if (priority <= minp->priority) |
1625 | { | 1548 | { |
1626 | #if DEBUG_CORE | 1549 | #if DEBUG_CORE |
1627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1628 | "Dropping transmission request: priority too low\n"); | 1551 | "Dropping transmission request: priority too low\n"); |
1629 | #endif | 1552 | #endif |
1630 | GNUNET_free(th); | 1553 | GNUNET_free (th); |
1631 | return NULL; /* priority too low */ | 1554 | return NULL; /* priority too low */ |
1632 | } | ||
1633 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, | ||
1634 | pr->pending_tail, | ||
1635 | minp); | ||
1636 | pr->queue_size--; | ||
1637 | GNUNET_assert (0 == | ||
1638 | minp->get_message (minp->get_message_cls, | ||
1639 | 0, NULL)); | ||
1640 | GNUNET_free (minp); | ||
1641 | } | 1555 | } |
1556 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, minp); | ||
1557 | pr->queue_size--; | ||
1558 | GNUNET_assert (0 == minp->get_message (minp->get_message_cls, 0, NULL)); | ||
1559 | GNUNET_free (minp); | ||
1560 | } | ||
1642 | 1561 | ||
1643 | /* Order entries by deadline, but SKIP 'HEAD' if | 1562 | /* Order entries by deadline, but SKIP 'HEAD' if |
1644 | we're in the 'ready_peer_*' DLL */ | 1563 | * we're in the 'ready_peer_*' DLL */ |
1645 | pos = pr->pending_head; | 1564 | pos = pr->pending_head; |
1646 | if ( (pr->prev != NULL) || | 1565 | if ((pr->prev != NULL) || |
1647 | (pr->next != NULL) || | 1566 | (pr->next != NULL) || (pr == handle->ready_peer_head)) |
1648 | (pr == handle->ready_peer_head) ) | 1567 | { |
1649 | { | 1568 | GNUNET_assert (pos != NULL); |
1650 | GNUNET_assert (pos != NULL); | 1569 | pos = pos->next; /* skip head */ |
1651 | pos = pos->next; /* skip head */ | 1570 | } |
1652 | } | ||
1653 | 1571 | ||
1654 | /* insertion sort */ | 1572 | /* insertion sort */ |
1655 | prev = pos; | 1573 | prev = pos; |
1656 | while ( (pos != NULL) && | 1574 | while ((pos != NULL) && (pos->timeout.abs_value < th->timeout.abs_value)) |
1657 | (pos->timeout.abs_value < th->timeout.abs_value) ) | 1575 | { |
1658 | { | 1576 | prev = pos; |
1659 | prev = pos; | 1577 | pos = pos->next; |
1660 | pos = pos->next; | 1578 | } |
1661 | } | ||
1662 | GNUNET_CONTAINER_DLL_insert_after (pr->pending_head, | 1579 | GNUNET_CONTAINER_DLL_insert_after (pr->pending_head, |
1663 | pr->pending_tail, | 1580 | pr->pending_tail, prev, th); |
1664 | prev, | ||
1665 | th); | ||
1666 | pr->queue_size++; | 1581 | pr->queue_size++; |
1667 | /* was the request queue previously empty? */ | 1582 | /* was the request queue previously empty? */ |
1668 | #if DEBUG_CORE | 1583 | #if DEBUG_CORE |
1669 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n"); |
1670 | "Transmission request added to queue\n"); | ||
1671 | #endif | 1585 | #endif |
1672 | if ( (pr->pending_head == th) && | 1586 | if ((pr->pending_head == th) && |
1673 | (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && | 1587 | (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && |
1674 | (pr->next == NULL) && | 1588 | (pr->next == NULL) && |
1675 | (pr->prev == NULL) && | 1589 | (pr->prev == NULL) && (handle->ready_peer_head != pr)) |
1676 | (handle->ready_peer_head != pr) ) | 1590 | pr->ntr_task = |
1677 | pr->ntr_task = GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr); | 1591 | GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr); |
1678 | return th; | 1592 | return th; |
1679 | } | 1593 | } |
1680 | 1594 | ||
@@ -1685,42 +1599,34 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, | |||
1685 | * @param th handle that was returned by "notify_transmit_ready". | 1599 | * @param th handle that was returned by "notify_transmit_ready". |
1686 | */ | 1600 | */ |
1687 | void | 1601 | void |
1688 | GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle | 1602 | GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th) |
1689 | *th) | ||
1690 | { | 1603 | { |
1691 | struct PeerRecord *pr = th->peer; | 1604 | struct PeerRecord *pr = th->peer; |
1692 | struct GNUNET_CORE_Handle *h = pr->ch; | 1605 | struct GNUNET_CORE_Handle *h = pr->ch; |
1693 | int was_head; | 1606 | int was_head; |
1694 | 1607 | ||
1695 | was_head = (pr->pending_head == th); | 1608 | was_head = (pr->pending_head == th); |
1696 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, | 1609 | GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th); |
1697 | pr->pending_tail, | ||
1698 | th); | ||
1699 | pr->queue_size--; | 1610 | pr->queue_size--; |
1700 | if (th->cm != NULL) | 1611 | if (th->cm != NULL) |
1701 | { | 1612 | { |
1702 | /* we're currently in the control queue, remove */ | 1613 | /* we're currently in the control queue, remove */ |
1703 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | 1614 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, |
1704 | h->control_pending_tail, | 1615 | h->control_pending_tail, th->cm); |
1705 | th->cm); | 1616 | GNUNET_free (th->cm); |
1706 | GNUNET_free (th->cm); | 1617 | } |
1707 | } | ||
1708 | GNUNET_free (th); | 1618 | GNUNET_free (th); |
1709 | if (was_head) | 1619 | if (was_head) |
1620 | { | ||
1621 | if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head)) | ||
1710 | { | 1622 | { |
1711 | if ( (pr->prev != NULL) || | 1623 | /* the request that was 'approved' by core was |
1712 | (pr->next != NULL) || | 1624 | * canceled before it could be transmitted; remove |
1713 | (pr == h->ready_peer_head) ) | 1625 | * us from the 'ready' list */ |
1714 | { | 1626 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); |
1715 | /* the request that was 'approved' by core was | ||
1716 | canceled before it could be transmitted; remove | ||
1717 | us from the 'ready' list */ | ||
1718 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, | ||
1719 | h->ready_peer_tail, | ||
1720 | pr); | ||
1721 | } | ||
1722 | request_next_transmission (pr); | ||
1723 | } | 1627 | } |
1628 | request_next_transmission (pr); | ||
1629 | } | ||
1724 | } | 1630 | } |
1725 | 1631 | ||
1726 | 1632 | ||
@@ -1766,13 +1672,12 @@ struct GNUNET_CORE_PeerRequestHandle | |||
1766 | * @param success was the request transmitted? | 1672 | * @param success was the request transmitted? |
1767 | */ | 1673 | */ |
1768 | static void | 1674 | static void |
1769 | peer_request_connect_cont (void *cls, | 1675 | peer_request_connect_cont (void *cls, int success) |
1770 | int success) | ||
1771 | { | 1676 | { |
1772 | struct GNUNET_CORE_PeerRequestHandle *ret = cls; | 1677 | struct GNUNET_CORE_PeerRequestHandle *ret = cls; |
1773 | 1678 | ||
1774 | if (ret->cont != NULL) | 1679 | if (ret->cont != NULL) |
1775 | ret->cont (ret->cont_cls, success); | 1680 | ret->cont (ret->cont_cls, success); |
1776 | GNUNET_free (ret); | 1681 | GNUNET_free (ret); |
1777 | } | 1682 | } |
1778 | 1683 | ||
@@ -1798,34 +1703,31 @@ peer_request_connect_cont (void *cls, | |||
1798 | */ | 1703 | */ |
1799 | struct GNUNET_CORE_PeerRequestHandle * | 1704 | struct GNUNET_CORE_PeerRequestHandle * |
1800 | GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, | 1705 | GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, |
1801 | const struct GNUNET_PeerIdentity * peer, | 1706 | const struct GNUNET_PeerIdentity *peer, |
1802 | GNUNET_CORE_ControlContinuation cont, | 1707 | GNUNET_CORE_ControlContinuation cont, |
1803 | void *cont_cls) | 1708 | void *cont_cls) |
1804 | { | 1709 | { |
1805 | struct GNUNET_CORE_PeerRequestHandle *ret; | 1710 | struct GNUNET_CORE_PeerRequestHandle *ret; |
1806 | struct ControlMessage *cm; | 1711 | struct ControlMessage *cm; |
1807 | struct ConnectMessage *msg; | 1712 | struct ConnectMessage *msg; |
1808 | 1713 | ||
1809 | if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, | 1714 | if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey)) |
1810 | &peer->hashPubKey)) | 1715 | { |
1811 | { | ||
1812 | #if DEBUG_CORE | 1716 | #if DEBUG_CORE |
1813 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n"); |
1814 | "Peers are already connected!\n"); | ||
1815 | #endif | 1718 | #endif |
1816 | return NULL; | 1719 | return NULL; |
1817 | } | 1720 | } |
1818 | 1721 | ||
1819 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + | 1722 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + |
1820 | sizeof (struct ConnectMessage)); | 1723 | sizeof (struct ConnectMessage)); |
1821 | msg = (struct ConnectMessage*) &cm[1]; | 1724 | msg = (struct ConnectMessage *) &cm[1]; |
1822 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT); | 1725 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT); |
1823 | msg->header.size = htons (sizeof (struct ConnectMessage)); | 1726 | msg->header.size = htons (sizeof (struct ConnectMessage)); |
1824 | msg->reserved = htonl (0); | 1727 | msg->reserved = htonl (0); |
1825 | msg->peer = *peer; | 1728 | msg->peer = *peer; |
1826 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, | 1729 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, |
1827 | h->control_pending_tail, | 1730 | h->control_pending_tail, cm); |
1828 | cm); | ||
1829 | ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle)); | 1731 | ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle)); |
1830 | ret->h = h; | 1732 | ret->h = h; |
1831 | ret->cm = cm; | 1733 | ret->cm = cm; |
@@ -1834,8 +1736,7 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, | |||
1834 | cm->cont = &peer_request_connect_cont; | 1736 | cm->cont = &peer_request_connect_cont; |
1835 | cm->cont_cls = ret; | 1737 | cm->cont_cls = ret; |
1836 | #if DEBUG_CORE | 1738 | #if DEBUG_CORE |
1837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing REQUEST_CONNECT request\n"); |
1838 | "Queueing REQUEST_CONNECT request\n"); | ||
1839 | #endif | 1740 | #endif |
1840 | trigger_next_request (h, GNUNET_NO); | 1741 | trigger_next_request (h, GNUNET_NO); |
1841 | return ret; | 1742 | return ret; |
@@ -1849,18 +1750,18 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, | |||
1849 | * @param req request handle that was returned for the original request | 1750 | * @param req request handle that was returned for the original request |
1850 | */ | 1751 | */ |
1851 | void | 1752 | void |
1852 | GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req) | 1753 | GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle |
1754 | *req) | ||
1853 | { | 1755 | { |
1854 | struct GNUNET_CORE_Handle *h = req->h; | 1756 | struct GNUNET_CORE_Handle *h = req->h; |
1855 | struct ControlMessage *cm = req->cm; | 1757 | struct ControlMessage *cm = req->cm; |
1856 | 1758 | ||
1857 | #if DEBUG_CORE | 1759 | #if DEBUG_CORE |
1858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1859 | "A CHANGE PREFERENCE request was cancelled!\n"); | 1761 | "A CHANGE PREFERENCE request was cancelled!\n"); |
1860 | #endif | 1762 | #endif |
1861 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | 1763 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, |
1862 | h->control_pending_tail, | 1764 | h->control_pending_tail, cm); |
1863 | cm); | ||
1864 | GNUNET_free (cm); | 1765 | GNUNET_free (cm); |
1865 | GNUNET_free (req); | 1766 | GNUNET_free (req); |
1866 | } | 1767 | } |
@@ -1869,9 +1770,9 @@ GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *r | |||
1869 | /* ****************** GNUNET_CORE_peer_change_preference ******************** */ | 1770 | /* ****************** GNUNET_CORE_peer_change_preference ******************** */ |
1870 | 1771 | ||
1871 | 1772 | ||
1872 | struct GNUNET_CORE_InformationRequestContext | 1773 | struct GNUNET_CORE_InformationRequestContext |
1873 | { | 1774 | { |
1874 | 1775 | ||
1875 | /** | 1776 | /** |
1876 | * Our connection to the service. | 1777 | * Our connection to the service. |
1877 | */ | 1778 | */ |
@@ -1879,7 +1780,7 @@ struct GNUNET_CORE_InformationRequestContext | |||
1879 | 1780 | ||
1880 | /** | 1781 | /** |
1881 | * Link to control message, NULL if CM was sent. | 1782 | * Link to control message, NULL if CM was sent. |
1882 | */ | 1783 | */ |
1883 | struct ControlMessage *cm; | 1784 | struct ControlMessage *cm; |
1884 | 1785 | ||
1885 | /** | 1786 | /** |
@@ -1896,8 +1797,7 @@ struct GNUNET_CORE_InformationRequestContext | |||
1896 | * @param success were we successful? | 1797 | * @param success were we successful? |
1897 | */ | 1798 | */ |
1898 | static void | 1799 | static void |
1899 | change_preference_send_continuation (void *cls, | 1800 | change_preference_send_continuation (void *cls, int success) |
1900 | int success) | ||
1901 | { | 1801 | { |
1902 | struct GNUNET_CORE_InformationRequestContext *irc = cls; | 1802 | struct GNUNET_CORE_InformationRequestContext *irc = cls; |
1903 | 1803 | ||
@@ -1931,61 +1831,58 @@ change_preference_send_continuation (void *cls, | |||
1931 | */ | 1831 | */ |
1932 | struct GNUNET_CORE_InformationRequestContext * | 1832 | struct GNUNET_CORE_InformationRequestContext * |
1933 | GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, | 1833 | GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, |
1934 | const struct GNUNET_PeerIdentity *peer, | 1834 | const struct GNUNET_PeerIdentity *peer, |
1935 | struct GNUNET_TIME_Relative timeout, | 1835 | struct GNUNET_TIME_Relative timeout, |
1936 | struct GNUNET_BANDWIDTH_Value32NBO bw_out, | 1836 | struct GNUNET_BANDWIDTH_Value32NBO bw_out, |
1937 | int32_t amount, | 1837 | int32_t amount, |
1938 | uint64_t preference, | 1838 | uint64_t preference, |
1939 | GNUNET_CORE_PeerConfigurationInfoCallback info, | 1839 | GNUNET_CORE_PeerConfigurationInfoCallback |
1940 | void *info_cls) | 1840 | info, void *info_cls) |
1941 | { | 1841 | { |
1942 | struct GNUNET_CORE_InformationRequestContext *irc; | 1842 | struct GNUNET_CORE_InformationRequestContext *irc; |
1943 | struct PeerRecord *pr; | 1843 | struct PeerRecord *pr; |
1944 | struct RequestInfoMessage *rim; | 1844 | struct RequestInfoMessage *rim; |
1945 | struct ControlMessage *cm; | 1845 | struct ControlMessage *cm; |
1946 | 1846 | ||
1947 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, | 1847 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey); |
1948 | &peer->hashPubKey); | ||
1949 | if (NULL == pr) | 1848 | if (NULL == pr) |
1950 | { | 1849 | { |
1951 | /* attempt to change preference on peer that is not connected */ | 1850 | /* attempt to change preference on peer that is not connected */ |
1952 | GNUNET_assert (0); | 1851 | GNUNET_assert (0); |
1953 | return NULL; | 1852 | return NULL; |
1954 | } | 1853 | } |
1955 | if (pr->pcic != NULL) | 1854 | if (pr->pcic != NULL) |
1956 | { | 1855 | { |
1957 | /* second change before first one is done */ | 1856 | /* second change before first one is done */ |
1958 | GNUNET_break (0); | 1857 | GNUNET_break (0); |
1959 | return NULL; | 1858 | return NULL; |
1960 | } | 1859 | } |
1961 | irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext)); | 1860 | irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext)); |
1962 | irc->h = h; | 1861 | irc->h = h; |
1963 | irc->pr = pr; | 1862 | irc->pr = pr; |
1964 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + | 1863 | cm = GNUNET_malloc (sizeof (struct ControlMessage) + |
1965 | sizeof (struct RequestInfoMessage)); | 1864 | sizeof (struct RequestInfoMessage)); |
1966 | cm->cont = &change_preference_send_continuation; | 1865 | cm->cont = &change_preference_send_continuation; |
1967 | cm->cont_cls = irc; | 1866 | cm->cont_cls = irc; |
1968 | irc->cm = cm; | 1867 | irc->cm = cm; |
1969 | rim = (struct RequestInfoMessage*) &cm[1]; | 1868 | rim = (struct RequestInfoMessage *) &cm[1]; |
1970 | rim->header.size = htons (sizeof (struct RequestInfoMessage)); | 1869 | rim->header.size = htons (sizeof (struct RequestInfoMessage)); |
1971 | rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO); | 1870 | rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO); |
1972 | rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++); | 1871 | rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++); |
1973 | rim->limit_outbound = bw_out; | 1872 | rim->limit_outbound = bw_out; |
1974 | rim->reserve_inbound = htonl (amount); | 1873 | rim->reserve_inbound = htonl (amount); |
1975 | rim->preference_change = GNUNET_htonll(preference); | 1874 | rim->preference_change = GNUNET_htonll (preference); |
1976 | rim->peer = *peer; | 1875 | rim->peer = *peer; |
1977 | #if DEBUG_CORE | 1876 | #if DEBUG_CORE |
1978 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1877 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1979 | "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n", | 1878 | "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n", |
1980 | GNUNET_i2s (peer), | 1879 | GNUNET_i2s (peer), (unsigned int) pr->rim_id); |
1981 | (unsigned int) pr->rim_id); | ||
1982 | #endif | 1880 | #endif |
1983 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, | 1881 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, |
1984 | h->control_pending_tail, | 1882 | h->control_pending_tail, cm); |
1985 | cm); | ||
1986 | pr->pcic = info; | 1883 | pr->pcic = info; |
1987 | pr->pcic_cls = info_cls; | 1884 | pr->pcic_cls = info_cls; |
1988 | pr->pcic_ptr = irc; /* for free'ing irc */ | 1885 | pr->pcic_ptr = irc; /* for free'ing irc */ |
1989 | if (NULL != h->client) | 1886 | if (NULL != h->client) |
1990 | trigger_next_request (h, GNUNET_NO); | 1887 | trigger_next_request (h, GNUNET_NO); |
1991 | return irc; | 1888 | return irc; |
@@ -2004,19 +1901,20 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, | |||
2004 | * @param irc context returned by the original GNUNET_CORE_peer_get_info call | 1901 | * @param irc context returned by the original GNUNET_CORE_peer_get_info call |
2005 | */ | 1902 | */ |
2006 | void | 1903 | void |
2007 | GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequestContext *irc) | 1904 | GNUNET_CORE_peer_change_preference_cancel (struct |
1905 | GNUNET_CORE_InformationRequestContext | ||
1906 | *irc) | ||
2008 | { | 1907 | { |
2009 | struct GNUNET_CORE_Handle *h = irc->h; | 1908 | struct GNUNET_CORE_Handle *h = irc->h; |
2010 | struct PeerRecord *pr = irc->pr; | 1909 | struct PeerRecord *pr = irc->pr; |
2011 | 1910 | ||
2012 | GNUNET_assert (pr->pcic_ptr == irc); | 1911 | GNUNET_assert (pr->pcic_ptr == irc); |
2013 | if (irc->cm != NULL) | 1912 | if (irc->cm != NULL) |
2014 | { | 1913 | { |
2015 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | 1914 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, |
2016 | h->control_pending_tail, | 1915 | h->control_pending_tail, irc->cm); |
2017 | irc->cm); | 1916 | GNUNET_free (irc->cm); |
2018 | GNUNET_free (irc->cm); | 1917 | } |
2019 | } | ||
2020 | pr->pcic = NULL; | 1918 | pr->pcic = NULL; |
2021 | pr->pcic_cls = NULL; | 1919 | pr->pcic_cls = NULL; |
2022 | pr->pcic_ptr = NULL; | 1920 | pr->pcic_ptr = NULL; |
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c index 967580f83..1bad9a768 100644 --- a/src/core/core_api_iterate_peers.c +++ b/src/core/core_api_iterate_peers.c | |||
@@ -66,8 +66,7 @@ struct GNUNET_CORE_RequestContext | |||
66 | * @param msg NULL on error or last entry | 66 | * @param msg NULL on error or last entry |
67 | */ | 67 | */ |
68 | static void | 68 | static void |
69 | receive_info (void *cls, | 69 | receive_info (void *cls, const struct GNUNET_MessageHeader *msg) |
70 | const struct GNUNET_MessageHeader *msg) | ||
71 | { | 70 | { |
72 | struct GNUNET_CORE_RequestContext *request_context = cls; | 71 | struct GNUNET_CORE_RequestContext *request_context = cls; |
73 | const struct ConnectNotifyMessage *connect_message; | 72 | const struct ConnectNotifyMessage *connect_message; |
@@ -75,53 +74,51 @@ receive_info (void *cls, | |||
75 | uint16_t msize; | 74 | uint16_t msize; |
76 | 75 | ||
77 | /* Handle last message or error case, disconnect and clean up */ | 76 | /* Handle last message or error case, disconnect and clean up */ |
78 | if ( (msg == NULL) || | 77 | if ((msg == NULL) || |
79 | ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) && | 78 | ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) && |
80 | (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) ) | 79 | (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)))) |
81 | { | 80 | { |
82 | if (request_context->peer_cb != NULL) | 81 | if (request_context->peer_cb != NULL) |
83 | request_context->peer_cb (request_context->cb_cls, | 82 | request_context->peer_cb (request_context->cb_cls, NULL, NULL); |
84 | NULL, NULL); | 83 | GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); |
85 | GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); | 84 | GNUNET_free (request_context); |
86 | GNUNET_free (request_context); | 85 | return; |
87 | return; | 86 | } |
88 | } | ||
89 | 87 | ||
90 | msize = ntohs (msg->size); | 88 | msize = ntohs (msg->size); |
91 | /* Handle incorrect message type or size, disconnect and clean up */ | 89 | /* Handle incorrect message type or size, disconnect and clean up */ |
92 | if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) || | 90 | if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) || |
93 | (msize < sizeof (struct ConnectNotifyMessage)) ) | 91 | (msize < sizeof (struct ConnectNotifyMessage))) |
94 | { | 92 | { |
95 | GNUNET_break (0); | 93 | GNUNET_break (0); |
96 | if (request_context->peer_cb != NULL) | 94 | if (request_context->peer_cb != NULL) |
97 | request_context->peer_cb (request_context->cb_cls, | 95 | request_context->peer_cb (request_context->cb_cls, NULL, NULL); |
98 | NULL, NULL); | 96 | GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); |
99 | GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); | 97 | GNUNET_free (request_context); |
100 | GNUNET_free (request_context); | 98 | return; |
101 | return; | 99 | } |
102 | } | ||
103 | connect_message = (const struct ConnectNotifyMessage *) msg; | 100 | connect_message = (const struct ConnectNotifyMessage *) msg; |
104 | ats_count = ntohl (connect_message->ats_count); | 101 | ats_count = ntohl (connect_message->ats_count); |
105 | if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || | 102 | if ((msize != |
106 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&connect_message->ats)[ats_count].type)) ) | 103 | sizeof (struct ConnectNotifyMessage) + |
107 | { | 104 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || |
108 | GNUNET_break (0); | 105 | (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != |
109 | if (request_context->peer_cb != NULL) | 106 | ntohl ((&connect_message->ats)[ats_count].type))) |
110 | request_context->peer_cb (request_context->cb_cls, | 107 | { |
111 | NULL, NULL); | 108 | GNUNET_break (0); |
112 | GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); | 109 | if (request_context->peer_cb != NULL) |
113 | GNUNET_free (request_context); | 110 | request_context->peer_cb (request_context->cb_cls, NULL, NULL); |
114 | return; | 111 | GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO); |
115 | } | 112 | GNUNET_free (request_context); |
113 | return; | ||
114 | } | ||
116 | /* Normal case */ | 115 | /* Normal case */ |
117 | if (request_context->peer_cb != NULL) | 116 | if (request_context->peer_cb != NULL) |
118 | request_context->peer_cb (request_context->cb_cls, | 117 | request_context->peer_cb (request_context->cb_cls, |
119 | &connect_message->peer, | 118 | &connect_message->peer, &connect_message->ats); |
120 | &connect_message->ats); | 119 | GNUNET_CLIENT_receive (request_context->client, |
121 | GNUNET_CLIENT_receive(request_context->client, | 120 | &receive_info, |
122 | &receive_info, | 121 | request_context, GNUNET_TIME_UNIT_FOREVER_REL); |
123 | request_context, | ||
124 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
125 | } | 122 | } |
126 | 123 | ||
127 | /** | 124 | /** |
@@ -136,28 +133,29 @@ receive_info (void *cls, | |||
136 | * @return number of bytes written to buf | 133 | * @return number of bytes written to buf |
137 | */ | 134 | */ |
138 | static size_t | 135 | static size_t |
139 | transmit_request(void *cls, | 136 | transmit_request (void *cls, size_t size, void *buf) |
140 | size_t size, void *buf) | ||
141 | { | 137 | { |
142 | struct GNUNET_MessageHeader *msg; | 138 | struct GNUNET_MessageHeader *msg; |
143 | struct GNUNET_PeerIdentity *peer = cls; | 139 | struct GNUNET_PeerIdentity *peer = cls; |
144 | int msize; | 140 | int msize; |
145 | 141 | ||
146 | if (peer == NULL) | 142 | if (peer == NULL) |
147 | msize = sizeof(struct GNUNET_MessageHeader); | 143 | msize = sizeof (struct GNUNET_MessageHeader); |
148 | else | 144 | else |
149 | msize = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity); | 145 | msize = |
146 | sizeof (struct GNUNET_MessageHeader) + | ||
147 | sizeof (struct GNUNET_PeerIdentity); | ||
150 | 148 | ||
151 | if ((size < msize) || (buf == NULL)) | 149 | if ((size < msize) || (buf == NULL)) |
152 | return 0; | 150 | return 0; |
153 | 151 | ||
154 | msg = (struct GNUNET_MessageHeader *)buf; | 152 | msg = (struct GNUNET_MessageHeader *) buf; |
155 | msg->size = htons (msize); | 153 | msg->size = htons (msize); |
156 | if (peer != NULL) | 154 | if (peer != NULL) |
157 | { | 155 | { |
158 | msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED); | 156 | msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED); |
159 | memcpy(&msg[1], peer, sizeof(struct GNUNET_PeerIdentity)); | 157 | memcpy (&msg[1], peer, sizeof (struct GNUNET_PeerIdentity)); |
160 | } | 158 | } |
161 | else | 159 | else |
162 | msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS); | 160 | msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS); |
163 | 161 | ||
@@ -189,21 +187,26 @@ GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
189 | client = GNUNET_CLIENT_connect ("core", cfg); | 187 | client = GNUNET_CLIENT_connect ("core", cfg); |
190 | if (client == NULL) | 188 | if (client == NULL) |
191 | return GNUNET_SYSERR; | 189 | return GNUNET_SYSERR; |
192 | GNUNET_assert(peer != NULL); | 190 | GNUNET_assert (peer != NULL); |
193 | request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext)); | 191 | request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext)); |
194 | request_context->client = client; | 192 | request_context->client = client; |
195 | request_context->peer_cb = peer_cb; | 193 | request_context->peer_cb = peer_cb; |
196 | request_context->cb_cls = cb_cls; | 194 | request_context->cb_cls = cb_cls; |
197 | request_context->peer = peer; | 195 | request_context->peer = peer; |
198 | 196 | ||
199 | request_context->th = GNUNET_CLIENT_notify_transmit_ready(client, | 197 | request_context->th = GNUNET_CLIENT_notify_transmit_ready (client, |
200 | sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity), | 198 | sizeof (struct |
201 | GNUNET_TIME_relative_get_forever(), | 199 | GNUNET_MessageHeader) |
202 | GNUNET_YES, | 200 | + |
203 | &transmit_request, | 201 | sizeof (struct |
204 | peer); | 202 | GNUNET_PeerIdentity), |
205 | GNUNET_assert(request_context->th != NULL); | 203 | GNUNET_TIME_relative_get_forever |
206 | GNUNET_CLIENT_receive(client, &receive_info, request_context, GNUNET_TIME_relative_get_forever()); | 204 | (), GNUNET_YES, |
205 | &transmit_request, | ||
206 | peer); | ||
207 | GNUNET_assert (request_context->th != NULL); | ||
208 | GNUNET_CLIENT_receive (client, &receive_info, request_context, | ||
209 | GNUNET_TIME_relative_get_forever ()); | ||
207 | return GNUNET_OK; | 210 | return GNUNET_OK; |
208 | } | 211 | } |
209 | 212 | ||
@@ -235,14 +238,16 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
235 | request_context->peer_cb = peer_cb; | 238 | request_context->peer_cb = peer_cb; |
236 | request_context->cb_cls = cb_cls; | 239 | request_context->cb_cls = cb_cls; |
237 | 240 | ||
238 | request_context->th = GNUNET_CLIENT_notify_transmit_ready(client, | 241 | request_context->th = GNUNET_CLIENT_notify_transmit_ready (client, |
239 | sizeof(struct GNUNET_MessageHeader), | 242 | sizeof (struct |
240 | GNUNET_TIME_relative_get_forever(), | 243 | GNUNET_MessageHeader), |
241 | GNUNET_YES, | 244 | GNUNET_TIME_relative_get_forever |
242 | &transmit_request, | 245 | (), GNUNET_YES, |
243 | NULL); | 246 | &transmit_request, |
247 | NULL); | ||
244 | 248 | ||
245 | GNUNET_CLIENT_receive(client, &receive_info, request_context, GNUNET_TIME_relative_get_forever()); | 249 | GNUNET_CLIENT_receive (client, &receive_info, request_context, |
250 | GNUNET_TIME_relative_get_forever ()); | ||
246 | return GNUNET_OK; | 251 | return GNUNET_OK; |
247 | } | 252 | } |
248 | 253 | ||
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c index 8b0f6773a..284a79f69 100644 --- a/src/core/gnunet-core-list-connections.c +++ b/src/core/gnunet-core-list-connections.c | |||
@@ -36,7 +36,7 @@ | |||
36 | static int no_resolve; | 36 | static int no_resolve; |
37 | 37 | ||
38 | #if VERBOSE | 38 | #if VERBOSE |
39 | static unsigned int peer_count; | 39 | static unsigned int peer_count; |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -74,15 +74,15 @@ dump_pc (struct PrintContext *pc) | |||
74 | struct AddressStringList *address; | 74 | struct AddressStringList *address; |
75 | 75 | ||
76 | GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); | 76 | GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); |
77 | printf (_("Peer `%s'\n"), | 77 | printf (_("Peer `%s'\n"), (const char *) &enc); |
78 | (const char *) &enc); | ||
79 | while (NULL != (address = pc->address_list_head)) | 78 | while (NULL != (address = pc->address_list_head)) |
80 | { | 79 | { |
81 | printf ("\t%s\n", address->address_string); | 80 | printf ("\t%s\n", address->address_string); |
82 | GNUNET_free(address->address_string); | 81 | GNUNET_free (address->address_string); |
83 | GNUNET_CONTAINER_DLL_remove(pc->address_list_head, pc->address_list_tail, address); | 82 | GNUNET_CONTAINER_DLL_remove (pc->address_list_head, pc->address_list_tail, |
84 | GNUNET_free(address); | 83 | address); |
85 | } | 84 | GNUNET_free (address); |
85 | } | ||
86 | 86 | ||
87 | printf ("\n"); | 87 | printf ("\n"); |
88 | 88 | ||
@@ -97,24 +97,24 @@ dump_pc (struct PrintContext *pc) | |||
97 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | 97 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string |
98 | */ | 98 | */ |
99 | static void | 99 | static void |
100 | process_resolved_address (void *cls, | 100 | process_resolved_address (void *cls, const char *address) |
101 | const char *address) | ||
102 | { | 101 | { |
103 | struct PrintContext *pc = cls; | 102 | struct PrintContext *pc = cls; |
104 | struct AddressStringList *new_address; | 103 | struct AddressStringList *new_address; |
105 | 104 | ||
106 | if (address == NULL) | 105 | if (address == NULL) |
107 | { | 106 | { |
108 | dump_pc (pc); | 107 | dump_pc (pc); |
109 | return; | 108 | return; |
110 | } | 109 | } |
111 | 110 | ||
112 | new_address = GNUNET_malloc(sizeof(struct AddressStringList)); | 111 | new_address = GNUNET_malloc (sizeof (struct AddressStringList)); |
113 | #if VERBOSE | 112 | #if VERBOSE |
114 | fprintf(stderr, "Received address %s\n", address); | 113 | fprintf (stderr, "Received address %s\n", address); |
115 | #endif | 114 | #endif |
116 | new_address->address_string = GNUNET_strdup(address); | 115 | new_address->address_string = GNUNET_strdup (address); |
117 | GNUNET_CONTAINER_DLL_insert(pc->address_list_head, pc->address_list_tail, new_address); | 116 | GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, |
117 | new_address); | ||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
@@ -127,23 +127,23 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
127 | { | 127 | { |
128 | struct PrintContext *pc; | 128 | struct PrintContext *pc; |
129 | 129 | ||
130 | if (peer != NULL) /* Not yet finished */ | 130 | if (peer != NULL) /* Not yet finished */ |
131 | { | 131 | { |
132 | #if VERBOSE | 132 | #if VERBOSE |
133 | fprintf(stderr, "Learned about peer %s\n", GNUNET_i2s(peer)); | 133 | fprintf (stderr, "Learned about peer %s\n", GNUNET_i2s (peer)); |
134 | peer_count++; | 134 | peer_count++; |
135 | #endif | 135 | #endif |
136 | pc = GNUNET_malloc (sizeof (struct PrintContext)); | 136 | pc = GNUNET_malloc (sizeof (struct PrintContext)); |
137 | pc->peer = *peer; | 137 | pc->peer = *peer; |
138 | GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, | 138 | GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, |
139 | GNUNET_TIME_UNIT_MINUTES, | 139 | GNUNET_TIME_UNIT_MINUTES, |
140 | &process_resolved_address, pc); | 140 | &process_resolved_address, pc); |
141 | } | 141 | } |
142 | #if VERBOSE | 142 | #if VERBOSE |
143 | else | 143 | else |
144 | { | 144 | { |
145 | fprintf(stderr, "Counted %u total connected peers.\n", peer_count); | 145 | fprintf (stderr, "Counted %u total connected peers.\n", peer_count); |
146 | } | 146 | } |
147 | #endif | 147 | #endif |
148 | } | 148 | } |
149 | 149 | ||
@@ -159,22 +159,17 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
159 | static void | 159 | static void |
160 | run (void *cls, | 160 | run (void *cls, |
161 | char *const *args, | 161 | char *const *args, |
162 | const char *cfgfile, | 162 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
163 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
164 | { | 163 | { |
165 | 164 | ||
166 | cfg = c; | 165 | cfg = c; |
167 | if (args[0] != NULL) | 166 | if (args[0] != NULL) |
168 | { | 167 | { |
169 | fprintf (stderr, | 168 | fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]); |
170 | _("Invalid command line argument `%s'\n"), | 169 | return; |
171 | args[0]); | 170 | } |
172 | return; | ||
173 | } | ||
174 | 171 | ||
175 | GNUNET_CORE_iterate_peers (cfg, | 172 | GNUNET_CORE_iterate_peers (cfg, &connected_peer_callback, NULL); |
176 | &connected_peer_callback, | ||
177 | NULL); | ||
178 | 173 | ||
179 | } | 174 | } |
180 | 175 | ||
@@ -199,7 +194,8 @@ main (int argc, char *const *argv) | |||
199 | GNUNET_PROGRAM_run (argc, | 194 | GNUNET_PROGRAM_run (argc, |
200 | argv, | 195 | argv, |
201 | "gnunet-list-connections", | 196 | "gnunet-list-connections", |
202 | gettext_noop ("Print information about connected peers."), | 197 | gettext_noop |
198 | ("Print information about connected peers."), | ||
203 | options, &run, NULL)) ? 0 : 1; | 199 | options, &run, NULL)) ? 0 : 1; |
204 | } | 200 | } |
205 | 201 | ||
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 2e68571a4..95e182448 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -164,7 +164,7 @@ enum PeerStateMachine | |||
164 | * We've sent our session key. | 164 | * We've sent our session key. |
165 | */ | 165 | */ |
166 | PEER_STATE_KEY_SENT, | 166 | PEER_STATE_KEY_SENT, |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * We've received the other peers session key. | 169 | * We've received the other peers session key. |
170 | */ | 170 | */ |
@@ -241,7 +241,7 @@ struct PingMessage | |||
241 | * Message type is CORE_PING. | 241 | * Message type is CORE_PING. |
242 | */ | 242 | */ |
243 | struct GNUNET_MessageHeader header; | 243 | struct GNUNET_MessageHeader header; |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * Seed for the IV | 246 | * Seed for the IV |
247 | */ | 247 | */ |
@@ -271,7 +271,7 @@ struct PongMessage | |||
271 | * Message type is CORE_PONG. | 271 | * Message type is CORE_PONG. |
272 | */ | 272 | */ |
273 | struct GNUNET_MessageHeader header; | 273 | struct GNUNET_MessageHeader header; |
274 | 274 | ||
275 | /** | 275 | /** |
276 | * Seed for the IV | 276 | * Seed for the IV |
277 | */ | 277 | */ |
@@ -489,7 +489,7 @@ struct Neighbour | |||
489 | 489 | ||
490 | /** | 490 | /** |
491 | * Performance data for the peer. | 491 | * Performance data for the peer. |
492 | */ | 492 | */ |
493 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 493 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
494 | 494 | ||
495 | /** | 495 | /** |
@@ -578,7 +578,7 @@ struct Neighbour | |||
578 | 578 | ||
579 | /** | 579 | /** |
580 | * Number of entries in 'ats'. | 580 | * Number of entries in 'ats'. |
581 | */ | 581 | */ |
582 | unsigned int ats_count; | 582 | unsigned int ats_count; |
583 | 583 | ||
584 | /** | 584 | /** |
@@ -601,12 +601,12 @@ struct Neighbour | |||
601 | /** | 601 | /** |
602 | * Available bandwidth in for this peer (current target). | 602 | * Available bandwidth in for this peer (current target). |
603 | */ | 603 | */ |
604 | struct GNUNET_BANDWIDTH_Value32NBO bw_in; | 604 | struct GNUNET_BANDWIDTH_Value32NBO bw_in; |
605 | 605 | ||
606 | /** | 606 | /** |
607 | * Available bandwidth out for this peer (current target). | 607 | * Available bandwidth out for this peer (current target). |
608 | */ | 608 | */ |
609 | struct GNUNET_BANDWIDTH_Value32NBO bw_out; | 609 | struct GNUNET_BANDWIDTH_Value32NBO bw_out; |
610 | 610 | ||
611 | /** | 611 | /** |
612 | * Internal bandwidth limit set for this peer (initially typically | 612 | * Internal bandwidth limit set for this peer (initially typically |
@@ -634,7 +634,7 @@ struct Neighbour | |||
634 | 634 | ||
635 | /** | 635 | /** |
636 | * Are we currently connected to this neighbour? | 636 | * Are we currently connected to this neighbour? |
637 | */ | 637 | */ |
638 | int is_connected; | 638 | int is_connected; |
639 | 639 | ||
640 | }; | 640 | }; |
@@ -731,7 +731,7 @@ struct ClientActiveRequest | |||
731 | * Unique request ID (in big endian). | 731 | * Unique request ID (in big endian). |
732 | */ | 732 | */ |
733 | uint16_t smr_id; | 733 | uint16_t smr_id; |
734 | 734 | ||
735 | }; | 735 | }; |
736 | 736 | ||
737 | 737 | ||
@@ -754,7 +754,7 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | |||
754 | /** | 754 | /** |
755 | * Bitmap of message types this peer is able to handle. | 755 | * Bitmap of message types this peer is able to handle. |
756 | */ | 756 | */ |
757 | static uint32_t my_type_map[(UINT16_MAX + 1)/32]; | 757 | static uint32_t my_type_map[(UINT16_MAX + 1) / 32]; |
758 | 758 | ||
759 | /** | 759 | /** |
760 | * Handle to peerinfo service. | 760 | * Handle to peerinfo service. |
@@ -821,9 +821,8 @@ static unsigned long long bandwidth_target_out_bps; | |||
821 | */ | 821 | */ |
822 | static void | 822 | static void |
823 | derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | 823 | derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, |
824 | const struct GNUNET_CRYPTO_AesSessionKey *skey, | 824 | const struct GNUNET_CRYPTO_AesSessionKey *skey, |
825 | uint32_t seed, | 825 | uint32_t seed, struct GNUNET_TIME_Absolute creation_time) |
826 | struct GNUNET_TIME_Absolute creation_time) | ||
827 | { | 826 | { |
828 | static const char ctx[] = "authentication key"; | 827 | static const char ctx[] = "authentication key"; |
829 | struct GNUNET_TIME_AbsoluteNBO ctbe; | 828 | struct GNUNET_TIME_AbsoluteNBO ctbe; |
@@ -833,13 +832,10 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
833 | GNUNET_CRYPTO_hmac_derive_key (akey, | 832 | GNUNET_CRYPTO_hmac_derive_key (akey, |
834 | skey, | 833 | skey, |
835 | &seed, | 834 | &seed, |
836 | sizeof(seed), | 835 | sizeof (seed), |
837 | &skey->key, | 836 | &skey->key, |
838 | sizeof(skey->key), | 837 | sizeof (skey->key), |
839 | &ctbe, | 838 | &ctbe, sizeof (ctbe), ctx, sizeof (ctx), NULL); |
840 | sizeof(ctbe), | ||
841 | ctx, | ||
842 | sizeof(ctx), NULL); | ||
843 | } | 839 | } |
844 | 840 | ||
845 | 841 | ||
@@ -848,19 +844,18 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
848 | */ | 844 | */ |
849 | static void | 845 | static void |
850 | derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | 846 | derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
851 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, | 847 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, |
852 | const struct GNUNET_PeerIdentity *identity) | 848 | const struct GNUNET_PeerIdentity *identity) |
853 | { | 849 | { |
854 | static const char ctx[] = "initialization vector"; | 850 | static const char ctx[] = "initialization vector"; |
855 | 851 | ||
856 | GNUNET_CRYPTO_aes_derive_iv (iv, | 852 | GNUNET_CRYPTO_aes_derive_iv (iv, |
857 | skey, | 853 | skey, |
858 | &seed, | 854 | &seed, |
859 | sizeof(seed), | 855 | sizeof (seed), |
860 | &identity->hashPubKey.bits, | 856 | &identity->hashPubKey.bits, |
861 | sizeof(identity->hashPubKey.bits), | 857 | sizeof (identity->hashPubKey.bits), |
862 | ctx, | 858 | ctx, sizeof (ctx), NULL); |
863 | sizeof(ctx), NULL); | ||
864 | } | 859 | } |
865 | 860 | ||
866 | /** | 861 | /** |
@@ -868,21 +863,19 @@ derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | |||
868 | */ | 863 | */ |
869 | static void | 864 | static void |
870 | derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | 865 | derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
871 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, | 866 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, |
872 | uint32_t challenge, const struct GNUNET_PeerIdentity *identity) | 867 | uint32_t challenge, const struct GNUNET_PeerIdentity *identity) |
873 | { | 868 | { |
874 | static const char ctx[] = "pong initialization vector"; | 869 | static const char ctx[] = "pong initialization vector"; |
875 | 870 | ||
876 | GNUNET_CRYPTO_aes_derive_iv (iv, | 871 | GNUNET_CRYPTO_aes_derive_iv (iv, |
877 | skey, | 872 | skey, |
878 | &seed, | 873 | &seed, |
879 | sizeof(seed), | 874 | sizeof (seed), |
880 | &identity->hashPubKey.bits, | 875 | &identity->hashPubKey.bits, |
881 | sizeof(identity->hashPubKey.bits), | 876 | sizeof (identity->hashPubKey.bits), |
882 | &challenge, | 877 | &challenge, |
883 | sizeof(challenge), | 878 | sizeof (challenge), ctx, sizeof (ctx), NULL); |
884 | ctx, | ||
885 | sizeof(ctx), NULL); | ||
886 | } | 879 | } |
887 | 880 | ||
888 | 881 | ||
@@ -893,11 +886,11 @@ derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | |||
893 | * @param n neighbour in question | 886 | * @param n neighbour in question |
894 | * @return absolute timeout | 887 | * @return absolute timeout |
895 | */ | 888 | */ |
896 | static struct GNUNET_TIME_Absolute | 889 | static struct GNUNET_TIME_Absolute |
897 | get_neighbour_timeout (struct Neighbour *n) | 890 | get_neighbour_timeout (struct Neighbour *n) |
898 | { | 891 | { |
899 | return GNUNET_TIME_absolute_add (n->last_activity, | 892 | return GNUNET_TIME_absolute_add (n->last_activity, |
900 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 893 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
901 | } | 894 | } |
902 | 895 | ||
903 | 896 | ||
@@ -905,9 +898,7 @@ get_neighbour_timeout (struct Neighbour *n) | |||
905 | * Helper function for update_preference_sum. | 898 | * Helper function for update_preference_sum. |
906 | */ | 899 | */ |
907 | static int | 900 | static int |
908 | update_preference (void *cls, | 901 | update_preference (void *cls, const GNUNET_HashCode * key, void *value) |
909 | const GNUNET_HashCode *key, | ||
910 | void *value) | ||
911 | { | 902 | { |
912 | unsigned long long *ps = cls; | 903 | unsigned long long *ps = cls; |
913 | struct Neighbour *n = value; | 904 | struct Neighbour *n = value; |
@@ -915,7 +906,7 @@ update_preference (void *cls, | |||
915 | n->current_preference /= 2; | 906 | n->current_preference /= 2; |
916 | *ps += n->current_preference; | 907 | *ps += n->current_preference; |
917 | return GNUNET_OK; | 908 | return GNUNET_OK; |
918 | } | 909 | } |
919 | 910 | ||
920 | 911 | ||
921 | /** | 912 | /** |
@@ -932,13 +923,13 @@ update_preference_sum (unsigned long long inc) | |||
932 | os = preference_sum; | 923 | os = preference_sum; |
933 | preference_sum += inc; | 924 | preference_sum += inc; |
934 | if (preference_sum >= os) | 925 | if (preference_sum >= os) |
935 | return; /* done! */ | 926 | return; /* done! */ |
936 | /* overflow! compensate by cutting all values in half! */ | 927 | /* overflow! compensate by cutting all values in half! */ |
937 | preference_sum = 0; | 928 | preference_sum = 0; |
938 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 929 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
939 | &update_preference, | 930 | &update_preference, &preference_sum); |
940 | &preference_sum); | 931 | GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), |
941 | GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), preference_sum, GNUNET_NO); | 932 | preference_sum, GNUNET_NO); |
942 | } | 933 | } |
943 | 934 | ||
944 | 935 | ||
@@ -966,19 +957,17 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
966 | */ | 957 | */ |
967 | static void | 958 | static void |
968 | send_to_client (struct Client *client, | 959 | send_to_client (struct Client *client, |
969 | const struct GNUNET_MessageHeader *msg, | 960 | const struct GNUNET_MessageHeader *msg, int can_drop) |
970 | int can_drop) | ||
971 | { | 961 | { |
972 | #if DEBUG_CORE_CLIENT | 962 | #if DEBUG_CORE_CLIENT |
973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
974 | "Preparing to send %u bytes of message of type %u to client.\n", | 964 | "Preparing to send %u bytes of message of type %u to client.\n", |
975 | (unsigned int) ntohs (msg->size), | 965 | (unsigned int) ntohs (msg->size), |
976 | (unsigned int) ntohs (msg->type)); | 966 | (unsigned int) ntohs (msg->type)); |
977 | #endif | 967 | #endif |
978 | GNUNET_SERVER_notification_context_unicast (notifier, | 968 | GNUNET_SERVER_notification_context_unicast (notifier, |
979 | client->client_handle, | 969 | client->client_handle, |
980 | msg, | 970 | msg, can_drop); |
981 | can_drop); | ||
982 | } | 971 | } |
983 | 972 | ||
984 | 973 | ||
@@ -991,26 +980,25 @@ send_to_client (struct Client *client, | |||
991 | * @param options mask to use | 980 | * @param options mask to use |
992 | */ | 981 | */ |
993 | static void | 982 | static void |
994 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, | 983 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, |
995 | int can_drop, | 984 | int can_drop, int options) |
996 | int options) | ||
997 | { | 985 | { |
998 | struct Client *c; | 986 | struct Client *c; |
999 | 987 | ||
1000 | c = clients; | 988 | c = clients; |
1001 | while (c != NULL) | 989 | while (c != NULL) |
990 | { | ||
991 | if (0 != (c->options & options)) | ||
1002 | { | 992 | { |
1003 | if (0 != (c->options & options)) | ||
1004 | { | ||
1005 | #if DEBUG_CORE_CLIENT > 1 | 993 | #if DEBUG_CORE_CLIENT > 1 |
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 994 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1007 | "Sending message of type %u to client.\n", | 995 | "Sending message of type %u to client.\n", |
1008 | (unsigned int) ntohs (msg->type)); | 996 | (unsigned int) ntohs (msg->type)); |
1009 | #endif | 997 | #endif |
1010 | send_to_client (c, msg, can_drop); | 998 | send_to_client (c, msg, can_drop); |
1011 | } | ||
1012 | c = c->next; | ||
1013 | } | 999 | } |
1000 | c = c->next; | ||
1001 | } | ||
1014 | } | 1002 | } |
1015 | 1003 | ||
1016 | 1004 | ||
@@ -1028,27 +1016,23 @@ handle_peer_status_change (struct Neighbour *n) | |||
1028 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 1016 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
1029 | size_t size; | 1017 | size_t size; |
1030 | 1018 | ||
1031 | if ( (! n->is_connected) || | 1019 | if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED)) |
1032 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | ||
1033 | return; | 1020 | return; |
1034 | #if DEBUG_CORE > 1 | 1021 | #if DEBUG_CORE > 1 |
1035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1036 | "Peer `%4s' changed status\n", | 1023 | "Peer `%4s' changed status\n", GNUNET_i2s (&n->peer)); |
1037 | GNUNET_i2s (&n->peer)); | ||
1038 | #endif | 1024 | #endif |
1039 | size = sizeof (struct PeerStatusNotifyMessage) + | 1025 | size = sizeof (struct PeerStatusNotifyMessage) + |
1040 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1026 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1041 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1027 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1042 | { | 1028 | { |
1043 | GNUNET_break (0); | 1029 | GNUNET_break (0); |
1044 | /* recovery strategy: throw away performance data */ | 1030 | /* recovery strategy: throw away performance data */ |
1045 | GNUNET_array_grow (n->ats, | 1031 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1046 | n->ats_count, | 1032 | size = sizeof (struct PeerStatusNotifyMessage) + |
1047 | 0); | 1033 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1048 | size = sizeof (struct PeerStatusNotifyMessage) + | 1034 | } |
1049 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1035 | psnm = (struct PeerStatusNotifyMessage *) buf; |
1050 | } | ||
1051 | psnm = (struct PeerStatusNotifyMessage*) buf; | ||
1052 | psnm->header.size = htons (size); | 1036 | psnm->header.size = htons (size); |
1053 | psnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE); | 1037 | psnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE); |
1054 | psnm->timeout = GNUNET_TIME_absolute_hton (get_neighbour_timeout (n)); | 1038 | psnm->timeout = GNUNET_TIME_absolute_hton (get_neighbour_timeout (n)); |
@@ -1058,17 +1042,15 @@ handle_peer_status_change (struct Neighbour *n) | |||
1058 | psnm->ats_count = htonl (n->ats_count); | 1042 | psnm->ats_count = htonl (n->ats_count); |
1059 | ats = &psnm->ats; | 1043 | ats = &psnm->ats; |
1060 | memcpy (ats, | 1044 | memcpy (ats, |
1061 | n->ats, | 1045 | n->ats, |
1062 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 1046 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
1063 | ats[n->ats_count].type = htonl (0); | 1047 | ats[n->ats_count].type = htonl (0); |
1064 | ats[n->ats_count].value = htonl (0); | 1048 | ats[n->ats_count].value = htonl (0); |
1065 | send_to_all_clients (&psnm->header, | 1049 | send_to_all_clients (&psnm->header, |
1066 | GNUNET_YES, | 1050 | GNUNET_YES, GNUNET_CORE_OPTION_SEND_STATUS_CHANGE); |
1067 | GNUNET_CORE_OPTION_SEND_STATUS_CHANGE); | 1051 | GNUNET_STATISTICS_update (stats, |
1068 | GNUNET_STATISTICS_update (stats, | 1052 | gettext_noop ("# peer status changes"), |
1069 | gettext_noop ("# peer status changes"), | 1053 | 1, GNUNET_NO); |
1070 | 1, | ||
1071 | GNUNET_NO); | ||
1072 | } | 1054 | } |
1073 | 1055 | ||
1074 | 1056 | ||
@@ -1088,55 +1070,53 @@ schedule_peer_messages (struct Neighbour *n) | |||
1088 | struct Client *c; | 1070 | struct Client *c; |
1089 | struct MessageEntry *mqe; | 1071 | struct MessageEntry *mqe; |
1090 | unsigned int queue_size; | 1072 | unsigned int queue_size; |
1091 | 1073 | ||
1092 | /* check if neighbour queue is empty enough! */ | 1074 | /* check if neighbour queue is empty enough! */ |
1093 | if (n != &self) | 1075 | if (n != &self) |
1076 | { | ||
1077 | queue_size = 0; | ||
1078 | mqe = n->messages; | ||
1079 | while (mqe != NULL) | ||
1080 | { | ||
1081 | queue_size++; | ||
1082 | mqe = mqe->next; | ||
1083 | } | ||
1084 | if (queue_size >= MAX_PEER_QUEUE_SIZE) | ||
1094 | { | 1085 | { |
1095 | queue_size = 0; | ||
1096 | mqe = n->messages; | ||
1097 | while (mqe != NULL) | ||
1098 | { | ||
1099 | queue_size++; | ||
1100 | mqe = mqe->next; | ||
1101 | } | ||
1102 | if (queue_size >= MAX_PEER_QUEUE_SIZE) | ||
1103 | { | ||
1104 | #if DEBUG_CORE_CLIENT | 1086 | #if DEBUG_CORE_CLIENT |
1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1106 | "Not considering client transmission requests: queue full\n"); | 1088 | "Not considering client transmission requests: queue full\n"); |
1107 | #endif | 1089 | #endif |
1108 | return; /* queue still full */ | 1090 | return; /* queue still full */ |
1109 | } | ||
1110 | /* find highest priority request */ | ||
1111 | pos = n->active_client_request_head; | ||
1112 | car = NULL; | ||
1113 | while (pos != NULL) | ||
1114 | { | ||
1115 | if ( (car == NULL) || | ||
1116 | (pos->priority > car->priority) ) | ||
1117 | car = pos; | ||
1118 | pos = pos->next; | ||
1119 | } | ||
1120 | } | 1091 | } |
1121 | else | 1092 | /* find highest priority request */ |
1093 | pos = n->active_client_request_head; | ||
1094 | car = NULL; | ||
1095 | while (pos != NULL) | ||
1122 | { | 1096 | { |
1123 | car = n->active_client_request_head; | 1097 | if ((car == NULL) || (pos->priority > car->priority)) |
1098 | car = pos; | ||
1099 | pos = pos->next; | ||
1124 | } | 1100 | } |
1101 | } | ||
1102 | else | ||
1103 | { | ||
1104 | car = n->active_client_request_head; | ||
1105 | } | ||
1125 | if (car == NULL) | 1106 | if (car == NULL) |
1126 | return; /* no pending requests */ | 1107 | return; /* no pending requests */ |
1127 | #if DEBUG_CORE_CLIENT | 1108 | #if DEBUG_CORE_CLIENT |
1128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1129 | "Permitting client transmission request to `%s'\n", | 1110 | "Permitting client transmission request to `%s'\n", |
1130 | GNUNET_i2s (&n->peer)); | 1111 | GNUNET_i2s (&n->peer)); |
1131 | #endif | 1112 | #endif |
1132 | c = car->client; | 1113 | c = car->client; |
1133 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 1114 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
1134 | n->active_client_request_tail, | 1115 | n->active_client_request_tail, car); |
1135 | car); | ||
1136 | GNUNET_assert (GNUNET_YES == | 1116 | GNUNET_assert (GNUNET_YES == |
1137 | GNUNET_CONTAINER_multihashmap_remove (c->requests, | 1117 | GNUNET_CONTAINER_multihashmap_remove (c->requests, |
1138 | &n->peer.hashPubKey, | 1118 | &n->peer.hashPubKey, |
1139 | car)); | 1119 | car)); |
1140 | smr.header.size = htons (sizeof (struct SendMessageReady)); | 1120 | smr.header.size = htons (sizeof (struct SendMessageReady)); |
1141 | smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY); | 1121 | smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY); |
1142 | smr.size = htons (car->msize); | 1122 | smr.size = htons (car->msize); |
@@ -1160,27 +1140,28 @@ compute_type_map_message () | |||
1160 | struct GNUNET_MessageHeader *hdr; | 1140 | struct GNUNET_MessageHeader *hdr; |
1161 | 1141 | ||
1162 | #ifdef compressBound | 1142 | #ifdef compressBound |
1163 | dlen = compressBound (sizeof(my_type_map)); | 1143 | dlen = compressBound (sizeof (my_type_map)); |
1164 | #else | 1144 | #else |
1165 | dlen = sizeof(my_type_map) + (sizeof(my_type_map) / 100) + 20; | 1145 | dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20; |
1166 | /* documentation says 100.1% oldSize + 12 bytes, but we | 1146 | /* documentation says 100.1% oldSize + 12 bytes, but we |
1167 | should be able to overshoot by more to be safe */ | 1147 | * should be able to overshoot by more to be safe */ |
1168 | #endif | 1148 | #endif |
1169 | hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); | 1149 | hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); |
1170 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); | 1150 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); |
1171 | tmp = (char*) &hdr[1]; | 1151 | tmp = (char *) &hdr[1]; |
1172 | if ( (Z_OK != compress2 ((Bytef *) tmp, | 1152 | if ((Z_OK != compress2 ((Bytef *) tmp, |
1173 | &dlen, (const Bytef *) my_type_map, sizeof (my_type_map), 9)) || | 1153 | &dlen, (const Bytef *) my_type_map, |
1174 | (dlen >= sizeof(my_type_map)) ) | 1154 | sizeof (my_type_map), 9)) || |
1175 | { | 1155 | (dlen >= sizeof (my_type_map))) |
1176 | dlen = sizeof (my_type_map); | 1156 | { |
1177 | memcpy (tmp, my_type_map, sizeof (my_type_map)); | 1157 | dlen = sizeof (my_type_map); |
1178 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); | 1158 | memcpy (tmp, my_type_map, sizeof (my_type_map)); |
1179 | } | 1159 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); |
1160 | } | ||
1180 | else | 1161 | else |
1181 | { | 1162 | { |
1182 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); | 1163 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); |
1183 | } | 1164 | } |
1184 | return hdr; | 1165 | return hdr; |
1185 | } | 1166 | } |
1186 | 1167 | ||
@@ -1194,9 +1175,7 @@ compute_type_map_message () | |||
1194 | * @return always GNUNET_OK | 1175 | * @return always GNUNET_OK |
1195 | */ | 1176 | */ |
1196 | static int | 1177 | static int |
1197 | send_type_map_to_neighbour (void *cls, | 1178 | send_type_map_to_neighbour (void *cls, const GNUNET_HashCode * key, void *value) |
1198 | const GNUNET_HashCode *key, | ||
1199 | void *value) | ||
1200 | { | 1179 | { |
1201 | struct GNUNET_MessageHeader *hdr = cls; | 1180 | struct GNUNET_MessageHeader *hdr = cls; |
1202 | struct Neighbour *n = value; | 1181 | struct Neighbour *n = value; |
@@ -1225,15 +1204,14 @@ send_type_map_to_neighbour (void *cls, | |||
1225 | */ | 1204 | */ |
1226 | static void | 1205 | static void |
1227 | broadcast_my_type_map () | 1206 | broadcast_my_type_map () |
1228 | { | 1207 | { |
1229 | struct GNUNET_MessageHeader *hdr; | 1208 | struct GNUNET_MessageHeader *hdr; |
1230 | 1209 | ||
1231 | if (NULL == neighbours) | 1210 | if (NULL == neighbours) |
1232 | return; | 1211 | return; |
1233 | hdr = compute_type_map_message (); | 1212 | hdr = compute_type_map_message (); |
1234 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 1213 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
1235 | &send_type_map_to_neighbour, | 1214 | &send_type_map_to_neighbour, hdr); |
1236 | hdr); | ||
1237 | GNUNET_free (hdr); | 1215 | GNUNET_free (hdr); |
1238 | } | 1216 | } |
1239 | 1217 | ||
@@ -1243,72 +1221,68 @@ broadcast_my_type_map () | |||
1243 | */ | 1221 | */ |
1244 | static void | 1222 | static void |
1245 | handle_client_send_request (void *cls, | 1223 | handle_client_send_request (void *cls, |
1246 | struct GNUNET_SERVER_Client *client, | 1224 | struct GNUNET_SERVER_Client *client, |
1247 | const struct GNUNET_MessageHeader *message) | 1225 | const struct GNUNET_MessageHeader *message) |
1248 | { | 1226 | { |
1249 | const struct SendMessageRequest *req; | 1227 | const struct SendMessageRequest *req; |
1250 | struct Neighbour *n; | 1228 | struct Neighbour *n; |
1251 | struct Client *c; | 1229 | struct Client *c; |
1252 | struct ClientActiveRequest *car; | 1230 | struct ClientActiveRequest *car; |
1253 | 1231 | ||
1254 | req = (const struct SendMessageRequest*) message; | 1232 | req = (const struct SendMessageRequest *) message; |
1255 | if (0 == memcmp (&req->peer, | 1233 | if (0 == memcmp (&req->peer, |
1256 | &my_identity, | 1234 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
1257 | sizeof (struct GNUNET_PeerIdentity))) | ||
1258 | n = &self; | 1235 | n = &self; |
1259 | else | 1236 | else |
1260 | n = find_neighbour (&req->peer); | 1237 | n = find_neighbour (&req->peer); |
1261 | if ( (n == NULL) || | 1238 | if ((n == NULL) || |
1262 | (GNUNET_YES != n->is_connected) || | 1239 | (GNUNET_YES != n->is_connected) || |
1263 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | 1240 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
1264 | { | 1241 | { |
1265 | /* neighbour must have disconnected since request was issued, | 1242 | /* neighbour must have disconnected since request was issued, |
1266 | ignore (client will realize it once it processes the | 1243 | * ignore (client will realize it once it processes the |
1267 | disconnect notification) */ | 1244 | * disconnect notification) */ |
1268 | #if DEBUG_CORE_CLIENT | 1245 | #if DEBUG_CORE_CLIENT |
1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Dropped client request for transmission (am disconnected)\n"); | 1247 | "Dropped client request for transmission (am disconnected)\n"); |
1271 | #endif | 1248 | #endif |
1272 | GNUNET_STATISTICS_update (stats, | 1249 | GNUNET_STATISTICS_update (stats, |
1273 | gettext_noop ("# send requests dropped (disconnected)"), | 1250 | gettext_noop |
1274 | 1, | 1251 | ("# send requests dropped (disconnected)"), 1, |
1275 | GNUNET_NO); | 1252 | GNUNET_NO); |
1276 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1253 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1277 | return; | 1254 | return; |
1278 | } | 1255 | } |
1279 | c = clients; | 1256 | c = clients; |
1280 | while ( (c != NULL) && | 1257 | while ((c != NULL) && (c->client_handle != client)) |
1281 | (c->client_handle != client) ) | ||
1282 | c = c->next; | 1258 | c = c->next; |
1283 | if (c == NULL) | 1259 | if (c == NULL) |
1284 | { | 1260 | { |
1285 | /* client did not send INIT first! */ | 1261 | /* client did not send INIT first! */ |
1286 | GNUNET_break (0); | 1262 | GNUNET_break (0); |
1287 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1263 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1288 | return; | 1264 | return; |
1289 | } | 1265 | } |
1290 | if (c->requests == NULL) | 1266 | if (c->requests == NULL) |
1291 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); | 1267 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); |
1292 | #if DEBUG_CORE_CLIENT | 1268 | #if DEBUG_CORE_CLIENT |
1293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1294 | "Received client transmission request. queueing\n"); | 1270 | "Received client transmission request. queueing\n"); |
1295 | #endif | 1271 | #endif |
1296 | car = GNUNET_CONTAINER_multihashmap_get (c->requests, | 1272 | car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey); |
1297 | &req->peer.hashPubKey); | ||
1298 | if (car == NULL) | 1273 | if (car == NULL) |
1299 | { | 1274 | { |
1300 | /* create new entry */ | 1275 | /* create new entry */ |
1301 | car = GNUNET_malloc (sizeof (struct ClientActiveRequest)); | 1276 | car = GNUNET_malloc (sizeof (struct ClientActiveRequest)); |
1302 | GNUNET_assert (GNUNET_OK == | 1277 | GNUNET_assert (GNUNET_OK == |
1303 | GNUNET_CONTAINER_multihashmap_put (c->requests, | 1278 | GNUNET_CONTAINER_multihashmap_put (c->requests, |
1304 | &req->peer.hashPubKey, | 1279 | &req->peer.hashPubKey, |
1305 | car, | 1280 | car, |
1306 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 1281 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
1307 | GNUNET_CONTAINER_DLL_insert (n->active_client_request_head, | 1282 | GNUNET_CONTAINER_DLL_insert (n->active_client_request_head, |
1308 | n->active_client_request_tail, | 1283 | n->active_client_request_tail, car); |
1309 | car); | 1284 | car->client = c; |
1310 | car->client = c; | 1285 | } |
1311 | } | ||
1312 | car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); | 1286 | car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); |
1313 | car->priority = ntohl (req->priority); | 1287 | car->priority = ntohl (req->priority); |
1314 | car->queue_size = ntohl (req->queue_size); | 1288 | car->queue_size = ntohl (req->queue_size); |
@@ -1324,8 +1298,7 @@ handle_client_send_request (void *cls, | |||
1324 | */ | 1298 | */ |
1325 | static int | 1299 | static int |
1326 | notify_client_about_neighbour (void *cls, | 1300 | notify_client_about_neighbour (void *cls, |
1327 | const GNUNET_HashCode *key, | 1301 | const GNUNET_HashCode * key, void *value) |
1328 | void *value) | ||
1329 | { | 1302 | { |
1330 | struct Client *c = cls; | 1303 | struct Client *c = cls; |
1331 | struct Neighbour *n = value; | 1304 | struct Neighbour *n = value; |
@@ -1335,36 +1308,34 @@ notify_client_about_neighbour (void *cls, | |||
1335 | struct ConnectNotifyMessage *cnm; | 1308 | struct ConnectNotifyMessage *cnm; |
1336 | 1309 | ||
1337 | size = sizeof (struct ConnectNotifyMessage) + | 1310 | size = sizeof (struct ConnectNotifyMessage) + |
1338 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1311 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1339 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1312 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1340 | { | 1313 | { |
1341 | GNUNET_break (0); | 1314 | GNUNET_break (0); |
1342 | /* recovery strategy: throw away performance data */ | 1315 | /* recovery strategy: throw away performance data */ |
1343 | GNUNET_array_grow (n->ats, | 1316 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1344 | n->ats_count, | 1317 | size = sizeof (struct ConnectNotifyMessage) + |
1345 | 0); | 1318 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1346 | size = sizeof (struct ConnectNotifyMessage) + | 1319 | } |
1347 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1320 | cnm = (struct ConnectNotifyMessage *) buf; |
1348 | } | ||
1349 | cnm = (struct ConnectNotifyMessage*) buf; | ||
1350 | cnm->header.size = htons (size); | 1321 | cnm->header.size = htons (size); |
1351 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | 1322 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); |
1352 | cnm->ats_count = htonl (n->ats_count); | 1323 | cnm->ats_count = htonl (n->ats_count); |
1353 | ats = &cnm->ats; | 1324 | ats = &cnm->ats; |
1354 | memcpy (ats, | 1325 | memcpy (ats, |
1355 | n->ats, | 1326 | n->ats, |
1356 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count); | 1327 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count); |
1357 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 1328 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
1358 | ats[n->ats_count].value = htonl (0); | 1329 | ats[n->ats_count].value = htonl (0); |
1359 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 1330 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
1360 | { | 1331 | { |
1361 | #if DEBUG_CORE_CLIENT | 1332 | #if DEBUG_CORE_CLIENT |
1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1363 | "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); | 1334 | "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); |
1364 | #endif | 1335 | #endif |
1365 | cnm->peer = n->peer; | 1336 | cnm->peer = n->peer; |
1366 | send_to_client (c, &cnm->header, GNUNET_NO); | 1337 | send_to_client (c, &cnm->header, GNUNET_NO); |
1367 | } | 1338 | } |
1368 | return GNUNET_OK; | 1339 | return GNUNET_OK; |
1369 | } | 1340 | } |
1370 | 1341 | ||
@@ -1388,28 +1359,27 @@ handle_client_init (void *cls, | |||
1388 | 1359 | ||
1389 | #if DEBUG_CORE_CLIENT | 1360 | #if DEBUG_CORE_CLIENT |
1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1391 | "Client connecting to core service with `%s' message\n", | 1362 | "Client connecting to core service with `%s' message\n", "INIT"); |
1392 | "INIT"); | ||
1393 | #endif | 1363 | #endif |
1394 | /* check that we don't have an entry already */ | 1364 | /* check that we don't have an entry already */ |
1395 | c = clients; | 1365 | c = clients; |
1396 | while (c != NULL) | 1366 | while (c != NULL) |
1397 | { | 1367 | { |
1398 | if (client == c->client_handle) | 1368 | if (client == c->client_handle) |
1399 | { | ||
1400 | GNUNET_break (0); | ||
1401 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1402 | return; | ||
1403 | } | ||
1404 | c = c->next; | ||
1405 | } | ||
1406 | msize = ntohs (message->size); | ||
1407 | if (msize < sizeof (struct InitMessage)) | ||
1408 | { | 1369 | { |
1409 | GNUNET_break (0); | 1370 | GNUNET_break (0); |
1410 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1371 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1411 | return; | 1372 | return; |
1412 | } | 1373 | } |
1374 | c = c->next; | ||
1375 | } | ||
1376 | msize = ntohs (message->size); | ||
1377 | if (msize < sizeof (struct InitMessage)) | ||
1378 | { | ||
1379 | GNUNET_break (0); | ||
1380 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1381 | return; | ||
1382 | } | ||
1413 | GNUNET_SERVER_notification_context_add (notifier, client); | 1383 | GNUNET_SERVER_notification_context_add (notifier, client); |
1414 | im = (const struct InitMessage *) message; | 1384 | im = (const struct InitMessage *) message; |
1415 | types = (const uint16_t *) &im[1]; | 1385 | types = (const uint16_t *) &im[1]; |
@@ -1420,20 +1390,19 @@ handle_client_init (void *cls, | |||
1420 | clients = c; | 1390 | clients = c; |
1421 | c->tcnt = msize / sizeof (uint16_t); | 1391 | c->tcnt = msize / sizeof (uint16_t); |
1422 | c->types = (const uint16_t *) &c[1]; | 1392 | c->types = (const uint16_t *) &c[1]; |
1423 | wtypes = (uint16_t *) &c[1]; | 1393 | wtypes = (uint16_t *) & c[1]; |
1424 | for (i=0;i<c->tcnt;i++) | 1394 | for (i = 0; i < c->tcnt; i++) |
1425 | { | 1395 | { |
1426 | wtypes[i] = ntohs (types[i]); | 1396 | wtypes[i] = ntohs (types[i]); |
1427 | my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32)); | 1397 | my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32)); |
1428 | } | 1398 | } |
1429 | if (c->tcnt > 0) | 1399 | if (c->tcnt > 0) |
1430 | broadcast_my_type_map (); | 1400 | broadcast_my_type_map (); |
1431 | c->options = ntohl (im->options); | 1401 | c->options = ntohl (im->options); |
1432 | #if DEBUG_CORE_CLIENT | 1402 | #if DEBUG_CORE_CLIENT |
1433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1434 | "Client %p is interested in %u message types\n", | 1404 | "Client %p is interested in %u message types\n", |
1435 | c, | 1405 | c, (unsigned int) c->tcnt); |
1436 | (unsigned int) c->tcnt); | ||
1437 | #endif | 1406 | #endif |
1438 | /* send init reply message */ | 1407 | /* send init reply message */ |
1439 | irm.header.size = htons (sizeof (struct InitReplyMessage)); | 1408 | irm.header.size = htons (sizeof (struct InitReplyMessage)); |
@@ -1448,12 +1417,11 @@ handle_client_init (void *cls, | |||
1448 | #endif | 1417 | #endif |
1449 | send_to_client (c, &irm.header, GNUNET_NO); | 1418 | send_to_client (c, &irm.header, GNUNET_NO); |
1450 | if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) | 1419 | if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) |
1451 | { | 1420 | { |
1452 | /* notify new client about existing neighbours */ | 1421 | /* notify new client about existing neighbours */ |
1453 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 1422 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
1454 | ¬ify_client_about_neighbour, | 1423 | ¬ify_client_about_neighbour, c); |
1455 | c); | 1424 | } |
1456 | } | ||
1457 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1425 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1458 | } | 1426 | } |
1459 | 1427 | ||
@@ -1468,8 +1436,7 @@ handle_client_init (void *cls, | |||
1468 | */ | 1436 | */ |
1469 | static int | 1437 | static int |
1470 | destroy_active_client_request (void *cls, | 1438 | destroy_active_client_request (void *cls, |
1471 | const GNUNET_HashCode *key, | 1439 | const GNUNET_HashCode * key, void *value) |
1472 | void *value) | ||
1473 | { | 1440 | { |
1474 | struct ClientActiveRequest *car = value; | 1441 | struct ClientActiveRequest *car = value; |
1475 | struct Neighbour *n; | 1442 | struct Neighbour *n; |
@@ -1479,8 +1446,7 @@ destroy_active_client_request (void *cls, | |||
1479 | n = find_neighbour (&peer); | 1446 | n = find_neighbour (&peer); |
1480 | GNUNET_assert (NULL != n); | 1447 | GNUNET_assert (NULL != n); |
1481 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 1448 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
1482 | n->active_client_request_tail, | 1449 | n->active_client_request_tail, car); |
1483 | car); | ||
1484 | GNUNET_free (car); | 1450 | GNUNET_free (car); |
1485 | return GNUNET_YES; | 1451 | return GNUNET_YES; |
1486 | } | 1452 | } |
@@ -1504,44 +1470,43 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1504 | return; | 1470 | return; |
1505 | #if DEBUG_CORE_CLIENT | 1471 | #if DEBUG_CORE_CLIENT |
1506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "Client %p has disconnected from core service.\n", | 1473 | "Client %p has disconnected from core service.\n", client); |
1508 | client); | ||
1509 | #endif | 1474 | #endif |
1510 | prev = NULL; | 1475 | prev = NULL; |
1511 | pos = clients; | 1476 | pos = clients; |
1512 | while (pos != NULL) | 1477 | while (pos != NULL) |
1513 | { | 1478 | { |
1514 | if (client == pos->client_handle) | 1479 | if (client == pos->client_handle) |
1515 | break; | 1480 | break; |
1516 | prev = pos; | 1481 | prev = pos; |
1517 | pos = pos->next; | 1482 | pos = pos->next; |
1518 | } | 1483 | } |
1519 | if (pos == NULL) | 1484 | if (pos == NULL) |
1520 | { | 1485 | { |
1521 | /* client never sent INIT */ | 1486 | /* client never sent INIT */ |
1522 | return; | 1487 | return; |
1523 | } | 1488 | } |
1524 | if (prev == NULL) | 1489 | if (prev == NULL) |
1525 | clients = pos->next; | 1490 | clients = pos->next; |
1526 | else | 1491 | else |
1527 | prev->next = pos->next; | 1492 | prev->next = pos->next; |
1528 | if (pos->requests != NULL) | 1493 | if (pos->requests != NULL) |
1529 | { | 1494 | { |
1530 | GNUNET_CONTAINER_multihashmap_iterate (pos->requests, | 1495 | GNUNET_CONTAINER_multihashmap_iterate (pos->requests, |
1531 | &destroy_active_client_request, | 1496 | &destroy_active_client_request, |
1532 | NULL); | 1497 | NULL); |
1533 | GNUNET_CONTAINER_multihashmap_destroy (pos->requests); | 1498 | GNUNET_CONTAINER_multihashmap_destroy (pos->requests); |
1534 | } | 1499 | } |
1535 | GNUNET_free (pos); | 1500 | GNUNET_free (pos); |
1536 | 1501 | ||
1537 | /* rebuild my_type_map */ | 1502 | /* rebuild my_type_map */ |
1538 | memset (my_type_map, 0, sizeof (my_type_map)); | 1503 | memset (my_type_map, 0, sizeof (my_type_map)); |
1539 | for (pos = clients; NULL != pos; pos = pos->next) | 1504 | for (pos = clients; NULL != pos; pos = pos->next) |
1540 | { | 1505 | { |
1541 | wtypes = (const uint16_t *) &pos[1]; | 1506 | wtypes = (const uint16_t *) &pos[1]; |
1542 | for (i=0;i<pos->tcnt;i++) | 1507 | for (i = 0; i < pos->tcnt; i++) |
1543 | my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32)); | 1508 | my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32)); |
1544 | } | 1509 | } |
1545 | broadcast_my_type_map (); | 1510 | broadcast_my_type_map (); |
1546 | } | 1511 | } |
1547 | 1512 | ||
@@ -1555,9 +1520,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1555 | * @return GNUNET_OK (continue to iterate) | 1520 | * @return GNUNET_OK (continue to iterate) |
1556 | */ | 1521 | */ |
1557 | static int | 1522 | static int |
1558 | queue_connect_message (void *cls, | 1523 | queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value) |
1559 | const GNUNET_HashCode *key, | ||
1560 | void *value) | ||
1561 | { | 1524 | { |
1562 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 1525 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
1563 | struct Neighbour *n = value; | 1526 | struct Neighbour *n = value; |
@@ -1566,39 +1529,35 @@ queue_connect_message (void *cls, | |||
1566 | size_t size; | 1529 | size_t size; |
1567 | struct ConnectNotifyMessage *cnm; | 1530 | struct ConnectNotifyMessage *cnm; |
1568 | 1531 | ||
1569 | cnm = (struct ConnectNotifyMessage*) buf; | 1532 | cnm = (struct ConnectNotifyMessage *) buf; |
1570 | if (n->status != PEER_STATE_KEY_CONFIRMED) | 1533 | if (n->status != PEER_STATE_KEY_CONFIRMED) |
1571 | return GNUNET_OK; | 1534 | return GNUNET_OK; |
1572 | size = sizeof (struct ConnectNotifyMessage) + | 1535 | size = sizeof (struct ConnectNotifyMessage) + |
1573 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1536 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1574 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1537 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1575 | { | 1538 | { |
1576 | GNUNET_break (0); | 1539 | GNUNET_break (0); |
1577 | /* recovery strategy: throw away performance data */ | 1540 | /* recovery strategy: throw away performance data */ |
1578 | GNUNET_array_grow (n->ats, | 1541 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1579 | n->ats_count, | 1542 | size = sizeof (struct PeerStatusNotifyMessage) + |
1580 | 0); | 1543 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1581 | size = sizeof (struct PeerStatusNotifyMessage) + | 1544 | } |
1582 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1545 | cnm = (struct ConnectNotifyMessage *) buf; |
1583 | } | ||
1584 | cnm = (struct ConnectNotifyMessage*) buf; | ||
1585 | cnm->header.size = htons (size); | 1546 | cnm->header.size = htons (size); |
1586 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | 1547 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); |
1587 | cnm->ats_count = htonl (n->ats_count); | 1548 | cnm->ats_count = htonl (n->ats_count); |
1588 | ats = &cnm->ats; | 1549 | ats = &cnm->ats; |
1589 | memcpy (ats, | 1550 | memcpy (ats, |
1590 | n->ats, | 1551 | n->ats, |
1591 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 1552 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
1592 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 1553 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
1593 | ats[n->ats_count].value = htonl (0); | 1554 | ats[n->ats_count].value = htonl (0); |
1594 | #if DEBUG_CORE_CLIENT | 1555 | #if DEBUG_CORE_CLIENT |
1595 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1596 | "Sending `%s' message to client.\n", | 1557 | "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); |
1597 | "NOTIFY_CONNECT"); | ||
1598 | #endif | 1558 | #endif |
1599 | cnm->peer = n->peer; | 1559 | cnm->peer = n->peer; |
1600 | GNUNET_SERVER_transmit_context_append_message (tc, | 1560 | GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header); |
1601 | &cnm->header); | ||
1602 | return GNUNET_OK; | 1561 | return GNUNET_OK; |
1603 | } | 1562 | } |
1604 | 1563 | ||
@@ -1612,27 +1571,27 @@ queue_connect_message (void *cls, | |||
1612 | */ | 1571 | */ |
1613 | static void | 1572 | static void |
1614 | handle_client_iterate_peers (void *cls, | 1573 | handle_client_iterate_peers (void *cls, |
1615 | struct GNUNET_SERVER_Client *client, | 1574 | struct GNUNET_SERVER_Client *client, |
1616 | const struct GNUNET_MessageHeader *message) | 1575 | const struct GNUNET_MessageHeader *message) |
1617 | |||
1618 | { | 1576 | { |
1619 | struct GNUNET_MessageHeader done_msg; | 1577 | struct GNUNET_MessageHeader done_msg; |
1620 | struct GNUNET_SERVER_TransmitContext *tc; | 1578 | struct GNUNET_SERVER_TransmitContext *tc; |
1621 | int msize; | 1579 | int msize; |
1580 | |||
1622 | /* notify new client about existing neighbours */ | 1581 | /* notify new client about existing neighbours */ |
1623 | 1582 | ||
1624 | msize = ntohs(message->size); | 1583 | msize = ntohs (message->size); |
1625 | tc = GNUNET_SERVER_transmit_context_create (client); | 1584 | tc = GNUNET_SERVER_transmit_context_create (client); |
1626 | if (msize == sizeof(struct GNUNET_MessageHeader)) | 1585 | if (msize == sizeof (struct GNUNET_MessageHeader)) |
1627 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message, tc); | 1586 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message, |
1587 | tc); | ||
1628 | else | 1588 | else |
1629 | GNUNET_break(0); | 1589 | GNUNET_break (0); |
1630 | 1590 | ||
1631 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 1591 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
1632 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); | 1592 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); |
1633 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); | 1593 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); |
1634 | GNUNET_SERVER_transmit_context_run (tc, | 1594 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
1635 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1636 | } | 1595 | } |
1637 | 1596 | ||
1638 | 1597 | ||
@@ -1645,9 +1604,8 @@ handle_client_iterate_peers (void *cls, | |||
1645 | */ | 1604 | */ |
1646 | static void | 1605 | static void |
1647 | handle_client_have_peer (void *cls, | 1606 | handle_client_have_peer (void *cls, |
1648 | struct GNUNET_SERVER_Client *client, | 1607 | struct GNUNET_SERVER_Client *client, |
1649 | const struct GNUNET_MessageHeader *message) | 1608 | const struct GNUNET_MessageHeader *message) |
1650 | |||
1651 | { | 1609 | { |
1652 | struct GNUNET_MessageHeader done_msg; | 1610 | struct GNUNET_MessageHeader done_msg; |
1653 | struct GNUNET_SERVER_TransmitContext *tc; | 1611 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -1655,15 +1613,13 @@ handle_client_have_peer (void *cls, | |||
1655 | 1613 | ||
1656 | tc = GNUNET_SERVER_transmit_context_create (client); | 1614 | tc = GNUNET_SERVER_transmit_context_create (client); |
1657 | peer = (struct GNUNET_PeerIdentity *) &message[1]; | 1615 | peer = (struct GNUNET_PeerIdentity *) &message[1]; |
1658 | GNUNET_CONTAINER_multihashmap_get_multiple(neighbours, | 1616 | GNUNET_CONTAINER_multihashmap_get_multiple (neighbours, |
1659 | &peer->hashPubKey, | 1617 | &peer->hashPubKey, |
1660 | &queue_connect_message, | 1618 | &queue_connect_message, tc); |
1661 | tc); | ||
1662 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 1619 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
1663 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); | 1620 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); |
1664 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); | 1621 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); |
1665 | GNUNET_SERVER_transmit_context_run (tc, | 1622 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
1666 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1667 | } | 1623 | } |
1668 | 1624 | ||
1669 | 1625 | ||
@@ -1676,8 +1632,8 @@ handle_client_have_peer (void *cls, | |||
1676 | */ | 1632 | */ |
1677 | static void | 1633 | static void |
1678 | handle_client_request_info (void *cls, | 1634 | handle_client_request_info (void *cls, |
1679 | struct GNUNET_SERVER_Client *client, | 1635 | struct GNUNET_SERVER_Client *client, |
1680 | const struct GNUNET_MessageHeader *message) | 1636 | const struct GNUNET_MessageHeader *message) |
1681 | { | 1637 | { |
1682 | const struct RequestInfoMessage *rcm; | 1638 | const struct RequestInfoMessage *rcm; |
1683 | struct Client *pos; | 1639 | struct Client *pos; |
@@ -1688,97 +1644,94 @@ handle_client_request_info (void *cls, | |||
1688 | unsigned long long old_preference; | 1644 | unsigned long long old_preference; |
1689 | struct GNUNET_TIME_Relative rdelay; | 1645 | struct GNUNET_TIME_Relative rdelay; |
1690 | 1646 | ||
1691 | rdelay = GNUNET_TIME_relative_get_zero(); | 1647 | rdelay = GNUNET_TIME_relative_get_zero (); |
1692 | #if DEBUG_CORE_CLIENT | 1648 | #if DEBUG_CORE_CLIENT |
1693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1694 | "Core service receives `%s' request.\n", "REQUEST_INFO"); | 1650 | "Core service receives `%s' request.\n", "REQUEST_INFO"); |
1695 | #endif | 1651 | #endif |
1696 | pos = clients; | 1652 | pos = clients; |
1697 | while (pos != NULL) | 1653 | while (pos != NULL) |
1698 | { | 1654 | { |
1699 | if (client == pos->client_handle) | 1655 | if (client == pos->client_handle) |
1700 | break; | 1656 | break; |
1701 | pos = pos->next; | 1657 | pos = pos->next; |
1702 | } | 1658 | } |
1703 | if (pos == NULL) | 1659 | if (pos == NULL) |
1704 | { | 1660 | { |
1705 | GNUNET_break (0); | 1661 | GNUNET_break (0); |
1706 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1662 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1707 | return; | 1663 | return; |
1708 | } | 1664 | } |
1709 | 1665 | ||
1710 | rcm = (const struct RequestInfoMessage *) message; | 1666 | rcm = (const struct RequestInfoMessage *) message; |
1711 | n = find_neighbour (&rcm->peer); | 1667 | n = find_neighbour (&rcm->peer); |
1712 | memset (&cim, 0, sizeof (cim)); | 1668 | memset (&cim, 0, sizeof (cim)); |
1713 | if ( (n != NULL) && (GNUNET_YES == n->is_connected) ) | 1669 | if ((n != NULL) && (GNUNET_YES == n->is_connected)) |
1670 | { | ||
1671 | want_reserv = ntohl (rcm->reserve_inbound); | ||
1672 | if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__) | ||
1714 | { | 1673 | { |
1715 | want_reserv = ntohl (rcm->reserve_inbound); | 1674 | n->bw_out_internal_limit = rcm->limit_outbound; |
1716 | if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__) | 1675 | if (n->bw_out.value__ != |
1717 | { | 1676 | GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, |
1718 | n->bw_out_internal_limit = rcm->limit_outbound; | 1677 | n->bw_out_external_limit).value__) |
1719 | if (n->bw_out.value__ != GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, | 1678 | { |
1720 | n->bw_out_external_limit).value__) | 1679 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, |
1721 | { | 1680 | n->bw_out_external_limit); |
1722 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, | 1681 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, |
1723 | n->bw_out_external_limit); | 1682 | n->bw_out); |
1724 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, | 1683 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
1725 | n->bw_out); | 1684 | handle_peer_status_change (n); |
1726 | GNUNET_TRANSPORT_set_quota (transport, | 1685 | } |
1727 | &n->peer, | 1686 | } |
1728 | n->bw_in, | 1687 | if (want_reserv < 0) |
1729 | n->bw_out); | 1688 | { |
1730 | handle_peer_status_change (n); | 1689 | got_reserv = want_reserv; |
1731 | } | 1690 | } |
1732 | } | 1691 | else if (want_reserv > 0) |
1733 | if (want_reserv < 0) | 1692 | { |
1734 | { | 1693 | rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, |
1735 | got_reserv = want_reserv; | 1694 | want_reserv); |
1736 | } | 1695 | if (rdelay.rel_value == 0) |
1737 | else if (want_reserv > 0) | 1696 | got_reserv = want_reserv; |
1738 | { | ||
1739 | rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, | ||
1740 | want_reserv); | ||
1741 | if (rdelay.rel_value == 0) | ||
1742 | got_reserv = want_reserv; | ||
1743 | else | ||
1744 | got_reserv = 0; /* all or nothing */ | ||
1745 | } | ||
1746 | else | 1697 | else |
1747 | got_reserv = 0; | 1698 | got_reserv = 0; /* all or nothing */ |
1748 | GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, | ||
1749 | got_reserv); | ||
1750 | old_preference = n->current_preference; | ||
1751 | n->current_preference += GNUNET_ntohll(rcm->preference_change); | ||
1752 | if (old_preference > n->current_preference) | ||
1753 | { | ||
1754 | /* overflow; cap at maximum value */ | ||
1755 | n->current_preference = ULLONG_MAX; | ||
1756 | } | ||
1757 | update_preference_sum (n->current_preference - old_preference); | ||
1758 | #if DEBUG_CORE_QUOTA | ||
1759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1760 | "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", | ||
1761 | (int) want_reserv, | ||
1762 | GNUNET_i2s (&rcm->peer), | ||
1763 | (int) got_reserv, | ||
1764 | (unsigned long long) rdelay.rel_value); | ||
1765 | #endif | ||
1766 | cim.reserved_amount = htonl (got_reserv); | ||
1767 | cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); | ||
1768 | cim.bw_out = n->bw_out; | ||
1769 | cim.preference = n->current_preference; | ||
1770 | } | 1699 | } |
1771 | else | 1700 | else |
1701 | got_reserv = 0; | ||
1702 | GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, got_reserv); | ||
1703 | old_preference = n->current_preference; | ||
1704 | n->current_preference += GNUNET_ntohll (rcm->preference_change); | ||
1705 | if (old_preference > n->current_preference) | ||
1772 | { | 1706 | { |
1773 | /* Technically, this COULD happen (due to asynchronous behavior), | 1707 | /* overflow; cap at maximum value */ |
1774 | but it should be rare, so we should generate an info event | 1708 | n->current_preference = ULLONG_MAX; |
1775 | to help diagnosis of serious errors that might be masked by this */ | ||
1776 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1777 | _("Client asked for preference change with peer `%s', which is not connected!\n"), | ||
1778 | GNUNET_i2s (&rcm->peer)); | ||
1779 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1780 | return; | ||
1781 | } | 1709 | } |
1710 | update_preference_sum (n->current_preference - old_preference); | ||
1711 | #if DEBUG_CORE_QUOTA | ||
1712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1713 | "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", | ||
1714 | (int) want_reserv, | ||
1715 | GNUNET_i2s (&rcm->peer), | ||
1716 | (int) got_reserv, (unsigned long long) rdelay.rel_value); | ||
1717 | #endif | ||
1718 | cim.reserved_amount = htonl (got_reserv); | ||
1719 | cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); | ||
1720 | cim.bw_out = n->bw_out; | ||
1721 | cim.preference = n->current_preference; | ||
1722 | } | ||
1723 | else | ||
1724 | { | ||
1725 | /* Technically, this COULD happen (due to asynchronous behavior), | ||
1726 | * but it should be rare, so we should generate an info event | ||
1727 | * to help diagnosis of serious errors that might be masked by this */ | ||
1728 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1729 | _ | ||
1730 | ("Client asked for preference change with peer `%s', which is not connected!\n"), | ||
1731 | GNUNET_i2s (&rcm->peer)); | ||
1732 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1733 | return; | ||
1734 | } | ||
1782 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); | 1735 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); |
1783 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); | 1736 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); |
1784 | cim.peer = rcm->peer; | 1737 | cim.peer = rcm->peer; |
@@ -1806,47 +1759,44 @@ free_neighbour (struct Neighbour *n) | |||
1806 | 1759 | ||
1807 | #if DEBUG_CORE | 1760 | #if DEBUG_CORE |
1808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1761 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1809 | "Destroying neighbour entry for peer `%4s'\n", | 1762 | "Destroying neighbour entry for peer `%4s'\n", |
1810 | GNUNET_i2s (&n->peer)); | 1763 | GNUNET_i2s (&n->peer)); |
1811 | #endif | 1764 | #endif |
1812 | if (n->pitr != NULL) | 1765 | if (n->pitr != NULL) |
1813 | { | 1766 | { |
1814 | GNUNET_PEERINFO_iterate_cancel (n->pitr); | 1767 | GNUNET_PEERINFO_iterate_cancel (n->pitr); |
1815 | n->pitr = NULL; | 1768 | n->pitr = NULL; |
1816 | } | 1769 | } |
1817 | if (n->skm != NULL) | 1770 | if (n->skm != NULL) |
1818 | { | 1771 | { |
1819 | GNUNET_free (n->skm); | 1772 | GNUNET_free (n->skm); |
1820 | n->skm = NULL; | 1773 | n->skm = NULL; |
1821 | } | 1774 | } |
1822 | while (NULL != (m = n->messages)) | 1775 | while (NULL != (m = n->messages)) |
1823 | { | 1776 | { |
1824 | n->messages = m->next; | 1777 | n->messages = m->next; |
1825 | GNUNET_free (m); | 1778 | GNUNET_free (m); |
1826 | } | 1779 | } |
1827 | while (NULL != (m = n->encrypted_head)) | 1780 | while (NULL != (m = n->encrypted_head)) |
1828 | { | 1781 | { |
1829 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 1782 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m); |
1830 | n->encrypted_tail, | 1783 | GNUNET_free (m); |
1831 | m); | 1784 | } |
1832 | GNUNET_free (m); | ||
1833 | } | ||
1834 | while (NULL != (car = n->active_client_request_head)) | 1785 | while (NULL != (car = n->active_client_request_head)) |
1835 | { | 1786 | { |
1836 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 1787 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
1837 | n->active_client_request_tail, | 1788 | n->active_client_request_tail, car); |
1838 | car); | 1789 | GNUNET_assert (GNUNET_YES == |
1839 | GNUNET_assert (GNUNET_YES == | 1790 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, |
1840 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, | 1791 | &n->peer.hashPubKey, |
1841 | &n->peer.hashPubKey, | 1792 | car)); |
1842 | car)); | 1793 | GNUNET_free (car); |
1843 | GNUNET_free (car); | 1794 | } |
1844 | } | ||
1845 | if (NULL != n->th) | 1795 | if (NULL != n->th) |
1846 | { | 1796 | { |
1847 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); | 1797 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); |
1848 | n->th = NULL; | 1798 | n->th = NULL; |
1849 | } | 1799 | } |
1850 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) | 1800 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) |
1851 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); | 1801 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); |
1852 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 1802 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1855,13 +1805,12 @@ free_neighbour (struct Neighbour *n) | |||
1855 | GNUNET_SCHEDULER_cancel (n->quota_update_task); | 1805 | GNUNET_SCHEDULER_cancel (n->quota_update_task); |
1856 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) | 1806 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) |
1857 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); | 1807 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); |
1858 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | 1808 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) |
1859 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | 1809 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); |
1860 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 1810 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
1861 | GNUNET_STATISTICS_update (stats, | 1811 | GNUNET_STATISTICS_update (stats, |
1862 | gettext_noop ("# established sessions"), | 1812 | gettext_noop ("# established sessions"), |
1863 | -1, | 1813 | -1, GNUNET_NO); |
1864 | GNUNET_NO); | ||
1865 | GNUNET_array_grow (n->ats, n->ats_count, 0); | 1814 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1866 | GNUNET_free_non_null (n->public_key); | 1815 | GNUNET_free_non_null (n->public_key); |
1867 | GNUNET_free_non_null (n->pending_ping); | 1816 | GNUNET_free_non_null (n->pending_ping); |
@@ -1893,27 +1842,27 @@ static void process_encrypted_neighbour_queue (struct Neighbour *n); | |||
1893 | */ | 1842 | */ |
1894 | static int | 1843 | static int |
1895 | do_encrypt (struct Neighbour *n, | 1844 | do_encrypt (struct Neighbour *n, |
1896 | const struct GNUNET_CRYPTO_AesInitializationVector * iv, | 1845 | const struct GNUNET_CRYPTO_AesInitializationVector *iv, |
1897 | const void *in, void *out, size_t size) | 1846 | const void *in, void *out, size_t size) |
1898 | { | 1847 | { |
1899 | if (size != (uint16_t) size) | 1848 | if (size != (uint16_t) size) |
1900 | { | 1849 | { |
1901 | GNUNET_break (0); | 1850 | GNUNET_break (0); |
1902 | return GNUNET_NO; | 1851 | return GNUNET_NO; |
1903 | } | 1852 | } |
1904 | GNUNET_assert (size == | 1853 | GNUNET_assert (size == |
1905 | GNUNET_CRYPTO_aes_encrypt (in, | 1854 | GNUNET_CRYPTO_aes_encrypt (in, |
1906 | (uint16_t) size, | 1855 | (uint16_t) size, |
1907 | &n->encrypt_key, | 1856 | &n->encrypt_key, iv, out)); |
1908 | iv, out)); | 1857 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, |
1909 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO); | 1858 | GNUNET_NO); |
1910 | #if DEBUG_CORE > 2 | 1859 | #if DEBUG_CORE > 2 |
1911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1860 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1912 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", | 1861 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", |
1913 | (unsigned int) size, | 1862 | (unsigned int) size, |
1914 | GNUNET_i2s (&n->peer), | 1863 | GNUNET_i2s (&n->peer), |
1915 | (unsigned int) n->encrypt_key.crc32, | 1864 | (unsigned int) n->encrypt_key.crc32, |
1916 | GNUNET_CRYPTO_crc32_n (iv, sizeof(iv))); | 1865 | GNUNET_CRYPTO_crc32_n (iv, sizeof (iv))); |
1917 | #endif | 1866 | #endif |
1918 | return GNUNET_OK; | 1867 | return GNUNET_OK; |
1919 | } | 1868 | } |
@@ -1925,8 +1874,7 @@ do_encrypt (struct Neighbour *n, | |||
1925 | * | 1874 | * |
1926 | * @param n neighbour to consider discarding | 1875 | * @param n neighbour to consider discarding |
1927 | */ | 1876 | */ |
1928 | static void | 1877 | static void consider_free_neighbour (struct Neighbour *n); |
1929 | consider_free_neighbour (struct Neighbour *n); | ||
1930 | 1878 | ||
1931 | 1879 | ||
1932 | /** | 1880 | /** |
@@ -1937,8 +1885,7 @@ consider_free_neighbour (struct Neighbour *n); | |||
1937 | * @param tc scheduler context (not used) | 1885 | * @param tc scheduler context (not used) |
1938 | */ | 1886 | */ |
1939 | static void | 1887 | static void |
1940 | send_keep_alive (void *cls, | 1888 | send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1941 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1942 | { | 1889 | { |
1943 | struct Neighbour *n = cls; | 1890 | struct Neighbour *n = cls; |
1944 | struct GNUNET_TIME_Relative retry; | 1891 | struct GNUNET_TIME_Relative retry; |
@@ -1956,26 +1903,23 @@ send_keep_alive (void *cls, | |||
1956 | me->priority = PING_PRIORITY; | 1903 | me->priority = PING_PRIORITY; |
1957 | me->size = sizeof (struct PingMessage); | 1904 | me->size = sizeof (struct PingMessage); |
1958 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 1905 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
1959 | n->encrypted_tail, | 1906 | n->encrypted_tail, n->encrypted_tail, me); |
1960 | n->encrypted_tail, | ||
1961 | me); | ||
1962 | pm = (struct PingMessage *) &me[1]; | 1907 | pm = (struct PingMessage *) &me[1]; |
1963 | pm->header.size = htons (sizeof (struct PingMessage)); | 1908 | pm->header.size = htons (sizeof (struct PingMessage)); |
1964 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 1909 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
1965 | pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1910 | pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1966 | UINT32_MAX); | 1911 | UINT32_MAX); |
1967 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); | 1912 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); |
1968 | pp.challenge = n->ping_challenge; | 1913 | pp.challenge = n->ping_challenge; |
1969 | pp.target = n->peer; | 1914 | pp.target = n->peer; |
1970 | #if DEBUG_HANDSHAKE | 1915 | #if DEBUG_HANDSHAKE |
1971 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1972 | "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", | 1917 | "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", |
1973 | "PING", | 1918 | "PING", |
1974 | (unsigned int) n->ping_challenge, | 1919 | (unsigned int) n->ping_challenge, |
1975 | GNUNET_i2s (&n->peer), | 1920 | GNUNET_i2s (&n->peer), |
1976 | (unsigned int) n->encrypt_key.crc32, | 1921 | (unsigned int) n->encrypt_key.crc32, |
1977 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 1922 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); |
1978 | pm->iv_seed); | ||
1979 | #endif | 1923 | #endif |
1980 | do_encrypt (n, | 1924 | do_encrypt (n, |
1981 | &iv, | 1925 | &iv, |
@@ -1987,11 +1931,9 @@ send_keep_alive (void *cls, | |||
1987 | /* reschedule PING job */ | 1931 | /* reschedule PING job */ |
1988 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); | 1932 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); |
1989 | retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), | 1933 | retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), |
1990 | MIN_PING_FREQUENCY); | 1934 | MIN_PING_FREQUENCY); |
1991 | n->keep_alive_task | 1935 | n->keep_alive_task |
1992 | = GNUNET_SCHEDULER_add_delayed (retry, | 1936 | = GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n); |
1993 | &send_keep_alive, | ||
1994 | n); | ||
1995 | 1937 | ||
1996 | } | 1938 | } |
1997 | 1939 | ||
@@ -2003,8 +1945,7 @@ send_keep_alive (void *cls, | |||
2003 | * @param tc scheduler context (not used) | 1945 | * @param tc scheduler context (not used) |
2004 | */ | 1946 | */ |
2005 | static void | 1947 | static void |
2006 | consider_free_task (void *cls, | 1948 | consider_free_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2007 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2008 | { | 1949 | { |
2009 | struct Neighbour *n = cls; | 1950 | struct Neighbour *n = cls; |
2010 | 1951 | ||
@@ -2021,33 +1962,29 @@ consider_free_task (void *cls, | |||
2021 | */ | 1962 | */ |
2022 | static void | 1963 | static void |
2023 | consider_free_neighbour (struct Neighbour *n) | 1964 | consider_free_neighbour (struct Neighbour *n) |
2024 | { | 1965 | { |
2025 | struct GNUNET_TIME_Relative left; | 1966 | struct GNUNET_TIME_Relative left; |
2026 | 1967 | ||
2027 | if ( (n->th != NULL) || | 1968 | if ((n->th != NULL) || (n->pitr != NULL) || (GNUNET_YES == n->is_connected)) |
2028 | (n->pitr != NULL) || | 1969 | return; /* no chance */ |
2029 | (GNUNET_YES == n->is_connected) ) | 1970 | |
2030 | return; /* no chance */ | ||
2031 | |||
2032 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); | 1971 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); |
2033 | if (left.rel_value > 0) | 1972 | if (left.rel_value > 0) |
2034 | { | 1973 | { |
2035 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) | 1974 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) |
2036 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); | 1975 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); |
2037 | n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left, | 1976 | n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left, |
2038 | &consider_free_task, | 1977 | &consider_free_task, n); |
2039 | n); | 1978 | return; |
2040 | return; | 1979 | } |
2041 | } | ||
2042 | /* actually free the neighbour... */ | 1980 | /* actually free the neighbour... */ |
2043 | GNUNET_assert (GNUNET_YES == | 1981 | GNUNET_assert (GNUNET_YES == |
2044 | GNUNET_CONTAINER_multihashmap_remove (neighbours, | 1982 | GNUNET_CONTAINER_multihashmap_remove (neighbours, |
2045 | &n->peer.hashPubKey, | 1983 | &n->peer.hashPubKey, n)); |
2046 | n)); | ||
2047 | GNUNET_STATISTICS_set (stats, | 1984 | GNUNET_STATISTICS_set (stats, |
2048 | gettext_noop ("# neighbour entries allocated"), | 1985 | gettext_noop ("# neighbour entries allocated"), |
2049 | GNUNET_CONTAINER_multihashmap_size (neighbours), | 1986 | GNUNET_CONTAINER_multihashmap_size (neighbours), |
2050 | GNUNET_NO); | 1987 | GNUNET_NO); |
2051 | free_neighbour (n); | 1988 | free_neighbour (n); |
2052 | } | 1989 | } |
2053 | 1990 | ||
@@ -2062,9 +1999,7 @@ consider_free_neighbour (struct Neighbour *n) | |||
2062 | * @return number of bytes transmitted | 1999 | * @return number of bytes transmitted |
2063 | */ | 2000 | */ |
2064 | static size_t | 2001 | static size_t |
2065 | notify_encrypted_transmit_ready (void *cls, | 2002 | notify_encrypted_transmit_ready (void *cls, size_t size, void *buf) |
2066 | size_t size, | ||
2067 | void *buf) | ||
2068 | { | 2003 | { |
2069 | struct Neighbour *n = cls; | 2004 | struct Neighbour *n = cls; |
2070 | struct MessageEntry *m; | 2005 | struct MessageEntry *m; |
@@ -2074,50 +2009,48 @@ notify_encrypted_transmit_ready (void *cls, | |||
2074 | n->th = NULL; | 2009 | n->th = NULL; |
2075 | m = n->encrypted_head; | 2010 | m = n->encrypted_head; |
2076 | if (m == NULL) | 2011 | if (m == NULL) |
2077 | { | 2012 | { |
2078 | #if DEBUG_CORE | 2013 | #if DEBUG_CORE |
2079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2080 | "Encrypted message queue empty, no messages added to buffer for `%4s'\n", | 2015 | "Encrypted message queue empty, no messages added to buffer for `%4s'\n", |
2081 | GNUNET_i2s (&n->peer)); | 2016 | GNUNET_i2s (&n->peer)); |
2082 | #endif | 2017 | #endif |
2083 | return 0; | 2018 | return 0; |
2084 | } | 2019 | } |
2085 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 2020 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m); |
2086 | n->encrypted_tail, | ||
2087 | m); | ||
2088 | ret = 0; | 2021 | ret = 0; |
2089 | cbuf = buf; | 2022 | cbuf = buf; |
2090 | if (buf != NULL) | 2023 | if (buf != NULL) |
2091 | { | 2024 | { |
2092 | GNUNET_assert (size >= m->size); | 2025 | GNUNET_assert (size >= m->size); |
2093 | memcpy (cbuf, &m[1], m->size); | 2026 | memcpy (cbuf, &m[1], m->size); |
2094 | ret = m->size; | 2027 | ret = m->size; |
2095 | GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window, | 2028 | GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window, m->size); |
2096 | m->size); | ||
2097 | #if DEBUG_CORE | 2029 | #if DEBUG_CORE |
2098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2099 | "Copied message of type %u and size %u into transport buffer for `%4s'\n", | 2031 | "Copied message of type %u and size %u into transport buffer for `%4s'\n", |
2100 | (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), | 2032 | (unsigned int) |
2101 | (unsigned int) ret, | 2033 | ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), |
2102 | GNUNET_i2s (&n->peer)); | 2034 | (unsigned int) ret, GNUNET_i2s (&n->peer)); |
2103 | #endif | 2035 | #endif |
2104 | process_encrypted_neighbour_queue (n); | 2036 | process_encrypted_neighbour_queue (n); |
2105 | } | 2037 | } |
2106 | else | 2038 | else |
2107 | { | 2039 | { |
2108 | #if DEBUG_CORE | 2040 | #if DEBUG_CORE |
2109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2110 | "Transmission of message of type %u and size %u failed\n", | 2042 | "Transmission of message of type %u and size %u failed\n", |
2111 | (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), | 2043 | (unsigned int) |
2112 | (unsigned int) m->size); | 2044 | ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), |
2045 | (unsigned int) m->size); | ||
2113 | #endif | 2046 | #endif |
2114 | } | 2047 | } |
2115 | GNUNET_free (m); | 2048 | GNUNET_free (m); |
2116 | consider_free_neighbour (n); | 2049 | consider_free_neighbour (n); |
2117 | GNUNET_STATISTICS_update (stats, | 2050 | GNUNET_STATISTICS_update (stats, |
2118 | gettext_noop ("# encrypted bytes given to transport"), | 2051 | gettext_noop |
2119 | ret, | 2052 | ("# encrypted bytes given to transport"), ret, |
2120 | GNUNET_NO); | 2053 | GNUNET_NO); |
2121 | return ret; | 2054 | return ret; |
2122 | } | 2055 | } |
2123 | 2056 | ||
@@ -2143,47 +2076,46 @@ static void | |||
2143 | process_encrypted_neighbour_queue (struct Neighbour *n) | 2076 | process_encrypted_neighbour_queue (struct Neighbour *n) |
2144 | { | 2077 | { |
2145 | struct MessageEntry *m; | 2078 | struct MessageEntry *m; |
2146 | 2079 | ||
2147 | if (n->th != NULL) | 2080 | if (n->th != NULL) |
2148 | return; /* request already pending */ | 2081 | return; /* request already pending */ |
2149 | if (GNUNET_YES != n->is_connected) | 2082 | if (GNUNET_YES != n->is_connected) |
2150 | { | 2083 | { |
2151 | GNUNET_break (0); | 2084 | GNUNET_break (0); |
2152 | return; | 2085 | return; |
2153 | } | 2086 | } |
2154 | m = n->encrypted_head; | 2087 | m = n->encrypted_head; |
2155 | if (m == NULL) | 2088 | if (m == NULL) |
2156 | { | 2089 | { |
2157 | /* encrypted queue empty, try plaintext instead */ | 2090 | /* encrypted queue empty, try plaintext instead */ |
2158 | process_plaintext_neighbour_queue (n); | 2091 | process_plaintext_neighbour_queue (n); |
2159 | return; | 2092 | return; |
2160 | } | 2093 | } |
2161 | #if DEBUG_CORE > 1 | 2094 | #if DEBUG_CORE > 1 |
2162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2163 | "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", | 2096 | "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", |
2164 | (unsigned int) m->size, | 2097 | (unsigned int) m->size, |
2165 | GNUNET_i2s (&n->peer), | 2098 | GNUNET_i2s (&n->peer), |
2166 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); | 2099 | (unsigned long long) |
2100 | GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); | ||
2167 | #endif | 2101 | #endif |
2168 | n->th = | 2102 | n->th = |
2169 | GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, | 2103 | GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, |
2170 | m->size, | 2104 | m->size, |
2171 | m->priority, | 2105 | m->priority, |
2172 | GNUNET_TIME_absolute_get_remaining | 2106 | GNUNET_TIME_absolute_get_remaining |
2173 | (m->deadline), | 2107 | (m->deadline), |
2174 | ¬ify_encrypted_transmit_ready, | 2108 | ¬ify_encrypted_transmit_ready, |
2175 | n); | 2109 | n); |
2176 | if (n->th == NULL) | 2110 | if (n->th == NULL) |
2177 | { | 2111 | { |
2178 | /* message request too large or duplicate request */ | 2112 | /* message request too large or duplicate request */ |
2179 | GNUNET_break (0); | 2113 | GNUNET_break (0); |
2180 | /* discard encrypted message */ | 2114 | /* discard encrypted message */ |
2181 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 2115 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m); |
2182 | n->encrypted_tail, | 2116 | GNUNET_free (m); |
2183 | m); | 2117 | process_encrypted_neighbour_queue (n); |
2184 | GNUNET_free (m); | 2118 | } |
2185 | process_encrypted_neighbour_queue (n); | ||
2186 | } | ||
2187 | } | 2119 | } |
2188 | 2120 | ||
2189 | 2121 | ||
@@ -2201,41 +2133,36 @@ process_encrypted_neighbour_queue (struct Neighbour *n) | |||
2201 | */ | 2133 | */ |
2202 | static int | 2134 | static int |
2203 | do_decrypt (struct Neighbour *n, | 2135 | do_decrypt (struct Neighbour *n, |
2204 | const struct GNUNET_CRYPTO_AesInitializationVector * iv, | 2136 | const struct GNUNET_CRYPTO_AesInitializationVector *iv, |
2205 | const void *in, void *out, size_t size) | 2137 | const void *in, void *out, size_t size) |
2206 | { | 2138 | { |
2207 | if (size != (uint16_t) size) | 2139 | if (size != (uint16_t) size) |
2208 | { | 2140 | { |
2209 | GNUNET_break (0); | 2141 | GNUNET_break (0); |
2210 | return GNUNET_NO; | 2142 | return GNUNET_NO; |
2211 | } | 2143 | } |
2212 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | 2144 | if ((n->status != PEER_STATE_KEY_RECEIVED) && |
2213 | (n->status != PEER_STATE_KEY_CONFIRMED)) | 2145 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
2214 | { | 2146 | { |
2215 | GNUNET_break_op (0); | 2147 | GNUNET_break_op (0); |
2216 | return GNUNET_SYSERR; | 2148 | return GNUNET_SYSERR; |
2217 | } | 2149 | } |
2218 | if (size != | 2150 | if (size != |
2219 | GNUNET_CRYPTO_aes_decrypt (in, | 2151 | GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &n->decrypt_key, iv, out)) |
2220 | (uint16_t) size, | 2152 | { |
2221 | &n->decrypt_key, | 2153 | GNUNET_break (0); |
2222 | iv, | 2154 | return GNUNET_SYSERR; |
2223 | out)) | 2155 | } |
2224 | { | 2156 | GNUNET_STATISTICS_update (stats, |
2225 | GNUNET_break (0); | 2157 | gettext_noop ("# bytes decrypted"), |
2226 | return GNUNET_SYSERR; | 2158 | size, GNUNET_NO); |
2227 | } | ||
2228 | GNUNET_STATISTICS_update (stats, | ||
2229 | gettext_noop ("# bytes decrypted"), | ||
2230 | size, | ||
2231 | GNUNET_NO); | ||
2232 | #if DEBUG_CORE > 1 | 2159 | #if DEBUG_CORE > 1 |
2233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2234 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", | 2161 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", |
2235 | (unsigned int) size, | 2162 | (unsigned int) size, |
2236 | GNUNET_i2s (&n->peer), | 2163 | GNUNET_i2s (&n->peer), |
2237 | (unsigned int) n->decrypt_key.crc32, | 2164 | (unsigned int) n->decrypt_key.crc32, |
2238 | GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv))); | 2165 | GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv))); |
2239 | #endif | 2166 | #endif |
2240 | return GNUNET_OK; | 2167 | return GNUNET_OK; |
2241 | } | 2168 | } |
@@ -2270,7 +2197,7 @@ select_messages (struct Neighbour *n, | |||
2270 | struct GNUNET_TIME_Absolute now; | 2197 | struct GNUNET_TIME_Absolute now; |
2271 | struct GNUNET_TIME_Relative delta; | 2198 | struct GNUNET_TIME_Relative delta; |
2272 | uint64_t avail; | 2199 | uint64_t avail; |
2273 | struct GNUNET_TIME_Relative slack; /* how long could we wait before missing deadlines? */ | 2200 | struct GNUNET_TIME_Relative slack; /* how long could we wait before missing deadlines? */ |
2274 | size_t off; | 2201 | size_t off; |
2275 | uint64_t tsize; | 2202 | uint64_t tsize; |
2276 | unsigned int queue_size; | 2203 | unsigned int queue_size; |
@@ -2281,171 +2208,172 @@ select_messages (struct Neighbour *n, | |||
2281 | /* last entry in linked list of messages processed */ | 2208 | /* last entry in linked list of messages processed */ |
2282 | last = NULL; | 2209 | last = NULL; |
2283 | /* should we remove the entry with the lowest | 2210 | /* should we remove the entry with the lowest |
2284 | priority from consideration for scheduling at the | 2211 | * priority from consideration for scheduling at the |
2285 | end of the loop? */ | 2212 | * end of the loop? */ |
2286 | queue_size = 0; | 2213 | queue_size = 0; |
2287 | tsize = 0; | 2214 | tsize = 0; |
2288 | pos = n->messages; | 2215 | pos = n->messages; |
2289 | while (pos != NULL) | 2216 | while (pos != NULL) |
2290 | { | 2217 | { |
2291 | queue_size++; | 2218 | queue_size++; |
2292 | tsize += pos->size; | 2219 | tsize += pos->size; |
2293 | pos = pos->next; | 2220 | pos = pos->next; |
2294 | } | 2221 | } |
2295 | discard_low_prio = GNUNET_YES; | 2222 | discard_low_prio = GNUNET_YES; |
2296 | while (GNUNET_YES == discard_low_prio) | 2223 | while (GNUNET_YES == discard_low_prio) |
2224 | { | ||
2225 | min = NULL; | ||
2226 | min_prio = UINT_MAX; | ||
2227 | discard_low_prio = GNUNET_NO; | ||
2228 | /* calculate number of bytes available for transmission at time "t" */ | ||
2229 | avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window); | ||
2230 | t = now; | ||
2231 | /* how many bytes have we (hypothetically) scheduled so far */ | ||
2232 | off = 0; | ||
2233 | /* maximum time we can wait before transmitting anything | ||
2234 | * and still make all of our deadlines */ | ||
2235 | slack = GNUNET_TIME_UNIT_FOREVER_REL; | ||
2236 | pos = n->messages; | ||
2237 | /* note that we use "*2" here because we want to look | ||
2238 | * a bit further into the future; much more makes no | ||
2239 | * sense since new message might be scheduled in the | ||
2240 | * meantime... */ | ||
2241 | while ((pos != NULL) && (off < size * 2)) | ||
2297 | { | 2242 | { |
2298 | min = NULL; | 2243 | if (pos->do_transmit == GNUNET_YES) |
2299 | min_prio = UINT_MAX; | 2244 | { |
2300 | discard_low_prio = GNUNET_NO; | 2245 | /* already removed from consideration */ |
2301 | /* calculate number of bytes available for transmission at time "t" */ | 2246 | pos = pos->next; |
2302 | avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window); | 2247 | continue; |
2303 | t = now; | 2248 | } |
2304 | /* how many bytes have we (hypothetically) scheduled so far */ | 2249 | if (discard_low_prio == GNUNET_NO) |
2305 | off = 0; | 2250 | { |
2306 | /* maximum time we can wait before transmitting anything | 2251 | delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline); |
2307 | and still make all of our deadlines */ | 2252 | if (delta.rel_value > 0) |
2308 | slack = GNUNET_TIME_UNIT_FOREVER_REL; | 2253 | { |
2309 | pos = n->messages; | 2254 | // FIXME: HUH? Check! |
2310 | /* note that we use "*2" here because we want to look | 2255 | t = pos->deadline; |
2311 | a bit further into the future; much more makes no | 2256 | avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, |
2312 | sense since new message might be scheduled in the | 2257 | delta); |
2313 | meantime... */ | ||
2314 | while ((pos != NULL) && (off < size * 2)) | ||
2315 | { | ||
2316 | if (pos->do_transmit == GNUNET_YES) | ||
2317 | { | ||
2318 | /* already removed from consideration */ | ||
2319 | pos = pos->next; | ||
2320 | continue; | ||
2321 | } | ||
2322 | if (discard_low_prio == GNUNET_NO) | ||
2323 | { | ||
2324 | delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline); | ||
2325 | if (delta.rel_value > 0) | ||
2326 | { | ||
2327 | // FIXME: HUH? Check! | ||
2328 | t = pos->deadline; | ||
2329 | avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, | ||
2330 | delta); | ||
2331 | } | ||
2332 | if (avail < pos->size) | ||
2333 | { | ||
2334 | // FIXME: HUH? Check! | ||
2335 | discard_low_prio = GNUNET_YES; /* we could not schedule this one! */ | ||
2336 | } | ||
2337 | else | ||
2338 | { | ||
2339 | avail -= pos->size; | ||
2340 | /* update slack, considering both its absolute deadline | ||
2341 | and relative deadlines caused by other messages | ||
2342 | with their respective load */ | ||
2343 | slack = GNUNET_TIME_relative_min (slack, | ||
2344 | GNUNET_BANDWIDTH_value_get_delay_for (n->bw_out, | ||
2345 | avail)); | ||
2346 | if (pos->deadline.abs_value <= now.abs_value) | ||
2347 | { | ||
2348 | /* now or never */ | ||
2349 | slack = GNUNET_TIME_UNIT_ZERO; | ||
2350 | } | ||
2351 | else if (GNUNET_YES == pos->got_slack) | ||
2352 | { | ||
2353 | /* should be soon now! */ | ||
2354 | slack = GNUNET_TIME_relative_min (slack, | ||
2355 | GNUNET_TIME_absolute_get_remaining (pos->slack_deadline)); | ||
2356 | } | ||
2357 | else | ||
2358 | { | ||
2359 | slack = | ||
2360 | GNUNET_TIME_relative_min (slack, | ||
2361 | GNUNET_TIME_absolute_get_difference (now, pos->deadline)); | ||
2362 | pos->got_slack = GNUNET_YES; | ||
2363 | pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline, | ||
2364 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY)); | ||
2365 | } | ||
2366 | } | ||
2367 | } | ||
2368 | off += pos->size; | ||
2369 | t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check! | ||
2370 | if (pos->priority <= min_prio) | ||
2371 | { | ||
2372 | /* update min for discard */ | ||
2373 | min_prio = pos->priority; | ||
2374 | min = pos; | ||
2375 | } | ||
2376 | pos = pos->next; | ||
2377 | } | 2258 | } |
2378 | if (discard_low_prio) | 2259 | if (avail < pos->size) |
2379 | { | 2260 | { |
2380 | GNUNET_assert (min != NULL); | 2261 | // FIXME: HUH? Check! |
2381 | /* remove lowest-priority entry from consideration */ | 2262 | discard_low_prio = GNUNET_YES; /* we could not schedule this one! */ |
2382 | min->do_transmit = GNUNET_YES; /* means: discard (for now) */ | ||
2383 | } | 2263 | } |
2384 | last = pos; | 2264 | else |
2265 | { | ||
2266 | avail -= pos->size; | ||
2267 | /* update slack, considering both its absolute deadline | ||
2268 | * and relative deadlines caused by other messages | ||
2269 | * with their respective load */ | ||
2270 | slack = GNUNET_TIME_relative_min (slack, | ||
2271 | GNUNET_BANDWIDTH_value_get_delay_for | ||
2272 | (n->bw_out, avail)); | ||
2273 | if (pos->deadline.abs_value <= now.abs_value) | ||
2274 | { | ||
2275 | /* now or never */ | ||
2276 | slack = GNUNET_TIME_UNIT_ZERO; | ||
2277 | } | ||
2278 | else if (GNUNET_YES == pos->got_slack) | ||
2279 | { | ||
2280 | /* should be soon now! */ | ||
2281 | slack = GNUNET_TIME_relative_min (slack, | ||
2282 | GNUNET_TIME_absolute_get_remaining | ||
2283 | (pos->slack_deadline)); | ||
2284 | } | ||
2285 | else | ||
2286 | { | ||
2287 | slack = | ||
2288 | GNUNET_TIME_relative_min (slack, | ||
2289 | GNUNET_TIME_absolute_get_difference | ||
2290 | (now, pos->deadline)); | ||
2291 | pos->got_slack = GNUNET_YES; | ||
2292 | pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline, | ||
2293 | GNUNET_TIME_relative_to_absolute | ||
2294 | (GNUNET_CONSTANTS_MAX_CORK_DELAY)); | ||
2295 | } | ||
2296 | } | ||
2297 | } | ||
2298 | off += pos->size; | ||
2299 | t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check! | ||
2300 | if (pos->priority <= min_prio) | ||
2301 | { | ||
2302 | /* update min for discard */ | ||
2303 | min_prio = pos->priority; | ||
2304 | min = pos; | ||
2305 | } | ||
2306 | pos = pos->next; | ||
2385 | } | 2307 | } |
2308 | if (discard_low_prio) | ||
2309 | { | ||
2310 | GNUNET_assert (min != NULL); | ||
2311 | /* remove lowest-priority entry from consideration */ | ||
2312 | min->do_transmit = GNUNET_YES; /* means: discard (for now) */ | ||
2313 | } | ||
2314 | last = pos; | ||
2315 | } | ||
2386 | /* guard against sending "tiny" messages with large headers without | 2316 | /* guard against sending "tiny" messages with large headers without |
2387 | urgent deadlines */ | 2317 | * urgent deadlines */ |
2388 | if ( (slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) && | 2318 | if ((slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) && |
2389 | (size > 4 * off) && | 2319 | (size > 4 * off) && (queue_size <= MAX_PEER_QUEUE_SIZE - 2)) |
2390 | (queue_size <= MAX_PEER_QUEUE_SIZE - 2) ) | 2320 | { |
2321 | /* less than 25% of message would be filled with deadlines still | ||
2322 | * being met if we delay by one second or more; so just wait for | ||
2323 | * more data; but do not wait longer than 1s (since we don't want | ||
2324 | * to delay messages for a really long time either). */ | ||
2325 | *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY; | ||
2326 | /* reset do_transmit values for next time */ | ||
2327 | while (pos != last) | ||
2391 | { | 2328 | { |
2392 | /* less than 25% of message would be filled with deadlines still | 2329 | pos->do_transmit = GNUNET_NO; |
2393 | being met if we delay by one second or more; so just wait for | 2330 | pos = pos->next; |
2394 | more data; but do not wait longer than 1s (since we don't want | 2331 | } |
2395 | to delay messages for a really long time either). */ | 2332 | GNUNET_STATISTICS_update (stats, |
2396 | *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY; | 2333 | gettext_noop |
2397 | /* reset do_transmit values for next time */ | 2334 | ("# transmissions delayed due to corking"), 1, |
2398 | while (pos != last) | 2335 | GNUNET_NO); |
2399 | { | ||
2400 | pos->do_transmit = GNUNET_NO; | ||
2401 | pos = pos->next; | ||
2402 | } | ||
2403 | GNUNET_STATISTICS_update (stats, | ||
2404 | gettext_noop ("# transmissions delayed due to corking"), | ||
2405 | 1, GNUNET_NO); | ||
2406 | #if DEBUG_CORE | 2336 | #if DEBUG_CORE |
2407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2408 | "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n", | 2338 | "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n", |
2409 | (unsigned long long) retry_time->rel_value, | 2339 | (unsigned long long) retry_time->rel_value, |
2410 | (unsigned int) off, | 2340 | (unsigned int) off, (unsigned int) size); |
2411 | (unsigned int) size); | ||
2412 | #endif | 2341 | #endif |
2413 | return 0; | 2342 | return 0; |
2414 | } | 2343 | } |
2415 | /* select marked messages (up to size) for transmission */ | 2344 | /* select marked messages (up to size) for transmission */ |
2416 | off = 0; | 2345 | off = 0; |
2417 | pos = n->messages; | 2346 | pos = n->messages; |
2418 | while (pos != last) | 2347 | while (pos != last) |
2348 | { | ||
2349 | if ((pos->size <= size) && (pos->do_transmit == GNUNET_NO)) | ||
2419 | { | 2350 | { |
2420 | if ((pos->size <= size) && (pos->do_transmit == GNUNET_NO)) | 2351 | pos->do_transmit = GNUNET_YES; /* mark for transmission */ |
2421 | { | 2352 | off += pos->size; |
2422 | pos->do_transmit = GNUNET_YES; /* mark for transmission */ | 2353 | size -= pos->size; |
2423 | off += pos->size; | ||
2424 | size -= pos->size; | ||
2425 | #if DEBUG_CORE > 1 | 2354 | #if DEBUG_CORE > 1 |
2426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2427 | "Selecting message of size %u for transmission\n", | 2356 | "Selecting message of size %u for transmission\n", |
2428 | (unsigned int) pos->size); | 2357 | (unsigned int) pos->size); |
2429 | #endif | 2358 | #endif |
2430 | } | 2359 | } |
2431 | else | 2360 | else |
2432 | { | 2361 | { |
2433 | #if DEBUG_CORE > 1 | 2362 | #if DEBUG_CORE > 1 |
2434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2435 | "Not selecting message of size %u for transmission at this time (maximum is %u)\n", | 2364 | "Not selecting message of size %u for transmission at this time (maximum is %u)\n", |
2436 | (unsigned int) pos->size, | 2365 | (unsigned int) pos->size, size); |
2437 | size); | ||
2438 | #endif | 2366 | #endif |
2439 | pos->do_transmit = GNUNET_NO; /* mark for not transmitting! */ | 2367 | pos->do_transmit = GNUNET_NO; /* mark for not transmitting! */ |
2440 | } | ||
2441 | pos = pos->next; | ||
2442 | } | 2368 | } |
2369 | pos = pos->next; | ||
2370 | } | ||
2443 | #if DEBUG_CORE | 2371 | #if DEBUG_CORE |
2444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2445 | "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n", | 2373 | "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n", |
2446 | (unsigned long long) off, (unsigned long long) tsize, | 2374 | (unsigned long long) off, (unsigned long long) tsize, |
2447 | queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE, | 2375 | queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE, |
2448 | GNUNET_i2s (&n->peer)); | 2376 | GNUNET_i2s (&n->peer)); |
2449 | #endif | 2377 | #endif |
2450 | return off; | 2378 | return off; |
2451 | } | 2379 | } |
@@ -2468,29 +2396,28 @@ batch_message (struct Neighbour *n, | |||
2468 | char *buf, | 2396 | char *buf, |
2469 | size_t size, | 2397 | size_t size, |
2470 | struct GNUNET_TIME_Absolute *deadline, | 2398 | struct GNUNET_TIME_Absolute *deadline, |
2471 | struct GNUNET_TIME_Relative *retry_time, | 2399 | struct GNUNET_TIME_Relative *retry_time, unsigned int *priority) |
2472 | unsigned int *priority) | ||
2473 | { | 2400 | { |
2474 | char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 2401 | char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
2475 | struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb; | 2402 | struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage *) ntmb; |
2476 | struct MessageEntry *pos; | 2403 | struct MessageEntry *pos; |
2477 | struct MessageEntry *prev; | 2404 | struct MessageEntry *prev; |
2478 | struct MessageEntry *next; | 2405 | struct MessageEntry *next; |
2479 | size_t ret; | 2406 | size_t ret; |
2480 | 2407 | ||
2481 | ret = 0; | 2408 | ret = 0; |
2482 | *priority = 0; | 2409 | *priority = 0; |
2483 | *deadline = GNUNET_TIME_UNIT_FOREVER_ABS; | 2410 | *deadline = GNUNET_TIME_UNIT_FOREVER_ABS; |
2484 | *retry_time = GNUNET_TIME_UNIT_FOREVER_REL; | 2411 | *retry_time = GNUNET_TIME_UNIT_FOREVER_REL; |
2485 | if (0 == select_messages (n, size, retry_time)) | 2412 | if (0 == select_messages (n, size, retry_time)) |
2486 | { | 2413 | { |
2487 | #if DEBUG_CORE | 2414 | #if DEBUG_CORE |
2488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2489 | "No messages selected, will try again in %llu ms\n", | 2416 | "No messages selected, will try again in %llu ms\n", |
2490 | retry_time->rel_value); | 2417 | retry_time->rel_value); |
2491 | #endif | 2418 | #endif |
2492 | return 0; | 2419 | return 0; |
2493 | } | 2420 | } |
2494 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND); | 2421 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND); |
2495 | ntm->ats_count = htonl (0); | 2422 | ntm->ats_count = htonl (0); |
2496 | ntm->ats.type = htonl (0); | 2423 | ntm->ats.type = htonl (0); |
@@ -2499,72 +2426,74 @@ batch_message (struct Neighbour *n, | |||
2499 | pos = n->messages; | 2426 | pos = n->messages; |
2500 | prev = NULL; | 2427 | prev = NULL; |
2501 | while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader))) | 2428 | while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader))) |
2429 | { | ||
2430 | next = pos->next; | ||
2431 | if (GNUNET_YES == pos->do_transmit) | ||
2502 | { | 2432 | { |
2503 | next = pos->next; | 2433 | GNUNET_assert (pos->size <= size); |
2504 | if (GNUNET_YES == pos->do_transmit) | 2434 | /* do notifications */ |
2505 | { | 2435 | /* FIXME: track if we have *any* client that wants |
2506 | GNUNET_assert (pos->size <= size); | 2436 | * full notifications and only do this if that is |
2507 | /* do notifications */ | 2437 | * actually true */ |
2508 | /* FIXME: track if we have *any* client that wants | 2438 | if (pos->size < |
2509 | full notifications and only do this if that is | 2439 | GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage)) |
2510 | actually true */ | 2440 | { |
2511 | if (pos->size < GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage)) | 2441 | memcpy (&ntm[1], &pos[1], pos->size); |
2512 | { | 2442 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + |
2513 | memcpy (&ntm[1], &pos[1], pos->size); | 2443 | sizeof (struct GNUNET_MessageHeader)); |
2514 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + | 2444 | send_to_all_clients (&ntm->header, |
2515 | sizeof (struct GNUNET_MessageHeader)); | 2445 | GNUNET_YES, GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); |
2516 | send_to_all_clients (&ntm->header, | 2446 | } |
2517 | GNUNET_YES, | 2447 | else |
2518 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | 2448 | { |
2519 | } | 2449 | /* message too large for 'full' notifications, we do at |
2520 | else | 2450 | * least the 'hdr' type */ |
2521 | { | 2451 | memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader)); |
2522 | /* message too large for 'full' notifications, we do at | 2452 | } |
2523 | least the 'hdr' type */ | 2453 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + |
2524 | memcpy (&ntm[1], | 2454 | pos->size); |
2525 | &pos[1], | 2455 | send_to_all_clients (&ntm->header, |
2526 | sizeof (struct GNUNET_MessageHeader)); | 2456 | GNUNET_YES, GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); |
2527 | } | ||
2528 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + | ||
2529 | pos->size); | ||
2530 | send_to_all_clients (&ntm->header, | ||
2531 | GNUNET_YES, | ||
2532 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); | ||
2533 | #if DEBUG_HANDSHAKE | 2457 | #if DEBUG_HANDSHAKE |
2534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2535 | "Encrypting %u bytes with message of type %u and size %u\n", | 2459 | "Encrypting %u bytes with message of type %u and size %u\n", |
2536 | pos->size, | 2460 | pos->size, |
2537 | (unsigned int) ntohs(((const struct GNUNET_MessageHeader*)&pos[1])->type), | 2461 | (unsigned int) |
2538 | (unsigned int) ntohs(((const struct GNUNET_MessageHeader*)&pos[1])->size)); | 2462 | ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type), |
2463 | (unsigned int) | ||
2464 | ntohs (((const struct GNUNET_MessageHeader *) | ||
2465 | &pos[1])->size)); | ||
2539 | #endif | 2466 | #endif |
2540 | /* copy for encrypted transmission */ | 2467 | /* copy for encrypted transmission */ |
2541 | memcpy (&buf[ret], &pos[1], pos->size); | 2468 | memcpy (&buf[ret], &pos[1], pos->size); |
2542 | ret += pos->size; | 2469 | ret += pos->size; |
2543 | size -= pos->size; | 2470 | size -= pos->size; |
2544 | *priority += pos->priority; | 2471 | *priority += pos->priority; |
2545 | #if DEBUG_CORE > 1 | 2472 | #if DEBUG_CORE > 1 |
2546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2547 | "Adding plaintext message of size %u with deadline %llu ms to batch\n", | 2474 | "Adding plaintext message of size %u with deadline %llu ms to batch\n", |
2548 | (unsigned int) pos->size, | 2475 | (unsigned int) pos->size, |
2549 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (pos->deadline).rel_value); | 2476 | (unsigned long long) |
2477 | GNUNET_TIME_absolute_get_remaining (pos->deadline).rel_value); | ||
2550 | #endif | 2478 | #endif |
2551 | deadline->abs_value = GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value); | 2479 | deadline->abs_value = |
2552 | GNUNET_free (pos); | 2480 | GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value); |
2553 | if (prev == NULL) | 2481 | GNUNET_free (pos); |
2554 | n->messages = next; | 2482 | if (prev == NULL) |
2555 | else | 2483 | n->messages = next; |
2556 | prev->next = next; | ||
2557 | } | ||
2558 | else | 2484 | else |
2559 | { | 2485 | prev->next = next; |
2560 | prev = pos; | 2486 | } |
2561 | } | 2487 | else |
2562 | pos = next; | 2488 | { |
2489 | prev = pos; | ||
2563 | } | 2490 | } |
2491 | pos = next; | ||
2492 | } | ||
2564 | #if DEBUG_CORE > 1 | 2493 | #if DEBUG_CORE > 1 |
2565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2566 | "Deadline for message batch is %llu ms\n", | 2495 | "Deadline for message batch is %llu ms\n", |
2567 | GNUNET_TIME_absolute_get_remaining (*deadline).rel_value); | 2496 | GNUNET_TIME_absolute_get_remaining (*deadline).rel_value); |
2568 | #endif | 2497 | #endif |
2569 | return ret; | 2498 | return ret; |
2570 | } | 2499 | } |
@@ -2590,32 +2519,32 @@ discard_expired_messages (struct Neighbour *n) | |||
2590 | now = GNUNET_TIME_absolute_get (); | 2519 | now = GNUNET_TIME_absolute_get (); |
2591 | prev = NULL; | 2520 | prev = NULL; |
2592 | pos = n->messages; | 2521 | pos = n->messages; |
2593 | while (pos != NULL) | 2522 | while (pos != NULL) |
2523 | { | ||
2524 | next = pos->next; | ||
2525 | delta = GNUNET_TIME_absolute_get_difference (pos->deadline, now); | ||
2526 | if (delta.rel_value > PAST_EXPIRATION_DISCARD_TIME.rel_value) | ||
2594 | { | 2527 | { |
2595 | next = pos->next; | ||
2596 | delta = GNUNET_TIME_absolute_get_difference (pos->deadline, now); | ||
2597 | if (delta.rel_value > PAST_EXPIRATION_DISCARD_TIME.rel_value) | ||
2598 | { | ||
2599 | #if DEBUG_CORE | 2528 | #if DEBUG_CORE |
2600 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2529 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2601 | "Message is %llu ms past due, discarding.\n", | 2530 | "Message is %llu ms past due, discarding.\n", |
2602 | delta.rel_value); | 2531 | delta.rel_value); |
2603 | #endif | 2532 | #endif |
2604 | if (prev == NULL) | 2533 | if (prev == NULL) |
2605 | n->messages = next; | 2534 | n->messages = next; |
2606 | else | ||
2607 | prev->next = next; | ||
2608 | GNUNET_STATISTICS_update (stats, | ||
2609 | gettext_noop ("# messages discarded (expired prior to transmission)"), | ||
2610 | 1, | ||
2611 | GNUNET_NO); | ||
2612 | disc = GNUNET_YES; | ||
2613 | GNUNET_free (pos); | ||
2614 | } | ||
2615 | else | 2535 | else |
2616 | prev = pos; | 2536 | prev->next = next; |
2617 | pos = next; | 2537 | GNUNET_STATISTICS_update (stats, |
2538 | gettext_noop | ||
2539 | ("# messages discarded (expired prior to transmission)"), | ||
2540 | 1, GNUNET_NO); | ||
2541 | disc = GNUNET_YES; | ||
2542 | GNUNET_free (pos); | ||
2618 | } | 2543 | } |
2544 | else | ||
2545 | prev = pos; | ||
2546 | pos = next; | ||
2547 | } | ||
2619 | if (GNUNET_YES == disc) | 2548 | if (GNUNET_YES == disc) |
2620 | schedule_peer_messages (n); | 2549 | schedule_peer_messages (n); |
2621 | } | 2550 | } |
@@ -2656,12 +2585,11 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2656 | 2585 | ||
2657 | #if DEBUG_CORE | 2586 | #if DEBUG_CORE |
2658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2659 | "Retrying key transmission to `%4s'\n", | 2588 | "Retrying key transmission to `%4s'\n", GNUNET_i2s (&n->peer)); |
2660 | GNUNET_i2s (&n->peer)); | ||
2661 | #endif | 2589 | #endif |
2662 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 2590 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
2663 | n->set_key_retry_frequency = | 2591 | n->set_key_retry_frequency = |
2664 | GNUNET_TIME_relative_multiply (n->set_key_retry_frequency, 2); | 2592 | GNUNET_TIME_relative_multiply (n->set_key_retry_frequency, 2); |
2665 | send_key (n); | 2593 | send_key (n); |
2666 | } | 2594 | } |
2667 | 2595 | ||
@@ -2676,7 +2604,7 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2676 | static void | 2604 | static void |
2677 | process_plaintext_neighbour_queue (struct Neighbour *n) | 2605 | process_plaintext_neighbour_queue (struct Neighbour *n) |
2678 | { | 2606 | { |
2679 | char pbuf[GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE + sizeof (struct EncryptedMessage)]; /* plaintext */ | 2607 | char pbuf[GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE + sizeof (struct EncryptedMessage)]; /* plaintext */ |
2680 | size_t used; | 2608 | size_t used; |
2681 | struct EncryptedMessage *em; /* encrypted message */ | 2609 | struct EncryptedMessage *em; /* encrypted message */ |
2682 | struct EncryptedMessage *ph; /* plaintext header */ | 2610 | struct EncryptedMessage *ph; /* plaintext header */ |
@@ -2688,66 +2616,66 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2688 | struct GNUNET_CRYPTO_AuthKey auth_key; | 2616 | struct GNUNET_CRYPTO_AuthKey auth_key; |
2689 | 2617 | ||
2690 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) | 2618 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) |
2691 | { | 2619 | { |
2692 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); | 2620 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); |
2693 | n->retry_plaintext_task = GNUNET_SCHEDULER_NO_TASK; | 2621 | n->retry_plaintext_task = GNUNET_SCHEDULER_NO_TASK; |
2694 | } | 2622 | } |
2695 | switch (n->status) | 2623 | switch (n->status) |
2696 | { | 2624 | { |
2697 | case PEER_STATE_DOWN: | 2625 | case PEER_STATE_DOWN: |
2698 | send_key (n); | 2626 | send_key (n); |
2699 | #if DEBUG_CORE | 2627 | #if DEBUG_CORE |
2700 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2701 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", | 2629 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", |
2702 | GNUNET_i2s(&n->peer)); | 2630 | GNUNET_i2s (&n->peer)); |
2703 | #endif | 2631 | #endif |
2704 | return; | 2632 | return; |
2705 | case PEER_STATE_KEY_SENT: | 2633 | case PEER_STATE_KEY_SENT: |
2706 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) | 2634 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) |
2707 | n->retry_set_key_task | 2635 | n->retry_set_key_task |
2708 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 2636 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
2709 | &set_key_retry_task, n); | 2637 | &set_key_retry_task, n); |
2710 | #if DEBUG_CORE | 2638 | #if DEBUG_CORE |
2711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2712 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", | 2640 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", |
2713 | GNUNET_i2s(&n->peer)); | 2641 | GNUNET_i2s (&n->peer)); |
2714 | #endif | 2642 | #endif |
2715 | return; | 2643 | return; |
2716 | case PEER_STATE_KEY_RECEIVED: | 2644 | case PEER_STATE_KEY_RECEIVED: |
2717 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) | 2645 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) |
2718 | n->retry_set_key_task | 2646 | n->retry_set_key_task |
2719 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 2647 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
2720 | &set_key_retry_task, n); | 2648 | &set_key_retry_task, n); |
2721 | #if DEBUG_CORE | 2649 | #if DEBUG_CORE |
2722 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2723 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", | 2651 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", |
2724 | GNUNET_i2s(&n->peer)); | 2652 | GNUNET_i2s (&n->peer)); |
2725 | #endif | 2653 | #endif |
2726 | return; | 2654 | return; |
2727 | case PEER_STATE_KEY_CONFIRMED: | 2655 | case PEER_STATE_KEY_CONFIRMED: |
2728 | /* ready to continue */ | 2656 | /* ready to continue */ |
2729 | break; | 2657 | break; |
2730 | } | 2658 | } |
2731 | discard_expired_messages (n); | 2659 | discard_expired_messages (n); |
2732 | if (n->messages == NULL) | 2660 | if (n->messages == NULL) |
2733 | { | 2661 | { |
2734 | #if DEBUG_CORE | 2662 | #if DEBUG_CORE |
2735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2736 | "Plaintext message queue for `%4s' is empty.\n", | 2664 | "Plaintext message queue for `%4s' is empty.\n", |
2737 | GNUNET_i2s(&n->peer)); | 2665 | GNUNET_i2s (&n->peer)); |
2738 | #endif | 2666 | #endif |
2739 | return; /* no pending messages */ | 2667 | return; /* no pending messages */ |
2740 | } | 2668 | } |
2741 | if (n->encrypted_head != NULL) | 2669 | if (n->encrypted_head != NULL) |
2742 | { | 2670 | { |
2743 | #if DEBUG_CORE > 2 | 2671 | #if DEBUG_CORE > 2 |
2744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2745 | "Encrypted message queue for `%4s' is still full, delaying plaintext processing.\n", | 2673 | "Encrypted message queue for `%4s' is still full, delaying plaintext processing.\n", |
2746 | GNUNET_i2s(&n->peer)); | 2674 | GNUNET_i2s (&n->peer)); |
2747 | #endif | 2675 | #endif |
2748 | return; /* wait for messages already encrypted to be | 2676 | return; /* wait for messages already encrypted to be |
2749 | processed first! */ | 2677 | * processed first! */ |
2750 | } | 2678 | } |
2751 | ph = (struct EncryptedMessage *) pbuf; | 2679 | ph = (struct EncryptedMessage *) pbuf; |
2752 | deadline = GNUNET_TIME_UNIT_FOREVER_ABS; | 2680 | deadline = GNUNET_TIME_UNIT_FOREVER_ABS; |
2753 | priority = 0; | 2681 | priority = 0; |
@@ -2757,25 +2685,26 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2757 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, | 2685 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, |
2758 | &deadline, &retry_time, &priority); | 2686 | &deadline, &retry_time, &priority); |
2759 | if (used == sizeof (struct EncryptedMessage)) | 2687 | if (used == sizeof (struct EncryptedMessage)) |
2760 | { | 2688 | { |
2761 | #if DEBUG_CORE > 1 | 2689 | #if DEBUG_CORE > 1 |
2762 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2763 | "No messages selected for transmission to `%4s' at this time, will try again later.\n", | 2691 | "No messages selected for transmission to `%4s' at this time, will try again later.\n", |
2764 | GNUNET_i2s(&n->peer)); | 2692 | GNUNET_i2s (&n->peer)); |
2765 | #endif | 2693 | #endif |
2766 | /* no messages selected for sending, try again later... */ | 2694 | /* no messages selected for sending, try again later... */ |
2767 | n->retry_plaintext_task = | 2695 | n->retry_plaintext_task = |
2768 | GNUNET_SCHEDULER_add_delayed (retry_time, | 2696 | GNUNET_SCHEDULER_add_delayed (retry_time, |
2769 | &retry_plaintext_processing, n); | 2697 | &retry_plaintext_processing, n); |
2770 | return; | 2698 | return; |
2771 | } | 2699 | } |
2772 | #if DEBUG_CORE_QUOTA | 2700 | #if DEBUG_CORE_QUOTA |
2773 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2774 | "Sending %u b/s as new limit to peer `%4s'\n", | 2702 | "Sending %u b/s as new limit to peer `%4s'\n", |
2775 | (unsigned int) ntohl (n->bw_in.value__), | 2703 | (unsigned int) ntohl (n->bw_in.value__), GNUNET_i2s (&n->peer)); |
2776 | GNUNET_i2s (&n->peer)); | ||
2777 | #endif | 2704 | #endif |
2778 | ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 2705 | ph->iv_seed = |
2706 | htonl (GNUNET_CRYPTO_random_u32 | ||
2707 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | ||
2779 | ph->sequence_number = htonl (++n->last_sequence_number_sent); | 2708 | ph->sequence_number = htonl (++n->last_sequence_number_sent); |
2780 | ph->inbound_bw_limit = n->bw_in; | 2709 | ph->inbound_bw_limit = n->bw_in; |
2781 | ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 2710 | ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
@@ -2791,39 +2720,35 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2791 | em->iv_seed = ph->iv_seed; | 2720 | em->iv_seed = ph->iv_seed; |
2792 | derive_iv (&iv, &n->encrypt_key, ph->iv_seed, &n->peer); | 2721 | derive_iv (&iv, &n->encrypt_key, ph->iv_seed, &n->peer); |
2793 | /* encrypt */ | 2722 | /* encrypt */ |
2794 | #if DEBUG_HANDSHAKE | 2723 | #if DEBUG_HANDSHAKE |
2795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2796 | "Encrypting %u bytes of plaintext messages for `%4s' for transmission in %llums.\n", | 2725 | "Encrypting %u bytes of plaintext messages for `%4s' for transmission in %llums.\n", |
2797 | (unsigned int) used - ENCRYPTED_HEADER_SIZE, | 2726 | (unsigned int) used - ENCRYPTED_HEADER_SIZE, |
2798 | GNUNET_i2s(&n->peer), | 2727 | GNUNET_i2s (&n->peer), |
2799 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (deadline).rel_value); | 2728 | (unsigned long long) |
2729 | GNUNET_TIME_absolute_get_remaining (deadline).rel_value); | ||
2800 | #endif | 2730 | #endif |
2801 | GNUNET_assert (GNUNET_OK == | 2731 | GNUNET_assert (GNUNET_OK == |
2802 | do_encrypt (n, | 2732 | do_encrypt (n, |
2803 | &iv, | 2733 | &iv, |
2804 | &ph->sequence_number, | 2734 | &ph->sequence_number, |
2805 | &em->sequence_number, used - ENCRYPTED_HEADER_SIZE)); | 2735 | &em->sequence_number, |
2806 | derive_auth_key (&auth_key, | 2736 | used - ENCRYPTED_HEADER_SIZE)); |
2807 | &n->encrypt_key, | 2737 | derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed, |
2808 | ph->iv_seed, | ||
2809 | n->encrypt_key_created); | 2738 | n->encrypt_key_created); |
2810 | GNUNET_CRYPTO_hmac (&auth_key, | 2739 | GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, |
2811 | &em->sequence_number, | 2740 | used - ENCRYPTED_HEADER_SIZE, &em->hmac); |
2812 | used - ENCRYPTED_HEADER_SIZE, | ||
2813 | &em->hmac); | ||
2814 | #if DEBUG_HANDSHAKE | 2741 | #if DEBUG_HANDSHAKE |
2815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2816 | "Authenticated %u bytes of ciphertext %u: `%s'\n", | 2743 | "Authenticated %u bytes of ciphertext %u: `%s'\n", |
2817 | used - ENCRYPTED_HEADER_SIZE, | 2744 | used - ENCRYPTED_HEADER_SIZE, |
2818 | GNUNET_CRYPTO_crc32_n (&em->sequence_number, | 2745 | GNUNET_CRYPTO_crc32_n (&em->sequence_number, |
2819 | used - ENCRYPTED_HEADER_SIZE), | 2746 | used - ENCRYPTED_HEADER_SIZE), |
2820 | GNUNET_h2s (&em->hmac)); | 2747 | GNUNET_h2s (&em->hmac)); |
2821 | #endif | 2748 | #endif |
2822 | /* append to transmission list */ | 2749 | /* append to transmission list */ |
2823 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 2750 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
2824 | n->encrypted_tail, | 2751 | n->encrypted_tail, n->encrypted_tail, me); |
2825 | n->encrypted_tail, | ||
2826 | me); | ||
2827 | process_encrypted_neighbour_queue (n); | 2752 | process_encrypted_neighbour_queue (n); |
2828 | schedule_peer_messages (n); | 2753 | schedule_peer_messages (n); |
2829 | } | 2754 | } |
@@ -2838,7 +2763,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2838 | */ | 2763 | */ |
2839 | static void | 2764 | static void |
2840 | neighbour_quota_update (void *cls, | 2765 | neighbour_quota_update (void *cls, |
2841 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 2766 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
2842 | 2767 | ||
2843 | 2768 | ||
2844 | /** | 2769 | /** |
@@ -2849,12 +2774,10 @@ neighbour_quota_update (void *cls, | |||
2849 | static void | 2774 | static void |
2850 | schedule_quota_update (struct Neighbour *n) | 2775 | schedule_quota_update (struct Neighbour *n) |
2851 | { | 2776 | { |
2852 | GNUNET_assert (n->quota_update_task == | 2777 | GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK); |
2853 | GNUNET_SCHEDULER_NO_TASK); | ||
2854 | n->quota_update_task | 2778 | n->quota_update_task |
2855 | = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY, | 2779 | = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY, |
2856 | &neighbour_quota_update, | 2780 | &neighbour_quota_update, n); |
2857 | n); | ||
2858 | } | 2781 | } |
2859 | 2782 | ||
2860 | 2783 | ||
@@ -2872,8 +2795,7 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid) | |||
2872 | 2795 | ||
2873 | #if DEBUG_CORE | 2796 | #if DEBUG_CORE |
2874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2875 | "Creating neighbour entry for peer `%4s'\n", | 2798 | "Creating neighbour entry for peer `%4s'\n", GNUNET_i2s (pid)); |
2876 | GNUNET_i2s (pid)); | ||
2877 | #endif | 2799 | #endif |
2878 | n = GNUNET_malloc (sizeof (struct Neighbour)); | 2800 | n = GNUNET_malloc (sizeof (struct Neighbour)); |
2879 | n->peer = *pid; | 2801 | n->peer = *pid; |
@@ -2888,13 +2810,14 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid) | |||
2888 | n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; | 2810 | n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; |
2889 | n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 2811 | n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
2890 | UINT32_MAX); | 2812 | UINT32_MAX); |
2891 | GNUNET_assert (GNUNET_OK == | 2813 | GNUNET_assert (GNUNET_OK == |
2892 | GNUNET_CONTAINER_multihashmap_put (neighbours, | 2814 | GNUNET_CONTAINER_multihashmap_put (neighbours, |
2893 | &n->peer.hashPubKey, | 2815 | &n->peer.hashPubKey, |
2894 | n, | 2816 | n, |
2895 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2817 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2896 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), | 2818 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), |
2897 | GNUNET_CONTAINER_multihashmap_size (neighbours), GNUNET_NO); | 2819 | GNUNET_CONTAINER_multihashmap_size (neighbours), |
2820 | GNUNET_NO); | ||
2898 | neighbour_quota_update (n, NULL); | 2821 | neighbour_quota_update (n, NULL); |
2899 | consider_free_neighbour (n); | 2822 | consider_free_neighbour (n); |
2900 | return n; | 2823 | return n; |
@@ -2917,7 +2840,7 @@ handle_client_send (void *cls, | |||
2917 | struct Neighbour *n; | 2840 | struct Neighbour *n; |
2918 | struct MessageEntry *prev; | 2841 | struct MessageEntry *prev; |
2919 | struct MessageEntry *pos; | 2842 | struct MessageEntry *pos; |
2920 | struct MessageEntry *e; | 2843 | struct MessageEntry *e; |
2921 | struct MessageEntry *min_prio_entry; | 2844 | struct MessageEntry *min_prio_entry; |
2922 | struct MessageEntry *min_prio_prev; | 2845 | struct MessageEntry *min_prio_prev; |
2923 | unsigned int min_prio; | 2846 | unsigned int min_prio; |
@@ -2927,124 +2850,122 @@ handle_client_send (void *cls, | |||
2927 | msize = ntohs (message->size); | 2850 | msize = ntohs (message->size); |
2928 | if (msize < | 2851 | if (msize < |
2929 | sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader)) | 2852 | sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader)) |
2930 | { | 2853 | { |
2931 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2854 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2932 | "msize is %u, should be at least %u (in %s:%d)\n", | 2855 | "msize is %u, should be at least %u (in %s:%d)\n", |
2933 | msize, | 2856 | msize, |
2934 | sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader), | 2857 | sizeof (struct SendMessage) + |
2935 | __FILE__, __LINE__); | 2858 | sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__); |
2936 | GNUNET_break (0); | 2859 | GNUNET_break (0); |
2937 | if (client != NULL) | 2860 | if (client != NULL) |
2938 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2861 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2939 | return; | 2862 | return; |
2940 | } | 2863 | } |
2941 | sm = (const struct SendMessage *) message; | 2864 | sm = (const struct SendMessage *) message; |
2942 | msize -= sizeof (struct SendMessage); | 2865 | msize -= sizeof (struct SendMessage); |
2943 | if (0 == memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 2866 | if (0 == |
2944 | { | 2867 | memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
2945 | /* loopback */ | 2868 | { |
2946 | GNUNET_SERVER_mst_receive (mst, | 2869 | /* loopback */ |
2947 | &self, | 2870 | GNUNET_SERVER_mst_receive (mst, |
2948 | (const char*) &sm[1], | 2871 | &self, |
2949 | msize, | 2872 | (const char *) &sm[1], |
2950 | GNUNET_YES, | 2873 | msize, GNUNET_YES, GNUNET_NO); |
2951 | GNUNET_NO); | 2874 | if (client != NULL) |
2952 | if (client != NULL) | 2875 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2953 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2876 | return; |
2954 | return; | 2877 | } |
2955 | } | ||
2956 | n = find_neighbour (&sm->peer); | 2878 | n = find_neighbour (&sm->peer); |
2957 | if ( (n == NULL) || | 2879 | if ((n == NULL) || |
2958 | (GNUNET_YES != n->is_connected) || | 2880 | (GNUNET_YES != n->is_connected) || |
2959 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | 2881 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
2960 | { | 2882 | { |
2961 | /* attempt to send message to peer that is not connected anymore | 2883 | /* attempt to send message to peer that is not connected anymore |
2962 | (can happen due to asynchrony) */ | 2884 | * (can happen due to asynchrony) */ |
2963 | GNUNET_STATISTICS_update (stats, | 2885 | GNUNET_STATISTICS_update (stats, |
2964 | gettext_noop ("# messages discarded (disconnected)"), | 2886 | gettext_noop |
2965 | 1, | 2887 | ("# messages discarded (disconnected)"), 1, |
2966 | GNUNET_NO); | 2888 | GNUNET_NO); |
2967 | if (client != NULL) | 2889 | if (client != NULL) |
2968 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2890 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2969 | return; | 2891 | return; |
2970 | } | 2892 | } |
2971 | #if DEBUG_CORE | 2893 | #if DEBUG_CORE |
2972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2973 | "Core received `%s' request, queueing %u bytes of plaintext data for transmission to `%4s'.\n", | 2895 | "Core received `%s' request, queueing %u bytes of plaintext data for transmission to `%4s'.\n", |
2974 | "SEND", | 2896 | "SEND", (unsigned int) msize, GNUNET_i2s (&sm->peer)); |
2975 | (unsigned int) msize, | ||
2976 | GNUNET_i2s (&sm->peer)); | ||
2977 | #endif | 2897 | #endif |
2978 | discard_expired_messages (n); | 2898 | discard_expired_messages (n); |
2979 | /* bound queue size */ | 2899 | /* bound queue size */ |
2980 | /* NOTE: this entire block to bound the queue size should be | 2900 | /* NOTE: this entire block to bound the queue size should be |
2981 | obsolete with the new client-request code and the | 2901 | * obsolete with the new client-request code and the |
2982 | 'schedule_peer_messages' mechanism; we still have this code in | 2902 | * 'schedule_peer_messages' mechanism; we still have this code in |
2983 | here for now as a sanity check for the new mechanmism; | 2903 | * here for now as a sanity check for the new mechanmism; |
2984 | ultimately, we should probably simply reject SEND messages that | 2904 | * ultimately, we should probably simply reject SEND messages that |
2985 | are not 'approved' (or provide a new core API for very unreliable | 2905 | * are not 'approved' (or provide a new core API for very unreliable |
2986 | delivery that always sends with priority 0). Food for thought. */ | 2906 | * delivery that always sends with priority 0). Food for thought. */ |
2987 | min_prio = UINT32_MAX; | 2907 | min_prio = UINT32_MAX; |
2988 | min_prio_entry = NULL; | 2908 | min_prio_entry = NULL; |
2989 | min_prio_prev = NULL; | 2909 | min_prio_prev = NULL; |
2990 | queue_size = 0; | 2910 | queue_size = 0; |
2991 | prev = NULL; | 2911 | prev = NULL; |
2992 | pos = n->messages; | 2912 | pos = n->messages; |
2993 | while (pos != NULL) | 2913 | while (pos != NULL) |
2914 | { | ||
2915 | if (pos->priority <= min_prio) | ||
2994 | { | 2916 | { |
2995 | if (pos->priority <= min_prio) | 2917 | min_prio_entry = pos; |
2996 | { | 2918 | min_prio_prev = prev; |
2997 | min_prio_entry = pos; | 2919 | min_prio = pos->priority; |
2998 | min_prio_prev = prev; | ||
2999 | min_prio = pos->priority; | ||
3000 | } | ||
3001 | queue_size++; | ||
3002 | prev = pos; | ||
3003 | pos = pos->next; | ||
3004 | } | 2920 | } |
2921 | queue_size++; | ||
2922 | prev = pos; | ||
2923 | pos = pos->next; | ||
2924 | } | ||
3005 | if (queue_size >= MAX_PEER_QUEUE_SIZE) | 2925 | if (queue_size >= MAX_PEER_QUEUE_SIZE) |
2926 | { | ||
2927 | /* queue full */ | ||
2928 | if (ntohl (sm->priority) <= min_prio) | ||
3006 | { | 2929 | { |
3007 | /* queue full */ | 2930 | /* discard new entry; this should no longer happen! */ |
3008 | if (ntohl(sm->priority) <= min_prio) | 2931 | GNUNET_break (0); |
3009 | { | ||
3010 | /* discard new entry; this should no longer happen! */ | ||
3011 | GNUNET_break (0); | ||
3012 | #if DEBUG_CORE | ||
3013 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3014 | "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", | ||
3015 | queue_size, | ||
3016 | (unsigned int) MAX_PEER_QUEUE_SIZE, | ||
3017 | (unsigned int) msize, | ||
3018 | (unsigned int) ntohs (message->type)); | ||
3019 | #endif | ||
3020 | GNUNET_STATISTICS_update (stats, | ||
3021 | gettext_noop ("# discarded CORE_SEND requests"), | ||
3022 | 1, GNUNET_NO); | ||
3023 | |||
3024 | if (client != NULL) | ||
3025 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
3026 | return; | ||
3027 | } | ||
3028 | GNUNET_assert (min_prio_entry != NULL); | ||
3029 | /* discard "min_prio_entry" */ | ||
3030 | #if DEBUG_CORE | 2932 | #if DEBUG_CORE |
3031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2933 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3032 | "Queue full, discarding existing older request\n"); | 2934 | "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", |
2935 | queue_size, | ||
2936 | (unsigned int) MAX_PEER_QUEUE_SIZE, | ||
2937 | (unsigned int) msize, (unsigned int) ntohs (message->type)); | ||
3033 | #endif | 2938 | #endif |
3034 | GNUNET_STATISTICS_update (stats, gettext_noop ("# discarded lower priority CORE_SEND requests"), 1, GNUNET_NO); | 2939 | GNUNET_STATISTICS_update (stats, |
3035 | if (min_prio_prev == NULL) | 2940 | gettext_noop ("# discarded CORE_SEND requests"), |
3036 | n->messages = min_prio_entry->next; | 2941 | 1, GNUNET_NO); |
3037 | else | 2942 | |
3038 | min_prio_prev->next = min_prio_entry->next; | 2943 | if (client != NULL) |
3039 | GNUNET_free (min_prio_entry); | 2944 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2945 | return; | ||
3040 | } | 2946 | } |
2947 | GNUNET_assert (min_prio_entry != NULL); | ||
2948 | /* discard "min_prio_entry" */ | ||
2949 | #if DEBUG_CORE | ||
2950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2951 | "Queue full, discarding existing older request\n"); | ||
2952 | #endif | ||
2953 | GNUNET_STATISTICS_update (stats, | ||
2954 | gettext_noop | ||
2955 | ("# discarded lower priority CORE_SEND requests"), | ||
2956 | 1, GNUNET_NO); | ||
2957 | if (min_prio_prev == NULL) | ||
2958 | n->messages = min_prio_entry->next; | ||
2959 | else | ||
2960 | min_prio_prev->next = min_prio_entry->next; | ||
2961 | GNUNET_free (min_prio_entry); | ||
2962 | } | ||
3041 | 2963 | ||
3042 | #if DEBUG_CORE | 2964 | #if DEBUG_CORE |
3043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2965 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3044 | "Adding transmission request for `%4s' of size %u to queue\n", | 2966 | "Adding transmission request for `%4s' of size %u to queue\n", |
3045 | GNUNET_i2s (&sm->peer), | 2967 | GNUNET_i2s (&sm->peer), (unsigned int) msize); |
3046 | (unsigned int) msize); | 2968 | #endif |
3047 | #endif | ||
3048 | GNUNET_break (0 == ntohl (sm->reserved)); | 2969 | GNUNET_break (0 == ntohl (sm->reserved)); |
3049 | e = GNUNET_malloc (sizeof (struct MessageEntry) + msize); | 2970 | e = GNUNET_malloc (sizeof (struct MessageEntry) + msize); |
3050 | e->deadline = GNUNET_TIME_absolute_ntoh (sm->deadline); | 2971 | e->deadline = GNUNET_TIME_absolute_ntoh (sm->deadline); |
@@ -3058,10 +2979,10 @@ handle_client_send (void *cls, | |||
3058 | prev = NULL; | 2979 | prev = NULL; |
3059 | pos = n->messages; | 2980 | pos = n->messages; |
3060 | while ((pos != NULL) && (pos->deadline.abs_value < e->deadline.abs_value)) | 2981 | while ((pos != NULL) && (pos->deadline.abs_value < e->deadline.abs_value)) |
3061 | { | 2982 | { |
3062 | prev = pos; | 2983 | prev = pos; |
3063 | pos = pos->next; | 2984 | pos = pos->next; |
3064 | } | 2985 | } |
3065 | if (prev == NULL) | 2986 | if (prev == NULL) |
3066 | n->messages = e; | 2987 | n->messages = e; |
3067 | else | 2988 | else |
@@ -3084,46 +3005,41 @@ handle_client_send (void *cls, | |||
3084 | */ | 3005 | */ |
3085 | static void | 3006 | static void |
3086 | handle_client_request_connect (void *cls, | 3007 | handle_client_request_connect (void *cls, |
3087 | struct GNUNET_SERVER_Client *client, | 3008 | struct GNUNET_SERVER_Client *client, |
3088 | const struct GNUNET_MessageHeader *message) | 3009 | const struct GNUNET_MessageHeader *message) |
3089 | { | 3010 | { |
3090 | const struct ConnectMessage *cm = (const struct ConnectMessage*) message; | 3011 | const struct ConnectMessage *cm = (const struct ConnectMessage *) message; |
3091 | struct Neighbour *n; | 3012 | struct Neighbour *n; |
3092 | 3013 | ||
3093 | if (0 == memcmp (&cm->peer, | 3014 | if (0 == memcmp (&cm->peer, |
3094 | &my_identity, | 3015 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
3095 | sizeof (struct GNUNET_PeerIdentity))) | 3016 | { |
3096 | { | 3017 | /* In this case a client has asked us to connect to ourselves, not really an error! */ |
3097 | /* In this case a client has asked us to connect to ourselves, not really an error! */ | 3018 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3098 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3019 | return; |
3099 | return; | 3020 | } |
3100 | } | ||
3101 | GNUNET_break (ntohl (cm->reserved) == 0); | 3021 | GNUNET_break (ntohl (cm->reserved) == 0); |
3102 | #if DEBUG_CORE | 3022 | #if DEBUG_CORE |
3103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3104 | "Core received `%s' request for `%4s', will try to establish connection\n", | 3024 | "Core received `%s' request for `%4s', will try to establish connection\n", |
3105 | "REQUEST_CONNECT", | 3025 | "REQUEST_CONNECT", GNUNET_i2s (&cm->peer)); |
3106 | GNUNET_i2s (&cm->peer)); | ||
3107 | #endif | 3026 | #endif |
3108 | GNUNET_STATISTICS_update (stats, | 3027 | GNUNET_STATISTICS_update (stats, |
3109 | gettext_noop ("# connection requests received"), | 3028 | gettext_noop ("# connection requests received"), |
3110 | 1, | 3029 | 1, GNUNET_NO); |
3111 | GNUNET_NO); | ||
3112 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3030 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3113 | n = find_neighbour (&cm->peer); | 3031 | n = find_neighbour (&cm->peer); |
3114 | if ( (n == NULL) || | 3032 | if ((n == NULL) || (GNUNET_YES != n->is_connected)) |
3115 | (GNUNET_YES != n->is_connected) ) | 3033 | { |
3116 | { | 3034 | GNUNET_TRANSPORT_try_connect (transport, &cm->peer); |
3117 | GNUNET_TRANSPORT_try_connect (transport, | 3035 | } |
3118 | &cm->peer); | ||
3119 | } | ||
3120 | else | 3036 | else |
3121 | { | 3037 | { |
3122 | GNUNET_STATISTICS_update (stats, | 3038 | GNUNET_STATISTICS_update (stats, |
3123 | gettext_noop ("# connection requests ignored (already connected)"), | 3039 | gettext_noop |
3124 | 1, | 3040 | ("# connection requests ignored (already connected)"), |
3125 | GNUNET_NO); | 3041 | 1, GNUNET_NO); |
3126 | } | 3042 | } |
3127 | } | 3043 | } |
3128 | 3044 | ||
3129 | 3045 | ||
@@ -3153,81 +3069,78 @@ process_hello_retry_send_key (void *cls, | |||
3153 | } | 3069 | } |
3154 | 3070 | ||
3155 | if (peer == NULL) | 3071 | if (peer == NULL) |
3156 | { | 3072 | { |
3157 | #if DEBUG_CORE | 3073 | #if DEBUG_CORE |
3158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3159 | "Entered `%s' and `%s' is NULL!\n", | 3075 | "Entered `%s' and `%s' is NULL!\n", |
3160 | "process_hello_retry_send_key", | 3076 | "process_hello_retry_send_key", "peer"); |
3161 | "peer"); | ||
3162 | #endif | 3077 | #endif |
3163 | n->pitr = NULL; | 3078 | n->pitr = NULL; |
3164 | if (n->public_key != NULL) | 3079 | if (n->public_key != NULL) |
3165 | { | 3080 | { |
3166 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 3081 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
3167 | { | 3082 | { |
3168 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | 3083 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); |
3169 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 3084 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
3170 | } | 3085 | } |
3171 | GNUNET_STATISTICS_update (stats, | 3086 | GNUNET_STATISTICS_update (stats, |
3172 | gettext_noop ("# SET_KEY messages deferred (need public key)"), | 3087 | gettext_noop |
3173 | -1, | 3088 | ("# SET_KEY messages deferred (need public key)"), |
3174 | GNUNET_NO); | 3089 | -1, GNUNET_NO); |
3175 | send_key (n); | 3090 | send_key (n); |
3176 | } | 3091 | } |
3177 | else | 3092 | else |
3178 | { | 3093 | { |
3179 | #if DEBUG_CORE | 3094 | #if DEBUG_CORE |
3180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3181 | "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", | 3096 | "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", |
3182 | GNUNET_i2s (&n->peer)); | 3097 | GNUNET_i2s (&n->peer)); |
3183 | #endif | 3098 | #endif |
3184 | GNUNET_STATISTICS_update (stats, | 3099 | GNUNET_STATISTICS_update (stats, |
3185 | gettext_noop ("# Delayed connecting due to lack of public key"), | 3100 | gettext_noop |
3186 | 1, | 3101 | ("# Delayed connecting due to lack of public key"), |
3187 | GNUNET_NO); | 3102 | 1, GNUNET_NO); |
3188 | if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) | 3103 | if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) |
3189 | n->retry_set_key_task | 3104 | n->retry_set_key_task |
3190 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 3105 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
3191 | &set_key_retry_task, n); | 3106 | &set_key_retry_task, n); |
3192 | } | ||
3193 | return; | ||
3194 | } | 3107 | } |
3108 | return; | ||
3109 | } | ||
3195 | 3110 | ||
3196 | #if DEBUG_CORE | 3111 | #if DEBUG_CORE |
3197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3198 | "Entered `%s' for peer `%4s'\n", | 3113 | "Entered `%s' for peer `%4s'\n", |
3199 | "process_hello_retry_send_key", | 3114 | "process_hello_retry_send_key", GNUNET_i2s (peer)); |
3200 | GNUNET_i2s (peer)); | ||
3201 | #endif | 3115 | #endif |
3202 | if (n->public_key != NULL) | 3116 | if (n->public_key != NULL) |
3203 | { | 3117 | { |
3204 | /* already have public key, why are we here? */ | 3118 | /* already have public key, why are we here? */ |
3205 | GNUNET_break (0); | 3119 | GNUNET_break (0); |
3206 | return; | 3120 | return; |
3207 | } | 3121 | } |
3208 | 3122 | ||
3209 | #if DEBUG_CORE | 3123 | #if DEBUG_CORE |
3210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3211 | "Received new `%s' message for `%4s', initiating key exchange.\n", | 3125 | "Received new `%s' message for `%4s', initiating key exchange.\n", |
3212 | "HELLO", | 3126 | "HELLO", GNUNET_i2s (peer)); |
3213 | GNUNET_i2s (peer)); | ||
3214 | #endif | 3127 | #endif |
3215 | n->public_key = | 3128 | n->public_key = |
3216 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 3129 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
3217 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) | 3130 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) |
3218 | { | 3131 | { |
3219 | GNUNET_STATISTICS_update (stats, | 3132 | GNUNET_STATISTICS_update (stats, |
3220 | gettext_noop ("# Error extracting public key from HELLO"), | 3133 | gettext_noop |
3221 | 1, | 3134 | ("# Error extracting public key from HELLO"), 1, |
3222 | GNUNET_NO); | 3135 | GNUNET_NO); |
3223 | GNUNET_free (n->public_key); | 3136 | GNUNET_free (n->public_key); |
3224 | n->public_key = NULL; | 3137 | n->public_key = NULL; |
3225 | #if DEBUG_CORE | 3138 | #if DEBUG_CORE |
3226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3227 | "GNUNET_HELLO_get_key returned awfully\n"); | 3140 | "GNUNET_HELLO_get_key returned awfully\n"); |
3228 | #endif | 3141 | #endif |
3229 | return; | 3142 | return; |
3230 | } | 3143 | } |
3231 | } | 3144 | } |
3232 | 3145 | ||
3233 | 3146 | ||
@@ -3247,121 +3160,115 @@ send_key (struct Neighbour *n) | |||
3247 | struct GNUNET_CRYPTO_AesInitializationVector iv; | 3160 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
3248 | 3161 | ||
3249 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 3162 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
3250 | { | 3163 | { |
3251 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | 3164 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); |
3252 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 3165 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
3253 | } | 3166 | } |
3254 | if (n->pitr != NULL) | 3167 | if (n->pitr != NULL) |
3255 | { | 3168 | { |
3256 | #if DEBUG_CORE | 3169 | #if DEBUG_CORE |
3257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3258 | "Key exchange in progress with `%4s'.\n", | 3171 | "Key exchange in progress with `%4s'.\n", |
3259 | GNUNET_i2s (&n->peer)); | 3172 | GNUNET_i2s (&n->peer)); |
3260 | #endif | 3173 | #endif |
3261 | return; /* already in progress */ | 3174 | return; /* already in progress */ |
3262 | } | 3175 | } |
3263 | if (GNUNET_YES != n->is_connected) | 3176 | if (GNUNET_YES != n->is_connected) |
3264 | { | 3177 | { |
3265 | GNUNET_STATISTICS_update (stats, | 3178 | GNUNET_STATISTICS_update (stats, |
3266 | gettext_noop ("# Asking transport to connect (for SET_KEY)"), | 3179 | gettext_noop |
3267 | 1, | 3180 | ("# Asking transport to connect (for SET_KEY)"), |
3268 | GNUNET_NO); | 3181 | 1, GNUNET_NO); |
3269 | GNUNET_TRANSPORT_try_connect (transport, | 3182 | GNUNET_TRANSPORT_try_connect (transport, &n->peer); |
3270 | &n->peer); | 3183 | return; |
3271 | return; | 3184 | } |
3272 | } | ||
3273 | #if DEBUG_CORE | 3185 | #if DEBUG_CORE |
3274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3275 | "Asked to perform key exchange with `%4s'.\n", | 3187 | "Asked to perform key exchange with `%4s'.\n", |
3276 | GNUNET_i2s (&n->peer)); | 3188 | GNUNET_i2s (&n->peer)); |
3277 | #endif | 3189 | #endif |
3278 | if (n->public_key == NULL) | 3190 | if (n->public_key == NULL) |
3279 | { | 3191 | { |
3280 | /* lookup n's public key, then try again */ | 3192 | /* lookup n's public key, then try again */ |
3281 | #if DEBUG_CORE | 3193 | #if DEBUG_CORE |
3282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3283 | "Lacking public key for `%4s', trying to obtain one (send_key).\n", | 3195 | "Lacking public key for `%4s', trying to obtain one (send_key).\n", |
3284 | GNUNET_i2s (&n->peer)); | 3196 | GNUNET_i2s (&n->peer)); |
3285 | #endif | 3197 | #endif |
3286 | GNUNET_assert (n->pitr == NULL); | 3198 | GNUNET_assert (n->pitr == NULL); |
3287 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, | 3199 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, |
3288 | &n->peer, | 3200 | &n->peer, |
3289 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20), | 3201 | GNUNET_TIME_relative_multiply |
3290 | &process_hello_retry_send_key, n); | 3202 | (GNUNET_TIME_UNIT_SECONDS, 20), |
3291 | return; | 3203 | &process_hello_retry_send_key, n); |
3292 | } | 3204 | return; |
3205 | } | ||
3293 | pos = n->encrypted_head; | 3206 | pos = n->encrypted_head; |
3294 | while (pos != NULL) | 3207 | while (pos != NULL) |
3208 | { | ||
3209 | if (GNUNET_YES == pos->is_setkey) | ||
3295 | { | 3210 | { |
3296 | if (GNUNET_YES == pos->is_setkey) | 3211 | if (pos->sender_status == n->status) |
3297 | { | 3212 | { |
3298 | if (pos->sender_status == n->status) | ||
3299 | { | ||
3300 | #if DEBUG_CORE | 3213 | #if DEBUG_CORE |
3301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3302 | "`%s' message for `%4s' queued already\n", | 3215 | "`%s' message for `%4s' queued already\n", |
3303 | "SET_KEY", | 3216 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3304 | GNUNET_i2s (&n->peer)); | ||
3305 | #endif | 3217 | #endif |
3306 | goto trigger_processing; | 3218 | goto trigger_processing; |
3307 | } | 3219 | } |
3308 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 3220 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, pos); |
3309 | n->encrypted_tail, | 3221 | GNUNET_free (pos); |
3310 | pos); | ||
3311 | GNUNET_free (pos); | ||
3312 | #if DEBUG_CORE | 3222 | #if DEBUG_CORE |
3313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3314 | "Removing queued `%s' message for `%4s', will create a new one\n", | 3224 | "Removing queued `%s' message for `%4s', will create a new one\n", |
3315 | "SET_KEY", | 3225 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3316 | GNUNET_i2s (&n->peer)); | ||
3317 | #endif | 3226 | #endif |
3318 | break; | 3227 | break; |
3319 | } | ||
3320 | pos = pos->next; | ||
3321 | } | 3228 | } |
3229 | pos = pos->next; | ||
3230 | } | ||
3322 | 3231 | ||
3323 | /* update status */ | 3232 | /* update status */ |
3324 | switch (n->status) | 3233 | switch (n->status) |
3325 | { | 3234 | { |
3326 | case PEER_STATE_DOWN: | 3235 | case PEER_STATE_DOWN: |
3327 | n->status = PEER_STATE_KEY_SENT; | 3236 | n->status = PEER_STATE_KEY_SENT; |
3328 | break; | 3237 | break; |
3329 | case PEER_STATE_KEY_SENT: | 3238 | case PEER_STATE_KEY_SENT: |
3330 | break; | 3239 | break; |
3331 | case PEER_STATE_KEY_RECEIVED: | 3240 | case PEER_STATE_KEY_RECEIVED: |
3332 | break; | 3241 | break; |
3333 | case PEER_STATE_KEY_CONFIRMED: | 3242 | case PEER_STATE_KEY_CONFIRMED: |
3334 | break; | 3243 | break; |
3335 | default: | 3244 | default: |
3336 | GNUNET_break (0); | 3245 | GNUNET_break (0); |
3337 | break; | 3246 | break; |
3338 | } | 3247 | } |
3339 | 3248 | ||
3340 | 3249 | ||
3341 | /* first, set key message */ | 3250 | /* first, set key message */ |
3342 | me = GNUNET_malloc (sizeof (struct MessageEntry) + | 3251 | me = GNUNET_malloc (sizeof (struct MessageEntry) + |
3343 | sizeof (struct SetKeyMessage) + | 3252 | sizeof (struct SetKeyMessage) + |
3344 | sizeof (struct PingMessage)); | 3253 | sizeof (struct PingMessage)); |
3345 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY); | 3254 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY); |
3346 | me->priority = SET_KEY_PRIORITY; | 3255 | me->priority = SET_KEY_PRIORITY; |
3347 | me->size = sizeof (struct SetKeyMessage) + sizeof (struct PingMessage); | 3256 | me->size = sizeof (struct SetKeyMessage) + sizeof (struct PingMessage); |
3348 | me->is_setkey = GNUNET_YES; | 3257 | me->is_setkey = GNUNET_YES; |
3349 | me->got_slack = GNUNET_YES; /* do not defer this one! */ | 3258 | me->got_slack = GNUNET_YES; /* do not defer this one! */ |
3350 | me->sender_status = n->status; | 3259 | me->sender_status = n->status; |
3351 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 3260 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
3352 | n->encrypted_tail, | 3261 | n->encrypted_tail, n->encrypted_tail, me); |
3353 | n->encrypted_tail, | ||
3354 | me); | ||
3355 | sm = (struct SetKeyMessage *) &me[1]; | 3262 | sm = (struct SetKeyMessage *) &me[1]; |
3356 | sm->header.size = htons (sizeof (struct SetKeyMessage)); | 3263 | sm->header.size = htons (sizeof (struct SetKeyMessage)); |
3357 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); | 3264 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); |
3358 | sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ? | 3265 | sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ? |
3359 | PEER_STATE_KEY_SENT : n->status)); | 3266 | PEER_STATE_KEY_SENT : n->status)); |
3360 | sm->purpose.size = | 3267 | sm->purpose.size = |
3361 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 3268 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
3362 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 3269 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
3363 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + | 3270 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + |
3364 | sizeof (struct GNUNET_PeerIdentity)); | 3271 | sizeof (struct GNUNET_PeerIdentity)); |
3365 | sm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); | 3272 | sm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); |
3366 | sm->creation_time = GNUNET_TIME_absolute_hton (n->encrypt_key_created); | 3273 | sm->creation_time = GNUNET_TIME_absolute_hton (n->encrypt_key_created); |
3367 | sm->target = n->peer; | 3274 | sm->target = n->peer; |
@@ -3369,15 +3276,15 @@ send_key (struct Neighbour *n) | |||
3369 | GNUNET_CRYPTO_rsa_encrypt (&n->encrypt_key, | 3276 | GNUNET_CRYPTO_rsa_encrypt (&n->encrypt_key, |
3370 | sizeof (struct | 3277 | sizeof (struct |
3371 | GNUNET_CRYPTO_AesSessionKey), | 3278 | GNUNET_CRYPTO_AesSessionKey), |
3372 | n->public_key, | 3279 | n->public_key, &sm->encrypted_key)); |
3373 | &sm->encrypted_key)); | ||
3374 | GNUNET_assert (GNUNET_OK == | 3280 | GNUNET_assert (GNUNET_OK == |
3375 | GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose, | 3281 | GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose, |
3376 | &sm->signature)); | 3282 | &sm->signature)); |
3377 | pm = (struct PingMessage *) &sm[1]; | 3283 | pm = (struct PingMessage *) &sm[1]; |
3378 | pm->header.size = htons (sizeof (struct PingMessage)); | 3284 | pm->header.size = htons (sizeof (struct PingMessage)); |
3379 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 3285 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
3380 | pm->iv_seed = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 3286 | pm->iv_seed = |
3287 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | ||
3381 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); | 3288 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); |
3382 | pp.challenge = n->ping_challenge; | 3289 | pp.challenge = n->ping_challenge; |
3383 | pp.target = n->peer; | 3290 | pp.target = n->peer; |
@@ -3385,11 +3292,10 @@ send_key (struct Neighbour *n) | |||
3385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3386 | "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", | 3293 | "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", |
3387 | "SET_KEY", "PING", | 3294 | "SET_KEY", "PING", |
3388 | (unsigned int) n->ping_challenge, | 3295 | (unsigned int) n->ping_challenge, |
3389 | GNUNET_i2s (&n->peer), | 3296 | GNUNET_i2s (&n->peer), |
3390 | (unsigned int) n->encrypt_key.crc32, | 3297 | (unsigned int) n->encrypt_key.crc32, |
3391 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3298 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); |
3392 | pm->iv_seed); | ||
3393 | #endif | 3299 | #endif |
3394 | do_encrypt (n, | 3300 | do_encrypt (n, |
3395 | &iv, | 3301 | &iv, |
@@ -3397,24 +3303,25 @@ send_key (struct Neighbour *n) | |||
3397 | &pm->target, | 3303 | &pm->target, |
3398 | sizeof (struct PingMessage) - | 3304 | sizeof (struct PingMessage) - |
3399 | ((void *) &pm->target - (void *) pm)); | 3305 | ((void *) &pm->target - (void *) pm)); |
3400 | GNUNET_STATISTICS_update (stats, | 3306 | GNUNET_STATISTICS_update (stats, |
3401 | gettext_noop ("# SET_KEY and PING messages created"), | 3307 | gettext_noop |
3402 | 1, | 3308 | ("# SET_KEY and PING messages created"), 1, |
3403 | GNUNET_NO); | 3309 | GNUNET_NO); |
3404 | #if DEBUG_CORE | 3310 | #if DEBUG_CORE |
3405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3406 | "Have %llu ms left for `%s' transmission.\n", | 3312 | "Have %llu ms left for `%s' transmission.\n", |
3407 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value, | 3313 | (unsigned long long) |
3408 | "SET_KEY"); | 3314 | GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value, |
3315 | "SET_KEY"); | ||
3409 | #endif | 3316 | #endif |
3410 | trigger_processing: | 3317 | trigger_processing: |
3411 | /* trigger queue processing */ | 3318 | /* trigger queue processing */ |
3412 | process_encrypted_neighbour_queue (n); | 3319 | process_encrypted_neighbour_queue (n); |
3413 | if ( (n->status != PEER_STATE_KEY_CONFIRMED) && | 3320 | if ((n->status != PEER_STATE_KEY_CONFIRMED) && |
3414 | (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) ) | 3321 | (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)) |
3415 | n->retry_set_key_task | 3322 | n->retry_set_key_task |
3416 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 3323 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
3417 | &set_key_retry_task, n); | 3324 | &set_key_retry_task, n); |
3418 | } | 3325 | } |
3419 | 3326 | ||
3420 | 3327 | ||
@@ -3429,9 +3336,9 @@ send_key (struct Neighbour *n) | |||
3429 | */ | 3336 | */ |
3430 | static void | 3337 | static void |
3431 | handle_set_key (struct Neighbour *n, | 3338 | handle_set_key (struct Neighbour *n, |
3432 | const struct SetKeyMessage *m, | 3339 | const struct SetKeyMessage *m, |
3433 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3340 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3434 | uint32_t ats_count); | 3341 | uint32_t ats_count); |
3435 | 3342 | ||
3436 | 3343 | ||
3437 | 3344 | ||
@@ -3462,40 +3369,38 @@ process_hello_retry_handle_set_key (void *cls, | |||
3462 | } | 3369 | } |
3463 | 3370 | ||
3464 | if (peer == NULL) | 3371 | if (peer == NULL) |
3372 | { | ||
3373 | n->skm = NULL; | ||
3374 | n->pitr = NULL; | ||
3375 | if (n->public_key != NULL) | ||
3465 | { | 3376 | { |
3466 | n->skm = NULL; | ||
3467 | n->pitr = NULL; | ||
3468 | if (n->public_key != NULL) | ||
3469 | { | ||
3470 | #if DEBUG_CORE | 3377 | #if DEBUG_CORE |
3471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3472 | "Received `%s' for `%4s', continuing processing of `%s' message.\n", | 3379 | "Received `%s' for `%4s', continuing processing of `%s' message.\n", |
3473 | "HELLO", | 3380 | "HELLO", GNUNET_i2s (&n->peer), "SET_KEY"); |
3474 | GNUNET_i2s (&n->peer), | ||
3475 | "SET_KEY"); | ||
3476 | #endif | 3381 | #endif |
3477 | handle_set_key (n, sm, NULL, 0); | 3382 | handle_set_key (n, sm, NULL, 0); |
3478 | } | 3383 | } |
3479 | else | 3384 | else |
3480 | { | 3385 | { |
3481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3482 | _("Ignoring `%s' message due to lack of public key for peer `%4s' (failed to obtain one).\n"), | 3387 | _ |
3483 | "SET_KEY", | 3388 | ("Ignoring `%s' message due to lack of public key for peer `%4s' (failed to obtain one).\n"), |
3484 | GNUNET_i2s (&n->peer)); | 3389 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3485 | } | ||
3486 | GNUNET_free (sm); | ||
3487 | return; | ||
3488 | } | 3390 | } |
3391 | GNUNET_free (sm); | ||
3392 | return; | ||
3393 | } | ||
3489 | if (n->public_key != NULL) | 3394 | if (n->public_key != NULL) |
3490 | return; /* multiple HELLOs match!? */ | 3395 | return; /* multiple HELLOs match!? */ |
3491 | n->public_key = | 3396 | n->public_key = |
3492 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 3397 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
3493 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) | 3398 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) |
3494 | { | 3399 | { |
3495 | GNUNET_break_op (0); | 3400 | GNUNET_break_op (0); |
3496 | GNUNET_free (n->public_key); | 3401 | GNUNET_free (n->public_key); |
3497 | n->public_key = NULL; | 3402 | n->public_key = NULL; |
3498 | } | 3403 | } |
3499 | } | 3404 | } |
3500 | 3405 | ||
3501 | 3406 | ||
@@ -3509,8 +3414,8 @@ process_hello_retry_handle_set_key (void *cls, | |||
3509 | */ | 3414 | */ |
3510 | static void | 3415 | static void |
3511 | update_neighbour_performance (struct Neighbour *n, | 3416 | update_neighbour_performance (struct Neighbour *n, |
3512 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3417 | const struct GNUNET_TRANSPORT_ATS_Information |
3513 | uint32_t ats_count) | 3418 | *ats, uint32_t ats_count) |
3514 | { | 3419 | { |
3515 | uint32_t i; | 3420 | uint32_t i; |
3516 | unsigned int j; | 3421 | unsigned int j; |
@@ -3518,22 +3423,20 @@ update_neighbour_performance (struct Neighbour *n, | |||
3518 | if (ats_count == 0) | 3423 | if (ats_count == 0) |
3519 | return; | 3424 | return; |
3520 | for (i = 0; i < ats_count; i++) | 3425 | for (i = 0; i < ats_count; i++) |
3426 | { | ||
3427 | for (j = 0; j < n->ats_count; j++) | ||
3521 | { | 3428 | { |
3522 | for (j=0;j < n->ats_count; j++) | 3429 | if (n->ats[j].type == ats[i].type) |
3523 | { | 3430 | { |
3524 | if (n->ats[j].type == ats[i].type) | 3431 | n->ats[j].value = ats[i].value; |
3525 | { | 3432 | break; |
3526 | n->ats[j].value = ats[i].value; | 3433 | } |
3527 | break; | ||
3528 | } | ||
3529 | } | ||
3530 | if (j == n->ats_count) | ||
3531 | { | ||
3532 | GNUNET_array_append (n->ats, | ||
3533 | n->ats_count, | ||
3534 | ats[i]); | ||
3535 | } | ||
3536 | } | 3434 | } |
3435 | if (j == n->ats_count) | ||
3436 | { | ||
3437 | GNUNET_array_append (n->ats, n->ats_count, ats[i]); | ||
3438 | } | ||
3439 | } | ||
3537 | } | 3440 | } |
3538 | 3441 | ||
3539 | 3442 | ||
@@ -3548,9 +3451,9 @@ update_neighbour_performance (struct Neighbour *n, | |||
3548 | */ | 3451 | */ |
3549 | static void | 3452 | static void |
3550 | handle_ping (struct Neighbour *n, | 3453 | handle_ping (struct Neighbour *n, |
3551 | const struct PingMessage *m, | 3454 | const struct PingMessage *m, |
3552 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3455 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3553 | uint32_t ats_count) | 3456 | uint32_t ats_count) |
3554 | { | 3457 | { |
3555 | struct PingMessage t; | 3458 | struct PingMessage t; |
3556 | struct PongMessage tx; | 3459 | struct PongMessage tx; |
@@ -3578,37 +3481,32 @@ handle_ping (struct Neighbour *n, | |||
3578 | "PING", | 3481 | "PING", |
3579 | GNUNET_i2s (&t.target), | 3482 | GNUNET_i2s (&t.target), |
3580 | (unsigned int) t.challenge, | 3483 | (unsigned int) t.challenge, |
3581 | (unsigned int) n->decrypt_key.crc32, | 3484 | (unsigned int) n->decrypt_key.crc32, |
3582 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3485 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); |
3583 | m->iv_seed); | ||
3584 | #endif | 3486 | #endif |
3585 | GNUNET_STATISTICS_update (stats, | 3487 | GNUNET_STATISTICS_update (stats, |
3586 | gettext_noop ("# PING messages decrypted"), | 3488 | gettext_noop ("# PING messages decrypted"), |
3587 | 1, | 3489 | 1, GNUNET_NO); |
3588 | GNUNET_NO); | ||
3589 | if (0 != memcmp (&t.target, | 3490 | if (0 != memcmp (&t.target, |
3590 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 3491 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
3591 | { | 3492 | { |
3592 | char sender[9]; | 3493 | char sender[9]; |
3593 | char peer[9]; | 3494 | char peer[9]; |
3594 | 3495 | ||
3595 | GNUNET_snprintf(sender, sizeof (sender), "%8s", GNUNET_i2s (&n->peer)); | 3496 | GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&n->peer)); |
3596 | GNUNET_snprintf(peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); | 3497 | GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); |
3597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3598 | _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), | 3499 | _ |
3599 | sender, | 3500 | ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), |
3600 | GNUNET_i2s (&my_identity), | 3501 | sender, GNUNET_i2s (&my_identity), peer); |
3601 | peer); | 3502 | GNUNET_break_op (0); |
3602 | GNUNET_break_op (0); | 3503 | return; |
3603 | return; | 3504 | } |
3604 | } | ||
3605 | update_neighbour_performance (n, ats, ats_count); | 3505 | update_neighbour_performance (n, ats, ats_count); |
3606 | me = GNUNET_malloc (sizeof (struct MessageEntry) + | 3506 | me = GNUNET_malloc (sizeof (struct MessageEntry) + |
3607 | sizeof (struct PongMessage)); | 3507 | sizeof (struct PongMessage)); |
3608 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 3508 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
3609 | n->encrypted_tail, | 3509 | n->encrypted_tail, n->encrypted_tail, me); |
3610 | n->encrypted_tail, | ||
3611 | me); | ||
3612 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY); | 3510 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY); |
3613 | me->priority = PONG_PRIORITY; | 3511 | me->priority = PONG_PRIORITY; |
3614 | me->size = sizeof (struct PongMessage); | 3512 | me->size = sizeof (struct PongMessage); |
@@ -3618,7 +3516,8 @@ handle_ping (struct Neighbour *n, | |||
3618 | tp = (struct PongMessage *) &me[1]; | 3516 | tp = (struct PongMessage *) &me[1]; |
3619 | tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); | 3517 | tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); |
3620 | tp->header.size = htons (sizeof (struct PongMessage)); | 3518 | tp->header.size = htons (sizeof (struct PongMessage)); |
3621 | tp->iv_seed = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 3519 | tp->iv_seed = |
3520 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | ||
3622 | derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); | 3521 | derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); |
3623 | do_encrypt (n, | 3522 | do_encrypt (n, |
3624 | &iv, | 3523 | &iv, |
@@ -3626,18 +3525,16 @@ handle_ping (struct Neighbour *n, | |||
3626 | &tp->challenge, | 3525 | &tp->challenge, |
3627 | sizeof (struct PongMessage) - | 3526 | sizeof (struct PongMessage) - |
3628 | ((void *) &tp->challenge - (void *) tp)); | 3527 | ((void *) &tp->challenge - (void *) tp)); |
3629 | GNUNET_STATISTICS_update (stats, | 3528 | GNUNET_STATISTICS_update (stats, |
3630 | gettext_noop ("# PONG messages created"), | 3529 | gettext_noop ("# PONG messages created"), |
3631 | 1, | 3530 | 1, GNUNET_NO); |
3632 | GNUNET_NO); | ||
3633 | #if DEBUG_HANDSHAKE | 3531 | #if DEBUG_HANDSHAKE |
3634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3635 | "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", | 3533 | "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", |
3636 | "PONG", | 3534 | "PONG", |
3637 | (unsigned int) t.challenge, | 3535 | (unsigned int) t.challenge, |
3638 | (unsigned int) n->encrypt_key.crc32, | 3536 | (unsigned int) n->encrypt_key.crc32, |
3639 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3537 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), tp->iv_seed); |
3640 | tp->iv_seed); | ||
3641 | #endif | 3538 | #endif |
3642 | /* trigger queue processing */ | 3539 | /* trigger queue processing */ |
3643 | process_encrypted_neighbour_queue (n); | 3540 | process_encrypted_neighbour_queue (n); |
@@ -3653,10 +3550,10 @@ handle_ping (struct Neighbour *n, | |||
3653 | * @param ats_count number of entries in ats (excluding 0-termination) | 3550 | * @param ats_count number of entries in ats (excluding 0-termination) |
3654 | */ | 3551 | */ |
3655 | static void | 3552 | static void |
3656 | handle_pong (struct Neighbour *n, | 3553 | handle_pong (struct Neighbour *n, |
3657 | const struct PongMessage *m, | 3554 | const struct PongMessage *m, |
3658 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3555 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3659 | uint32_t ats_count) | 3556 | uint32_t ats_count) |
3660 | { | 3557 | { |
3661 | struct PongMessage t; | 3558 | struct PongMessage t; |
3662 | struct ConnectNotifyMessage *cnm; | 3559 | struct ConnectNotifyMessage *cnm; |
@@ -3673,7 +3570,7 @@ handle_pong (struct Neighbour *n, | |||
3673 | /* mark as garbage, just to be sure */ | 3570 | /* mark as garbage, just to be sure */ |
3674 | memset (&t, 255, sizeof (t)); | 3571 | memset (&t, 255, sizeof (t)); |
3675 | derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge, | 3572 | derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge, |
3676 | &my_identity); | 3573 | &my_identity); |
3677 | if (GNUNET_OK != | 3574 | if (GNUNET_OK != |
3678 | do_decrypt (n, | 3575 | do_decrypt (n, |
3679 | &iv, | 3576 | &iv, |
@@ -3681,14 +3578,13 @@ handle_pong (struct Neighbour *n, | |||
3681 | &t.challenge, | 3578 | &t.challenge, |
3682 | sizeof (struct PongMessage) - | 3579 | sizeof (struct PongMessage) - |
3683 | ((void *) &m->challenge - (void *) m))) | 3580 | ((void *) &m->challenge - (void *) m))) |
3684 | { | 3581 | { |
3685 | GNUNET_break_op (0); | 3582 | GNUNET_break_op (0); |
3686 | return; | 3583 | return; |
3687 | } | 3584 | } |
3688 | GNUNET_STATISTICS_update (stats, | 3585 | GNUNET_STATISTICS_update (stats, |
3689 | gettext_noop ("# PONG messages decrypted"), | 3586 | gettext_noop ("# PONG messages decrypted"), |
3690 | 1, | 3587 | 1, GNUNET_NO); |
3691 | GNUNET_NO); | ||
3692 | #if DEBUG_HANDSHAKE | 3588 | #if DEBUG_HANDSHAKE |
3693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3694 | "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", | 3590 | "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", |
@@ -3696,115 +3592,107 @@ handle_pong (struct Neighbour *n, | |||
3696 | GNUNET_i2s (&t.target), | 3592 | GNUNET_i2s (&t.target), |
3697 | (unsigned int) t.challenge, | 3593 | (unsigned int) t.challenge, |
3698 | (unsigned int) n->decrypt_key.crc32, | 3594 | (unsigned int) n->decrypt_key.crc32, |
3699 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3595 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); |
3700 | m->iv_seed); | ||
3701 | #endif | 3596 | #endif |
3702 | if ((0 != memcmp (&t.target, | 3597 | if ((0 != memcmp (&t.target, |
3703 | &n->peer, | 3598 | &n->peer, |
3704 | sizeof (struct GNUNET_PeerIdentity))) || | 3599 | sizeof (struct GNUNET_PeerIdentity))) || |
3705 | (n->ping_challenge != t.challenge)) | 3600 | (n->ping_challenge != t.challenge)) |
3706 | { | 3601 | { |
3707 | /* PONG malformed */ | 3602 | /* PONG malformed */ |
3708 | #if DEBUG_CORE | 3603 | #if DEBUG_CORE |
3709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3710 | "Received malformed `%s' wanted sender `%4s' with challenge %u\n", | 3605 | "Received malformed `%s' wanted sender `%4s' with challenge %u\n", |
3711 | "PONG", | 3606 | "PONG", |
3712 | GNUNET_i2s (&n->peer), | 3607 | GNUNET_i2s (&n->peer), (unsigned int) n->ping_challenge); |
3713 | (unsigned int) n->ping_challenge); | 3608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3609 | "Received malformed `%s' received from `%4s' with challenge %u\n", |
3715 | "Received malformed `%s' received from `%4s' with challenge %u\n", | 3610 | "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge); |
3716 | "PONG", GNUNET_i2s (&t.target), | ||
3717 | (unsigned int) t.challenge); | ||
3718 | #endif | 3611 | #endif |
3719 | GNUNET_break_op (n->ping_challenge != t.challenge); | 3612 | GNUNET_break_op (n->ping_challenge != t.challenge); |
3720 | return; | 3613 | return; |
3721 | } | 3614 | } |
3722 | switch (n->status) | 3615 | switch (n->status) |
3616 | { | ||
3617 | case PEER_STATE_DOWN: | ||
3618 | GNUNET_break (0); /* should be impossible */ | ||
3619 | return; | ||
3620 | case PEER_STATE_KEY_SENT: | ||
3621 | GNUNET_break (0); /* should be impossible, how did we decrypt? */ | ||
3622 | return; | ||
3623 | case PEER_STATE_KEY_RECEIVED: | ||
3624 | GNUNET_STATISTICS_update (stats, | ||
3625 | gettext_noop | ||
3626 | ("# Session keys confirmed via PONG"), 1, | ||
3627 | GNUNET_NO); | ||
3628 | n->status = PEER_STATE_KEY_CONFIRMED; | ||
3723 | { | 3629 | { |
3724 | case PEER_STATE_DOWN: | 3630 | struct GNUNET_MessageHeader *hdr; |
3725 | GNUNET_break (0); /* should be impossible */ | ||
3726 | return; | ||
3727 | case PEER_STATE_KEY_SENT: | ||
3728 | GNUNET_break (0); /* should be impossible, how did we decrypt? */ | ||
3729 | return; | ||
3730 | case PEER_STATE_KEY_RECEIVED: | ||
3731 | GNUNET_STATISTICS_update (stats, | ||
3732 | gettext_noop ("# Session keys confirmed via PONG"), | ||
3733 | 1, | ||
3734 | GNUNET_NO); | ||
3735 | n->status = PEER_STATE_KEY_CONFIRMED; | ||
3736 | { | ||
3737 | struct GNUNET_MessageHeader *hdr; | ||
3738 | 3631 | ||
3739 | hdr = compute_type_map_message (); | 3632 | hdr = compute_type_map_message (); |
3740 | send_type_map_to_neighbour (hdr, &n->peer.hashPubKey, n); | 3633 | send_type_map_to_neighbour (hdr, &n->peer.hashPubKey, n); |
3741 | GNUNET_free (hdr); | 3634 | GNUNET_free (hdr); |
3742 | } | 3635 | } |
3743 | if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__) | 3636 | if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__) |
3744 | { | 3637 | { |
3745 | n->bw_out_external_limit = t.inbound_bw_limit; | 3638 | n->bw_out_external_limit = t.inbound_bw_limit; |
3746 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, | 3639 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, |
3747 | n->bw_out_internal_limit); | 3640 | n->bw_out_internal_limit); |
3748 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, | 3641 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, |
3749 | n->bw_out); | 3642 | n->bw_out); |
3750 | GNUNET_TRANSPORT_set_quota (transport, | 3643 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
3751 | &n->peer, | 3644 | } |
3752 | n->bw_in, | ||
3753 | n->bw_out); | ||
3754 | } | ||
3755 | #if DEBUG_CORE | 3645 | #if DEBUG_CORE |
3756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3757 | "Confirmed key via `%s' message for peer `%4s'\n", | 3647 | "Confirmed key via `%s' message for peer `%4s'\n", |
3758 | "PONG", GNUNET_i2s (&n->peer)); | 3648 | "PONG", GNUNET_i2s (&n->peer)); |
3759 | #endif | 3649 | #endif |
3760 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 3650 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
3761 | { | 3651 | { |
3762 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | 3652 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); |
3763 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 3653 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
3764 | } | 3654 | } |
3765 | update_neighbour_performance (n, ats, ats_count); | 3655 | update_neighbour_performance (n, ats, ats_count); |
3766 | size = sizeof (struct ConnectNotifyMessage) + | 3656 | size = sizeof (struct ConnectNotifyMessage) + |
3767 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 3657 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
3768 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 3658 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
3769 | { | 3659 | { |
3770 | GNUNET_break (0); | ||
3771 | /* recovery strategy: throw away performance data */ | ||
3772 | GNUNET_array_grow (n->ats, | ||
3773 | n->ats_count, | ||
3774 | 0); | ||
3775 | size = sizeof (struct PeerStatusNotifyMessage) + | ||
3776 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | ||
3777 | } | ||
3778 | cnm = (struct ConnectNotifyMessage*) buf; | ||
3779 | cnm->header.size = htons (size); | ||
3780 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | ||
3781 | cnm->ats_count = htonl (n->ats_count); | ||
3782 | cnm->peer = n->peer; | ||
3783 | mats = &cnm->ats; | ||
3784 | memcpy (mats, | ||
3785 | n->ats, | ||
3786 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | ||
3787 | mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | ||
3788 | mats[n->ats_count].value = htonl (0); | ||
3789 | send_to_all_clients (&cnm->header, | ||
3790 | GNUNET_NO, | ||
3791 | GNUNET_CORE_OPTION_SEND_CONNECT); | ||
3792 | process_encrypted_neighbour_queue (n); | ||
3793 | /* fall-through! */ | ||
3794 | case PEER_STATE_KEY_CONFIRMED: | ||
3795 | n->last_activity = GNUNET_TIME_absolute_get (); | ||
3796 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
3797 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
3798 | n->keep_alive_task | ||
3799 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), | ||
3800 | &send_keep_alive, | ||
3801 | n); | ||
3802 | handle_peer_status_change (n); | ||
3803 | break; | ||
3804 | default: | ||
3805 | GNUNET_break (0); | 3660 | GNUNET_break (0); |
3806 | break; | 3661 | /* recovery strategy: throw away performance data */ |
3662 | GNUNET_array_grow (n->ats, n->ats_count, 0); | ||
3663 | size = sizeof (struct PeerStatusNotifyMessage) + | ||
3664 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | ||
3807 | } | 3665 | } |
3666 | cnm = (struct ConnectNotifyMessage *) buf; | ||
3667 | cnm->header.size = htons (size); | ||
3668 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | ||
3669 | cnm->ats_count = htonl (n->ats_count); | ||
3670 | cnm->peer = n->peer; | ||
3671 | mats = &cnm->ats; | ||
3672 | memcpy (mats, | ||
3673 | n->ats, | ||
3674 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | ||
3675 | mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | ||
3676 | mats[n->ats_count].value = htonl (0); | ||
3677 | send_to_all_clients (&cnm->header, | ||
3678 | GNUNET_NO, GNUNET_CORE_OPTION_SEND_CONNECT); | ||
3679 | process_encrypted_neighbour_queue (n); | ||
3680 | /* fall-through! */ | ||
3681 | case PEER_STATE_KEY_CONFIRMED: | ||
3682 | n->last_activity = GNUNET_TIME_absolute_get (); | ||
3683 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
3684 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
3685 | n->keep_alive_task | ||
3686 | = | ||
3687 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
3688 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
3689 | 2), &send_keep_alive, n); | ||
3690 | handle_peer_status_change (n); | ||
3691 | break; | ||
3692 | default: | ||
3693 | GNUNET_break (0); | ||
3694 | break; | ||
3695 | } | ||
3808 | } | 3696 | } |
3809 | 3697 | ||
3810 | 3698 | ||
@@ -3818,10 +3706,10 @@ handle_pong (struct Neighbour *n, | |||
3818 | * @param ats_count number of entries in ats (excluding 0-termination) | 3706 | * @param ats_count number of entries in ats (excluding 0-termination) |
3819 | */ | 3707 | */ |
3820 | static void | 3708 | static void |
3821 | handle_set_key (struct Neighbour *n, | 3709 | handle_set_key (struct Neighbour *n, |
3822 | const struct SetKeyMessage *m, | 3710 | const struct SetKeyMessage *m, |
3823 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3711 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3824 | uint32_t ats_count) | 3712 | uint32_t ats_count) |
3825 | { | 3713 | { |
3826 | struct SetKeyMessage *m_cpy; | 3714 | struct SetKeyMessage *m_cpy; |
3827 | struct GNUNET_TIME_Absolute t; | 3715 | struct GNUNET_TIME_Absolute t; |
@@ -3836,45 +3724,44 @@ handle_set_key (struct Neighbour *n, | |||
3836 | "SET_KEY", GNUNET_i2s (&n->peer)); | 3724 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3837 | #endif | 3725 | #endif |
3838 | if (n->public_key == NULL) | 3726 | if (n->public_key == NULL) |
3727 | { | ||
3728 | if (n->pitr != NULL) | ||
3839 | { | 3729 | { |
3840 | if (n->pitr != NULL) | ||
3841 | { | ||
3842 | #if DEBUG_CORE | ||
3843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3844 | "Ignoring `%s' message due to lack of public key for peer (still trying to obtain one).\n", | ||
3845 | "SET_KEY"); | ||
3846 | #endif | ||
3847 | return; | ||
3848 | } | ||
3849 | #if DEBUG_CORE | 3730 | #if DEBUG_CORE |
3850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3731 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3851 | "Lacking public key for peer, trying to obtain one (handle_set_key).\n"); | 3732 | "Ignoring `%s' message due to lack of public key for peer (still trying to obtain one).\n", |
3733 | "SET_KEY"); | ||
3852 | #endif | 3734 | #endif |
3853 | m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage)); | ||
3854 | memcpy (m_cpy, m, sizeof (struct SetKeyMessage)); | ||
3855 | /* lookup n's public key, then try again */ | ||
3856 | GNUNET_assert (n->skm == NULL); | ||
3857 | n->skm = m_cpy; | ||
3858 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, | ||
3859 | &n->peer, | ||
3860 | GNUNET_TIME_UNIT_MINUTES, | ||
3861 | &process_hello_retry_handle_set_key, n); | ||
3862 | GNUNET_STATISTICS_update (stats, | ||
3863 | gettext_noop ("# SET_KEY messages deferred (need public key)"), | ||
3864 | 1, | ||
3865 | GNUNET_NO); | ||
3866 | return; | 3735 | return; |
3867 | } | 3736 | } |
3737 | #if DEBUG_CORE | ||
3738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3739 | "Lacking public key for peer, trying to obtain one (handle_set_key).\n"); | ||
3740 | #endif | ||
3741 | m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage)); | ||
3742 | memcpy (m_cpy, m, sizeof (struct SetKeyMessage)); | ||
3743 | /* lookup n's public key, then try again */ | ||
3744 | GNUNET_assert (n->skm == NULL); | ||
3745 | n->skm = m_cpy; | ||
3746 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, | ||
3747 | &n->peer, | ||
3748 | GNUNET_TIME_UNIT_MINUTES, | ||
3749 | &process_hello_retry_handle_set_key, n); | ||
3750 | GNUNET_STATISTICS_update (stats, | ||
3751 | gettext_noop | ||
3752 | ("# SET_KEY messages deferred (need public key)"), | ||
3753 | 1, GNUNET_NO); | ||
3754 | return; | ||
3755 | } | ||
3868 | if (0 != memcmp (&m->target, | 3756 | if (0 != memcmp (&m->target, |
3869 | &my_identity, | 3757 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
3870 | sizeof (struct GNUNET_PeerIdentity))) | 3758 | { |
3871 | { | 3759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3760 | _ |
3873 | _("Received `%s' message that was for `%s', not for me. Ignoring.\n"), | 3761 | ("Received `%s' message that was for `%s', not for me. Ignoring.\n"), |
3874 | "SET_KEY", | 3762 | "SET_KEY", GNUNET_i2s (&m->target)); |
3875 | GNUNET_i2s (&m->target)); | 3763 | return; |
3876 | return; | 3764 | } |
3877 | } | ||
3878 | if ((ntohl (m->purpose.size) != | 3765 | if ((ntohl (m->purpose.size) != |
3879 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 3766 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
3880 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 3767 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
@@ -3883,107 +3770,103 @@ handle_set_key (struct Neighbour *n, | |||
3883 | (GNUNET_OK != | 3770 | (GNUNET_OK != |
3884 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, | 3771 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, |
3885 | &m->purpose, &m->signature, n->public_key))) | 3772 | &m->purpose, &m->signature, n->public_key))) |
3886 | { | 3773 | { |
3887 | /* invalid signature */ | 3774 | /* invalid signature */ |
3888 | GNUNET_break_op (0); | 3775 | GNUNET_break_op (0); |
3889 | return; | 3776 | return; |
3890 | } | 3777 | } |
3891 | t = GNUNET_TIME_absolute_ntoh (m->creation_time); | 3778 | t = GNUNET_TIME_absolute_ntoh (m->creation_time); |
3892 | if (((n->status == PEER_STATE_KEY_RECEIVED) || | 3779 | if (((n->status == PEER_STATE_KEY_RECEIVED) || |
3893 | (n->status == PEER_STATE_KEY_CONFIRMED)) && | 3780 | (n->status == PEER_STATE_KEY_CONFIRMED)) && |
3894 | (t.abs_value < n->decrypt_key_created.abs_value)) | 3781 | (t.abs_value < n->decrypt_key_created.abs_value)) |
3895 | { | 3782 | { |
3896 | /* this could rarely happen due to massive re-ordering of | 3783 | /* this could rarely happen due to massive re-ordering of |
3897 | messages on the network level, but is most likely either | 3784 | * messages on the network level, but is most likely either |
3898 | a bug or some adversary messing with us. Report. */ | 3785 | * a bug or some adversary messing with us. Report. */ |
3899 | GNUNET_break_op (0); | 3786 | GNUNET_break_op (0); |
3900 | return; | 3787 | return; |
3901 | } | 3788 | } |
3902 | #if DEBUG_CORE | 3789 | #if DEBUG_CORE |
3903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n"); |
3904 | "Decrypting key material.\n"); | 3791 | #endif |
3905 | #endif | ||
3906 | if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key, | 3792 | if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key, |
3907 | &m->encrypted_key, | 3793 | &m->encrypted_key, |
3908 | &k, | 3794 | &k, |
3909 | sizeof (struct GNUNET_CRYPTO_AesSessionKey)) | 3795 | sizeof (struct GNUNET_CRYPTO_AesSessionKey)) |
3910 | != sizeof (struct GNUNET_CRYPTO_AesSessionKey)) || | 3796 | != sizeof (struct GNUNET_CRYPTO_AesSessionKey)) || |
3911 | (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) | 3797 | (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) |
3912 | { | 3798 | { |
3913 | /* failed to decrypt !? */ | 3799 | /* failed to decrypt !? */ |
3914 | GNUNET_break_op (0); | 3800 | GNUNET_break_op (0); |
3915 | return; | 3801 | return; |
3916 | } | 3802 | } |
3917 | GNUNET_STATISTICS_update (stats, | 3803 | GNUNET_STATISTICS_update (stats, |
3918 | gettext_noop ("# SET_KEY messages decrypted"), | 3804 | gettext_noop ("# SET_KEY messages decrypted"), |
3919 | 1, | 3805 | 1, GNUNET_NO); |
3920 | GNUNET_NO); | ||
3921 | n->decrypt_key = k; | 3806 | n->decrypt_key = k; |
3922 | if (n->decrypt_key_created.abs_value != t.abs_value) | 3807 | if (n->decrypt_key_created.abs_value != t.abs_value) |
3923 | { | 3808 | { |
3924 | /* fresh key, reset sequence numbers */ | 3809 | /* fresh key, reset sequence numbers */ |
3925 | n->last_sequence_number_received = 0; | 3810 | n->last_sequence_number_received = 0; |
3926 | n->last_packets_bitmap = 0; | 3811 | n->last_packets_bitmap = 0; |
3927 | n->decrypt_key_created = t; | 3812 | n->decrypt_key_created = t; |
3928 | } | 3813 | } |
3929 | update_neighbour_performance (n, ats, ats_count); | 3814 | update_neighbour_performance (n, ats, ats_count); |
3930 | sender_status = (enum PeerStateMachine) ntohl (m->sender_status); | 3815 | sender_status = (enum PeerStateMachine) ntohl (m->sender_status); |
3931 | switch (n->status) | 3816 | switch (n->status) |
3817 | { | ||
3818 | case PEER_STATE_DOWN: | ||
3819 | n->status = PEER_STATE_KEY_RECEIVED; | ||
3820 | #if DEBUG_CORE | ||
3821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3822 | "Responding to `%s' with my own key.\n", "SET_KEY"); | ||
3823 | #endif | ||
3824 | send_key (n); | ||
3825 | break; | ||
3826 | case PEER_STATE_KEY_SENT: | ||
3827 | case PEER_STATE_KEY_RECEIVED: | ||
3828 | n->status = PEER_STATE_KEY_RECEIVED; | ||
3829 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && | ||
3830 | (sender_status != PEER_STATE_KEY_CONFIRMED)) | ||
3932 | { | 3831 | { |
3933 | case PEER_STATE_DOWN: | ||
3934 | n->status = PEER_STATE_KEY_RECEIVED; | ||
3935 | #if DEBUG_CORE | 3832 | #if DEBUG_CORE |
3936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3937 | "Responding to `%s' with my own key.\n", "SET_KEY"); | 3834 | "Responding to `%s' with my own key (other peer has status %u).\n", |
3835 | "SET_KEY", (unsigned int) sender_status); | ||
3938 | #endif | 3836 | #endif |
3939 | send_key (n); | 3837 | send_key (n); |
3940 | break; | 3838 | } |
3941 | case PEER_STATE_KEY_SENT: | 3839 | break; |
3942 | case PEER_STATE_KEY_RECEIVED: | 3840 | case PEER_STATE_KEY_CONFIRMED: |
3943 | n->status = PEER_STATE_KEY_RECEIVED; | 3841 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && |
3944 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && | 3842 | (sender_status != PEER_STATE_KEY_CONFIRMED)) |
3945 | (sender_status != PEER_STATE_KEY_CONFIRMED)) | 3843 | { |
3946 | { | ||
3947 | #if DEBUG_CORE | ||
3948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3949 | "Responding to `%s' with my own key (other peer has status %u).\n", | ||
3950 | "SET_KEY", | ||
3951 | (unsigned int) sender_status); | ||
3952 | #endif | ||
3953 | send_key (n); | ||
3954 | } | ||
3955 | break; | ||
3956 | case PEER_STATE_KEY_CONFIRMED: | ||
3957 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && | ||
3958 | (sender_status != PEER_STATE_KEY_CONFIRMED)) | ||
3959 | { | ||
3960 | #if DEBUG_CORE | 3844 | #if DEBUG_CORE |
3961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3962 | "Responding to `%s' with my own key (other peer has status %u), I was already fully up.\n", | 3846 | "Responding to `%s' with my own key (other peer has status %u), I was already fully up.\n", |
3963 | "SET_KEY", | 3847 | "SET_KEY", (unsigned int) sender_status); |
3964 | (unsigned int) sender_status); | ||
3965 | #endif | 3848 | #endif |
3966 | send_key (n); | 3849 | send_key (n); |
3967 | } | ||
3968 | break; | ||
3969 | default: | ||
3970 | GNUNET_break (0); | ||
3971 | break; | ||
3972 | } | 3850 | } |
3851 | break; | ||
3852 | default: | ||
3853 | GNUNET_break (0); | ||
3854 | break; | ||
3855 | } | ||
3973 | if (n->pending_ping != NULL) | 3856 | if (n->pending_ping != NULL) |
3974 | { | 3857 | { |
3975 | ping = n->pending_ping; | 3858 | ping = n->pending_ping; |
3976 | n->pending_ping = NULL; | 3859 | n->pending_ping = NULL; |
3977 | handle_ping (n, ping, NULL, 0); | 3860 | handle_ping (n, ping, NULL, 0); |
3978 | GNUNET_free (ping); | 3861 | GNUNET_free (ping); |
3979 | } | 3862 | } |
3980 | if (n->pending_pong != NULL) | 3863 | if (n->pending_pong != NULL) |
3981 | { | 3864 | { |
3982 | pong = n->pending_pong; | 3865 | pong = n->pending_pong; |
3983 | n->pending_pong = NULL; | 3866 | n->pending_pong = NULL; |
3984 | handle_pong (n, pong, NULL, 0); | 3867 | handle_pong (n, pong, NULL, 0); |
3985 | GNUNET_free (pong); | 3868 | GNUNET_free (pong); |
3986 | } | 3869 | } |
3987 | } | 3870 | } |
3988 | 3871 | ||
3989 | 3872 | ||
@@ -3997,31 +3880,29 @@ handle_set_key (struct Neighbour *n, | |||
3997 | */ | 3880 | */ |
3998 | static void | 3881 | static void |
3999 | send_p2p_message_to_client (struct Neighbour *sender, | 3882 | send_p2p_message_to_client (struct Neighbour *sender, |
4000 | struct Client *client, | 3883 | struct Client *client, const void *m, size_t msize) |
4001 | const void *m, size_t msize) | ||
4002 | { | 3884 | { |
4003 | size_t size = msize + sizeof (struct NotifyTrafficMessage) + | 3885 | size_t size = msize + sizeof (struct NotifyTrafficMessage) + |
4004 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 3886 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
4005 | char buf[size]; | 3887 | char buf[size]; |
4006 | struct NotifyTrafficMessage *ntm; | 3888 | struct NotifyTrafficMessage *ntm; |
4007 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 3889 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
4008 | 3890 | ||
4009 | GNUNET_assert (GNUNET_YES == sender->is_connected); | 3891 | GNUNET_assert (GNUNET_YES == sender->is_connected); |
4010 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 3892 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
4011 | { | 3893 | { |
4012 | GNUNET_break (0); | 3894 | GNUNET_break (0); |
4013 | /* recovery strategy: throw performance data away... */ | 3895 | /* recovery strategy: throw performance data away... */ |
4014 | GNUNET_array_grow (sender->ats, | 3896 | GNUNET_array_grow (sender->ats, sender->ats_count, 0); |
4015 | sender->ats_count, | 3897 | size = msize + sizeof (struct NotifyTrafficMessage) + |
4016 | 0); | 3898 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
4017 | size = msize + sizeof (struct NotifyTrafficMessage) + | 3899 | } |
4018 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | ||
4019 | } | ||
4020 | #if DEBUG_CORE | 3900 | #if DEBUG_CORE |
4021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3901 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4022 | "Core service passes message from `%4s' of type %u to client.\n", | 3902 | "Core service passes message from `%4s' of type %u to client.\n", |
4023 | GNUNET_i2s(&sender->peer), | 3903 | GNUNET_i2s (&sender->peer), |
4024 | (unsigned int) ntohs (((const struct GNUNET_MessageHeader *) m)->type)); | 3904 | (unsigned int) |
3905 | ntohs (((const struct GNUNET_MessageHeader *) m)->type)); | ||
4025 | #endif | 3906 | #endif |
4026 | ntm = (struct NotifyTrafficMessage *) buf; | 3907 | ntm = (struct NotifyTrafficMessage *) buf; |
4027 | ntm->header.size = htons (size); | 3908 | ntm->header.size = htons (size); |
@@ -4030,13 +3911,11 @@ send_p2p_message_to_client (struct Neighbour *sender, | |||
4030 | ntm->peer = sender->peer; | 3911 | ntm->peer = sender->peer; |
4031 | ats = &ntm->ats; | 3912 | ats = &ntm->ats; |
4032 | memcpy (ats, | 3913 | memcpy (ats, |
4033 | sender->ats, | 3914 | sender->ats, |
4034 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count); | 3915 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count); |
4035 | ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 3916 | ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
4036 | ats[sender->ats_count].value = htonl (0); | 3917 | ats[sender->ats_count].value = htonl (0); |
4037 | memcpy (&ats[sender->ats_count+1], | 3918 | memcpy (&ats[sender->ats_count + 1], m, msize); |
4038 | m, | ||
4039 | msize); | ||
4040 | send_to_client (client, &ntm->header, GNUNET_YES); | 3919 | send_to_client (client, &ntm->header, GNUNET_YES); |
4041 | } | 3920 | } |
4042 | 3921 | ||
@@ -4049,9 +3928,7 @@ send_p2p_message_to_client (struct Neighbour *sender, | |||
4049 | * @param m the message | 3928 | * @param m the message |
4050 | */ | 3929 | */ |
4051 | static void | 3930 | static void |
4052 | deliver_message (void *cls, | 3931 | deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) |
4053 | void *client, | ||
4054 | const struct GNUNET_MessageHeader *m) | ||
4055 | { | 3932 | { |
4056 | struct Neighbour *sender = client; | 3933 | struct Neighbour *sender = client; |
4057 | size_t msize = ntohs (m->size); | 3934 | size_t msize = ntohs (m->size); |
@@ -4065,66 +3942,61 @@ deliver_message (void *cls, | |||
4065 | type = ntohs (m->type); | 3942 | type = ntohs (m->type); |
4066 | #if DEBUG_CORE > 1 | 3943 | #if DEBUG_CORE > 1 |
4067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3944 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4068 | "Received encapsulated message of type %u and size %u from `%4s'\n", | 3945 | "Received encapsulated message of type %u and size %u from `%4s'\n", |
4069 | (unsigned int) type, | 3946 | (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer)); |
4070 | ntohs (m->size), | ||
4071 | GNUNET_i2s (&sender->peer)); | ||
4072 | #endif | 3947 | #endif |
4073 | GNUNET_snprintf (buf, | 3948 | GNUNET_snprintf (buf, |
4074 | sizeof(buf), | 3949 | sizeof (buf), |
4075 | gettext_noop ("# bytes of messages of type %u received"), | 3950 | gettext_noop ("# bytes of messages of type %u received"), |
4076 | (unsigned int) type); | 3951 | (unsigned int) type); |
4077 | GNUNET_STATISTICS_update (stats, | 3952 | GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO); |
4078 | buf, | 3953 | if ((GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) || |
4079 | msize, | 3954 | (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type)) |
4080 | GNUNET_NO); | 3955 | { |
4081 | if ( (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) || | 3956 | /* FIXME: update message type map for 'Neighbour' */ |
4082 | (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type) ) | 3957 | return; |
4083 | { | 3958 | } |
4084 | /* FIXME: update message type map for 'Neighbour' */ | ||
4085 | return; | ||
4086 | } | ||
4087 | dropped = GNUNET_YES; | 3959 | dropped = GNUNET_YES; |
4088 | cpos = clients; | 3960 | cpos = clients; |
4089 | while (cpos != NULL) | 3961 | while (cpos != NULL) |
3962 | { | ||
3963 | deliver_full = GNUNET_NO; | ||
3964 | if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) | ||
3965 | deliver_full = GNUNET_YES; | ||
3966 | else | ||
4090 | { | 3967 | { |
4091 | deliver_full = GNUNET_NO; | 3968 | for (tpos = 0; tpos < cpos->tcnt; tpos++) |
4092 | if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) | 3969 | { |
3970 | if (type != cpos->types[tpos]) | ||
3971 | continue; | ||
4093 | deliver_full = GNUNET_YES; | 3972 | deliver_full = GNUNET_YES; |
4094 | else | 3973 | break; |
4095 | { | 3974 | } |
4096 | for (tpos = 0; tpos < cpos->tcnt; tpos++) | ||
4097 | { | ||
4098 | if (type != cpos->types[tpos]) | ||
4099 | continue; | ||
4100 | deliver_full = GNUNET_YES; | ||
4101 | break; | ||
4102 | } | ||
4103 | } | ||
4104 | if (GNUNET_YES == deliver_full) | ||
4105 | { | ||
4106 | send_p2p_message_to_client (sender, cpos, m, msize); | ||
4107 | dropped = GNUNET_NO; | ||
4108 | } | ||
4109 | else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND) | ||
4110 | { | ||
4111 | send_p2p_message_to_client (sender, cpos, m, | ||
4112 | sizeof (struct GNUNET_MessageHeader)); | ||
4113 | } | ||
4114 | cpos = cpos->next; | ||
4115 | } | 3975 | } |
4116 | if (dropped == GNUNET_YES) | 3976 | if (GNUNET_YES == deliver_full) |
4117 | { | 3977 | { |
3978 | send_p2p_message_to_client (sender, cpos, m, msize); | ||
3979 | dropped = GNUNET_NO; | ||
3980 | } | ||
3981 | else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND) | ||
3982 | { | ||
3983 | send_p2p_message_to_client (sender, cpos, m, | ||
3984 | sizeof (struct GNUNET_MessageHeader)); | ||
3985 | } | ||
3986 | cpos = cpos->next; | ||
3987 | } | ||
3988 | if (dropped == GNUNET_YES) | ||
3989 | { | ||
4118 | #if DEBUG_CORE | 3990 | #if DEBUG_CORE |
4119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4120 | "Message of type %u from `%4s' not delivered to any client.\n", | 3992 | "Message of type %u from `%4s' not delivered to any client.\n", |
4121 | (unsigned int) type, | 3993 | (unsigned int) type, GNUNET_i2s (&sender->peer)); |
4122 | GNUNET_i2s (&sender->peer)); | ||
4123 | #endif | 3994 | #endif |
4124 | GNUNET_STATISTICS_update (stats, | 3995 | GNUNET_STATISTICS_update (stats, |
4125 | gettext_noop ("# messages not delivered to any client"), | 3996 | gettext_noop |
4126 | 1, GNUNET_NO); | 3997 | ("# messages not delivered to any client"), 1, |
4127 | } | 3998 | GNUNET_NO); |
3999 | } | ||
4128 | } | 4000 | } |
4129 | 4001 | ||
4130 | 4002 | ||
@@ -4140,8 +4012,8 @@ deliver_message (void *cls, | |||
4140 | static void | 4012 | static void |
4141 | handle_encrypted_message (struct Neighbour *n, | 4013 | handle_encrypted_message (struct Neighbour *n, |
4142 | const struct EncryptedMessage *m, | 4014 | const struct EncryptedMessage *m, |
4143 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 4015 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
4144 | uint32_t ats_count) | 4016 | uint32_t ats_count) |
4145 | { | 4017 | { |
4146 | size_t size = ntohs (m->header.size); | 4018 | size_t size = ntohs (m->header.size); |
4147 | char buf[size]; | 4019 | char buf[size]; |
@@ -4156,147 +4028,140 @@ handle_encrypted_message (struct Neighbour *n, | |||
4156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4157 | "Core service receives `%s' request from `%4s'.\n", | 4029 | "Core service receives `%s' request from `%4s'.\n", |
4158 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); | 4030 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); |
4159 | #endif | 4031 | #endif |
4160 | /* validate hash */ | 4032 | /* validate hash */ |
4161 | derive_auth_key (&auth_key, | 4033 | derive_auth_key (&auth_key, |
4162 | &n->decrypt_key, | 4034 | &n->decrypt_key, m->iv_seed, n->decrypt_key_created); |
4163 | m->iv_seed, | ||
4164 | n->decrypt_key_created); | ||
4165 | GNUNET_CRYPTO_hmac (&auth_key, | 4035 | GNUNET_CRYPTO_hmac (&auth_key, |
4166 | &m->sequence_number, | 4036 | &m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &ph); |
4167 | size - ENCRYPTED_HEADER_SIZE, &ph); | ||
4168 | #if DEBUG_HANDSHAKE | 4037 | #if DEBUG_HANDSHAKE |
4169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4170 | "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n", | 4039 | "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n", |
4171 | (unsigned int) size - ENCRYPTED_HEADER_SIZE, | 4040 | (unsigned int) size - ENCRYPTED_HEADER_SIZE, |
4172 | GNUNET_CRYPTO_crc32_n (&m->sequence_number, | 4041 | GNUNET_CRYPTO_crc32_n (&m->sequence_number, |
4173 | size - ENCRYPTED_HEADER_SIZE), | 4042 | size - ENCRYPTED_HEADER_SIZE), |
4174 | GNUNET_h2s (&ph)); | 4043 | GNUNET_h2s (&ph)); |
4175 | #endif | 4044 | #endif |
4176 | 4045 | ||
4177 | if (0 != memcmp (&ph, | 4046 | if (0 != memcmp (&ph, &m->hmac, sizeof (GNUNET_HashCode))) |
4178 | &m->hmac, | 4047 | { |
4179 | sizeof (GNUNET_HashCode))) | 4048 | /* checksum failed */ |
4180 | { | 4049 | GNUNET_break_op (0); |
4181 | /* checksum failed */ | 4050 | return; |
4182 | GNUNET_break_op (0); | 4051 | } |
4183 | return; | ||
4184 | } | ||
4185 | derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); | 4052 | derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); |
4186 | /* decrypt */ | 4053 | /* decrypt */ |
4187 | if (GNUNET_OK != | 4054 | if (GNUNET_OK != |
4188 | do_decrypt (n, | 4055 | do_decrypt (n, |
4189 | &iv, | 4056 | &iv, |
4190 | &m->sequence_number, | 4057 | &m->sequence_number, |
4191 | &buf[ENCRYPTED_HEADER_SIZE], | 4058 | &buf[ENCRYPTED_HEADER_SIZE], size - ENCRYPTED_HEADER_SIZE)) |
4192 | size - ENCRYPTED_HEADER_SIZE)) | ||
4193 | return; | 4059 | return; |
4194 | pt = (struct EncryptedMessage *) buf; | 4060 | pt = (struct EncryptedMessage *) buf; |
4195 | 4061 | ||
4196 | /* validate sequence number */ | 4062 | /* validate sequence number */ |
4197 | snum = ntohl (pt->sequence_number); | 4063 | snum = ntohl (pt->sequence_number); |
4198 | if (n->last_sequence_number_received == snum) | 4064 | if (n->last_sequence_number_received == snum) |
4199 | { | 4065 | { |
4200 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4066 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4201 | "Received duplicate message, ignoring.\n"); | 4067 | "Received duplicate message, ignoring.\n"); |
4202 | /* duplicate, ignore */ | 4068 | /* duplicate, ignore */ |
4203 | GNUNET_STATISTICS_update (stats, | 4069 | GNUNET_STATISTICS_update (stats, |
4204 | gettext_noop ("# bytes dropped (duplicates)"), | 4070 | gettext_noop ("# bytes dropped (duplicates)"), |
4205 | size, | 4071 | size, GNUNET_NO); |
4206 | GNUNET_NO); | 4072 | return; |
4207 | return; | 4073 | } |
4208 | } | ||
4209 | if ((n->last_sequence_number_received > snum) && | 4074 | if ((n->last_sequence_number_received > snum) && |
4210 | (n->last_sequence_number_received - snum > 32)) | 4075 | (n->last_sequence_number_received - snum > 32)) |
4076 | { | ||
4077 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
4078 | "Received ancient out of sequence message, ignoring.\n"); | ||
4079 | /* ancient out of sequence, ignore */ | ||
4080 | GNUNET_STATISTICS_update (stats, | ||
4081 | gettext_noop | ||
4082 | ("# bytes dropped (out of sequence)"), size, | ||
4083 | GNUNET_NO); | ||
4084 | return; | ||
4085 | } | ||
4086 | if (n->last_sequence_number_received > snum) | ||
4087 | { | ||
4088 | unsigned int rotbit = 1 << (n->last_sequence_number_received - snum - 1); | ||
4089 | |||
4090 | if ((n->last_packets_bitmap & rotbit) != 0) | ||
4211 | { | 4091 | { |
4212 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4092 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4213 | "Received ancient out of sequence message, ignoring.\n"); | 4093 | "Received duplicate message, ignoring.\n"); |
4214 | /* ancient out of sequence, ignore */ | ||
4215 | GNUNET_STATISTICS_update (stats, | 4094 | GNUNET_STATISTICS_update (stats, |
4216 | gettext_noop ("# bytes dropped (out of sequence)"), | 4095 | gettext_noop ("# bytes dropped (duplicates)"), |
4217 | size, | 4096 | size, GNUNET_NO); |
4218 | GNUNET_NO); | 4097 | /* duplicate, ignore */ |
4219 | return; | 4098 | return; |
4220 | } | 4099 | } |
4221 | if (n->last_sequence_number_received > snum) | 4100 | n->last_packets_bitmap |= rotbit; |
4222 | { | 4101 | } |
4223 | unsigned int rotbit = | ||
4224 | 1 << (n->last_sequence_number_received - snum - 1); | ||
4225 | if ((n->last_packets_bitmap & rotbit) != 0) | ||
4226 | { | ||
4227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
4228 | "Received duplicate message, ignoring.\n"); | ||
4229 | GNUNET_STATISTICS_update (stats, | ||
4230 | gettext_noop ("# bytes dropped (duplicates)"), | ||
4231 | size, | ||
4232 | GNUNET_NO); | ||
4233 | /* duplicate, ignore */ | ||
4234 | return; | ||
4235 | } | ||
4236 | n->last_packets_bitmap |= rotbit; | ||
4237 | } | ||
4238 | if (n->last_sequence_number_received < snum) | 4102 | if (n->last_sequence_number_received < snum) |
4239 | { | 4103 | { |
4240 | int shift = (snum - n->last_sequence_number_received); | 4104 | int shift = (snum - n->last_sequence_number_received); |
4241 | if (shift >= 8 * sizeof(n->last_packets_bitmap)) | 4105 | |
4242 | n->last_packets_bitmap = 0; | 4106 | if (shift >= 8 * sizeof (n->last_packets_bitmap)) |
4243 | else | 4107 | n->last_packets_bitmap = 0; |
4244 | n->last_packets_bitmap <<= shift; | 4108 | else |
4245 | n->last_sequence_number_received = snum; | 4109 | n->last_packets_bitmap <<= shift; |
4246 | } | 4110 | n->last_sequence_number_received = snum; |
4111 | } | ||
4247 | 4112 | ||
4248 | /* check timestamp */ | 4113 | /* check timestamp */ |
4249 | t = GNUNET_TIME_absolute_ntoh (pt->timestamp); | 4114 | t = GNUNET_TIME_absolute_ntoh (pt->timestamp); |
4250 | if (GNUNET_TIME_absolute_get_duration (t).rel_value > MAX_MESSAGE_AGE.rel_value) | 4115 | if (GNUNET_TIME_absolute_get_duration (t).rel_value > |
4251 | { | 4116 | MAX_MESSAGE_AGE.rel_value) |
4252 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4117 | { |
4253 | _ | 4118 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4254 | ("Message received far too old (%llu ms). Content ignored.\n"), | 4119 | _ |
4255 | GNUNET_TIME_absolute_get_duration (t).rel_value); | 4120 | ("Message received far too old (%llu ms). Content ignored.\n"), |
4256 | GNUNET_STATISTICS_update (stats, | 4121 | GNUNET_TIME_absolute_get_duration (t).rel_value); |
4257 | gettext_noop ("# bytes dropped (ancient message)"), | 4122 | GNUNET_STATISTICS_update (stats, |
4258 | size, | 4123 | gettext_noop |
4259 | GNUNET_NO); | 4124 | ("# bytes dropped (ancient message)"), size, |
4260 | return; | 4125 | GNUNET_NO); |
4261 | } | 4126 | return; |
4127 | } | ||
4262 | 4128 | ||
4263 | /* process decrypted message(s) */ | 4129 | /* process decrypted message(s) */ |
4264 | if (n->bw_out_external_limit.value__ != pt->inbound_bw_limit.value__) | 4130 | if (n->bw_out_external_limit.value__ != pt->inbound_bw_limit.value__) |
4265 | { | 4131 | { |
4266 | #if DEBUG_CORE_SET_QUOTA | 4132 | #if DEBUG_CORE_SET_QUOTA |
4267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4268 | "Received %u b/s as new inbound limit for peer `%4s'\n", | 4134 | "Received %u b/s as new inbound limit for peer `%4s'\n", |
4269 | (unsigned int) ntohl (pt->inbound_bw_limit.value__), | 4135 | (unsigned int) ntohl (pt->inbound_bw_limit.value__), |
4270 | GNUNET_i2s (&n->peer)); | 4136 | GNUNET_i2s (&n->peer)); |
4271 | #endif | 4137 | #endif |
4272 | n->bw_out_external_limit = pt->inbound_bw_limit; | 4138 | n->bw_out_external_limit = pt->inbound_bw_limit; |
4273 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, | 4139 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, |
4274 | n->bw_out_internal_limit); | 4140 | n->bw_out_internal_limit); |
4275 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, | 4141 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, |
4276 | n->bw_out); | 4142 | n->bw_out); |
4277 | GNUNET_TRANSPORT_set_quota (transport, | 4143 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
4278 | &n->peer, | 4144 | } |
4279 | n->bw_in, | ||
4280 | n->bw_out); | ||
4281 | } | ||
4282 | n->last_activity = GNUNET_TIME_absolute_get (); | 4145 | n->last_activity = GNUNET_TIME_absolute_get (); |
4283 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | 4146 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) |
4284 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | 4147 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); |
4285 | n->keep_alive_task | 4148 | n->keep_alive_task |
4286 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), | 4149 | = |
4287 | &send_keep_alive, | 4150 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
4288 | n); | 4151 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
4152 | 2), &send_keep_alive, n); | ||
4289 | GNUNET_STATISTICS_update (stats, | 4153 | GNUNET_STATISTICS_update (stats, |
4290 | gettext_noop ("# bytes of payload decrypted"), | 4154 | gettext_noop ("# bytes of payload decrypted"), |
4291 | size - sizeof (struct EncryptedMessage), | 4155 | size - sizeof (struct EncryptedMessage), GNUNET_NO); |
4292 | GNUNET_NO); | ||
4293 | handle_peer_status_change (n); | 4156 | handle_peer_status_change (n); |
4294 | update_neighbour_performance (n, ats, ats_count); | 4157 | update_neighbour_performance (n, ats, ats_count); |
4295 | if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst, | 4158 | if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst, |
4296 | n, | 4159 | n, |
4297 | &buf[sizeof (struct EncryptedMessage)], | 4160 | &buf[sizeof |
4298 | size - sizeof (struct EncryptedMessage), | 4161 | (struct EncryptedMessage)], |
4299 | GNUNET_YES, GNUNET_NO)) | 4162 | size - |
4163 | sizeof (struct EncryptedMessage), | ||
4164 | GNUNET_YES, GNUNET_NO)) | ||
4300 | GNUNET_break_op (0); | 4165 | GNUNET_break_op (0); |
4301 | } | 4166 | } |
4302 | 4167 | ||
@@ -4314,8 +4179,8 @@ static void | |||
4314 | handle_transport_receive (void *cls, | 4179 | handle_transport_receive (void *cls, |
4315 | const struct GNUNET_PeerIdentity *peer, | 4180 | const struct GNUNET_PeerIdentity *peer, |
4316 | const struct GNUNET_MessageHeader *message, | 4181 | const struct GNUNET_MessageHeader *message, |
4317 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 4182 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
4318 | uint32_t ats_count) | 4183 | uint32_t ats_count) |
4319 | { | 4184 | { |
4320 | struct Neighbour *n; | 4185 | struct Neighbour *n; |
4321 | struct GNUNET_TIME_Absolute now; | 4186 | struct GNUNET_TIME_Absolute now; |
@@ -4327,134 +4192,130 @@ handle_transport_receive (void *cls, | |||
4327 | #if DEBUG_CORE > 1 | 4192 | #if DEBUG_CORE > 1 |
4328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4329 | "Received message of type %u from `%4s', demultiplexing.\n", | 4194 | "Received message of type %u from `%4s', demultiplexing.\n", |
4330 | (unsigned int) ntohs (message->type), | 4195 | (unsigned int) ntohs (message->type), GNUNET_i2s (peer)); |
4331 | GNUNET_i2s (peer)); | ||
4332 | #endif | 4196 | #endif |
4333 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 4197 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
4334 | { | 4198 | { |
4335 | GNUNET_break (0); | 4199 | GNUNET_break (0); |
4336 | return; | 4200 | return; |
4337 | } | 4201 | } |
4338 | n = find_neighbour (peer); | 4202 | n = find_neighbour (peer); |
4339 | if ( (n == NULL) || (GNUNET_NO == n->is_connected) ) | 4203 | if ((n == NULL) || (GNUNET_NO == n->is_connected)) |
4340 | { | 4204 | { |
4341 | /* received message from peer that is not connected!? */ | 4205 | /* received message from peer that is not connected!? */ |
4342 | GNUNET_break (0); | 4206 | GNUNET_break (0); |
4343 | return; | 4207 | return; |
4344 | } | 4208 | } |
4345 | changed = GNUNET_NO; | 4209 | changed = GNUNET_NO; |
4346 | up = (n->status == PEER_STATE_KEY_CONFIRMED); | 4210 | up = (n->status == PEER_STATE_KEY_CONFIRMED); |
4347 | type = ntohs (message->type); | 4211 | type = ntohs (message->type); |
4348 | size = ntohs (message->size); | 4212 | size = ntohs (message->size); |
4349 | switch (type) | 4213 | switch (type) |
4214 | { | ||
4215 | case GNUNET_MESSAGE_TYPE_CORE_SET_KEY: | ||
4216 | if (size != sizeof (struct SetKeyMessage)) | ||
4217 | { | ||
4218 | GNUNET_break_op (0); | ||
4219 | return; | ||
4220 | } | ||
4221 | GNUNET_STATISTICS_update (stats, | ||
4222 | gettext_noop ("# session keys received"), | ||
4223 | 1, GNUNET_NO); | ||
4224 | handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count); | ||
4225 | break; | ||
4226 | case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: | ||
4227 | if (size < sizeof (struct EncryptedMessage) + | ||
4228 | sizeof (struct GNUNET_MessageHeader)) | ||
4229 | { | ||
4230 | GNUNET_break_op (0); | ||
4231 | return; | ||
4232 | } | ||
4233 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | ||
4234 | (n->status != PEER_STATE_KEY_CONFIRMED)) | ||
4350 | { | 4235 | { |
4351 | case GNUNET_MESSAGE_TYPE_CORE_SET_KEY: | ||
4352 | if (size != sizeof (struct SetKeyMessage)) | ||
4353 | { | ||
4354 | GNUNET_break_op (0); | ||
4355 | return; | ||
4356 | } | ||
4357 | GNUNET_STATISTICS_update (stats, | 4236 | GNUNET_STATISTICS_update (stats, |
4358 | gettext_noop ("# session keys received"), | 4237 | gettext_noop |
4359 | 1, | 4238 | ("# failed to decrypt message (no session key)"), |
4360 | GNUNET_NO); | 4239 | 1, GNUNET_NO); |
4361 | handle_set_key (n, | 4240 | send_key (n); |
4362 | (const struct SetKeyMessage *) message, | 4241 | return; |
4363 | ats, ats_count); | 4242 | } |
4364 | break; | 4243 | handle_encrypted_message (n, |
4365 | case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: | 4244 | (const struct EncryptedMessage *) message, |
4366 | if (size < sizeof (struct EncryptedMessage) + | 4245 | ats, ats_count); |
4367 | sizeof (struct GNUNET_MessageHeader)) | 4246 | break; |
4368 | { | 4247 | case GNUNET_MESSAGE_TYPE_CORE_PING: |
4369 | GNUNET_break_op (0); | 4248 | if (size != sizeof (struct PingMessage)) |
4370 | return; | 4249 | { |
4371 | } | 4250 | GNUNET_break_op (0); |
4372 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | 4251 | return; |
4373 | (n->status != PEER_STATE_KEY_CONFIRMED)) | 4252 | } |
4374 | { | 4253 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages received"), |
4375 | GNUNET_STATISTICS_update (stats, | 4254 | 1, GNUNET_NO); |
4376 | gettext_noop ("# failed to decrypt message (no session key)"), | 4255 | if ((n->status != PEER_STATE_KEY_RECEIVED) && |
4377 | 1, | 4256 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
4378 | GNUNET_NO); | 4257 | { |
4379 | send_key (n); | ||
4380 | return; | ||
4381 | } | ||
4382 | handle_encrypted_message (n, | ||
4383 | (const struct EncryptedMessage *) message, | ||
4384 | ats, ats_count); | ||
4385 | break; | ||
4386 | case GNUNET_MESSAGE_TYPE_CORE_PING: | ||
4387 | if (size != sizeof (struct PingMessage)) | ||
4388 | { | ||
4389 | GNUNET_break_op (0); | ||
4390 | return; | ||
4391 | } | ||
4392 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages received"), 1, GNUNET_NO); | ||
4393 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | ||
4394 | (n->status != PEER_STATE_KEY_CONFIRMED)) | ||
4395 | { | ||
4396 | #if DEBUG_CORE > 1 | 4258 | #if DEBUG_CORE > 1 |
4397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4398 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", | 4260 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", |
4399 | "PING", GNUNET_i2s (&n->peer)); | 4261 | "PING", GNUNET_i2s (&n->peer)); |
4400 | #endif | 4262 | #endif |
4401 | GNUNET_free_non_null (n->pending_ping); | 4263 | GNUNET_free_non_null (n->pending_ping); |
4402 | n->pending_ping = GNUNET_malloc (sizeof (struct PingMessage)); | 4264 | n->pending_ping = GNUNET_malloc (sizeof (struct PingMessage)); |
4403 | memcpy (n->pending_ping, message, sizeof (struct PingMessage)); | 4265 | memcpy (n->pending_ping, message, sizeof (struct PingMessage)); |
4404 | return; | 4266 | return; |
4405 | } | 4267 | } |
4406 | handle_ping (n, (const struct PingMessage *) message, | 4268 | handle_ping (n, (const struct PingMessage *) message, ats, ats_count); |
4407 | ats, ats_count); | 4269 | break; |
4408 | break; | 4270 | case GNUNET_MESSAGE_TYPE_CORE_PONG: |
4409 | case GNUNET_MESSAGE_TYPE_CORE_PONG: | 4271 | if (size != sizeof (struct PongMessage)) |
4410 | if (size != sizeof (struct PongMessage)) | 4272 | { |
4411 | { | 4273 | GNUNET_break_op (0); |
4412 | GNUNET_break_op (0); | 4274 | return; |
4413 | return; | 4275 | } |
4414 | } | 4276 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages received"), |
4415 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages received"), 1, GNUNET_NO); | 4277 | 1, GNUNET_NO); |
4416 | if ( (n->status != PEER_STATE_KEY_RECEIVED) && | 4278 | if ((n->status != PEER_STATE_KEY_RECEIVED) && |
4417 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | 4279 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
4418 | { | 4280 | { |
4419 | #if DEBUG_CORE > 1 | 4281 | #if DEBUG_CORE > 1 |
4420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4421 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", | 4283 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", |
4422 | "PONG", GNUNET_i2s (&n->peer)); | 4284 | "PONG", GNUNET_i2s (&n->peer)); |
4423 | #endif | 4285 | #endif |
4424 | GNUNET_free_non_null (n->pending_pong); | 4286 | GNUNET_free_non_null (n->pending_pong); |
4425 | n->pending_pong = GNUNET_malloc (sizeof (struct PongMessage)); | 4287 | n->pending_pong = GNUNET_malloc (sizeof (struct PongMessage)); |
4426 | memcpy (n->pending_pong, message, sizeof (struct PongMessage)); | 4288 | memcpy (n->pending_pong, message, sizeof (struct PongMessage)); |
4427 | return; | ||
4428 | } | ||
4429 | handle_pong (n, (const struct PongMessage *) message, | ||
4430 | ats, ats_count); | ||
4431 | break; | ||
4432 | default: | ||
4433 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
4434 | _("Unsupported message of type %u received.\n"), | ||
4435 | (unsigned int) type); | ||
4436 | return; | 4289 | return; |
4437 | } | 4290 | } |
4291 | handle_pong (n, (const struct PongMessage *) message, ats, ats_count); | ||
4292 | break; | ||
4293 | default: | ||
4294 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
4295 | _("Unsupported message of type %u received.\n"), | ||
4296 | (unsigned int) type); | ||
4297 | return; | ||
4298 | } | ||
4438 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 4299 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
4300 | { | ||
4301 | now = GNUNET_TIME_absolute_get (); | ||
4302 | n->last_activity = now; | ||
4303 | changed = GNUNET_YES; | ||
4304 | if (!up) | ||
4439 | { | 4305 | { |
4440 | now = GNUNET_TIME_absolute_get (); | 4306 | GNUNET_STATISTICS_update (stats, |
4441 | n->last_activity = now; | 4307 | gettext_noop ("# established sessions"), |
4442 | changed = GNUNET_YES; | 4308 | 1, GNUNET_NO); |
4443 | if (!up) | 4309 | n->time_established = now; |
4444 | { | ||
4445 | GNUNET_STATISTICS_update (stats, | ||
4446 | gettext_noop ("# established sessions"), | ||
4447 | 1, | ||
4448 | GNUNET_NO); | ||
4449 | n->time_established = now; | ||
4450 | } | ||
4451 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
4452 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
4453 | n->keep_alive_task | ||
4454 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), | ||
4455 | &send_keep_alive, | ||
4456 | n); | ||
4457 | } | 4310 | } |
4311 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
4312 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
4313 | n->keep_alive_task | ||
4314 | = | ||
4315 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
4316 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
4317 | 2), &send_keep_alive, n); | ||
4318 | } | ||
4458 | if (changed) | 4319 | if (changed) |
4459 | handle_peer_status_change (n); | 4320 | handle_peer_status_change (n); |
4460 | } | 4321 | } |
@@ -4469,7 +4330,7 @@ handle_transport_receive (void *cls, | |||
4469 | */ | 4330 | */ |
4470 | static void | 4331 | static void |
4471 | neighbour_quota_update (void *cls, | 4332 | neighbour_quota_update (void *cls, |
4472 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 4333 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
4473 | { | 4334 | { |
4474 | struct Neighbour *n = cls; | 4335 | struct Neighbour *n = cls; |
4475 | struct GNUNET_BANDWIDTH_Value32NBO q_in; | 4336 | struct GNUNET_BANDWIDTH_Value32NBO q_in; |
@@ -4484,27 +4345,28 @@ neighbour_quota_update (void *cls, | |||
4484 | 4345 | ||
4485 | #if DEBUG_CORE > 1 | 4346 | #if DEBUG_CORE > 1 |
4486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4487 | "Neighbour quota update calculation running for peer `%4s'\n", | 4348 | "Neighbour quota update calculation running for peer `%4s'\n", |
4488 | GNUNET_i2s (&n->peer)); | 4349 | GNUNET_i2s (&n->peer)); |
4489 | #endif | 4350 | #endif |
4490 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; | 4351 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; |
4491 | /* calculate relative preference among all neighbours; | 4352 | /* calculate relative preference among all neighbours; |
4492 | divides by a bit more to avoid division by zero AND to | 4353 | * divides by a bit more to avoid division by zero AND to |
4493 | account for possibility of new neighbours joining any time | 4354 | * account for possibility of new neighbours joining any time |
4494 | AND to convert to double... */ | 4355 | * AND to convert to double... */ |
4495 | neighbour_count = GNUNET_CONTAINER_multihashmap_size (neighbours); | 4356 | neighbour_count = GNUNET_CONTAINER_multihashmap_size (neighbours); |
4496 | if (neighbour_count == 0) | 4357 | if (neighbour_count == 0) |
4497 | return; | 4358 | return; |
4498 | if (preference_sum == 0) | 4359 | if (preference_sum == 0) |
4499 | { | 4360 | { |
4500 | pref_rel = 1.0 / (double) neighbour_count; | 4361 | pref_rel = 1.0 / (double) neighbour_count; |
4501 | } | 4362 | } |
4502 | else | 4363 | else |
4503 | { | 4364 | { |
4504 | pref_rel = (double) n->current_preference / preference_sum; | 4365 | pref_rel = (double) n->current_preference / preference_sum; |
4505 | } | 4366 | } |
4506 | need_per_peer = GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER, | 4367 | need_per_peer = |
4507 | GNUNET_TIME_UNIT_SECONDS); | 4368 | GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER, |
4369 | GNUNET_TIME_UNIT_SECONDS); | ||
4508 | need_per_second = need_per_peer * neighbour_count; | 4370 | need_per_second = need_per_peer * neighbour_count; |
4509 | 4371 | ||
4510 | /* calculate inbound bandwidth per peer */ | 4372 | /* calculate inbound bandwidth per peer */ |
@@ -4528,43 +4390,45 @@ neighbour_quota_update (void *cls, | |||
4528 | q_out = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); | 4390 | q_out = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); |
4529 | n->bw_out_internal_limit = q_out; | 4391 | n->bw_out_internal_limit = q_out; |
4530 | 4392 | ||
4531 | q_out_min = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, n->bw_out_internal_limit); | 4393 | q_out_min = |
4394 | GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, | ||
4395 | n->bw_out_internal_limit); | ||
4532 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, n->bw_out); | 4396 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, n->bw_out); |
4533 | 4397 | ||
4534 | /* check if we want to disconnect for good due to inactivity */ | 4398 | /* check if we want to disconnect for good due to inactivity */ |
4535 | if ( (GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value > 0) && | 4399 | if ((GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value > |
4536 | (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value > GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) ) | 4400 | 0) && |
4537 | { | 4401 | (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value > |
4402 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value)) | ||
4403 | { | ||
4538 | #if DEBUG_CORE | 4404 | #if DEBUG_CORE |
4539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4540 | "Forcing disconnect of `%4s' due to inactivity\n", | 4406 | "Forcing disconnect of `%4s' due to inactivity\n", |
4541 | GNUNET_i2s (&n->peer)); | 4407 | GNUNET_i2s (&n->peer)); |
4542 | #endif | 4408 | #endif |
4543 | q_in = GNUNET_BANDWIDTH_value_init (0); /* force disconnect */ | 4409 | q_in = GNUNET_BANDWIDTH_value_init (0); /* force disconnect */ |
4544 | } | 4410 | } |
4545 | #if DEBUG_CORE_QUOTA | 4411 | #if DEBUG_CORE_QUOTA |
4546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4547 | "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n", | 4413 | "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n", |
4548 | GNUNET_i2s (&n->peer), | 4414 | GNUNET_i2s (&n->peer), |
4549 | (unsigned int) ntohl (q_in.value__), | 4415 | (unsigned int) ntohl (q_in.value__), |
4550 | bandwidth_target_out_bps, | 4416 | bandwidth_target_out_bps, |
4551 | (unsigned int) ntohl (n->bw_in.value__), | 4417 | (unsigned int) ntohl (n->bw_in.value__), |
4552 | (unsigned int) ntohl (n->bw_out.value__), | 4418 | (unsigned int) ntohl (n->bw_out.value__), |
4553 | (unsigned int) ntohl (n->bw_out_internal_limit.value__)); | 4419 | (unsigned int) ntohl (n->bw_out_internal_limit.value__)); |
4554 | #endif | 4420 | #endif |
4555 | if ((n->bw_in.value__ != q_in.value__) || (n->bw_out.value__ != q_out_min.value__)) | 4421 | if ((n->bw_in.value__ != q_in.value__) || |
4556 | { | 4422 | (n->bw_out.value__ != q_out_min.value__)) |
4557 | if (n->bw_in.value__ != q_in.value__) | 4423 | { |
4558 | n->bw_in = q_in; | 4424 | if (n->bw_in.value__ != q_in.value__) |
4559 | if (n->bw_out.value__ != q_out_min.value__) | 4425 | n->bw_in = q_in; |
4560 | n->bw_out = q_out_min; | 4426 | if (n->bw_out.value__ != q_out_min.value__) |
4561 | if (GNUNET_YES == n->is_connected) | 4427 | n->bw_out = q_out_min; |
4562 | GNUNET_TRANSPORT_set_quota (transport, | 4428 | if (GNUNET_YES == n->is_connected) |
4563 | &n->peer, | 4429 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
4564 | n->bw_in, | 4430 | handle_peer_status_change (n); |
4565 | n->bw_out); | 4431 | } |
4566 | handle_peer_status_change (n); | ||
4567 | } | ||
4568 | schedule_quota_update (n); | 4432 | schedule_quota_update (n); |
4569 | } | 4433 | } |
4570 | 4434 | ||
@@ -4581,52 +4445,45 @@ neighbour_quota_update (void *cls, | |||
4581 | static void | 4445 | static void |
4582 | handle_transport_notify_connect (void *cls, | 4446 | handle_transport_notify_connect (void *cls, |
4583 | const struct GNUNET_PeerIdentity *peer, | 4447 | const struct GNUNET_PeerIdentity *peer, |
4584 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 4448 | const struct GNUNET_TRANSPORT_ATS_Information |
4585 | uint32_t ats_count) | 4449 | *ats, uint32_t ats_count) |
4586 | { | 4450 | { |
4587 | struct Neighbour *n; | 4451 | struct Neighbour *n; |
4588 | 4452 | ||
4589 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 4453 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
4590 | { | 4454 | { |
4591 | GNUNET_break (0); | 4455 | GNUNET_break (0); |
4592 | return; | 4456 | return; |
4593 | } | 4457 | } |
4594 | n = find_neighbour (peer); | 4458 | n = find_neighbour (peer); |
4595 | if (n != NULL) | 4459 | if (n != NULL) |
4460 | { | ||
4461 | if (GNUNET_YES == n->is_connected) | ||
4596 | { | 4462 | { |
4597 | if (GNUNET_YES == n->is_connected) | 4463 | /* duplicate connect notification!? */ |
4598 | { | 4464 | GNUNET_break (0); |
4599 | /* duplicate connect notification!? */ | 4465 | return; |
4600 | GNUNET_break (0); | ||
4601 | return; | ||
4602 | } | ||
4603 | } | 4466 | } |
4467 | } | ||
4604 | else | 4468 | else |
4605 | { | 4469 | { |
4606 | n = create_neighbour (peer); | 4470 | n = create_neighbour (peer); |
4607 | } | 4471 | } |
4608 | GNUNET_STATISTICS_update (stats, | 4472 | GNUNET_STATISTICS_update (stats, |
4609 | gettext_noop ("# peers connected (transport)"), | 4473 | gettext_noop ("# peers connected (transport)"), |
4610 | 1, | 4474 | 1, GNUNET_NO); |
4611 | GNUNET_NO); | 4475 | n->is_connected = GNUNET_YES; |
4612 | n->is_connected = GNUNET_YES; | ||
4613 | update_neighbour_performance (n, ats, ats_count); | 4476 | update_neighbour_performance (n, ats, ats_count); |
4614 | GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, | 4477 | GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, |
4615 | n->bw_out, | 4478 | n->bw_out, MAX_WINDOW_TIME_S); |
4616 | MAX_WINDOW_TIME_S); | ||
4617 | GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, | 4479 | GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, |
4618 | n->bw_in, | 4480 | n->bw_in, MAX_WINDOW_TIME_S); |
4619 | MAX_WINDOW_TIME_S); | ||
4620 | #if DEBUG_CORE | 4481 | #if DEBUG_CORE |
4621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4622 | "Received connection from `%4s'.\n", | 4483 | "Received connection from `%4s'.\n", GNUNET_i2s (&n->peer)); |
4623 | GNUNET_i2s (&n->peer)); | ||
4624 | #endif | 4484 | #endif |
4625 | GNUNET_TRANSPORT_set_quota (transport, | 4485 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
4626 | &n->peer, | 4486 | send_key (n); |
4627 | n->bw_in, | ||
4628 | n->bw_out); | ||
4629 | send_key (n); | ||
4630 | } | 4487 | } |
4631 | 4488 | ||
4632 | 4489 | ||
@@ -4648,67 +4505,65 @@ handle_transport_notify_disconnect (void *cls, | |||
4648 | 4505 | ||
4649 | #if DEBUG_CORE | 4506 | #if DEBUG_CORE |
4650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4651 | "Peer `%4s' disconnected from us; received notification from transport.\n", | 4508 | "Peer `%4s' disconnected from us; received notification from transport.\n", |
4652 | GNUNET_i2s (peer)); | 4509 | GNUNET_i2s (peer)); |
4653 | #endif | 4510 | #endif |
4654 | n = find_neighbour (peer); | 4511 | n = find_neighbour (peer); |
4655 | if (n == NULL) | 4512 | if (n == NULL) |
4656 | { | 4513 | { |
4657 | GNUNET_break (0); | 4514 | GNUNET_break (0); |
4658 | return; | 4515 | return; |
4659 | } | 4516 | } |
4660 | GNUNET_break (n->is_connected == GNUNET_YES); | 4517 | GNUNET_break (n->is_connected == GNUNET_YES); |
4661 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 4518 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
4662 | { | 4519 | { |
4663 | cnm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); | 4520 | cnm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); |
4664 | cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); | 4521 | cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); |
4665 | cnm.reserved = htonl (0); | 4522 | cnm.reserved = htonl (0); |
4666 | cnm.peer = *peer; | 4523 | cnm.peer = *peer; |
4667 | send_to_all_clients (&cnm.header, GNUNET_NO, GNUNET_CORE_OPTION_SEND_DISCONNECT); | 4524 | send_to_all_clients (&cnm.header, GNUNET_NO, |
4668 | GNUNET_STATISTICS_update (stats, | 4525 | GNUNET_CORE_OPTION_SEND_DISCONNECT); |
4669 | gettext_noop ("# established sessions"), | 4526 | GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"), |
4670 | -1, | 4527 | -1, GNUNET_NO); |
4671 | GNUNET_NO); | 4528 | } |
4672 | } | ||
4673 | 4529 | ||
4674 | /* On transport disconnect transport doesn't cancel requests, so must do so here. */ | 4530 | /* On transport disconnect transport doesn't cancel requests, so must do so here. */ |
4675 | if (n->th != NULL) | 4531 | if (n->th != NULL) |
4676 | { | 4532 | { |
4677 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); | 4533 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); |
4678 | n->th = NULL; | 4534 | n->th = NULL; |
4679 | } | 4535 | } |
4680 | if (GNUNET_SCHEDULER_NO_TASK != n->keep_alive_task) | 4536 | if (GNUNET_SCHEDULER_NO_TASK != n->keep_alive_task) |
4681 | { | 4537 | { |
4682 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | 4538 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); |
4683 | n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; | 4539 | n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; |
4684 | } | 4540 | } |
4685 | n->is_connected = GNUNET_NO; | 4541 | n->is_connected = GNUNET_NO; |
4686 | n->status = PEER_STATE_DOWN; | 4542 | n->status = PEER_STATE_DOWN; |
4687 | while (NULL != (car = n->active_client_request_head)) | 4543 | while (NULL != (car = n->active_client_request_head)) |
4688 | { | 4544 | { |
4689 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 4545 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
4690 | n->active_client_request_tail, | 4546 | n->active_client_request_tail, car); |
4691 | car); | 4547 | GNUNET_assert (GNUNET_YES == |
4692 | GNUNET_assert (GNUNET_YES == | 4548 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, |
4693 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, | 4549 | &n->peer.hashPubKey, |
4694 | &n->peer.hashPubKey, | 4550 | car)); |
4695 | car)); | 4551 | GNUNET_free (car); |
4696 | GNUNET_free (car); | 4552 | } |
4697 | } | ||
4698 | 4553 | ||
4699 | GNUNET_STATISTICS_update (stats, | 4554 | GNUNET_STATISTICS_update (stats, |
4700 | gettext_noop ("# peers connected (transport)"), | 4555 | gettext_noop ("# peers connected (transport)"), |
4701 | -1, | 4556 | -1, GNUNET_NO); |
4702 | GNUNET_NO); | ||
4703 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) | 4557 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) |
4704 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); | 4558 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); |
4705 | left = GNUNET_TIME_relative_subtract (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 4559 | left = |
4706 | GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT); | 4560 | GNUNET_TIME_relative_subtract (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
4707 | n->last_activity = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), | 4561 | GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT); |
4708 | left); | 4562 | n->last_activity = |
4709 | n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT, | 4563 | GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), left); |
4710 | &consider_free_task, | 4564 | n->dead_clean_task = |
4711 | n); | 4565 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT, |
4566 | &consider_free_task, n); | ||
4712 | } | 4567 | } |
4713 | 4568 | ||
4714 | 4569 | ||
@@ -4716,9 +4571,7 @@ handle_transport_notify_disconnect (void *cls, | |||
4716 | * Wrapper around 'free_neighbour'; helper for 'cleaning_task'. | 4571 | * Wrapper around 'free_neighbour'; helper for 'cleaning_task'. |
4717 | */ | 4572 | */ |
4718 | static int | 4573 | static int |
4719 | free_neighbour_helper (void *cls, | 4574 | free_neighbour_helper (void *cls, const GNUNET_HashCode * key, void *value) |
4720 | const GNUNET_HashCode *key, | ||
4721 | void *value) | ||
4722 | { | 4575 | { |
4723 | struct Neighbour *n = value; | 4576 | struct Neighbour *n = value; |
4724 | 4577 | ||
@@ -4737,18 +4590,17 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4737 | struct Client *c; | 4590 | struct Client *c; |
4738 | 4591 | ||
4739 | #if DEBUG_CORE | 4592 | #if DEBUG_CORE |
4740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); |
4741 | "Core service shutting down.\n"); | ||
4742 | #endif | 4594 | #endif |
4743 | GNUNET_assert (transport != NULL); | 4595 | GNUNET_assert (transport != NULL); |
4744 | GNUNET_TRANSPORT_disconnect (transport); | 4596 | GNUNET_TRANSPORT_disconnect (transport); |
4745 | transport = NULL; | 4597 | transport = NULL; |
4746 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 4598 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
4747 | &free_neighbour_helper, | 4599 | &free_neighbour_helper, NULL); |
4748 | NULL); | ||
4749 | GNUNET_CONTAINER_multihashmap_destroy (neighbours); | 4600 | GNUNET_CONTAINER_multihashmap_destroy (neighbours); |
4750 | neighbours = NULL; | 4601 | neighbours = NULL; |
4751 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), 0, GNUNET_NO); | 4602 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), |
4603 | 0, GNUNET_NO); | ||
4752 | GNUNET_SERVER_notification_context_destroy (notifier); | 4604 | GNUNET_SERVER_notification_context_destroy (notifier); |
4753 | notifier = NULL; | 4605 | notifier = NULL; |
4754 | while (NULL != (c = clients)) | 4606 | while (NULL != (c = clients)) |
@@ -4784,7 +4636,8 @@ run (void *cls, | |||
4784 | sizeof (struct GNUNET_MessageHeader)}, | 4636 | sizeof (struct GNUNET_MessageHeader)}, |
4785 | {&handle_client_have_peer, NULL, | 4637 | {&handle_client_have_peer, NULL, |
4786 | GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED, | 4638 | GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED, |
4787 | sizeof (struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity)}, | 4639 | sizeof (struct GNUNET_MessageHeader) + |
4640 | sizeof (struct GNUNET_PeerIdentity)}, | ||
4788 | {&handle_client_request_info, NULL, | 4641 | {&handle_client_request_info, NULL, |
4789 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO, | 4642 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO, |
4790 | sizeof (struct RequestInfoMessage)}, | 4643 | sizeof (struct RequestInfoMessage)}, |
@@ -4800,49 +4653,48 @@ run (void *cls, | |||
4800 | }; | 4653 | }; |
4801 | char *keyfile; | 4654 | char *keyfile; |
4802 | 4655 | ||
4803 | cfg = c; | 4656 | cfg = c; |
4804 | /* parse configuration */ | 4657 | /* parse configuration */ |
4805 | if ( | 4658 | if ((GNUNET_OK != |
4806 | (GNUNET_OK != | 4659 | GNUNET_CONFIGURATION_get_value_number (c, |
4807 | GNUNET_CONFIGURATION_get_value_number (c, | 4660 | "CORE", |
4808 | "CORE", | 4661 | "TOTAL_QUOTA_IN", |
4809 | "TOTAL_QUOTA_IN", | 4662 | &bandwidth_target_in_bps)) || |
4810 | &bandwidth_target_in_bps)) || | 4663 | (GNUNET_OK != |
4811 | (GNUNET_OK != | 4664 | GNUNET_CONFIGURATION_get_value_number (c, |
4812 | GNUNET_CONFIGURATION_get_value_number (c, | 4665 | "CORE", |
4813 | "CORE", | 4666 | "TOTAL_QUOTA_OUT", |
4814 | "TOTAL_QUOTA_OUT", | 4667 | &bandwidth_target_out_bps)) || |
4815 | &bandwidth_target_out_bps)) || | 4668 | (GNUNET_OK != |
4816 | (GNUNET_OK != | 4669 | GNUNET_CONFIGURATION_get_value_filename (c, |
4817 | GNUNET_CONFIGURATION_get_value_filename (c, | 4670 | "GNUNETD", |
4818 | "GNUNETD", | 4671 | "HOSTKEY", &keyfile))) |
4819 | "HOSTKEY", &keyfile))) | 4672 | { |
4820 | { | 4673 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4821 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4674 | _ |
4822 | _ | 4675 | ("Core service is lacking key configuration settings. Exiting.\n")); |
4823 | ("Core service is lacking key configuration settings. Exiting.\n")); | 4676 | GNUNET_SCHEDULER_shutdown (); |
4824 | GNUNET_SCHEDULER_shutdown (); | 4677 | return; |
4825 | return; | 4678 | } |
4826 | } | ||
4827 | peerinfo = GNUNET_PEERINFO_connect (cfg); | 4679 | peerinfo = GNUNET_PEERINFO_connect (cfg); |
4828 | if (NULL == peerinfo) | 4680 | if (NULL == peerinfo) |
4829 | { | 4681 | { |
4830 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4831 | _("Could not access PEERINFO service. Exiting.\n")); | 4683 | _("Could not access PEERINFO service. Exiting.\n")); |
4832 | GNUNET_SCHEDULER_shutdown (); | 4684 | GNUNET_SCHEDULER_shutdown (); |
4833 | GNUNET_free (keyfile); | 4685 | GNUNET_free (keyfile); |
4834 | return; | 4686 | return; |
4835 | } | 4687 | } |
4836 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 4688 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
4837 | GNUNET_free (keyfile); | 4689 | GNUNET_free (keyfile); |
4838 | if (my_private_key == NULL) | 4690 | if (my_private_key == NULL) |
4839 | { | 4691 | { |
4840 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4692 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4841 | _("Core service could not access hostkey. Exiting.\n")); | 4693 | _("Core service could not access hostkey. Exiting.\n")); |
4842 | GNUNET_PEERINFO_disconnect (peerinfo); | 4694 | GNUNET_PEERINFO_disconnect (peerinfo); |
4843 | GNUNET_SCHEDULER_shutdown (); | 4695 | GNUNET_SCHEDULER_shutdown (); |
4844 | return; | 4696 | return; |
4845 | } | 4697 | } |
4846 | neighbours = GNUNET_CONTAINER_multihashmap_create (128); | 4698 | neighbours = GNUNET_CONTAINER_multihashmap_create (128); |
4847 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | 4699 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
4848 | GNUNET_CRYPTO_hash (&my_public_key, | 4700 | GNUNET_CRYPTO_hash (&my_public_key, |
@@ -4853,12 +4705,12 @@ run (void *cls, | |||
4853 | self.status = PEER_STATE_KEY_CONFIRMED; | 4705 | self.status = PEER_STATE_KEY_CONFIRMED; |
4854 | self.is_connected = GNUNET_YES; | 4706 | self.is_connected = GNUNET_YES; |
4855 | /* setup notification */ | 4707 | /* setup notification */ |
4856 | notifier = GNUNET_SERVER_notification_context_create (server, | 4708 | notifier = GNUNET_SERVER_notification_context_create (server, |
4857 | MAX_NOTIFY_QUEUE); | 4709 | MAX_NOTIFY_QUEUE); |
4858 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 4710 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
4859 | /* setup transport connection */ | 4711 | /* setup transport connection */ |
4860 | transport = GNUNET_TRANSPORT_connect (cfg, | 4712 | transport = GNUNET_TRANSPORT_connect (cfg, |
4861 | &my_identity, | 4713 | &my_identity, |
4862 | NULL, | 4714 | NULL, |
4863 | &handle_transport_receive, | 4715 | &handle_transport_receive, |
4864 | &handle_transport_notify_connect, | 4716 | &handle_transport_notify_connect, |
@@ -4866,15 +4718,15 @@ run (void *cls, | |||
4866 | GNUNET_assert (NULL != transport); | 4718 | GNUNET_assert (NULL != transport); |
4867 | stats = GNUNET_STATISTICS_create ("core", cfg); | 4719 | stats = GNUNET_STATISTICS_create ("core", cfg); |
4868 | 4720 | ||
4869 | GNUNET_STATISTICS_set (stats, | 4721 | GNUNET_STATISTICS_set (stats, |
4870 | gettext_noop ("# discarded CORE_SEND requests"), | 4722 | gettext_noop ("# discarded CORE_SEND requests"), |
4871 | 0, GNUNET_NO); | 4723 | 0, GNUNET_NO); |
4872 | GNUNET_STATISTICS_set (stats, | 4724 | GNUNET_STATISTICS_set (stats, |
4873 | gettext_noop ("# discarded lower priority CORE_SEND requests"), | 4725 | gettext_noop |
4874 | 0, GNUNET_NO); | 4726 | ("# discarded lower priority CORE_SEND requests"), 0, |
4727 | GNUNET_NO); | ||
4875 | 4728 | ||
4876 | mst = GNUNET_SERVER_mst_create (&deliver_message, | 4729 | mst = GNUNET_SERVER_mst_create (&deliver_message, NULL); |
4877 | NULL); | ||
4878 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 4730 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
4879 | &cleaning_task, NULL); | 4731 | &cleaning_task, NULL); |
4880 | /* process client requests */ | 4732 | /* process client requests */ |
@@ -4899,8 +4751,7 @@ main (int argc, char *const *argv) | |||
4899 | GNUNET_SERVICE_run (argc, | 4751 | GNUNET_SERVICE_run (argc, |
4900 | argv, | 4752 | argv, |
4901 | "core", | 4753 | "core", |
4902 | GNUNET_SERVICE_OPTION_NONE, | 4754 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
4903 | &run, NULL)) ? 0 : 1; | ||
4904 | } | 4755 | } |
4905 | 4756 | ||
4906 | /* end of gnunet-service-core.c */ | 4757 | /* end of gnunet-service-core.c */ |
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index d45560a5d..b5e93a8a2 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c | |||
@@ -44,7 +44,7 @@ struct PeerContext | |||
44 | { | 44 | { |
45 | struct GNUNET_CONFIGURATION_Handle *cfg; | 45 | struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | struct GNUNET_CORE_Handle *ch; | 46 | struct GNUNET_CORE_Handle *ch; |
47 | struct GNUNET_PeerIdentity id; | 47 | struct GNUNET_PeerIdentity id; |
48 | struct GNUNET_TRANSPORT_Handle *th; | 48 | struct GNUNET_TRANSPORT_Handle *th; |
49 | struct GNUNET_MessageHeader *hello; | 49 | struct GNUNET_MessageHeader *hello; |
50 | int connect_status; | 50 | int connect_status; |
@@ -71,14 +71,12 @@ static int ok; | |||
71 | 71 | ||
72 | 72 | ||
73 | static void | 73 | static void |
74 | process_hello (void *cls, | 74 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
75 | const struct GNUNET_MessageHeader *message) | ||
76 | { | 75 | { |
77 | struct PeerContext *p = cls; | 76 | struct PeerContext *p = cls; |
78 | 77 | ||
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
80 | "Received (my) `%s' from transport service\n", | 79 | "Received (my) `%s' from transport service\n", "HELLO"); |
81 | "HELLO"); | ||
82 | GNUNET_assert (message != NULL); | 80 | GNUNET_assert (message != NULL); |
83 | if ((p == &p1) && (p2.th != NULL)) | 81 | if ((p == &p1) && (p2.th != NULL)) |
84 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | 82 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); |
@@ -105,31 +103,31 @@ static void | |||
105 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 103 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
106 | { | 104 | { |
107 | #if VERBOSE | 105 | #if VERBOSE |
108 | fprintf(stderr, "ENDING ANGRILY %u\n", ok); | 106 | fprintf (stderr, "ENDING ANGRILY %u\n", ok); |
109 | #endif | 107 | #endif |
110 | GNUNET_break (0); | 108 | GNUNET_break (0); |
111 | if (NULL != p1.ch) | 109 | if (NULL != p1.ch) |
112 | { | 110 | { |
113 | GNUNET_CORE_disconnect (p1.ch); | 111 | GNUNET_CORE_disconnect (p1.ch); |
114 | p1.ch = NULL; | 112 | p1.ch = NULL; |
115 | } | 113 | } |
116 | if (NULL != p2.ch) | 114 | if (NULL != p2.ch) |
117 | { | 115 | { |
118 | GNUNET_CORE_disconnect (p2.ch); | 116 | GNUNET_CORE_disconnect (p2.ch); |
119 | p2.ch = NULL; | 117 | p2.ch = NULL; |
120 | } | 118 | } |
121 | if (p1.th != NULL) | 119 | if (p1.th != NULL) |
122 | { | 120 | { |
123 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | 121 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); |
124 | GNUNET_TRANSPORT_disconnect (p1.th); | 122 | GNUNET_TRANSPORT_disconnect (p1.th); |
125 | p1.th = NULL; | 123 | p1.th = NULL; |
126 | } | 124 | } |
127 | if (p2.th != NULL) | 125 | if (p2.th != NULL) |
128 | { | 126 | { |
129 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | 127 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); |
130 | GNUNET_TRANSPORT_disconnect (p2.th); | 128 | GNUNET_TRANSPORT_disconnect (p2.th); |
131 | p2.th = NULL; | 129 | p2.th = NULL; |
132 | } | 130 | } |
133 | ok = 42; | 131 | ok = 42; |
134 | } | 132 | } |
135 | 133 | ||
@@ -154,54 +152,51 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
154 | static void | 152 | static void |
155 | connect_notify (void *cls, | 153 | connect_notify (void *cls, |
156 | const struct GNUNET_PeerIdentity *peer, | 154 | const struct GNUNET_PeerIdentity *peer, |
157 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 155 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
158 | { | 156 | { |
159 | struct PeerContext *pc = cls; | 157 | struct PeerContext *pc = cls; |
160 | 158 | ||
161 | if (0 == memcmp (&pc->id, | 159 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
162 | peer, | ||
163 | sizeof (struct GNUNET_PeerIdentity))) | ||
164 | return; | 160 | return; |
165 | GNUNET_assert (pc->connect_status == 0); | 161 | GNUNET_assert (pc->connect_status == 0); |
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
167 | "Encrypted connection established to peer `%4s'\n", | 163 | "Encrypted connection established to peer `%4s'\n", |
168 | GNUNET_i2s (peer)); | 164 | GNUNET_i2s (peer)); |
169 | if (GNUNET_SCHEDULER_NO_TASK != con_task) | 165 | if (GNUNET_SCHEDULER_NO_TASK != con_task) |
170 | { | 166 | { |
171 | GNUNET_SCHEDULER_cancel (con_task); | 167 | GNUNET_SCHEDULER_cancel (con_task); |
172 | con_task = GNUNET_SCHEDULER_NO_TASK; | 168 | con_task = GNUNET_SCHEDULER_NO_TASK; |
173 | } | 169 | } |
174 | pc->connect_status = 1; | 170 | pc->connect_status = 1; |
175 | if (pc == &p1) | 171 | if (pc == &p1) |
172 | { | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
174 | "Asking core (1) for transmission to peer `%4s'\n", | ||
175 | GNUNET_i2s (&p2.id)); | ||
176 | if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, | ||
177 | GNUNET_YES, | ||
178 | 0, | ||
179 | GNUNET_TIME_relative_multiply | ||
180 | (GNUNET_TIME_UNIT_SECONDS, | ||
181 | 45), &p2.id, | ||
182 | sizeof (struct | ||
183 | GNUNET_MessageHeader), | ||
184 | &transmit_ready, &p1)) | ||
176 | { | 185 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
178 | "Asking core (1) for transmission to peer `%4s'\n", | 187 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
179 | GNUNET_i2s (&p2.id)); | 188 | GNUNET_i2s (&p2.id)); |
180 | if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, | ||
181 | GNUNET_YES, | ||
182 | 0, | ||
183 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), | ||
184 | &p2.id, | ||
185 | sizeof (struct GNUNET_MessageHeader), | ||
186 | &transmit_ready, &p1)) | ||
187 | { | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
189 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | ||
190 | GNUNET_i2s (&p2.id)); | ||
191 | } | ||
192 | } | 189 | } |
190 | } | ||
193 | } | 191 | } |
194 | 192 | ||
195 | 193 | ||
196 | static void | 194 | static void |
197 | disconnect_notify (void *cls, | 195 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
198 | const struct GNUNET_PeerIdentity *peer) | ||
199 | { | 196 | { |
200 | struct PeerContext *pc = cls; | 197 | struct PeerContext *pc = cls; |
201 | 198 | ||
202 | if (0 == memcmp (&pc->id, | 199 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
203 | peer, | ||
204 | sizeof (struct GNUNET_PeerIdentity))) | ||
205 | return; | 200 | return; |
206 | pc->connect_status = 0; | 201 | pc->connect_status = 0; |
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -213,7 +208,7 @@ static int | |||
213 | inbound_notify (void *cls, | 208 | inbound_notify (void *cls, |
214 | const struct GNUNET_PeerIdentity *other, | 209 | const struct GNUNET_PeerIdentity *other, |
215 | const struct GNUNET_MessageHeader *message, | 210 | const struct GNUNET_MessageHeader *message, |
216 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 211 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
217 | { | 212 | { |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
219 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); | 214 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); |
@@ -225,7 +220,7 @@ static int | |||
225 | outbound_notify (void *cls, | 220 | outbound_notify (void *cls, |
226 | const struct GNUNET_PeerIdentity *other, | 221 | const struct GNUNET_PeerIdentity *other, |
227 | const struct GNUNET_MessageHeader *message, | 222 | const struct GNUNET_MessageHeader *message, |
228 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 223 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
229 | { | 224 | { |
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
231 | "Core notifies about outbound data for `%4s'.\n", | 226 | "Core notifies about outbound data for `%4s'.\n", |
@@ -239,7 +234,7 @@ static int | |||
239 | process_mtype (void *cls, | 234 | process_mtype (void *cls, |
240 | const struct GNUNET_PeerIdentity *peer, | 235 | const struct GNUNET_PeerIdentity *peer, |
241 | const struct GNUNET_MessageHeader *message, | 236 | const struct GNUNET_MessageHeader *message, |
242 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 237 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
243 | { | 238 | { |
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
245 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); | 240 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); |
@@ -258,23 +253,19 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
258 | 253 | ||
259 | 254 | ||
260 | static void | 255 | static void |
261 | connect_task (void *cls, | 256 | connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
262 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
263 | { | 257 | { |
264 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 258 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
265 | { | 259 | { |
266 | con_task = GNUNET_SCHEDULER_NO_TASK; | 260 | con_task = GNUNET_SCHEDULER_NO_TASK; |
267 | return; | 261 | return; |
268 | } | 262 | } |
269 | con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 263 | con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
270 | &connect_task, | 264 | &connect_task, NULL); |
271 | NULL); | ||
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Asking core (1) to connect to peer `%4s'\n", | 266 | "Asking core (1) to connect to peer `%4s'\n", |
274 | GNUNET_i2s (&p2.id)); | 267 | GNUNET_i2s (&p2.id)); |
275 | GNUNET_CORE_peer_request_connect (p1.ch, | 268 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
276 | &p2.id, | ||
277 | NULL, NULL); | ||
278 | } | 269 | } |
279 | 270 | ||
280 | static void | 271 | static void |
@@ -292,28 +283,27 @@ init_notify (void *cls, | |||
292 | p->id = *my_identity; | 283 | p->id = *my_identity; |
293 | p->ch = server; | 284 | p->ch = server; |
294 | if (cls == &p1) | 285 | if (cls == &p1) |
295 | { | 286 | { |
296 | GNUNET_assert (ok == 2); | 287 | GNUNET_assert (ok == 2); |
297 | OKPP; | 288 | OKPP; |
298 | /* connect p2 */ | 289 | /* connect p2 */ |
299 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, | 290 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, |
300 | &p2, | 291 | &p2, |
301 | &init_notify, | 292 | &init_notify, |
302 | &connect_notify, | 293 | &connect_notify, |
303 | &disconnect_notify, | 294 | &disconnect_notify, |
304 | NULL, | 295 | NULL, |
305 | &inbound_notify, | 296 | &inbound_notify, |
306 | GNUNET_YES, | 297 | GNUNET_YES, |
307 | &outbound_notify, GNUNET_YES, handlers); | 298 | &outbound_notify, GNUNET_YES, handlers); |
308 | } | 299 | } |
309 | else | 300 | else |
310 | { | 301 | { |
311 | GNUNET_assert (ok == 3); | 302 | GNUNET_assert (ok == 3); |
312 | OKPP; | 303 | OKPP; |
313 | GNUNET_assert (cls == &p2); | 304 | GNUNET_assert (cls == &p2); |
314 | con_task = GNUNET_SCHEDULER_add_now (&connect_task, | 305 | con_task = GNUNET_SCHEDULER_add_now (&connect_task, NULL); |
315 | NULL); | 306 | } |
316 | } | ||
317 | } | 307 | } |
318 | 308 | ||
319 | 309 | ||
@@ -323,11 +313,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
323 | p->cfg = GNUNET_CONFIGURATION_create (); | 313 | p->cfg = GNUNET_CONFIGURATION_create (); |
324 | #if START_ARM | 314 | #if START_ARM |
325 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 315 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
326 | "gnunet-service-arm", | 316 | "gnunet-service-arm", |
327 | #if VERBOSE | 317 | #if VERBOSE |
328 | "-L", "DEBUG", | 318 | "-L", "DEBUG", |
329 | #endif | 319 | #endif |
330 | "-c", cfgname, NULL); | 320 | "-c", cfgname, NULL); |
331 | #endif | 321 | #endif |
332 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 322 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
333 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 323 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
@@ -339,24 +329,20 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
339 | static void | 329 | static void |
340 | run (void *cls, | 330 | run (void *cls, |
341 | char *const *args, | 331 | char *const *args, |
342 | const char *cfgfile, | 332 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
343 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
344 | { | 333 | { |
345 | GNUNET_assert (ok == 1); | 334 | GNUNET_assert (ok == 1); |
346 | OKPP; | 335 | OKPP; |
347 | setup_peer (&p1, "test_core_api_peer1.conf"); | 336 | setup_peer (&p1, "test_core_api_peer1.conf"); |
348 | setup_peer (&p2, "test_core_api_peer2.conf"); | 337 | setup_peer (&p2, "test_core_api_peer2.conf"); |
349 | err_task = | 338 | err_task = |
350 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | 339 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
351 | &terminate_task_error, NULL); | 340 | (GNUNET_TIME_UNIT_SECONDS, 120), |
352 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, | 341 | &terminate_task_error, NULL); |
353 | &p1, | 342 | p1.ch = |
354 | &init_notify, | 343 | GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, |
355 | &connect_notify, | 344 | &disconnect_notify, NULL, &inbound_notify, |
356 | &disconnect_notify, | 345 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
357 | NULL, | ||
358 | &inbound_notify, | ||
359 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
360 | } | 346 | } |
361 | 347 | ||
362 | static void | 348 | static void |
@@ -365,10 +351,11 @@ stop_arm (struct PeerContext *p) | |||
365 | #if START_ARM | 351 | #if START_ARM |
366 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 352 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
367 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 353 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
368 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 354 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
369 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 355 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
371 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 357 | "ARM process %u stopped\n", |
358 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
372 | GNUNET_OS_process_close (p->arm_proc); | 359 | GNUNET_OS_process_close (p->arm_proc); |
373 | p->arm_proc = NULL; | 360 | p->arm_proc = NULL; |
374 | #endif | 361 | #endif |
@@ -410,7 +397,7 @@ main (int argc, char *argv[]) | |||
410 | #endif | 397 | #endif |
411 | NULL); | 398 | NULL); |
412 | ret = check (); | 399 | ret = check (); |
413 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 400 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
414 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 401 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
415 | 402 | ||
416 | return ret; | 403 | return ret; |
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c index cc55f1644..200ae4176 100644 --- a/src/core/test_core_api_preferences.c +++ b/src/core/test_core_api_preferences.c | |||
@@ -41,7 +41,7 @@ struct PeerContext | |||
41 | { | 41 | { |
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | struct GNUNET_CORE_Handle *ch; | 43 | struct GNUNET_CORE_Handle *ch; |
44 | struct GNUNET_PeerIdentity id; | 44 | struct GNUNET_PeerIdentity id; |
45 | struct GNUNET_TRANSPORT_Handle *th; | 45 | struct GNUNET_TRANSPORT_Handle *th; |
46 | struct GNUNET_MessageHeader *hello; | 46 | struct GNUNET_MessageHeader *hello; |
47 | int connect_status; | 47 | int connect_status; |
@@ -75,13 +75,14 @@ static GNUNET_SCHEDULER_TaskIdentifier ask_task; | |||
75 | static unsigned int total_reserve = 5; | 75 | static unsigned int total_reserve = 5; |
76 | 76 | ||
77 | 77 | ||
78 | static void process_hello (void *cls, const struct GNUNET_MessageHeader *message); | 78 | static void process_hello (void *cls, |
79 | const struct GNUNET_MessageHeader *message); | ||
79 | 80 | ||
80 | static void | 81 | static void |
81 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 82 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
82 | { | 83 | { |
83 | #if VERBOSE | 84 | #if VERBOSE |
84 | fprintf(stderr, "Regular shutdown\n"); | 85 | fprintf (stderr, "Regular shutdown\n"); |
85 | #endif | 86 | #endif |
86 | GNUNET_assert (ok == 6); | 87 | GNUNET_assert (ok == 6); |
87 | GNUNET_assert (NULL == irc); | 88 | GNUNET_assert (NULL == irc); |
@@ -100,24 +101,24 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
100 | { | 101 | { |
101 | err_task = GNUNET_SCHEDULER_NO_TASK; | 102 | err_task = GNUNET_SCHEDULER_NO_TASK; |
102 | #if VERBOSE | 103 | #if VERBOSE |
103 | fprintf(stderr, "ENDING ANGRILY %u\n", ok); | 104 | fprintf (stderr, "ENDING ANGRILY %u\n", ok); |
104 | #endif | 105 | #endif |
105 | GNUNET_break (0); | 106 | GNUNET_break (0); |
106 | if (NULL != irc) | 107 | if (NULL != irc) |
107 | { | 108 | { |
108 | GNUNET_CORE_peer_change_preference_cancel (irc); | 109 | GNUNET_CORE_peer_change_preference_cancel (irc); |
109 | irc = NULL; | 110 | irc = NULL; |
110 | } | 111 | } |
111 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) | 112 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) |
112 | { | 113 | { |
113 | GNUNET_SCHEDULER_cancel (irc_task); | 114 | GNUNET_SCHEDULER_cancel (irc_task); |
114 | irc_task = GNUNET_SCHEDULER_NO_TASK; | 115 | irc_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 116 | } |
116 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | 117 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) |
117 | { | 118 | { |
118 | GNUNET_SCHEDULER_cancel (ask_task); | 119 | GNUNET_SCHEDULER_cancel (ask_task); |
119 | ask_task = GNUNET_SCHEDULER_NO_TASK; | 120 | ask_task = GNUNET_SCHEDULER_NO_TASK; |
120 | } | 121 | } |
121 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | 122 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); |
122 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | 123 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); |
123 | GNUNET_CORE_disconnect (p1.ch); | 124 | GNUNET_CORE_disconnect (p1.ch); |
@@ -142,160 +143,151 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
142 | m = (struct GNUNET_MessageHeader *) buf; | 143 | m = (struct GNUNET_MessageHeader *) buf; |
143 | m->type = htons (MTYPE); | 144 | m->type = htons (MTYPE); |
144 | m->size = htons (sizeof (struct GNUNET_MessageHeader)); | 145 | m->size = htons (sizeof (struct GNUNET_MessageHeader)); |
145 | err_task = | 146 | err_task = |
146 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | 147 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
147 | &terminate_task_error, NULL); | 148 | (GNUNET_TIME_UNIT_SECONDS, 120), |
149 | &terminate_task_error, NULL); | ||
148 | 150 | ||
149 | return sizeof (struct GNUNET_MessageHeader); | 151 | return sizeof (struct GNUNET_MessageHeader); |
150 | } | 152 | } |
151 | 153 | ||
152 | static void | 154 | static void |
153 | preference_cb (void *cls, | 155 | preference_cb (void *cls, |
154 | const struct | 156 | const struct |
155 | GNUNET_PeerIdentity *peer, | 157 | GNUNET_PeerIdentity *peer, |
156 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 158 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
157 | int32_t amount, | 159 | int32_t amount, |
158 | struct GNUNET_TIME_Relative res_delay, | 160 | struct GNUNET_TIME_Relative res_delay, uint64_t preference); |
159 | uint64_t preference); | ||
160 | 161 | ||
161 | static void | 162 | static void |
162 | do_reserve (void *cls, | 163 | do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
163 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
164 | { | 164 | { |
165 | struct PeerContext *pc = cls; | 165 | struct PeerContext *pc = cls; |
166 | 166 | ||
167 | irc_task = GNUNET_SCHEDULER_NO_TASK; | 167 | irc_task = GNUNET_SCHEDULER_NO_TASK; |
168 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 168 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
169 | { | 169 | { |
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
171 | "Aborted during attempt to request reservation\n"); | 171 | "Aborted during attempt to request reservation\n"); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Requesting reservatin of 32k from core in 1s!\n"); | 175 | "Requesting reservatin of 32k from core in 1s!\n"); |
176 | irc = GNUNET_CORE_peer_change_preference (p1.ch, | 176 | irc = GNUNET_CORE_peer_change_preference (p1.ch, |
177 | &p2.id, | 177 | &p2.id, |
178 | GNUNET_TIME_UNIT_SECONDS, | 178 | GNUNET_TIME_UNIT_SECONDS, |
179 | GNUNET_BANDWIDTH_VALUE_MAX, | 179 | GNUNET_BANDWIDTH_VALUE_MAX, |
180 | 1000000 /* bandwidth for 1s */, | 180 | 1000000 /* bandwidth for 1s */ , |
181 | 0, | 181 | 0, &preference_cb, pc); |
182 | &preference_cb, | ||
183 | pc); | ||
184 | } | 182 | } |
185 | 183 | ||
186 | static void | 184 | static void |
187 | preference_cb (void *cls, | 185 | preference_cb (void *cls, |
188 | const struct | 186 | const struct |
189 | GNUNET_PeerIdentity *peer, | 187 | GNUNET_PeerIdentity *peer, |
190 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 188 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
191 | int32_t amount, | 189 | int32_t amount, |
192 | struct GNUNET_TIME_Relative res_delay, | 190 | struct GNUNET_TIME_Relative res_delay, uint64_t preference) |
193 | uint64_t preference) | ||
194 | { | 191 | { |
195 | struct PeerContext *pc = cls; | 192 | struct PeerContext *pc = cls; |
196 | 193 | ||
197 | irc = NULL; | 194 | irc = NULL; |
198 | if (0 == amount) | 195 | if (0 == amount) |
199 | { | 196 | { |
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | "Delaying reservation request by %llu ms!\n", | 198 | "Delaying reservation request by %llu ms!\n", |
202 | (unsigned long long) res_delay.rel_value); | 199 | (unsigned long long) res_delay.rel_value); |
203 | irc_task = GNUNET_SCHEDULER_add_delayed (res_delay, | 200 | irc_task = GNUNET_SCHEDULER_add_delayed (res_delay, &do_reserve, pc); |
204 | &do_reserve, pc); | 201 | return; |
205 | return; | 202 | } |
206 | } | ||
207 | total_reserve--; | 203 | total_reserve--; |
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation done!\n"); |
209 | "Reservation done!\n"); | ||
210 | if (total_reserve > 0) | 205 | if (total_reserve > 0) |
211 | { | 206 | { |
212 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); | 207 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); |
213 | return; | 208 | return; |
214 | } | 209 | } |
215 | GNUNET_SCHEDULER_cancel (err_task); | 210 | GNUNET_SCHEDULER_cancel (err_task); |
216 | err_task = GNUNET_SCHEDULER_NO_TASK; | 211 | err_task = GNUNET_SCHEDULER_NO_TASK; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
218 | "Asking core (1) for transmission to peer `%4s'\n", | 213 | "Asking core (1) for transmission to peer `%4s'\n", |
219 | GNUNET_i2s (&p2.id)); | 214 | GNUNET_i2s (&p2.id)); |
220 | if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch, | 215 | if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch, |
221 | GNUNET_YES, | 216 | GNUNET_YES, |
222 | 0, | 217 | 0, |
223 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), | 218 | GNUNET_TIME_relative_multiply |
224 | &p2.id, | 219 | (GNUNET_TIME_UNIT_SECONDS, |
225 | sizeof (struct GNUNET_MessageHeader), | 220 | 45), &p2.id, |
226 | &transmit_ready, &p1))) | 221 | sizeof (struct |
227 | { | 222 | GNUNET_MessageHeader), |
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 223 | &transmit_ready, &p1))) |
229 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 224 | { |
230 | GNUNET_i2s (&p2.id)); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
231 | } | 226 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
227 | GNUNET_i2s (&p2.id)); | ||
228 | } | ||
232 | } | 229 | } |
233 | 230 | ||
234 | 231 | ||
235 | static void | 232 | static void |
236 | connect_notify (void *cls, | 233 | connect_notify (void *cls, |
237 | const struct GNUNET_PeerIdentity *peer, | 234 | const struct GNUNET_PeerIdentity *peer, |
238 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 235 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
239 | { | 236 | { |
240 | struct PeerContext *pc = cls; | 237 | struct PeerContext *pc = cls; |
241 | 238 | ||
242 | if (0 == memcmp (&pc->id, | 239 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
243 | peer, | ||
244 | sizeof (struct GNUNET_PeerIdentity))) | ||
245 | return; | 240 | return; |
246 | GNUNET_assert (pc->connect_status == 0); | 241 | GNUNET_assert (pc->connect_status == 0); |
247 | pc->connect_status = 1; | 242 | pc->connect_status = 1; |
248 | if (pc == &p1) | 243 | if (pc == &p1) |
244 | { | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
246 | "Encrypted connection established to peer `%4s'\n", | ||
247 | GNUNET_i2s (peer)); | ||
248 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | ||
249 | { | 249 | { |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_SCHEDULER_cancel (ask_task); |
251 | "Encrypted connection established to peer `%4s'\n", | 251 | ask_task = GNUNET_SCHEDULER_NO_TASK; |
252 | GNUNET_i2s (peer)); | ||
253 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | ||
254 | { | ||
255 | GNUNET_SCHEDULER_cancel (ask_task); | ||
256 | ask_task = GNUNET_SCHEDULER_NO_TASK; | ||
257 | } | ||
258 | GNUNET_SCHEDULER_cancel (err_task); | ||
259 | err_task = | ||
260 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | ||
261 | &terminate_task_error, NULL); | ||
262 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); | ||
263 | } | 252 | } |
253 | GNUNET_SCHEDULER_cancel (err_task); | ||
254 | err_task = | ||
255 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
256 | (GNUNET_TIME_UNIT_SECONDS, 120), | ||
257 | &terminate_task_error, NULL); | ||
258 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); | ||
259 | } | ||
264 | } | 260 | } |
265 | 261 | ||
266 | 262 | ||
267 | static void | 263 | static void |
268 | disconnect_notify (void *cls, | 264 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
269 | const struct GNUNET_PeerIdentity *peer) | ||
270 | { | 265 | { |
271 | struct PeerContext *pc = cls; | 266 | struct PeerContext *pc = cls; |
272 | 267 | ||
273 | if (0 == memcmp (&pc->id, | 268 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
274 | peer, | ||
275 | sizeof (struct GNUNET_PeerIdentity))) | ||
276 | return; | 269 | return; |
277 | pc->connect_status = 0; | 270 | pc->connect_status = 0; |
278 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) | 271 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) |
272 | { | ||
273 | GNUNET_SCHEDULER_cancel (irc_task); | ||
274 | irc_task = GNUNET_SCHEDULER_NO_TASK; | ||
275 | } | ||
276 | if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity))) | ||
277 | { | ||
278 | if (irc != NULL) | ||
279 | { | 279 | { |
280 | GNUNET_SCHEDULER_cancel (irc_task); | 280 | GNUNET_CORE_peer_change_preference_cancel (irc); |
281 | irc_task = GNUNET_SCHEDULER_NO_TASK; | 281 | irc = NULL; |
282 | } | 282 | } |
283 | if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity))) | 283 | if (th != NULL) |
284 | { | 284 | { |
285 | if (irc != NULL) | 285 | GNUNET_CORE_notify_transmit_ready_cancel (th); |
286 | { | 286 | th = NULL; |
287 | GNUNET_CORE_peer_change_preference_cancel (irc); | ||
288 | irc = NULL; | ||
289 | } | ||
290 | if (th != NULL) | ||
291 | { | ||
292 | GNUNET_CORE_notify_transmit_ready_cancel (th); | ||
293 | th = NULL; | ||
294 | } | ||
295 | } | 287 | } |
288 | } | ||
296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
297 | "Encrypted connection to `%4s' cut\n", | 290 | "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); |
298 | GNUNET_i2s (peer)); | ||
299 | } | 291 | } |
300 | 292 | ||
301 | 293 | ||
@@ -303,7 +295,7 @@ static int | |||
303 | inbound_notify (void *cls, | 295 | inbound_notify (void *cls, |
304 | const struct GNUNET_PeerIdentity *other, | 296 | const struct GNUNET_PeerIdentity *other, |
305 | const struct GNUNET_MessageHeader *message, | 297 | const struct GNUNET_MessageHeader *message, |
306 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 298 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
307 | { | 299 | { |
308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
309 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); | 301 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); |
@@ -315,7 +307,7 @@ static int | |||
315 | outbound_notify (void *cls, | 307 | outbound_notify (void *cls, |
316 | const struct GNUNET_PeerIdentity *other, | 308 | const struct GNUNET_PeerIdentity *other, |
317 | const struct GNUNET_MessageHeader *message, | 309 | const struct GNUNET_MessageHeader *message, |
318 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 310 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
319 | { | 311 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
321 | "Core notifies about outbound data for `%4s'.\n", | 313 | "Core notifies about outbound data for `%4s'.\n", |
@@ -329,7 +321,7 @@ static int | |||
329 | process_mtype (void *cls, | 321 | process_mtype (void *cls, |
330 | const struct GNUNET_PeerIdentity *peer, | 322 | const struct GNUNET_PeerIdentity *peer, |
331 | const struct GNUNET_MessageHeader *message, | 323 | const struct GNUNET_MessageHeader *message, |
332 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 324 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
333 | { | 325 | { |
334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
335 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); | 327 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); |
@@ -349,19 +341,16 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
349 | 341 | ||
350 | 342 | ||
351 | 343 | ||
352 | static void | 344 | static void |
353 | ask_connect_task (void *cls, | 345 | ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
354 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
355 | { | 346 | { |
356 | ask_task = | 347 | ask_task = |
357 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 348 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
358 | &ask_connect_task, NULL); | 349 | &ask_connect_task, NULL); |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
360 | "Asking core (1) AGAIN to connect to peer `%4s'\n", | 351 | "Asking core (1) AGAIN to connect to peer `%4s'\n", |
361 | GNUNET_i2s (&p2.id)); | 352 | GNUNET_i2s (&p2.id)); |
362 | GNUNET_CORE_peer_request_connect (p1.ch, | 353 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
363 | &p2.id, | ||
364 | NULL, NULL); | ||
365 | } | 354 | } |
366 | 355 | ||
367 | 356 | ||
@@ -380,52 +369,48 @@ init_notify (void *cls, | |||
380 | p->id = *my_identity; | 369 | p->id = *my_identity; |
381 | p->ch = server; | 370 | p->ch = server; |
382 | if (cls == &p1) | 371 | if (cls == &p1) |
383 | { | 372 | { |
384 | GNUNET_assert (ok == 2); | 373 | GNUNET_assert (ok == 2); |
385 | OKPP; | 374 | OKPP; |
386 | /* connect p2 */ | 375 | /* connect p2 */ |
387 | GNUNET_CORE_connect (p2.cfg, 1, | 376 | GNUNET_CORE_connect (p2.cfg, 1, |
388 | &p2, | 377 | &p2, |
389 | &init_notify, | 378 | &init_notify, |
390 | &connect_notify, | 379 | &connect_notify, |
391 | &disconnect_notify, | 380 | &disconnect_notify, |
392 | NULL, | 381 | NULL, |
393 | &inbound_notify, | 382 | &inbound_notify, |
394 | GNUNET_YES, | 383 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
395 | &outbound_notify, GNUNET_YES, handlers); | 384 | } |
396 | } | ||
397 | else | 385 | else |
398 | { | 386 | { |
399 | GNUNET_assert (ok == 3); | 387 | GNUNET_assert (ok == 3); |
400 | OKPP; | 388 | OKPP; |
401 | GNUNET_assert (cls == &p2); | 389 | GNUNET_assert (cls == &p2); |
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
403 | "Asking core (1) to connect to peer `%4s'\n", | 391 | "Asking core (1) to connect to peer `%4s'\n", |
404 | GNUNET_i2s (&p2.id)); | 392 | GNUNET_i2s (&p2.id)); |
405 | err_task = | 393 | err_task = |
406 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), | 394 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
407 | &terminate_task_error, NULL); | 395 | (GNUNET_TIME_UNIT_SECONDS, 60), |
408 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | 396 | &terminate_task_error, NULL); |
409 | GNUNET_SCHEDULER_cancel (ask_task); | 397 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) |
410 | ask_task = | 398 | GNUNET_SCHEDULER_cancel (ask_task); |
411 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 399 | ask_task = |
412 | &ask_connect_task, NULL); | 400 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
413 | GNUNET_CORE_peer_request_connect (p1.ch, | 401 | &ask_connect_task, NULL); |
414 | &p2.id, | 402 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
415 | NULL, NULL); | 403 | } |
416 | } | ||
417 | } | 404 | } |
418 | 405 | ||
419 | 406 | ||
420 | static void | 407 | static void |
421 | process_hello (void *cls, | 408 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
422 | const struct GNUNET_MessageHeader *message) | ||
423 | { | 409 | { |
424 | struct PeerContext *p = cls; | 410 | struct PeerContext *p = cls; |
425 | 411 | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
427 | "Received (my) `%s' from transport service\n", | 413 | "Received (my) `%s' from transport service\n", "HELLO"); |
428 | "HELLO"); | ||
429 | GNUNET_assert (message != NULL); | 414 | GNUNET_assert (message != NULL); |
430 | p->hello = GNUNET_malloc (ntohs (message->size)); | 415 | p->hello = GNUNET_malloc (ntohs (message->size)); |
431 | memcpy (p->hello, message, ntohs (message->size)); | 416 | memcpy (p->hello, message, ntohs (message->size)); |
@@ -448,11 +433,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
448 | p->cfg = GNUNET_CONFIGURATION_create (); | 433 | p->cfg = GNUNET_CONFIGURATION_create (); |
449 | #if START_ARM | 434 | #if START_ARM |
450 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 435 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
451 | "gnunet-service-arm", | 436 | "gnunet-service-arm", |
452 | #if VERBOSE | 437 | #if VERBOSE |
453 | "-L", "DEBUG", | 438 | "-L", "DEBUG", |
454 | #endif | 439 | #endif |
455 | "-c", cfgname, NULL); | 440 | "-c", cfgname, NULL); |
456 | #endif | 441 | #endif |
457 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 442 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
458 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 443 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
@@ -464,8 +449,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
464 | static void | 449 | static void |
465 | run (void *cls, | 450 | run (void *cls, |
466 | char *const *args, | 451 | char *const *args, |
467 | const char *cfgfile, | 452 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
468 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
469 | { | 453 | { |
470 | GNUNET_assert (ok == 1); | 454 | GNUNET_assert (ok == 1); |
471 | OKPP; | 455 | OKPP; |
@@ -474,9 +458,9 @@ run (void *cls, | |||
474 | GNUNET_CORE_connect (p1.cfg, 1, | 458 | GNUNET_CORE_connect (p1.cfg, 1, |
475 | &p1, | 459 | &p1, |
476 | &init_notify, | 460 | &init_notify, |
477 | &connect_notify, | 461 | &connect_notify, |
478 | &disconnect_notify, | 462 | &disconnect_notify, |
479 | NULL, | 463 | NULL, |
480 | &inbound_notify, | 464 | &inbound_notify, |
481 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | 465 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
482 | } | 466 | } |
@@ -487,10 +471,11 @@ stop_arm (struct PeerContext *p) | |||
487 | #if START_ARM | 471 | #if START_ARM |
488 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 472 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
489 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 473 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
490 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 474 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
491 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 475 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
493 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 477 | "ARM process %u stopped\n", |
478 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
494 | GNUNET_OS_process_close (p->arm_proc); | 479 | GNUNET_OS_process_close (p->arm_proc); |
495 | p->arm_proc = NULL; | 480 | p->arm_proc = NULL; |
496 | #endif | 481 | #endif |
@@ -513,7 +498,8 @@ check () | |||
513 | }; | 498 | }; |
514 | ok = 1; | 499 | ok = 1; |
515 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 500 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
516 | argv, "test-core-api-preferences", "nohelp", options, &run, &ok); | 501 | argv, "test-core-api-preferences", "nohelp", options, |
502 | &run, &ok); | ||
517 | stop_arm (&p1); | 503 | stop_arm (&p1); |
518 | stop_arm (&p2); | 504 | stop_arm (&p2); |
519 | return ok; | 505 | return ok; |
@@ -532,7 +518,7 @@ main (int argc, char *argv[]) | |||
532 | #endif | 518 | #endif |
533 | NULL); | 519 | NULL); |
534 | ret = check (); | 520 | ret = check (); |
535 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 521 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
536 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 522 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
537 | 523 | ||
538 | return ret; | 524 | return ret; |
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index b279acb91..1f82a0058 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c | |||
@@ -71,7 +71,7 @@ struct PeerContext | |||
71 | { | 71 | { |
72 | struct GNUNET_CONFIGURATION_Handle *cfg; | 72 | struct GNUNET_CONFIGURATION_Handle *cfg; |
73 | struct GNUNET_CORE_Handle *ch; | 73 | struct GNUNET_CORE_Handle *ch; |
74 | struct GNUNET_PeerIdentity id; | 74 | struct GNUNET_PeerIdentity id; |
75 | struct GNUNET_TRANSPORT_Handle *th; | 75 | struct GNUNET_TRANSPORT_Handle *th; |
76 | struct GNUNET_MessageHeader *hello; | 76 | struct GNUNET_MessageHeader *hello; |
77 | int connect_status; | 77 | int connect_status; |
@@ -95,7 +95,7 @@ static int32_t tr_n; | |||
95 | #define OKPP do { ok++; } while (0) | 95 | #define OKPP do { ok++; } while (0) |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | struct TestMessage | 98 | struct TestMessage |
99 | { | 99 | { |
100 | struct GNUNET_MessageHeader header; | 100 | struct GNUNET_MessageHeader header; |
101 | uint32_t num; | 101 | uint32_t num; |
@@ -106,13 +106,15 @@ static unsigned int | |||
106 | get_size (unsigned int iter) | 106 | get_size (unsigned int iter) |
107 | { | 107 | { |
108 | unsigned int ret; | 108 | unsigned int ret; |
109 | |||
109 | if (iter < 60000) | 110 | if (iter < 60000) |
110 | return iter + sizeof (struct TestMessage); | 111 | return iter + sizeof (struct TestMessage); |
111 | ret = (iter * iter * iter); | 112 | ret = (iter * iter * iter); |
112 | return sizeof (struct TestMessage) + (ret % 60000); | 113 | return sizeof (struct TestMessage) + (ret % 60000); |
113 | } | 114 | } |
114 | 115 | ||
115 | static void process_hello (void *cls, const struct GNUNET_MessageHeader *message); | 116 | static void process_hello (void *cls, |
117 | const struct GNUNET_MessageHeader *message); | ||
116 | 118 | ||
117 | static void | 119 | static void |
118 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 120 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -131,9 +133,9 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
131 | p2.th = NULL; | 133 | p2.th = NULL; |
132 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | 134 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; |
133 | fprintf (stderr, | 135 | fprintf (stderr, |
134 | "\nThroughput was %llu kb/s\n", | 136 | "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); |
135 | total_bytes * 1000 / 1024 / delta); | 137 | GAUGER ("CORE", "Core throughput/s", total_bytes * 1000 / 1024 / delta, |
136 | GAUGER ("CORE", "Core throughput/s", total_bytes * 1000 / 1024 / delta, "kb/s"); | 138 | "kb/s"); |
137 | ok = 0; | 139 | ok = 0; |
138 | } | 140 | } |
139 | 141 | ||
@@ -143,27 +145,27 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
143 | { | 145 | { |
144 | GNUNET_break (0); | 146 | GNUNET_break (0); |
145 | if (p1.ch != NULL) | 147 | if (p1.ch != NULL) |
146 | { | 148 | { |
147 | GNUNET_CORE_disconnect (p1.ch); | 149 | GNUNET_CORE_disconnect (p1.ch); |
148 | p1.ch = NULL; | 150 | p1.ch = NULL; |
149 | } | 151 | } |
150 | if (p2.ch != NULL) | 152 | if (p2.ch != NULL) |
151 | { | 153 | { |
152 | GNUNET_CORE_disconnect (p2.ch); | 154 | GNUNET_CORE_disconnect (p2.ch); |
153 | p2.ch = NULL; | 155 | p2.ch = NULL; |
154 | } | 156 | } |
155 | if (p1.th != NULL) | 157 | if (p1.th != NULL) |
156 | { | 158 | { |
157 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | 159 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); |
158 | GNUNET_TRANSPORT_disconnect (p1.th); | 160 | GNUNET_TRANSPORT_disconnect (p1.th); |
159 | p1.th = NULL; | 161 | p1.th = NULL; |
160 | } | 162 | } |
161 | if (p2.th != NULL) | 163 | if (p2.th != NULL) |
162 | { | 164 | { |
163 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | 165 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); |
164 | GNUNET_TRANSPORT_disconnect (p2.th); | 166 | GNUNET_TRANSPORT_disconnect (p2.th); |
165 | p2.th = NULL; | 167 | p2.th = NULL; |
166 | } | 168 | } |
167 | ok = 42; | 169 | ok = 42; |
168 | } | 170 | } |
169 | 171 | ||
@@ -176,20 +178,20 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
176 | unsigned int s; | 178 | unsigned int s; |
177 | unsigned int ret; | 179 | unsigned int ret; |
178 | 180 | ||
179 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | 181 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); |
180 | if (buf == NULL) | 182 | if (buf == NULL) |
181 | { | 183 | { |
182 | if (p1.ch != NULL) | 184 | if (p1.ch != NULL) |
183 | GNUNET_break (NULL != | 185 | GNUNET_break (NULL != |
184 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 186 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
185 | GNUNET_NO, | 187 | GNUNET_NO, |
186 | 0, | 188 | 0, |
187 | FAST_TIMEOUT, | 189 | FAST_TIMEOUT, |
188 | &p2.id, | 190 | &p2.id, |
189 | get_size(tr_n), | 191 | get_size (tr_n), |
190 | &transmit_ready, &p1)); | 192 | &transmit_ready, &p1)); |
191 | return 0; | 193 | return 0; |
192 | } | 194 | } |
193 | GNUNET_assert (tr_n < TOTAL_MSGS); | 195 | GNUNET_assert (tr_n < TOTAL_MSGS); |
194 | ret = 0; | 196 | ret = 0; |
195 | s = get_size (tr_n); | 197 | s = get_size (tr_n); |
@@ -197,35 +199,29 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
197 | GNUNET_assert (buf != NULL); | 199 | GNUNET_assert (buf != NULL); |
198 | cbuf = buf; | 200 | cbuf = buf; |
199 | do | 201 | do |
200 | { | 202 | { |
201 | #if VERBOSE | 203 | #if VERBOSE |
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
203 | "Sending message %u of size %u at offset %u\n", | 205 | "Sending message %u of size %u at offset %u\n", tr_n, s, ret); |
204 | tr_n, | ||
205 | s, | ||
206 | ret); | ||
207 | #endif | 206 | #endif |
208 | hdr.header.size = htons (s); | 207 | hdr.header.size = htons (s); |
209 | hdr.header.type = htons (MTYPE); | 208 | hdr.header.type = htons (MTYPE); |
210 | hdr.num = htonl (tr_n); | 209 | hdr.num = htonl (tr_n); |
211 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 210 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
212 | ret += sizeof (struct TestMessage); | 211 | ret += sizeof (struct TestMessage); |
213 | memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage)); | 212 | memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage)); |
214 | ret += s - sizeof (struct TestMessage); | 213 | ret += s - sizeof (struct TestMessage); |
215 | tr_n++; | 214 | tr_n++; |
216 | s = get_size (tr_n); | 215 | s = get_size (tr_n); |
217 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 216 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
218 | break; /* sometimes pack buffer full, sometimes not */ | 217 | break; /* sometimes pack buffer full, sometimes not */ |
219 | } | 218 | } |
220 | while (size - ret >= s); | 219 | while (size - ret >= s); |
221 | GNUNET_SCHEDULER_cancel (err_task); | 220 | GNUNET_SCHEDULER_cancel (err_task); |
222 | err_task = | 221 | err_task = |
223 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 222 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); |
224 | &terminate_task_error, | ||
225 | NULL); | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
227 | "Returning total message block of size %u\n", | 224 | "Returning total message block of size %u\n", ret); |
228 | ret); | ||
229 | total_bytes += ret; | 225 | total_bytes += ret; |
230 | return ret; | 226 | return ret; |
231 | } | 227 | } |
@@ -235,51 +231,44 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
235 | static void | 231 | static void |
236 | connect_notify (void *cls, | 232 | connect_notify (void *cls, |
237 | const struct GNUNET_PeerIdentity *peer, | 233 | const struct GNUNET_PeerIdentity *peer, |
238 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 234 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
239 | { | 235 | { |
240 | struct PeerContext *pc = cls; | 236 | struct PeerContext *pc = cls; |
241 | 237 | ||
242 | if (0 == memcmp (&pc->id, | 238 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
243 | peer, | ||
244 | sizeof (struct GNUNET_PeerIdentity))) | ||
245 | return; | 239 | return; |
246 | GNUNET_assert (pc->connect_status == 0); | 240 | GNUNET_assert (pc->connect_status == 0); |
247 | pc->connect_status = 1; | 241 | pc->connect_status = 1; |
248 | if (pc == &p1) | 242 | if (pc == &p1) |
249 | { | 243 | { |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
251 | "Encrypted connection established to peer `%4s'\n", | 245 | "Encrypted connection established to peer `%4s'\n", |
252 | GNUNET_i2s (peer)); | 246 | GNUNET_i2s (peer)); |
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
254 | "Asking core (1) for transmission to peer `%4s'\n", | 248 | "Asking core (1) for transmission to peer `%4s'\n", |
255 | GNUNET_i2s (&p2.id)); | 249 | GNUNET_i2s (&p2.id)); |
256 | GNUNET_SCHEDULER_cancel (err_task); | 250 | GNUNET_SCHEDULER_cancel (err_task); |
257 | err_task = | 251 | err_task = |
258 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 252 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); |
259 | &terminate_task_error, | 253 | start_time = GNUNET_TIME_absolute_get (); |
260 | NULL); | 254 | GNUNET_break (NULL != |
261 | start_time = GNUNET_TIME_absolute_get (); | 255 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
262 | GNUNET_break (NULL != | 256 | GNUNET_NO, |
263 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 257 | 0, |
264 | GNUNET_NO, | 258 | TIMEOUT, |
265 | 0, | 259 | &p2.id, |
266 | TIMEOUT, | 260 | get_size (0), |
267 | &p2.id, | 261 | &transmit_ready, &p1)); |
268 | get_size (0), | 262 | } |
269 | &transmit_ready, &p1)); | ||
270 | } | ||
271 | } | 263 | } |
272 | 264 | ||
273 | 265 | ||
274 | static void | 266 | static void |
275 | disconnect_notify (void *cls, | 267 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
276 | const struct GNUNET_PeerIdentity *peer) | ||
277 | { | 268 | { |
278 | struct PeerContext *pc = cls; | 269 | struct PeerContext *pc = cls; |
279 | 270 | ||
280 | if (0 == memcmp (&pc->id, | 271 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
281 | peer, | ||
282 | sizeof (struct GNUNET_PeerIdentity))) | ||
283 | return; | 272 | return; |
284 | pc->connect_status = 0; | 273 | pc->connect_status = 0; |
285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -291,7 +280,7 @@ static int | |||
291 | inbound_notify (void *cls, | 280 | inbound_notify (void *cls, |
292 | const struct GNUNET_PeerIdentity *other, | 281 | const struct GNUNET_PeerIdentity *other, |
293 | const struct GNUNET_MessageHeader *message, | 282 | const struct GNUNET_MessageHeader *message, |
294 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 283 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
295 | { | 284 | { |
296 | #if VERBOSE | 285 | #if VERBOSE |
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -305,7 +294,7 @@ static int | |||
305 | outbound_notify (void *cls, | 294 | outbound_notify (void *cls, |
306 | const struct GNUNET_PeerIdentity *other, | 295 | const struct GNUNET_PeerIdentity *other, |
307 | const struct GNUNET_MessageHeader *message, | 296 | const struct GNUNET_MessageHeader *message, |
308 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 297 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
309 | { | 298 | { |
310 | #if VERBOSE | 299 | #if VERBOSE |
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -316,71 +305,65 @@ outbound_notify (void *cls, | |||
316 | } | 305 | } |
317 | 306 | ||
318 | 307 | ||
319 | static size_t | 308 | static size_t transmit_ready (void *cls, size_t size, void *buf); |
320 | transmit_ready (void *cls, size_t size, void *buf); | ||
321 | 309 | ||
322 | static int | 310 | static int |
323 | process_mtype (void *cls, | 311 | process_mtype (void *cls, |
324 | const struct GNUNET_PeerIdentity *peer, | 312 | const struct GNUNET_PeerIdentity *peer, |
325 | const struct GNUNET_MessageHeader *message, | 313 | const struct GNUNET_MessageHeader *message, |
326 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 314 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
327 | { | 315 | { |
328 | static int n; | 316 | static int n; |
329 | unsigned int s; | 317 | unsigned int s; |
330 | const struct TestMessage *hdr; | 318 | const struct TestMessage *hdr; |
331 | 319 | ||
332 | hdr = (const struct TestMessage*) message; | 320 | hdr = (const struct TestMessage *) message; |
333 | s = get_size (n); | 321 | s = get_size (n); |
334 | if (MTYPE != ntohs (message->type)) | 322 | if (MTYPE != ntohs (message->type)) |
335 | return GNUNET_SYSERR; | 323 | return GNUNET_SYSERR; |
336 | if (ntohs (message->size) != s) | 324 | if (ntohs (message->size) != s) |
337 | { | 325 | { |
338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
339 | "Expected message %u of size %u, got %u bytes of message %u\n", | 327 | "Expected message %u of size %u, got %u bytes of message %u\n", |
340 | n, s, | 328 | n, s, ntohs (message->size), ntohl (hdr->num)); |
341 | ntohs (message->size), | 329 | GNUNET_SCHEDULER_cancel (err_task); |
342 | ntohl (hdr->num)); | 330 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); |
343 | GNUNET_SCHEDULER_cancel (err_task); | 331 | return GNUNET_SYSERR; |
344 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); | 332 | } |
345 | return GNUNET_SYSERR; | ||
346 | } | ||
347 | if (ntohl (hdr->num) != n) | 333 | if (ntohl (hdr->num) != n) |
348 | { | 334 | { |
349 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
350 | "Expected message %u of size %u, got %u bytes of message %u\n", | 336 | "Expected message %u of size %u, got %u bytes of message %u\n", |
351 | n, s, | 337 | n, s, ntohs (message->size), ntohl (hdr->num)); |
352 | ntohs (message->size), | 338 | GNUNET_SCHEDULER_cancel (err_task); |
353 | ntohl (hdr->num)); | 339 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); |
354 | GNUNET_SCHEDULER_cancel (err_task); | 340 | return GNUNET_SYSERR; |
355 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); | 341 | } |
356 | return GNUNET_SYSERR; | ||
357 | } | ||
358 | #if VERBOSE | 342 | #if VERBOSE |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
360 | "Got message %u of size %u\n", | 344 | "Got message %u of size %u\n", |
361 | ntohl (hdr->num), | 345 | ntohl (hdr->num), ntohs (message->size)); |
362 | ntohs (message->size)); | ||
363 | #endif | 346 | #endif |
364 | n++; | 347 | n++; |
365 | if (0 == (n % (TOTAL_MSGS/100))) | 348 | if (0 == (n % (TOTAL_MSGS / 100))) |
366 | fprintf (stderr, "."); | 349 | fprintf (stderr, "."); |
367 | if (n == TOTAL_MSGS) | 350 | if (n == TOTAL_MSGS) |
368 | { | 351 | { |
369 | GNUNET_SCHEDULER_cancel (err_task); | 352 | GNUNET_SCHEDULER_cancel (err_task); |
370 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); | 353 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); |
371 | } | 354 | } |
372 | else | 355 | else |
373 | { | 356 | { |
374 | if (n == tr_n) | 357 | if (n == tr_n) |
375 | GNUNET_break (NULL != | 358 | GNUNET_break (NULL != |
376 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 359 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
377 | GNUNET_NO, | 360 | GNUNET_NO, |
378 | 0, | 361 | 0, |
379 | FAST_TIMEOUT, | 362 | FAST_TIMEOUT, |
380 | &p2.id, | 363 | &p2.id, |
381 | get_size(tr_n), | 364 | get_size (tr_n), |
382 | &transmit_ready, &p1)); | 365 | &transmit_ready, &p1)); |
383 | } | 366 | } |
384 | return GNUNET_OK; | 367 | return GNUNET_OK; |
385 | } | 368 | } |
386 | 369 | ||
@@ -407,44 +390,39 @@ init_notify (void *cls, | |||
407 | p->id = *my_identity; | 390 | p->id = *my_identity; |
408 | p->ch = server; | 391 | p->ch = server; |
409 | if (cls == &p1) | 392 | if (cls == &p1) |
410 | { | 393 | { |
411 | GNUNET_assert (ok == 2); | 394 | GNUNET_assert (ok == 2); |
412 | OKPP; | 395 | OKPP; |
413 | /* connect p2 */ | 396 | /* connect p2 */ |
414 | GNUNET_CORE_connect (p2.cfg, 1, | 397 | GNUNET_CORE_connect (p2.cfg, 1, |
415 | &p2, | 398 | &p2, |
416 | &init_notify, | 399 | &init_notify, |
417 | &connect_notify, | 400 | &connect_notify, |
418 | &disconnect_notify, | 401 | &disconnect_notify, |
419 | NULL, | 402 | NULL, |
420 | &inbound_notify, | 403 | &inbound_notify, |
421 | GNUNET_YES, | 404 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
422 | &outbound_notify, GNUNET_YES, handlers); | 405 | } |
423 | } | ||
424 | else | 406 | else |
425 | { | 407 | { |
426 | GNUNET_assert (ok == 3); | 408 | GNUNET_assert (ok == 3); |
427 | OKPP; | 409 | OKPP; |
428 | GNUNET_assert (cls == &p2); | 410 | GNUNET_assert (cls == &p2); |
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
430 | "Asking core (1) to connect to peer `%4s'\n", | 412 | "Asking core (1) to connect to peer `%4s'\n", |
431 | GNUNET_i2s (&p2.id)); | 413 | GNUNET_i2s (&p2.id)); |
432 | GNUNET_CORE_peer_request_connect (p1.ch, | 414 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
433 | &p2.id, | 415 | } |
434 | NULL, NULL); | ||
435 | } | ||
436 | } | 416 | } |
437 | 417 | ||
438 | 418 | ||
439 | static void | 419 | static void |
440 | process_hello (void *cls, | 420 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
441 | const struct GNUNET_MessageHeader *message) | ||
442 | { | 421 | { |
443 | struct PeerContext *p = cls; | 422 | struct PeerContext *p = cls; |
444 | 423 | ||
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
446 | "Received (my) `%s' from transport service\n", | 425 | "Received (my) `%s' from transport service\n", "HELLO"); |
447 | "HELLO"); | ||
448 | GNUNET_assert (message != NULL); | 426 | GNUNET_assert (message != NULL); |
449 | p->hello = GNUNET_malloc (ntohs (message->size)); | 427 | p->hello = GNUNET_malloc (ntohs (message->size)); |
450 | memcpy (p->hello, message, ntohs (message->size)); | 428 | memcpy (p->hello, message, ntohs (message->size)); |
@@ -467,11 +445,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
467 | p->cfg = GNUNET_CONFIGURATION_create (); | 445 | p->cfg = GNUNET_CONFIGURATION_create (); |
468 | #if START_ARM | 446 | #if START_ARM |
469 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 447 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
470 | "gnunet-service-arm", | 448 | "gnunet-service-arm", |
471 | #if VERBOSE | 449 | #if VERBOSE |
472 | "-L", "DEBUG", | 450 | "-L", "DEBUG", |
473 | #endif | 451 | #endif |
474 | "-c", cfgname, NULL); | 452 | "-c", cfgname, NULL); |
475 | #endif | 453 | #endif |
476 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 454 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
477 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 455 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
@@ -483,23 +461,20 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
483 | static void | 461 | static void |
484 | run (void *cls, | 462 | run (void *cls, |
485 | char *const *args, | 463 | char *const *args, |
486 | const char *cfgfile, | 464 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
487 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
488 | { | 465 | { |
489 | GNUNET_assert (ok == 1); | 466 | GNUNET_assert (ok == 1); |
490 | OKPP; | 467 | OKPP; |
491 | setup_peer (&p1, "test_core_api_peer1.conf"); | 468 | setup_peer (&p1, "test_core_api_peer1.conf"); |
492 | setup_peer (&p2, "test_core_api_peer2.conf"); | 469 | setup_peer (&p2, "test_core_api_peer2.conf"); |
493 | err_task = | 470 | err_task = |
494 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 471 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); |
495 | &terminate_task_error, | ||
496 | NULL); | ||
497 | GNUNET_CORE_connect (p1.cfg, 1, | 472 | GNUNET_CORE_connect (p1.cfg, 1, |
498 | &p1, | 473 | &p1, |
499 | &init_notify, | 474 | &init_notify, |
500 | &connect_notify, | 475 | &connect_notify, |
501 | &disconnect_notify, | 476 | &disconnect_notify, |
502 | NULL, | 477 | NULL, |
503 | &inbound_notify, | 478 | &inbound_notify, |
504 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | 479 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
505 | } | 480 | } |
@@ -511,10 +486,11 @@ stop_arm (struct PeerContext *p) | |||
511 | #if START_ARM | 486 | #if START_ARM |
512 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 487 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
513 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 488 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
514 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 489 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
515 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 490 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
517 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 492 | "ARM process %u stopped\n", |
493 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
518 | GNUNET_OS_process_close (p->arm_proc); | 494 | GNUNET_OS_process_close (p->arm_proc); |
519 | p->arm_proc = NULL; | 495 | p->arm_proc = NULL; |
520 | #endif | 496 | #endif |
@@ -537,7 +513,8 @@ check () | |||
537 | }; | 513 | }; |
538 | ok = 1; | 514 | ok = 1; |
539 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 515 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
540 | argv, "test-core-api-reliability", "nohelp", options, &run, &ok); | 516 | argv, "test-core-api-reliability", "nohelp", options, |
517 | &run, &ok); | ||
541 | stop_arm (&p1); | 518 | stop_arm (&p1); |
542 | stop_arm (&p2); | 519 | stop_arm (&p2); |
543 | return ok; | 520 | return ok; |
@@ -556,7 +533,7 @@ main (int argc, char *argv[]) | |||
556 | #endif | 533 | #endif |
557 | NULL); | 534 | NULL); |
558 | ret = check (); | 535 | ret = check (); |
559 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 536 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
560 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 537 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
561 | 538 | ||
562 | return ret; | 539 | return ret; |
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c index f2ddeb9fe..09d6edacc 100644 --- a/src/core/test_core_api_send_to_self.c +++ b/src/core/test_core_api_send_to_self.c | |||
@@ -66,18 +66,17 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) | |||
66 | die_task = GNUNET_SCHEDULER_NO_TASK; | 66 | die_task = GNUNET_SCHEDULER_NO_TASK; |
67 | 67 | ||
68 | if (core != NULL) | 68 | if (core != NULL) |
69 | { | 69 | { |
70 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n"); | 70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n"); |
71 | GNUNET_CORE_disconnect (core); | 71 | GNUNET_CORE_disconnect (core); |
72 | core = NULL; | 72 | core = NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); |
76 | "Stopping peer\n"); | ||
77 | if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) | 76 | if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) |
78 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 77 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
79 | 78 | ||
80 | if (GNUNET_OS_process_wait(arm_proc) != GNUNET_OK) | 79 | if (GNUNET_OS_process_wait (arm_proc) != GNUNET_OK) |
81 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 80 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
82 | 81 | ||
83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -85,33 +84,37 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) | |||
85 | GNUNET_OS_process_close (arm_proc); | 84 | GNUNET_OS_process_close (arm_proc); |
86 | arm_proc = NULL; | 85 | arm_proc = NULL; |
87 | 86 | ||
88 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); |
89 | } | 88 | } |
90 | 89 | ||
91 | static int | 90 | static int |
92 | receive(void* cls, const struct GNUNET_PeerIdentity* other, const struct GNUNET_MessageHeader* message, const struct GNUNET_TRANSPORT_ATS_Information* atsi) | 91 | receive (void *cls, const struct GNUNET_PeerIdentity *other, |
92 | const struct GNUNET_MessageHeader *message, | ||
93 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
93 | { | 94 | { |
94 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 95 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
95 | GNUNET_SCHEDULER_cancel(die_task); | 96 | GNUNET_SCHEDULER_cancel (die_task); |
96 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", GNUNET_i2s(other)); | 97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", |
97 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | 98 | GNUNET_i2s (other)); |
99 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
98 | ret = 0; | 100 | ret = 0; |
99 | return GNUNET_OK; | 101 | return GNUNET_OK; |
100 | } | 102 | } |
101 | 103 | ||
102 | static size_t | 104 | static size_t |
103 | send_message (void* cls, size_t size, void* buf) | 105 | send_message (void *cls, size_t size, void *buf) |
104 | { | 106 | { |
105 | if (size == 0 || buf == NULL) | 107 | if (size == 0 || buf == NULL) |
106 | { | 108 | { |
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Could not send; got 0 buffer\n"); | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send; got 0 buffer\n"); |
108 | return 0; | 110 | return 0; |
109 | } | 111 | } |
110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending!\n"); | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending!\n"); |
111 | struct GNUNET_MessageHeader *hdr = buf; | 113 | struct GNUNET_MessageHeader *hdr = buf; |
112 | hdr->size = htons(sizeof(struct GNUNET_MessageHeader)); | 114 | |
113 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); | 115 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); |
114 | return ntohs(hdr->size); | 116 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); |
117 | return ntohs (hdr->size); | ||
115 | } | 118 | } |
116 | 119 | ||
117 | static void | 120 | static void |
@@ -120,33 +123,33 @@ init (void *cls, struct GNUNET_CORE_Handle *core, | |||
120 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pk) | 123 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pk) |
121 | { | 124 | { |
122 | if (core == NULL) | 125 | if (core == NULL) |
123 | { | 126 | { |
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could NOT connect to CORE;\n"); | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could NOT connect to CORE;\n"); |
125 | return; | 128 | return; |
126 | } | 129 | } |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
128 | "Correctly connected to CORE; we are the peer %s.\n", | 131 | "Correctly connected to CORE; we are the peer %s.\n", |
129 | GNUNET_i2s (my_identity)); | 132 | GNUNET_i2s (my_identity)); |
130 | memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity)); | 133 | memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity)); |
131 | } | 134 | } |
132 | 135 | ||
133 | static void | 136 | static void |
134 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 137 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
135 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 138 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
136 | { | 139 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n", | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n", |
138 | GNUNET_i2s (peer)); | 141 | GNUNET_i2s (peer)); |
139 | if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity))) | 142 | if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity))) |
140 | { | 143 | { |
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "Connected to myself; sending message!\n"); | 145 | "Connected to myself; sending message!\n"); |
143 | GNUNET_CORE_notify_transmit_ready (core, | 146 | GNUNET_CORE_notify_transmit_ready (core, |
144 | GNUNET_YES, | 147 | GNUNET_YES, |
145 | 0, GNUNET_TIME_UNIT_FOREVER_REL, | 148 | 0, GNUNET_TIME_UNIT_FOREVER_REL, |
146 | peer, | 149 | peer, |
147 | sizeof (struct GNUNET_MessageHeader), | 150 | sizeof (struct GNUNET_MessageHeader), |
148 | send_message, NULL); | 151 | send_message, NULL); |
149 | } | 152 | } |
150 | } | 153 | } |
151 | 154 | ||
152 | 155 | ||
@@ -161,8 +164,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
161 | static void | 164 | static void |
162 | run (void *cls, | 165 | run (void *cls, |
163 | char *const *args, | 166 | char *const *args, |
164 | const char *cfgfile, | 167 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
165 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
166 | { | 168 | { |
167 | const static struct GNUNET_CORE_MessageHandler handlers[] = { | 169 | const static struct GNUNET_CORE_MessageHandler handlers[] = { |
168 | {&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, | 170 | {&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, |
@@ -172,22 +174,27 @@ run (void *cls, | |||
172 | core_cfg = GNUNET_CONFIGURATION_create (); | 174 | core_cfg = GNUNET_CONFIGURATION_create (); |
173 | 175 | ||
174 | arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 176 | arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
175 | "gnunet-service-arm", | 177 | "gnunet-service-arm", |
176 | #if VERBOSE | 178 | #if VERBOSE |
177 | "-L", "DEBUG", | 179 | "-L", "DEBUG", |
178 | #endif | 180 | #endif |
179 | "-c", "test_core_api_peer1.conf", NULL); | 181 | "-c", "test_core_api_peer1.conf", NULL); |
180 | 182 | ||
181 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load (core_cfg, "test_core_api_peer1.conf")); | 183 | GNUNET_assert (GNUNET_OK == |
184 | GNUNET_CONFIGURATION_load (core_cfg, | ||
185 | "test_core_api_peer1.conf")); | ||
182 | 186 | ||
183 | core = GNUNET_CORE_connect (core_cfg, | 187 | core = GNUNET_CORE_connect (core_cfg, |
184 | 42, | 188 | 42, |
185 | NULL, | 189 | NULL, |
186 | &init, | 190 | &init, |
187 | &connect_cb, | 191 | &connect_cb, |
188 | NULL, NULL, NULL, 0, NULL, 0, handlers); | 192 | NULL, NULL, NULL, 0, NULL, 0, handlers); |
189 | 193 | ||
190 | die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &cleanup, cls); | 194 | die_task = |
195 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
196 | (GNUNET_TIME_UNIT_SECONDS, 60), &cleanup, | ||
197 | cls); | ||
191 | } | 198 | } |
192 | 199 | ||
193 | 200 | ||
@@ -210,11 +217,11 @@ check () | |||
210 | ret = 1; | 217 | ret = 1; |
211 | 218 | ||
212 | return (GNUNET_OK == | 219 | return (GNUNET_OK == |
213 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 220 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
214 | argv, | 221 | argv, |
215 | "test_core_api_send_to_self", | 222 | "test_core_api_send_to_self", |
216 | gettext_noop ("help text"), | 223 | gettext_noop ("help text"), |
217 | options, &run, NULL)) ? ret : 1; | 224 | options, &run, NULL)) ? ret : 1; |
218 | } | 225 | } |
219 | 226 | ||
220 | /** | 227 | /** |
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index b6ad19b77..36d964796 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c | |||
@@ -68,14 +68,13 @@ static int ok; | |||
68 | static void | 68 | static void |
69 | connect_notify (void *cls, | 69 | connect_notify (void *cls, |
70 | const struct GNUNET_PeerIdentity *peer, | 70 | const struct GNUNET_PeerIdentity *peer, |
71 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 71 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static void | 76 | static void |
77 | disconnect_notify (void *cls, | 77 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
78 | const struct GNUNET_PeerIdentity *peer) | ||
79 | { | 78 | { |
80 | } | 79 | } |
81 | 80 | ||
@@ -84,7 +83,7 @@ static int | |||
84 | inbound_notify (void *cls, | 83 | inbound_notify (void *cls, |
85 | const struct GNUNET_PeerIdentity *other, | 84 | const struct GNUNET_PeerIdentity *other, |
86 | const struct GNUNET_MessageHeader *message, | 85 | const struct GNUNET_MessageHeader *message, |
87 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 86 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
88 | { | 87 | { |
89 | return GNUNET_OK; | 88 | return GNUNET_OK; |
90 | } | 89 | } |
@@ -94,7 +93,7 @@ static int | |||
94 | outbound_notify (void *cls, | 93 | outbound_notify (void *cls, |
95 | const struct GNUNET_PeerIdentity *other, | 94 | const struct GNUNET_PeerIdentity *other, |
96 | const struct GNUNET_MessageHeader *message, | 95 | const struct GNUNET_MessageHeader *message, |
97 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 96 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
98 | { | 97 | { |
99 | return GNUNET_OK; | 98 | return GNUNET_OK; |
100 | } | 99 | } |
@@ -106,8 +105,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
106 | 105 | ||
107 | 106 | ||
108 | static void | 107 | static void |
109 | shutdown_task (void *cls, | 108 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
110 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
111 | { | 109 | { |
112 | GNUNET_CORE_disconnect (p1.ch); | 110 | GNUNET_CORE_disconnect (p1.ch); |
113 | p1.ch = NULL; | 111 | p1.ch = NULL; |
@@ -130,24 +128,24 @@ init_notify (void *cls, | |||
130 | GNUNET_assert (server != NULL); | 128 | GNUNET_assert (server != NULL); |
131 | GNUNET_assert (p->ch == server); | 129 | GNUNET_assert (p->ch == server); |
132 | if (cls == &p1) | 130 | if (cls == &p1) |
133 | { | 131 | { |
134 | /* connect p2 */ | 132 | /* connect p2 */ |
135 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, | 133 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, |
136 | &p2, | 134 | &p2, |
137 | &init_notify, | 135 | &init_notify, |
138 | &connect_notify, | 136 | &connect_notify, |
139 | &disconnect_notify, | 137 | &disconnect_notify, |
140 | NULL, | 138 | NULL, |
141 | &inbound_notify, | 139 | &inbound_notify, |
142 | GNUNET_YES, | 140 | GNUNET_YES, |
143 | &outbound_notify, GNUNET_YES, handlers); | 141 | &outbound_notify, GNUNET_YES, handlers); |
144 | } | 142 | } |
145 | else | 143 | else |
146 | { | 144 | { |
147 | GNUNET_assert (cls == &p2); | 145 | GNUNET_assert (cls == &p2); |
148 | GNUNET_SCHEDULER_cancel (timeout_task_id); | 146 | GNUNET_SCHEDULER_cancel (timeout_task_id); |
149 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 147 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
150 | } | 148 | } |
151 | } | 149 | } |
152 | 150 | ||
153 | 151 | ||
@@ -157,31 +155,30 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
157 | p->cfg = GNUNET_CONFIGURATION_create (); | 155 | p->cfg = GNUNET_CONFIGURATION_create (); |
158 | #if START_ARM | 156 | #if START_ARM |
159 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 157 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
160 | "gnunet-service-arm", | 158 | "gnunet-service-arm", |
161 | #if VERBOSE | 159 | #if VERBOSE |
162 | "-L", "DEBUG", | 160 | "-L", "DEBUG", |
163 | #endif | 161 | #endif |
164 | "-c", cfgname, NULL); | 162 | "-c", cfgname, NULL); |
165 | #endif | 163 | #endif |
166 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 164 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
167 | } | 165 | } |
168 | 166 | ||
169 | 167 | ||
170 | static void | 168 | static void |
171 | timeout_task (void *cls, | 169 | timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
172 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
173 | { | 170 | { |
174 | fprintf (stderr, "Timeout.\n"); | 171 | fprintf (stderr, "Timeout.\n"); |
175 | if (p1.ch != NULL) | 172 | if (p1.ch != NULL) |
176 | { | 173 | { |
177 | GNUNET_CORE_disconnect (p1.ch); | 174 | GNUNET_CORE_disconnect (p1.ch); |
178 | p1.ch = NULL; | 175 | p1.ch = NULL; |
179 | } | 176 | } |
180 | if (p2.ch != NULL) | 177 | if (p2.ch != NULL) |
181 | { | 178 | { |
182 | GNUNET_CORE_disconnect (p2.ch); | 179 | GNUNET_CORE_disconnect (p2.ch); |
183 | p2.ch = NULL; | 180 | p2.ch = NULL; |
184 | } | 181 | } |
185 | ok = 42; | 182 | ok = 42; |
186 | } | 183 | } |
187 | 184 | ||
@@ -190,39 +187,35 @@ timeout_task (void *cls, | |||
190 | static void | 187 | static void |
191 | run (void *cls, | 188 | run (void *cls, |
192 | char *const *args, | 189 | char *const *args, |
193 | const char *cfgfile, | 190 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
194 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
195 | { | 191 | { |
196 | GNUNET_assert (ok == 1); | 192 | GNUNET_assert (ok == 1); |
197 | OKPP; | 193 | OKPP; |
198 | setup_peer (&p1, "test_core_api_peer1.conf"); | 194 | setup_peer (&p1, "test_core_api_peer1.conf"); |
199 | setup_peer (&p2, "test_core_api_peer2.conf"); | 195 | setup_peer (&p2, "test_core_api_peer2.conf"); |
200 | timeout_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, TIMEOUT), | 196 | timeout_task_id = |
201 | &timeout_task, | 197 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
202 | NULL); | 198 | (GNUNET_TIME_UNIT_MINUTES, TIMEOUT), |
203 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, | 199 | &timeout_task, NULL); |
204 | &p1, | 200 | p1.ch = |
205 | &init_notify, | 201 | GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, |
206 | &connect_notify, | 202 | &disconnect_notify, NULL, &inbound_notify, |
207 | &disconnect_notify, | 203 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
208 | NULL, | ||
209 | &inbound_notify, | ||
210 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
211 | } | 204 | } |
212 | 205 | ||
213 | 206 | ||
214 | static void | 207 | static void |
215 | stop_arm (struct PeerContext *p) | 208 | stop_arm (struct PeerContext *p) |
216 | { | 209 | { |
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); |
218 | "Stopping peer\n"); | ||
219 | #if START_ARM | 211 | #if START_ARM |
220 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 212 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
221 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 213 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
222 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 214 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
223 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 215 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
225 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 217 | "ARM process %u stopped\n", |
218 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
226 | GNUNET_OS_process_close (p->arm_proc); | 219 | GNUNET_OS_process_close (p->arm_proc); |
227 | p->arm_proc = NULL; | 220 | p->arm_proc = NULL; |
228 | #endif | 221 | #endif |
@@ -249,9 +242,9 @@ check () | |||
249 | 242 | ||
250 | ok = 1; | 243 | ok = 1; |
251 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 244 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
252 | argv, "test-core-api-start-only", "nohelp", options, &run, &ok); | 245 | argv, "test-core-api-start-only", "nohelp", options, &run, |
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 246 | &ok); |
254 | "Test finished\n"); | 247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test finished\n"); |
255 | stop_arm (&p1); | 248 | stop_arm (&p1); |
256 | stop_arm (&p2); | 249 | stop_arm (&p2); |
257 | return ok; | 250 | return ok; |
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index 03a7c62eb..5dcc20597 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -77,7 +77,7 @@ struct PeerContext | |||
77 | { | 77 | { |
78 | struct GNUNET_CONFIGURATION_Handle *cfg; | 78 | struct GNUNET_CONFIGURATION_Handle *cfg; |
79 | struct GNUNET_CORE_Handle *ch; | 79 | struct GNUNET_CORE_Handle *ch; |
80 | struct GNUNET_PeerIdentity id; | 80 | struct GNUNET_PeerIdentity id; |
81 | struct GNUNET_TRANSPORT_Handle *th; | 81 | struct GNUNET_TRANSPORT_Handle *th; |
82 | struct GNUNET_MessageHeader *hello; | 82 | struct GNUNET_MessageHeader *hello; |
83 | struct GNUNET_STATISTICS_Handle *stats; | 83 | struct GNUNET_STATISTICS_Handle *stats; |
@@ -108,13 +108,14 @@ static int running; | |||
108 | #define OKPP do { ok++; } while (0) | 108 | #define OKPP do { ok++; } while (0) |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | struct TestMessage | 111 | struct TestMessage |
112 | { | 112 | { |
113 | struct GNUNET_MessageHeader header; | 113 | struct GNUNET_MessageHeader header; |
114 | uint32_t num; | 114 | uint32_t num; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | static void process_hello (void *cls, const struct GNUNET_MessageHeader *message); | 117 | static void process_hello (void *cls, |
118 | const struct GNUNET_MessageHeader *message); | ||
118 | 119 | ||
119 | static void | 120 | static void |
120 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 121 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -140,11 +141,11 @@ static void | |||
140 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 141 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
141 | { | 142 | { |
142 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 143 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); | 144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); |
144 | //GNUNET_break (0); | 145 | //GNUNET_break (0); |
145 | 146 | ||
146 | if (measure_task != GNUNET_SCHEDULER_NO_TASK) | 147 | if (measure_task != GNUNET_SCHEDULER_NO_TASK) |
147 | GNUNET_SCHEDULER_cancel(measure_task); | 148 | GNUNET_SCHEDULER_cancel (measure_task); |
148 | 149 | ||
149 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | 150 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); |
150 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | 151 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); |
@@ -173,21 +174,15 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
173 | */ | 174 | */ |
174 | static int | 175 | static int |
175 | print_stat (void *cls, | 176 | print_stat (void *cls, |
176 | const char *subsystem, | 177 | const char *subsystem, |
177 | const char *name, | 178 | const char *name, uint64_t value, int is_persistent) |
178 | uint64_t value, | ||
179 | int is_persistent) | ||
180 | { | 179 | { |
181 | if (cls==&p1) | 180 | if (cls == &p1) |
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
183 | "Peer1 %50s = %12llu\n", | 182 | "Peer1 %50s = %12llu\n", name, (unsigned long long) value); |
184 | name, | 183 | if (cls == &p2) |
185 | (unsigned long long) value); | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
186 | if (cls==&p2) | 185 | "Peer2 %50s = %12llu\n", name, (unsigned long long) value); |
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
188 | "Peer2 %50s = %12llu\n", | ||
189 | name, | ||
190 | (unsigned long long) value); | ||
191 | return GNUNET_OK; | 186 | return GNUNET_OK; |
192 | } | 187 | } |
193 | 188 | ||
@@ -202,7 +197,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
202 | unsigned long long int quota_delta; | 197 | unsigned long long int quota_delta; |
203 | 198 | ||
204 | measure_task = GNUNET_SCHEDULER_NO_TASK; | 199 | measure_task = GNUNET_SCHEDULER_NO_TASK; |
205 | fprintf(stdout,"\n"); | 200 | fprintf (stdout, "\n"); |
206 | running = GNUNET_NO; | 201 | running = GNUNET_NO; |
207 | 202 | ||
208 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | 203 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; |
@@ -211,96 +206,91 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
211 | throughput_in = total_bytes_recv * 1000 / 1024 / delta; | 206 | throughput_in = total_bytes_recv * 1000 / 1024 / delta; |
212 | 207 | ||
213 | if (current_quota_p1_in < current_quota_p2_in) | 208 | if (current_quota_p1_in < current_quota_p2_in) |
214 | max_quota_in = current_quota_p1_in; | 209 | max_quota_in = current_quota_p1_in; |
215 | else | 210 | else |
216 | max_quota_in = current_quota_p2_in; | 211 | max_quota_in = current_quota_p2_in; |
217 | if (current_quota_p1_out < current_quota_p2_out) | 212 | if (current_quota_p1_out < current_quota_p2_out) |
218 | max_quota_out = current_quota_p1_out; | 213 | max_quota_out = current_quota_p1_out; |
219 | else | 214 | else |
220 | max_quota_out = current_quota_p2_out; | 215 | max_quota_out = current_quota_p2_out; |
221 | 216 | ||
222 | if (max_quota_out < max_quota_in) | 217 | if (max_quota_out < max_quota_in) |
223 | quota_delta = max_quota_in / 10; | 218 | quota_delta = max_quota_in / 10; |
224 | else | 219 | else |
225 | quota_delta = max_quota_out / 10; | 220 | quota_delta = max_quota_out / 10; |
226 | 221 | ||
227 | if ((throughput_out > (max_quota_out+quota_delta)/1024) || (throughput_in > (max_quota_in+quota_delta)/1024)) | 222 | if ((throughput_out > (max_quota_out + quota_delta) / 1024) || |
228 | ok = 1; | 223 | (throughput_in > (max_quota_in + quota_delta) / 1024)) |
224 | ok = 1; | ||
229 | else | 225 | else |
230 | ok = 0; | 226 | ok = 0; |
231 | 227 | ||
232 | GNUNET_STATISTICS_get (p1.stats, | 228 | GNUNET_STATISTICS_get (p1.stats, |
233 | "core", | 229 | "core", |
234 | "# discarded CORE_SEND requests", | 230 | "# discarded CORE_SEND requests", |
235 | GNUNET_TIME_UNIT_FOREVER_REL, | 231 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); |
236 | NULL, | ||
237 | &print_stat, &p1); | ||
238 | 232 | ||
239 | GNUNET_STATISTICS_get (p1.stats, | 233 | GNUNET_STATISTICS_get (p1.stats, |
240 | "core", | 234 | "core", |
241 | "# discarded CORE_SEND request bytes", | 235 | "# discarded CORE_SEND request bytes", |
242 | GNUNET_TIME_UNIT_FOREVER_REL, | 236 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); |
243 | NULL, | ||
244 | &print_stat, &p1); | ||
245 | GNUNET_STATISTICS_get (p1.stats, | 237 | GNUNET_STATISTICS_get (p1.stats, |
246 | "core", | 238 | "core", |
247 | "# discarded lower priority CORE_SEND requests", | 239 | "# discarded lower priority CORE_SEND requests", |
248 | GNUNET_TIME_UNIT_FOREVER_REL, | 240 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL); |
249 | NULL, | ||
250 | &print_stat, NULL); | ||
251 | GNUNET_STATISTICS_get (p1.stats, | 241 | GNUNET_STATISTICS_get (p1.stats, |
252 | "core", | 242 | "core", |
253 | "# discarded lower priority CORE_SEND request bytes", | 243 | "# discarded lower priority CORE_SEND request bytes", |
254 | GNUNET_TIME_UNIT_FOREVER_REL, | 244 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1); |
255 | NULL, | ||
256 | &print_stat, &p1); | ||
257 | GNUNET_STATISTICS_get (p2.stats, | 245 | GNUNET_STATISTICS_get (p2.stats, |
258 | "core", | 246 | "core", |
259 | "# discarded CORE_SEND requests", | 247 | "# discarded CORE_SEND requests", |
260 | GNUNET_TIME_UNIT_FOREVER_REL, | 248 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); |
261 | NULL, | ||
262 | &print_stat, &p2); | ||
263 | 249 | ||
264 | GNUNET_STATISTICS_get (p2.stats, | 250 | GNUNET_STATISTICS_get (p2.stats, |
265 | "core", | 251 | "core", |
266 | "# discarded CORE_SEND request bytes", | 252 | "# discarded CORE_SEND request bytes", |
267 | GNUNET_TIME_UNIT_FOREVER_REL, | 253 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); |
268 | NULL, | ||
269 | &print_stat, &p2); | ||
270 | GNUNET_STATISTICS_get (p2.stats, | 254 | GNUNET_STATISTICS_get (p2.stats, |
271 | "core", | 255 | "core", |
272 | "# discarded lower priority CORE_SEND requests", | 256 | "# discarded lower priority CORE_SEND requests", |
273 | GNUNET_TIME_UNIT_FOREVER_REL, | 257 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); |
274 | NULL, | ||
275 | &print_stat, &p2); | ||
276 | GNUNET_STATISTICS_get (p2.stats, | 258 | GNUNET_STATISTICS_get (p2.stats, |
277 | "core", | 259 | "core", |
278 | "# discarded lower priority CORE_SEND request bytes", | 260 | "# discarded lower priority CORE_SEND request bytes", |
279 | GNUNET_TIME_UNIT_FOREVER_REL, | 261 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); |
280 | NULL, | ||
281 | &print_stat, &p2); | ||
282 | 262 | ||
283 | enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; | 263 | enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; |
284 | if (ok==1) | 264 | |
265 | if (ok == 1) | ||
285 | { | 266 | { |
286 | kind = GNUNET_ERROR_TYPE_ERROR; | 267 | kind = GNUNET_ERROR_TYPE_ERROR; |
287 | } | 268 | } |
288 | switch (test) | 269 | switch (test) |
289 | { | 270 | { |
290 | case SYMMETRIC: | 271 | case SYMMETRIC: |
291 | GNUNET_log (kind,"Core quota compliance test with symmetric quotas: %s\n", (ok==0)?"PASSED":"FAILED"); | 272 | GNUNET_log (kind, "Core quota compliance test with symmetric quotas: %s\n", |
292 | break; | 273 | (ok == 0) ? "PASSED" : "FAILED"); |
274 | break; | ||
293 | case ASYMMETRIC_SEND_LIMITED: | 275 | case ASYMMETRIC_SEND_LIMITED: |
294 | GNUNET_log (kind,"Core quota compliance test with limited sender quota: %s\n", (ok==0)?"PASSED":"FAILED"); | 276 | GNUNET_log (kind, |
295 | break; | 277 | "Core quota compliance test with limited sender quota: %s\n", |
278 | (ok == 0) ? "PASSED" : "FAILED"); | ||
279 | break; | ||
296 | case ASYMMETRIC_RECV_LIMITED: | 280 | case ASYMMETRIC_RECV_LIMITED: |
297 | GNUNET_log (kind,"Core quota compliance test with limited receiver quota: %s\n", (ok==0)?"PASSED":"FAILED"); | 281 | GNUNET_log (kind, |
298 | break; | 282 | "Core quota compliance test with limited receiver quota: %s\n", |
283 | (ok == 0) ? "PASSED" : "FAILED"); | ||
284 | break; | ||
299 | }; | 285 | }; |
300 | GNUNET_log (kind,"Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_out,total_bytes_sent, delta/1000); | 286 | GNUNET_log (kind, "Peer 1 send rate: %llu kB/s (%llu Bytes in %u sec.)\n", |
301 | GNUNET_log (kind,"Peer 1 send quota: %llu kB/s\n",current_quota_p1_out / 1024); | 287 | throughput_out, total_bytes_sent, delta / 1000); |
302 | GNUNET_log (kind,"Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n",throughput_in,total_bytes_recv, delta/1000); | 288 | GNUNET_log (kind, "Peer 1 send quota: %llu kB/s\n", |
303 | GNUNET_log (kind,"Peer 2 receive quota: %llu kB/s\n",current_quota_p2_in / 1024); | 289 | current_quota_p1_out / 1024); |
290 | GNUNET_log (kind, "Peer 2 receive rate: %llu kB/s (%llu Bytes in %u sec.)\n", | ||
291 | throughput_in, total_bytes_recv, delta / 1000); | ||
292 | GNUNET_log (kind, "Peer 2 receive quota: %llu kB/s\n", | ||
293 | current_quota_p2_in / 1024); | ||
304 | /* | 294 | /* |
305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kB/s\n",max_quota_in /1024); | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu kB/s\n",max_quota_in /1024); |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); | 296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024); |
@@ -319,49 +309,45 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
319 | 309 | ||
320 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | 310 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); |
321 | if (buf == NULL) | 311 | if (buf == NULL) |
322 | { | 312 | { |
323 | if ( (p1.ch != NULL) && | 313 | if ((p1.ch != NULL) && (p1.connect_status == 1)) |
324 | (p1.connect_status == 1) ) | 314 | GNUNET_break (NULL != |
325 | GNUNET_break (NULL != | 315 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
326 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 316 | GNUNET_NO, |
327 | GNUNET_NO, | 317 | 0, |
328 | 0, | 318 | FAST_TIMEOUT, |
329 | FAST_TIMEOUT, | 319 | &p2.id, |
330 | &p2.id, | 320 | MESSAGESIZE, |
331 | MESSAGESIZE, | 321 | &transmit_ready, &p1)); |
332 | &transmit_ready, &p1)); | 322 | return 0; |
333 | return 0; | 323 | } |
334 | } | ||
335 | GNUNET_assert (tr_n < TOTAL_MSGS); | 324 | GNUNET_assert (tr_n < TOTAL_MSGS); |
336 | ret = 0; | 325 | ret = 0; |
337 | GNUNET_assert (size >= MESSAGESIZE); | 326 | GNUNET_assert (size >= MESSAGESIZE); |
338 | GNUNET_assert (buf != NULL); | 327 | GNUNET_assert (buf != NULL); |
339 | cbuf = buf; | 328 | cbuf = buf; |
340 | do | 329 | do |
341 | { | 330 | { |
342 | #if DEBUG_TRANSMISSION | 331 | #if DEBUG_TRANSMISSION |
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
344 | "Sending message %u of size %u at offset %u\n", | 333 | "Sending message %u of size %u at offset %u\n", |
345 | tr_n, | 334 | tr_n, MESSAGESIZE, ret); |
346 | MESSAGESIZE, | ||
347 | ret); | ||
348 | #endif | 335 | #endif |
349 | hdr.header.size = htons (MESSAGESIZE); | 336 | hdr.header.size = htons (MESSAGESIZE); |
350 | hdr.header.type = htons (MTYPE); | 337 | hdr.header.type = htons (MTYPE); |
351 | hdr.num = htonl (tr_n); | 338 | hdr.num = htonl (tr_n); |
352 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 339 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
353 | ret += sizeof (struct TestMessage); | 340 | ret += sizeof (struct TestMessage); |
354 | memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage)); | 341 | memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage)); |
355 | ret += MESSAGESIZE - sizeof (struct TestMessage); | 342 | ret += MESSAGESIZE - sizeof (struct TestMessage); |
356 | tr_n++; | 343 | tr_n++; |
357 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 344 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
358 | break; /* sometimes pack buffer full, sometimes not */ | 345 | break; /* sometimes pack buffer full, sometimes not */ |
359 | } | 346 | } |
360 | while (size - ret >= MESSAGESIZE); | 347 | while (size - ret >= MESSAGESIZE); |
361 | GNUNET_SCHEDULER_cancel (err_task); | 348 | GNUNET_SCHEDULER_cancel (err_task); |
362 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 349 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
363 | &terminate_task_error, | 350 | &terminate_task_error, NULL); |
364 | NULL); | ||
365 | 351 | ||
366 | total_bytes_sent += ret; | 352 | total_bytes_sent += ret; |
367 | return ret; | 353 | return ret; |
@@ -376,50 +362,48 @@ connect_notify (void *cls, | |||
376 | { | 362 | { |
377 | struct PeerContext *pc = cls; | 363 | struct PeerContext *pc = cls; |
378 | 364 | ||
379 | if (0 == memcmp (&pc->id, | 365 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
380 | peer, | ||
381 | sizeof (struct GNUNET_PeerIdentity))) | ||
382 | return; | 366 | return; |
383 | GNUNET_assert (pc->connect_status == 0); | 367 | GNUNET_assert (pc->connect_status == 0); |
384 | pc->connect_status = 1; | 368 | pc->connect_status = 1; |
385 | if (pc == &p1) | 369 | if (pc == &p1) |
386 | { | 370 | { |
387 | #if DEBUG_TRANSMISSION | 371 | #if DEBUG_TRANSMISSION |
388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
389 | "Encrypted connection established to peer `%4s'\n", | 373 | "Encrypted connection established to peer `%4s'\n", |
390 | GNUNET_i2s (peer)); | 374 | GNUNET_i2s (peer)); |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
392 | "Asking core (1) for transmission to peer `%4s'\n", | 376 | "Asking core (1) for transmission to peer `%4s'\n", |
393 | GNUNET_i2s (&p2.id)); | 377 | GNUNET_i2s (&p2.id)); |
394 | #endif | 378 | #endif |
395 | if (err_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (err_task); | 379 | if (err_task != GNUNET_SCHEDULER_NO_TASK) |
396 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 380 | GNUNET_SCHEDULER_cancel (err_task); |
397 | &terminate_task_error, | 381 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
398 | NULL); | 382 | &terminate_task_error, NULL); |
399 | start_time = GNUNET_TIME_absolute_get (); | 383 | start_time = GNUNET_TIME_absolute_get (); |
400 | running = GNUNET_YES; | 384 | running = GNUNET_YES; |
401 | measure_task = GNUNET_SCHEDULER_add_delayed(MEASUREMENT_LENGTH, &measurement_stop, NULL); | 385 | measure_task = |
402 | 386 | GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop, | |
403 | GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch, | 387 | NULL); |
404 | GNUNET_NO, | 388 | |
405 | 0, | 389 | GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch, |
406 | TIMEOUT, | 390 | GNUNET_NO, |
407 | &p2.id, | 391 | 0, |
408 | MESSAGESIZE, | 392 | TIMEOUT, |
409 | &transmit_ready, &p1)); | 393 | &p2.id, |
410 | } | 394 | MESSAGESIZE, |
395 | &transmit_ready, | ||
396 | &p1)); | ||
397 | } | ||
411 | } | 398 | } |
412 | 399 | ||
413 | 400 | ||
414 | static void | 401 | static void |
415 | disconnect_notify (void *cls, | 402 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
416 | const struct GNUNET_PeerIdentity *peer) | ||
417 | { | 403 | { |
418 | struct PeerContext *pc = cls; | 404 | struct PeerContext *pc = cls; |
419 | 405 | ||
420 | if (0 == memcmp (&pc->id, | 406 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
421 | peer, | ||
422 | sizeof (struct GNUNET_PeerIdentity))) | ||
423 | return; | 407 | return; |
424 | pc->connect_status = 0; | 408 | pc->connect_status = 0; |
425 | #if DEBUG_TRANSMISSION | 409 | #if DEBUG_TRANSMISSION |
@@ -433,13 +417,14 @@ static int | |||
433 | inbound_notify (void *cls, | 417 | inbound_notify (void *cls, |
434 | const struct GNUNET_PeerIdentity *other, | 418 | const struct GNUNET_PeerIdentity *other, |
435 | const struct GNUNET_MessageHeader *message, | 419 | const struct GNUNET_MessageHeader *message, |
436 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 420 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
437 | { | 421 | { |
438 | #if DEBUG_TRANSMISSION | 422 | #if DEBUG_TRANSMISSION |
439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
440 | "Core provides inbound data from `%4s' %llu.\n", GNUNET_i2s (other), ntohs(message->size)); | 424 | "Core provides inbound data from `%4s' %llu.\n", |
425 | GNUNET_i2s (other), ntohs (message->size)); | ||
441 | #endif | 426 | #endif |
442 | total_bytes_recv += ntohs(message->size); | 427 | total_bytes_recv += ntohs (message->size); |
443 | return GNUNET_OK; | 428 | return GNUNET_OK; |
444 | } | 429 | } |
445 | 430 | ||
@@ -448,7 +433,7 @@ static int | |||
448 | outbound_notify (void *cls, | 433 | outbound_notify (void *cls, |
449 | const struct GNUNET_PeerIdentity *other, | 434 | const struct GNUNET_PeerIdentity *other, |
450 | const struct GNUNET_MessageHeader *message, | 435 | const struct GNUNET_MessageHeader *message, |
451 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 436 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
452 | { | 437 | { |
453 | #if DEBUG_TRANSMISSION | 438 | #if DEBUG_TRANSMISSION |
454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -459,48 +444,42 @@ outbound_notify (void *cls, | |||
459 | } | 444 | } |
460 | 445 | ||
461 | 446 | ||
462 | static size_t | 447 | static size_t transmit_ready (void *cls, size_t size, void *buf); |
463 | transmit_ready (void *cls, size_t size, void *buf); | ||
464 | 448 | ||
465 | static int | 449 | static int |
466 | process_mtype (void *cls, | 450 | process_mtype (void *cls, |
467 | const struct GNUNET_PeerIdentity *peer, | 451 | const struct GNUNET_PeerIdentity *peer, |
468 | const struct GNUNET_MessageHeader *message, | 452 | const struct GNUNET_MessageHeader *message, |
469 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 453 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
470 | { | 454 | { |
471 | static int n; | 455 | static int n; |
472 | const struct TestMessage *hdr; | 456 | const struct TestMessage *hdr; |
473 | 457 | ||
474 | hdr = (const struct TestMessage*) message; | 458 | hdr = (const struct TestMessage *) message; |
475 | if (MTYPE != ntohs (message->type)) | 459 | if (MTYPE != ntohs (message->type)) |
476 | return GNUNET_SYSERR; | 460 | return GNUNET_SYSERR; |
477 | if (ntohs (message->size) != MESSAGESIZE) | 461 | if (ntohs (message->size) != MESSAGESIZE) |
478 | { | 462 | { |
479 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 463 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
480 | "Expected message %u of size %u, got %u bytes of message %u\n", | 464 | "Expected message %u of size %u, got %u bytes of message %u\n", |
481 | n, MESSAGESIZE, | 465 | n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num)); |
482 | ntohs (message->size), | 466 | GNUNET_SCHEDULER_cancel (err_task); |
483 | ntohl (hdr->num)); | 467 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); |
484 | GNUNET_SCHEDULER_cancel (err_task); | 468 | return GNUNET_SYSERR; |
485 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); | 469 | } |
486 | return GNUNET_SYSERR; | ||
487 | } | ||
488 | if (ntohl (hdr->num) != n) | 470 | if (ntohl (hdr->num) != n) |
489 | { | 471 | { |
490 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 472 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
491 | "Expected message %u of size %u, got %u bytes of message %u\n", | 473 | "Expected message %u of size %u, got %u bytes of message %u\n", |
492 | n, MESSAGESIZE, | 474 | n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num)); |
493 | ntohs (message->size), | 475 | GNUNET_SCHEDULER_cancel (err_task); |
494 | ntohl (hdr->num)); | 476 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); |
495 | GNUNET_SCHEDULER_cancel (err_task); | 477 | return GNUNET_SYSERR; |
496 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); | 478 | } |
497 | return GNUNET_SYSERR; | ||
498 | } | ||
499 | #if DEBUG_TRANSMISSION | 479 | #if DEBUG_TRANSMISSION |
500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
501 | "Got message %u of size %u\n", | 481 | "Got message %u of size %u\n", |
502 | ntohl (hdr->num), | 482 | ntohl (hdr->num), ntohs (message->size)); |
503 | ntohs (message->size)); | ||
504 | #endif | 483 | #endif |
505 | n++; | 484 | n++; |
506 | if (0 == (n % 10)) | 485 | if (0 == (n % 10)) |
@@ -508,14 +487,14 @@ process_mtype (void *cls, | |||
508 | 487 | ||
509 | 488 | ||
510 | if (running == GNUNET_YES) | 489 | if (running == GNUNET_YES) |
511 | GNUNET_break (NULL != | 490 | GNUNET_break (NULL != |
512 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 491 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
513 | GNUNET_NO, | 492 | GNUNET_NO, |
514 | 0, | 493 | 0, |
515 | FAST_TIMEOUT, | 494 | FAST_TIMEOUT, |
516 | &p2.id, | 495 | &p2.id, |
517 | MESSAGESIZE, | 496 | MESSAGESIZE, |
518 | &transmit_ready, &p1)); | 497 | &transmit_ready, &p1)); |
519 | return GNUNET_OK; | 498 | return GNUNET_OK; |
520 | } | 499 | } |
521 | 500 | ||
@@ -542,48 +521,43 @@ init_notify (void *cls, | |||
542 | p->id = *my_identity; | 521 | p->id = *my_identity; |
543 | p->ch = server; | 522 | p->ch = server; |
544 | if (cls == &p1) | 523 | if (cls == &p1) |
545 | { | 524 | { |
546 | GNUNET_assert (ok == 2); | 525 | GNUNET_assert (ok == 2); |
547 | OKPP; | 526 | OKPP; |
548 | /* connect p2 */ | 527 | /* connect p2 */ |
549 | GNUNET_CORE_connect (p2.cfg, 1, | 528 | GNUNET_CORE_connect (p2.cfg, 1, |
550 | &p2, | 529 | &p2, |
551 | &init_notify, | 530 | &init_notify, |
552 | &connect_notify, | 531 | &connect_notify, |
553 | &disconnect_notify, | 532 | &disconnect_notify, |
554 | NULL, | 533 | NULL, |
555 | &inbound_notify, | 534 | &inbound_notify, |
556 | GNUNET_YES, | 535 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
557 | &outbound_notify, GNUNET_YES, handlers); | 536 | } |
558 | } | ||
559 | else | 537 | else |
560 | { | 538 | { |
561 | GNUNET_assert (ok == 3); | 539 | GNUNET_assert (ok == 3); |
562 | OKPP; | 540 | OKPP; |
563 | GNUNET_assert (cls == &p2); | 541 | GNUNET_assert (cls == &p2); |
564 | #if DEBUG_TRANSMISSION | 542 | #if DEBUG_TRANSMISSION |
565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
566 | "Asking core (1) to connect to peer `%4s'\n", | 544 | "Asking core (1) to connect to peer `%4s'\n", |
567 | GNUNET_i2s (&p2.id)); | 545 | GNUNET_i2s (&p2.id)); |
568 | #endif | 546 | #endif |
569 | GNUNET_CORE_peer_request_connect (p1.ch, | 547 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
570 | &p2.id, | 548 | } |
571 | NULL, NULL); | ||
572 | } | ||
573 | } | 549 | } |
574 | 550 | ||
575 | 551 | ||
576 | static void | 552 | static void |
577 | process_hello (void *cls, | 553 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
578 | const struct GNUNET_MessageHeader *message) | ||
579 | { | 554 | { |
580 | struct PeerContext *p = cls; | 555 | struct PeerContext *p = cls; |
581 | 556 | ||
582 | 557 | ||
583 | #if DEBUG_TRANSMISSION | 558 | #if DEBUG_TRANSMISSION |
584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Received (my) `%s' from transport service\n", | 560 | "Received (my) `%s' from transport service\n", "HELLO"); |
586 | "HELLO"); | ||
587 | #endif | 561 | #endif |
588 | GNUNET_assert (message != NULL); | 562 | GNUNET_assert (message != NULL); |
589 | p->hello = GNUNET_malloc (ntohs (message->size)); | 563 | p->hello = GNUNET_malloc (ntohs (message->size)); |
@@ -607,15 +581,15 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
607 | p->cfg = GNUNET_CONFIGURATION_create (); | 581 | p->cfg = GNUNET_CONFIGURATION_create (); |
608 | #if START_ARM | 582 | #if START_ARM |
609 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 583 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
610 | "gnunet-service-arm", | 584 | "gnunet-service-arm", |
611 | #if VERBOSE | 585 | #if VERBOSE |
612 | "-L", "DEBUG", | 586 | "-L", "DEBUG", |
613 | #endif | 587 | #endif |
614 | "-c", cfgname, NULL); | 588 | "-c", cfgname, NULL); |
615 | #endif | 589 | #endif |
616 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 590 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
617 | p->stats = GNUNET_STATISTICS_create ("core",p->cfg); | 591 | p->stats = GNUNET_STATISTICS_create ("core", p->cfg); |
618 | GNUNET_assert (p->stats!=NULL); | 592 | GNUNET_assert (p->stats != NULL); |
619 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 593 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
620 | GNUNET_assert (p->th != NULL); | 594 | GNUNET_assert (p->th != NULL); |
621 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 595 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
@@ -625,47 +599,45 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
625 | static void | 599 | static void |
626 | run (void *cls, | 600 | run (void *cls, |
627 | char *const *args, | 601 | char *const *args, |
628 | const char *cfgfile, | 602 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
629 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
630 | { | 603 | { |
631 | GNUNET_assert (ok == 1); | 604 | GNUNET_assert (ok == 1); |
632 | OKPP; | 605 | OKPP; |
633 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 606 | err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
634 | &terminate_task_error, | 607 | &terminate_task_error, NULL); |
635 | NULL); | ||
636 | if (test == SYMMETRIC) | 608 | if (test == SYMMETRIC) |
637 | { | 609 | { |
638 | setup_peer (&p1, "test_core_quota_peer1.conf"); | 610 | setup_peer (&p1, "test_core_quota_peer1.conf"); |
639 | setup_peer (&p2, "test_core_quota_peer2.conf"); | 611 | setup_peer (&p2, "test_core_quota_peer2.conf"); |
640 | } | 612 | } |
641 | else if (test == ASYMMETRIC_SEND_LIMITED) | 613 | else if (test == ASYMMETRIC_SEND_LIMITED) |
642 | { | 614 | { |
643 | setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf"); | 615 | setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf"); |
644 | setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf"); | 616 | setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf"); |
645 | } | 617 | } |
646 | else if (test == ASYMMETRIC_RECV_LIMITED) | 618 | else if (test == ASYMMETRIC_RECV_LIMITED) |
647 | { | 619 | { |
648 | setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); | 620 | setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); |
649 | setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); | 621 | setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); |
650 | } | 622 | } |
651 | 623 | ||
652 | GNUNET_assert (test != -1); | 624 | GNUNET_assert (test != -1); |
653 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, | 625 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, |
654 | "CORE", | 626 | "CORE", |
655 | "TOTAL_QUOTA_IN", | 627 | "TOTAL_QUOTA_IN", |
656 | ¤t_quota_p1_in)); | 628 | ¤t_quota_p1_in)); |
657 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, | 629 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, |
658 | "CORE", | 630 | "CORE", |
659 | "TOTAL_QUOTA_IN", | 631 | "TOTAL_QUOTA_IN", |
660 | ¤t_quota_p2_in)); | 632 | ¤t_quota_p2_in)); |
661 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, | 633 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg, |
662 | "CORE", | 634 | "CORE", |
663 | "TOTAL_QUOTA_OUT", | 635 | "TOTAL_QUOTA_OUT", |
664 | ¤t_quota_p1_out)); | 636 | ¤t_quota_p1_out)); |
665 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, | 637 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg, |
666 | "CORE", | 638 | "CORE", |
667 | "TOTAL_QUOTA_OUT", | 639 | "TOTAL_QUOTA_OUT", |
668 | ¤t_quota_p2_out)); | 640 | ¤t_quota_p2_out)); |
669 | 641 | ||
670 | GNUNET_CORE_connect (p1.cfg, 1, | 642 | GNUNET_CORE_connect (p1.cfg, 1, |
671 | &p1, | 643 | &p1, |
@@ -684,10 +656,11 @@ stop_arm (struct PeerContext *p) | |||
684 | #if START_ARM | 656 | #if START_ARM |
685 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 657 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
686 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 658 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
687 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 659 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
688 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 660 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
690 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 662 | "ARM process %u stopped\n", |
663 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
691 | GNUNET_OS_process_close (p->arm_proc); | 664 | GNUNET_OS_process_close (p->arm_proc); |
692 | p->arm_proc = NULL; | 665 | p->arm_proc = NULL; |
693 | #endif | 666 | #endif |
@@ -712,7 +685,8 @@ check () | |||
712 | }; | 685 | }; |
713 | ok = 1; | 686 | ok = 1; |
714 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 687 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
715 | argv, "test-core-quota-compliance", "nohelp", options, &run, &ok); | 688 | argv, "test-core-quota-compliance", "nohelp", options, |
689 | &run, &ok); | ||
716 | stop_arm (&p1); | 690 | stop_arm (&p1); |
717 | stop_arm (&p2); | 691 | stop_arm (&p2); |
718 | return ok; | 692 | return ok; |
@@ -724,34 +698,38 @@ main (int argc, char *argv[]) | |||
724 | int ret; | 698 | int ret; |
725 | 699 | ||
726 | test = -1; | 700 | test = -1; |
727 | if (strstr(argv[0], "_symmetric") != NULL) | 701 | if (strstr (argv[0], "_symmetric") != NULL) |
728 | { | 702 | { |
729 | test = SYMMETRIC; | 703 | test = SYMMETRIC; |
730 | } | 704 | } |
731 | else if (strstr(argv[0], "_asymmetric_send") != NULL) | 705 | else if (strstr (argv[0], "_asymmetric_send") != NULL) |
732 | { | 706 | { |
733 | test = ASYMMETRIC_SEND_LIMITED; | 707 | test = ASYMMETRIC_SEND_LIMITED; |
734 | } | 708 | } |
735 | else if (strstr(argv[0], "_asymmetric_recv") != NULL) | 709 | else if (strstr (argv[0], "_asymmetric_recv") != NULL) |
736 | { | 710 | { |
737 | test = ASYMMETRIC_RECV_LIMITED; | 711 | test = ASYMMETRIC_RECV_LIMITED; |
738 | } | 712 | } |
739 | GNUNET_assert (test != -1); | 713 | GNUNET_assert (test != -1); |
740 | if (test == SYMMETRIC) | 714 | if (test == SYMMETRIC) |
741 | { | 715 | { |
742 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); | 716 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); |
743 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); | 717 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); |
744 | } | 718 | } |
745 | else if (test == ASYMMETRIC_SEND_LIMITED) | 719 | else if (test == ASYMMETRIC_SEND_LIMITED) |
746 | { | 720 | { |
747 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); | 721 | GNUNET_DISK_directory_remove |
748 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); | 722 | ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); |
749 | } | 723 | GNUNET_DISK_directory_remove |
724 | ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); | ||
725 | } | ||
750 | else if (test == ASYMMETRIC_RECV_LIMITED) | 726 | else if (test == ASYMMETRIC_RECV_LIMITED) |
751 | { | 727 | { |
752 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); | 728 | GNUNET_DISK_directory_remove |
753 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); | 729 | ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); |
754 | } | 730 | GNUNET_DISK_directory_remove |
731 | ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); | ||
732 | } | ||
755 | 733 | ||
756 | GNUNET_log_setup ("test-core-quota-compliance", | 734 | GNUNET_log_setup ("test-core-quota-compliance", |
757 | #if VERBOSE | 735 | #if VERBOSE |
@@ -762,23 +740,28 @@ main (int argc, char *argv[]) | |||
762 | NULL); | 740 | NULL); |
763 | ret = check (); | 741 | ret = check (); |
764 | if (test == SYMMETRIC) | 742 | if (test == SYMMETRIC) |
765 | { | 743 | { |
766 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); | 744 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); |
767 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); | 745 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); |
768 | } | 746 | } |
769 | else if (test == ASYMMETRIC_SEND_LIMITED) | 747 | else if (test == ASYMMETRIC_SEND_LIMITED) |
770 | { | 748 | { |
771 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); | 749 | GNUNET_DISK_directory_remove |
772 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); | 750 | ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); |
773 | } | 751 | GNUNET_DISK_directory_remove |
752 | ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); | ||
753 | } | ||
774 | else if (test == ASYMMETRIC_RECV_LIMITED) | 754 | else if (test == ASYMMETRIC_RECV_LIMITED) |
775 | { | 755 | { |
776 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); | 756 | GNUNET_DISK_directory_remove |
777 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); | 757 | ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); |
778 | } | 758 | GNUNET_DISK_directory_remove |
759 | ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); | ||
760 | } | ||
779 | 761 | ||
780 | 762 | ||
781 | 763 | ||
782 | return ret; | 764 | return ret; |
783 | } | 765 | } |
766 | |||
784 | /* end of test_core_api_reliability.c */ | 767 | /* end of test_core_api_reliability.c */ |