gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11305 - gnunet/src/arm


From: gnunet
Subject: [GNUnet-SVN] r11305 - gnunet/src/arm
Date: Tue, 11 May 2010 14:44:50 +0200

Author: grothoff
Date: 2010-05-11 14:44:50 +0200 (Tue, 11 May 2010)
New Revision: 11305

Modified:
   gnunet/src/arm/arm_api.c
   gnunet/src/arm/gnunet-service-manager.c
   gnunet/src/arm/test_arm_api_data.conf
   gnunet/src/arm/test_gnunet_service_manager.c
Log:
fixes

Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c    2010-05-11 12:44:35 UTC (rev 11304)
+++ gnunet/src/arm/arm_api.c    2010-05-11 12:44:50 UTC (rev 11305)
@@ -81,16 +81,10 @@
                    const char *service)
 {
   struct GNUNET_ARM_Handle *ret;
-  struct GNUNET_CLIENT_Connection *client;
 
-  client = GNUNET_CLIENT_connect (sched, "arm", cfg);
-  if (client == NULL)
-    return NULL;
-  GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
   ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
   ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
   ret->sched = sched;
-  ret->client = client;
   return ret;
 }
 
@@ -412,6 +406,7 @@
                           GNUNET_ARM_Callback cb, void *cb_cls)
 {
   struct RequestContext *sctx;
+  struct GNUNET_CLIENT_Connection *client;
   size_t slen;
 #if DEBUG_ARM
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -432,6 +427,17 @@
                                   h->cfg, timeout, &arm_service_report, sctx);
       return;
     }
+  if (h->client == NULL)
+    {
+      client = GNUNET_CLIENT_connect (h->sched, "arm", h->cfg);
+      if (client == NULL)
+       {
+         cb (cb_cls, GNUNET_SYSERR);
+         return;
+       }
+      GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
+      h->client = client;
+    }
   change_service (h, service_name, timeout, cb, cb_cls, 
GNUNET_MESSAGE_TYPE_ARM_START);
 }
 
