gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34379 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r34379 - gnunet/src/transport
Date: Thu, 23 Oct 2014 12:59:15 +0200

Author: grothoff
Date: 2014-10-23 12:59:15 +0200 (Thu, 23 Oct 2014)
New Revision: 34379

Modified:
   gnunet/src/transport/gnunet-service-transport_clients.c
   gnunet/src/transport/gnunet-service-transport_plugins.c
   gnunet/src/transport/gnunet-service-transport_plugins.h
   gnunet/src/transport/transport.h
Log:
implementing monitoring functionality in transport service

Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c     2014-10-23 
10:22:47 UTC (rev 34378)
+++ gnunet/src/transport/gnunet-service-transport_clients.c     2014-10-23 
10:59:15 UTC (rev 34379)
@@ -220,6 +220,12 @@
 static struct GNUNET_SERVER_NotificationContext *val_nc;
 
 /**
+ * Notification context, to send updates on changes to active plugin
+ * connections.
+ */
+static struct GNUNET_SERVER_NotificationContext *plugin_nc;
+
+/**
  * Find the internal handle associated with the given client handle
  *
  * @param client server's client handle to look up
@@ -1279,8 +1285,9 @@
  * @param message the peer address information request
  */
 static void
-clients_handle_monitor_validation (void *cls, struct GNUNET_SERVER_Client 
*client,
-                                const struct GNUNET_MessageHeader *message)
+clients_handle_monitor_validation (void *cls,
+                                  struct GNUNET_SERVER_Client *client,
+                                  const struct GNUNET_MessageHeader *message)
 {
   static struct GNUNET_PeerIdentity all_zeros;
   struct GNUNET_SERVER_TransmitContext *tc;
@@ -1341,7 +1348,87 @@
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
+
 /**
+ * Function called by the plugin with information about the
+ * current sessions managed by the plugin (for monitoring).
+ *
+ * @param cls closure
+ * @param session session handle this information is about,
+ *        NULL to indicate that we are "in sync" (initial
+ *        iteration complete)
+ * @param info information about the state of the session,
+ *        NULL if @a session is also NULL and we are
+ *        merely signalling that the initial iteration is over
+ */
+static void
+plugin_session_info_cb (void *cls,
+                       struct Session *session,
+                       const struct GNUNET_TRANSPORT_SessionInfo *info)
+{
+  struct TransportPluginMonitorMessage *msg;
+  size_t size;
+  size_t slen;
+  uint16_t alen;
+  char *name;
+  char *addr;
+
+  if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc))
+  {
+    GST_plugins_monitor_subscribe (NULL, NULL);
+    return;
+  }
+  slen = strlen (info->address->transport_name) + 1;
+  alen = info->address->address_length;
+  size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
+  if (size > UINT16_MAX)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  msg = GNUNET_malloc (size);
+  msg->header.size = htons (size);
+  msg->header.type = htons 
(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
+  msg->session_state = htons ((uint16_t) info->state);
+  msg->is_inbound = htons ((int16_t) info->is_inbound);
+  msg->msgs_pending = htonl (info->num_msg_pending);
+  msg->bytes_pending = htonl (info->num_bytes_pending);
+  msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
+  msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
+  msg->peer = info->address->peer;
+  msg->plugin_name_len = htons (slen);
+  msg->plugin_address_len = htons (alen);
+  name = (char *) &msg[1];
+  memcpy (name, info->address->transport_name, slen);
+  addr = &name[slen + 1];
+  memcpy (addr, info->address->address, alen);
+  GNUNET_SERVER_notification_context_broadcast (plugin_nc,
+                                               &msg->header,
+                                               GNUNET_NO);
+  GNUNET_free (msg);
+}
+
+
+/**
+ * Client asked to obtain information about all plugin connections.
+ *
+ * @param cls unused
+ * @param client the client
+ * @param message the peer address information request
+ */
+static void
+clients_handle_monitor_plugins (void *cls,
+                               struct GNUNET_SERVER_Client *client,
+                               const struct GNUNET_MessageHeader *message)
+{
+  GNUNET_SERVER_disable_receive_done_warning (client);
+  if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc))
+    GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL);
+  GNUNET_SERVER_notification_context_add (plugin_nc, client);
+}
+
+
+/**
  * Start handling requests from clients.
  *
  * @param server server used to accept clients from.
@@ -1375,10 +1462,14 @@
      sizeof (struct BlacklistMessage)},
     {&GST_manipulation_set_metric, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0},
+    {&clients_handle_monitor_plugins, NULL,
+     GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT,
+     sizeof (struct GNUNET_MessageHeader) },
     {NULL, NULL, 0, 0}
   };
   peer_nc = GNUNET_SERVER_notification_context_create (server, 0);
   val_nc = GNUNET_SERVER_notification_context_create (server, 0);
+  plugin_nc = GNUNET_SERVER_notification_context_create (server, 0);
   GNUNET_SERVER_add_handlers (server, handlers);
   GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
                                    NULL);
@@ -1409,6 +1500,11 @@
     GNUNET_SERVER_notification_context_destroy (val_nc);
     val_nc = NULL;
   }
+  if (NULL != plugin_nc)
+  {
+    GNUNET_SERVER_notification_context_destroy (plugin_nc);
+    plugin_nc = NULL;
+  }
 }
 
 

Modified: gnunet/src/transport/gnunet-service-transport_plugins.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.c     2014-10-23 
10:22:47 UTC (rev 34378)
+++ gnunet/src/transport/gnunet-service-transport_plugins.c     2014-10-23 
10:59:15 UTC (rev 34379)
@@ -1,21 +1,21 @@
 /*
-     This file is part of GNUnet.
-     (C) 2010,2011 Christian Grothoff (and other contributing authors)
+  This file is part of GNUnet.
+  (C) 2010-2014 Christian Grothoff (and other contributing authors)
+  
+  GNUnet is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 3, or (at your
+  option) any later version.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+  GNUnet is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
 
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+  You should have received a copy of the GNU General Public License
+  along with GNUnet; see the file COPYING.  If not, write to the
+  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+  Boston, MA 02111-1307, USA.
 */
 
 /**
@@ -302,13 +302,14 @@
 struct GNUNET_TRANSPORT_PluginFunctions *
 GST_plugins_find (const char *name)
 {
-  struct TransportPlugin *head = plugins_head;
+  struct TransportPlugin *pos;
 
-  while ((head != NULL) && (0 != strcmp (name, head->short_name)))
-    head = head->next;
-  if (NULL == head)
+  for (pos = plugins_head; NULL != pos; pos = pos->next)
+    if (0 == strcmp (name, pos->short_name))
+      break;
+  if (NULL == pos)
     return NULL;
-  return head->api;
+  return pos->api;
 }
 
 
@@ -325,23 +326,19 @@
 struct GNUNET_TRANSPORT_PluginFunctions *
 GST_plugins_printer_find (const char *name)
 {
-  struct TransportPlugin *head = plugins_head;
-
+  struct TransportPlugin *pos;
   char *stripped = GNUNET_strdup (name);
   char *sep = strchr (stripped, '_');
+
   if (NULL != sep)
     sep[0] = '\0';
-
-  while (head != NULL)
-  {
-    if (head->short_name == strstr (head->short_name, stripped))
+  for (pos = plugins_head; NULL != pos; pos = pos->next)
+    if (pos->short_name == strstr (pos->short_name, stripped))
         break;
-    head = head->next;
-  }
   GNUNET_free (stripped);
-  if (NULL == head)
+  if (NULL == pos)
     return NULL;
-  return head->api;
+  return pos->api;
 }
 
 
@@ -359,9 +356,9 @@
   static char unable_to_show[1024];
   static const char *s;
 
-  if (address == NULL)
+  if (NULL == address)
   {
-       GNUNET_break (0); /* a HELLO address cannot be NULL */
+    GNUNET_break (0); /* a HELLO address cannot be NULL */
     return "<invalid>";
   }
   if (0 == address->address_length)
