diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-06 15:24:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-06 15:24:26 +0000 |
commit | 3d7bae58c4b9b128e6000a2fe1fe65595235bb14 (patch) | |
tree | d50cfa569c5d447da5663333e61964c47ac09f73 /src/ats-tests/gnunet-ats-sim.c | |
parent | 6cef8fea0c3b6756870786ebc4db0588373c8f65 (diff) | |
download | gnunet-3d7bae58c4b9b128e6000a2fe1fe65595235bb14.tar.gz gnunet-3d7bae58c4b9b128e6000a2fe1fe65595235bb14.zip |
misc fixes
Diffstat (limited to 'src/ats-tests/gnunet-ats-sim.c')
-rw-r--r-- | src/ats-tests/gnunet-ats-sim.c | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c index 27850e3e7..f624c2b21 100644 --- a/src/ats-tests/gnunet-ats-sim.c +++ b/src/ats-tests/gnunet-ats-sim.c | |||
@@ -57,10 +57,12 @@ static int opt_plot; | |||
57 | */ | 57 | */ |
58 | static int opt_verbose; | 58 | static int opt_verbose; |
59 | 59 | ||
60 | struct GNUNET_SCHEDULER_Task * timeout_task; | 60 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
61 | |||
62 | static struct Experiment *e; | ||
63 | |||
64 | static struct LoggingHandle *l; | ||
61 | 65 | ||
62 | struct Experiment *e; | ||
63 | struct LoggingHandle *l; | ||
64 | 66 | ||
65 | static void | 67 | static void |
66 | evaluate (struct GNUNET_TIME_Relative duration_total) | 68 | evaluate (struct GNUNET_TIME_Relative duration_total) |
@@ -125,11 +127,16 @@ evaluate (struct GNUNET_TIME_Relative duration_total) | |||
125 | } | 127 | } |
126 | } | 128 | } |
127 | 129 | ||
130 | |||
128 | static void | 131 | static void |
129 | do_shutdown () | 132 | do_shutdown (void *cls) |
130 | { | 133 | { |
131 | fprintf (stderr, "Shutdown\n"); | 134 | fprintf (stderr, "Shutdown\n"); |
132 | /* timeout */ | 135 | if (NULL != timeout_task) |
136 | { | ||
137 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
138 | timeout_task = NULL; | ||
139 | } | ||
133 | if (NULL != l) | 140 | if (NULL != l) |
134 | { | 141 | { |
135 | GNUNET_ATS_TEST_logging_stop (l); | 142 | GNUNET_ATS_TEST_logging_stop (l); |
@@ -153,9 +160,17 @@ do_shutdown () | |||
153 | 160 | ||
154 | 161 | ||
155 | static void | 162 | static void |
163 | do_timeout (void *cls) | ||
164 | { | ||
165 | timeout_task = NULL; | ||
166 | GNUNET_SCHEDULER_shutdown (); | ||
167 | } | ||
168 | |||
169 | |||
170 | static void | ||
156 | transport_recv_cb (void *cls, | 171 | transport_recv_cb (void *cls, |
157 | const struct GNUNET_PeerIdentity * peer, | 172 | const struct GNUNET_PeerIdentity *peer, |
158 | const struct GNUNET_MessageHeader * message) | 173 | const struct GNUNET_MessageHeader *message) |
159 | { | 174 | { |
160 | 175 | ||
161 | } | 176 | } |
@@ -175,19 +190,19 @@ log_request__cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
175 | 190 | ||
176 | } | 191 | } |
177 | 192 | ||
193 | |||
178 | static void | 194 | static void |
179 | experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success) | 195 | experiment_done_cb (struct Experiment *e, |
196 | struct GNUNET_TIME_Relative duration,int success) | ||
180 | { | 197 | { |
181 | if (GNUNET_OK == success) | 198 | if (GNUNET_OK == success) |
182 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n", | 199 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
183 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | 200 | "Experiment done successful in %s\n", |
201 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
202 | GNUNET_YES)); | ||
184 | else | 203 | else |
185 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); | 204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); |
186 | if (NULL != timeout_task) | 205 | |
187 | { | ||
188 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
189 | timeout_task = NULL; | ||
190 | } | ||
191 | /* Stop logging */ | 206 | /* Stop logging */ |
192 | GNUNET_ATS_TEST_logging_stop (l); | 207 | GNUNET_ATS_TEST_logging_stop (l); |
193 | 208 | ||
@@ -200,31 +215,20 @@ experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,i | |||
200 | evaluate (duration); | 215 | evaluate (duration); |
201 | if (opt_log) | 216 | if (opt_log) |
202 | GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot); | 217 | GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot); |
203 | 218 | GNUNET_SCHEDULER_shutdown (); | |
204 | if (NULL != l) | ||
205 | { | ||
206 | GNUNET_ATS_TEST_logging_stop (l); | ||
207 | GNUNET_ATS_TEST_logging_clean_up (l); | ||
208 | l = NULL; | ||
209 | } | ||
210 | |||
211 | /* Clean up experiment */ | ||
212 | GNUNET_ATS_TEST_experimentation_stop (e); | ||
213 | e = NULL; | ||
214 | |||
215 | /* Shutdown topology */ | ||
216 | GNUNET_ATS_TEST_shutdown_topology (); | ||
217 | } | 219 | } |
218 | 220 | ||
221 | |||
219 | static void | 222 | static void |
220 | episode_done_cb (struct Episode *ep) | 223 | episode_done_cb (struct Episode *ep) |
221 | { | 224 | { |
222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id); |
223 | } | 226 | } |
224 | 227 | ||
228 | |||
225 | static void topology_setup_done (void *cls, | 229 | static void topology_setup_done (void *cls, |
226 | struct BenchmarkPeer *masters, | 230 | struct BenchmarkPeer *masters, |
227 | struct BenchmarkPeer *slaves) | 231 | struct BenchmarkPeer *slaves) |
228 | { | 232 | { |
229 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n"); | 233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n"); |
230 | 234 | ||
@@ -309,10 +313,15 @@ static void topology_setup_done (void *cls, | |||
309 | } | 313 | } |
310 | #endif | 314 | #endif |
311 | 315 | ||
312 | timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_UNIT_MINUTES, | 316 | timeout_task |
313 | e->max_duration), &do_shutdown, NULL); | 317 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_UNIT_MINUTES, |
318 | e->max_duration), | ||
319 | &do_timeout, | ||
320 | NULL); | ||
321 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
314 | } | 322 | } |
315 | 323 | ||
324 | |||
316 | static void | 325 | static void |
317 | parse_args (int argc, char *argv[]) | 326 | parse_args (int argc, char *argv[]) |
318 | { | 327 | { |
@@ -325,6 +334,7 @@ parse_args (int argc, char *argv[]) | |||
325 | { | 334 | { |
326 | if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e"))) | 335 | if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e"))) |
327 | { | 336 | { |
337 | GNUNET_free_non_null (opt_exp_file); | ||
328 | opt_exp_file = GNUNET_strdup ( argv[c + 1]); | 338 | opt_exp_file = GNUNET_strdup ( argv[c + 1]); |
329 | } | 339 | } |
330 | if (0 == strcmp (argv[c], "-l")) | 340 | if (0 == strcmp (argv[c], "-l")) |
@@ -342,6 +352,7 @@ parse_args (int argc, char *argv[]) | |||
342 | } | 352 | } |
343 | } | 353 | } |
344 | 354 | ||
355 | |||
345 | int | 356 | int |
346 | main (int argc, char *argv[]) | 357 | main (int argc, char *argv[]) |
347 | { | 358 | { |