gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30112 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r30112 - gnunet/src/mesh
Date: Thu, 10 Oct 2013 18:29:07 +0200

Author: bartpolot
Date: 2013-10-10 18:29:06 +0200 (Thu, 10 Oct 2013)
New Revision: 30112

Modified:
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_peer.c
   gnunet/src/mesh/gnunet-service-mesh_peer.h
Log:
- change queueing API, adapt connections


Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-10 16:12:29 UTC 
(rev 30111)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-10 16:29:06 UTC 
(rev 30112)
@@ -389,8 +389,66 @@
 }
 
 
+/**
+ * Get the previous hop in a connection
+ *
+ * @param c Connection.
+ *
+ * @return Previous peer in the connection.
+ */
+static struct MeshPeer *
+get_prev_hop (struct MeshConnection *c)
+{
+  GNUNET_PEER_Id id;
 
+  if (0 == c->own_pos || c->path->length < 2)
+    id = c->path->peers[0];
+  else
+    id = c->path->peers[c->own_pos - 1];
+
+  return GMP_get_short (id);
+}
+
+
 /**
+ * Get the next hop in a connection
+ *
+ * @param c Connection.
+ *
+ * @return Next peer in the connection.
+ */
+static struct MeshPeer *
+get_next_hop (struct MeshConnection *c)
+{
+  GNUNET_PEER_Id id;
+
+  if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
+    id = c->path->peers[c->path->length - 1];
+  else
+    id = c->path->peers[c->own_pos + 1];
+
+  return GMP_get_short (id);
+}
+
+
+/**
+ * Get the hop in a connection.
+ *
+ * @param c Connection.
+ * @param fwd Next hop?
+ *
+ * @return Next peer in the connection.
+ */
+static struct MeshPeer *
+get_hop (struct MeshConnection *c, int fwd)
+{
+  if (fwd)
+    return get_next_hop (c);
+  return get_prev_hop (c);
+}
+
+
+/**
  * Send an ACK informing the predecessor about the available buffer space.
  *
  * Note that for fwd ack, the FWD mean forward *traffic* (root->dest),
@@ -466,7 +524,7 @@
 
   t = connection->t;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n");
-  GMP_queue_add (NULL,
+  GMP_queue_add (get_hop (connection, fwd), NULL,
                  GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
                  sizeof (struct GNUNET_MESH_ConnectionACK),
                  connection, NULL, fwd,
@@ -590,67 +648,7 @@
 }
 
 
-
 /**
- * Get the previous hop in a connection
- *
- * @param c Connection.
- *
- * @return Previous peer in the connection.
- */
-static struct MeshPeer *
-connection_get_prev_hop (struct MeshConnection *c)
-{
-  GNUNET_PEER_Id id;
-
-  if (0 == c->own_pos || c->path->length < 2)
-    id = c->path->peers[0];
-  else
-    id = c->path->peers[c->own_pos - 1];
-
-  return peer_get_short (id);
-}
-
-
-/**
- * Get the next hop in a connection
- *
- * @param c Connection.
- *
- * @return Next peer in the connection.
- */
-static struct MeshPeer *
-connection_get_next_hop (struct MeshConnection *c)
-{
-  GNUNET_PEER_Id id;
-
-  if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
-    id = c->path->peers[c->path->length - 1];
-  else
-    id = c->path->peers[c->own_pos + 1];
-
-  return peer_get_short (id);
-}
-
-
-/**
- * Get the hop in a connection.
- *
- * @param c Connection.
- * @param fwd Next hop?
- *
- * @return Next peer in the connection.
- */
-static struct MeshPeer *
-connection_get_hop (struct MeshConnection *c, int fwd)
-{
-  if (fwd)
-    return connection_get_next_hop (c);
-  return connection_get_prev_hop (c);
-}
-
-
-/**
  * @brief Re-initiate traffic on this connection if necessary.
  *
  * Check if there is traffic queued towards this peer
@@ -675,7 +673,7 @@
     return;
   }
 
-  peer = connection_get_hop (c, fwd);
+  peer = get_hop (c, fwd);
   GMP_queue_unlock (peer, c);
 }
 
@@ -699,7 +697,7 @@
     return;
   }
 
-  peer = connection_get_hop (c, fwd);
+  peer = get_hop (c, fwd);
   GMP_queue_cancel (peer, c);
 
   fc = fwd ? &c->fwd_fc : &c->bck_fc;
@@ -855,14 +853,14 @@
 {
   struct MeshPeer *peer;
 
-  peer = connection_get_next_hop (c);
+  peer = get_next_hop (c);
   if (GNUNET_NO == GMP_is_neighbor (peer))
   {
     GMC_destroy (c);
     return;
   }
   GMP_add_connection (peer, c);
-  peer = connection_get_prev_hop (c);
+  peer = get_prev_hop (c);
   if (GNUNET_NO == GMP_is_neighbor (peer))
   {
     GMC_destroy (c);
@@ -882,10 +880,10 @@
 {
   struct MeshPeer *peer;
 
-  peer = connection_get_next_hop (c);
+  peer = get_next_hop (c);
   GMP_remove_connection (peer, c);
 
-  peer = connection_get_prev_hop (c);
+  peer = get_prev_hop (c);
   GMP_remove_connection (peer, c);
 
 }
@@ -1065,14 +1063,14 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  via peer %s\n",
               GNUNET_i2s (peer));
   pi = peer_get (peer);
-  if (connection_get_next_hop (c) == pi)
+  if (get_next_hop (c) == pi)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  SYNACK\n");
     fwd = GNUNET_NO;
     if (MESH_CONNECTION_SENT == c->state)
       connection_change_state (c, MESH_CONNECTION_ACK);
   }
-  else if (connection_get_prev_hop (c) == pi)
+  else if (get_prev_hop (c) == pi)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  ACK\n");
     fwd = GNUNET_YES;
@@ -1198,9 +1196,9 @@
     return GNUNET_OK;
   }
   id = GNUNET_PEER_search (peer);
-  if (id == GMP_get_short_id (connection_get_prev_hop (c)))
+  if (id == GMP_get_short_id (get_prev_hop (c)))
     fwd = GNUNET_YES;
-  else if (id == GMP_get_short_id (connection_get_next_hop (c)))
+  else if (id == GMP_get_short_id (get_next_hop (c)))
     fwd = GNUNET_NO;
   else
   {
@@ -1263,7 +1261,7 @@
   fc = fwd ? &c->bck_fc : &c->fwd_fc;
 
   /* Check if origin is as expected */
