aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c153
1 files changed, 76 insertions, 77 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 65446eb77..335457dcb 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -88,6 +88,7 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
88{ 88{
89 struct GNUNET_TESTING_Daemon *daemon = cls; 89 struct GNUNET_TESTING_Daemon *daemon = cls;
90 int msize; 90 int msize;
91
91#if EMPTY_HACK 92#if EMPTY_HACK
92 int empty; 93 int empty;
93 94
@@ -1870,7 +1871,8 @@ notify_connect_result (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1870 else if (ctx->connect_attempts > 0) 1871 else if (ctx->connect_attempts > 0)
1871 { 1872 {
1872 ctx->d1core_ready = GNUNET_NO; 1873 ctx->d1core_ready = GNUNET_NO;
1873 ctx->timeout_task = GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); 1874 ctx->timeout_task =
1875 GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
1874 return; 1876 return;
1875 } 1877 }
1876 else 1878 else
@@ -1907,12 +1909,12 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
1907 if (0 != memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) 1909 if (0 != memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
1908 return; 1910 return;
1909 ctx->connected = GNUNET_YES; 1911 ctx->connected = GNUNET_YES;
1910 ctx->distance = 0; /* FIXME: distance */ 1912 ctx->distance = 0; /* FIXME: distance */
1911 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) 1913 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
1912 { 1914 {
1913 GNUNET_SCHEDULER_cancel (ctx->hello_send_task); 1915 GNUNET_SCHEDULER_cancel (ctx->hello_send_task);
1914 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK; 1916 ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
1915 } 1917 }
1916 GNUNET_SCHEDULER_cancel (ctx->timeout_task); 1918 GNUNET_SCHEDULER_cancel (ctx->timeout_task);
1917 ctx->timeout_task = GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx); 1919 ctx->timeout_task = GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
1918} 1920}
@@ -2130,74 +2132,72 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer,
2130 return; 2132 return;
2131 } 2133 }
2132 if (peer != NULL) 2134 if (peer != NULL)
2133 return; /* ignore other peers */ 2135 return; /* ignore other peers */
2134 /* peer == NULL: End of iteration over peers */ 2136 /* peer == NULL: End of iteration over peers */
2135
2136 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->timeout_task);
2137 if (ctx->connected == GNUNET_YES)
2138 {
2139 ctx->timeout_task =
2140 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2141 return;
2142 }
2143 2137
2144 /* Peer not already connected, need to schedule connect request! */ 2138 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->timeout_task);
2145 if (ctx->d1core == NULL) 2139 if (ctx->connected == GNUNET_YES)
2146 { 2140 {
2141 ctx->timeout_task = GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2142 return;
2143 }
2144
2145 /* Peer not already connected, need to schedule connect request! */
2146 if (ctx->d1core == NULL)
2147 {
2147#if DEBUG_TESTING 2148#if DEBUG_TESTING
2148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2149 "Peers are NOT connected, connecting to core!\n"); 2150 "Peers are NOT connected, connecting to core!\n");
2150#endif 2151#endif
2151 ctx->d1core = 2152 ctx->d1core =
2152 GNUNET_CORE_connect (ctx->d1->cfg, 1, ctx, &core_init_notify, 2153 GNUNET_CORE_connect (ctx->d1->cfg, 1, ctx, &core_init_notify,
2153 &connect_notify, NULL, NULL, NULL, GNUNET_NO, 2154 &connect_notify, NULL, NULL, NULL, GNUNET_NO, NULL,
2154 NULL, GNUNET_NO, no_handlers); 2155 GNUNET_NO, no_handlers);
2155 } 2156 }
2157
2158 if (ctx->d1core == NULL)
2159 {
2160 ctx->timeout_task = GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2161 return;
2162 }
2156 2163
2157 if (ctx->d1core == NULL) 2164 if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */
2165 {
2166 ctx->d2->th =
2167 GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL,
2168 NULL);
2169 if (ctx->d2->th == NULL)
2158 { 2170 {
2171 GNUNET_CORE_disconnect (ctx->d1core);
2172 ctx->d1core = NULL;
2159 ctx->timeout_task = 2173 ctx->timeout_task =
2160 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx); 2174 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2161 return; 2175 return;
2162 } 2176 }
2177 ctx->d2->ghh =
2178 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2179 }
2163 2180
2164 if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ 2181 if (ctx->send_hello == GNUNET_YES)
2165 { 2182 {
2166 ctx->d2->th = 2183 ctx->d1th =
2167 GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, 2184 GNUNET_TRANSPORT_connect (ctx->d1->cfg, &ctx->d1->id, ctx->d1, NULL,
2168 NULL, NULL); 2185 NULL, NULL);
2169 if (ctx->d2->th == NULL) 2186 if (ctx->d1th == NULL)
2170 {
2171 GNUNET_CORE_disconnect (ctx->d1core);
2172 ctx->d1core = NULL;
2173 ctx->timeout_task =
2174 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2175 return;
2176 }
2177 ctx->d2->ghh =
2178 GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2);
2179 }
2180
2181 if (ctx->send_hello == GNUNET_YES)
2182 { 2187 {
2183 ctx->d1th = 2188 GNUNET_CORE_disconnect (ctx->d1core);
2184 GNUNET_TRANSPORT_connect (ctx->d1->cfg, &ctx->d1->id, ctx->d1, NULL, 2189 ctx->d1core = NULL;
2185 NULL, NULL); 2190 ctx->timeout_task =
2186 if (ctx->d1th == NULL)
2187 {
2188 GNUNET_CORE_disconnect (ctx->d1core);
2189 ctx->d1core = NULL;
2190 ctx->timeout_task =
2191 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx); 2191 GNUNET_SCHEDULER_add_now (&notify_connect_result, ctx);
2192 return; 2192 return;
2193 }
2194 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->hello_send_task);
2195 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
2196 } 2193 }
2194 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == ctx->hello_send_task);
2195 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
2196 }
2197 2197
2198 ctx->timeout_task = 2198 ctx->timeout_task =
2199 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, 2199 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
2200 &notify_connect_result, ctx); 2200 &notify_connect_result, ctx);
2201 2201
2202} 2202}
2203 2203
@@ -2271,29 +2271,28 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
2271 * @param cc connect context 2271 * @param cc connect context
2272 */ 2272 */
2273void 2273void
2274GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext 2274GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext *cc)
2275 *cc)
2276{ 2275{
2277 if (GNUNET_SCHEDULER_NO_TASK != cc->timeout_task) 2276 if (GNUNET_SCHEDULER_NO_TASK != cc->timeout_task)
2278 { 2277 {
2279 GNUNET_SCHEDULER_cancel (cc->timeout_task); 2278 GNUNET_SCHEDULER_cancel (cc->timeout_task);
2280 cc->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2279 cc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2281 } 2280 }
2282 if (GNUNET_SCHEDULER_NO_TASK != cc->hello_send_task) 2281 if (GNUNET_SCHEDULER_NO_TASK != cc->hello_send_task)
2283 { 2282 {
2284 GNUNET_SCHEDULER_cancel (cc->hello_send_task); 2283 GNUNET_SCHEDULER_cancel (cc->hello_send_task);
2285 cc->hello_send_task = GNUNET_SCHEDULER_NO_TASK; 2284 cc->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
2286 } 2285 }
2287 if (NULL != cc->d1core) 2286 if (NULL != cc->d1core)
2288 { 2287 {
2289 GNUNET_CORE_disconnect (cc->d1core); 2288 GNUNET_CORE_disconnect (cc->d1core);
2290 cc->d1core = NULL; 2289 cc->d1core = NULL;
2291 } 2290 }
2292 if (NULL != cc->d1th) 2291 if (NULL != cc->d1th)
2293 { 2292 {
2294 GNUNET_TRANSPORT_disconnect (cc->d1th); 2293 GNUNET_TRANSPORT_disconnect (cc->d1th);
2295 cc->d1th = NULL; 2294 cc->d1th = NULL;
2296 } 2295 }
2297 GNUNET_free (cc); 2296 GNUNET_free (cc);
2298} 2297}
2299 2298