aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-27 16:15:33 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-27 16:15:33 +0000
commitf27f46409ec33cef42379006d561d33a2ae44682 (patch)
tree0d32d879b31feb0d9aa0d19e44b41a2146cb1973 /src/testbed/testbed_api.c
parent3a4870624812ac4286624d3946981cac6aef4e67 (diff)
downloadgnunet-f27f46409ec33cef42379006d561d33a2ae44682.tar.gz
gnunet-f27f46409ec33cef42379006d561d33a2ae44682.zip
convert testbed_api to MQ (not perfect, but working)
Diffstat (limited to 'src/testbed/testbed_api.c')
-rw-r--r--src/testbed/testbed_api.c507
1 files changed, 258 insertions, 249 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 9b8066412..aad5055ef 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -67,28 +67,6 @@
67 67
68 68
69/** 69/**
70 * The message queue for sending messages to the controller service
71 */
72struct MessageQueue
73{
74 /**
75 * The message to be sent
76 */
77 struct GNUNET_MessageHeader *msg;
78
79 /**
80 * next pointer for DLL
81 */
82 struct MessageQueue *next;
83
84 /**
85 * prev pointer for DLL
86 */
87 struct MessageQueue *prev;
88};
89
90
91/**
92 * Context data for forwarded Operation 70 * Context data for forwarded Operation
93 */ 71 */
94struct ForwardedOperationData 72struct ForwardedOperationData
@@ -272,12 +250,13 @@ struct SearchContext
272 * @param cls the serach context 250 * @param cls the serach context
273 * @param key current key code 251 * @param key current key code
274 * @param value value in the hash map 252 * @param value value in the hash map
275 * @return GNUNET_YES if we should continue to 253 * @return #GNUNET_YES if we should continue to iterate,
276 * iterate, 254 * #GNUNET_NO if not.
277 * GNUNET_NO if not.
278 */ 255 */
279static int 256static int
280opc_search_iterator (void *cls, uint32_t key, void *value) 257opc_search_iterator (void *cls,
258 uint32_t key,
259 void *value)
281{ 260{
282 struct SearchContext *sc = cls; 261 struct SearchContext *sc = cls;
283 struct OperationContext *opc = value; 262 struct OperationContext *opc = value;
@@ -358,6 +337,85 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
358} 337}
359 338
360 339
340
341/**
342 * Check #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message is well-formed.
343 *
344 * @param cls the controller handler
345 * @param msg message received
346 * @return #GNUNET_OK if message is well-formed
347 */
348static int
349check_add_host_confirm (void *cls,
350 const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
351{
352 const char *emsg;
353 uint16_t msg_size;
354
355 msg_size = ntohs (msg->header.size) - sizeof (*msg);
356 if (0 == msg_size)
357 return GNUNET_OK;
358 /* We have an error message */
359 emsg = (const char *) &msg[1];
360 if ('\0' != emsg[msg_size - 1])
361 {
362 GNUNET_break (0);
363 return GNUNET_SYSERR;
364 }
365 return GNUNET_OK;
366}
367
368
369/**
370 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
371 * controller (testbed service)
372 *
373 * @param cls the controller handler
374 * @param msg message received
375 */
376static void
377handle_add_host_confirm (void *cls,
378 const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
379{
380 struct GNUNET_TESTBED_Controller *c = cls;
381 struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh;
382 const char *emsg;
383 uint16_t msg_size;
384
385 if (NULL == rh)
386 return;
387 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
388 {
389 LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
390 GNUNET_TESTBED_host_get_id_ (rh->host),
391 ntohl (msg->host_id));
392 return;
393 }
394 c->rh = NULL;
395 msg_size = ntohs (msg->header.size) - sizeof (*msg);
396 if (0 == msg_size)
397 {
398 LOG_DEBUG ("Host %u successfully registered\n",
399 ntohl (msg->host_id));
400 GNUNET_TESTBED_mark_host_registered_at_ (rh->host,
401 c);
402 rh->cc (rh->cc_cls,
403 NULL);
404 GNUNET_free (rh);
405 return;
406 }
407 /* We have an error message */
408 emsg = (const char *) &msg[1];
409 LOG (GNUNET_ERROR_TYPE_ERROR,
410 _("Adding host %u failed with error: %s\n"),
411 ntohl (msg->host_id),
412 emsg);
413 rh->cc (rh->cc_cls,
414 emsg);
415 GNUNET_free (rh);
416}
417
418
361/** 419/**
362 * Handler for forwarded operations 420 * Handler for forwarded operations
363 * 421 *
@@ -690,6 +748,22 @@ handle_peer_conevent (void *cls,
690 748
691 749
692/** 750/**
751 * Validate #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from
752 * controller (testbed service)
753 *
754 * @param c the controller handler
755 * @param msg message received
756 */
757static int
758check_peer_config (void *cls,
759 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
760{
761 /* anything goes? */
762 return GNUNET_OK;
763}
764
765
766/**
693 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from 767 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from
694 * controller (testbed service) 768 * controller (testbed service)
695 * 769 *
@@ -698,8 +772,7 @@ handle_peer_conevent (void *cls,
698 */ 772 */
699static void 773static void
700handle_peer_config (void *cls, 774handle_peer_config (void *cls,
701 const struct 775 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
702 GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
703{ 776{
704 struct GNUNET_TESTBED_Controller *c = cls; 777 struct GNUNET_TESTBED_Controller *c = cls;
705 struct OperationContext *opc; 778 struct OperationContext *opc;
@@ -718,8 +791,9 @@ handle_peer_config (void *cls,
718 } 791 }
719 if (OP_FORWARDED == opc->type) 792 if (OP_FORWARDED == opc->type)
720 { 793 {
721 handle_forwarded_operation_msg (c, opc, 794 handle_forwarded_operation_msg (c,
722 (const struct GNUNET_MessageHeader *) msg); 795 opc,
796 &msg->header);
723 return; 797 return;
724 } 798 }
725 data = opc->data; 799 data = opc->data;
@@ -761,6 +835,23 @@ handle_peer_config (void *cls,
761 835
762 836
763/** 837/**
838 * Validate #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from
839 * controller (testbed service)
840 *
841 * @param c the controller handler
842 * @param msg message received
843 * @return #GNUNET_OK if message is well-formed
844 */
845static int
846check_op_fail_event (void *cls,
847 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
848{
849 /* we accept anything as a valid error message */
850 return GNUNET_OK;
851}
852
853
854/**
764 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from 855 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from
765 * controller (testbed service) 856 * controller (testbed service)
766 * 857 *
@@ -917,6 +1008,23 @@ GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id)
917} 1008}
918 1009
919 1010
1011
1012/**
1013 * Validate #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_INFORMATION message from
1014 * controller (testbed service)
1015 *
1016 * @param c the controller handler
1017 * @param msg message received
1018 */
1019static int
1020check_slave_config (void *cls,
1021 const struct GNUNET_TESTBED_SlaveConfiguration *msg)
1022{
1023 /* anything goes? */
1024 return GNUNET_OK;
1025}
1026
1027
920/** 1028/**
921 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION message from controller 1029 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION message from controller
922 * (testbed service) 1030 * (testbed service)
@@ -963,6 +1071,23 @@ handle_slave_config (void *cls,
963 1071
964 1072
965/** 1073/**
1074 * Check #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller
1075 * (testbed service)
1076 *
1077 * @param c the controller handler
1078 * @param msg message received
1079 * @return #GNUNET_OK if @a msg is well-formed
1080 */
1081static int
1082check_link_controllers_result (void *cls,
1083 const struct GNUNET_TESTBED_ControllerLinkResponse *msg)
1084{
1085 /* actual check to be implemented */
1086 return GNUNET_OK;
1087}
1088
1089
1090/**
966 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller 1091 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller
967 * (testbed service) 1092 * (testbed service)
968 * 1093 *
@@ -971,8 +1096,7 @@ handle_slave_config (void *cls,
971 */ 1096 */
972static void 1097static void
973handle_link_controllers_result (void *cls, 1098handle_link_controllers_result (void *cls,
974 const struct 1099 const struct GNUNET_TESTBED_ControllerLinkResponse *msg)
975 GNUNET_TESTBED_ControllerLinkResponse *msg)
976{ 1100{
977 struct GNUNET_TESTBED_Controller *c = cls; 1101 struct GNUNET_TESTBED_Controller *c = cls;
978 struct OperationContext *opc; 1102 struct OperationContext *opc;
@@ -1056,8 +1180,8 @@ handle_link_controllers_result (void *cls,
1056 * down signalling an error (message malformed) 1180 * down signalling an error (message malformed)
1057 */ 1181 */
1058static int 1182static int
1059check_barrier_status_ (struct GNUNET_TESTBED_Controller *c, 1183check_barrier_status (void *cls,
1060 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 1184 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1061{ 1185{
1062 uint16_t msize; 1186 uint16_t msize;
1063 uint16_t name_len; 1187 uint16_t name_len;
@@ -1097,14 +1221,15 @@ check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
1097/** 1221/**
1098 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages 1222 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages
1099 * 1223 *
1100 * @param c the controller handle to determine the connection this message 1224 * @param cls the controller handle to determine the connection this message
1101 * belongs to 1225 * belongs to
1102 * @param msg the barrier status message 1226 * @param msg the barrier status message
1103 */ 1227 */
1104static void 1228static void
1105handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, 1229handle_barrier_status (void *cls,
1106 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 1230 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1107{ 1231{
1232 struct GNUNET_TESTBED_Controller *c = cls;
1108 struct GNUNET_TESTBED_Barrier *barrier; 1233 struct GNUNET_TESTBED_Barrier *barrier;
1109 char *emsg; 1234 char *emsg;
1110 const char *name; 1235 const char *name;
@@ -1159,191 +1284,18 @@ handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
1159 1284
1160 1285
1161/** 1286/**
1162 * Handler for messages from controller (testbed service)
1163 *
1164 * @param cls the controller handler
1165 * @param msg message received, NULL on timeout or fatal error
1166 */
1167static void
1168message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1169{
1170 struct GNUNET_TESTBED_Controller *c = cls;
1171 int status;
1172 uint16_t msize;
1173
1174 c->in_receive = GNUNET_NO;
1175 /* FIXME: Add checks for message integrity */
1176 if (NULL == msg)
1177 {
1178 LOG_DEBUG ("Receive timed out or connection to service dropped\n");
1179 return;
1180 }
1181 msize = ntohs (msg->size);
1182 switch (ntohs (msg->type))
1183 {
1184 case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS:
1185 GNUNET_assert (msize >=
1186 sizeof (struct GNUNET_TESTBED_HostConfirmedMessage));
1187 status =
1188 GNUNET_TESTBED_host_handle_addhostconfirm_
1189 (c, (const struct GNUNET_TESTBED_HostConfirmedMessage*) msg);
1190 break;
1191 case GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS:
1192 GNUNET_assert (msize ==
1193 sizeof (struct
1194 GNUNET_TESTBED_GenericOperationSuccessEventMessage));
1195 handle_opsuccess (c,
1196 (const struct
1197 GNUNET_TESTBED_GenericOperationSuccessEventMessage *)
1198 msg);
1199 status = GNUNET_YES;
1200 break;
1201 case GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT:
1202 GNUNET_assert (msize >=
1203 sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage));
1204 handle_op_fail_event (c,
1205 (const struct
1206 GNUNET_TESTBED_OperationFailureEventMessage *)
1207 msg);
1208 status = GNUNET_YES;
1209 break;
1210 case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS:
1211 GNUNET_assert (msize ==
1212 sizeof (struct
1213 GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1214 handle_peer_create_success (c,
1215 (const struct
1216 GNUNET_TESTBED_PeerCreateSuccessEventMessage
1217 *) msg);
1218 status = GNUNET_YES;
1219 break;
1220 case GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT:
1221 GNUNET_assert (msize == sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1222 handle_peer_event (c,
1223 (const struct GNUNET_TESTBED_PeerEventMessage *)
1224 msg);
1225
1226 status = GNUNET_YES;
1227 break;
1228 case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION:
1229 GNUNET_assert (msize >=
1230 sizeof (struct
1231 GNUNET_TESTBED_PeerConfigurationInformationMessage));
1232 handle_peer_config (c,
1233 (const struct
1234 GNUNET_TESTBED_PeerConfigurationInformationMessage
1235 *) msg);
1236 status = GNUNET_YES;
1237
1238 break;
1239 case GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT:
1240 GNUNET_assert (msize ==
1241 sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
1242 handle_peer_conevent (c,
1243 (const struct
1244 GNUNET_TESTBED_ConnectionEventMessage *) msg);
1245 status = GNUNET_YES;
1246 break;
1247 case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION:
1248 GNUNET_assert (msize > sizeof (struct GNUNET_TESTBED_SlaveConfiguration));
1249 handle_slave_config (c,
1250 (const struct GNUNET_TESTBED_SlaveConfiguration *)
1251 msg);
1252 status = GNUNET_YES;
1253 break;
1254 case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT:
1255 handle_link_controllers_result (c,
1256 (const struct
1257 GNUNET_TESTBED_ControllerLinkResponse
1258 *) msg);
1259 status = GNUNET_YES;
1260 break;
1261 case GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS:
1262 status = check_barrier_status_ (c,
1263 (const struct GNUNET_TESTBED_BarrierStatusMsg *) msg);
1264 if (GNUNET_OK == status)
1265 handle_barrier_status_ (c,
1266 (const struct
1267 GNUNET_TESTBED_BarrierStatusMsg *)
1268 msg);
1269 break;
1270 default:
1271 GNUNET_assert (0);
1272 }
1273 if ((GNUNET_OK == status) && (GNUNET_NO == c->in_receive))
1274 {
1275 c->in_receive = GNUNET_YES;
1276 GNUNET_CLIENT_receive (c->client, &message_handler, c,
1277 GNUNET_TIME_UNIT_FOREVER_REL);
1278 }
1279}
1280
1281
1282/**
1283 * Function called to notify a client about the connection begin ready to queue
1284 * more data. "buf" will be NULL and "size" zero if the connection was closed
1285 * for writing in the meantime.
1286 *
1287 * @param cls closure
1288 * @param size number of bytes available in buf
1289 * @param buf where the callee should write the message
1290 * @return number of bytes written to buf
1291 */
1292static size_t
1293transmit_ready_notify (void *cls, size_t size, void *buf)
1294{
1295 struct GNUNET_TESTBED_Controller *c = cls;
1296 struct MessageQueue *mq_entry;
1297
1298 c->th = NULL;
1299 mq_entry = c->mq_head;
1300 GNUNET_assert (NULL != mq_entry);
1301 if ((0 == size) && (NULL == buf)) /* Timeout */
1302 {
1303 LOG_DEBUG ("Message sending timed out -- retrying\n");
1304 c->th =
1305 GNUNET_CLIENT_notify_transmit_ready (c->client,
1306 ntohs (mq_entry->msg->size),
1307 TIMEOUT_REL, GNUNET_YES,
1308 &transmit_ready_notify, c);
1309 return 0;
1310 }
1311 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
1312 size = ntohs (mq_entry->msg->size);
1313 memcpy (buf, mq_entry->msg, size);
1314 LOG_DEBUG ("Message of type: %u and size: %u sent\n",
1315 ntohs (mq_entry->msg->type), size);
1316 GNUNET_free (mq_entry->msg);
1317 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry);
1318 GNUNET_free (mq_entry);
1319 mq_entry = c->mq_head;
1320 if (NULL != mq_entry)
1321 c->th =
1322 GNUNET_CLIENT_notify_transmit_ready (c->client,
1323 ntohs (mq_entry->msg->size),
1324 TIMEOUT_REL, GNUNET_YES,
1325 &transmit_ready_notify, c);
1326 if (GNUNET_NO == c->in_receive)
1327 {
1328 c->in_receive = GNUNET_YES;
1329 GNUNET_CLIENT_receive (c->client, &message_handler, c,
1330 GNUNET_TIME_UNIT_FOREVER_REL);
1331 }
1332 return size;
1333}
1334
1335
1336/**
1337 * Queues a message in send queue for sending to the service 1287 * Queues a message in send queue for sending to the service
1338 * 1288 *
1339 * @param controller the handle to the controller 1289 * @param controller the handle to the controller
1340 * @param msg the message to queue 1290 * @param msg the message to queue
1291 * @deprecated
1341 */ 1292 */
1342void 1293void
1343GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, 1294GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
1344 struct GNUNET_MessageHeader *msg) 1295 struct GNUNET_MessageHeader *msg)
1345{ 1296{
1346 struct MessageQueue *mq_entry; 1297 struct GNUNET_MQ_Envelope *env;
1298 struct GNUNET_MessageHeader *m2;
1347 uint16_t type; 1299 uint16_t type;
1348 uint16_t size; 1300 uint16_t size;
1349 1301
@@ -1351,19 +1303,13 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
1351 size = ntohs (msg->size); 1303 size = ntohs (msg->size);
1352 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && 1304 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
1353 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); 1305 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
1354 mq_entry = GNUNET_new (struct MessageQueue); 1306 env = GNUNET_MQ_msg_extra (m2,
1355 mq_entry->msg = msg; 1307 size - sizeof (*m2),
1356 LOG (GNUNET_ERROR_TYPE_DEBUG, 1308 type);
1357 "Queueing message of type %u, size %u for sending\n", type, 1309 memcpy (m2, msg, size);
1358 ntohs (msg->size)); 1310 GNUNET_free (msg);
1359 GNUNET_CONTAINER_DLL_insert_tail (controller->mq_head, controller->mq_tail, 1311 GNUNET_MQ_send (controller->mq,
1360 mq_entry); 1312 env);
1361 if (NULL == controller->th)
1362 controller->th =
1363 GNUNET_CLIENT_notify_transmit_ready (controller->client, size,
1364 TIMEOUT_REL, GNUNET_YES,
1365 &transmit_ready_notify,
1366 controller);
1367} 1313}
1368 1314
1369 1315
@@ -1527,6 +1473,28 @@ oprelease_get_slave_config (void *cls)
1527 1473
1528 1474
1529/** 1475/**
1476 * Generic error handler, called with the appropriate error code and
1477 * the same closure specified at the creation of the message queue.
1478 * Not every message queue implementation supports an error handler.
1479 *
1480 * @param cls closure, a `struct GNUNET_TESTBED_Controller *`
1481 * @param error error code
1482 */
1483static void
1484mq_error_handler (void *cls,
1485 enum GNUNET_MQ_Error error)
1486{
1487 /* struct GNUNET_TESTBED_Controller *c = cls; */
1488
1489 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1490 "Encountered MQ error: %d\n",
1491 error);
1492 /* now what? */
1493 GNUNET_SCHEDULER_shutdown (); /* seems most reasonable */
1494}
1495
1496
1497/**
1530 * Start a controller process using the given configuration at the 1498 * Start a controller process using the given configuration at the
1531 * given host. 1499 * given host.
1532 * 1500 *
@@ -1547,7 +1515,51 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1547 GNUNET_TESTBED_ControllerCallback cc, 1515 GNUNET_TESTBED_ControllerCallback cc,
1548 void *cc_cls) 1516 void *cc_cls)
1549{ 1517{
1550 struct GNUNET_TESTBED_Controller *controller; 1518 GNUNET_MQ_hd_var_size (add_host_confirm,
1519 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS,
1520 struct GNUNET_TESTBED_HostConfirmedMessage);
1521 GNUNET_MQ_hd_fixed_size (peer_conevent,
1522 GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT,
1523 struct GNUNET_TESTBED_ConnectionEventMessage);
1524 GNUNET_MQ_hd_fixed_size (opsuccess,
1525 GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS,
1526 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
1527 GNUNET_MQ_hd_var_size (op_fail_event,
1528 GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT,
1529 struct GNUNET_TESTBED_OperationFailureEventMessage);
1530 GNUNET_MQ_hd_fixed_size (peer_create_success,
1531 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS,
1532 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage);
1533 GNUNET_MQ_hd_fixed_size (peer_event,
1534 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT,
1535 struct GNUNET_TESTBED_PeerEventMessage);
1536 GNUNET_MQ_hd_var_size (peer_config,
1537 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION,
1538 struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
1539 GNUNET_MQ_hd_var_size (slave_config,
1540 GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION,
1541 struct GNUNET_TESTBED_SlaveConfiguration);
1542 GNUNET_MQ_hd_var_size (link_controllers_result,
1543 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT,
1544 struct GNUNET_TESTBED_ControllerLinkResponse);
1545 GNUNET_MQ_hd_var_size (barrier_status,
1546 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
1547 const struct GNUNET_TESTBED_BarrierStatusMsg);
1548 struct GNUNET_TESTBED_Controller *controller
1549 = GNUNET_new (struct GNUNET_TESTBED_Controller);
1550 struct GNUNET_MQ_MessageHandler handlers[] = {
1551 make_add_host_confirm_handler (controller),
1552 make_peer_conevent_handler (controller),
1553 make_opsuccess_handler (controller),
1554 make_op_fail_event_handler (controller),
1555 make_peer_create_success_handler (controller),
1556 make_peer_event_handler (controller),
1557 make_peer_config_handler (controller),
1558 make_slave_config_handler (controller),
1559 make_link_controllers_result_handler (controller),
1560 make_barrier_status_handler (controller),
1561 GNUNET_MQ_handler_end ()
1562 };
1551 struct GNUNET_TESTBED_InitMessage *msg; 1563 struct GNUNET_TESTBED_InitMessage *msg;
1552 const struct GNUNET_CONFIGURATION_Handle *cfg; 1564 const struct GNUNET_CONFIGURATION_Handle *cfg;
1553 const char *controller_hostname; 1565 const char *controller_hostname;
@@ -1562,6 +1574,7 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1562 &max_parallel_operations)) 1574 &max_parallel_operations))
1563 { 1575 {
1564 GNUNET_break (0); 1576 GNUNET_break (0);
1577 GNUNET_free (controller);
1565 return NULL; 1578 return NULL;
1566 } 1579 }
1567 if (GNUNET_OK != 1580 if (GNUNET_OK !=
@@ -1570,6 +1583,7 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1570 &max_parallel_service_connections)) 1583 &max_parallel_service_connections))
1571 { 1584 {
1572 GNUNET_break (0); 1585 GNUNET_break (0);
1586 GNUNET_free (controller);
1573 return NULL; 1587 return NULL;
1574 } 1588 }
1575 if (GNUNET_OK != 1589 if (GNUNET_OK !=
@@ -1578,16 +1592,21 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1578 &max_parallel_topology_config_operations)) 1592 &max_parallel_topology_config_operations))
1579 { 1593 {
1580 GNUNET_break (0); 1594 GNUNET_break (0);
1595 GNUNET_free (controller);
1581 return NULL; 1596 return NULL;
1582 } 1597 }
1583 controller = GNUNET_new (struct GNUNET_TESTBED_Controller);
1584 controller->cc = cc; 1598 controller->cc = cc;
1585 controller->cc_cls = cc_cls; 1599 controller->cc_cls = cc_cls;
1586 controller->event_mask = event_mask; 1600 controller->event_mask = event_mask;
1587 controller->cfg = GNUNET_CONFIGURATION_dup (cfg); 1601 controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
1588 controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg); 1602 controller->mq = GNUNET_CLIENT_connecT (controller->cfg,
1589 if (NULL == controller->client) 1603 "testbed",
1604 handlers,
1605 &mq_error_handler,
1606 controller);
1607 if (NULL == controller->mq)
1590 { 1608 {
1609 GNUNET_break (0);
1591 GNUNET_TESTBED_controller_disconnect (controller); 1610 GNUNET_TESTBED_controller_disconnect (controller);
1592 return NULL; 1611 return NULL;
1593 } 1612 }
@@ -1629,9 +1648,8 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1629 * @param cls closure 1648 * @param cls closure
1630 * @param key current key code 1649 * @param key current key code
1631 * @param value value in the hash map 1650 * @param value value in the hash map
1632 * @return GNUNET_YES if we should continue to 1651 * @return #GNUNET_YES if we should continue to iterate,
1633 * iterate, 1652 * #GNUNET_NO if not.
1634 * GNUNET_NO if not.
1635 */ 1653 */
1636static int 1654static int
1637opc_free_iterator (void *cls, uint32_t key, void *value) 1655opc_free_iterator (void *cls, uint32_t key, void *value)
@@ -1658,20 +1676,11 @@ opc_free_iterator (void *cls, uint32_t key, void *value)
1658void 1676void
1659GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) 1677GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c)
1660{ 1678{
1661 struct MessageQueue *mq_entry; 1679 if (NULL != c->mq)
1662
1663 if (NULL != c->th)
1664 GNUNET_CLIENT_notify_transmit_ready_cancel (c->th);
1665 /* Clear the message queue */
1666 while (NULL != (mq_entry = c->mq_head))
1667 { 1680 {
1668 GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, 1681 GNUNET_MQ_destroy (c->mq);
1669 mq_entry); 1682 c->mq = NULL;
1670 GNUNET_free (mq_entry->msg);
1671 GNUNET_free (mq_entry);
1672 } 1683 }
1673 if (NULL != c->client)
1674 GNUNET_CLIENT_disconnect (c->client);
1675 if (NULL != c->host) 1684 if (NULL != c->host)
1676 GNUNET_TESTBED_deregister_host_at_ (c->host, c); 1685 GNUNET_TESTBED_deregister_host_at_ (c->host, c);
1677 GNUNET_CONFIGURATION_destroy (c->cfg); 1686 GNUNET_CONFIGURATION_destroy (c->cfg);
@@ -1703,7 +1712,8 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c)
1703 * @return the size of the xconfig 1712 * @return the size of the xconfig
1704 */ 1713 */
1705size_t 1714size_t
1706GNUNET_TESTBED_compress_config_ (const char *config, size_t size, 1715GNUNET_TESTBED_compress_config_ (const char *config,
1716 size_t size,
1707 char **xconfig) 1717 char **xconfig)
1708{ 1718{
1709 size_t xsize; 1719 size_t xsize;
@@ -2002,6 +2012,8 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
2002 * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 2012 * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
2003 * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, 2013 * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT,
2004 * 2014 *
2015 * FIXME: This API is incredibly ugly.
2016 *
2005 * @param msg the message containing compressed configuration 2017 * @param msg the message containing compressed configuration
2006 * @return handle to the parsed configuration; NULL upon error while parsing the message 2018 * @return handle to the parsed configuration; NULL upon error while parsing the message
2007 */ 2019 */
@@ -2407,7 +2419,4 @@ GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
2407} 2419}
2408 2420
2409 2421
2410
2411
2412
2413/* end of testbed_api.c */ 2422/* end of testbed_api.c */