-  neighbor = connection_get_hop (c, !fwd);
+  neighbor = get_hop (c, !fwd);
   if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
   {
     GNUNET_break_op (0);
@@ -1413,13 +1411,13 @@
 
   /* Is this a forward or backward ACK? */
   id = GNUNET_PEER_search (peer);
-  if (GMP_get_short_id (connection_get_next_hop (c)) == id)
+  if (GMP_get_short_id (get_next_hop (c)) == id)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  FWD ACK\n");
     fc = &c->fwd_fc;
     fwd = GNUNET_YES;
   }
-  else if (GMP_get_short_id (connection_get_prev_hop (c)) == id)
+  else if (GMP_get_short_id (get_prev_hop (c)) == id)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  BCK ACK\n");
     fc = &c->bck_fc;
@@ -1496,12 +1494,12 @@
    * this way of discerining FWD/BCK should not be a problem.
    */
   id = GNUNET_PEER_search (peer);
-  if (GMP_get_short_id (connection_get_next_hop (c)) == id)
+  if (GMP_get_short_id (get_next_hop (c)) == id)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  FWD ACK\n");
     fc = &c->fwd_fc;
   }
-  else if (GMP_get_short_id (connection_get_prev_hop (c)) == id)
+  else if (GMP_get_short_id (get_prev_hop (c)) == id)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  BCK ACK\n");
     fc = &c->bck_fc;
@@ -1559,7 +1557,7 @@
         GNUNET_YES : GNUNET_NO;
 
   /* Check if origin is as expected */
-  neighbor = connection_get_hop (c, fwd);
+  neighbor = get_hop (c, fwd);
   if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
   {
     GNUNET_break_op (0);
@@ -1843,7 +1841,7 @@
   struct GNUNET_MESH_ConnectionBroken msg;
   int fwd;
 
-  fwd = peer == connection_get_prev_hop (c);
+  fwd = peer == get_prev_hop (c);
 
   connection_cancel_queues (c, !fwd);
   if (GMC_is_terminal (c, fwd))
@@ -2003,7 +2001,8 @@
       GNUNET_break (0);
   }
 
