gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26964 - in gnunet/src: include testbed


From: gnunet
Subject: [GNUnet-SVN] r26964 - in gnunet/src: include testbed
Date: Sun, 21 Apr 2013 22:01:34 +0200

Author: harsha
Date: 2013-04-21 22:01:34 +0200 (Sun, 21 Apr 2013)
New Revision: 26964

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_testbed_service.h
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/testbed.conf.in
   gnunet/src/testbed/testbed.h
   gnunet/src/testbed/testbed_api.c
Log:
fix #2666: Implement service sharing among peers



Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-04-21 17:57:26 UTC (rev 
26963)
+++ gnunet/src/include/gnunet_protocols.h       2013-04-21 20:01:34 UTC (rev 
26964)
@@ -1524,122 +1524,117 @@
 #define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS 462
 
 /**
- * Message to configure a service to be shared among peers
- */
-#define GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE 463
-
-/**
  * Message to link delegated controller to slave controller
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS 464
+#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS 463
 
 /**
  * Message to create a peer at a host
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER 465
+#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER 464
 
 /**
  * Message to reconfigure a peer
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER 466
+#define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER 465
 
 /**
  * Message to start a peer at a host
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_START_PEER 467
+#define GNUNET_MESSAGE_TYPE_TESTBED_START_PEER 466
 
 /**
  * Message to stop a peer at a host
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER 468
+#define GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER 467
 
 /**
  * Message to destroy a peer
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER 469
+#define GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER 468
 
 /**
  * Configure underlay link message
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK 470
+#define GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK 469
 
 /**
  * Message to connect peers in a overlay
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT 471
+#define GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT 470
 
 /**
  * Message for peer events
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT 472
+#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT 471
 
 /**
  * Message for peer connect events
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT 473
+#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT 472
 
 /**
  * Message for operation events
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT 474
+#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT 473
 
 /**
  * Message to signal successful peer creation
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS 475
+#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS 474
 
 /**
  * Message to signal a generic operation has been successful
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS 476
+#define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS 475
 
 /**
  * Message to get the configuration of a peer
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION 477
+#define GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION 476
 
 /**
  * Message containing the peer configuration
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION 478
+#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION 477
 
 /**
  * Message to request a controller to make one of its peer to connect to 
another
  * peer using the contained HELLO
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT 479
+#define GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT 478
 
 /**
  * Message to request configuration of a slave controller
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION 480
+#define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION 479
 
 /**
  * Message which contains the configuration of slave controller
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION 481
+#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION 480
 
 /**
  * Message to signal the result of 
GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS request
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 482
+#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 481
 
 /**
  * A controller receiving this message floods it to its directly-connected
  * sub-controllers and then stops and destroys all peers
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 483
+#define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 482
 
 /**
  * Message to start/stop a service of a peer
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE 484
+#define GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE 483
 
 /**
  * Not really a message, but for careful checks on the testbed messages; Should
  * always be the maximum and never be used to send messages with this type
  */
-#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 485
+#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 484
 
 /**
  * The initialization message towards gnunet-testbed-helper

Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2013-04-21 17:57:26 UTC (rev 
26963)
+++ gnunet/src/include/gnunet_testbed_service.h 2013-04-21 20:01:34 UTC (rev 
26964)
@@ -501,25 +501,6 @@
 
 
 /**
- * Configure shared services at a controller.  Using this function,
- * you can specify that certain services (such as "resolver")
- * should not be run for each peer but instead be shared
- * across N peers on the specified host.  This function
- * must be called before any peers are created at the host.
- *
- * @param controller controller to configure
- * @param service_name name of the service to share
- * @param num_peers number of peers that should share one instance
- *        of the specified service (1 for no sharing is the default),
- *        use 0 to disable the service
- */
-void
-GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller 
*controller,
-                                             const char *service_name,
-                                             uint32_t num_peers);
-
-
-/**
  * Stop the given controller (also will terminate all peers and
  * controllers dependent on this controller).  This function
  * blocks until the testbed has been fully terminated (!).

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2013-04-21 17:57:26 UTC (rev 
26963)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2013-04-21 20:01:34 UTC (rev 
26964)
@@ -127,10 +127,6 @@
  */
 static struct MessageQueue *mq_tail;
 
