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.c302
1 files changed, 128 insertions, 174 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index b342d9657..2eeb99dad 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -37,12 +37,12 @@ struct PendingMessage
37 37
38 /** 38 /**
39 * Kept in a DLL. 39 * Kept in a DLL.
40 */ 40 */
41 struct PendingMessage *next; 41 struct PendingMessage *next;
42 42
43 /** 43 /**
44 * Kept in a DLL. 44 * Kept in a DLL.
45 */ 45 */
46 struct PendingMessage *prev; 46 struct PendingMessage *prev;
47 47
48 /** 48 /**
@@ -52,7 +52,7 @@ struct PendingMessage
52 52
53 /** 53 /**
54 * Is this the 'ATS_START' message? 54 * Is this the 'ATS_START' message?
55 */ 55 */
56 int is_init; 56 int is_init;
57}; 57};
58 58
@@ -84,7 +84,7 @@ struct SessionRecord
84 */ 84 */
85struct GNUNET_ATS_SchedulingHandle 85struct GNUNET_ATS_SchedulingHandle
86{ 86{
87 87
88 /** 88 /**
89 * Our configuration. 89 * Our configuration.
90 */ 90 */
@@ -94,7 +94,7 @@ struct GNUNET_ATS_SchedulingHandle
94 * Callback to invoke on suggestions. 94 * Callback to invoke on suggestions.
95 */ 95 */
96 GNUNET_ATS_AddressSuggestionCallback suggest_cb; 96 GNUNET_ATS_AddressSuggestionCallback suggest_cb;
97 97
98 /** 98 /**
99 * Closure for 'suggest_cb'. 99 * Closure for 'suggest_cb'.
100 */ 100 */
@@ -130,9 +130,9 @@ struct GNUNET_ATS_SchedulingHandle
130 130
131 /** 131 /**
132 * Task to trigger reconnect. 132 * Task to trigger reconnect.
133 */ 133 */
134 GNUNET_SCHEDULER_TaskIdentifier task; 134 GNUNET_SCHEDULER_TaskIdentifier task;
135 135
136 /** 136 /**
137 * Size of the session array. 137 * Size of the session array.
138 */ 138 */
@@ -161,8 +161,7 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
161 * @param tc scheduler context 161 * @param tc scheduler context
162 */ 162 */
163static void 163static void
164reconnect_task (void *cls, 164reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
166{ 165{
167 struct GNUNET_ATS_SchedulingHandle *sh = cls; 166 struct GNUNET_ATS_SchedulingHandle *sh = cls;
168 167
@@ -182,8 +181,9 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
182 sh->reconnect = GNUNET_NO; 181 sh->reconnect = GNUNET_NO;
183 GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO); 182 GNUNET_CLIENT_disconnect (sh->client, GNUNET_NO);
184 sh->client = NULL; 183 sh->client = NULL;
185 sh->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 184 sh->task =
186 &reconnect_task, sh); 185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
186 sh);
187} 187}
188 188
189 189
@@ -205,8 +205,7 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh);
205 * @param msg message received, NULL on timeout or fatal error 205 * @param msg message received, NULL on timeout or fatal error
206 */ 206 */
207static void 207static void
208process_ats_message (void *cls, 208process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg);
209 const struct GNUNET_MessageHeader *msg);
210 209
211 210
212/** 211/**
@@ -218,9 +217,7 @@ process_ats_message (void *cls,
218 * @return number of bytes copied into buf 217 * @return number of bytes copied into buf
219 */ 218 */
220static size_t 219static size_t
221transmit_message_to_ats (void *cls, 220transmit_message_to_ats (void *cls, size_t size, void *buf)
222 size_t size,
223 void *buf)
224{ 221{
225 struct GNUNET_ATS_SchedulingHandle *sh = cls; 222 struct GNUNET_ATS_SchedulingHandle *sh = cls;
226 struct PendingMessage *p; 223 struct PendingMessage *p;
@@ -228,26 +225,22 @@ transmit_message_to_ats (void *cls,
228 char *cbuf; 225 char *cbuf;
229 226
230 sh->th = NULL; 227 sh->th = NULL;
231 if ( (size == 0) || (buf == NULL)) 228 if ((size == 0) || (buf == NULL))
232 { 229 {
233 force_reconnect (sh); 230 force_reconnect (sh);
234 return 0; 231 return 0;
235 } 232 }
236 ret = 0; 233 ret = 0;
237 cbuf = buf; 234 cbuf = buf;
238 while ( (NULL != (p = sh->pending_head)) && 235 while ((NULL != (p = sh->pending_head)) && (p->size <= size))
239 (p->size <= size) )
240 { 236 {
241 memcpy (&cbuf[ret], &p[1], p->size); 237 memcpy (&cbuf[ret], &p[1], p->size);
242 ret += p->size; 238 ret += p->size;
243 size -= p->size; 239 size -= p->size;
244 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 240 GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
245 sh->pending_tail,
246 p);
247 if (GNUNET_YES == p->is_init) 241 if (GNUNET_YES == p->is_init)
248 GNUNET_CLIENT_receive (sh->client, 242 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
249 &process_ats_message, sh, 243 GNUNET_TIME_UNIT_FOREVER_REL);
250 GNUNET_TIME_UNIT_FOREVER_REL);
251 GNUNET_free (p); 244 GNUNET_free (p);
252 } 245 }
253 do_transmit (sh); 246 do_transmit (sh);
@@ -271,12 +264,12 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
271 if (NULL == (p = sh->pending_head)) 264 if (NULL == (p = sh->pending_head))
272 return; 265 return;
273 if (NULL == sh->client) 266 if (NULL == sh->client)
274 return; /* currently reconnecting */ 267 return; /* currently reconnecting */
275 sh->th = GNUNET_CLIENT_notify_transmit_ready (sh->client, 268 sh->th =
276 p->size, 269 GNUNET_CLIENT_notify_transmit_ready (sh->client, p->size,
277 GNUNET_TIME_UNIT_FOREVER_REL, 270 GNUNET_TIME_UNIT_FOREVER_REL,
278 GNUNET_NO, 271 GNUNET_NO, &transmit_message_to_ats,
279 &transmit_message_to_ats, sh); 272 sh);
280} 273}
281 274
282 275
@@ -288,10 +281,9 @@ do_transmit (struct GNUNET_ATS_SchedulingHandle *sh)
288 * @param peer peer the session belongs to 281 * @param peer peer the session belongs to
289 * @return the session object (or NULL) 282 * @return the session object (or NULL)
290 */ 283 */
291static struct Session* 284static struct Session *
292find_session (struct GNUNET_ATS_SchedulingHandle *sh, 285find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
293 uint32_t session_id, 286 const struct GNUNET_PeerIdentity *peer)
294 const struct GNUNET_PeerIdentity *peer)
295{ 287{
296 if (session_id >= sh->session_array_size) 288 if (session_id >= sh->session_array_size)
297 { 289 {
@@ -300,9 +292,9 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
300 } 292 }
301 if (session_id == 0) 293 if (session_id == 0)
302 return NULL; 294 return NULL;
303 if (0 != memcmp (peer, 295 if (0 !=
304 &sh->session_array[session_id].peer, 296 memcmp (peer, &sh->session_array[session_id].peer,
305 sizeof (struct GNUNET_PeerIdentity))) 297 sizeof (struct GNUNET_PeerIdentity)))
306 { 298 {
307 GNUNET_break (0); 299 GNUNET_break (0);
308 sh->reconnect = GNUNET_YES; 300 sh->reconnect = GNUNET_YES;
@@ -321,36 +313,33 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh,
321 * @param peer peer the session belongs to 313 * @param peer peer the session belongs to
322 * @return the session id 314 * @return the session id
323 */ 315 */
324static uint32_t 316static uint32_t
325get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, 317get_session_id (struct GNUNET_ATS_SchedulingHandle *sh, struct Session *session,
326 struct Session *session, 318 const struct GNUNET_PeerIdentity *peer)
327 const struct GNUNET_PeerIdentity *peer)
328{ 319{
329 unsigned int i; 320 unsigned int i;
330 unsigned int f; 321 unsigned int f;
331 322
332 if (NULL == session) 323 if (NULL == session)
333 return 0; 324 return 0;
334 f = 0; 325 f = 0;
335 for (i=1;i<sh->session_array_size;i++) 326 for (i = 1; i < sh->session_array_size; i++)
336 { 327 {
337 if (session == sh->session_array[i].session) 328 if (session == sh->session_array[i].session)
338 { 329 {
339 GNUNET_assert (0 == memcmp (peer, 330 GNUNET_assert (0 ==
340 &sh->session_array[i].peer, 331 memcmp (peer, &sh->session_array[i].peer,
341 sizeof (struct GNUNET_PeerIdentity))); 332 sizeof (struct GNUNET_PeerIdentity)));
342 return i; 333 return i;
343 } 334 }
344 if ( (f == 0) && 335 if ((f == 0) && (sh->session_array[i].slot_used == GNUNET_NO))
345 (sh->session_array[i].slot_used == GNUNET_NO) )
346 f = i; 336 f = i;
347 } 337 }
348 if (f == 0) 338 if (f == 0)
349 { 339 {
350 f = sh->session_array_size; 340 f = sh->session_array_size;
351 GNUNET_array_grow (sh->session_array, 341 GNUNET_array_grow (sh->session_array, sh->session_array_size,
352 sh->session_array_size, 342 sh->session_array_size * 2);
353 sh->session_array_size * 2);
354 } 343 }
355 GNUNET_assert (f > 0); 344 GNUNET_assert (f > 0);
356 sh->session_array[f].session = session; 345 sh->session_array[f].session = session;
@@ -369,17 +358,16 @@ get_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
369 * @param peer peer the session belongs to 358 * @param peer peer the session belongs to
370 */ 359 */
371static void 360static void
372remove_session (struct GNUNET_ATS_SchedulingHandle *sh, 361remove_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
373 uint32_t session_id, 362 const struct GNUNET_PeerIdentity *peer)
374 const struct GNUNET_PeerIdentity *peer)
375{ 363{
376 if (0 == session_id) 364 if (0 == session_id)
377 return; 365 return;
378 GNUNET_assert (session_id < sh->session_array_size); 366 GNUNET_assert (session_id < sh->session_array_size);
379 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used); 367 GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
380 GNUNET_assert (0 == memcmp (peer, 368 GNUNET_assert (0 ==
381 &sh->session_array[session_id].peer, 369 memcmp (peer, &sh->session_array[session_id].peer,
382 sizeof (struct GNUNET_PeerIdentity))); 370 sizeof (struct GNUNET_PeerIdentity)));
383 sh->session_array[session_id].session = NULL; 371 sh->session_array[session_id].session = NULL;
384} 372}
385 373
@@ -393,9 +381,8 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
393 * @param peer peer the session belongs to 381 * @param peer peer the session belongs to
394 */ 382 */
395static void 383static void
396release_session (struct GNUNET_ATS_SchedulingHandle *sh, 384release_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
397 uint32_t session_id, 385 const struct GNUNET_PeerIdentity *peer)
398 const struct GNUNET_PeerIdentity *peer)
399{ 386{
400 if (session_id >= sh->session_array_size) 387 if (session_id >= sh->session_array_size)
401 { 388 {
@@ -403,28 +390,25 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh,
403 sh->reconnect = GNUNET_YES; 390 sh->reconnect = GNUNET_YES;
404 return; 391 return;
405 } 392 }
406 if (0 != memcmp (peer, 393 if (0 !=
407 &sh->session_array[session_id].peer, 394 memcmp (peer, &sh->session_array[session_id].peer,
408 sizeof (struct GNUNET_PeerIdentity))) 395 sizeof (struct GNUNET_PeerIdentity)))
409 { 396 {
410 GNUNET_break (0); 397 GNUNET_break (0);
411 sh->reconnect = GNUNET_YES; 398 sh->reconnect = GNUNET_YES;
412 return; 399 return;
413 } 400 }
414 sh->session_array[session_id].slot_used = GNUNET_NO; 401 sh->session_array[session_id].slot_used = GNUNET_NO;
415 memset (&sh->session_array[session_id].peer, 402 memset (&sh->session_array[session_id].peer, 0,
416 0, 403 sizeof (struct GNUNET_PeerIdentity));
417 sizeof (struct GNUNET_PeerIdentity));
418} 404}
419 405
420 406
421static void 407static void
422process_release_message (struct GNUNET_ATS_SchedulingHandle *sh, 408process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
423 const struct SessionReleaseMessage *srm) 409 const struct SessionReleaseMessage *srm)
424{ 410{
425 release_session (sh, 411 release_session (sh, ntohl (srm->session_id), &srm->peer);
426 ntohl (srm->session_id),
427 &srm->peer);
428} 412}
429 413
430 414
@@ -436,8 +420,7 @@ process_release_message (struct GNUNET_ATS_SchedulingHandle *sh,
436 * @param msg message received, NULL on timeout or fatal error 420 * @param msg message received, NULL on timeout or fatal error
437 */ 421 */
438static void 422static void
439process_ats_message (void *cls, 423process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
440 const struct GNUNET_MessageHeader *msg)
441{ 424{
442 struct GNUNET_ATS_SchedulingHandle *sh = cls; 425 struct GNUNET_ATS_SchedulingHandle *sh = cls;
443 const struct AddressSuggestionMessage *m; 426 const struct AddressSuggestionMessage *m;
@@ -448,60 +431,52 @@ process_ats_message (void *cls,
448 uint16_t plugin_name_length; 431 uint16_t plugin_name_length;
449 uint32_t ats_count; 432 uint32_t ats_count;
450 433
451 if (NULL == msg) 434 if (NULL == msg)
452 { 435 {
453 force_reconnect (sh); 436 force_reconnect (sh);
454 return; 437 return;
455 } 438 }
456 if ( (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) && 439 if ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE) &&
457 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)) ) 440 (ntohs (msg->size) == sizeof (struct SessionReleaseMessage)))
458 { 441 {
459 process_release_message (sh, 442 process_release_message (sh, (const struct SessionReleaseMessage *) msg);
460 (const struct SessionReleaseMessage*) msg); 443 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
461 GNUNET_CLIENT_receive (sh->client, 444 GNUNET_TIME_UNIT_FOREVER_REL);
462 &process_ats_message, sh,
463 GNUNET_TIME_UNIT_FOREVER_REL);
464 if (GNUNET_YES == sh->reconnect) 445 if (GNUNET_YES == sh->reconnect)
465 force_reconnect (sh); 446 force_reconnect (sh);
466 return; 447 return;
467 } 448 }
468 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) || 449 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION) ||
469 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)) ) 450 (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage)))
470 { 451 {
471 GNUNET_break (0); 452 GNUNET_break (0);
472 force_reconnect (sh); 453 force_reconnect (sh);
473 return; 454 return;
474 } 455 }
475 m = (const struct AddressSuggestionMessage*) msg; 456 m = (const struct AddressSuggestionMessage *) msg;
476 ats_count = ntohl (m->ats_count); 457 ats_count = ntohl (m->ats_count);
477 address_length = ntohs (m->address_length); 458 address_length = ntohs (m->address_length);
478 atsi = (const struct GNUNET_ATS_Information*) &m[1]; 459 atsi = (const struct GNUNET_ATS_Information *) &m[1];
479 address = (const char*) &atsi[ats_count]; 460 address = (const char *) &atsi[ats_count];
480 plugin_name = &address[address_length]; 461 plugin_name = &address[address_length];
481 plugin_name_length = ntohs (m->plugin_name_length); 462 plugin_name_length = ntohs (m->plugin_name_length);
482 if ( (address_length + 463 if ((address_length + plugin_name_length +
483 plugin_name_length + 464 ats_count * sizeof (struct GNUNET_ATS_Information) +
484 ats_count * sizeof (struct GNUNET_ATS_Information) + 465 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) ||
485 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) || 466 (ats_count >
486 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 467 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
487 (plugin_name[plugin_name_length - 1] != '\0') ) 468 || (plugin_name[plugin_name_length - 1] != '\0'))
488 { 469 {
489 GNUNET_break (0); 470 GNUNET_break (0);
490 force_reconnect (sh); 471 force_reconnect (sh);
491 return; 472 return;
492 } 473 }
493 sh->suggest_cb (sh->suggest_cb_cls, 474 sh->suggest_cb (sh->suggest_cb_cls, &m->peer, plugin_name, address,
494 &m->peer, 475 address_length, find_session (sh, ntohl (m->session_id),
495 plugin_name, 476 &m->peer), m->bandwidth_out,
496 address, address_length, 477 m->bandwidth_in, atsi, ats_count);
497 find_session (sh, ntohl (m->session_id), &m->peer), 478 GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
498 m->bandwidth_out, 479 GNUNET_TIME_UNIT_FOREVER_REL);
499 m->bandwidth_in,
500 atsi,
501 ats_count);
502 GNUNET_CLIENT_receive (sh->client,
503 &process_ats_message, sh,
504 GNUNET_TIME_UNIT_FOREVER_REL);
505 if (GNUNET_YES == sh->reconnect) 480 if (GNUNET_YES == sh->reconnect)
506 force_reconnect (sh); 481 force_reconnect (sh);
507} 482}
@@ -521,20 +496,17 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
521 GNUNET_assert (NULL == sh->client); 496 GNUNET_assert (NULL == sh->client);
522 sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg); 497 sh->client = GNUNET_CLIENT_connect ("ats", sh->cfg);
523 GNUNET_assert (NULL != sh->client); 498 GNUNET_assert (NULL != sh->client);
524 if ( (NULL == (p = sh->pending_head)) || 499 if ((NULL == (p = sh->pending_head)) || (GNUNET_YES != p->is_init))
525 (GNUNET_YES != p->is_init) )
526 { 500 {
527 p = GNUNET_malloc (sizeof (struct PendingMessage) + 501 p = GNUNET_malloc (sizeof (struct PendingMessage) +
528 sizeof (struct ClientStartMessage)); 502 sizeof (struct ClientStartMessage));
529 p->size = sizeof (struct ClientStartMessage); 503 p->size = sizeof (struct ClientStartMessage);
530 p->is_init = GNUNET_YES; 504 p->is_init = GNUNET_YES;
531 init = (struct ClientStartMessage *) &p[1]; 505 init = (struct ClientStartMessage *) &p[1];
532 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 506 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
533 init->header.size = htons (sizeof (struct ClientStartMessage)); 507 init->header.size = htons (sizeof (struct ClientStartMessage));
534 init->start_flag = htonl (START_FLAG_SCHEDULING); 508 init->start_flag = htonl (START_FLAG_SCHEDULING);
535 GNUNET_CONTAINER_DLL_insert (sh->pending_head, 509 GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, p);
536 sh->pending_tail,
537 p);
538 } 510 }
539 do_transmit (sh); 511 do_transmit (sh);
540} 512}
@@ -550,8 +522,8 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
550 */ 522 */
551struct GNUNET_ATS_SchedulingHandle * 523struct GNUNET_ATS_SchedulingHandle *
552GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 524GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
553 GNUNET_ATS_AddressSuggestionCallback suggest_cb, 525 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
554 void *suggest_cb_cls) 526 void *suggest_cb_cls)
555{ 527{
556 struct GNUNET_ATS_SchedulingHandle *sh; 528 struct GNUNET_ATS_SchedulingHandle *sh;
557 529
@@ -559,9 +531,7 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
559 sh->cfg = cfg; 531 sh->cfg = cfg;
560 sh->suggest_cb = suggest_cb; 532 sh->suggest_cb = suggest_cb;
561 sh->suggest_cb_cls = suggest_cb_cls; 533 sh->suggest_cb_cls = suggest_cb_cls;
562 GNUNET_array_grow (sh->session_array, 534 GNUNET_array_grow (sh->session_array, sh->session_array_size, 4);
563 sh->session_array_size,
564 4);
565 reconnect (sh); 535 reconnect (sh);
566 return sh; 536 return sh;
567} 537}
@@ -579,9 +549,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
579 549
580 while (NULL != (p = sh->pending_head)) 550 while (NULL != (p = sh->pending_head))
581 { 551 {
582 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 552 GNUNET_CONTAINER_DLL_remove (sh->pending_head, sh->pending_tail, p);
583 sh->pending_tail,
584 p);
585 GNUNET_free (p); 553 GNUNET_free (p);
586 } 554 }
587 if (NULL != sh->client) 555 if (NULL != sh->client)
@@ -594,9 +562,7 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
594 GNUNET_SCHEDULER_cancel (sh->task); 562 GNUNET_SCHEDULER_cancel (sh->task);
595 sh->task = GNUNET_SCHEDULER_NO_TASK; 563 sh->task = GNUNET_SCHEDULER_NO_TASK;
596 } 564 }
597 GNUNET_array_grow (sh->session_array, 565 GNUNET_array_grow (sh->session_array, sh->session_array_size, 0);
598 sh->session_array_size,
599 0);
600 GNUNET_free (sh); 566 GNUNET_free (sh);
601} 567}
602 568
@@ -616,17 +582,15 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
616 struct RequestAddressMessage *m; 582 struct RequestAddressMessage *m;
617 583
618 p = GNUNET_malloc (sizeof (struct PendingMessage) + 584 p = GNUNET_malloc (sizeof (struct PendingMessage) +
619 sizeof (struct RequestAddressMessage)); 585 sizeof (struct RequestAddressMessage));
620 p->size = sizeof (struct RequestAddressMessage); 586 p->size = sizeof (struct RequestAddressMessage);
621 p->is_init = GNUNET_NO; 587 p->is_init = GNUNET_NO;
622 m = (struct RequestAddressMessage*) &p[1]; 588 m = (struct RequestAddressMessage *) &p[1];
623 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); 589 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
624 m->header.size = htons (sizeof (struct RequestAddressMessage)); 590 m->header.size = htons (sizeof (struct RequestAddressMessage));
625 m->reserved = htonl (0); 591 m->reserved = htonl (0);
626 m->peer = *peer; 592 m->peer = *peer;
627 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 593 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
628 sh->pending_tail,
629 p);
630 do_transmit (sh); 594 do_transmit (sh);
631} 595}
632 596
@@ -651,9 +615,8 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
651void 615void
652GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, 616GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
653 const struct GNUNET_PeerIdentity *peer, 617 const struct GNUNET_PeerIdentity *peer,
654 const char *plugin_name, 618 const char *plugin_name, const void *plugin_addr,
655 const void *plugin_addr, size_t plugin_addr_len, 619 size_t plugin_addr_len, struct Session *session,
656 struct Session *session,
657 const struct GNUNET_ATS_Information *ats, 620 const struct GNUNET_ATS_Information *ats,
658 uint32_t ats_count) 621 uint32_t ats_count)
659{ 622{
@@ -664,21 +627,23 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
664 size_t namelen; 627 size_t namelen;
665 size_t msize; 628 size_t msize;
666 629
667 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 630 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
668 msize = sizeof (struct AddressUpdateMessage) + plugin_addr_len + 631 msize =
669 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; 632 sizeof (struct AddressUpdateMessage) + plugin_addr_len +
670 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 633 ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
671 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 634 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
672 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 635 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
673 (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) ) 636 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
637 (ats_count >=
638 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
674 { 639 {
675 GNUNET_break (0); 640 GNUNET_break (0);
676 return; 641 return;
677 } 642 }
678 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 643 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
679 p->size = msize; 644 p->size = msize;
680 p->is_init = GNUNET_NO; 645 p->is_init = GNUNET_NO;
681 m = (struct AddressUpdateMessage*) &p[1]; 646 m = (struct AddressUpdateMessage *) &p[1];
682 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); 647 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
683 m->header.size = htons (msize); 648 m->header.size = htons (msize);
684 m->ats_count = htonl (ats_count); 649 m->ats_count = htonl (ats_count);
@@ -686,14 +651,12 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
686 m->address_length = htons (plugin_addr_len); 651 m->address_length = htons (plugin_addr_len);
687 m->plugin_name_length = htons (namelen); 652 m->plugin_name_length = htons (namelen);
688 m->session_id = htonl (get_session_id (sh, session, peer)); 653 m->session_id = htonl (get_session_id (sh, session, peer));
689 am = (struct GNUNET_ATS_Information*) &m[1]; 654 am = (struct GNUNET_ATS_Information *) &m[1];
690 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 655 memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
691 pm = (char *) &am[ats_count]; 656 pm = (char *) &am[ats_count];
692 memcpy (pm, plugin_addr, plugin_addr_len); 657 memcpy (pm, plugin_addr, plugin_addr_len);
693 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 658 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
694 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 659 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
695 sh->pending_tail,
696 p);
697 do_transmit (sh); 660 do_transmit (sh);
698} 661}
699 662
@@ -712,12 +675,10 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
712 */ 675 */
713void 676void
714GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, 677GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
715 const struct GNUNET_PeerIdentity *peer, 678 const struct GNUNET_PeerIdentity *peer,
716 const char *plugin_name, 679 const char *plugin_name, const void *plugin_addr,
717 const void *plugin_addr, 680 size_t plugin_addr_len, struct Session *session,
718 size_t plugin_addr_len, 681 int in_use)
719 struct Session *session,
720 int in_use)
721{ 682{
722 struct PendingMessage *p; 683 struct PendingMessage *p;
723 struct AddressUseMessage *m; 684 struct AddressUseMessage *m;
@@ -727,30 +688,28 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
727 688
728 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 689 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
729 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen; 690 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen;
730 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 691 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
731 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 692 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
732 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 693 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
733 { 694 {
734 GNUNET_break (0); 695 GNUNET_break (0);
735 return; 696 return;
736 } 697 }
737 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 698 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
738 p->size = msize; 699 p->size = msize;
739 p->is_init = GNUNET_NO; 700 p->is_init = GNUNET_NO;
740 m = (struct AddressUseMessage*) &p[1]; 701 m = (struct AddressUseMessage *) &p[1];
741 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); 702 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
742 m->header.size = htons (msize); 703 m->header.size = htons (msize);
743 m->peer = *peer; 704 m->peer = *peer;
744 m->in_use = htons(in_use); 705 m->in_use = htons (in_use);
745 m->address_length = htons (plugin_addr_len); 706 m->address_length = htons (plugin_addr_len);
746 m->plugin_name_length = htons (namelen); 707 m->plugin_name_length = htons (namelen);
747 m->session_id = htonl (get_session_id (sh, session, peer)); 708 m->session_id = htonl (get_session_id (sh, session, peer));
748 pm = (char *) &m[1]; 709 pm = (char *) &m[1];
749 memcpy (pm, plugin_addr, plugin_addr_len); 710 memcpy (pm, plugin_addr, plugin_addr_len);
750 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 711 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
751 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 712 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
752 sh->pending_tail,
753 p);
754 713
755 do_transmit (sh); 714 do_transmit (sh);
756} 715}
@@ -768,10 +727,8 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
768void 727void
769GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, 728GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
770 const struct GNUNET_PeerIdentity *peer, 729 const struct GNUNET_PeerIdentity *peer,
771 const char *plugin_name, 730 const char *plugin_name, const void *plugin_addr,
772 const void *plugin_addr, 731 size_t plugin_addr_len, struct Session *session)
773 size_t plugin_addr_len,
774 struct Session *session)
775{ 732{
776 struct PendingMessage *p; 733 struct PendingMessage *p;
777 struct AddressDestroyedMessage *m; 734 struct AddressDestroyedMessage *m;
@@ -780,20 +737,19 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
780 size_t msize; 737 size_t msize;
781 uint32_t session_id; 738 uint32_t session_id;
782 739
783 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; 740 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
784 msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + 741 msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + namelen;
785 namelen; 742 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
786 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 743 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
787 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 744 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
788 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
789 { 745 {
790 GNUNET_break (0); 746 GNUNET_break (0);
791 return; 747 return;
792 } 748 }
793 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 749 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
794 p->size = msize; 750 p->size = msize;
795 p->is_init = GNUNET_NO; 751 p->is_init = GNUNET_NO;
796 m = (struct AddressDestroyedMessage*) &p[1]; 752 m = (struct AddressDestroyedMessage *) &p[1];
797 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); 753 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
798 m->header.size = htons (msize); 754 m->header.size = htons (msize);
799 m->reserved = htonl (0); 755 m->reserved = htonl (0);
@@ -804,9 +760,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
804 pm = (char *) &m[1]; 760 pm = (char *) &m[1];
805 memcpy (pm, plugin_addr, plugin_addr_len); 761 memcpy (pm, plugin_addr, plugin_addr_len);
806 memcpy (&pm[plugin_addr_len], plugin_name, namelen); 762 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
807 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, 763 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
808 sh->pending_tail,
809 p);
810 do_transmit (sh); 764 do_transmit (sh);
811 remove_session (sh, session_id, peer); 765 remove_session (sh, session_id, peer);
812} 766}