diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 12 | ||||
-rw-r--r-- | src/testing/test_testing.c | 41 | ||||
-rw-r--r-- | src/testing/test_testing_connect.c | 73 | ||||
-rw-r--r-- | src/testing/test_testing_group.c | 24 | ||||
-rw-r--r-- | src/testing/testing.c | 789 | ||||
-rw-r--r-- | src/testing/testing_group.c | 354 | ||||
-rw-r--r-- | src/testing/testing_testbed.c | 23 |
7 files changed, 698 insertions, 618 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 18144c514..4ddcc2b97 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am | |||
@@ -23,12 +23,14 @@ libgnunettesting_la_LIBADD = $(XLIB) \ | |||
23 | check_PROGRAMS = \ | 23 | check_PROGRAMS = \ |
24 | test_testing \ | 24 | test_testing \ |
25 | test_testing_connect \ | 25 | test_testing_connect \ |
26 | test_testing_group | 26 | test_testing_group \ |
27 | test_testing_topology_clique | ||
27 | 28 | ||
28 | TESTS = \ | 29 | TESTS = \ |
29 | test_testing \ | 30 | test_testing \ |
30 | test_testing_connect \ | 31 | test_testing_connect \ |
31 | test_testing_group | 32 | test_testing_group \ |
33 | test_testing_topology_clique | ||
32 | #$(check_PROGRAMS) | 34 | #$(check_PROGRAMS) |
33 | 35 | ||
34 | test_testing_SOURCES = \ | 36 | test_testing_SOURCES = \ |
@@ -48,6 +50,12 @@ test_testing_group_SOURCES = \ | |||
48 | test_testing_group_LDADD = \ | 50 | test_testing_group_LDADD = \ |
49 | $(top_builddir)/src/testing/libgnunettesting.la \ | 51 | $(top_builddir)/src/testing/libgnunettesting.la \ |
50 | $(top_builddir)/src/util/libgnunetutil.la | 52 | $(top_builddir)/src/util/libgnunetutil.la |
53 | |||
54 | test_testing_topology_clique_SOURCES = \ | ||
55 | test_testing_topology_clique.c | ||
56 | test_testing_topology_clique_LDADD = \ | ||
57 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
58 | $(top_builddir)/src/util/libgnunetutil.la | ||
51 | 59 | ||
52 | EXTRA_DIST = \ | 60 | EXTRA_DIST = \ |
53 | test_testing_data.conf \ | 61 | test_testing_data.conf \ |
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c index 1a52f3681..15b7e10ec 100644 --- a/src/testing/test_testing.c +++ b/src/testing/test_testing.c | |||
@@ -28,28 +28,26 @@ | |||
28 | 28 | ||
29 | static int ok; | 29 | static int ok; |
30 | 30 | ||
31 | static void end_cb(void *cls, | 31 | static void |
32 | const char *emsg) | 32 | end_cb (void *cls, const char *emsg) |
33 | { | 33 | { |
34 | GNUNET_assert (emsg == NULL); | 34 | GNUNET_assert (emsg == NULL); |
35 | #if VERBOSE | 35 | #if VERBOSE |
36 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 36 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon terminated, will now exit.\n"); |
37 | "Daemon terminated, will now exit.\n"); | ||
38 | #endif | 37 | #endif |
39 | ok = 0; | 38 | ok = 0; |
40 | } | 39 | } |
41 | 40 | ||
42 | static void my_cb(void *cls, | 41 | static void |
43 | const struct GNUNET_PeerIdentity *id, | 42 | my_cb (void *cls, |
44 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 43 | const struct GNUNET_PeerIdentity *id, |
45 | struct GNUNET_TESTING_Daemon *d, | 44 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
46 | const char *emsg) | 45 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
47 | { | 46 | { |
48 | GNUNET_assert (id != NULL); | 47 | GNUNET_assert (id != NULL); |
49 | #if VERBOSE | 48 | #if VERBOSE |
50 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 49 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
51 | "Daemon `%s' started, will now stop it.\n", | 50 | "Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id)); |
52 | GNUNET_i2s (id)); | ||
53 | #endif | 51 | #endif |
54 | GNUNET_TESTING_daemon_stop (d, &end_cb, NULL); | 52 | GNUNET_TESTING_daemon_stop (d, &end_cb, NULL); |
55 | } | 53 | } |
@@ -59,21 +57,15 @@ static void | |||
59 | run (void *cls, | 57 | run (void *cls, |
60 | struct GNUNET_SCHEDULER_Handle *sched, | 58 | struct GNUNET_SCHEDULER_Handle *sched, |
61 | char *const *args, | 59 | char *const *args, |
62 | const char *cfgfile, | 60 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
63 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
64 | { | 61 | { |
65 | struct GNUNET_TESTING_Daemon *d; | 62 | struct GNUNET_TESTING_Daemon *d; |
66 | 63 | ||
67 | ok = 1; | 64 | ok = 1; |
68 | #if VERBOSE | 65 | #if VERBOSE |
69 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); |
70 | "Starting daemon.\n"); | ||
71 | #endif | 67 | #endif |
72 | d = GNUNET_TESTING_daemon_start (sched, | 68 | d = GNUNET_TESTING_daemon_start (sched, cfg, NULL, &my_cb, NULL); |
73 | cfg, | ||
74 | NULL, | ||
75 | &my_cb, | ||
76 | NULL); | ||
77 | GNUNET_assert (d != NULL); | 69 | GNUNET_assert (d != NULL); |
78 | } | 70 | } |
79 | 71 | ||
@@ -92,8 +84,7 @@ check () | |||
92 | GNUNET_GETOPT_OPTION_END | 84 | GNUNET_GETOPT_OPTION_END |
93 | }; | 85 | }; |
94 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 86 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
95 | argv, "test-testing", "nohelp", | 87 | argv, "test-testing", "nohelp", options, &run, &ok); |
96 | options, &run, &ok); | ||
97 | return ok; | 88 | return ok; |
98 | } | 89 | } |
99 | 90 | ||
@@ -110,7 +101,7 @@ main (int argc, char *argv[]) | |||
110 | #endif | 101 | #endif |
111 | NULL); | 102 | NULL); |
112 | ret = check (); | 103 | ret = check (); |
113 | sleep (1); /* FIXME: make this unnecessary */ | 104 | sleep (1); /* FIXME: make this unnecessary */ |
114 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); | 105 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); |
115 | return ret; | 106 | return ret; |
116 | } | 107 | } |
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index c243cb1d7..ca08eaad3 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c | |||
@@ -45,71 +45,62 @@ static struct GNUNET_CONFIGURATION_Handle *c2; | |||
45 | 45 | ||
46 | static struct GNUNET_SCHEDULER_Handle *sched; | 46 | static struct GNUNET_SCHEDULER_Handle *sched; |
47 | 47 | ||
48 | static void end2_cb(void *cls, | 48 | static void |
49 | const char *emsg) | 49 | end2_cb (void *cls, const char *emsg) |
50 | { | 50 | { |
51 | GNUNET_assert (emsg == NULL); | 51 | GNUNET_assert (emsg == NULL); |
52 | #if VERBOSE | 52 | #if VERBOSE |
53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
54 | "Both daemons terminated, will now exit.\n"); | 54 | "Both daemons terminated, will now exit.\n"); |
55 | #endif | 55 | #endif |
56 | ok = 0; | 56 | ok = 0; |
57 | } | 57 | } |
58 | 58 | ||
59 | static void end1_cb(void *cls, | 59 | static void |
60 | const char *emsg) | 60 | end1_cb (void *cls, const char *emsg) |
61 | { | 61 | { |
62 | GNUNET_assert (emsg == NULL); | 62 | GNUNET_assert (emsg == NULL); |
63 | GNUNET_TESTING_daemon_stop (d2, &end2_cb, NULL); | 63 | GNUNET_TESTING_daemon_stop (d2, &end2_cb, NULL); |
64 | d2 = NULL; | 64 | d2 = NULL; |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static void | 68 | static void |
69 | my_connect_complete (void *cls, | 69 | my_connect_complete (void *cls, const char *emsg) |
70 | const char *emsg) | ||
71 | { | 70 | { |
72 | GNUNET_TESTING_daemon_stop (d1, &end1_cb, NULL); | 71 | GNUNET_TESTING_daemon_stop (d1, &end1_cb, NULL); |
73 | d1 = NULL; | 72 | d1 = NULL; |
74 | } | 73 | } |
75 | 74 | ||
76 | 75 | ||
77 | static void my_cb2(void *cls, | 76 | static void |
78 | const struct GNUNET_PeerIdentity *id, | 77 | my_cb2 (void *cls, |
79 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 78 | const struct GNUNET_PeerIdentity *id, |
80 | struct GNUNET_TESTING_Daemon *d, | 79 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
81 | const char *emsg) | 80 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
82 | { | 81 | { |
83 | GNUNET_assert (id != NULL); | 82 | GNUNET_assert (id != NULL); |
84 | #if VERBOSE | 83 | #if VERBOSE |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Daemon `%s' started.\n", | 85 | "Daemon `%s' started.\n", GNUNET_i2s (id)); |
87 | GNUNET_i2s (id)); | ||
88 | #endif | 86 | #endif |
89 | GNUNET_TESTING_daemons_connect (d1, d2, | 87 | GNUNET_TESTING_daemons_connect (d1, d2, |
90 | TIMEOUT, | 88 | TIMEOUT, &my_connect_complete, NULL); |
91 | &my_connect_complete, | ||
92 | NULL); | ||
93 | } | 89 | } |
94 | 90 | ||
95 | 91 | ||
96 | static void my_cb1(void *cls, | 92 | static void |
97 | const struct GNUNET_PeerIdentity *id, | 93 | my_cb1 (void *cls, |
98 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 94 | const struct GNUNET_PeerIdentity *id, |
99 | struct GNUNET_TESTING_Daemon *d, | 95 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
100 | const char *emsg) | 96 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
101 | { | 97 | { |
102 | GNUNET_assert (id != NULL); | 98 | GNUNET_assert (id != NULL); |
103 | #if VERBOSE | 99 | #if VERBOSE |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
105 | "Daemon `%s' started.\n", | 101 | "Daemon `%s' started.\n", GNUNET_i2s (id)); |
106 | GNUNET_i2s (id)); | ||
107 | #endif | 102 | #endif |
108 | d2 = GNUNET_TESTING_daemon_start (sched, | 103 | d2 = GNUNET_TESTING_daemon_start (sched, c2, NULL, &my_cb2, NULL); |
109 | c2, | ||
110 | NULL, | ||
111 | &my_cb2, | ||
112 | NULL); | ||
113 | GNUNET_assert (d2 != NULL); | 104 | GNUNET_assert (d2 != NULL); |
114 | 105 | ||
115 | } | 106 | } |
@@ -119,26 +110,18 @@ static void | |||
119 | run (void *cls, | 110 | run (void *cls, |
120 | struct GNUNET_SCHEDULER_Handle *s, | 111 | struct GNUNET_SCHEDULER_Handle *s, |
121 | char *const *args, | 112 | char *const *args, |
122 | const char *cfgfile, | 113 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
123 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
124 | { | 114 | { |
125 | sched = s; | 115 | sched = s; |
126 | ok = 1; | 116 | ok = 1; |
127 | #if VERBOSE | 117 | #if VERBOSE |
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n"); |
129 | "Starting daemon.\n"); | ||
130 | #endif | 119 | #endif |
131 | c1 = GNUNET_CONFIGURATION_create (); | 120 | c1 = GNUNET_CONFIGURATION_create (); |
132 | GNUNET_CONFIGURATION_parse (c1, | 121 | GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf"); |
133 | "test_testing_connect_peer1.conf"); | ||
134 | c2 = GNUNET_CONFIGURATION_create (); | 122 | c2 = GNUNET_CONFIGURATION_create (); |
135 | GNUNET_CONFIGURATION_parse (c2, | 123 | GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf"); |
136 | "test_testing_connect_peer2.conf"); | 124 | d1 = GNUNET_TESTING_daemon_start (sched, c1, NULL, &my_cb1, NULL); |
137 | d1 = GNUNET_TESTING_daemon_start (sched, | ||
138 | c1, | ||
139 | NULL, | ||
140 | &my_cb1, | ||
141 | NULL); | ||
142 | GNUNET_assert (d1 != NULL); | 125 | GNUNET_assert (d1 != NULL); |
143 | } | 126 | } |
144 | 127 | ||
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c index 1d38ef5ec..2b6df732e 100644 --- a/src/testing/test_testing_group.c +++ b/src/testing/test_testing_group.c | |||
@@ -42,11 +42,11 @@ static struct GNUNET_TESTING_PeerGroup *pg; | |||
42 | static struct GNUNET_SCHEDULER_Handle *sched; | 42 | static struct GNUNET_SCHEDULER_Handle *sched; |
43 | 43 | ||
44 | 44 | ||
45 | static void my_cb(void *cls, | 45 | static void |
46 | const struct GNUNET_PeerIdentity *id, | 46 | my_cb (void *cls, |
47 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 47 | const struct GNUNET_PeerIdentity *id, |
48 | struct GNUNET_TESTING_Daemon *d, | 48 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
49 | const char *emsg) | 49 | struct GNUNET_TESTING_Daemon *d, const char *emsg) |
50 | { | 50 | { |
51 | GNUNET_assert (id != NULL); | 51 | GNUNET_assert (id != NULL); |
52 | peers_left--; | 52 | peers_left--; |
@@ -62,19 +62,17 @@ static void | |||
62 | run (void *cls, | 62 | run (void *cls, |
63 | struct GNUNET_SCHEDULER_Handle *s, | 63 | struct GNUNET_SCHEDULER_Handle *s, |
64 | char *const *args, | 64 | char *const *args, |
65 | const char *cfgfile, | 65 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
66 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
67 | { | 66 | { |
68 | sched = s; | 67 | sched = s; |
69 | ok = 1; | 68 | ok = 1; |
70 | #if VERBOSE | 69 | #if VERBOSE |
71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); |
72 | "Starting daemons.\n"); | ||
73 | #endif | 71 | #endif |
74 | peers_left = 4; | 72 | peers_left = 8; |
75 | pg = GNUNET_TESTING_daemons_start (sched, cfg, | 73 | pg = GNUNET_TESTING_daemons_start (sched, cfg, |
76 | peers_left, | 74 | peers_left, |
77 | &my_cb, NULL, NULL); | 75 | &my_cb, NULL, NULL, NULL, NULL); |
78 | GNUNET_assert (pg != NULL); | 76 | GNUNET_assert (pg != NULL); |
79 | } | 77 | } |
80 | 78 | ||
diff --git a/src/testing/testing.c b/src/testing/testing.c index 628856b21..8ceaace75 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -58,40 +58,40 @@ | |||
58 | * Phases of starting GNUnet on a system. | 58 | * Phases of starting GNUnet on a system. |
59 | */ | 59 | */ |
60 | enum StartPhase | 60 | enum StartPhase |
61 | { | 61 | { |
62 | /** | 62 | /** |
63 | * Copy the configuration file to the target system. | 63 | * Copy the configuration file to the target system. |
64 | */ | 64 | */ |
65 | SP_COPYING, | 65 | SP_COPYING, |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Configuration file has been copied, start ARM on target system. | 68 | * Configuration file has been copied, start ARM on target system. |
69 | */ | 69 | */ |
70 | SP_COPIED, | 70 | SP_COPIED, |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * ARM has been started, check that it has properly daemonized and | 73 | * ARM has been started, check that it has properly daemonized and |
74 | * then try to connect to the CORE service (which should be | 74 | * then try to connect to the CORE service (which should be |
75 | * auto-started by ARM). | 75 | * auto-started by ARM). |
76 | */ | 76 | */ |
77 | SP_START_ARMING, | 77 | SP_START_ARMING, |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * We're waiting for CORE to start. | 80 | * We're waiting for CORE to start. |
81 | */ | 81 | */ |
82 | SP_START_CORE, | 82 | SP_START_CORE, |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Core has notified us that we've established a connection to the service. | 85 | * Core has notified us that we've established a connection to the service. |
86 | * The main FSM halts here and waits to be moved to UPDATE or CLEANUP. | 86 | * The main FSM halts here and waits to be moved to UPDATE or CLEANUP. |
87 | */ | 87 | */ |
88 | SP_START_DONE, | 88 | SP_START_DONE, |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * We've been asked to terminate the instance and are now waiting for | 91 | * We've been asked to terminate the instance and are now waiting for |
92 | * the remote command to delete the configuration file to complete. | 92 | * the remote command to delete the configuration file to complete. |
93 | */ | 93 | */ |
94 | SP_CLEANUP, | 94 | SP_CLEANUP, |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * We've received a configuration update and are currently waiting for | 97 | * We've received a configuration update and are currently waiting for |
@@ -99,8 +99,8 @@ enum StartPhase | |||
99 | * return to "SP_START_DONE" (and rely on ARM to restart all affected | 99 | * return to "SP_START_DONE" (and rely on ARM to restart all affected |
100 | * services). | 100 | * services). |
101 | */ | 101 | */ |
102 | SP_CONFIG_UPDATE | 102 | SP_CONFIG_UPDATE |
103 | }; | 103 | }; |
104 | 104 | ||
105 | 105 | ||
106 | /** | 106 | /** |
@@ -125,6 +125,9 @@ struct GNUNET_TESTING_Daemon | |||
125 | */ | 125 | */ |
126 | char *hostname; | 126 | char *hostname; |
127 | 127 | ||
128 | /* Result of GNUNET_i2s of this peer, for printing */ | ||
129 | char *shortname; | ||
130 | |||
128 | /** | 131 | /** |
129 | * Username we are using. | 132 | * Username we are using. |
130 | */ | 133 | */ |
@@ -201,8 +204,8 @@ struct GNUNET_TESTING_Daemon | |||
201 | 204 | ||
202 | /** | 205 | /** |
203 | * Handle to the server. | 206 | * Handle to the server. |
204 | */ | 207 | */ |
205 | struct GNUNET_CORE_Handle * server; | 208 | struct GNUNET_CORE_Handle *server; |
206 | }; | 209 | }; |
207 | 210 | ||
208 | 211 | ||
@@ -220,12 +223,9 @@ struct GNUNET_TESTING_Daemon | |||
220 | */ | 223 | */ |
221 | static void | 224 | static void |
222 | testing_init (void *cls, | 225 | testing_init (void *cls, |
223 | struct GNUNET_CORE_Handle * server, | 226 | struct GNUNET_CORE_Handle *server, |
224 | const struct GNUNET_PeerIdentity * | 227 | const struct GNUNET_PeerIdentity *my_identity, |
225 | my_identity, | 228 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
226 | const struct | ||
227 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | ||
228 | publicKey) | ||
229 | { | 229 | { |
230 | struct GNUNET_TESTING_Daemon *d = cls; | 230 | struct GNUNET_TESTING_Daemon *d = cls; |
231 | GNUNET_TESTING_NotifyDaemonRunning cb; | 231 | GNUNET_TESTING_NotifyDaemonRunning cb; |
@@ -238,18 +238,18 @@ testing_init (void *cls, | |||
238 | { | 238 | { |
239 | d->server = NULL; | 239 | d->server = NULL; |
240 | if (GNUNET_YES == d->dead) | 240 | if (GNUNET_YES == d->dead) |
241 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); | 241 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); |
242 | else if (NULL != cb) | 242 | else if (NULL != cb) |
243 | cb (d->cb_cls, NULL, d->cfg, d, | 243 | cb (d->cb_cls, NULL, d->cfg, d, |
244 | _("Failed to connect to core service\n")); | 244 | _("Failed to connect to core service\n")); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | #if DEBUG_TESTING | 247 | #if DEBUG_TESTING |
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
249 | "Successfully started peer `%4s'.\n", | 249 | "Successfully started peer `%4s'.\n", GNUNET_i2s (my_identity)); |
250 | GNUNET_i2s(my_identity)); | ||
251 | #endif | 250 | #endif |
252 | d->id = *my_identity; | 251 | d->id = *my_identity; |
252 | d->shortname = strdup (GNUNET_i2s (my_identity)); | ||
253 | d->server = server; | 253 | d->server = server; |
254 | if (GNUNET_YES == d->dead) | 254 | if (GNUNET_YES == d->dead) |
255 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); | 255 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); |
@@ -265,179 +265,150 @@ testing_init (void *cls, | |||
265 | * @param tc unused | 265 | * @param tc unused |
266 | */ | 266 | */ |
267 | static void | 267 | static void |
268 | start_fsm (void *cls, | 268 | start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
269 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
270 | { | 269 | { |
271 | static struct GNUNET_CORE_MessageHandler no_handlers[] = | 270 | static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} }; |
272 | { { NULL, 0, 0 } }; | 271 | struct GNUNET_TESTING_Daemon *d = cls; |
273 | struct GNUNET_TESTING_Daemon * d = cls; | ||
274 | GNUNET_TESTING_NotifyDaemonRunning cb; | 272 | GNUNET_TESTING_NotifyDaemonRunning cb; |
275 | enum GNUNET_OS_ProcessStatusType type; | 273 | enum GNUNET_OS_ProcessStatusType type; |
276 | unsigned long code; | 274 | unsigned long code; |
277 | char *dst; | 275 | char *dst; |
278 | 276 | ||
279 | #if DEBUG_TESTING | 277 | #if DEBUG_TESTING |
280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
281 | "Peer FSM is in phase %u.\n", | 279 | "Peer FSM is in phase %u.\n", d->phase); |
282 | d->phase); | ||
283 | #endif | 280 | #endif |
284 | d->task = GNUNET_SCHEDULER_NO_TASK; | 281 | d->task = GNUNET_SCHEDULER_NO_TASK; |
285 | switch (d->phase) | 282 | switch (d->phase) |
286 | { | 283 | { |
287 | case SP_COPYING: | 284 | case SP_COPYING: |
288 | /* confirm copying complete */ | 285 | /* confirm copying complete */ |
289 | if (GNUNET_OK != | 286 | if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) |
290 | GNUNET_OS_process_status (d->pid, | 287 | { |
291 | &type, | 288 | d->wait_runs++; |
292 | &code)) | 289 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) |
293 | { | 290 | { |
294 | d->wait_runs++; | 291 | cb = d->cb; |
295 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) | 292 | d->cb = NULL; |
296 | { | 293 | if (NULL != cb) |
297 | cb = d->cb; | 294 | cb (d->cb_cls, |
298 | d->cb = NULL; | 295 | NULL, |
299 | if (NULL != cb) | 296 | d->cfg, d, _("`scp' does not seem to terminate.\n")); |
300 | cb (d->cb_cls, | 297 | return; |
301 | NULL, | 298 | } |
302 | d->cfg, | 299 | /* wait some more */ |
303 | d, | 300 | d->task |
304 | _("`scp' does not seem to terminate.\n")); | 301 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
305 | return; | 302 | GNUNET_CONSTANTS_EXEC_WAIT, |
306 | } | 303 | &start_fsm, d); |
307 | /* wait some more */ | 304 | return; |
308 | d->task | 305 | } |
309 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 306 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
310 | GNUNET_CONSTANTS_EXEC_WAIT, | 307 | { |
311 | &start_fsm, | 308 | cb = d->cb; |
312 | d); | 309 | d->cb = NULL; |
313 | return; | 310 | if (NULL != cb) |
314 | } | 311 | cb (d->cb_cls, |
315 | if ( (type != GNUNET_OS_PROCESS_EXITED) || | 312 | NULL, d->cfg, d, _("`scp' did not complete cleanly.\n")); |
316 | (code != 0) ) | 313 | return; |
317 | { | 314 | } |
318 | cb = d->cb; | ||
319 | d->cb = NULL; | ||
320 | if (NULL != cb) | ||
321 | cb (d->cb_cls, | ||
322 | NULL, | ||
323 | d->cfg, | ||
324 | d, | ||
325 | _("`scp' did not complete cleanly.\n")); | ||
326 | return; | ||
327 | } | ||
328 | #if DEBUG_TESTING | 315 | #if DEBUG_TESTING |
329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
330 | "Successfully copied configuration file.\n"); | 317 | "Successfully copied configuration file.\n"); |
331 | #endif | 318 | #endif |
332 | d->phase = SP_COPIED; | 319 | d->phase = SP_COPIED; |
333 | /* fall-through */ | 320 | /* fall-through */ |
334 | case SP_COPIED: | 321 | case SP_COPIED: |
335 | /* start GNUnet on remote host */ | 322 | /* start GNUnet on remote host */ |
336 | if (NULL == d->hostname) | 323 | if (NULL == d->hostname) |
337 | { | 324 | { |
338 | d->pid = GNUNET_OS_start_process ("gnunet-service-arm", | 325 | d->pid = GNUNET_OS_start_process ("gnunet-service-arm", |
339 | "gnunet-service-arm", | 326 | "gnunet-service-arm", |
340 | "-c", | 327 | "-c", d->cfgfile, |
341 | d->cfgfile, | ||
342 | #if DEBUG_TESTING | 328 | #if DEBUG_TESTING |
343 | "-L", "DEBUG", | 329 | "-L", "DEBUG", |
344 | #endif | 330 | #endif |
345 | "-d", | 331 | "-d", NULL); |
346 | NULL); | 332 | } |
347 | } | ||
348 | else | 333 | else |
349 | { | 334 | { |
350 | if (d->username != NULL) | 335 | if (d->username != NULL) |
351 | GNUNET_asprintf (&dst, | 336 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); |
352 | "%s@%s", | 337 | else |
353 | d->username, | 338 | dst = GNUNET_strdup (d->hostname); |
354 | d->hostname); | 339 | d->pid = GNUNET_OS_start_process ("ssh", |
355 | else | 340 | "ssh", |
356 | dst = GNUNET_strdup (d->hostname); | 341 | dst, |
357 | d->pid = GNUNET_OS_start_process ("ssh", | 342 | "gnunet-service-arm", |
358 | "ssh", | 343 | "-c", d->cfgfile, "-d", NULL); |
359 | dst, | 344 | GNUNET_free (dst); |
360 | "gnunet-service-arm", | 345 | } |
361 | "-c", | ||
362 | d->cfgfile, | ||
363 | "-d", | ||
364 | NULL); | ||
365 | GNUNET_free (dst); | ||
366 | } | ||
367 | if (-1 == d->pid) | 346 | if (-1 == d->pid) |
368 | { | 347 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 348 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
370 | _("Could not start `%s' process to start GNUnet.\n"), | 349 | _("Could not start `%s' process to start GNUnet.\n"), |
371 | (NULL == d->hostname) ? "gnunet-service-arm" : "ssh"); | 350 | (NULL == d->hostname) ? "gnunet-service-arm" : "ssh"); |
372 | cb = d->cb; | 351 | cb = d->cb; |
373 | d->cb = NULL; | 352 | d->cb = NULL; |
374 | if (NULL != cb) | 353 | if (NULL != cb) |
375 | cb (d->cb_cls, | 354 | cb (d->cb_cls, |
376 | NULL, | 355 | NULL, |
377 | d->cfg, | 356 | d->cfg, |
378 | d, | 357 | d, |
379 | (NULL == d->hostname) | 358 | (NULL == d->hostname) |
380 | ? _("Failed to start `gnunet-service-arm' process.\n") | 359 | ? _("Failed to start `gnunet-service-arm' process.\n") |
381 | : _("Failed to start `ssh' process.\n")); | 360 | : _("Failed to start `ssh' process.\n")); |
382 | } | 361 | } |
383 | #if DEBUG_TESTING | 362 | #if DEBUG_TESTING |
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
385 | "Started `%s', waiting for `%s' to be up.\n", | 364 | "Started `%s', waiting for `%s' to be up.\n", |
386 | "gnunet-service-arm", | 365 | "gnunet-service-arm", "gnunet-service-core"); |
387 | "gnunet-service-core"); | ||
388 | #endif | 366 | #endif |
389 | d->phase = SP_START_ARMING; | 367 | d->phase = SP_START_ARMING; |
390 | d->wait_runs = 0; | 368 | d->wait_runs = 0; |
391 | d->task | 369 | d->task |
392 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 370 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
393 | GNUNET_CONSTANTS_EXEC_WAIT, | 371 | GNUNET_CONSTANTS_EXEC_WAIT, |
394 | &start_fsm, | 372 | &start_fsm, d); |
395 | d); | 373 | break; |
396 | break; | ||
397 | case SP_START_ARMING: | 374 | case SP_START_ARMING: |
398 | if (GNUNET_OK != | 375 | if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) |
399 | GNUNET_OS_process_status (d->pid, | 376 | { |
400 | &type, | 377 | d->wait_runs++; |
401 | &code)) | 378 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) |
402 | { | 379 | { |
403 | d->wait_runs++; | 380 | cb = d->cb; |
404 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) | 381 | d->cb = NULL; |
405 | { | 382 | if (NULL != cb) |
406 | cb = d->cb; | 383 | cb (d->cb_cls, |
407 | d->cb = NULL; | 384 | NULL, |
408 | if (NULL != cb) | 385 | d->cfg, |
409 | cb (d->cb_cls, | 386 | d, |
410 | NULL, | 387 | (NULL == d->hostname) |
411 | d->cfg, | 388 | ? _("`gnunet-service-arm' does not seem to terminate.\n") |
412 | d, | 389 | : _("`ssh' does not seem to terminate.\n")); |
413 | (NULL == d->hostname) | 390 | return; |
414 | ? _("`gnunet-service-arm' does not seem to terminate.\n") | 391 | } |
415 | : _("`ssh' does not seem to terminate.\n")); | 392 | /* wait some more */ |
416 | return; | 393 | d->task |
417 | } | 394 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
418 | /* wait some more */ | 395 | GNUNET_CONSTANTS_EXEC_WAIT, |
419 | d->task | 396 | &start_fsm, d); |
420 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 397 | return; |
421 | GNUNET_CONSTANTS_EXEC_WAIT, | 398 | } |
422 | &start_fsm, | ||
423 | d); | ||
424 | return; | ||
425 | } | ||
426 | #if DEBUG_TESTING | 399 | #if DEBUG_TESTING |
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
428 | "Successfully started `%s'.\n", | 401 | "Successfully started `%s'.\n", "gnunet-service-arm"); |
429 | "gnunet-service-arm"); | ||
430 | #endif | 402 | #endif |
431 | d->phase = SP_START_CORE; | 403 | d->phase = SP_START_CORE; |
432 | d->server = GNUNET_CORE_connect (d->sched, | 404 | d->server = GNUNET_CORE_connect (d->sched, |
433 | d->cfg, | 405 | d->cfg, |
434 | ARM_START_WAIT, | 406 | ARM_START_WAIT, |
435 | d, | 407 | d, |
436 | &testing_init, | 408 | &testing_init, |
437 | NULL, NULL, NULL, | 409 | NULL, NULL, NULL, |
438 | NULL, GNUNET_NO, | 410 | NULL, GNUNET_NO, |
439 | NULL, GNUNET_NO, | 411 | NULL, GNUNET_NO, no_handlers); |
440 | no_handlers); | ||
441 | break; | 412 | break; |
442 | case SP_START_CORE: | 413 | case SP_START_CORE: |
443 | GNUNET_break (0); | 414 | GNUNET_break (0); |
@@ -447,95 +418,82 @@ start_fsm (void *cls, | |||
447 | break; | 418 | break; |
448 | case SP_CLEANUP: | 419 | case SP_CLEANUP: |
449 | /* confirm copying complete */ | 420 | /* confirm copying complete */ |
450 | if (GNUNET_OK != | 421 | if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) |
451 | GNUNET_OS_process_status (d->pid, | 422 | { |
452 | &type, | 423 | d->wait_runs++; |
453 | &code)) | 424 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) |
454 | { | 425 | { |
455 | d->wait_runs++; | 426 | d->dead_cb (d->dead_cb_cls, |
456 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) | 427 | _("`ssh' does not seem to terminate.\n")); |
457 | { | 428 | GNUNET_free (d->cfgfile); |
458 | d->dead_cb (d->dead_cb_cls, | 429 | GNUNET_free_non_null (d->hostname); |
459 | _("`ssh' does not seem to terminate.\n")); | 430 | GNUNET_free_non_null (d->username); |
460 | GNUNET_free (d->cfgfile); | 431 | GNUNET_free (d); |
461 | GNUNET_free_non_null (d->hostname); | 432 | return; |
462 | GNUNET_free_non_null (d->username); | 433 | } |
463 | GNUNET_free (d); | 434 | /* wait some more */ |
464 | return; | 435 | d->task |
465 | } | 436 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
466 | /* wait some more */ | 437 | GNUNET_CONSTANTS_EXEC_WAIT, |
467 | d->task | 438 | &start_fsm, d); |
468 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 439 | return; |
469 | GNUNET_CONSTANTS_EXEC_WAIT, | 440 | } |
470 | &start_fsm, | 441 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
471 | d); | 442 | { |
472 | return; | 443 | if (NULL != d->dead_cb) |
473 | } | 444 | d->dead_cb (d->dead_cb_cls, |
474 | if ( (type != GNUNET_OS_PROCESS_EXITED) || | 445 | _("`ssh' did not complete cleanly.\n")); |
475 | (code != 0) ) | 446 | GNUNET_free (d->cfgfile); |
476 | { | 447 | GNUNET_free_non_null (d->hostname); |
477 | if (NULL != d->dead_cb) | 448 | GNUNET_free_non_null (d->username); |
478 | d->dead_cb (d->dead_cb_cls, | 449 | GNUNET_free (d); |
479 | _("`ssh' did not complete cleanly.\n")); | 450 | return; |
480 | GNUNET_free (d->cfgfile); | 451 | } |
481 | GNUNET_free_non_null (d->hostname); | ||
482 | GNUNET_free_non_null (d->username); | ||
483 | GNUNET_free (d); | ||
484 | return; | ||
485 | } | ||
486 | #if DEBUG_TESTING | 452 | #if DEBUG_TESTING |
487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); |
488 | "Peer shutdown complete.\n"); | ||
489 | #endif | 454 | #endif |
490 | GNUNET_free (d->cfgfile); | 455 | GNUNET_free (d->cfgfile); |
491 | GNUNET_free_non_null (d->hostname); | 456 | GNUNET_free_non_null (d->hostname); |
492 | GNUNET_free_non_null (d->username); | 457 | GNUNET_free_non_null (d->username); |
493 | if (NULL != d->dead_cb) | 458 | if (NULL != d->dead_cb) |
494 | d->dead_cb (d->dead_cb_cls, NULL); | 459 | d->dead_cb (d->dead_cb_cls, NULL); |
495 | GNUNET_free (d); | 460 | GNUNET_free (d); |
496 | break; | 461 | break; |
497 | case SP_CONFIG_UPDATE: | 462 | case SP_CONFIG_UPDATE: |
498 | /* confirm copying complete */ | 463 | /* confirm copying complete */ |
499 | if (GNUNET_OK != | 464 | if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) |
500 | GNUNET_OS_process_status (d->pid, | 465 | { |
501 | &type, | 466 | d->wait_runs++; |
502 | &code)) | 467 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) |
503 | { | 468 | { |
504 | d->wait_runs++; | 469 | cb = d->cb; |
505 | if (d->wait_runs > MAX_EXEC_WAIT_RUNS) | 470 | d->cb = NULL; |
506 | { | 471 | if (NULL != cb) |
507 | cb = d->cb; | 472 | cb (d->cb_cls, |
508 | d->cb = NULL; | 473 | NULL, |
509 | if (NULL != cb) | 474 | d->cfg, d, _("`scp' does not seem to terminate.\n")); |
510 | cb (d->cb_cls, | 475 | return; |
511 | NULL, | 476 | } |
512 | d->cfg, | 477 | /* wait some more */ |
513 | d, | 478 | d->task |
514 | _("`scp' does not seem to terminate.\n")); | 479 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
515 | return; | 480 | GNUNET_CONSTANTS_EXEC_WAIT, |
516 | } | 481 | &start_fsm, d); |
517 | /* wait some more */ | 482 | return; |
518 | d->task | 483 | } |
519 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 484 | if ((type != GNUNET_OS_PROCESS_EXITED) || (code != 0)) |
520 | GNUNET_CONSTANTS_EXEC_WAIT, | 485 | { |
521 | &start_fsm, | 486 | if (NULL != d->update_cb) |
522 | d); | 487 | d->update_cb (d->update_cb_cls, |
523 | return; | 488 | _("`scp' did not complete cleanly.\n")); |
524 | } | 489 | return; |
525 | if ( (type != GNUNET_OS_PROCESS_EXITED) || | 490 | } |
526 | (code != 0) ) | ||
527 | { | ||
528 | if (NULL != d->update_cb) | ||
529 | d->update_cb (d->update_cb_cls, | ||
530 | _("`scp' did not complete cleanly.\n")); | ||
531 | return; | ||
532 | } | ||
533 | #if DEBUG_TESTING | 491 | #if DEBUG_TESTING |
534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
535 | "Successfully copied configuration file.\n"); | 493 | "Successfully copied configuration file.\n"); |
536 | #endif | 494 | #endif |
537 | if (NULL != d->update_cb) | 495 | if (NULL != d->update_cb) |
538 | d->update_cb (d->update_cb_cls, NULL); | 496 | d->update_cb (d->update_cb_cls, NULL); |
539 | d->phase = SP_START_DONE; | 497 | d->phase = SP_START_DONE; |
540 | break; | 498 | break; |
541 | } | 499 | } |
@@ -558,26 +516,26 @@ start_fsm (void *cls, | |||
558 | */ | 516 | */ |
559 | struct GNUNET_TESTING_Daemon * | 517 | struct GNUNET_TESTING_Daemon * |
560 | GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | 518 | GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, |
561 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 519 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
562 | const char *hostname, | 520 | const char *hostname, |
563 | GNUNET_TESTING_NotifyDaemonRunning cb, | 521 | GNUNET_TESTING_NotifyDaemonRunning cb, |
564 | void *cb_cls) | 522 | void *cb_cls) |
565 | { | 523 | { |
566 | struct GNUNET_TESTING_Daemon * ret; | 524 | struct GNUNET_TESTING_Daemon *ret; |
567 | char *arg; | 525 | char *arg; |
568 | char *username; | 526 | char *username; |
569 | 527 | ||
570 | ret = GNUNET_malloc (sizeof(struct GNUNET_TESTING_Daemon)); | 528 | ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon)); |
571 | ret->sched = sched; | 529 | ret->sched = sched; |
572 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); | 530 | ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname); |
573 | ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config"); | 531 | ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config"); |
574 | #if DEBUG_TESTING | 532 | #if DEBUG_TESTING |
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
576 | "Setting up peer with configuration file `%s'.\n", | 534 | "Setting up peer with configuration file `%s'.\n", |
577 | ret->cfgfile); | 535 | ret->cfgfile); |
578 | #endif | 536 | #endif |
579 | if (NULL == ret->cfgfile) | 537 | if (NULL == ret->cfgfile) |
580 | { | 538 | { |
581 | GNUNET_free_non_null (ret->hostname); | 539 | GNUNET_free_non_null (ret->hostname); |
582 | GNUNET_free (ret); | 540 | GNUNET_free (ret); |
583 | return NULL; | 541 | return NULL; |
@@ -586,18 +544,14 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
586 | ret->cb_cls = cb_cls; | 544 | ret->cb_cls = cb_cls; |
587 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); | 545 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); |
588 | GNUNET_CONFIGURATION_set_value_string (ret->cfg, | 546 | GNUNET_CONFIGURATION_set_value_string (ret->cfg, |
589 | "PATHS", | 547 | "PATHS", |
590 | "DEFAULTCONFIG", | 548 | "DEFAULTCONFIG", ret->cfgfile); |
591 | ret->cfgfile); | ||
592 | /* 1) write configuration to temporary file */ | 549 | /* 1) write configuration to temporary file */ |
593 | if (GNUNET_OK != | 550 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (ret->cfg, ret->cfgfile)) |
594 | GNUNET_CONFIGURATION_write (ret->cfg, | ||
595 | ret->cfgfile)) | ||
596 | { | 551 | { |
597 | if (0 != UNLINK (ret->cfgfile)) | 552 | if (0 != UNLINK (ret->cfgfile)) |
598 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 553 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
599 | "unlink", | 554 | "unlink", ret->cfgfile); |
600 | ret->cfgfile); | ||
601 | GNUNET_CONFIGURATION_destroy (ret->cfg); | 555 | GNUNET_CONFIGURATION_destroy (ret->cfg); |
602 | GNUNET_free_non_null (ret->hostname); | 556 | GNUNET_free_non_null (ret->hostname); |
603 | GNUNET_free (ret->cfgfile); | 557 | GNUNET_free (ret->cfgfile); |
@@ -606,75 +560,62 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
606 | } | 560 | } |
607 | if (GNUNET_OK != | 561 | if (GNUNET_OK != |
608 | GNUNET_CONFIGURATION_get_value_string (cfg, | 562 | GNUNET_CONFIGURATION_get_value_string (cfg, |
609 | "TESTING", | 563 | "TESTING", |
610 | "USERNAME", | 564 | "USERNAME", &username)) |
611 | &username)) | ||
612 | { | 565 | { |
613 | if (NULL != getenv ("USER")) | 566 | if (NULL != getenv ("USER")) |
614 | username = GNUNET_strdup (getenv("USER")); | 567 | username = GNUNET_strdup (getenv ("USER")); |
615 | else | 568 | else |
616 | username = NULL; | 569 | username = NULL; |
617 | } | 570 | } |
618 | ret->username = username; | 571 | ret->username = username; |
619 | 572 | ||
620 | /* 2) copy file to remote host */ | 573 | /* 2) copy file to remote host */ |
621 | if (NULL != hostname) | 574 | if (NULL != hostname) |
622 | { | 575 | { |
623 | #if DEBUG_TESTING | 576 | #if DEBUG_TESTING |
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
625 | "Copying configuration file to host `%s'.\n", | 578 | "Copying configuration file to host `%s'.\n", hostname); |
626 | hostname); | ||
627 | #endif | 579 | #endif |
628 | ret->phase = SP_COPYING; | 580 | ret->phase = SP_COPYING; |
629 | if (NULL != username) | 581 | if (NULL != username) |
630 | GNUNET_asprintf (&arg, | 582 | GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile); |
631 | "%s@%s:%s", | ||
632 | username, | ||
633 | hostname, | ||
634 | ret->cfgfile); | ||
635 | else | 583 | else |
636 | GNUNET_asprintf (&arg, | 584 | GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile); |
637 | "%s:%s", | ||
638 | hostname, | ||
639 | ret->cfgfile); | ||
640 | ret->pid = GNUNET_OS_start_process ("scp", | 585 | ret->pid = GNUNET_OS_start_process ("scp", |
641 | "scp", | 586 | "scp", ret->cfgfile, arg, NULL); |
642 | ret->cfgfile, | ||
643 | arg, | ||
644 | NULL); | ||
645 | GNUNET_free (arg); | 587 | GNUNET_free (arg); |
646 | if (-1 == ret->pid) | 588 | if (-1 == ret->pid) |
647 | { | 589 | { |
648 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 590 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
649 | _("Could not start `%s' process to copy configuration file.\n"), | 591 | _ |
650 | "scp"); | 592 | ("Could not start `%s' process to copy configuration file.\n"), |
651 | if (0 != UNLINK (ret->cfgfile)) | 593 | "scp"); |
652 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 594 | if (0 != UNLINK (ret->cfgfile)) |
653 | "unlink", | 595 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
654 | ret->cfgfile); | 596 | "unlink", ret->cfgfile); |
655 | GNUNET_CONFIGURATION_destroy (ret->cfg); | 597 | GNUNET_CONFIGURATION_destroy (ret->cfg); |
656 | GNUNET_free_non_null (ret->hostname); | 598 | GNUNET_free_non_null (ret->hostname); |
657 | GNUNET_free_non_null (ret->username); | 599 | GNUNET_free_non_null (ret->username); |
658 | GNUNET_free (ret->cfgfile); | 600 | GNUNET_free (ret->cfgfile); |
659 | GNUNET_free (ret); | 601 | GNUNET_free (ret); |
660 | return NULL; | 602 | return NULL; |
661 | } | 603 | } |
662 | ret->task | 604 | ret->task |
663 | = GNUNET_SCHEDULER_add_delayed (sched, | 605 | = GNUNET_SCHEDULER_add_delayed (sched, |
664 | GNUNET_CONSTANTS_EXEC_WAIT, | 606 | GNUNET_CONSTANTS_EXEC_WAIT, |
665 | &start_fsm, | 607 | &start_fsm, ret); |
666 | ret); | ||
667 | return ret; | 608 | return ret; |
668 | } | 609 | } |
669 | #if DEBUG_TESTING | 610 | #if DEBUG_TESTING |
670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
671 | "No need to copy configuration file since we are running locally.\n"); | 612 | "No need to copy configuration file since we are running locally.\n"); |
672 | #endif | 613 | #endif |
673 | ret->phase = SP_COPIED; | 614 | ret->phase = SP_COPIED; |
674 | GNUNET_SCHEDULER_add_continuation (sched, | 615 | GNUNET_SCHEDULER_add_continuation (sched, |
675 | &start_fsm, | 616 | &start_fsm, |
676 | ret, | 617 | ret, |
677 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 618 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
678 | return ret; | 619 | return ret; |
679 | } | 620 | } |
680 | 621 | ||
@@ -686,9 +627,9 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
686 | * @param cb function called once the daemon was stopped | 627 | * @param cb function called once the daemon was stopped |
687 | * @param cb_cls closure for cb | 628 | * @param cb_cls closure for cb |
688 | */ | 629 | */ |
689 | void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | 630 | void |
690 | GNUNET_TESTING_NotifyCompletion cb, | 631 | GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, |
691 | void * cb_cls) | 632 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
692 | { | 633 | { |
693 | struct GNUNET_CLIENT_Connection *cc; | 634 | struct GNUNET_CLIENT_Connection *cc; |
694 | char *dst; | 635 | char *dst; |
@@ -702,8 +643,7 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
702 | } | 643 | } |
703 | if (d->phase == SP_CONFIG_UPDATE) | 644 | if (d->phase == SP_CONFIG_UPDATE) |
704 | { | 645 | { |
705 | GNUNET_SCHEDULER_cancel (d->sched, | 646 | GNUNET_SCHEDULER_cancel (d->sched, d->task); |
706 | d->task); | ||
707 | d->phase = SP_START_DONE; | 647 | d->phase = SP_START_DONE; |
708 | } | 648 | } |
709 | if (d->server != NULL) | 649 | if (d->server != NULL) |
@@ -714,60 +654,49 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
714 | /* shutdown ARM process (will also terminate others) */ | 654 | /* shutdown ARM process (will also terminate others) */ |
715 | #if DEBUG_TESTING | 655 | #if DEBUG_TESTING |
716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
717 | _("Terminating peer `%4s'\n"), | 657 | _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); |
718 | GNUNET_i2s(&d->id)); | ||
719 | #endif | 658 | #endif |
720 | cc = GNUNET_CLIENT_connect (d->sched, | 659 | cc = GNUNET_CLIENT_connect (d->sched, "arm", d->cfg); |
721 | "arm", | ||
722 | d->cfg); | ||
723 | GNUNET_CLIENT_service_shutdown (cc); | 660 | GNUNET_CLIENT_service_shutdown (cc); |
724 | 661 | ||
725 | /* state clean up and notifications */ | 662 | /* state clean up and notifications */ |
726 | if (0 != UNLINK (d->cfgfile)) | 663 | if (0 != UNLINK (d->cfgfile)) |
727 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 664 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
728 | "unlink", | 665 | "unlink", d->cfgfile); |
729 | d->cfgfile); | ||
730 | if (d->hostname != NULL) | 666 | if (d->hostname != NULL) |
731 | { | 667 | { |
732 | #if DEBUG_TESTING | 668 | #if DEBUG_TESTING |
733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 669 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
734 | "Removing configuration file on remote host `%s'.\n", | 670 | "Removing configuration file on remote host `%s'.\n", |
735 | d->hostname); | 671 | d->hostname); |
736 | #endif | 672 | #endif |
737 | if (NULL != d->username) | 673 | if (NULL != d->username) |
738 | GNUNET_asprintf (&dst, | 674 | GNUNET_asprintf (&dst, "%s@%s", d->username, d->hostname); |
739 | "%s@%s", | ||
740 | d->username, | ||
741 | d->hostname); | ||
742 | else | 675 | else |
743 | dst = GNUNET_strdup (d->hostname); | 676 | dst = GNUNET_strdup (d->hostname); |
744 | d->pid = GNUNET_OS_start_process ("ssh", | 677 | d->pid = GNUNET_OS_start_process ("ssh", |
745 | "ssh", | 678 | "ssh", dst, "rm", d->cfgfile, NULL); |
746 | dst, | ||
747 | "rm", | ||
748 | d->cfgfile, | ||
749 | NULL); | ||
750 | GNUNET_free (dst); | 679 | GNUNET_free (dst); |
751 | if (-1 == d->pid) | 680 | if (-1 == d->pid) |
752 | { | 681 | { |
753 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
754 | _("Could not start `%s' process to delete configuration file.\n"), | 683 | _ |
755 | "ssh"); | 684 | ("Could not start `%s' process to delete configuration file.\n"), |
756 | GNUNET_free (d->cfgfile); | 685 | "ssh"); |
757 | GNUNET_free_non_null (d->hostname); | 686 | GNUNET_free (d->cfgfile); |
758 | GNUNET_free_non_null (d->username); | 687 | GNUNET_free_non_null (d->hostname); |
759 | GNUNET_free (d); | 688 | GNUNET_free_non_null (d->username); |
760 | cb (cb_cls, _("Error cleaning up configuration file.\n")); | 689 | GNUNET_free (d); |
761 | return; | 690 | cb (cb_cls, _("Error cleaning up configuration file.\n")); |
762 | } | 691 | return; |
692 | } | ||
763 | d->phase = SP_CLEANUP; | 693 | d->phase = SP_CLEANUP; |
764 | d->dead_cb = cb; | 694 | d->dead_cb = cb; |
765 | d->dead_cb_cls = cb_cls; | 695 | d->dead_cb_cls = cb_cls; |
766 | d->task | 696 | d->task |
767 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 697 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
768 | GNUNET_CONSTANTS_EXEC_WAIT, | 698 | GNUNET_CONSTANTS_EXEC_WAIT, |
769 | &start_fsm, | 699 | &start_fsm, d); |
770 | d); | ||
771 | return; | 700 | return; |
772 | } | 701 | } |
773 | GNUNET_CONFIGURATION_destroy (d->cfg); | 702 | GNUNET_CONFIGURATION_destroy (d->cfg); |
@@ -788,81 +717,68 @@ void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | |||
788 | * @param cb function called once the configuration was changed | 717 | * @param cb function called once the configuration was changed |
789 | * @param cb_cls closure for cb | 718 | * @param cb_cls closure for cb |
790 | */ | 719 | */ |
791 | void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | 720 | void |
792 | struct GNUNET_CONFIGURATION_Handle *cfg, | 721 | GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, |
793 | GNUNET_TESTING_NotifyCompletion cb, | 722 | struct GNUNET_CONFIGURATION_Handle *cfg, |
794 | void * cb_cls) | 723 | GNUNET_TESTING_NotifyCompletion cb, |
724 | void *cb_cls) | ||
795 | { | 725 | { |
796 | char *arg; | 726 | char *arg; |
797 | 727 | ||
798 | if (d->phase != SP_START_DONE) | 728 | if (d->phase != SP_START_DONE) |
799 | { | 729 | { |
800 | if (NULL != cb) | 730 | if (NULL != cb) |
801 | cb (cb_cls, | 731 | cb (cb_cls, |
802 | _("Peer not yet running, can not change configuration at this point.")); | 732 | _ |
803 | return; | 733 | ("Peer not yet running, can not change configuration at this point.")); |
734 | return; | ||
804 | } | 735 | } |
805 | 736 | ||
806 | /* 1) write configuration to temporary file */ | 737 | /* 1) write configuration to temporary file */ |
807 | if (GNUNET_OK != | 738 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, d->cfgfile)) |
808 | GNUNET_CONFIGURATION_write (cfg, | ||
809 | d->cfgfile)) | ||
810 | { | 739 | { |
811 | if (NULL != cb) | 740 | if (NULL != cb) |
812 | cb (cb_cls, | 741 | cb (cb_cls, _("Failed to write new configuration to disk.")); |
813 | _("Failed to write new configuration to disk.")); | ||
814 | return; | 742 | return; |
815 | } | 743 | } |
816 | 744 | ||
817 | /* 2) copy file to remote host (if necessary) */ | 745 | /* 2) copy file to remote host (if necessary) */ |
818 | if (NULL == d->hostname) | 746 | if (NULL == d->hostname) |
819 | { | 747 | { |
820 | /* signal success */ | 748 | /* signal success */ |
821 | if (NULL != cb) | 749 | if (NULL != cb) |
822 | cb (cb_cls, NULL); | 750 | cb (cb_cls, NULL); |
823 | return; | 751 | return; |
824 | } | 752 | } |
825 | #if DEBUG_TESTING | 753 | #if DEBUG_TESTING |
826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 754 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
827 | "Copying updated configuration file to remote host `%s'.\n", | 755 | "Copying updated configuration file to remote host `%s'.\n", |
828 | d->hostname); | 756 | d->hostname); |
829 | #endif | 757 | #endif |
830 | d->phase = SP_CONFIG_UPDATE; | 758 | d->phase = SP_CONFIG_UPDATE; |
831 | if (NULL != d->username) | 759 | if (NULL != d->username) |
832 | GNUNET_asprintf (&arg, | 760 | GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile); |
833 | "%s@%s:%s", | ||
834 | d->username, | ||
835 | d->hostname, | ||
836 | d->cfgfile); | ||
837 | else | 761 | else |
838 | GNUNET_asprintf (&arg, | 762 | GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile); |
839 | "%s:%s", | 763 | d->pid = GNUNET_OS_start_process ("scp", "scp", d->cfgfile, arg, NULL); |
840 | d->hostname, | ||
841 | d->cfgfile); | ||
842 | d->pid = GNUNET_OS_start_process ("scp", | ||
843 | "scp", | ||
844 | d->cfgfile, | ||
845 | arg, | ||
846 | NULL); | ||
847 | GNUNET_free (arg); | 764 | GNUNET_free (arg); |
848 | if (-1 == d->pid) | 765 | if (-1 == d->pid) |
849 | { | 766 | { |
850 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 767 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
851 | _("Could not start `%s' process to copy configuration file.\n"), | 768 | _ |
852 | "scp"); | 769 | ("Could not start `%s' process to copy configuration file.\n"), |
770 | "scp"); | ||
853 | if (NULL != cb) | 771 | if (NULL != cb) |
854 | cb (cb_cls, | 772 | cb (cb_cls, _("Failed to copy new configuration to remote machine.")); |
855 | _("Failed to copy new configuration to remote machine.")); | ||
856 | d->phase = SP_START_DONE; | 773 | d->phase = SP_START_DONE; |
857 | return; | 774 | return; |
858 | } | 775 | } |
859 | d->update_cb = cb; | 776 | d->update_cb = cb; |
860 | d->update_cb_cls = cb_cls; | 777 | d->update_cb_cls = cb_cls; |
861 | d->task | 778 | d->task |
862 | = GNUNET_SCHEDULER_add_delayed (d->sched, | 779 | = GNUNET_SCHEDULER_add_delayed (d->sched, |
863 | GNUNET_CONSTANTS_EXEC_WAIT, | 780 | GNUNET_CONSTANTS_EXEC_WAIT, |
864 | &start_fsm, | 781 | &start_fsm, d); |
865 | d); | ||
866 | } | 782 | } |
867 | 783 | ||
868 | 784 | ||
@@ -895,7 +811,7 @@ struct ConnectContext | |||
895 | /** | 811 | /** |
896 | * Function to call once we are done (or have timed out). | 812 | * Function to call once we are done (or have timed out). |
897 | */ | 813 | */ |
898 | GNUNET_TESTING_NotifyCompletion cb; | 814 | GNUNET_TESTING_NotifyConnection cb; |
899 | 815 | ||
900 | /** | 816 | /** |
901 | * Closure for "nb". | 817 | * Closure for "nb". |
@@ -926,16 +842,19 @@ struct ConnectContext | |||
926 | */ | 842 | */ |
927 | static void | 843 | static void |
928 | notify_connect_result (void *cls, | 844 | notify_connect_result (void *cls, |
929 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 845 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
930 | { | 846 | { |
931 | struct ConnectContext *ctx = cls; | 847 | struct ConnectContext *ctx = cls; |
932 | 848 | ||
933 | if (ctx->cb != NULL) | 849 | if (ctx->cb != NULL) |
934 | { | 850 | { |
935 | if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) | 851 | if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) |
936 | ctx->cb (ctx->cb_cls, _("Peers failed to connect")); | 852 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, |
853 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
854 | _("Peers failed to connect")); | ||
937 | else | 855 | else |
938 | ctx->cb (ctx->cb_cls, NULL); | 856 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, |
857 | ctx->d2->cfg, ctx->d1, ctx->d2, NULL); | ||
939 | } | 858 | } |
940 | GNUNET_free (ctx); | 859 | GNUNET_free (ctx); |
941 | } | 860 | } |
@@ -964,28 +883,24 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
964 | GNUNET_TRANSPORT_disconnect (ctx->d2th); | 883 | GNUNET_TRANSPORT_disconnect (ctx->d2th); |
965 | ctx->d2th = NULL; | 884 | ctx->d2th = NULL; |
966 | GNUNET_SCHEDULER_add_continuation (ctx->d1->sched, | 885 | GNUNET_SCHEDULER_add_continuation (ctx->d1->sched, |
967 | ¬ify_connect_result, | 886 | ¬ify_connect_result, |
968 | ctx, | 887 | ctx, |
969 | (buf == NULL) ? | 888 | (buf == NULL) ? |
970 | GNUNET_SCHEDULER_REASON_TIMEOUT : | 889 | GNUNET_SCHEDULER_REASON_TIMEOUT : |
971 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 890 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
972 | return 0; | 891 | return 0; |
973 | } | 892 | } |
974 | 893 | ||
975 | 894 | ||
976 | #if 0 | 895 | #if 0 |
977 | static void | 896 | static void |
978 | timeout_hello_task (void *cls, | 897 | timeout_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
979 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
980 | { | 898 | { |
981 | GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, | 899 | GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx); |
982 | &process_hello, | ||
983 | ctx); | ||
984 | GNUNET_TRANSPORT_disconnect (ctx->d1th); | 900 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
985 | GNUNET_TRANSPORT_disconnect (ctx->d2th); | 901 | GNUNET_TRANSPORT_disconnect (ctx->d2th); |
986 | if (NULL != ctx->cb) | 902 | if (NULL != ctx->cb) |
987 | ctx->cb (ctx->cb_cls, | 903 | ctx->cb (ctx->cb_cls, _("Failed to receive `HELLO' from peer\n")); |
988 | _("Failed to receive `HELLO' from peer\n")); | ||
989 | GNUNET_free (ctx); | 904 | GNUNET_free (ctx); |
990 | } | 905 | } |
991 | #endif | 906 | #endif |
@@ -999,31 +914,38 @@ timeout_hello_task (void *cls, | |||
999 | * @param message HELLO message of peer | 914 | * @param message HELLO message of peer |
1000 | */ | 915 | */ |
1001 | static void | 916 | static void |
1002 | process_hello (void *cls, | 917 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
1003 | const struct GNUNET_MessageHeader *message) | ||
1004 | { | 918 | { |
1005 | struct ConnectContext *ctx = cls; | 919 | struct ConnectContext *ctx = cls; |
1006 | 920 | ||
1007 | /* first of all, stop the notification stuff */ | 921 | /* first of all, stop the notification stuff */ |
1008 | GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, | 922 | GNUNET_TRANSPORT_get_hello_cancel (ctx->d1th, &process_hello, ctx); |
1009 | &process_hello, | ||
1010 | ctx); | ||
1011 | #if DEBUG_TESTING | 923 | #if DEBUG_TESTING |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1013 | "Received `%s' from transport service of `%4s'\n", | 925 | "Received `%s' from transport service of `%4s'\n", |
1014 | "HELLO", GNUNET_i2s (peer)); | 926 | "HELLO", GNUNET_i2s (&ctx->d1->id)); |
1015 | #endif | 927 | #endif |
1016 | GNUNET_assert (message != NULL); | 928 | GNUNET_assert (message != NULL); |
1017 | GNUNET_TRANSPORT_offer_hello (ctx->d2th, message); | 929 | GNUNET_TRANSPORT_offer_hello (ctx->d2th, message); |
1018 | ctx->ntr | 930 | ctx->ntr |
1019 | = GNUNET_CORE_notify_transmit_ready (ctx->d2->server, | 931 | = GNUNET_CORE_notify_transmit_ready (ctx->d2->server, |
1020 | 0, | 932 | 0, |
1021 | GNUNET_TIME_absolute_get_remaining (ctx->timeout), | 933 | GNUNET_TIME_absolute_get_remaining |
1022 | &ctx->d1->id, | 934 | (ctx->timeout), &ctx->d1->id, |
1023 | sizeof (struct GNUNET_MessageHeader), | 935 | sizeof (struct GNUNET_MessageHeader), |
1024 | &transmit_ready, ctx); | 936 | &transmit_ready, ctx); |
1025 | } | 937 | } |
1026 | 938 | ||
939 | /* | ||
940 | * Accessor function since we have hidden what GNUNET_TESTING_Daemon is | ||
941 | * | ||
942 | * FIXME: Either expose members or figure out a better way! | ||
943 | */ | ||
944 | char * | ||
945 | GNUNET_TESTING_daemon_get_shortname (struct GNUNET_TESTING_Daemon *d) | ||
946 | { | ||
947 | return d->shortname; | ||
948 | } | ||
1027 | 949 | ||
1028 | /** | 950 | /** |
1029 | * Establish a connection between two GNUnet daemons. | 951 | * Establish a connection between two GNUnet daemons. |
@@ -1035,55 +957,72 @@ process_hello (void *cls, | |||
1035 | * @param cb function to call at the end | 957 | * @param cb function to call at the end |
1036 | * @param cb_cls closure for cb | 958 | * @param cb_cls closure for cb |
1037 | */ | 959 | */ |
1038 | void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | 960 | void |
1039 | struct GNUNET_TESTING_Daemon *d2, | 961 | GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, |
1040 | struct GNUNET_TIME_Relative timeout, | 962 | struct GNUNET_TESTING_Daemon *d2, |
1041 | GNUNET_TESTING_NotifyCompletion cb, | 963 | struct GNUNET_TIME_Relative timeout, |
1042 | void *cb_cls) | 964 | GNUNET_TESTING_NotifyConnection cb, |
965 | void *cb_cls) | ||
1043 | { | 966 | { |
1044 | struct ConnectContext *ctx; | 967 | struct ConnectContext *ctx; |
1045 | 968 | ||
1046 | if ( (d1->server == NULL) || | 969 | if ((d1->server == NULL) || (d2->server == NULL)) |
1047 | (d2->server == NULL) ) | ||
1048 | { | 970 | { |
1049 | if (NULL != cb) | 971 | if (NULL != cb) |
1050 | cb (cb_cls, _("Peers are not fully running yet, can not connect!\n")); | 972 | cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, |
973 | _("Peers are not fully running yet, can not connect!\n")); | ||
1051 | return; | 974 | return; |
1052 | } | 975 | } |
1053 | ctx = GNUNET_malloc (sizeof(struct ConnectContext)); | 976 | ctx = GNUNET_malloc (sizeof (struct ConnectContext)); |
1054 | ctx->d1 = d1; | 977 | ctx->d1 = d1; |
1055 | ctx->d2 = d2; | 978 | ctx->d2 = d2; |
1056 | ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 979 | ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1057 | ctx->cb = cb; | 980 | ctx->cb = cb; |
1058 | ctx->cb_cls = cb_cls; | 981 | ctx->cb_cls = cb_cls; |
982 | #if DEBUG_TESTING | ||
983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
984 | "Asked to connect peer %s to peer %s\n", | ||
985 | d1->shortname, d2->shortname); | ||
986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
987 | "Connecting to transport service of peer %s\n", d1->shortname); | ||
988 | #endif | ||
1059 | ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched, | 989 | ctx->d1th = GNUNET_TRANSPORT_connect (d1->sched, |
1060 | d1->cfg, | 990 | d1->cfg, d1, NULL, NULL, NULL); |
1061 | d1, | ||
1062 | NULL, NULL, NULL); | ||
1063 | if (ctx->d1th == NULL) | 991 | if (ctx->d1th == NULL) |
1064 | { | 992 | { |
1065 | GNUNET_free (ctx); | 993 | GNUNET_free (ctx); |
1066 | if (NULL != cb) | 994 | if (NULL != cb) |
1067 | cb (cb_cls, _("Failed to connect to transport service!\n")); | 995 | cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, |
996 | _("Failed to connect to transport service!\n")); | ||
1068 | return; | 997 | return; |
1069 | } | 998 | } |
999 | #if DEBUG_TESTING | ||
1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1001 | "Asked to connect peer %s to peer %s\n", | ||
1002 | d1->shortname, d2->shortname); | ||
1003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1004 | "Connecting to transport service of peer %s\n", d2->shortname); | ||
1005 | |||
1006 | #endif | ||
1070 | ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched, | 1007 | ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched, |
1071 | d2->cfg, | 1008 | d2->cfg, d2, NULL, NULL, NULL); |
1072 | d2, | ||
1073 | NULL, NULL, NULL); | ||
1074 | if (ctx->d2th == NULL) | 1009 | if (ctx->d2th == NULL) |
1075 | { | 1010 | { |
1076 | GNUNET_TRANSPORT_disconnect (ctx->d1th); | 1011 | GNUNET_TRANSPORT_disconnect (ctx->d1th); |
1077 | GNUNET_free (ctx); | 1012 | GNUNET_free (ctx); |
1078 | if (NULL != cb) | 1013 | if (NULL != cb) |
1079 | cb (cb_cls, _("Failed to connect to transport service!\n")); | 1014 | cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2, |
1015 | _("Failed to connect to transport service!\n")); | ||
1080 | return; | 1016 | return; |
1081 | } | 1017 | } |
1018 | |||
1019 | #if DEBUG_TESTING | ||
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1021 | "Asking for hello from peer %s\n", GNUNET_i2s (&d1->id)); | ||
1022 | #endif | ||
1082 | /* FIXME: need to handle timeout: start timeout task | 1023 | /* FIXME: need to handle timeout: start timeout task |
1083 | as well here! (use 'timeout_hello_task') */ | 1024 | as well here! (use 'timeout_hello_task') */ |
1084 | GNUNET_TRANSPORT_get_hello (ctx->d1th, | 1025 | GNUNET_TRANSPORT_get_hello (ctx->d1th, &process_hello, ctx); |
1085 | &process_hello, | ||
1086 | ctx); | ||
1087 | } | 1026 | } |
1088 | 1027 | ||
1089 | 1028 | ||
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index b87507364..424dada34 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "gnunet_arm_service.h" | 27 | #include "gnunet_arm_service.h" |
28 | #include "gnunet_testing_lib.h" | 28 | #include "gnunet_testing_lib.h" |
29 | 29 | ||
30 | #define VERBOSE_TESTING GNUNET_YES | ||
31 | |||
30 | /** | 32 | /** |
31 | * Lowest port used for GNUnet testing. Should be high enough to not | 33 | * Lowest port used for GNUnet testing. Should be high enough to not |
32 | * conflict with other applications running on the hosts but be low | 34 | * conflict with other applications running on the hosts but be low |
@@ -42,6 +44,8 @@ | |||
42 | */ | 44 | */ |
43 | #define HIGH_PORT 32000 | 45 | #define HIGH_PORT 32000 |
44 | 46 | ||
47 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
48 | |||
45 | /** | 49 | /** |
46 | * Data we keep per peer. | 50 | * Data we keep per peer. |
47 | */ | 51 | */ |
@@ -54,7 +58,7 @@ struct PeerData | |||
54 | * updates). | 58 | * updates). |
55 | */ | 59 | */ |
56 | struct GNUNET_CONFIGURATION_Handle *cfg; | 60 | struct GNUNET_CONFIGURATION_Handle *cfg; |
57 | 61 | ||
58 | /** | 62 | /** |
59 | * Handle for controlling the daemon. | 63 | * Handle for controlling the daemon. |
60 | */ | 64 | */ |
@@ -71,7 +75,7 @@ struct HostData | |||
71 | * Name of the host. | 75 | * Name of the host. |
72 | */ | 76 | */ |
73 | char *hostname; | 77 | char *hostname; |
74 | 78 | ||
75 | /** | 79 | /** |
76 | * Lowest port that we have not yet used | 80 | * Lowest port that we have not yet used |
77 | * for GNUnet. | 81 | * for GNUnet. |
@@ -87,7 +91,7 @@ struct GNUNET_TESTING_PeerGroup | |||
87 | { | 91 | { |
88 | /** | 92 | /** |
89 | * Our scheduler. | 93 | * Our scheduler. |
90 | */ | 94 | */ |
91 | struct GNUNET_SCHEDULER_Handle *sched; | 95 | struct GNUNET_SCHEDULER_Handle *sched; |
92 | 96 | ||
93 | /** | 97 | /** |
@@ -97,7 +101,7 @@ struct GNUNET_TESTING_PeerGroup | |||
97 | 101 | ||
98 | /** | 102 | /** |
99 | * Function to call on each started daemon. | 103 | * Function to call on each started daemon. |
100 | */ | 104 | */ |
101 | GNUNET_TESTING_NotifyDaemonRunning cb; | 105 | GNUNET_TESTING_NotifyDaemonRunning cb; |
102 | 106 | ||
103 | /** | 107 | /** |
@@ -105,6 +109,16 @@ struct GNUNET_TESTING_PeerGroup | |||
105 | */ | 109 | */ |
106 | void *cb_cls; | 110 | void *cb_cls; |
107 | 111 | ||
112 | /* | ||
113 | * Function to call on each topology connection created | ||
114 | */ | ||
115 | GNUNET_TESTING_NotifyConnection notify_connection; | ||
116 | |||
117 | /* | ||
118 | * Callback for notify_connection | ||
119 | */ | ||
120 | void *notify_connection_cls; | ||
121 | |||
108 | /** | 122 | /** |
109 | * NULL-terminated array of information about | 123 | * NULL-terminated array of information about |
110 | * hosts. | 124 | * hosts. |
@@ -118,13 +132,13 @@ struct GNUNET_TESTING_PeerGroup | |||
118 | 132 | ||
119 | /** | 133 | /** |
120 | * Number of peers in this group. | 134 | * Number of peers in this group. |
121 | */ | 135 | */ |
122 | unsigned int total; | 136 | unsigned int total; |
123 | 137 | ||
124 | }; | 138 | }; |
125 | 139 | ||
126 | 140 | ||
127 | struct UpdateContext | 141 | struct UpdateContext |
128 | { | 142 | { |
129 | struct GNUNET_CONFIGURATION_Handle *ret; | 143 | struct GNUNET_CONFIGURATION_Handle *ret; |
130 | unsigned int nport; | 144 | unsigned int nport; |
@@ -140,29 +154,20 @@ struct UpdateContext | |||
140 | * @param option name of the option | 154 | * @param option name of the option |
141 | * @param value value of the option | 155 | * @param value value of the option |
142 | */ | 156 | */ |
143 | static void | 157 | static void |
144 | update_config(void *cls, | 158 | update_config (void *cls, |
145 | const char *section, | 159 | const char *section, const char *option, const char *value) |
146 | const char *option, | ||
147 | const char *value) | ||
148 | { | 160 | { |
149 | struct UpdateContext *ctx = cls; | 161 | struct UpdateContext *ctx = cls; |
150 | unsigned int ival; | 162 | unsigned int ival; |
151 | char cval[12]; | 163 | char cval[12]; |
152 | 164 | ||
153 | if ( (0 == strcmp (option, "PORT")) && | 165 | if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) |
154 | (1 == sscanf (value, "%u", &ival)) ) | ||
155 | { | 166 | { |
156 | GNUNET_snprintf (cval, | 167 | GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++); |
157 | sizeof(cval), | ||
158 | "%u", | ||
159 | ctx->nport++); | ||
160 | value = cval; | 168 | value = cval; |
161 | } | 169 | } |
162 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, | 170 | GNUNET_CONFIGURATION_set_value_string (ctx->ret, section, option, value); |
163 | section, | ||
164 | option, | ||
165 | value); | ||
166 | } | 171 | } |
167 | 172 | ||
168 | 173 | ||
@@ -177,9 +182,8 @@ update_config(void *cls, | |||
177 | * port numbers that were used | 182 | * port numbers that were used |
178 | * @return new configuration, NULL on error | 183 | * @return new configuration, NULL on error |
179 | */ | 184 | */ |
180 | static struct GNUNET_CONFIGURATION_Handle* | 185 | static struct GNUNET_CONFIGURATION_Handle * |
181 | make_config (const struct GNUNET_CONFIGURATION_Handle*cfg, | 186 | make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t * port) |
182 | uint16_t *port) | ||
183 | { | 187 | { |
184 | struct UpdateContext uc; | 188 | struct UpdateContext uc; |
185 | uint16_t orig; | 189 | uint16_t orig; |
@@ -187,9 +191,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle*cfg, | |||
187 | orig = *port; | 191 | orig = *port; |
188 | uc.nport = *port; | 192 | uc.nport = *port; |
189 | uc.ret = GNUNET_CONFIGURATION_create (); | 193 | uc.ret = GNUNET_CONFIGURATION_create (); |
190 | GNUNET_CONFIGURATION_iterate (cfg, | 194 | GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); |
191 | &update_config, | ||
192 | &uc); | ||
193 | if (uc.nport >= HIGH_PORT) | 195 | if (uc.nport >= HIGH_PORT) |
194 | { | 196 | { |
195 | *port = orig; | 197 | *port = orig; |
@@ -200,6 +202,143 @@ make_config (const struct GNUNET_CONFIGURATION_Handle*cfg, | |||
200 | return uc.ret; | 202 | return uc.ret; |
201 | } | 203 | } |
202 | 204 | ||
205 | static int | ||
206 | create_clique (struct GNUNET_TESTING_PeerGroup *pg) | ||
207 | { | ||
208 | unsigned int outer_count; | ||
209 | unsigned int inner_count; | ||
210 | int connect_attempts; | ||
211 | |||
212 | connect_attempts = 0; | ||
213 | |||
214 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | ||
215 | { | ||
216 | for (inner_count = outer_count + 1; inner_count < pg->total; | ||
217 | inner_count++) | ||
218 | { | ||
219 | #if VERBOSE_TESTING | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
221 | "Connecting peer %d to peer %d\n", | ||
222 | outer_count, inner_count); | ||
223 | #endif | ||
224 | GNUNET_TESTING_daemons_connect (pg->peers[outer_count].daemon, | ||
225 | pg->peers[inner_count].daemon, | ||
226 | CONNECT_TIMEOUT, | ||
227 | pg->notify_connection, | ||
228 | pg->notify_connection_cls); | ||
229 | connect_attempts++; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | return connect_attempts; | ||
234 | } | ||
235 | |||
236 | |||
237 | /* | ||
238 | * Takes a peer group and attempts to create a topology based on the | ||
239 | * one specified in the configuration file. Returns the number of connections | ||
240 | * that will attempt to be created, but this will happen asynchronously(?) so | ||
241 | * the caller will have to keep track (via the callback) of whether or not | ||
242 | * the connection actually happened. | ||
243 | * | ||
244 | * @param pg the peer group struct representing the running peers | ||
245 | * | ||
246 | */ | ||
247 | int | ||
248 | GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg) | ||
249 | { | ||
250 | /* Put stuff at home in here... */ | ||
251 | unsigned long long topology_num; | ||
252 | int ret; | ||
253 | |||
254 | GNUNET_assert (pg->notify_connection != NULL); | ||
255 | ret = 0; | ||
256 | if (GNUNET_YES == | ||
257 | GNUNET_CONFIGURATION_get_value_number (pg->cfg, "testing", "topology", | ||
258 | &topology_num)) | ||
259 | { | ||
260 | switch (topology_num) | ||
261 | { | ||
262 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | ||
263 | #if VERBOSE_TESTING | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
265 | _("Creating clique topology (may take a bit!)\n")); | ||
266 | ret = create_clique (pg); | ||
267 | break; | ||
268 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
270 | _("Creating small world topology (may take a bit!)\n")); | ||
271 | #endif | ||
272 | ret = GNUNET_SYSERR; | ||
273 | /* ret = | ||
274 | GNUNET_REMOTE_connect_small_world_ring (&totalConnections, | ||
275 | number_of_daemons, | ||
276 | list_as_array, dotOutFile, | ||
277 | percentage, logNModifier); | ||
278 | */ | ||
279 | break; | ||
280 | case GNUNET_TESTING_TOPOLOGY_RING: | ||
281 | #if VERBOSE_TESTING | ||
282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
283 | _("Creating ring topology (may take a bit!)\n")); | ||
284 | #endif | ||
285 | /* | ||
286 | ret = GNUNET_REMOTE_connect_ring (&totalConnections, head, dotOutFile); | ||
287 | */ | ||
288 | ret = GNUNET_SYSERR; | ||
289 | break; | ||
290 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | ||
291 | #if VERBOSE_TESTING | ||
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
293 | _("Creating 2d torus topology (may take a bit!)\n")); | ||
294 | #endif | ||
295 | /* | ||
296 | ret = | ||
297 | GNUNET_REMOTE_connect_2d_torus (&totalConnections, number_of_daemons, | ||
298 | list_as_array, dotOutFile); | ||
299 | */ | ||
300 | ret = GNUNET_SYSERR; | ||
301 | break; | ||
302 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | ||
303 | #if VERBOSE_TESTING | ||
304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
305 | _("Creating Erdos-Renyi topology (may take a bit!)\n")); | ||
306 | #endif | ||
307 | /* ret = | ||
308 | GNUNET_REMOTE_connect_erdos_renyi (&totalConnections, percentage, | ||
309 | head, dotOutFile); | ||
310 | */ | ||
311 | ret = GNUNET_SYSERR; | ||
312 | break; | ||
313 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | ||
314 | #if VERBOSE_TESTING | ||
315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
316 | _("Creating InterNAT topology (may take a bit!)\n")); | ||
317 | #endif | ||
318 | /* | ||
319 | ret = | ||
320 | GNUNET_REMOTE_connect_nated_internet (&totalConnections, percentage, | ||
321 | number_of_daemons, head, | ||
322 | dotOutFile); | ||
323 | */ | ||
324 | ret = GNUNET_SYSERR; | ||
325 | break; | ||
326 | case GNUNET_TESTING_TOPOLOGY_NONE: | ||
327 | ret = 0; | ||
328 | break; | ||
329 | default: | ||
330 | ret = GNUNET_SYSERR; | ||
331 | break; | ||
332 | } | ||
333 | } | ||
334 | else | ||
335 | { | ||
336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
337 | _("No topology specified, was one intended?\n")); | ||
338 | } | ||
339 | |||
340 | return ret; | ||
341 | } | ||
203 | 342 | ||
204 | /** | 343 | /** |
205 | * Start count gnunetd processes with the same set of transports and | 344 | * Start count gnunetd processes with the same set of transports and |
@@ -212,85 +351,93 @@ make_config (const struct GNUNET_CONFIGURATION_Handle*cfg, | |||
212 | * @param total number of daemons to start | 351 | * @param total number of daemons to start |
213 | * @param cb function to call on each daemon that was started | 352 | * @param cb function to call on each daemon that was started |
214 | * @param cb_cls closure for cb | 353 | * @param cb_cls closure for cb |
354 | * @param connect_callback function to call each time two hosts are connected | ||
355 | * @param connect_callback_cls closure for connect_callback | ||
215 | * @param hostnames space-separated list of hostnames to use; can be NULL (to run | 356 | * @param hostnames space-separated list of hostnames to use; can be NULL (to run |
216 | * everything on localhost). | 357 | * everything on localhost). |
217 | * @return NULL on error, otherwise handle to control peer group | 358 | * @return NULL on error, otherwise handle to control peer group |
218 | */ | 359 | */ |
219 | struct GNUNET_TESTING_PeerGroup * | 360 | struct GNUNET_TESTING_PeerGroup * |
220 | GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, | 361 | GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, |
221 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 362 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
222 | unsigned int total, | 363 | unsigned int total, |
223 | GNUNET_TESTING_NotifyDaemonRunning cb, | 364 | GNUNET_TESTING_NotifyDaemonRunning cb, |
224 | void *cb_cls, | 365 | void *cb_cls, |
225 | const char *hostnames) | 366 | GNUNET_TESTING_NotifyConnection |
367 | connect_callback, void *connect_callback_cls, | ||
368 | const char *hostnames) | ||
226 | { | 369 | { |
227 | struct GNUNET_TESTING_PeerGroup *pg; | 370 | struct GNUNET_TESTING_PeerGroup *pg; |
228 | const char *rpos; | 371 | const char *rpos; |
229 | char *pos; | 372 | char *pos; |
230 | char *start; | 373 | char *start; |
231 | const char *hostname; | 374 | const char *hostname; |
375 | char *baseservicehome; | ||
376 | char *newservicehome; | ||
232 | struct GNUNET_CONFIGURATION_Handle *pcfg; | 377 | struct GNUNET_CONFIGURATION_Handle *pcfg; |
233 | unsigned int off; | 378 | unsigned int off; |
234 | unsigned int hostcnt; | 379 | unsigned int hostcnt; |
235 | uint16_t minport; | 380 | uint16_t minport; |
381 | int tempsize; | ||
236 | 382 | ||
237 | if (0 == total) | 383 | if (0 == total) |
238 | { | 384 | { |
239 | GNUNET_break (0); | 385 | GNUNET_break (0); |
240 | return NULL; | 386 | return NULL; |
241 | } | 387 | } |
242 | pg = GNUNET_malloc (sizeof(struct GNUNET_TESTING_PeerGroup)); | 388 | pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup)); |
243 | pg->sched = sched; | 389 | pg->sched = sched; |
244 | pg->cfg = cfg; | 390 | pg->cfg = cfg; |
245 | pg->cb = cb; | 391 | pg->cb = cb; |
246 | pg->cb_cls = cb_cls; | 392 | pg->cb_cls = cb_cls; |
393 | pg->notify_connection = connect_callback; | ||
394 | pg->notify_connection_cls = connect_callback_cls; | ||
247 | pg->total = total; | 395 | pg->total = total; |
248 | pg->peers = GNUNET_malloc (total * sizeof(struct PeerData)); | 396 | pg->peers = GNUNET_malloc (total * sizeof (struct PeerData)); |
249 | if (NULL != hostnames) | 397 | if (NULL != hostnames) |
250 | { | 398 | { |
251 | off = 2; | 399 | off = 2; |
252 | /* skip leading spaces */ | 400 | /* skip leading spaces */ |
253 | while ( (0 != *hostnames) && | 401 | while ((0 != *hostnames) && (isspace (*hostnames))) |
254 | (isspace(*hostnames))) | 402 | hostnames++; |
255 | hostnames++; | ||
256 | rpos = hostnames; | 403 | rpos = hostnames; |
257 | while ('\0' != *rpos) | 404 | while ('\0' != *rpos) |
258 | { | 405 | { |
259 | if (isspace (*rpos)) | 406 | if (isspace (*rpos)) |
260 | off++; | 407 | off++; |
261 | rpos++; | 408 | rpos++; |
262 | } | 409 | } |
263 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); | 410 | pg->hosts = GNUNET_malloc (off * sizeof (struct HostData)); |
264 | off = 0; | 411 | off = 0; |
265 | start = GNUNET_strdup (hostnames); | 412 | start = GNUNET_strdup (hostnames); |
266 | pos = start; | 413 | pos = start; |
267 | while ('\0' != *pos) | 414 | while ('\0' != *pos) |
268 | { | 415 | { |
269 | if (isspace (*pos)) | 416 | if (isspace (*pos)) |
270 | { | 417 | { |
271 | *pos = '\0'; | 418 | *pos = '\0'; |
272 | if (strlen(start) > 0) | 419 | if (strlen (start) > 0) |
273 | { | 420 | { |
274 | pg->hosts[off].minport = LOW_PORT; | 421 | pg->hosts[off].minport = LOW_PORT; |
275 | pg->hosts[off++].hostname = start; | 422 | pg->hosts[off++].hostname = start; |
276 | } | 423 | } |
277 | start = pos+1; | 424 | start = pos + 1; |
278 | } | 425 | } |
279 | pos++; | 426 | pos++; |
280 | } | 427 | } |
281 | if (strlen(start) > 0) | 428 | if (strlen (start) > 0) |
282 | { | 429 | { |
283 | pg->hosts[off].minport = LOW_PORT; | 430 | pg->hosts[off].minport = LOW_PORT; |
284 | pg->hosts[off++].hostname = start; | 431 | pg->hosts[off++].hostname = start; |
285 | } | 432 | } |
286 | if (off == 0) | 433 | if (off == 0) |
287 | { | 434 | { |
288 | GNUNET_free (start); | 435 | GNUNET_free (start); |
289 | GNUNET_free (pg->hosts); | 436 | GNUNET_free (pg->hosts); |
290 | pg->hosts = NULL; | 437 | pg->hosts = NULL; |
291 | } | 438 | } |
292 | hostcnt = off; | 439 | hostcnt = off; |
293 | minport = 0; /* make gcc happy */ | 440 | minport = 0; /* make gcc happy */ |
294 | } | 441 | } |
295 | else | 442 | else |
296 | { | 443 | { |
@@ -300,33 +447,51 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
300 | for (off = 0; off < total; off++) | 447 | for (off = 0; off < total; off++) |
301 | { | 448 | { |
302 | if (hostcnt > 0) | 449 | if (hostcnt > 0) |
303 | { | 450 | { |
304 | hostname = pg->hosts[off % hostcnt].hostname; | 451 | hostname = pg->hosts[off % hostcnt].hostname; |
305 | pcfg = make_config (cfg, &pg->hosts[off % hostcnt].minport); | 452 | pcfg = make_config (cfg, &pg->hosts[off % hostcnt].minport); |
306 | } | 453 | } |
307 | else | 454 | else |
308 | { | 455 | { |
309 | hostname = NULL; | 456 | hostname = NULL; |
310 | pcfg = make_config (cfg, &minport); | 457 | pcfg = make_config (cfg, &minport); |
311 | } | 458 | } |
312 | if (NULL == pcfg) | 459 | if (NULL == pcfg) |
313 | { | 460 | { |
314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 461 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
315 | _("Could not create configuration for peer number %u on `%s'!\n"), | 462 | _ |
316 | off, | 463 | ("Could not create configuration for peer number %u on `%s'!\n"), |
317 | hostname == NULL ? "localhost" : hostname); | 464 | off, hostname == NULL ? "localhost" : hostname); |
318 | continue; | 465 | continue; |
319 | } | 466 | } |
467 | |||
468 | if (GNUNET_YES == | ||
469 | GNUNET_CONFIGURATION_get_value_string (pcfg, "PATHS", "SERVICEHOME", | ||
470 | &baseservicehome)) | ||
471 | { | ||
472 | tempsize = snprintf (NULL, 0, "%s/%d/", baseservicehome, off) + 1; | ||
473 | newservicehome = GNUNET_malloc (tempsize); | ||
474 | snprintf (newservicehome, tempsize, "%s/%d/", baseservicehome, off); | ||
475 | } | ||
476 | else | ||
477 | { | ||
478 | tempsize = snprintf (NULL, 0, "%s/%d/", "/tmp/gnunet-testing-test-test", off) + 1; /* FIXME: set a default path, or read the TMPDIR variable or something */ | ||
479 | newservicehome = GNUNET_malloc (tempsize); | ||
480 | snprintf (newservicehome, tempsize, "%s/%d/", | ||
481 | "/tmp/gnunet-testing-test-test", off); | ||
482 | } | ||
483 | GNUNET_CONFIGURATION_set_value_string (pcfg, | ||
484 | "PATHS", | ||
485 | "SERVICEHOME", newservicehome); | ||
486 | |||
320 | pg->peers[off].cfg = pcfg; | 487 | pg->peers[off].cfg = pcfg; |
321 | pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched, | 488 | pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched, |
322 | pcfg, | 489 | pcfg, |
323 | hostname, | 490 | hostname, |
324 | cb, | 491 | cb, cb_cls); |
325 | cb_cls); | ||
326 | if (NULL == pg->peers[off].daemon) | 492 | if (NULL == pg->peers[off].daemon) |
327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
328 | _("Could not start peer number %u!\n"), | 494 | _("Could not start peer number %u!\n"), off); |
329 | off); | ||
330 | } | 495 | } |
331 | return pg; | 496 | return pg; |
332 | } | 497 | } |
@@ -345,14 +510,13 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg) | |||
345 | for (off = 0; off < pg->total; off++) | 510 | for (off = 0; off < pg->total; off++) |
346 | { | 511 | { |
347 | /* FIXME: should we wait for our | 512 | /* FIXME: should we wait for our |
348 | continuations to be called here? This | 513 | continuations to be called here? This |
349 | would require us to take a continuation | 514 | would require us to take a continuation |
350 | as well... */ | 515 | as well... */ |
351 | if (NULL != pg->peers[off].daemon) | 516 | if (NULL != pg->peers[off].daemon) |
352 | GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, | 517 | GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, NULL, NULL); |
353 | NULL, NULL); | ||
354 | if (NULL != pg->peers[off].cfg) | 518 | if (NULL != pg->peers[off].cfg) |
355 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); | 519 | GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg); |
356 | } | 520 | } |
357 | GNUNET_free (pg->peers); | 521 | GNUNET_free (pg->peers); |
358 | if (NULL != pg->hosts) | 522 | if (NULL != pg->hosts) |
diff --git a/src/testing/testing_testbed.c b/src/testing/testing_testbed.c index a3b2c93eb..3d973da77 100644 --- a/src/testing/testing_testbed.c +++ b/src/testing/testing_testbed.c | |||
@@ -59,13 +59,11 @@ struct GNUNET_TESTING_Testbed | |||
59 | */ | 59 | */ |
60 | struct GNUNET_TESTING_Testbed * | 60 | struct GNUNET_TESTING_Testbed * |
61 | GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched, | 61 | GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched, |
62 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 62 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
63 | unsigned int count, | 63 | unsigned int count, |
64 | enum GNUNET_TESTING_Topology topology, | 64 | enum GNUNET_TESTING_Topology topology, |
65 | GNUNET_TESTING_NotifyDaemonRunning cb, | 65 | GNUNET_TESTING_NotifyDaemonRunning cb, |
66 | void *cb_cls, | 66 | void *cb_cls, const char *hostname, ...) |
67 | const char *hostname, | ||
68 | ...) | ||
69 | { | 67 | { |
70 | GNUNET_break (0); | 68 | GNUNET_break (0); |
71 | return NULL; | 69 | return NULL; |
@@ -81,8 +79,7 @@ GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
81 | */ | 79 | */ |
82 | void | 80 | void |
83 | GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb, | 81 | GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb, |
84 | GNUNET_TESTING_NotifyCompletion cb, | 82 | GNUNET_TESTING_NotifyCompletion cb, void *cb_cls) |
85 | void *cb_cls) | ||
86 | { | 83 | { |
87 | GNUNET_break (0); | 84 | GNUNET_break (0); |
88 | } | 85 | } |
@@ -110,10 +107,10 @@ GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb, | |||
110 | */ | 107 | */ |
111 | void | 108 | void |
112 | GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb, | 109 | GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb, |
113 | unsigned int voff, | 110 | unsigned int voff, |
114 | unsigned int von, | 111 | unsigned int von, |
115 | GNUNET_TESTING_NotifyCompletion cb, | 112 | GNUNET_TESTING_NotifyCompletion cb, |
116 | void *cb_cls) | 113 | void *cb_cls) |
117 | { | 114 | { |
118 | GNUNET_break (0); | 115 | GNUNET_break (0); |
119 | } | 116 | } |