gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r33807 - gnunet/src/transport
Date: Mon, 23 Jun 2014 23:40:21 +0200

Author: grothoff
Date: 2014-06-23 23:40:20 +0200 (Mon, 23 Jun 2014)
New Revision: 33807

Modified:
   gnunet/src/transport/plugin_transport_http_client.c
Log:
-simplify deletion logic, tell monitor that we are initiator

Modified: gnunet/src/transport/plugin_transport_http_client.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_client.c 2014-06-23 21:39:24 UTC 
(rev 33806)
+++ gnunet/src/transport/plugin_transport_http_client.c 2014-06-23 21:40:20 UTC 
(rev 33807)
@@ -392,7 +392,7 @@
     return;
   memset (&info, 0, sizeof (info));
   info.state = state;
-  info.is_inbound = GNUNET_SYSERR; /* hard to say */
+  info.is_inbound = GNUNET_NO;
   info.num_msg_pending = session->msgs_in_queue;
   info.num_bytes_pending = session->bytes_in_queue;
   info.receive_delay = session->next_receive;
@@ -405,6 +405,70 @@
 
 
 /**
+ * Delete session @a s.
+ *
+ * @param s the session to delete
+ */
+static void
+client_delete_session (struct Session *s)
+{
+  struct HTTP_Client_Plugin *plugin = s->plugin;
+  struct HTTP_Message *pos;
+  struct HTTP_Message *next;
+
+  if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (s->timeout_task);
+    s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
+  }
+  if (GNUNET_SCHEDULER_NO_TASK != s->put_disconnect_task)
+  {
+    GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
+    s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
+                                                       &s->target,
+                                                       s));
+
+  next = s->msg_head;
+  while (NULL != (pos = next))
+  {
+    next = pos->next;
+    GNUNET_CONTAINER_DLL_remove (s->msg_head,
+                                 s->msg_tail,
+                                 pos);
+    GNUNET_assert (0 < s->msgs_in_queue);
+    s->msgs_in_queue--;
+    GNUNET_assert (pos->size <= s->bytes_in_queue);
+    s->bytes_in_queue -= pos->size;
+    if (NULL != pos->transmit_cont)
+      pos->transmit_cont (pos->transmit_cont_cls,
+                          &s->target,
+                          GNUNET_SYSERR,
+                          pos->size,
+                          pos->pos + s->overhead);
+    s->overhead = 0;
+    GNUNET_free (pos);
+  }
+  GNUNET_assert (0 == s->msgs_in_queue);
+  GNUNET_assert (0 == s->bytes_in_queue);
+  notify_session_monitor (plugin,
+                          s,
+                          GNUNET_TRANSPORT_SS_DOWN);
+  if (NULL != s->msg_tk)
+  {
+    GNUNET_SERVER_mst_destroy (s->msg_tk);
+    s->msg_tk = NULL;
+  }
+  GNUNET_HELLO_address_free (s->address);
+  GNUNET_free (s->url);
+  GNUNET_free (s);
+}
+
+
+/**
  * Increment session timeout due to activity for session @a s.
  *
  * @param s the session
@@ -418,27 +482,87 @@
 
 
 /**
+ * Task performing curl operations
+ *
+ * @param cls plugin as closure
+ * @param tc gnunet scheduler task context
+ */
+static void
+client_run (void *cls,
+            const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
  * Function setting up file descriptors and scheduling task to run
  *
- * @param  plugin plugin as closure
+ * @param plugin the plugin as closure
  * @param now schedule task in 1ms, regardless of what curl may say
  * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
  */
 static int
 client_schedule (struct HTTP_Client_Plugin *plugin,
-                 int now);
+                 int now)
+{
+  fd_set rs;
+  fd_set ws;
+  fd_set es;
+  int max;
+  struct GNUNET_NETWORK_FDSet *grs;
+  struct GNUNET_NETWORK_FDSet *gws;
+  long to;
+  CURLMcode mret;
+  struct GNUNET_TIME_Relative timeout;
 
+  /* Cancel previous scheduled task */
+  if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
+  {
+    GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
+    plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+  max = -1;
+  FD_ZERO (&rs);
+  FD_ZERO (&ws);
+  FD_ZERO (&es);
+  mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
+  if (mret != CURLM_OK)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
+                "curl_multi_fdset", __FILE__, __LINE__,
+                curl_multi_strerror (mret));
+    return GNUNET_SYSERR;
+  }
+  mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
+  if (to == -1)
+    timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
+  else
+    timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 
to);
+  if (now == GNUNET_YES)
+    timeout = GNUNET_TIME_UNIT_MILLISECONDS;
 
