diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/transport/test_transport_api_disconnect.c | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/transport/test_transport_api_disconnect.c')
-rw-r--r-- | src/transport/test_transport_api_disconnect.c | 98 |
1 files changed, 48 insertions, 50 deletions
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index 0be922e93..f97c449fc 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c | |||
@@ -71,7 +71,7 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | |||
71 | 71 | ||
72 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 72 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
73 | 73 | ||
74 | struct GNUNET_TRANSPORT_TESTING_handle * tth; | 74 | struct GNUNET_TRANSPORT_TESTING_handle *tth; |
75 | 75 | ||
76 | int shutdown_; | 76 | int shutdown_; |
77 | 77 | ||
@@ -148,9 +148,11 @@ static void | |||
148 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 148 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
149 | { | 149 | { |
150 | struct PeerContext *p = cls; | 150 | struct PeerContext *p = cls; |
151 | char * ps = strdup (GNUNET_i2s(&p->id)); | 151 | char *ps = strdup (GNUNET_i2s (&p->id)); |
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", | 152 | |
153 | p->no, ps, GNUNET_i2s (peer)); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, | ||
155 | GNUNET_i2s (peer)); | ||
154 | 156 | ||
155 | if (th != NULL) | 157 | if (th != NULL) |
156 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 158 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
@@ -158,8 +160,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
158 | 160 | ||
159 | if (shutdown_ == GNUNET_YES) | 161 | if (shutdown_ == GNUNET_YES) |
160 | { | 162 | { |
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); | 163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); |
162 | GNUNET_SCHEDULER_add_now (&end, NULL); | 164 | GNUNET_SCHEDULER_add_now (&end, NULL); |
163 | } | 165 | } |
164 | } | 166 | } |
165 | 167 | ||
@@ -170,12 +172,12 @@ stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
170 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 172 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
171 | return; | 173 | return; |
172 | 174 | ||
173 | struct PeerContext * p = cls; | 175 | struct PeerContext *p = cls; |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", | 176 | |
175 | p->no, | 177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", p->no, |
176 | GNUNET_i2s (&p->id)); | 178 | GNUNET_i2s (&p->id)); |
177 | shutdown_ = GNUNET_YES; | 179 | shutdown_ = GNUNET_YES; |
178 | GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2); | 180 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
179 | p2 = NULL; | 181 | p2 = NULL; |
180 | GNUNET_assert (p2 == NULL); | 182 | GNUNET_assert (p2 == NULL); |
181 | } | 183 | } |
@@ -183,10 +185,9 @@ stop_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
183 | static void | 185 | static void |
184 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 186 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
185 | const struct GNUNET_MessageHeader *message, | 187 | const struct GNUNET_MessageHeader *message, |
186 | const struct GNUNET_ATS_Information *ats, | 188 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
187 | uint32_t ats_count) | ||
188 | { | 189 | { |
189 | struct PeerContext * p = cls; | 190 | struct PeerContext *p = cls; |
190 | struct PeerContext *t = NULL; | 191 | struct PeerContext *t = NULL; |
191 | 192 | ||
192 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | 193 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) |
@@ -195,17 +196,18 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
195 | t = p2; | 196 | t = p2; |
196 | GNUNET_assert (t != NULL); | 197 | GNUNET_assert (t != NULL); |
197 | 198 | ||
198 | char * ps = strdup (GNUNET_i2s(&p->id)); | 199 | char *ps = strdup (GNUNET_i2s (&p->id)); |
199 | 200 | ||
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 202 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", |
202 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); | 203 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, |
204 | GNUNET_i2s (&t->id)); | ||
203 | 205 | ||
204 | if ((MTYPE == ntohs (message->type)) && | 206 | if ((MTYPE == ntohs (message->type)) && |
205 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 207 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
206 | { | 208 | { |
207 | ok = 1; | 209 | ok = 1; |
208 | GNUNET_SCHEDULER_add_now(stop_peer, p2); | 210 | GNUNET_SCHEDULER_add_now (stop_peer, p2); |
209 | return; | 211 | return; |
210 | } | 212 | } |
211 | } | 213 | } |
@@ -238,13 +240,12 @@ notify_ready (void *cls, size_t size, void *buf) | |||
238 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | 240 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); |
239 | hdr->type = htons (MTYPE); | 241 | hdr->type = htons (MTYPE); |
240 | } | 242 | } |
241 | char * ps = strdup (GNUNET_i2s(&p2->id)); | 243 | char *ps = strdup (GNUNET_i2s (&p2->id)); |
244 | |||
242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
243 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | 246 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", |
244 | p2->no, | 247 | p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, |
245 | ps, | 248 | GNUNET_i2s (&p->id)); |
246 | ntohs (hdr->type), | ||
247 | ntohs (hdr->size), p->no, GNUNET_i2s (&p->id)); | ||
248 | GNUNET_free (ps); | 249 | GNUNET_free (ps); |
249 | return sizeof (struct GNUNET_MessageHeader); | 250 | return sizeof (struct GNUNET_MessageHeader); |
250 | } | 251 | } |
@@ -257,11 +258,11 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
257 | 258 | ||
258 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 259 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
259 | return; | 260 | return; |
260 | char * receiver_s = strdup(GNUNET_i2s (&p1->id)); | 261 | char *receiver_s = strdup (GNUNET_i2s (&p1->id)); |
262 | |||
261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
262 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 264 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
263 | p2->no, | 265 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); |
264 | GNUNET_i2s (&p2->id), p1->no, receiver_s); | ||
265 | GNUNET_free (receiver_s); | 266 | GNUNET_free (receiver_s); |
266 | 267 | ||
267 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, | 268 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, |
@@ -272,10 +273,10 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
272 | 273 | ||
273 | static void | 274 | static void |
274 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 275 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
275 | const struct GNUNET_ATS_Information *ats, | 276 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
276 | uint32_t ats_count) | ||
277 | { | 277 | { |
278 | static int c; | 278 | static int c; |
279 | |||
279 | c++; | 280 | c++; |
280 | struct PeerContext *p = cls; | 281 | struct PeerContext *p = cls; |
281 | struct PeerContext *t = NULL; | 282 | struct PeerContext *t = NULL; |
@@ -284,11 +285,12 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
284 | t = p1; | 285 | t = p1; |
285 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | 286 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) |
286 | t = p2; | 287 | t = p2; |
287 | GNUNET_assert (t!=NULL); | 288 | GNUNET_assert (t != NULL); |
289 | |||
290 | char *ps = strdup (GNUNET_i2s (&p->id)); | ||
288 | 291 | ||
289 | char * ps = strdup (GNUNET_i2s(&p->id)); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", | 293 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, |
291 | p->no, ps, | ||
292 | t->no, GNUNET_i2s (peer)); | 294 | t->no, GNUNET_i2s (peer)); |
293 | GNUNET_free (ps); | 295 | GNUNET_free (ps); |
294 | } | 296 | } |
@@ -301,8 +303,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
301 | char *p1_c = strdup (GNUNET_i2s (&p1->id)); | 303 | char *p1_c = strdup (GNUNET_i2s (&p1->id)); |
302 | 304 | ||
303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | 305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", |
304 | p1->no, p1_c, | 306 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); |
305 | p2->no, GNUNET_i2s (&p2->id)); | ||
306 | GNUNET_free (p1_c); | 307 | GNUNET_free (p1_c); |
307 | 308 | ||
308 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 309 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
@@ -310,23 +311,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
310 | 311 | ||
311 | 312 | ||
312 | 313 | ||
313 | void start_cb (struct PeerContext * p, | 314 | void |
314 | void *cls) | 315 | start_cb (struct PeerContext *p, void *cls) |
315 | { | 316 | { |
316 | static int started; | 317 | static int started; |
318 | |||
317 | started++; | 319 | started++; |
318 | 320 | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", | 321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, |
320 | p->no, | 322 | GNUNET_i2s (&p->id)); |
321 | GNUNET_i2s (&p->id)); | ||
322 | 323 | ||
323 | if (started != 2) | 324 | if (started != 2) |
324 | return; | 325 | return; |
325 | 326 | ||
326 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); | 327 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); |
327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 328 | |
328 | p1->no, sender_c, | 329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
329 | p2->no, GNUNET_i2s (&p2->id)); | 330 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", |
331 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
330 | 332 | ||
331 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | 333 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
332 | NULL); | 334 | NULL); |
@@ -340,17 +342,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
340 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 342 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
341 | 343 | ||
342 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | 344 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
343 | ¬ify_receive, | 345 | ¬ify_receive, ¬ify_connect, |
344 | ¬ify_connect, | 346 | ¬ify_disconnect, &start_cb, |
345 | ¬ify_disconnect, | 347 | NULL); |
346 | &start_cb, | ||
347 | NULL); | ||
348 | 348 | ||
349 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | 349 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, |
350 | ¬ify_receive, | 350 | ¬ify_receive, ¬ify_connect, |
351 | ¬ify_connect, | 351 | ¬ify_disconnect, &start_cb, |
352 | ¬ify_disconnect, | ||
353 | &start_cb, | ||
354 | NULL); | 352 | NULL); |
355 | 353 | ||
356 | if ((p1 == NULL) || (p2 == NULL)) | 354 | if ((p1 == NULL) || (p2 == NULL)) |