backup errno
[oweals/gnunet.git] / src / transport / transport_api.c
index 3a5c8e0f5b3c3bf524ed8226759fa1385991e558..8d08f82d9d3f516796604a662dcc9b977b3992af 100644 (file)
@@ -203,7 +203,7 @@ struct GNUNET_TRANSPORT_TransmitHandle
    * Function to call when notify_size bytes are available
    * for transmission.
    */
-  GNUNET_NETWORK_TransmitReadyNotify notify;
+  GNUNET_CONNECTION_TransmitReadyNotify notify;
 
   /**
    * Closure for notify.
@@ -278,7 +278,7 @@ struct GNUNET_TRANSPORT_Handle
   /**
    * Handle to our registration with the client for notification.
    */
-  struct GNUNET_NETWORK_TransmitHandle *network_handle;
+  struct GNUNET_CONNECTION_TransmitHandle *network_handle;
 
   /**
    * Linked list of transmit handles that are waiting for the
@@ -390,8 +390,15 @@ transport_notify_ready (void *cls, size_t size, void *buf)
           GNUNET_assert (n->transmit_handle == th);
           n->transmit_handle = NULL;
         }
+      if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
+       {
+         GNUNET_SCHEDULER_cancel (h->sched,
+                                  th->notify_delay_task);
+         th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
+       }
       GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
       GNUNET_free (th);
+      if (h->connect_ready_head != NULL) schedule_transmission (h); /* FIXME: is this ok? */
       return 0;
     } 
 #if DEBUG_TRANSPORT
@@ -407,8 +414,6 @@ transport_notify_ready (void *cls, size_t size, void *buf)
       th = h->connect_ready_head;
       if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
        {
-         /* remove existing time out task (only applies if
-            this is not the first iteration of the loop) */
          GNUNET_SCHEDULER_cancel (h->sched,
                                   th->notify_delay_task);
          th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
@@ -569,7 +574,7 @@ try_connect (struct GNUNET_TRANSPORT_TransmitHandle *th);
  * TransmitHandle.
  */
 static void
-transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
 
@@ -605,7 +610,7 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
                            size_t size,
                            int at_head,
                            struct GNUNET_TIME_Relative timeout,
-                           GNUNET_NETWORK_TransmitReadyNotify notify,
+                           GNUNET_CONNECTION_TransmitReadyNotify notify,
                            void *notify_cls)
 {
   struct GNUNET_TRANSPORT_TransmitHandle *th;
@@ -622,7 +627,7 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
                                    GNUNET_SCHEDULER_PRIORITY_KEEP,
                                    GNUNET_SCHEDULER_NO_TASK,
                                    timeout,
-                                   &transmit_timeout, th);    
+                                   &peer_transmit_timeout, th);    
   if (at_head)
     {
       th->next = h->connect_ready_head;
@@ -989,6 +994,11 @@ request_connect (void *cls, size_t size, void *buf)
                  "TRY_CONNECT",
                  GNUNET_i2s(&th->target));
 #endif
+      if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
+       {
+         GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task);
+         th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
+       }
       th->notify (th->notify_cls, 0, NULL);
       GNUNET_free (th);
       return 0;
@@ -1011,7 +1021,7 @@ request_connect (void *cls, size_t size, void *buf)
                                     GNUNET_SCHEDULER_NO_TASK,
                                    GNUNET_TIME_absolute_get_remaining
                                    (th->timeout),
-                                   &transmit_timeout, th);
+                                   &peer_transmit_timeout, th);
   insert_transmit_handle (&h->connect_wait_head, th);
   return sizeof (struct TryConnectMessage);
 }
@@ -1104,10 +1114,14 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h,
        {
          /* signal error */
          GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task);
-         transmit_timeout (th, NULL);    
+         peer_transmit_timeout (th, NULL);       
        }
       else
        {
+         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                     _("Connection with `%4s' failed, will keep trying for %llu ms to deliver message\n"),
+                     GNUNET_i2s (peer),
+                     GNUNET_TIME_absolute_get_remaining (th->timeout).value);
          /* try again in a bit */
          GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task);
          th->notify_delay_task 
