simplifying transport plugin API
authorChristian Grothoff <christian@grothoff.org>
Fri, 15 Jan 2010 09:38:53 +0000 (09:38 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 15 Jan 2010 09:38:53 +0000 (09:38 +0000)
src/arm/arm.h
src/hostlist/test_gnunet_daemon_hostlist.c
src/topology/gnunet-daemon-topology.c
src/transport/gnunet-service-transport.c
src/transport/plugin_transport.h
src/transport/plugin_transport_tcp.c
src/transport/plugin_transport_template.c

index 562113068c3bd664803cc2b6e4622861d5ca1f72..2f107351cf5c22ab17db3ca5b0e6210bba9355ec 100644 (file)
@@ -31,6 +31,6 @@
  * This option will turn on the DEBUG loglevel for
  * all processes controlled by this ARM!
  */
-#define DEBUG_ARM GNUNET_NO
+#define DEBUG_ARM GNUNET_YES
 
 #endif
index a98aa52fe7708fd5cdd4e38d2dea812eb39e31ca..0d5ab561de4f68e979d1a16a6c52d828c8fad711 100644 (file)
@@ -35,7 +35,7 @@
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150)
 
 static int ok;
 
index ad306e03c90952aeab157e61b61af036e734cfae..40582029d869fb12fffe67913987e7c359464231 100644 (file)
@@ -33,7 +33,7 @@
 #include "gnunet_util_lib.h"
 
 
-#define DEBUG_TOPOLOGY GNUNET_YES
+#define DEBUG_TOPOLOGY GNUNET_NO
 
 /**
  * For how long do we blacklist a peer after a failed
@@ -388,7 +388,7 @@ static void connect_notify (void *cls,
 
 #if DEBUG_TOPOLOGY
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Core told us that we connected to `%s'\n",
+             "Core told us that we are connecting to `%s'\n",
              GNUNET_i2s (peer));
 #endif       
   connection_count++;
index 67ad5bfc271d63f02ca44be69228676479035e93..292f38039129306095367cf6ae6d1c0a80da96b9 100644 (file)
@@ -250,12 +250,6 @@ struct ReadyList
    */
   struct NeighbourList *neighbour;
 
-  /**
-   * Opaque handle (specific to the plugin) for the
-   * connection to our target; can be NULL.
-   */
-  void *plugin_handle;
-
   /**
    * What was the last latency observed for this plugin
    * and peer?  Invalid if connected is GNUNET_NO.
@@ -887,7 +881,6 @@ transmit_send_continuation (void *cls,
                  "Transmission to peer `%s' failed, marking connection as down.\n",
                  GNUNET_i2s(target));
       rl->connected = GNUNET_NO;
-      rl->plugin_handle = NULL;
     }
   if (!mq->internal_msg)
     rl->transmit_ready = GNUNET_YES;
@@ -986,15 +979,13 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
               ntohs (mq->message->type),
               GNUNET_i2s (&neighbour->id), rl->plugin->short_name);
 #endif
-  rl->plugin_handle
-    = rl->plugin->api->send (rl->plugin->api->cls,
-                             rl->plugin_handle,
-                             rl,
-                             &neighbour->id,
-                            mq->priority,
-                             mq->message,
-                             GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
-                             &transmit_send_continuation, mq);
+  rl->plugin->api->send (rl->plugin->api->cls,
+                        rl,
+                        &neighbour->id,
+                        mq->priority,
+                        mq->message,
+                        GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+                        &transmit_send_continuation, mq);
 }
 
 
@@ -1939,7 +1930,6 @@ disconnect_neighbour (struct NeighbourList *n,
       GNUNET_assert (rpos->neighbour == n);
       if (GNUNET_YES == rpos->connected)
        rpos->plugin->api->cancel (rpos->plugin->api->cls,
-                                  rpos->plugin_handle,
                                   rpos,
                                   &n->id);
       GNUNET_free (rpos);
@@ -2054,9 +2044,6 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer)
  * and generally forward to our receive callback.
  *
  * @param cls the "struct TransportPlugin *" we gave to the plugin
- * @param plugin_context value to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing)
  * @param service_context value passed to the transport-service
  *        to identify the neighbour; will be NULL on the first
  *        call for a given peer
@@ -2070,7 +2057,6 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer)
  */
 static struct ReadyList *
 plugin_env_receive (void *cls,
-                    void *plugin_context,
                     struct ReadyList *service_context,
                     struct GNUNET_TIME_Relative latency,
                     const struct GNUNET_PeerIdentity *peer,
@@ -2114,12 +2100,8 @@ plugin_env_receive (void *cls,
                  GNUNET_i2s(&n->id));
 #endif
       /* TODO: call stats */
-      if ((service_context != NULL) &&
-          (service_context->plugin_handle == plugin_context))
-        {
-          service_context->connected = GNUNET_NO;
-          service_context->plugin_handle = NULL;
-        }
+      if (service_context != NULL) 
+       service_context->connected = GNUNET_NO;        
       disconnect_neighbour (n, GNUNET_YES);
       return NULL;
     }
