diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-22 21:25:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-22 21:25:54 +0000 |
commit | 750da2796162b92c533f9666104c47407ed09e46 (patch) | |
tree | b1fe3ec2ca36854a15fd8e97760d05e9a54836b9 /src/ats/gnunet-service-ats_addresses.c | |
parent | 9c95f4ea09fa61fc193fc45873f76bf6fe6d93f3 (diff) | |
download | gnunet-750da2796162b92c533f9666104c47407ed09e46.tar.gz gnunet-750da2796162b92c533f9666104c47407ed09e46.zip |
simplifying IPC for address in use and address update
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 123 |
1 files changed, 60 insertions, 63 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index abdc40c59..ff7b2b024 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -468,9 +468,9 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
468 | static void | 468 | static void |
469 | free_address (struct ATS_Address *addr) | 469 | free_address (struct ATS_Address *addr) |
470 | { | 470 | { |
471 | GNUNET_free(addr->plugin); | 471 | GNUNET_free (addr->plugin); |
472 | GNUNET_free_non_null(addr->atsi); | 472 | GNUNET_free_non_null (addr->atsi); |
473 | GNUNET_free(addr); | 473 | GNUNET_free (addr); |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
@@ -642,44 +642,69 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, | |||
642 | 642 | ||
643 | 643 | ||
644 | /** | 644 | /** |
645 | * Closure for #find_address_cb() | ||
646 | */ | ||
647 | struct FindAddressContext | ||
648 | { | ||
649 | /** | ||
650 | * Session Id to look for. | ||
651 | */ | ||
652 | uint32_t session_id; | ||
653 | |||
654 | /** | ||
655 | * Where to store matching address result. | ||
656 | */ | ||
657 | struct ATS_Address *exact_address; | ||
658 | |||
659 | }; | ||
660 | |||
661 | |||
662 | /** | ||
663 | * Find session matching given session ID. | ||
664 | * | ||
665 | * @param cls a `struct FindAddressContext` | ||
666 | * @param key peer id | ||
667 | * @param value the address to compare with | ||
668 | * @return #GNUNET_YES to continue, #GNUNET_NO if address is found | ||
669 | */ | ||
670 | static int | ||
671 | find_address_cb (void *cls, | ||
672 | const struct GNUNET_PeerIdentity *key, | ||
673 | void *value) | ||
674 | { | ||
675 | struct FindAddressContext *fac = cls; | ||
676 | struct ATS_Address *aa = value; | ||
677 | |||
678 | if (aa->session_id == fac->session_id) | ||
679 | { | ||
680 | fac->exact_address = aa; | ||
681 | return GNUNET_NO; | ||
682 | } | ||
683 | return GNUNET_YES; | ||
684 | } | ||
685 | |||
686 | |||
687 | /** | ||
645 | * Find the exact address | 688 | * Find the exact address |
646 | * | 689 | * |
647 | * @param handle the address handle to use | 690 | * @param handle the address handle to use |
648 | * @param peer peer | 691 | * @param peer peer |
649 | * @param plugin_name transport plugin name | ||
650 | * @param plugin_addr plugin address | ||
651 | * @param plugin_addr_len length of the plugin address | ||
652 | * @param local_address_info the local address for the address | ||
653 | * @param session_id session id, can never be 0 | 692 | * @param session_id session id, can never be 0 |
654 | * @return an ATS_address or NULL | 693 | * @return an ATS_address or NULL |
655 | */ | 694 | */ |
656 | static struct ATS_Address * | 695 | static struct ATS_Address * |
657 | find_exact_address (struct GAS_Addresses_Handle *handle, | 696 | find_exact_address (struct GAS_Addresses_Handle *handle, |
658 | const struct GNUNET_PeerIdentity *peer, | 697 | const struct GNUNET_PeerIdentity *peer, |
659 | const char *plugin_name, | ||
660 | const void *plugin_addr, | ||
661 | size_t plugin_addr_len, | ||
662 | uint32_t local_address_info, | ||
663 | uint32_t session_id) | 698 | uint32_t session_id) |
664 | { | 699 | { |
665 | struct ATS_Address *aa; | 700 | struct FindAddressContext fac; |
666 | struct ATS_Address *ea; | ||
667 | 701 | ||
668 | aa = create_address (peer, | 702 | fac.exact_address = NULL; |
669 | plugin_name, | 703 | fac.session_id = session_id; |
670 | plugin_addr, | 704 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, |
671 | plugin_addr_len, | 705 | peer, |
672 | local_address_info, | 706 | &find_address_cb, &fac); |
673 | session_id); | 707 | return fac.exact_address; |
674 | |||
675 | /* Get existing address or address with session == 0 */ | ||
676 | ea = find_equivalent_address (handle, peer, aa); | ||
677 | free_address (aa); | ||
678 | if (ea == NULL) | ||
679 | return NULL; | ||
680 | else if (ea->session_id != session_id) | ||
681 | return NULL; | ||
682 | return ea; | ||
683 | } | 708 | } |
684 | 709 | ||
685 | 710 | ||
@@ -918,28 +943,17 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
918 | 943 | ||
919 | 944 | ||
920 | /** | 945 | /** |
921 | * Update an address with a session or performance information for a peer. | 946 | * Update an address with new performance information for a peer. |
922 | * | ||
923 | * If an address was added without a session it will be updated with the | ||
924 | * session | ||
925 | * | 947 | * |
926 | * @param handle the address handle to use | 948 | * @param handle the address handle to use |
927 | * @param peer peer | 949 | * @param peer peer |
928 | * @param plugin_name transport plugin name | 950 | * @param session_id session id, never 0 |
929 | * @param plugin_addr plugin address | ||
930 | * @param plugin_addr_len length of the plugin address | ||
931 | * @param local_address_info the local address for the address | ||
932 | * @param session_id session id, can be 0 | ||
933 | * @param atsi performance information for this address | 951 | * @param atsi performance information for this address |
934 | * @param atsi_count number of performance information contained in @a atsi | 952 | * @param atsi_count number of performance information contained in @a atsi |
935 | */ | 953 | */ |
936 | void | 954 | void |
937 | GAS_addresses_update (struct GAS_Addresses_Handle *handle, | 955 | GAS_addresses_update (struct GAS_Addresses_Handle *handle, |
938 | const struct GNUNET_PeerIdentity *peer, | 956 | const struct GNUNET_PeerIdentity *peer, |
939 | const char *plugin_name, | ||
940 | const void *plugin_addr, | ||
941 | size_t plugin_addr_len, | ||
942 | uint32_t local_address_info, | ||
943 | uint32_t session_id, | 957 | uint32_t session_id, |
944 | const struct GNUNET_ATS_Information *atsi, | 958 | const struct GNUNET_ATS_Information *atsi, |
945 | uint32_t atsi_count) | 959 | uint32_t atsi_count) |
@@ -955,11 +969,10 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
955 | GNUNET_assert (NULL != handle->addresses); | 969 | GNUNET_assert (NULL != handle->addresses); |
956 | 970 | ||
957 | /* Get existing address */ | 971 | /* Get existing address */ |
958 | aa = find_exact_address (handle, peer, plugin_name, plugin_addr, | 972 | aa = find_exact_address (handle, |
959 | plugin_addr_len, | 973 | peer, |
960 | local_address_info, | ||
961 | session_id); | 974 | session_id); |
962 | if (aa == NULL) | 975 | if (NULL == aa) |
963 | { | 976 | { |
964 | GNUNET_break (0); | 977 | GNUNET_break (0); |
965 | return; | 978 | return; |
@@ -1129,10 +1142,6 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1129 | /* Get existing address */ | 1142 | /* Get existing address */ |
1130 | ea = find_exact_address (handle, | 1143 | ea = find_exact_address (handle, |
1131 | peer, | 1144 | peer, |
1132 | plugin_name, | ||
1133 | plugin_addr, | ||
1134 | plugin_addr_len, | ||
1135 | local_address_info, | ||
1136 | session_id); | 1145 | session_id); |
1137 | if (NULL == ea) | 1146 | if (NULL == ea) |
1138 | { | 1147 | { |
@@ -1182,10 +1191,6 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1182 | * | 1191 | * |
1183 | * @param handle the address handle to use | 1192 | * @param handle the address handle to use |
1184 | * @param peer peer | 1193 | * @param peer peer |
1185 | * @param plugin_name transport plugin name | ||
1186 | * @param plugin_addr plugin address | ||
1187 | * @param plugin_addr_len length of the plugin address | ||
1188 | * @param local_address_info the local address for the address | ||
1189 | * @param session_id session id, can be 0 | 1194 | * @param session_id session id, can be 0 |
1190 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME | 1195 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME |
1191 | * @return #GNUNET_SYSERR on failure (address unknown ...) | 1196 | * @return #GNUNET_SYSERR on failure (address unknown ...) |
@@ -1193,10 +1198,6 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1193 | int | 1198 | int |
1194 | GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | 1199 | GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, |
1195 | const struct GNUNET_PeerIdentity *peer, | 1200 | const struct GNUNET_PeerIdentity *peer, |
1196 | const char *plugin_name, | ||
1197 | const void *plugin_addr, | ||
1198 | size_t plugin_addr_len, | ||
1199 | uint32_t local_address_info, | ||
1200 | uint32_t session_id, | 1201 | uint32_t session_id, |
1201 | int in_use) | 1202 | int in_use) |
1202 | { | 1203 | { |
@@ -1209,17 +1210,13 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1209 | if (GNUNET_NO == handle->running) | 1210 | if (GNUNET_NO == handle->running) |
1210 | return GNUNET_SYSERR; | 1211 | return GNUNET_SYSERR; |
1211 | ea = find_exact_address (handle, | 1212 | ea = find_exact_address (handle, |
1212 | peer, plugin_name, | 1213 | peer, |
1213 | plugin_addr, | ||
1214 | plugin_addr_len, | ||
1215 | local_address_info, | ||
1216 | session_id); | 1214 | session_id); |
1217 | if (NULL == ea) | 1215 | if (NULL == ea) |
1218 | { | 1216 | { |
1219 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1217 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1220 | "Trying to set unknown address `%s' `%s' `%u' to %s \n", | 1218 | "Trying to set unknown address `%s' `%u' to %s \n", |
1221 | GNUNET_i2s (peer), | 1219 | GNUNET_i2s (peer), |
1222 | plugin_name, | ||
1223 | session_id, | 1220 | session_id, |
1224 | (GNUNET_NO == in_use) ? "NO" : "YES"); | 1221 | (GNUNET_NO == in_use) ? "NO" : "YES"); |
1225 | GNUNET_break (0); | 1222 | GNUNET_break (0); |