@@ -1136,6 +1150,9 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GNUNET_TRANSPORT_TransmitHandle *pos;
   struct NeighbourList *n;
 
+  fprintf (stderr,
+          "Trying to reconnect to transport!\n");
+
   /* Forget about all neighbours that we used to be connected
      to */
   while (NULL != (n = h->neighbours))
@@ -1322,7 +1339,7 @@ schedule_request (struct GNUNET_TRANSPORT_TransmitHandle *th)
                                         GNUNET_SCHEDULER_PRIORITY_KEEP,
                                         GNUNET_SCHEDULER_NO_TASK,
                                         GNUNET_TIME_absolute_get_remaining
-                                        (th->timeout), &transmit_timeout, th);
+                                        (th->timeout), &peer_transmit_timeout, th);
       return;
     }
   n->transmit_ok = GNUNET_NO;
@@ -1484,11 +1501,13 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
   struct GNUNET_CLIENT_Connection *client;
 
 #if DEBUG_TRANSPORT
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+             "Transport disconnect called!\n");
 #endif
   while (NULL != (th = handle->connect_ready_head))
     {
       handle->connect_ready_head = th->next;
+      GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK);
       th->notify (th->notify_cls, 0, NULL);
       GNUNET_free (th);
     }
@@ -1573,7 +1592,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
 #endif
           if (h->network_handle != NULL)
             {
-              GNUNET_NETWORK_notify_transmit_ready_cancel (h->network_handle);
+              GNUNET_CONNECTION_notify_transmit_ready_cancel (h->network_handle);
               h->network_handle = NULL;
               h->transmission_scheduled = GNUNET_NO;
              th = h->connect_ready_head;
@@ -1585,7 +1604,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
                                                GNUNET_SCHEDULER_PRIORITY_KEEP,
                                                GNUNET_SCHEDULER_NO_TASK,
                                                GNUNET_TIME_absolute_get_remaining(th->timeout),
-                                               &transmit_timeout, 
+                                               &peer_transmit_timeout, 
                                                th);    
             }
           GNUNET_CLIENT_disconnect (h->client);
@@ -1768,7 +1787,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
 
 struct ClientTransmitWrapper
 {
-  GNUNET_NETWORK_TransmitReadyNotify notify;
+  GNUNET_CONNECTION_TransmitReadyNotify notify;
   void *notify_cls;
   struct GNUNET_TRANSPORT_TransmitHandle *th;
 };
@@ -1856,7 +1875,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
                                         *target, size_t size,
                                        unsigned int priority,
                                         struct GNUNET_TIME_Relative timeout,
-                                        GNUNET_NETWORK_TransmitReadyNotify
+                                        GNUNET_CONNECTION_TransmitReadyNotify
                                         notify, void *notify_cls)
 {
   struct GNUNET_TRANSPORT_TransmitHandle *pos;
@@ -1928,7 +1947,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
                                        GNUNET_NO,
                                        GNUNET_SCHEDULER_PRIORITY_KEEP,
                                        GNUNET_SCHEDULER_NO_TASK,
-                                       timeout, &transmit_timeout, th);
+                                       timeout, &peer_transmit_timeout, th);
       return th;
     }
   
@@ -1943,8 +1962,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
 
 
 /**
- * Cancel the specified transmission-ready
- * notification.
+ * Cancel the specified transmission-ready notification.
  */
 void
 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
@@ -1964,11 +1982,12 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
   h = th->handle;
   if ((h->connect_ready_head == NULL) && (h->network_handle != NULL))
     {
-      GNUNET_NETWORK_notify_transmit_ready_cancel (h->network_handle);
+      GNUNET_CONNECTION_notify_transmit_ready_cancel (h->network_handle);
       h->network_handle = NULL;
       h->transmission_scheduled = GNUNET_NO;
     }
   GNUNET_free (th->notify_cls);
+  GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK);
   GNUNET_free (th);
 }