diff options
Diffstat (limited to 'src/core/test_core_api_preferences.c')
-rw-r--r-- | src/core/test_core_api_preferences.c | 328 |
1 files changed, 157 insertions, 171 deletions
diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c index cc55f1644..200ae4176 100644 --- a/src/core/test_core_api_preferences.c +++ b/src/core/test_core_api_preferences.c | |||
@@ -41,7 +41,7 @@ struct PeerContext | |||
41 | { | 41 | { |
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | struct GNUNET_CORE_Handle *ch; | 43 | struct GNUNET_CORE_Handle *ch; |
44 | struct GNUNET_PeerIdentity id; | 44 | struct GNUNET_PeerIdentity id; |
45 | struct GNUNET_TRANSPORT_Handle *th; | 45 | struct GNUNET_TRANSPORT_Handle *th; |
46 | struct GNUNET_MessageHeader *hello; | 46 | struct GNUNET_MessageHeader *hello; |
47 | int connect_status; | 47 | int connect_status; |
@@ -75,13 +75,14 @@ static GNUNET_SCHEDULER_TaskIdentifier ask_task; | |||
75 | static unsigned int total_reserve = 5; | 75 | static unsigned int total_reserve = 5; |
76 | 76 | ||
77 | 77 | ||
78 | static void process_hello (void *cls, const struct GNUNET_MessageHeader *message); | 78 | static void process_hello (void *cls, |
79 | const struct GNUNET_MessageHeader *message); | ||
79 | 80 | ||
80 | static void | 81 | static void |
81 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 82 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
82 | { | 83 | { |
83 | #if VERBOSE | 84 | #if VERBOSE |
84 | fprintf(stderr, "Regular shutdown\n"); | 85 | fprintf (stderr, "Regular shutdown\n"); |
85 | #endif | 86 | #endif |
86 | GNUNET_assert (ok == 6); | 87 | GNUNET_assert (ok == 6); |
87 | GNUNET_assert (NULL == irc); | 88 | GNUNET_assert (NULL == irc); |
@@ -100,24 +101,24 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
100 | { | 101 | { |
101 | err_task = GNUNET_SCHEDULER_NO_TASK; | 102 | err_task = GNUNET_SCHEDULER_NO_TASK; |
102 | #if VERBOSE | 103 | #if VERBOSE |
103 | fprintf(stderr, "ENDING ANGRILY %u\n", ok); | 104 | fprintf (stderr, "ENDING ANGRILY %u\n", ok); |
104 | #endif | 105 | #endif |
105 | GNUNET_break (0); | 106 | GNUNET_break (0); |
106 | if (NULL != irc) | 107 | if (NULL != irc) |
107 | { | 108 | { |
108 | GNUNET_CORE_peer_change_preference_cancel (irc); | 109 | GNUNET_CORE_peer_change_preference_cancel (irc); |
109 | irc = NULL; | 110 | irc = NULL; |
110 | } | 111 | } |
111 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) | 112 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) |
112 | { | 113 | { |
113 | GNUNET_SCHEDULER_cancel (irc_task); | 114 | GNUNET_SCHEDULER_cancel (irc_task); |
114 | irc_task = GNUNET_SCHEDULER_NO_TASK; | 115 | irc_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 116 | } |
116 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | 117 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) |
117 | { | 118 | { |
118 | GNUNET_SCHEDULER_cancel (ask_task); | 119 | GNUNET_SCHEDULER_cancel (ask_task); |
119 | ask_task = GNUNET_SCHEDULER_NO_TASK; | 120 | ask_task = GNUNET_SCHEDULER_NO_TASK; |
120 | } | 121 | } |
121 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | 122 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); |
122 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | 123 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); |
123 | GNUNET_CORE_disconnect (p1.ch); | 124 | GNUNET_CORE_disconnect (p1.ch); |
@@ -142,160 +143,151 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
142 | m = (struct GNUNET_MessageHeader *) buf; | 143 | m = (struct GNUNET_MessageHeader *) buf; |
143 | m->type = htons (MTYPE); | 144 | m->type = htons (MTYPE); |
144 | m->size = htons (sizeof (struct GNUNET_MessageHeader)); | 145 | m->size = htons (sizeof (struct GNUNET_MessageHeader)); |
145 | err_task = | 146 | err_task = |
146 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | 147 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
147 | &terminate_task_error, NULL); | 148 | (GNUNET_TIME_UNIT_SECONDS, 120), |
149 | &terminate_task_error, NULL); | ||
148 | 150 | ||
149 | return sizeof (struct GNUNET_MessageHeader); | 151 | return sizeof (struct GNUNET_MessageHeader); |
150 | } | 152 | } |
151 | 153 | ||
152 | static void | 154 | static void |
153 | preference_cb (void *cls, | 155 | preference_cb (void *cls, |
154 | const struct | 156 | const struct |
155 | GNUNET_PeerIdentity *peer, | 157 | GNUNET_PeerIdentity *peer, |
156 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 158 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
157 | int32_t amount, | 159 | int32_t amount, |
158 | struct GNUNET_TIME_Relative res_delay, | 160 | struct GNUNET_TIME_Relative res_delay, uint64_t preference); |
159 | uint64_t preference); | ||
160 | 161 | ||
161 | static void | 162 | static void |
162 | do_reserve (void *cls, | 163 | do_reserve (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
163 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
164 | { | 164 | { |
165 | struct PeerContext *pc = cls; | 165 | struct PeerContext *pc = cls; |
166 | 166 | ||
167 | irc_task = GNUNET_SCHEDULER_NO_TASK; | 167 | irc_task = GNUNET_SCHEDULER_NO_TASK; |
168 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 168 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
169 | { | 169 | { |
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
171 | "Aborted during attempt to request reservation\n"); | 171 | "Aborted during attempt to request reservation\n"); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Requesting reservatin of 32k from core in 1s!\n"); | 175 | "Requesting reservatin of 32k from core in 1s!\n"); |
176 | irc = GNUNET_CORE_peer_change_preference (p1.ch, | 176 | irc = GNUNET_CORE_peer_change_preference (p1.ch, |
177 | &p2.id, | 177 | &p2.id, |
178 | GNUNET_TIME_UNIT_SECONDS, | 178 | GNUNET_TIME_UNIT_SECONDS, |
179 | GNUNET_BANDWIDTH_VALUE_MAX, | 179 | GNUNET_BANDWIDTH_VALUE_MAX, |
180 | 1000000 /* bandwidth for 1s */, | 180 | 1000000 /* bandwidth for 1s */ , |
181 | 0, | 181 | 0, &preference_cb, pc); |
182 | &preference_cb, | ||
183 | pc); | ||
184 | } | 182 | } |
185 | 183 | ||
186 | static void | 184 | static void |
187 | preference_cb (void *cls, | 185 | preference_cb (void *cls, |
188 | const struct | 186 | const struct |
189 | GNUNET_PeerIdentity *peer, | 187 | GNUNET_PeerIdentity *peer, |
190 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 188 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
191 | int32_t amount, | 189 | int32_t amount, |
192 | struct GNUNET_TIME_Relative res_delay, | 190 | struct GNUNET_TIME_Relative res_delay, uint64_t preference) |
193 | uint64_t preference) | ||
194 | { | 191 | { |
195 | struct PeerContext *pc = cls; | 192 | struct PeerContext *pc = cls; |
196 | 193 | ||
197 | irc = NULL; | 194 | irc = NULL; |
198 | if (0 == amount) | 195 | if (0 == amount) |
199 | { | 196 | { |
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | "Delaying reservation request by %llu ms!\n", | 198 | "Delaying reservation request by %llu ms!\n", |
202 | (unsigned long long) res_delay.rel_value); | 199 | (unsigned long long) res_delay.rel_value); |
203 | irc_task = GNUNET_SCHEDULER_add_delayed (res_delay, | 200 | irc_task = GNUNET_SCHEDULER_add_delayed (res_delay, &do_reserve, pc); |
204 | &do_reserve, pc); | 201 | return; |
205 | return; | 202 | } |
206 | } | ||
207 | total_reserve--; | 203 | total_reserve--; |
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation done!\n"); |
209 | "Reservation done!\n"); | ||
210 | if (total_reserve > 0) | 205 | if (total_reserve > 0) |
211 | { | 206 | { |
212 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); | 207 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); |
213 | return; | 208 | return; |
214 | } | 209 | } |
215 | GNUNET_SCHEDULER_cancel (err_task); | 210 | GNUNET_SCHEDULER_cancel (err_task); |
216 | err_task = GNUNET_SCHEDULER_NO_TASK; | 211 | err_task = GNUNET_SCHEDULER_NO_TASK; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
218 | "Asking core (1) for transmission to peer `%4s'\n", | 213 | "Asking core (1) for transmission to peer `%4s'\n", |
219 | GNUNET_i2s (&p2.id)); | 214 | GNUNET_i2s (&p2.id)); |
220 | if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch, | 215 | if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch, |
221 | GNUNET_YES, | 216 | GNUNET_YES, |
222 | 0, | 217 | 0, |
223 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), | 218 | GNUNET_TIME_relative_multiply |
224 | &p2.id, | 219 | (GNUNET_TIME_UNIT_SECONDS, |
225 | sizeof (struct GNUNET_MessageHeader), | 220 | 45), &p2.id, |
226 | &transmit_ready, &p1))) | 221 | sizeof (struct |
227 | { | 222 | GNUNET_MessageHeader), |
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 223 | &transmit_ready, &p1))) |
229 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", | 224 | { |
230 | GNUNET_i2s (&p2.id)); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
231 | } | 226 | "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", |
227 | GNUNET_i2s (&p2.id)); | ||
228 | } | ||
232 | } | 229 | } |
233 | 230 | ||
234 | 231 | ||
235 | static void | 232 | static void |
236 | connect_notify (void *cls, | 233 | connect_notify (void *cls, |
237 | const struct GNUNET_PeerIdentity *peer, | 234 | const struct GNUNET_PeerIdentity *peer, |
238 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 235 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
239 | { | 236 | { |
240 | struct PeerContext *pc = cls; | 237 | struct PeerContext *pc = cls; |
241 | 238 | ||
242 | if (0 == memcmp (&pc->id, | 239 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
243 | peer, | ||
244 | sizeof (struct GNUNET_PeerIdentity))) | ||
245 | return; | 240 | return; |
246 | GNUNET_assert (pc->connect_status == 0); | 241 | GNUNET_assert (pc->connect_status == 0); |
247 | pc->connect_status = 1; | 242 | pc->connect_status = 1; |
248 | if (pc == &p1) | 243 | if (pc == &p1) |
244 | { | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
246 | "Encrypted connection established to peer `%4s'\n", | ||
247 | GNUNET_i2s (peer)); | ||
248 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | ||
249 | { | 249 | { |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_SCHEDULER_cancel (ask_task); |
251 | "Encrypted connection established to peer `%4s'\n", | 251 | ask_task = GNUNET_SCHEDULER_NO_TASK; |
252 | GNUNET_i2s (peer)); | ||
253 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | ||
254 | { | ||
255 | GNUNET_SCHEDULER_cancel (ask_task); | ||
256 | ask_task = GNUNET_SCHEDULER_NO_TASK; | ||
257 | } | ||
258 | GNUNET_SCHEDULER_cancel (err_task); | ||
259 | err_task = | ||
260 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | ||
261 | &terminate_task_error, NULL); | ||
262 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); | ||
263 | } | 252 | } |
253 | GNUNET_SCHEDULER_cancel (err_task); | ||
254 | err_task = | ||
255 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
256 | (GNUNET_TIME_UNIT_SECONDS, 120), | ||
257 | &terminate_task_error, NULL); | ||
258 | irc_task = GNUNET_SCHEDULER_add_now (&do_reserve, pc); | ||
259 | } | ||
264 | } | 260 | } |
265 | 261 | ||
266 | 262 | ||
267 | static void | 263 | static void |
268 | disconnect_notify (void *cls, | 264 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
269 | const struct GNUNET_PeerIdentity *peer) | ||
270 | { | 265 | { |
271 | struct PeerContext *pc = cls; | 266 | struct PeerContext *pc = cls; |
272 | 267 | ||
273 | if (0 == memcmp (&pc->id, | 268 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
274 | peer, | ||
275 | sizeof (struct GNUNET_PeerIdentity))) | ||
276 | return; | 269 | return; |
277 | pc->connect_status = 0; | 270 | pc->connect_status = 0; |
278 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) | 271 | if (GNUNET_SCHEDULER_NO_TASK != irc_task) |
272 | { | ||
273 | GNUNET_SCHEDULER_cancel (irc_task); | ||
274 | irc_task = GNUNET_SCHEDULER_NO_TASK; | ||
275 | } | ||
276 | if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity))) | ||
277 | { | ||
278 | if (irc != NULL) | ||
279 | { | 279 | { |
280 | GNUNET_SCHEDULER_cancel (irc_task); | 280 | GNUNET_CORE_peer_change_preference_cancel (irc); |
281 | irc_task = GNUNET_SCHEDULER_NO_TASK; | 281 | irc = NULL; |
282 | } | 282 | } |
283 | if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity))) | 283 | if (th != NULL) |
284 | { | 284 | { |
285 | if (irc != NULL) | 285 | GNUNET_CORE_notify_transmit_ready_cancel (th); |
286 | { | 286 | th = NULL; |
287 | GNUNET_CORE_peer_change_preference_cancel (irc); | ||
288 | irc = NULL; | ||
289 | } | ||
290 | if (th != NULL) | ||
291 | { | ||
292 | GNUNET_CORE_notify_transmit_ready_cancel (th); | ||
293 | th = NULL; | ||
294 | } | ||
295 | } | 287 | } |
288 | } | ||
296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
297 | "Encrypted connection to `%4s' cut\n", | 290 | "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); |
298 | GNUNET_i2s (peer)); | ||
299 | } | 291 | } |
300 | 292 | ||
301 | 293 | ||
@@ -303,7 +295,7 @@ static int | |||
303 | inbound_notify (void *cls, | 295 | inbound_notify (void *cls, |
304 | const struct GNUNET_PeerIdentity *other, | 296 | const struct GNUNET_PeerIdentity *other, |
305 | const struct GNUNET_MessageHeader *message, | 297 | const struct GNUNET_MessageHeader *message, |
306 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 298 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
307 | { | 299 | { |
308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
309 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); | 301 | "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); |
@@ -315,7 +307,7 @@ static int | |||
315 | outbound_notify (void *cls, | 307 | outbound_notify (void *cls, |
316 | const struct GNUNET_PeerIdentity *other, | 308 | const struct GNUNET_PeerIdentity *other, |
317 | const struct GNUNET_MessageHeader *message, | 309 | const struct GNUNET_MessageHeader *message, |
318 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 310 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
319 | { | 311 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
321 | "Core notifies about outbound data for `%4s'.\n", | 313 | "Core notifies about outbound data for `%4s'.\n", |
@@ -329,7 +321,7 @@ static int | |||
329 | process_mtype (void *cls, | 321 | process_mtype (void *cls, |
330 | const struct GNUNET_PeerIdentity *peer, | 322 | const struct GNUNET_PeerIdentity *peer, |
331 | const struct GNUNET_MessageHeader *message, | 323 | const struct GNUNET_MessageHeader *message, |
332 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 324 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
333 | { | 325 | { |
334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
335 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); | 327 | "Receiving message from `%4s'.\n", GNUNET_i2s (peer)); |
@@ -349,19 +341,16 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
349 | 341 | ||
350 | 342 | ||
351 | 343 | ||
352 | static void | 344 | static void |
353 | ask_connect_task (void *cls, | 345 | ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
354 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
355 | { | 346 | { |
356 | ask_task = | 347 | ask_task = |
357 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 348 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
358 | &ask_connect_task, NULL); | 349 | &ask_connect_task, NULL); |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
360 | "Asking core (1) AGAIN to connect to peer `%4s'\n", | 351 | "Asking core (1) AGAIN to connect to peer `%4s'\n", |
361 | GNUNET_i2s (&p2.id)); | 352 | GNUNET_i2s (&p2.id)); |
362 | GNUNET_CORE_peer_request_connect (p1.ch, | 353 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
363 | &p2.id, | ||
364 | NULL, NULL); | ||
365 | } | 354 | } |
366 | 355 | ||
367 | 356 | ||
@@ -380,52 +369,48 @@ init_notify (void *cls, | |||
380 | p->id = *my_identity; | 369 | p->id = *my_identity; |
381 | p->ch = server; | 370 | p->ch = server; |
382 | if (cls == &p1) | 371 | if (cls == &p1) |
383 | { | 372 | { |
384 | GNUNET_assert (ok == 2); | 373 | GNUNET_assert (ok == 2); |
385 | OKPP; | 374 | OKPP; |
386 | /* connect p2 */ | 375 | /* connect p2 */ |
387 | GNUNET_CORE_connect (p2.cfg, 1, | 376 | GNUNET_CORE_connect (p2.cfg, 1, |
388 | &p2, | 377 | &p2, |
389 | &init_notify, | 378 | &init_notify, |
390 | &connect_notify, | 379 | &connect_notify, |
391 | &disconnect_notify, | 380 | &disconnect_notify, |
392 | NULL, | 381 | NULL, |
393 | &inbound_notify, | 382 | &inbound_notify, |
394 | GNUNET_YES, | 383 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
395 | &outbound_notify, GNUNET_YES, handlers); | 384 | } |
396 | } | ||
397 | else | 385 | else |
398 | { | 386 | { |
399 | GNUNET_assert (ok == 3); | 387 | GNUNET_assert (ok == 3); |
400 | OKPP; | 388 | OKPP; |
401 | GNUNET_assert (cls == &p2); | 389 | GNUNET_assert (cls == &p2); |
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
403 | "Asking core (1) to connect to peer `%4s'\n", | 391 | "Asking core (1) to connect to peer `%4s'\n", |
404 | GNUNET_i2s (&p2.id)); | 392 | GNUNET_i2s (&p2.id)); |
405 | err_task = | 393 | err_task = |
406 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), | 394 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
407 | &terminate_task_error, NULL); | 395 | (GNUNET_TIME_UNIT_SECONDS, 60), |
408 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) | 396 | &terminate_task_error, NULL); |
409 | GNUNET_SCHEDULER_cancel (ask_task); | 397 | if (GNUNET_SCHEDULER_NO_TASK != ask_task) |
410 | ask_task = | 398 | GNUNET_SCHEDULER_cancel (ask_task); |
411 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 399 | ask_task = |
412 | &ask_connect_task, NULL); | 400 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
413 | GNUNET_CORE_peer_request_connect (p1.ch, | 401 | &ask_connect_task, NULL); |
414 | &p2.id, | 402 | GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); |
415 | NULL, NULL); | 403 | } |
416 | } | ||
417 | } | 404 | } |
418 | 405 | ||
419 | 406 | ||
420 | static void | 407 | static void |
421 | process_hello (void *cls, | 408 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
422 | const struct GNUNET_MessageHeader *message) | ||
423 | { | 409 | { |
424 | struct PeerContext *p = cls; | 410 | struct PeerContext *p = cls; |
425 | 411 | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
427 | "Received (my) `%s' from transport service\n", | 413 | "Received (my) `%s' from transport service\n", "HELLO"); |
428 | "HELLO"); | ||
429 | GNUNET_assert (message != NULL); | 414 | GNUNET_assert (message != NULL); |
430 | p->hello = GNUNET_malloc (ntohs (message->size)); | 415 | p->hello = GNUNET_malloc (ntohs (message->size)); |
431 | memcpy (p->hello, message, ntohs (message->size)); | 416 | memcpy (p->hello, message, ntohs (message->size)); |
@@ -448,11 +433,11 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
448 | p->cfg = GNUNET_CONFIGURATION_create (); | 433 | p->cfg = GNUNET_CONFIGURATION_create (); |
449 | #if START_ARM | 434 | #if START_ARM |
450 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 435 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
451 | "gnunet-service-arm", | 436 | "gnunet-service-arm", |
452 | #if VERBOSE | 437 | #if VERBOSE |
453 | "-L", "DEBUG", | 438 | "-L", "DEBUG", |
454 | #endif | 439 | #endif |
455 | "-c", cfgname, NULL); | 440 | "-c", cfgname, NULL); |
456 | #endif | 441 | #endif |
457 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 442 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
458 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 443 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
@@ -464,8 +449,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
464 | static void | 449 | static void |
465 | run (void *cls, | 450 | run (void *cls, |
466 | char *const *args, | 451 | char *const *args, |
467 | const char *cfgfile, | 452 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
468 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
469 | { | 453 | { |
470 | GNUNET_assert (ok == 1); | 454 | GNUNET_assert (ok == 1); |
471 | OKPP; | 455 | OKPP; |
@@ -474,9 +458,9 @@ run (void *cls, | |||
474 | GNUNET_CORE_connect (p1.cfg, 1, | 458 | GNUNET_CORE_connect (p1.cfg, 1, |
475 | &p1, | 459 | &p1, |
476 | &init_notify, | 460 | &init_notify, |
477 | &connect_notify, | 461 | &connect_notify, |
478 | &disconnect_notify, | 462 | &disconnect_notify, |
479 | NULL, | 463 | NULL, |
480 | &inbound_notify, | 464 | &inbound_notify, |
481 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | 465 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
482 | } | 466 | } |
@@ -487,10 +471,11 @@ stop_arm (struct PeerContext *p) | |||
487 | #if START_ARM | 471 | #if START_ARM |
488 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 472 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
489 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 473 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
490 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 474 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
491 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 475 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
493 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 477 | "ARM process %u stopped\n", |
478 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
494 | GNUNET_OS_process_close (p->arm_proc); | 479 | GNUNET_OS_process_close (p->arm_proc); |
495 | p->arm_proc = NULL; | 480 | p->arm_proc = NULL; |
496 | #endif | 481 | #endif |
@@ -513,7 +498,8 @@ check () | |||
513 | }; | 498 | }; |
514 | ok = 1; | 499 | ok = 1; |
515 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 500 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
516 | argv, "test-core-api-preferences", "nohelp", options, &run, &ok); | 501 | argv, "test-core-api-preferences", "nohelp", options, |
502 | &run, &ok); | ||
517 | stop_arm (&p1); | 503 | stop_arm (&p1); |
518 | stop_arm (&p2); | 504 | stop_arm (&p2); |
519 | return ok; | 505 | return ok; |
@@ -532,7 +518,7 @@ main (int argc, char *argv[]) | |||
532 | #endif | 518 | #endif |
533 | NULL); | 519 | NULL); |
534 | ret = check (); | 520 | ret = check (); |
535 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 521 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
536 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 522 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
537 | 523 | ||
538 | return ret; | 524 | return ret; |