Use proper core priority for each message type and message origin.
authorBart Polot <bart@net.in.tum.de>
Tue, 4 Feb 2014 12:36:29 +0000 (12:36 +0000)
committerBart Polot <bart@net.in.tum.de>
Tue, 4 Feb 2014 12:36:29 +0000 (12:36 +0000)
src/mesh/gnunet-service-mesh_peer.c

index 7d499f953f5ca98579a3273753b1cc1bc1d1b963..c02de9edc4c9868f3d668ec030d458c71fb649d7 100644 (file)
@@ -508,6 +508,46 @@ send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf)
 /********************************   STATIC  ***********************************/
 /******************************************************************************/
 
+
+/**
+ * Get priority for a queued message.
+ *
+ * @param q Queued message
+ *
+ * @return CORE priority to use.
+ */
+static enum GNUNET_CORE_Priority
+get_priority (struct MeshPeerQueue *q)
+{
+  enum GNUNET_CORE_Priority low;
+  enum GNUNET_CORE_Priority high;
+
+  if (NULL == q)
+  {
+    GNUNET_break (0);
+    return GNUNET_CORE_PRIO_BACKGROUND;
+  }
+
+  /* Relayed traffic has lower priority, our own traffic has higher */
+  if (NULL == q->c || GNUNET_NO == GMC_is_origin (q->c, q->fwd))
+  {
+    low = GNUNET_CORE_PRIO_BEST_EFFORT;
+    high = GNUNET_CORE_PRIO_URGENT;
+  }
+  else
+  {
+    low = GNUNET_CORE_PRIO_URGENT;
+    high = GNUNET_CORE_PRIO_CRITICAL_CONTROL;
+  }
+
+  /* Bulky payload has lower priority, control traffic has higher. */
+  if (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED == q->type)
+    return low;
+  else
+    return high;
+}
+
+
 /**
  * Iterator over tunnel hash map entries to destroy the tunnel during shutdown.
  *
@@ -531,7 +571,6 @@ shutdown_tunnel (void *cls,
 }
 
 
-
 /**
  * Destroy the peer_info and free any allocated resources linked to it
  *
@@ -792,6 +831,7 @@ search_handler (void *cls, const struct MeshPeerPath *path)
 }
 
 
+
 /**
  * Core callback to write a queued packet to core buffer
  *
@@ -837,8 +877,7 @@ queue_send (void *cls, size_t size, void *buf)
       LOG (GNUNET_ERROR_TYPE_DEBUG, "*   not enough room, reissue\n");
       peer->core_transmit =
           GNUNET_CORE_notify_transmit_ready (core_handle,
-                                             GNUNET_NO,
-                                             GNUNET_CORE_PRIO_CRITICAL_CONTROL,
+                                             GNUNET_NO, get_priority (queue),
                                              GNUNET_TIME_UNIT_FOREVER_REL,
                                              dst_id,
                                              queue->size,
@@ -910,8 +949,7 @@ queue_send (void *cls, size_t size, void *buf)
     {
       peer->core_transmit =
           GNUNET_CORE_notify_transmit_ready (core_handle,
-                                             GNUNET_NO,
-                                             GNUNET_CORE_PRIO_CRITICAL_CONTROL,
+                                             GNUNET_NO, get_priority (queue),
                                              GNUNET_TIME_UNIT_FOREVER_REL,
                                              dst_id,
                                              queue->size,
@@ -1079,8 +1117,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
                 GMP_2s (peer), size);
     peer->core_transmit =
         GNUNET_CORE_notify_transmit_ready (core_handle,
-                                           GNUNET_NO,
-                                           GNUNET_CORE_PRIO_CRITICAL_CONTROL,
+                                           GNUNET_NO, get_priority (queue),
                                            GNUNET_TIME_UNIT_FOREVER_REL,
                                            GNUNET_PEER_resolve2 (peer->id),
                                            size,
@@ -1196,8 +1233,7 @@ GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c)
   size = q->size;
   peer->core_transmit =
       GNUNET_CORE_notify_transmit_ready (core_handle,
-                                         GNUNET_NO,
-                                         GNUNET_CORE_PRIO_CRITICAL_CONTROL,
+                                         GNUNET_NO, get_priority (q),
                                          GNUNET_TIME_UNIT_FOREVER_REL,
                                          GNUNET_PEER_resolve2 (peer->id),
                                          size,