aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-02 13:31:20 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-02 13:31:20 +0000
commitd723a288c2185671ef410a70d9113d1f19a5c36a (patch)
tree2aa1f4c7e0001bbe02d4e6fe465c4e12af060dd1 /src
parenta59b9fbcf5f6d05501b1d0b403abe41e7ac0e60e (diff)
downloadgnunet-d723a288c2185671ef410a70d9113d1f19a5c36a.tar.gz
gnunet-d723a288c2185671ef410a70d9113d1f19a5c36a.zip
- manage services of peers (client API)
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_protocols.h5
-rw-r--r--src/testbed/testbed.h31
-rw-r--r--src/testbed/testbed_api.c62
-rw-r--r--src/testbed/testbed_api.h7
-rw-r--r--src/testbed/testbed_api_peers.c88
-rw-r--r--src/testbed/testbed_api_peers.h16
6 files changed, 203 insertions, 6 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 0293c1c90..a012a7c53 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1630,6 +1630,11 @@ extern "C"
1630#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 483 1630#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 483
1631 1631
1632/** 1632/**
1633 * Message to start/stop a service of a peer
1634 */
1635#define GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE 484
1636
1637/**
1633 * Not really a message, but for careful checks on the testbed messages; Should 1638 * Not really a message, but for careful checks on the testbed messages; Should
1634 * always be the maximum and never be used to send messages with this type 1639 * always be the maximum and never be used to send messages with this type
1635 */ 1640 */
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index c9692c088..82747de5c 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -768,6 +768,37 @@ struct GNUNET_TESTBED_ShutdownPeersMessage
768}; 768};
769 769
770 770
771/**
772 * Message to start/stop services of a peer
773 */
774struct GNUNET_TESTBED_ManagePeerServiceMessage
775{
776 /**
777 * Type is GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS
778 */
779 struct GNUNET_MessageHeader header;
780
781 /**
782 * Unique ID of the peer whose service has to be managed.
783 */
784 uint32_t peer_id GNUNET_PACKED;
785
786 /**
787 * Operation ID
788 */
789 uint64_t operation_id GNUNET_PACKED;
790
791 /**
792 * set this to 1 to start the service; 0 to stop the service
793 */
794 uint8_t start;
795
796 /**
797 * The NULL-terminated name of the service to start/stop follows here
798 */
799};
800
801
771GNUNET_NETWORK_STRUCT_END 802GNUNET_NETWORK_STRUCT_END
772#endif 803#endif
773/* end of testbed.h */ 804/* end of testbed.h */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index e85fbb8f1..95ff9e432 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -178,11 +178,23 @@ struct ExpireOperationEntry
178 const struct GNUNET_TESTBED_Operation *op; 178 const struct GNUNET_TESTBED_Operation *op;
179}; 179};
180 180
181
182/**
183 * DLL head for list of operations marked for expiry
184 */
181static struct ExpireOperationEntry *exop_head; 185static struct ExpireOperationEntry *exop_head;
182 186
187/**
188 * DLL tail for list of operation marked for expiry
189 */
183static struct ExpireOperationEntry *exop_tail; 190static struct ExpireOperationEntry *exop_tail;
184 191
185 192
193/**
194 * Inserts an operation into the list of operations marked for expiry
195 *
196 * @param op the operation to insert
197 */
186static void 198static void
187exop_insert (struct GNUNET_TESTBED_Operation *op) 199exop_insert (struct GNUNET_TESTBED_Operation *op)
188{ 200{
@@ -194,6 +206,17 @@ exop_insert (struct GNUNET_TESTBED_Operation *op)
194} 206}
195 207
196 208
209/**
210 * Checks if an operation is present in the list of operations marked for
211 * expiry. If the operation is found, it and the tail of operations after it
212 * are removed from the list.
213 *
214 * @param op the operation to check
215 * @return GNUNET_NO if the operation is not present in the list; GNUNET_YES if
216 * the operation is found in the list (the operation is then removed
217 * from the list -- calling this function again with the same
218 * paramenter will return GNUNET_NO)
219 */
197static int 220static int
198exop_check (const struct GNUNET_TESTBED_Operation *const op) 221exop_check (const struct GNUNET_TESTBED_Operation *const op)
199{ 222{
@@ -337,6 +360,17 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
337 GNUNET_TESTBED_cleanup_peers_ (); 360 GNUNET_TESTBED_cleanup_peers_ ();
338 } 361 }
339 break; 362 break;
363 case OP_MANAGE_SERVICE:
364 {
365 struct ManageServiceData *data;
366
367 GNUNET_assert (NULL != (data = opc->data));
368 op_comp_cb = data->cb;
369 op_comp_cb_cls = data->cb_cls;
370 GNUNET_free (data);
371 opc->data = NULL;
372 }
373 break;
340 default: 374 default:
341 GNUNET_assert (0); 375 GNUNET_assert (0);
342 } 376 }
@@ -691,14 +725,14 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
691 GNUNET_free (data); 725 GNUNET_free (data);
692 return GNUNET_YES; /* We do not call controller callback for peer info */ 726 return GNUNET_YES; /* We do not call controller callback for peer info */
693 } 727 }
728 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
729 event.op = opc->op;
730 event.op_cls = opc->op_cls;
731 event.details.operation_finished.emsg = emsg;
732 event.details.operation_finished.generic = NULL;
694 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && 733 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
695 (NULL != c->cc)) 734 (NULL != c->cc))
696 { 735 {
697 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
698 event.op = opc->op;
699 event.op_cls = opc->op_cls;
700 event.details.operation_finished.emsg = emsg;
701 event.details.operation_finished.generic = NULL;
702 exop_insert (event.op); 736 exop_insert (event.op);
703 c->cc (c->cc_cls, &event); 737 c->cc (c->cc_cls, &event);
704 if (GNUNET_NO == exop_check (event.op)) 738 if (GNUNET_NO == exop_check (event.op))
@@ -755,6 +789,24 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c,
755 opc->data = NULL; 789 opc->data = NULL;
756 } 790 }
757 break; 791 break;
792 case OP_MANAGE_SERVICE:
793 {
794 struct ManageServiceData *data = opc->data;
795 GNUNET_TESTBED_OperationCompletionCallback cb;
796 void *cb_cls;
797
798 GNUNET_assert (NULL != data);
799 cb = data->cb;
800 cb_cls = data->cb_cls;
801 GNUNET_free (data);
802 opc->data = NULL;
803 exop_insert (event.op);
804 if (NULL != cb)
805 cb (cb_cls, opc->op, emsg);
806 /* You could have marked the operation as done by now */
807 GNUNET_break (GNUNET_NO == exop_check (event.op));
808 }
809 break;
758 default: 810 default:
759 GNUNET_break (0); 811 GNUNET_break (0);
760 } 812 }
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index 65e9efe36..c3b702755 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -90,7 +90,12 @@ enum OperationType
90 /** 90 /**
91 * Stop and destroy all peers 91 * Stop and destroy all peers
92 */ 92 */
93 OP_SHUTDOWN_PEERS 93 OP_SHUTDOWN_PEERS,
94
95 /**
96 * Start/stop service at a peer
97 */
98 OP_MANAGE_SERVICE
94}; 99};
95 100
96 101
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 8944ec776..252131313 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -774,5 +774,93 @@ GNUNET_TESTBED_overlay_connect (void *op_cls,
774} 774}
775 775
776 776
777static void
778opstart_manage_service (void *cls)
779{
780 struct OperationContext *opc = cls;
781 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg;
782 struct ManageServiceData *data;
783
784 GNUNET_assert (NULL != (data = opc->data));
785 msg = GNUNET_malloc (data->msize);
786 msg->header.size = htons (data->msize);
787 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE);
788 msg->peer_id = htonl (data->peer->unique_id);
789 msg->operation_id = GNUNET_htonll (opc->id);
790 msg->start = (uint8_t) data->start;
791 (void) memcpy (&msg[1], data->service_name, data->msize
792 - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage));
793 GNUNET_free (data->service_name);
794 data->service_name = NULL;
795 opc->state = OPC_STATE_STARTED;
796 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
797 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
798}
799
800
801static void
802oprelease_manage_service (void *cls)
803{
804 struct OperationContext *opc = cls;
805 struct ManageServiceData *data;
806
807 data = opc->data;
808 switch (opc->state)
809 {
810 case OPC_STATE_STARTED:
811 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
812 break;
813 case OPC_STATE_INIT:
814 GNUNET_assert (NULL != data);
815 GNUNET_free (data->service_name);
816 break;
817 case OPC_STATE_FINISHED:
818 break;
819 }
820 GNUNET_free_non_null (data);
821 GNUNET_free (opc);
822}
823
824
825struct GNUNET_TESTBED_Operation *
826GNUNET_TESTBED_peer_manage_service (void *op_cls,
827 struct GNUNET_TESTBED_Peer *peer,
828 const char *service_name,
829 GNUNET_TESTBED_OperationCompletionCallback cb,
830 void *cb_cls,
831 unsigned int start)
832{
833 struct ManageServiceData *data;
834 struct OperationContext *opc;
835 size_t msize;
836
837 GNUNET_assert (PS_STARTED == peer->state); /* peer is not running? */
838 msize = strlen (service_name) + 1;
839 msize += sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage);
840 if (GNUNET_SERVER_MAX_MESSAGE_SIZE < msize)
841 return NULL;
842 data = GNUNET_malloc (sizeof (struct ManageServiceData));
843 data->cb = cb;
844 data->cb_cls = cb_cls;
845 data->peer = peer;
846 data->service_name = GNUNET_strdup (service_name);
847 data->start = start;
848 data->msize = (uint16_t) msize;
849 opc = GNUNET_malloc (sizeof (struct OperationContext));
850 opc->data = data;
851 opc->c = peer->controller;
852 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
853 opc->type = OP_MANAGE_SERVICE;
854 opc->op_cls = op_cls;
855 opc->op =
856 GNUNET_TESTBED_operation_create_ (opc, &opstart_manage_service,
857 &oprelease_manage_service);
858 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
859 opc->op);
860 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
861 return opc->op;
862}
863
864
777 865
778/* end of testbed_api_peers.c */ 866/* end of testbed_api_peers.c */
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 49f875607..96b718026 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -246,6 +246,22 @@ struct OverlayConnectData
246}; 246};
247 247
248 248
249struct ManageServiceData {
250 GNUNET_TESTBED_OperationCompletionCallback cb;
251
252 void *cb_cls;
253
254 struct GNUNET_TESTBED_Peer *peer;
255
256 char *service_name;
257
258 unsigned int start;
259
260 uint16_t msize;
261
262};
263
264
249/** 265/**
250 * Generate PeerGetConfigurationMessage 266 * Generate PeerGetConfigurationMessage
251 * 267 *