diff options
Diffstat (limited to 'src/dht/dht_test_lib.c')
-rw-r--r-- | src/dht/dht_test_lib.c | 135 |
1 files changed, 67 insertions, 68 deletions
diff --git a/src/dht/dht_test_lib.c b/src/dht/dht_test_lib.c index b4afa3516..8ce3e98ea 100644 --- a/src/dht/dht_test_lib.c +++ b/src/dht/dht_test_lib.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file dht/dht_test_lib.c | 21 | * @file dht/dht_test_lib.c |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -28,8 +28,7 @@ | |||
28 | /** | 28 | /** |
29 | * Test context for a DHT Test. | 29 | * Test context for a DHT Test. |
30 | */ | 30 | */ |
31 | struct GNUNET_DHT_TEST_Context | 31 | struct GNUNET_DHT_TEST_Context { |
32 | { | ||
33 | /** | 32 | /** |
34 | * Array of running peers. | 33 | * Array of running peers. |
35 | */ | 34 | */ |
@@ -59,7 +58,6 @@ struct GNUNET_DHT_TEST_Context | |||
59 | * Number of peers running, size of the arrays above. | 58 | * Number of peers running, size of the arrays above. |
60 | */ | 59 | */ |
61 | unsigned int num_peers; | 60 | unsigned int num_peers; |
62 | |||
63 | }; | 61 | }; |
64 | 62 | ||
65 | 63 | ||
@@ -74,10 +72,10 @@ struct GNUNET_DHT_TEST_Context | |||
74 | * @return service handle to return in 'op_result', NULL on error | 72 | * @return service handle to return in 'op_result', NULL on error |
75 | */ | 73 | */ |
76 | static void * | 74 | static void * |
77 | dht_connect_adapter (void *cls, | 75 | dht_connect_adapter(void *cls, |
78 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 76 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
79 | { | 77 | { |
80 | return GNUNET_DHT_connect (cfg, 16); | 78 | return GNUNET_DHT_connect(cfg, 16); |
81 | } | 79 | } |
82 | 80 | ||
83 | 81 | ||
@@ -89,12 +87,12 @@ dht_connect_adapter (void *cls, | |||
89 | * @param op_result service handle returned from the connect adapter | 87 | * @param op_result service handle returned from the connect adapter |
90 | */ | 88 | */ |
91 | static void | 89 | static void |
92 | dht_disconnect_adapter (void *cls, | 90 | dht_disconnect_adapter(void *cls, |
93 | void *op_result) | 91 | void *op_result) |
94 | { | 92 | { |
95 | struct GNUNET_DHT_Handle *dht = op_result; | 93 | struct GNUNET_DHT_Handle *dht = op_result; |
96 | 94 | ||
97 | GNUNET_DHT_disconnect (dht); | 95 | GNUNET_DHT_disconnect(dht); |
98 | } | 96 | } |
99 | 97 | ||
100 | 98 | ||
@@ -108,33 +106,34 @@ dht_disconnect_adapter (void *cls, | |||
108 | * operation has executed successfully. | 106 | * operation has executed successfully. |
109 | */ | 107 | */ |
110 | static void | 108 | static void |
111 | dht_connect_cb (void *cls, | 109 | dht_connect_cb(void *cls, |
112 | struct GNUNET_TESTBED_Operation *op, | 110 | struct GNUNET_TESTBED_Operation *op, |
113 | void *ca_result, | 111 | void *ca_result, |
114 | const char *emsg) | 112 | const char *emsg) |
115 | { | 113 | { |
116 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 114 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
117 | 115 | ||
118 | if (NULL != emsg) | 116 | if (NULL != emsg) |
119 | { | 117 | { |
120 | fprintf (stderr, | 118 | fprintf(stderr, |
121 | "Failed to connect to DHT service: %s\n", | 119 | "Failed to connect to DHT service: %s\n", |
122 | emsg); | 120 | emsg); |
123 | GNUNET_SCHEDULER_shutdown (); | 121 | GNUNET_SCHEDULER_shutdown(); |
124 | return; | 122 | return; |
125 | } | 123 | } |
126 | for (unsigned int i=0;i<ctx->num_peers;i++) | 124 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
127 | if (op == ctx->ops[i]) | 125 | if (op == ctx->ops[i]) |
128 | ctx->dhts[i] = ca_result; | 126 | ctx->dhts[i] = ca_result; |
129 | for (unsigned int i=0;i<ctx->num_peers;i++) | 127 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
130 | if (NULL == ctx->dhts[i]) | 128 | if (NULL == ctx->dhts[i]) |
131 | return; /* still some DHT connections missing */ | 129 | return; |
130 | /* still some DHT connections missing */ | ||
132 | /* all DHT connections ready! */ | 131 | /* all DHT connections ready! */ |
133 | ctx->app_main (ctx->app_main_cls, | 132 | ctx->app_main(ctx->app_main_cls, |
134 | ctx, | 133 | ctx, |
135 | ctx->num_peers, | 134 | ctx->num_peers, |
136 | ctx->peers, | 135 | ctx->peers, |
137 | ctx->dhts); | 136 | ctx->dhts); |
138 | } | 137 | } |
139 | 138 | ||
140 | 139 | ||
@@ -144,38 +143,38 @@ dht_connect_cb (void *cls, | |||
144 | * @param ctx handle for the testbed | 143 | * @param ctx handle for the testbed |
145 | */ | 144 | */ |
146 | void | 145 | void |
147 | GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx) | 146 | GNUNET_DHT_TEST_cleanup(struct GNUNET_DHT_TEST_Context *ctx) |
148 | { | 147 | { |
149 | for (unsigned int i=0;i<ctx->num_peers;i++) | 148 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
150 | GNUNET_TESTBED_operation_done (ctx->ops[i]); | 149 | GNUNET_TESTBED_operation_done(ctx->ops[i]); |
151 | GNUNET_free (ctx->ops); | 150 | GNUNET_free(ctx->ops); |
152 | GNUNET_free (ctx->dhts); | 151 | GNUNET_free(ctx->dhts); |
153 | GNUNET_free (ctx); | 152 | GNUNET_free(ctx); |
154 | GNUNET_SCHEDULER_shutdown (); | 153 | GNUNET_SCHEDULER_shutdown(); |
155 | } | 154 | } |
156 | 155 | ||
157 | 156 | ||
158 | static void | 157 | static void |
159 | dht_test_run (void *cls, | 158 | dht_test_run(void *cls, |
160 | struct GNUNET_TESTBED_RunHandle *h, | 159 | struct GNUNET_TESTBED_RunHandle *h, |
161 | unsigned int num_peers, | 160 | unsigned int num_peers, |
162 | struct GNUNET_TESTBED_Peer **peers, | 161 | struct GNUNET_TESTBED_Peer **peers, |
163 | unsigned int links_succeeded, | 162 | unsigned int links_succeeded, |
164 | unsigned int links_failed) | 163 | unsigned int links_failed) |
165 | { | 164 | { |
166 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 165 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
167 | 166 | ||
168 | GNUNET_assert (num_peers == ctx->num_peers); | 167 | GNUNET_assert(num_peers == ctx->num_peers); |
169 | ctx->peers = peers; | 168 | ctx->peers = peers; |
170 | for (unsigned int i=0;i<num_peers;i++) | 169 | for (unsigned int i = 0; i < num_peers; i++) |
171 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, | 170 | ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx, |
172 | peers[i], | 171 | peers[i], |
173 | "dht", | 172 | "dht", |
174 | &dht_connect_cb, | 173 | &dht_connect_cb, |
175 | ctx, | 174 | ctx, |
176 | &dht_connect_adapter, | 175 | &dht_connect_adapter, |
177 | &dht_disconnect_adapter, | 176 | &dht_disconnect_adapter, |
178 | ctx); | 177 | ctx); |
179 | } | 178 | } |
180 | 179 | ||
181 | 180 | ||
@@ -190,27 +189,27 @@ dht_test_run (void *cls, | |||
190 | * @param tmain_cls closure for 'tmain' | 189 | * @param tmain_cls closure for 'tmain' |
191 | */ | 190 | */ |
192 | void | 191 | void |
193 | GNUNET_DHT_TEST_run (const char *testname, | 192 | GNUNET_DHT_TEST_run(const char *testname, |
194 | const char *cfgname, | 193 | const char *cfgname, |
195 | unsigned int num_peers, | 194 | unsigned int num_peers, |
196 | GNUNET_DHT_TEST_AppMain tmain, | 195 | GNUNET_DHT_TEST_AppMain tmain, |
197 | void *tmain_cls) | 196 | void *tmain_cls) |
198 | { | 197 | { |
199 | struct GNUNET_DHT_TEST_Context *ctx; | 198 | struct GNUNET_DHT_TEST_Context *ctx; |
200 | 199 | ||
201 | ctx = GNUNET_new (struct GNUNET_DHT_TEST_Context); | 200 | ctx = GNUNET_new(struct GNUNET_DHT_TEST_Context); |
202 | ctx->num_peers = num_peers; | 201 | ctx->num_peers = num_peers; |
203 | ctx->ops = GNUNET_new_array (num_peers, | 202 | ctx->ops = GNUNET_new_array(num_peers, |
204 | struct GNUNET_TESTBED_Operation *); | 203 | struct GNUNET_TESTBED_Operation *); |
205 | ctx->dhts = GNUNET_new_array (num_peers, | 204 | ctx->dhts = GNUNET_new_array(num_peers, |
206 | struct GNUNET_DHT_Handle *); | 205 | struct GNUNET_DHT_Handle *); |
207 | ctx->app_main = tmain; | 206 | ctx->app_main = tmain; |
208 | ctx->app_main_cls = tmain_cls; | 207 | ctx->app_main_cls = tmain_cls; |
209 | (void) GNUNET_TESTBED_test_run (testname, | 208 | (void)GNUNET_TESTBED_test_run(testname, |
210 | cfgname, | 209 | cfgname, |
211 | num_peers, | 210 | num_peers, |
212 | 0LL, NULL, NULL, | 211 | 0LL, NULL, NULL, |
213 | &dht_test_run, ctx); | 212 | &dht_test_run, ctx); |
214 | } | 213 | } |
215 | 214 | ||
216 | /* end of dht_test_lib.c */ | 215 | /* end of dht_test_lib.c */ |