aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ats/ats_api_scheduling.c72
1 files changed, 59 insertions, 13 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 663a7925a..fa1b6bc26 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -27,6 +27,7 @@
27#include "gnunet_ats_service.h" 27#include "gnunet_ats_service.h"
28#include "ats.h" 28#include "ats.h"
29 29
30#define DEBUG_ATS GNUNET_EXTRA_LOGGING
30 31
31/** 32/**
32 * Message in linked list we should send to the ATS service. The 33 * Message in linked list we should send to the ATS service. The
@@ -285,6 +286,13 @@ static struct Session *
285find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, 286find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
286 const struct GNUNET_PeerIdentity *peer) 287 const struct GNUNET_PeerIdentity *peer)
287{ 288{
289#if DEBUG_ATS
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 "Find session %u from peer %s in %p\n",
292 (unsigned int) session_id,
293 GNUNET_i2s (peer),
294 sh);
295#endif
288 if (session_id >= sh->session_array_size) 296 if (session_id >= sh->session_array_size)
289 { 297 {
290 GNUNET_break (0); 298 GNUNET_break (0);
@@ -292,13 +300,22 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
292 } 300 }
293 if (0 == session_id) 301 if (0 == session_id)
294 return NULL; 302 return NULL;
295 /* Check if this session was:
296 * removed by remove_session (transport service)
297 * released by release_session (ATS)
298 * */
299 if (sh->session_array[session_id].session == NULL) 303 if (sh->session_array[session_id].session == NULL)
304 {
305 GNUNET_break (0 ==
306 memcmp (peer, &sh->session_array[session_id].peer,
307 sizeof (struct GNUNET_PeerIdentity)));
300 return NULL; 308 return NULL;
309 }
301 310
311 if (0 !=
312 memcmp (peer, &sh->session_array[session_id].peer,
313 sizeof (struct GNUNET_PeerIdentity)))
314 {
315 GNUNET_break (0);
316 sh->reconnect = GNUNET_YES;
317 return NULL;
318 }
302 return sh->session_array[session_id].session; 319 return sh->session_array[session_id].session;
303} 320}
304 321
@@ -319,6 +336,13 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
319 unsigned int i; 336 unsigned int i;
320 unsigned int f; 337 unsigned int f;
321 338
339#if DEBUG_ATS
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Get session ID for session %p from peer %s in %p\n",
342 session,
343 GNUNET_i2s (peer),
344 sh);
345#endif
322 if (NULL == session) 346 if (NULL == session)
323 return 0; 347 return 0;
324 f = 0; 348 f = 0;
@@ -326,11 +350,9 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
326 { 350 {
327 if (session == sh->session_array[i].session) 351 if (session == sh->session_array[i].session)
328 { 352 {
329 if (0 != memcmp (peer, &sh->session_array[i].peer, 353 GNUNET_assert (0 == memcmp (peer, &sh->session_array[i].peer,
330 sizeof (struct GNUNET_PeerIdentity))) 354 sizeof (struct GNUNET_PeerIdentity)));
331 continue; 355 return i;
332 else
333 return i;
334 } 356 }
335 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO)) 357 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO))
336 f = i; 358 f = i;
@@ -345,6 +367,14 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
345 sh->session_array[f].session = session; 367 sh->session_array[f].session = session;
346 sh->session_array[f].peer = *peer; 368 sh->session_array[f].peer = *peer;
347 sh->session_array[f].slot_used = GNUNET_YES; 369 sh->session_array[f].slot_used = GNUNET_YES;
370#if DEBUG_ATS
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
372 "Assigning session ID %u for session %p of peer %s in %p\n",
373 f,
374 session,
375 GNUNET_i2s (peer),
376 sh);
377#endif
348 return f; 378 return f;
349} 379}
350 380
@@ -361,6 +391,13 @@ static void
361remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, 391remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
362 const struct GNUNET_PeerIdentity *peer) 392 const struct GNUNET_PeerIdentity *peer)
363{ 393{
394#if DEBUG_ATS
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Remove sessionID %u from peer %s in %p\n",
397 (unsigned int) session_id,
398 GNUNET_i2s (peer),
399 sh);
400#endif
364 if (0 == session_id) 401 if (0 == session_id)
365 return; 402 return;
366 GNUNET_assert (session_id < sh->session_array_size); 403 GNUNET_assert (session_id < sh->session_array_size);
@@ -383,6 +420,13 @@ static void
383release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, 420release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
384 const struct GNUNET_PeerIdentity *peer) 421 const struct GNUNET_PeerIdentity *peer)
385{ 422{
423#if DEBUG_ATS
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Release sessionID %u from peer %s in %p\n",
426 (unsigned int) session_id,
427 GNUNET_i2s (peer),
428 sh);
429#endif
386 if (session_id >= sh->session_array_size) 430 if (session_id >= sh->session_array_size)
387 { 431 {
388 GNUNET_break (0); 432 GNUNET_break (0);
@@ -433,6 +477,7 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
433 uint16_t plugin_name_length; 477 uint16_t plugin_name_length;
434 uint32_t ats_count; 478 uint32_t ats_count;
435 struct GNUNET_HELLO_Address address; 479 struct GNUNET_HELLO_Address address;
480 struct Session * s;
436 481
437 if (NULL == msg) 482 if (NULL == msg)
438 { 483 {
@@ -476,7 +521,6 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
476 } 521 }
477 uint32_t session_id = ntohl (m->session_id); 522 uint32_t session_id = ntohl (m->session_id);
478 523
479 struct Session * s = NULL;
480 if (session_id == 0) 524 if (session_id == 0)
481 s = NULL; 525 s = NULL;
482 else 526 else
@@ -484,8 +528,11 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
484 s = find_session (sh, session_id, &m->peer); 528 s = find_session (sh, session_id, &m->peer);
485 if (s == NULL) 529 if (s == NULL)
486 { 530 {
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS tries to use outdated session `%s'\n", GNUNET_i2s(&m->peer)); 531#if DEBUG_ATS
488 //GNUNET_break (0); 532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "ATS tries to use outdated session `%s'\n",
534 GNUNET_i2s(&m->peer));
535#endif
489 return; 536 return;
490 } 537 }
491 } 538 }
@@ -785,7 +832,6 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
785 return; 832 return;
786 } 833 }
787 834
788
789 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 835 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
790 p->size = msize; 836 p->size = msize;
791 p->is_init = GNUNET_NO; 837 p->is_init = GNUNET_NO;