- move queue canceling to peer.c
authorBart Polot <bart@net.in.tum.de>
Thu, 10 Oct 2013 12:46:15 +0000 (12:46 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 10 Oct 2013 12:46:15 +0000 (12:46 +0000)
src/mesh/gnunet-service-mesh_connection.c
src/mesh/gnunet-service-mesh_peer.c
src/mesh/gnunet-service-mesh_peer.h

index e70211cb9d9ca53989ecaf45b241876b4a499a14..d7d6f89f7dcadeb228206edc1e4f9b3919deb1e1 100644 (file)
@@ -723,8 +723,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd)
 static void
 connection_cancel_queues (struct MeshConnection *c, int fwd)
 {
-  struct MeshPeerQueue *q;
-  struct MeshPeerQueue *next;
+
   struct MeshFlowControl *fc;
   struct MeshPeer *peer;
 
@@ -733,32 +732,15 @@ connection_cancel_queues (struct MeshConnection *c, int fwd)
     GNUNET_break (0);
     return;
   }
-  fc = fwd ? &c->fwd_fc : &c->bck_fc;
+
   peer = connection_get_hop (c, fwd);
+  GMP_queue_cancel (peer, c);
 
-  for (q = peer->queue_head; NULL != q; q = next)
-  {
-    next = q->next;
-    if (q->c == c)
-    {
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
-                  "connection_cancel_queue %s\n",
-                  GNUNET_MESH_DEBUG_M2S (q->type));
-      queue_destroy (q, GNUNET_YES);
-    }
-  }
-  if (NULL == peer->queue_head)
+  fc = fwd ? &c->fwd_fc : &c->bck_fc;
+  if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task)
   {
-    if (NULL != peer->core_transmit)
-    {
-      GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit);
-      peer->core_transmit = NULL;
-    }
-    if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task)
-    {
-      GNUNET_SCHEDULER_cancel (fc->poll_task);
-      fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
-    }
+    GNUNET_SCHEDULER_cancel (fc->poll_task);
+    fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
   }
 }
 
index d700f3aa210e86db453d57e29cd201ee20980ae3..5e44bbc8600527d4d6aa5aa050e8aef6444eacb1 100644 (file)
@@ -1407,6 +1407,39 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
 }
 
 
+/**
+ * Cancel all queued messages to a peer that belong to a certain connection.
+ *
+ * @param peer Peer towards whom to cancel.
+ * @param c Connection whose queued messages to cancel.
+ */
+void
+GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c)
+{
+  struct MeshPeerQueue *q;
+  struct MeshPeerQueue *next;
+
+  for (q = peer->queue_head; NULL != q; q = next)
+  {
+    next = q->next;
+    if (q->c == c)
+    {
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+                  "connection_cancel_queue %s\n",
+                  GNUNET_MESH_DEBUG_M2S (q->type));
+      GMP_queue_destroy (q, GNUNET_YES);
+    }
+  }
+  if (NULL == peer->queue_head)
+  {
+    if (NULL != peer->core_transmit)
+    {
+      GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit);
+      peer->core_transmit = NULL;
+    }
+  }
+}
+
 
 /**
  * Initialize the peer subsystem.
@@ -1624,6 +1657,14 @@ GMP_add_connection (struct MeshPeer *peer,
 }
 
 
+/**
+ * Remove a connection from a neighboring peer.
+ *
+ * @param peer Peer to remove connection from.
+ * @param c Connection to remove.
+ *
+ * @return GNUNET_OK on success.
+ */
 int
 GMP_remove_connection (struct MeshPeer *peer,
                        const struct MeshConnection *c)
index ad195539023c102be2b76b25225de22fe4af4909..c898af351d06d18e984602df8d65f7a72b940590 100644 (file)
@@ -97,6 +97,15 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
                int fwd,
                GMP_sent callback, void *callback_cls);
 
+/**
+ * Cancel all queued messages to a peer that belong to a certain connection.
+ *
+ * @param peer Peer towards whom to cancel.
+ * @param c Connection whose queued messages to cancel.
+ */
+void
+GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c);
+
 /**
  * Set tunnel.
  *
@@ -132,6 +141,14 @@ GMP_is_neighbor (const struct MeshPeer *peer);
 int
 GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
 
+/**
+ * Remove a connection from a neighboring peer.
+ *
+ * @param peer Peer to remove connection from.
+ * @param c Connection to remove.
+ *
+ * @return GNUNET_OK on success.
+ */
 int
 GMP_remove_connection (struct MeshPeer *peer, struct MeshConnection *c);