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