diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-06 10:02:38 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-12-06 10:02:38 +0000 |
commit | c3bf7a364a9dac82d17631f2f2fd71353df5bb2e (patch) | |
tree | 3320f4ccafcaf43b0e7eb17f91c69afa178c03b4 /src | |
parent | 99af92822080987875a34372e00c09a68d937659 (diff) | |
download | gnunet-c3bf7a364a9dac82d17631f2f2fd71353df5bb2e.tar.gz gnunet-c3bf7a364a9dac82d17631f2f2fd71353df5bb2e.zip |
changes
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 2 | ||||
-rw-r--r-- | src/ats/test_ats_api_common.h | 2 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_session.c | 241 |
3 files changed, 174 insertions, 71 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 45af6a1e5..d92f600bb 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -742,7 +742,7 @@ GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer) | |||
742 | "No address requests pending for peer `%s', cannot remove!\n", GNUNET_i2s (peer)); | 742 | "No address requests pending for peer `%s', cannot remove!\n", GNUNET_i2s (peer)); |
743 | return; | 743 | return; |
744 | } | 744 | } |
745 | 745 | GAS_addresses_handle_backoff_reset (peer); | |
746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
747 | "Removed request pending for peer `%s\n", GNUNET_i2s (peer)); | 747 | "Removed request pending for peer `%s\n", GNUNET_i2s (peer)); |
748 | GNUNET_CONTAINER_DLL_remove (handle->r_head, handle->r_tail, cur); | 748 | GNUNET_CONTAINER_DLL_remove (handle->r_head, handle->r_tail, cur); |
diff --git a/src/ats/test_ats_api_common.h b/src/ats/test_ats_api_common.h index 591b692b0..f7e787fca 100644 --- a/src/ats/test_ats_api_common.h +++ b/src/ats/test_ats_api_common.h | |||
@@ -24,7 +24,7 @@ | |||
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 27 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
28 | 28 | ||
29 | #define PEERID "2AK99KD8RM9UA9LC3QKA0IQ5UBFC0FBB50EBGCFQT8448DGGACNAC4CJQDD1CPFS494O41U88DJD1FLIG8VA5CQR9IN4L96GP104MVO" | 29 | #define PEERID "2AK99KD8RM9UA9LC3QKA0IQ5UBFC0FBB50EBGCFQT8448DGGACNAC4CJQDD1CPFS494O41U88DJD1FLIG8VA5CQR9IN4L96GP104MVO" |
30 | 30 | ||
diff --git a/src/ats/test_ats_api_scheduling_destroy_session.c b/src/ats/test_ats_api_scheduling_destroy_session.c index a776a87c4..17583bd20 100644 --- a/src/ats/test_ats_api_scheduling_destroy_session.c +++ b/src/ats/test_ats_api_scheduling_destroy_session.c | |||
@@ -19,8 +19,10 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_api_scheduling_destroy_session.c | 21 | * @file ats/test_ats_api_scheduling_destroy_session.c |
22 | * @brief test destroying sessions with unknown address (address NULL, length 0) | 22 | * @brief test destroying sessions: first add an address with a session, |
23 | * in automatic transport selection scheduling API | 23 | * request the address and compare, delete the session, request and |
24 | * compare again, delete whole address, request and wait for timeout, | ||
25 | * shutdown | ||
24 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
25 | * @author Matthias Wachs | 27 | * @author Matthias Wachs |
26 | * | 28 | * |
@@ -31,25 +33,47 @@ | |||
31 | #include "ats.h" | 33 | #include "ats.h" |
32 | #include "test_ats_api_common.h" | 34 | #include "test_ats_api_common.h" |
33 | 35 | ||
34 | |||
35 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 36 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
36 | 37 | ||
37 | static struct GNUNET_ATS_SchedulingHandle *ats; | 38 | static GNUNET_SCHEDULER_TaskIdentifier wait_task; |
38 | 39 | ||
39 | static int ret; | 40 | #define WAIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
41 | |||
42 | |||
43 | /** | ||
44 | * Scheduling handle | ||
45 | */ | ||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
40 | 47 | ||
41 | static int stage; | 48 | /** |
49 | * Return value | ||
50 | */ | ||
51 | static int ret; | ||
42 | 52 | ||
53 | /** | ||
54 | * Test address | ||
55 | */ | ||
43 | static struct Test_Address test_addr; | 56 | static struct Test_Address test_addr; |
44 | 57 | ||
58 | /** | ||
59 | * Test peer | ||
60 | */ | ||
45 | static struct PeerContext p; | 61 | static struct PeerContext p; |
46 | 62 | ||
47 | static struct GNUNET_HELLO_Address hello_address; | 63 | /** |
64 | * HELLO address | ||
65 | */ | ||
66 | struct GNUNET_HELLO_Address hello_address; | ||
48 | 67 | ||
68 | /** | ||
69 | * Session | ||
70 | */ | ||
71 | static void *test_session; | ||
49 | 72 | ||
50 | static void | 73 | static void |
51 | create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) | 74 | create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) |
52 | { | 75 | { |
76 | |||
53 | dest->plugin = GNUNET_strdup (plugin); | 77 | dest->plugin = GNUNET_strdup (plugin); |
54 | dest->session = session; | 78 | dest->session = session; |
55 | dest->addr = GNUNET_malloc (addrlen); | 79 | dest->addr = GNUNET_malloc (addrlen); |
@@ -64,12 +88,14 @@ free_test_address (struct Test_Address *dest) | |||
64 | GNUNET_free (dest->addr); | 88 | GNUNET_free (dest->addr); |
65 | } | 89 | } |
66 | 90 | ||
91 | |||
67 | static void | 92 | static void |
68 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
69 | { | 94 | { |
70 | die_task = GNUNET_SCHEDULER_NO_TASK; | 95 | die_task = GNUNET_SCHEDULER_NO_TASK; |
71 | if (ats != NULL) | 96 | |
72 | GNUNET_ATS_scheduling_done (ats); | 97 | if (sched_ats != NULL) |
98 | GNUNET_ATS_scheduling_done (sched_ats); | ||
73 | free_test_address (&test_addr); | 99 | free_test_address (&test_addr); |
74 | ret = GNUNET_SYSERR; | 100 | ret = GNUNET_SYSERR; |
75 | } | 101 | } |
@@ -79,23 +105,17 @@ static void | |||
79 | end () | 105 | end () |
80 | { | 106 | { |
81 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | 107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); |
108 | wait_task = GNUNET_SCHEDULER_NO_TASK; | ||
82 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 109 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
83 | { | 110 | { |
84 | GNUNET_SCHEDULER_cancel (die_task); | 111 | GNUNET_SCHEDULER_cancel (die_task); |
85 | die_task = GNUNET_SCHEDULER_NO_TASK; | 112 | die_task = GNUNET_SCHEDULER_NO_TASK; |
86 | } | 113 | } |
87 | GNUNET_ATS_scheduling_done (ats); | ||
88 | free_test_address (&test_addr); | 114 | free_test_address (&test_addr); |
89 | if (2 == stage) | 115 | GNUNET_ATS_scheduling_done (sched_ats); |
90 | ret = 0; | 116 | sched_ats = NULL; |
91 | else | ||
92 | { | ||
93 | GNUNET_break (0); | ||
94 | ret = 1; | ||
95 | } | ||
96 | } | 117 | } |
97 | 118 | ||
98 | |||
99 | static void | 119 | static void |
100 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | 120 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, |
101 | struct Session *session, | 121 | struct Session *session, |
@@ -104,47 +124,122 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
104 | const struct GNUNET_ATS_Information *atsi, | 124 | const struct GNUNET_ATS_Information *atsi, |
105 | uint32_t ats_count) | 125 | uint32_t ats_count) |
106 | { | 126 | { |
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage %u: ATS suggests address `%s' session %p\n", | 127 | static int stage = 0; |
108 | stage, GNUNET_i2s (&address->peer), session); | 128 | int res = 0; |
109 | GNUNET_ATS_reset_backoff(ats, &address->peer); | ||
110 | |||
111 | GNUNET_assert (0 == | ||
112 | memcmp (&address->peer, &p.id, | ||
113 | sizeof (struct GNUNET_PeerIdentity))); | ||
114 | GNUNET_assert (0 == strcmp (address->transport_name, test_addr.plugin)); | ||
115 | GNUNET_assert (address->address_length == test_addr.addr_len); | ||
116 | GNUNET_assert (0 == | ||
117 | memcmp (address->address, test_addr.plugin, | ||
118 | address->address_length)); | ||
119 | GNUNET_assert (test_addr.session == session); | ||
120 | 129 | ||
121 | if (0 == stage) | 130 | if (0 == stage) |
122 | { | 131 | { |
123 | /* Delete session without the address */ | 132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Received suggestion for peer `%s'\n", |
124 | struct GNUNET_HELLO_Address hello_address_2; | 133 | GNUNET_i2s(&address->peer)); |
125 | hello_address_2.peer = p.id; | 134 | |
126 | hello_address_2.transport_name = test_addr.plugin; | 135 | if (0 != memcmp (&address->peer, &p.id, sizeof (struct GNUNET_PeerIdentity))) |
127 | hello_address_2.address = NULL; | 136 | { |
128 | hello_address_2.address_length = 0; | 137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer id'\n"); |
129 | 138 | res = 1; | |
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 139 | } |
131 | "Stage %u: Destroying address for peer `%s' address %p length %u session %p\n", | 140 | else if (0 != strcmp (address->transport_name, test_addr.plugin)) |
132 | stage, | 141 | { |
133 | GNUNET_i2s (&hello_address_2.peer), | 142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid plugin'\n"); |
134 | hello_address_2.address, | 143 | res = 1; |
135 | hello_address_2.address_length, | 144 | } |
136 | session); | 145 | else if (address->address_length != test_addr.addr_len) |
137 | 146 | { | |
138 | GNUNET_ATS_address_destroyed (ats, &hello_address_2, test_addr.session); | 147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length'\n"); |
139 | test_addr.session = NULL; | 148 | res = 1; |
140 | GNUNET_ATS_suggest_address (ats, &p.id); | 149 | } |
150 | else if (0 != memcmp (address->address, test_addr.plugin, address->address_length)) | ||
151 | { | ||
152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address'\n"); | ||
153 | res = 1; | ||
154 | } | ||
155 | else if (test_session != &test_addr) | ||
156 | { | ||
157 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid session'\n"); | ||
158 | res = 1; | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for correct address `%s'\n", | ||
163 | GNUNET_i2s (&address->peer)); | ||
164 | res = 0; | ||
165 | } | ||
166 | GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id); | ||
167 | if (1 == res) | ||
168 | { | ||
169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for invalid address `%s'\n", | ||
170 | GNUNET_i2s (&address->peer)); | ||
171 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
172 | ret = 1; | ||
173 | } | ||
174 | stage ++; | ||
175 | ret = 0; | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying address for `%s'\n", | ||
177 | GNUNET_i2s (&address->peer)); | ||
178 | /* Destroying session for address */ | ||
179 | test_session = NULL; | ||
180 | GNUNET_ATS_address_destroyed (sched_ats, &hello_address, test_addr.session); | ||
181 | /* Request address */ | ||
182 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | ||
183 | return; | ||
141 | } | 184 | } |
142 | if (1 == stage) | 185 | else if (1 == stage) |
143 | { | 186 | { |
144 | /* End */ | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 1: Received suggestion for peer `%s'\n", |
145 | GNUNET_SCHEDULER_add_now (&end, NULL); | 188 | GNUNET_i2s(&address->peer)); |
189 | |||
190 | if (0 != memcmp (&address->peer, &p.id, sizeof (struct GNUNET_PeerIdentity))) | ||
191 | { | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer id'\n"); | ||
193 | res = 1; | ||
194 | } | ||
195 | else if (0 != strcmp (address->transport_name, test_addr.plugin)) | ||
196 | { | ||
197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid plugin'\n"); | ||
198 | res = 1; | ||
199 | } | ||
200 | else if (address->address_length != test_addr.addr_len) | ||
201 | { | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length'\n"); | ||
203 | res = 1; | ||
204 | } | ||
205 | else if (0 != memcmp (address->address, test_addr.plugin, address->address_length)) | ||
206 | { | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address'\n"); | ||
208 | res = 1; | ||
209 | } | ||
210 | else if (session != test_session) | ||
211 | { | ||
212 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid session %p != %p'\n", test_session, session); | ||
213 | res = 1; | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for correct address `%s'\n", | ||
218 | GNUNET_i2s (&address->peer)); | ||
219 | res = 0; | ||
220 | } | ||
221 | GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id); | ||
222 | if (1 == res) | ||
223 | { | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for invalid address `%s'\n", | ||
225 | GNUNET_i2s (&address->peer)); | ||
226 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
227 | ret = 1; | ||
228 | } | ||
229 | stage ++; | ||
230 | ret = 0; | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying address for `%s'\n", | ||
232 | GNUNET_i2s (&address->peer)); | ||
233 | /* Destroying complete address */ | ||
234 | GNUNET_ATS_address_destroyed (sched_ats, &hello_address, session); | ||
235 | /* Request address */ | ||
236 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | ||
237 | wait_task = GNUNET_SCHEDULER_add_delayed (WAIT_TIMEOUT, &end, NULL); | ||
238 | return; | ||
146 | } | 239 | } |
147 | stage++; | 240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Unexpected address suggestion\n"); |
241 | ret = 1; | ||
242 | |||
148 | } | 243 | } |
149 | 244 | ||
150 | 245 | ||
@@ -153,41 +248,49 @@ run (void *cls, | |||
153 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 248 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
154 | struct GNUNET_TESTING_Peer *peer) | 249 | struct GNUNET_TESTING_Peer *peer) |
155 | { | 250 | { |
156 | ret = GNUNET_SYSERR; | ||
157 | |||
158 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 251 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
159 | ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | 252 | |
160 | if (ats == NULL) | 253 | /* Connect to ATS scheduling */ |
254 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
255 | if (sched_ats == NULL) | ||
161 | { | 256 | { |
162 | ret = GNUNET_SYSERR; | 257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); |
258 | ret = 1; | ||
163 | end (); | 259 | end (); |
164 | return; | 260 | return; |
165 | } | 261 | } |
166 | 262 | ||
167 | /* set up peer */ | 263 | /* Set up peer */ |
168 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, | 264 | if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID, &p.id.hashPubKey)) |
169 | &p.id.hashPubKey); | 265 | { |
266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
267 | ret = GNUNET_SYSERR; | ||
268 | end (); | ||
269 | return; | ||
270 | } | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | 271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", |
171 | GNUNET_i2s (&p.id)); | 272 | GNUNET_i2s_full(&p.id)); |
172 | |||
173 | create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); | ||
174 | 273 | ||
175 | /* Adding address with session */ | 274 | /* Adding address with session */ |
275 | create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); | ||
276 | test_session = &test_addr; | ||
176 | hello_address.peer = p.id; | 277 | hello_address.peer = p.id; |
177 | hello_address.transport_name = test_addr.plugin; | 278 | hello_address.transport_name = test_addr.plugin; |
178 | hello_address.address = test_addr.addr; | 279 | hello_address.address = test_addr.addr; |
179 | hello_address.address_length = test_addr.addr_len; | 280 | hello_address.address_length = test_addr.addr_len; |
180 | GNUNET_ATS_address_add (ats, &hello_address, test_addr.session, NULL, 0); | 281 | GNUNET_ATS_address_add (sched_ats, &hello_address, test_addr.session, NULL, 0); |
181 | GNUNET_ATS_suggest_address (ats, &p.id); | 282 | |
283 | /* Request address */ | ||
284 | GNUNET_ATS_suggest_address (sched_ats, &p.id); | ||
182 | } | 285 | } |
183 | 286 | ||
184 | 287 | ||
185 | int | 288 | int |
186 | main (int argc, char *argv[]) | 289 | main (int argc, char *argv[]) |
187 | { | 290 | { |
188 | if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_destroy_session", | 291 | if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_add_address", |
189 | "test_ats_api.conf", | 292 | "test_ats_api.conf", |
190 | &run, NULL)) | 293 | &run, NULL)) |
191 | return 1; | 294 | return 1; |
192 | return ret; | 295 | return ret; |
193 | } | 296 | } |