@@ -382,4 +379,25 @@
 }
 
 
+/**
+ * Register callback with all plugins to monitor their status.
+ *
+ * @param cb callback to register, NULL to unsubscribe
+ * @param cb_cls closure for @a cb
+ */
+void
+GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb,
+                              void *cb_cls)
+{
+  struct TransportPlugin *pos;
+
+  for (pos = plugins_head; NULL != pos; pos = pos->next)
+    if (NULL == pos->api->setup_monitor)
+      GNUNET_break (0);
+    else
+      pos->api->setup_monitor (pos->api->cls,
+                              cb, cb_cls);
+}
+
+
 /* end of file gnunet-service-transport_plugins.c */

Modified: gnunet/src/transport/gnunet-service-transport_plugins.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.h     2014-10-23 
10:22:47 UTC (rev 34378)
+++ gnunet/src/transport/gnunet-service-transport_plugins.h     2014-10-23 
10:59:15 UTC (rev 34379)
@@ -100,5 +100,16 @@
 GST_plugins_a2s (const struct GNUNET_HELLO_Address *address);
 
 
+/**
+ * Register callback with all plugins to monitor their status.
+ *
+ * @param cb callback to register, NULL to unsubscribe
+ * @param cb_cls closure for @a cb
+ */
+void
+GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb,
+                              void *cb_cls);
+
+
 #endif
 /* end of file gnunet-service-transport_plugins.h */

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2014-10-23 10:22:47 UTC (rev 34378)
+++ gnunet/src/transport/transport.h    2014-10-23 10:59:15 UTC (rev 34379)
@@ -606,9 +606,19 @@
   /**
    * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
    */
-  int32_t session_state GNUNET_PACKED;
+  uint16_t session_state GNUNET_PACKED;
 
   /**
+   * #GNUNET_YES if this is an inbound connection,
+   * #GNUNET_NO if this is an outbound connection,
+   * #GNUNET_SYSERR if connections of this plugin
+   *             are so fundamentally bidirectional
+   *             that they have no 'initiator'
+   * Value given in NBO.
+   */
+  int16_t is_inbound GNUNET_PACKED;
+
+  /**
    * Number of messages waiting transmission.
    */
   uint32_t msgs_pending GNUNET_PACKED;
@@ -624,9 +634,9 @@
   struct GNUNET_TIME_AbsoluteNBO timeout;
 
   /**
-   * What is the expected latency?
+   * Until how long is this plugin currently blocked from reading?
    */
-  struct GNUNET_TIME_RelativeNBO delay;
+  struct GNUNET_TIME_AbsoluteNBO delay;
 
   /**
    * Which peer is this connection for?
@@ -634,7 +644,7 @@
   struct GNUNET_PeerIdentity peer;
 
   /**
-   * Length of the plugin name in bytes, excluding 0-termination.
+   * Length of the plugin name in bytes, including 0-termination.
    */
   uint16_t plugin_name_len GNUNET_PACKED;
 




reply via email to

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