{
ss.service = NULL;
ss.share = 0;
- if (2 != sscanf (arg, "%255s:%u", service, &ss.share))
+ if (2 != sscanf (arg, "%255[^:]:%u", service, &ss.share))
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Ignoring shared service spec: %s", arg);
continue;
}
+/**
+ * Callback function invoked for each interface found.
+ *
+ * @param cls NULL
+ * @param name name of the interface (can be NULL for unknown)
+ * @param isDefault is this presumably the default interface
+ * @param addr address of this interface (can be NULL for unknown or unassigned)
+ * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
+ * @param netmask the network mask (can be NULL for unknown or unassigned))
+ * @param addrlen length of the address
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
+ */
+static int
+addr_proc (void *cls, const char *name, int isDefault,
+ const struct sockaddr *addr,
+ const struct sockaddr *broadcast_addr,
+ const struct sockaddr *netmask, socklen_t addrlen)
+{
+ struct Context *ctx = cls;
+ const struct sockaddr_in *in_addr;
+ char *ipaddr;
+ char *tmp;
+
+ if (sizeof (struct sockaddr_in) != addrlen)
+ return GNUNET_OK;
+ in_addr = (const struct sockaddr_in *) addr;
+ if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr)))
+ return GNUNET_OK;
+ if (NULL == ctx->master_ips)
+ {
+ ctx->master_ips = GNUNET_strdup (ipaddr);
+ return GNUNET_OK;
+ }
+ tmp = NULL;
+ (void) GNUNET_asprintf (&tmp, "%s; %s", ctx->master_ips, ipaddr);
+ GNUNET_free (ctx->master_ips);
+ ctx->master_ips = tmp;
+ return GNUNET_OK;
+}
+
+
+
/**
* Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
*
{
const struct GNUNET_TESTBED_InitMessage *msg;
struct GNUNET_TESTBED_Host *host;
- const char *controller_hostname;
char *ss_str;
struct GNUNET_TESTING_SharedService *ss;
+ char *hostname;
unsigned int cnt;
- uint16_t msize;
+ unsigned int len;
if (NULL != GST_context)
{
return;
}
msg = (const struct GNUNET_TESTBED_InitMessage *) message;
- msize = ntohs (message->size);
- if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
- controller_hostname = (const char *) &msg[1];
- if ('\0' != controller_hostname[msize - 1])
+ len = GNUNET_OS_get_hostname_max_length ();
+ hostname = GNUNET_malloc (len);
+ if (0 != gethostname (hostname, len))
{
- GNUNET_break (0);
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname");
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
GNUNET_SERVER_client_keep (client);
GST_context->client = client;
GST_context->host_id = ntohl (msg->host_id);
- GST_context->master_ip = GNUNET_strdup (controller_hostname);
- LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
+ GNUNET_OS_network_interfaces_list (&addr_proc, GST_context);
+ if (NULL == GST_context->master_ips)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Testbed needs networking, but no network interfaces are found on this host. Exiting\n");
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ LOG_DEBUG ("Our IP addresses: %s\n", GST_context->master_ips);
GST_context->system =
- GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
+ GNUNET_TESTING_system_create ("testbed", GST_context->master_ips,
hostname, ss);
if (NULL != ss)
{
GNUNET_free (ss);
ss = NULL;
}
- host =
- GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
- GST_context->master_ip, NULL,
- our_config, 0);
+
+ host = GNUNET_TESTBED_host_create_with_id (GST_context->host_id, hostname,
+ NULL, our_config, 0);
host_list_add (host);
LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
case OP_LINK_CONTROLLERS:
case OP_GET_SLAVE_CONFIG:
case OP_MANAGE_SERVICE:
+ case OP_PEER_RECONFIGURE:
break;
case OP_FORWARDED:
GNUNET_assert (0);
uint32_t id;
shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
+ LOG_DEBUG ("Shutting down testbed service\n");
/* cleanup any remaining forwarded operations */
GST_clear_fopcq ();
GST_free_lcfq ();
GST_free_roccq ();
GST_free_nccq ();
GST_neighbour_list_clean();
+ GST_free_prcq ();
/* Clear peer list */
GST_destroy_peers ();
/* Clear route list */
GNUNET_free_non_null (GST_host_list);
if (NULL != GST_context)
{
- GNUNET_free_non_null (GST_context->master_ip);
+ GNUNET_free_non_null (GST_context->master_ips);
if (NULL != GST_context->system)
GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES);
GNUNET_SERVER_client_drop (GST_context->client);
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
- {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
+ {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT,
+ sizeof (struct GNUNET_TESTBED_InitMessage)},
{&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
{&GST_handle_link_controllers, NULL,
GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
{&GST_handle_shutdown_peers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS,
sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)},
+ {&GST_handle_peer_reconfigure, NULL,
+ GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0},
{NULL, NULL, 0, 0}
};
char *logfile;
unsigned long long num;
+ LOG_DEBUG ("Starting testbed\n");
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
&logfile))