aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_scheduling.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/ats_api_scheduling.c')
-rw-r--r--src/ats/ats_api_scheduling.c81
1 files changed, 39 insertions, 42 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 89a3bb472..0658e362c 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -287,11 +287,8 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
287 const struct GNUNET_PeerIdentity *peer) 287 const struct GNUNET_PeerIdentity *peer)
288{ 288{
289#if DEBUG_ATS 289#if DEBUG_ATS
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Find session %u from peer %s in %p\n",
291 "Find session %u from peer %s in %p\n", 291 (unsigned int) session_id, GNUNET_i2s (peer), sh);
292 (unsigned int) session_id,
293 GNUNET_i2s (peer),
294 sh);
295#endif 292#endif
296 if (session_id >= sh->session_array_size) 293 if (session_id >= sh->session_array_size)
297 { 294 {
@@ -303,14 +300,14 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
303 if (sh->session_array[session_id].session == NULL) 300 if (sh->session_array[session_id].session == NULL)
304 { 301 {
305 GNUNET_break (0 == 302 GNUNET_break (0 ==
306 memcmp (peer, &sh->session_array[session_id].peer, 303 memcmp (peer, &sh->session_array[session_id].peer,
307 sizeof (struct GNUNET_PeerIdentity))); 304 sizeof (struct GNUNET_PeerIdentity)));
308 return NULL; 305 return NULL;
309 } 306 }
310 307
311 if (0 != 308 if (0 !=
312 memcmp (peer, &sh->session_array[session_id].peer, 309 memcmp (peer, &sh->session_array[session_id].peer,
313 sizeof (struct GNUNET_PeerIdentity))) 310 sizeof (struct GNUNET_PeerIdentity)))
314 { 311 {
315 GNUNET_break (0); 312 GNUNET_break (0);
316 sh->reconnect = GNUNET_YES; 313 sh->reconnect = GNUNET_YES;
@@ -338,10 +335,8 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
338 335
339#if DEBUG_ATS 336#if DEBUG_ATS
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Get session ID for session %p from peer %s in %p\n", 338 "Get session ID for session %p from peer %s in %p\n", session,
342 session, 339 GNUNET_i2s (peer), sh);
343 GNUNET_i2s (peer),
344 sh);
345#endif 340#endif
346 if (NULL == session) 341 if (NULL == session)
347 return 0; 342 return 0;
@@ -350,8 +345,9 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
350 { 345 {
351 if (session == sh->session_array[i].session) 346 if (session == sh->session_array[i].session)
352 { 347 {
353 GNUNET_assert (0 == memcmp (peer, &sh->session_array[i].peer, 348 GNUNET_assert (0 ==
354 sizeof (struct GNUNET_PeerIdentity))); 349 memcmp (peer, &sh->session_array[i].peer,
350 sizeof (struct GNUNET_PeerIdentity)));
355 return i; 351 return i;
356 } 352 }
357 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO)) 353 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO))
@@ -369,11 +365,8 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
369 sh->session_array[f].slot_used = GNUNET_YES; 365 sh->session_array[f].slot_used = GNUNET_YES;
370#if DEBUG_ATS 366#if DEBUG_ATS
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
372 "Assigning session ID %u for session %p of peer %s in %p\n", 368 "Assigning session ID %u for session %p of peer %s in %p\n", f,
373 f, 369 session, GNUNET_i2s (peer), sh);
374 session,
375 GNUNET_i2s (peer),
376 sh);
377#endif 370#endif
378 return f; 371 return f;
379} 372}
@@ -393,16 +386,15 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
393{ 386{
394#if DEBUG_ATS 387#if DEBUG_ATS
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Remove sessionID %u from peer %s in %p\n", 389 "Remove sessionID %u from peer %s in %p\n",
397 (unsigned int) session_id, 390 (unsigned int) session_id, GNUNET_i2s (peer), sh);
398 GNUNET_i2s (peer),
399 sh);
400#endif 391#endif
401 if (0 == session_id) 392 if (0 == session_id)
402 return; 393 return;
403 GNUNET_assert (session_id < sh->session_array_size); 394 GNUNET_assert (session_id < sh->session_array_size);
404 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used); 395 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
405 GNUNET_assert (0 == memcmp (peer, &sh->session_array[session_id].peer, 396 GNUNET_assert (0 ==
397 memcmp (peer, &sh->session_array[session_id].peer,
406 sizeof (struct GNUNET_PeerIdentity))); 398 sizeof (struct GNUNET_PeerIdentity)));
407 sh->session_array[session_id].session = NULL; 399 sh->session_array[session_id].session = NULL;
408} 400}
@@ -422,10 +414,8 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
422{ 414{
423#if DEBUG_ATS 415#if DEBUG_ATS
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Release sessionID %u from peer %s in %p\n", 417 "Release sessionID %u from peer %s in %p\n",
426 (unsigned int) session_id, 418 (unsigned int) session_id, GNUNET_i2s (peer), sh);
427 GNUNET_i2s (peer),
428 sh);
429#endif 419#endif
430 if (session_id >= sh->session_array_size) 420 if (session_id >= sh->session_array_size)
431 { 421 {
@@ -437,7 +427,8 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
437 /* this slot should have been removed from remove_session before */ 427 /* this slot should have been removed from remove_session before */
438 GNUNET_assert (sh->session_array[session_id].session == NULL); 428 GNUNET_assert (sh->session_array[session_id].session == NULL);
439 429
440 if (0 != memcmp (peer, &sh->session_array[session_id].peer, 430 if (0 !=
431 memcmp (peer, &sh->session_array[session_id].peer,
441 sizeof (struct GNUNET_PeerIdentity))) 432 sizeof (struct GNUNET_PeerIdentity)))
442 { 433 {
443 GNUNET_break (0); 434 GNUNET_break (0);
@@ -477,7 +468,7 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
477 uint16_t plugin_name_length; 468 uint16_t plugin_name_length;
478 uint32_t ats_count; 469 uint32_t ats_count;
479 struct GNUNET_HELLO_Address address; 470 struct GNUNET_HELLO_Address address;
480 struct Session * s; 471 struct Session *s;
481 472
482 if (NULL == msg) 473 if (NULL == msg)
483 { 474 {
@@ -519,7 +510,7 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
519 force_reconnect (sh); 510 force_reconnect (sh);
520 return; 511 return;
521 } 512 }
522 uint32_t session_id = ntohl (m->session_id); 513 uint32_t session_id = ntohl (m->session_id);
523 514
524 if (session_id == 0) 515 if (session_id == 0)
525 s = NULL; 516 s = NULL;
@@ -529,9 +520,9 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
529 if (s == NULL) 520 if (s == NULL)
530 { 521 {
531#if DEBUG_ATS 522#if DEBUG_ATS
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "ATS tries to use outdated session `%s'\n", 524 "ATS tries to use outdated session `%s'\n",
534 GNUNET_i2s(&m->peer)); 525 GNUNET_i2s (&m->peer));
535#endif 526#endif
536 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh, 527 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
537 GNUNET_TIME_UNIT_FOREVER_REL); 528 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -545,9 +536,10 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
545 536
546 if ((s == NULL) && (0 == address.address_length)) 537 if ((s == NULL) && (0 == address.address_length))
547 { 538 {
548 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 539 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
549 "ATS returned invalid address for peer `%s' transport `%s' address length %i, session_id %i\n", 540 "ATS returned invalid address for peer `%s' transport `%s' address length %i, session_id %i\n",
550 GNUNET_i2s(&address.peer) , address.transport_name, plugin_address_length, session_id); 541 GNUNET_i2s (&address.peer), address.transport_name,
542 plugin_address_length, session_id);
551 GNUNET_break_op (0); 543 GNUNET_break_op (0);
552 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh, 544 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
553 GNUNET_TIME_UNIT_FOREVER_REL); 545 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -731,7 +723,9 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
731 size_t namelen; 723 size_t namelen;
732 size_t msize; 724 size_t msize;
733 725
734 namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1; 726 namelen =
727 (address->transport_name ==
728 NULL) ? 0 : strlen (address->transport_name) + 1;
735 msize = 729 msize =
736 sizeof (struct AddressUpdateMessage) + address->address_length + 730 sizeof (struct AddressUpdateMessage) + address->address_length +
737 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; 731 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
@@ -778,8 +772,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
778void 772void
779GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, 773GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
780 const struct GNUNET_HELLO_Address *address, 774 const struct GNUNET_HELLO_Address *address,
781 struct Session *session, 775 struct Session *session, int in_use)
782 int in_use)
783{ 776{
784 struct PendingMessage *p; 777 struct PendingMessage *p;
785 struct AddressUseMessage *m; 778 struct AddressUseMessage *m;
@@ -788,7 +781,9 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
788 size_t msize; 781 size_t msize;
789 782
790 GNUNET_assert (NULL != address); 783 GNUNET_assert (NULL != address);
791 namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1; 784 namelen =
785 (address->transport_name ==
786 NULL) ? 0 : strlen (address->transport_name) + 1;
792 msize = sizeof (struct AddressUseMessage) + address->address_length + namelen; 787 msize = sizeof (struct AddressUseMessage) + address->address_length + namelen;
793 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 788 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
794 (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 789 (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
@@ -839,7 +834,9 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
839 GNUNET_assert (address->transport_name != NULL); 834 GNUNET_assert (address->transport_name != NULL);
840 namelen = strlen (address->transport_name) + 1; 835 namelen = strlen (address->transport_name) + 1;
841 GNUNET_assert (namelen > 1); 836 GNUNET_assert (namelen > 1);
842 msize = sizeof (struct AddressDestroyedMessage) + address->address_length + namelen; 837 msize =
838 sizeof (struct AddressDestroyedMessage) + address->address_length +
839 namelen;
843 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 840 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
844 (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 841 (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
845 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) 842 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))