-  GMP_queue_add (data, type, size, c, ch, fwd, &message_sent, (void *) size);
+  GMP_queue_add (get_hop (c, fwd), data, type, size, c, ch, fwd,
+                 &message_sent, (void *) size);
 }
 
 
@@ -2022,7 +2021,7 @@
   size = sizeof (struct GNUNET_MESH_ConnectionCreate);
   size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
-  GMP_queue_add (NULL,
+  GMP_queue_add (get_next_hop (connection), NULL,
                  GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
                  size,
                  connection,

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-10 16:12:29 UTC (rev 
30111)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-10 16:29:06 UTC (rev 
30112)
@@ -1083,6 +1083,7 @@
 /**
  * @brief Queue and pass message to core when possible.
  *
+ * @param peer Peer towards which to queue the message.
  * @param cls Closure (@c type dependant). It will be used by queue_send to
  *            build the message to be sent if not already prebuilt.
  * @param type Type of the message, 0 for a raw message.
@@ -1090,19 +1091,15 @@
  * @param c Connection this message belongs to (cannot be NULL).
  * @param ch Channel this message belongs to, if applicable (otherwise NULL).
  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
- * @param callback Function to be called once CORE has taken the message.
- * @param callback_cls Closure for @c callback.
+ * @param cont Continuation to be called once CORE has taken the message.
+ * @param cont_cls Closure for @c cont.
  */
 void
-GMP_queue_add (void *cls, uint16_t type, size_t size,
-               struct MeshConnection *c,
-               struct MeshChannel *ch,
-               int fwd,
-               GMP_sent callback, void *callback_cls)
+GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
+               struct MeshConnection *c, struct MeshChannel *ch, int fwd,
+               GMP_sent cont, void *cont_cls)
 {
   struct MeshPeerQueue *queue;
-  struct MeshFlowControl *fc;
-  struct MeshPeer *peer;
   int priority;
   int call_core;
 
@@ -1111,15 +1108,6 @@
               fwd ? "FWD" : "BCK",  GNUNET_MESH_DEBUG_M2S (type), size, c, ch);
   GNUNET_assert (NULL != c);
 
-  fc   = fwd ? &c->fwd_fc : &c->bck_fc;
-  peer = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c);
-
-  if (NULL == fc)
-  {
-    GNUNET_break (0);
-    return;
-  }
-
   if (NULL == peer->connections)
   {
     /* We are not connected to this peer, ignore request. */
@@ -1172,8 +1160,8 @@
   queue->c = c;
   queue->ch = ch;
   queue->fwd = fwd;
-  queue->callback = callback;
-  queue->callback_cls = callback_cls;
+  queue->callback = cont;
+  queue->callback_cls = cont_cls;
   if (100 <= priority)
   {
     struct MeshPeerQueue *copy;

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.h  2013-10-10 16:12:29 UTC (rev 
30111)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.h  2013-10-10 16:29:06 UTC (rev 
30112)
@@ -114,6 +114,7 @@
 /**
  * @brief Queue and pass message to core when possible.
  *
+ * @param peer Peer towards which to queue the message.
  * @param cls Closure (@c type dependant). It will be used by queue_send to
  *            build the message to be sent if not already prebuilt.
  * @param type Type of the message, 0 for a raw message.
@@ -121,15 +122,13 @@
  * @param c Connection this message belongs to (cannot be NULL).
  * @param ch Channel this message belongs to, if applicable (otherwise NULL).
  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
- * @param callback Function to be called once CORE has taken the message.
- * @param callback_cls Closure for @c callback.
+ * @param cont Continuation to be called once CORE has taken the message.
+ * @param cont_cls Closure for @c cont.
  */
 void
-GMP_queue_add (void *cls, uint16_t type, size_t size,
-               struct MeshConnection *c,
-               struct MeshChannel *ch,
-               int fwd,
-               GMP_sent callback, void *callback_cls);
+GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
+               struct MeshConnection *c, struct MeshChannel *ch, int fwd,
+               GMP_sent cont, void *cont_cls);
 
 /**
  * Cancel all queued messages to a peer that belong to a certain connection.




reply via email to

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