aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-05-07 14:35:46 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-05-07 14:35:46 +0000
commit05aa8d8001e3977adb5d68d851db608c075dffee (patch)
tree2c4e23e307a917d67fb41719f2b858bccea590aa /src/testbed/testbed_api_peers.c
parent3029a328070bd5eb422261fb3559b01f415ae51c (diff)
downloadgnunet-05aa8d8001e3977adb5d68d851db608c075dffee.tar.gz
gnunet-05aa8d8001e3977adb5d68d851db608c075dffee.zip
fix #2665: peer reconfiguration now implemented
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c102
1 files changed, 98 insertions, 4 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 8341a96a3..e9328ffb8 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -120,7 +120,7 @@ opstart_peer_create (void *cls)
120 msg->operation_id = GNUNET_htonll (opc->id); 120 msg->operation_id = GNUNET_htonll (opc->id);
121 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); 121 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host));
122 msg->peer_id = htonl (data->peer->unique_id); 122 msg->peer_id = htonl (data->peer->unique_id);
123 msg->config_size = htonl (c_size); 123 msg->config_size = htons ((uint16_t) c_size);
124 GNUNET_TESTBED_insert_opc_ (opc->c, opc); 124 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
125 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); 125 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
126} 126}
@@ -457,6 +457,71 @@ oprelease_overlay_connect (void *cls)
457 457
458 458
459/** 459/**
460 * Function called when a peer reconfigure operation is ready
461 *
462 * @param cls the closure from GNUNET_TESTBED_operation_create_()
463 */
464static void
465opstart_peer_reconfigure (void *cls)
466{
467 struct OperationContext *opc = cls;
468 struct PeerReconfigureData *data = opc->data;
469 struct GNUNET_TESTBED_PeerReconfigureMessage *msg;
470 char *xconfig;
471 size_t xc_size;
472 uint16_t msize;
473
474 opc->state = OPC_STATE_STARTED;
475 GNUNET_assert (NULL != data);
476 xc_size = GNUNET_TESTBED_compress_config_ (data->config, data->cfg_size,
477 &xconfig);
478 GNUNET_free (data->config);
479 data->config = NULL;
480 GNUNET_assert (xc_size <= UINT16_MAX);
481 msize = (uint16_t) xc_size +
482 sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage);
483 msg = GNUNET_realloc (xconfig, msize);
484 (void) memmove (&msg[1], msg, xc_size);
485 msg->header.size = htons (msize);
486 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER);
487 msg->peer_id = htonl (data->peer->unique_id);
488 msg->operation_id = GNUNET_htonll (opc->id);
489 msg->config_size = htons (data->cfg_size);
490 GNUNET_free (data);
491 opc->data = NULL;
492 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
493 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
494}
495
496
497/**
498 * Callback which will be called when a peer reconfigure operation is released
499 *
500 * @param cls the closure from GNUNET_TESTBED_operation_create_()
501 */
502static void
503oprelease_peer_reconfigure (void *cls)
504{
505 struct OperationContext *opc = cls;
506 struct PeerReconfigureData *data = opc->data;
507
508 switch (opc->state)
509 {
510 case OPC_STATE_INIT:
511 GNUNET_free (data->config);
512 GNUNET_free (data);
513 break;
514 case OPC_STATE_STARTED:
515 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
516 break;
517 case OPC_STATE_FINISHED:
518 break;
519 }
520 GNUNET_free (opc);
521}
522
523
524/**
460 * Lookup a peer by ID. 525 * Lookup a peer by ID.
461 * 526 *
462 * @param id global peer ID assigned to the peer 527 * @param id global peer ID assigned to the peer
@@ -673,9 +738,38 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
673 const struct 738 const struct
674 GNUNET_CONFIGURATION_Handle *cfg) 739 GNUNET_CONFIGURATION_Handle *cfg)
675{ 740{
676 // FIXME: handle locally or delegate... 741 struct OperationContext *opc;
677 GNUNET_break (0); 742 struct PeerReconfigureData *data;
678 return NULL; 743 size_t csize;
744
745 data = GNUNET_malloc (sizeof (struct PeerReconfigureData));
746 data->peer = peer;
747 data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize);
748 if (NULL == data->config)
749 {
750 GNUNET_free (data);
751 return NULL;
752 }
753 if (csize > UINT16_MAX)
754 {
755 GNUNET_break (0);
756 GNUNET_free (data->config);
757 GNUNET_free (data);
758 return NULL;
759 }
760 data->cfg_size = (uint16_t) csize;
761 opc = GNUNET_malloc (sizeof (struct OperationContext));
762 opc->c = peer->controller;
763 opc->data = data;
764 opc->type = OP_PEER_RECONFIGURE;
765 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
766 opc->op =
767 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure,
768 &oprelease_peer_reconfigure);
769 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
770 opc->op);
771 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
772 return opc->op;
679} 773}
680 774
681 775