diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-04-13 08:51:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-04-13 08:51:53 +0000 |
commit | d045ec0ba4e862904fc310f3a247c5fb041bf6a8 (patch) | |
tree | 9728fa705372decdb35fa04413a80ee3bfddea6f /src/core | |
parent | 3ed48a1abff62a5b0e7ddd4a2a9964e2c2d7a1ff (diff) | |
download | gnunet-d045ec0ba4e862904fc310f3a247c5fb041bf6a8.tar.gz gnunet-d045ec0ba4e862904fc310f3a247c5fb041bf6a8.zip |
-fixing outbound notifications in core API
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/core_api.c | 63 | ||||
-rw-r--r-- | src/core/gnunet-service-core_clients.c | 88 | ||||
-rw-r--r-- | src/core/gnunet-service-core_clients.h | 3 |
3 files changed, 63 insertions, 91 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c index ecfe8b478..d2eaa260d 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c | |||
@@ -367,9 +367,7 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
367 | struct GNUNET_CORE_Handle *h = cls; | 367 | struct GNUNET_CORE_Handle *h = cls; |
368 | 368 | ||
369 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 369 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
370 | #if DEBUG_CORE | ||
371 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n"); | 370 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n"); |
372 | #endif | ||
373 | reconnect (h); | 371 | reconnect (h); |
374 | } | 372 | } |
375 | 373 | ||
@@ -546,11 +544,9 @@ request_next_transmission (struct PeerRecord *pr) | |||
546 | smr->smr_id = htons (th->smr_id = pr->smr_id_gen++); | 544 | smr->smr_id = htons (th->smr_id = pr->smr_id_gen++); |
547 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, | 545 | GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, |
548 | h->control_pending_tail, cm); | 546 | h->control_pending_tail, cm); |
549 | #if DEBUG_CORE | ||
550 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 547 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
551 | "Adding SEND REQUEST for peer `%s' to message queue\n", | 548 | "Adding SEND REQUEST for peer `%s' to message queue\n", |
552 | GNUNET_i2s (&pr->peer)); | 549 | GNUNET_i2s (&pr->peer)); |
553 | #endif | ||
554 | trigger_next_request (h, GNUNET_NO); | 550 | trigger_next_request (h, GNUNET_NO); |
555 | } | 551 | } |
556 | 552 | ||
@@ -580,10 +576,8 @@ transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
580 | * us from the 'ready' list */ | 576 | * us from the 'ready' list */ |
581 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); | 577 | GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); |
582 | } | 578 | } |
583 | #if DEBUG_CORE | ||
584 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 579 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Signalling timeout of request for transmission to CORE service\n"); | 580 | "Signalling timeout of request for transmission to CORE service\n"); |
586 | #endif | ||
587 | request_next_transmission (pr); | 581 | request_next_transmission (pr); |
588 | GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); | 582 | GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL)); |
589 | GNUNET_free (th); | 583 | GNUNET_free (th); |
@@ -609,10 +603,8 @@ transmit_message (void *cls, size_t size, void *buf) | |||
609 | h->cth = NULL; | 603 | h->cth = NULL; |
610 | if (buf == NULL) | 604 | if (buf == NULL) |
611 | { | 605 | { |
612 | #if DEBUG_CORE | ||
613 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 606 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
614 | "Transmission failed, initiating reconnect\n"); | 607 | "Transmission failed, initiating reconnect\n"); |
615 | #endif | ||
616 | reconnect_later (h); | 608 | reconnect_later (h); |
617 | return 0; | 609 | return 0; |
618 | } | 610 | } |
@@ -626,11 +618,9 @@ transmit_message (void *cls, size_t size, void *buf) | |||
626 | trigger_next_request (h, GNUNET_NO); | 618 | trigger_next_request (h, GNUNET_NO); |
627 | return 0; | 619 | return 0; |
628 | } | 620 | } |
629 | #if DEBUG_CORE | ||
630 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 621 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
631 | "Transmitting control message with %u bytes of type %u to core.\n", | 622 | "Transmitting control message with %u bytes of type %u to core.\n", |
632 | (unsigned int) msize, (unsigned int) ntohs (hdr->type)); | 623 | (unsigned int) msize, (unsigned int) ntohs (hdr->type)); |
633 | #endif | ||
634 | memcpy (buf, hdr, msize); | 624 | memcpy (buf, hdr, msize); |
635 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, | 625 | GNUNET_CONTAINER_DLL_remove (h->control_pending_head, |
636 | h->control_pending_tail, cm); | 626 | h->control_pending_tail, cm); |
@@ -660,11 +650,9 @@ transmit_message (void *cls, size_t size, void *buf) | |||
660 | GNUNET_SCHEDULER_cancel (pr->timeout_task); | 650 | GNUNET_SCHEDULER_cancel (pr->timeout_task); |
661 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 651 | pr->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
662 | } | 652 | } |
663 | #if DEBUG_CORE | ||
664 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 653 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
665 | "Transmitting SEND request to `%s' with %u bytes.\n", | 654 | "Transmitting SEND request to `%s' with %u bytes.\n", |
666 | GNUNET_i2s (&pr->peer), (unsigned int) th->msize); | 655 | GNUNET_i2s (&pr->peer), (unsigned int) th->msize); |
667 | #endif | ||
668 | sm = (struct SendMessage *) buf; | 656 | sm = (struct SendMessage *) buf; |
669 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); | 657 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND); |
670 | sm->priority = htonl (th->priority); | 658 | sm->priority = htonl (th->priority); |
@@ -676,28 +664,22 @@ transmit_message (void *cls, size_t size, void *buf) | |||
676 | th->get_message (th->get_message_cls, | 664 | th->get_message (th->get_message_cls, |
677 | size - sizeof (struct SendMessage), &sm[1]); | 665 | size - sizeof (struct SendMessage), &sm[1]); |
678 | 666 | ||
679 | #if DEBUG_CORE | ||
680 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 667 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
681 | "Transmitting SEND request to `%s' yielded %u bytes.\n", | 668 | "Transmitting SEND request to `%s' yielded %u bytes.\n", |
682 | GNUNET_i2s (&pr->peer), ret); | 669 | GNUNET_i2s (&pr->peer), ret); |
683 | #endif | ||
684 | GNUNET_free (th); | 670 | GNUNET_free (th); |
685 | if (0 == ret) | 671 | if (0 == ret) |
686 | { | 672 | { |
687 | #if DEBUG_CORE | ||
688 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 673 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
689 | "Size of clients message to peer %s is 0!\n", | 674 | "Size of clients message to peer %s is 0!\n", |
690 | GNUNET_i2s (&pr->peer)); | 675 | GNUNET_i2s (&pr->peer)); |
691 | #endif | ||
692 | /* client decided to send nothing! */ | 676 | /* client decided to send nothing! */ |
693 | request_next_transmission (pr); | 677 | request_next_transmission (pr); |
694 | return 0; | 678 | return 0; |
695 | } | 679 | } |
696 | #if DEBUG_CORE | ||
697 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 680 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
698 | "Produced SEND message to core with %u bytes payload\n", | 681 | "Produced SEND message to core with %u bytes payload\n", |
699 | (unsigned int) ret); | 682 | (unsigned int) ret); |
700 | #endif | ||
701 | GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader)); | 683 | GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader)); |
702 | if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 684 | if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
703 | { | 685 | { |
@@ -729,17 +711,13 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down) | |||
729 | 711 | ||
730 | if ((GNUNET_YES == h->currently_down) && (ignore_currently_down == GNUNET_NO)) | 712 | if ((GNUNET_YES == h->currently_down) && (ignore_currently_down == GNUNET_NO)) |
731 | { | 713 | { |
732 | #if DEBUG_CORE | ||
733 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 714 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
734 | "Core connection down, not processing queue\n"); | 715 | "Core connection down, not processing queue\n"); |
735 | #endif | ||
736 | return; | 716 | return; |
737 | } | 717 | } |
738 | if (NULL != h->cth) | 718 | if (NULL != h->cth) |
739 | { | 719 | { |
740 | #if DEBUG_CORE | ||
741 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Request pending, not processing queue\n"); | 720 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Request pending, not processing queue\n"); |
742 | #endif | ||
743 | return; | 721 | return; |
744 | } | 722 | } |
745 | if (h->control_pending_head != NULL) | 723 | if (h->control_pending_head != NULL) |
@@ -751,10 +729,8 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down) | |||
751 | h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); | 729 | h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); |
752 | else | 730 | else |
753 | { | 731 | { |
754 | #if DEBUG_CORE | ||
755 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 732 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
756 | "Request queue empty, not processing queue\n"); | 733 | "Request queue empty, not processing queue\n"); |
757 | #endif | ||
758 | return; /* no pending message */ | 734 | return; /* no pending message */ |
759 | } | 735 | } |
760 | h->cth = | 736 | h->cth = |
@@ -800,11 +776,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
800 | return; | 776 | return; |
801 | } | 777 | } |
802 | msize = ntohs (msg->size); | 778 | msize = ntohs (msg->size); |
803 | #if DEBUG_CORE > 2 | ||
804 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 779 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
805 | "Processing message of type %u and size %u from core service\n", | 780 | "Processing message of type %u and size %u from core service\n", |
806 | ntohs (msg->type), msize); | 781 | ntohs (msg->type), msize); |
807 | #endif | ||
808 | switch (ntohs (msg->type)) | 782 | switch (ntohs (msg->type)) |
809 | { | 783 | { |
810 | case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY: | 784 | case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY: |
@@ -828,18 +802,14 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
828 | { | 802 | { |
829 | /* mark so we don't call init on reconnect */ | 803 | /* mark so we don't call init on reconnect */ |
830 | h->init = NULL; | 804 | h->init = NULL; |
831 | #if DEBUG_CORE | ||
832 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to core service of peer `%s'.\n", | 805 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to core service of peer `%s'.\n", |
833 | GNUNET_i2s (&h->me)); | 806 | GNUNET_i2s (&h->me)); |
834 | #endif | ||
835 | init (h->cls, h, &h->me); | 807 | init (h->cls, h, &h->me); |
836 | } | 808 | } |
837 | else | 809 | else |
838 | { | 810 | { |
839 | #if DEBUG_CORE | ||
840 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 811 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
841 | "Successfully reconnected to core service.\n"); | 812 | "Successfully reconnected to core service.\n"); |
842 | #endif | ||
843 | } | 813 | } |
844 | /* fake 'connect to self' */ | 814 | /* fake 'connect to self' */ |
845 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &h->me.hashPubKey); | 815 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &h->me.hashPubKey); |
@@ -871,11 +841,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
871 | reconnect_later (h); | 841 | reconnect_later (h); |
872 | return; | 842 | return; |
873 | } | 843 | } |
874 | #if DEBUG_CORE | ||
875 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 844 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
876 | "Received notification about connection from `%s'.\n", | 845 | "Received notification about connection from `%s'.\n", |
877 | GNUNET_i2s (&cnm->peer)); | 846 | GNUNET_i2s (&cnm->peer)); |
878 | #endif | ||
879 | if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity))) | 847 | if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity))) |
880 | { | 848 | { |
881 | /* connect to self!? */ | 849 | /* connect to self!? */ |
@@ -915,11 +883,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
915 | return; | 883 | return; |
916 | } | 884 | } |
917 | GNUNET_break (0 == ntohl (dnm->reserved)); | 885 | GNUNET_break (0 == ntohl (dnm->reserved)); |
918 | #if DEBUG_CORE | ||
919 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 886 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
920 | "Received notification about disconnect from `%s'.\n", | 887 | "Received notification about disconnect from `%s'.\n", |
921 | GNUNET_i2s (&dnm->peer)); | 888 | GNUNET_i2s (&dnm->peer)); |
922 | #endif | ||
923 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &dnm->peer.hashPubKey); | 889 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &dnm->peer.hashPubKey); |
924 | if (pr == NULL) | 890 | if (pr == NULL) |
925 | { | 891 | { |
@@ -954,11 +920,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
954 | return; | 920 | return; |
955 | } | 921 | } |
956 | em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1]; | 922 | em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1]; |
957 | #if DEBUG_CORE | ||
958 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 923 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
959 | "Received message of type %u and size %u from peer `%4s'\n", | 924 | "Received message of type %u and size %u from peer `%4s'\n", |
960 | ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer)); | 925 | ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer)); |
961 | #endif | ||
962 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); | 926 | pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey); |
963 | if (pr == NULL) | 927 | if (pr == NULL) |
964 | { | 928 | { |
@@ -1033,11 +997,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1033 | reconnect_later (h); | 997 | reconnect_later (h); |
1034 | return; | 998 | return; |
1035 | } | 999 | } |
1036 | #if DEBUG_CORE | ||
1037 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1000 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1038 | "Received notification about transmission to `%s'.\n", | 1001 | "Received notification about transmission to `%s'.\n", |
1039 | GNUNET_i2s (&ntm->peer)); | 1002 | GNUNET_i2s (&ntm->peer)); |
1040 | #endif | ||
1041 | if ((GNUNET_NO == h->outbound_hdr_only) && | 1003 | if ((GNUNET_NO == h->outbound_hdr_only) && |
1042 | (msize != | 1004 | (msize != |
1043 | ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + | 1005 | ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + |
@@ -1069,11 +1031,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1069 | reconnect_later (h); | 1031 | reconnect_later (h); |
1070 | return; | 1032 | return; |
1071 | } | 1033 | } |
1072 | #if DEBUG_CORE | ||
1073 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1034 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1074 | "Received notification about transmission readiness to `%s'.\n", | 1035 | "Received notification about transmission readiness to `%s'.\n", |
1075 | GNUNET_i2s (&smr->peer)); | 1036 | GNUNET_i2s (&smr->peer)); |
1076 | #endif | ||
1077 | if (pr->pending_head == NULL) | 1037 | if (pr->pending_head == NULL) |
1078 | { | 1038 | { |
1079 | /* request must have been cancelled between the original request | 1039 | /* request must have been cancelled between the original request |
@@ -1123,10 +1083,8 @@ init_done_task (void *cls, int success) | |||
1123 | return; /* shutdown */ | 1083 | return; /* shutdown */ |
1124 | if (success == GNUNET_NO) | 1084 | if (success == GNUNET_NO) |
1125 | { | 1085 | { |
1126 | #if DEBUG_CORE | ||
1127 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1086 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1128 | "Failed to exchange INIT with core, retrying\n"); | 1087 | "Failed to exchange INIT with core, retrying\n"); |
1129 | #endif | ||
1130 | if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK) | 1088 | if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK) |
1131 | reconnect_later (h); | 1089 | reconnect_later (h); |
1132 | return; | 1090 | return; |
@@ -1152,9 +1110,6 @@ reconnect (struct GNUNET_CORE_Handle *h) | |||
1152 | uint16_t *ts; | 1110 | uint16_t *ts; |
1153 | unsigned int hpos; | 1111 | unsigned int hpos; |
1154 | 1112 | ||
1155 | #if DEBUG_CORE | ||
1156 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to CORE service\n"); | ||
1157 | #endif | ||
1158 | GNUNET_assert (h->client == NULL); | 1113 | GNUNET_assert (h->client == NULL); |
1159 | GNUNET_assert (h->currently_down == GNUNET_YES); | 1114 | GNUNET_assert (h->currently_down == GNUNET_YES); |
1160 | h->client = GNUNET_CLIENT_connect ("core", h->cfg); | 1115 | h->client = GNUNET_CLIENT_connect ("core", h->cfg); |
@@ -1185,6 +1140,10 @@ reconnect (struct GNUNET_CORE_Handle *h) | |||
1185 | else | 1140 | else |
1186 | opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND; | 1141 | opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND; |
1187 | } | 1142 | } |
1143 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1144 | "(Re)connecting to CORE service, monitoring messages of type %u\n", | ||
1145 | opt); | ||
1146 | |||
1188 | init->options = htonl (opt); | 1147 | init->options = htonl (opt); |
1189 | ts = (uint16_t *) & init[1]; | 1148 | ts = (uint16_t *) & init[1]; |
1190 | for (hpos = 0; hpos < h->hcnt; hpos++) | 1149 | for (hpos = 0; hpos < h->hcnt; hpos++) |
@@ -1203,8 +1162,8 @@ reconnect (struct GNUNET_CORE_Handle *h) | |||
1203 | * @param cfg configuration to use | 1162 | * @param cfg configuration to use |
1204 | * @param queue_size size of the per-peer message queue | 1163 | * @param queue_size size of the per-peer message queue |
1205 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) | 1164 | * @param cls closure for the various callbacks that follow (including handlers in the handlers array) |
1206 | * @param init callback to call on timeout or once we have successfully | 1165 | * @param init callback to call once we have successfully |
1207 | * connected to the core service; note that timeout is only meaningful if init is not NULL | 1166 | * connected to the core service |
1208 | * @param connects function to call on peer connect, can be NULL | 1167 | * @param connects function to call on peer connect, can be NULL |
1209 | * @param disconnects function to call on peer disconnect / timeout, can be NULL | 1168 | * @param disconnects function to call on peer disconnect / timeout, can be NULL |
1210 | * @param inbound_notify function to call for all inbound messages, can be NULL | 1169 | * @param inbound_notify function to call for all inbound messages, can be NULL |
@@ -1255,9 +1214,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1255 | GNUNET_assert (h->hcnt < | 1214 | GNUNET_assert (h->hcnt < |
1256 | (GNUNET_SERVER_MAX_MESSAGE_SIZE - | 1215 | (GNUNET_SERVER_MAX_MESSAGE_SIZE - |
1257 | sizeof (struct InitMessage)) / sizeof (uint16_t)); | 1216 | sizeof (struct InitMessage)) / sizeof (uint16_t)); |
1258 | #if DEBUG_CORE | ||
1259 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n"); | 1217 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n"); |
1260 | #endif | ||
1261 | reconnect (h); | 1218 | reconnect (h); |
1262 | return h; | 1219 | return h; |
1263 | } | 1220 | } |
@@ -1275,9 +1232,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) | |||
1275 | { | 1232 | { |
1276 | struct ControlMessage *cm; | 1233 | struct ControlMessage *cm; |
1277 | 1234 | ||
1278 | #if DEBUG_CORE | ||
1279 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n"); | 1235 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n"); |
1280 | #endif | ||
1281 | if (handle->cth != NULL) | 1236 | if (handle->cth != NULL) |
1282 | { | 1237 | { |
1283 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth); | 1238 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth); |
@@ -1401,18 +1356,14 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, | |||
1401 | GNUNET_break (handle->queue_size != 0); | 1356 | GNUNET_break (handle->queue_size != 0); |
1402 | GNUNET_break (pr->queue_size == 1); | 1357 | GNUNET_break (pr->queue_size == 1); |
1403 | GNUNET_free (th); | 1358 | GNUNET_free (th); |
1404 | #if DEBUG_CORE | ||
1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1359 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1406 | "Dropping transmission request: cannot drop queue head and limit is one\n"); | 1360 | "Dropping transmission request: cannot drop queue head and limit is one\n"); |
1407 | #endif | ||
1408 | return NULL; | 1361 | return NULL; |
1409 | } | 1362 | } |
1410 | if (priority <= minp->priority) | 1363 | if (priority <= minp->priority) |
1411 | { | 1364 | { |
1412 | #if DEBUG_CORE | ||
1413 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1365 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1414 | "Dropping transmission request: priority too low\n"); | 1366 | "Dropping transmission request: priority too low\n"); |
1415 | #endif | ||
1416 | GNUNET_free (th); | 1367 | GNUNET_free (th); |
1417 | return NULL; /* priority too low */ | 1368 | return NULL; /* priority too low */ |
1418 | } | 1369 | } |
@@ -1440,9 +1391,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, | |||
1440 | th); | 1391 | th); |
1441 | pr->queue_size++; | 1392 | pr->queue_size++; |
1442 | /* was the request queue previously empty? */ | 1393 | /* was the request queue previously empty? */ |
1443 | #if DEBUG_CORE | ||
1444 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n"); | 1394 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n"); |
1445 | #endif | ||
1446 | if ((pr->pending_head == th) && (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && | 1395 | if ((pr->pending_head == th) && (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && |
1447 | (pr->next == NULL) && (pr->prev == NULL) && | 1396 | (pr->next == NULL) && (pr->prev == NULL) && |
1448 | (handle->ready_peer_head != pr)) | 1397 | (handle->ready_peer_head != pr)) |
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c index 4098b45b1..b57936baa 100644 --- a/src/core/gnunet-service-core_clients.c +++ b/src/core/gnunet-service-core_clients.c | |||
@@ -96,6 +96,11 @@ struct GSC_Client | |||
96 | 96 | ||
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Big "or" of all client options. | ||
100 | */ | ||
101 | static uint32_t all_client_options; | ||
102 | |||
103 | /** | ||
99 | * Head of linked list of our clients. | 104 | * Head of linked list of our clients. |
100 | */ | 105 | */ |
101 | static struct GSC_Client *client_head; | 106 | static struct GSC_Client *client_head; |
@@ -146,12 +151,10 @@ static void | |||
146 | send_to_client (struct GSC_Client *client, | 151 | send_to_client (struct GSC_Client *client, |
147 | const struct GNUNET_MessageHeader *msg, int can_drop) | 152 | const struct GNUNET_MessageHeader *msg, int can_drop) |
148 | { | 153 | { |
149 | #if DEBUG_CORE | ||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
151 | "Preparing to send %u bytes of message of type %u to client.\n", | 155 | "Preparing to send %u bytes of message of type %u to client.\n", |
152 | (unsigned int) ntohs (msg->size), | 156 | (unsigned int) ntohs (msg->size), |
153 | (unsigned int) ntohs (msg->type)); | 157 | (unsigned int) ntohs (msg->type)); |
154 | #endif | ||
155 | GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle, | 158 | GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle, |
156 | msg, can_drop); | 159 | msg, can_drop); |
157 | } | 160 | } |
@@ -207,7 +210,7 @@ type_match (uint16_t type, struct GSC_Client *c) | |||
207 | * Send a message to all of our current clients that have the right | 210 | * Send a message to all of our current clients that have the right |
208 | * options set. | 211 | * options set. |
209 | * | 212 | * |
210 | * @param sender origin of the message (used to check that this peer is | 213 | * @param partner origin (or destination) of the message (used to check that this peer is |
211 | * known to be connected to the respective client) | 214 | * known to be connected to the respective client) |
212 | * @param msg message to multicast | 215 | * @param msg message to multicast |
213 | * @param can_drop can this message be discarded if the queue is too long | 216 | * @param can_drop can this message be discarded if the queue is too long |
@@ -215,27 +218,33 @@ type_match (uint16_t type, struct GSC_Client *c) | |||
215 | * @param type type of the embedded message, 0 for none | 218 | * @param type type of the embedded message, 0 for none |
216 | */ | 219 | */ |
217 | static void | 220 | static void |
218 | send_to_all_clients (const struct GNUNET_PeerIdentity *sender, | 221 | send_to_all_clients (const struct GNUNET_PeerIdentity *partner, |
219 | const struct GNUNET_MessageHeader *msg, int can_drop, | 222 | const struct GNUNET_MessageHeader *msg, int can_drop, |
220 | int options, uint16_t type) | 223 | uint32_t options, uint16_t type) |
221 | { | 224 | { |
222 | struct GSC_Client *c; | 225 | struct GSC_Client *c; |
223 | 226 | ||
224 | for (c = client_head; c != NULL; c = c->next) | 227 | for (c = client_head; c != NULL; c = c->next) |
225 | { | 228 | { |
226 | if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && | 229 | if (! ( (0 != (c->options & options)) || |
227 | (GNUNET_YES == type_match (type, c))) | 230 | ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && |
228 | continue; /* not the full message, but we'd like the full one! */ | 231 | (GNUNET_YES == type_match (type, c)) ) ) ) |
229 | if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c))) | 232 | continue; /* neither options nor type match permit the message */ |
230 | continue; /* neither options nor type match permit the message */ | 233 | if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) && |
231 | #if DEBUG_CORE | 234 | ( (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) || |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 235 | (GNUNET_YES == type_match (type, c)) ) ) |
233 | "Sending message to client interested in messages of type %u.\n", | 236 | continue; |
237 | if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && | ||
238 | (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) ) | ||
239 | continue; | ||
240 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
241 | "Sending %u message with %u bytes to client interested in messages of type %u.\n", | ||
242 | options, | ||
243 | ntohs (msg->size), | ||
234 | (unsigned int) type); | 244 | (unsigned int) type); |
235 | #endif | ||
236 | GNUNET_assert (GNUNET_YES == | 245 | GNUNET_assert (GNUNET_YES == |
237 | GNUNET_CONTAINER_multihashmap_contains (c->connectmap, | 246 | GNUNET_CONTAINER_multihashmap_contains (c->connectmap, |
238 | &sender->hashPubKey)); | 247 | &partner->hashPubKey)); |
239 | send_to_client (c, msg, can_drop); | 248 | send_to_client (c, msg, can_drop); |
240 | } | 249 | } |
241 | } | 250 | } |
@@ -283,6 +292,7 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
283 | c->client_handle = client; | 292 | c->client_handle = client; |
284 | c->tcnt = msize / sizeof (uint16_t); | 293 | c->tcnt = msize / sizeof (uint16_t); |
285 | c->options = ntohl (im->options); | 294 | c->options = ntohl (im->options); |
295 | all_client_options |= c->options; | ||
286 | c->types = (const uint16_t *) &c[1]; | 296 | c->types = (const uint16_t *) &c[1]; |
287 | c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); | 297 | c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); |
288 | GNUNET_assert (GNUNET_YES == | 298 | GNUNET_assert (GNUNET_YES == |
@@ -295,11 +305,9 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
295 | wtypes[i] = ntohs (types[i]); | 305 | wtypes[i] = ntohs (types[i]); |
296 | GSC_TYPEMAP_add (wtypes, c->tcnt); | 306 | GSC_TYPEMAP_add (wtypes, c->tcnt); |
297 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c); | 307 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c); |
298 | #if DEBUG_CORE | ||
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
300 | "Client connecting to core service is interested in %u message types\n", | 309 | "Client connecting to core service is interested in %u message types\n", |
301 | (unsigned int) c->tcnt); | 310 | (unsigned int) c->tcnt); |
302 | #endif | ||
303 | /* send init reply message */ | 311 | /* send init reply message */ |
304 | irm.header.size = htons (sizeof (struct InitReplyMessage)); | 312 | irm.header.size = htons (sizeof (struct InitReplyMessage)); |
305 | irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); | 313 | irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); |
@@ -338,11 +346,9 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, | |||
338 | } | 346 | } |
339 | if (c->requests == NULL) | 347 | if (c->requests == NULL) |
340 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); | 348 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); |
341 | #if DEBUG_CORE | ||
342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
343 | "Client asked for transmission to `%s'\n", | 350 | "Client asked for transmission to `%s'\n", |
344 | GNUNET_i2s (&req->peer)); | 351 | GNUNET_i2s (&req->peer)); |
345 | #endif | ||
346 | is_loopback = | 352 | is_loopback = |
347 | (0 == | 353 | (0 == |
348 | memcmp (&req->peer, &GSC_my_identity, | 354 | memcmp (&req->peer, &GSC_my_identity, |
@@ -472,11 +478,9 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client, | |||
472 | &sm->peer.hashPubKey, | 478 | &sm->peer.hashPubKey, |
473 | tc.car)); | 479 | tc.car)); |
474 | tc.cork = ntohl (sm->cork); | 480 | tc.cork = ntohl (sm->cork); |
475 | #if DEBUG_CORE | ||
476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
477 | "Client asked for transmission of %u bytes to `%s' %s\n", msize, | 482 | "Client asked for transmission of %u bytes to `%s' %s\n", msize, |
478 | GNUNET_i2s (&sm->peer), tc.cork ? "now" : ""); | 483 | GNUNET_i2s (&sm->peer), tc.cork ? "now" : ""); |
479 | #endif | ||
480 | GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize, | 484 | GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize, |
481 | GNUNET_YES, GNUNET_NO); | 485 | GNUNET_YES, GNUNET_NO); |
482 | if (0 != | 486 | if (0 != |
@@ -509,19 +513,21 @@ client_tokenizer_callback (void *cls, void *client, | |||
509 | memcmp (&car->target, &GSC_my_identity, | 513 | memcmp (&car->target, &GSC_my_identity, |
510 | sizeof (struct GNUNET_PeerIdentity))) | 514 | sizeof (struct GNUNET_PeerIdentity))) |
511 | { | 515 | { |
512 | #if DEBUG_CORE | ||
513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
514 | "Delivering message of type %u to myself\n", | 517 | "Delivering message of type %u to myself\n", |
515 | ntohs (message->type)); | 518 | ntohs (message->type)); |
516 | #endif | ||
517 | GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, | 519 | GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, |
518 | ntohs (message->size), | 520 | ntohs (message->size), |
519 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND | | 521 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); |
520 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); | 522 | GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, |
523 | sizeof (struct GNUNET_MessageHeader), | ||
524 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | ||
521 | GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, | 525 | GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, |
522 | sizeof (struct GNUNET_MessageHeader), | 526 | ntohs (message->size), |
523 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND | | 527 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); |
524 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | 528 | GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message, |
529 | sizeof (struct GNUNET_MessageHeader), | ||
530 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
525 | } | 531 | } |
526 | else | 532 | else |
527 | { | 533 | { |
@@ -530,6 +536,12 @@ client_tokenizer_callback (void *cls, void *client, | |||
530 | "Delivering message of type %u to %s\n", ntohs (message->type), | 536 | "Delivering message of type %u to %s\n", ntohs (message->type), |
531 | GNUNET_i2s (&car->target)); | 537 | GNUNET_i2s (&car->target)); |
532 | #endif | 538 | #endif |
539 | GSC_CLIENTS_deliver_message (&car->target, NULL, 0, message, | ||
540 | ntohs (message->size), | ||
541 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); | ||
542 | GSC_CLIENTS_deliver_message (&car->target, NULL, 0, message, | ||
543 | sizeof (struct GNUNET_MessageHeader), | ||
544 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | ||
533 | GSC_SESSIONS_transmit (car, message, tc->cork); | 545 | GSC_SESSIONS_transmit (car, message, tc->cork); |
534 | } | 546 | } |
535 | } | 547 | } |
@@ -592,6 +604,11 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
592 | c->connectmap = NULL; | 604 | c->connectmap = NULL; |
593 | GSC_TYPEMAP_remove (c->types, c->tcnt); | 605 | GSC_TYPEMAP_remove (c->types, c->tcnt); |
594 | GNUNET_free (c); | 606 | GNUNET_free (c); |
607 | |||
608 | /* recalculate 'all_client_options' */ | ||
609 | all_client_options = 0; | ||
610 | for (c = client_head; NULL != c ; c = c->next) | ||
611 | all_client_options |= c->options; | ||
595 | } | 612 | } |
596 | 613 | ||
597 | 614 | ||
@@ -786,7 +803,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
786 | const struct GNUNET_ATS_Information *atsi, | 803 | const struct GNUNET_ATS_Information *atsi, |
787 | unsigned int atsi_count, | 804 | unsigned int atsi_count, |
788 | const struct GNUNET_MessageHeader *msg, | 805 | const struct GNUNET_MessageHeader *msg, |
789 | uint16_t msize, int options) | 806 | uint16_t msize, |
807 | uint32_t options) | ||
790 | { | 808 | { |
791 | size_t size = | 809 | size_t size = |
792 | msize + sizeof (struct NotifyTrafficMessage) + | 810 | msize + sizeof (struct NotifyTrafficMessage) + |
@@ -809,15 +827,19 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
809 | atsi_count = 0; | 827 | atsi_count = 0; |
810 | size = msize + sizeof (struct NotifyTrafficMessage); | 828 | size = msize + sizeof (struct NotifyTrafficMessage); |
811 | } | 829 | } |
812 | #if DEBUG_CORE | 830 | if (! ( (0 != (all_client_options & options)) || |
831 | (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) )) | ||
832 | return; /* no client cares about this message notification */ | ||
813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
814 | "Core service passes message from `%4s' of type %u to client.\n", | 834 | "Core service passes message from `%4s' of type %u to client.\n", |
815 | GNUNET_i2s (sender), (unsigned int) ntohs (msg->type)); | 835 | GNUNET_i2s (sender), (unsigned int) ntohs (msg->type)); |
816 | #endif | ||
817 | GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); | 836 | GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); |
818 | ntm = (struct NotifyTrafficMessage *) buf; | 837 | ntm = (struct NotifyTrafficMessage *) buf; |
819 | ntm->header.size = htons (size); | 838 | ntm->header.size = htons (size); |
820 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); | 839 | if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_INBOUND))) |
840 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); | ||
841 | else | ||
842 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND); | ||
821 | ntm->ats_count = htonl (atsi_count); | 843 | ntm->ats_count = htonl (atsi_count); |
822 | ntm->peer = *sender; | 844 | ntm->peer = *sender; |
823 | a = &ntm->ats; | 845 | a = &ntm->ats; |
diff --git a/src/core/gnunet-service-core_clients.h b/src/core/gnunet-service-core_clients.h index bdad20da8..8ece1ce1d 100644 --- a/src/core/gnunet-service-core_clients.h +++ b/src/core/gnunet-service-core_clients.h | |||
@@ -105,7 +105,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
105 | const struct GNUNET_ATS_Information *atsi, | 105 | const struct GNUNET_ATS_Information *atsi, |
106 | unsigned int atsi_count, | 106 | unsigned int atsi_count, |
107 | const struct GNUNET_MessageHeader *msg, | 107 | const struct GNUNET_MessageHeader *msg, |
108 | uint16_t msize, int options); | 108 | uint16_t msize, |
109 | uint32_t options); | ||
109 | 110 | ||
110 | 111 | ||
111 | /** | 112 | /** |