diff options
Diffstat (limited to 'src/core/test_core_api_reliability.c')
-rw-r--r-- | src/core/test_core_api_reliability.c | 560 |
1 files changed, 282 insertions, 278 deletions
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 745b0b7d9..ca0919294 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c | |||
@@ -41,7 +41,7 @@ | |||
41 | /** | 41 | /** |
42 | * How long until we give up on transmitting the message? | 42 | * How long until we give up on transmitting the message? |
43 | */ | 43 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 600) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) |
45 | 45 | ||
46 | #define MTYPE 12345 | 46 | #define MTYPE 12345 |
47 | 47 | ||
@@ -53,7 +53,8 @@ static struct GNUNET_TIME_Absolute start_time; | |||
53 | static struct GNUNET_SCHEDULER_Task *err_task; | 53 | static struct GNUNET_SCHEDULER_Task *err_task; |
54 | 54 | ||
55 | 55 | ||
56 | struct PeerContext { | 56 | struct PeerContext |
57 | { | ||
57 | struct GNUNET_CONFIGURATION_Handle *cfg; | 58 | struct GNUNET_CONFIGURATION_Handle *cfg; |
58 | struct GNUNET_CORE_Handle *ch; | 59 | struct GNUNET_CORE_Handle *ch; |
59 | struct GNUNET_MQ_Handle *mq; | 60 | struct GNUNET_MQ_Handle *mq; |
@@ -76,16 +77,19 @@ static int ok; | |||
76 | static int32_t tr_n; | 77 | static int32_t tr_n; |
77 | 78 | ||
78 | 79 | ||
79 | #define OKPP do { ok++; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 80 | #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, \ |
81 | "Now at stage %u at %s:%u\n", ok, __FILE__, \ | ||
82 | __LINE__); } while (0) | ||
80 | 83 | ||
81 | struct TestMessage { | 84 | struct TestMessage |
85 | { | ||
82 | struct GNUNET_MessageHeader header; | 86 | struct GNUNET_MessageHeader header; |
83 | uint32_t num GNUNET_PACKED; | 87 | uint32_t num GNUNET_PACKED; |
84 | }; | 88 | }; |
85 | 89 | ||
86 | 90 | ||
87 | static unsigned int | 91 | static unsigned int |
88 | get_size(unsigned int iter) | 92 | get_size (unsigned int iter) |
89 | { | 93 | { |
90 | unsigned int ret; | 94 | unsigned int ret; |
91 | 95 | ||
@@ -97,273 +101,273 @@ get_size(unsigned int iter) | |||
97 | 101 | ||
98 | 102 | ||
99 | static void | 103 | static void |
100 | terminate_peer(struct PeerContext *p) | 104 | terminate_peer (struct PeerContext *p) |
101 | { | 105 | { |
102 | if (NULL != p->ch) | 106 | if (NULL != p->ch) |
103 | { | 107 | { |
104 | GNUNET_CORE_disconnect(p->ch); | 108 | GNUNET_CORE_disconnect (p->ch); |
105 | p->ch = NULL; | 109 | p->ch = NULL; |
106 | } | 110 | } |
107 | if (NULL != p->ghh) | 111 | if (NULL != p->ghh) |
108 | { | 112 | { |
109 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); | 113 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); |
110 | p->ghh = NULL; | 114 | p->ghh = NULL; |
111 | } | 115 | } |
112 | if (NULL != p->oh) | 116 | if (NULL != p->oh) |
113 | { | 117 | { |
114 | GNUNET_TRANSPORT_offer_hello_cancel(p->oh); | 118 | GNUNET_TRANSPORT_offer_hello_cancel (p->oh); |
115 | p->oh = NULL; | 119 | p->oh = NULL; |
116 | } | 120 | } |
117 | if (NULL != p->ats_sh) | 121 | if (NULL != p->ats_sh) |
118 | { | 122 | { |
119 | GNUNET_ATS_connectivity_suggest_cancel(p->ats_sh); | 123 | GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); |
120 | p->ats_sh = NULL; | 124 | p->ats_sh = NULL; |
121 | } | 125 | } |
122 | if (NULL != p->ats) | 126 | if (NULL != p->ats) |
123 | { | 127 | { |
124 | GNUNET_ATS_connectivity_done(p->ats); | 128 | GNUNET_ATS_connectivity_done (p->ats); |
125 | p->ats = NULL; | 129 | p->ats = NULL; |
126 | } | 130 | } |
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
130 | static void | 134 | static void |
131 | terminate_task_error(void *cls) | 135 | terminate_task_error (void *cls) |
132 | { | 136 | { |
133 | err_task = NULL; | 137 | err_task = NULL; |
134 | GNUNET_break(0); | 138 | GNUNET_break (0); |
135 | GNUNET_SCHEDULER_shutdown(); | 139 | GNUNET_SCHEDULER_shutdown (); |
136 | ok = 42; | 140 | ok = 42; |
137 | } | 141 | } |
138 | 142 | ||
139 | 143 | ||
140 | static void | 144 | static void |
141 | do_shutdown(void *cls) | 145 | do_shutdown (void *cls) |
142 | { | 146 | { |
143 | unsigned long long delta; | 147 | unsigned long long delta; |
144 | 148 | ||
145 | delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; | 149 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
146 | if (0 == delta) | 150 | if (0 == delta) |
147 | delta = 1; | 151 | delta = 1; |
148 | fprintf(stderr, | 152 | fprintf (stderr, |
149 | "\nThroughput was %llu kb/s\n", | 153 | "\nThroughput was %llu kb/s\n", |
150 | total_bytes * 1000000LL / 1024 / delta); | 154 | total_bytes * 1000000LL / 1024 / delta); |
151 | GAUGER("CORE", | 155 | GAUGER ("CORE", |
152 | "Core throughput/s", | 156 | "Core throughput/s", |
153 | total_bytes * 1000000LL / 1024 / delta, | 157 | total_bytes * 1000000LL / 1024 / delta, |
154 | "kb/s"); | 158 | "kb/s"); |
155 | if (NULL != err_task) | 159 | if (NULL != err_task) |
156 | { | 160 | { |
157 | GNUNET_SCHEDULER_cancel(err_task); | 161 | GNUNET_SCHEDULER_cancel (err_task); |
158 | err_task = NULL; | 162 | err_task = NULL; |
159 | } | 163 | } |
160 | terminate_peer(&p1); | 164 | terminate_peer (&p1); |
161 | terminate_peer(&p2); | 165 | terminate_peer (&p2); |
162 | } | 166 | } |
163 | 167 | ||
164 | 168 | ||
165 | static void | 169 | static void |
166 | send_message(struct GNUNET_MQ_Handle *mq, | 170 | send_message (struct GNUNET_MQ_Handle *mq, |
167 | int32_t num) | 171 | int32_t num) |
168 | { | 172 | { |
169 | struct GNUNET_MQ_Envelope *env; | 173 | struct GNUNET_MQ_Envelope *env; |
170 | struct TestMessage *hdr; | 174 | struct TestMessage *hdr; |
171 | unsigned int s; | 175 | unsigned int s; |
172 | 176 | ||
173 | GNUNET_assert(NULL != mq); | 177 | GNUNET_assert (NULL != mq); |
174 | GNUNET_assert(tr_n < TOTAL_MSGS); | 178 | GNUNET_assert (tr_n < TOTAL_MSGS); |
175 | s = get_size(tr_n); | 179 | s = get_size (tr_n); |
176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
177 | "Sending message %u of size %u\n", | 181 | "Sending message %u of size %u\n", |
178 | tr_n, | 182 | tr_n, |
179 | s); | 183 | s); |
180 | env = GNUNET_MQ_msg_extra(hdr, | 184 | env = GNUNET_MQ_msg_extra (hdr, |
181 | s - sizeof(struct TestMessage), | 185 | s - sizeof(struct TestMessage), |
182 | MTYPE); | 186 | MTYPE); |
183 | hdr->num = htonl(tr_n); | 187 | hdr->num = htonl (tr_n); |
184 | memset(&hdr[1], | 188 | memset (&hdr[1], |
185 | tr_n, | 189 | tr_n, |
186 | s - sizeof(struct TestMessage)); | 190 | s - sizeof(struct TestMessage)); |
187 | tr_n++; | 191 | tr_n++; |
188 | GNUNET_SCHEDULER_cancel(err_task); | 192 | GNUNET_SCHEDULER_cancel (err_task); |
189 | err_task = | 193 | err_task = |
190 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 194 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
191 | &terminate_task_error, | 195 | &terminate_task_error, |
192 | NULL); | 196 | NULL); |
193 | total_bytes += s; | 197 | total_bytes += s; |
194 | GNUNET_MQ_send(mq, | 198 | GNUNET_MQ_send (mq, |
195 | env); | 199 | env); |
196 | } | 200 | } |
197 | 201 | ||
198 | 202 | ||
199 | static void * | 203 | static void * |
200 | connect_notify(void *cls, | 204 | connect_notify (void *cls, |
201 | const struct GNUNET_PeerIdentity *peer, | 205 | const struct GNUNET_PeerIdentity *peer, |
202 | struct GNUNET_MQ_Handle *mq) | 206 | struct GNUNET_MQ_Handle *mq) |
203 | { | 207 | { |
204 | struct PeerContext *pc = cls; | 208 | struct PeerContext *pc = cls; |
205 | 209 | ||
206 | if (0 == memcmp(&pc->id, | 210 | if (0 == memcmp (&pc->id, |
207 | peer, | 211 | peer, |
208 | sizeof(struct GNUNET_PeerIdentity))) | 212 | sizeof(struct GNUNET_PeerIdentity))) |
209 | return (void *)peer; | 213 | return (void *) peer; |
210 | pc->mq = mq; | 214 | pc->mq = mq; |
211 | GNUNET_assert(0 == pc->connect_status); | 215 | GNUNET_assert (0 == pc->connect_status); |
212 | pc->connect_status = 1; | 216 | pc->connect_status = 1; |
213 | if (pc == &p1) | 217 | if (pc == &p1) |
214 | { | 218 | { |
215 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
216 | "Encrypted connection established to peer `%s'\n", | 220 | "Encrypted connection established to peer `%s'\n", |
217 | GNUNET_i2s(peer)); | 221 | GNUNET_i2s (peer)); |
218 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
219 | "Asking core (1) for transmission to peer `%s'\n", | 223 | "Asking core (1) for transmission to peer `%s'\n", |
220 | GNUNET_i2s(&p2.id)); | 224 | GNUNET_i2s (&p2.id)); |
221 | GNUNET_SCHEDULER_cancel(err_task); | 225 | GNUNET_SCHEDULER_cancel (err_task); |
222 | err_task = | 226 | err_task = |
223 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 227 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
224 | &terminate_task_error, | 228 | &terminate_task_error, |
225 | NULL); | 229 | NULL); |
226 | start_time = GNUNET_TIME_absolute_get(); | 230 | start_time = GNUNET_TIME_absolute_get (); |
227 | send_message(mq, | 231 | send_message (mq, |
228 | 0); | 232 | 0); |
229 | } | 233 | } |
230 | return (void *)peer; | 234 | return (void *) peer; |
231 | } | 235 | } |
232 | 236 | ||
233 | 237 | ||
234 | static void | 238 | static void |
235 | disconnect_notify(void *cls, | 239 | disconnect_notify (void *cls, |
236 | const struct GNUNET_PeerIdentity *peer, | 240 | const struct GNUNET_PeerIdentity *peer, |
237 | void *internal_cls) | 241 | void *internal_cls) |
238 | { | 242 | { |
239 | struct PeerContext *pc = cls; | 243 | struct PeerContext *pc = cls; |
240 | 244 | ||
241 | if (0 == memcmp(&pc->id, | 245 | if (0 == memcmp (&pc->id, |
242 | peer, | 246 | peer, |
243 | sizeof(struct GNUNET_PeerIdentity))) | 247 | sizeof(struct GNUNET_PeerIdentity))) |
244 | return; | 248 | return; |
245 | pc->mq = NULL; | 249 | pc->mq = NULL; |
246 | pc->connect_status = 0; | 250 | pc->connect_status = 0; |
247 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
248 | "Encrypted connection to `%s' cut\n", | 252 | "Encrypted connection to `%s' cut\n", |
249 | GNUNET_i2s(peer)); | 253 | GNUNET_i2s (peer)); |
250 | } | 254 | } |
251 | 255 | ||
252 | 256 | ||
253 | static int | 257 | static int |
254 | check_test(void *cls, | 258 | check_test (void *cls, |
255 | const struct TestMessage *hdr) | 259 | const struct TestMessage *hdr) |
256 | { | 260 | { |
257 | return GNUNET_OK; /* accept all */ | 261 | return GNUNET_OK; /* accept all */ |
258 | } | 262 | } |
259 | 263 | ||
260 | 264 | ||
261 | static void | 265 | static void |
262 | handle_test(void *cls, | 266 | handle_test (void *cls, |
263 | const struct TestMessage *hdr) | 267 | const struct TestMessage *hdr) |
264 | { | 268 | { |
265 | static int n; | 269 | static int n; |
266 | unsigned int s; | 270 | unsigned int s; |
267 | 271 | ||
268 | s = get_size(n); | 272 | s = get_size (n); |
269 | if (ntohs(hdr->header.size) != s) | 273 | if (ntohs (hdr->header.size) != s) |
270 | { | 274 | { |
271 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
272 | "Expected message %u of size %u, got %u bytes of message %u\n", | 276 | "Expected message %u of size %u, got %u bytes of message %u\n", |
273 | n, | 277 | n, |
274 | s, | 278 | s, |
275 | ntohs(hdr->header.size), | 279 | ntohs (hdr->header.size), |
276 | ntohl(hdr->num)); | 280 | ntohl (hdr->num)); |
277 | GNUNET_SCHEDULER_cancel(err_task); | 281 | GNUNET_SCHEDULER_cancel (err_task); |
278 | err_task = GNUNET_SCHEDULER_add_now(&terminate_task_error, | 282 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, |
279 | NULL); | 283 | NULL); |
280 | return; | 284 | return; |
281 | } | 285 | } |
282 | if (ntohl(hdr->num) != n) | 286 | if (ntohl (hdr->num) != n) |
283 | { | 287 | { |
284 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
285 | "Expected message %u of size %u, got %u bytes of message %u\n", | 289 | "Expected message %u of size %u, got %u bytes of message %u\n", |
286 | n, | 290 | n, |
287 | s, | 291 | s, |
288 | (unsigned int)ntohs(hdr->header.size), | 292 | (unsigned int) ntohs (hdr->header.size), |
289 | (unsigned int)ntohl(hdr->num)); | 293 | (unsigned int) ntohl (hdr->num)); |
290 | GNUNET_SCHEDULER_cancel(err_task); | 294 | GNUNET_SCHEDULER_cancel (err_task); |
291 | err_task = GNUNET_SCHEDULER_add_now(&terminate_task_error, | 295 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, |
292 | NULL); | 296 | NULL); |
293 | return; | 297 | return; |
294 | } | 298 | } |
295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Got message %u of size %u\n", | 300 | "Got message %u of size %u\n", |
297 | (unsigned int)ntohl(hdr->num), | 301 | (unsigned int) ntohl (hdr->num), |
298 | (unsigned int)ntohs(hdr->header.size)); | 302 | (unsigned int) ntohs (hdr->header.size)); |
299 | n++; | 303 | n++; |
300 | if (0 == (n % (TOTAL_MSGS / 100))) | 304 | if (0 == (n % (TOTAL_MSGS / 100))) |
301 | fprintf(stderr, | 305 | fprintf (stderr, |
302 | "%s", | 306 | "%s", |
303 | "."); | 307 | "."); |
304 | if (n == TOTAL_MSGS) | 308 | if (n == TOTAL_MSGS) |
305 | { | 309 | { |
306 | ok = 0; | 310 | ok = 0; |
307 | GNUNET_SCHEDULER_shutdown(); | 311 | GNUNET_SCHEDULER_shutdown (); |
308 | } | 312 | } |
309 | else | 313 | else |
314 | { | ||
315 | if (n == tr_n) | ||
310 | { | 316 | { |
311 | if (n == tr_n) | 317 | send_message (p1.mq, |
312 | { | 318 | tr_n); |
313 | send_message(p1.mq, | ||
314 | tr_n); | ||
315 | } | ||
316 | } | 319 | } |
320 | } | ||
317 | } | 321 | } |
318 | 322 | ||
319 | 323 | ||
320 | static void | 324 | static void |
321 | init_notify(void *cls, | 325 | init_notify (void *cls, |
322 | const struct GNUNET_PeerIdentity *my_identity) | 326 | const struct GNUNET_PeerIdentity *my_identity) |
323 | { | 327 | { |
324 | struct PeerContext *p = cls; | 328 | struct PeerContext *p = cls; |
325 | struct GNUNET_MQ_MessageHandler handlers[] = { | 329 | struct GNUNET_MQ_MessageHandler handlers[] = { |
326 | GNUNET_MQ_hd_var_size(test, | 330 | GNUNET_MQ_hd_var_size (test, |
327 | MTYPE, | 331 | MTYPE, |
328 | struct TestMessage, | 332 | struct TestMessage, |
329 | NULL), | 333 | NULL), |
330 | GNUNET_MQ_handler_end() | 334 | GNUNET_MQ_handler_end () |
331 | }; | 335 | }; |
332 | 336 | ||
333 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
334 | "Connection to CORE service of `%s' established\n", | 338 | "Connection to CORE service of `%s' established\n", |
335 | GNUNET_i2s(my_identity)); | 339 | GNUNET_i2s (my_identity)); |
336 | p->id = *my_identity; | 340 | p->id = *my_identity; |
337 | if (cls == &p1) | 341 | if (cls == &p1) |
338 | { | 342 | { |
339 | GNUNET_assert(ok == 2); | 343 | GNUNET_assert (ok == 2); |
340 | OKPP; | 344 | OKPP; |
341 | /* connect p2 */ | 345 | /* connect p2 */ |
342 | GNUNET_assert(NULL != | 346 | GNUNET_assert (NULL != |
343 | (p2.ch = GNUNET_CORE_connect(p2.cfg, | 347 | (p2.ch = GNUNET_CORE_connect (p2.cfg, |
344 | &p2, | 348 | &p2, |
345 | &init_notify, | 349 | &init_notify, |
346 | &connect_notify, | 350 | &connect_notify, |
347 | &disconnect_notify, | 351 | &disconnect_notify, |
348 | handlers))); | 352 | handlers))); |
349 | } | 353 | } |
350 | else | 354 | else |
351 | { | 355 | { |
352 | GNUNET_assert(ok == 3); | 356 | GNUNET_assert (ok == 3); |
353 | OKPP; | 357 | OKPP; |
354 | GNUNET_assert(cls == &p2); | 358 | GNUNET_assert (cls == &p2); |
355 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
356 | "Asking transport (1) to connect to peer `%s'\n", | 360 | "Asking transport (1) to connect to peer `%s'\n", |
357 | GNUNET_i2s(&p2.id)); | 361 | GNUNET_i2s (&p2.id)); |
358 | p1.ats_sh = GNUNET_ATS_connectivity_suggest(p1.ats, | 362 | p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, |
359 | &p2.id, | 363 | &p2.id, |
360 | 1); | 364 | 1); |
361 | } | 365 | } |
362 | } | 366 | } |
363 | 367 | ||
364 | 368 | ||
365 | static void | 369 | static void |
366 | offer_hello_done(void *cls) | 370 | offer_hello_done (void *cls) |
367 | { | 371 | { |
368 | struct PeerContext *p = cls; | 372 | struct PeerContext *p = cls; |
369 | 373 | ||
@@ -372,129 +376,129 @@ offer_hello_done(void *cls) | |||
372 | 376 | ||
373 | 377 | ||
374 | static void | 378 | static void |
375 | process_hello(void *cls, | 379 | process_hello (void *cls, |
376 | const struct GNUNET_MessageHeader *message) | 380 | const struct GNUNET_MessageHeader *message) |
377 | { | 381 | { |
378 | struct PeerContext *p = cls; | 382 | struct PeerContext *p = cls; |
379 | 383 | ||
380 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
381 | "Received (my) `%s' from transport service\n", "HELLO"); | 385 | "Received (my) `%s' from transport service\n", "HELLO"); |
382 | GNUNET_assert(message != NULL); | 386 | GNUNET_assert (message != NULL); |
383 | GNUNET_free_non_null(p->hello); | 387 | GNUNET_free_non_null (p->hello); |
384 | p->hello = GNUNET_copy_message(message); | 388 | p->hello = GNUNET_copy_message (message); |
385 | if ((p == &p1) && (NULL == p2.oh)) | 389 | if ((p == &p1) && (NULL == p2.oh)) |
386 | p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg, | 390 | p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, |
387 | message, | 391 | message, |
388 | &offer_hello_done, | 392 | &offer_hello_done, |
389 | &p2); | 393 | &p2); |
390 | if ((p == &p2) && (NULL == p1.oh)) | 394 | if ((p == &p2) && (NULL == p1.oh)) |
391 | p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg, | 395 | p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, |
392 | message, | 396 | message, |
393 | &offer_hello_done, | 397 | &offer_hello_done, |
394 | &p1); | 398 | &p1); |
395 | 399 | ||
396 | if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh)) | 400 | if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh)) |
397 | p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg, | 401 | p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, |
398 | p2.hello, | 402 | p2.hello, |
399 | &offer_hello_done, | 403 | &offer_hello_done, |
400 | &p1); | 404 | &p1); |
401 | if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh)) | 405 | if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh)) |
402 | p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg, | 406 | p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, |
403 | p1.hello, | 407 | p1.hello, |
404 | &offer_hello_done, | 408 | &offer_hello_done, |
405 | &p2); | 409 | &p2); |
406 | } | 410 | } |
407 | 411 | ||
408 | 412 | ||
409 | static void | 413 | static void |
410 | setup_peer(struct PeerContext *p, | 414 | setup_peer (struct PeerContext *p, |
411 | const char *cfgname) | 415 | const char *cfgname) |
412 | { | 416 | { |
413 | char *binary; | 417 | char *binary; |
414 | 418 | ||
415 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); | 419 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
416 | p->cfg = GNUNET_CONFIGURATION_create(); | 420 | p->cfg = GNUNET_CONFIGURATION_create (); |
417 | p->arm_proc | 421 | p->arm_proc |
418 | = GNUNET_OS_start_process(GNUNET_YES, | 422 | = GNUNET_OS_start_process (GNUNET_YES, |
419 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 423 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
420 | NULL, NULL, NULL, | 424 | NULL, NULL, NULL, |
421 | binary, | 425 | binary, |
422 | "gnunet-service-arm", | 426 | "gnunet-service-arm", |
423 | "-c", | 427 | "-c", |
424 | cfgname, | 428 | cfgname, |
425 | NULL); | 429 | NULL); |
426 | GNUNET_assert(GNUNET_OK == | 430 | GNUNET_assert (GNUNET_OK == |
427 | GNUNET_CONFIGURATION_load(p->cfg, | 431 | GNUNET_CONFIGURATION_load (p->cfg, |
428 | cfgname)); | 432 | cfgname)); |
429 | p->ats = GNUNET_ATS_connectivity_init(p->cfg); | 433 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); |
430 | GNUNET_assert(NULL != p->ats); | 434 | GNUNET_assert (NULL != p->ats); |
431 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, | 435 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
432 | GNUNET_TRANSPORT_AC_ANY, | 436 | GNUNET_TRANSPORT_AC_ANY, |
433 | &process_hello, | 437 | &process_hello, |
434 | p); | 438 | p); |
435 | GNUNET_free(binary); | 439 | GNUNET_free (binary); |
436 | } | 440 | } |
437 | 441 | ||
438 | 442 | ||
439 | static void | 443 | static void |
440 | run(void *cls, | 444 | run (void *cls, |
441 | char *const *args, | 445 | char *const *args, |
442 | const char *cfgfile, | 446 | const char *cfgfile, |
443 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 447 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
444 | { | 448 | { |
445 | struct GNUNET_MQ_MessageHandler handlers[] = { | 449 | struct GNUNET_MQ_MessageHandler handlers[] = { |
446 | GNUNET_MQ_hd_fixed_size(test, | 450 | GNUNET_MQ_hd_fixed_size (test, |
447 | MTYPE, | 451 | MTYPE, |
448 | struct TestMessage, | 452 | struct TestMessage, |
449 | NULL), | 453 | NULL), |
450 | GNUNET_MQ_handler_end() | 454 | GNUNET_MQ_handler_end () |
451 | }; | 455 | }; |
452 | 456 | ||
453 | GNUNET_assert(ok == 1); | 457 | GNUNET_assert (ok == 1); |
454 | OKPP; | 458 | OKPP; |
455 | setup_peer(&p1, | 459 | setup_peer (&p1, |
456 | "test_core_api_peer1.conf"); | 460 | "test_core_api_peer1.conf"); |
457 | setup_peer(&p2, | 461 | setup_peer (&p2, |
458 | "test_core_api_peer2.conf"); | 462 | "test_core_api_peer2.conf"); |
459 | err_task = | 463 | err_task = |
460 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 464 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
461 | &terminate_task_error, | 465 | &terminate_task_error, |
466 | NULL); | ||
467 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
462 | NULL); | 468 | NULL); |
463 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 469 | |
464 | NULL); | 470 | GNUNET_assert (NULL != |
465 | 471 | (p1.ch = GNUNET_CORE_connect (p1.cfg, | |
466 | GNUNET_assert(NULL != | 472 | &p1, |
467 | (p1.ch = GNUNET_CORE_connect(p1.cfg, | 473 | &init_notify, |
468 | &p1, | 474 | &connect_notify, |
469 | &init_notify, | 475 | &disconnect_notify, |
470 | &connect_notify, | 476 | handlers))); |
471 | &disconnect_notify, | ||
472 | handlers))); | ||
473 | } | 477 | } |
474 | 478 | ||
475 | 479 | ||
476 | static void | 480 | static void |
477 | stop_arm(struct PeerContext *p) | 481 | stop_arm (struct PeerContext *p) |
478 | { | 482 | { |
479 | if (0 != GNUNET_OS_process_kill(p->arm_proc, | 483 | if (0 != GNUNET_OS_process_kill (p->arm_proc, |
480 | GNUNET_TERM_SIG)) | 484 | GNUNET_TERM_SIG)) |
481 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, | 485 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
482 | "kill"); | 486 | "kill"); |
483 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) | 487 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) |
484 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, | 488 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
485 | "waitpid"); | 489 | "waitpid"); |
486 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
487 | "ARM process %u stopped\n", | 491 | "ARM process %u stopped\n", |
488 | GNUNET_OS_process_get_pid(p->arm_proc)); | 492 | GNUNET_OS_process_get_pid (p->arm_proc)); |
489 | GNUNET_OS_process_destroy(p->arm_proc); | 493 | GNUNET_OS_process_destroy (p->arm_proc); |
490 | p->arm_proc = NULL; | 494 | p->arm_proc = NULL; |
491 | GNUNET_CONFIGURATION_destroy(p->cfg); | 495 | GNUNET_CONFIGURATION_destroy (p->cfg); |
492 | } | 496 | } |
493 | 497 | ||
494 | 498 | ||
495 | int | 499 | int |
496 | main(int argc, | 500 | main (int argc, |
497 | char *argv1[]) | 501 | char *argv1[]) |
498 | { | 502 | { |
499 | char *const argv[] = { | 503 | char *const argv[] = { |
500 | "test-core-api-reliability", | 504 | "test-core-api-reliability", |
@@ -507,22 +511,22 @@ main(int argc, | |||
507 | }; | 511 | }; |
508 | 512 | ||
509 | ok = 1; | 513 | ok = 1; |
510 | GNUNET_log_setup("test-core-api-reliability", | 514 | GNUNET_log_setup ("test-core-api-reliability", |
511 | "WARNING", | 515 | "WARNING", |
512 | NULL); | 516 | NULL); |
513 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 517 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
514 | argv, | 518 | argv, |
515 | "test-core-api-reliability", | 519 | "test-core-api-reliability", |
516 | "nohelp", | 520 | "nohelp", |
517 | options, | 521 | options, |
518 | &run, | 522 | &run, |
519 | &ok); | 523 | &ok); |
520 | stop_arm(&p1); | 524 | stop_arm (&p1); |
521 | stop_arm(&p2); | 525 | stop_arm (&p2); |
522 | GNUNET_free_non_null(p1.hello); | 526 | GNUNET_free_non_null (p1.hello); |
523 | GNUNET_free_non_null(p2.hello); | 527 | GNUNET_free_non_null (p2.hello); |
524 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1"); | 528 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |
525 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2"); | 529 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); |
526 | 530 | ||
527 | return ok; | 531 | return ok; |
528 | } | 532 | } |