@@ -2138,7 +2120,6 @@ plugin_env_receive (void *cls,
         }
       service_context->timeout
         = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
-      service_context->plugin_handle = plugin_context;
       service_context->latency = latency;
     }
   /* update traffic received amount ... */
index 1c545480d091b8f0db2004dad6d4334d5dd05e19..a309f0edf879b6e6a2d675c7ab3dd3c3a8740bb8 100644 (file)
@@ -58,9 +58,6 @@ struct ReadyList;
  * message to signal that the other peer disconnected.
  *
  * @param cls closure
- * @param plugin_context value to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing)
  * @param service_context value passed to the transport-service
  *        to identify the neighbour; will be NULL on the first
  *        call for a given peer
@@ -79,7 +76,6 @@ struct ReadyList;
  */
 typedef struct ReadyList *
   (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls,
-                                             void *plugin_context,
                                              struct ReadyList *
                                              service_context,
                                              struct GNUNET_TIME_Relative
@@ -299,9 +295,6 @@ typedef void
  * a fresh connection to another peer.
  *
  * @param cls closure
- * @param plugin_context value we were asked to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing), can be NULL
  * @param service_context value passed to the transport-service
  *        to identify the neighbour; NULL is used to indicate
  *        an urgent message.  If the urgent message can not be
@@ -316,12 +309,9 @@ typedef void
  *        for the next transmission call; or if the
  *        peer disconnected...); can be NULL
  * @param cont_cls closure for cont
- * @return plugin_context that should be used next time for
- *         sending messages to the specified peer
  */
-typedef void *
+typedef void 
   (*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
-                                        void *plugin_context,
                                         struct ReadyList * service_context,
                                         const struct GNUNET_PeerIdentity *
                                         target,
@@ -346,14 +336,6 @@ typedef void *
  * closed after a getting this call.
  *
  * @param cls closure
- * @param plugin_context value we were asked to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing), can be NULL (if
- *        NULL was returned from the transmit function); note
- *        that use of NULL is dangerous since then this call may
- *        cancel any session with the target peer (including
- *        HELLO validation sessions), which is likely not what
- *        is intended.
  * @param service_context must correspond to the service context
  *        of the corresponding Transmit call; the plugin should
  *        not cancel a send call made with a different service
@@ -363,7 +345,6 @@ typedef void *
  */
 typedef void
   (*GNUNET_TRANSPORT_CancelFunction) (void *cls,
-                                      void *plugin_context,
                                       struct ReadyList * service_context,
                                       const struct GNUNET_PeerIdentity *
                                       target);
index af35d5a74bf7dc8da8dba1ef68a7a0606b929ebb..89fff4be0a4e5862dd141fd095c6d1cfbcf40229 100644 (file)
@@ -385,6 +385,11 @@ struct Plugin
    */
   struct GNUNET_SERVER_MessageHandler *handlers;
 
