diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-14 12:25:48 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-14 12:25:48 +0000 |
commit | 02219049255a8612969794f661f3cd576014dc9b (patch) | |
tree | a53b1937740360303b9715ce3551729d9da7cd15 /src/ats/gnunet-service-ats_addresses.c | |
parent | 8a1d955ccbf2ee62eef41802f3d4b0f71e022c9d (diff) | |
download | gnunet-02219049255a8612969794f661f3cd576014dc9b.tar.gz gnunet-02219049255a8612969794f661f3cd576014dc9b.zip |
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index e7da7dca3..8a79889f3 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -26,7 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet-service-ats_addresses.h" | 28 | #include "gnunet-service-ats_addresses.h" |
29 | 29 | #include "gnunet-service-ats_scheduling.h" | |
30 | 30 | ||
31 | struct ATS_Address | 31 | struct ATS_Address |
32 | { | 32 | { |
@@ -45,6 +45,10 @@ struct ATS_Address | |||
45 | char * plugin; | 45 | char * plugin; |
46 | 46 | ||
47 | struct GNUNET_TRANSPORT_ATS_Information * ats; | 47 | struct GNUNET_TRANSPORT_ATS_Information * ats; |
48 | |||
49 | struct GNUNET_BANDWIDTH_Value32NBO bw_in; | ||
50 | |||
51 | struct GNUNET_BANDWIDTH_Value32NBO bw_out; | ||
48 | }; | 52 | }; |
49 | 53 | ||
50 | 54 | ||
@@ -100,19 +104,27 @@ find_address (const struct GNUNET_PeerIdentity *peer, | |||
100 | static void | 104 | static void |
101 | merge_ats (struct ATS_Address * dest, struct ATS_Address * source) | 105 | merge_ats (struct ATS_Address * dest, struct ATS_Address * source) |
102 | { | 106 | { |
107 | /* | ||
103 | int c_src = 0; | 108 | int c_src = 0; |
104 | int c_dest = 0; | 109 | int c_dest = 0; |
105 | struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats; | 110 | struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats; |
106 | struct GNUNET_TRANSPORT_ATS_Information * a_dest = dest->ats; | 111 | struct GNUNET_TRANSPORT_ATS_Information * a_dest = dest->ats; |
107 | 112 | ||
113 | int new_entries = dest->ats_count; | ||
114 | |||
108 | for (c_dest = 0; c_dest < dest->ats_count; c_dest ++) | 115 | for (c_dest = 0; c_dest < dest->ats_count; c_dest ++) |
109 | { | 116 | { |
110 | for (c_src = 0; c_src < source->ats_count; c_src ++) | 117 | for (c_src = 0; c_src < source->ats_count; c_src ++) |
111 | { | 118 | { |
112 | if (a_src[c_src].type == a_dest[c_dest].type) | 119 | if (a_src[c_src].type == a_dest[c_dest].type) |
113 | a_src[c_src].value = a_dest[c_dest].value; | 120 | new_entries--; |
114 | } | 121 | } |
115 | } | 122 | } |
123 | |||
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
125 | "Have %u new entries\n", | ||
126 | new_entries); | ||
127 | */ | ||
116 | } | 128 | } |
117 | 129 | ||
118 | void | 130 | void |
@@ -128,14 +140,14 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer, | |||
128 | struct ATS_Address * old; | 140 | struct ATS_Address * old; |
129 | 141 | ||
130 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + | 142 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + |
131 | atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + | 143 | plugin_addr_len); |
132 | plugin_addr_len); | 144 | aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
145 | |||
133 | aa->peer = *peer; | 146 | aa->peer = *peer; |
134 | aa->addr_len = plugin_addr_len; | 147 | aa->addr_len = plugin_addr_len; |
135 | aa->ats_count = atsi_count; | 148 | aa->ats_count = atsi_count; |
136 | aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1]; | 149 | memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
137 | memcpy (&aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 150 | aa->addr = &aa[1]; |
138 | aa->addr = &aa->ats[atsi_count]; | ||
139 | memcpy (&aa->addr, plugin_addr, plugin_addr_len); | 151 | memcpy (&aa->addr, plugin_addr, plugin_addr_len); |
140 | aa->plugin = GNUNET_strdup (plugin_name); | 152 | aa->plugin = GNUNET_strdup (plugin_name); |
141 | aa->session_client = session_client; | 153 | aa->session_client = session_client; |
@@ -150,15 +162,16 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer, | |||
150 | aa, | 162 | aa, |
151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 163 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
153 | "Added new address for peer `%s' \n", | 165 | "Added new address for peer `%s' %X\n", |
154 | GNUNET_i2s (peer)); | 166 | GNUNET_i2s (peer), aa); |
155 | } | 167 | } |
156 | else | 168 | else |
157 | { | 169 | { |
158 | merge_ats (old, aa); | 170 | merge_ats (old, aa); |
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Updated existing address for peer `%s' \n", | 172 | "Updated existing address for peer `%s' %X \n", |
161 | GNUNET_i2s (peer)); | 173 | GNUNET_i2s (peer), old); |
174 | GNUNET_free (aa->ats); | ||
162 | GNUNET_free (aa); | 175 | GNUNET_free (aa); |
163 | } | 176 | } |
164 | 177 | ||
@@ -192,6 +205,7 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer, | |||
192 | GNUNET_break (GNUNET_YES == | 205 | GNUNET_break (GNUNET_YES == |
193 | GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res)); | 206 | GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res)); |
194 | GNUNET_free (res->plugin); | 207 | GNUNET_free (res->plugin); |
208 | GNUNET_free_non_null (res->ats); | ||
195 | GNUNET_free (res); | 209 | GNUNET_free (res); |
196 | 210 | ||
197 | } | 211 | } |
@@ -200,8 +214,10 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer, | |||
200 | void | 214 | void |
201 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | 215 | GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) |
202 | { | 216 | { |
203 | 217 | struct ATS_Address * aa = NULL; | |
204 | 218 | aa = GNUNET_CONTAINER_multihashmap_get (addresses, &peer->hashPubKey); | |
219 | if (aa != NULL) | ||
220 | GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, aa->addr_len, aa->session_client, aa->session_id, aa->ats, aa->ats_count, aa->bw_out, aa->bw_in); | ||
205 | } | 221 | } |
206 | 222 | ||
207 | 223 | ||
@@ -228,7 +244,10 @@ free_address_it (void *cls, | |||
228 | const GNUNET_HashCode * key, | 244 | const GNUNET_HashCode * key, |
229 | void *value) | 245 | void *value) |
230 | { | 246 | { |
231 | struct ATS_Address * aa = cls; | 247 | struct ATS_Address * aa = value; |
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
249 | "Freeing address for peer `%s' %X\n", | ||
250 | GNUNET_i2s (&aa->peer), aa); | ||
232 | GNUNET_free (aa); | 251 | GNUNET_free (aa); |
233 | return GNUNET_OK; | 252 | return GNUNET_OK; |
234 | } | 253 | } |