diff options
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r-- | src/ats/ats_api_performance.c | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 51980f079..aaaaee089 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -364,35 +364,27 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
364 | const struct GNUNET_MessageHeader *msg) | 364 | const struct GNUNET_MessageHeader *msg) |
365 | { | 365 | { |
366 | const struct PeerInformationMessage *pi; | 366 | const struct PeerInformationMessage *pi; |
367 | const struct GNUNET_ATS_Information *atsi; | ||
368 | const char *plugin_address; | 367 | const char *plugin_address; |
369 | const char *plugin_name; | 368 | const char *plugin_name; |
370 | struct GNUNET_HELLO_Address address; | 369 | struct GNUNET_HELLO_Address address; |
371 | uint16_t plugin_address_length; | 370 | uint16_t plugin_address_length; |
372 | uint16_t plugin_name_length; | 371 | uint16_t plugin_name_length; |
373 | uint32_t ats_count; | ||
374 | int addr_active; | 372 | int addr_active; |
373 | struct GNUNET_ATS_Properties prop; | ||
375 | 374 | ||
376 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) | 375 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) |
377 | { | 376 | { |
378 | GNUNET_break(0); | 377 | GNUNET_break(0); |
379 | return GNUNET_SYSERR; | 378 | return GNUNET_SYSERR; |
380 | } | 379 | } |
381 | |||
382 | pi = (const struct PeerInformationMessage *) msg; | 380 | pi = (const struct PeerInformationMessage *) msg; |
383 | ats_count = ntohl (pi->ats_count); | ||
384 | plugin_address_length = ntohs (pi->address_length); | 381 | plugin_address_length = ntohs (pi->address_length); |
385 | plugin_name_length = ntohs (pi->plugin_name_length); | 382 | plugin_name_length = ntohs (pi->plugin_name_length); |
386 | addr_active = (int) ntohl (pi->address_active); | 383 | addr_active = (int) ntohl (pi->address_active); |
387 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 384 | plugin_address = (const char *) &pi[1]; |
388 | plugin_address = (const char *) &atsi[ats_count]; | ||
389 | plugin_name = &plugin_address[plugin_address_length]; | 385 | plugin_name = &plugin_address[plugin_address_length]; |
390 | if ((plugin_address_length + plugin_name_length | 386 | if ((plugin_address_length + plugin_name_length |
391 | + ats_count * sizeof(struct GNUNET_ATS_Information) | ||
392 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) | 387 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) |
393 | || (ats_count | ||
394 | > GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
395 | / sizeof(struct GNUNET_ATS_Information)) | ||
396 | || (plugin_name[plugin_name_length - 1] != '\0')) | 388 | || (plugin_name[plugin_name_length - 1] != '\0')) |
397 | { | 389 | { |
398 | GNUNET_break(0); | 390 | GNUNET_break(0); |
@@ -401,6 +393,8 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
401 | 393 | ||
402 | if (NULL != ph->addr_info_cb) | 394 | if (NULL != ph->addr_info_cb) |
403 | { | 395 | { |
396 | GNUNET_ATS_properties_ntoh (&prop, | ||
397 | &pi->properties); | ||
404 | address.peer = pi->peer; | 398 | address.peer = pi->peer; |
405 | address.address = plugin_address; | 399 | address.address = plugin_address; |
406 | address.address_length = plugin_address_length; | 400 | address.address_length = plugin_address_length; |
@@ -410,7 +404,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
410 | addr_active, | 404 | addr_active, |
411 | pi->bandwidth_out, | 405 | pi->bandwidth_out, |
412 | pi->bandwidth_in, | 406 | pi->bandwidth_in, |
413 | atsi, ats_count); | 407 | &prop); |
414 | } | 408 | } |
415 | return GNUNET_OK; | 409 | return GNUNET_OK; |
416 | } | 410 | } |
@@ -488,15 +482,14 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
488 | const struct PeerInformationMessage *pi; | 482 | const struct PeerInformationMessage *pi; |
489 | struct GNUNET_ATS_AddressListHandle *alh; | 483 | struct GNUNET_ATS_AddressListHandle *alh; |
490 | struct GNUNET_ATS_AddressListHandle *next; | 484 | struct GNUNET_ATS_AddressListHandle *next; |
491 | const struct GNUNET_ATS_Information *atsi; | ||
492 | const char *plugin_address; | 485 | const char *plugin_address; |
493 | const char *plugin_name; | 486 | const char *plugin_name; |
494 | struct GNUNET_HELLO_Address address; | 487 | struct GNUNET_HELLO_Address address; |
495 | struct GNUNET_PeerIdentity allzeros; | 488 | struct GNUNET_PeerIdentity allzeros; |
496 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | 489 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; |
490 | struct GNUNET_ATS_Properties prop; | ||
497 | uint16_t plugin_address_length; | 491 | uint16_t plugin_address_length; |
498 | uint16_t plugin_name_length; | 492 | uint16_t plugin_name_length; |
499 | uint32_t ats_count; | ||
500 | uint32_t active; | 493 | uint32_t active; |
501 | uint32_t id; | 494 | uint32_t id; |
502 | 495 | ||
@@ -507,18 +500,13 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
507 | } | 500 | } |
508 | pi = (const struct PeerInformationMessage *) msg; | 501 | pi = (const struct PeerInformationMessage *) msg; |
509 | id = ntohl (pi->id); | 502 | id = ntohl (pi->id); |
510 | ats_count = ntohl (pi->ats_count); | ||
511 | active = ntohl (pi->address_active); | 503 | active = ntohl (pi->address_active); |
512 | plugin_address_length = ntohs (pi->address_length); | 504 | plugin_address_length = ntohs (pi->address_length); |
513 | plugin_name_length = ntohs (pi->plugin_name_length); | 505 | plugin_name_length = ntohs (pi->plugin_name_length); |
514 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 506 | plugin_address = (const char *) &pi[1]; |
515 | plugin_address = (const char *) &atsi[ats_count]; | ||
516 | plugin_name = &plugin_address[plugin_address_length]; | 507 | plugin_name = &plugin_address[plugin_address_length]; |
517 | if ( (plugin_address_length + plugin_name_length | 508 | if ( (plugin_address_length + plugin_name_length |
518 | + ats_count * sizeof(struct GNUNET_ATS_Information) | ||
519 | + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | 509 | + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || |
520 | (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
521 | / sizeof(struct GNUNET_ATS_Information)) || | ||
522 | (plugin_name[plugin_name_length - 1] != '\0') ) | 510 | (plugin_name[plugin_name_length - 1] != '\0') ) |
523 | { | 511 | { |
524 | GNUNET_break(0); | 512 | GNUNET_break(0); |
@@ -545,8 +533,7 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
545 | memset (&allzeros, '\0', sizeof (allzeros)); | 533 | memset (&allzeros, '\0', sizeof (allzeros)); |
546 | if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) && | 534 | if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) && |
547 | (0 == plugin_name_length) && | 535 | (0 == plugin_name_length) && |
548 | (0 == plugin_address_length) && | 536 | (0 == plugin_address_length) ) |
549 | (0 == ats_count) ) | ||
550 | { | 537 | { |
551 | /* Done */ | 538 | /* Done */ |
552 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 539 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -561,7 +548,7 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
561 | GNUNET_NO, | 548 | GNUNET_NO, |
562 | bandwidth_zero, | 549 | bandwidth_zero, |
563 | bandwidth_zero, | 550 | bandwidth_zero, |
564 | NULL, 0); | 551 | NULL); |
565 | GNUNET_free (alh); | 552 | GNUNET_free (alh); |
566 | return GNUNET_OK; | 553 | return GNUNET_OK; |
567 | } | 554 | } |
@@ -573,12 +560,16 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
573 | if ( ( (GNUNET_YES == alh->all_addresses) || | 560 | if ( ( (GNUNET_YES == alh->all_addresses) || |
574 | (GNUNET_YES == active) ) && | 561 | (GNUNET_YES == active) ) && |
575 | (NULL != alh->cb) ) | 562 | (NULL != alh->cb) ) |
563 | { | ||
564 | GNUNET_ATS_properties_ntoh (&prop, | ||
565 | &pi->properties); | ||
576 | alh->cb (ph->addr_info_cb_cls, | 566 | alh->cb (ph->addr_info_cb_cls, |
577 | &address, | 567 | &address, |
578 | active, | 568 | active, |
579 | pi->bandwidth_out, | 569 | pi->bandwidth_out, |
580 | pi->bandwidth_in, | 570 | pi->bandwidth_in, |
581 | atsi, ats_count); | 571 | &prop); |
572 | } | ||
582 | return GNUNET_OK; | 573 | return GNUNET_OK; |
583 | } | 574 | } |
584 | 575 | ||
@@ -641,7 +632,7 @@ process_ats_message (void *cls, | |||
641 | GNUNET_NO, | 632 | GNUNET_NO, |
642 | GNUNET_BANDWIDTH_value_init (0), | 633 | GNUNET_BANDWIDTH_value_init (0), |
643 | GNUNET_BANDWIDTH_value_init (0), | 634 | GNUNET_BANDWIDTH_value_init (0), |
644 | NULL, 0); | 635 | NULL); |
645 | } | 636 | } |
646 | ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff); | 637 | ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff); |
647 | ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff, | 638 | ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff, |
@@ -917,8 +908,9 @@ GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandl | |||
917 | const char * | 908 | const char * |
918 | GNUNET_ATS_print_preference_type (uint32_t type) | 909 | GNUNET_ATS_print_preference_type (uint32_t type) |
919 | { | 910 | { |
920 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; | 911 | const char *prefs[] = GNUNET_ATS_PreferenceTypeString; |
921 | if (type < GNUNET_ATS_PreferenceCount) | 912 | |
913 | if (type < GNUNET_ATS_PREFERENCE_END) | ||
922 | return prefs[type]; | 914 | return prefs[type]; |
923 | return NULL; | 915 | return NULL; |
924 | } | 916 | } |
@@ -930,7 +922,7 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
930 | * | 922 | * |
931 | * @param ph performance handle | 923 | * @param ph performance handle |
932 | * @param peer identifies the peer | 924 | * @param peer identifies the peer |
933 | * @param ... 0-terminated specification of the desired changes | 925 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
934 | */ | 926 | */ |
935 | void | 927 | void |
936 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, | 928 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, |
@@ -946,20 +938,18 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
946 | 938 | ||
947 | count = 0; | 939 | count = 0; |
948 | va_start(ap, peer); | 940 | va_start(ap, peer); |
949 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 941 | while (GNUNET_ATS_PREFERENCE_END != |
950 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) | 942 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
951 | { | 943 | { |
952 | switch (kind) | 944 | switch (kind) |
953 | { | 945 | { |
954 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 946 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
955 | count++; | 947 | count++; |
956 | (void) va_arg (ap, double); | 948 | (void) va_arg (ap, double); |
957 | |||
958 | break; | 949 | break; |
959 | case GNUNET_ATS_PREFERENCE_LATENCY: | 950 | case GNUNET_ATS_PREFERENCE_LATENCY: |
960 | count++; | 951 | count++; |
961 | (void) va_arg (ap, double); | 952 | (void) va_arg (ap, double); |
962 | |||
963 | break; | 953 | break; |
964 | default: | 954 | default: |
965 | GNUNET_assert(0); | 955 | GNUNET_assert(0); |
@@ -1012,7 +1002,7 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
1012 | * @param ph performance handle | 1002 | * @param ph performance handle |
1013 | * @param scope the time interval this valid for: [now - scope .. now] | 1003 | * @param scope the time interval this valid for: [now - scope .. now] |
1014 | * @param peer identifies the peer | 1004 | * @param peer identifies the peer |
1015 | * @param ... 0-terminated specification of the desired changes | 1005 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
1016 | */ | 1006 | */ |
1017 | void | 1007 | void |
1018 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 1008 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, |
@@ -1029,8 +1019,8 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
1029 | 1019 | ||
1030 | count = 0; | 1020 | count = 0; |
1031 | va_start(ap, scope); | 1021 | va_start(ap, scope); |
1032 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 1022 | while (GNUNET_ATS_PREFERENCE_END != |
1033 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) | 1023 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
1034 | { | 1024 | { |
1035 | switch (kind) | 1025 | switch (kind) |
1036 | { | 1026 | { |