gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r30141 - gnunet/src/mesh
Date: Fri, 11 Oct 2013 15:30:44 +0200

Author: bartpolot
Date: 2013-10-11 15:30:43 +0200 (Fri, 11 Oct 2013)
New Revision: 30141

Modified:
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_connection.h
   gnunet/src/mesh/gnunet-service-mesh_peer.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
Log:
- fix "broken connection" notifications


Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-11 13:25:48 UTC 
(rev 30140)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-11 13:30:43 UTC 
(rev 30141)
@@ -217,6 +217,11 @@
 extern GNUNET_PEER_Id myid;
 
 /**
+ * Local peer own ID (full value).
+ */
+extern struct GNUNET_PeerIdentity my_full_id;
+
+/**
  * Connections known, indexed by cid (MeshConnection).
  */
 static struct GNUNET_CONTAINER_MultiHashMap *connections;
@@ -1157,24 +1162,53 @@
 
 
 /**
+ * Is traffic coming from this sender 'FWD' traffic?
+ *
+ * @param c Connection to check.
+ * @param sender Peer identity of neighbor.
+ *
+ * @return GNUNET_YES in case the sender is the 'prev' hop and therefore
+ *         the traffic is 'FWD'. GNUNET_NO for BCK. GNUNET_SYSERR for errors.
+ */
+int 
+is_fwd (const struct MeshConnection *c,
+        const struct GNUNET_PeerIdentity *sender)
+{
+  GNUNET_PEER_Id id;
+
+  id = GNUNET_PEER_search (sender);
+  if (GMP_get_short_id (get_prev_hop (c)) == id)
+    return GNUNET_YES;
+
+  if (GMP_get_short_id (get_next_hop (c)) == id)
+    return GNUNET_NO;
+
+  GNUNET_break (0);
+  return GNUNET_SYSERR;
+}
+
+
+/**
  * Core handler for notifications of broken paths
  *
  * @param cls Closure (unused).
- * @param peer Peer identity of sending neighbor.
+ * @param id Peer identity of sending neighbor.
  * @param message Message.
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 int
-GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
-                   const struct GNUNET_MessageHeader *message)
+GMC_handle_broken (void* cls,
+                   const struct GNUNET_PeerIdentity* id,
+                   const struct GNUNET_MessageHeader* message)
 {
   struct GNUNET_MESH_ConnectionBroken *msg;
   struct MeshConnection *c;
+  int fwd;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "Received a CONNECTION BROKEN msg from %s\n", GNUNET_i2s (peer));
+              "Received a CONNECTION BROKEN msg from %s\n", GNUNET_i2s (id));
   msg = (struct GNUNET_MESH_ConnectionBroken *) message;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  regarding %s\n",
               GNUNET_i2s (&msg->peer1));
@@ -1186,8 +1220,22 @@
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
-  tunnel_notify_connection_broken (c->t, GNUNET_PEER_search (&msg->peer1),
-                                   GNUNET_PEER_search (&msg->peer2));
+
+  fwd = is_fwd (c, id);
+  connection_cancel_queues (c, !fwd);
+  if (GMC_is_terminal (c, fwd))
+  {
+    if (0 < c->pending_messages)
+      c->destroy = GNUNET_YES;
+    else
+      GMC_destroy (c);
+  }
+  else
+  {
+    GMC_send_prebuilt_message (message, c, NULL, fwd);
+    c->destroy = GNUNET_YES;
+  }
+
   return GNUNET_OK;
 
 }
@@ -1209,7 +1257,6 @@
 {
   struct GNUNET_MESH_ConnectionDestroy *msg;
   struct MeshConnection *c;
-  GNUNET_PEER_Id id;
   int fwd;
 
   msg = (struct GNUNET_MESH_ConnectionDestroy *) message;
@@ -1230,12 +1277,8 @@
                               1, GNUNET_NO);
     return GNUNET_OK;
   }
-  id = GNUNET_PEER_search (peer);
-  if (id == GMP_get_short_id (get_prev_hop (c)))
-    fwd = GNUNET_YES;
-  else if (id == GMP_get_short_id (get_next_hop (c)))
-    fwd = GNUNET_NO;
-  else
+  fwd = is_fwd (c, peer);
+  if (GNUNET_SYSERR == fwd)
   {
     GNUNET_break_op (0);
     return GNUNET_OK;
@@ -1875,19 +1918,40 @@
 
 
 /**
+ * Send a notification that a connection is broken.
+ *
+ * @param c Connection that is broken.
+ * @param id1 Peer that has disconnected.
+ * @param id2 Peer that has disconnected.
+ * @param fwd Direction towards which to send it.
+ */
+static void
+send_broken (struct MeshConnection *c,
+             const struct GNUNET_PeerIdentity *id1,
+             const struct GNUNET_PeerIdentity *id2,
+             int fwd)
+{
+  struct GNUNET_MESH_ConnectionBroken msg;
+
+  msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
+  msg.cid = c->id;
+  msg.peer1 = *id1;
+  msg.peer2 = *id2;
+  GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
+}
+
+/**
  * Notify other peers on a connection of a broken link. Mark connections
  * to destroy after all traffic has been sent.
  *
  * @param c Connection on which there has been a disconnection.
  * @param peer Peer that disconnected.
- * @param my_full_id My ID (to send to other peers).
  */
 void
 GMC_notify_broken (struct MeshConnection *c,
-                   struct MeshPeer *peer,
-                   struct GNUNET_PeerIdentity *my_full_id)
+                   struct MeshPeer *peer)
 {
-  struct GNUNET_MESH_ConnectionBroken msg;
   int fwd;
 
   fwd = peer == get_prev_hop (c);
@@ -1900,12 +1964,11 @@
     return;
   }
 