-/**
- * The hashmap of shared services
- */
-static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
 
 /**
  * The shutdown task handle
@@ -235,19 +231,6 @@
 
 
 /**
- * Routes message to a host given its host_id
- *
- * @param host_id the id of the destination host
- * @param msg the message to be routed
- */
-static void
-route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
-{
-  GNUNET_break (0);
-}
-
-
-/**
  * Send operation failure message to client
  *
  * @param client the client to which the failure message has to be sent to
@@ -440,6 +423,57 @@
 
 
 /**
+ * Parse service sharing specification line.
+ * Format is "[<service:share>] [<service:share>] ..."
+ *
+ * @param ss_str the spec string to be parsed
+ * @param cfg the configuration to use for shared services
+ * @return an array suitable to pass to GNUNET_TESTING_system_create().  NULL
+ *           upon empty service sharing specification.
+ */
+static struct GNUNET_TESTING_SharedService *
+parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_TESTING_SharedService ss;
+  struct GNUNET_TESTING_SharedService *slist;
+  char service[256];
+  char *arg;
+  unsigned int n;
+#define GROW_SS                                 \
+  do {                                          \
+    GNUNET_array_grow (slist, n, n+1);                                  \
+    (void) memcpy (&slist[n - 1], &ss,                                  \
+                   sizeof (struct GNUNET_TESTING_SharedService));       \
+  } while (0)
+  
+  slist = NULL;
+  n = 0;
+  ss.cfg = cfg;
+  for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL)
+  {
+    ss.service = NULL;
+    ss.share = 0;
+    if (2 != sscanf (arg, "%255s:%u", service, &ss.share))
+    {
+      LOG (GNUNET_ERROR_TYPE_WARNING, "Ignoring shared service spec: %s", arg);
+      continue;
+    }
+    LOG_DEBUG ("Will be sharing %s service among %u peers\n", service, 
ss.share);
+    ss.service = GNUNET_strdup (service);
+    GROW_SS;
+  }
+  if (NULL != slist)
+  {
+    /* Add trailing NULL block */
+    (void) memset (&ss, 0, sizeof (struct GNUNET_TESTING_SharedService));
+    GROW_SS;
+  }
+  return slist;
+#undef GROW_SS
+}
+
+
+/**
  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
  *
  * @param cls NULL
@@ -453,6 +487,9 @@
   const struct GNUNET_TESTBED_InitMessage *msg;
   struct GNUNET_TESTBED_Host *host;
   const char *controller_hostname;
+  char *ss_str;
+  struct GNUNET_TESTING_SharedService *ss;
+  unsigned int cnt;
   uint16_t msize;
 
   if (NULL != GST_context)
@@ -477,6 +514,16 @@
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+  ss_str = NULL;
+  ss = NULL;
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (our_config, 
"TESTBED",
+                                                          "SHARED_SERVICES",
+                                                          &ss_str))
+  {
+    ss = parse_shared_services (ss_str, our_config);
+    GNUNET_free (ss_str);
+    ss_str = NULL;
+  }
   GST_context = GNUNET_malloc (sizeof (struct Context));
   GNUNET_SERVER_client_keep (client);
   GST_context->client = client;
@@ -485,7 +532,17 @@
   LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip);
   GST_context->system =
       GNUNET_TESTING_system_create ("testbed", GST_context->master_ip,
-                                    hostname, NULL);
+                                    hostname, ss);
+  if (NULL != ss)
+  {
+    for (cnt = 0; NULL != ss[cnt].service; cnt++)
+    {
+      ss_str = (char *) ss[cnt].service;
+      GNUNET_free (ss_str);
+    }
+    GNUNET_free (ss);
+    ss = NULL;
+  }
   host =
       GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
                                           GST_context->master_ip, NULL,
@@ -614,93 +671,6 @@
 
 
 /**
- * Iterator over hash map entries.
- *
- * @param cls closure
- * @param key current key code
- * @param value value in the hash map
- * @return GNUNET_YES if we should continue to
- *         iterate,
- *         GNUNET_NO if not.
- */
-int
-ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
-{
-  struct SharedService *queried_ss = cls;
-  struct SharedService *ss = value;
-
-  if (0 == strcmp (ss->name, queried_ss->name))
-    return GNUNET_NO;
-  else
-    return GNUNET_YES;
-}
-
-
-/**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
- *
- * @param cls NULL
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client 
*client,
-                                 const struct GNUNET_MessageHeader *message)
-{
-  const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
-  struct SharedService *ss;
-  char *service_name;
-  struct GNUNET_HashCode hash;
-  uint16_t msg_size;
-  uint16_t service_name_size;
-
-  msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
-  msg_size = ntohs (message->size);
-  if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-  service_name_size =
-      msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
-  service_name = (char *) &msg[1];
-  if ('\0' != service_name[service_name_size - 1])
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-  LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
-             service_name, ntohl (msg->num_peers));
-  if (ntohl (msg->host_id) != GST_context->host_id)
-  {
-    route_message (ntohl (msg->host_id), message);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
-    return;
-  }
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-  ss = GNUNET_malloc (sizeof (struct SharedService));
-  ss->name = strdup (service_name);
-  ss->num_shared = ntohl (msg->num_peers);
-  GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
-  if (GNUNET_SYSERR ==
-      GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
-                                                  &ss_exists_iterator, ss))
-  {
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "Service %s already configured as a shared service. "
-         "Ignoring service sharing request \n", ss->name);
-    GNUNET_free (ss->name);
-    GNUNET_free (ss);
-    return;
-  }
-  GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
-                                     
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-}
-
-
-/**
  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
  *
  * @param cls NULL
@@ -802,29 +772,6 @@
 
 
 /**
- * Iterator over hash map entries.
- *
- * @param cls closure
- * @param key current key code
- * @param value value in the hash map
- * @return GNUNET_YES if we should continue to
- *         iterate,
- *         GNUNET_NO if not.
- */
-static int
-ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void 
*value)
-{
-  struct SharedService *ss = value;
-
-  GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
-  GNUNET_free (ss->name);
-  GNUNET_free (ss);
-  return GNUNET_YES;
-}
-
-
-/**
  * Task to clean up and shutdown nicely
  *
  * @param cls NULL
@@ -838,9 +785,6 @@
 
   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
-  (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
-                                                NULL);
-  GNUNET_CONTAINER_multihashmap_destroy (ss_map);
   /* cleanup any remaining forwarded operations */
   GST_clear_fopcq ();
   GST_free_lcfq ();