+  /**
+   * Handle for request of hostname resolution, non-NULL if pending.
+   */
+  struct GNUNET_RESOLVER_RequestHandle *hostname_dns;
+
   /**
    * ID of task used to update our addresses when one expires.
    */
@@ -404,13 +409,6 @@ struct Plugin
 };
 
 
-
-/**
- * Handle for request of hostname resolution, non-NULL if pending.
- */
-static struct GNUNET_RESOLVER_RequestHandle *hostname_dns;
-
-
 /**
  * Find the session handle for the given peer.
  */
@@ -837,7 +835,6 @@ disconnect_session (struct Session *session)
         know about this one, so we need to 
         notify transport service about disconnect */
       session->plugin->env->receive (session->plugin->env->cls,
-                                    session,
                                     session->service_context,
                                     GNUNET_TIME_UNIT_ZERO,
                                     &session->target, NULL);
@@ -1058,9 +1055,6 @@ session_try_connect (void *cls,
  * a message using the plugin.
  *
  * @param cls closure
- * @param plugin_context value we were asked to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing), can be NULL
  * @param service_context value passed to the transport-service
  *        to identify the neighbour
  * @param target who should receive this message
@@ -1072,12 +1066,9 @@ session_try_connect (void *cls,
  *        for the next transmission call; or if the
  *        peer disconnected...)
  * @param cont_cls closure for cont
- * @return plugin_context that should be used next time for
-  *         sending messages to the specified peer
  */
