aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-18 07:45:18 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-18 07:45:18 +0000
commit46db19f996978187a3e596188465b41ca0706318 (patch)
tree719cf1e30fe3aaf449a243e7111be23bd632fd5d /src/ats
parent122717567d8c65f62dba6790a4573298735af6e6 (diff)
downloadgnunet-46db19f996978187a3e596188465b41ca0706318.tar.gz
gnunet-46db19f996978187a3e596188465b41ca0706318.zip
extra checks
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats_api_scheduling.c64
1 files changed, 50 insertions, 14 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index dc90e3131..a6eeb8576 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -58,6 +58,23 @@ struct PendingMessage
58 58
59 59
60/** 60/**
61 * Information we track per session.
62 */
63struct SessionRecord
64{
65 /**
66 * Identity of the peer (just needed for error checking).
67 */
68 struct GNUNET_PeerIdentity peer;
69
70 /**
71 * Session handle.
72 */
73 struct Session *session;
74};
75
76
77/**
61 * Handle to the ATS subsystem for bandwidth/transport scheduling information. 78 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
62 */ 79 */
63struct GNUNET_ATS_SchedulingHandle 80struct GNUNET_ATS_SchedulingHandle
@@ -104,7 +121,7 @@ struct GNUNET_ATS_SchedulingHandle
104 * network). Index 0 is always NULL and reserved to represent the NULL pointer. 121 * network). Index 0 is always NULL and reserved to represent the NULL pointer.
105 * Unused entries are also NULL. 122 * Unused entries are also NULL.
106 */ 123 */
107 struct Session **session_array; 124 struct SessionRecord *session_array;
108 125
109 /** 126 /**
110 * Task to trigger reconnect. 127 * Task to trigger reconnect.
@@ -239,18 +256,23 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
239 * 256 *
240 * @param sh our handle 257 * @param sh our handle
241 * @param session_id current session ID 258 * @param session_id current session ID
259 * @param peer peer the session belongs to
242 * @return the session object (or NULL) 260 * @return the session object (or NULL)
243 */ 261 */
244static struct Session* 262static struct Session*
245find_session (struct GNUNET_ATS_SchedulingHandle *sh, 263find_session (struct GNUNET_ATS_SchedulingHandle *sh,
246 uint32_t session_id) 264 uint32_t session_id,
265 const struct GNUNET_PeerIdentity *peer)
247{ 266{
248 if (session_id >= sh->session_array_size) 267 if (session_id >= sh->session_array_size)
249 { 268 {
250 GNUNET_break (0); 269 GNUNET_break (0);
251 return NULL; 270 return NULL;
252 } 271 }
253 return sh->session_array[session_id]; 272 GNUNET_assert (0 == memcmp (peer,
273 &sh->session_array[session_id].peer,
274 sizeof (struct GNUNET_PeerIdentity)));
275 return sh->session_array[session_id].session;
254} 276}
255 277
256 278
@@ -260,11 +282,13 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
260 * 282 *
261 * @param sh our handle 283 * @param sh our handle
262 * @param session session object 284 * @param session session object
285 * @param peer peer the session belongs to
263 * @return the session id 286 * @return the session id
264 */ 287 */
265static uint32_t 288static uint32_t
266get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, 289get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
267 struct Session *session) 290 struct Session *session,
291 const struct GNUNET_PeerIdentity *peer)
268{ 292{
269 unsigned int i; 293 unsigned int i;
270 unsigned int f; 294 unsigned int f;
@@ -272,20 +296,27 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
272 f = 0; 296 f = 0;
273 for (i=1;i<sh->session_array_size;i++) 297 for (i=1;i<sh->session_array_size;i++)
274 { 298 {
275 if (session == sh->session_array[i]) 299 if (session == sh->session_array[i].session)
300 {
301 GNUNET_assert (0 == memcmp (peer,
302 &sh->session_array[i].peer,
303 sizeof (struct GNUNET_PeerIdentity)));
276 return i; 304 return i;
305 }
277 if ( (f == 0) && 306 if ( (f == 0) &&
278 (sh->session_array[i] == NULL) ) 307 (sh->session_array[i].session == NULL) )
279 f = i; 308 f = i;
280 } 309 }
281 if (f == 0) 310 if (f == 0)
282 { 311 {
283 f = sh->session_array_size; 312 f = sh->session_array_size;
284 GNUNET_array_grow (sh->session_array, 313 GNUNET_array_grow (sh->session_array,
285 sh->session_array_size, 314 sh->session_array_size,
286 sh->session_array_size * 2); 315 sh->session_array_size * 2);
287 } 316 }
288 sh->session_array[f] = session; 317 GNUNET_assert (f > 0);
318 sh->session_array[f].session = session;
319 sh->session_array[f].peer = *peer;
289 return f; 320 return f;
290} 321}
291 322
@@ -296,13 +327,18 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
296 * 327 *
297 * @param sh our handle 328 * @param sh our handle
298 * @param session_id identifies session that is no longer valid 329 * @param session_id identifies session that is no longer valid
330 * @param peer peer the session belongs to
299 */ 331 */
300static void 332static void
301remove_session (struct GNUNET_ATS_SchedulingHandle *sh, 333remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
302 uint32_t session_id) 334 uint32_t session_id,
335 const struct GNUNET_PeerIdentity *peer)
303{ 336{
304 GNUNET_assert (session_id < sh->session_array_size); 337 GNUNET_assert (session_id < sh->session_array_size);
305 sh->session_array[session_id] = NULL; 338 GNUNET_assert (0 == memcmp (peer,
339 &sh->session_array[session_id].peer,
340 sizeof (struct GNUNET_PeerIdentity)));
341 sh->session_array[session_id].session = NULL;
306} 342}
307 343
308 344
@@ -369,7 +405,7 @@ process_ats_message (void *cls,
369 &m->peer, 405 &m->peer,
370 plugin_name, 406 plugin_name,
371 address, address_length, 407 address, address_length,
372 find_session (sh, ntohl (m->session_id)), 408 find_session (sh, ntohl (m->session_id), &m->peer),
373 m->bandwidth_out, 409 m->bandwidth_out,
374 m->bandwidth_in, 410 m->bandwidth_in,
375 atsi, 411 atsi,
@@ -558,7 +594,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
558 m->peer = *peer; 594 m->peer = *peer;
559 m->address_length = htons (plugin_addr_len); 595 m->address_length = htons (plugin_addr_len);
560 m->plugin_name_length = htons (namelen); 596 m->plugin_name_length = htons (namelen);
561 m->session_id = htonl (get_session_id (sh, session)); 597 m->session_id = htonl (get_session_id (sh, session, peer));
562 am = (struct GNUNET_ATS_Information*) &m[1]; 598 am = (struct GNUNET_ATS_Information*) &m[1];
563 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 599 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
564 pm = (char *) &am[ats_count]; 600 pm = (char *) &am[ats_count];
@@ -616,7 +652,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
616 m->peer = *peer; 652 m->peer = *peer;
617 m->address_length = htons (plugin_addr_len); 653 m->address_length = htons (plugin_addr_len);
618 m->plugin_name_length = htons (namelen); 654 m->plugin_name_length = htons (namelen);
619 m->session_id = htonl (session_id = get_session_id (sh, session)); 655 m->session_id = htonl (session_id = get_session_id (sh, session, peer));
620 pm = (char *) &m[1]; 656 pm = (char *) &m[1];
621 memcpy (pm, plugin_addr, plugin_addr_len); 657 memcpy (pm, plugin_addr, plugin_addr_len);
622 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 658 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
@@ -624,7 +660,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
624 sh->pending_tail, 660 sh->pending_tail,
625 p); 661 p);
626 do_transmit (sh); 662 do_transmit (sh);
627 remove_session (sh, session_id); 663 remove_session (sh, session_id, peer);
628} 664}
629 665
630/* end of ats_api_scheduling.c */ 666/* end of ats_api_scheduling.c */