@@ -471,12 +477,24 @@
                          GNUNET_ARM_Callback cb, void *cb_cls)
 {
   struct ARM_ShutdownContext *arm_shutdown_ctx;
+  struct GNUNET_CLIENT_Connection *client;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Stopping service `%s' within %llu ms\n"), service_name,
              (unsigned long long) timeout.value);
   if (0 == strcasecmp ("arm", service_name))
     {
+      if (h->client == NULL)
+       {
+         client = GNUNET_CLIENT_connect (h->sched, "arm", h->cfg);
+         if (client == NULL)
+           {
+             cb (cb_cls, GNUNET_SYSERR);
+             return;
+           }
+         GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
+         h->client = client;
+       }
       arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext));
       arm_shutdown_ctx->cb = cb;
       arm_shutdown_ctx->cb_cls = cb_cls;

Modified: gnunet/src/arm/gnunet-service-manager.c
===================================================================
--- gnunet/src/arm/gnunet-service-manager.c     2010-05-11 12:44:35 UTC (rev 
11304)
+++ gnunet/src/arm/gnunet-service-manager.c     2010-05-11 12:44:50 UTC (rev 
11305)
@@ -192,11 +192,15 @@
   if ( (fc->clientReceivingTask != GNUNET_SCHEDULER_NO_TASK) ||
        (fc->serviceReceivingTask != GNUNET_SCHEDULER_NO_TASK) )
     return;
-  if (GNUNET_SYSERR ==
-      GNUNET_NETWORK_socket_close (fc->armClientSocket))
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Closing forwarding connection (done with both directions)\n");
+  if ( (NULL != fc->armClientSocket) &&
+       (GNUNET_SYSERR ==
+       GNUNET_NETWORK_socket_close (fc->armClientSocket)) )
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close");
-  if (GNUNET_SYSERR ==
-      GNUNET_NETWORK_socket_close (fc->armServiceSocket))
+  if ( (NULL != fc->armServiceSocket) &&
+       (GNUNET_SYSERR ==
+       GNUNET_NETWORK_socket_close (fc->armServiceSocket)) )
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close");
   GNUNET_free (fc->listen_info->serviceName);             
   GNUNET_free (fc->listen_info->service_addr);
@@ -240,6 +244,9 @@
     GNUNET_NETWORK_socket_send (fc->armClientSocket,
                                fc->serviceBufferPos,
                                fc->serviceBufferDataLength);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Forwarded %d bytes to client\n",
+             numberOfBytesSent);
   if ((numberOfBytesSent == GNUNET_SYSERR) || (numberOfBytesSent == 0))
     {
       /* Error occured or connection closed by client */
@@ -300,6 +307,9 @@
     GNUNET_NETWORK_socket_recv (fc->armServiceSocket,
                                fc->serviceBuffer, BUFFER_SIZE);
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Received %d bytes for client\n",
+             fc->serviceBufferDataLength);
   if (fc->serviceBufferDataLength <= 0)
     {
       /* The service has closed the connection or an error occured */
@@ -314,7 +324,6 @@
          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                      _("Error receiving from service: %s\n"), 
                      STRERROR (errno));
-         abort ();
        }
       closeClientAndServiceSockets (fc, REASON_SERVICE);
       return;
@@ -357,6 +366,9 @@
     GNUNET_NETWORK_socket_send (fc->armServiceSocket,
                                fc->clientBufferPos,
                                fc->clientBufferDataLength);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Forwarded %d bytes to service\n",
+             numberOfBytesSent);
   if ((numberOfBytesSent == GNUNET_SYSERR) || (numberOfBytesSent == 0))
     {
       /* Error occured or connection closed by service */
@@ -419,7 +431,9 @@
   fc->clientBufferDataLength =
     GNUNET_NETWORK_socket_recv (fc->armClientSocket,
                                fc->clientBuffer, BUFFER_SIZE);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Received %d bytes for service\n",
+             fc->clientBufferDataLength);
   if (fc->clientBufferDataLength <= 0)
     {
       /* The client has closed the connection or and error occured */
@@ -443,15 +457,9 @@
 }
 
 
-/**
- * ARM connects to the just created service, 
- * starts the processes for relaying messages between the client and the 
service
- * 
- * @param cls callback data, struct ForwardedConnection for the communication 
between client and service
- * @param tc context
- */
 static void
-connectToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_forwarding (void *cls,
+                 const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct ForwardedConnection *fc = cls;
 
@@ -465,18 +473,8 @@
                                    (REASON_CLIENT & REASON_SERVICE));
       return;
     }
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                 _("Unable to start service `%s': shutdown\n"),
-                 fc->listen_info->serviceName);
-      closeClientAndServiceSockets (fc,
-                                   (REASON_CLIENT & REASON_SERVICE));
-      return;
-    }
-  GNUNET_break (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' started\n"),
-             fc->listen_info->serviceName);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             _("Connection to service to start forwarding\n"));
   fc->armServiceSocket =
     GNUNET_NETWORK_socket_create (fc->listen_info->service_addr->sa_family,
                                  SOCK_STREAM, 0);
@@ -516,6 +514,50 @@
 }
 
 
+/**
+ * ARM connects to the just created service, 
+ * starts the processes for relaying messages between the client and the 
service
+ * 
+ * @param cls callback data, struct ForwardedConnection for the communication 
between client and service
+ * @param tc context
+ */
+static void
+connectToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct ForwardedConnection *fc = cls;
+
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
+    {
+      /* Service is not up. Unable to proceed */
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Unable to start service `%s': timeout\n"),
+                 fc->listen_info->serviceName);
+      closeClientAndServiceSockets (fc,
+                                   (REASON_CLIENT & REASON_SERVICE));
+      return;
+    }
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Unable to start service `%s': shutdown\n"),
+                 fc->listen_info->serviceName);
+      closeClientAndServiceSockets (fc,
+                                   (REASON_CLIENT & REASON_SERVICE));
+      return;
+    }
+  GNUNET_break (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' started\n"),
+             fc->listen_info->serviceName);
+
+  GNUNET_CLIENT_service_test (scheduler,
+                             fc->listen_info->serviceName,
+                             cfg,
+                             TIMEOUT,
+                             &start_forwarding,
+                             fc);
+}
+
+
 void stop_listening (const char *serviceName)
 {
   struct ServiceListeningInfo *pos;
@@ -610,34 +652,39 @@
                       socklen_t addr_len,
                       const char *serviceName)
 {
-  struct GNUNET_NETWORK_Handle *socket;
+  const static int on = 1;
+  struct GNUNET_NETWORK_Handle *sock;
   struct ServiceListeningInfo *serviceListeningInfo;
 
   switch (sa->sa_family)
     {
     case AF_INET:
-      socket = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
+      sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
       fprintf (stderr, "IPv4 listening at %p\n", 
-              socket);
+              sock);
       break;
     case AF_INET6:
-      socket = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
+      sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
       fprintf (stderr, "IPv6 listening at %p\n", 
-              socket);
+              sock);
       break;
     default:
-      socket = NULL;
+      sock = NULL;
       break;
     }
-  if (NULL == socket)
+  if (NULL == sock)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  "Unable to create socket for service %s", serviceName);
       GNUNET_free (sa);
       return;
     }
+  if (GNUNET_NETWORK_socket_setsockopt
+      (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+                         "setsockopt");
   if (GNUNET_NETWORK_socket_bind
-      (socket, (const struct sockaddr *) sa, addr_len) != GNUNET_OK)
+      (sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Unable to bind listening socket for service `%s'\n"),
@@ -645,12 +692,12 @@
       GNUNET_free (sa);
       return;
     }
-  if (GNUNET_NETWORK_socket_listen (socket, 5) != GNUNET_OK)
+  if (GNUNET_NETWORK_socket_listen (sock, 5) != GNUNET_OK)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  _("Error listening socket for service `%s'\n"),
                  serviceName);
-      GNUNET_NETWORK_socket_close (socket);
+      GNUNET_NETWORK_socket_close (sock);
       GNUNET_free (sa);
       return;
     }
@@ -658,10 +705,10 @@
   serviceListeningInfo->serviceName = GNUNET_strdup (serviceName);
   serviceListeningInfo->service_addr = sa;
   serviceListeningInfo->service_addr_len = addr_len;
-  serviceListeningInfo->listeningSocket = socket;
+  serviceListeningInfo->listeningSocket = sock;
   serviceListeningInfo->acceptTask =
     GNUNET_SCHEDULER_add_read_net (scheduler,
-                                  GNUNET_TIME_UNIT_FOREVER_REL, socket,
+                                  GNUNET_TIME_UNIT_FOREVER_REL, sock,
                                   &acceptConnection,
                                   serviceListeningInfo);
   GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
@@ -690,8 +737,8 @@
   int ret;
   unsigned int i;
   
-  if ( (strcmp (section, "arm") == 0) ||
-       (strcmp (option, "PORT") != 0) ||
+  if ( (strcasecmp (section, "arm") == 0) ||
+       (strcasecmp (option, "PORT") != 0) ||
        (isInDefaultList (section) == GNUNET_YES) )
     return;
   if (0 >= (ret = GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs,

Modified: gnunet/src/arm/test_arm_api_data.conf
===================================================================
--- gnunet/src/arm/test_arm_api_data.conf       2010-05-11 12:44:35 UTC (rev 
11304)
+++ gnunet/src/arm/test_arm_api_data.conf       2010-05-11 12:44:50 UTC (rev 
11305)
@@ -6,7 +6,7 @@
 PORT = 23354
 DEFAULTSERVICES =
 BINARY = gnunet-service-arm
-OPTIONS = -L ERROR
+OPTIONS = -L DEBUG
 #DEBUG = YES
 
 [resolver]

Modified: gnunet/src/arm/test_gnunet_service_manager.c
===================================================================
--- gnunet/src/arm/test_gnunet_service_manager.c        2010-05-11 12:44:35 UTC 
(rev 11304)
+++ gnunet/src/arm/test_gnunet_service_manager.c        2010-05-11 12:44:50 UTC 
(rev 11305)
@@ -38,19 +38,28 @@
 
 #define START_ARM GNUNET_YES
 
+#define VERBOSE GNUNET_YES
+
 static int ret = 1;
 
 static struct GNUNET_SCHEDULER_Handle *sched;
 
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
+#if START_ARM
 static struct GNUNET_ARM_Handle *arm;
+#endif
 
 static void
 arm_stopped (void *cls, int success)
 {
-  if (success != GNUNET_OK)        
-    ret = 4;
+  if (success != GNUNET_NO)       
+    {
+      GNUNET_break (0);
+      ret = 4;
+    }
+  GNUNET_ARM_disconnect (arm);
+  arm = NULL;
 }
 
 static void 
@@ -62,8 +71,8 @@
     return;
   if (NULL == addr)
     {
-      GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 
-                "Name not resolved!\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                 "Name not resolved!\n");
 #if START_ARM
       GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
 #endif
@@ -77,7 +86,6 @@
 }
 
 
-
 static void
 arm_notify (void *cls, int success)
 {
@@ -113,8 +121,8 @@
 {
   cfg = c;
   sched = s;   
+#if START_ARM
   arm = GNUNET_ARM_connect (cfg, sched, NULL);
-#if START_ARM
   GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL);
 #else
   arm_notify (NULL, GNUNET_YES);




reply via email to

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