diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-31 10:36:28 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-31 10:36:28 +0000 |
commit | a94a1861d123fe850d2ab5ae74cbb59b132a15ea (patch) | |
tree | a16d2518067d13f2463e83cd9dc66bdd6b733621 /src/testbed/testbed_api_hosts.c | |
parent | d0c55c3ee57913977b1497ea0e6f20573820b206 (diff) | |
download | gnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.tar.gz gnunet-a94a1861d123fe850d2ab5ae74cbb59b132a15ea.zip |
adhering to indentation standard
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 27731caf8..20e601265 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -57,7 +57,7 @@ struct RegisteredController | |||
57 | * The controller at which this host is registered | 57 | * The controller at which this host is registered |
58 | */ | 58 | */ |
59 | const struct GNUNET_TESTBED_Controller *controller; | 59 | const struct GNUNET_TESTBED_Controller *controller; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * The next ptr for DLL | 62 | * The next ptr for DLL |
63 | */ | 63 | */ |
@@ -134,7 +134,7 @@ static uint32_t host_list_size; | |||
134 | 134 | ||
135 | /** | 135 | /** |
136 | * Lookup a host by ID. | 136 | * Lookup a host by ID. |
137 | * | 137 | * |
138 | * @param id global host ID assigned to the host; 0 is | 138 | * @param id global host ID assigned to the host; 0 is |
139 | * reserved to always mean 'localhost' | 139 | * reserved to always mean 'localhost' |
140 | * @return handle to the host, NULL if host not found | 140 | * @return handle to the host, NULL if host not found |
@@ -152,7 +152,7 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) | |||
152 | * Create a host by ID; given this host handle, we could not | 152 | * Create a host by ID; given this host handle, we could not |
153 | * run peers at the host, but we can talk about the host | 153 | * run peers at the host, but we can talk about the host |
154 | * internally. | 154 | * internally. |
155 | * | 155 | * |
156 | * @param id global host ID assigned to the host; 0 is | 156 | * @param id global host ID assigned to the host; 0 is |
157 | * reserved to always mean 'localhost' | 157 | * reserved to always mean 'localhost' |
158 | * @return handle to the host, NULL on error | 158 | * @return handle to the host, NULL on error |
@@ -166,13 +166,13 @@ GNUNET_TESTBED_host_create_by_id_ (uint32_t id) | |||
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Obtain the host's unique global ID. | 168 | * Obtain the host's unique global ID. |
169 | * | 169 | * |
170 | * @param host handle to the host, NULL means 'localhost' | 170 | * @param host handle to the host, NULL means 'localhost' |
171 | * @return id global host ID assigned to the host (0 is | 171 | * @return id global host ID assigned to the host (0 is |
172 | * 'localhost', but then obviously not globally unique) | 172 | * 'localhost', but then obviously not globally unique) |
173 | */ | 173 | */ |
174 | uint32_t | 174 | uint32_t |
175 | GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) | 175 | GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host * host) |
176 | { | 176 | { |
177 | return host->id; | 177 | return host->id; |
178 | } | 178 | } |
@@ -180,7 +180,7 @@ GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) | |||
180 | 180 | ||
181 | /** | 181 | /** |
182 | * Obtain the host's hostname. | 182 | * Obtain the host's hostname. |
183 | * | 183 | * |
184 | * @param host handle to the host, NULL means 'localhost' | 184 | * @param host handle to the host, NULL means 'localhost' |
185 | * @return hostname of the host | 185 | * @return hostname of the host |
186 | */ | 186 | */ |
@@ -193,7 +193,7 @@ GNUNET_TESTBED_host_get_hostname_ (const struct GNUNET_TESTBED_Host *host) | |||
193 | 193 | ||
194 | /** | 194 | /** |
195 | * Obtain the host's username | 195 | * Obtain the host's username |
196 | * | 196 | * |
197 | * @param host handle to the host, NULL means 'localhost' | 197 | * @param host handle to the host, NULL means 'localhost' |
198 | * @return username to login to the host | 198 | * @return username to login to the host |
199 | */ | 199 | */ |
@@ -206,12 +206,12 @@ GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host) | |||
206 | 206 | ||
207 | /** | 207 | /** |
208 | * Obtain the host's ssh port | 208 | * Obtain the host's ssh port |
209 | * | 209 | * |
210 | * @param host handle to the host, NULL means 'localhost' | 210 | * @param host handle to the host, NULL means 'localhost' |
211 | * @return username to login to the host | 211 | * @return username to login to the host |
212 | */ | 212 | */ |
213 | uint16_t | 213 | uint16_t |
214 | GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) | 214 | GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host * host) |
215 | { | 215 | { |
216 | return host->port; | 216 | return host->port; |
217 | } | 217 | } |
@@ -219,7 +219,7 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) | |||
219 | 219 | ||
220 | /** | 220 | /** |
221 | * Create a host to run peers and controllers on. | 221 | * Create a host to run peers and controllers on. |
222 | * | 222 | * |
223 | * @param id global host ID assigned to the host; 0 is | 223 | * @param id global host ID assigned to the host; 0 is |
224 | * reserved to always mean 'localhost' | 224 | * reserved to always mean 'localhost' |
225 | * @param hostname name of the host, use "NULL" for localhost | 225 | * @param hostname name of the host, use "NULL" for localhost |
@@ -228,10 +228,8 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) | |||
228 | * @return handle to the host, NULL on error | 228 | * @return handle to the host, NULL on error |
229 | */ | 229 | */ |
230 | struct GNUNET_TESTBED_Host * | 230 | struct GNUNET_TESTBED_Host * |
231 | GNUNET_TESTBED_host_create_with_id (uint32_t id, | 231 | GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname, |
232 | const char *hostname, | 232 | const char *username, uint16_t port) |
233 | const char *username, | ||
234 | uint16_t port) | ||
235 | { | 233 | { |
236 | struct GNUNET_TESTBED_Host *host; | 234 | struct GNUNET_TESTBED_Host *host; |
237 | uint32_t new_size; | 235 | uint32_t new_size; |
@@ -251,15 +249,15 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, | |||
251 | new_size += HOST_LIST_GROW_STEP; | 249 | new_size += HOST_LIST_GROW_STEP; |
252 | if (new_size != host_list_size) | 250 | if (new_size != host_list_size) |
253 | { | 251 | { |
254 | host_list = GNUNET_realloc (host_list, sizeof (struct GNUNET_TESTBED_Host *) | 252 | host_list = |
255 | * new_size); | 253 | GNUNET_realloc (host_list, |
256 | (void) memset(&host_list[host_list_size], 0, | 254 | sizeof (struct GNUNET_TESTBED_Host *) * new_size); |
257 | sizeof (struct GNUNET_TESTBED_Host *) * | 255 | (void) memset (&host_list[host_list_size], 0, |
258 | (new_size - host_list_size)); | 256 | sizeof (struct GNUNET_TESTBED_Host *) * (new_size - |
257 | host_list_size)); | ||
259 | host_list_size = new_size; | 258 | host_list_size = new_size; |
260 | } | 259 | } |
261 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 260 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); |
262 | "Adding host with id: %u\n", host->id); | ||
263 | host_list[id] = host; | 261 | host_list[id] = host; |
264 | return host; | 262 | return host; |
265 | } | 263 | } |
@@ -267,24 +265,22 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, | |||
267 | 265 | ||
268 | /** | 266 | /** |
269 | * Create a host to run peers and controllers on. | 267 | * Create a host to run peers and controllers on. |
270 | * | 268 | * |
271 | * @param hostname name of the host, use "NULL" for localhost | 269 | * @param hostname name of the host, use "NULL" for localhost |
272 | * @param username username to use for the login; may be NULL | 270 | * @param username username to use for the login; may be NULL |
273 | * @param port port number to use for ssh; use 0 to let ssh decide | 271 | * @param port port number to use for ssh; use 0 to let ssh decide |
274 | * @return handle to the host, NULL on error | 272 | * @return handle to the host, NULL on error |
275 | */ | 273 | */ |
276 | struct GNUNET_TESTBED_Host * | 274 | struct GNUNET_TESTBED_Host * |
277 | GNUNET_TESTBED_host_create (const char *hostname, | 275 | GNUNET_TESTBED_host_create (const char *hostname, const char *username, |
278 | const char *username, | 276 | uint16_t port) |
279 | uint16_t port) | ||
280 | { | 277 | { |
281 | static uint32_t uid_generator; | 278 | static uint32_t uid_generator; |
282 | 279 | ||
283 | if (NULL == hostname) | 280 | if (NULL == hostname) |
284 | return GNUNET_TESTBED_host_create_with_id (0, hostname, username, port); | 281 | return GNUNET_TESTBED_host_create_with_id (0, hostname, username, port); |
285 | return GNUNET_TESTBED_host_create_with_id (++uid_generator, | 282 | return GNUNET_TESTBED_host_create_with_id (++uid_generator, hostname, |
286 | hostname, username, | 283 | username, port); |
287 | port); | ||
288 | } | 284 | } |
289 | 285 | ||
290 | 286 | ||
@@ -297,7 +293,7 @@ GNUNET_TESTBED_host_create (const char *hostname, | |||
297 | */ | 293 | */ |
298 | unsigned int | 294 | unsigned int |
299 | GNUNET_TESTBED_hosts_load_from_file (const char *filename, | 295 | GNUNET_TESTBED_hosts_load_from_file (const char *filename, |
300 | struct GNUNET_TESTBED_Host **hosts) | 296 | struct GNUNET_TESTBED_Host **hosts) |
301 | { | 297 | { |
302 | // see testing_group.c, GNUNET_TESTING_hosts_load | 298 | // see testing_group.c, GNUNET_TESTING_hosts_load |
303 | GNUNET_break (0); | 299 | GNUNET_break (0); |
@@ -313,7 +309,7 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename, | |||
313 | */ | 309 | */ |
314 | void | 310 | void |
315 | GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | 311 | GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) |
316 | { | 312 | { |
317 | struct RegisteredController *rc; | 313 | struct RegisteredController *rc; |
318 | uint32_t id; | 314 | uint32_t id; |
319 | 315 | ||
@@ -321,7 +317,7 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
321 | GNUNET_assert (host_list[host->id] == host); | 317 | GNUNET_assert (host_list[host->id] == host); |
322 | host_list[host->id] = NULL; | 318 | host_list[host->id] = NULL; |
323 | /* clear registered controllers list */ | 319 | /* clear registered controllers list */ |
324 | for (rc=host->rc_head; NULL != rc; rc=host->rc_head) | 320 | for (rc = host->rc_head; NULL != rc; rc = host->rc_head) |
325 | { | 321 | { |
326 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); | 322 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); |
327 | GNUNET_free (rc); | 323 | GNUNET_free (rc); |
@@ -331,18 +327,19 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
331 | GNUNET_free (host); | 327 | GNUNET_free (host); |
332 | while (host_list_size >= HOST_LIST_GROW_STEP) | 328 | while (host_list_size >= HOST_LIST_GROW_STEP) |
333 | { | 329 | { |
334 | for (id = host_list_size - 1; | 330 | for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; |
335 | id > host_list_size - HOST_LIST_GROW_STEP; id--) | 331 | id--) |
336 | if (NULL != host_list[id]) | 332 | if (NULL != host_list[id]) |
337 | break; | 333 | break; |
338 | if (id != host_list_size - HOST_LIST_GROW_STEP) | 334 | if (id != host_list_size - HOST_LIST_GROW_STEP) |
339 | break; | 335 | break; |
340 | if (NULL != host_list[id]) | 336 | if (NULL != host_list[id]) |
341 | break; | 337 | break; |
342 | host_list_size -= HOST_LIST_GROW_STEP; | 338 | host_list_size -= HOST_LIST_GROW_STEP; |
343 | } | 339 | } |
344 | host_list = GNUNET_realloc (host_list, sizeof (struct GNUNET_TESTBED_Host) * | 340 | host_list = |
345 | host_list_size); | 341 | GNUNET_realloc (host_list, |
342 | sizeof (struct GNUNET_TESTBED_Host) * host_list_size); | ||
346 | } | 343 | } |
347 | 344 | ||
348 | 345 | ||
@@ -354,14 +351,14 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
354 | */ | 351 | */ |
355 | void | 352 | void |
356 | GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, | 353 | GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, |
357 | const struct GNUNET_TESTBED_Controller | 354 | const struct GNUNET_TESTBED_Controller |
358 | * const controller) | 355 | *const controller) |
359 | { | 356 | { |
360 | struct RegisteredController *rc; | 357 | struct RegisteredController *rc; |
361 | 358 | ||
362 | for (rc=host->rc_head; NULL != rc; rc=rc->next) | 359 | for (rc = host->rc_head; NULL != rc; rc = rc->next) |
363 | { | 360 | { |
364 | if (controller == rc->controller) /* already registered at controller */ | 361 | if (controller == rc->controller) /* already registered at controller */ |
365 | { | 362 | { |
366 | GNUNET_break (0); | 363 | GNUNET_break (0); |
367 | return; | 364 | return; |
@@ -383,14 +380,14 @@ GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, | |||
383 | */ | 380 | */ |
384 | int | 381 | int |
385 | GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, | 382 | GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, |
386 | const struct GNUNET_TESTBED_Controller | 383 | const struct GNUNET_TESTBED_Controller |
387 | *const controller) | 384 | *const controller) |
388 | { | 385 | { |
389 | struct RegisteredController *rc; | 386 | struct RegisteredController *rc; |
390 | 387 | ||
391 | for (rc=host->rc_head; NULL != rc; rc=rc->next) | 388 | for (rc = host->rc_head; NULL != rc; rc = rc->next) |
392 | { | 389 | { |
393 | if (controller == rc->controller) /* already registered at controller */ | 390 | if (controller == rc->controller) /* already registered at controller */ |
394 | { | 391 | { |
395 | return GNUNET_YES; | 392 | return GNUNET_YES; |
396 | } | 393 | } |