aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_reservations.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
commitd4afc6e37a14fe3257263c377a243c1a22ed9ee5 (patch)
treeccfce6d4f92808372d3e7ebfe9f5372e9f21f50c /src/ats/gnunet-service-ats_reservations.c
parent60d02b5b0899f454cb65408bd2ed4c453fa75a3d (diff)
downloadgnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.tar.gz
gnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.zip
migrating more services to new service API
Diffstat (limited to 'src/ats/gnunet-service-ats_reservations.c')
-rw-r--r--src/ats/gnunet-service-ats_reservations.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c
index 97098c819..95952e96f 100644
--- a/src/ats/gnunet-service-ats_reservations.c
+++ b/src/ats/gnunet-service-ats_reservations.c
@@ -138,63 +138,43 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer,
138/** 138/**
139 * Handle 'reservation request' messages from clients. 139 * Handle 'reservation request' messages from clients.
140 * 140 *
141 * @param cls unused, NULL
142 * @param client client that sent the request 141 * @param client client that sent the request
143 * @param message the request message 142 * @param msg the request message
144 */ 143 */
145void 144void
146GAS_handle_reservation_request (void *cls, 145GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client,
147 struct GNUNET_SERVER_Client *client, 146 const struct ReservationRequestMessage *msg)
148 const struct GNUNET_MessageHeader *message)
149{ 147{
150 const struct ReservationRequestMessage *msg = 148 struct GNUNET_MQ_Envelope *env;
151 (const struct ReservationRequestMessage *) message; 149 struct ReservationResultMessage *result;
152 struct ReservationResultMessage result;
153 int32_t amount; 150 int32_t amount;
154 struct GNUNET_TIME_Relative res_delay; 151 struct GNUNET_TIME_Relative res_delay;
155 struct GNUNET_SERVER_NotificationContext **uc;
156 struct GNUNET_SERVER_NotificationContext *nc;
157 152
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "Received RESERVATION_REQUEST message\n"); 154 "Received RESERVATION_REQUEST message\n");
160 uc = GNUNET_SERVER_client_get_user_context (client,
161 struct GNUNET_SERVER_NotificationContext *);
162 if (NULL == uc)
163 {
164 GNUNET_break (0);
165 return;
166 }
167 nc = *uc;
168 amount = (int32_t) ntohl (msg->amount); 155 amount = (int32_t) ntohl (msg->amount);
169 res_delay = reservations_reserve (&msg->peer, amount); 156 res_delay = reservations_reserve (&msg->peer, amount);
170 if (res_delay.rel_value_us > 0) 157 if (res_delay.rel_value_us > 0)
171 amount = 0; 158 amount = 0;
172 result.header.size = htons (sizeof (struct ReservationResultMessage)); 159 env = GNUNET_MQ_msg (result,
173 result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); 160 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
174 result.amount = htonl (amount); 161 result->amount = htonl (amount);
175 result.peer = msg->peer; 162 result->peer = msg->peer;
176 result.res_delay = GNUNET_TIME_relative_hton (res_delay); 163 result->res_delay = GNUNET_TIME_relative_hton (res_delay);
177 GNUNET_STATISTICS_update (GSA_stats, 164 GNUNET_STATISTICS_update (GSA_stats,
178 "# reservation requests processed", 165 "# reservation requests processed",
179 1, 166 1,
180 GNUNET_NO); 167 GNUNET_NO);
181 168 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
182 GNUNET_SERVER_notification_context_unicast (nc, 169 env);
183 client,
184 &result.header,
185 GNUNET_NO);
186 GNUNET_SERVER_receive_done (client,
187 GNUNET_OK);
188} 170}
189 171
190 172
191/** 173/**
192 * Initialize reservations subsystem. 174 * Initialize reservations subsystem.
193 *
194 * @param server handle to our server
195 */ 175 */
196void 176void
197GAS_reservations_init (struct GNUNET_SERVER_Handle *server) 177GAS_reservations_init ()
198{ 178{
199 trackers = GNUNET_CONTAINER_multipeermap_create (128, 179 trackers = GNUNET_CONTAINER_multipeermap_create (128,
200 GNUNET_NO); 180 GNUNET_NO);
@@ -211,7 +191,8 @@ GAS_reservations_init (struct GNUNET_SERVER_Handle *server)
211 */ 191 */
212static int 192static int
213free_tracker (void *cls, 193free_tracker (void *cls,
214 const struct GNUNET_PeerIdentity *key, void *value) 194 const struct GNUNET_PeerIdentity *key,
195 void *value)
215{ 196{
216 struct GNUNET_BANDWIDTH_Tracker *tracker = value; 197 struct GNUNET_BANDWIDTH_Tracker *tracker = value;
217 198