diff options
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r-- | src/testing/testing.c | 311 |
1 files changed, 88 insertions, 223 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index ecd6140a6..78ed39e4a 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -41,8 +41,6 @@ | |||
41 | 41 | ||
42 | #define DEBUG_TESTING_RECONNECT GNUNET_NO | 42 | #define DEBUG_TESTING_RECONNECT GNUNET_NO |
43 | 43 | ||
44 | #define WAIT_FOR_HELLO GNUNET_NO | ||
45 | |||
46 | /** | 44 | /** |
47 | * Hack to deal with initial HELLO's being often devoid of addresses. | 45 | * Hack to deal with initial HELLO's being often devoid of addresses. |
48 | * This hack causes 'process_hello' to ignore HELLOs without addresses. | 46 | * This hack causes 'process_hello' to ignore HELLOs without addresses. |
@@ -90,10 +88,6 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
90 | { | 88 | { |
91 | struct GNUNET_TESTING_Daemon *daemon = cls; | 89 | struct GNUNET_TESTING_Daemon *daemon = cls; |
92 | int msize; | 90 | int msize; |
93 | |||
94 | #if WAIT_FOR_HELLO | ||
95 | GNUNET_TESTING_NotifyDaemonRunning cb; | ||
96 | #endif | ||
97 | #if EMPTY_HACK | 91 | #if EMPTY_HACK |
98 | int empty; | 92 | int empty; |
99 | 93 | ||
@@ -109,14 +103,8 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
109 | return; | 103 | return; |
110 | } | 104 | } |
111 | #endif | 105 | #endif |
112 | if (daemon == NULL) | ||
113 | return; | ||
114 | |||
115 | GNUNET_assert (daemon->phase == SP_GET_HELLO || | 106 | GNUNET_assert (daemon->phase == SP_GET_HELLO || |
116 | daemon->phase == SP_START_DONE); | 107 | daemon->phase == SP_START_DONE); |
117 | #if WAIT_FOR_HELLO | ||
118 | cb = daemon->cb; | ||
119 | #endif | ||
120 | daemon->cb = NULL; | 108 | daemon->cb = NULL; |
121 | if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */ | 109 | if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */ |
122 | GNUNET_SCHEDULER_cancel (daemon->task); | 110 | GNUNET_SCHEDULER_cancel (daemon->task); |
@@ -157,105 +145,11 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
157 | daemon->th = NULL; | 145 | daemon->th = NULL; |
158 | } | 146 | } |
159 | daemon->phase = SP_START_DONE; | 147 | daemon->phase = SP_START_DONE; |
160 | |||
161 | #if WAIT_FOR_HELLO | ||
162 | if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */ | ||
163 | cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL); | ||
164 | #endif | ||
165 | } | 148 | } |
166 | 149 | ||
167 | static void | 150 | static void |
168 | start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 151 | start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
169 | 152 | ||
170 | #if WAIT_FOR_HELLO | ||
171 | /** | ||
172 | * Function called after GNUNET_CORE_connect has succeeded | ||
173 | * (or failed for good). Note that the private key of the | ||
174 | * peer is intentionally not exposed here; if you need it, | ||
175 | * your process should try to read the private key file | ||
176 | * directly (which should work if you are authorized...). | ||
177 | * | ||
178 | * @param cls closure | ||
179 | * @param server handle to the server, NULL if we failed | ||
180 | * @param my_identity ID of this peer, NULL if we failed | ||
181 | * @param publicKey public key of this peer, NULL if we failed | ||
182 | */ | ||
183 | static void | ||
184 | testing_init (void *cls, struct GNUNET_CORE_Handle *server, | ||
185 | const struct GNUNET_PeerIdentity *my_identity, | ||
186 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | ||
187 | { | ||
188 | struct GNUNET_TESTING_Daemon *d = cls; | ||
189 | |||
190 | GNUNET_assert (d->phase == SP_START_CORE); | ||
191 | d->phase = SP_GET_HELLO; | ||
192 | |||
193 | if (server == NULL) | ||
194 | { | ||
195 | d->server = NULL; | ||
196 | if (GNUNET_YES == d->dead) | ||
197 | GNUNET_TESTING_daemon_stop (d, | ||
198 | GNUNET_TIME_absolute_get_remaining | ||
199 | (d->max_timeout), d->dead_cb, d->dead_cb_cls, | ||
200 | GNUNET_YES, GNUNET_NO); | ||
201 | else if (NULL != d->cb) | ||
202 | d->cb (d->cb_cls, NULL, d->cfg, d, | ||
203 | _("Failed to connect to core service\n")); | ||
204 | return; | ||
205 | } | ||
206 | #if DEBUG_TESTING | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully started peer `%4s'.\n", | ||
208 | GNUNET_i2s (my_identity)); | ||
209 | #endif | ||
210 | d->id = *my_identity; /* FIXME: shouldn't we already have this from reading the hostkey file? */ | ||
211 | if (d->shortname == NULL) | ||
212 | d->shortname = strdup (GNUNET_i2s (my_identity)); | ||
213 | d->server = server; | ||
214 | d->running = GNUNET_YES; | ||
215 | |||
216 | if (GNUNET_NO == d->running) | ||
217 | { | ||
218 | #if DEBUG_TESTING | ||
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
220 | "Peer is dead (d->running == GNUNET_NO)\n"); | ||
221 | #endif | ||
222 | return; | ||
223 | } | ||
224 | #if DEBUG_TESTING | ||
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
226 | "Successfully started peer `%4s', connecting to transport service.\n", | ||
227 | GNUNET_i2s (my_identity)); | ||
228 | #endif | ||
229 | |||
230 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | ||
231 | if (d->th == NULL) | ||
232 | { | ||
233 | if (GNUNET_YES == d->dead) | ||
234 | GNUNET_TESTING_daemon_stop (d, | ||
235 | GNUNET_TIME_absolute_get_remaining | ||
236 | (d->max_timeout), d->dead_cb, d->dead_cb_cls, | ||
237 | GNUNET_YES, GNUNET_NO); | ||
238 | else if (NULL != d->cb) | ||
239 | d->cb (d->cb_cls, &d->id, d->cfg, d, | ||
240 | _("Failed to connect to transport service!\n")); | ||
241 | return; | ||
242 | } | ||
243 | #if DEBUG_TESTING | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
245 | "Connected to transport service `%s', getting HELLO\n", | ||
246 | GNUNET_i2s (my_identity)); | ||
247 | #endif | ||
248 | |||
249 | d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | ||
250 | /* wait some more */ | ||
251 | if (d->task != GNUNET_SCHEDULER_NO_TASK) | ||
252 | GNUNET_SCHEDULER_cancel (d->task); | ||
253 | d->task = | ||
254 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, d); | ||
255 | } | ||
256 | #endif | ||
257 | |||
258 | #if !WAIT_FOR_HELLO | ||
259 | /** | 153 | /** |
260 | * Notify of a peer being up and running. Scheduled as a task | 154 | * Notify of a peer being up and running. Scheduled as a task |
261 | * so that variables which may need to be set are set before | 155 | * so that variables which may need to be set are set before |
@@ -275,7 +169,7 @@ notify_daemon_started (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
275 | if (NULL != cb) | 169 | if (NULL != cb) |
276 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); | 170 | cb (d->cb_cls, &d->id, d->cfg, d, NULL); |
277 | } | 171 | } |
278 | #endif | 172 | |
279 | 173 | ||
280 | /** | 174 | /** |
281 | * Finite-state machine for starting GNUnet. | 175 | * Finite-state machine for starting GNUnet. |
@@ -664,29 +558,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
664 | if (d->server != NULL) | 558 | if (d->server != NULL) |
665 | GNUNET_CORE_disconnect (d->server); | 559 | GNUNET_CORE_disconnect (d->server); |
666 | 560 | ||
667 | #if WAIT_FOR_HELLO | ||
668 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | ||
669 | { | ||
670 | cb = d->cb; | ||
671 | d->cb = NULL; | ||
672 | if (NULL != cb) | ||
673 | cb (d->cb_cls, NULL, d->cfg, d, | ||
674 | _("Unable to connect to CORE service for peer!\n")); | ||
675 | GNUNET_CONFIGURATION_destroy (d->cfg); | ||
676 | GNUNET_free (d->cfgfile); | ||
677 | GNUNET_free_non_null (d->hostname); | ||
678 | GNUNET_free_non_null (d->username); | ||
679 | GNUNET_free (d); | ||
680 | return; | ||
681 | } | ||
682 | d->server = | ||
683 | GNUNET_CORE_connect (d->cfg, 1, d, &testing_init, NULL, NULL, NULL, | ||
684 | NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers); | ||
685 | d->task = | ||
686 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
687 | (GNUNET_CONSTANTS_SERVICE_RETRY, 2), | ||
688 | &start_fsm, d); | ||
689 | #else | ||
690 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); | 561 | d->th = GNUNET_TRANSPORT_connect (d->cfg, &d->id, d, NULL, NULL, NULL); |
691 | if (d->th == NULL) | 562 | if (d->th == NULL) |
692 | { | 563 | { |
@@ -707,6 +578,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
707 | #endif | 578 | #endif |
708 | 579 | ||
709 | d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); | 580 | d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); |
581 | /* FIXME: store task ID somewhere! */ | ||
710 | GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); | 582 | GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); |
711 | /*cb = d->cb; | 583 | /*cb = d->cb; |
712 | * d->cb = NULL; | 584 | * d->cb = NULL; |
@@ -714,7 +586,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
714 | * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */ | 586 | * cb (d->cb_cls, &d->id, d->cfg, d, NULL); */ |
715 | d->running = GNUNET_YES; | 587 | d->running = GNUNET_YES; |
716 | d->phase = SP_GET_HELLO; | 588 | d->phase = SP_GET_HELLO; |
717 | #endif | ||
718 | break; | 589 | break; |
719 | case SP_GET_HELLO: | 590 | case SP_GET_HELLO: |
720 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) | 591 | if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value == 0) |
@@ -985,7 +856,7 @@ GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon) | |||
985 | * daemon is down, GNUNET_SYSERR on error. | 856 | * daemon is down, GNUNET_SYSERR on error. |
986 | */ | 857 | */ |
987 | int | 858 | int |
988 | GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon) | 859 | GNUNET_TESTING_test_daemon_running (struct GNUNET_TESTING_Daemon *daemon) |
989 | { | 860 | { |
990 | if (daemon == NULL) | 861 | if (daemon == NULL) |
991 | return GNUNET_SYSERR; | 862 | return GNUNET_SYSERR; |
@@ -1098,7 +969,7 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, | |||
1098 | */ | 969 | */ |
1099 | void | 970 | void |
1100 | GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, | 971 | GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, |
1101 | char *service, | 972 | const char *service, |
1102 | struct GNUNET_TIME_Relative timeout, | 973 | struct GNUNET_TIME_Relative timeout, |
1103 | GNUNET_TESTING_NotifyDaemonRunning cb, | 974 | GNUNET_TESTING_NotifyDaemonRunning cb, |
1104 | void *cb_cls) | 975 | void *cb_cls) |
@@ -1202,7 +1073,7 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, | |||
1202 | daemon->cb_cls = cb_cls; | 1073 | daemon->cb_cls = cb_cls; |
1203 | daemon->phase = SP_TOPOLOGY_SETUP; | 1074 | daemon->phase = SP_TOPOLOGY_SETUP; |
1204 | daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1075 | daemon->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1205 | 1076 | /* FIXME: why add_continuation? */ | |
1206 | GNUNET_SCHEDULER_add_continuation (&start_fsm, daemon, | 1077 | GNUNET_SCHEDULER_add_continuation (&start_fsm, daemon, |
1207 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1078 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
1208 | } | 1079 | } |
@@ -1429,6 +1300,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1429 | "No need to copy configuration file since we are running locally.\n"); | 1300 | "No need to copy configuration file since we are running locally.\n"); |
1430 | #endif | 1301 | #endif |
1431 | ret->phase = SP_COPIED; | 1302 | ret->phase = SP_COPIED; |
1303 | /* FIXME: why add_cont? */ | ||
1432 | GNUNET_SCHEDULER_add_continuation (&start_fsm, ret, | 1304 | GNUNET_SCHEDULER_add_continuation (&start_fsm, ret, |
1433 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1305 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
1434 | } | 1306 | } |
@@ -1551,7 +1423,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, | |||
1551 | */ | 1423 | */ |
1552 | void | 1424 | void |
1553 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, | 1425 | GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, |
1554 | char *service, | 1426 | const char *service, |
1555 | struct GNUNET_TIME_Relative timeout, | 1427 | struct GNUNET_TIME_Relative timeout, |
1556 | GNUNET_TESTING_NotifyCompletion cb, | 1428 | GNUNET_TESTING_NotifyCompletion cb, |
1557 | void *cb_cls) | 1429 | void *cb_cls) |
@@ -1852,7 +1724,7 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, | |||
1852 | * Data kept for each pair of peers that we try | 1724 | * Data kept for each pair of peers that we try |
1853 | * to connect. | 1725 | * to connect. |
1854 | */ | 1726 | */ |
1855 | struct ConnectContext | 1727 | struct GNUNET_TESTING_ConnectContext |
1856 | { | 1728 | { |
1857 | /** | 1729 | /** |
1858 | * Testing handle to the first daemon. | 1730 | * Testing handle to the first daemon. |
@@ -1949,13 +1821,13 @@ reattempt_daemons_connect (void *cls, | |||
1949 | * Notify callback about success or failure of the attempt | 1821 | * Notify callback about success or failure of the attempt |
1950 | * to connect the two peers | 1822 | * to connect the two peers |
1951 | * | 1823 | * |
1952 | * @param cls our "struct ConnectContext" (freed) | 1824 | * @param cls our "struct GNUNET_TESTING_ConnectContext" (freed) |
1953 | * @param tc reason tells us if we succeeded or failed | 1825 | * @param tc reason tells us if we succeeded or failed |
1954 | */ | 1826 | */ |
1955 | static void | 1827 | static void |
1956 | notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1828 | notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1957 | { | 1829 | { |
1958 | struct ConnectContext *ctx = cls; | 1830 | struct GNUNET_TESTING_ConnectContext *ctx = cls; |
1959 | 1831 | ||
1960 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1832 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1961 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | 1833 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1977,11 +1849,6 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1977 | ctx->d1th = NULL; | 1849 | ctx->d1th = NULL; |
1978 | if (ctx->d1core != NULL) | 1850 | if (ctx->d1core != NULL) |
1979 | GNUNET_CORE_disconnect (ctx->d1core); | 1851 | GNUNET_CORE_disconnect (ctx->d1core); |
1980 | #if CONNECT_CORE2 | ||
1981 | if (ctx->d2core != NULL) | ||
1982 | GNUNET_CORE_disconnect (ctx->d2core); | ||
1983 | ctx->d2core = NULL; | ||
1984 | #endif | ||
1985 | ctx->d1core = NULL; | 1852 | ctx->d1core = NULL; |
1986 | GNUNET_free (ctx); | 1853 | GNUNET_free (ctx); |
1987 | return; | 1854 | return; |
@@ -2005,14 +1872,7 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2005 | else if (ctx->connect_attempts > 0) | 1872 | else if (ctx->connect_attempts > 0) |
2006 | { | 1873 | { |
2007 | ctx->d1core_ready = GNUNET_NO; | 1874 | ctx->d1core_ready = GNUNET_NO; |
2008 | #if CONNECT_CORE2 | 1875 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); |
2009 | if (ctx->d2core != NULL) | ||
2010 | { | ||
2011 | GNUNET_CORE_disconnect (ctx->d2core); | ||
2012 | ctx->d2core = NULL; | ||
2013 | } | ||
2014 | #endif | ||
2015 | GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); | ||
2016 | return; | 1876 | return; |
2017 | } | 1877 | } |
2018 | else | 1878 | else |
@@ -2023,7 +1883,6 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2023 | ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect")); | 1883 | ctx->d2->cfg, ctx->d1, ctx->d2, _("Peers failed to connect")); |
2024 | } | 1884 | } |
2025 | } | 1885 | } |
2026 | |||
2027 | GNUNET_free (ctx); | 1886 | GNUNET_free (ctx); |
2028 | } | 1887 | } |
2029 | 1888 | ||
@@ -2031,7 +1890,7 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2031 | /** | 1890 | /** |
2032 | * Success, connection is up. Signal client our success. | 1891 | * Success, connection is up. Signal client our success. |
2033 | * | 1892 | * |
2034 | * @param cls our "struct ConnectContext" | 1893 | * @param cls our "struct GNUNET_TESTING_ConnectContext" |
2035 | * @param peer identity of the peer that has connected | 1894 | * @param peer identity of the peer that has connected |
2036 | * @param atsi performance information | 1895 | * @param atsi performance information |
2037 | * | 1896 | * |
@@ -2040,64 +1899,36 @@ static void | |||
2040 | connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, | 1899 | connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, |
2041 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1900 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
2042 | { | 1901 | { |
2043 | struct ConnectContext *ctx = cls; | 1902 | struct GNUNET_TESTING_ConnectContext *ctx = cls; |
2044 | 1903 | ||
2045 | #if DEBUG_TESTING | 1904 | #if DEBUG_TESTING |
2046 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to peer %s\n", | 1905 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Connected peer %s to peer %s\n", |
2047 | ctx->d1->shortname, GNUNET_i2s (peer)); | 1906 | ctx->d1->shortname, GNUNET_i2s (peer)); |
2048 | #endif | 1907 | #endif |
2049 | 1908 | ||
2050 | if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 1909 | if (0 != memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
2051 | { | 1910 | return; |
2052 | 1911 | ctx->connected = GNUNET_YES; | |
2053 | ctx->connected = GNUNET_YES; | 1912 | ctx->distance = 0; /* FIXME: distance */ |
2054 | ctx->distance = 0; /* FIXME: distance */ | 1913 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) |
2055 | if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) | ||
2056 | { | 1914 | { |
2057 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); | 1915 | GNUNET_SCHEDULER_cancel (ctx->hello_send_task); |
2058 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 1916 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
2059 | } | 1917 | } |
2060 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | 1918 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); |
2061 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); | 1919 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); |
2062 | } | ||
2063 | } | ||
2064 | |||
2065 | #if CONNECT_CORE2 | ||
2066 | /** | ||
2067 | * Success, connection is up. Signal client our success. | ||
2068 | * | ||
2069 | * @param cls our "struct ConnectContext" | ||
2070 | * @param peer identity of the peer that has connected | ||
2071 | * @param atsi performance information | ||
2072 | * | ||
2073 | */ | ||
2074 | static void | ||
2075 | connect_notify_core2 (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
2076 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
2077 | { | ||
2078 | struct ConnectContext *ctx = cls; | ||
2079 | |||
2080 | if (memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)) == 0) | ||
2081 | { | ||
2082 | ctx->connected = GNUNET_YES; | ||
2083 | ctx->distance = 0; /* FIXME: distance */ | ||
2084 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | ||
2085 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); | ||
2086 | } | ||
2087 | |||
2088 | } | 1920 | } |
2089 | #endif | ||
2090 | 1921 | ||
2091 | /** | 1922 | /** |
2092 | * Task called once a core connect request has been transmitted. | 1923 | * Task called once a core connect request has been transmitted. |
2093 | * | 1924 | * |
2094 | * @param cls struct ConnectContext | 1925 | * @param cls struct GNUNET_TESTING_ConnectContext |
2095 | * @param success was the request successful? | 1926 | * @param success was the request successful? |
2096 | */ | 1927 | */ |
2097 | void | 1928 | void |
2098 | core_connect_request_cont (void *cls, int success) | 1929 | core_connect_request_cont (void *cls, int success) |
2099 | { | 1930 | { |
2100 | struct ConnectContext *ctx = cls; | 1931 | struct GNUNET_TESTING_ConnectContext *ctx = cls; |
2101 | 1932 | ||
2102 | ctx->connect_request_handle = NULL; | 1933 | ctx->connect_request_handle = NULL; |
2103 | } | 1934 | } |
@@ -2105,7 +1936,7 @@ core_connect_request_cont (void *cls, int success) | |||
2105 | static void | 1936 | static void |
2106 | send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1937 | send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2107 | { | 1938 | { |
2108 | struct ConnectContext *ctx = cls; | 1939 | struct GNUNET_TESTING_ConnectContext *ctx = cls; |
2109 | struct GNUNET_MessageHeader *hello; | 1940 | struct GNUNET_MessageHeader *hello; |
2110 | 1941 | ||
2111 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | 1942 | ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -2156,7 +1987,7 @@ core_init_notify (void *cls, struct GNUNET_CORE_Handle *server, | |||
2156 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 1987 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
2157 | *publicKey) | 1988 | *publicKey) |
2158 | { | 1989 | { |
2159 | struct ConnectContext *connect_ctx = cls; | 1990 | struct GNUNET_TESTING_ConnectContext *connect_ctx = cls; |
2160 | 1991 | ||
2161 | connect_ctx->d1core_ready = GNUNET_YES; | 1992 | connect_ctx->d1core_ready = GNUNET_YES; |
2162 | 1993 | ||
@@ -2182,13 +2013,11 @@ static void | |||
2182 | reattempt_daemons_connect (void *cls, | 2013 | reattempt_daemons_connect (void *cls, |
2183 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2014 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2184 | { | 2015 | { |
2185 | struct ConnectContext *ctx = cls; | 2016 | struct GNUNET_TESTING_ConnectContext *ctx = cls; |
2186 | 2017 | ||
2018 | ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
2187 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2019 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
2188 | { | ||
2189 | GNUNET_free (ctx); | ||
2190 | return; | 2020 | return; |
2191 | } | ||
2192 | #if DEBUG_TESTING_RECONNECT | 2021 | #if DEBUG_TESTING_RECONNECT |
2193 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2022 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2194 | "re-attempting connect of peer %s to peer %s\n", | 2023 | "re-attempting connect of peer %s to peer %s\n", |
@@ -2264,6 +2093,7 @@ reattempt_daemons_connect (void *cls, | |||
2264 | _("Failed to connect to transport service!\n")); | 2093 | _("Failed to connect to transport service!\n")); |
2265 | return; | 2094 | return; |
2266 | } | 2095 | } |
2096 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->hello_send_task); | ||
2267 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | 2097 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); |
2268 | } | 2098 | } |
2269 | else | 2099 | else |
@@ -2282,7 +2112,7 @@ reattempt_daemons_connect (void *cls, | |||
2282 | * that we don't try to send duplicate connect | 2112 | * that we don't try to send duplicate connect |
2283 | * requests to core. | 2113 | * requests to core. |
2284 | * | 2114 | * |
2285 | * @param cls our "struct ConnectContext" | 2115 | * @param cls our "struct GNUNET_TESTING_ConnectContext" |
2286 | * @param peer identity of the peer that has connected, | 2116 | * @param peer identity of the peer that has connected, |
2287 | * NULL when iteration has finished | 2117 | * NULL when iteration has finished |
2288 | * @param atsi performance information | 2118 | * @param atsi performance information |
@@ -2292,7 +2122,7 @@ static void | |||
2292 | core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, | 2122 | core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, |
2293 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 2123 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
2294 | { | 2124 | { |
2295 | struct ConnectContext *ctx = cls; | 2125 | struct GNUNET_TESTING_ConnectContext *ctx = cls; |
2296 | 2126 | ||
2297 | if ((peer != NULL) && | 2127 | if ((peer != NULL) && |
2298 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) | 2128 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) |
@@ -2301,8 +2131,11 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2301 | ctx->distance = 0; /* FIXME: distance */ | 2131 | ctx->distance = 0; /* FIXME: distance */ |
2302 | return; | 2132 | return; |
2303 | } | 2133 | } |
2304 | else if (peer == NULL) /* End of iteration over peers */ | 2134 | if (peer != NULL) |
2305 | { | 2135 | return; /* ignore other peers */ |
2136 | /* peer == NULL: End of iteration over peers */ | ||
2137 | |||
2138 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->timeout_task); | ||
2306 | if (ctx->connected == GNUNET_YES) | 2139 | if (ctx->connected == GNUNET_YES) |
2307 | { | 2140 | { |
2308 | ctx->timeout_task = | 2141 | ctx->timeout_task = |
@@ -2325,11 +2158,8 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2325 | 2158 | ||
2326 | if (ctx->d1core == NULL) | 2159 | if (ctx->d1core == NULL) |
2327 | { | 2160 | { |
2328 | GNUNET_free (ctx); | 2161 | ctx->timeout_task = |
2329 | if (NULL != ctx->cb) | 2162 | GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); |
2330 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | ||
2331 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2332 | _("Failed to connect to core service of first peer!\n")); | ||
2333 | return; | 2163 | return; |
2334 | } | 2164 | } |
2335 | 2165 | ||
@@ -2341,11 +2171,9 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2341 | if (ctx->d2->th == NULL) | 2171 | if (ctx->d2->th == NULL) |
2342 | { | 2172 | { |
2343 | GNUNET_CORE_disconnect (ctx->d1core); | 2173 | GNUNET_CORE_disconnect (ctx->d1core); |
2344 | GNUNET_free (ctx); | 2174 | ctx->d1core = NULL; |
2345 | if (NULL != ctx->cb) | 2175 | ctx->timeout_task = |
2346 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | 2176 | GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); |
2347 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2348 | _("Failed to connect to transport service!\n")); | ||
2349 | return; | 2177 | return; |
2350 | } | 2178 | } |
2351 | ctx->d2->ghh = | 2179 | ctx->d2->ghh = |
@@ -2360,25 +2188,27 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2360 | if (ctx->d1th == NULL) | 2188 | if (ctx->d1th == NULL) |
2361 | { | 2189 | { |
2362 | GNUNET_CORE_disconnect (ctx->d1core); | 2190 | GNUNET_CORE_disconnect (ctx->d1core); |
2363 | GNUNET_free (ctx); | 2191 | ctx->d1core = NULL; |
2364 | if (NULL != ctx->cb) | 2192 | ctx->timeout_task = |
2365 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, | 2193 | GNUNET_SCHEDULER_add_now (¬ify_connect_result, ctx); |
2366 | ctx->d2->cfg, ctx->d1, ctx->d2, | ||
2367 | _("Failed to connect to transport service!\n")); | ||
2368 | return; | 2194 | return; |
2369 | } | 2195 | } |
2196 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->hello_send_task); | ||
2370 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | 2197 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); |
2371 | } | 2198 | } |
2372 | 2199 | ||
2373 | ctx->timeout_task = | 2200 | ctx->timeout_task = |
2374 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, | 2201 | GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, |
2375 | ¬ify_connect_result, ctx); | 2202 | ¬ify_connect_result, ctx); |
2376 | } | 2203 | |
2377 | } | 2204 | } |
2378 | 2205 | ||
2379 | 2206 | ||
2380 | /** | 2207 | /** |
2381 | * Establish a connection between two GNUnet daemons. | 2208 | * Establish a connection between two GNUnet daemons. The daemons |
2209 | * must both be running and not be stopped until either the | ||
2210 | * 'cb' callback is called OR the connection request has been | ||
2211 | * explicitly cancelled. | ||
2382 | * | 2212 | * |
2383 | * @param d1 handle for the first daemon | 2213 | * @param d1 handle for the first daemon |
2384 | * @param d2 handle for the second daemon | 2214 | * @param d2 handle for the second daemon |
@@ -2390,8 +2220,9 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2390 | * the HELLO has already been exchanged | 2220 | * the HELLO has already been exchanged |
2391 | * @param cb function to call at the end | 2221 | * @param cb function to call at the end |
2392 | * @param cb_cls closure for cb | 2222 | * @param cb_cls closure for cb |
2223 | * @return handle to cancel the request | ||
2393 | */ | 2224 | */ |
2394 | void | 2225 | struct GNUNET_TESTING_ConnectContext * |
2395 | GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | 2226 | GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, |
2396 | struct GNUNET_TESTING_Daemon *d2, | 2227 | struct GNUNET_TESTING_Daemon *d2, |
2397 | struct GNUNET_TIME_Relative timeout, | 2228 | struct GNUNET_TIME_Relative timeout, |
@@ -2400,7 +2231,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2400 | GNUNET_TESTING_NotifyConnection cb, | 2231 | GNUNET_TESTING_NotifyConnection cb, |
2401 | void *cb_cls) | 2232 | void *cb_cls) |
2402 | { | 2233 | { |
2403 | struct ConnectContext *ctx; | 2234 | struct GNUNET_TESTING_ConnectContext *ctx; |
2404 | 2235 | ||
2405 | if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) | 2236 | if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO)) |
2406 | { | 2237 | { |
@@ -2408,10 +2239,10 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2408 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | 2239 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, |
2409 | _("Peers are not fully running yet, can not connect!\n")); | 2240 | _("Peers are not fully running yet, can not connect!\n")); |
2410 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n"); | 2241 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers are not up!\n"); |
2411 | return; | 2242 | return NULL; |
2412 | } | 2243 | } |
2413 | 2244 | ||
2414 | ctx = GNUNET_malloc (sizeof (struct ConnectContext)); | 2245 | ctx = GNUNET_malloc (sizeof (struct GNUNET_TESTING_ConnectContext)); |
2415 | ctx->d1 = d1; | 2246 | ctx->d1 = d1; |
2416 | ctx->d2 = d2; | 2247 | ctx->d2 = d2; |
2417 | ctx->timeout_hello = | 2248 | ctx->timeout_hello = |
@@ -2432,7 +2263,41 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
2432 | GNUNET_assert (GNUNET_OK == | 2263 | GNUNET_assert (GNUNET_OK == |
2433 | GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, | 2264 | GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, |
2434 | &core_initial_iteration, ctx)); | 2265 | &core_initial_iteration, ctx)); |
2435 | /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx)); */ | 2266 | return ctx; |
2436 | } | 2267 | } |
2437 | 2268 | ||
2269 | |||
2270 | /** | ||
2271 | * Cancel an attempt to connect two daemons. | ||
2272 | * | ||
2273 | * @param cc connect context | ||
2274 | */ | ||
2275 | void | ||
2276 | GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext | ||
2277 | *cc) | ||
2278 | { | ||
2279 | if (GNUNET_SCHEDULER_NO_TASK != cc->timeout_task) | ||
2280 | { | ||
2281 | GNUNET_SCHEDULER_cancel (cc->timeout_task); | ||
2282 | cc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
2283 | } | ||
2284 | if (GNUNET_SCHEDULER_NO_TASK != cc->hello_send_task) | ||
2285 | { | ||
2286 | GNUNET_SCHEDULER_cancel (cc->hello_send_task); | ||
2287 | cc->hello_send_task = GNUNET_SCHEDULER_NO_TASK; | ||
2288 | } | ||
2289 | if (NULL != cc->d1core) | ||
2290 | { | ||
2291 | GNUNET_CORE_disconnect (cc->d1core); | ||
2292 | cc->d1core = NULL; | ||
2293 | } | ||
2294 | if (NULL != cc->d1th) | ||
2295 | { | ||
2296 | GNUNET_TRANSPORT_disconnect (cc->d1th); | ||
2297 | cc->d1th = NULL; | ||
2298 | } | ||
2299 | GNUNET_free (cc); | ||
2300 | } | ||
2301 | |||
2302 | |||
2438 | /* end of testing.c */ | 2303 | /* end of testing.c */ |