aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-18 15:20:50 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-18 15:20:50 +0000
commitb35fa325e2e5dad6c83af8252e06561d60ef7147 (patch)
tree00aff4814b3a9d13f5e486c986ee0c8f7f4df8b8 /src/ats
parentd2b7b35c48254cb3e892d2a39659e108898b360f (diff)
downloadgnunet-b35fa325e2e5dad6c83af8252e06561d60ef7147.tar.gz
gnunet-b35fa325e2e5dad6c83af8252e06561d60ef7147.zip
send session release messages back to ATS API
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats.h14
-rw-r--r--src/ats/ats_api_scheduling.c53
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c12
3 files changed, 79 insertions, 0 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index fbc6ca712..a39b16942 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -169,6 +169,20 @@ struct ReservationRequestMessage
169}; 169};
170 170
171 171
172/**
173 * Message sent by ATS service to client to confirm that it is done
174 * using the given session ID.
175 */
176struct SessionReleaseMessage
177{
178 struct GNUNET_MessageHeader header;
179
180 uint32_t session_id GNUNET_PACKED;
181
182 struct GNUNET_PeerIdentity peer;
183};
184
185
172struct ReservationResultMessage 186struct ReservationResultMessage
173{ 187{
174 struct GNUNET_MessageHeader header; 188 struct GNUNET_MessageHeader header;
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index b61d320a7..94c798b53 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -71,6 +71,11 @@ struct SessionRecord
71 * Session handle. 71 * Session handle.
72 */ 72 */
73 struct Session *session; 73 struct Session *session;
74
75 /**
76 * Set to GNUNET_YES if the slot is used.
77 */
78 int slot_used;
74}; 79};
75 80
76 81
@@ -321,6 +326,7 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
321 GNUNET_assert (f > 0); 326 GNUNET_assert (f > 0);
322 sh->session_array[f].session = session; 327 sh->session_array[f].session = session;
323 sh->session_array[f].peer = *peer; 328 sh->session_array[f].peer = *peer;
329 sh->session_array[f].slot_used = GNUNET_YES;
324 return f; 330 return f;
325} 331}
326 332
@@ -343,6 +349,43 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
343 &sh->session_array[session_id].peer, 349 &sh->session_array[session_id].peer,
344 sizeof (struct GNUNET_PeerIdentity))); 350 sizeof (struct GNUNET_PeerIdentity)));
345 sh->session_array[session_id].session = NULL; 351 sh->session_array[session_id].session = NULL;
352 memset (&sh->session_array[session_id].peer,
353 0,
354 sizeof (struct GNUNET_PeerIdentity));
355}
356
357
358/**
359 * Release the session slot from the session table (ATS service is
360 * also done using it).
361 *
362 * @param sh our handle
363 * @param session_id identifies session that is no longer valid
364 * @param peer peer the session belongs to
365 */
366static void
367release_session (struct GNUNET_ATS_SchedulingHandle *sh,
368 uint32_t session_id,
369 const struct GNUNET_PeerIdentity *peer)
370{
371 GNUNET_assert (session_id < sh->session_array_size);
372 GNUNET_assert (0 == memcmp (peer,
373 &sh->session_array[session_id].peer,
374 sizeof (struct GNUNET_PeerIdentity)));
375 sh->session_array[session_id].slot_used = GNUNET_NO;
376 memset (&sh->session_array[session_id].peer,
377 0,
378 sizeof (struct GNUNET_PeerIdentity));
379}
380
381
382static void
383process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
384 const struct SessionReleaseMessage *srm)
385{
386 release_session (sh,
387 ntohl (srm->session_id),
388 &srm->peer);
346} 389}
347 390
348 391
@@ -374,6 +417,16 @@ process_ats_message (void *cls,
374 &reconnect_task, sh); 417 &reconnect_task, sh);
375 return; 418 return;
376 } 419 }
420 if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
421 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) )
422 {
423 process_release_message (sh,
424 (const struct SessionReleaseMessage*) msg);
425 GNUNET_CLIENT_receive (sh->client,
426 &process_ats_message, sh,
427 GNUNET_TIME_UNIT_FOREVER_REL);
428 return;
429 }
377 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || 430 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
378 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) 431 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) )
379 { 432 {
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 6f3fa990e..242076568 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -234,6 +234,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
234 234
235{ 235{
236 const struct AddressDestroyedMessage * m; 236 const struct AddressDestroyedMessage * m;
237 struct SessionReleaseMessage srm;
237 const char *address; 238 const char *address;
238 const char *plugin_name; 239 const char *plugin_name;
239 uint16_t address_length; 240 uint16_t address_length;
@@ -280,6 +281,17 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
280 address, 281 address,
281 address_length, 282 address_length,
282 ntohl (m->session_id)); 283 ntohl (m->session_id));
284 if (0 != ntohl (m->session_id))
285 {
286 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
287 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage));
288 srm.session_id = m->session_id;
289 srm.peer = m->peer;
290 GNUNET_SERVER_notification_context_unicast (nc,
291 client,
292 &srm.header,
293 GNUNET_NO);
294 }
283 GNUNET_SERVER_receive_done (client, GNUNET_OK); 295 GNUNET_SERVER_receive_done (client, GNUNET_OK);
284} 296}
285 297