aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r--src/testbed/testbed_api_peers.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 8beae14f9..0010105dc 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -72,15 +72,21 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
72 * @param controller controller process to use 72 * @param controller controller process to use
73 * @param host host to run the peer on 73 * @param host host to run the peer on
74 * @param cfg configuration to use for the peer 74 * @param cfg configuration to use for the peer
75 * @return handle to the peer (actual startup will happen asynchronously) 75 * @param cb the callback to call when the peer has been created
76 * @param cls the closure to the above callback
77 * @return the operation handle
76 */ 78 */
77struct GNUNET_TESTBED_Peer * 79struct GNUNET_TESTBED_Operation *
78GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, 80GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
79 struct GNUNET_TESTBED_Controller *controller, 81 struct GNUNET_TESTBED_Controller *controller,
80 struct GNUNET_TESTBED_Host *host, 82 struct GNUNET_TESTBED_Host *host,
81 const struct GNUNET_CONFIGURATION_Handle *cfg) 83 const struct GNUNET_CONFIGURATION_Handle *cfg,
84 GNUNET_TESTBED_PeerCreateCallback cb,
85 void *cls)
82{ 86{
83 struct GNUNET_TESTBED_Peer *peer; 87 struct GNUNET_TESTBED_Peer *peer;
88 struct PeerCreateData *data;
89 struct GNUNET_TESTBED_Operation *op;
84 struct GNUNET_TESTBED_PeerCreateMessage *msg; 90 struct GNUNET_TESTBED_PeerCreateMessage *msg;
85 char *config; 91 char *config;
86 char *xconfig; 92 char *xconfig;
@@ -92,6 +98,14 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
92 peer->controller = controller; 98 peer->controller = controller;
93 peer->host = host; 99 peer->host = host;
94 peer->unique_id = unique_id; 100 peer->unique_id = unique_id;
101 data = GNUNET_malloc (sizeof (struct PeerCreateData));
102 data->cb = cb;
103 data->cls = cls;
104 data->peer = peer;
105 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
106 op->operation_id = controller->operation_counter++;
107 op->type = OP_PEER_CREATE;
108 op->data = data;
95 config = GNUNET_CONFIGURATION_serialize (cfg, &c_size); 109 config = GNUNET_CONFIGURATION_serialize (cfg, &c_size);
96 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 110 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
97 GNUNET_free (config); 111 GNUNET_free (config);
@@ -100,12 +114,15 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
100 memmove (&msg[1], msg, xc_size); /* Move the compressed config */ 114 memmove (&msg[1], msg, xc_size); /* Move the compressed config */
101 msg->header.size = htons (msize); 115 msg->header.size = htons (msize);
102 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER); 116 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
117 msg->operation_id = GNUNET_htonll (op->operation_id);
103 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host)); 118 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (peer->host));
104 msg->peer_id = htonl (peer->unique_id); 119 msg->peer_id = htonl (peer->unique_id);
105 msg->config_size = htonl (c_size); 120 msg->config_size = htonl (c_size);
121 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
122 peer->controller->op_tail, op);
106 GNUNET_TESTBED_queue_message_ (controller, 123 GNUNET_TESTBED_queue_message_ (controller,
107 (struct GNUNET_MessageHeader *) msg); 124 (struct GNUNET_MessageHeader *) msg);
108 return peer; 125 return op;
109} 126}
110 127
111 128
@@ -133,19 +150,24 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
133 * @param controller controller process to use 150 * @param controller controller process to use
134 * @param host host to run the peer on 151 * @param host host to run the peer on
135 * @param cfg configuration to use for the peer 152 * @param cfg configuration to use for the peer
136 * @return handle to the peer (actual startup will happen asynchronously) 153 * @param cb the callback to call when the peer has been created
154 * @param cls the closure to the above callback
155 * @return the operation handle
137 */ 156 */
138struct GNUNET_TESTBED_Peer * 157struct GNUNET_TESTBED_Operation *
139GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, 158GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
140 struct GNUNET_TESTBED_Host *host, 159 struct GNUNET_TESTBED_Host *host,
141 const struct GNUNET_CONFIGURATION_Handle *cfg) 160 const struct GNUNET_CONFIGURATION_Handle *cfg,
161 GNUNET_TESTBED_PeerCreateCallback cb,
162 void *cls)
142{ 163{
143 static uint32_t id_gen; 164 static uint32_t id_gen;
144 165
145 return GNUNET_TESTBED_peer_create_with_id_ (++id_gen, 166 return GNUNET_TESTBED_peer_create_with_id_ (++id_gen,
146 controller, 167 controller,
147 host, 168 host,
148 cfg); 169 cfg,
170 cb, cls);
149} 171}
150 172
151 173