aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_hosts.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-14 09:25:54 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-14 09:25:54 +0000
commitda1f2411d623d100d9df6a72c6081ccaccc23d13 (patch)
tree81fd3d43d9f7220896aa6367469daa1ba479fb4a /src/testbed/testbed_api_hosts.c
parent3ced678ccb6e8c7ceacc96bfc0281470b81c189d (diff)
downloadgnunet-da1f2411d623d100d9df6a72c6081ccaccc23d13.tar.gz
gnunet-da1f2411d623d100d9df6a72c6081ccaccc23d13.zip
-testbed hackery
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r--src/testbed/testbed_api_hosts.c86
1 files changed, 59 insertions, 27 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index a12d6ce11..c4dfcf3c9 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -132,7 +132,7 @@ GNUNET_TESTBED_host_create_by_id_ (uint32_t id)
132uint32_t 132uint32_t
133GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) 133GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
134{ 134{
135 return host->unique_id; 135 return host->unique_id;
136} 136}
137 137
138 138
@@ -147,10 +147,10 @@ GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
147 * @return handle to the host, NULL on error 147 * @return handle to the host, NULL on error
148 */ 148 */
149struct GNUNET_TESTBED_Host * 149struct GNUNET_TESTBED_Host *
150GNUNET_TESTBED_host_create_with_id_ (uint32_t id, 150GNUNET_TESTBED_host_create_with_id (uint32_t id,
151 const char *hostname, 151 const char *hostname,
152 const char *username, 152 const char *username,
153 uint16_t port) 153 uint16_t port)
154{ 154{
155 struct GNUNET_TESTBED_Host *host; 155 struct GNUNET_TESTBED_Host *host;
156 156
@@ -180,10 +180,10 @@ GNUNET_TESTBED_host_create (const char *hostname,
180 static uint32_t uid_generator; 180 static uint32_t uid_generator;
181 181
182 if (NULL == hostname) 182 if (NULL == hostname)
183 return GNUNET_TESTBED_host_create_with_id_ (0, hostname, username, port); 183 return GNUNET_TESTBED_host_create_with_id (0, hostname, username, port);
184 return GNUNET_TESTBED_host_create_with_id_ (++uid_generator, 184 return GNUNET_TESTBED_host_create_with_id (++uid_generator,
185 hostname, username, 185 hostname, username,
186 port); 186 port);
187} 187}
188 188
189 189
@@ -198,6 +198,7 @@ unsigned int
198GNUNET_TESTBED_hosts_load_from_file (const char *filename, 198GNUNET_TESTBED_hosts_load_from_file (const char *filename,
199 struct GNUNET_TESTBED_Host **hosts) 199 struct GNUNET_TESTBED_Host **hosts)
200{ 200{
201 // see testing_group.c, GNUNET_TESTING_hosts_load
201 GNUNET_break (0); 202 GNUNET_break (0);
202 return 0; 203 return 0;
203} 204}
@@ -223,9 +224,14 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
223struct GNUNET_TESTBED_HelperHandle 224struct GNUNET_TESTBED_HelperHandle
224{ 225{
225 /** 226 /**
226 * The helper handle 227 * The process handle
227 */ 228 */
228 struct GNUNET_HELPER_Handle *handle; 229 struct GNUNET_OS_Process *process;
230
231 /**
232 * Pipe connecting to stdin of the process.
233 */
234 struct GNUNET_DISK_PipeHandle *cpipe;
229 235
230 /** 236 /**
231 * The port number for ssh; used for helpers starting ssh 237 * The port number for ssh; used for helpers starting ssh
@@ -247,39 +253,62 @@ struct GNUNET_TESTBED_HelperHandle
247 * 253 *
248 * @param host host to use, use "NULL" for localhost 254 * @param host host to use, use "NULL" for localhost
249 * @param binary_argv binary name and command-line arguments to give to the binary 255 * @param binary_argv binary name and command-line arguments to give to the binary
250 * @param cb function to call for messages received from the binary
251 * @param cb_cls closure for cb
252 * @return handle to terminate the command, NULL on error 256 * @return handle to terminate the command, NULL on error
253 */ 257 */
254struct GNUNET_TESTBED_HelperHandle * 258struct GNUNET_TESTBED_HelperHandle *
255GNUNET_TESTBED_host_run_ (struct GNUNET_TESTBED_Host *host, 259GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host,
256 char *const binary_argv[], 260 char *const binary_argv[])
257 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
258{ 261{
259 /* FIXME: decide on the SSH command line, prepend it and
260 run GNUNET_HELPER_start with the modified binary_name and binary_argv! */
261 struct GNUNET_TESTBED_HelperHandle *h; 262 struct GNUNET_TESTBED_HelperHandle *h;
262 char *const local_args[] = {NULL}; 263 unsigned int argc;
263 264
265 argc = 0;
266 while (NULL != binary_argv[argc])
267 argc++;
264 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle)); 268 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle));
269 h->cpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
265 if (0 == host->unique_id) 270 if (0 == host->unique_id)
266 { 271 {
267 h->handle = GNUNET_HELPER_start ("gnunet-service-testbed", local_args, 272 h->process = GNUNET_OS_start_process_vap (GNUNET_YES,
268 cb, cb_cls); 273 h->cpipe, NULL,
274 "gnunet-service-testbed",
275 binary_argv);
269 } 276 }
270 else 277 else
271 { 278 {
279 char *remote_args[argc + 6 + 1];
280 unsigned int argp;
281
272 GNUNET_asprintf (&h->port, "%d", host->port); 282 GNUNET_asprintf (&h->port, "%d", host->port);
273 GNUNET_asprintf (&h->dst, "%s@%s", host->hostname, host->username); 283 GNUNET_asprintf (&h->dst, "%s@%s", host->hostname, host->username);
274 char *remote_args[] = {"ssh", "-p", h->port, "-q", h->dst, 284 argp = 0;
275 "gnunet-service-testbed", NULL}; 285 remote_args[argp++] = "ssh";
276 h->handle = GNUNET_HELPER_start ("ssh", remote_args, cb, cb_cls); 286 remote_args[argp++] = "-p";
287 remote_args[argp++] = h->port;
288 remote_args[argp++] = "-q";
289 remote_args[argp++] = h->dst;
290 remote_args[argp++] = "gnunet-service-testbed";
291 while (NULL != binary_argv[argp-6])
292 {
293 remote_args[argp] = binary_argv[argp - 6];
294 argp++;
295 }
296 remote_args[argp++] = NULL;
297 GNUNET_assert (argp == argc + 6 + 1);
298 h->process = GNUNET_OS_start_process_vap (GNUNET_YES,
299 h->cpipe, NULL,
300 "ssh",
301 remote_args);
277 } 302 }
278 if (NULL == h->handle) 303 if (NULL == h->process)
279 { 304 {
305 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close (h->cpipe));
306 GNUNET_free_non_null (h->port);
307 GNUNET_free_non_null (h->dst);
280 GNUNET_free (h); 308 GNUNET_free (h);
281 return NULL; 309 return NULL;
282 } 310 }
311 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close_end (h->cpipe, GNUNET_DISK_PIPE_END_READ));
283 return h; 312 return h;
284} 313}
285 314
@@ -292,7 +321,10 @@ GNUNET_TESTBED_host_run_ (struct GNUNET_TESTBED_Host *host,
292void 321void
293GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle) 322GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle)
294{ 323{
295 GNUNET_HELPER_stop (handle->handle); 324 GNUNET_break (GNUNET_OK == GNUNET_DISK_pipe_close (handle->cpipe));
325 GNUNET_break (0 == GNUNET_OS_process_kill (handle->process, SIGTERM));
326 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (handle->process));
327 GNUNET_OS_process_destroy (handle->process);
296 GNUNET_free_non_null (handle->port); 328 GNUNET_free_non_null (handle->port);
297 GNUNET_free_non_null (handle->dst); 329 GNUNET_free_non_null (handle->dst);
298 GNUNET_free (handle); 330 GNUNET_free (handle);