aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r--src/transport/transport-testing.c1027
1 files changed, 521 insertions, 506 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index acf1645a9..225f7044f 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -26,19 +26,19 @@
26#include "transport-testing.h" 26#include "transport-testing.h"
27 27
28 28
29#define LOG(kind, ...) GNUNET_log_from(kind, "transport-testing", __VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)
30 30
31 31
32static struct GNUNET_TRANSPORT_TESTING_PeerContext * 32static struct GNUNET_TRANSPORT_TESTING_PeerContext *
33find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, 33find_peer_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
34 const struct GNUNET_PeerIdentity *peer) 34 const struct GNUNET_PeerIdentity *peer)
35{ 35{
36 struct GNUNET_TRANSPORT_TESTING_PeerContext *t; 36 struct GNUNET_TRANSPORT_TESTING_PeerContext *t;
37 37
38 for (t = tth->p_head; NULL != t; t = t->next) 38 for (t = tth->p_head; NULL != t; t = t->next)
39 if (0 == memcmp(&t->id, 39 if (0 == memcmp (&t->id,
40 peer, 40 peer,
41 sizeof(struct GNUNET_PeerIdentity))) 41 sizeof(struct GNUNET_PeerIdentity)))
42 return t; 42 return t;
43 return NULL; 43 return NULL;
44} 44}
@@ -53,29 +53,34 @@ find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
53 * @param cb_cls closure for @a cb 53 * @param cb_cls closure for @a cb
54 */ 54 */
55void 55void
56GNUNET_TRANSPORT_TESTING_find_connecting_context(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 56GNUNET_TRANSPORT_TESTING_find_connecting_context (struct
57 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 57 GNUNET_TRANSPORT_TESTING_PeerContext
58 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, 58 *p1,
59 void *cb_cls) 59 struct
60 GNUNET_TRANSPORT_TESTING_PeerContext
61 *p2,
62 GNUNET_TRANSPORT_TESTING_ConnectContextCallback
63 cb,
64 void *cb_cls)
60{ 65{
61 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; 66 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
62 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 67 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
63 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 68 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
64 69
65 for (cc = tth->cc_head; NULL != cc; cc = ccn) 70 for (cc = tth->cc_head; NULL != cc; cc = ccn)
66 { 71 {
67 ccn = cc->next; 72 ccn = cc->next;
68 if ((cc->p1 == p1) && 73 if ((cc->p1 == p1) &&
69 (cc->p2 == p2)) 74 (cc->p2 == p2))
70 cb(cb_cls, 75 cb (cb_cls,
71 cc); 76 cc);
72 } 77 }
73} 78}
74 79
75 80
76static void 81static void
77set_p1c(void *cls, 82set_p1c (void *cls,
78 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 83 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
79{ 84{
80 int *found = cls; 85 int *found = cls;
81 86
@@ -86,8 +91,8 @@ set_p1c(void *cls,
86 91
87 92
88static void 93static void
89set_mq(void *cls, 94set_mq (void *cls,
90 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 95 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
91{ 96{
92 struct GNUNET_MQ_Handle *mq = cls; 97 struct GNUNET_MQ_Handle *mq = cls;
93 98
@@ -96,8 +101,8 @@ set_mq(void *cls,
96 101
97 102
98static void 103static void
99set_p2c(void *cls, 104set_p2c (void *cls,
100 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 105 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
101{ 106{
102 int *found = cls; 107 int *found = cls;
103 108
@@ -108,8 +113,8 @@ set_p2c(void *cls,
108 113
109 114
110static void 115static void
111clear_p1c(void *cls, 116clear_p1c (void *cls,
112 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 117 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
113{ 118{
114 int *found = cls; 119 int *found = cls;
115 120
@@ -120,8 +125,8 @@ clear_p1c(void *cls,
120 125
121 126
122static void 127static void
123clear_p2c(void *cls, 128clear_p2c (void *cls,
124 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 129 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
125{ 130{
126 int *found = cls; 131 int *found = cls;
127 132
@@ -132,9 +137,9 @@ clear_p2c(void *cls,
132 137
133 138
134static void * 139static void *
135notify_connect(void *cls, 140notify_connect (void *cls,
136 const struct GNUNET_PeerIdentity *peer, 141 const struct GNUNET_PeerIdentity *peer,
137 struct GNUNET_MQ_Handle *mq) 142 struct GNUNET_MQ_Handle *mq)
138{ 143{
139 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 144 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
140 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 145 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -145,103 +150,103 @@ notify_connect(void *cls,
145 int found; 150 int found;
146 void *ret; 151 void *ret;
147 152
148 p2 = find_peer_context(p->tth, 153 p2 = find_peer_context (p->tth,
149 peer); 154 peer);
150 if (NULL != p->nc) 155 if (NULL != p->nc)
151 ret = p->nc(p->cb_cls, 156 ret = p->nc (p->cb_cls,
152 peer, 157 peer,
153 mq); 158 mq);
154 else 159 else
155 ret = NULL; 160 ret = NULL;
156 161
157 if (NULL != p2) 162 if (NULL != p2)
158 GNUNET_asprintf(&p2_s, 163 GNUNET_asprintf (&p2_s,
159 "%u (`%s')", 164 "%u (`%s')",
160 p2->no, 165 p2->no,
161 GNUNET_i2s(&p2->id)); 166 GNUNET_i2s (&p2->id));
162 else 167 else
163 GNUNET_asprintf(&p2_s, 168 GNUNET_asprintf (&p2_s,
164 "`%s'", 169 "`%s'",
165 GNUNET_i2s(peer)); 170 GNUNET_i2s (peer));
166 LOG(GNUNET_ERROR_TYPE_DEBUG, 171 LOG (GNUNET_ERROR_TYPE_DEBUG,
167 "Peers %s connected to peer %u (`%s')\n", 172 "Peers %s connected to peer %u (`%s')\n",
168 p2_s, 173 p2_s,
169 p->no, 174 p->no,
170 GNUNET_i2s(&p->id)); 175 GNUNET_i2s (&p->id));
171 GNUNET_free(p2_s); 176 GNUNET_free (p2_s);
172 /* update flags in connecting contexts */ 177 /* update flags in connecting contexts */
173 found = GNUNET_NO; 178 found = GNUNET_NO;
174 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 179 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
175 p2, 180 p2,
176 &set_p1c, 181 &set_p1c,
177 &found); 182 &found);
178 if (GNUNET_NO == found) 183 if (GNUNET_NO == found)
179 { 184 {
180 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 185 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
181 cc->p1 = p; 186 cc->p1 = p;
182 cc->p2 = p2; 187 cc->p2 = p2;
183 cc->p1_c = GNUNET_YES; 188 cc->p1_c = GNUNET_YES;
184 GNUNET_CONTAINER_DLL_insert(tth->cc_head, 189 GNUNET_CONTAINER_DLL_insert (tth->cc_head,
185 tth->cc_tail, 190 tth->cc_tail,
186 cc); 191 cc);
187 } 192 }
188 found = GNUNET_NO; 193 found = GNUNET_NO;
189 GNUNET_TRANSPORT_TESTING_find_connecting_context(p2, 194 GNUNET_TRANSPORT_TESTING_find_connecting_context (p2,
190 p, 195 p,
191 &set_p2c, 196 &set_p2c,
192 &found); 197 &found);
193 if (GNUNET_NO == found) 198 if (GNUNET_NO == found)
194 { 199 {
195 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 200 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
196 cc->p1 = p2; 201 cc->p1 = p2;
197 cc->p2 = p; 202 cc->p2 = p;
198 cc->p1_c = GNUNET_YES; 203 cc->p1_c = GNUNET_YES;
199 GNUNET_CONTAINER_DLL_insert(tth->cc_head, 204 GNUNET_CONTAINER_DLL_insert (tth->cc_head,
200 tth->cc_tail, 205 tth->cc_tail,
201 cc); 206 cc);
202 } 207 }
203 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 208 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
204 p2, 209 p2,
205 &set_mq, 210 &set_mq,
206 mq); 211 mq);
207 /* update set connected flag for all requests */ 212 /* update set connected flag for all requests */
208 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 213 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
209 { 214 {
210 if (GNUNET_YES == cc->connected) 215 if (GNUNET_YES == cc->connected)
211 continue; 216 continue;
212 if ((GNUNET_YES == cc->p1_c) && 217 if ((GNUNET_YES == cc->p1_c) &&
213 (GNUNET_YES == cc->p2_c)) 218 (GNUNET_YES == cc->p2_c))
214 { 219 {
215 cc->connected = GNUNET_YES; 220 cc->connected = GNUNET_YES;
216 /* stop trying to connect */ 221 /* stop trying to connect */
217 if (NULL != cc->tct) 222 if (NULL != cc->tct)
218 { 223 {
219 GNUNET_SCHEDULER_cancel(cc->tct); 224 GNUNET_SCHEDULER_cancel (cc->tct);
220 cc->tct = NULL; 225 cc->tct = NULL;
221 } 226 }
222 if (NULL != cc->oh) 227 if (NULL != cc->oh)
223 { 228 {
224 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); 229 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh);
225 cc->oh = NULL; 230 cc->oh = NULL;
226 } 231 }
227 if (NULL != cc->ats_sh) 232 if (NULL != cc->ats_sh)
228 { 233 {
229 GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh); 234 GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh);
230 cc->ats_sh = NULL; 235 cc->ats_sh = NULL;
231 } 236 }
232 }
233 } 237 }
238 }
234 /* then notify application */ 239 /* then notify application */
235 for (cc = tth->cc_head; NULL != cc; cc = ccn) 240 for (cc = tth->cc_head; NULL != cc; cc = ccn)
241 {
242 ccn = cc->next;
243 if ((GNUNET_YES == cc->connected) &&
244 (NULL != cc->cb))
236 { 245 {
237 ccn = cc->next; 246 cc->cb (cc->cb_cls);
238 if ((GNUNET_YES == cc->connected) && 247 cc->cb = NULL; /* only notify once! */
239 (NULL != cc->cb))
240 {
241 cc->cb(cc->cb_cls);
242 cc->cb = NULL; /* only notify once! */
243 }
244 } 248 }
249 }
245 return ret; 250 return ret;
246} 251}
247 252
@@ -252,13 +257,13 @@ notify_connect(void *cls,
252 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` 257 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
253 */ 258 */
254static void 259static void
255offer_hello(void *cls); 260offer_hello (void *cls);
256 261
257 262
258static void 263static void
259notify_disconnect(void *cls, 264notify_disconnect (void *cls,
260 const struct GNUNET_PeerIdentity *peer, 265 const struct GNUNET_PeerIdentity *peer,
261 void *handler_cls) 266 void *handler_cls)
262{ 267{
263 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
264 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 269 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -268,93 +273,94 @@ notify_disconnect(void *cls,
268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; 273 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
269 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 274 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
270 275
271 p2 = find_peer_context(p->tth, 276 p2 = find_peer_context (p->tth,
272 peer); 277 peer);
273 no = p->no; 278 no = p->no;
274 if (NULL != p2) 279 if (NULL != p2)
275 GNUNET_asprintf(&p2_s, 280 GNUNET_asprintf (&p2_s,
276 "%u (`%s')", 281 "%u (`%s')",
277 p2->no, 282 p2->no,
278 GNUNET_i2s(&p2->id)); 283 GNUNET_i2s (&p2->id));
279 else 284 else
280 GNUNET_asprintf(&p2_s, 285 GNUNET_asprintf (&p2_s,
281 "`%s'", 286 "`%s'",
282 GNUNET_i2s(peer)); 287 GNUNET_i2s (peer));
283 LOG(GNUNET_ERROR_TYPE_DEBUG, 288 LOG (GNUNET_ERROR_TYPE_DEBUG,
284 "Peers %s disconnected from peer %u (`%s')\n", 289 "Peers %s disconnected from peer %u (`%s')\n",
285 p2_s, 290 p2_s,
286 no, 291 no,
287 GNUNET_i2s(&p->id)); 292 GNUNET_i2s (&p->id));
288 GNUNET_free(p2_s); 293 GNUNET_free (p2_s);
289 /* notify about disconnect */ 294 /* notify about disconnect */
290 if (NULL != p->nd) 295 if (NULL != p->nd)
291 p->nd(p->cb_cls, 296 p->nd (p->cb_cls,
292 peer, 297 peer,
293 handler_cls); 298 handler_cls);
294 if (NULL == p2) 299 if (NULL == p2)
295 return; 300 return;
296 /* clear MQ, it is now invalid */ 301 /* clear MQ, it is now invalid */
297 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 302 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
298 p2, 303 p2,
299 &set_mq, 304 &set_mq,
300 NULL); 305 NULL);
301 /* update set connected flags for all requests */ 306 /* update set connected flags for all requests */
302 GNUNET_TRANSPORT_TESTING_find_connecting_context(p, 307 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
303 p2, 308 p2,
304 &clear_p1c, 309 &clear_p1c,
305 NULL); 310 NULL);
306 GNUNET_TRANSPORT_TESTING_find_connecting_context(p2, 311 GNUNET_TRANSPORT_TESTING_find_connecting_context (p2,
307 p, 312 p,
308 &clear_p2c, 313 &clear_p2c,
309 NULL); 314 NULL);
310 /* resume connectivity requests as necessary */ 315 /* resume connectivity requests as necessary */
311 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 316 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
312 { 317 {
313 if (GNUNET_NO == cc->connected) 318 if (GNUNET_NO == cc->connected)
314 continue; 319 continue;
315 if ((GNUNET_YES != cc->p1_c) || 320 if ((GNUNET_YES != cc->p1_c) ||
316 (GNUNET_YES != cc->p2_c)) 321 (GNUNET_YES != cc->p2_c))
317 { 322 {
318 cc->connected = GNUNET_NO; 323 cc->connected = GNUNET_NO;
319 /* start trying to connect */ 324 /* start trying to connect */
320 if ((NULL == cc->tct) && 325 if ((NULL == cc->tct) &&
321 (NULL == cc->oh)) 326 (NULL == cc->oh))
322 cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello, 327 cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello,
323 cc); 328 cc);
324 if (NULL == cc->ats_sh) 329 if (NULL == cc->ats_sh)
325 cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats, 330 cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats,
326 &p2->id, 331 &p2->id,
327 1); 332 1);
328 }
329 } 333 }
334 }
330} 335}
331 336
332 337
333static void 338static void
334get_hello(void *cb_cls, 339get_hello (void *cb_cls,
335 const struct GNUNET_MessageHeader *message) 340 const struct GNUNET_MessageHeader *message)
336{ 341{
337 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls; 342 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls;
338 struct GNUNET_PeerIdentity hello_id; 343 struct GNUNET_PeerIdentity hello_id;
339 344
340 GNUNET_assert(GNUNET_OK == 345 GNUNET_assert (GNUNET_OK ==
341 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)message, 346 GNUNET_HELLO_get_id ((const struct
342 &hello_id)); 347 GNUNET_HELLO_Message *) message,
343 GNUNET_assert(0 == memcmp(&hello_id, 348 &hello_id));
344 &p->id, 349 GNUNET_assert (0 == memcmp (&hello_id,
345 sizeof(hello_id))); 350 &p->id,
346 GNUNET_free_non_null(p->hello); 351 sizeof(hello_id)));
347 p->hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(message); 352 GNUNET_free_non_null (p->hello);
353 p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message);
348 354
349 if (NULL != p->start_cb) 355 if (NULL != p->start_cb)
350 { 356 {
351 LOG(GNUNET_ERROR_TYPE_DEBUG, 357 LOG (GNUNET_ERROR_TYPE_DEBUG,
352 "Peer %u (`%s') successfully started\n", 358 "Peer %u (`%s') successfully started\n",
353 p->no, 359 p->no,
354 GNUNET_i2s(&p->id)); 360 GNUNET_i2s (&p->id));
355 p->start_cb(p->start_cb_cls); 361 p->start_cb (p->start_cb_cls);
356 p->start_cb = NULL; 362 p->start_cb = NULL;
357 } 363 }
358} 364}
359 365
360 366
@@ -372,43 +378,45 @@ get_hello(void *cb_cls,
372 * @return the peer context 378 * @return the peer context
373 */ 379 */
374struct GNUNET_TRANSPORT_TESTING_PeerContext * 380struct GNUNET_TRANSPORT_TESTING_PeerContext *
375GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, 381GNUNET_TRANSPORT_TESTING_start_peer (struct
376 const char *cfgname, 382 GNUNET_TRANSPORT_TESTING_Handle *tth,
377 int peer_id, 383 const char *cfgname,
378 const struct GNUNET_MQ_MessageHandler *handlers, 384 int peer_id,
379 GNUNET_TRANSPORT_NotifyConnect nc, 385 const struct
380 GNUNET_TRANSPORT_NotifyDisconnect nd, 386 GNUNET_MQ_MessageHandler *handlers,
381 void *cb_cls, 387 GNUNET_TRANSPORT_NotifyConnect nc,
382 GNUNET_SCHEDULER_TaskCallback start_cb, 388 GNUNET_TRANSPORT_NotifyDisconnect nd,
383 void *start_cb_cls) 389 void *cb_cls,
390 GNUNET_SCHEDULER_TaskCallback start_cb,
391 void *start_cb_cls)
384{ 392{
385 char *emsg = NULL; 393 char *emsg = NULL;
386 struct GNUNET_TRANSPORT_TESTING_PeerContext *p; 394 struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
387 struct GNUNET_PeerIdentity dummy; 395 struct GNUNET_PeerIdentity dummy;
388 unsigned int i; 396 unsigned int i;
389 397
390 if (GNUNET_NO == GNUNET_DISK_file_test(cfgname)) 398 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
391 { 399 {
392 LOG(GNUNET_ERROR_TYPE_ERROR, 400 LOG (GNUNET_ERROR_TYPE_ERROR,
393 "File not found: `%s'\n", 401 "File not found: `%s'\n",
394 cfgname); 402 cfgname);
395 return NULL; 403 return NULL;
396 } 404 }
397 405
398 p = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_PeerContext); 406 p = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_PeerContext);
399 p->tth = tth; 407 p->tth = tth;
400 p->nc = nc; 408 p->nc = nc;
401 p->nd = nd; 409 p->nd = nd;
402 if (NULL != handlers) 410 if (NULL != handlers)
403 { 411 {
404 for (i = 0; NULL != handlers[i].cb; i++) 412 for (i = 0; NULL != handlers[i].cb; i++)
405 ; 413 ;
406 p->handlers = GNUNET_new_array(i + 1, 414 p->handlers = GNUNET_new_array (i + 1,
407 struct GNUNET_MQ_MessageHandler); 415 struct GNUNET_MQ_MessageHandler);
408 GNUNET_memcpy(p->handlers, 416 GNUNET_memcpy (p->handlers,
409 handlers, 417 handlers,
410 i * sizeof(struct GNUNET_MQ_MessageHandler)); 418 i * sizeof(struct GNUNET_MQ_MessageHandler));
411 } 419 }
412 if (NULL != cb_cls) 420 if (NULL != cb_cls)
413 p->cb_cls = cb_cls; 421 p->cb_cls = cb_cls;
414 else 422 else
@@ -418,105 +426,105 @@ GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
418 p->start_cb_cls = start_cb_cls; 426 p->start_cb_cls = start_cb_cls;
419 else 427 else
420 p->start_cb_cls = p; 428 p->start_cb_cls = p;
421 GNUNET_CONTAINER_DLL_insert(tth->p_head, 429 GNUNET_CONTAINER_DLL_insert (tth->p_head,
422 tth->p_tail, 430 tth->p_tail,
423 p); 431 p);
424 432
425 /* Create configuration and call testing lib to modify it */ 433 /* Create configuration and call testing lib to modify it */
426 p->cfg = GNUNET_CONFIGURATION_create(); 434 p->cfg = GNUNET_CONFIGURATION_create ();
427 GNUNET_assert(GNUNET_OK == 435 GNUNET_assert (GNUNET_OK ==
428 GNUNET_CONFIGURATION_load(p->cfg, cfgname)); 436 GNUNET_CONFIGURATION_load (p->cfg, cfgname));
429 if (GNUNET_SYSERR == 437 if (GNUNET_SYSERR ==
430 GNUNET_TESTING_configuration_create(tth->tl_system, 438 GNUNET_TESTING_configuration_create (tth->tl_system,
431 p->cfg)) 439 p->cfg))
432 { 440 {
433 LOG(GNUNET_ERROR_TYPE_ERROR, 441 LOG (GNUNET_ERROR_TYPE_ERROR,
434 "Testing library failed to create unique configuration based on `%s'\n", 442 "Testing library failed to create unique configuration based on `%s'\n",
435 cfgname); 443 cfgname);
436 GNUNET_CONFIGURATION_destroy(p->cfg); 444 GNUNET_CONFIGURATION_destroy (p->cfg);
437 GNUNET_free(p); 445 GNUNET_free (p);
438 return NULL; 446 return NULL;
439 } 447 }
440 448
441 p->no = peer_id; 449 p->no = peer_id;
442 /* Configure peer with configuration */ 450 /* Configure peer with configuration */
443 p->peer = GNUNET_TESTING_peer_configure(tth->tl_system, 451 p->peer = GNUNET_TESTING_peer_configure (tth->tl_system,
444 p->cfg, 452 p->cfg,
445 p->no, 453 p->no,
446 NULL, 454 NULL,
447 &emsg); 455 &emsg);
448 if (NULL == p->peer) 456 if (NULL == p->peer)
449 { 457 {
450 LOG(GNUNET_ERROR_TYPE_ERROR, 458 LOG (GNUNET_ERROR_TYPE_ERROR,
451 "Testing library failed to create unique configuration based on `%s': `%s'\n", 459 "Testing library failed to create unique configuration based on `%s': `%s'\n",
452 cfgname, 460 cfgname,
453 emsg); 461 emsg);
454 GNUNET_TRANSPORT_TESTING_stop_peer(p); 462 GNUNET_TRANSPORT_TESTING_stop_peer (p);
455 GNUNET_free_non_null(emsg); 463 GNUNET_free_non_null (emsg);
456 return NULL; 464 return NULL;
457 } 465 }
458 GNUNET_free_non_null(emsg); 466 GNUNET_free_non_null (emsg);
459 if (GNUNET_OK != GNUNET_TESTING_peer_start(p->peer)) 467 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
460 { 468 {
461 LOG(GNUNET_ERROR_TYPE_ERROR, 469 LOG (GNUNET_ERROR_TYPE_ERROR,
462 "Testing library failed to create unique configuration based on `%s'\n", 470 "Testing library failed to create unique configuration based on `%s'\n",
463 cfgname); 471 cfgname);
464 GNUNET_TRANSPORT_TESTING_stop_peer(p); 472 GNUNET_TRANSPORT_TESTING_stop_peer (p);
465 return NULL; 473 return NULL;
466 } 474 }
467 475
468 memset(&dummy, 476 memset (&dummy,
469 '\0', 477 '\0',
470 sizeof(dummy)); 478 sizeof(dummy));
471 GNUNET_TESTING_peer_get_identity(p->peer, 479 GNUNET_TESTING_peer_get_identity (p->peer,
472 &p->id); 480 &p->id);
473 if (0 == memcmp(&dummy, 481 if (0 == memcmp (&dummy,
474 &p->id, 482 &p->id,
475 sizeof(struct GNUNET_PeerIdentity))) 483 sizeof(struct GNUNET_PeerIdentity)))
476 { 484 {
477 LOG(GNUNET_ERROR_TYPE_ERROR, 485 LOG (GNUNET_ERROR_TYPE_ERROR,
478 "Testing library failed to obtain peer identity for peer %u\n", 486 "Testing library failed to obtain peer identity for peer %u\n",
479 p->no); 487 p->no);
480 GNUNET_TRANSPORT_TESTING_stop_peer(p); 488 GNUNET_TRANSPORT_TESTING_stop_peer (p);
481 return NULL; 489 return NULL;
482 } 490 }
483 LOG(GNUNET_ERROR_TYPE_DEBUG, 491 LOG (GNUNET_ERROR_TYPE_DEBUG,
484 "Peer %u configured with identity `%s'\n", 492 "Peer %u configured with identity `%s'\n",
485 p->no, 493 p->no,
486 GNUNET_i2s_full(&p->id)); 494 GNUNET_i2s_full (&p->id));
487 p->tmh = GNUNET_TRANSPORT_manipulation_connect(p->cfg); 495 p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg);
488 p->th = GNUNET_TRANSPORT_core_connect(p->cfg, 496 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
489 NULL, 497 NULL,
490 handlers, 498 handlers,
491 p, 499 p,
492 &notify_connect, 500 &notify_connect,
493 &notify_disconnect, 501 &notify_disconnect,
494 NULL); 502 NULL);
495 if ((NULL == p->th) || 503 if ((NULL == p->th) ||
496 (NULL == p->tmh)) 504 (NULL == p->tmh))
497 { 505 {
498 LOG(GNUNET_ERROR_TYPE_ERROR, 506 LOG (GNUNET_ERROR_TYPE_ERROR,
499 "Failed to connect to transport service for peer `%s': `%s'\n", 507 "Failed to connect to transport service for peer `%s': `%s'\n",
500 cfgname, 508 cfgname,
501 emsg); 509 emsg);
502 GNUNET_TRANSPORT_TESTING_stop_peer(p); 510 GNUNET_TRANSPORT_TESTING_stop_peer (p);
503 return NULL; 511 return NULL;
504 } 512 }
505 p->ats = GNUNET_ATS_connectivity_init(p->cfg); 513 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
506 if (NULL == p->ats) 514 if (NULL == p->ats)
507 { 515 {
508 LOG(GNUNET_ERROR_TYPE_ERROR, 516 LOG (GNUNET_ERROR_TYPE_ERROR,
509 "Failed to connect to ATS service for peer `%s': `%s'\n", 517 "Failed to connect to ATS service for peer `%s': `%s'\n",
510 cfgname, 518 cfgname,
511 emsg); 519 emsg);
512 GNUNET_TRANSPORT_TESTING_stop_peer(p); 520 GNUNET_TRANSPORT_TESTING_stop_peer (p);
513 return NULL; 521 return NULL;
514 } 522 }
515 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, 523 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
516 GNUNET_TRANSPORT_AC_ANY, 524 GNUNET_TRANSPORT_AC_ANY,
517 &get_hello, 525 &get_hello,
518 p); 526 p);
519 GNUNET_assert(NULL != p->ghh); 527 GNUNET_assert (NULL != p->ghh);
520 return p; 528 return p;
521} 529}
522 530
@@ -530,89 +538,90 @@ GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
530 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 538 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
531 */ 539 */
532int 540int
533GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 541GNUNET_TRANSPORT_TESTING_restart_peer (struct
534 GNUNET_SCHEDULER_TaskCallback restart_cb, 542 GNUNET_TRANSPORT_TESTING_PeerContext *p,
535 void *restart_cb_cls) 543 GNUNET_SCHEDULER_TaskCallback restart_cb,
544 void *restart_cb_cls)
536{ 545{
537 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 546 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
538 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 547 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
539 548
540 /* shutdown */ 549 /* shutdown */
541 LOG(GNUNET_ERROR_TYPE_DEBUG, 550 LOG (GNUNET_ERROR_TYPE_DEBUG,
542 "Stopping peer %u (`%s')\n", 551 "Stopping peer %u (`%s')\n",
543 p->no, 552 p->no,
544 GNUNET_i2s(&p->id)); 553 GNUNET_i2s (&p->id));
545 if (NULL != p->ghh) 554 if (NULL != p->ghh)
546 { 555 {
547 GNUNET_TRANSPORT_hello_get_cancel(p->ghh); 556 GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
548 p->ghh = NULL; 557 p->ghh = NULL;
549 } 558 }
550 if (NULL != p->th) 559 if (NULL != p->th)
551 { 560 {
552 GNUNET_TRANSPORT_core_disconnect(p->th); 561 GNUNET_TRANSPORT_core_disconnect (p->th);
553 p->th = NULL; 562 p->th = NULL;
554 } 563 }
555 if (NULL != p->tmh) 564 if (NULL != p->tmh)
556 { 565 {
557 GNUNET_TRANSPORT_manipulation_disconnect(p->tmh); 566 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
558 p->tmh = NULL; 567 p->tmh = NULL;
559 } 568 }
560 for (cc = p->tth->cc_head; NULL != cc; cc = ccn) 569 for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
561 { 570 {
562 ccn = cc->next; 571 ccn = cc->next;
563 if ((cc->p1 == p) || 572 if ((cc->p1 == p) ||
564 (cc->p2 == p)) 573 (cc->p2 == p))
565 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 574 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
566 } 575 }
567 if (NULL != p->ats) 576 if (NULL != p->ats)
568 { 577 {
569 GNUNET_ATS_connectivity_done(p->ats); 578 GNUNET_ATS_connectivity_done (p->ats);
570 p->ats = NULL; 579 p->ats = NULL;
571 } 580 }
572 if (GNUNET_SYSERR == 581 if (GNUNET_SYSERR ==
573 GNUNET_TESTING_peer_stop(p->peer)) 582 GNUNET_TESTING_peer_stop (p->peer))
574 { 583 {
575 LOG(GNUNET_ERROR_TYPE_ERROR, 584 LOG (GNUNET_ERROR_TYPE_ERROR,
576 "Failed to stop peer %u (`%s')\n", 585 "Failed to stop peer %u (`%s')\n",
577 p->no, 586 p->no,
578 GNUNET_i2s(&p->id)); 587 GNUNET_i2s (&p->id));
579 return GNUNET_SYSERR; 588 return GNUNET_SYSERR;
580 } 589 }
581 590
582 sleep(5); // YUCK! 591 sleep (5); // YUCK!
583 592
584 LOG(GNUNET_ERROR_TYPE_DEBUG, 593 LOG (GNUNET_ERROR_TYPE_DEBUG,
585 "Restarting peer %u (`%s')\n", 594 "Restarting peer %u (`%s')\n",
586 p->no, 595 p->no,
587 GNUNET_i2s(&p->id)); 596 GNUNET_i2s (&p->id));
588 /* restart */ 597 /* restart */
589 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start(p->peer)) 598 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start (p->peer))
590 { 599 {
591 LOG(GNUNET_ERROR_TYPE_ERROR, 600 LOG (GNUNET_ERROR_TYPE_ERROR,
592 "Failed to restart peer %u (`%s')\n", 601 "Failed to restart peer %u (`%s')\n",
593 p->no, 602 p->no,
594 GNUNET_i2s(&p->id)); 603 GNUNET_i2s (&p->id));
595 return GNUNET_SYSERR; 604 return GNUNET_SYSERR;
596 } 605 }
597 606
598 GNUNET_assert(NULL == p->start_cb); 607 GNUNET_assert (NULL == p->start_cb);
599 p->start_cb = restart_cb; 608 p->start_cb = restart_cb;
600 p->start_cb_cls = restart_cb_cls; 609 p->start_cb_cls = restart_cb_cls;
601 610
602 p->th = GNUNET_TRANSPORT_core_connect(p->cfg, 611 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
603 NULL, 612 NULL,
604 p->handlers, 613 p->handlers,
605 p, 614 p,
606 &notify_connect, 615 &notify_connect,
607 &notify_disconnect, 616 &notify_disconnect,
608 NULL); 617 NULL);
609 GNUNET_assert(NULL != p->th); 618 GNUNET_assert (NULL != p->th);
610 p->ats = GNUNET_ATS_connectivity_init(p->cfg); 619 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
611 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, 620 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
612 GNUNET_TRANSPORT_AC_ANY, 621 GNUNET_TRANSPORT_AC_ANY,
613 &get_hello, 622 &get_hello,
614 p); 623 p);
615 GNUNET_assert(NULL != p->ghh); 624 GNUNET_assert (NULL != p->ghh);
616 return GNUNET_OK; 625 return GNUNET_OK;
617} 626}
618 627
@@ -623,75 +632,76 @@ GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContex
623 * @param p the peer 632 * @param p the peer
624 */ 633 */
625void 634void
626GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p) 635GNUNET_TRANSPORT_TESTING_stop_peer (struct
636 GNUNET_TRANSPORT_TESTING_PeerContext *p)
627{ 637{
628 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 638 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
629 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 639 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
630 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 640 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
631 641
632 for (cc = tth->cc_head; NULL != cc; cc = ccn) 642 for (cc = tth->cc_head; NULL != cc; cc = ccn)
633 { 643 {
634 ccn = cc->next; 644 ccn = cc->next;
635 if ((cc->p1 == p) || 645 if ((cc->p1 == p) ||
636 (cc->p2 == p)) 646 (cc->p2 == p))
637 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 647 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
638 } 648 }
639 if (NULL != p->ghh) 649 if (NULL != p->ghh)
640 { 650 {
641 GNUNET_TRANSPORT_hello_get_cancel(p->ghh); 651 GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
642 p->ghh = NULL; 652 p->ghh = NULL;
643 } 653 }
644 if (NULL != p->tmh) 654 if (NULL != p->tmh)
645 { 655 {
646 GNUNET_TRANSPORT_manipulation_disconnect(p->tmh); 656 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
647 p->tmh = NULL; 657 p->tmh = NULL;
648 } 658 }
649 if (NULL != p->th) 659 if (NULL != p->th)
650 { 660 {
651 GNUNET_TRANSPORT_core_disconnect(p->th); 661 GNUNET_TRANSPORT_core_disconnect (p->th);
652 p->th = NULL; 662 p->th = NULL;
653 } 663 }
654 if (NULL != p->peer) 664 if (NULL != p->peer)
665 {
666 if (GNUNET_OK !=
667 GNUNET_TESTING_peer_stop (p->peer))
655 { 668 {
656 if (GNUNET_OK != 669 LOG (GNUNET_ERROR_TYPE_DEBUG,
657 GNUNET_TESTING_peer_stop(p->peer)) 670 "Testing lib failed to stop peer %u (`%s')\n",
658 { 671 p->no,
659 LOG(GNUNET_ERROR_TYPE_DEBUG, 672 GNUNET_i2s (&p->id));
660 "Testing lib failed to stop peer %u (`%s')\n",
661 p->no,
662 GNUNET_i2s(&p->id));
663 }
664 GNUNET_TESTING_peer_destroy(p->peer);
665 p->peer = NULL;
666 } 673 }
674 GNUNET_TESTING_peer_destroy (p->peer);
675 p->peer = NULL;
676 }
667 if (NULL != p->ats) 677 if (NULL != p->ats)
668 { 678 {
669 GNUNET_ATS_connectivity_done(p->ats); 679 GNUNET_ATS_connectivity_done (p->ats);
670 p->ats = NULL; 680 p->ats = NULL;
671 } 681 }
672 if (NULL != p->hello) 682 if (NULL != p->hello)
673 { 683 {
674 GNUNET_free(p->hello); 684 GNUNET_free (p->hello);
675 p->hello = NULL; 685 p->hello = NULL;
676 } 686 }
677 if (NULL != p->cfg) 687 if (NULL != p->cfg)
678 { 688 {
679 GNUNET_CONFIGURATION_destroy(p->cfg); 689 GNUNET_CONFIGURATION_destroy (p->cfg);
680 p->cfg = NULL; 690 p->cfg = NULL;
681 } 691 }
682 if (NULL != p->handlers) 692 if (NULL != p->handlers)
683 { 693 {
684 GNUNET_free(p->handlers); 694 GNUNET_free (p->handlers);
685 p->handlers = NULL; 695 p->handlers = NULL;
686 } 696 }
687 GNUNET_CONTAINER_DLL_remove(tth->p_head, 697 GNUNET_CONTAINER_DLL_remove (tth->p_head,
688 tth->p_tail, 698 tth->p_tail,
689 p); 699 p);
690 LOG(GNUNET_ERROR_TYPE_DEBUG, 700 LOG (GNUNET_ERROR_TYPE_DEBUG,
691 "Peer %u (`%s') stopped\n", 701 "Peer %u (`%s') stopped\n",
692 p->no, 702 p->no,
693 GNUNET_i2s(&p->id)); 703 GNUNET_i2s (&p->id));
694 GNUNET_free(p); 704 GNUNET_free (p);
695} 705}
696 706
697 707
@@ -700,14 +710,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *
700 * transport service. 710 * transport service.
701 */ 711 */
702static void 712static void
703hello_offered(void *cls) 713hello_offered (void *cls)
704{ 714{
705 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; 715 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
706 716
707 cc->oh = NULL; 717 cc->oh = NULL;
708 cc->tct = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 718 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
709 &offer_hello, 719 &offer_hello,
710 cc); 720 cc);
711} 721}
712 722
713 723
@@ -717,7 +727,7 @@ hello_offered(void *cls)
717 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` 727 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
718 */ 728 */
719static void 729static void
720offer_hello(void *cls) 730offer_hello (void *cls)
721{ 731{
722 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; 732 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
723 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1; 733 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1;
@@ -725,25 +735,26 @@ offer_hello(void *cls)
725 735
726 cc->tct = NULL; 736 cc->tct = NULL;
727 { 737 {
728 char *p2_s = GNUNET_strdup(GNUNET_i2s(&p2->id)); 738 char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
729 739
730 LOG(GNUNET_ERROR_TYPE_DEBUG, 740 LOG (GNUNET_ERROR_TYPE_DEBUG,
731 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", 741 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
732 p1->no, 742 p1->no,
733 GNUNET_i2s(&p1->id), 743 GNUNET_i2s (&p1->id),
734 p2->no, 744 p2->no,
735 p2_s, 745 p2_s,
736 GNUNET_HELLO_size(cc->p2->hello)); 746 GNUNET_HELLO_size (cc->p2->hello));
737 GNUNET_free(p2_s); 747 GNUNET_free (p2_s);
738 } 748 }
739 749
740 if (NULL != cc->oh) 750 if (NULL != cc->oh)
741 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); 751 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh);
742 cc->oh = 752 cc->oh =
743 GNUNET_TRANSPORT_offer_hello(cc->p1->cfg, 753 GNUNET_TRANSPORT_offer_hello (cc->p1->cfg,
744 (const struct GNUNET_MessageHeader *)cc->p2->hello, 754 (const struct
745 &hello_offered, 755 GNUNET_MessageHeader *) cc->p2->hello,
746 cc); 756 &hello_offered,
757 cc);
747} 758}
748 759
749 760
@@ -760,10 +771,12 @@ offer_hello(void *cls)
760 * @return a connect request handle 771 * @return a connect request handle
761 */ 772 */
762struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 773struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
763GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 774GNUNET_TRANSPORT_TESTING_connect_peers (struct
764 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 775 GNUNET_TRANSPORT_TESTING_PeerContext *p1,
765 GNUNET_SCHEDULER_TaskCallback cb, 776 struct
766 void *cls) 777 GNUNET_TRANSPORT_TESTING_PeerContext *p2,
778 GNUNET_SCHEDULER_TaskCallback cb,
779 void *cls)
767{ 780{
768 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; 781 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
769 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 782 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
@@ -771,16 +784,16 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte
771 784
772 ccn = NULL; 785 ccn = NULL;
773 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 786 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
787 {
788 if ((cc->p1 == p1) &&
789 (cc->p2 == p2))
774 { 790 {
775 if ((cc->p1 == p1) && 791 ccn = cc;
776 (cc->p2 == p2)) 792 break;
777 {
778 ccn = cc;
779 break;
780 }
781 } 793 }
794 }
782 795
783 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 796 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
784 cc->p1 = p1; 797 cc->p1 = p1;
785 cc->p2 = p2; 798 cc->p2 = p2;
786 cc->cb = cb; 799 cc->cb = cb;
@@ -789,22 +802,22 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte
789 else 802 else
790 cc->cb_cls = cc; 803 cc->cb_cls = cc;
791 if (NULL != ccn) 804 if (NULL != ccn)
792 { 805 {
793 cc->p1_c = ccn->p1_c; 806 cc->p1_c = ccn->p1_c;
794 cc->p2_c = ccn->p2_c; 807 cc->p2_c = ccn->p2_c;
795 cc->connected = ccn->connected; 808 cc->connected = ccn->connected;
796 } 809 }
797 GNUNET_CONTAINER_DLL_insert(tth->cc_head, 810 GNUNET_CONTAINER_DLL_insert (tth->cc_head,
798 tth->cc_tail, 811 tth->cc_tail,
799 cc); 812 cc);
800 cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello, 813 cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello,
801 cc); 814 cc);
802 cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats, 815 cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats,
803 &p2->id, 816 &p2->id,
804 1); 817 1);
805 LOG(GNUNET_ERROR_TYPE_DEBUG, 818 LOG (GNUNET_ERROR_TYPE_DEBUG,
806 "New connect request %p\n", 819 "New connect request %p\n",
807 cc); 820 cc);
808 return cc; 821 return cc;
809} 822}
810 823
@@ -817,31 +830,33 @@ GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerConte
817 * @param cc a connect request handle 830 * @param cc a connect request handle
818 */ 831 */
819void 832void
820GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) 833GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct
834 GNUNET_TRANSPORT_TESTING_ConnectRequest
835 *cc)
821{ 836{
822 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth; 837 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
823 838
824 LOG(GNUNET_ERROR_TYPE_DEBUG, 839 LOG (GNUNET_ERROR_TYPE_DEBUG,
825 "Canceling connect request!\n"); 840 "Canceling connect request!\n");
826 if (NULL != cc->tct) 841 if (NULL != cc->tct)
827 { 842 {
828 GNUNET_SCHEDULER_cancel(cc->tct); 843 GNUNET_SCHEDULER_cancel (cc->tct);
829 cc->tct = NULL; 844 cc->tct = NULL;
830 } 845 }
831 if (NULL != cc->oh) 846 if (NULL != cc->oh)
832 { 847 {
833 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh); 848 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh);
834 cc->oh = NULL; 849 cc->oh = NULL;
835 } 850 }
836 if (NULL != cc->ats_sh) 851 if (NULL != cc->ats_sh)
837 { 852 {
838 GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh); 853 GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh);
839 cc->ats_sh = NULL; 854 cc->ats_sh = NULL;
840 } 855 }
841 GNUNET_CONTAINER_DLL_remove(tth->cc_head, 856 GNUNET_CONTAINER_DLL_remove (tth->cc_head,
842 tth->cc_tail, 857 tth->cc_tail,
843 cc); 858 cc);
844 GNUNET_free(cc); 859 GNUNET_free (cc);
845} 860}
846 861
847 862
@@ -851,7 +866,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_Co
851 * @param tth transport testing handle 866 * @param tth transport testing handle
852 */ 867 */
853void 868void
854GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth) 869GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth)
855{ 870{
856 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 871 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
857 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct; 872 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct;
@@ -862,26 +877,26 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
862 return; 877 return;
863 cc = tth->cc_head; 878 cc = tth->cc_head;
864 while (NULL != cc) 879 while (NULL != cc)
865 { 880 {
866 ct = cc->next; 881 ct = cc->next;
867 LOG(GNUNET_ERROR_TYPE_ERROR, 882 LOG (GNUNET_ERROR_TYPE_ERROR,
868 "Developer forgot to cancel connect request!\n"); 883 "Developer forgot to cancel connect request!\n");
869 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 884 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
870 cc = ct; 885 cc = ct;
871 } 886 }
872 p = tth->p_head; 887 p = tth->p_head;
873 while (NULL != p) 888 while (NULL != p)
874 { 889 {
875 t = p->next; 890 t = p->next;
876 LOG(GNUNET_ERROR_TYPE_ERROR, 891 LOG (GNUNET_ERROR_TYPE_ERROR,
877 "Developer forgot to stop peer!\n"); 892 "Developer forgot to stop peer!\n");
878 GNUNET_TRANSPORT_TESTING_stop_peer(p); 893 GNUNET_TRANSPORT_TESTING_stop_peer (p);
879 p = t; 894 p = t;
880 } 895 }
881 GNUNET_TESTING_system_destroy(tth->tl_system, 896 GNUNET_TESTING_system_destroy (tth->tl_system,
882 GNUNET_YES); 897 GNUNET_YES);
883 898
884 GNUNET_free(tth); 899 GNUNET_free (tth);
885} 900}
886 901
887 902
@@ -891,22 +906,22 @@ GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
891 * @return transport testing handle 906 * @return transport testing handle
892 */ 907 */
893struct GNUNET_TRANSPORT_TESTING_Handle * 908struct GNUNET_TRANSPORT_TESTING_Handle *
894GNUNET_TRANSPORT_TESTING_init() 909GNUNET_TRANSPORT_TESTING_init ()
895{ 910{
896 struct GNUNET_TRANSPORT_TESTING_Handle *tth; 911 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
897 912
898 tth = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_Handle); 913 tth = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_Handle);
899 tth->tl_system = GNUNET_TESTING_system_create("transport-testing", 914 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
900 NULL, 915 NULL,
901 NULL, 916 NULL,
902 NULL); 917 NULL);
903 if (NULL == tth->tl_system) 918 if (NULL == tth->tl_system)
904 { 919 {
905 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 920 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
906 "Failed to initialize testing library!\n"); 921 "Failed to initialize testing library!\n");
907 GNUNET_free(tth); 922 GNUNET_free (tth);
908 return NULL; 923 return NULL;
909 } 924 }
910 return tth; 925 return tth;
911} 926}
912 927