aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-27 16:52:08 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-27 16:52:08 +0000
commit9335b7094d8a11449c322b2ca3f5a6cb7a257dad (patch)
tree9b0c7369111ab6e0ded80329a65a0c51e37e2b7f /src/testbed/testbed_api.c
parentf27f46409ec33cef42379006d561d33a2ae44682 (diff)
downloadgnunet-9335b7094d8a11449c322b2ca3f5a6cb7a257dad.tar.gz
gnunet-9335b7094d8a11449c322b2ca3f5a6cb7a257dad.zip
-use more of MQ API
Diffstat (limited to 'src/testbed/testbed_api.c')
-rw-r--r--src/testbed/testbed_api.c100
1 files changed, 58 insertions, 42 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index aad5055ef..b74b48b69 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -1288,7 +1288,6 @@ handle_barrier_status (void *cls,
1288 * 1288 *
1289 * @param controller the handle to the controller 1289 * @param controller the handle to the controller
1290 * @param msg the message to queue 1290 * @param msg the message to queue
1291 * @deprecated
1292 */ 1291 */
1293void 1292void
1294GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, 1293GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
@@ -1328,17 +1327,27 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
1328 * operation 1327 * operation
1329 */ 1328 */
1330struct OperationContext * 1329struct OperationContext *
1331GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller 1330GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller,
1332 *controller, uint64_t operation_id, 1331 uint64_t operation_id,
1333 const struct GNUNET_MessageHeader *msg, 1332 const struct GNUNET_MessageHeader *msg,
1334 GNUNET_CLIENT_MessageHandler cc, 1333 GNUNET_CLIENT_MessageHandler cc,
1335 void *cc_cls) 1334 void *cc_cls)
1336{ 1335{
1337 struct OperationContext *opc; 1336 struct OperationContext *opc;
1338 struct ForwardedOperationData *data; 1337 struct ForwardedOperationData *data;
1339 struct GNUNET_MessageHeader *dup_msg; 1338 struct GNUNET_MQ_Envelope *env;
1340 uint16_t msize; 1339 struct GNUNET_MessageHeader *m2;
1340 uint16_t type = ntohs (msg->type);
1341 uint16_t size = ntohs (msg->size);
1341 1342
1343 env = GNUNET_MQ_msg_extra (m2,
1344 size - sizeof (*m2),
1345 type);
1346 memcpy (m2,
1347 msg,
1348 size);
1349 GNUNET_MQ_send (controller->mq,
1350 env);
1342 data = GNUNET_new (struct ForwardedOperationData); 1351 data = GNUNET_new (struct ForwardedOperationData);
1343 data->cc = cc; 1352 data->cc = cc;
1344 data->cc_cls = cc_cls; 1353 data->cc_cls = cc_cls;
@@ -1347,11 +1356,8 @@ GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
1347 opc->type = OP_FORWARDED; 1356 opc->type = OP_FORWARDED;
1348 opc->data = data; 1357 opc->data = data;
1349 opc->id = operation_id; 1358 opc->id = operation_id;
1350 msize = ntohs (msg->size); 1359 GNUNET_TESTBED_insert_opc_ (controller,
1351 dup_msg = GNUNET_malloc (msize); 1360 opc);
1352 (void) memcpy (dup_msg, msg, msize);
1353 GNUNET_TESTBED_queue_message_ (opc->c, dup_msg);
1354 GNUNET_TESTBED_insert_opc_ (controller, opc);
1355 return opc; 1361 return opc;
1356} 1362}
1357 1363
@@ -1365,7 +1371,8 @@ GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
1365void 1371void
1366GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc) 1372GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc)
1367{ 1373{
1368 GNUNET_TESTBED_remove_opc_ (opc->c, opc); 1374 GNUNET_TESTBED_remove_opc_ (opc->c,
1375 opc);
1369 GNUNET_free (opc->data); 1376 GNUNET_free (opc->data);
1370 GNUNET_free (opc); 1377 GNUNET_free (opc);
1371} 1378}
@@ -1561,11 +1568,13 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1561 GNUNET_MQ_handler_end () 1568 GNUNET_MQ_handler_end ()
1562 }; 1569 };
1563 struct GNUNET_TESTBED_InitMessage *msg; 1570 struct GNUNET_TESTBED_InitMessage *msg;
1571 struct GNUNET_MQ_Envelope *env;
1564 const struct GNUNET_CONFIGURATION_Handle *cfg; 1572 const struct GNUNET_CONFIGURATION_Handle *cfg;
1565 const char *controller_hostname; 1573 const char *controller_hostname;
1566 unsigned long long max_parallel_operations; 1574 unsigned long long max_parallel_operations;
1567 unsigned long long max_parallel_service_connections; 1575 unsigned long long max_parallel_service_connections;
1568 unsigned long long max_parallel_topology_config_operations; 1576 unsigned long long max_parallel_topology_config_operations;
1577 size_t slen;
1569 1578
1570 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); 1579 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
1571 if (GNUNET_OK != 1580 if (GNUNET_OK !=
@@ -1626,18 +1635,17 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1626 controller_hostname = GNUNET_TESTBED_host_get_hostname (host); 1635 controller_hostname = GNUNET_TESTBED_host_get_hostname (host);
1627 if (NULL == controller_hostname) 1636 if (NULL == controller_hostname)
1628 controller_hostname = "127.0.0.1"; 1637 controller_hostname = "127.0.0.1";
1629 msg = 1638 slen = strlen (controller_hostname) + 1;
1630 GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) + 1639 env = GNUNET_MQ_msg_extra (msg,
1631 strlen (controller_hostname) + 1); 1640 slen,
1632 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT); 1641 GNUNET_MESSAGE_TYPE_TESTBED_INIT);
1633 msg->header.size =
1634 htons (sizeof (struct GNUNET_TESTBED_InitMessage) +
1635 strlen (controller_hostname) + 1);
1636 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); 1642 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1637 msg->event_mask = GNUNET_htonll (controller->event_mask); 1643 msg->event_mask = GNUNET_htonll (controller->event_mask);
1638 strcpy ((char *) &msg[1], controller_hostname); 1644 memcpy (&msg[1],
1639 GNUNET_TESTBED_queue_message_ (controller, 1645 controller_hostname,
1640 (struct GNUNET_MessageHeader *) msg); 1646 slen);
1647 GNUNET_MQ_send (controller->mq,
1648 env);
1641 return controller; 1649 return controller;
1642} 1650}
1643 1651
@@ -2182,16 +2190,17 @@ static void
2182opstart_shutdown_peers (void *cls) 2190opstart_shutdown_peers (void *cls)
2183{ 2191{
2184 struct OperationContext *opc = cls; 2192 struct OperationContext *opc = cls;
2193 struct GNUNET_MQ_Envelope *env;
2185 struct GNUNET_TESTBED_ShutdownPeersMessage *msg; 2194 struct GNUNET_TESTBED_ShutdownPeersMessage *msg;
2186 2195
2187 opc->state = OPC_STATE_STARTED; 2196 opc->state = OPC_STATE_STARTED;
2188 msg = GNUNET_new (struct GNUNET_TESTBED_ShutdownPeersMessage); 2197 env = GNUNET_MQ_msg (msg,
2189 msg->header.size = 2198 GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS);
2190 htons (sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage));
2191 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS);
2192 msg->operation_id = GNUNET_htonll (opc->id); 2199 msg->operation_id = GNUNET_htonll (opc->id);
2193 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 2200 GNUNET_TESTBED_insert_opc_ (opc->c,
2194 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 2201 opc);
2202 GNUNET_MQ_send (opc->c->mq,
2203 env);
2195} 2204}
2196 2205
2197 2206
@@ -2330,10 +2339,10 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
2330 int echo) 2339 int echo)
2331{ 2340{
2332 struct GNUNET_TESTBED_BarrierInit *msg; 2341 struct GNUNET_TESTBED_BarrierInit *msg;
2342 struct GNUNET_MQ_Envelope *env;
2333 struct GNUNET_TESTBED_Barrier *barrier; 2343 struct GNUNET_TESTBED_Barrier *barrier;
2334 struct GNUNET_HashCode key; 2344 struct GNUNET_HashCode key;
2335 size_t name_len; 2345 size_t name_len;
2336 uint16_t msize;
2337 2346
2338 GNUNET_assert (quorum <= 100); 2347 GNUNET_assert (quorum <= 100);
2339 GNUNET_assert (NULL != cb); 2348 GNUNET_assert (NULL != cb);
@@ -2362,13 +2371,16 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
2362 &barrier->key, 2371 &barrier->key,
2363 barrier, 2372 barrier,
2364 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 2373 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
2365 msize = name_len + sizeof (struct GNUNET_TESTBED_BarrierInit); 2374
2366 msg = GNUNET_malloc (msize); 2375 env = GNUNET_MQ_msg_extra (msg,
2367 msg->header.size = htons (msize); 2376 name_len,
2368 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT); 2377 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT);
2369 msg->quorum = (uint8_t) quorum; 2378 msg->quorum = (uint8_t) quorum;
2370 (void) memcpy (msg->name, barrier->name, name_len); 2379 memcpy (msg->name,
2371 GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header); 2380 barrier->name,
2381 name_len);
2382 GNUNET_MQ_send (barrier->c->mq,
2383 env);
2372 return barrier; 2384 return barrier;
2373} 2385}
2374 2386
@@ -2406,15 +2418,19 @@ GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
2406void 2418void
2407GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier) 2419GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
2408{ 2420{
2421 struct GNUNET_MQ_Envelope *env;
2409 struct GNUNET_TESTBED_BarrierCancel *msg; 2422 struct GNUNET_TESTBED_BarrierCancel *msg;
2410 uint16_t msize; 2423 size_t slen;
2411 2424
2412 msize = sizeof (struct GNUNET_TESTBED_BarrierCancel) + strlen (barrier->name); 2425 slen = strlen (barrier->name);
2413 msg = GNUNET_malloc (msize); 2426 env = GNUNET_MQ_msg_extra (msg,
2414 msg->header.size = htons (msize); 2427 slen,
2415 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); 2428 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
2416 (void) memcpy (msg->name, barrier->name, strlen (barrier->name)); 2429 memcpy (msg->name,
2417 GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header); 2430 barrier->name,
2431 slen);
2432 GNUNET_MQ_send (barrier->c->mq,
2433 env);
2418 GNUNET_TESTBED_barrier_remove_ (barrier); 2434 GNUNET_TESTBED_barrier_remove_ (barrier);
2419} 2435}
2420 2436