-  msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
-  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
-  msg.cid = c->id;
-  msg.peer1 = *my_full_id;
-  msg.peer2 = *GMP_get_id (peer);
-  GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
+  send_broken (c, &my_full_id, GMP_get_id (peer), fwd);
+
+  /* Connection will have at least one pending message
+   * (the one we just scheduled), so no point in checking whether to
+   * destroy immediately. */
   c->destroy = GNUNET_YES;
 
   return;

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-11 13:25:48 UTC 
(rev 30140)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-11 13:30:43 UTC 
(rev 30141)
@@ -110,15 +110,16 @@
  * Core handler for notifications of broken paths
  *
  * @param cls Closure (unused).
- * @param peer Peer identity of sending neighbor.
+ * @param id Peer identity of sending neighbor.
  * @param message Message.
  *
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 int
-GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
-                   const struct GNUNET_MessageHeader *message);
+GMC_handle_broken (void* cls,
+                   const struct GNUNET_PeerIdentity* id,
+                   const struct GNUNET_MessageHeader* message);
 
 /**
  * Core handler for tunnel destruction
@@ -340,12 +341,10 @@
  *
  * @param c Connection on which there has been a disconnection.
  * @param peer Peer that disconnected.
- * @param my_full_id My ID (to send to other peers).
  */
 void
 GMC_notify_broken (struct MeshConnection *c,
-                   struct MeshPeer *peer,
-                   struct GNUNET_PeerIdentity *my_full_id);
+                   struct MeshPeer *peer);
 
 /**
  * Is this peer the first one on the connection?

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-11 13:25:48 UTC (rev 
30140)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-11 13:30:43 UTC (rev 
30141)
@@ -232,7 +232,7 @@
   struct MeshPeer *peer = cls;
   struct MeshConnection *c = value;
 
-  GMC_notify_broken (c, peer, &my_full_id);
+  GMC_notify_broken (c, peer);
 
   return GNUNET_YES;
 }

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-11 13:25:48 UTC 
(rev 30140)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-11 13:30:43 UTC 
(rev 30141)
@@ -827,48 +827,6 @@
 
 
 /**
- * Notifies a tunnel that a connection has broken that affects at least
- * some of its peers. Sends a notification towards the root of the tree.
- * In case the peer is the owner of the tree, notifies the client that owns
- * the tunnel and tries to reconnect.
- *
- * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
- *
- * @param t Tunnel affected.
- * @param p1 Peer that got disconnected from p2.
- * @param p2 Peer that got disconnected from p1.
- *
- * @return Short ID of the peer disconnected (either p1 or p2).
- *         0 if the tunnel remained unaffected.
- */
-GNUNET_PEER_Id
-GMT_notify_connection_broken (struct MeshTunnel3* t,
-                              GNUNET_PEER_Id p1, GNUNET_PEER_Id p2)
-{
-//   if (myid != p1 && myid != p2) FIXME
-//   {
-//     return;
-//   }
-//
-//   if (tree_get_predecessor (t->tree) != 0)
-//   {
-//     /* We are the peer still connected, notify owner of the disconnection. 
*/
-//     struct GNUNET_MESH_PathBroken msg;
-//     struct GNUNET_PeerIdentity neighbor;
-//
-//     msg.header.size = htons (sizeof (msg));
-//     msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN);
-//     GNUNET_PEER_resolve (t->id.oid, &msg.oid);
-//     msg.tid = htonl (t->id.tid);
-//     msg.peer1 = my_full_id;
-//     GNUNET_PEER_resolve (pid, &msg.peer2);
-//     GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &neighbor);
-//     send_prebuilt_message (&msg.header, &neighbor, t);
-//   }
-  return 0;
-}
-
-/**
  * @brief Use the given path for the tunnel.
  * Update the next and prev hops (and RCs).
  * (Re)start the path refresh in case the tunnel is locally owned.




reply via email to

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