aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.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_peers.c
parentf27f46409ec33cef42379006d561d33a2ae44682 (diff)
downloadgnunet-9335b7094d8a11449c322b2ca3f5a6cb7a257dad.tar.gz
gnunet-9335b7094d8a11449c322b2ca3f5a6cb7a257dad.zip
-use more of MQ API
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c104
1 files changed, 61 insertions, 43 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 884d4ffca..c30f960c8 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -99,30 +99,36 @@ opstart_peer_create (void *cls)
99 struct OperationContext *opc = cls; 99 struct OperationContext *opc = cls;
100 struct PeerCreateData *data = opc->data; 100 struct PeerCreateData *data = opc->data;
101 struct GNUNET_TESTBED_PeerCreateMessage *msg; 101 struct GNUNET_TESTBED_PeerCreateMessage *msg;
102 struct GNUNET_MQ_Envelope *env;
102 char *config; 103 char *config;
103 char *xconfig; 104 char *xconfig;
104 size_t c_size; 105 size_t c_size;
105 size_t xc_size; 106 size_t xc_size;
106 uint16_t msize;
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, &c_size); 112 config = GNUNET_CONFIGURATION_serialize (data->cfg,
113 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 113 &c_size);
114 xc_size = GNUNET_TESTBED_compress_config_ (config,
115 c_size,
116 &xconfig);
114 GNUNET_free (config); 117 GNUNET_free (config);
115 msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage); 118 env = GNUNET_MQ_msg_extra (msg,
116 msg = GNUNET_realloc (xconfig, msize); 119 xc_size,
117 memmove (&msg[1], msg, xc_size); 120 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER);
118 msg->header.size = htons (msize);
119 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER);
120 msg->operation_id = GNUNET_htonll (opc->id); 121 msg->operation_id = GNUNET_htonll (opc->id);
121 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));
122 msg->peer_id = htonl (data->peer->unique_id); 123 msg->peer_id = htonl (data->peer->unique_id);
123 msg->config_size = htons ((uint16_t) c_size); 124 msg->config_size = htons ((uint16_t) c_size);
125 memcpy (&msg[1],
126 xconfig,
127 xc_size);
128 GNUNET_MQ_send (opc->c->mq,
129 env);
130 GNUNET_free (xconfig);
124 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 131 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
125 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
126} 132}
127 133
128 134
@@ -163,17 +169,18 @@ opstart_peer_destroy (void *cls)
163 struct OperationContext *opc = cls; 169 struct OperationContext *opc = cls;
164 struct GNUNET_TESTBED_Peer *peer = opc->data; 170 struct GNUNET_TESTBED_Peer *peer = opc->data;
165 struct GNUNET_TESTBED_PeerDestroyMessage *msg; 171 struct GNUNET_TESTBED_PeerDestroyMessage *msg;
172 struct GNUNET_MQ_Envelope *env;
166 173
167 GNUNET_assert (OP_PEER_DESTROY == opc->type); 174 GNUNET_assert (OP_PEER_DESTROY == opc->type);
168 GNUNET_assert (NULL != peer); 175 GNUNET_assert (NULL != peer);
169 opc->state = OPC_STATE_STARTED; 176 opc->state = OPC_STATE_STARTED;
170 msg = GNUNET_new (struct GNUNET_TESTBED_PeerDestroyMessage); 177 env = GNUNET_MQ_msg (msg,
171 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); 178 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER);
172 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER);
173 msg->peer_id = htonl (peer->unique_id); 179 msg->peer_id = htonl (peer->unique_id);
174 msg->operation_id = GNUNET_htonll (opc->id); 180 msg->operation_id = GNUNET_htonll (opc->id);
175 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 181 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
176 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); 182 GNUNET_MQ_send (peer->controller->mq,
183 env);
177} 184}
178 185
179 186
@@ -211,6 +218,7 @@ opstart_peer_start (void *cls)
211{ 218{
212 struct OperationContext *opc = cls; 219 struct OperationContext *opc = cls;
213 struct GNUNET_TESTBED_PeerStartMessage *msg; 220 struct GNUNET_TESTBED_PeerStartMessage *msg;
221 struct GNUNET_MQ_Envelope *env;
214 struct PeerEventData *data; 222 struct PeerEventData *data;
215 struct GNUNET_TESTBED_Peer *peer; 223 struct GNUNET_TESTBED_Peer *peer;
216 224
@@ -219,13 +227,13 @@ opstart_peer_start (void *cls)
219 GNUNET_assert (NULL != (peer = data->peer)); 227 GNUNET_assert (NULL != (peer = data->peer));
220 GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); 228 GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state));
221 opc->state = OPC_STATE_STARTED; 229 opc->state = OPC_STATE_STARTED;
222 msg = GNUNET_new (struct GNUNET_TESTBED_PeerStartMessage); 230 env = GNUNET_MQ_msg (msg,
223 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 231 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER);
224 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_START_PEER);
225 msg->peer_id = htonl (peer->unique_id); 232 msg->peer_id = htonl (peer->unique_id);
226 msg->operation_id = GNUNET_htonll (opc->id); 233 msg->operation_id = GNUNET_htonll (opc->id);
227 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 234 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
228 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); 235 GNUNET_MQ_send (peer->controller->mq,
236 env);
229} 237}
230 238
231 239
@@ -266,18 +274,19 @@ opstart_peer_stop (void *cls)
266 struct GNUNET_TESTBED_PeerStopMessage *msg; 274 struct GNUNET_TESTBED_PeerStopMessage *msg;
267 struct PeerEventData *data; 275 struct PeerEventData *data;
268 struct GNUNET_TESTBED_Peer *peer; 276 struct GNUNET_TESTBED_Peer *peer;
277 struct GNUNET_MQ_Envelope *env;
269 278
270 GNUNET_assert (NULL != (data = opc->data)); 279 GNUNET_assert (NULL != (data = opc->data));
271 GNUNET_assert (NULL != (peer = data->peer)); 280 GNUNET_assert (NULL != (peer = data->peer));
272 GNUNET_assert (TESTBED_PS_STARTED == peer->state); 281 GNUNET_assert (TESTBED_PS_STARTED == peer->state);
273 opc->state = OPC_STATE_STARTED; 282 opc->state = OPC_STATE_STARTED;
274 msg = GNUNET_new (struct GNUNET_TESTBED_PeerStopMessage); 283 env = GNUNET_MQ_msg (msg,
275 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); 284 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER);
276 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
277 msg->peer_id = htonl (peer->unique_id); 285 msg->peer_id = htonl (peer->unique_id);
278 msg->operation_id = GNUNET_htonll (opc->id); 286 msg->operation_id = GNUNET_htonll (opc->id);
279 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 287 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
280 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); 288 GNUNET_MQ_send (peer->controller->mq,
289 env);
281} 290}
282 291
283 292
@@ -404,22 +413,23 @@ static void
404opstart_overlay_connect (void *cls) 413opstart_overlay_connect (void *cls)
405{ 414{
406 struct OperationContext *opc = cls; 415 struct OperationContext *opc = cls;
416 struct GNUNET_MQ_Envelope *env;
407 struct GNUNET_TESTBED_OverlayConnectMessage *msg; 417 struct GNUNET_TESTBED_OverlayConnectMessage *msg;
408 struct OverlayConnectData *data; 418 struct OverlayConnectData *data;
409 419
410 opc->state = OPC_STATE_STARTED; 420 opc->state = OPC_STATE_STARTED;
411 data = opc->data; 421 data = opc->data;
412 GNUNET_assert (NULL != data); 422 GNUNET_assert (NULL != data);
413 msg = GNUNET_new (struct GNUNET_TESTBED_OverlayConnectMessage); 423 env = GNUNET_MQ_msg (msg,
414 msg->header.size = 424 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT);
415 htons (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage));
416 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT);
417 msg->peer1 = htonl (data->p1->unique_id); 425 msg->peer1 = htonl (data->p1->unique_id);
418 msg->peer2 = htonl (data->p2->unique_id); 426 msg->peer2 = htonl (data->p2->unique_id);
419 msg->operation_id = GNUNET_htonll (opc->id); 427 msg->operation_id = GNUNET_htonll (opc->id);
420 msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); 428 msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host));
421 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 429 GNUNET_TESTBED_insert_opc_ (opc->c,
422 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 430 opc);
431 GNUNET_MQ_send (opc->c->mq,
432 env);
423} 433}
424 434
425 435
@@ -460,31 +470,34 @@ opstart_peer_reconfigure (void *cls)
460{ 470{
461 struct OperationContext *opc = cls; 471 struct OperationContext *opc = cls;
462 struct PeerReconfigureData *data = opc->data; 472 struct PeerReconfigureData *data = opc->data;
473 struct GNUNET_MQ_Envelope *env;
463 struct GNUNET_TESTBED_PeerReconfigureMessage *msg; 474 struct GNUNET_TESTBED_PeerReconfigureMessage *msg;
464 char *xconfig; 475 char *xconfig;
465 size_t xc_size; 476 size_t xc_size;
466 uint16_t msize;
467 477
468 opc->state = OPC_STATE_STARTED; 478 opc->state = OPC_STATE_STARTED;
469 GNUNET_assert (NULL != data); 479 GNUNET_assert (NULL != data);
470 xc_size = GNUNET_TESTBED_compress_config_ (data->config, data->cfg_size, 480 xc_size = GNUNET_TESTBED_compress_config_ (data->config,
481 data->cfg_size,
471 &xconfig); 482 &xconfig);
472 GNUNET_free (data->config); 483 GNUNET_free (data->config);
473 data->config = NULL; 484 data->config = NULL;
474 GNUNET_assert (xc_size <= UINT16_MAX); 485 GNUNET_assert (xc_size < UINT16_MAX - sizeof (*msg));
475 msize = (uint16_t) xc_size + 486 env = GNUNET_MQ_msg_extra (msg,
476 sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage); 487 xc_size,
477 msg = GNUNET_realloc (xconfig, msize); 488 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER);
478 (void) memmove (&msg[1], msg, xc_size);
479 msg->header.size = htons (msize);
480 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER);
481 msg->peer_id = htonl (data->peer->unique_id); 489 msg->peer_id = htonl (data->peer->unique_id);
482 msg->operation_id = GNUNET_htonll (opc->id); 490 msg->operation_id = GNUNET_htonll (opc->id);
483 msg->config_size = htons (data->cfg_size); 491 msg->config_size = htons (data->cfg_size);
492 memcpy (&msg[1],
493 xconfig,
494 xc_size);
495 GNUNET_free (xconfig);
484 GNUNET_free (data); 496 GNUNET_free (data);
485 opc->data = NULL; 497 opc->data = NULL;
486 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 498 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
487 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 499 GNUNET_MQ_send (opc->c->mq,
500 env);
488} 501}
489 502
490 503
@@ -873,22 +886,27 @@ opstart_manage_service (void *cls)
873{ 886{
874 struct OperationContext *opc = cls; 887 struct OperationContext *opc = cls;
875 struct ManageServiceData *data = opc->data; 888 struct ManageServiceData *data = opc->data;
889 struct GNUNET_MQ_Envelope *env;
876 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; 890 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg;
891 size_t xlen;
877 892
878 GNUNET_assert (NULL != data); 893 GNUNET_assert (NULL != data);
879 msg = GNUNET_malloc (data->msize); 894 xlen = data->msize - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage);
880 msg->header.size = htons (data->msize); 895 env = GNUNET_MQ_msg_extra (msg,
881 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); 896 xlen,
897 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE);
882 msg->peer_id = htonl (data->peer->unique_id); 898 msg->peer_id = htonl (data->peer->unique_id);
883 msg->operation_id = GNUNET_htonll (opc->id); 899 msg->operation_id = GNUNET_htonll (opc->id);
884 msg->start = (uint8_t) data->start; 900 msg->start = (uint8_t) data->start;
885 (void) memcpy (&msg[1], data->service_name, data->msize 901 memcpy (&msg[1],
886 - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage)); 902 data->service_name,
903 xlen);
887 GNUNET_free (data->service_name); 904 GNUNET_free (data->service_name);
888 data->service_name = NULL; 905 data->service_name = NULL;
889 opc->state = OPC_STATE_STARTED; 906 opc->state = OPC_STATE_STARTED;
890 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 907 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
891 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 908 GNUNET_MQ_send (opc->c->mq,
909 env);
892} 910}
893 911
894 912