-static void *
+static void 
 tcp_plugin_send (void *cls,
-                 void *plugin_context,
                  struct ReadyList *service_context,
                  const struct GNUNET_PeerIdentity *target,   
                 unsigned int priority,
@@ -1086,12 +1077,11 @@ tcp_plugin_send (void *cls,
                  GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
 {
   struct Plugin *plugin = cls;
-  struct Session *session = plugin_context;
+  struct Session *session;
   struct PendingMessage *pm;
   struct PendingMessage *pme;
 
-  if (session == NULL)
-    session = find_session_by_target (plugin, target);  
+  session = find_session_by_target (plugin, target);  
   pm = GNUNET_malloc (sizeof (struct PendingMessage) + ntohs (msg->size));
   pm->msg = (struct GNUNET_MessageHeader *) &pm[1];
   memcpy (pm->msg, msg, ntohs (msg->size));
@@ -1120,7 +1110,7 @@ tcp_plugin_send (void *cls,
                                plugin->env->sched,
                                target,
                                0, timeout, &session_try_connect, session);
-      return session;
+      return;
     }
   GNUNET_assert (session != NULL);
   GNUNET_assert (session->client != NULL);
@@ -1142,7 +1132,6 @@ tcp_plugin_send (void *cls,
                    "tcp", "Asked to transmit, added message to list.\n");
 #endif
   process_pending_messages (session);
-  return session;
 }
 
 
@@ -1160,14 +1149,6 @@ tcp_plugin_send (void *cls,
  * closed after a getting this call.
  *
  * @param cls closure
- * @param plugin_context value we were asked to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing), can be NULL (if
- *        NULL was returned from the transmit function); note
- *        that use of NULL is dangerous since then this call may
- *        cancel any session with the target peer (including
- *        HELLO validation sessions), which is likely not what
- *        is intended.
  * @param service_context must correspond to the service context
  *        of the corresponding Transmit call; the plugin should
  *        not cancel a send call made with a different service
@@ -1177,24 +1158,14 @@ tcp_plugin_send (void *cls,
  */
 static void
 tcp_plugin_cancel (void *cls,
-                   void *plugin_context,
                    struct ReadyList *service_context,
                    const struct GNUNET_PeerIdentity *target)
 {
   struct Plugin *plugin = cls;
-  struct Session *session = plugin_context;
+  struct Session *session;
   struct PendingMessage *pm;
   
-  if (session == NULL)
-    {
-#if DEBUG_TCP
-      GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
-                      "tcp",
-                      "Asked to cancel with `%4s' without specification of specifics; will try to find an applicable session\n",
-                      GNUNET_i2s(target));
-#endif
-      session = find_session_by_target (plugin, target);
-    }
+  session = find_session_by_target (plugin, target);
   if (session == NULL)
     {
       GNUNET_break (0);
@@ -1886,7 +1857,6 @@ handle_tcp_data (void *cls,
 #endif
   session->service_context
     = plugin->env->receive (plugin->env->cls,
-                            session,
                             session->service_context,
                             latency, &session->target, msg);
   /* update bandwidth used */
@@ -2014,7 +1984,7 @@ process_hostname_ips (void *cls,
 
   if (addr == NULL)
     {
-      hostname_dns = NULL;
+      plugin->hostname_dns = NULL;
       return;
     }
   process_interfaces (plugin,
@@ -2100,11 +2070,11 @@ libgnunet_plugin_transport_tcp_init (void *cls)
   GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify,
                                    plugin);
   GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
-  hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched,
-                                                  env->cfg,
-                                                  AF_UNSPEC,
-                                                  HOSTNAME_RESOLVE_TIMEOUT,
-                                                  &process_hostname_ips, plugin);
+  plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched,
+                                                          env->cfg,
+                                                          AF_UNSPEC,
+                                                          HOSTNAME_RESOLVE_TIMEOUT,
+                                                          &process_hostname_ips, plugin);
   return api;
 }
 
@@ -2121,10 +2091,10 @@ libgnunet_plugin_transport_tcp_done (void *cls)
 
   while (NULL != (session = plugin->sessions))
     disconnect_session (session);    
-  if (NULL != hostname_dns)
+  if (NULL != plugin->hostname_dns)
     {
-      GNUNET_RESOLVER_request_cancel (hostname_dns);
-      hostname_dns = NULL;
+      GNUNET_RESOLVER_request_cancel (plugin->hostname_dns);
+      plugin->hostname_dns = NULL;
     }
   GNUNET_SERVICE_stop (plugin->service);
   GNUNET_free (plugin->handlers);
index 95fd2de5f71f3aae0ea0a5ca957052ad543e78ff..1d949f3450bdb66f3b9e9def07eb5af9b11a4baf 100644 (file)
@@ -163,9 +163,6 @@ template_plugin_validate (void *cls,
  * a message using the plugin.
  *
  * @param cls closure
- * @param plugin_context value we were asked to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing), can be NULL
  * @param service_context value passed to the transport-service
  *        to identify the neighbour
  * @param target who should receive this message
@@ -177,12 +174,9 @@ template_plugin_validate (void *cls,
  *        for the next transmission call; or if the
  *        peer disconnected...)
  * @param cont_cls closure for cont
- * @return plugin_context that should be used next time for
- *         sending messages to the specified peer
  */
-static void *
+static void 
 template_plugin_send (void *cls,
-                      void *plugin_context,
                       struct ReadyList *service_context,
                       const struct GNUNET_PeerIdentity *target,
                      unsigned int priority,
@@ -192,18 +186,16 @@ template_plugin_send (void *cls,
                       void *cont_cls)
 {
   //  struct Plugin *plugin = cls;
-  return NULL;
 }
 
 
 
 /**
+ * Function that can be used to force the plugin to disconnect
+ * from the given peer and cancel all previous transmissions
+ * (and their continuationc).
  *
  * @param cls closure
- * @param plugin_context value we were asked to pass to this plugin
- *        to respond to the given peer (use is optional,
- *        but may speed up processing), can be NULL (if
- *        NULL was returned from the transmit function)
  * @param service_context must correspond to the service context
  *        of the corresponding Transmit call; the plugin should
  *        not cancel a send call made with a different service
@@ -213,7 +205,6 @@ template_plugin_send (void *cls,
  */
 static void
 template_plugin_cancel (void *cls,
-                        void *plugin_context,
                         struct ReadyList *service_context,
                         const struct GNUNET_PeerIdentity *target)
 {