-/**
- * Connect a HTTP put connection
- *
- * @param s the session to connect
- * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success
- */
-static int
-client_connect_put (struct Session *s);
+  if (mret != CURLM_OK)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("%s failed at %s:%d: `%s'\n"),
+                "curl_multi_timeout", __FILE__, __LINE__,
+                curl_multi_strerror (mret));
+    return GNUNET_SYSERR;
+  }
 
+  grs = GNUNET_NETWORK_fdset_create ();
+  gws = GNUNET_NETWORK_fdset_create ();
+  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
+  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
 
+  plugin->client_perform_task =
+      GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+                                   timeout, grs, gws,
+                                   &client_run, plugin);
+  GNUNET_NETWORK_fdset_destroy (gws);
+  GNUNET_NETWORK_fdset_destroy (grs);
+  return GNUNET_OK;
+}
+
+
 /**
  * Loggging function
  *
@@ -502,6 +626,16 @@
 
 
 /**
+ * Connect a HTTP put connection
+ *
+ * @param s the session to connect
+ * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success
+ */
+static int
+client_connect_put (struct Session *s);
+
+
+/**
  * Function that can be used by the transport service to transmit
  * a message using the plugin.   Note that in the case of a
  * peer disconnecting, the continuation MUST be called
@@ -601,7 +735,7 @@
          "Session %p: Reconnecting PUT connection\n",
          s);
     s->put_tmp_disconnected = GNUNET_NO;
-    GNUNET_break (s->client_put == NULL);
+    GNUNET_break (NULL == s->client_put);
     if (GNUNET_SYSERR == client_connect_put (s))
       return GNUNET_SYSERR;
   }
@@ -612,70 +746,6 @@
 
 
 /**
- * Delete session @a s.
- *
- * @param s the session to delete
- */
-static void
-client_delete_session (struct Session *s)
-{
-  struct HTTP_Client_Plugin *plugin = s->plugin;
-  struct HTTP_Message *pos;
-  struct HTTP_Message *next;
-
-  if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (s->timeout_task);
-    s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
-    s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
-  }
-  if (GNUNET_SCHEDULER_NO_TASK != s->put_disconnect_task)
-  {
-    GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
-    s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK;
-  }
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
-                                                       &s->target,
-                                                       s));
-
-  next = s->msg_head;
-  while (NULL != (pos = next))
-  {
-    next = pos->next;
-    GNUNET_CONTAINER_DLL_remove (s->msg_head,
-                                 s->msg_tail,
-                                 pos);
-    GNUNET_assert (0 < s->msgs_in_queue);
-    s->msgs_in_queue--;
-    GNUNET_assert (pos->size <= s->bytes_in_queue);
-    s->bytes_in_queue -= pos->size;
-    if (NULL != pos->transmit_cont)
-      pos->transmit_cont (pos->transmit_cont_cls,
-                          &s->target,
-                          GNUNET_SYSERR,
-                          pos->size,
-                          pos->pos + s->overhead);
-    s->overhead = 0;
-    GNUNET_free (pos);
-  }
-  GNUNET_assert (0 == s->msgs_in_queue);
-  GNUNET_assert (0 == s->bytes_in_queue);
-  notify_session_monitor (plugin,
-                          s,
-                          GNUNET_TRANSPORT_SS_DOWN);
-  if (NULL != s->msg_tk)
-  {
-    GNUNET_SERVER_mst_destroy (s->msg_tk);
-    s->msg_tk = NULL;
-  }
-  GNUNET_HELLO_address_free (s->address);
-  GNUNET_free (s->url);
-  GNUNET_free (s);
-}
-
-
-/**
  * Disconnect a session
  *
  * @param cls the `struct HTTP_Client_Plugin *`
@@ -701,7 +771,8 @@
          GNUNET_i2s (&s->target));
 
     /* remove curl handle from multi handle */
