diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_reservations.c')
-rw-r--r-- | src/ats/gnunet-service-ats_reservations.c | 158 |
1 files changed, 79 insertions, 79 deletions
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index 41de442c7..ec1f4b0d5 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats_reservations.c | 21 | * @file ats/gnunet-service-ats_reservations.c |
22 | * @brief ats service, inbound bandwidth reservation management | 22 | * @brief ats service, inbound bandwidth reservation management |
@@ -53,38 +53,38 @@ static struct GNUNET_CONTAINER_MultiPeerMap *trackers; | |||
53 | * until the reservation might succeed | 53 | * until the reservation might succeed |
54 | */ | 54 | */ |
55 | static struct GNUNET_TIME_Relative | 55 | static struct GNUNET_TIME_Relative |
56 | reservations_reserve (const struct GNUNET_PeerIdentity *peer, | 56 | reservations_reserve(const struct GNUNET_PeerIdentity *peer, |
57 | int32_t amount) | 57 | int32_t amount) |
58 | { | 58 | { |
59 | struct GNUNET_BANDWIDTH_Tracker *tracker; | 59 | struct GNUNET_BANDWIDTH_Tracker *tracker; |
60 | struct GNUNET_TIME_Relative ret; | 60 | struct GNUNET_TIME_Relative ret; |
61 | 61 | ||
62 | tracker = GNUNET_CONTAINER_multipeermap_get (trackers, | 62 | tracker = GNUNET_CONTAINER_multipeermap_get(trackers, |
63 | peer); | 63 | peer); |
64 | if (NULL == tracker) | 64 | if (NULL == tracker) |
65 | { | 65 | { |
66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 66 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
67 | "Not connected, allowing reservation of %d bytes\n", | 67 | "Not connected, allowing reservation of %d bytes\n", |
68 | (int) amount); | 68 | (int)amount); |
69 | return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ | 69 | return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ |
70 | } | 70 | } |
71 | if (amount >= 0) | 71 | if (amount >= 0) |
72 | { | ||
73 | ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount); | ||
74 | if (ret.rel_value_us > 0) | ||
75 | { | 72 | { |
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 73 | ret = GNUNET_BANDWIDTH_tracker_get_delay(tracker, amount); |
77 | "Delay to satisfy reservation for %d bytes is %s\n", | 74 | if (ret.rel_value_us > 0) |
78 | (int) amount, | 75 | { |
79 | GNUNET_STRINGS_relative_time_to_string (ret, | 76 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
80 | GNUNET_YES)); | 77 | "Delay to satisfy reservation for %d bytes is %s\n", |
81 | return ret; | 78 | (int)amount, |
79 | GNUNET_STRINGS_relative_time_to_string(ret, | ||
80 | GNUNET_YES)); | ||
81 | return ret; | ||
82 | } | ||
82 | } | 83 | } |
83 | } | 84 | (void)GNUNET_BANDWIDTH_tracker_consume(tracker, amount); |
84 | (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount); | 85 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 86 | "Reserved %d bytes\n", |
86 | "Reserved %d bytes\n", | 87 | (int)amount); |
87 | (int) amount); | ||
88 | return GNUNET_TIME_UNIT_ZERO; | 88 | return GNUNET_TIME_UNIT_ZERO; |
89 | } | 89 | } |
90 | 90 | ||
@@ -98,40 +98,40 @@ reservations_reserve (const struct GNUNET_PeerIdentity *peer, | |||
98 | * this peer (estimate) | 98 | * this peer (estimate) |
99 | */ | 99 | */ |
100 | void | 100 | void |
101 | GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | 101 | GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, |
102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
103 | { | 103 | { |
104 | struct GNUNET_BANDWIDTH_Tracker *tracker; | 104 | struct GNUNET_BANDWIDTH_Tracker *tracker; |
105 | 105 | ||
106 | tracker = GNUNET_CONTAINER_multipeermap_get (trackers, peer); | 106 | tracker = GNUNET_CONTAINER_multipeermap_get(trackers, peer); |
107 | if (0 == ntohl (bandwidth_in.value__)) | 107 | if (0 == ntohl(bandwidth_in.value__)) |
108 | { | 108 | { |
109 | if (NULL == tracker) | 109 | if (NULL == tracker) |
110 | return; | 110 | return; |
111 | GNUNET_assert (GNUNET_YES == | 111 | GNUNET_assert(GNUNET_YES == |
112 | GNUNET_CONTAINER_multipeermap_remove (trackers, | 112 | GNUNET_CONTAINER_multipeermap_remove(trackers, |
113 | peer, | 113 | peer, |
114 | tracker)); | 114 | tracker)); |
115 | GNUNET_free (tracker); | 115 | GNUNET_free(tracker); |
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | if (NULL == tracker) | 118 | if (NULL == tracker) |
119 | { | 119 | { |
120 | tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker); | 120 | tracker = GNUNET_new(struct GNUNET_BANDWIDTH_Tracker); |
121 | GNUNET_BANDWIDTH_tracker_init (tracker, | 121 | GNUNET_BANDWIDTH_tracker_init(tracker, |
122 | NULL, | 122 | NULL, |
123 | NULL, | 123 | NULL, |
124 | bandwidth_in, | 124 | bandwidth_in, |
125 | MAX_BANDWIDTH_CARRY_S); | 125 | MAX_BANDWIDTH_CARRY_S); |
126 | GNUNET_assert (GNUNET_OK == | 126 | GNUNET_assert(GNUNET_OK == |
127 | GNUNET_CONTAINER_multipeermap_put (trackers, | 127 | GNUNET_CONTAINER_multipeermap_put(trackers, |
128 | peer, | 128 | peer, |
129 | tracker, | 129 | tracker, |
130 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 130 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | GNUNET_BANDWIDTH_tracker_update_quota (tracker, | 133 | GNUNET_BANDWIDTH_tracker_update_quota(tracker, |
134 | bandwidth_in); | 134 | bandwidth_in); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
@@ -142,31 +142,31 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | |||
142 | * @param msg the request message | 142 | * @param msg the request message |
143 | */ | 143 | */ |
144 | void | 144 | void |
145 | GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, | 145 | GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client, |
146 | const struct ReservationRequestMessage *msg) | 146 | const struct ReservationRequestMessage *msg) |
147 | { | 147 | { |
148 | struct GNUNET_MQ_Envelope *env; | 148 | struct GNUNET_MQ_Envelope *env; |
149 | struct ReservationResultMessage *result; | 149 | struct ReservationResultMessage *result; |
150 | int32_t amount; | 150 | int32_t amount; |
151 | struct GNUNET_TIME_Relative res_delay; | 151 | struct GNUNET_TIME_Relative res_delay; |
152 | 152 | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
154 | "Received RESERVATION_REQUEST message\n"); | 154 | "Received RESERVATION_REQUEST message\n"); |
155 | amount = (int32_t) ntohl (msg->amount); | 155 | amount = (int32_t)ntohl(msg->amount); |
156 | res_delay = reservations_reserve (&msg->peer, amount); | 156 | res_delay = reservations_reserve(&msg->peer, amount); |
157 | if (res_delay.rel_value_us > 0) | 157 | if (res_delay.rel_value_us > 0) |
158 | amount = 0; | 158 | amount = 0; |
159 | env = GNUNET_MQ_msg (result, | 159 | env = GNUNET_MQ_msg(result, |
160 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); | 160 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); |
161 | result->amount = htonl (amount); | 161 | result->amount = htonl(amount); |
162 | result->peer = msg->peer; | 162 | result->peer = msg->peer; |
163 | result->res_delay = GNUNET_TIME_relative_hton (res_delay); | 163 | result->res_delay = GNUNET_TIME_relative_hton(res_delay); |
164 | GNUNET_STATISTICS_update (GSA_stats, | 164 | GNUNET_STATISTICS_update(GSA_stats, |
165 | "# reservation requests processed", | 165 | "# reservation requests processed", |
166 | 1, | 166 | 1, |
167 | GNUNET_NO); | 167 | GNUNET_NO); |
168 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 168 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
169 | env); | 169 | env); |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
@@ -174,10 +174,10 @@ GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, | |||
174 | * Initialize reservations subsystem. | 174 | * Initialize reservations subsystem. |
175 | */ | 175 | */ |
176 | void | 176 | void |
177 | GAS_reservations_init () | 177 | GAS_reservations_init() |
178 | { | 178 | { |
179 | trackers = GNUNET_CONTAINER_multipeermap_create (128, | 179 | trackers = GNUNET_CONTAINER_multipeermap_create(128, |
180 | GNUNET_NO); | 180 | GNUNET_NO); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
@@ -190,13 +190,13 @@ GAS_reservations_init () | |||
190 | * @return #GNUNET_OK (continue to iterate) | 190 | * @return #GNUNET_OK (continue to iterate) |
191 | */ | 191 | */ |
192 | static int | 192 | static int |
193 | free_tracker (void *cls, | 193 | free_tracker(void *cls, |
194 | const struct GNUNET_PeerIdentity *key, | 194 | const struct GNUNET_PeerIdentity *key, |
195 | void *value) | 195 | void *value) |
196 | { | 196 | { |
197 | struct GNUNET_BANDWIDTH_Tracker *tracker = value; | 197 | struct GNUNET_BANDWIDTH_Tracker *tracker = value; |
198 | 198 | ||
199 | GNUNET_free (tracker); | 199 | GNUNET_free(tracker); |
200 | return GNUNET_OK; | 200 | return GNUNET_OK; |
201 | } | 201 | } |
202 | 202 | ||
@@ -205,12 +205,12 @@ free_tracker (void *cls, | |||
205 | * Shutdown reservations subsystem. | 205 | * Shutdown reservations subsystem. |
206 | */ | 206 | */ |
207 | void | 207 | void |
208 | GAS_reservations_done () | 208 | GAS_reservations_done() |
209 | { | 209 | { |
210 | GNUNET_CONTAINER_multipeermap_iterate (trackers, | 210 | GNUNET_CONTAINER_multipeermap_iterate(trackers, |
211 | &free_tracker, | 211 | &free_tracker, |
212 | NULL); | 212 | NULL); |
213 | GNUNET_CONTAINER_multipeermap_destroy (trackers); | 213 | GNUNET_CONTAINER_multipeermap_destroy(trackers); |
214 | } | 214 | } |
215 | 215 | ||
216 | /* end of gnunet-service-ats_reservations.c */ | 216 | /* end of gnunet-service-ats_reservations.c */ |