- fix connection.c
authorBart Polot <bart@net.in.tum.de>
Thu, 10 Oct 2013 15:35:30 +0000 (15:35 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 10 Oct 2013 15:35:30 +0000 (15:35 +0000)
src/mesh/gnunet-service-mesh_connection.c
src/mesh/gnunet-service-mesh_peer.c
src/mesh/gnunet-service-mesh_peer.h
src/mesh/gnunet-service-mesh_tunnel.c
src/mesh/gnunet-service-mesh_tunnel.h

index 06ca072e9967e64b921e975c6360d18a878b5634..2a0cfbc174d8070230b16697808e96d683b39621 100644 (file)
@@ -1023,8 +1023,8 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
     connection_change_state (c, MESH_CONNECTION_SENT);
 
   /* Remember peers */
-  dest_peer = peer_get (&id[size - 1]);
-  orig_peer = peer_get (&id[0]);
+  dest_peer = GMP_get (&id[size - 1]);
+  orig_peer = GMP_get (&id[0]);
 
   /* Is it a connection to us? */
   if (c->own_pos == size - 1)
@@ -1032,12 +1032,8 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  It's for us!\n");
     GMP_add_path_to_origin (orig_peer, path, GNUNET_YES);
 
-    if (NULL == orig_peer->tunnel)
-    {
-      orig_peer->tunnel = GMT_new ();
-      orig_peer->tunnel->peer = orig_peer;
-    }
-    GMT_add_connection (orig_peer->tunnel, c);
+    GMP_add_tunnel (orig_peer);
+    GMP_add_connection (orig_peer, c);
     if (MESH_TUNNEL3_NEW == GMT_get_state (c->t))
       GMT_change_state (c->t,  MESH_TUNNEL3_WAITING);
 
index 42717b8eba18c50a395d95e16dbd912c9cfe7a68..21ddf6592380607e971c960bc5a31f00be6446dd 100644 (file)
@@ -139,7 +139,7 @@ struct MeshPeer
     /**
      * Tunnel to this peer, if any.
      */
-  struct MeshTunnel2 *tunnel;
+  struct MeshTunnel3 *tunnel;
 
     /**
      * Connections that go through this peer, indexed by tid;
@@ -252,7 +252,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 
   LOG ("Peer connected\n");
   LOG ("     %s\n", GNUNET_i2s (&my_full_id));
-  pi = peer_get (peer);
+  pi = GMP_get (peer);
   if (myid == pi->id)
   {
     LOG ("     (self)\n");
@@ -461,7 +461,7 @@ static size_t
 send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf)
 {
   struct GNUNET_MESH_ConnectionACK *msg = buf;
-  struct MeshTunnel2 *t = c->t;
+  struct MeshTunnel3 *t = c->t;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION ACK...\n");
   GNUNET_assert (NULL != t);
@@ -501,7 +501,7 @@ shutdown_tunnel (void *cls,
                  void *value)
 {
   struct MeshPeer *p = value;
-  struct MeshTunnel2 *t = p->tunnel;
+  struct MeshTunnel3 *t = p->tunnel;
 
   if (NULL != t)
     GMT_destroy (t);
@@ -646,52 +646,6 @@ peer_delete_oldest (void)
 }
 
 
-/**
- * Retrieve the MeshPeer stucture associated with the peer, create one
- * and insert it in the appropriate structures if the peer is not known yet.
- *
- * @param peer Full identity of the peer.
- *
- * @return Existing or newly created peer info.
- */
-static struct MeshPeer *
-peer_get (const struct GNUNET_PeerIdentity *peer_id)
-{
-  struct MeshPeer *peer;
-
-  peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id);
-  if (NULL == peer)
-  {
-    peer = GNUNET_new (struct MeshPeer);
-    if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers)
-    {
-      peer_delete_oldest ();
-    }
-        GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer,
-                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-        peer->id = GNUNET_PEER_intern (peer_id);
-  }
-    peer->last_contact = GNUNET_TIME_absolute_get();
-
-    return peer;
-}
-
-
-/**
- * Retrieve the MeshPeer stucture associated with the peer, create one
- * and insert it in the appropriate structures if the peer is not known yet.
- *
- * @param peer Short identity of the peer.
- *
- * @return Existing or newly created peer info.
- */
-static struct MeshPeer *
-peer_get_short (const GNUNET_PEER_Id peer)
-{
-  return peer_get (GNUNET_PEER_resolve2 (peer));
-}
-
-
 /**
  * Get a cost of a path for a peer considering existing tunnel connections.
  *
@@ -818,7 +772,7 @@ queue_send (void *cls, size_t size, void *buf)
   struct MeshConnection *c;
   struct GNUNET_MessageHeader *msg;
   struct MeshPeerQueue *queue;
-  struct MeshTunnel2 *t;
+  struct MeshTunnel3 *t;
   struct MeshChannel *ch;
   const struct GNUNET_PeerIdentity *dst_id;
   size_t data_size;
@@ -1434,6 +1388,50 @@ GMP_shutdown (void)
   GNUNET_PEER_change_rc (myid, -1);
 }
 
+/**
+ * Retrieve the MeshPeer stucture associated with the peer, create one
+ * and insert it in the appropriate structures if the peer is not known yet.
+ *
+ * @param peer Full identity of the peer.
+ *
+ * @return Existing or newly created peer structure.
+ */
+struct MeshPeer *
+GMP_get (const struct GNUNET_PeerIdentity *peer_id)
+{
+  struct MeshPeer *peer;
+
+  peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id);
+  if (NULL == peer)
+  {
+    peer = GNUNET_new (struct MeshPeer);
+    if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers)
+    {
+      peer_delete_oldest ();
+    }
+        GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer,
+                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+        peer->id = GNUNET_PEER_intern (peer_id);
+  }
+    peer->last_contact = GNUNET_TIME_absolute_get();
+
+    return peer;
+}
+
+
+/**
+ * Retrieve the MeshPeer stucture associated with the peer, create one
+ * and insert it in the appropriate structures if the peer is not known yet.
+ *
+ * @param peer Short identity of the peer.
+ *
+ * @return Existing or newly created peer structure.
+ */
+struct MeshPeer *
+GMP_get_short (const GNUNET_PEER_Id peer)
+{
+  return GMP_get (GNUNET_PEER_resolve2 (peer));
+}
 
 /**
  * Try to establish a new connection to this peer in the given tunnel.
@@ -1445,7 +1443,7 @@ GMP_shutdown (void)
 void
 GMP_connect (struct MeshPeer *peer)
 {
-  struct MeshTunnel2 *t;
+  struct MeshTunnel3 *t;
   struct MeshPeerPath *p;
   struct MeshConnection *c;
   int rerun_search;
@@ -1520,7 +1518,7 @@ GMP_connect (struct MeshPeer *peer)
  * @param t Tunnel.
  */
 void
-GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel2 *t)
+GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t)
 {
   peer->tunnel = t;
 }
@@ -1552,6 +1550,22 @@ GMP_is_neighbor (const struct MeshPeer *peer)
 }
 
 
+/**
+ * Create and initialize a new tunnel towards a peer, in case it has none.
+ *
+ * Does not generate any traffic, just creates the local data structures.
+ *
+ * @param peer Peer towards which to create the tunnel.
+ */
+void
+GMP_add_tunnel (struct MeshPeer *peer)
+{
+  if (NULL != peer->tunnel)
+    return;
+  peer->tunnel = GMT_new (peer);
+}
+
+
 /**
  * Add a connection to a neighboring peer.
  *
@@ -1707,7 +1721,7 @@ GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed)
     struct MeshPeer *aux;
     struct MeshPeerPath *copy;
 
-    aux = peer_get_short (p->peers[i]);
+    aux = GMP_get_short (p->peers[i]);
     copy = path_duplicate (p);
     copy->length = i + 1;
     GMP_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed);
index 1918a78421fb1ebbb51ddfa2ee6a47ca4ff25650..4cd108b3095d9838dbb16088df089d36d55fdf68 100644 (file)
@@ -77,6 +77,30 @@ GMP_init (const struct GNUNET_CONFIGURATION_Handle *c);
 void
 GMP_shutdown (void);
 
+
+/**
+ * Retrieve the MeshPeer stucture associated with the peer, create one
+ * and insert it in the appropriate structures if the peer is not known yet.
+ *
+ * @param peer Full identity of the peer.
+ *
+ * @return Existing or newly created peer structure.
+ */
+struct MeshPeer *
+GMP_get (const struct GNUNET_PeerIdentity *peer_id);
+
+
+/**
+ * Retrieve the MeshPeer stucture associated with the peer, create one
+ * and insert it in the appropriate structures if the peer is not known yet.
+ *
+ * @param peer Short identity of the peer.
+ *
+ * @return Existing or newly created peer structure.
+ */
+struct MeshPeer *
+GMP_get_short (const GNUNET_PEER_Id peer);
+
 /**
  * @brief Queue and pass message to core when possible.
  *
@@ -128,6 +152,15 @@ GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t);
 int
 GMP_is_neighbor (const struct MeshPeer *peer);
 
+/**
+ * Create and initialize a new tunnel towards a peer, in case it has none.
+ *
+ * Does not generate any traffic, just creates the local data structures.
+ *
+ * @param peer Peer towards which to create the tunnel.
+ */
+void
+GMP_add_tunnel (struct MeshPeer *peer);
 
 /**
  * Add a connection to a neighboring peer.
@@ -142,7 +175,7 @@ GMP_is_neighbor (const struct MeshPeer *peer);
  * @return GNUNET_OK on success.
  */
 int
-GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
+GMP_add_connection (struct MeshPeer *peer, const struct MeshConnection *c);
 
 /**
  * Add the path to the peer and update the path used to reach it in case this
index bd57956adb12ed94d6fc04c4d02a486139f797d3..286eca61847ca404fc8a5a56807cd180f034f5a5 100644 (file)
@@ -573,14 +573,17 @@ GMT_shutdown (void)
 
 /**
  * Create a tunnel.
+ *
+ * @param destination Peer this tunnel is towards.
  */
 struct MeshTunnel3 *
-GMT_new (void)
+GMT_new (struct MeshPeer *destination)
 {
   struct MeshTunnel3 *t;
 
   t = GNUNET_new (struct MeshTunnel3);
   t->next_chid = 0;
+  t->peer = destination;
 //   if (GNUNET_OK !=
 //       GNUNET_CONTAINER_multihashmap_put (tunnels, tid, t,
 //                                          GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
index 6ec94ed531c8419d865c606907a091307f4002d7..f966fb2fe87385ca1106420e7899f5008e4fc39d 100644 (file)
@@ -101,6 +101,14 @@ GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
 void
 GMT_shutdown (void);
 
+/**
+ * Create a tunnel.
+ *
+ * @param destination Peer this tunnel is towards.
+ */
+struct MeshTunnel3 *
+GMT_new (struct MeshPeer *destination);
+
 /**
  * Tunnel is empty: destroy it.
  *