aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-05-17 09:23:41 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-05-17 09:23:41 +0000
commit6ebfc499830f2d447ef20514c66a1bb9e24f1dad (patch)
treeefab039fde14230dbab2032268774c4c8dd3ceb8 /src/testbed/gnunet-service-testbed.c
parentc47979fd1c48558a4981ca853348d8b8d4c4197d (diff)
downloadgnunet-6ebfc499830f2d447ef20514c66a1bb9e24f1dad.tar.gz
gnunet-6ebfc499830f2d447ef20514c66a1bb9e24f1dad.zip
- revert 27104
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r--src/testbed/gnunet-service-testbed.c87
1 files changed, 22 insertions, 65 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index f3d629f5f..1b74ad1df 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -474,48 +474,6 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
474 474
475 475
476/** 476/**
477 * Callback function invoked for each interface found.
478 *
479 * @param cls NULL
480 * @param name name of the interface (can be NULL for unknown)
481 * @param isDefault is this presumably the default interface
482 * @param addr address of this interface (can be NULL for unknown or unassigned)
483 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
484 * @param netmask the network mask (can be NULL for unknown or unassigned))
485 * @param addrlen length of the address
486 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
487 */
488static int
489addr_proc (void *cls, const char *name, int isDefault,
490 const struct sockaddr *addr,
491 const struct sockaddr *broadcast_addr,
492 const struct sockaddr *netmask, socklen_t addrlen)
493{
494 struct Context *ctx = cls;
495 const struct sockaddr_in *in_addr;
496 char *ipaddr;
497 char *tmp;
498
499 if (sizeof (struct sockaddr_in) != addrlen)
500 return GNUNET_OK;
501 in_addr = (const struct sockaddr_in *) addr;
502 if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr)))
503 return GNUNET_OK;
504 if (NULL == ctx->master_ips)
505 {
506 ctx->master_ips = GNUNET_strdup (ipaddr);
507 return GNUNET_OK;
508 }
509 tmp = NULL;
510 (void) GNUNET_asprintf (&tmp, "%s; %s", ctx->master_ips, ipaddr);
511 GNUNET_free (ctx->master_ips);
512 ctx->master_ips = tmp;
513 return GNUNET_OK;
514}
515
516
517
518/**
519 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages 477 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
520 * 478 *
521 * @param cls NULL 479 * @param cls NULL
@@ -528,11 +486,11 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
528{ 486{
529 const struct GNUNET_TESTBED_InitMessage *msg; 487 const struct GNUNET_TESTBED_InitMessage *msg;
530 struct GNUNET_TESTBED_Host *host; 488 struct GNUNET_TESTBED_Host *host;
489 const char *controller_hostname;
531 char *ss_str; 490 char *ss_str;
532 struct GNUNET_TESTING_SharedService *ss; 491 struct GNUNET_TESTING_SharedService *ss;
533 char *hostname;
534 unsigned int cnt; 492 unsigned int cnt;
535 unsigned int len; 493 uint16_t msize;
536 494
537 if (NULL != GST_context) 495 if (NULL != GST_context)
538 { 496 {
@@ -541,11 +499,18 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
541 return; 499 return;
542 } 500 }
543 msg = (const struct GNUNET_TESTBED_InitMessage *) message; 501 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
544 len = GNUNET_OS_get_hostname_max_length (); 502 msize = ntohs (message->size);
545 hostname = GNUNET_malloc (len); 503 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
546 if (0 != gethostname (hostname, len)) 504 {
505 GNUNET_break (0);
506 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
507 return;
508 }
509 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
510 controller_hostname = (const char *) &msg[1];
511 if ('\0' != controller_hostname[msize - 1])
547 { 512 {
548 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); 513 GNUNET_break (0);
549 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 514 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
550 return; 515 return;
551 } 516 }
@@ -563,18 +528,10 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
563 GNUNET_SERVER_client_keep (client); 528 GNUNET_SERVER_client_keep (client);
564 GST_context->client = client; 529 GST_context->client = client;
565 GST_context->host_id = ntohl (msg->host_id); 530 GST_context->host_id = ntohl (msg->host_id);
566 GNUNET_OS_network_interfaces_list (&addr_proc, GST_context); 531 GST_context->master_ip = GNUNET_strdup (controller_hostname);
567 if (NULL == GST_context->master_ips) 532 LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
568 {
569 LOG (GNUNET_ERROR_TYPE_ERROR,
570 "Testbed needs networking, but no network interfaces are found on this host. Exiting\n");
571 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
572 GNUNET_SCHEDULER_shutdown ();
573 return;
574 }
575 LOG_DEBUG ("Our IP addresses: %s\n", GST_context->master_ips);
576 GST_context->system = 533 GST_context->system =
577 GNUNET_TESTING_system_create ("testbed", GST_context->master_ips, 534 GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
578 hostname, ss); 535 hostname, ss);
579 if (NULL != ss) 536 if (NULL != ss)
580 { 537 {
@@ -586,9 +543,10 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
586 GNUNET_free (ss); 543 GNUNET_free (ss);
587 ss = NULL; 544 ss = NULL;
588 } 545 }
589 546 host =
590 host = GNUNET_TESTBED_host_create_with_id (GST_context->host_id, hostname, 547 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
591 NULL, our_config, 0); 548 GST_context->master_ip, NULL,
549 our_config, 0);
592 host_list_add (host); 550 host_list_add (host);
593 LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); 551 LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
594 GNUNET_SERVER_receive_done (client, GNUNET_OK); 552 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -850,7 +808,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
850 GNUNET_free_non_null (GST_host_list); 808 GNUNET_free_non_null (GST_host_list);
851 if (NULL != GST_context) 809 if (NULL != GST_context)
852 { 810 {
853 GNUNET_free_non_null (GST_context->master_ips); 811 GNUNET_free_non_null (GST_context->master_ip);
854 if (NULL != GST_context->system) 812 if (NULL != GST_context->system)
855 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); 813 GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
856 GNUNET_SERVER_client_drop (GST_context->client); 814 GNUNET_SERVER_client_drop (GST_context->client);
@@ -912,8 +870,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
912 const struct GNUNET_CONFIGURATION_Handle *cfg) 870 const struct GNUNET_CONFIGURATION_Handle *cfg)
913{ 871{
914 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { 872 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
915 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 873 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
916 sizeof (struct GNUNET_TESTBED_InitMessage)},
917 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, 874 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
918 {&GST_handle_link_controllers, NULL, 875 {&GST_handle_link_controllers, NULL,
919 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 876 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,