-    mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_put);
+    mret = curl_multi_remove_handle (plugin->curl_multi_handle,
+                                     s->client_put);
     if (mret != CURLM_OK)
     {
       /* clean up easy handle, handle is now invalid and free'd */
@@ -1203,88 +1274,6 @@
  * Task performing curl operations
  *
  * @param cls plugin as closure
- * @param tc gnunet scheduler task context
- */
-static void
-client_run (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-/**
- * Function setting up file descriptors and scheduling task to run
- *
- * @param plugin the plugin as closure
- * @param now schedule task in 1ms, regardless of what curl may say
- * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
- */
-static int
-client_schedule (struct HTTP_Client_Plugin *plugin,
-                 int now)
-{
-  fd_set rs;
-  fd_set ws;
-  fd_set es;
-  int max;
-  struct GNUNET_NETWORK_FDSet *grs;
-  struct GNUNET_NETWORK_FDSet *gws;
-  long to;
-  CURLMcode mret;
-  struct GNUNET_TIME_Relative timeout;
-
-  /* Cancel previous scheduled task */
-  if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
-  {
-    GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
-    plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
-  }
-  max = -1;
-  FD_ZERO (&rs);
-  FD_ZERO (&ws);
-  FD_ZERO (&es);
-  mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
-  if (mret != CURLM_OK)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
-                "curl_multi_fdset", __FILE__, __LINE__,
-                curl_multi_strerror (mret));
-    return GNUNET_SYSERR;
-  }
-  mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
-  if (to == -1)
-    timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
-  else
-    timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 
to);
-  if (now == GNUNET_YES)
-    timeout = GNUNET_TIME_UNIT_MILLISECONDS;
-
-  if (mret != CURLM_OK)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("%s failed at %s:%d: `%s'\n"),
-                "curl_multi_timeout", __FILE__, __LINE__,
-                curl_multi_strerror (mret));
-    return GNUNET_SYSERR;
-  }
-
-  grs = GNUNET_NETWORK_fdset_create ();
-  gws = GNUNET_NETWORK_fdset_create ();
-  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
-  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
-
-  plugin->client_perform_task =
-      GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                                   timeout, grs, gws,
-                                   &client_run, plugin);
-  GNUNET_NETWORK_fdset_destroy (gws);
-  GNUNET_NETWORK_fdset_destroy (grs);
-  return GNUNET_OK;
-}
-
-
-/**
- * Task performing curl operations
- *
- * @param cls plugin as closure
  * @param tc scheduler task context
  */
 static void
@@ -1369,12 +1358,12 @@
              */
             if (GNUNET_YES == s->put_reconnect_required)
             {
-                s->put_reconnect_required = GNUNET_NO;
-                if (GNUNET_SYSERR == client_connect_put(s))
-                {
-                    GNUNET_break (s->client_put == NULL);
-                    GNUNET_break (s->put_tmp_disconnected == GNUNET_NO);
-                }
+              s->put_reconnect_required = GNUNET_NO;
+              if (GNUNET_SYSERR == client_connect_put (s))
+              {
+                GNUNET_break (s->client_put == NULL);
+                GNUNET_break (s->put_tmp_disconnected == GNUNET_NO);
+              }
             }
         }
         if (easy_h == s->client_get)
@@ -2171,7 +2160,6 @@
 }
 
 
-
 /**
  * Entry point for the plugin.
  */




reply via email to

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