aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c727
1 files changed, 372 insertions, 355 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 5b7820e39..78ed71a42 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -11,7 +11,7 @@
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
@@ -51,9 +51,9 @@ static struct GNUNET_TESTBED_Peer *peer_list_tail;
51 * @param peer the peer to add to the peer list 51 * @param peer the peer to add to the peer list
52 */ 52 */
53void 53void
54GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer) 54GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer)
55{ 55{
56 GNUNET_CONTAINER_DLL_insert_tail (peer_list_head, peer_list_tail, peer); 56 GNUNET_CONTAINER_DLL_insert_tail(peer_list_head, peer_list_tail, peer);
57} 57}
58 58
59 59
@@ -63,9 +63,9 @@ GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer)
63 * @param peer the peer to remove 63 * @param peer the peer to remove
64 */ 64 */
65void 65void
66GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer) 66GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer)
67{ 67{
68 GNUNET_CONTAINER_DLL_remove (peer_list_head, peer_list_tail, peer); 68 GNUNET_CONTAINER_DLL_remove(peer_list_head, peer_list_tail, peer);
69} 69}
70 70
71 71
@@ -73,15 +73,15 @@ GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer)
73 * Frees all peers 73 * Frees all peers
74 */ 74 */
75void 75void
76GNUNET_TESTBED_cleanup_peers_ (void) 76GNUNET_TESTBED_cleanup_peers_(void)
77{ 77{
78 struct GNUNET_TESTBED_Peer *peer; 78 struct GNUNET_TESTBED_Peer *peer;
79 79
80 while (NULL != (peer = peer_list_head)) 80 while (NULL != (peer = peer_list_head))
81 { 81 {
82 GNUNET_TESTBED_peer_deregister_ (peer); 82 GNUNET_TESTBED_peer_deregister_(peer);
83 GNUNET_free (peer); 83 GNUNET_free(peer);
84 } 84 }
85} 85}
86 86
87 87
@@ -94,7 +94,7 @@ GNUNET_TESTBED_cleanup_peers_ (void)
94 * @param cls the closure from GNUNET_TESTBED_operation_create_() 94 * @param cls the closure from GNUNET_TESTBED_operation_create_()
95 */ 95 */
96static void 96static void
97opstart_peer_create (void *cls) 97opstart_peer_create(void *cls)
98{ 98{
99 struct OperationContext *opc = cls; 99 struct OperationContext *opc = cls;
100 struct PeerCreateData *data = opc->data; 100 struct PeerCreateData *data = opc->data;
@@ -105,30 +105,30 @@ opstart_peer_create (void *cls)
105 size_t c_size; 105 size_t c_size;
106 size_t xc_size; 106 size_t xc_size;
107 107
108 GNUNET_assert (OP_PEER_CREATE == opc->type); 108 GNUNET_assert(OP_PEER_CREATE == opc->type);
109 GNUNET_assert (NULL != data); 109 GNUNET_assert(NULL != data);
110 GNUNET_assert (NULL != data->peer); 110 GNUNET_assert(NULL != data->peer);
111 opc->state = OPC_STATE_STARTED; 111 opc->state = OPC_STATE_STARTED;
112 config = GNUNET_CONFIGURATION_serialize (data->cfg, 112 config = GNUNET_CONFIGURATION_serialize(data->cfg,
113 &c_size); 113 &c_size);
114 xc_size = GNUNET_TESTBED_compress_config_ (config, 114 xc_size = GNUNET_TESTBED_compress_config_(config,
115 c_size, 115 c_size,
116 &xconfig); 116 &xconfig);
117 GNUNET_free (config); 117 GNUNET_free(config);
118 env = GNUNET_MQ_msg_extra (msg, 118 env = GNUNET_MQ_msg_extra(msg,
119 xc_size, 119 xc_size,
120 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER); 120 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER);
121 msg->operation_id = GNUNET_htonll (opc->id); 121 msg->operation_id = GNUNET_htonll(opc->id);
122 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); 122 msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(data->peer->host));
123 msg->peer_id = htonl (data->peer->unique_id); 123 msg->peer_id = htonl(data->peer->unique_id);
124 msg->config_size = htons ((uint16_t) c_size); 124 msg->config_size = htons((uint16_t)c_size);
125 GNUNET_memcpy (&msg[1], 125 GNUNET_memcpy(&msg[1],
126 xconfig, 126 xconfig,
127 xc_size); 127 xc_size);
128 GNUNET_MQ_send (opc->c->mq, 128 GNUNET_MQ_send(opc->c->mq,
129 env); 129 env);
130 GNUNET_free (xconfig); 130 GNUNET_free(xconfig);
131 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 131 GNUNET_TESTBED_insert_opc_(opc->c, opc);
132} 132}
133 133
134 134
@@ -138,23 +138,25 @@ opstart_peer_create (void *cls)
138 * @param cls the closure from GNUNET_TESTBED_operation_create_() 138 * @param cls the closure from GNUNET_TESTBED_operation_create_()
139 */ 139 */
140static void 140static void
141oprelease_peer_create (void *cls) 141oprelease_peer_create(void *cls)
142{ 142{
143 struct OperationContext *opc = cls; 143 struct OperationContext *opc = cls;
144 144
145 switch (opc->state) 145 switch (opc->state)
146 { 146 {
147 case OPC_STATE_STARTED: 147 case OPC_STATE_STARTED:
148 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 148 GNUNET_TESTBED_remove_opc_(opc->c, opc);
149
149 /* No break we continue flow */ 150 /* No break we continue flow */
150 case OPC_STATE_INIT: 151 case OPC_STATE_INIT:
151 GNUNET_free (((struct PeerCreateData *) opc->data)->peer); 152 GNUNET_free(((struct PeerCreateData *)opc->data)->peer);
152 GNUNET_free (opc->data); 153 GNUNET_free(opc->data);
153 break; 154 break;
154 case OPC_STATE_FINISHED: 155
155 break; 156 case OPC_STATE_FINISHED:
156 } 157 break;
157 GNUNET_free (opc); 158 }
159 GNUNET_free(opc);
158} 160}
159 161
160 162
@@ -164,23 +166,23 @@ oprelease_peer_create (void *cls)
164 * @param cls the closure from GNUNET_TESTBED_operation_create_() 166 * @param cls the closure from GNUNET_TESTBED_operation_create_()
165 */ 167 */
166static void 168static void
167opstart_peer_destroy (void *cls) 169opstart_peer_destroy(void *cls)
168{ 170{
169 struct OperationContext *opc = cls; 171 struct OperationContext *opc = cls;
170 struct GNUNET_TESTBED_Peer *peer = opc->data; 172 struct GNUNET_TESTBED_Peer *peer = opc->data;
171 struct GNUNET_TESTBED_PeerDestroyMessage *msg; 173 struct GNUNET_TESTBED_PeerDestroyMessage *msg;
172 struct GNUNET_MQ_Envelope *env; 174 struct GNUNET_MQ_Envelope *env;
173 175
174 GNUNET_assert (OP_PEER_DESTROY == opc->type); 176 GNUNET_assert(OP_PEER_DESTROY == opc->type);
175 GNUNET_assert (NULL != peer); 177 GNUNET_assert(NULL != peer);
176 opc->state = OPC_STATE_STARTED; 178 opc->state = OPC_STATE_STARTED;
177 env = GNUNET_MQ_msg (msg, 179 env = GNUNET_MQ_msg(msg,
178 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); 180 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER);
179 msg->peer_id = htonl (peer->unique_id); 181 msg->peer_id = htonl(peer->unique_id);
180 msg->operation_id = GNUNET_htonll (opc->id); 182 msg->operation_id = GNUNET_htonll(opc->id);
181 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 183 GNUNET_TESTBED_insert_opc_(opc->c, opc);
182 GNUNET_MQ_send (peer->controller->mq, 184 GNUNET_MQ_send(peer->controller->mq,
183 env); 185 env);
184} 186}
185 187
186 188
@@ -190,21 +192,23 @@ opstart_peer_destroy (void *cls)
190 * @param cls the closure from GNUNET_TESTBED_operation_create_() 192 * @param cls the closure from GNUNET_TESTBED_operation_create_()
191 */ 193 */
192static void 194static void
193oprelease_peer_destroy (void *cls) 195oprelease_peer_destroy(void *cls)
194{ 196{
195 struct OperationContext *opc = cls; 197 struct OperationContext *opc = cls;
196 198
197 switch (opc->state) 199 switch (opc->state)
198 { 200 {
199 case OPC_STATE_STARTED: 201 case OPC_STATE_STARTED:
200 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 202 GNUNET_TESTBED_remove_opc_(opc->c, opc);
203
201 /* no break; continue */ 204 /* no break; continue */
202 case OPC_STATE_INIT: 205 case OPC_STATE_INIT:
203 break; 206 break;
204 case OPC_STATE_FINISHED: 207
205 break; 208 case OPC_STATE_FINISHED:
206 } 209 break;
207 GNUNET_free (opc); 210 }
211 GNUNET_free(opc);
208} 212}
209 213
210 214
@@ -214,7 +218,7 @@ oprelease_peer_destroy (void *cls)
214 * @param cls the closure from GNUNET_TESTBED_operation_create_() 218 * @param cls the closure from GNUNET_TESTBED_operation_create_()
215 */ 219 */
216static void 220static void
217opstart_peer_start (void *cls) 221opstart_peer_start(void *cls)
218{ 222{
219 struct OperationContext *opc = cls; 223 struct OperationContext *opc = cls;
220 struct GNUNET_TESTBED_PeerStartMessage *msg; 224 struct GNUNET_TESTBED_PeerStartMessage *msg;
@@ -222,18 +226,18 @@ opstart_peer_start (void *cls)
222 struct PeerEventData *data; 226 struct PeerEventData *data;
223 struct GNUNET_TESTBED_Peer *peer; 227 struct GNUNET_TESTBED_Peer *peer;
224 228
225 GNUNET_assert (OP_PEER_START == opc->type); 229 GNUNET_assert(OP_PEER_START == opc->type);
226 GNUNET_assert (NULL != (data = opc->data)); 230 GNUNET_assert(NULL != (data = opc->data));
227 GNUNET_assert (NULL != (peer = data->peer)); 231 GNUNET_assert(NULL != (peer = data->peer));
228 GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); 232 GNUNET_assert((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state));
229 opc->state = OPC_STATE_STARTED; 233 opc->state = OPC_STATE_STARTED;
230 env = GNUNET_MQ_msg (msg, 234 env = GNUNET_MQ_msg(msg,
231 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); 235 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER);
232 msg->peer_id = htonl (peer->unique_id); 236 msg->peer_id = htonl(peer->unique_id);
233 msg->operation_id = GNUNET_htonll (opc->id); 237 msg->operation_id = GNUNET_htonll(opc->id);
234 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 238 GNUNET_TESTBED_insert_opc_(opc->c, opc);
235 GNUNET_MQ_send (peer->controller->mq, 239 GNUNET_MQ_send(peer->controller->mq,
236 env); 240 env);
237} 241}
238 242
239 243
@@ -243,22 +247,24 @@ opstart_peer_start (void *cls)
243 * @param cls the closure from GNUNET_TESTBED_operation_create_() 247 * @param cls the closure from GNUNET_TESTBED_operation_create_()
244 */ 248 */
245static void 249static void
246oprelease_peer_start (void *cls) 250oprelease_peer_start(void *cls)
247{ 251{
248 struct OperationContext *opc = cls; 252 struct OperationContext *opc = cls;
249 253
250 switch (opc->state) 254 switch (opc->state)
251 { 255 {
252 case OPC_STATE_STARTED: 256 case OPC_STATE_STARTED:
253 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 257 GNUNET_TESTBED_remove_opc_(opc->c, opc);
258
254 /* no break; continue */ 259 /* no break; continue */
255 case OPC_STATE_INIT: 260 case OPC_STATE_INIT:
256 GNUNET_free (opc->data); 261 GNUNET_free(opc->data);
257 break; 262 break;
258 case OPC_STATE_FINISHED: 263
259 break; 264 case OPC_STATE_FINISHED:
260 } 265 break;
261 GNUNET_free (opc); 266 }
267 GNUNET_free(opc);
262} 268}
263 269
264 270
@@ -268,7 +274,7 @@ oprelease_peer_start (void *cls)
268 * @param cls the closure from GNUNET_TESTBED_operation_create_() 274 * @param cls the closure from GNUNET_TESTBED_operation_create_()
269 */ 275 */
270static void 276static void
271opstart_peer_stop (void *cls) 277opstart_peer_stop(void *cls)
272{ 278{
273 struct OperationContext *opc = cls; 279 struct OperationContext *opc = cls;
274 struct GNUNET_TESTBED_PeerStopMessage *msg; 280 struct GNUNET_TESTBED_PeerStopMessage *msg;
@@ -276,17 +282,17 @@ opstart_peer_stop (void *cls)
276 struct GNUNET_TESTBED_Peer *peer; 282 struct GNUNET_TESTBED_Peer *peer;
277 struct GNUNET_MQ_Envelope *env; 283 struct GNUNET_MQ_Envelope *env;
278 284
279 GNUNET_assert (NULL != (data = opc->data)); 285 GNUNET_assert(NULL != (data = opc->data));
280 GNUNET_assert (NULL != (peer = data->peer)); 286 GNUNET_assert(NULL != (peer = data->peer));
281 GNUNET_assert (TESTBED_PS_STARTED == peer->state); 287 GNUNET_assert(TESTBED_PS_STARTED == peer->state);
282 opc->state = OPC_STATE_STARTED; 288 opc->state = OPC_STATE_STARTED;
283 env = GNUNET_MQ_msg (msg, 289 env = GNUNET_MQ_msg(msg,
284 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); 290 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER);
285 msg->peer_id = htonl (peer->unique_id); 291 msg->peer_id = htonl(peer->unique_id);
286 msg->operation_id = GNUNET_htonll (opc->id); 292 msg->operation_id = GNUNET_htonll(opc->id);
287 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 293 GNUNET_TESTBED_insert_opc_(opc->c, opc);
288 GNUNET_MQ_send (peer->controller->mq, 294 GNUNET_MQ_send(peer->controller->mq,
289 env); 295 env);
290} 296}
291 297
292 298
@@ -296,22 +302,24 @@ opstart_peer_stop (void *cls)
296 * @param cls the closure from GNUNET_TESTBED_operation_create_() 302 * @param cls the closure from GNUNET_TESTBED_operation_create_()
297 */ 303 */
298static void 304static void
299oprelease_peer_stop (void *cls) 305oprelease_peer_stop(void *cls)
300{ 306{
301 struct OperationContext *opc = cls; 307 struct OperationContext *opc = cls;
302 308
303 switch (opc->state) 309 switch (opc->state)
304 { 310 {
305 case OPC_STATE_STARTED: 311 case OPC_STATE_STARTED:
306 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 312 GNUNET_TESTBED_remove_opc_(opc->c, opc);
313
307 /* no break; continue */ 314 /* no break; continue */
308 case OPC_STATE_INIT: 315 case OPC_STATE_INIT:
309 GNUNET_free (opc->data); 316 GNUNET_free(opc->data);
310 break; 317 break;
311 case OPC_STATE_FINISHED: 318
312 break; 319 case OPC_STATE_FINISHED:
313 } 320 break;
314 GNUNET_free (opc); 321 }
322 GNUNET_free(opc);
315} 323}
316 324
317 325
@@ -324,19 +332,19 @@ oprelease_peer_stop (void *cls)
324 * @return the PeerGetConfigurationMessage 332 * @return the PeerGetConfigurationMessage
325 */ 333 */
326struct GNUNET_TESTBED_PeerGetConfigurationMessage * 334struct GNUNET_TESTBED_PeerGetConfigurationMessage *
327GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, 335GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id,
328 uint64_t operation_id) 336 uint64_t operation_id)
329{ 337{
330 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 338 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
331 339
332 msg = 340 msg =
333 GNUNET_malloc (sizeof 341 GNUNET_malloc(sizeof
334 (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); 342 (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
335 msg->header.size = 343 msg->header.size =
336 htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); 344 htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage));
337 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); 345 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION);
338 msg->peer_id = htonl (peer_id); 346 msg->peer_id = htonl(peer_id);
339 msg->operation_id = GNUNET_htonll (operation_id); 347 msg->operation_id = GNUNET_htonll(operation_id);
340 return msg; 348 return msg;
341} 349}
342 350
@@ -347,19 +355,19 @@ GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
347 * @param cls the closure from GNUNET_TESTBED_operation_create_() 355 * @param cls the closure from GNUNET_TESTBED_operation_create_()
348 */ 356 */
349static void 357static void
350opstart_peer_getinfo (void *cls) 358opstart_peer_getinfo(void *cls)
351{ 359{
352 struct OperationContext *opc = cls; 360 struct OperationContext *opc = cls;
353 struct PeerInfoData *data = opc->data; 361 struct PeerInfoData *data = opc->data;
354 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 362 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
355 363
356 GNUNET_assert (NULL != data); 364 GNUNET_assert(NULL != data);
357 opc->state = OPC_STATE_STARTED; 365 opc->state = OPC_STATE_STARTED;
358 msg = 366 msg =
359 GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, 367 GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id,
360 opc->id); 368 opc->id);
361 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 369 GNUNET_TESTBED_insert_opc_(opc->c, opc);
362 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 370 GNUNET_TESTBED_queue_message_(opc->c, &msg->header);
363} 371}
364 372
365 373
@@ -369,38 +377,42 @@ opstart_peer_getinfo (void *cls)
369 * @param cls the closure from GNUNET_TESTBED_operation_create_() 377 * @param cls the closure from GNUNET_TESTBED_operation_create_()
370 */ 378 */
371static void 379static void
372oprelease_peer_getinfo (void *cls) 380oprelease_peer_getinfo(void *cls)
373{ 381{
374 struct OperationContext *opc = cls; 382 struct OperationContext *opc = cls;
375 struct GNUNET_TESTBED_PeerInformation *data; 383 struct GNUNET_TESTBED_PeerInformation *data;
376 384
377 switch (opc->state) 385 switch (opc->state)
378 {
379 case OPC_STATE_STARTED:
380 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
381 /* no break; continue */
382 case OPC_STATE_INIT:
383 GNUNET_free (opc->data);
384 break;
385 case OPC_STATE_FINISHED:
386 data = opc->data;
387 GNUNET_assert (NULL != data);
388 switch (data->pit)
389 { 386 {
390 case GNUNET_TESTBED_PIT_CONFIGURATION: 387 case OPC_STATE_STARTED:
391 if (NULL != data->result.cfg) 388 GNUNET_TESTBED_remove_opc_(opc->c, opc);
392 GNUNET_CONFIGURATION_destroy (data->result.cfg); 389
390 /* no break; continue */
391 case OPC_STATE_INIT:
392 GNUNET_free(opc->data);
393 break; 393 break;
394 case GNUNET_TESTBED_PIT_IDENTITY: 394
395 GNUNET_free (data->result.id); 395 case OPC_STATE_FINISHED:
396 data = opc->data;
397 GNUNET_assert(NULL != data);
398 switch (data->pit)
399 {
400 case GNUNET_TESTBED_PIT_CONFIGURATION:
401 if (NULL != data->result.cfg)
402 GNUNET_CONFIGURATION_destroy(data->result.cfg);
403 break;
404
405 case GNUNET_TESTBED_PIT_IDENTITY:
406 GNUNET_free(data->result.id);
407 break;
408
409 default:
410 GNUNET_assert(0); /* We should never reach here */
411 }
412 GNUNET_free(data);
396 break; 413 break;
397 default:
398 GNUNET_assert (0); /* We should never reach here */
399 } 414 }
400 GNUNET_free (data); 415 GNUNET_free(opc);
401 break;
402 }
403 GNUNET_free (opc);
404} 416}
405 417
406 418
@@ -410,7 +422,7 @@ oprelease_peer_getinfo (void *cls)
410 * @param cls the closure from GNUNET_TESTBED_operation_create_() 422 * @param cls the closure from GNUNET_TESTBED_operation_create_()
411 */ 423 */
412static void 424static void
413opstart_overlay_connect (void *cls) 425opstart_overlay_connect(void *cls)
414{ 426{
415 struct OperationContext *opc = cls; 427 struct OperationContext *opc = cls;
416 struct GNUNET_MQ_Envelope *env; 428 struct GNUNET_MQ_Envelope *env;
@@ -419,17 +431,17 @@ opstart_overlay_connect (void *cls)
419 431
420 opc->state = OPC_STATE_STARTED; 432 opc->state = OPC_STATE_STARTED;
421 data = opc->data; 433 data = opc->data;
422 GNUNET_assert (NULL != data); 434 GNUNET_assert(NULL != data);
423 env = GNUNET_MQ_msg (msg, 435 env = GNUNET_MQ_msg(msg,
424 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); 436 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT);
425 msg->peer1 = htonl (data->p1->unique_id); 437 msg->peer1 = htonl(data->p1->unique_id);
426 msg->peer2 = htonl (data->p2->unique_id); 438 msg->peer2 = htonl(data->p2->unique_id);
427 msg->operation_id = GNUNET_htonll (opc->id); 439 msg->operation_id = GNUNET_htonll(opc->id);
428 msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); 440 msg->peer2_host_id = htonl(GNUNET_TESTBED_host_get_id_(data->p2->host));
429 GNUNET_TESTBED_insert_opc_ (opc->c, 441 GNUNET_TESTBED_insert_opc_(opc->c,
430 opc); 442 opc);
431 GNUNET_MQ_send (opc->c->mq, 443 GNUNET_MQ_send(opc->c->mq,
432 env); 444 env);
433} 445}
434 446
435 447
@@ -439,24 +451,26 @@ opstart_overlay_connect (void *cls)
439 * @param cls the closure from GNUNET_TESTBED_operation_create_() 451 * @param cls the closure from GNUNET_TESTBED_operation_create_()
440 */ 452 */
441static void 453static void
442oprelease_overlay_connect (void *cls) 454oprelease_overlay_connect(void *cls)
443{ 455{
444 struct OperationContext *opc = cls; 456 struct OperationContext *opc = cls;
445 struct OverlayConnectData *data; 457 struct OverlayConnectData *data;
446 458
447 data = opc->data; 459 data = opc->data;
448 switch (opc->state) 460 switch (opc->state)
449 { 461 {
450 case OPC_STATE_INIT: 462 case OPC_STATE_INIT:
451 break; 463 break;
452 case OPC_STATE_STARTED: 464
453 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 465 case OPC_STATE_STARTED:
454 break; 466 GNUNET_TESTBED_remove_opc_(opc->c, opc);
455 case OPC_STATE_FINISHED: 467 break;
456 break; 468
457 } 469 case OPC_STATE_FINISHED:
458 GNUNET_free (data); 470 break;
459 GNUNET_free (opc); 471 }
472 GNUNET_free(data);
473 GNUNET_free(opc);
460} 474}
461 475
462 476
@@ -466,7 +480,7 @@ oprelease_overlay_connect (void *cls)
466 * @param cls the closure from GNUNET_TESTBED_operation_create_() 480 * @param cls the closure from GNUNET_TESTBED_operation_create_()
467 */ 481 */
468static void 482static void
469opstart_peer_reconfigure (void *cls) 483opstart_peer_reconfigure(void *cls)
470{ 484{
471 struct OperationContext *opc = cls; 485 struct OperationContext *opc = cls;
472 struct PeerReconfigureData *data = opc->data; 486 struct PeerReconfigureData *data = opc->data;
@@ -476,28 +490,28 @@ opstart_peer_reconfigure (void *cls)
476 size_t xc_size; 490 size_t xc_size;
477 491
478 opc->state = OPC_STATE_STARTED; 492 opc->state = OPC_STATE_STARTED;
479 GNUNET_assert (NULL != data); 493 GNUNET_assert(NULL != data);
480 xc_size = GNUNET_TESTBED_compress_config_ (data->config, 494 xc_size = GNUNET_TESTBED_compress_config_(data->config,
481 data->cfg_size, 495 data->cfg_size,
482 &xconfig); 496 &xconfig);
483 GNUNET_free (data->config); 497 GNUNET_free(data->config);
484 data->config = NULL; 498 data->config = NULL;
485 GNUNET_assert (xc_size < UINT16_MAX - sizeof (*msg)); 499 GNUNET_assert(xc_size < UINT16_MAX - sizeof(*msg));
486 env = GNUNET_MQ_msg_extra (msg, 500 env = GNUNET_MQ_msg_extra(msg,
487 xc_size, 501 xc_size,
488 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); 502 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER);
489 msg->peer_id = htonl (data->peer->unique_id); 503 msg->peer_id = htonl(data->peer->unique_id);
490 msg->operation_id = GNUNET_htonll (opc->id); 504 msg->operation_id = GNUNET_htonll(opc->id);
491 msg->config_size = htons (data->cfg_size); 505 msg->config_size = htons(data->cfg_size);
492 GNUNET_memcpy (&msg[1], 506 GNUNET_memcpy(&msg[1],
493 xconfig, 507 xconfig,
494 xc_size); 508 xc_size);
495 GNUNET_free (xconfig); 509 GNUNET_free(xconfig);
496 GNUNET_free (data); 510 GNUNET_free(data);
497 opc->data = NULL; 511 opc->data = NULL;
498 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 512 GNUNET_TESTBED_insert_opc_(opc->c, opc);
499 GNUNET_MQ_send (opc->c->mq, 513 GNUNET_MQ_send(opc->c->mq,
500 env); 514 env);
501} 515}
502 516
503 517
@@ -507,24 +521,26 @@ opstart_peer_reconfigure (void *cls)
507 * @param cls the closure from GNUNET_TESTBED_operation_create_() 521 * @param cls the closure from GNUNET_TESTBED_operation_create_()
508 */ 522 */
509static void 523static void
510oprelease_peer_reconfigure (void *cls) 524oprelease_peer_reconfigure(void *cls)
511{ 525{
512 struct OperationContext *opc = cls; 526 struct OperationContext *opc = cls;
513 struct PeerReconfigureData *data = opc->data; 527 struct PeerReconfigureData *data = opc->data;
514 528
515 switch (opc->state) 529 switch (opc->state)
516 { 530 {
517 case OPC_STATE_INIT: 531 case OPC_STATE_INIT:
518 GNUNET_free (data->config); 532 GNUNET_free(data->config);
519 GNUNET_free (data); 533 GNUNET_free(data);
520 break; 534 break;
521 case OPC_STATE_STARTED: 535
522 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 536 case OPC_STATE_STARTED:
523 break; 537 GNUNET_TESTBED_remove_opc_(opc->c, opc);
524 case OPC_STATE_FINISHED: 538 break;
525 break; 539
526 } 540 case OPC_STATE_FINISHED:
527 GNUNET_free (opc); 541 break;
542 }
543 GNUNET_free(opc);
528} 544}
529 545
530 546
@@ -535,9 +551,9 @@ oprelease_peer_reconfigure (void *cls)
535 * @return handle to the host, NULL on error 551 * @return handle to the host, NULL on error
536 */ 552 */
537struct GNUNET_TESTBED_Peer * 553struct GNUNET_TESTBED_Peer *
538GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) 554GNUNET_TESTBED_peer_lookup_by_id_(uint32_t id)
539{ 555{
540 GNUNET_break (0); 556 GNUNET_break(0);
541 return NULL; 557 return NULL;
542} 558}
543 559
@@ -572,39 +588,38 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
572 * @return the operation handle 588 * @return the operation handle
573 */ 589 */
574struct GNUNET_TESTBED_Operation * 590struct GNUNET_TESTBED_Operation *
575GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, 591GNUNET_TESTBED_peer_create(struct GNUNET_TESTBED_Controller *controller,
576 struct GNUNET_TESTBED_Host *host, 592 struct GNUNET_TESTBED_Host *host,
577 const struct GNUNET_CONFIGURATION_Handle *cfg, 593 const struct GNUNET_CONFIGURATION_Handle *cfg,
578 GNUNET_TESTBED_PeerCreateCallback cb, void *cls) 594 GNUNET_TESTBED_PeerCreateCallback cb, void *cls)
579{ 595{
580
581 struct GNUNET_TESTBED_Peer *peer; 596 struct GNUNET_TESTBED_Peer *peer;
582 struct PeerCreateData *data; 597 struct PeerCreateData *data;
583 struct OperationContext *opc; 598 struct OperationContext *opc;
584 static uint32_t id_gen; 599 static uint32_t id_gen;
585 600
586 peer = GNUNET_new (struct GNUNET_TESTBED_Peer); 601 peer = GNUNET_new(struct GNUNET_TESTBED_Peer);
587 peer->controller = controller; 602 peer->controller = controller;
588 peer->host = host; 603 peer->host = host;
589 peer->unique_id = id_gen++; 604 peer->unique_id = id_gen++;
590 peer->state = TESTBED_PS_INVALID; 605 peer->state = TESTBED_PS_INVALID;
591 data = GNUNET_new (struct PeerCreateData); 606 data = GNUNET_new(struct PeerCreateData);
592 data->host = host; 607 data->host = host;
593 data->cfg = cfg; 608 data->cfg = cfg;
594 data->cb = cb; 609 data->cb = cb;
595 data->cls = cls; 610 data->cls = cls;
596 data->peer = peer; 611 data->peer = peer;
597 opc = GNUNET_new (struct OperationContext); 612 opc = GNUNET_new(struct OperationContext);
598 opc->c = controller; 613 opc->c = controller;
599 opc->data = data; 614 opc->data = data;
600 opc->id = GNUNET_TESTBED_get_next_op_id (controller); 615 opc->id = GNUNET_TESTBED_get_next_op_id(controller);
601 opc->type = OP_PEER_CREATE; 616 opc->type = OP_PEER_CREATE;
602 opc->op = 617 opc->op =
603 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create, 618 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_create,
604 &oprelease_peer_create); 619 &oprelease_peer_create);
605 GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations, 620 GNUNET_TESTBED_operation_queue_insert_(controller->opq_parallel_operations,
606 opc->op); 621 opc->op);
607 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 622 GNUNET_TESTBED_operation_begin_wait_(opc->op);
608 return opc->op; 623 return opc->op;
609} 624}
610 625
@@ -620,28 +635,28 @@ GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
620 * @return handle to the operation 635 * @return handle to the operation
621 */ 636 */
622struct GNUNET_TESTBED_Operation * 637struct GNUNET_TESTBED_Operation *
623GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer, 638GNUNET_TESTBED_peer_start(void *op_cls, struct GNUNET_TESTBED_Peer *peer,
624 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) 639 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls)
625{ 640{
626 struct OperationContext *opc; 641 struct OperationContext *opc;
627 struct PeerEventData *data; 642 struct PeerEventData *data;
628 643
629 data = GNUNET_new (struct PeerEventData); 644 data = GNUNET_new(struct PeerEventData);
630 data->peer = peer; 645 data->peer = peer;
631 data->pcc = pcc; 646 data->pcc = pcc;
632 data->pcc_cls = pcc_cls; 647 data->pcc_cls = pcc_cls;
633 opc = GNUNET_new (struct OperationContext); 648 opc = GNUNET_new(struct OperationContext);
634 opc->c = peer->controller; 649 opc->c = peer->controller;
635 opc->data = data; 650 opc->data = data;
636 opc->op_cls = op_cls; 651 opc->op_cls = op_cls;
637 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); 652 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c);
638 opc->type = OP_PEER_START; 653 opc->type = OP_PEER_START;
639 opc->op = 654 opc->op =
640 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start, 655 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_start,
641 &oprelease_peer_start); 656 &oprelease_peer_start);
642 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, 657 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations,
643 opc->op); 658 opc->op);
644 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 659 GNUNET_TESTBED_operation_begin_wait_(opc->op);
645 return opc->op; 660 return opc->op;
646} 661}
647 662
@@ -659,29 +674,29 @@ GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer,
659 * @return handle to the operation 674 * @return handle to the operation
660 */ 675 */
661struct GNUNET_TESTBED_Operation * 676struct GNUNET_TESTBED_Operation *
662GNUNET_TESTBED_peer_stop (void *op_cls, 677GNUNET_TESTBED_peer_stop(void *op_cls,
663 struct GNUNET_TESTBED_Peer *peer, 678 struct GNUNET_TESTBED_Peer *peer,
664 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) 679 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls)
665{ 680{
666 struct OperationContext *opc; 681 struct OperationContext *opc;
667 struct PeerEventData *data; 682 struct PeerEventData *data;
668 683
669 data = GNUNET_new (struct PeerEventData); 684 data = GNUNET_new(struct PeerEventData);
670 data->peer = peer; 685 data->peer = peer;
671 data->pcc = pcc; 686 data->pcc = pcc;
672 data->pcc_cls = pcc_cls; 687 data->pcc_cls = pcc_cls;
673 opc = GNUNET_new (struct OperationContext); 688 opc = GNUNET_new(struct OperationContext);
674 opc->c = peer->controller; 689 opc->c = peer->controller;
675 opc->data = data; 690 opc->data = data;
676 opc->op_cls = op_cls; 691 opc->op_cls = op_cls;
677 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); 692 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c);
678 opc->type = OP_PEER_STOP; 693 opc->type = OP_PEER_STOP;
679 opc->op = 694 opc->op =
680 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop, 695 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_stop,
681 &oprelease_peer_stop); 696 &oprelease_peer_stop);
682 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, 697 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations,
683 opc->op); 698 opc->op);
684 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 699 GNUNET_TESTBED_operation_begin_wait_(opc->op);
685 return opc->op; 700 return opc->op;
686} 701}
687 702
@@ -701,32 +716,32 @@ GNUNET_TESTBED_peer_stop (void *op_cls,
701 * @return handle to the operation 716 * @return handle to the operation
702 */ 717 */
703struct GNUNET_TESTBED_Operation * 718struct GNUNET_TESTBED_Operation *
704GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, 719GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer,
705 enum GNUNET_TESTBED_PeerInformationType 720 enum GNUNET_TESTBED_PeerInformationType
706 pit, GNUNET_TESTBED_PeerInfoCallback cb, 721 pit, GNUNET_TESTBED_PeerInfoCallback cb,
707 void *cb_cls) 722 void *cb_cls)
708{ 723{
709 struct OperationContext *opc; 724 struct OperationContext *opc;
710 struct PeerInfoData *data; 725 struct PeerInfoData *data;
711 726
712 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); 727 GNUNET_assert(GNUNET_TESTBED_PIT_GENERIC != pit);
713 GNUNET_assert (NULL != cb); 728 GNUNET_assert(NULL != cb);
714 data = GNUNET_new (struct PeerInfoData); 729 data = GNUNET_new(struct PeerInfoData);
715 data->peer = peer; 730 data->peer = peer;
716 data->pit = pit; 731 data->pit = pit;
717 data->cb = cb; 732 data->cb = cb;
718 data->cb_cls = cb_cls; 733 data->cb_cls = cb_cls;
719 opc = GNUNET_new (struct OperationContext); 734 opc = GNUNET_new(struct OperationContext);
720 opc->c = peer->controller; 735 opc->c = peer->controller;
721 opc->data = data; 736 opc->data = data;
722 opc->type = OP_PEER_INFO; 737 opc->type = OP_PEER_INFO;
723 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); 738 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c);
724 opc->op = 739 opc->op =
725 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo, 740 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_getinfo,
726 &oprelease_peer_getinfo); 741 &oprelease_peer_getinfo);
727 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, 742 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations,
728 opc->op); 743 opc->op);
729 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 744 GNUNET_TESTBED_operation_begin_wait_(opc->op);
730 return opc->op; 745 return opc->op;
731} 746}
732 747
@@ -742,41 +757,41 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
742 * @return handle to the operation 757 * @return handle to the operation
743 */ 758 */
744struct GNUNET_TESTBED_Operation * 759struct GNUNET_TESTBED_Operation *
745GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, 760GNUNET_TESTBED_peer_update_configuration(struct GNUNET_TESTBED_Peer *peer,
746 const struct 761 const struct
747 GNUNET_CONFIGURATION_Handle *cfg) 762 GNUNET_CONFIGURATION_Handle *cfg)
748{ 763{
749 struct OperationContext *opc; 764 struct OperationContext *opc;
750 struct PeerReconfigureData *data; 765 struct PeerReconfigureData *data;
751 size_t csize; 766 size_t csize;
752 767
753 data = GNUNET_new (struct PeerReconfigureData); 768 data = GNUNET_new(struct PeerReconfigureData);
754 data->peer = peer; 769 data->peer = peer;
755 data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize); 770 data->config = GNUNET_CONFIGURATION_serialize(cfg, &csize);
756 if (NULL == data->config) 771 if (NULL == data->config)
757 { 772 {
758 GNUNET_free (data); 773 GNUNET_free(data);
759 return NULL; 774 return NULL;
760 } 775 }
761 if (csize > UINT16_MAX) 776 if (csize > UINT16_MAX)
762 { 777 {
763 GNUNET_break (0); 778 GNUNET_break(0);
764 GNUNET_free (data->config); 779 GNUNET_free(data->config);
765 GNUNET_free (data); 780 GNUNET_free(data);
766 return NULL; 781 return NULL;
767 } 782 }
768 data->cfg_size = (uint16_t) csize; 783 data->cfg_size = (uint16_t)csize;
769 opc = GNUNET_new (struct OperationContext); 784 opc = GNUNET_new(struct OperationContext);
770 opc->c = peer->controller; 785 opc->c = peer->controller;
771 opc->data = data; 786 opc->data = data;
772 opc->type = OP_PEER_RECONFIGURE; 787 opc->type = OP_PEER_RECONFIGURE;
773 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); 788 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c);
774 opc->op = 789 opc->op =
775 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure, 790 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_reconfigure,
776 &oprelease_peer_reconfigure); 791 &oprelease_peer_reconfigure);
777 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, 792 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations,
778 opc->op); 793 opc->op);
779 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 794 GNUNET_TESTBED_operation_begin_wait_(opc->op);
780 return opc->op; 795 return opc->op;
781} 796}
782 797
@@ -789,21 +804,21 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
789 * @return handle to the operation 804 * @return handle to the operation
790 */ 805 */
791struct GNUNET_TESTBED_Operation * 806struct GNUNET_TESTBED_Operation *
792GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) 807GNUNET_TESTBED_peer_destroy(struct GNUNET_TESTBED_Peer *peer)
793{ 808{
794 struct OperationContext *opc; 809 struct OperationContext *opc;
795 810
796 opc = GNUNET_new (struct OperationContext); 811 opc = GNUNET_new(struct OperationContext);
797 opc->data = peer; 812 opc->data = peer;
798 opc->c = peer->controller; 813 opc->c = peer->controller;
799 opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller); 814 opc->id = GNUNET_TESTBED_get_next_op_id(peer->controller);
800 opc->type = OP_PEER_DESTROY; 815 opc->type = OP_PEER_DESTROY;
801 opc->op = 816 opc->op =
802 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, 817 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_destroy,
803 &oprelease_peer_destroy); 818 &oprelease_peer_destroy);
804 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, 819 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations,
805 opc->op); 820 opc->op);
806 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 821 GNUNET_TESTBED_operation_begin_wait_(opc->op);
807 return opc->op; 822 return opc->op;
808} 823}
809 824
@@ -821,13 +836,13 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
821 * time is not allowed 836 * time is not allowed
822 */ 837 */
823struct GNUNET_TESTBED_Operation * 838struct GNUNET_TESTBED_Operation *
824GNUNET_TESTBED_underlay_configure_link (void *op_cls, 839GNUNET_TESTBED_underlay_configure_link(void *op_cls,
825 struct GNUNET_TESTBED_Peer *p1, 840 struct GNUNET_TESTBED_Peer *p1,
826 struct GNUNET_TESTBED_Peer *p2, 841 struct GNUNET_TESTBED_Peer *p2,
827 enum GNUNET_TESTBED_ConnectOption co, 842 enum GNUNET_TESTBED_ConnectOption co,
828 ...) 843 ...)
829{ 844{
830 GNUNET_break (0); 845 GNUNET_break(0);
831 return NULL; 846 return NULL;
832} 847}
833 848
@@ -847,31 +862,31 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls,
847 * not running or underlay disallows) 862 * not running or underlay disallows)
848 */ 863 */
849struct GNUNET_TESTBED_Operation * 864struct GNUNET_TESTBED_Operation *
850GNUNET_TESTBED_overlay_connect (void *op_cls, 865GNUNET_TESTBED_overlay_connect(void *op_cls,
851 GNUNET_TESTBED_OperationCompletionCallback cb, 866 GNUNET_TESTBED_OperationCompletionCallback cb,
852 void *cb_cls, struct GNUNET_TESTBED_Peer *p1, 867 void *cb_cls, struct GNUNET_TESTBED_Peer *p1,
853 struct GNUNET_TESTBED_Peer *p2) 868 struct GNUNET_TESTBED_Peer *p2)
854{ 869{
855 struct OperationContext *opc; 870 struct OperationContext *opc;
856 struct OverlayConnectData *data; 871 struct OverlayConnectData *data;
857 872
858 GNUNET_assert ((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state)); 873 GNUNET_assert((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state));
859 data = GNUNET_new (struct OverlayConnectData); 874 data = GNUNET_new(struct OverlayConnectData);
860 data->p1 = p1; 875 data->p1 = p1;
861 data->p2 = p2; 876 data->p2 = p2;
862 data->cb = cb; 877 data->cb = cb;
863 data->cb_cls = cb_cls; 878 data->cb_cls = cb_cls;
864 opc = GNUNET_new (struct OperationContext); 879 opc = GNUNET_new(struct OperationContext);
865 opc->data = data; 880 opc->data = data;
866 opc->c = p1->controller; 881 opc->c = p1->controller;
867 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); 882 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c);
868 opc->type = OP_OVERLAY_CONNECT; 883 opc->type = OP_OVERLAY_CONNECT;
869 opc->op_cls = op_cls; 884 opc->op_cls = op_cls;
870 opc->op = 885 opc->op =
871 GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, 886 GNUNET_TESTBED_operation_create_(opc, &opstart_overlay_connect,
872 &oprelease_overlay_connect); 887 &oprelease_overlay_connect);
873 GNUNET_TESTBED_host_queue_oc_ (p1->host, opc->op); 888 GNUNET_TESTBED_host_queue_oc_(p1->host, opc->op);
874 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 889 GNUNET_TESTBED_operation_begin_wait_(opc->op);
875 return opc->op; 890 return opc->op;
876} 891}
877 892
@@ -882,7 +897,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls,
882 * @param cls the closure from GNUNET_TESTBED_operation_create_() 897 * @param cls the closure from GNUNET_TESTBED_operation_create_()
883 */ 898 */
884static void 899static void
885opstart_manage_service (void *cls) 900opstart_manage_service(void *cls)
886{ 901{
887 struct OperationContext *opc = cls; 902 struct OperationContext *opc = cls;
888 struct ManageServiceData *data = opc->data; 903 struct ManageServiceData *data = opc->data;
@@ -890,23 +905,23 @@ opstart_manage_service (void *cls)
890 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; 905 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg;
891 size_t xlen; 906 size_t xlen;
892 907
893 GNUNET_assert (NULL != data); 908 GNUNET_assert(NULL != data);
894 xlen = data->msize - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage); 909 xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage);
895 env = GNUNET_MQ_msg_extra (msg, 910 env = GNUNET_MQ_msg_extra(msg,
896 xlen, 911 xlen,
897 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); 912 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE);
898 msg->peer_id = htonl (data->peer->unique_id); 913 msg->peer_id = htonl(data->peer->unique_id);
899 msg->operation_id = GNUNET_htonll (opc->id); 914 msg->operation_id = GNUNET_htonll(opc->id);
900 msg->start = (uint8_t) data->start; 915 msg->start = (uint8_t)data->start;
901 GNUNET_memcpy (&msg[1], 916 GNUNET_memcpy(&msg[1],
902 data->service_name, 917 data->service_name,
903 xlen); 918 xlen);
904 GNUNET_free (data->service_name); 919 GNUNET_free(data->service_name);
905 data->service_name = NULL; 920 data->service_name = NULL;
906 opc->state = OPC_STATE_STARTED; 921 opc->state = OPC_STATE_STARTED;
907 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 922 GNUNET_TESTBED_insert_opc_(opc->c, opc);
908 GNUNET_MQ_send (opc->c->mq, 923 GNUNET_MQ_send(opc->c->mq,
909 env); 924 env);
910} 925}
911 926
912 927
@@ -916,26 +931,28 @@ opstart_manage_service (void *cls)
916 * @param cls the closure from GNUNET_TESTBED_operation_create_() 931 * @param cls the closure from GNUNET_TESTBED_operation_create_()
917 */ 932 */
918static void 933static void
919oprelease_manage_service (void *cls) 934oprelease_manage_service(void *cls)
920{ 935{
921 struct OperationContext *opc = cls; 936 struct OperationContext *opc = cls;
922 struct ManageServiceData *data; 937 struct ManageServiceData *data;
923 938
924 data = opc->data; 939 data = opc->data;
925 switch (opc->state) 940 switch (opc->state)
926 { 941 {
927 case OPC_STATE_STARTED: 942 case OPC_STATE_STARTED:
928 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 943 GNUNET_TESTBED_remove_opc_(opc->c, opc);
929 break; 944 break;
930 case OPC_STATE_INIT: 945
931 GNUNET_assert (NULL != data); 946 case OPC_STATE_INIT:
932 GNUNET_free (data->service_name); 947 GNUNET_assert(NULL != data);
933 break; 948 GNUNET_free(data->service_name);
934 case OPC_STATE_FINISHED: 949 break;
935 break; 950
936 } 951 case OPC_STATE_FINISHED:
937 GNUNET_free_non_null (data); 952 break;
938 GNUNET_free (opc); 953 }
954 GNUNET_free_non_null(data);
955 GNUNET_free(opc);
939} 956}
940 957
941 958
@@ -955,41 +972,41 @@ oprelease_manage_service (void *cls)
955 * @return an operation handle; NULL upon error (peer not running) 972 * @return an operation handle; NULL upon error (peer not running)
956 */ 973 */
957struct GNUNET_TESTBED_Operation * 974struct GNUNET_TESTBED_Operation *
958GNUNET_TESTBED_peer_manage_service (void *op_cls, 975GNUNET_TESTBED_peer_manage_service(void *op_cls,
959 struct GNUNET_TESTBED_Peer *peer, 976 struct GNUNET_TESTBED_Peer *peer,
960 const char *service_name, 977 const char *service_name,
961 GNUNET_TESTBED_OperationCompletionCallback cb, 978 GNUNET_TESTBED_OperationCompletionCallback cb,
962 void *cb_cls, 979 void *cb_cls,
963 unsigned int start) 980 unsigned int start)
964{ 981{
965 struct ManageServiceData *data; 982 struct ManageServiceData *data;
966 struct OperationContext *opc; 983 struct OperationContext *opc;
967 size_t msize; 984 size_t msize;
968 985
969 GNUNET_assert (TESTBED_PS_STARTED == peer->state); /* peer is not running? */ 986 GNUNET_assert(TESTBED_PS_STARTED == peer->state); /* peer is not running? */
970 msize = strlen (service_name) + 1; 987 msize = strlen(service_name) + 1;
971 msize += sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage); 988 msize += sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage);
972 if (GNUNET_MAX_MESSAGE_SIZE < msize) 989 if (GNUNET_MAX_MESSAGE_SIZE < msize)
973 return NULL; 990 return NULL;
974 data = GNUNET_new (struct ManageServiceData); 991 data = GNUNET_new(struct ManageServiceData);
975 data->cb = cb; 992 data->cb = cb;
976 data->cb_cls = cb_cls; 993 data->cb_cls = cb_cls;
977 data->peer = peer; 994 data->peer = peer;
978 data->service_name = GNUNET_strdup (service_name); 995 data->service_name = GNUNET_strdup(service_name);
979 data->start = start; 996 data->start = start;
980 data->msize = (uint16_t) msize; 997 data->msize = (uint16_t)msize;
981 opc = GNUNET_new (struct OperationContext); 998 opc = GNUNET_new(struct OperationContext);
982 opc->data = data; 999 opc->data = data;
983 opc->c = peer->controller; 1000 opc->c = peer->controller;
984 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); 1001 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c);
985 opc->type = OP_MANAGE_SERVICE; 1002 opc->type = OP_MANAGE_SERVICE;
986 opc->op_cls = op_cls; 1003 opc->op_cls = op_cls;
987 opc->op = 1004 opc->op =
988 GNUNET_TESTBED_operation_create_ (opc, &opstart_manage_service, 1005 GNUNET_TESTBED_operation_create_(opc, &opstart_manage_service,
989 &oprelease_manage_service); 1006 &oprelease_manage_service);
990 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, 1007 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations,
991 opc->op); 1008 opc->op);
992 GNUNET_TESTBED_operation_begin_wait_ (opc->op); 1009 GNUNET_TESTBED_operation_begin_wait_(opc->op);
993 return opc->op; 1010 return opc->op;
994} 1011}
995 1012