aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-14 11:59:46 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-14 11:59:46 +0000
commit1fe79fd553e21a20206301c18568d30158c9dd46 (patch)
tree3db4e42adb872d1e8aa792643c341a14b2959736 /src/testing
parentf709218364f7d40e5a13938886514e866602715d (diff)
downloadgnunet-1fe79fd553e21a20206301c18568d30158c9dd46.tar.gz
gnunet-1fe79fd553e21a20206301c18568d30158c9dd46.zip
indentation
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_testing_connect.c4
-rw-r--r--src/testing/test_testing_reconnect.c4
-rw-r--r--src/testing/testing.c153
-rw-r--r--src/testing/testing_group.c84
4 files changed, 121 insertions, 124 deletions
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c
index fd14f76be..a31449a71 100644
--- a/src/testing/test_testing_connect.c
+++ b/src/testing/test_testing_connect.c
@@ -116,8 +116,8 @@ my_cb2 (void *cls, const struct GNUNET_PeerIdentity *id,
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n", 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
117 GNUNET_i2s (id)); 117 GNUNET_i2s (id));
118#endif 118#endif
119 cc = GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES, 119 cc = GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS,
120 &my_connect_complete, NULL); 120 GNUNET_YES, &my_connect_complete, NULL);
121} 121}
122 122
123 123
diff --git a/src/testing/test_testing_reconnect.c b/src/testing/test_testing_reconnect.c
index 36675012f..d12e29e78 100644
--- a/src/testing/test_testing_reconnect.c
+++ b/src/testing/test_testing_reconnect.c
@@ -146,8 +146,8 @@ my_cb2 (void *cls, const struct GNUNET_PeerIdentity *id,
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n", 146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Daemon `%s' started.\n",
147 GNUNET_i2s (id)); 147 GNUNET_i2s (id));
148#endif 148#endif
149 cc = GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS, GNUNET_YES, 149 cc = GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, CONNECT_ATTEMPTS,
150 &my_connect_complete, NULL); 150 GNUNET_YES, &my_connect_complete, NULL);
151} 151}
152 152
153 153
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
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index c81373025..4ace9f055 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -893,7 +893,7 @@ struct ConnectContext
893 893
894 /** 894 /**
895 * Context in 'testing.c', to cancel connection attempt. 895 * Context in 'testing.c', to cancel connection attempt.
896 */ 896 */
897 struct GNUNET_TESTING_ConnectContext *cc; 897 struct GNUNET_TESTING_ConnectContext *cc;
898 898
899 /** 899 /**
@@ -3231,10 +3231,9 @@ preschedule_connect (struct GNUNET_TESTING_PeerGroup *pg)
3231 connect_context->first_index = random_peer; 3231 connect_context->first_index = random_peer;
3232 connect_context->second_index = connection_iter->index; 3232 connect_context->second_index = connection_iter->index;
3233 connect_context->ct_ctx = ct_ctx; 3233 connect_context->ct_ctx = ct_ctx;
3234 connect_context->task = GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); 3234 connect_context->task =
3235 GNUNET_CONTAINER_DLL_insert (pg->cc_head, 3235 GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
3236 pg->cc_tail, 3236 GNUNET_CONTAINER_DLL_insert (pg->cc_head, pg->cc_tail, connect_context);
3237 connect_context);
3238 GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head, 3237 GNUNET_CONTAINER_DLL_remove (pg->peers[random_peer].connect_peers_head,
3239 pg->peers[random_peer].connect_peers_tail, 3238 pg->peers[random_peer].connect_peers_tail,
3240 connection_iter); 3239 connection_iter);
@@ -3639,9 +3638,7 @@ internal_connect_notify (void *cls, const struct GNUNET_PeerIdentity *first,
3639 connect_ctx->cc = NULL; 3638 connect_ctx->cc = NULL;
3640 GNUNET_assert (0 < pg->outstanding_connects); 3639 GNUNET_assert (0 < pg->outstanding_connects);
3641 pg->outstanding_connects--; 3640 pg->outstanding_connects--;
3642 GNUNET_CONTAINER_DLL_remove (pg->cc_head, 3641 GNUNET_CONTAINER_DLL_remove (pg->cc_head, pg->cc_tail, connect_ctx);
3643 pg->cc_tail,
3644 connect_ctx);
3645 /* 3642 /*
3646 * Check whether the inverse connection has been scheduled yet, 3643 * Check whether the inverse connection has been scheduled yet,
3647 * if not, we can remove it from the other peers list and avoid 3644 * if not, we can remove it from the other peers list and avoid
@@ -3719,33 +3716,36 @@ schedule_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3719 _ 3716 _
3720 ("Delaying connect, we have too many outstanding connections!\n")); 3717 ("Delaying connect, we have too many outstanding connections!\n"));
3721#endif 3718#endif
3722 connect_context->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 3719 connect_context->task =
3723 (GNUNET_TIME_UNIT_MILLISECONDS, 100), 3720 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
3724 &schedule_connect, connect_context); 3721 (GNUNET_TIME_UNIT_MILLISECONDS, 100),
3722 &schedule_connect, connect_context);
3725 return; 3723 return;
3726 } 3724 }
3727#if VERBOSE_TESTING 3725#if VERBOSE_TESTING
3728 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3726 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3729 _ 3727 _
3730 ("Creating connection, outstanding_connections is %d (max %d)\n"), 3728 ("Creating connection, outstanding_connections is %d (max %d)\n"),
3731 pg->outstanding_connects, pg->max_outstanding_connections); 3729 pg->outstanding_connects, pg->max_outstanding_connections);
3732#endif 3730#endif
3733 pg->outstanding_connects++; 3731 pg->outstanding_connects++;
3734 pg->total_connects_scheduled++; 3732 pg->total_connects_scheduled++;
3735 GNUNET_assert (NULL == connect_context->cc); 3733 GNUNET_assert (NULL == connect_context->cc);
3736 connect_context->cc 3734 connect_context->cc =
3737 = GNUNET_TESTING_daemons_connect (pg-> 3735 GNUNET_TESTING_daemons_connect (pg->
3738 peers[connect_context->first_index].daemon, 3736 peers[connect_context->
3739 pg->peers[connect_context-> 3737 first_index].daemon,
3740 second_index].daemon, 3738 pg->peers[connect_context->
3741 connect_context->ct_ctx->connect_timeout, 3739 second_index].daemon,
3742 connect_context->ct_ctx->connect_attempts, 3740 connect_context->ct_ctx->connect_timeout,
3741 connect_context->ct_ctx->connect_attempts,
3743#if USE_SEND_HELLOS 3742#if USE_SEND_HELLOS
3744 GNUNET_NO, 3743 GNUNET_NO,
3745#else 3744#else
3746 GNUNET_YES, 3745 GNUNET_YES,
3747#endif 3746#endif
3748 &internal_connect_notify, connect_context); 3747 &internal_connect_notify,
3748 connect_context);
3749 3749
3750} 3750}
3751 3751
@@ -3772,10 +3772,10 @@ connect_iterator (void *cls, const GNUNET_HashCode * key, void *value)
3772 connect_context->first = first->daemon; 3772 connect_context->first = first->daemon;
3773 connect_context->second = second; 3773 connect_context->second = second;
3774 connect_context->ct_ctx = ct_ctx; 3774 connect_context->ct_ctx = ct_ctx;
3775 connect_context->task = GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context); 3775 connect_context->task =
3776 GNUNET_CONTAINER_DLL_insert (ct_ctx->pg->cc_head, 3776 GNUNET_SCHEDULER_add_now (&schedule_connect, connect_context);
3777 ct_ctx->pg->cc_tail, 3777 GNUNET_CONTAINER_DLL_insert (ct_ctx->pg->cc_head, ct_ctx->pg->cc_tail,
3778 connect_context); 3778 connect_context);
3779 return GNUNET_YES; 3779 return GNUNET_YES;
3780} 3780}
3781#endif 3781#endif
@@ -7103,16 +7103,14 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg,
7103 7103
7104 GNUNET_assert (pg->total > 0); 7104 GNUNET_assert (pg->total > 0);
7105 while (NULL != (cc = pg->cc_head)) 7105 while (NULL != (cc = pg->cc_head))
7106 { 7106 {
7107 GNUNET_CONTAINER_DLL_remove (pg->cc_head, 7107 GNUNET_CONTAINER_DLL_remove (pg->cc_head, pg->cc_tail, cc);
7108 pg->cc_tail, 7108 if (GNUNET_SCHEDULER_NO_TASK != cc->task)
7109 cc); 7109 GNUNET_SCHEDULER_cancel (cc->task);
7110 if (GNUNET_SCHEDULER_NO_TASK != cc->task) 7110 if (NULL != cc->cc)
7111 GNUNET_SCHEDULER_cancel (cc->task); 7111 GNUNET_TESTING_daemons_connect_cancel (cc->cc);
7112 if (NULL != cc->cc) 7112 GNUNET_free (cc);
7113 GNUNET_TESTING_daemons_connect_cancel (cc->cc); 7113 }
7114 GNUNET_free (cc);
7115 }
7116 7114
7117 shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); 7115 shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
7118 shutdown_ctx->delete_files = 7116 shutdown_ctx->delete_files =