@@ -926,8 +870,6 @@
   static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
     {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
     {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0},
-    {&handle_configure_shared_service, NULL,
-     GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE, 0},
     {&GST_handle_link_controllers, NULL,
      GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
      sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)},
@@ -985,7 +927,6 @@
   our_config = GNUNET_CONFIGURATION_dup (cfg);
   GNUNET_SERVER_add_handlers (server, message_handlers);
   GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
-  ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
   shutdown_task_id =
       GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
                                                   
GNUNET_SCHEDULER_PRIORITY_IDLE,

Modified: gnunet/src/testbed/testbed.conf.in
===================================================================
--- gnunet/src/testbed/testbed.conf.in  2013-04-21 17:57:26 UTC (rev 26963)
+++ gnunet/src/testbed/testbed.conf.in  2013-04-21 20:01:34 UTC (rev 26964)
@@ -49,6 +49,23 @@
 # Where should testbed write load statistics data
 # STATS_DIR = /tmp/load
 
+# What services should be shared among peers.  
+# Format is "[<service:share>] [<service:share>] ...".  The shared services are
+# started standalone without any other peer services or a hostkey.  For this
+# reason, only services which doesn't depend on other services can only be
+# shared.  Example: To share peerinfo among every 10 peers.  The following spec
+# will start 5 peerinfo services when 50 peers are started:
+#
+#   SHARED_SERVICES = peerinfo:10
+#
+# To share multiple services
+#
+#   SHARED_SERVICES = service1:n_share1 service2:n_share2 ...
+#
+# Default is to share no services
+SHARED_SERVICES =
+
+
 [testbed-logger]
 AUTOSTART = NO
 @UNIXONLY@ PORT = 2102

Modified: gnunet/src/testbed/testbed.h
===================================================================
--- gnunet/src/testbed/testbed.h        2013-04-21 17:57:26 UTC (rev 26963)
+++ gnunet/src/testbed/testbed.h        2013-04-21 20:01:34 UTC (rev 26964)
@@ -134,34 +134,6 @@
 
 
 /**
- * Message to testing service: configure service sharing
- * at a host.
- */
-struct GNUNET_TESTBED_ConfigureSharedServiceMessage
-{
-
-  /**
-   * Type is GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE
-   */
-  struct GNUNET_MessageHeader header;
-
-  /**
-   * Host that is being configured.
-   */
-  uint32_t host_id GNUNET_PACKED;
-
-  /**
-   * Number of peers that should share a service instance;
-   * 1 for no sharing, 0 to forcefully disable the service.
-   */
-  uint32_t num_peers GNUNET_PACKED;
-
-  /* followed by 0-terminated name of the service */
-
-};
-
-
-/**
  * Client notifies controller that it should delegate
  * requests for a particular client to a particular
  * sub-controller.

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2013-04-21 17:57:26 UTC (rev 26963)
+++ gnunet/src/testbed/testbed_api.c    2013-04-21 20:01:34 UTC (rev 26964)
@@ -1508,46 +1508,6 @@
 
 
 /**
- * Configure shared services at a controller.  Using this function,
- * you can specify that certain services (such as "resolver")
- * should not be run for each peer but instead be shared
- * across N peers on the specified host.  This function
- * must be called before any peers are created at the host.
- *
- * @param controller controller to configure
- * @param service_name name of the service to share
- * @param num_peers number of peers that should share one instance
- *        of the specified service (1 for no sharing is the default),
- *        use 0 to disable the service
- */
-void
-GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller
-                                             *controller,
-                                             const char *service_name,
-                                             uint32_t num_peers)
-{
-  struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
-  uint16_t service_name_size;
-  uint16_t msg_size;
-
-  service_name_size = strlen (service_name) + 1;
-  msg_size =
-      sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage) +
-      service_name_size;
-  msg = GNUNET_malloc (msg_size);
-  msg->header.size = htons (msg_size);
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE);
-  msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (controller->host));
-  msg->num_peers = htonl (num_peers);
-  memcpy (&msg[1], service_name, service_name_size);
-  GNUNET_TESTBED_queue_message_ (controller,
-                                 (struct GNUNET_MessageHeader *) msg);
-  GNUNET_break (0);             /* This function is not yet implemented on the
-                                 * testbed service */
-}
-
-
-/**
  * Iterator to free opc map entries
  *
  * @param cls closure




reply via email to

[Prev in Thread] Current Thread [Next in Thread]