diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 8a79889f3..213b43124 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -77,8 +77,11 @@ compare_address_it (void *cls, | |||
77 | 77 | ||
78 | if (0 == strcmp(aa->plugin, cac->search->plugin)) | 78 | if (0 == strcmp(aa->plugin, cac->search->plugin)) |
79 | { | 79 | { |
80 | if ((aa->addr_len == cac->search->addr_len) && | 80 | if (aa->addr_len != cac->search->addr_len) |
81 | (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len))) | 81 | return GNUNET_YES; |
82 | if (aa->addr_len == 0) | ||
83 | return GNUNET_YES; | ||
84 | if (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) | ||
82 | cac->result = aa; | 85 | cac->result = aa; |
83 | return GNUNET_NO; | 86 | return GNUNET_NO; |
84 | } | 87 | } |
@@ -104,13 +107,17 @@ find_address (const struct GNUNET_PeerIdentity *peer, | |||
104 | static void | 107 | static void |
105 | merge_ats (struct ATS_Address * dest, struct ATS_Address * source) | 108 | merge_ats (struct ATS_Address * dest, struct ATS_Address * source) |
106 | { | 109 | { |
107 | /* | ||
108 | int c_src = 0; | 110 | int c_src = 0; |
109 | int c_dest = 0; | 111 | int c_dest = 0; |
110 | struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats; | 112 | struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats; |
111 | struct GNUNET_TRANSPORT_ATS_Information * a_dest = dest->ats; | 113 | struct GNUNET_TRANSPORT_ATS_Information * a_dest = dest->ats; |
114 | struct ATS_Address * bigger = NULL; | ||
112 | 115 | ||
113 | int new_entries = dest->ats_count; | 116 | bigger = (dest->ats_count > source->ats_count) ? dest : source; |
117 | int new_entries = bigger->ats_count; | ||
118 | |||
119 | if (new_entries == 0) | ||
120 | return; | ||
114 | 121 | ||
115 | for (c_dest = 0; c_dest < dest->ats_count; c_dest ++) | 122 | for (c_dest = 0; c_dest < dest->ats_count; c_dest ++) |
116 | { | 123 | { |
@@ -122,9 +129,8 @@ merge_ats (struct ATS_Address * dest, struct ATS_Address * source) | |||
122 | } | 129 | } |
123 | 130 | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
125 | "Have %u new entries\n", | 132 | "Have %u entries to update and %u new entries\n",bigger->ats_count, |
126 | new_entries); | 133 | new_entries); |
127 | */ | ||
128 | } | 134 | } |
129 | 135 | ||
130 | void | 136 | void |
@@ -139,8 +145,7 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer, | |||
139 | struct ATS_Address * aa; | 145 | struct ATS_Address * aa; |
140 | struct ATS_Address * old; | 146 | struct ATS_Address * old; |
141 | 147 | ||
142 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + | 148 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); |
143 | plugin_addr_len); | ||
144 | aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 149 | aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
145 | 150 | ||
146 | aa->peer = *peer; | 151 | aa->peer = *peer; |
@@ -148,7 +153,7 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer, | |||
148 | aa->ats_count = atsi_count; | 153 | aa->ats_count = atsi_count; |
149 | memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 154 | memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
150 | aa->addr = &aa[1]; | 155 | aa->addr = &aa[1]; |
151 | memcpy (&aa->addr, plugin_addr, plugin_addr_len); | 156 | memcpy (aa->addr, plugin_addr, plugin_addr_len); |
152 | aa->plugin = GNUNET_strdup (plugin_name); | 157 | aa->plugin = GNUNET_strdup (plugin_name); |
153 | aa->session_client = session_client; | 158 | aa->session_client = session_client; |
154 | aa->session_id = session_id; | 159 | aa->session_id = session_id; |
@@ -172,6 +177,7 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer, | |||
172 | "Updated existing address for peer `%s' %X \n", | 177 | "Updated existing address for peer `%s' %X \n", |
173 | GNUNET_i2s (peer), old); | 178 | GNUNET_i2s (peer), old); |
174 | GNUNET_free (aa->ats); | 179 | GNUNET_free (aa->ats); |
180 | GNUNET_free (aa->plugin); | ||
175 | GNUNET_free (aa); | 181 | GNUNET_free (aa); |
176 | } | 182 | } |
177 | 183 | ||
@@ -201,9 +207,13 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer, | |||
201 | aa->session_id = session_id; | 207 | aa->session_id = session_id; |
202 | 208 | ||
203 | res = find_address (peer, aa); | 209 | res = find_address (peer, aa); |
210 | GNUNET_assert (res != 0); | ||
211 | |||
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
213 | "Deleting address for peer `%s'\n", | ||
214 | GNUNET_i2s (peer)); | ||
204 | 215 | ||
205 | GNUNET_break (GNUNET_YES == | 216 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res)); |
206 | GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res)); | ||
207 | GNUNET_free (res->plugin); | 217 | GNUNET_free (res->plugin); |
208 | GNUNET_free_non_null (res->ats); | 218 | GNUNET_free_non_null (res->ats); |
209 | GNUNET_free (res); | 219 | GNUNET_free (res); |
@@ -248,6 +258,8 @@ free_address_it (void *cls, | |||
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
249 | "Freeing address for peer `%s' %X\n", | 259 | "Freeing address for peer `%s' %X\n", |
250 | GNUNET_i2s (&aa->peer), aa); | 260 | GNUNET_i2s (&aa->peer), aa); |
261 | GNUNET_free (aa->plugin); | ||
262 | GNUNET_free_non_null (aa->ats); | ||
251 | GNUNET_free (aa); | 263 | GNUNET_free (aa); |
252 | return GNUNET_OK; | 264 | return GNUNET_OK; |
253 | } | 265 | } |