diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-07 15:26:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-07 15:26:06 +0000 |
commit | 013cf64f56c0a529f0c11597e912b39e4a0a896c (patch) | |
tree | 763624e31708ea0d0b7b8f11f5c1308e220c0b94 /src/core | |
parent | 900c1831440d1b6f9fdb35d39334bca2e94bdefb (diff) | |
download | gnunet-013cf64f56c0a529f0c11597e912b39e4a0a896c.tar.gz gnunet-013cf64f56c0a529f0c11597e912b39e4a0a896c.zip |
first round of simplification to change preference API
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 3 | ||||
-rw-r--r-- | src/core/core_api.c | 21 | ||||
-rw-r--r-- | src/core/gnunet-service-core_sessions.c | 128 | ||||
-rw-r--r-- | src/core/test_core_api_preferences.c | 10 |
4 files changed, 66 insertions, 96 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2ea90c9ff..65883d537 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am | |||
@@ -43,7 +43,8 @@ gnunet_service_core_new_SOURCES = \ | |||
43 | gnunet-service-core_clients.c gnunet-service-core_clients.h \ | 43 | gnunet-service-core_clients.c gnunet-service-core_clients.h \ |
44 | gnunet-service-core_neighbours.c gnunet-service-core_neighbours.h \ | 44 | gnunet-service-core_neighbours.c gnunet-service-core_neighbours.h \ |
45 | gnunet-service-core_kx.c gnunet-service-core_kx.h \ | 45 | gnunet-service-core_kx.c gnunet-service-core_kx.h \ |
46 | gnunet-service-core_sessions.c gnunet-service-core_sessions.h | 46 | gnunet-service-core_sessions.c gnunet-service-core_sessions.h \ |
47 | gnunet-service-core_typemap.c gnunet-service-core_typemap.h | ||
47 | gnunet_service_core_new_LDADD = \ | 48 | gnunet_service_core_new_LDADD = \ |
48 | $(top_builddir)/src/hello/libgnunethello.la \ | 49 | $(top_builddir)/src/hello/libgnunethello.la \ |
49 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | 50 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ |
diff --git a/src/core/core_api.c b/src/core/core_api.c index 24013b7cf..91368ffc3 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c | |||
@@ -421,7 +421,6 @@ static int | |||
421 | disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key, | 421 | disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key, |
422 | void *value) | 422 | void *value) |
423 | { | 423 | { |
424 | static struct GNUNET_BANDWIDTH_Value32NBO zero; | ||
425 | struct GNUNET_CORE_Handle *h = cls; | 424 | struct GNUNET_CORE_Handle *h = cls; |
426 | struct GNUNET_CORE_TransmitHandle *th; | 425 | struct GNUNET_CORE_TransmitHandle *th; |
427 | struct PeerRecord *pr = value; | 426 | struct PeerRecord *pr = value; |
@@ -449,7 +448,7 @@ disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key, | |||
449 | GNUNET_break (0); | 448 | GNUNET_break (0); |
450 | pcic_cls = pr->pcic_cls; | 449 | pcic_cls = pr->pcic_cls; |
451 | GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr); | 450 | GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr); |
452 | pcic (pcic_cls, &pr->peer, zero, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0); | 451 | pcic (pcic_cls, &pr->peer, 0, GNUNET_TIME_UNIT_FOREVER_REL); |
453 | } | 452 | } |
454 | while (NULL != (th = pr->pending_head)) | 453 | while (NULL != (th = pr->pending_head)) |
455 | { | 454 | { |
@@ -1230,9 +1229,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1230 | GNUNET_free_non_null (pr->pcic_ptr); | 1229 | GNUNET_free_non_null (pr->pcic_ptr); |
1231 | pr->pcic_ptr = NULL; | 1230 | pr->pcic_ptr = NULL; |
1232 | if (pcic != NULL) | 1231 | if (pcic != NULL) |
1233 | pcic (pr->pcic_cls, &pr->peer, cim->bw_out, ntohl (cim->reserved_amount), | 1232 | pcic (pr->pcic_cls, &pr->peer, ntohl (cim->reserved_amount), |
1234 | GNUNET_TIME_relative_ntoh (cim->reserve_delay), | 1233 | GNUNET_TIME_relative_ntoh (cim->reserve_delay)); |
1235 | GNUNET_ntohll (cim->preference)); | ||
1236 | break; | 1234 | break; |
1237 | default: | 1235 | default: |
1238 | reconnect_later (h); | 1236 | reconnect_later (h); |
@@ -1677,15 +1675,6 @@ change_preference_send_continuation (void *cls, int success) | |||
1677 | * | 1675 | * |
1678 | * @param h core handle | 1676 | * @param h core handle |
1679 | * @param peer identifies the peer | 1677 | * @param peer identifies the peer |
1680 | * @param timeout after how long should we give up (and call "info" with NULL | ||
1681 | * for "peer" to signal an error)? | ||
1682 | * @param bw_out set to the current bandwidth limit (sending) for this peer, | ||
1683 | * caller should set "bw_out" to "-1" to avoid changing | ||
1684 | * the current value; otherwise "bw_out" will be lowered to | ||
1685 | * the specified value; passing a pointer to "0" can be used to force | ||
1686 | * us to disconnect from the peer; "bw_out" might not increase | ||
1687 | * as specified since the upper bound is generally | ||
1688 | * determined by the other peer! | ||
1689 | * @param amount reserve N bytes for receiving, negative | 1678 | * @param amount reserve N bytes for receiving, negative |
1690 | * amounts can be used to undo a (recent) reservation; | 1679 | * amounts can be used to undo a (recent) reservation; |
1691 | * @param preference increase incoming traffic share preference by this amount; | 1680 | * @param preference increase incoming traffic share preference by this amount; |
@@ -1699,8 +1688,6 @@ change_preference_send_continuation (void *cls, int success) | |||
1699 | struct GNUNET_CORE_InformationRequestContext * | 1688 | struct GNUNET_CORE_InformationRequestContext * |
1700 | GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, | 1689 | GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, |
1701 | const struct GNUNET_PeerIdentity *peer, | 1690 | const struct GNUNET_PeerIdentity *peer, |
1702 | struct GNUNET_TIME_Relative timeout, | ||
1703 | struct GNUNET_BANDWIDTH_Value32NBO bw_out, | ||
1704 | int32_t amount, uint64_t preference, | 1691 | int32_t amount, uint64_t preference, |
1705 | GNUNET_CORE_PeerConfigurationInfoCallback | 1692 | GNUNET_CORE_PeerConfigurationInfoCallback |
1706 | info, void *info_cls) | 1693 | info, void *info_cls) |
@@ -1735,7 +1722,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h, | |||
1735 | rim->header.size = htons (sizeof (struct RequestInfoMessage)); | 1722 | rim->header.size = htons (sizeof (struct RequestInfoMessage)); |
1736 | rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO); | 1723 | rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO); |
1737 | rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++); | 1724 | rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++); |
1738 | rim->limit_outbound = bw_out; | 1725 | rim->limit_outbound = GNUNET_BANDWIDTH_VALUE_MAX; // FIXME: remove entirely soon... |
1739 | rim->reserve_inbound = htonl (amount); | 1726 | rim->reserve_inbound = htonl (amount); |
1740 | rim->preference_change = GNUNET_htonll (preference); | 1727 | rim->preference_change = GNUNET_htonll (preference); |
1741 | rim->peer = *peer; | 1728 | rim->peer = *peer; |
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c index b379c3ac7..6e1494373 100644 --- a/src/core/gnunet-service-core_sessions.c +++ b/src/core/gnunet-service-core_sessions.c | |||
@@ -710,102 +710,86 @@ void | |||
710 | GSC_SESSIONS_handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client, | 710 | GSC_SESSIONS_handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client, |
711 | const struct GNUNET_MessageHeader *message) | 711 | const struct GNUNET_MessageHeader *message) |
712 | { | 712 | { |
713 | #if 0 | ||
714 | // FIXME! | ||
715 | const struct RequestInfoMessage *rcm; | 713 | const struct RequestInfoMessage *rcm; |
716 | struct GSC_Client *pos; | 714 | struct Session *session; |
717 | struct Neighbour *n; | ||
718 | struct ConfigurationInfoMessage cim; | 715 | struct ConfigurationInfoMessage cim; |
719 | int32_t want_reserv; | 716 | int32_t want_reserv; |
720 | int32_t got_reserv; | 717 | int32_t got_reserv; |
721 | unsigned long long old_preference; | ||
722 | struct GNUNET_TIME_Relative rdelay; | 718 | struct GNUNET_TIME_Relative rdelay; |
723 | 719 | ||
724 | rdelay = GNUNET_TIME_UNIT_ZERO; | 720 | rdelay = GNUNET_TIME_UNIT_ZERO; |
725 | #if DEBUG_CORE_CLIENT | 721 | #if DEBUG_CORE_CLIENT |
726 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service receives `%s' request.\n", | 722 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
723 | "Core service receives `%s' request.\n", | ||
727 | "REQUEST_INFO"); | 724 | "REQUEST_INFO"); |
728 | #endif | 725 | #endif |
729 | rcm = (const struct RequestInfoMessage *) message; | 726 | rcm = (const struct RequestInfoMessage *) message; |
730 | n = find_neighbour (&rcm->peer); | 727 | session = find_session (&rcm->peer); |
731 | memset (&cim, 0, sizeof (cim)); | 728 | if (NULL == session) |
732 | if ((n != NULL) && (GNUNET_YES == n->is_connected)) | ||
733 | { | ||
734 | want_reserv = ntohl (rcm->reserve_inbound); | ||
735 | if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__) | ||
736 | { | ||
737 | n->bw_out_internal_limit = rcm->limit_outbound; | ||
738 | if (n->bw_out.value__ != | ||
739 | GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, | ||
740 | n->bw_out_external_limit).value__) | ||
741 | { | ||
742 | n->bw_out = | ||
743 | GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, | ||
744 | n->bw_out_external_limit); | ||
745 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, | ||
746 | n->bw_out); | ||
747 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); | ||
748 | handle_peer_status_change (n); | ||
749 | } | ||
750 | } | ||
751 | if (want_reserv < 0) | ||
752 | { | ||
753 | got_reserv = want_reserv; | ||
754 | } | ||
755 | else if (want_reserv > 0) | ||
756 | { | ||
757 | rdelay = | ||
758 | GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, | ||
759 | want_reserv); | ||
760 | if (rdelay.rel_value == 0) | ||
761 | got_reserv = want_reserv; | ||
762 | else | ||
763 | got_reserv = 0; /* all or nothing */ | ||
764 | } | ||
765 | else | ||
766 | got_reserv = 0; | ||
767 | GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, got_reserv); | ||
768 | old_preference = n->current_preference; | ||
769 | n->current_preference += GNUNET_ntohll (rcm->preference_change); | ||
770 | if (old_preference > n->current_preference) | ||
771 | { | ||
772 | /* overflow; cap at maximum value */ | ||
773 | n->current_preference = ULLONG_MAX; | ||
774 | } | ||
775 | update_preference_sum (n->current_preference - old_preference); | ||
776 | #if DEBUG_CORE_QUOTA | ||
777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
778 | "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", | ||
779 | (int) want_reserv, GNUNET_i2s (&rcm->peer), (int) got_reserv, | ||
780 | (unsigned long long) rdelay.rel_value); | ||
781 | #endif | ||
782 | cim.reserved_amount = htonl (got_reserv); | ||
783 | cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); | ||
784 | cim.bw_out = n->bw_out; | ||
785 | cim.preference = n->current_preference; | ||
786 | } | ||
787 | else | ||
788 | { | 729 | { |
789 | /* Technically, this COULD happen (due to asynchronous behavior), | 730 | /* Technically, this COULD happen (due to asynchronous behavior), |
790 | * but it should be rare, so we should generate an info event | 731 | * but it should be rare, so we should generate an info event |
791 | * to help diagnosis of serious errors that might be masked by this */ | 732 | * to help diagnosis of serious errors that might be masked by this */ |
792 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 733 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
793 | _ | 734 | _("Client asked for preference change with peer `%s', which is not connected!\n"), |
794 | ("Client asked for preference change with peer `%s', which is not connected!\n"), | ||
795 | GNUNET_i2s (&rcm->peer)); | 735 | GNUNET_i2s (&rcm->peer)); |
796 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 736 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
797 | return; | 737 | return; |
798 | } | 738 | } |
739 | |||
740 | want_reserv = ntohl (rcm->reserve_inbound); | ||
741 | if (session->bw_out_internal_limit.value__ != rcm->limit_outbound.value__) | ||
742 | { | ||
743 | session->bw_out_internal_limit = rcm->limit_outbound; | ||
744 | if (session->bw_out.value__ != | ||
745 | GNUNET_BANDWIDTH_value_min (session->bw_out_internal_limit, | ||
746 | session->bw_out_external_limit).value__) | ||
747 | { | ||
748 | session->bw_out = | ||
749 | GNUNET_BANDWIDTH_value_min (session->bw_out_internal_limit, | ||
750 | session->bw_out_external_limit); | ||
751 | GNUNET_BANDWIDTH_tracker_update_quota (&session->available_recv_window, | ||
752 | session->bw_out); | ||
753 | #if 0 | ||
754 | // FIXME: who does this? | ||
755 | GNUNET_TRANSPORT_set_quota (transport, &session->peer, | ||
756 | session->bw_in, | ||
757 | session->bw_out); | ||
758 | #endif | ||
759 | } | ||
760 | } | ||
761 | if (want_reserv < 0) | ||
762 | { | ||
763 | got_reserv = want_reserv; | ||
764 | } | ||
765 | else if (want_reserv > 0) | ||
766 | { | ||
767 | rdelay = | ||
768 | GNUNET_BANDWIDTH_tracker_get_delay (&session->available_recv_window, | ||
769 | want_reserv); | ||
770 | if (rdelay.rel_value == 0) | ||
771 | got_reserv = want_reserv; | ||
772 | else | ||
773 | got_reserv = 0; /* all or nothing */ | ||
774 | } | ||
775 | else | ||
776 | got_reserv = 0; | ||
777 | GNUNET_BANDWIDTH_tracker_consume (&session->available_recv_window, got_reserv); | ||
778 | #if DEBUG_CORE_QUOTA | ||
779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
780 | "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", | ||
781 | (int) want_reserv, GNUNET_i2s (&rcm->peer), (int) got_reserv, | ||
782 | (unsigned long long) rdelay.rel_value); | ||
783 | #endif | ||
799 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); | 784 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); |
800 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); | 785 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); |
801 | cim.peer = rcm->peer; | 786 | cim.reserved_amount = htonl (got_reserv); |
787 | cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); | ||
802 | cim.rim_id = rcm->rim_id; | 788 | cim.rim_id = rcm->rim_id; |
803 | #if DEBUG_CORE_CLIENT | 789 | cim.bw_out = session->bw_out; |
804 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n", | 790 | cim.preference = 0; /* FIXME: remove */ |
805 | "CONFIGURATION_INFO"); | 791 | cim.peer = rcm->peer; |
806 | #endif | ||
807 | GSC_CLIENTS_send_to_client (client, &cim.header, GNUNET_NO); | 792 | GSC_CLIENTS_send_to_client (client, &cim.header, GNUNET_NO); |
808 | #endif | ||
809 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 793 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
810 | } | 794 | } |
811 | 795 | ||
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c index 19d51ef60..6d7f52953 100644 --- a/src/core/test_core_api_preferences.c +++ b/src/core/test_core_api_preferences.c | |||
@@ -154,8 +154,8 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
154 | 154 | ||
155 | static void | 155 | static void |
156 | preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 156 | preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
157 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, int32_t amount, | 157 | int32_t amount, |
158 | struct GNUNET_TIME_Relative res_delay, uint64_t preference); | 158 | struct GNUNET_TIME_Relative res_delay); |
159 | 159 | ||
160 | static void | 160 | static void |
161 | do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 161 | do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -173,16 +173,14 @@ do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
173 | "Requesting reservatin of 32k from core in 1s!\n"); | 173 | "Requesting reservatin of 32k from core in 1s!\n"); |
174 | irc = | 174 | irc = |
175 | GNUNET_CORE_peer_change_preference (p1.ch, &p2.id, | 175 | GNUNET_CORE_peer_change_preference (p1.ch, &p2.id, |
176 | GNUNET_TIME_UNIT_SECONDS, | ||
177 | GNUNET_BANDWIDTH_VALUE_MAX, | ||
178 | 1000000 /* bandwidth for 1s */ , | 176 | 1000000 /* bandwidth for 1s */ , |
179 | 0, &preference_cb, pc); | 177 | 0, &preference_cb, pc); |
180 | } | 178 | } |
181 | 179 | ||
182 | static void | 180 | static void |
183 | preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 181 | preference_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
184 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, int32_t amount, | 182 | int32_t amount, |
185 | struct GNUNET_TIME_Relative res_delay, uint64_t preference) | 183 | struct GNUNET_TIME_Relative res_delay) |
186 | { | 184 | { |
187 | struct PeerContext *pc = cls; | 185 | struct PeerContext *pc = cls; |
188 | 186 | ||