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 | |
parent | 8a1d955ccbf2ee62eef41802f3d4b0f71e022c9d (diff) | |
download | gnunet-02219049255a8612969794f661f3cd576014dc9b.tar.gz gnunet-02219049255a8612969794f661f3cd576014dc9b.zip |
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 47 | ||||
-rw-r--r-- | src/ats/test_ats_api.conf | 1 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling.c | 44 |
3 files changed, 73 insertions, 19 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 | } |
diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf index 8ee71a7e8..c2bb1942d 100644 --- a/src/ats/test_ats_api.conf +++ b/src/ats/test_ats_api.conf | |||
@@ -7,6 +7,7 @@ DEFAULTSERVICES = ats | |||
7 | UNIXPATH = /tmp/test-ats-scheduling-arm.sock | 7 | UNIXPATH = /tmp/test-ats-scheduling-arm.sock |
8 | 8 | ||
9 | [ats] | 9 | [ats] |
10 | DEBUG = YES | ||
10 | AUTOSTART = YES | 11 | AUTOSTART = YES |
11 | PORT = 12002 | 12 | PORT = 12002 |
12 | HOSTNAME = localhost | 13 | HOSTNAME = localhost |
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c index 68026e196..4ed68ba87 100644 --- a/src/ats/test_ats_api_scheduling.c +++ b/src/ats/test_ats_api_scheduling.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include "gnunet_ats_service.h" | 34 | #include "gnunet_ats_service.h" |
35 | #include "ats.h" | 35 | #include "ats.h" |
36 | 36 | ||
37 | #define VERBOSE GNUNET_EXTRA_LOGGING | 37 | #define VERBOSE GNUNET_YES |
38 | 38 | ||
39 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING | 39 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING |
40 | 40 | ||
@@ -46,6 +46,10 @@ static struct GNUNET_ATS_SchedulingHandle *ats; | |||
46 | 46 | ||
47 | struct GNUNET_OS_Process * arm_proc; | 47 | struct GNUNET_OS_Process * arm_proc; |
48 | 48 | ||
49 | struct Address addr; | ||
50 | struct PeerContext p; | ||
51 | struct GNUNET_TRANSPORT_ATS_Information atsi[2]; | ||
52 | |||
49 | static int ret; | 53 | static int ret; |
50 | 54 | ||
51 | struct Address | 55 | struct Address |
@@ -97,6 +101,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
97 | static void | 101 | static void |
98 | end () | 102 | end () |
99 | { | 103 | { |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
100 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 105 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
101 | { | 106 | { |
102 | GNUNET_SCHEDULER_cancel(die_task); | 107 | GNUNET_SCHEDULER_cancel(die_task); |
@@ -132,9 +137,26 @@ address_suggest_cb (void *cls, | |||
132 | uint32_t ats_count) | 137 | uint32_t ats_count) |
133 | 138 | ||
134 | { | 139 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "address_suggest_cb `%s'\n", GNUNET_i2s (peer)); | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer)); |
141 | |||
142 | GNUNET_assert (0 == memcmp (peer, &p.id, sizeof (struct GNUNET_PeerIdentity))); | ||
143 | GNUNET_assert (0 == strcmp (plugin_name, addr.plugin)); | ||
144 | GNUNET_assert (plugin_addr_len == addr.addr_len); | ||
145 | GNUNET_assert (0 == memcmp (plugin_addr, addr.plugin, plugin_addr_len)); | ||
146 | GNUNET_assert (addr.session == session); | ||
147 | |||
148 | |||
149 | /* TODO ats merge | ||
150 | GNUNET_assert (ats_count == 2); | ||
151 | GNUNET_assert (atsi[0].type == htons (1)); | ||
152 | GNUNET_assert (atsi[0].type == htons (2)); | ||
153 | GNUNET_assert (atsi[1].type == htons (2)); | ||
154 | GNUNET_assert (atsi[1].type == htons (2)); | ||
155 | */ | ||
156 | |||
157 | ret = 0; | ||
136 | 158 | ||
137 | end (); | 159 | GNUNET_SCHEDULER_add_now(&end, NULL); |
138 | } | 160 | } |
139 | 161 | ||
140 | void | 162 | void |
@@ -153,8 +175,6 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
153 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 175 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
154 | { | 176 | { |
155 | ret = GNUNET_SYSERR; | 177 | ret = GNUNET_SYSERR; |
156 | struct Address addr; | ||
157 | struct PeerContext p; | ||
158 | 178 | ||
159 | die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); | 179 | die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); |
160 | start_arm (cfgfile); | 180 | start_arm (cfgfile); |
@@ -181,6 +201,20 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
181 | 201 | ||
182 | GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0); | 202 | GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0); |
183 | 203 | ||
204 | atsi[0].type = htons (1); | ||
205 | atsi[0].type = htons (1); | ||
206 | |||
207 | GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 1); | ||
208 | |||
209 | atsi[0].type = htons (1); | ||
210 | atsi[0].type = htons (2); | ||
211 | |||
212 | atsi[1].type = htons (2); | ||
213 | atsi[1].type = htons (2); | ||
214 | |||
215 | GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 2); | ||
216 | |||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p.id)); | ||
184 | GNUNET_ATS_suggest_address(ats, &p.id); | 218 | GNUNET_ATS_suggest_address(ats, &p.id); |
185 | } | 219 | } |
186 | 220 | ||