aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_hosts.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-04 13:49:54 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-04 13:49:54 +0000
commita93954693fef730d7a41c168b4961d19e5dff90c (patch)
treee3442617d8cc8813b5a1bb487c0bc69e5e7692ae /src/testbed/testbed_api_hosts.c
parent15de701534fc172c6622397b6692974f784db3e5 (diff)
downloadgnunet-a93954693fef730d7a41c168b4961d19e5dff90c.tar.gz
gnunet-a93954693fef730d7a41c168b4961d19e5dff90c.zip
-controller startup, connect and duals
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r--src/testbed/testbed_api_hosts.c76
1 files changed, 53 insertions, 23 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index 6c0877cea..4d9fb2e61 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -34,6 +34,18 @@
34#include "gnunet_container_lib.h" 34#include "gnunet_container_lib.h"
35 35
36/** 36/**
37 * Generic logging shorthand
38 */
39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
41
42/**
43 * Number of extra elements we create space for when we grow host list
44 */
45#define HOST_LIST_GROW_STEP 10
46
47
48/**
37 * A list entry for registered controllers list 49 * A list entry for registered controllers list
38 */ 50 */
39struct RegisteredController 51struct RegisteredController
@@ -54,6 +66,7 @@ struct RegisteredController
54 struct RegisteredController *prev; 66 struct RegisteredController *prev;
55}; 67};
56 68
69
57/** 70/**
58 * Opaque handle to a host running experiments managed by the testing framework. 71 * Opaque handle to a host running experiments managed by the testing framework.
59 * The master process must be able to SSH to this host without password (via 72 * The master process must be able to SSH to this host without password (via
@@ -95,7 +108,7 @@ struct GNUNET_TESTBED_Host
95 /** 108 /**
96 * Global ID we use to refer to a host on the network 109 * Global ID we use to refer to a host on the network
97 */ 110 */
98 uint32_t unique_id; 111 uint32_t id;
99 112
100 /** 113 /**
101 * The port which is to be used for SSH 114 * The port which is to be used for SSH
@@ -106,14 +119,14 @@ struct GNUNET_TESTBED_Host
106 119
107 120
108/** 121/**
109 * Head element in the list of available hosts 122 * Array of available hosts
110 */ 123 */
111static struct GNUNET_TESTBED_Host *host_list_head; 124static struct GNUNET_TESTBED_Host **host_list;
112 125
113/** 126/**
114 * Tail element in the list of available hosts 127 * The size of the available hosts list
115 */ 128 */
116static struct GNUNET_TESTBED_Host *host_list_tail; 129static uint32_t host_list_size;
117 130
118 131
119/** 132/**
@@ -126,12 +139,9 @@ static struct GNUNET_TESTBED_Host *host_list_tail;
126struct GNUNET_TESTBED_Host * 139struct GNUNET_TESTBED_Host *
127GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) 140GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
128{ 141{
129 struct GNUNET_TESTBED_Host *host; 142 if (host_list_size <= id)
130 143 return NULL;
131 for (host = host_list_head; NULL != host; host=host->next) 144 return host_list[id];
132 if (id == host->unique_id)
133 return host;
134 return NULL;
135} 145}
136 146
137 147
@@ -147,11 +157,7 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
147struct GNUNET_TESTBED_Host * 157struct GNUNET_TESTBED_Host *
148GNUNET_TESTBED_host_create_by_id_ (uint32_t id) 158GNUNET_TESTBED_host_create_by_id_ (uint32_t id)
149{ 159{
150 struct GNUNET_TESTBED_Host *host; 160 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, 0);
151
152 host = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host));
153 host->unique_id = id;
154 return host;
155} 161}
156 162
157 163
@@ -165,7 +171,7 @@ GNUNET_TESTBED_host_create_by_id_ (uint32_t id)
165uint32_t 171uint32_t
166GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) 172GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
167{ 173{
168 return host->unique_id; 174 return host->id;
169} 175}
170 176
171 177
@@ -226,12 +232,23 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id,
226{ 232{
227 struct GNUNET_TESTBED_Host *host; 233 struct GNUNET_TESTBED_Host *host;
228 234
235 if ((id < host_list_size) && (NULL != host_list[host_list_size]))
236 {
237 LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n");
238 return NULL;
239 }
229 host = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host)); 240 host = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host));
230 host->hostname = hostname; 241 host->hostname = hostname;
231 host->username = username; 242 host->username = username;
232 host->unique_id = id; 243 host->id = id;
233 host->port = (0 == port) ? 22 : port; 244 host->port = (0 == port) ? 22 : port;
234 GNUNET_CONTAINER_DLL_insert_tail (host_list_head, host_list_tail, host); 245 if (id < host_list_size)
246 {
247 host_list_size += HOST_LIST_GROW_STEP;
248 host_list = GNUNET_realloc (host_list, sizeof (struct GNUNET_TESTBED_Host)
249 * host_list_size);
250 }
251 host_list[id] = host;
235 return host; 252 return host;
236} 253}
237 254
@@ -286,14 +303,27 @@ void
286GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) 303GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
287{ 304{
288 struct RegisteredController *rc; 305 struct RegisteredController *rc;
289 306 uint32_t id;
290 GNUNET_CONTAINER_DLL_remove (host_list_head, host_list_tail, host); 307
308 GNUNET_assert (host->id < host_list_size);
309 GNUNET_assert (host_list[host->id] == host);
310 host_list[host->id] = NULL;
291 /* clear registered controllers list */ 311 /* clear registered controllers list */
292 for (rc=host->rc_head; NULL != rc; rc=host->rc_head) 312 for (rc=host->rc_head; NULL != rc; rc=host->rc_head)
293 { 313 {
294 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); 314 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
295 GNUNET_free (rc); 315 GNUNET_free (rc);
296 } 316 }
317 for (id = 0; id < HOST_LIST_GROW_STEP; id++)
318 {
319 if ((host->id + id >= host_list_size) || (NULL != host_list[host->id + id]))
320 break;
321 }
322 if (HOST_LIST_GROW_STEP == id)
323 {
324 host_list_size -= HOST_LIST_GROW_STEP;
325 host_list = GNUNET_realloc (host_list, host_list_size);
326 }
297 GNUNET_free (host); 327 GNUNET_free (host);
298} 328}
299 329
@@ -347,7 +377,7 @@ GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host,
347 argc++; 377 argc++;
348 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle)); 378 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HelperHandle));
349 h->cpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); 379 h->cpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
350 if (0 == host->unique_id) 380 if ((NULL == host) || (0 == host->id))
351 { 381 {
352 h->process = GNUNET_OS_start_process_vap (GNUNET_YES, 382 h->process = GNUNET_OS_start_process_vap (GNUNET_YES,
353 h->cpipe, NULL, 383 h->cpipe, NULL,
@@ -355,7 +385,7 @@ GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host,
355 binary_argv); 385 binary_argv);
356 } 386 }
357 else 387 else
358 { 388 {
359 char *remote_args[argc + 6 + 1]; 389 char *remote_args[argc + 6 + 1];
360 unsigned int argp; 390 unsigned int argp;
361 391