aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_performance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r--src/ats/ats_api_performance.c225
1 files changed, 98 insertions, 127 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index ba124fe21..ca489e4a6 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.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
@@ -65,19 +65,19 @@ struct GNUNET_ATS_ReservationContext
65 65
66 /** 66 /**
67 * Kept in a DLL. 67 * Kept in a DLL.
68 */ 68 */
69 struct GNUNET_ATS_ReservationContext *next; 69 struct GNUNET_ATS_ReservationContext *next;
70 70
71 /** 71 /**
72 * Kept in a DLL. 72 * Kept in a DLL.
73 */ 73 */
74 struct GNUNET_ATS_ReservationContext *prev; 74 struct GNUNET_ATS_ReservationContext *prev;
75 75
76 /** 76 /**
77 * Target peer. 77 * Target peer.
78 */ 78 */
79 struct GNUNET_PeerIdentity peer; 79 struct GNUNET_PeerIdentity peer;
80 80
81 /** 81 /**
82 * Desired reservation 82 * Desired reservation
83 */ 83 */
@@ -110,7 +110,7 @@ struct GNUNET_ATS_ReservationContext
110 */ 110 */
111struct GNUNET_ATS_PerformanceHandle 111struct GNUNET_ATS_PerformanceHandle
112{ 112{
113 113
114 /** 114 /**
115 * Our configuration. 115 * Our configuration.
116 */ 116 */
@@ -120,7 +120,7 @@ struct GNUNET_ATS_PerformanceHandle
120 * Callback to invoke on performance changes. 120 * Callback to invoke on performance changes.
121 */ 121 */
122 GNUNET_ATS_PeerInformationCallback infocb; 122 GNUNET_ATS_PeerInformationCallback infocb;
123 123
124 /** 124 /**
125 * Closure for 'infocb'. 125 * Closure for 'infocb'.
126 */ 126 */
@@ -158,9 +158,9 @@ struct GNUNET_ATS_PerformanceHandle
158 158
159 /** 159 /**
160 * Task to trigger reconnect. 160 * Task to trigger reconnect.
161 */ 161 */
162 GNUNET_SCHEDULER_TaskIdentifier task; 162 GNUNET_SCHEDULER_TaskIdentifier task;
163 163
164}; 164};
165 165
166 166
@@ -180,8 +180,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
180 * @param tc scheduler context 180 * @param tc scheduler context
181 */ 181 */
182static void 182static void
183reconnect_task (void *cls, 183reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 const struct GNUNET_SCHEDULER_TaskContext *tc)
185{ 184{
186 struct GNUNET_ATS_PerformanceHandle *ph = cls; 185 struct GNUNET_ATS_PerformanceHandle *ph = cls;
187 186
@@ -209,9 +208,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph);
209 * @return number of bytes copied into buf 208 * @return number of bytes copied into buf
210 */ 209 */
211static size_t 210static size_t
212transmit_message_to_ats (void *cls, 211transmit_message_to_ats (void *cls, size_t size, void *buf)
213 size_t size,
214 void *buf)
215{ 212{
216 struct GNUNET_ATS_PerformanceHandle *ph = cls; 213 struct GNUNET_ATS_PerformanceHandle *ph = cls;
217 struct PendingMessage *p; 214 struct PendingMessage *p;
@@ -221,15 +218,12 @@ transmit_message_to_ats (void *cls,
221 ph->th = NULL; 218 ph->th = NULL;
222 ret = 0; 219 ret = 0;
223 cbuf = buf; 220 cbuf = buf;
224 while ( (NULL != (p = ph->pending_head)) && 221 while ((NULL != (p = ph->pending_head)) && (p->size <= size))
225 (p->size <= size) )
226 { 222 {
227 memcpy (&cbuf[ret], &p[1], p->size); 223 memcpy (&cbuf[ret], &p[1], p->size);
228 ret += p->size; 224 ret += p->size;
229 size -= p->size; 225 size -= p->size;
230 GNUNET_CONTAINER_DLL_remove (ph->pending_head, 226 GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
231 ph->pending_tail,
232 p);
233 GNUNET_free (p); 227 GNUNET_free (p);
234 } 228 }
235 do_transmit (ph); 229 do_transmit (ph);
@@ -253,12 +247,12 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
253 if (NULL == (p = ph->pending_head)) 247 if (NULL == (p = ph->pending_head))
254 return; 248 return;
255 if (NULL == ph->client) 249 if (NULL == ph->client)
256 return; /* currently reconnecting */ 250 return; /* currently reconnecting */
257 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, 251 ph->th =
258 p->size, 252 GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size,
259 GNUNET_TIME_UNIT_FOREVER_REL, 253 GNUNET_TIME_UNIT_FOREVER_REL,
260 GNUNET_YES, 254 GNUNET_YES, &transmit_message_to_ats,
261 &transmit_message_to_ats, ph); 255 ph);
262} 256}
263 257
264 258
@@ -271,7 +265,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
271 */ 265 */
272static int 266static int
273process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, 267process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
274 const struct GNUNET_MessageHeader *msg) 268 const struct GNUNET_MessageHeader *msg)
275{ 269{
276 const struct PeerInformationMessage *pi; 270 const struct PeerInformationMessage *pi;
277 const struct GNUNET_ATS_Information *atsi; 271 const struct GNUNET_ATS_Information *atsi;
@@ -285,37 +279,31 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
285 { 279 {
286 GNUNET_break (0); 280 GNUNET_break (0);
287 return GNUNET_SYSERR; 281 return GNUNET_SYSERR;
288 } 282 }
289 if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) 283 if (ntohs (msg->size) < sizeof (struct PeerInformationMessage))
290 { 284 {
291 GNUNET_break (0); 285 GNUNET_break (0);
292 return GNUNET_SYSERR; 286 return GNUNET_SYSERR;
293 } 287 }
294 pi = (const struct PeerInformationMessage*) msg; 288 pi = (const struct PeerInformationMessage *) msg;
295 ats_count = ntohl (pi->ats_count); 289 ats_count = ntohl (pi->ats_count);
296 address_length = ntohs (pi->address_length); 290 address_length = ntohs (pi->address_length);
297 plugin_name_length = ntohs (pi->plugin_name_length); 291 plugin_name_length = ntohs (pi->plugin_name_length);
298 atsi = (const struct GNUNET_ATS_Information*) &pi[1]; 292 atsi = (const struct GNUNET_ATS_Information *) &pi[1];
299 address = (const char*) &atsi[ats_count]; 293 address = (const char *) &atsi[ats_count];
300 plugin_name = &address[address_length]; 294 plugin_name = &address[address_length];
301 if ( (address_length + 295 if ((address_length + plugin_name_length +
302 plugin_name_length + 296 ats_count * sizeof (struct GNUNET_ATS_Information) +
303 ats_count * sizeof (struct GNUNET_ATS_Information) + 297 sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
304 sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || 298 (ats_count >
305 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 299 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
306 (plugin_name[plugin_name_length - 1] != '\0') ) 300 || (plugin_name[plugin_name_length - 1] != '\0'))
307 { 301 {
308 GNUNET_break (0); 302 GNUNET_break (0);
309 return GNUNET_SYSERR; 303 return GNUNET_SYSERR;
310 } 304 }
311 ph->infocb (ph->infocb_cls, 305 ph->infocb (ph->infocb_cls, &pi->peer, plugin_name, address, address_length,
312 &pi->peer, 306 pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count);
313 plugin_name,
314 address, address_length,
315 pi->bandwidth_out,
316 pi->bandwidth_in,
317 atsi,
318 ats_count);
319 return GNUNET_OK; 307 return GNUNET_OK;
320} 308}
321 309
@@ -329,7 +317,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
329 */ 317 */
330static int 318static int
331process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, 319process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
332 const struct GNUNET_MessageHeader *msg) 320 const struct GNUNET_MessageHeader *msg)
333{ 321{
334 const struct ReservationResultMessage *rr; 322 const struct ReservationResultMessage *rr;
335 struct GNUNET_ATS_ReservationContext *rc; 323 struct GNUNET_ATS_ReservationContext *rc;
@@ -340,28 +328,21 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
340 GNUNET_break (0); 328 GNUNET_break (0);
341 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
342 } 330 }
343 rr = (const struct ReservationResultMessage*) msg; 331 rr = (const struct ReservationResultMessage *) msg;
344 amount = ntohl (rr->amount); 332 amount = ntohl (rr->amount);
345 rc = ph->reservation_head; 333 rc = ph->reservation_head;
346 if (0 != memcmp (&rr->peer, 334 if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity)))
347 &rc->peer,
348 sizeof (struct GNUNET_PeerIdentity)))
349 { 335 {
350 GNUNET_break (0); 336 GNUNET_break (0);
351 return GNUNET_SYSERR; 337 return GNUNET_SYSERR;
352 } 338 }
353 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, 339 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc);
354 ph->reservation_tail, 340 if ((amount == 0) || (rc->rcb != NULL))
355 rc);
356 if ( (amount == 0) ||
357 (rc->rcb != NULL) )
358 { 341 {
359 /* tell client if not cancelled */ 342 /* tell client if not cancelled */
360 if (rc->rcb != NULL) 343 if (rc->rcb != NULL)
361 rc->rcb (rc->rcb_cls, 344 rc->rcb (rc->rcb_cls, &rr->peer, amount,
362 &rr->peer, 345 GNUNET_TIME_relative_ntoh (rr->res_delay));
363 amount,
364 GNUNET_TIME_relative_ntoh (rr->res_delay));
365 GNUNET_free (rc); 346 GNUNET_free (rc);
366 return GNUNET_OK; 347 return GNUNET_OK;
367 } 348 }
@@ -369,7 +350,7 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
369 if (GNUNET_YES != rc->undo) 350 if (GNUNET_YES != rc->undo)
370 { 351 {
371 GNUNET_free (rc); 352 GNUNET_free (rc);
372 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ 353 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
373 } 354 }
374 GNUNET_free (rc); 355 GNUNET_free (rc);
375 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); 356 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL);
@@ -385,12 +366,11 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
385 * @param msg message received, NULL on timeout or fatal error 366 * @param msg message received, NULL on timeout or fatal error
386 */ 367 */
387static void 368static void
388process_ats_message (void *cls, 369process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
389 const struct GNUNET_MessageHeader *msg)
390{ 370{
391 struct GNUNET_ATS_PerformanceHandle *ph = cls; 371 struct GNUNET_ATS_PerformanceHandle *ph = cls;
392 372
393 if (NULL == msg) 373 if (NULL == msg)
394 goto reconnect; 374 goto reconnect;
395 switch (ntohs (msg->type)) 375 switch (ntohs (msg->type))
396 { 376 {
@@ -400,22 +380,22 @@ process_ats_message (void *cls,
400 break; 380 break;
401 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT: 381 case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
402 if (GNUNET_OK != process_rr_message (ph, msg)) 382 if (GNUNET_OK != process_rr_message (ph, msg))
403 goto reconnect; 383 goto reconnect;
404 break; 384 break;
405 default: 385 default:
406 GNUNET_break (0); 386 GNUNET_break (0);
407 goto reconnect; 387 goto reconnect;
408 return; 388 return;
409 } 389 }
410 GNUNET_CLIENT_receive (ph->client, 390 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
411 &process_ats_message, ph, 391 GNUNET_TIME_UNIT_FOREVER_REL);
412 GNUNET_TIME_UNIT_FOREVER_REL);
413 return; 392 return;
414 reconnect: 393reconnect:
415 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO); 394 GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
416 ph->client = NULL; 395 ph->client = NULL;
417 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 396 ph->task =
418 &reconnect_task, ph); 397 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
398 ph);
419} 399}
420 400
421 401
@@ -433,25 +413,22 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
433 GNUNET_assert (NULL == ph->client); 413 GNUNET_assert (NULL == ph->client);
434 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); 414 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg);
435 GNUNET_assert (NULL != ph->client); 415 GNUNET_assert (NULL != ph->client);
436 GNUNET_CLIENT_receive (ph->client, 416 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
437 &process_ats_message, ph, 417 GNUNET_TIME_UNIT_FOREVER_REL);
438 GNUNET_TIME_UNIT_FOREVER_REL); 418 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
439 if ( (NULL == (p = ph->pending_head)) ||
440 (GNUNET_YES != p->is_init) )
441 { 419 {
442 p = GNUNET_malloc (sizeof (struct PendingMessage) + 420 p = GNUNET_malloc (sizeof (struct PendingMessage) +
443 sizeof (struct ClientStartMessage)); 421 sizeof (struct ClientStartMessage));
444 p->size = sizeof (struct ClientStartMessage); 422 p->size = sizeof (struct ClientStartMessage);
445 p->is_init = GNUNET_YES; 423 p->is_init = GNUNET_YES;
446 init = (struct ClientStartMessage *) &p[1]; 424 init = (struct ClientStartMessage *) &p[1];
447 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 425 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
448 init->header.size = htons (sizeof (struct ClientStartMessage)); 426 init->header.size = htons (sizeof (struct ClientStartMessage));
449 init->start_flag = htonl ((ph->infocb == NULL) 427 init->start_flag =
450 ? START_FLAG_PERFORMANCE_NO_PIC 428 htonl ((ph->infocb ==
451 : START_FLAG_PERFORMANCE_WITH_PIC); 429 NULL) ? START_FLAG_PERFORMANCE_NO_PIC :
452 GNUNET_CONTAINER_DLL_insert (ph->pending_head, 430 START_FLAG_PERFORMANCE_WITH_PIC);
453 ph->pending_tail, 431 GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p);
454 p);
455 } 432 }
456 do_transmit (ph); 433 do_transmit (ph);
457} 434}
@@ -468,8 +445,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
468 */ 445 */
469struct GNUNET_ATS_PerformanceHandle * 446struct GNUNET_ATS_PerformanceHandle *
470GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 447GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
471 GNUNET_ATS_PeerInformationCallback infocb, 448 GNUNET_ATS_PeerInformationCallback infocb,
472 void *infocb_cls) 449 void *infocb_cls)
473{ 450{
474 struct GNUNET_ATS_PerformanceHandle *ph; 451 struct GNUNET_ATS_PerformanceHandle *ph;
475 452
@@ -492,22 +469,19 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
492{ 469{
493 struct PendingMessage *p; 470 struct PendingMessage *p;
494 struct GNUNET_ATS_ReservationContext *rc; 471 struct GNUNET_ATS_ReservationContext *rc;
495 472
496 while (NULL != (p = ph->pending_head)) 473 while (NULL != (p = ph->pending_head))
497 { 474 {
498 GNUNET_CONTAINER_DLL_remove (ph->pending_head, 475 GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p);
499 ph->pending_tail,
500 p);
501 GNUNET_free (p); 476 GNUNET_free (p);
502 } 477 }
503 while (NULL != (rc = ph->reservation_head)) 478 while (NULL != (rc = ph->reservation_head))
504 { 479 {
505 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, 480 GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail,
506 ph->reservation_tail, 481 rc);
507 rc);
508 GNUNET_break (NULL == rc->rcb); 482 GNUNET_break (NULL == rc->rcb);
509 GNUNET_free (rc); 483 GNUNET_free (rc);
510 } 484 }
511 if (GNUNET_SCHEDULER_NO_TASK != ph->task) 485 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
512 { 486 {
513 GNUNET_SCHEDULER_cancel (ph->task); 487 GNUNET_SCHEDULER_cancel (ph->task);
@@ -538,10 +512,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
538 */ 512 */
539struct GNUNET_ATS_ReservationContext * 513struct GNUNET_ATS_ReservationContext *
540GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, 514GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
541 const struct GNUNET_PeerIdentity *peer, 515 const struct GNUNET_PeerIdentity *peer,
542 int32_t amount, 516 int32_t amount,
543 GNUNET_ATS_ReservationCallback rcb, 517 GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
544 void *rcb_cls)
545{ 518{
546 struct GNUNET_ATS_ReservationContext *rc; 519 struct GNUNET_ATS_ReservationContext *rc;
547 struct PendingMessage *p; 520 struct PendingMessage *p;
@@ -552,24 +525,21 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
552 rc->peer = *peer; 525 rc->peer = *peer;
553 rc->rcb = rcb; 526 rc->rcb = rcb;
554 rc->rcb_cls = rcb_cls; 527 rc->rcb_cls = rcb_cls;
555 if ( (rcb != NULL) && (amount > 0) ) 528 if ((rcb != NULL) && (amount > 0))
556 rc->undo = GNUNET_YES; 529 rc->undo = GNUNET_YES;
557 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, 530 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail,
558 ph->reservation_tail, 531 rc);
559 rc); 532
560 533 p = GNUNET_malloc (sizeof (struct PendingMessage) +
561 p = GNUNET_malloc (sizeof (struct PendingMessage) + 534 sizeof (struct ReservationRequestMessage));
562 sizeof (struct ReservationRequestMessage));
563 p->size = sizeof (struct ReservationRequestMessage); 535 p->size = sizeof (struct ReservationRequestMessage);
564 p->is_init = GNUNET_NO; 536 p->is_init = GNUNET_NO;
565 m = (struct ReservationRequestMessage*) &p[1]; 537 m = (struct ReservationRequestMessage *) &p[1];
566 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); 538 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
567 m->header.size = htons (sizeof (struct ReservationRequestMessage)); 539 m->header.size = htons (sizeof (struct ReservationRequestMessage));
568 m->amount = htonl (amount); 540 m->amount = htonl (amount);
569 m->peer = *peer; 541 m->peer = *peer;
570 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, 542 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
571 ph->pending_tail,
572 p);
573 do_transmit (ph); 543 do_transmit (ph);
574 return rc; 544 return rc;
575} 545}
@@ -581,8 +551,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
581 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call 551 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
582 */ 552 */
583void 553void
584GNUNET_ATS_reserve_bandwidth_cancel (struct 554GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
585 GNUNET_ATS_ReservationContext *rc)
586{ 555{
587 rc->rcb = NULL; 556 rc->rcb = NULL;
588} 557}
@@ -591,15 +560,14 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct
591/** 560/**
592 * Change preferences for the given peer. Preference changes are forgotten if peers 561 * Change preferences for the given peer. Preference changes are forgotten if peers
593 * disconnect. 562 * disconnect.
594 * 563 *
595 * @param ph performance handle 564 * @param ph performance handle
596 * @param peer identifies the peer 565 * @param peer identifies the peer
597 * @param ... 0-terminated specification of the desired changes 566 * @param ... 0-terminated specification of the desired changes
598 */ 567 */
599void 568void
600GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, 569GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
601 const struct GNUNET_PeerIdentity *peer, 570 const struct GNUNET_PeerIdentity *peer, ...)
602 ...)
603{ 571{
604 struct PendingMessage *p; 572 struct PendingMessage *p;
605 struct ChangePreferenceMessage *m; 573 struct ChangePreferenceMessage *m;
@@ -611,60 +579,63 @@ GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
611 579
612 count = 0; 580 count = 0;
613 va_start (ap, peer); 581 va_start (ap, peer);
614 while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) 582 while (GNUNET_ATS_PREFERENCE_END !=
583 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
615 { 584 {
616 switch (kind) 585 switch (kind)
617 { 586 {
618 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 587 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
619 count++; 588 count++;
620 (void) va_arg (ap, double); 589 (void) va_arg (ap, double);
590
621 break; 591 break;
622 case GNUNET_ATS_PREFERENCE_LATENCY: 592 case GNUNET_ATS_PREFERENCE_LATENCY:
623 count++; 593 count++;
624 (void) va_arg (ap, double); 594 (void) va_arg (ap, double);
595
625 break; 596 break;
626 default: 597 default:
627 GNUNET_assert (0); 598 GNUNET_assert (0);
628 } 599 }
629 } 600 }
630 va_end (ap); 601 va_end (ap);
631 msize = count * sizeof (struct PreferenceInformation) + 602 msize =
632 sizeof (struct ChangePreferenceMessage); 603 count * sizeof (struct PreferenceInformation) +
633 p = GNUNET_malloc (sizeof (struct PendingMessage) + 604 sizeof (struct ChangePreferenceMessage);
634 msize); 605 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
635 p->size = msize; 606 p->size = msize;
636 p->is_init = GNUNET_NO; 607 p->is_init = GNUNET_NO;
637 m = (struct ChangePreferenceMessage*) &p[1]; 608 m = (struct ChangePreferenceMessage *) &p[1];
638 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); 609 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
639 m->header.size = htons (msize); 610 m->header.size = htons (msize);
640 m->num_preferences = htonl (count); 611 m->num_preferences = htonl (count);
641 m->peer = *peer; 612 m->peer = *peer;
642 pi = (struct PreferenceInformation*) &m[1]; 613 pi = (struct PreferenceInformation *) &m[1];
643 count = 0; 614 count = 0;
644 va_start (ap, peer); 615 va_start (ap, peer);
645 while (GNUNET_ATS_PREFERENCE_END != (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) 616 while (GNUNET_ATS_PREFERENCE_END !=
617 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
646 { 618 {
647 pi[count].preference_kind = htonl (kind); 619 pi[count].preference_kind = htonl (kind);
648 switch (kind) 620 switch (kind)
649 { 621 {
650 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 622 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
651 pi[count].preference_value = (float) va_arg (ap, double); 623 pi[count].preference_value = (float) va_arg (ap, double);
624
652 count++; 625 count++;
653 break; 626 break;
654 case GNUNET_ATS_PREFERENCE_LATENCY: 627 case GNUNET_ATS_PREFERENCE_LATENCY:
655 pi[count].preference_value = (float) va_arg (ap, double); 628 pi[count].preference_value = (float) va_arg (ap, double);
629
656 count++; 630 count++;
657 break; 631 break;
658 default: 632 default:
659 GNUNET_assert (0); 633 GNUNET_assert (0);
660 } 634 }
661 } 635 }
662 va_end (ap); 636 va_end (ap);
663 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, 637 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
664 ph->pending_tail,
665 p);
666 do_transmit (ph); 638 do_transmit (ph);
667} 639}
668 640
669/* end of ats_api_performance.c */ 641/* end of ats_api_performance.c */
670