diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-13 16:30:48 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-13 16:30:48 +0000 |
commit | a8c5598ba43fcd61a5a340f14a3bab1613adbe7c (patch) | |
tree | 1af703dc3561f4d17ab919c666d22fd94ff3d5b9 /src/testbed/testbed_api_hosts.c | |
parent | b658d1469d6bdaf5930867151130903d221fae37 (diff) | |
download | gnunet-a8c5598ba43fcd61a5a340f14a3bab1613adbe7c.tar.gz gnunet-a8c5598ba43fcd61a5a340f14a3bab1613adbe7c.zip |
-Helper handle wrapper
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index ca7c44cd7..a12d6ce11 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -213,11 +213,33 @@ void | |||
213 | GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | 213 | GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) |
214 | { | 214 | { |
215 | GNUNET_CONTAINER_DLL_remove (host_list_head, host_list_tail, host); | 215 | GNUNET_CONTAINER_DLL_remove (host_list_head, host_list_tail, host); |
216 | GNUNET_free (host); | 216 | GNUNET_free (host); |
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | /** | 220 | /** |
221 | * Wrapper around GNUNET_HELPER_Handle | ||
222 | */ | ||
223 | struct GNUNET_TESTBED_HelperHandle | ||
224 | { | ||
225 | /** | ||
226 | * The helper handle | ||
227 | */ | ||
228 | struct GNUNET_HELPER_Handle *handle; | ||
229 | |||
230 | /** | ||
231 | * The port number for ssh; used for helpers starting ssh | ||
232 | */ | ||
233 | char *port; | ||
234 | |||
235 | /** | ||
236 | * The ssh destination string; used for helpers starting ssh | ||
237 | */ | ||
238 | char *dst; | ||
239 | }; | ||
240 | |||
241 | |||
242 | /** | ||
221 | * Run a given helper process at the given host. Communication | 243 | * Run a given helper process at the given host. Communication |
222 | * with the helper will be via GNUnet messages on stdin/stdout. | 244 | * with the helper will be via GNUnet messages on stdin/stdout. |
223 | * Runs the process via 'ssh' at the specified host, or locally. | 245 | * Runs the process via 'ssh' at the specified host, or locally. |
@@ -229,33 +251,51 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
229 | * @param cb_cls closure for cb | 251 | * @param cb_cls closure for cb |
230 | * @return handle to terminate the command, NULL on error | 252 | * @return handle to terminate the command, NULL on error |
231 | */ | 253 | */ |
232 | struct GNUNET_HELPER_Handle * | 254 | struct GNUNET_TESTBED_HelperHandle * |
233 | GNUNET_TESTBED_host_run_ (struct GNUNET_TESTBED_Host *host, | 255 | GNUNET_TESTBED_host_run_ (struct GNUNET_TESTBED_Host *host, |
234 | char *const binary_argv[], | 256 | char *const binary_argv[], |
235 | GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) | 257 | GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) |
236 | { | 258 | { |
237 | /* FIXME: decide on the SSH command line, prepend it and | 259 | /* FIXME: decide on the SSH command line, prepend it and |
238 | run GNUNET_HELPER_start with the modified binary_name and binary_argv! */ | 260 | run GNUNET_HELPER_start with the modified binary_name and binary_argv! */ |
239 | struct GNUNET_HELPER_Handle *h; | 261 | struct GNUNET_TESTBED_HelperHandle *h; |
240 | char *const local_args[] = {NULL}; | 262 | char *const local_args[] = {NULL}; |
241 | char *port; | ||
242 | char *dst; | ||
243 | char *remote_args[] = {"ssh", "-p", port, "-q", dst, | ||
244 | "gnunet-service-testbed", NULL}; | ||
245 | 263 | ||
264 | h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle)); | ||
246 | if (0 == host->unique_id) | 265 | if (0 == host->unique_id) |
247 | return GNUNET_HELPER_start ("gnunet-service-testbed", local_args, | 266 | { |
248 | cb, cb_cls); | 267 | h->handle = GNUNET_HELPER_start ("gnunet-service-testbed", local_args, |
268 | cb, cb_cls); | ||
269 | } | ||
249 | else | 270 | else |
271 | { | ||
272 | GNUNET_asprintf (&h->port, "%d", host->port); | ||
273 | GNUNET_asprintf (&h->dst, "%s@%s", host->hostname, host->username); | ||
274 | char *remote_args[] = {"ssh", "-p", h->port, "-q", h->dst, | ||
275 | "gnunet-service-testbed", NULL}; | ||
276 | h->handle = GNUNET_HELPER_start ("ssh", remote_args, cb, cb_cls); | ||
277 | } | ||
278 | if (NULL == h->handle) | ||
250 | { | 279 | { |
251 | GNUNET_asprintf (&port, "%d", host->port); | 280 | GNUNET_free (h); |
252 | GNUNET_asprintf (&dst, "%s@%s", host->hostname, host->username); | 281 | return NULL; |
253 | h = GNUNET_HELPER_start ("ssh", remote_args, cb, cb_cls); | ||
254 | GNUNET_free (port); /* FIXME: Can we free them? */ | ||
255 | GNUNET_free (dst); | ||
256 | return h; | ||
257 | } | 282 | } |
283 | return h; | ||
258 | } | 284 | } |
259 | 285 | ||
260 | 286 | ||
287 | /** | ||
288 | * Stops a helper in the HelperHandle using GNUNET_HELPER_stop | ||
289 | * | ||
290 | * @param handle the handle returned from GNUNET_TESTBED_host_start_ | ||
291 | */ | ||
292 | void | ||
293 | GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle) | ||
294 | { | ||
295 | GNUNET_HELPER_stop (handle->handle); | ||
296 | GNUNET_free_non_null (handle->port); | ||
297 | GNUNET_free_non_null (handle->dst); | ||
298 | GNUNET_free (handle); | ||
299 | } | ||
300 | |||
261 | /* end of testbed_api_hosts.c */ | 301 | /* end of testbed_api_hosts.c */ |