aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_addresses.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r--src/ats/gnunet-service-ats_addresses.c198
1 files changed, 66 insertions, 132 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index dfbef6eb2..2e662a661 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -370,43 +370,9 @@ struct GAS_Addresses_Handle
370 370
371 371
372/** 372/**
373 * Assemble ATS information from address 373 * Disassemble ATS information and update performance information in address
374 * 374 *
375 * @param aa source address 375 * Updates existing information and adds new information
376 * @param dest destination
377 * @return number of elements
378 */
379static unsigned int
380assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Information **dest)
381{
382 unsigned int ats_count = GNUNET_ATS_PropertyCount - 1;
383 struct GNUNET_ATS_Information *ats;
384
385 ats = GNUNET_malloc (ats_count * sizeof (struct GNUNET_ATS_Information));
386 (*dest) = ats;
387
388 ats[0].type = ntohl(GNUNET_ATS_UTILIZATION_UP);
389 ats[0].value = aa->atsp_utilization_out.value__;
390 ats[1].type = ntohl(GNUNET_ATS_UTILIZATION_DOWN);
391 ats[1].value = aa->atsp_utilization_in.value__;
392 ats[2].type = ntohl(GNUNET_ATS_NETWORK_TYPE);
393 ats[2].value = ntohl(aa->atsp_network_type);
394 ats[3].type = ntohl(GNUNET_ATS_QUALITY_NET_DELAY);
395 ats[3].value = ntohl(aa->atsp_latency.rel_value);
396 ats[4].type = ntohl(GNUNET_ATS_QUALITY_NET_DISTANCE);
397 ats[4].value = ntohl(aa->atsp_distance);
398 ats[5].type = ntohl(GNUNET_ATS_COST_WAN);
399 ats[5].value = ntohl (aa->atsp_cost_wan);
400 ats[6].type = ntohl(GNUNET_ATS_COST_LAN);
401 ats[6].value = ntohl (aa->atsp_cost_lan);
402 ats[7].type = ntohl(GNUNET_ATS_COST_WLAN);
403 ats[7].value = ntohl (aa->atsp_cost_wlan);
404 return ats_count;
405}
406
407
408/**
409 * Disassemble ATS information and update address
410 * 376 *
411 * @param src source ATS information 377 * @param src source ATS information
412 * @param ats_count number of ATS information 378 * @param ats_count number of ATS information
@@ -418,68 +384,60 @@ disassemble_ats_information (const struct GNUNET_ATS_Information *src,
418 uint32_t ats_count, 384 uint32_t ats_count,
419 struct ATS_Address *dest) 385 struct ATS_Address *dest)
420{ 386{
421 int i; 387
422 int change = GNUNET_NO; 388 int c1;
423 int res = 0; 389 int c2;
424 for (i = 0; i < ats_count; i++) 390 int found;
425 switch (ntohl (src[i].type)) 391 int change;
426 { 392
427 case GNUNET_ATS_UTILIZATION_UP: 393 struct GNUNET_ATS_Information add_atsi[ats_count];
428 if (dest->atsp_utilization_out.value__ != src[i].value) 394 struct GNUNET_ATS_Information *tmp_atsi;
429 change = GNUNET_YES; 395 uint32_t add_atsi_count;
430 dest->atsp_utilization_out.value__ = src[i].value; 396
431 res ++; 397 change = GNUNET_NO;
432 break; 398 add_atsi_count = 0;
433 case GNUNET_ATS_UTILIZATION_DOWN: 399
434 if (dest->atsp_utilization_in.value__ != src[i].value) 400 if (NULL == dest->atsi)
435 change = GNUNET_YES; 401 {
436 dest->atsp_utilization_in.value__ = src[i].value; 402 dest->atsi = GNUNET_malloc (ats_count * sizeof (struct GNUNET_ATS_Information));
437 res ++; 403 dest->atsi_count = ats_count;
438 break; 404 memcpy (dest->atsi, src, ats_count * sizeof (struct GNUNET_ATS_Information));
439 case GNUNET_ATS_QUALITY_NET_DELAY: 405 return GNUNET_YES;
440 if (dest->atsp_latency.rel_value != src[i].value) 406 }
441 change = GNUNET_YES; 407
442 dest->atsp_latency.rel_value = ntohl (src[i].value); 408 /* Update existing performance information */
443 res ++; 409 for (c1 = 0; c1 < ats_count; c1++)
444 break; 410 {
445 case GNUNET_ATS_QUALITY_NET_DISTANCE: 411 found = GNUNET_NO;
446 if (dest->atsp_distance!= src[i].value) 412 for (c2 = 0; c2 < dest->atsi_count; c2++)
447 change = GNUNET_YES; 413 {
448 dest->atsp_distance = ntohl (src[i].value); 414 if (src[c1].type == dest->atsi[c2].type)
449 res ++; 415 {
450 break; 416 if (src[c1].value != dest->atsi[c2].value)
451 case GNUNET_ATS_COST_WAN: 417 {
452 if (dest->atsp_cost_wan != src[i].value) 418 dest->atsi[c2].value = src[c1].value;
453 change = GNUNET_YES; 419 change = GNUNET_YES;
454 dest->atsp_cost_wan = ntohl (src[i].value); 420 }
455 res ++; 421 found = GNUNET_YES;
456 break; 422 break;
457 case GNUNET_ATS_COST_LAN: 423 }
458 if (dest->atsp_cost_lan != src[i].value) 424 }
459 change = GNUNET_YES; 425 if (GNUNET_NO == found)
460 dest->atsp_cost_lan = ntohl (src[i].value); 426 {
461 res ++; 427 add_atsi[add_atsi_count] = src[c1];
462 break; 428 add_atsi_count ++;
463 case GNUNET_ATS_COST_WLAN: 429 }
464 if (dest->atsp_cost_wlan != src[i].value) 430 }
465 change = GNUNET_YES; 431
466 dest->atsp_cost_wlan = ntohl (src[i].value); 432 if (add_atsi_count > 0)
467 res ++; 433 {
468 break; 434 tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) *
469 case GNUNET_ATS_NETWORK_TYPE: 435 sizeof (sizeof (struct GNUNET_ATS_Information)));
470 if (dest->atsp_network_type != src[i].value) 436 memcpy (tmp_atsi, dest->atsi, dest->atsi_count * sizeof (struct GNUNET_ATS_Information));
471 change = GNUNET_YES; 437 memcpy (&tmp_atsi[dest->atsi_count], add_atsi, add_atsi_count * sizeof (struct GNUNET_ATS_Information));
472 dest->atsp_network_type = ntohl (src[i].value); 438 change = GNUNET_YES;
473 res ++; 439 }
474 break; 440
475 case GNUNET_ATS_ARRAY_TERMINATOR:
476 break;
477 default:
478 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
479 "Received unsupported ATS type %u\n", ntohl (src[i].type));
480 GNUNET_break (0);
481 break;
482 }
483 return change; 441 return change;
484} 442}
485 443
@@ -492,6 +450,7 @@ static void
492free_address (struct ATS_Address *addr) 450free_address (struct ATS_Address *addr)
493{ 451{
494 GNUNET_free (addr->plugin); 452 GNUNET_free (addr->plugin);
453 GNUNET_free_non_null (addr->atsi);
495 GNUNET_free (addr); 454 GNUNET_free (addr);
496} 455}
497 456
@@ -523,6 +482,8 @@ create_address (const struct GNUNET_PeerIdentity *peer,
523 aa->active = GNUNET_NO; 482 aa->active = GNUNET_NO;
524 aa->used = GNUNET_NO; 483 aa->used = GNUNET_NO;
525 aa->solver_information = NULL; 484 aa->solver_information = NULL;
485 aa->atsi = NULL;
486 aa->atsi_count = 0;
526 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0); 487 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
527 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0); 488 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
528 return aa; 489 return aa;
@@ -736,8 +697,6 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
736{ 697{
737 struct ATS_Address *aa; 698 struct ATS_Address *aa;
738 struct ATS_Address *ea; 699 struct ATS_Address *ea;
739 struct GNUNET_ATS_Information *ats_new;
740 uint32_t ats_count_new;
741 unsigned int ats_res; 700 unsigned int ats_res;
742 701
743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -774,15 +733,13 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
774 /* Tell solver about new address */ 733 /* Tell solver about new address */
775 handle->s_add (handle->solver, handle->addresses, aa); 734 handle->s_add (handle->solver, handle->addresses, aa);
776 /* Notify performance clients about new address */ 735 /* Notify performance clients about new address */
777 ats_count_new = assemble_ats_information (aa, &ats_new);
778 GAS_performance_notify_all_clients (&aa->peer, 736 GAS_performance_notify_all_clients (&aa->peer,
779 aa->plugin, 737 aa->plugin,
780 aa->addr, aa->addr_len, 738 aa->addr, aa->addr_len,
781 aa->session_id, 739 aa->session_id,
782 ats_new, ats_count_new, 740 aa->atsi, aa->atsi_count,
783 aa->assigned_bw_out, 741 aa->assigned_bw_out,
784 aa->assigned_bw_in); 742 aa->assigned_bw_in);
785 GNUNET_free (ats_new);
786 return; 743 return;
787 } 744 }
788 GNUNET_free (aa->plugin); 745 GNUNET_free (aa->plugin);
@@ -808,15 +765,13 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
808 ea->session_id = session_id; 765 ea->session_id = session_id;
809 if (GNUNET_YES == disassemble_ats_information(atsi, atsi_count, ea)) 766 if (GNUNET_YES == disassemble_ats_information(atsi, atsi_count, ea))
810 { 767 {
811 ats_count_new = assemble_ats_information (aa, &ats_new);
812 GAS_performance_notify_all_clients (&aa->peer, 768 GAS_performance_notify_all_clients (&aa->peer,
813 aa->plugin, 769 aa->plugin,
814 aa->addr, aa->addr_len, 770 aa->addr, aa->addr_len,
815 aa->session_id, 771 aa->session_id,
816 ats_new, ats_count_new, 772 aa->atsi, aa->atsi_count,
817 aa->assigned_bw_out, 773 aa->assigned_bw_out,
818 aa->assigned_bw_in); 774 aa->assigned_bw_in);
819 GNUNET_free (ats_new);
820 } 775 }
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
822 "Updated existing address for peer `%s' %p with new session %u\n", 777 "Updated existing address for peer `%s' %p with new session %u\n",
@@ -848,8 +803,6 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
848 uint32_t atsi_count) 803 uint32_t atsi_count)
849{ 804{
850 struct ATS_Address *aa; 805 struct ATS_Address *aa;
851 struct GNUNET_ATS_Information *ats_new;
852 uint32_t ats_count_new;
853 806
854 if (GNUNET_NO == handle->running) 807 if (GNUNET_NO == handle->running)
855 return; 808 return;
@@ -878,16 +831,14 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
878 /* Update address */ 831 /* Update address */
879 if (GNUNET_YES == disassemble_ats_information (atsi, atsi_count, aa)) 832 if (GNUNET_YES == disassemble_ats_information (atsi, atsi_count, aa))
880 { 833 {
881 ats_count_new = assemble_ats_information (aa, &ats_new);
882 /* Notify performance clients about updated address */ 834 /* Notify performance clients about updated address */
883 GAS_performance_notify_all_clients (&aa->peer, 835 GAS_performance_notify_all_clients (&aa->peer,
884 aa->plugin, 836 aa->plugin,
885 aa->addr, aa->addr_len, 837 aa->addr, aa->addr_len,
886 aa->session_id, 838 aa->session_id,
887 ats_new, ats_count_new, 839 aa->atsi, aa->atsi_count,
888 aa->assigned_bw_out, 840 aa->assigned_bw_out,
889 aa->assigned_bw_in); 841 aa->assigned_bw_in);
890 GNUNET_free (ats_new);
891 } 842 }
892} 843}
893 844
@@ -1163,8 +1114,6 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
1163{ 1114{
1164 struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head; 1115 struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head;
1165 struct ATS_Address *aa; 1116 struct ATS_Address *aa;
1166 struct GNUNET_ATS_Information *ats;
1167 unsigned int ats_count;
1168 1117
1169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1170 "Received `%s' for peer `%s'\n", 1119 "Received `%s' for peer `%s'\n",
@@ -1198,12 +1147,11 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
1198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1199 "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s (peer)); 1148 "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s (peer));
1200 1149
1201 ats_count = assemble_ats_information (aa, &ats);
1202 GAS_scheduling_transmit_address_suggestion (peer, 1150 GAS_scheduling_transmit_address_suggestion (peer,
1203 aa->plugin, 1151 aa->plugin,
1204 aa->addr, aa->addr_len, 1152 aa->addr, aa->addr_len,
1205 aa->session_id, 1153 aa->session_id,
1206 ats, ats_count, 1154 aa->atsi, aa->atsi_count,
1207 aa->assigned_bw_out, 1155 aa->assigned_bw_out,
1208 aa->assigned_bw_in); 1156 aa->assigned_bw_in);
1209 1157
@@ -1213,8 +1161,6 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
1213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1214 "Address %p ready for suggestion, block interval now %llu \n", 1162 "Address %p ready for suggestion, block interval now %llu \n",
1215 aa, aa->block_interval); 1163 aa, aa->block_interval);
1216
1217 GNUNET_free (ats);
1218} 1164}
1219 1165
1220 1166
@@ -1418,23 +1364,18 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1418{ 1364{
1419 struct GAS_Addresses_Handle *handle = cls; 1365 struct GAS_Addresses_Handle *handle = cls;
1420 struct GAS_Addresses_Suggestion_Requests *cur; 1366 struct GAS_Addresses_Suggestion_Requests *cur;
1421 struct GNUNET_ATS_Information *ats;
1422 unsigned int ats_count;
1423 1367
1424 GNUNET_assert (handle != NULL); 1368 GNUNET_assert (handle != NULL);
1425 GNUNET_assert (address != NULL); 1369 GNUNET_assert (address != NULL);
1426 1370
1427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bandwidth assignment changed for peer %s \n", GNUNET_i2s(&address->peer)); 1371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bandwidth assignment changed for peer %s \n", GNUNET_i2s(&address->peer));
1428 1372
1429
1430 ats_count = assemble_ats_information (address, &ats);
1431
1432 /* Notify performance clients about changes to address */ 1373 /* Notify performance clients about changes to address */
1433 GAS_performance_notify_all_clients (&address->peer, 1374 GAS_performance_notify_all_clients (&address->peer,
1434 address->plugin, 1375 address->plugin,
1435 address->addr, address->addr_len, 1376 address->addr, address->addr_len,
1436 address->session_id, 1377 address->session_id,
1437 ats, ats_count, 1378 address->atsi, address->atsi_count,
1438 address->assigned_bw_out, 1379 address->assigned_bw_out,
1439 address->assigned_bw_in); 1380 address->assigned_bw_in);
1440 cur = handle->r_head; 1381 cur = handle->r_head;
@@ -1448,7 +1389,6 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1448 { 1389 {
1449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1450 "Nobody is interested in peer `%s' :(\n",GNUNET_i2s (&address->peer)); 1391 "Nobody is interested in peer `%s' :(\n",GNUNET_i2s (&address->peer));
1451 GNUNET_free (ats);
1452 return; 1392 return;
1453 } 1393 }
1454 1394
@@ -1460,10 +1400,9 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1460 address->plugin, 1400 address->plugin,
1461 address->addr, address->addr_len, 1401 address->addr, address->addr_len,
1462 address->session_id, 1402 address->session_id,
1463 ats, ats_count, 1403 address->atsi, address->atsi_count,
1464 address->assigned_bw_out, 1404 address->assigned_bw_out,
1465 address->assigned_bw_in); 1405 address->assigned_bw_in);
1466 GNUNET_free (ats);
1467} 1406}
1468 1407
1469 1408
@@ -1746,22 +1685,17 @@ peerinfo_it (void *cls,
1746{ 1685{
1747 struct PeerInfoIteratorContext *pi_ctx = cls; 1686 struct PeerInfoIteratorContext *pi_ctx = cls;
1748 struct ATS_Address *addr = (struct ATS_Address *) value; 1687 struct ATS_Address *addr = (struct ATS_Address *) value;
1749 struct GNUNET_ATS_Information *ats;
1750 uint32_t ats_count;
1751 1688
1752 if (NULL != pi_ctx->it) 1689 if (NULL != pi_ctx->it)
1753 { 1690 {
1754 ats_count = assemble_ats_information (addr, &ats);
1755
1756 pi_ctx->it (pi_ctx->it_cls, 1691 pi_ctx->it (pi_ctx->it_cls,
1757 &addr->peer, 1692 &addr->peer,
1758 addr->plugin, 1693 addr->plugin,
1759 addr->addr, addr->addr_len, 1694 addr->addr, addr->addr_len,
1760 addr->active, 1695 addr->active,
1761 ats, ats_count, 1696 addr->atsi, addr->atsi_count,
1762 addr->assigned_bw_out, 1697 addr->assigned_bw_out,
1763 addr->assigned_bw_in); 1698 addr->assigned_bw_in);
1764 GNUNET_free (ats);
1765 } 1699 }
1766 return GNUNET_YES; 1700 return GNUNET_YES;
1767} 1701}