diff options
Diffstat (limited to 'src/topology/test_gnunet_daemon_topology.c')
-rw-r--r-- | src/topology/test_gnunet_daemon_topology.c | 237 |
1 files changed, 119 insertions, 118 deletions
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c index 9e2db4f66..f6d0e2c2b 100644 --- a/src/topology/test_gnunet_daemon_topology.c +++ b/src/topology/test_gnunet_daemon_topology.c | |||
@@ -41,7 +41,7 @@ | |||
41 | /** | 41 | /** |
42 | * How long until we give up on connecting the peers? | 42 | * How long until we give up on connecting the peers? |
43 | */ | 43 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * Store manual connections. | 47 | * Store manual connections. |
@@ -71,7 +71,8 @@ static struct GNUNET_SCHEDULER_Task *timeout_tid; | |||
71 | /* | 71 | /* |
72 | * Peer context for every testbed peer. | 72 | * Peer context for every testbed peer. |
73 | */ | 73 | */ |
74 | struct peerctx { | 74 | struct peerctx |
75 | { | ||
75 | int index; | 76 | int index; |
76 | struct GNUNET_STATISTICS_Handle *statistics; | 77 | struct GNUNET_STATISTICS_Handle *statistics; |
77 | int connections; | 78 | int connections; |
@@ -80,32 +81,32 @@ struct peerctx { | |||
80 | 81 | ||
81 | 82 | ||
82 | static void | 83 | static void |
83 | shutdown_task(void *cls) | 84 | shutdown_task (void *cls) |
84 | { | 85 | { |
85 | unsigned int i; | 86 | unsigned int i; |
86 | 87 | ||
87 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 88 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
88 | "Shutting down testcase\n"); | 89 | "Shutting down testcase\n"); |
89 | 90 | ||
90 | for (i = 0; i < NUM_PEERS; i++) | 91 | for (i = 0; i < NUM_PEERS; i++) |
91 | { | 92 | { |
92 | if (NULL != op[i]) | 93 | if (NULL != op[i]) |
93 | GNUNET_TESTBED_operation_done(op[i]); | 94 | GNUNET_TESTBED_operation_done (op[i]); |
94 | } | 95 | } |
95 | 96 | ||
96 | if (NULL != timeout_tid) | 97 | if (NULL != timeout_tid) |
97 | GNUNET_SCHEDULER_cancel(timeout_tid); | 98 | GNUNET_SCHEDULER_cancel (timeout_tid); |
98 | } | 99 | } |
99 | 100 | ||
100 | static void | 101 | static void |
101 | timeout_task(void *cls) | 102 | timeout_task (void *cls) |
102 | { | 103 | { |
103 | timeout_tid = NULL; | 104 | timeout_tid = NULL; |
104 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 105 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
105 | "Testcase timeout\n"); | 106 | "Testcase timeout\n"); |
106 | 107 | ||
107 | result = GNUNET_SYSERR; | 108 | result = GNUNET_SYSERR; |
108 | GNUNET_SCHEDULER_shutdown(); | 109 | GNUNET_SCHEDULER_shutdown (); |
109 | } | 110 | } |
110 | 111 | ||
111 | /* | 112 | /* |
@@ -113,174 +114,174 @@ timeout_task(void *cls) | |||
113 | * peers to a peer changes. | 114 | * peers to a peer changes. |
114 | */ | 115 | */ |
115 | int | 116 | int |
116 | statistics_iterator(void *cls, | 117 | statistics_iterator (void *cls, |
117 | const char *subsystem, | 118 | const char *subsystem, |
118 | const char *name, | 119 | const char *name, |
119 | uint64_t value, | 120 | uint64_t value, |
120 | int is_persistent) | 121 | int is_persistent) |
121 | { | 122 | { |
122 | struct peerctx *p_ctx = (struct peerctx*)cls; | 123 | struct peerctx *p_ctx = (struct peerctx*) cls; |
123 | 124 | ||
124 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 125 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
125 | "Peer %d: %s = %llu\n", | 126 | "Peer %d: %s = %llu\n", |
126 | p_ctx->index, | 127 | p_ctx->index, |
127 | name, | 128 | name, |
128 | (unsigned long long)value); | 129 | (unsigned long long) value); |
129 | 130 | ||
130 | if (p_ctx->connections < value) | 131 | if (p_ctx->connections < value) |
131 | p_ctx->connections = value; | 132 | p_ctx->connections = value; |
132 | 133 | ||
133 | if (THRESHOLD <= value && GNUNET_NO == p_ctx->reported) | 134 | if ((THRESHOLD <= value)&&(GNUNET_NO == p_ctx->reported)) |
135 | { | ||
136 | p_ctx->reported = GNUNET_YES; | ||
137 | checked_peers++; | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
139 | "Peer %d successfully connected to at least %d peers once.\n", | ||
140 | p_ctx->index, | ||
141 | THRESHOLD); | ||
142 | |||
143 | if (checked_peers == NUM_PEERS) | ||
134 | { | 144 | { |
135 | p_ctx->reported = GNUNET_YES; | 145 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
136 | checked_peers++; | 146 | "Test OK: All peers have connected to %d peers once.\n", |
137 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 147 | THRESHOLD); |
138 | "Peer %d successfully connected to at least %d peers once.\n", | 148 | result = GNUNET_YES; |
139 | p_ctx->index, | 149 | GNUNET_SCHEDULER_shutdown (); |
140 | THRESHOLD); | ||
141 | |||
142 | if (checked_peers == NUM_PEERS) | ||
143 | { | ||
144 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
145 | "Test OK: All peers have connected to %d peers once.\n", | ||
146 | THRESHOLD); | ||
147 | result = GNUNET_YES; | ||
148 | GNUNET_SCHEDULER_shutdown(); | ||
149 | } | ||
150 | } | 150 | } |
151 | } | ||
151 | 152 | ||
152 | return GNUNET_YES; | 153 | return GNUNET_YES; |
153 | } | 154 | } |
154 | 155 | ||
155 | static void * | 156 | static void * |
156 | ca_statistics(void *cls, | 157 | ca_statistics (void *cls, |
157 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 158 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
158 | { | 159 | { |
159 | return GNUNET_STATISTICS_create("topology", cfg); | 160 | return GNUNET_STATISTICS_create ("topology", cfg); |
160 | } | 161 | } |
161 | 162 | ||
162 | 163 | ||
163 | void | 164 | void |
164 | da_statistics(void *cls, | 165 | da_statistics (void *cls, |
165 | void *op_result) | 166 | void *op_result) |
166 | { | 167 | { |
167 | struct peerctx *p_ctx = (struct peerctx *)cls; | 168 | struct peerctx *p_ctx = (struct peerctx *) cls; |
168 | 169 | ||
169 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch_cancel | 170 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel |
170 | (p_ctx->statistics, "topology", "# peers connected", | 171 | (p_ctx->statistics, "topology", "# peers connected", |
171 | statistics_iterator, p_ctx)); | 172 | statistics_iterator, p_ctx)); |
172 | 173 | ||
173 | GNUNET_STATISTICS_destroy(p_ctx->statistics, GNUNET_NO); | 174 | GNUNET_STATISTICS_destroy (p_ctx->statistics, GNUNET_NO); |
174 | p_ctx->statistics = NULL; | 175 | p_ctx->statistics = NULL; |
175 | 176 | ||
176 | GNUNET_free(p_ctx); | 177 | GNUNET_free (p_ctx); |
177 | } | 178 | } |
178 | 179 | ||
179 | 180 | ||
180 | static void | 181 | static void |
181 | service_connect_complete(void *cls, | 182 | service_connect_complete (void *cls, |
182 | struct GNUNET_TESTBED_Operation *op, | 183 | struct GNUNET_TESTBED_Operation *op, |
183 | void *ca_result, | 184 | void *ca_result, |
184 | const char *emsg) | 185 | const char *emsg) |
185 | { | 186 | { |
186 | int ret; | 187 | int ret; |
187 | struct peerctx *p_ctx = (struct peerctx*)cls; | 188 | struct peerctx *p_ctx = (struct peerctx*) cls; |
188 | 189 | ||
189 | if (NULL == ca_result) | 190 | if (NULL == ca_result) |
190 | GNUNET_SCHEDULER_shutdown(); | 191 | GNUNET_SCHEDULER_shutdown (); |
191 | 192 | ||
192 | p_ctx->statistics = ca_result; | 193 | p_ctx->statistics = ca_result; |
193 | 194 | ||
194 | ret = GNUNET_STATISTICS_watch(ca_result, | 195 | ret = GNUNET_STATISTICS_watch (ca_result, |
195 | "topology", | 196 | "topology", |
196 | "# peers connected", | 197 | "# peers connected", |
197 | statistics_iterator, | 198 | statistics_iterator, |
198 | p_ctx); | 199 | p_ctx); |
199 | 200 | ||
200 | if (GNUNET_NO == ret) | 201 | if (GNUNET_NO == ret) |
201 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
202 | "call to GNUNET_STATISTICS_watch() failed\n"); | 203 | "call to GNUNET_STATISTICS_watch() failed\n"); |
203 | } | 204 | } |
204 | 205 | ||
205 | static void | 206 | static void |
206 | notify_connect_complete(void *cls, | 207 | notify_connect_complete (void *cls, |
207 | struct GNUNET_TESTBED_Operation *op, | 208 | struct GNUNET_TESTBED_Operation *op, |
208 | const char *emsg) | 209 | const char *emsg) |
209 | { | 210 | { |
210 | GNUNET_TESTBED_operation_done(op); | 211 | GNUNET_TESTBED_operation_done (op); |
211 | if (NULL != emsg) | 212 | if (NULL != emsg) |
212 | { | 213 | { |
213 | fprintf(stderr, "Failed to connect two peers: %s\n", emsg); | 214 | fprintf (stderr, "Failed to connect two peers: %s\n", emsg); |
214 | result = GNUNET_SYSERR; | 215 | result = GNUNET_SYSERR; |
215 | GNUNET_SCHEDULER_shutdown(); | 216 | GNUNET_SCHEDULER_shutdown (); |
216 | return; | 217 | return; |
217 | } | 218 | } |
218 | connect_left--; | 219 | connect_left--; |
219 | } | 220 | } |
220 | 221 | ||
221 | static void | 222 | static void |
222 | do_connect(void *cls, | 223 | do_connect (void *cls, |
223 | struct GNUNET_TESTBED_RunHandle *h, | 224 | struct GNUNET_TESTBED_RunHandle *h, |
224 | unsigned int num_peers, | 225 | unsigned int num_peers, |
225 | struct GNUNET_TESTBED_Peer **peers, | 226 | struct GNUNET_TESTBED_Peer **peers, |
226 | unsigned int links_succeeded, | 227 | unsigned int links_succeeded, |
227 | unsigned int links_failed) | 228 | unsigned int links_failed) |
228 | { | 229 | { |
229 | unsigned int i; | 230 | unsigned int i; |
230 | struct peerctx *p_ctx; | 231 | struct peerctx *p_ctx; |
231 | 232 | ||
232 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
233 | "Threshold is set to %d.\n", | 234 | "Threshold is set to %d.\n", |
234 | THRESHOLD); | 235 | THRESHOLD); |
235 | 236 | ||
236 | GNUNET_assert(NUM_PEERS == num_peers); | 237 | GNUNET_assert (NUM_PEERS == num_peers); |
237 | 238 | ||
238 | for (i = 0; i < NUM_PEERS; i++) | 239 | for (i = 0; i < NUM_PEERS; i++) |
240 | { | ||
241 | p_ctx = GNUNET_new (struct peerctx); | ||
242 | p_ctx->index = i; | ||
243 | p_ctx->connections = 0; | ||
244 | p_ctx->reported = GNUNET_NO; | ||
245 | |||
246 | if (i < NUM_PEERS - 1) | ||
239 | { | 247 | { |
240 | p_ctx = GNUNET_new(struct peerctx); | 248 | connect_left++; |
241 | p_ctx->index = i; | 249 | GNUNET_TESTBED_overlay_connect (NULL, |
242 | p_ctx->connections = 0; | 250 | ¬ify_connect_complete, NULL, |
243 | p_ctx->reported = GNUNET_NO; | 251 | peers[i], peers[i + 1]); |
244 | |||
245 | if (i < NUM_PEERS - 1) | ||
246 | { | ||
247 | connect_left++; | ||
248 | GNUNET_TESTBED_overlay_connect(NULL, | ||
249 | ¬ify_connect_complete, NULL, | ||
250 | peers[i], peers[i + 1]); | ||
251 | } | ||
252 | |||
253 | op[i] = | ||
254 | GNUNET_TESTBED_service_connect(cls, | ||
255 | peers[i], | ||
256 | "statistics", | ||
257 | service_connect_complete, | ||
258 | p_ctx, /* cls of completion cb */ | ||
259 | ca_statistics, /* connect adapter */ | ||
260 | da_statistics, /* disconnect adapter */ | ||
261 | p_ctx); | ||
262 | } | 252 | } |
263 | 253 | ||
264 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 254 | op[i] = |
255 | GNUNET_TESTBED_service_connect (cls, | ||
256 | peers[i], | ||
257 | "statistics", | ||
258 | service_connect_complete, | ||
259 | p_ctx, /* cls of completion cb */ | ||
260 | ca_statistics, /* connect adapter */ | ||
261 | da_statistics, /* disconnect adapter */ | ||
262 | p_ctx); | ||
263 | } | ||
264 | |||
265 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
265 | timeout_tid = | 266 | timeout_tid = |
266 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 267 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
267 | &timeout_task, | 268 | &timeout_task, |
268 | NULL); | 269 | NULL); |
269 | } | 270 | } |
270 | 271 | ||
271 | 272 | ||
272 | int | 273 | int |
273 | main(int argc, char *argv[]) | 274 | main (int argc, char *argv[]) |
274 | { | 275 | { |
275 | result = GNUNET_SYSERR; | 276 | result = GNUNET_SYSERR; |
276 | checked_peers = 0; | 277 | checked_peers = 0; |
277 | 278 | ||
278 | (void)GNUNET_TESTBED_test_run("test-gnunet-daemon-topology", | 279 | (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology", |
279 | "test_gnunet_daemon_topology_data.conf", | 280 | "test_gnunet_daemon_topology_data.conf", |
280 | NUM_PEERS, | 281 | NUM_PEERS, |
281 | 0, NULL, NULL, | 282 | 0, NULL, NULL, |
282 | &do_connect, NULL); | 283 | &do_connect, NULL); |
283 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-topology"); | 284 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology"); |
284 | 285 | ||
285 | return (GNUNET_OK != result) ? 1 : 0; | 286 | return (GNUNET_OK != result) ? 1 : 0; |
286 | } | 287 | } |