aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_addresses.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-09-16 20:30:48 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-09-16 20:30:48 +0000
commit4bf802ac4b418e705022a0098e7551fbcdef3103 (patch)
treecf3b1365d9ad3e8b6261b9fb6627c2b35de215b6 /src/ats/gnunet-service-ats_addresses.c
parent78df6a4353ad066d88d8ce835021d0d684d706ba (diff)
downloadgnunet-4bf802ac4b418e705022a0098e7551fbcdef3103.tar.gz
gnunet-4bf802ac4b418e705022a0098e7551fbcdef3103.zip
indent
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r--src/ats/gnunet-service-ats_addresses.c272
1 files changed, 135 insertions, 137 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 229af78bb..9388a66b4 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -412,7 +412,7 @@ struct GAS_Addresses_Handle
412 */ 412 */
413static unsigned int 413static unsigned int
414disassemble_ats_information (struct ATS_Address *dest, 414disassemble_ats_information (struct ATS_Address *dest,
415 const struct GNUNET_ATS_Information *update, 415 const struct GNUNET_ATS_Information *update,
416 uint32_t update_count, 416 uint32_t update_count,
417 struct GNUNET_ATS_Information **delta_dest, 417 struct GNUNET_ATS_Information **delta_dest,
418 uint32_t *delta_count) 418 uint32_t *delta_count)
@@ -438,71 +438,71 @@ disassemble_ats_information (struct ATS_Address *dest,
438 438
439 if (NULL == dest->atsi) 439 if (NULL == dest->atsi)
440 { 440 {
441 /* Create performance information */ 441 /* Create performance information */
442 dest->atsi = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); 442 dest->atsi = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information));
443 dest->atsi_count = update_count; 443 dest->atsi_count = update_count;
444 memcpy (dest->atsi, update, update_count * sizeof (struct GNUNET_ATS_Information)); 444 memcpy (dest->atsi, update, update_count * sizeof (struct GNUNET_ATS_Information));
445 (*delta_dest) = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); 445 (*delta_dest) = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information));
446 for (c1 = 0; c1 < update_count; c1 ++) 446 for (c1 = 0; c1 < update_count; c1 ++)
447 { 447 {
448 (*delta_dest)[c1].type = update[c1].type; 448 (*delta_dest)[c1].type = update[c1].type;
449 (*delta_dest)[c1].value = htonl(GNUNET_ATS_VALUE_UNDEFINED); 449 (*delta_dest)[c1].value = htonl(GNUNET_ATS_VALUE_UNDEFINED);
450 } 450 }
451 (*delta_count) = update_count; 451 (*delta_count) = update_count;
452 return GNUNET_YES; 452 return GNUNET_YES;
453 } 453 }
454 454
455 for (c1 = 0; c1 < update_count; c1++) 455 for (c1 = 0; c1 < update_count; c1++)
456 { 456 {
457 /* Update existing performance information */ 457 /* Update existing performance information */
458 found = GNUNET_NO; 458 found = GNUNET_NO;
459 for (c2 = 0; c2 < dest->atsi_count; c2++) 459 for (c2 = 0; c2 < dest->atsi_count; c2++)
460 { 460 {
461 if (update[c1].type == dest->atsi[c2].type) 461 if (update[c1].type == dest->atsi[c2].type)
462 { 462 {
463 if (update[c1].value != dest->atsi[c2].value) 463 if (update[c1].value != dest->atsi[c2].value)
464 { 464 {
465 /* Save previous value in delta */ 465 /* Save previous value in delta */
466 delta_atsi[delta_atsi_count] = dest->atsi[c2]; 466 delta_atsi[delta_atsi_count] = dest->atsi[c2];
467 delta_atsi_count ++; 467 delta_atsi_count ++;
468 /* Set new value */ 468 /* Set new value */
469 dest->atsi[c2].value = update[c1].value; 469 dest->atsi[c2].value = update[c1].value;
470 change = GNUNET_YES; 470 change = GNUNET_YES;
471 } 471 }
472 found = GNUNET_YES; 472 found = GNUNET_YES;
473 break; 473 break;
474 } 474 }
475 } 475 }
476 if (GNUNET_NO == found) 476 if (GNUNET_NO == found)
477 { 477 {
478 add_atsi[add_atsi_count] = update[c1]; 478 add_atsi[add_atsi_count] = update[c1];
479 add_atsi_count ++; 479 add_atsi_count ++;
480 delta_atsi[delta_atsi_count].type = update[c1].type; 480 delta_atsi[delta_atsi_count].type = update[c1].type;
481 delta_atsi[delta_atsi_count].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); 481 delta_atsi[delta_atsi_count].value = htonl (GNUNET_ATS_VALUE_UNDEFINED);
482 delta_atsi_count ++; 482 delta_atsi_count ++;
483 } 483 }
484 } 484 }
485 485
486 if (add_atsi_count > 0) 486 if (add_atsi_count > 0)
487 { 487 {
488 /* Extend ats performance information */ 488 /* Extend ats performance information */
489 489
490 tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) * 490 tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) *
491 (sizeof (struct GNUNET_ATS_Information))); 491 (sizeof (struct GNUNET_ATS_Information)));
492 memcpy (tmp_atsi, dest->atsi, dest->atsi_count * sizeof (struct GNUNET_ATS_Information)); 492 memcpy (tmp_atsi, dest->atsi, dest->atsi_count * sizeof (struct GNUNET_ATS_Information));
493 memcpy (&tmp_atsi[dest->atsi_count], add_atsi, add_atsi_count * sizeof (struct GNUNET_ATS_Information)); 493 memcpy (&tmp_atsi[dest->atsi_count], add_atsi, add_atsi_count * sizeof (struct GNUNET_ATS_Information));
494 GNUNET_free (dest->atsi); 494 GNUNET_free (dest->atsi);
495 dest->atsi = tmp_atsi; 495 dest->atsi = tmp_atsi;
496 dest->atsi_count = dest->atsi_count + add_atsi_count; 496 dest->atsi_count = dest->atsi_count + add_atsi_count;
497 change = GNUNET_YES; 497 change = GNUNET_YES;
498 } 498 }
499 499
500 if (delta_atsi_count > 0) 500 if (delta_atsi_count > 0)
501 { 501 {
502 /* Copy delta */ 502 /* Copy delta */
503 (*delta_dest) = GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); 503 (*delta_dest) = GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information));
504 memcpy ((*delta_dest), delta_atsi, delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); 504 memcpy ((*delta_dest), delta_atsi, delta_atsi_count * sizeof (struct GNUNET_ATS_Information));
505 (*delta_count) = delta_atsi_count; 505 (*delta_count) = delta_atsi_count;
506 } 506 }
507 507
508 return change; 508 return change;
@@ -853,37 +853,35 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
853 atsi_delta_count = 0; 853 atsi_delta_count = 0;
854 if (GNUNET_YES == disassemble_ats_information (existing_address, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) 854 if (GNUNET_YES == disassemble_ats_information (existing_address, atsi, atsi_count, &atsi_delta, &atsi_delta_count))
855 { 855 {
856 /* Notify performance clients about properties */ 856 /* Notify performance clients about properties */
857 GAS_performance_notify_all_clients (&existing_address->peer, 857 GAS_performance_notify_all_clients (&existing_address->peer,
858 existing_address->plugin, 858 existing_address->plugin,
859 existing_address->addr, existing_address->addr_len, 859 existing_address->addr, existing_address->addr_len,
860 existing_address->session_id, 860 existing_address->session_id,
861 existing_address->atsi, existing_address->atsi_count, 861 existing_address->atsi, existing_address->atsi_count,
862 existing_address->assigned_bw_out, 862 existing_address->assigned_bw_out,
863 existing_address->assigned_bw_in); 863 existing_address->assigned_bw_in);
864 864
865 for (c1 = 0; c1 < atsi_delta_count; c1++) 865 for (c1 = 0; c1 < atsi_delta_count; c1++)
866 { 866 {
867 if ((GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) && 867 if ((GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) &&
868 (addr_net != ntohl (atsi_delta[c1].value))) 868 (addr_net != ntohl (atsi_delta[c1].value)))
869 { 869 {
870 /* Network type changed */ 870 /* Network type changed */
871 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Address for peer `%s' %p changed from network %s to %s\n", 871 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Address for peer `%s' %p changed from network %s to %s\n",
872 GNUNET_i2s (peer), 872 GNUNET_i2s (peer), existing_address,
873 existing_address, 873 GNUNET_ATS_print_network_type (addr_net),
874 GNUNET_ATS_print_network_type (addr_net), 874 GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value)));
875 GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); 875 handle->s_address_update_network (handle->solver, existing_address,
876 handle->s_address_update_network (handle->solver, existing_address, 876 ntohl (atsi_delta[c1].value),
877 ntohl (atsi_delta[c1].value), 877 get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE));
878 get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); 878 addr_net = get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE);
879 addr_net = get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE); 879 }
880 } 880 }
881 } 881 /* Notify solver about update with atsi information and session */
882 882 handle->s_bulk_start (handle->solver);
883 /* Notify solver about update with atsi information and session */ 883 GAS_normalization_normalize_property (handle->addresses, existing_address, atsi, atsi_count);
884 handle->s_bulk_start (handle->solver); 884 handle->s_bulk_stop (handle->solver);
885 GAS_normalization_normalize_property (handle->addresses, existing_address, atsi, atsi_count);
886 handle->s_bulk_stop (handle->solver);
887 } 885 }
888 GNUNET_free_non_null (atsi_delta); 886 GNUNET_free_non_null (atsi_delta);
889 887
@@ -942,7 +940,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
942 940
943 /* Get existing address */ 941 /* Get existing address */
944 aa = find_exact_address (handle, peer, plugin_name, 942 aa = find_exact_address (handle, peer, plugin_name,
945 plugin_addr, plugin_addr_len, session_id); 943 plugin_addr, plugin_addr_len, session_id);
946 if (aa == NULL) 944 if (aa == NULL)
947 { 945 {
948 /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", */ 946 /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", */
@@ -976,30 +974,30 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
976 atsi_delta_count = 0; 974 atsi_delta_count = 0;
977 if (GNUNET_YES == disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) 975 if (GNUNET_YES == disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count))
978 { 976 {
979 /* ATS properties changed */ 977 /* ATS properties changed */
980 for (c1 = 0; c1 < atsi_delta_count; c1++) 978 for (c1 = 0; c1 < atsi_delta_count; c1++)
981 { 979 {
982 if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) 980 if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type))
983 { 981 {
984 /* Network type changed */ 982 /* Network type changed */
985 handle->s_address_update_network (handle->solver, aa, 983 handle->s_address_update_network (handle->solver, aa,
986 ntohl (atsi_delta[c1].value), 984 ntohl (atsi_delta[c1].value),
987 get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); 985 get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE));
988 } 986 }
989 } 987 }
990 988
991 /* Notify performance clients about updated address */ 989 /* Notify performance clients about updated address */
992 GAS_performance_notify_all_clients (&aa->peer, 990 GAS_performance_notify_all_clients (&aa->peer,
993 aa->plugin, 991 aa->plugin,
994 aa->addr, aa->addr_len, 992 aa->addr, aa->addr_len,
995 aa->session_id, 993 aa->session_id,
996 aa->atsi, aa->atsi_count, 994 aa->atsi, aa->atsi_count,
997 aa->assigned_bw_out, 995 aa->assigned_bw_out,
998 aa->assigned_bw_in); 996 aa->assigned_bw_in);
999 997
1000 handle->s_bulk_start (handle->solver); 998 handle->s_bulk_start (handle->solver);
1001 GAS_normalization_normalize_property (handle->addresses, aa, atsi, atsi_count); 999 GAS_normalization_normalize_property (handle->addresses, aa, atsi, atsi_count);
1002 handle->s_bulk_stop (handle->solver); 1000 handle->s_bulk_stop (handle->solver);
1003 } 1001 }
1004 GNUNET_free_non_null (atsi_delta); 1002 GNUNET_free_non_null (atsi_delta);
1005} 1003}
@@ -1410,12 +1408,13 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
1410 */ 1408 */
1411static void 1409static void
1412normalized_preference_changed_cb (void *cls, 1410normalized_preference_changed_cb (void *cls,
1413 const struct GNUNET_PeerIdentity *peer, 1411 const struct GNUNET_PeerIdentity *peer,
1414 enum GNUNET_ATS_PreferenceKind kind, 1412 enum GNUNET_ATS_PreferenceKind kind,
1415 double pref_rel) 1413 double pref_rel)
1416{ 1414{
1417 GNUNET_assert (NULL != cls); 1415 GNUNET_assert (NULL != cls);
1418 struct GAS_Addresses_Handle *handle = cls; 1416 struct GAS_Addresses_Handle *handle = cls;
1417
1419 /* Tell solver about update */ 1418 /* Tell solver about update */
1420 handle->s_pref (handle->solver, peer, kind, pref_rel); 1419 handle->s_pref (handle->solver, peer, kind, pref_rel);
1421} 1420}
@@ -1431,24 +1430,20 @@ normalized_preference_changed_cb (void *cls,
1431 */ 1430 */
1432static void 1431static void
1433normalized_property_changed_cb (void *cls, 1432normalized_property_changed_cb (void *cls,
1434 struct ATS_Address *address, 1433 struct ATS_Address *address,
1435 uint32_t type, 1434 uint32_t type,
1436 double prop_rel) 1435 double prop_rel)
1437{ 1436{
1438 struct GAS_Addresses_Handle *ah = (struct GAS_Addresses_Handle *) cls; 1437 struct GAS_Addresses_Handle *ah = (struct GAS_Addresses_Handle *) cls;
1439 GNUNET_assert (NULL != ah); 1438 GNUNET_assert (NULL != ah);
1440 1439
1441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1442 "Normalized property %s for peer `%s' changed to %.3f \n", 1441 "Normalized property %s for peer `%s' changed to %.3f \n",
1443 GNUNET_ATS_print_property_type (type), 1442 GNUNET_ATS_print_property_type (type),
1444 GNUNET_i2s (&address->peer), 1443 GNUNET_i2s (&address->peer),
1445 prop_rel); 1444 prop_rel);
1446 1445
1447 ah->s_address_update_property (ah->solver, 1446 ah->s_address_update_property (ah->solver, address, type, 0, prop_rel);
1448 address,
1449 type,
1450 0,
1451 prop_rel);
1452} 1447}
1453 1448
1454 1449
@@ -1496,10 +1491,10 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
1496 enum GNUNET_ATS_PreferenceKind kind, 1491 enum GNUNET_ATS_PreferenceKind kind,
1497 float score_abs) 1492 float score_abs)
1498{ 1493{
1499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1500 "Received `%s' for peer `%s' for client %p\n", 1495 "Received `%s' for peer `%s' for client %p\n",
1501 "CHANGE PREFERENCE", 1496 "CHANGE PREFERENCE",
1502 GNUNET_i2s (peer), client); 1497 GNUNET_i2s (peer), client);
1503 1498
1504 if (GNUNET_NO == handle->running) 1499 if (GNUNET_NO == handle->running)
1505 return; 1500 return;
@@ -1571,7 +1566,10 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
1571 * @return number of networks loaded 1566 * @return number of networks loaded
1572 */ 1567 */
1573static unsigned int 1568static unsigned int
1574load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) 1569load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
1570 unsigned long long *out_dest,
1571 unsigned long long *in_dest,
1572 int dest_length)
1575{ 1573{
1576 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; 1574 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
1577 char * entry_in = NULL; 1575 char * entry_in = NULL;