diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet/gnunet-service-cadet_channel.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet/gnunet-service-cadet_channel.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.c | 1874 |
1 files changed, 940 insertions, 934 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index dad5325fc..0a261039c 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -41,26 +41,26 @@ | |||
41 | #include "gnunet-service-cadet_tunnels.h" | 41 | #include "gnunet-service-cadet_tunnels.h" |
42 | #include "gnunet-service-cadet_paths.h" | 42 | #include "gnunet-service-cadet_paths.h" |
43 | 43 | ||
44 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-chn", __VA_ARGS__) | 44 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-chn", __VA_ARGS__) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * How long do we initially wait before retransmitting? | 47 | * How long do we initially wait before retransmitting? |
48 | */ | 48 | */ |
49 | #define CADET_INITIAL_RETRANSMIT_TIME \ | 49 | #define CADET_INITIAL_RETRANSMIT_TIME \ |
50 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) | 50 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * How long do we wait before dropping state about incoming | 53 | * How long do we wait before dropping state about incoming |
54 | * connection to closed port? | 54 | * connection to closed port? |
55 | */ | 55 | */ |
56 | #define TIMEOUT_CLOSED_PORT \ | 56 | #define TIMEOUT_CLOSED_PORT \ |
57 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 57 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * How long do we wait at least before retransmitting ever? | 60 | * How long do we wait at least before retransmitting ever? |
61 | */ | 61 | */ |
62 | #define MIN_RTT_DELAY \ | 62 | #define MIN_RTT_DELAY \ |
63 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 75) | 63 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75) |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Maximum message ID into the future we accept for out-of-order messages. | 66 | * Maximum message ID into the future we accept for out-of-order messages. |
@@ -78,7 +78,8 @@ | |||
78 | /** | 78 | /** |
79 | * All the states a channel can be in. | 79 | * All the states a channel can be in. |
80 | */ | 80 | */ |
81 | enum CadetChannelState { | 81 | enum CadetChannelState |
82 | { | ||
82 | /** | 83 | /** |
83 | * Uninitialized status, should never appear in operation. | 84 | * Uninitialized status, should never appear in operation. |
84 | */ | 85 | */ |
@@ -107,7 +108,8 @@ enum CadetChannelState { | |||
107 | * Note that we DO use this structure also for unreliable | 108 | * Note that we DO use this structure also for unreliable |
108 | * messages. | 109 | * messages. |
109 | */ | 110 | */ |
110 | struct CadetReliableMessage { | 111 | struct CadetReliableMessage |
112 | { | ||
111 | /** | 113 | /** |
112 | * Double linked list, FIFO style | 114 | * Double linked list, FIFO style |
113 | */ | 115 | */ |
@@ -171,7 +173,8 @@ struct CadetReliableMessage { | |||
171 | /** | 173 | /** |
172 | * List of received out-of-order data messages. | 174 | * List of received out-of-order data messages. |
173 | */ | 175 | */ |
174 | struct CadetOutOfOrderMessage { | 176 | struct CadetOutOfOrderMessage |
177 | { | ||
175 | /** | 178 | /** |
176 | * Double linked list, FIFO style | 179 | * Double linked list, FIFO style |
177 | */ | 180 | */ |
@@ -200,7 +203,8 @@ struct CadetOutOfOrderMessage { | |||
200 | * loopback channel, in which case it has two of these endpoints. | 203 | * loopback channel, in which case it has two of these endpoints. |
201 | * Note that flow control also is required in both directions. | 204 | * Note that flow control also is required in both directions. |
202 | */ | 205 | */ |
203 | struct CadetChannelClient { | 206 | struct CadetChannelClient |
207 | { | ||
204 | /** | 208 | /** |
205 | * Client handle. Not by itself sufficient to designate | 209 | * Client handle. Not by itself sufficient to designate |
206 | * the client endpoint, as the same client handle may | 210 | * the client endpoint, as the same client handle may |
@@ -241,7 +245,8 @@ struct CadetChannelClient { | |||
241 | /** | 245 | /** |
242 | * Struct containing all information regarding a channel to a remote client. | 246 | * Struct containing all information regarding a channel to a remote client. |
243 | */ | 247 | */ |
244 | struct CadetChannel { | 248 | struct CadetChannel |
249 | { | ||
245 | /** | 250 | /** |
246 | * Tunnel this channel is in. | 251 | * Tunnel this channel is in. |
247 | */ | 252 | */ |
@@ -386,24 +391,24 @@ struct CadetChannel { | |||
386 | * @return Static string with the channel IDs. | 391 | * @return Static string with the channel IDs. |
387 | */ | 392 | */ |
388 | const char * | 393 | const char * |
389 | GCCH_2s(const struct CadetChannel *ch) | 394 | GCCH_2s (const struct CadetChannel *ch) |
390 | { | 395 | { |
391 | static char buf[128]; | 396 | static char buf[128]; |
392 | 397 | ||
393 | GNUNET_snprintf(buf, | 398 | GNUNET_snprintf (buf, |
394 | sizeof(buf), | 399 | sizeof(buf), |
395 | "Channel %s:%s ctn:%X(%X/%X)", | 400 | "Channel %s:%s ctn:%X(%X/%X)", |
396 | (GNUNET_YES == ch->is_loopback) | 401 | (GNUNET_YES == ch->is_loopback) |
397 | ? "loopback" | 402 | ? "loopback" |
398 | : GNUNET_i2s(GCP_get_id(GCT_get_destination(ch->t))), | 403 | : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), |
399 | GNUNET_h2s(&ch->port), | 404 | GNUNET_h2s (&ch->port), |
400 | ch->ctn, | 405 | ch->ctn, |
401 | (NULL == ch->owner) | 406 | (NULL == ch->owner) |
402 | ? 0 | 407 | ? 0 |
403 | : ntohl(ch->owner->ccn.channel_of_client), | 408 | : ntohl (ch->owner->ccn.channel_of_client), |
404 | (NULL == ch->dest) | 409 | (NULL == ch->dest) |
405 | ? 0 | 410 | ? 0 |
406 | : ntohl(ch->dest->ccn.channel_of_client)); | 411 | : ntohl (ch->dest->ccn.channel_of_client)); |
407 | return buf; | 412 | return buf; |
408 | } | 413 | } |
409 | 414 | ||
@@ -418,19 +423,19 @@ GCCH_2s(const struct CadetChannel *ch) | |||
418 | * @param listener peer that is listining on @a port | 423 | * @param listener peer that is listining on @a port |
419 | */ | 424 | */ |
420 | void | 425 | void |
421 | GCCH_hash_port(struct GNUNET_HashCode *h_port, | 426 | GCCH_hash_port (struct GNUNET_HashCode *h_port, |
422 | const struct GNUNET_HashCode *port, | 427 | const struct GNUNET_HashCode *port, |
423 | const struct GNUNET_PeerIdentity *listener) | 428 | const struct GNUNET_PeerIdentity *listener) |
424 | { | 429 | { |
425 | struct GNUNET_HashContext *hc; | 430 | struct GNUNET_HashContext *hc; |
426 | 431 | ||
427 | hc = GNUNET_CRYPTO_hash_context_start(); | 432 | hc = GNUNET_CRYPTO_hash_context_start (); |
428 | GNUNET_CRYPTO_hash_context_read(hc, port, sizeof(*port)); | 433 | GNUNET_CRYPTO_hash_context_read (hc, port, sizeof(*port)); |
429 | GNUNET_CRYPTO_hash_context_read(hc, listener, sizeof(*listener)); | 434 | GNUNET_CRYPTO_hash_context_read (hc, listener, sizeof(*listener)); |
430 | GNUNET_CRYPTO_hash_context_finish(hc, h_port); | 435 | GNUNET_CRYPTO_hash_context_finish (hc, h_port); |
431 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 436 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
432 | "Calculated port hash %s\n", | 437 | "Calculated port hash %s\n", |
433 | GNUNET_h2s(h_port)); | 438 | GNUNET_h2s (h_port)); |
434 | } | 439 | } |
435 | 440 | ||
436 | 441 | ||
@@ -442,7 +447,7 @@ GCCH_hash_port(struct GNUNET_HashCode *h_port, | |||
442 | * @return ID used to identify the channel with the remote peer. | 447 | * @return ID used to identify the channel with the remote peer. |
443 | */ | 448 | */ |
444 | struct GNUNET_CADET_ChannelTunnelNumber | 449 | struct GNUNET_CADET_ChannelTunnelNumber |
445 | GCCH_get_id(const struct CadetChannel *ch) | 450 | GCCH_get_id (const struct CadetChannel *ch) |
446 | { | 451 | { |
447 | return ch->ctn; | 452 | return ch->ctn; |
448 | } | 453 | } |
@@ -454,18 +459,18 @@ GCCH_get_id(const struct CadetChannel *ch) | |||
454 | * @param ccc data structure to clean up | 459 | * @param ccc data structure to clean up |
455 | */ | 460 | */ |
456 | static void | 461 | static void |
457 | free_channel_client(struct CadetChannelClient *ccc) | 462 | free_channel_client (struct CadetChannelClient *ccc) |
458 | { | 463 | { |
459 | struct CadetOutOfOrderMessage *com; | 464 | struct CadetOutOfOrderMessage *com; |
460 | 465 | ||
461 | while (NULL != (com = ccc->head_recv)) | 466 | while (NULL != (com = ccc->head_recv)) |
462 | { | 467 | { |
463 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); | 468 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
464 | ccc->num_recv--; | 469 | ccc->num_recv--; |
465 | GNUNET_MQ_discard(com->env); | 470 | GNUNET_MQ_discard (com->env); |
466 | GNUNET_free(com); | 471 | GNUNET_free (com); |
467 | } | 472 | } |
468 | GNUNET_free(ccc); | 473 | GNUNET_free (ccc); |
469 | } | 474 | } |
470 | 475 | ||
471 | 476 | ||
@@ -475,57 +480,57 @@ free_channel_client(struct CadetChannelClient *ccc) | |||
475 | * @param ch channel to destroy | 480 | * @param ch channel to destroy |
476 | */ | 481 | */ |
477 | static void | 482 | static void |
478 | channel_destroy(struct CadetChannel *ch) | 483 | channel_destroy (struct CadetChannel *ch) |
479 | { | 484 | { |
480 | struct CadetReliableMessage *crm; | 485 | struct CadetReliableMessage *crm; |
481 | 486 | ||
482 | while (NULL != (crm = ch->head_sent)) | 487 | while (NULL != (crm = ch->head_sent)) |
488 | { | ||
489 | GNUNET_assert (ch == crm->ch); | ||
490 | if (NULL != crm->qe) | ||
483 | { | 491 | { |
484 | GNUNET_assert(ch == crm->ch); | 492 | GCT_send_cancel (crm->qe); |
485 | if (NULL != crm->qe) | 493 | crm->qe = NULL; |
486 | { | ||
487 | GCT_send_cancel(crm->qe); | ||
488 | crm->qe = NULL; | ||
489 | } | ||
490 | GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); | ||
491 | GNUNET_free(crm->data_message); | ||
492 | GNUNET_free(crm); | ||
493 | } | 494 | } |
495 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); | ||
496 | GNUNET_free (crm->data_message); | ||
497 | GNUNET_free (crm); | ||
498 | } | ||
494 | if (CADET_CHANNEL_LOOSE == ch->state) | 499 | if (CADET_CHANNEL_LOOSE == ch->state) |
495 | { | 500 | { |
496 | GSC_drop_loose_channel(&ch->h_port, ch); | 501 | GSC_drop_loose_channel (&ch->h_port, ch); |
497 | } | 502 | } |
498 | if (NULL != ch->owner) | 503 | if (NULL != ch->owner) |
499 | { | 504 | { |
500 | free_channel_client(ch->owner); | 505 | free_channel_client (ch->owner); |
501 | ch->owner = NULL; | 506 | ch->owner = NULL; |
502 | } | 507 | } |
503 | if (NULL != ch->dest) | 508 | if (NULL != ch->dest) |
504 | { | 509 | { |
505 | free_channel_client(ch->dest); | 510 | free_channel_client (ch->dest); |
506 | ch->dest = NULL; | 511 | ch->dest = NULL; |
507 | } | 512 | } |
508 | if (NULL != ch->last_control_qe) | 513 | if (NULL != ch->last_control_qe) |
509 | { | 514 | { |
510 | GCT_send_cancel(ch->last_control_qe); | 515 | GCT_send_cancel (ch->last_control_qe); |
511 | ch->last_control_qe = NULL; | 516 | ch->last_control_qe = NULL; |
512 | } | 517 | } |
513 | if (NULL != ch->retry_data_task) | 518 | if (NULL != ch->retry_data_task) |
514 | { | 519 | { |
515 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); | 520 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
516 | ch->retry_data_task = NULL; | 521 | ch->retry_data_task = NULL; |
517 | } | 522 | } |
518 | if (NULL != ch->retry_control_task) | 523 | if (NULL != ch->retry_control_task) |
519 | { | 524 | { |
520 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); | 525 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); |
521 | ch->retry_control_task = NULL; | 526 | ch->retry_control_task = NULL; |
522 | } | 527 | } |
523 | if (GNUNET_NO == ch->is_loopback) | 528 | if (GNUNET_NO == ch->is_loopback) |
524 | { | 529 | { |
525 | GCT_remove_channel(ch->t, ch, ch->ctn); | 530 | GCT_remove_channel (ch->t, ch, ch->ctn); |
526 | ch->t = NULL; | 531 | ch->t = NULL; |
527 | } | 532 | } |
528 | GNUNET_free(ch); | 533 | GNUNET_free (ch); |
529 | } | 534 | } |
530 | 535 | ||
531 | 536 | ||
@@ -535,7 +540,7 @@ channel_destroy(struct CadetChannel *ch) | |||
535 | * @param cls Channel for which to send. | 540 | * @param cls Channel for which to send. |
536 | */ | 541 | */ |
537 | static void | 542 | static void |
538 | send_channel_open(void *cls); | 543 | send_channel_open (void *cls); |
539 | 544 | ||
540 | 545 | ||
541 | /** | 546 | /** |
@@ -547,20 +552,20 @@ send_channel_open(void *cls); | |||
547 | * if transmission failed | 552 | * if transmission failed |
548 | */ | 553 | */ |
549 | static void | 554 | static void |
550 | channel_open_sent_cb(void *cls, | 555 | channel_open_sent_cb (void *cls, |
551 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 556 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
552 | { | 557 | { |
553 | struct CadetChannel *ch = cls; | 558 | struct CadetChannel *ch = cls; |
554 | 559 | ||
555 | GNUNET_assert(NULL != ch->last_control_qe); | 560 | GNUNET_assert (NULL != ch->last_control_qe); |
556 | ch->last_control_qe = NULL; | 561 | ch->last_control_qe = NULL; |
557 | ch->retry_time = GNUNET_TIME_STD_BACKOFF(ch->retry_time); | 562 | ch->retry_time = GNUNET_TIME_STD_BACKOFF (ch->retry_time); |
558 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 563 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
559 | "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", | 564 | "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", |
560 | GCCH_2s(ch), | 565 | GCCH_2s (ch), |
561 | GNUNET_STRINGS_relative_time_to_string(ch->retry_time, GNUNET_YES)); | 566 | GNUNET_STRINGS_relative_time_to_string (ch->retry_time, GNUNET_YES)); |
562 | ch->retry_control_task = | 567 | ch->retry_control_task = |
563 | GNUNET_SCHEDULER_add_delayed(ch->retry_time, &send_channel_open, ch); | 568 | GNUNET_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch); |
564 | } | 569 | } |
565 | 570 | ||
566 | 571 | ||
@@ -570,27 +575,27 @@ channel_open_sent_cb(void *cls, | |||
570 | * @param cls Channel for which to send. | 575 | * @param cls Channel for which to send. |
571 | */ | 576 | */ |
572 | static void | 577 | static void |
573 | send_channel_open(void *cls) | 578 | send_channel_open (void *cls) |
574 | { | 579 | { |
575 | struct CadetChannel *ch = cls; | 580 | struct CadetChannel *ch = cls; |
576 | struct GNUNET_CADET_ChannelOpenMessage msgcc; | 581 | struct GNUNET_CADET_ChannelOpenMessage msgcc; |
577 | 582 | ||
578 | ch->retry_control_task = NULL; | 583 | ch->retry_control_task = NULL; |
579 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 584 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
580 | "Sending CHANNEL_OPEN message for %s\n", | 585 | "Sending CHANNEL_OPEN message for %s\n", |
581 | GCCH_2s(ch)); | 586 | GCCH_2s (ch)); |
582 | msgcc.header.size = htons(sizeof(msgcc)); | 587 | msgcc.header.size = htons (sizeof(msgcc)); |
583 | msgcc.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); | 588 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); |
584 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed. | 589 | // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed. |
585 | msgcc.opt = 2; | 590 | msgcc.opt = 2; |
586 | msgcc.h_port = ch->h_port; | 591 | msgcc.h_port = ch->h_port; |
587 | msgcc.ctn = ch->ctn; | 592 | msgcc.ctn = ch->ctn; |
588 | ch->state = CADET_CHANNEL_OPEN_SENT; | 593 | ch->state = CADET_CHANNEL_OPEN_SENT; |
589 | if (NULL != ch->last_control_qe) | 594 | if (NULL != ch->last_control_qe) |
590 | GCT_send_cancel(ch->last_control_qe); | 595 | GCT_send_cancel (ch->last_control_qe); |
591 | ch->last_control_qe = | 596 | ch->last_control_qe = |
592 | GCT_send(ch->t, &msgcc.header, &channel_open_sent_cb, ch); | 597 | GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); |
593 | GNUNET_assert(NULL == ch->retry_control_task); | 598 | GNUNET_assert (NULL == ch->retry_control_task); |
594 | } | 599 | } |
595 | 600 | ||
596 | 601 | ||
@@ -605,13 +610,13 @@ send_channel_open(void *cls) | |||
605 | * @param ch the channel for which the tunnel is now ready | 610 | * @param ch the channel for which the tunnel is now ready |
606 | */ | 611 | */ |
607 | void | 612 | void |
608 | GCCH_tunnel_up(struct CadetChannel *ch) | 613 | GCCH_tunnel_up (struct CadetChannel *ch) |
609 | { | 614 | { |
610 | GNUNET_assert(NULL == ch->retry_control_task); | 615 | GNUNET_assert (NULL == ch->retry_control_task); |
611 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 616 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
612 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", | 617 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", |
613 | GCCH_2s(ch)); | 618 | GCCH_2s (ch)); |
614 | ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_channel_open, ch); | 619 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch); |
615 | } | 620 | } |
616 | 621 | ||
617 | 622 | ||
@@ -626,22 +631,22 @@ GCCH_tunnel_up(struct CadetChannel *ch) | |||
626 | * @return handle to the new channel | 631 | * @return handle to the new channel |
627 | */ | 632 | */ |
628 | struct CadetChannel * | 633 | struct CadetChannel * |
629 | GCCH_channel_local_new(struct CadetClient *owner, | 634 | GCCH_channel_local_new (struct CadetClient *owner, |
630 | struct GNUNET_CADET_ClientChannelNumber ccn, | 635 | struct GNUNET_CADET_ClientChannelNumber ccn, |
631 | struct CadetPeer *destination, | 636 | struct CadetPeer *destination, |
632 | const struct GNUNET_HashCode *port, | 637 | const struct GNUNET_HashCode *port, |
633 | uint32_t options) | 638 | uint32_t options) |
634 | { | 639 | { |
635 | struct CadetChannel *ch; | 640 | struct CadetChannel *ch; |
636 | struct CadetChannelClient *ccco; | 641 | struct CadetChannelClient *ccco; |
637 | 642 | ||
638 | ccco = GNUNET_new(struct CadetChannelClient); | 643 | ccco = GNUNET_new (struct CadetChannelClient); |
639 | ccco->c = owner; | 644 | ccco->c = owner; |
640 | ccco->ccn = ccn; | 645 | ccco->ccn = ccn; |
641 | ccco->client_ready = GNUNET_YES; | 646 | ccco->client_ready = GNUNET_YES; |
642 | 647 | ||
643 | ch = GNUNET_new(struct CadetChannel); | 648 | ch = GNUNET_new (struct CadetChannel); |
644 | ch->mid_recv.mid = htonl(1); /* The OPEN_ACK counts as message 0! */ | 649 | ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */ |
645 | ch->nobuffer = GNUNET_NO; | 650 | ch->nobuffer = GNUNET_NO; |
646 | ch->reliable = GNUNET_YES; | 651 | ch->reliable = GNUNET_YES; |
647 | ch->out_of_order = GNUNET_NO; | 652 | ch->out_of_order = GNUNET_NO; |
@@ -649,44 +654,44 @@ GCCH_channel_local_new(struct CadetClient *owner, | |||
649 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 654 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ |
650 | ch->owner = ccco; | 655 | ch->owner = ccco; |
651 | ch->port = *port; | 656 | ch->port = *port; |
652 | GCCH_hash_port(&ch->h_port, port, GCP_get_id(destination)); | 657 | GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination)); |
653 | if (0 == GNUNET_memcmp(&my_full_id, GCP_get_id(destination))) | 658 | if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination))) |
659 | { | ||
660 | struct OpenPort *op; | ||
661 | |||
662 | ch->is_loopback = GNUNET_YES; | ||
663 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port); | ||
664 | if (NULL == op) | ||
654 | { | 665 | { |
655 | struct OpenPort *op; | 666 | /* port closed, wait for it to possibly open */ |
656 | 667 | ch->state = CADET_CHANNEL_LOOSE; | |
657 | ch->is_loopback = GNUNET_YES; | 668 | (void) GNUNET_CONTAINER_multihashmap_put ( |
658 | op = GNUNET_CONTAINER_multihashmap_get(open_ports, &ch->h_port); | 669 | loose_channels, |
659 | if (NULL == op) | 670 | &ch->h_port, |
660 | { | 671 | ch, |
661 | /* port closed, wait for it to possibly open */ | 672 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
662 | ch->state = CADET_CHANNEL_LOOSE; | 673 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
663 | (void)GNUNET_CONTAINER_multihashmap_put( | 674 | "Created loose incoming loopback channel to port %s\n", |
664 | loose_channels, | 675 | GNUNET_h2s (&ch->port)); |
665 | &ch->h_port, | ||
666 | ch, | ||
667 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
668 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
669 | "Created loose incoming loopback channel to port %s\n", | ||
670 | GNUNET_h2s(&ch->port)); | ||
671 | } | ||
672 | else | ||
673 | { | ||
674 | GCCH_bind(ch, op->c, &op->port); | ||
675 | } | ||
676 | } | 676 | } |
677 | else | 677 | else |
678 | { | 678 | { |
679 | ch->t = GCP_get_tunnel(destination, GNUNET_YES); | 679 | GCCH_bind (ch, op->c, &op->port); |
680 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; | ||
681 | ch->ctn = GCT_add_channel(ch->t, ch); | ||
682 | } | 680 | } |
683 | GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); | 681 | } |
684 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 682 | else |
685 | "Created channel to port %s at peer %s for %s using %s\n", | 683 | { |
686 | GNUNET_h2s(port), | 684 | ch->t = GCP_get_tunnel (destination, GNUNET_YES); |
687 | GCP_2s(destination), | 685 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; |
688 | GSC_2s(owner), | 686 | ch->ctn = GCT_add_channel (ch->t, ch); |
689 | (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s(ch->t)); | 687 | } |
688 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); | ||
689 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
690 | "Created channel to port %s at peer %s for %s using %s\n", | ||
691 | GNUNET_h2s (port), | ||
692 | GCP_2s (destination), | ||
693 | GSC_2s (owner), | ||
694 | (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s (ch->t)); | ||
690 | return ch; | 695 | return ch; |
691 | } | 696 | } |
692 | 697 | ||
@@ -698,16 +703,16 @@ GCCH_channel_local_new(struct CadetClient *owner, | |||
698 | * @param cls the channel to drop | 703 | * @param cls the channel to drop |
699 | */ | 704 | */ |
700 | static void | 705 | static void |
701 | timeout_closed_cb(void *cls) | 706 | timeout_closed_cb (void *cls) |
702 | { | 707 | { |
703 | struct CadetChannel *ch = cls; | 708 | struct CadetChannel *ch = cls; |
704 | 709 | ||
705 | ch->retry_control_task = NULL; | 710 | ch->retry_control_task = NULL; |
706 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 711 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
707 | "Closing incoming channel to port %s from peer %s due to timeout\n", | 712 | "Closing incoming channel to port %s from peer %s due to timeout\n", |
708 | GNUNET_h2s(&ch->port), | 713 | GNUNET_h2s (&ch->port), |
709 | GCP_2s(GCT_get_destination(ch->t))); | 714 | GCP_2s (GCT_get_destination (ch->t))); |
710 | channel_destroy(ch); | 715 | channel_destroy (ch); |
711 | } | 716 | } |
712 | 717 | ||
713 | 718 | ||
@@ -721,15 +726,15 @@ timeout_closed_cb(void *cls) | |||
721 | * @return handle to the new channel | 726 | * @return handle to the new channel |
722 | */ | 727 | */ |
723 | struct CadetChannel * | 728 | struct CadetChannel * |
724 | GCCH_channel_incoming_new(struct CadetTunnel *t, | 729 | GCCH_channel_incoming_new (struct CadetTunnel *t, |
725 | struct GNUNET_CADET_ChannelTunnelNumber ctn, | 730 | struct GNUNET_CADET_ChannelTunnelNumber ctn, |
726 | const struct GNUNET_HashCode *h_port, | 731 | const struct GNUNET_HashCode *h_port, |
727 | uint32_t options) | 732 | uint32_t options) |
728 | { | 733 | { |
729 | struct CadetChannel *ch; | 734 | struct CadetChannel *ch; |
730 | struct OpenPort *op; | 735 | struct OpenPort *op; |
731 | 736 | ||
732 | ch = GNUNET_new(struct CadetChannel); | 737 | ch = GNUNET_new (struct CadetChannel); |
733 | ch->h_port = *h_port; | 738 | ch->h_port = *h_port; |
734 | ch->t = t; | 739 | ch->t = t; |
735 | ch->ctn = ctn; | 740 | ch->ctn = ctn; |
@@ -739,32 +744,32 @@ GCCH_channel_incoming_new(struct CadetTunnel *t, | |||
739 | ch->out_of_order = GNUNET_NO; | 744 | ch->out_of_order = GNUNET_NO; |
740 | ch->max_pending_messages = | 745 | ch->max_pending_messages = |
741 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 746 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ |
742 | GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); | 747 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
743 | 748 | ||
744 | op = GNUNET_CONTAINER_multihashmap_get(open_ports, h_port); | 749 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port); |
745 | if (NULL == op) | 750 | if (NULL == op) |
746 | { | 751 | { |
747 | /* port closed, wait for it to possibly open */ | 752 | /* port closed, wait for it to possibly open */ |
748 | ch->state = CADET_CHANNEL_LOOSE; | 753 | ch->state = CADET_CHANNEL_LOOSE; |
749 | (void)GNUNET_CONTAINER_multihashmap_put( | 754 | (void) GNUNET_CONTAINER_multihashmap_put ( |
750 | loose_channels, | 755 | loose_channels, |
751 | &ch->h_port, | 756 | &ch->h_port, |
752 | ch, | 757 | ch, |
753 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 758 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
754 | GNUNET_assert(NULL == ch->retry_control_task); | 759 | GNUNET_assert (NULL == ch->retry_control_task); |
755 | ch->retry_control_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT_CLOSED_PORT, | 760 | ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, |
756 | &timeout_closed_cb, | 761 | &timeout_closed_cb, |
757 | ch); | 762 | ch); |
758 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 763 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
759 | "Created loose incoming channel to port %s from peer %s\n", | 764 | "Created loose incoming channel to port %s from peer %s\n", |
760 | GNUNET_h2s(&ch->port), | 765 | GNUNET_h2s (&ch->port), |
761 | GCP_2s(GCT_get_destination(ch->t))); | 766 | GCP_2s (GCT_get_destination (ch->t))); |
762 | } | 767 | } |
763 | else | 768 | else |
764 | { | 769 | { |
765 | GCCH_bind(ch, op->c, &op->port); | 770 | GCCH_bind (ch, op->c, &op->port); |
766 | } | 771 | } |
767 | GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO); | 772 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
768 | return ch; | 773 | return ch; |
769 | } | 774 | } |
770 | 775 | ||
@@ -779,12 +784,12 @@ GCCH_channel_incoming_new(struct CadetTunnel *t, | |||
779 | * if transmission failed | 784 | * if transmission failed |
780 | */ | 785 | */ |
781 | static void | 786 | static void |
782 | send_ack_cb(void *cls, | 787 | send_ack_cb (void *cls, |
783 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 788 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
784 | { | 789 | { |
785 | struct CadetChannel *ch = cls; | 790 | struct CadetChannel *ch = cls; |
786 | 791 | ||
787 | GNUNET_assert(NULL != ch->last_control_qe); | 792 | GNUNET_assert (NULL != ch->last_control_qe); |
788 | ch->last_control_qe = NULL; | 793 | ch->last_control_qe = NULL; |
789 | } | 794 | } |
790 | 795 | ||
@@ -795,25 +800,25 @@ send_ack_cb(void *cls, | |||
795 | * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for | 800 | * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for |
796 | */ | 801 | */ |
797 | static void | 802 | static void |
798 | send_channel_data_ack(struct CadetChannel *ch) | 803 | send_channel_data_ack (struct CadetChannel *ch) |
799 | { | 804 | { |
800 | struct GNUNET_CADET_ChannelDataAckMessage msg; | 805 | struct GNUNET_CADET_ChannelDataAckMessage msg; |
801 | 806 | ||
802 | if (GNUNET_NO == ch->reliable) | 807 | if (GNUNET_NO == ch->reliable) |
803 | return; /* no ACKs */ | 808 | return; /* no ACKs */ |
804 | msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); | 809 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); |
805 | msg.header.size = htons(sizeof(msg)); | 810 | msg.header.size = htons (sizeof(msg)); |
806 | msg.ctn = ch->ctn; | 811 | msg.ctn = ch->ctn; |
807 | msg.mid.mid = htonl(ntohl(ch->mid_recv.mid)); | 812 | msg.mid.mid = htonl (ntohl (ch->mid_recv.mid)); |
808 | msg.futures = GNUNET_htonll(ch->mid_futures); | 813 | msg.futures = GNUNET_htonll (ch->mid_futures); |
809 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 814 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
810 | "Sending DATA_ACK %u:%llX via %s\n", | 815 | "Sending DATA_ACK %u:%llX via %s\n", |
811 | (unsigned int)ntohl(msg.mid.mid), | 816 | (unsigned int) ntohl (msg.mid.mid), |
812 | (unsigned long long)ch->mid_futures, | 817 | (unsigned long long) ch->mid_futures, |
813 | GCCH_2s(ch)); | 818 | GCCH_2s (ch)); |
814 | if (NULL != ch->last_control_qe) | 819 | if (NULL != ch->last_control_qe) |
815 | GCT_send_cancel(ch->last_control_qe); | 820 | GCT_send_cancel (ch->last_control_qe); |
816 | ch->last_control_qe = GCT_send(ch->t, &msg.header, &send_ack_cb, ch); | 821 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); |
817 | } | 822 | } |
818 | 823 | ||
819 | 824 | ||
@@ -824,23 +829,23 @@ send_channel_data_ack(struct CadetChannel *ch) | |||
824 | * @param cls the `struct CadetChannel` | 829 | * @param cls the `struct CadetChannel` |
825 | */ | 830 | */ |
826 | static void | 831 | static void |
827 | send_open_ack(void *cls) | 832 | send_open_ack (void *cls) |
828 | { | 833 | { |
829 | struct CadetChannel *ch = cls; | 834 | struct CadetChannel *ch = cls; |
830 | struct GNUNET_CADET_ChannelOpenAckMessage msg; | 835 | struct GNUNET_CADET_ChannelOpenAckMessage msg; |
831 | 836 | ||
832 | ch->retry_control_task = NULL; | 837 | ch->retry_control_task = NULL; |
833 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 838 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
834 | "Sending CHANNEL_OPEN_ACK on %s\n", | 839 | "Sending CHANNEL_OPEN_ACK on %s\n", |
835 | GCCH_2s(ch)); | 840 | GCCH_2s (ch)); |
836 | msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK); | 841 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK); |
837 | msg.header.size = htons(sizeof(msg)); | 842 | msg.header.size = htons (sizeof(msg)); |
838 | msg.reserved = htonl(0); | 843 | msg.reserved = htonl (0); |
839 | msg.ctn = ch->ctn; | 844 | msg.ctn = ch->ctn; |
840 | msg.port = ch->port; | 845 | msg.port = ch->port; |
841 | if (NULL != ch->last_control_qe) | 846 | if (NULL != ch->last_control_qe) |
842 | GCT_send_cancel(ch->last_control_qe); | 847 | GCT_send_cancel (ch->last_control_qe); |
843 | ch->last_control_qe = GCT_send(ch->t, &msg.header, &send_ack_cb, ch); | 848 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); |
844 | } | 849 | } |
845 | 850 | ||
846 | 851 | ||
@@ -853,28 +858,28 @@ send_open_ack(void *cls) | |||
853 | * @param cti identifier of the connection that delivered the message | 858 | * @param cti identifier of the connection that delivered the message |
854 | */ | 859 | */ |
855 | void | 860 | void |
856 | GCCH_handle_duplicate_open( | 861 | GCCH_handle_duplicate_open ( |
857 | struct CadetChannel *ch, | 862 | struct CadetChannel *ch, |
858 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 863 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) |
859 | { | 864 | { |
860 | if (NULL == ch->dest) | 865 | if (NULL == ch->dest) |
861 | { | 866 | { |
862 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 867 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
863 | "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n", | 868 | "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n", |
864 | GCCH_2s(ch)); | 869 | GCCH_2s (ch)); |
865 | return; | 870 | return; |
866 | } | 871 | } |
867 | if (NULL != ch->retry_control_task) | 872 | if (NULL != ch->retry_control_task) |
868 | { | 873 | { |
869 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 874 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
870 | "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n", | 875 | "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n", |
871 | GCCH_2s(ch)); | 876 | GCCH_2s (ch)); |
872 | return; | 877 | return; |
873 | } | 878 | } |
874 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 879 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
875 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", | 880 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", |
876 | GCCH_2s(ch)); | 881 | GCCH_2s (ch)); |
877 | ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_open_ack, ch); | 882 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); |
878 | } | 883 | } |
879 | 884 | ||
880 | 885 | ||
@@ -886,7 +891,7 @@ GCCH_handle_duplicate_open( | |||
886 | * #GNUNET_NO to send to dest | 891 | * #GNUNET_NO to send to dest |
887 | */ | 892 | */ |
888 | static void | 893 | static void |
889 | send_ack_to_client(struct CadetChannel *ch, int to_owner) | 894 | send_ack_to_client (struct CadetChannel *ch, int to_owner) |
890 | { | 895 | { |
891 | struct GNUNET_MQ_Envelope *env; | 896 | struct GNUNET_MQ_Envelope *env; |
892 | struct GNUNET_CADET_LocalAck *ack; | 897 | struct GNUNET_CADET_LocalAck *ack; |
@@ -894,22 +899,22 @@ send_ack_to_client(struct CadetChannel *ch, int to_owner) | |||
894 | 899 | ||
895 | ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; | 900 | ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest; |
896 | if (NULL == ccc) | 901 | if (NULL == ccc) |
897 | { | 902 | { |
898 | /* This can happen if we are just getting ACKs after | 903 | /* This can happen if we are just getting ACKs after |
899 | our local client already disconnected. */ | 904 | our local client already disconnected. */ |
900 | GNUNET_assert(GNUNET_YES == ch->destroy); | 905 | GNUNET_assert (GNUNET_YES == ch->destroy); |
901 | return; | 906 | return; |
902 | } | 907 | } |
903 | env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | 908 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
904 | ack->ccn = ccc->ccn; | 909 | ack->ccn = ccc->ccn; |
905 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 910 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
906 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", | 911 | "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", |
907 | GSC_2s(ccc->c), | 912 | GSC_2s (ccc->c), |
908 | (GNUNET_YES == to_owner) ? "owner" : "dest", | 913 | (GNUNET_YES == to_owner) ? "owner" : "dest", |
909 | ntohl(ack->ccn.channel_of_client), | 914 | ntohl (ack->ccn.channel_of_client), |
910 | ch->pending_messages, | 915 | ch->pending_messages, |
911 | ch->max_pending_messages); | 916 | ch->max_pending_messages); |
912 | GSC_send_to_client(ccc->c, env); | 917 | GSC_send_to_client (ccc->c, env); |
913 | } | 918 | } |
914 | 919 | ||
915 | 920 | ||
@@ -923,58 +928,58 @@ send_ack_to_client(struct CadetChannel *ch, int to_owner) | |||
923 | * @param port the port @a is listening on | 928 | * @param port the port @a is listening on |
924 | */ | 929 | */ |
925 | void | 930 | void |
926 | GCCH_bind(struct CadetChannel *ch, | 931 | GCCH_bind (struct CadetChannel *ch, |
927 | struct CadetClient *c, | 932 | struct CadetClient *c, |
928 | const struct GNUNET_HashCode *port) | 933 | const struct GNUNET_HashCode *port) |
929 | { | 934 | { |
930 | uint32_t options; | 935 | uint32_t options; |
931 | struct CadetChannelClient *cccd; | 936 | struct CadetChannelClient *cccd; |
932 | 937 | ||
933 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 938 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
934 | "Binding %s from %s to port %s of %s\n", | 939 | "Binding %s from %s to port %s of %s\n", |
935 | GCCH_2s(ch), | 940 | GCCH_2s (ch), |
936 | GCT_2s(ch->t), | 941 | GCT_2s (ch->t), |
937 | GNUNET_h2s(&ch->port), | 942 | GNUNET_h2s (&ch->port), |
938 | GSC_2s(c)); | 943 | GSC_2s (c)); |
939 | if (NULL != ch->retry_control_task) | 944 | if (NULL != ch->retry_control_task) |
940 | { | 945 | { |
941 | /* there might be a timeout task here */ | 946 | /* there might be a timeout task here */ |
942 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); | 947 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); |
943 | ch->retry_control_task = NULL; | 948 | ch->retry_control_task = NULL; |
944 | } | 949 | } |
945 | options = 0; | 950 | options = 0; |
946 | cccd = GNUNET_new(struct CadetChannelClient); | 951 | cccd = GNUNET_new (struct CadetChannelClient); |
947 | GNUNET_assert(NULL == ch->dest); | 952 | GNUNET_assert (NULL == ch->dest); |
948 | ch->dest = cccd; | 953 | ch->dest = cccd; |
949 | ch->port = *port; | 954 | ch->port = *port; |
950 | cccd->c = c; | 955 | cccd->c = c; |
951 | cccd->client_ready = GNUNET_YES; | 956 | cccd->client_ready = GNUNET_YES; |
952 | cccd->ccn = GSC_bind(c, | 957 | cccd->ccn = GSC_bind (c, |
953 | ch, | 958 | ch, |
954 | (GNUNET_YES == ch->is_loopback) | 959 | (GNUNET_YES == ch->is_loopback) |
955 | ? GCP_get(&my_full_id, GNUNET_YES) | 960 | ? GCP_get (&my_full_id, GNUNET_YES) |
956 | : GCT_get_destination(ch->t), | 961 | : GCT_get_destination (ch->t), |
957 | port, | 962 | port, |
958 | options); | 963 | options); |
959 | GNUNET_assert(ntohl(cccd->ccn.channel_of_client) < | 964 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < |
960 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 965 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
961 | ch->mid_recv.mid = htonl(1); /* The OPEN counts as message 0! */ | 966 | ch->mid_recv.mid = htonl (1); /* The OPEN counts as message 0! */ |
962 | if (GNUNET_YES == ch->is_loopback) | 967 | if (GNUNET_YES == ch->is_loopback) |
963 | { | 968 | { |
964 | ch->state = CADET_CHANNEL_OPEN_SENT; | 969 | ch->state = CADET_CHANNEL_OPEN_SENT; |
965 | GCCH_handle_channel_open_ack(ch, NULL, port); | 970 | GCCH_handle_channel_open_ack (ch, NULL, port); |
966 | } | 971 | } |
967 | else | 972 | else |
968 | { | 973 | { |
969 | /* notify other peer that we accepted the connection */ | 974 | /* notify other peer that we accepted the connection */ |
970 | ch->state = CADET_CHANNEL_READY; | 975 | ch->state = CADET_CHANNEL_READY; |
971 | ch->retry_control_task = GNUNET_SCHEDULER_add_now(&send_open_ack, ch); | 976 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); |
972 | } | 977 | } |
973 | /* give client it's initial supply of ACKs */ | 978 | /* give client it's initial supply of ACKs */ |
974 | GNUNET_assert(ntohl(cccd->ccn.channel_of_client) < | 979 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < |
975 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 980 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
976 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) | 981 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) |
977 | send_ack_to_client(ch, GNUNET_NO); | 982 | send_ack_to_client (ch, GNUNET_NO); |
978 | } | 983 | } |
979 | 984 | ||
980 | 985 | ||
@@ -986,7 +991,7 @@ GCCH_bind(struct CadetChannel *ch, | |||
986 | * @param cls the `struct CadetChannel` where one of the ends is now dead | 991 | * @param cls the `struct CadetChannel` where one of the ends is now dead |
987 | */ | 992 | */ |
988 | static void | 993 | static void |
989 | signal_remote_destroy_cb(void *cls) | 994 | signal_remote_destroy_cb (void *cls) |
990 | { | 995 | { |
991 | struct CadetChannel *ch = cls; | 996 | struct CadetChannel *ch = cls; |
992 | struct CadetChannelClient *ccc; | 997 | struct CadetChannelClient *ccc; |
@@ -994,8 +999,8 @@ signal_remote_destroy_cb(void *cls) | |||
994 | /* Find which end is left... */ | 999 | /* Find which end is left... */ |
995 | ch->retry_control_task = NULL; | 1000 | ch->retry_control_task = NULL; |
996 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1001 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
997 | GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch); | 1002 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); |
998 | channel_destroy(ch); | 1003 | channel_destroy (ch); |
999 | } | 1004 | } |
1000 | 1005 | ||
1001 | 1006 | ||
@@ -1008,74 +1013,74 @@ signal_remote_destroy_cb(void *cls) | |||
1008 | * @param ccn client number of the client @a c | 1013 | * @param ccn client number of the client @a c |
1009 | */ | 1014 | */ |
1010 | void | 1015 | void |
1011 | GCCH_channel_local_destroy(struct CadetChannel *ch, | 1016 | GCCH_channel_local_destroy (struct CadetChannel *ch, |
1012 | struct CadetClient *c, | 1017 | struct CadetClient *c, |
1013 | struct GNUNET_CADET_ClientChannelNumber ccn) | 1018 | struct GNUNET_CADET_ClientChannelNumber ccn) |
1014 | { | 1019 | { |
1015 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1020 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1016 | "%s asks for destruction of %s\n", | 1021 | "%s asks for destruction of %s\n", |
1017 | GSC_2s(c), | 1022 | GSC_2s (c), |
1018 | GCCH_2s(ch)); | 1023 | GCCH_2s (ch)); |
1019 | GNUNET_assert(NULL != c); | 1024 | GNUNET_assert (NULL != c); |
1020 | if ((NULL != ch->owner) && (c == ch->owner->c) && | 1025 | if ((NULL != ch->owner) && (c == ch->owner->c) && |
1021 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | 1026 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
1022 | { | 1027 | { |
1023 | free_channel_client(ch->owner); | 1028 | free_channel_client (ch->owner); |
1024 | ch->owner = NULL; | 1029 | ch->owner = NULL; |
1025 | } | 1030 | } |
1026 | else if ((NULL != ch->dest) && (c == ch->dest->c) && | 1031 | else if ((NULL != ch->dest) && (c == ch->dest->c) && |
1027 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) | 1032 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) |
1028 | { | 1033 | { |
1029 | free_channel_client(ch->dest); | 1034 | free_channel_client (ch->dest); |
1030 | ch->dest = NULL; | 1035 | ch->dest = NULL; |
1031 | } | 1036 | } |
1032 | else | 1037 | else |
1033 | { | 1038 | { |
1034 | GNUNET_assert(0); | 1039 | GNUNET_assert (0); |
1035 | } | 1040 | } |
1036 | 1041 | ||
1037 | if (GNUNET_YES == ch->destroy) | 1042 | if (GNUNET_YES == ch->destroy) |
1038 | { | 1043 | { |
1039 | /* other end already destroyed, with the local client gone, no need | 1044 | /* other end already destroyed, with the local client gone, no need |
1040 | to finish transmissions, just destroy immediately. */ | 1045 | to finish transmissions, just destroy immediately. */ |
1041 | channel_destroy(ch); | 1046 | channel_destroy (ch); |
1042 | return; | 1047 | return; |
1043 | } | 1048 | } |
1044 | if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) | 1049 | if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) |
1045 | { | 1050 | { |
1046 | /* Wait for other end to destroy us as well, | 1051 | /* Wait for other end to destroy us as well, |
1047 | and otherwise allow send queue to be transmitted first */ | 1052 | and otherwise allow send queue to be transmitted first */ |
1048 | ch->destroy = GNUNET_YES; | 1053 | ch->destroy = GNUNET_YES; |
1049 | return; | 1054 | return; |
1050 | } | 1055 | } |
1051 | if ((GNUNET_YES == ch->is_loopback) && | 1056 | if ((GNUNET_YES == ch->is_loopback) && |
1052 | ((NULL != ch->owner) || (NULL != ch->dest))) | 1057 | ((NULL != ch->owner) || (NULL != ch->dest))) |
1053 | { | 1058 | { |
1054 | if (NULL != ch->retry_control_task) | 1059 | if (NULL != ch->retry_control_task) |
1055 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); | 1060 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); |
1056 | ch->retry_control_task = | 1061 | ch->retry_control_task = |
1057 | GNUNET_SCHEDULER_add_now(&signal_remote_destroy_cb, ch); | 1062 | GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch); |
1058 | return; | 1063 | return; |
1059 | } | 1064 | } |
1060 | if (GNUNET_NO == ch->is_loopback) | 1065 | if (GNUNET_NO == ch->is_loopback) |
1066 | { | ||
1067 | /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */ | ||
1068 | switch (ch->state) | ||
1061 | { | 1069 | { |
1062 | /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */ | 1070 | case CADET_CHANNEL_NEW: |
1063 | switch (ch->state) | 1071 | /* We gave up on a channel that we created as a client to a remote |
1064 | { | 1072 | target, but that never went anywhere. Nothing to do here. */ |
1065 | case CADET_CHANNEL_NEW: | 1073 | break; |
1066 | /* We gave up on a channel that we created as a client to a remote | 1074 | |
1067 | target, but that never went anywhere. Nothing to do here. */ | 1075 | case CADET_CHANNEL_LOOSE: |
1068 | break; | 1076 | break; |
1069 | 1077 | ||
1070 | case CADET_CHANNEL_LOOSE: | 1078 | default: |
1071 | break; | 1079 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1072 | |||
1073 | default: | ||
1074 | GCT_send_channel_destroy(ch->t, ch->ctn); | ||
1075 | } | ||
1076 | } | 1080 | } |
1081 | } | ||
1077 | /* Nothing left to do, just finish destruction */ | 1082 | /* Nothing left to do, just finish destruction */ |
1078 | channel_destroy(ch); | 1083 | channel_destroy (ch); |
1079 | } | 1084 | } |
1080 | 1085 | ||
1081 | 1086 | ||
@@ -1089,60 +1094,60 @@ GCCH_channel_local_destroy(struct CadetChannel *ch, | |||
1089 | * @param port port number (needed to verify receiver knows the port) | 1094 | * @param port port number (needed to verify receiver knows the port) |
1090 | */ | 1095 | */ |
1091 | void | 1096 | void |
1092 | GCCH_handle_channel_open_ack( | 1097 | GCCH_handle_channel_open_ack ( |
1093 | struct CadetChannel *ch, | 1098 | struct CadetChannel *ch, |
1094 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1099 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1095 | const struct GNUNET_HashCode *port) | 1100 | const struct GNUNET_HashCode *port) |
1096 | { | 1101 | { |
1097 | switch (ch->state) | 1102 | switch (ch->state) |
1103 | { | ||
1104 | case CADET_CHANNEL_NEW: | ||
1105 | /* this should be impossible */ | ||
1106 | GNUNET_break (0); | ||
1107 | break; | ||
1108 | |||
1109 | case CADET_CHANNEL_LOOSE: | ||
1110 | /* This makes no sense. */ | ||
1111 | GNUNET_break_op (0); | ||
1112 | break; | ||
1113 | |||
1114 | case CADET_CHANNEL_OPEN_SENT: | ||
1115 | if (NULL == ch->owner) | ||
1098 | { | 1116 | { |
1099 | case CADET_CHANNEL_NEW: | 1117 | /* We're not the owner, wrong direction! */ |
1100 | /* this should be impossible */ | 1118 | GNUNET_break_op (0); |
1101 | GNUNET_break(0); | 1119 | return; |
1102 | break; | 1120 | } |
1103 | 1121 | if (0 != GNUNET_memcmp (&ch->port, port)) | |
1104 | case CADET_CHANNEL_LOOSE: | 1122 | { |
1105 | /* This makes no sense. */ | 1123 | /* Other peer failed to provide the right port, |
1106 | GNUNET_break_op(0); | 1124 | refuse connection. */ |
1107 | break; | 1125 | GNUNET_break_op (0); |
1108 | 1126 | return; | |
1109 | case CADET_CHANNEL_OPEN_SENT: | ||
1110 | if (NULL == ch->owner) | ||
1111 | { | ||
1112 | /* We're not the owner, wrong direction! */ | ||
1113 | GNUNET_break_op(0); | ||
1114 | return; | ||
1115 | } | ||
1116 | if (0 != GNUNET_memcmp(&ch->port, port)) | ||
1117 | { | ||
1118 | /* Other peer failed to provide the right port, | ||
1119 | refuse connection. */ | ||
1120 | GNUNET_break_op(0); | ||
1121 | return; | ||
1122 | } | ||
1123 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1124 | "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n", | ||
1125 | GCCH_2s(ch)); | ||
1126 | if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */ | ||
1127 | { | ||
1128 | GNUNET_SCHEDULER_cancel(ch->retry_control_task); | ||
1129 | ch->retry_control_task = NULL; | ||
1130 | } | ||
1131 | ch->state = CADET_CHANNEL_READY; | ||
1132 | /* On first connect, send client as many ACKs as we allow messages | ||
1133 | to be buffered! */ | ||
1134 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) | ||
1135 | send_ack_to_client(ch, GNUNET_YES); | ||
1136 | break; | ||
1137 | |||
1138 | case CADET_CHANNEL_READY: | ||
1139 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ | ||
1140 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1141 | "Received duplicate channel OPEN_ACK for %s\n", | ||
1142 | GCCH_2s(ch)); | ||
1143 | GNUNET_STATISTICS_update(stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); | ||
1144 | break; | ||
1145 | } | 1127 | } |
1128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1129 | "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n", | ||
1130 | GCCH_2s (ch)); | ||
1131 | if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */ | ||
1132 | { | ||
1133 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | ||
1134 | ch->retry_control_task = NULL; | ||
1135 | } | ||
1136 | ch->state = CADET_CHANNEL_READY; | ||
1137 | /* On first connect, send client as many ACKs as we allow messages | ||
1138 | to be buffered! */ | ||
1139 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) | ||
1140 | send_ack_to_client (ch, GNUNET_YES); | ||
1141 | break; | ||
1142 | |||
1143 | case CADET_CHANNEL_READY: | ||
1144 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ | ||
1145 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1146 | "Received duplicate channel OPEN_ACK for %s\n", | ||
1147 | GCCH_2s (ch)); | ||
1148 | GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); | ||
1149 | break; | ||
1150 | } | ||
1146 | } | 1151 | } |
1147 | 1152 | ||
1148 | 1153 | ||
@@ -1155,28 +1160,28 @@ GCCH_handle_channel_open_ack( | |||
1155 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO | 1160 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO |
1156 | */ | 1161 | */ |
1157 | static int | 1162 | static int |
1158 | is_before(void *cls, | 1163 | is_before (void *cls, |
1159 | struct CadetOutOfOrderMessage *m1, | 1164 | struct CadetOutOfOrderMessage *m1, |
1160 | struct CadetOutOfOrderMessage *m2) | 1165 | struct CadetOutOfOrderMessage *m2) |
1161 | { | 1166 | { |
1162 | int *duplicate = cls; | 1167 | int *duplicate = cls; |
1163 | uint32_t v1 = ntohl(m1->mid.mid); | 1168 | uint32_t v1 = ntohl (m1->mid.mid); |
1164 | uint32_t v2 = ntohl(m2->mid.mid); | 1169 | uint32_t v2 = ntohl (m2->mid.mid); |
1165 | uint32_t delta; | 1170 | uint32_t delta; |
1166 | 1171 | ||
1167 | delta = v2 - v1; | 1172 | delta = v2 - v1; |
1168 | if (0 == delta) | 1173 | if (0 == delta) |
1169 | *duplicate = GNUNET_YES; | 1174 | *duplicate = GNUNET_YES; |
1170 | if (delta > (uint32_t)INT_MAX) | 1175 | if (delta > (uint32_t) INT_MAX) |
1171 | { | 1176 | { |
1172 | /* in overflow range, we can safely assume we wrapped around */ | 1177 | /* in overflow range, we can safely assume we wrapped around */ |
1173 | return GNUNET_NO; | 1178 | return GNUNET_NO; |
1174 | } | 1179 | } |
1175 | else | 1180 | else |
1176 | { | 1181 | { |
1177 | /* result is small, thus v2 > v1, thus m1 < m2 */ | 1182 | /* result is small, thus v2 > v1, thus m1 < m2 */ |
1178 | return GNUNET_YES; | 1183 | return GNUNET_YES; |
1179 | } | 1184 | } |
1180 | } | 1185 | } |
1181 | 1186 | ||
1182 | 1187 | ||
@@ -1189,7 +1194,7 @@ is_before(void *cls, | |||
1189 | * @param msg message that was received | 1194 | * @param msg message that was received |
1190 | */ | 1195 | */ |
1191 | void | 1196 | void |
1192 | GCCH_handle_channel_plaintext_data( | 1197 | GCCH_handle_channel_plaintext_data ( |
1193 | struct CadetChannel *ch, | 1198 | struct CadetChannel *ch, |
1194 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1199 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1195 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) | 1200 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) |
@@ -1205,239 +1210,239 @@ GCCH_handle_channel_plaintext_data( | |||
1205 | uint32_t mid_msg; | 1210 | uint32_t mid_msg; |
1206 | uint32_t delta; | 1211 | uint32_t delta; |
1207 | 1212 | ||
1208 | GNUNET_assert(GNUNET_NO == ch->is_loopback); | 1213 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1209 | if ((NULL == ch->owner) && (NULL == ch->dest)) | 1214 | if ((NULL == ch->owner) && (NULL == ch->dest)) |
1210 | { | 1215 | { |
1211 | /* This client is gone, but we still have messages to send to | 1216 | /* This client is gone, but we still have messages to send to |
1212 | the other end (which is why @a ch is not yet dead). However, | 1217 | the other end (which is why @a ch is not yet dead). However, |
1213 | we cannot pass messages to our client anymore. */ | 1218 | we cannot pass messages to our client anymore. */ |
1214 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1219 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1215 | "Dropping incoming payload on %s as this end is already closed\n", | 1220 | "Dropping incoming payload on %s as this end is already closed\n", |
1216 | GCCH_2s(ch)); | 1221 | GCCH_2s (ch)); |
1217 | /* send back DESTROY notification to stop further retransmissions! */ | 1222 | /* send back DESTROY notification to stop further retransmissions! */ |
1218 | if (GNUNET_YES == ch->destroy) | 1223 | if (GNUNET_YES == ch->destroy) |
1219 | GCT_send_channel_destroy(ch->t, ch->ctn); | 1224 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1220 | return; | 1225 | return; |
1221 | } | 1226 | } |
1222 | payload_size = ntohs(msg->header.size) - sizeof(*msg); | 1227 | payload_size = ntohs (msg->header.size) - sizeof(*msg); |
1223 | env = GNUNET_MQ_msg_extra(ld, | 1228 | env = GNUNET_MQ_msg_extra (ld, |
1224 | payload_size, | 1229 | payload_size, |
1225 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1230 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1226 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; | 1231 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; |
1227 | GNUNET_memcpy(&ld[1], &msg[1], payload_size); | 1232 | GNUNET_memcpy (&ld[1], &msg[1], payload_size); |
1228 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1233 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1229 | if (GNUNET_YES == ccc->client_ready) | 1234 | if (GNUNET_YES == ccc->client_ready) |
1235 | { | ||
1236 | /* | ||
1237 | * We ad-hoc send the message if | ||
1238 | * - The channel is out-of-order | ||
1239 | * - The channel is reliable and MID matches next expected MID | ||
1240 | * - The channel is unreliable and MID is before lowest seen MID | ||
1241 | */ | ||
1242 | if ((GNUNET_YES == ch->out_of_order) || | ||
1243 | ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || | ||
1244 | ((GNUNET_NO == ch->reliable) && | ||
1245 | (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && | ||
1246 | ((NULL == ccc->head_recv) || | ||
1247 | (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid))))) | ||
1230 | { | 1248 | { |
1231 | /* | 1249 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1232 | * We ad-hoc send the message if | 1250 | "Giving %u bytes of payload with MID %u from %s to client %s\n", |
1233 | * - The channel is out-of-order | 1251 | (unsigned int) payload_size, |
1234 | * - The channel is reliable and MID matches next expected MID | 1252 | ntohl (msg->mid.mid), |
1235 | * - The channel is unreliable and MID is before lowest seen MID | 1253 | GCCH_2s (ch), |
1236 | */ | 1254 | GSC_2s (ccc->c)); |
1237 | if ((GNUNET_YES == ch->out_of_order) || | 1255 | ccc->client_ready = GNUNET_NO; |
1238 | ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || | 1256 | GSC_send_to_client (ccc->c, env); |
1239 | ((GNUNET_NO == ch->reliable) && | 1257 | if (GNUNET_NO == ch->out_of_order) |
1240 | (ntohl(msg->mid.mid) >= ntohl(ch->mid_recv.mid)) && | 1258 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); |
1241 | ((NULL == ccc->head_recv) || | 1259 | else |
1242 | (ntohl(msg->mid.mid) < ntohl(ccc->head_recv->mid.mid))))) | 1260 | ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); |
1243 | { | 1261 | ch->mid_futures >>= 1; |
1244 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1262 | if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) |
1245 | "Giving %u bytes of payload with MID %u from %s to client %s\n", | 1263 | { |
1246 | (unsigned int)payload_size, | 1264 | /* possibly shift by more if we skipped messages */ |
1247 | ntohl(msg->mid.mid), | 1265 | uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); |
1248 | GCCH_2s(ch), | 1266 | |
1249 | GSC_2s(ccc->c)); | 1267 | if (delta > 63) |
1250 | ccc->client_ready = GNUNET_NO; | 1268 | ch->mid_futures = 0; |
1251 | GSC_send_to_client(ccc->c, env); | 1269 | else |
1252 | if (GNUNET_NO == ch->out_of_order) | 1270 | ch->mid_futures >>= delta; |
1253 | ch->mid_recv.mid = htonl(1 + ntohl(msg->mid.mid)); | 1271 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); |
1254 | else | 1272 | } |
1255 | ch->mid_recv.mid = htonl(1 + ntohl(ch->mid_recv.mid)); | 1273 | send_channel_data_ack (ch); |
1256 | ch->mid_futures >>= 1; | 1274 | return; |
1257 | if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) | ||
1258 | { | ||
1259 | /* possibly shift by more if we skipped messages */ | ||
1260 | uint64_t delta = htonl(msg->mid.mid) - 1 - ntohl(ch->mid_recv.mid); | ||
1261 | |||
1262 | if (delta > 63) | ||
1263 | ch->mid_futures = 0; | ||
1264 | else | ||
1265 | ch->mid_futures >>= delta; | ||
1266 | ch->mid_recv.mid = htonl(1 + ntohl(msg->mid.mid)); | ||
1267 | } | ||
1268 | send_channel_data_ack(ch); | ||
1269 | return; | ||
1270 | } | ||
1271 | } | 1275 | } |
1276 | } | ||
1272 | 1277 | ||
1273 | if (GNUNET_YES == ch->reliable) | 1278 | if (GNUNET_YES == ch->reliable) |
1279 | { | ||
1280 | /* check if message ought to be dropped because it is ancient/too distant/duplicate */ | ||
1281 | mid_min = ntohl (ch->mid_recv.mid); | ||
1282 | mid_max = mid_min + ch->max_pending_messages; | ||
1283 | mid_msg = ntohl (msg->mid.mid); | ||
1284 | if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || | ||
1285 | ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages)) | ||
1286 | { | ||
1287 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1288 | "%s at %u drops ancient or far-future message %u\n", | ||
1289 | GCCH_2s (ch), | ||
1290 | (unsigned int) mid_min, | ||
1291 | ntohl (msg->mid.mid)); | ||
1292 | |||
1293 | GNUNET_STATISTICS_update (stats, | ||
1294 | "# duplicate DATA (ancient or future)", | ||
1295 | 1, | ||
1296 | GNUNET_NO); | ||
1297 | GNUNET_MQ_discard (env); | ||
1298 | send_channel_data_ack (ch); | ||
1299 | return; | ||
1300 | } | ||
1301 | /* mark bit for future ACKs */ | ||
1302 | delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */ | ||
1303 | if (delta < 64) | ||
1274 | { | 1304 | { |
1275 | /* check if message ought to be dropped because it is ancient/too distant/duplicate */ | 1305 | if (0 != (ch->mid_futures & (1LLU << delta))) |
1276 | mid_min = ntohl(ch->mid_recv.mid); | 1306 | { |
1277 | mid_max = mid_min + ch->max_pending_messages; | 1307 | /* Duplicate within the queue, drop also */ |
1278 | mid_msg = ntohl(msg->mid.mid); | 1308 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1279 | if (((uint32_t)(mid_msg - mid_min) > ch->max_pending_messages) || | 1309 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", |
1280 | ((uint32_t)(mid_max - mid_msg) > ch->max_pending_messages)) | 1310 | (unsigned int) payload_size, |
1281 | { | 1311 | GCCH_2s (ch), |
1282 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1312 | ntohl (msg->mid.mid)); |
1283 | "%s at %u drops ancient or far-future message %u\n", | 1313 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); |
1284 | GCCH_2s(ch), | 1314 | GNUNET_MQ_discard (env); |
1285 | (unsigned int)mid_min, | 1315 | send_channel_data_ack (ch); |
1286 | ntohl(msg->mid.mid)); | 1316 | return; |
1287 | 1317 | } | |
1288 | GNUNET_STATISTICS_update(stats, | 1318 | ch->mid_futures |= (1LLU << delta); |
1289 | "# duplicate DATA (ancient or future)", | 1319 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1290 | 1, | 1320 | "Marked bit %llX for mid %u (base: %u); now: %llX\n", |
1291 | GNUNET_NO); | 1321 | (1LLU << delta), |
1292 | GNUNET_MQ_discard(env); | 1322 | mid_msg, |
1293 | send_channel_data_ack(ch); | 1323 | mid_min, |
1294 | return; | 1324 | ch->mid_futures); |
1295 | } | ||
1296 | /* mark bit for future ACKs */ | ||
1297 | delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */ | ||
1298 | if (delta < 64) | ||
1299 | { | ||
1300 | if (0 != (ch->mid_futures & (1LLU << delta))) | ||
1301 | { | ||
1302 | /* Duplicate within the queue, drop also */ | ||
1303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1304 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", | ||
1305 | (unsigned int)payload_size, | ||
1306 | GCCH_2s(ch), | ||
1307 | ntohl(msg->mid.mid)); | ||
1308 | GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO); | ||
1309 | GNUNET_MQ_discard(env); | ||
1310 | send_channel_data_ack(ch); | ||
1311 | return; | ||
1312 | } | ||
1313 | ch->mid_futures |= (1LLU << delta); | ||
1314 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1315 | "Marked bit %llX for mid %u (base: %u); now: %llX\n", | ||
1316 | (1LLU << delta), | ||
1317 | mid_msg, | ||
1318 | mid_min, | ||
1319 | ch->mid_futures); | ||
1320 | } | ||
1321 | } | 1325 | } |
1326 | } | ||
1322 | else /* ! ch->reliable */ | 1327 | else /* ! ch->reliable */ |
1328 | { | ||
1329 | struct CadetOutOfOrderMessage *next_msg; | ||
1330 | |||
1331 | /** | ||
1332 | * We always send if possible in this case. | ||
1333 | * It is guaranteed that the queued MID < received MID | ||
1334 | **/ | ||
1335 | if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) | ||
1336 | { | ||
1337 | next_msg = ccc->head_recv; | ||
1338 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1339 | "Giving queued MID %u from %s to client %s\n", | ||
1340 | ntohl (next_msg->mid.mid), | ||
1341 | GCCH_2s (ch), | ||
1342 | GSC_2s (ccc->c)); | ||
1343 | ccc->client_ready = GNUNET_NO; | ||
1344 | GSC_send_to_client (ccc->c, next_msg->env); | ||
1345 | ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); | ||
1346 | ch->mid_futures >>= 1; | ||
1347 | send_channel_data_ack (ch); | ||
1348 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg); | ||
1349 | ccc->num_recv--; | ||
1350 | /* Do not process duplicate MID */ | ||
1351 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ | ||
1352 | { | ||
1353 | /* Duplicate within the queue, drop */ | ||
1354 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1355 | "Message on %s (mid %u) dropped, duplicate\n", | ||
1356 | GCCH_2s (ch), | ||
1357 | ntohl (msg->mid.mid)); | ||
1358 | GNUNET_free (next_msg); | ||
1359 | GNUNET_MQ_discard (env); | ||
1360 | return; | ||
1361 | } | ||
1362 | GNUNET_free (next_msg); | ||
1363 | } | ||
1364 | |||
1365 | if (ntohl (msg->mid.mid) < ntohl (ch->mid_recv.mid)) /* Old */ | ||
1366 | { | ||
1367 | /* Duplicate within the queue, drop */ | ||
1368 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1369 | "Message on %s (mid %u) dropped, old.\n", | ||
1370 | GCCH_2s (ch), | ||
1371 | ntohl (msg->mid.mid)); | ||
1372 | GNUNET_MQ_discard (env); | ||
1373 | return; | ||
1374 | } | ||
1375 | |||
1376 | /* Channel is unreliable, so we do not ACK. But we also cannot | ||
1377 | allow buffering everything, so check if we have space... */ | ||
1378 | if (ccc->num_recv >= ch->max_pending_messages) | ||
1323 | { | 1379 | { |
1324 | struct CadetOutOfOrderMessage *next_msg; | 1380 | struct CadetOutOfOrderMessage *drop; |
1325 | 1381 | ||
1326 | /** | 1382 | /* Yep, need to drop. Drop the oldest message in |
1327 | * We always send if possible in this case. | 1383 | the buffer. */ |
1328 | * It is guaranteed that the queued MID < received MID | 1384 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1329 | **/ | 1385 | "Queue full due slow client on %s, dropping oldest message\n", |
1330 | if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) | 1386 | GCCH_2s (ch)); |
1331 | { | 1387 | GNUNET_STATISTICS_update (stats, |
1332 | next_msg = ccc->head_recv; | 1388 | "# messages dropped due to slow client", |
1333 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1389 | 1, |
1334 | "Giving queued MID %u from %s to client %s\n", | 1390 | GNUNET_NO); |
1335 | ntohl(next_msg->mid.mid), | 1391 | drop = ccc->head_recv; |
1336 | GCCH_2s(ch), | 1392 | GNUNET_assert (NULL != drop); |
1337 | GSC_2s(ccc->c)); | 1393 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop); |
1338 | ccc->client_ready = GNUNET_NO; | 1394 | ccc->num_recv--; |
1339 | GSC_send_to_client(ccc->c, next_msg->env); | 1395 | GNUNET_MQ_discard (drop->env); |
1340 | ch->mid_recv.mid = htonl(1 + ntohl(next_msg->mid.mid)); | 1396 | GNUNET_free (drop); |
1341 | ch->mid_futures >>= 1; | ||
1342 | send_channel_data_ack(ch); | ||
1343 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, next_msg); | ||
1344 | ccc->num_recv--; | ||
1345 | /* Do not process duplicate MID */ | ||
1346 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ | ||
1347 | { | ||
1348 | /* Duplicate within the queue, drop */ | ||
1349 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1350 | "Message on %s (mid %u) dropped, duplicate\n", | ||
1351 | GCCH_2s(ch), | ||
1352 | ntohl(msg->mid.mid)); | ||
1353 | GNUNET_free(next_msg); | ||
1354 | GNUNET_MQ_discard(env); | ||
1355 | return; | ||
1356 | } | ||
1357 | GNUNET_free(next_msg); | ||
1358 | } | ||
1359 | |||
1360 | if (ntohl(msg->mid.mid) < ntohl(ch->mid_recv.mid)) /* Old */ | ||
1361 | { | ||
1362 | /* Duplicate within the queue, drop */ | ||
1363 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1364 | "Message on %s (mid %u) dropped, old.\n", | ||
1365 | GCCH_2s(ch), | ||
1366 | ntohl(msg->mid.mid)); | ||
1367 | GNUNET_MQ_discard(env); | ||
1368 | return; | ||
1369 | } | ||
1370 | |||
1371 | /* Channel is unreliable, so we do not ACK. But we also cannot | ||
1372 | allow buffering everything, so check if we have space... */ | ||
1373 | if (ccc->num_recv >= ch->max_pending_messages) | ||
1374 | { | ||
1375 | struct CadetOutOfOrderMessage *drop; | ||
1376 | |||
1377 | /* Yep, need to drop. Drop the oldest message in | ||
1378 | the buffer. */ | ||
1379 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1380 | "Queue full due slow client on %s, dropping oldest message\n", | ||
1381 | GCCH_2s(ch)); | ||
1382 | GNUNET_STATISTICS_update(stats, | ||
1383 | "# messages dropped due to slow client", | ||
1384 | 1, | ||
1385 | GNUNET_NO); | ||
1386 | drop = ccc->head_recv; | ||
1387 | GNUNET_assert(NULL != drop); | ||
1388 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, drop); | ||
1389 | ccc->num_recv--; | ||
1390 | GNUNET_MQ_discard(drop->env); | ||
1391 | GNUNET_free(drop); | ||
1392 | } | ||
1393 | } | 1397 | } |
1398 | } | ||
1394 | 1399 | ||
1395 | /* Insert message into sorted out-of-order queue */ | 1400 | /* Insert message into sorted out-of-order queue */ |
1396 | com = GNUNET_new(struct CadetOutOfOrderMessage); | 1401 | com = GNUNET_new (struct CadetOutOfOrderMessage); |
1397 | com->mid = msg->mid; | 1402 | com->mid = msg->mid; |
1398 | com->env = env; | 1403 | com->env = env; |
1399 | duplicate = GNUNET_NO; | 1404 | duplicate = GNUNET_NO; |
1400 | GNUNET_CONTAINER_DLL_insert_sorted(struct CadetOutOfOrderMessage, | 1405 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetOutOfOrderMessage, |
1401 | is_before, | 1406 | is_before, |
1402 | &duplicate, | 1407 | &duplicate, |
1403 | ccc->head_recv, | 1408 | ccc->head_recv, |
1404 | ccc->tail_recv, | 1409 | ccc->tail_recv, |
1405 | com); | 1410 | com); |
1406 | ccc->num_recv++; | 1411 | ccc->num_recv++; |
1407 | if (GNUNET_YES == duplicate) | 1412 | if (GNUNET_YES == duplicate) |
1408 | { | 1413 | { |
1409 | /* Duplicate within the queue, drop also (this is not covered by | 1414 | /* Duplicate within the queue, drop also (this is not covered by |
1410 | the case above if "delta" >= 64, which could be the case if | 1415 | the case above if "delta" >= 64, which could be the case if |
1411 | max_pending_messages is also >= 64 or if our client is unready | 1416 | max_pending_messages is also >= 64 or if our client is unready |
1412 | and we are seeing retransmissions of the message our client is | 1417 | and we are seeing retransmissions of the message our client is |
1413 | blocked on. */ | 1418 | blocked on. */ |
1414 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1419 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1415 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", | 1420 | "Duplicate payload of %u bytes on %s (mid %u) dropped\n", |
1416 | (unsigned int)payload_size, | 1421 | (unsigned int) payload_size, |
1417 | GCCH_2s(ch), | 1422 | GCCH_2s (ch), |
1418 | ntohl(msg->mid.mid)); | 1423 | ntohl (msg->mid.mid)); |
1419 | GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO); | 1424 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); |
1420 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); | 1425 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
1421 | ccc->num_recv--; | 1426 | ccc->num_recv--; |
1422 | GNUNET_MQ_discard(com->env); | 1427 | GNUNET_MQ_discard (com->env); |
1423 | GNUNET_free(com); | 1428 | GNUNET_free (com); |
1424 | send_channel_data_ack(ch); | 1429 | send_channel_data_ack (ch); |
1425 | return; | 1430 | return; |
1426 | } | 1431 | } |
1427 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1432 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1428 | "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", | 1433 | "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", |
1429 | (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", | 1434 | (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", |
1430 | (unsigned int)payload_size, | 1435 | (unsigned int) payload_size, |
1431 | GCCH_2s(ch), | 1436 | GCCH_2s (ch), |
1432 | ntohl(ccc->ccn.channel_of_client), | 1437 | ntohl (ccc->ccn.channel_of_client), |
1433 | ccc, | 1438 | ccc, |
1434 | ntohl(msg->mid.mid), | 1439 | ntohl (msg->mid.mid), |
1435 | ntohl(ch->mid_recv.mid)); | 1440 | ntohl (ch->mid_recv.mid)); |
1436 | /* NOTE: this ACK we _could_ skip, as the packet is out-of-order and | 1441 | /* NOTE: this ACK we _could_ skip, as the packet is out-of-order and |
1437 | the sender may already be transmitting the previous one. Needs | 1442 | the sender may already be transmitting the previous one. Needs |
1438 | experimental evaluation to see if/when this ACK helps or | 1443 | experimental evaluation to see if/when this ACK helps or |
1439 | hurts. (We might even want another option.) */ | 1444 | hurts. (We might even want another option.) */ |
1440 | send_channel_data_ack(ch); | 1445 | send_channel_data_ack (ch); |
1441 | } | 1446 | } |
1442 | 1447 | ||
1443 | 1448 | ||
@@ -1452,8 +1457,8 @@ GCCH_handle_channel_plaintext_data( | |||
1452 | * if transmission failed | 1457 | * if transmission failed |
1453 | */ | 1458 | */ |
1454 | static void | 1459 | static void |
1455 | data_sent_cb(void *cls, | 1460 | data_sent_cb (void *cls, |
1456 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); | 1461 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid); |
1457 | 1462 | ||
1458 | 1463 | ||
1459 | /** | 1464 | /** |
@@ -1463,19 +1468,19 @@ data_sent_cb(void *cls, | |||
1463 | * @param cls the `struct CadetChannel` where we need to retransmit | 1468 | * @param cls the `struct CadetChannel` where we need to retransmit |
1464 | */ | 1469 | */ |
1465 | static void | 1470 | static void |
1466 | retry_transmission(void *cls) | 1471 | retry_transmission (void *cls) |
1467 | { | 1472 | { |
1468 | struct CadetChannel *ch = cls; | 1473 | struct CadetChannel *ch = cls; |
1469 | struct CadetReliableMessage *crm = ch->head_sent; | 1474 | struct CadetReliableMessage *crm = ch->head_sent; |
1470 | 1475 | ||
1471 | ch->retry_data_task = NULL; | 1476 | ch->retry_data_task = NULL; |
1472 | GNUNET_assert(NULL == crm->qe); | 1477 | GNUNET_assert (NULL == crm->qe); |
1473 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1478 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1474 | "Retrying transmission on %s of message %u\n", | 1479 | "Retrying transmission on %s of message %u\n", |
1475 | GCCH_2s(ch), | 1480 | GCCH_2s (ch), |
1476 | (unsigned int)ntohl(crm->data_message->mid.mid)); | 1481 | (unsigned int) ntohl (crm->data_message->mid.mid)); |
1477 | crm->qe = GCT_send(ch->t, &crm->data_message->header, &data_sent_cb, crm); | 1482 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1478 | GNUNET_assert(NULL == ch->retry_data_task); | 1483 | GNUNET_assert (NULL == ch->retry_data_task); |
1479 | } | 1484 | } |
1480 | 1485 | ||
1481 | 1486 | ||
@@ -1488,36 +1493,36 @@ retry_transmission(void *cls) | |||
1488 | * @param crm the message that got acknowledged | 1493 | * @param crm the message that got acknowledged |
1489 | */ | 1494 | */ |
1490 | static void | 1495 | static void |
1491 | handle_matching_ack(struct CadetChannel *ch, | 1496 | handle_matching_ack (struct CadetChannel *ch, |
1492 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1497 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1493 | struct CadetReliableMessage *crm) | 1498 | struct CadetReliableMessage *crm) |
1494 | { | 1499 | { |
1495 | GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); | 1500 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
1496 | ch->pending_messages--; | 1501 | ch->pending_messages--; |
1497 | GNUNET_assert(ch->pending_messages < ch->max_pending_messages); | 1502 | GNUNET_assert (ch->pending_messages < ch->max_pending_messages); |
1498 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1503 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1499 | "Received DATA_ACK on %s for message %u (%u ACKs pending)\n", | 1504 | "Received DATA_ACK on %s for message %u (%u ACKs pending)\n", |
1500 | GCCH_2s(ch), | 1505 | GCCH_2s (ch), |
1501 | (unsigned int)ntohl(crm->data_message->mid.mid), | 1506 | (unsigned int) ntohl (crm->data_message->mid.mid), |
1502 | ch->pending_messages); | 1507 | ch->pending_messages); |
1503 | if (NULL != crm->qe) | 1508 | if (NULL != crm->qe) |
1504 | { | 1509 | { |
1505 | GCT_send_cancel(crm->qe); | 1510 | GCT_send_cancel (crm->qe); |
1506 | crm->qe = NULL; | 1511 | crm->qe = NULL; |
1507 | } | 1512 | } |
1508 | if ((1 == crm->num_transmissions) && (NULL != cti)) | 1513 | if ((1 == crm->num_transmissions) && (NULL != cti)) |
1514 | { | ||
1515 | GCC_ack_observed (cti); | ||
1516 | if (0 == GNUNET_memcmp (cti, &crm->connection_taken)) | ||
1509 | { | 1517 | { |
1510 | GCC_ack_observed(cti); | 1518 | GCC_latency_observed (cti, |
1511 | if (0 == GNUNET_memcmp(cti, &crm->connection_taken)) | 1519 | GNUNET_TIME_absolute_get_duration ( |
1512 | { | 1520 | crm->first_transmission_time)); |
1513 | GCC_latency_observed(cti, | ||
1514 | GNUNET_TIME_absolute_get_duration( | ||
1515 | crm->first_transmission_time)); | ||
1516 | } | ||
1517 | } | 1521 | } |
1518 | GNUNET_free(crm->data_message); | 1522 | } |
1519 | GNUNET_free(crm); | 1523 | GNUNET_free (crm->data_message); |
1520 | send_ack_to_client(ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); | 1524 | GNUNET_free (crm); |
1525 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); | ||
1521 | } | 1526 | } |
1522 | 1527 | ||
1523 | 1528 | ||
@@ -1530,7 +1535,7 @@ handle_matching_ack(struct CadetChannel *ch, | |||
1530 | * @param ack details about what was received | 1535 | * @param ack details about what was received |
1531 | */ | 1536 | */ |
1532 | void | 1537 | void |
1533 | GCCH_handle_channel_plaintext_data_ack( | 1538 | GCCH_handle_channel_plaintext_data_ack ( |
1534 | struct CadetChannel *ch, | 1539 | struct CadetChannel *ch, |
1535 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1540 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1536 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) | 1541 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) |
@@ -1542,72 +1547,72 @@ GCCH_handle_channel_plaintext_data_ack( | |||
1542 | uint64_t mid_mask; | 1547 | uint64_t mid_mask; |
1543 | unsigned int delta; | 1548 | unsigned int delta; |
1544 | 1549 | ||
1545 | GNUNET_break(GNUNET_NO == ch->is_loopback); | 1550 | GNUNET_break (GNUNET_NO == ch->is_loopback); |
1546 | if (GNUNET_NO == ch->reliable) | 1551 | if (GNUNET_NO == ch->reliable) |
1547 | { | 1552 | { |
1548 | /* not expecting ACKs on unreliable channel, odd */ | 1553 | /* not expecting ACKs on unreliable channel, odd */ |
1549 | GNUNET_break_op(0); | 1554 | GNUNET_break_op (0); |
1550 | return; | 1555 | return; |
1551 | } | 1556 | } |
1552 | /* mid_base is the MID of the next message that the | 1557 | /* mid_base is the MID of the next message that the |
1553 | other peer expects (i.e. that is missing!), everything | 1558 | other peer expects (i.e. that is missing!), everything |
1554 | LOWER (but excluding mid_base itself) was received. */ | 1559 | LOWER (but excluding mid_base itself) was received. */ |
1555 | mid_base = ntohl(ack->mid.mid); | 1560 | mid_base = ntohl (ack->mid.mid); |
1556 | mid_mask = GNUNET_htonll(ack->futures); | 1561 | mid_mask = GNUNET_htonll (ack->futures); |
1557 | found = GNUNET_NO; | 1562 | found = GNUNET_NO; |
1558 | for (crm = ch->head_sent; NULL != crm; crm = crmn) | 1563 | for (crm = ch->head_sent; NULL != crm; crm = crmn) |
1564 | { | ||
1565 | crmn = crm->next; | ||
1566 | delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); | ||
1567 | if (delta >= UINT_MAX - ch->max_pending_messages) | ||
1559 | { | 1568 | { |
1560 | crmn = crm->next; | 1569 | /* overflow, means crm was a bit in the past, so this ACK counts for it. */ |
1561 | delta = (unsigned int)(ntohl(crm->data_message->mid.mid) - mid_base); | 1570 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1562 | if (delta >= UINT_MAX - ch->max_pending_messages) | 1571 | "Got DATA_ACK with base %u satisfying past message %u on %s\n", |
1563 | { | 1572 | (unsigned int) mid_base, |
1564 | /* overflow, means crm was a bit in the past, so this ACK counts for it. */ | 1573 | ntohl (crm->data_message->mid.mid), |
1565 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1574 | GCCH_2s (ch)); |
1566 | "Got DATA_ACK with base %u satisfying past message %u on %s\n", | 1575 | handle_matching_ack (ch, cti, crm); |
1567 | (unsigned int)mid_base, | 1576 | found = GNUNET_YES; |
1568 | ntohl(crm->data_message->mid.mid), | 1577 | continue; |
1569 | GCCH_2s(ch)); | ||
1570 | handle_matching_ack(ch, cti, crm); | ||
1571 | found = GNUNET_YES; | ||
1572 | continue; | ||
1573 | } | ||
1574 | delta--; | ||
1575 | if (delta >= 64) | ||
1576 | continue; | ||
1577 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1578 | "Testing bit %llX for mid %u (base: %u)\n", | ||
1579 | (1LLU << delta), | ||
1580 | ntohl(crm->data_message->mid.mid), | ||
1581 | mid_base); | ||
1582 | if (0 != (mid_mask & (1LLU << delta))) | ||
1583 | { | ||
1584 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1585 | "Got DATA_ACK with mask for %u on %s\n", | ||
1586 | ntohl(crm->data_message->mid.mid), | ||
1587 | GCCH_2s(ch)); | ||
1588 | handle_matching_ack(ch, cti, crm); | ||
1589 | found = GNUNET_YES; | ||
1590 | } | ||
1591 | } | 1578 | } |
1592 | if (GNUNET_NO == found) | 1579 | delta--; |
1580 | if (delta >= 64) | ||
1581 | continue; | ||
1582 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1583 | "Testing bit %llX for mid %u (base: %u)\n", | ||
1584 | (1LLU << delta), | ||
1585 | ntohl (crm->data_message->mid.mid), | ||
1586 | mid_base); | ||
1587 | if (0 != (mid_mask & (1LLU << delta))) | ||
1593 | { | 1588 | { |
1594 | /* ACK for message we already dropped, might have been a | 1589 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1595 | duplicate ACK? Ignore. */ | 1590 | "Got DATA_ACK with mask for %u on %s\n", |
1596 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1591 | ntohl (crm->data_message->mid.mid), |
1597 | "Duplicate DATA_ACK on %s, ignoring\n", | 1592 | GCCH_2s (ch)); |
1598 | GCCH_2s(ch)); | 1593 | handle_matching_ack (ch, cti, crm); |
1599 | GNUNET_STATISTICS_update(stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); | 1594 | found = GNUNET_YES; |
1600 | return; | ||
1601 | } | 1595 | } |
1596 | } | ||
1597 | if (GNUNET_NO == found) | ||
1598 | { | ||
1599 | /* ACK for message we already dropped, might have been a | ||
1600 | duplicate ACK? Ignore. */ | ||
1601 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1602 | "Duplicate DATA_ACK on %s, ignoring\n", | ||
1603 | GCCH_2s (ch)); | ||
1604 | GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); | ||
1605 | return; | ||
1606 | } | ||
1602 | if (NULL != ch->retry_data_task) | 1607 | if (NULL != ch->retry_data_task) |
1603 | { | 1608 | { |
1604 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); | 1609 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1605 | ch->retry_data_task = NULL; | 1610 | ch->retry_data_task = NULL; |
1606 | } | 1611 | } |
1607 | if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) | 1612 | if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) |
1608 | ch->retry_data_task = GNUNET_SCHEDULER_add_at(ch->head_sent->next_retry, | 1613 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, |
1609 | &retry_transmission, | 1614 | &retry_transmission, |
1610 | ch); | 1615 | ch); |
1611 | } | 1616 | } |
1612 | 1617 | ||
1613 | 1618 | ||
@@ -1621,34 +1626,34 @@ GCCH_handle_channel_plaintext_data_ack( | |||
1621 | * NULL if we are simulating receiving a destroy due to shutdown | 1626 | * NULL if we are simulating receiving a destroy due to shutdown |
1622 | */ | 1627 | */ |
1623 | void | 1628 | void |
1624 | GCCH_handle_remote_destroy( | 1629 | GCCH_handle_remote_destroy ( |
1625 | struct CadetChannel *ch, | 1630 | struct CadetChannel *ch, |
1626 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 1631 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) |
1627 | { | 1632 | { |
1628 | struct CadetChannelClient *ccc; | 1633 | struct CadetChannelClient *ccc; |
1629 | 1634 | ||
1630 | GNUNET_assert(GNUNET_NO == ch->is_loopback); | 1635 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1631 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1636 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1632 | "Received remote channel DESTROY for %s\n", | 1637 | "Received remote channel DESTROY for %s\n", |
1633 | GCCH_2s(ch)); | 1638 | GCCH_2s (ch)); |
1634 | if (GNUNET_YES == ch->destroy) | 1639 | if (GNUNET_YES == ch->destroy) |
1635 | { | 1640 | { |
1636 | /* Local client already gone, this is instant-death. */ | 1641 | /* Local client already gone, this is instant-death. */ |
1637 | channel_destroy(ch); | 1642 | channel_destroy (ch); |
1638 | return; | 1643 | return; |
1639 | } | 1644 | } |
1640 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1645 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1641 | if ((NULL != ccc) && (NULL != ccc->head_recv)) | 1646 | if ((NULL != ccc) && (NULL != ccc->head_recv)) |
1642 | { | 1647 | { |
1643 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1648 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1644 | "Lost end of transmission due to remote shutdown on %s\n", | 1649 | "Lost end of transmission due to remote shutdown on %s\n", |
1645 | GCCH_2s(ch)); | 1650 | GCCH_2s (ch)); |
1646 | /* FIXME: change API to notify client about truncated transmission! */ | 1651 | /* FIXME: change API to notify client about truncated transmission! */ |
1647 | } | 1652 | } |
1648 | ch->destroy = GNUNET_YES; | 1653 | ch->destroy = GNUNET_YES; |
1649 | if (NULL != ccc) | 1654 | if (NULL != ccc) |
1650 | GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch); | 1655 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); |
1651 | channel_destroy(ch); | 1656 | channel_destroy (ch); |
1652 | } | 1657 | } |
1653 | 1658 | ||
1654 | 1659 | ||
@@ -1661,9 +1666,9 @@ GCCH_handle_remote_destroy( | |||
1661 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO | 1666 | * @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO |
1662 | */ | 1667 | */ |
1663 | static int | 1668 | static int |
1664 | cmp_crm_by_next_retry(void *cls, | 1669 | cmp_crm_by_next_retry (void *cls, |
1665 | struct CadetReliableMessage *crm1, | 1670 | struct CadetReliableMessage *crm1, |
1666 | struct CadetReliableMessage *crm2) | 1671 | struct CadetReliableMessage *crm2) |
1667 | { | 1672 | { |
1668 | if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) | 1673 | if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) |
1669 | return GNUNET_YES; | 1674 | return GNUNET_YES; |
@@ -1682,75 +1687,76 @@ cmp_crm_by_next_retry(void *cls, | |||
1682 | * if transmission failed | 1687 | * if transmission failed |
1683 | */ | 1688 | */ |
1684 | static void | 1689 | static void |
1685 | data_sent_cb(void *cls, | 1690 | data_sent_cb (void *cls, |
1686 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 1691 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
1687 | { | 1692 | { |
1688 | struct CadetReliableMessage *crm = cls; | 1693 | struct CadetReliableMessage *crm = cls; |
1689 | struct CadetChannel *ch = crm->ch; | 1694 | struct CadetChannel *ch = crm->ch; |
1690 | 1695 | ||
1691 | GNUNET_assert(GNUNET_NO == ch->is_loopback); | 1696 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1692 | GNUNET_assert(NULL != crm->qe); | 1697 | GNUNET_assert (NULL != crm->qe); |
1693 | crm->qe = NULL; | 1698 | crm->qe = NULL; |
1694 | GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm); | 1699 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
1695 | if (GNUNET_NO == ch->reliable) | 1700 | if (GNUNET_NO == ch->reliable) |
1696 | { | 1701 | { |
1697 | GNUNET_free(crm->data_message); | 1702 | GNUNET_free (crm->data_message); |
1698 | GNUNET_free(crm); | 1703 | GNUNET_free (crm); |
1699 | ch->pending_messages--; | 1704 | ch->pending_messages--; |
1700 | send_ack_to_client(ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); | 1705 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1701 | return; | 1706 | return; |
1702 | } | 1707 | } |
1703 | if (NULL == cid) | 1708 | if (NULL == cid) |
1704 | { | 1709 | { |
1705 | /* There was an error sending. */ | 1710 | /* There was an error sending. */ |
1706 | crm->num_transmissions = GNUNET_SYSERR; | 1711 | crm->num_transmissions = GNUNET_SYSERR; |
1707 | } | 1712 | } |
1708 | else if (GNUNET_SYSERR != crm->num_transmissions) | 1713 | else if (GNUNET_SYSERR != crm->num_transmissions) |
1714 | { | ||
1715 | /* Increment transmission counter, and possibly store @a cid | ||
1716 | if this was the first transmission. */ | ||
1717 | crm->num_transmissions++; | ||
1718 | if (1 == crm->num_transmissions) | ||
1709 | { | 1719 | { |
1710 | /* Increment transmission counter, and possibly store @a cid | 1720 | crm->first_transmission_time = GNUNET_TIME_absolute_get (); |
1711 | if this was the first transmission. */ | 1721 | crm->connection_taken = *cid; |
1712 | crm->num_transmissions++; | 1722 | GCC_ack_expected (cid); |
1713 | if (1 == crm->num_transmissions) | ||
1714 | { | ||
1715 | crm->first_transmission_time = GNUNET_TIME_absolute_get(); | ||
1716 | crm->connection_taken = *cid; | ||
1717 | GCC_ack_expected(cid); | ||
1718 | } | ||
1719 | } | 1723 | } |
1724 | } | ||
1720 | if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) | 1725 | if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) |
1721 | { | 1726 | { |
1722 | struct CadetConnection *cc = GCC_lookup(cid); | 1727 | struct CadetConnection *cc = GCC_lookup (cid); |
1723 | 1728 | ||
1724 | if (NULL != cc) | 1729 | if (NULL != cc) |
1725 | crm->retry_delay = GCC_get_metrics(cc)->aged_latency; | 1730 | crm->retry_delay = GCC_get_metrics (cc)->aged_latency; |
1726 | else | 1731 | else |
1727 | crm->retry_delay = ch->retry_time; | 1732 | crm->retry_delay = ch->retry_time; |
1728 | } | 1733 | } |
1729 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF(crm->retry_delay); | 1734 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); |
1730 | crm->retry_delay = GNUNET_TIME_relative_max(crm->retry_delay, MIN_RTT_DELAY); | 1735 | crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY); |
1731 | crm->next_retry = GNUNET_TIME_relative_to_absolute(crm->retry_delay); | 1736 | crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); |
1732 | 1737 | ||
1733 | GNUNET_CONTAINER_DLL_insert_sorted(struct CadetReliableMessage, | 1738 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, |
1734 | cmp_crm_by_next_retry, | 1739 | cmp_crm_by_next_retry, |
1735 | NULL, | 1740 | NULL, |
1736 | ch->head_sent, | 1741 | ch->head_sent, |
1737 | ch->tail_sent, | 1742 | ch->tail_sent, |
1738 | crm); | 1743 | crm); |
1739 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1744 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1740 | "Message %u sent, next transmission on %s in %s\n", | 1745 | "Message %u sent, next transmission on %s in %s\n", |
1741 | (unsigned int)ntohl(crm->data_message->mid.mid), | 1746 | (unsigned int) ntohl (crm->data_message->mid.mid), |
1742 | GCCH_2s(ch), | 1747 | GCCH_2s (ch), |
1743 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( | 1748 | GNUNET_STRINGS_relative_time_to_string ( |
1744 | ch->head_sent->next_retry), | 1749 | GNUNET_TIME_absolute_get_remaining ( |
1745 | GNUNET_YES)); | 1750 | ch->head_sent->next_retry), |
1751 | GNUNET_YES)); | ||
1746 | if (NULL == ch->head_sent->qe) | 1752 | if (NULL == ch->head_sent->qe) |
1747 | { | 1753 | { |
1748 | if (NULL != ch->retry_data_task) | 1754 | if (NULL != ch->retry_data_task) |
1749 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); | 1755 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1750 | ch->retry_data_task = GNUNET_SCHEDULER_add_at(ch->head_sent->next_retry, | 1756 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, |
1751 | &retry_transmission, | 1757 | &retry_transmission, |
1752 | ch); | 1758 | ch); |
1753 | } | 1759 | } |
1754 | } | 1760 | } |
1755 | 1761 | ||
1756 | 1762 | ||
@@ -1769,100 +1775,100 @@ data_sent_cb(void *cls, | |||
1769 | * #GNUNET_SYSERR in case of an error. | 1775 | * #GNUNET_SYSERR in case of an error. |
1770 | */ | 1776 | */ |
1771 | int | 1777 | int |
1772 | GCCH_handle_local_data(struct CadetChannel *ch, | 1778 | GCCH_handle_local_data (struct CadetChannel *ch, |
1773 | struct GNUNET_CADET_ClientChannelNumber sender_ccn, | 1779 | struct GNUNET_CADET_ClientChannelNumber sender_ccn, |
1774 | const char *buf, | 1780 | const char *buf, |
1775 | size_t buf_len) | 1781 | size_t buf_len) |
1776 | { | 1782 | { |
1777 | struct CadetReliableMessage *crm; | 1783 | struct CadetReliableMessage *crm; |
1778 | 1784 | ||
1779 | if (ch->pending_messages >= ch->max_pending_messages) | 1785 | if (ch->pending_messages >= ch->max_pending_messages) |
1786 | { | ||
1787 | GNUNET_break (0); /* Fails: #5370 */ | ||
1788 | return GNUNET_SYSERR; | ||
1789 | } | ||
1790 | if (GNUNET_YES == ch->destroy) | ||
1791 | { | ||
1792 | /* we are going down, drop messages */ | ||
1793 | return GNUNET_OK; | ||
1794 | } | ||
1795 | ch->pending_messages++; | ||
1796 | |||
1797 | if (GNUNET_YES == ch->is_loopback) | ||
1798 | { | ||
1799 | struct CadetChannelClient *receiver; | ||
1800 | struct GNUNET_MQ_Envelope *env; | ||
1801 | struct GNUNET_CADET_LocalData *ld; | ||
1802 | int ack_to_owner; | ||
1803 | |||
1804 | env = | ||
1805 | GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | ||
1806 | if ((NULL != ch->owner) && | ||
1807 | (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1808 | { | ||
1809 | receiver = ch->dest; | ||
1810 | ack_to_owner = GNUNET_YES; | ||
1811 | } | ||
1812 | else if ((NULL != ch->dest) && | ||
1813 | (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) | ||
1814 | { | ||
1815 | receiver = ch->owner; | ||
1816 | ack_to_owner = GNUNET_NO; | ||
1817 | } | ||
1818 | else | ||
1780 | { | 1819 | { |
1781 | GNUNET_break(0); /* Fails: #5370 */ | 1820 | GNUNET_break (0); |
1782 | return GNUNET_SYSERR; | 1821 | return GNUNET_SYSERR; |
1783 | } | 1822 | } |
1784 | if (GNUNET_YES == ch->destroy) | 1823 | GNUNET_assert (NULL != receiver); |
1824 | ld->ccn = receiver->ccn; | ||
1825 | GNUNET_memcpy (&ld[1], buf, buf_len); | ||
1826 | if (GNUNET_YES == receiver->client_ready) | ||
1785 | { | 1827 | { |
1786 | /* we are going down, drop messages */ | 1828 | ch->pending_messages--; |
1787 | return GNUNET_OK; | 1829 | GSC_send_to_client (receiver->c, env); |
1830 | send_ack_to_client (ch, ack_to_owner); | ||
1788 | } | 1831 | } |
1789 | ch->pending_messages++; | 1832 | else |
1790 | |||
1791 | if (GNUNET_YES == ch->is_loopback) | ||
1792 | { | 1833 | { |
1793 | struct CadetChannelClient *receiver; | 1834 | struct CadetOutOfOrderMessage *oom; |
1794 | struct GNUNET_MQ_Envelope *env; | 1835 | |
1795 | struct GNUNET_CADET_LocalData *ld; | 1836 | oom = GNUNET_new (struct CadetOutOfOrderMessage); |
1796 | int ack_to_owner; | 1837 | oom->env = env; |
1797 | 1838 | GNUNET_CONTAINER_DLL_insert_tail (receiver->head_recv, | |
1798 | env = | 1839 | receiver->tail_recv, |
1799 | GNUNET_MQ_msg_extra(ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1840 | oom); |
1800 | if ((NULL != ch->owner) && | 1841 | receiver->num_recv++; |
1801 | (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1802 | { | ||
1803 | receiver = ch->dest; | ||
1804 | ack_to_owner = GNUNET_YES; | ||
1805 | } | ||
1806 | else if ((NULL != ch->dest) && | ||
1807 | (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) | ||
1808 | { | ||
1809 | receiver = ch->owner; | ||
1810 | ack_to_owner = GNUNET_NO; | ||
1811 | } | ||
1812 | else | ||
1813 | { | ||
1814 | GNUNET_break(0); | ||
1815 | return GNUNET_SYSERR; | ||
1816 | } | ||
1817 | GNUNET_assert(NULL != receiver); | ||
1818 | ld->ccn = receiver->ccn; | ||
1819 | GNUNET_memcpy(&ld[1], buf, buf_len); | ||
1820 | if (GNUNET_YES == receiver->client_ready) | ||
1821 | { | ||
1822 | ch->pending_messages--; | ||
1823 | GSC_send_to_client(receiver->c, env); | ||
1824 | send_ack_to_client(ch, ack_to_owner); | ||
1825 | } | ||
1826 | else | ||
1827 | { | ||
1828 | struct CadetOutOfOrderMessage *oom; | ||
1829 | |||
1830 | oom = GNUNET_new(struct CadetOutOfOrderMessage); | ||
1831 | oom->env = env; | ||
1832 | GNUNET_CONTAINER_DLL_insert_tail(receiver->head_recv, | ||
1833 | receiver->tail_recv, | ||
1834 | oom); | ||
1835 | receiver->num_recv++; | ||
1836 | } | ||
1837 | return GNUNET_OK; | ||
1838 | } | 1842 | } |
1843 | return GNUNET_OK; | ||
1844 | } | ||
1839 | 1845 | ||
1840 | /* Everything is correct, send the message. */ | 1846 | /* Everything is correct, send the message. */ |
1841 | crm = GNUNET_malloc(sizeof(*crm)); | 1847 | crm = GNUNET_malloc (sizeof(*crm)); |
1842 | crm->ch = ch; | 1848 | crm->ch = ch; |
1843 | crm->data_message = GNUNET_malloc( | 1849 | crm->data_message = GNUNET_malloc ( |
1844 | sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); | 1850 | sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1845 | crm->data_message->header.size = | 1851 | crm->data_message->header.size = |
1846 | htons(sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); | 1852 | htons (sizeof(struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1847 | crm->data_message->header.type = | 1853 | crm->data_message->header.type = |
1848 | htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); | 1854 | htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); |
1849 | ch->mid_send.mid = htonl(ntohl(ch->mid_send.mid) + 1); | 1855 | ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); |
1850 | crm->data_message->mid = ch->mid_send; | 1856 | crm->data_message->mid = ch->mid_send; |
1851 | crm->data_message->ctn = ch->ctn; | 1857 | crm->data_message->ctn = ch->ctn; |
1852 | GNUNET_memcpy(&crm->data_message[1], buf, buf_len); | 1858 | GNUNET_memcpy (&crm->data_message[1], buf, buf_len); |
1853 | GNUNET_CONTAINER_DLL_insert_tail(ch->head_sent, ch->tail_sent, crm); | 1859 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); |
1854 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1860 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1855 | "Sending message %u from local client to %s with %u bytes\n", | 1861 | "Sending message %u from local client to %s with %u bytes\n", |
1856 | ntohl(crm->data_message->mid.mid), | 1862 | ntohl (crm->data_message->mid.mid), |
1857 | GCCH_2s(ch), | 1863 | GCCH_2s (ch), |
1858 | buf_len); | 1864 | buf_len); |
1859 | if (NULL != ch->retry_data_task) | 1865 | if (NULL != ch->retry_data_task) |
1860 | { | 1866 | { |
1861 | GNUNET_SCHEDULER_cancel(ch->retry_data_task); | 1867 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1862 | ch->retry_data_task = NULL; | 1868 | ch->retry_data_task = NULL; |
1863 | } | 1869 | } |
1864 | crm->qe = GCT_send(ch->t, &crm->data_message->header, &data_sent_cb, crm); | 1870 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1865 | GNUNET_assert(NULL == ch->retry_data_task); | 1871 | GNUNET_assert (NULL == ch->retry_data_task); |
1866 | return GNUNET_OK; | 1872 | return GNUNET_OK; |
1867 | } | 1873 | } |
1868 | 1874 | ||
@@ -1875,8 +1881,8 @@ GCCH_handle_local_data(struct CadetChannel *ch, | |||
1875 | * @param client_ccn ccn of the client sending the ack | 1881 | * @param client_ccn ccn of the client sending the ack |
1876 | */ | 1882 | */ |
1877 | void | 1883 | void |
1878 | GCCH_handle_local_ack(struct CadetChannel *ch, | 1884 | GCCH_handle_local_ack (struct CadetChannel *ch, |
1879 | struct GNUNET_CADET_ClientChannelNumber client_ccn) | 1885 | struct GNUNET_CADET_ClientChannelNumber client_ccn) |
1880 | { | 1886 | { |
1881 | struct CadetChannelClient *ccc; | 1887 | struct CadetChannelClient *ccc; |
1882 | struct CadetOutOfOrderMessage *com; | 1888 | struct CadetOutOfOrderMessage *com; |
@@ -1888,87 +1894,87 @@ GCCH_handle_local_ack(struct CadetChannel *ch, | |||
1888 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) | 1894 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) |
1889 | ccc = ch->dest; | 1895 | ccc = ch->dest; |
1890 | else | 1896 | else |
1891 | GNUNET_assert(0); | 1897 | GNUNET_assert (0); |
1892 | ccc->client_ready = GNUNET_YES; | 1898 | ccc->client_ready = GNUNET_YES; |
1893 | com = ccc->head_recv; | 1899 | com = ccc->head_recv; |
1894 | if (NULL == com) | 1900 | if (NULL == com) |
1901 | { | ||
1902 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1903 | "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n", | ||
1904 | GSC_2s (ccc->c), | ||
1905 | ntohl (client_ccn.channel_of_client), | ||
1906 | GCCH_2s (ch), | ||
1907 | ntohl (ccc->ccn.channel_of_client), | ||
1908 | ccc); | ||
1909 | return; /* none pending */ | ||
1910 | } | ||
1911 | if (GNUNET_YES == ch->is_loopback) | ||
1912 | { | ||
1913 | int to_owner; | ||
1914 | |||
1915 | /* Messages are always in-order, just send */ | ||
1916 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); | ||
1917 | ccc->num_recv--; | ||
1918 | GSC_send_to_client (ccc->c, com->env); | ||
1919 | /* Notify sender that we can receive more */ | ||
1920 | if ((NULL != ch->owner) && | ||
1921 | (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1895 | { | 1922 | { |
1896 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1923 | to_owner = GNUNET_NO; |
1897 | "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n", | ||
1898 | GSC_2s(ccc->c), | ||
1899 | ntohl(client_ccn.channel_of_client), | ||
1900 | GCCH_2s(ch), | ||
1901 | ntohl(ccc->ccn.channel_of_client), | ||
1902 | ccc); | ||
1903 | return; /* none pending */ | ||
1904 | } | 1924 | } |
1905 | if (GNUNET_YES == ch->is_loopback) | 1925 | else |
1906 | { | 1926 | { |
1907 | int to_owner; | 1927 | GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client == |
1908 | 1928 | ch->dest->ccn.channel_of_client)); | |
1909 | /* Messages are always in-order, just send */ | 1929 | to_owner = GNUNET_YES; |
1910 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); | ||
1911 | ccc->num_recv--; | ||
1912 | GSC_send_to_client(ccc->c, com->env); | ||
1913 | /* Notify sender that we can receive more */ | ||
1914 | if ((NULL != ch->owner) && | ||
1915 | (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) | ||
1916 | { | ||
1917 | to_owner = GNUNET_NO; | ||
1918 | } | ||
1919 | else | ||
1920 | { | ||
1921 | GNUNET_assert((NULL != ch->dest) && (ccc->ccn.channel_of_client == | ||
1922 | ch->dest->ccn.channel_of_client)); | ||
1923 | to_owner = GNUNET_YES; | ||
1924 | } | ||
1925 | send_ack_to_client(ch, to_owner); | ||
1926 | GNUNET_free(com); | ||
1927 | return; | ||
1928 | } | 1930 | } |
1931 | send_ack_to_client (ch, to_owner); | ||
1932 | GNUNET_free (com); | ||
1933 | return; | ||
1934 | } | ||
1929 | 1935 | ||
1930 | if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && | 1936 | if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && |
1931 | (GNUNET_YES == ch->reliable)) | 1937 | (GNUNET_YES == ch->reliable)) |
1932 | { | 1938 | { |
1933 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1939 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1934 | "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", | 1940 | "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", |
1935 | GSC_2s(ccc->c), | 1941 | GSC_2s (ccc->c), |
1936 | ntohl(ccc->ccn.channel_of_client), | 1942 | ntohl (ccc->ccn.channel_of_client), |
1937 | ntohl(com->mid.mid), | 1943 | ntohl (com->mid.mid), |
1938 | ntohl(ch->mid_recv.mid)); | 1944 | ntohl (ch->mid_recv.mid)); |
1939 | return; /* missing next one in-order */ | 1945 | return; /* missing next one in-order */ |
1940 | } | 1946 | } |
1941 | 1947 | ||
1942 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1948 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1943 | "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n", | 1949 | "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n", |
1944 | ntohl(com->mid.mid), | 1950 | ntohl (com->mid.mid), |
1945 | GSC_2s(ccc->c), | 1951 | GSC_2s (ccc->c), |
1946 | ntohl(ccc->ccn.channel_of_client), | 1952 | ntohl (ccc->ccn.channel_of_client), |
1947 | GCCH_2s(ch)); | 1953 | GCCH_2s (ch)); |
1948 | 1954 | ||
1949 | /* all good, pass next message to client */ | 1955 | /* all good, pass next message to client */ |
1950 | GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com); | 1956 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
1951 | ccc->num_recv--; | 1957 | ccc->num_recv--; |
1952 | /* FIXME: if unreliable, this is not aggressive | 1958 | /* FIXME: if unreliable, this is not aggressive |
1953 | enough, as it would be OK to have lost some! */ | 1959 | enough, as it would be OK to have lost some! */ |
1954 | 1960 | ||
1955 | ch->mid_recv.mid = htonl(1 + ntohl(com->mid.mid)); | 1961 | ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); |
1956 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ | 1962 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ |
1957 | ccc->client_ready = GNUNET_NO; | 1963 | ccc->client_ready = GNUNET_NO; |
1958 | GSC_send_to_client(ccc->c, com->env); | 1964 | GSC_send_to_client (ccc->c, com->env); |
1959 | GNUNET_free(com); | 1965 | GNUNET_free (com); |
1960 | send_channel_data_ack(ch); | 1966 | send_channel_data_ack (ch); |
1961 | if (NULL != ccc->head_recv) | 1967 | if (NULL != ccc->head_recv) |
1962 | return; | 1968 | return; |
1963 | if (GNUNET_NO == ch->destroy) | 1969 | if (GNUNET_NO == ch->destroy) |
1964 | return; | 1970 | return; |
1965 | GCT_send_channel_destroy(ch->t, ch->ctn); | 1971 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1966 | channel_destroy(ch); | 1972 | channel_destroy (ch); |
1967 | } | 1973 | } |
1968 | 1974 | ||
1969 | 1975 | ||
1970 | #define LOG2(level, ...) \ | 1976 | #define LOG2(level, ...) \ |
1971 | GNUNET_log_from_nocheck(level, "cadet-chn", __VA_ARGS__) | 1977 | GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__) |
1972 | 1978 | ||
1973 | 1979 | ||
1974 | /** | 1980 | /** |
@@ -1978,46 +1984,46 @@ GCCH_handle_local_ack(struct CadetChannel *ch, | |||
1978 | * @param level Debug level to use. | 1984 | * @param level Debug level to use. |
1979 | */ | 1985 | */ |
1980 | void | 1986 | void |
1981 | GCCH_debug(struct CadetChannel *ch, enum GNUNET_ErrorType level) | 1987 | GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) |
1982 | { | 1988 | { |
1983 | #if !defined(GNUNET_CULL_LOGGING) | 1989 | #if ! defined(GNUNET_CULL_LOGGING) |
1984 | int do_log; | 1990 | int do_log; |
1985 | 1991 | ||
1986 | do_log = GNUNET_get_log_call_status(level & (~GNUNET_ERROR_TYPE_BULK), | 1992 | do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), |
1987 | "cadet-chn", | 1993 | "cadet-chn", |
1988 | __FILE__, | 1994 | __FILE__, |
1989 | __FUNCTION__, | 1995 | __FUNCTION__, |
1990 | __LINE__); | 1996 | __LINE__); |
1991 | if (0 == do_log) | 1997 | if (0 == do_log) |
1992 | return; | 1998 | return; |
1993 | 1999 | ||
1994 | if (NULL == ch) | 2000 | if (NULL == ch) |
1995 | { | 2001 | { |
1996 | LOG2(level, "CHN *** DEBUG NULL CHANNEL ***\n"); | 2002 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); |
1997 | return; | 2003 | return; |
1998 | } | 2004 | } |
1999 | LOG2(level, "CHN %s:%X (%p)\n", GCT_2s(ch->t), ch->ctn, ch); | 2005 | LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch); |
2000 | if (NULL != ch->owner) | 2006 | if (NULL != ch->owner) |
2001 | { | 2007 | { |
2002 | LOG2(level, | 2008 | LOG2 (level, |
2003 | "CHN origin %s ready %s local-id: %u\n", | 2009 | "CHN origin %s ready %s local-id: %u\n", |
2004 | GSC_2s(ch->owner->c), | 2010 | GSC_2s (ch->owner->c), |
2005 | ch->owner->client_ready ? "YES" : "NO", | 2011 | ch->owner->client_ready ? "YES" : "NO", |
2006 | ntohl(ch->owner->ccn.channel_of_client)); | 2012 | ntohl (ch->owner->ccn.channel_of_client)); |
2007 | } | 2013 | } |
2008 | if (NULL != ch->dest) | 2014 | if (NULL != ch->dest) |
2009 | { | 2015 | { |
2010 | LOG2(level, | 2016 | LOG2 (level, |
2011 | "CHN destination %s ready %s local-id: %u\n", | 2017 | "CHN destination %s ready %s local-id: %u\n", |
2012 | GSC_2s(ch->dest->c), | 2018 | GSC_2s (ch->dest->c), |
2013 | ch->dest->client_ready ? "YES" : "NO", | 2019 | ch->dest->client_ready ? "YES" : "NO", |
2014 | ntohl(ch->dest->ccn.channel_of_client)); | 2020 | ntohl (ch->dest->ccn.channel_of_client)); |
2015 | } | 2021 | } |
2016 | LOG2(level, | 2022 | LOG2 (level, |
2017 | "CHN Message IDs recv: %d (%LLX), send: %d\n", | 2023 | "CHN Message IDs recv: %d (%LLX), send: %d\n", |
2018 | ntohl(ch->mid_recv.mid), | 2024 | ntohl (ch->mid_recv.mid), |
2019 | (unsigned long long)ch->mid_futures, | 2025 | (unsigned long long) ch->mid_futures, |
2020 | ntohl(ch->mid_send.mid)); | 2026 | ntohl (ch->mid_send.mid)); |
2021 | #endif | 2027 | #endif |
2022 | } | 2028 | } |
2023 | 2029 | ||