diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-03 10:56:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-03 10:56:21 +0000 |
commit | 533dfb8408d57317bad310fa24853bcb2d6fb3b6 (patch) | |
tree | 2335b0d84a2e6bc765ca06388c1defc440b3ed7b /src/ats | |
parent | dd4f096c7566128770b4902b620ba8818d48e138 (diff) | |
download | gnunet-533dfb8408d57317bad310fa24853bcb2d6fb3b6.tar.gz gnunet-533dfb8408d57317bad310fa24853bcb2d6fb3b6.zip |
delta support for disassemble
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 88 |
1 files changed, 65 insertions, 23 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 587147ec9..ce4346e55 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -376,13 +376,18 @@ struct GAS_Addresses_Handle | |||
376 | * | 376 | * |
377 | * @param src source ATS information | 377 | * @param src source ATS information |
378 | * @param ats_count number of ATS information | 378 | * @param ats_count number of ATS information |
379 | * @param delta ats performance information which were updated | ||
380 | * including previous value | ||
381 | * @param delta_count number of ATS information in the delta | ||
379 | * @param dest destination address | 382 | * @param dest destination address |
380 | * @return GNUNET_YES if address was address updated, GNUNET_NO otherwise | 383 | * @return GNUNET_YES if address was address updated, GNUNET_NO otherwise |
381 | */ | 384 | */ |
382 | static unsigned int | 385 | static unsigned int |
383 | disassemble_ats_information (const struct GNUNET_ATS_Information *src, | 386 | disassemble_ats_information (struct ATS_Address *dest, |
384 | uint32_t ats_count, | 387 | const struct GNUNET_ATS_Information *update, |
385 | struct ATS_Address *dest) | 388 | uint32_t update_count, |
389 | struct GNUNET_ATS_Information **delta_dest, | ||
390 | uint32_t *delta_count) | ||
386 | { | 391 | { |
387 | 392 | ||
388 | int c1; | 393 | int c1; |
@@ -390,36 +395,51 @@ disassemble_ats_information (const struct GNUNET_ATS_Information *src, | |||
390 | int found; | 395 | int found; |
391 | int change; | 396 | int change; |
392 | 397 | ||
393 | struct GNUNET_ATS_Information add_atsi[ats_count]; | 398 | struct GNUNET_ATS_Information add_atsi[update_count]; |
399 | struct GNUNET_ATS_Information delta_atsi[update_count]; | ||
394 | struct GNUNET_ATS_Information *tmp_atsi; | 400 | struct GNUNET_ATS_Information *tmp_atsi; |
395 | uint32_t add_atsi_count; | 401 | uint32_t add_atsi_count; |
402 | uint32_t delta_atsi_count; | ||
396 | 403 | ||
397 | change = GNUNET_NO; | 404 | change = GNUNET_NO; |
398 | add_atsi_count = 0; | 405 | add_atsi_count = 0; |
406 | delta_atsi_count = 0; | ||
399 | 407 | ||
400 | if (0 == ats_count) | 408 | if (0 == update_count) |
401 | return GNUNET_NO; | 409 | return GNUNET_NO; |
402 | 410 | ||
403 | if (NULL == dest->atsi) | 411 | if (NULL == dest->atsi) |
404 | { | 412 | { |
405 | /* Create performance information */ | 413 | /* Create performance information */ |
406 | dest->atsi = GNUNET_malloc (ats_count * sizeof (struct GNUNET_ATS_Information)); | 414 | dest->atsi = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); |
407 | dest->atsi_count = ats_count; | 415 | dest->atsi_count = update_count; |
408 | memcpy (dest->atsi, src, ats_count * sizeof (struct GNUNET_ATS_Information)); | 416 | memcpy (dest->atsi, update, update_count * sizeof (struct GNUNET_ATS_Information)); |
417 | delta_atsi_count = update_count; | ||
418 | (*delta_dest) = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | ||
419 | for (c1 = 0; c1 < update_count; c1 ++) | ||
420 | { | ||
421 | (*delta_dest)[c1].type = update[c1].type; | ||
422 | (*delta_dest)[c1].value = htonl(UINT32_MAX); | ||
423 | } | ||
424 | (*delta_count) = update_count; | ||
409 | return GNUNET_YES; | 425 | return GNUNET_YES; |
410 | } | 426 | } |
411 | 427 | ||
412 | for (c1 = 0; c1 < ats_count; c1++) | 428 | for (c1 = 0; c1 < update_count; c1++) |
413 | { | 429 | { |
414 | /* Update existing performance information */ | 430 | /* Update existing performance information */ |
415 | found = GNUNET_NO; | 431 | found = GNUNET_NO; |
416 | for (c2 = 0; c2 < dest->atsi_count; c2++) | 432 | for (c2 = 0; c2 < dest->atsi_count; c2++) |
417 | { | 433 | { |
418 | if (src[c1].type == dest->atsi[c2].type) | 434 | if (update[c1].type == dest->atsi[c2].type) |
419 | { | 435 | { |
420 | if (src[c1].value != dest->atsi[c2].value) | 436 | if (update[c1].value != dest->atsi[c2].value) |
421 | { | 437 | { |
422 | dest->atsi[c2].value = src[c1].value; | 438 | /* Save previous value in delta */ |
439 | delta_atsi[delta_atsi_count] = dest->atsi[c2]; | ||
440 | delta_atsi_count ++; | ||
441 | /* Set new value */ | ||
442 | dest->atsi[c2].value = update[c1].value; | ||
423 | change = GNUNET_YES; | 443 | change = GNUNET_YES; |
424 | } | 444 | } |
425 | found = GNUNET_YES; | 445 | found = GNUNET_YES; |
@@ -428,8 +448,11 @@ disassemble_ats_information (const struct GNUNET_ATS_Information *src, | |||
428 | } | 448 | } |
429 | if (GNUNET_NO == found) | 449 | if (GNUNET_NO == found) |
430 | { | 450 | { |
431 | add_atsi[add_atsi_count] = src[c1]; | 451 | add_atsi[add_atsi_count] = update[c1]; |
432 | add_atsi_count ++; | 452 | add_atsi_count ++; |
453 | delta_atsi[delta_atsi_count].type = update[c1].type; | ||
454 | delta_atsi[delta_atsi_count].type = htonl (UINT32_MAX); | ||
455 | delta_atsi_count ++; | ||
433 | } | 456 | } |
434 | } | 457 | } |
435 | 458 | ||
@@ -446,6 +469,14 @@ disassemble_ats_information (const struct GNUNET_ATS_Information *src, | |||
446 | change = GNUNET_YES; | 469 | change = GNUNET_YES; |
447 | } | 470 | } |
448 | 471 | ||
472 | if (delta_atsi_count > 0) | ||
473 | { | ||
474 | /* Copy delta */ | ||
475 | (*delta_dest) = GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
476 | memcpy ((*delta_dest), delta_atsi, delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
477 | (*delta_count) = delta_atsi_count; | ||
478 | } | ||
479 | |||
449 | return change; | 480 | return change; |
450 | } | 481 | } |
451 | 482 | ||
@@ -728,8 +759,11 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
728 | { | 759 | { |
729 | struct ATS_Address *aa; | 760 | struct ATS_Address *aa; |
730 | struct ATS_Address *ea; | 761 | struct ATS_Address *ea; |
762 | struct GNUNET_ATS_Information *atsi_delta; | ||
763 | uint32_t atsi_delta_count; | ||
731 | uint32_t addr_net; | 764 | uint32_t addr_net; |
732 | 765 | ||
766 | |||
733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 767 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
734 | "Received `%s' for peer `%s'\n", | 768 | "Received `%s' for peer `%s'\n", |
735 | "ADDRESS ADD", | 769 | "ADDRESS ADD", |
@@ -742,8 +776,9 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
742 | 776 | ||
743 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, | 777 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, |
744 | session_id); | 778 | session_id); |
745 | disassemble_ats_information (atsi, atsi_count, aa); | 779 | atsi_delta = NULL; |
746 | 780 | disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count); | |
781 | GNUNET_free_non_null (atsi_delta); | ||
747 | /* Get existing address or address with session == 0 */ | 782 | /* Get existing address or address with session == 0 */ |
748 | ea = find_equivalent_address (handle, peer, aa); | 783 | ea = find_equivalent_address (handle, peer, aa); |
749 | if (ea == NULL) | 784 | if (ea == NULL) |
@@ -787,13 +822,9 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
787 | } | 822 | } |
788 | 823 | ||
789 | /* We have an address without an session, update this address */ | 824 | /* We have an address without an session, update this address */ |
790 | 825 | atsi_delta = NULL; | |
791 | /* Notify solver about update with atsi information and session */ | 826 | atsi_delta_count = 0; |
792 | handle->s_update (handle->solver, handle->addresses, ea, session_id, ea->used, atsi, atsi_count); | 827 | if (GNUNET_YES == disassemble_ats_information (ea, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) |
793 | |||
794 | /* Do the update */ | ||
795 | ea->session_id = session_id; | ||
796 | if (GNUNET_YES == disassemble_ats_information (atsi, atsi_count, ea)) | ||
797 | { | 828 | { |
798 | GAS_performance_notify_all_clients (&aa->peer, | 829 | GAS_performance_notify_all_clients (&aa->peer, |
799 | aa->plugin, | 830 | aa->plugin, |
@@ -803,6 +834,13 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
803 | aa->assigned_bw_out, | 834 | aa->assigned_bw_out, |
804 | aa->assigned_bw_in); | 835 | aa->assigned_bw_in); |
805 | } | 836 | } |
837 | |||
838 | /* Notify solver about update with atsi information and session */ | ||
839 | handle->s_update (handle->solver, handle->addresses, ea, session_id, ea->used, atsi_delta, atsi_delta_count); | ||
840 | GNUNET_free_non_null (atsi_delta); | ||
841 | |||
842 | /* Do the update */ | ||
843 | ea->session_id = session_id; | ||
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
807 | "Updated existing address for peer `%s' %p with new session %u\n", | 845 | "Updated existing address for peer `%s' %p with new session %u\n", |
808 | GNUNET_i2s (peer), ea, session_id); | 846 | GNUNET_i2s (peer), ea, session_id); |
@@ -833,6 +871,8 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
833 | uint32_t atsi_count) | 871 | uint32_t atsi_count) |
834 | { | 872 | { |
835 | struct ATS_Address *aa; | 873 | struct ATS_Address *aa; |
874 | struct GNUNET_ATS_Information *atsi_delta; | ||
875 | uint32_t atsi_delta_count; | ||
836 | 876 | ||
837 | if (GNUNET_NO == handle->running) | 877 | if (GNUNET_NO == handle->running) |
838 | return; | 878 | return; |
@@ -859,7 +899,8 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
859 | handle->s_update (handle->solver, handle->addresses, aa, session_id, aa->used, atsi, atsi_count); | 899 | handle->s_update (handle->solver, handle->addresses, aa, session_id, aa->used, atsi, atsi_count); |
860 | 900 | ||
861 | /* Update address */ | 901 | /* Update address */ |
862 | if (GNUNET_YES == disassemble_ats_information (atsi, atsi_count, aa)) | 902 | atsi_delta = NULL; |
903 | if (GNUNET_YES == disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) | ||
863 | { | 904 | { |
864 | /* Notify performance clients about updated address */ | 905 | /* Notify performance clients about updated address */ |
865 | GAS_performance_notify_all_clients (&aa->peer, | 906 | GAS_performance_notify_all_clients (&aa->peer, |
@@ -870,6 +911,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
870 | aa->assigned_bw_out, | 911 | aa->assigned_bw_out, |
871 | aa->assigned_bw_in); | 912 | aa->assigned_bw_in); |
872 | } | 913 | } |
914 | GNUNET_free_non_null (atsi_delta); | ||
873 | } | 915 | } |
874 | 916 | ||
875 | 917 | ||