diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-12 08:08:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-12 08:08:17 +0000 |
commit | a00afbdaae8de7fd752aab1ed5028833a85eeea7 (patch) | |
tree | 7f332838143653bf2bc7e4f3969ef9e8e43a03b7 | |
parent | 6bfa05291c469d0aba00e85456ceadf8b433601c (diff) | |
download | gnunet-a00afbdaae8de7fd752aab1ed5028833a85eeea7.tar.gz gnunet-a00afbdaae8de7fd752aab1ed5028833a85eeea7.zip |
more transport testing hacking
21 files changed, 316 insertions, 608 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 067d12f4d..6c1eff093 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -406,10 +406,15 @@ src/transport/plugin_transport_wlan.c | |||
406 | src/transport/transport_api_address_to_string.c | 406 | src/transport/transport_api_address_to_string.c |
407 | src/transport/transport_api_blacklist.c | 407 | src/transport/transport_api_blacklist.c |
408 | src/transport/transport_api.c | 408 | src/transport/transport_api.c |
409 | src/transport/transport_api_core.c | ||
410 | src/transport/transport_api_get_hello.c | ||
409 | src/transport/transport_api_monitor_peers.c | 411 | src/transport/transport_api_monitor_peers.c |
410 | src/transport/transport_api_monitor_plugins.c | 412 | src/transport/transport_api_monitor_plugins.c |
411 | src/transport/transport_api_monitor_validation.c | 413 | src/transport/transport_api_offer_hello.c |
412 | src/transport/transport-testing.c | 414 | src/transport/transport-testing.c |
415 | src/transport/transport-testing-filenames.c | ||
416 | src/transport/transport-testing-loggers.c | ||
417 | src/transport/transport-testing-main.c | ||
413 | src/tun/regex.c | 418 | src/tun/regex.c |
414 | src/tun/tun.c | 419 | src/tun/tun.c |
415 | src/util/bandwidth.c | 420 | src/util/bandwidth.c |
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index af6438bb2..a074d132a 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -472,10 +472,11 @@ handle_store (void *cls, struct GNUNET_SERVER_Client *client, | |||
472 | return; | 472 | return; |
473 | } | 473 | } |
474 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 474 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
475 | "Received a store request (size: %lu).\n" " Sub system `%s'\n" | 475 | "Received a store request (size: %u). Sub system `%s' Peer `%s Key `%s' Options: %d.\n", |
476 | " Peer `%s'\n" " Key `%s'\n" " Value size %lu\n" | 476 | (unsigned int) record->value_size, |
477 | " Options: %d.\n", record->value_size, record->sub_system, | 477 | record->sub_system, |
478 | GNUNET_i2s (record->peer), record->key, record->value_size, | 478 | GNUNET_i2s (record->peer), |
479 | record->key, | ||
479 | ntohl (srm->options)); | 480 | ntohl (srm->options)); |
480 | record->client = client; | 481 | record->client = client; |
481 | if (GNUNET_OK != | 482 | if (GNUNET_OK != |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 2c6c7dfd8..767031e6f 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -509,7 +509,6 @@ AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PAT | |||
509 | TESTS = \ | 509 | TESTS = \ |
510 | test_transport_testing_startstop \ | 510 | test_transport_testing_startstop \ |
511 | test_transport_testing_restart \ | 511 | test_transport_testing_restart \ |
512 | test_transport_testing \ | ||
513 | test_plugin_tcp \ | 512 | test_plugin_tcp \ |
514 | test_plugin_udp \ | 513 | test_plugin_udp \ |
515 | $(UNIX_TEST) \ | 514 | $(UNIX_TEST) \ |
@@ -1266,6 +1265,8 @@ test_transport_api_timeout_tcp_peer1.conf\ | |||
1266 | test_transport_api_timeout_tcp_peer2.conf\ | 1265 | test_transport_api_timeout_tcp_peer2.conf\ |
1267 | test_transport_api_multi_peer1.conf\ | 1266 | test_transport_api_multi_peer1.conf\ |
1268 | test_transport_api_multi_peer2.conf\ | 1267 | test_transport_api_multi_peer2.conf\ |
1268 | test_transport_api_restart_1peer_peer1.conf\ | ||
1269 | test_transport_api_restart_1peer_peer2.conf\ | ||
1269 | test_transport_api_reliability_http_peer1.conf\ | 1270 | test_transport_api_reliability_http_peer1.conf\ |
1270 | test_transport_api_reliability_http_peer2.conf\ | 1271 | test_transport_api_reliability_http_peer2.conf\ |
1271 | test_transport_api_reliability_https_peer1.conf\ | 1272 | test_transport_api_reliability_https_peer1.conf\ |
@@ -1284,6 +1285,10 @@ test_transport_api_manipulation_recv_tcp_peer1.conf\ | |||
1284 | test_transport_api_manipulation_recv_tcp_peer2.conf\ | 1285 | test_transport_api_manipulation_recv_tcp_peer2.conf\ |
1285 | test_transport_api_manipulation_cfg_peer1.conf\ | 1286 | test_transport_api_manipulation_cfg_peer1.conf\ |
1286 | test_transport_api_manipulation_cfg_peer2.conf\ | 1287 | test_transport_api_manipulation_cfg_peer2.conf\ |
1288 | test_transport_api_restart_1peer_peer1.conf\ | ||
1289 | test_transport_api_restart_1peer_peer2.conf\ | ||
1290 | test_transport_api_restart_2peers_peer1.conf\ | ||
1291 | test_transport_api_restart_2peers_peer2.conf\ | ||
1287 | test_transport_api_tcp_nat_peer1.conf\ | 1292 | test_transport_api_tcp_nat_peer1.conf\ |
1288 | test_transport_api_tcp_nat_peer2.conf\ | 1293 | test_transport_api_tcp_nat_peer2.conf\ |
1289 | test_transport_api_tcp_peer1.conf\ | 1294 | test_transport_api_tcp_peer1.conf\ |
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 96e11b7de..198e82118 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -486,7 +486,7 @@ main (int argc, | |||
486 | { | 486 | { |
487 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 487 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
488 | .connect_continuation = &connected_cb, | 488 | .connect_continuation = &connected_cb, |
489 | .config_file = "test_transport_startonly.conf", | 489 | .config_file = "test_transport_api.conf", |
490 | .rec = ¬ify_receive, | 490 | .rec = ¬ify_receive, |
491 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 491 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
492 | .nd = ¬ify_disconnect, | 492 | .nd = ¬ify_disconnect, |
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index ad078f582..bc0061363 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -72,7 +72,7 @@ notify_receive (void *cls, | |||
72 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 72 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
73 | 73 | ||
74 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 74 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
75 | "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n", | 75 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
76 | receiver->no, | 76 | receiver->no, |
77 | ps, | 77 | ps, |
78 | ntohs (message->type), | 78 | ntohs (message->type), |
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c index 6948d3e6a..0b7fd645c 100644 --- a/src/transport/test_transport_api_limited_sockets.c +++ b/src/transport/test_transport_api_limited_sockets.c | |||
@@ -254,6 +254,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
254 | ¬ify_receive, | 254 | ¬ify_receive, |
255 | ¬ify_connect, | 255 | ¬ify_connect, |
256 | ¬ify_disconnect, | 256 | ¬ify_disconnect, |
257 | NULL, | ||
257 | &start_cb, | 258 | &start_cb, |
258 | NULL); | 259 | NULL); |
259 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 260 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
@@ -262,6 +263,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
262 | ¬ify_receive, | 263 | ¬ify_receive, |
263 | ¬ify_connect, | 264 | ¬ify_connect, |
264 | ¬ify_disconnect, | 265 | ¬ify_disconnect, |
266 | NULL, | ||
265 | &start_cb, | 267 | &start_cb, |
266 | NULL); | 268 | NULL); |
267 | if ((p1 == NULL) || (p2 == NULL)) | 269 | if ((p1 == NULL) || (p2 == NULL)) |
diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c index e814ad817..7a63ed16b 100644 --- a/src/transport/test_transport_api_restart_1peer.c +++ b/src/transport/test_transport_api_restart_1peer.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2015 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -37,116 +37,57 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
41 | 41 | ||
42 | #define MTYPE 12345 | 42 | #define MTYPE 12345 |
43 | 43 | ||
44 | static char *test_name; | ||
45 | 44 | ||
46 | static int ok; | 45 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
47 | |||
48 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
49 | |||
50 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
51 | 46 | ||
52 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | 47 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; |
53 | 48 | ||
54 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
55 | |||
56 | static int p1_connected; | 49 | static int p1_connected; |
57 | 50 | ||
58 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
59 | |||
60 | static int p2_connected; | 51 | static int p2_connected; |
61 | 52 | ||
62 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | ||
63 | |||
64 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 53 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
65 | 54 | ||
66 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 55 | static struct GNUNET_SCHEDULER_Task *send_task; |
67 | |||
68 | static char *cfg_file_p1; | ||
69 | |||
70 | static char *cfg_file_p2; | ||
71 | 56 | ||
72 | static int restarted; | 57 | static int restarted; |
73 | 58 | ||
74 | 59 | ||
75 | static void | 60 | static void |
76 | end () | 61 | custom_shutdown (void *cls) |
77 | { | 62 | { |
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Stopping peers\n"); | ||
80 | |||
81 | if (NULL != send_task) | ||
82 | { | ||
83 | GNUNET_SCHEDULER_cancel (send_task); | ||
84 | send_task = NULL; | ||
85 | } | ||
86 | if (NULL != ats_sh) | 63 | if (NULL != ats_sh) |
87 | { | 64 | { |
88 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | 65 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); |
89 | ats_sh = NULL; | 66 | ats_sh = NULL; |
90 | } | 67 | } |
91 | if (NULL != die_task) | ||
92 | { | ||
93 | GNUNET_SCHEDULER_cancel (die_task); | ||
94 | die_task = NULL; | ||
95 | } | ||
96 | if (NULL != th) | 68 | if (NULL != th) |
97 | { | 69 | { |
98 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 70 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
99 | th = NULL; | 71 | th = NULL; |
100 | } | 72 | } |
101 | if (NULL != p1) | 73 | if (NULL != send_task) |
102 | { | ||
103 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
104 | p1 = NULL; | ||
105 | } | ||
106 | if (NULL != p2) | ||
107 | { | ||
108 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
109 | p2 = NULL; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | |||
114 | static void | ||
115 | end_badly (void *cls) | ||
116 | { | ||
117 | die_task = NULL; | ||
118 | |||
119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
120 | "Fail! Stopping peers\n"); | ||
121 | |||
122 | if (restarted == GNUNET_YES) | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
124 | "Peer was restarted\n"); | ||
125 | |||
126 | if (restarted == GNUNET_NO) | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
128 | "Peer was NOT restarted\n"); | ||
129 | if (NULL != cc) | ||
130 | { | 74 | { |
131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 75 | GNUNET_SCHEDULER_cancel (send_task); |
132 | _("Fail! Could not connect peers\n")); | 76 | send_task = NULL; |
133 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
134 | cc = NULL; | ||
135 | } | 77 | } |
136 | end (); | ||
137 | ok = GNUNET_SYSERR; | ||
138 | } | 78 | } |
139 | 79 | ||
140 | 80 | ||
141 | static void | 81 | static void |
142 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | 82 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
83 | void *cls) | ||
143 | { | 84 | { |
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Restarted peer %u (`%4s'), issuing reconnect\n", | 86 | "Restarted peer %u (`%s'), issuing reconnect\n", |
146 | p->no, | 87 | p->no, |
147 | GNUNET_i2s (&p->id)); | 88 | GNUNET_i2s (&p->id)); |
148 | ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, | 89 | ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, |
149 | &p2->id, | 90 | &ccc->p[1]->id, |
150 | 1); | 91 | 1); |
151 | } | 92 | } |
152 | 93 | ||
@@ -155,81 +96,75 @@ static void | |||
155 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) | 96 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) |
156 | { | 97 | { |
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
158 | "Restarting peer %u (`%4s')\n", | 99 | "Restarting peer %u (`%s')\n", |
159 | p->no, | 100 | p->no, |
160 | GNUNET_i2s (&p->id)); | 101 | GNUNET_i2s (&p->id)); |
161 | GNUNET_TRANSPORT_TESTING_restart_peer (p, | 102 | GNUNET_assert (GNUNET_OK == |
162 | &restart_cb, | 103 | GNUNET_TRANSPORT_TESTING_restart_peer (p, |
163 | p); | 104 | &restart_cb, |
105 | p)); | ||
164 | } | 106 | } |
165 | 107 | ||
166 | 108 | ||
167 | static void | 109 | static void |
168 | notify_receive (void *cls, | 110 | notify_receive (void *cls, |
169 | const struct GNUNET_PeerIdentity *peer, | 111 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
112 | const struct GNUNET_PeerIdentity *sender, | ||
170 | const struct GNUNET_MessageHeader *message) | 113 | const struct GNUNET_MessageHeader *message) |
171 | { | 114 | { |
172 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 115 | { |
173 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | 116 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
174 | |||
175 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
176 | t = p1; | ||
177 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
178 | t = p2; | ||
179 | GNUNET_assert (t != NULL); | ||
180 | |||
181 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
182 | |||
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
184 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | ||
185 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | ||
186 | GNUNET_i2s (&t->id)); | ||
187 | GNUNET_free (ps); | ||
188 | 117 | ||
118 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
119 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", | ||
120 | receiver->no, | ||
121 | ps, | ||
122 | ntohs (message->type), | ||
123 | ntohs (message->size), | ||
124 | GNUNET_i2s (sender)); | ||
125 | GNUNET_free (ps); | ||
126 | } | ||
189 | if ((MTYPE == ntohs (message->type)) && | 127 | if ((MTYPE == ntohs (message->type)) && |
190 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 128 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
191 | { | 129 | { |
192 | if (restarted == GNUNET_NO) | 130 | if (GNUNET_NO == restarted) |
193 | { | 131 | { |
194 | restarted = GNUNET_YES; | 132 | restarted = GNUNET_YES; |
195 | restart (p1); | 133 | restart (ccc->p[0]); |
196 | return; | 134 | return; |
197 | } | 135 | } |
198 | else | 136 | else |
199 | { | 137 | { |
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | "Restarted peers connected and message was sent, stopping test...\n"); | 139 | "Restarted peers connected and message was sent, stopping test...\n"); |
202 | ok = 0; | 140 | ccc->global_ret = GNUNET_OK; |
203 | end (); | 141 | GNUNET_SCHEDULER_shutdown (); |
204 | } | 142 | } |
205 | } | 143 | } |
206 | else | 144 | else |
207 | { | 145 | { |
208 | GNUNET_break (0); | 146 | GNUNET_break (0); |
209 | ok = 1; | 147 | ccc->global_ret = GNUNET_SYSERR; |
210 | if (die_task != NULL) | 148 | GNUNET_SCHEDULER_shutdown (); |
211 | GNUNET_SCHEDULER_cancel (die_task); | ||
212 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
213 | } | 149 | } |
214 | } | 150 | } |
215 | 151 | ||
216 | 152 | ||
217 | static size_t | 153 | static size_t |
218 | notify_ready (void *cls, size_t size, void *buf) | 154 | notify_ready (void *cls, |
155 | size_t size, | ||
156 | void *buf) | ||
219 | { | 157 | { |
220 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 158 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
221 | struct GNUNET_MessageHeader *hdr; | 159 | struct GNUNET_MessageHeader *hdr; |
222 | 160 | ||
223 | th = NULL; | 161 | th = NULL; |
224 | |||
225 | if (NULL == buf) | 162 | if (NULL == buf) |
226 | { | 163 | { |
227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
228 | "Timeout occurred while waiting for transmit_ready\n"); | 165 | "Timeout occurred while waiting for transmit_ready\n"); |
229 | if (NULL != die_task) | 166 | GNUNET_SCHEDULER_shutdown (); |
230 | GNUNET_SCHEDULER_cancel (die_task); | 167 | ccc->global_ret = 42; |
231 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
232 | ok = 42; | ||
233 | return 0; | 168 | return 0; |
234 | } | 169 | } |
235 | 170 | ||
@@ -239,11 +174,12 @@ notify_ready (void *cls, size_t size, void *buf) | |||
239 | hdr->type = htons (MTYPE); | 174 | hdr->type = htons (MTYPE); |
240 | 175 | ||
241 | { | 176 | { |
242 | char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); | 177 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); |
178 | |||
243 | 179 | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
245 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | 181 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", |
246 | p2->no, | 182 | ccc->p[1]->no, |
247 | ps, | 183 | ps, |
248 | ntohs (hdr->type), | 184 | ntohs (hdr->type), |
249 | ntohs (hdr->size), | 185 | ntohs (hdr->size), |
@@ -259,212 +195,99 @@ static void | |||
259 | sendtask (void *cls) | 195 | sendtask (void *cls) |
260 | { | 196 | { |
261 | send_task = NULL; | 197 | send_task = NULL; |
262 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 198 | { |
263 | 199 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | |
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | |
265 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
266 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); | 202 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
267 | GNUNET_free (receiver_s); | 203 | ccc->p[1]->no, |
268 | 204 | GNUNET_i2s (&ccc->p[1]->id), | |
269 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | 205 | ccc->p[0]->no, |
270 | &p1->id, | 206 | receiver_s); |
207 | GNUNET_free (receiver_s); | ||
208 | } | ||
209 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
210 | &ccc->p[0]->id, | ||
271 | 256, | 211 | 256, |
272 | TIMEOUT_TRANSMIT, | 212 | TIMEOUT_TRANSMIT, |
273 | ¬ify_ready, | 213 | ¬ify_ready, |
274 | p1); | 214 | ccc->p[0]); |
275 | } | 215 | } |
276 | 216 | ||
277 | 217 | ||
278 | static void | 218 | static void |
279 | notify_connect (void *cls, | 219 | notify_connect (void *cls, |
280 | const struct GNUNET_PeerIdentity *peer) | 220 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
221 | const struct GNUNET_PeerIdentity *other) | ||
281 | { | 222 | { |
282 | static int c; | 223 | GNUNET_TRANSPORT_TESTING_log_connect (cls, |
283 | 224 | me, | |
284 | c++; | 225 | other); |
285 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 226 | if (0 == memcmp (other, |
286 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | 227 | &ccc->p[0]->id, |
287 | 228 | sizeof (struct GNUNET_PeerIdentity))) | |
288 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
289 | { | ||
290 | p1_connected = GNUNET_YES; | 229 | p1_connected = GNUNET_YES; |
291 | t = p1; | 230 | if (0 == memcmp (other, |
292 | } | 231 | &ccc->p[1]->id, |
293 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | 232 | sizeof (struct GNUNET_PeerIdentity))) |
294 | { | ||
295 | p2_connected = GNUNET_YES; | 233 | p2_connected = GNUNET_YES; |
296 | t = p2; | ||
297 | } | ||
298 | GNUNET_assert (t != NULL); | ||
299 | 234 | ||
300 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 235 | if ( (GNUNET_YES == restarted) && |
301 | 236 | (GNUNET_YES == p1_connected) && | |
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 237 | (GNUNET_YES == p2_connected) ) |
303 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, | ||
304 | t->no, GNUNET_i2s (peer)); | ||
305 | GNUNET_free (ps); | ||
306 | |||
307 | if ( (restarted == GNUNET_YES) && | ||
308 | (p1_connected == GNUNET_YES) && | ||
309 | (p2_connected == GNUNET_YES) ) | ||
310 | { | 238 | { |
311 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ | 239 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ |
312 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 240 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, |
241 | NULL); | ||
313 | } | 242 | } |
314 | } | 243 | } |
315 | 244 | ||
316 | 245 | ||
317 | static void | 246 | static void |
318 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 247 | notify_disconnect (void *cls, |
248 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
249 | const struct GNUNET_PeerIdentity *other) | ||
319 | { | 250 | { |
320 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 251 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
321 | 252 | me, | |
322 | if ( (NULL != p1) && | 253 | other); |
323 | (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))) | 254 | if (me == ccc->p[0]) |
324 | { | ||
325 | p1_connected = GNUNET_NO; | 255 | p1_connected = GNUNET_NO; |
326 | } | 256 | if (me == ccc->p[1]) |
327 | if ( (NULL != p2) && | ||
328 | (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))) | ||
329 | { | ||
330 | p2_connected = GNUNET_NO; | 257 | p2_connected = GNUNET_NO; |
331 | } | 258 | if (NULL != th) |
332 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 259 | { |
333 | |||
334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
335 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, | ||
336 | GNUNET_i2s (peer)); | ||
337 | GNUNET_free (ps); | ||
338 | |||
339 | if (th != NULL) | ||
340 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 260 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
341 | th = NULL; | 261 | th = NULL; |
262 | } | ||
342 | if (NULL != send_task) | 263 | if (NULL != send_task) |
343 | GNUNET_SCHEDULER_cancel (send_task); | ||
344 | send_task = NULL; | ||
345 | } | ||
346 | |||
347 | |||
348 | static void | ||
349 | testing_connect_cb (void *cls) | ||
350 | { | ||
351 | cc = NULL; | ||
352 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
353 | |||
354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
355 | "Peers connected: %u (%s) <-> %u (%s)\n", | ||
356 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
357 | GNUNET_free (p1_c); | ||
358 | |||
359 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
360 | } | ||
361 | |||
362 | |||
363 | |||
364 | static void | ||
365 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
366 | { | ||
367 | static int started; | ||
368 | |||
369 | started++; | ||
370 | |||
371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
372 | GNUNET_i2s (&p->id)); | ||
373 | |||
374 | if (started != 2) | ||
375 | return; | ||
376 | |||
377 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
378 | |||
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
380 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
381 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
382 | GNUNET_free (sender_c); | ||
383 | |||
384 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | ||
385 | p2, | ||
386 | &testing_connect_cb, | ||
387 | NULL); | ||
388 | |||
389 | } | ||
390 | |||
391 | static void | ||
392 | run (void *cls, char *const *args, const char *cfgfile, | ||
393 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
394 | { | ||
395 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
396 | p1_connected = GNUNET_NO; | ||
397 | p2_connected = GNUNET_NO; | ||
398 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
399 | cfg_file_p1, | ||
400 | 1, | ||
401 | ¬ify_receive, | ||
402 | ¬ify_connect, | ||
403 | ¬ify_disconnect, | ||
404 | &start_cb, | ||
405 | NULL); | ||
406 | |||
407 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
408 | cfg_file_p2, | ||
409 | 2, | ||
410 | ¬ify_receive, | ||
411 | ¬ify_connect, | ||
412 | ¬ify_disconnect, | ||
413 | &start_cb, | ||
414 | NULL); | ||
415 | |||
416 | if ((p1 == NULL) || (p2 == NULL)) | ||
417 | { | 264 | { |
418 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 265 | GNUNET_SCHEDULER_cancel (send_task); |
419 | "Fail! Could not start peers!\n"); | 266 | send_task = NULL; |
420 | if (die_task != NULL) | ||
421 | GNUNET_SCHEDULER_cancel (die_task); | ||
422 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, | ||
423 | NULL); | ||
424 | return; | ||
425 | } | 267 | } |
426 | } | 268 | } |
427 | 269 | ||
428 | 270 | ||
429 | static int | ||
430 | check () | ||
431 | { | ||
432 | static char *const argv[] = { "test-transport-api", | ||
433 | "-c", | ||
434 | "test_transport_api_data.conf", | ||
435 | NULL | ||
436 | }; | ||
437 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
438 | GNUNET_GETOPT_OPTION_END | ||
439 | }; | ||
440 | |||
441 | send_task = NULL; | ||
442 | |||
443 | ok = 1; | ||
444 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
445 | "nohelp", options, &run, &ok); | ||
446 | |||
447 | return ok; | ||
448 | } | ||
449 | |||
450 | int | 271 | int |
451 | main (int argc, char *argv[]) | 272 | main (int argc, char *argv[]) |
452 | { | 273 | { |
453 | int ret; | 274 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
454 | 275 | .connect_continuation = &sendtask, | |
455 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 276 | .config_file = "test_transport_api_data.conf", |
456 | GNUNET_log_setup (test_name, | 277 | .rec = ¬ify_receive, |
457 | "WARNING", | 278 | .nc = ¬ify_connect, |
458 | NULL); | 279 | .nd = ¬ify_disconnect, |
459 | tth = GNUNET_TRANSPORT_TESTING_init (); | 280 | .shutdown_task = &custom_shutdown, |
460 | GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf"); | 281 | .timeout = TIMEOUT |
461 | GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf"); | 282 | }; |
462 | ret = check (); | 283 | |
463 | GNUNET_free (cfg_file_p1); | 284 | ccc = &my_ccc; |
464 | GNUNET_free (cfg_file_p2); | 285 | if (GNUNET_OK != |
465 | GNUNET_free (test_name); | 286 | GNUNET_TRANSPORT_TESTING_main (2, |
466 | GNUNET_TRANSPORT_TESTING_done (tth); | 287 | &GNUNET_TRANSPORT_TESTING_connect_check, |
467 | return ret; | 288 | ccc)) |
289 | return 1; | ||
290 | return 0; | ||
468 | } | 291 | } |
469 | 292 | ||
470 | /* end of test_transport_api_restart_1peer.c */ | 293 | /* end of test_transport_api_restart_1peer.c */ |
diff --git a/src/transport/test_transport_api_restart_1peer_peer1.conf b/src/transport/test_transport_api_restart_1peer_peer1.conf new file mode 100644 index 000000000..4bfe9b6ca --- /dev/null +++ b/src/transport/test_transport_api_restart_1peer_peer1.conf | |||
@@ -0,0 +1,9 @@ | |||
1 | @INLINE@ template_cfg_peer1.conf | ||
2 | [PATHS] | ||
3 | GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/ | ||
4 | |||
5 | [transport] | ||
6 | PLUGINS = tcp | ||
7 | |||
8 | #[transport] | ||
9 | #PREFIX = valgrind | ||
diff --git a/src/transport/test_transport_api_restart_1peer_peer2.conf b/src/transport/test_transport_api_restart_1peer_peer2.conf new file mode 100644 index 000000000..e68cdbee4 --- /dev/null +++ b/src/transport/test_transport_api_restart_1peer_peer2.conf | |||
@@ -0,0 +1,9 @@ | |||
1 | @INLINE@ template_cfg_peer2.conf | ||
2 | [PATHS] | ||
3 | GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/ | ||
4 | |||
5 | [transport] | ||
6 | PLUGINS = tcp | ||
7 | |||
8 | #[transport] | ||
9 | #PREFIX = valgrind | ||
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c index 876b7209c..40f287623 100644 --- a/src/transport/test_transport_api_restart_2peers.c +++ b/src/transport/test_transport_api_restart_2peers.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2015 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -18,11 +18,12 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api_restart_2peers.c | 21 | * @file transport/test_transport_api_restart_1peer.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case starts 2 peers, connects and exchanges a message | 24 | * This test case starts 2 peers, connects and exchanges a message |
25 | * boths peer are restarted and tested if peers reconnect | 25 | * 1 peer is restarted and tested if peers reconnect |
26 | * C code apparently. | ||
26 | */ | 27 | */ |
27 | #include "platform.h" | 28 | #include "platform.h" |
28 | #include "gnunet_transport_service.h" | 29 | #include "gnunet_transport_service.h" |
@@ -31,100 +32,49 @@ | |||
31 | /** | 32 | /** |
32 | * How long until we give up on transmitting the message? | 33 | * How long until we give up on transmitting the message? |
33 | */ | 34 | */ |
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
38 | */ | 39 | */ |
39 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
40 | 41 | ||
41 | #define MTYPE 12345 | 42 | #define MTYPE 12345 |
42 | 43 | ||
43 | static char *test_name; | ||
44 | 44 | ||
45 | static int ok; | 45 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
46 | |||
47 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
48 | |||
49 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
50 | 46 | ||
51 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | 47 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; |
52 | 48 | ||
53 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | 49 | static int p1_connected; |
54 | |||
55 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
56 | 50 | ||
57 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 51 | static int p2_connected; |
58 | 52 | ||
59 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 53 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
60 | 54 | ||
61 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 55 | static struct GNUNET_SCHEDULER_Task *send_task; |
62 | |||
63 | static char *cfg_file_p1; | ||
64 | |||
65 | static char *cfg_file_p2; | ||
66 | 56 | ||
67 | static int restarted; | 57 | static int restarted; |
68 | 58 | ||
69 | 59 | ||
70 | static void | 60 | static void |
71 | end () | 61 | custom_shutdown (void *cls) |
72 | { | 62 | { |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
74 | if (NULL != send_task) | ||
75 | { | ||
76 | GNUNET_SCHEDULER_cancel (send_task); | ||
77 | send_task = NULL; | ||
78 | } | ||
79 | if (NULL != ats_sh) | 63 | if (NULL != ats_sh) |
80 | { | 64 | { |
81 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | 65 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); |
82 | ats_sh = NULL; | 66 | ats_sh = NULL; |
83 | } | 67 | } |
84 | if (NULL != die_task) | ||
85 | { | ||
86 | GNUNET_SCHEDULER_cancel (die_task); | ||
87 | die_task = NULL; | ||
88 | } | ||
89 | if (NULL != th) | 68 | if (NULL != th) |
90 | { | 69 | { |
91 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 70 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
92 | th = NULL; | 71 | th = NULL; |
93 | } | 72 | } |
94 | if (NULL != p1) | 73 | if (NULL != send_task) |
95 | { | ||
96 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
97 | p1 = NULL; | ||
98 | } | ||
99 | if (NULL != p2) | ||
100 | { | ||
101 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
102 | p2 = NULL; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | |||
107 | static void | ||
108 | end_badly (void *cls) | ||
109 | { | ||
110 | die_task = NULL; | ||
111 | |||
112 | if (restarted == GNUNET_YES) | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
114 | "Peer was restarted, but communication did not resume\n"); | ||
115 | |||
116 | if (restarted == GNUNET_NO) | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
118 | "Peer was NOT (even) restarted\n"); | ||
119 | if (cc != NULL) | ||
120 | { | 74 | { |
121 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 75 | GNUNET_SCHEDULER_cancel (send_task); |
122 | _("Fail! Could not connect peers\n")); | 76 | send_task = NULL; |
123 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
124 | cc = NULL; | ||
125 | } | 77 | } |
126 | end (); | ||
127 | ok = GNUNET_SYSERR; | ||
128 | } | 78 | } |
129 | 79 | ||
130 | 80 | ||
@@ -132,17 +82,17 @@ static void | |||
132 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 82 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
133 | void *cls) | 83 | void *cls) |
134 | { | 84 | { |
135 | static int c; | 85 | static unsigned int c; |
136 | 86 | ||
137 | c++; | 87 | c++; |
138 | if (c != 2) | 88 | if (c != 2) |
139 | return; | 89 | return; |
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
141 | "Restarted peer %u (`%4s'), issuing reconnect\n", | 91 | "Restarted peer %u (`%s'), issuing reconnect\n", |
142 | p->no, | 92 | p->no, |
143 | GNUNET_i2s (&p->id)); | 93 | GNUNET_i2s (&p->id)); |
144 | ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, | 94 | ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats, |
145 | &p2->id, | 95 | &ccc->p[1]->id, |
146 | 1); | 96 | 1); |
147 | } | 97 | } |
148 | 98 | ||
@@ -150,78 +100,66 @@ restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | |||
150 | static void | 100 | static void |
151 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) | 101 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) |
152 | { | 102 | { |
153 | GNUNET_assert (NULL != p); | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "Restarting peer %u (`%4s')\n", | 104 | "Restarting peer %u (`%s')\n", |
156 | p->no, | 105 | p->no, |
157 | GNUNET_i2s (&p->id)); | 106 | GNUNET_i2s (&p->id)); |
158 | GNUNET_TRANSPORT_TESTING_restart_peer (p, | 107 | GNUNET_assert (GNUNET_OK == |
159 | &restart_cb, | 108 | GNUNET_TRANSPORT_TESTING_restart_peer (p, |
160 | p); | 109 | &restart_cb, |
110 | p)); | ||
161 | } | 111 | } |
162 | 112 | ||
163 | 113 | ||
164 | static void | 114 | static void |
165 | notify_receive (void *cls, | 115 | notify_receive (void *cls, |
166 | const struct GNUNET_PeerIdentity *peer, | 116 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
117 | const struct GNUNET_PeerIdentity *sender, | ||
167 | const struct GNUNET_MessageHeader *message) | 118 | const struct GNUNET_MessageHeader *message) |
168 | { | 119 | { |
169 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
170 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | ||
171 | |||
172 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
173 | t = p1; | ||
174 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
175 | t = p2; | ||
176 | GNUNET_assert (t != NULL); | ||
177 | |||
178 | { | 120 | { |
179 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 121 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
180 | 122 | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
182 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 124 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
183 | p->no, | 125 | receiver->no, |
184 | ps, | 126 | ps, |
185 | ntohs (message->type), | 127 | ntohs (message->type), |
186 | ntohs (message->size), | 128 | ntohs (message->size), |
187 | t->no, | 129 | GNUNET_i2s (sender)); |
188 | GNUNET_i2s (&t->id)); | ||
189 | GNUNET_free (ps); | 130 | GNUNET_free (ps); |
190 | } | 131 | } |
191 | |||
192 | if ((MTYPE == ntohs (message->type)) && | 132 | if ((MTYPE == ntohs (message->type)) && |
193 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 133 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
194 | { | 134 | { |
195 | if (restarted == GNUNET_NO) | 135 | if (GNUNET_NO == restarted) |
196 | { | 136 | { |
197 | restarted = GNUNET_YES; | 137 | restarted = GNUNET_YES; |
198 | restart (p1); | 138 | restart (ccc->p[0]); |
199 | restart (p2); | 139 | restart (ccc->p[1]); |
200 | return; | 140 | return; |
201 | } | 141 | } |
202 | else | 142 | else |
203 | { | 143 | { |
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
205 | "Restarted peers connected, stopping test...\n"); | 145 | "Restarted peers connected and message was sent, stopping test...\n"); |
206 | ok = 0; | 146 | ccc->global_ret = GNUNET_OK; |
207 | end (); | 147 | GNUNET_SCHEDULER_shutdown (); |
208 | } | 148 | } |
209 | } | 149 | } |
210 | else | 150 | else |
211 | { | 151 | { |
212 | GNUNET_break (0); | 152 | GNUNET_break (0); |
213 | ok = 1; | 153 | ccc->global_ret = GNUNET_SYSERR; |
214 | if (die_task != NULL) | 154 | GNUNET_SCHEDULER_shutdown (); |
215 | GNUNET_SCHEDULER_cancel (die_task); | ||
216 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
217 | } | 155 | } |
218 | } | 156 | } |
219 | 157 | ||
220 | 158 | ||
221 | static size_t | 159 | static size_t |
222 | notify_ready (void *cls, | 160 | notify_ready (void *cls, |
223 | size_t size, | 161 | size_t size, |
224 | void *buf) | 162 | void *buf) |
225 | { | 163 | { |
226 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 164 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
227 | struct GNUNET_MessageHeader *hdr; | 165 | struct GNUNET_MessageHeader *hdr; |
@@ -231,10 +169,8 @@ notify_ready (void *cls, | |||
231 | { | 169 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
233 | "Timeout occurred while waiting for transmit_ready\n"); | 171 | "Timeout occurred while waiting for transmit_ready\n"); |
234 | if (NULL != die_task) | 172 | GNUNET_SCHEDULER_shutdown (); |
235 | GNUNET_SCHEDULER_cancel (die_task); | 173 | ccc->global_ret = 42; |
236 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
237 | ok = 42; | ||
238 | return 0; | 174 | return 0; |
239 | } | 175 | } |
240 | 176 | ||
@@ -244,11 +180,11 @@ notify_ready (void *cls, | |||
244 | hdr->type = htons (MTYPE); | 180 | hdr->type = htons (MTYPE); |
245 | 181 | ||
246 | { | 182 | { |
247 | char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); | 183 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); |
248 | 184 | ||
249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
250 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | 186 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", |
251 | p2->no, | 187 | ccc->p[1]->no, |
252 | ps, | 188 | ps, |
253 | ntohs (hdr->type), | 189 | ntohs (hdr->type), |
254 | ntohs (hdr->size), | 190 | ntohs (hdr->size), |
@@ -256,7 +192,6 @@ notify_ready (void *cls, | |||
256 | GNUNET_i2s (&p->id)); | 192 | GNUNET_i2s (&p->id)); |
257 | GNUNET_free (ps); | 193 | GNUNET_free (ps); |
258 | } | 194 | } |
259 | |||
260 | return sizeof (struct GNUNET_MessageHeader); | 195 | return sizeof (struct GNUNET_MessageHeader); |
261 | } | 196 | } |
262 | 197 | ||
@@ -266,82 +201,66 @@ sendtask (void *cls) | |||
266 | { | 201 | { |
267 | send_task = NULL; | 202 | send_task = NULL; |
268 | { | 203 | { |
269 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 204 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
270 | 205 | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
272 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 207 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
273 | p2->no, | 208 | ccc->p[1]->no, |
274 | GNUNET_i2s (&p2->id), | 209 | GNUNET_i2s (&ccc->p[1]->id), |
275 | p1->no, | 210 | ccc->p[0]->no, |
276 | receiver_s); | 211 | receiver_s); |
277 | GNUNET_free (receiver_s); | 212 | GNUNET_free (receiver_s); |
278 | } | 213 | } |
279 | 214 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | |
280 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | 215 | &ccc->p[0]->id, |
281 | &p1->id, | ||
282 | 256, | 216 | 256, |
283 | TIMEOUT_TRANSMIT, | 217 | TIMEOUT_TRANSMIT, |
284 | ¬ify_ready, | 218 | ¬ify_ready, |
285 | p1); | 219 | ccc->p[0]); |
286 | } | 220 | } |
287 | 221 | ||
288 | 222 | ||
289 | static void | 223 | static void |
290 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 224 | notify_connect (void *cls, |
225 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
226 | const struct GNUNET_PeerIdentity *other) | ||
291 | { | 227 | { |
292 | static int c; | 228 | GNUNET_TRANSPORT_TESTING_log_connect (cls, |
293 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 229 | me, |
294 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | 230 | other); |
295 | 231 | if (0 == memcmp (other, | |
296 | c++; | 232 | &ccc->p[0]->id, |
297 | if (0 == memcmp (peer, | 233 | sizeof (struct GNUNET_PeerIdentity))) |
298 | &p1->id, | 234 | p1_connected = GNUNET_YES; |
299 | sizeof (struct GNUNET_PeerIdentity))) | 235 | if (0 == memcmp (other, |
300 | t = p1; | 236 | &ccc->p[1]->id, |
301 | if (0 == memcmp (peer, | 237 | sizeof (struct GNUNET_PeerIdentity))) |
302 | &p2->id, | 238 | p2_connected = GNUNET_YES; |
303 | sizeof (struct GNUNET_PeerIdentity))) | 239 | |
304 | t = p2; | 240 | if ( (GNUNET_YES == restarted) && |
305 | GNUNET_assert (t != NULL); | 241 | (GNUNET_YES == p1_connected) && |
306 | 242 | (GNUNET_YES == p2_connected) ) | |
307 | { | ||
308 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
309 | |||
310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
311 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", | ||
312 | p->no, | ||
313 | ps, | ||
314 | t->no, | ||
315 | GNUNET_i2s (peer)); | ||
316 | GNUNET_free (ps); | ||
317 | } | ||
318 | |||
319 | if ((restarted == GNUNET_YES) && (c == 4)) | ||
320 | { | 243 | { |
244 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ | ||
321 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | 245 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, |
322 | NULL); | 246 | NULL); |
323 | } | 247 | } |
324 | } | 248 | } |
325 | 249 | ||
326 | 250 | ||
327 | static void | 251 | static void |
328 | notify_disconnect (void *cls, | 252 | notify_disconnect (void *cls, |
329 | const struct GNUNET_PeerIdentity *peer) | 253 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
254 | const struct GNUNET_PeerIdentity *other) | ||
330 | { | 255 | { |
331 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 256 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
332 | 257 | me, | |
333 | { | 258 | other); |
334 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 259 | if (me == ccc->p[0]) |
335 | 260 | p1_connected = GNUNET_NO; | |
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 261 | if (me == ccc->p[1]) |
337 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", | 262 | p2_connected = GNUNET_NO; |
338 | p->no, | 263 | if (NULL != th) |
339 | ps, | ||
340 | GNUNET_i2s (peer)); | ||
341 | GNUNET_free (ps); | ||
342 | } | ||
343 | |||
344 | if (th != NULL) | ||
345 | { | 264 | { |
346 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 265 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
347 | th = NULL; | 266 | th = NULL; |
@@ -354,137 +273,26 @@ notify_disconnect (void *cls, | |||
354 | } | 273 | } |
355 | 274 | ||
356 | 275 | ||
357 | static void | ||
358 | testing_connect_cb (void *cls) | ||
359 | { | ||
360 | cc = NULL; | ||
361 | |||
362 | { | ||
363 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
364 | |||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
366 | "Peers connected: %u (%s) <-> %u (%s)\n", | ||
367 | p1->no, | ||
368 | p1_c, | ||
369 | p2->no, | ||
370 | GNUNET_i2s (&p2->id)); | ||
371 | GNUNET_free (p1_c); | ||
372 | } | ||
373 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | ||
374 | NULL); | ||
375 | } | ||
376 | |||
377 | |||
378 | static void | ||
379 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
380 | { | ||
381 | static int started; | ||
382 | |||
383 | started++; | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Peer %u (`%s') started\n", | ||
386 | p->no, | ||
387 | GNUNET_i2s (&p->id)); | ||
388 | if (started != 2) | ||
389 | return; | ||
390 | |||
391 | { | ||
392 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
393 | |||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
396 | p1->no, | ||
397 | sender_c, | ||
398 | p2->no, | ||
399 | GNUNET_i2s (&p2->id)); | ||
400 | GNUNET_free (sender_c); | ||
401 | } | ||
402 | |||
403 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | ||
404 | p2, | ||
405 | &testing_connect_cb, | ||
406 | NULL); | ||
407 | } | ||
408 | |||
409 | |||
410 | static void | ||
411 | run (void *cls, | ||
412 | char *const *args, | ||
413 | const char *cfgfile, | ||
414 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
415 | { | ||
416 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
417 | &end_badly, | ||
418 | NULL); | ||
419 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
420 | cfg_file_p1, | ||
421 | 1, | ||
422 | ¬ify_receive, | ||
423 | ¬ify_connect, | ||
424 | ¬ify_disconnect, | ||
425 | &start_cb, | ||
426 | NULL); | ||
427 | |||
428 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
429 | cfg_file_p2, | ||
430 | 2, | ||
431 | ¬ify_receive, | ||
432 | ¬ify_connect, | ||
433 | ¬ify_disconnect, | ||
434 | &start_cb, | ||
435 | NULL); | ||
436 | |||
437 | if ((p1 == NULL) || (p2 == NULL)) | ||
438 | { | ||
439 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
440 | if (die_task != NULL) | ||
441 | GNUNET_SCHEDULER_cancel (die_task); | ||
442 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
443 | return; | ||
444 | } | ||
445 | } | ||
446 | |||
447 | |||
448 | static int | ||
449 | check () | ||
450 | { | ||
451 | static char *const argv[] = { "test-transport-api", | ||
452 | "-c", | ||
453 | "test_transport_api_data.conf", | ||
454 | NULL | ||
455 | }; | ||
456 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
457 | GNUNET_GETOPT_OPTION_END | ||
458 | }; | ||
459 | |||
460 | send_task = NULL; | ||
461 | |||
462 | ok = 1; | ||
463 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
464 | "nohelp", options, &run, NULL); | ||
465 | |||
466 | return ok; | ||
467 | } | ||
468 | |||
469 | |||
470 | int | 276 | int |
471 | main (int argc, char *argv[]) | 277 | main (int argc, char *argv[]) |
472 | { | 278 | { |
473 | int ret; | 279 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
474 | 280 | .connect_continuation = &sendtask, | |
475 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 281 | .config_file = "test_transport_api_data.conf", |
476 | GNUNET_log_setup (test_name, | 282 | .rec = ¬ify_receive, |
477 | "WARNING", | 283 | .nc = ¬ify_connect, |
478 | NULL); | 284 | .nd = ¬ify_disconnect, |
479 | tth = GNUNET_TRANSPORT_TESTING_init (); | 285 | .shutdown_task = &custom_shutdown, |
480 | GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf"); | 286 | .timeout = TIMEOUT |
481 | GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf"); | 287 | }; |
482 | ret = check (); | 288 | |
483 | GNUNET_free (cfg_file_p1); | 289 | ccc = &my_ccc; |
484 | GNUNET_free (cfg_file_p2); | 290 | if (GNUNET_OK != |
485 | GNUNET_free (test_name); | 291 | GNUNET_TRANSPORT_TESTING_main (2, |
486 | GNUNET_TRANSPORT_TESTING_done (tth); | 292 | &GNUNET_TRANSPORT_TESTING_connect_check, |
487 | return ret; | 293 | ccc)) |
294 | return 1; | ||
295 | return 0; | ||
488 | } | 296 | } |
489 | 297 | ||
490 | /* end of test_transport_api_restart_2peers.c */ | 298 | /* end of test_transport_api_restart_1peer.c */ |
diff --git a/src/transport/test_transport_api_restart_2peers_peer1.conf b/src/transport/test_transport_api_restart_2peers_peer1.conf new file mode 100644 index 000000000..4bfe9b6ca --- /dev/null +++ b/src/transport/test_transport_api_restart_2peers_peer1.conf | |||
@@ -0,0 +1,9 @@ | |||
1 | @INLINE@ template_cfg_peer1.conf | ||
2 | [PATHS] | ||
3 | GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/ | ||
4 | |||
5 | [transport] | ||
6 | PLUGINS = tcp | ||
7 | |||
8 | #[transport] | ||
9 | #PREFIX = valgrind | ||
diff --git a/src/transport/test_transport_api_restart_2peers_peer2.conf b/src/transport/test_transport_api_restart_2peers_peer2.conf new file mode 100644 index 000000000..e68cdbee4 --- /dev/null +++ b/src/transport/test_transport_api_restart_2peers_peer2.conf | |||
@@ -0,0 +1,9 @@ | |||
1 | @INLINE@ template_cfg_peer2.conf | ||
2 | [PATHS] | ||
3 | GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/ | ||
4 | |||
5 | [transport] | ||
6 | PLUGINS = tcp | ||
7 | |||
8 | #[transport] | ||
9 | #PREFIX = valgrind | ||
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c index fcc0b044e..29d69c879 100644 --- a/src/transport/test_transport_api_timeout.c +++ b/src/transport/test_transport_api_timeout.c | |||
@@ -261,6 +261,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
261 | ¬ify_receive, | 261 | ¬ify_receive, |
262 | ¬ify_connect, | 262 | ¬ify_connect, |
263 | ¬ify_disconnect, | 263 | ¬ify_disconnect, |
264 | NULL, | ||
264 | &start_cb, | 265 | &start_cb, |
265 | NULL); | 266 | NULL); |
266 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 267 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
@@ -269,6 +270,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
269 | ¬ify_receive, | 270 | ¬ify_receive, |
270 | ¬ify_connect, | 271 | ¬ify_connect, |
271 | ¬ify_disconnect, | 272 | ¬ify_disconnect, |
273 | NULL, | ||
272 | &start_cb, | 274 | &start_cb, |
273 | NULL); | 275 | NULL); |
274 | 276 | ||
diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c index 3696dc71a..4c1f73152 100644 --- a/src/transport/test_transport_blacklisting.c +++ b/src/transport/test_transport_blacklisting.c | |||
@@ -275,6 +275,7 @@ run_stage (void *cls) | |||
275 | 1, | 275 | 1, |
276 | NULL, | 276 | NULL, |
277 | NULL, | 277 | NULL, |
278 | NULL, | ||
278 | NULL, | 279 | NULL, |
279 | &start_cb, | 280 | &start_cb, |
280 | NULL); | 281 | NULL); |
@@ -284,6 +285,7 @@ run_stage (void *cls) | |||
284 | 2, | 285 | 2, |
285 | NULL, | 286 | NULL, |
286 | NULL, | 287 | NULL, |
288 | NULL, | ||
287 | NULL, | 289 | NULL, |
288 | &start_cb, | 290 | &start_cb, |
289 | NULL); | 291 | NULL); |
@@ -297,10 +299,12 @@ run_stage (void *cls) | |||
297 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 299 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
298 | cfg_p1, | 300 | cfg_p1, |
299 | 1, NULL, NULL, NULL, | 301 | 1, NULL, NULL, NULL, |
302 | NULL, | ||
300 | &start_cb, NULL); | 303 | &start_cb, NULL); |
301 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 304 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
302 | cfg_p2, 2, | 305 | cfg_p2, 2, |
303 | NULL, NULL, NULL, | 306 | NULL, NULL, NULL, |
307 | NULL, | ||
304 | &start_cb, NULL); | 308 | &start_cb, NULL); |
305 | 309 | ||
306 | /* check if configuration contain correct blacklist entries */ | 310 | /* check if configuration contain correct blacklist entries */ |
@@ -328,6 +332,7 @@ run_stage (void *cls) | |||
328 | cfg_p1, | 332 | cfg_p1, |
329 | 1, | 333 | 1, |
330 | NULL, | 334 | NULL, |
335 | NULL, | ||
331 | NULL, | 336 | NULL, |
332 | NULL, | 337 | NULL, |
333 | &start_cb, | 338 | &start_cb, |
@@ -337,6 +342,7 @@ run_stage (void *cls) | |||
337 | cfg_p2, 2, | 342 | cfg_p2, 2, |
338 | NULL, | 343 | NULL, |
339 | NULL, | 344 | NULL, |
345 | NULL, | ||
340 | NULL, | 346 | NULL, |
341 | &start_cb, | 347 | &start_cb, |
342 | NULL); | 348 | NULL); |
@@ -363,11 +369,13 @@ run_stage (void *cls) | |||
363 | 369 | ||
364 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 370 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
365 | cfg_p1, 1, | 371 | cfg_p1, 1, |
372 | NULL, | ||
366 | NULL, NULL, NULL, | 373 | NULL, NULL, NULL, |
367 | &start_cb, NULL); | 374 | &start_cb, NULL); |
368 | 375 | ||
369 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 376 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
370 | cfg_p2, 2, | 377 | cfg_p2, 2, |
378 | NULL, | ||
371 | NULL, NULL, NULL, | 379 | NULL, NULL, NULL, |
372 | &start_cb, NULL); | 380 | &start_cb, NULL); |
373 | 381 | ||
@@ -391,11 +399,13 @@ run_stage (void *cls) | |||
391 | 399 | ||
392 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 400 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
393 | cfg_p1, 1, | 401 | cfg_p1, 1, |
402 | NULL, | ||
394 | NULL, NULL, NULL, | 403 | NULL, NULL, NULL, |
395 | &start_cb, NULL); | 404 | &start_cb, NULL); |
396 | 405 | ||
397 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 406 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
398 | cfg_p2, 2, | 407 | cfg_p2, 2, |
408 | NULL, | ||
399 | NULL, NULL, | 409 | NULL, NULL, |
400 | NULL, | 410 | NULL, |
401 | &start_cb, NULL); | 411 | &start_cb, NULL); |
@@ -421,11 +431,13 @@ run_stage (void *cls) | |||
421 | 431 | ||
422 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 432 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
423 | cfg_p1, 1, | 433 | cfg_p1, 1, |
434 | NULL, | ||
424 | NULL, NULL, NULL, | 435 | NULL, NULL, NULL, |
425 | &start_cb, NULL); | 436 | &start_cb, NULL); |
426 | 437 | ||
427 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 438 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
428 | cfg_p2, 2, | 439 | cfg_p2, 2, |
440 | NULL, | ||
429 | NULL, NULL, NULL, | 441 | NULL, NULL, NULL, |
430 | &start_cb, NULL); | 442 | &start_cb, NULL); |
431 | 443 | ||
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c index 2d06bf668..4d5433713 100644 --- a/src/transport/test_transport_testing_restart.c +++ b/src/transport/test_transport_testing_restart.c | |||
@@ -122,6 +122,7 @@ run (void *cls, | |||
122 | NULL, /* receive cb */ | 122 | NULL, /* receive cb */ |
123 | NULL, /* connect cb */ | 123 | NULL, /* connect cb */ |
124 | NULL, /* disconnect cb */ | 124 | NULL, /* disconnect cb */ |
125 | NULL, /* nc/nd closure */ | ||
125 | start_cb, /* startup cb */ | 126 | start_cb, /* startup cb */ |
126 | NULL); /* closure */ | 127 | NULL); /* closure */ |
127 | if (NULL == p) | 128 | if (NULL == p) |
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index c516d4277..0846357e6 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c | |||
@@ -91,14 +91,15 @@ run (void *cls, | |||
91 | &end_badly, | 91 | &end_badly, |
92 | NULL); | 92 | NULL); |
93 | 93 | ||
94 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, | 94 | p = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
95 | cfgfile, | 95 | cfgfile, |
96 | 1, | 96 | 1, |
97 | NULL, /* receive cb */ | 97 | NULL, /* receive cb */ |
98 | NULL, /* connect cb */ | 98 | NULL, /* connect cb */ |
99 | NULL, /* disconnect cb */ | 99 | NULL, /* disconnect cb */ |
100 | &start_cb, /* startup cb */ | 100 | NULL, /* nc/nd closure */ |
101 | NULL); /* closure */ | 101 | &start_cb, /* startup cb */ |
102 | NULL); /* closure */ | ||
102 | if (NULL == p) | 103 | if (NULL == p) |
103 | { | 104 | { |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | 105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); |
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index de2ec3d0c..f196d586b 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c | |||
@@ -383,6 +383,7 @@ connect_check_run (void *cls, | |||
383 | &my_rec, | 383 | &my_rec, |
384 | &my_nc, | 384 | &my_nc, |
385 | &my_nd, | 385 | &my_nd, |
386 | &ccc->ip[i], | ||
386 | &start_cb, | 387 | &start_cb, |
387 | &ccc->ip[i]); | 388 | &ccc->ip[i]); |
388 | if (NULL == ccc->p[i]) | 389 | if (NULL == ccc->p[i]) |
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index ae878a79e..322627459 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -186,7 +186,7 @@ get_hello (void *cb_cls, | |||
186 | p->no, | 186 | p->no, |
187 | GNUNET_i2s (&p->id)); | 187 | GNUNET_i2s (&p->id)); |
188 | p->start_cb (p, | 188 | p->start_cb (p, |
189 | p->cb_cls); | 189 | p->start_cb_cls); |
190 | p->start_cb = NULL; | 190 | p->start_cb = NULL; |
191 | } | 191 | } |
192 | } | 192 | } |
@@ -200,8 +200,9 @@ get_hello (void *cb_cls, | |||
200 | * @param rec receive callback | 200 | * @param rec receive callback |
201 | * @param nc connect callback | 201 | * @param nc connect callback |
202 | * @param nd disconnect callback | 202 | * @param nd disconnect callback |
203 | * @param start_cb start callback | ||
204 | * @param cb_cls closure for callback | 203 | * @param cb_cls closure for callback |
204 | * @param start_cb start callback | ||
205 | * @param start_cb_cls closure for callback | ||
205 | * @return the peer context | 206 | * @return the peer context |
206 | */ | 207 | */ |
207 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | 208 | struct GNUNET_TRANSPORT_TESTING_PeerContext * |
@@ -211,8 +212,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
211 | GNUNET_TRANSPORT_ReceiveCallback rec, | 212 | GNUNET_TRANSPORT_ReceiveCallback rec, |
212 | GNUNET_TRANSPORT_NotifyConnect nc, | 213 | GNUNET_TRANSPORT_NotifyConnect nc, |
213 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 214 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
215 | void *cb_cls, | ||
214 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb, | 216 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb, |
215 | void *cb_cls) | 217 | void *start_cb_cls) |
216 | { | 218 | { |
217 | char *emsg = NULL; | 219 | char *emsg = NULL; |
218 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p; | 220 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p; |
@@ -231,11 +233,12 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
231 | p->nc = nc; | 233 | p->nc = nc; |
232 | p->nd = nd; | 234 | p->nd = nd; |
233 | p->rec = rec; | 235 | p->rec = rec; |
234 | p->start_cb = start_cb; | 236 | if (NULL != cb_cls) |
235 | if (cb_cls != NULL) | ||
236 | p->cb_cls = cb_cls; | 237 | p->cb_cls = cb_cls; |
237 | else | 238 | else |
238 | p->cb_cls = p; | 239 | p->cb_cls = p; |
240 | p->start_cb = start_cb; | ||
241 | p->start_cb_cls = start_cb_cls; | ||
239 | GNUNET_CONTAINER_DLL_insert (tth->p_head, | 242 | GNUNET_CONTAINER_DLL_insert (tth->p_head, |
240 | tth->p_tail, | 243 | tth->p_tail, |
241 | p); | 244 | p); |
@@ -341,13 +344,13 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
341 | * | 344 | * |
342 | * @param p the peer | 345 | * @param p the peer |
343 | * @param restart_cb callback to call when restarted | 346 | * @param restart_cb callback to call when restarted |
344 | * @param cb_cls callback closure | 347 | * @param restart_cb_cls callback closure |
345 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR | 348 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR |
346 | */ | 349 | */ |
347 | int | 350 | int |
348 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 351 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
349 | GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, | 352 | GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, |
350 | void *cb_cls) | 353 | void *restart_cb_cls) |
351 | { | 354 | { |
352 | /* shutdown */ | 355 | /* shutdown */ |
353 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 356 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -397,7 +400,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte | |||
397 | 400 | ||
398 | GNUNET_assert (NULL == p->start_cb); | 401 | GNUNET_assert (NULL == p->start_cb); |
399 | p->start_cb = restart_cb; | 402 | p->start_cb = restart_cb; |
400 | p->cb_cls = cb_cls; | 403 | p->start_cb_cls = restart_cb_cls; |
401 | 404 | ||
402 | p->th = GNUNET_TRANSPORT_connect (p->cfg, | 405 | p->th = GNUNET_TRANSPORT_connect (p->cfg, |
403 | NULL, | 406 | NULL, |
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index b78d11dbe..4be451d35 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -140,11 +140,16 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
140 | struct GNUNET_HELLO_Message *hello; | 140 | struct GNUNET_HELLO_Message *hello; |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * Closure for the callbacks | 143 | * Closure for the @a nc and @a nd callbacks |
144 | */ | 144 | */ |
145 | void *cb_cls; | 145 | void *cb_cls; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Closure for @e start_cb. | ||
149 | */ | ||
150 | void *start_cb_cls; | ||
151 | |||
152 | /** | ||
148 | * An unique number to identify the peer | 153 | * An unique number to identify the peer |
149 | */ | 154 | */ |
150 | unsigned int no; | 155 | unsigned int no; |
@@ -266,8 +271,9 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); | |||
266 | * @param rec receive callback | 271 | * @param rec receive callback |
267 | * @param nc connect callback | 272 | * @param nc connect callback |
268 | * @param nd disconnect callback | 273 | * @param nd disconnect callback |
274 | * @param cb_cls closure for @a nc and @a nd callback | ||
269 | * @param start_cb start callback | 275 | * @param start_cb start callback |
270 | * @param cb_cls closure for callback | 276 | * @param start_cb_cls closure for @a start_cb |
271 | * @return the peer context | 277 | * @return the peer context |
272 | */ | 278 | */ |
273 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | 279 | struct GNUNET_TRANSPORT_TESTING_PeerContext * |
@@ -277,8 +283,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
277 | GNUNET_TRANSPORT_ReceiveCallback rec, | 283 | GNUNET_TRANSPORT_ReceiveCallback rec, |
278 | GNUNET_TRANSPORT_NotifyConnect nc, | 284 | GNUNET_TRANSPORT_NotifyConnect nc, |
279 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 285 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
286 | void *cb_cls, | ||
280 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb, | 287 | GNUNET_TRANSPORT_TESTING_StartCallback start_cb, |
281 | void *cb_cls); | 288 | void *start_cb_cls); |
282 | 289 | ||
283 | 290 | ||
284 | /** | 291 | /** |
@@ -295,13 +302,13 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
295 | * | 302 | * |
296 | * @param p the peer | 303 | * @param p the peer |
297 | * @param restart_cb restart callback | 304 | * @param restart_cb restart callback |
298 | * @param cb_cls callback closure | 305 | * @param restart_cb_cls callback closure |
299 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR | 306 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR |
300 | */ | 307 | */ |
301 | int | 308 | int |
302 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 309 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
303 | GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, | 310 | GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, |
304 | void *cb_cls); | 311 | void *restart_cb_cls); |
305 | 312 | ||
306 | 313 | ||
307 | 314 | ||
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index e7db5493e..83b7732e4 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -817,6 +817,7 @@ transmit_ready (struct GNUNET_TRANSPORT_Handle *h) | |||
817 | GNUNET_MQ_discard (env); | 817 | GNUNET_MQ_discard (env); |
818 | continue; | 818 | continue; |
819 | } | 819 | } |
820 | obm->header.size = htons (mret + sizeof (*obm)); | ||
820 | if (NULL != n->unready_warn_task) | 821 | if (NULL != n->unready_warn_task) |
821 | n->unready_warn_task | 822 | n->unready_warn_task |
822 | = GNUNET_SCHEDULER_add_delayed (UNREADY_WARN_TIME, | 823 | = GNUNET_SCHEDULER_add_delayed (UNREADY_WARN_TIME, |
diff --git a/src/util/server_mst.c b/src/util/server_mst.c index 41b2e8ed9..89a25983c 100644 --- a/src/util/server_mst.c +++ b/src/util/server_mst.c | |||
@@ -244,7 +244,7 @@ do_align: | |||
244 | want = ntohs (hdr->size); | 244 | want = ntohs (hdr->size); |
245 | if (want < sizeof (struct GNUNET_MessageHeader)) | 245 | if (want < sizeof (struct GNUNET_MessageHeader)) |
246 | { | 246 | { |
247 | GNUNET_break_op (0); | 247 | GNUNET_break_op (0); |
248 | mst->off = 0; | 248 | mst->off = 0; |
249 | return GNUNET_SYSERR; | 249 | return GNUNET_SYSERR; |
250 | } | 250 | } |