gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r29975 - gnunet/src/mesh
Date: Tue, 8 Oct 2013 12:30:26 +0200

Author: bartpolot
Date: 2013-10-08 12:30:26 +0200 (Tue, 08 Oct 2013)
New Revision: 29975

Modified:
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_connection.h
   gnunet/src/mesh/gnunet-service-mesh_local.c
   gnunet/src/mesh/gnunet-service-mesh_peer.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.h
Log:
- move all core/PeerIdentity interacting code to _peer, remove 
GNUNET_PeerIdentity from _connection


Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-08 09:59:46 UTC 
(rev 29974)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-08 10:30:26 UTC 
(rev 29975)
@@ -27,16 +27,12 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
-#include "gnunet_core_service.h"
-
 #include "gnunet-service-mesh_connection.h"
 #include "gnunet-service-mesh_peer.h"
-#include "gnunet-service-mesh_local.h"
 #include "mesh_protocol_enc.h"
 #include "mesh_path.h"
 
 
-#define MESH_DEBUG_CONNECTION   GNUNET_NO
 #define MESH_MAX_POLL_TIME      GNUNET_TIME_relative_multiply (\
                                   GNUNET_TIME_UNIT_MINUTES,\
                                   10)
@@ -44,13 +40,6 @@
 #define MESH_RETRANSMIT_MARGIN  4
 
 
-#if MESH_DEBUG_CONNECTION
-#define DEBUG_CONN(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
-#else
-#define DEBUG_CONN(...)
-#endif
-
-
 /**
  * All the states a connection can be in.
  */
@@ -281,10 +270,6 @@
  */
 static struct GNUNET_TIME_Relative refresh_connection_time;
 
-/**
- * Handle to communicate with core.
- */
-static struct GNUNET_CORE_Handle *core_handle;
 
 #if 0 // avoid compiler warning for unused static function
 static void
@@ -377,98 +362,6 @@
 
 
 /**
- * Sends an already built message on a connection, properly registering
- * all used resources.
- *
- * @param message Message to send. Function makes a copy of it.
- *                If message is not hop-by-hop, decrements TTL of copy.
- * @param c Connection on which this message is transmitted.
- * @param ch Channel on which this message is transmitted, or NULL.
- * @param fwd Is this a fwd message?
- */
-static void
-send_prebuilt_message_connection (const struct GNUNET_MessageHeader *message,
-                                  struct MeshConnection *c,
-                                  struct MeshChannel *ch,
-                                  int fwd)
-{
-  void *data;
-  size_t size;
-  uint16_t type;
-
-  size = ntohs (message->size);
-  data = GNUNET_malloc (size);
-  memcpy (data, message, size);
-  type = ntohs (message->type);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u) on connection %s\n",
-              GNUNET_MESH_DEBUG_M2S (type), size, GNUNET_h2s (&c->id));
-
-  switch (type)
-  {
-    struct GNUNET_MESH_Encrypted *emsg;
-    struct GNUNET_MESH_ACK       *amsg;
-    struct GNUNET_MESH_Poll      *pmsg;
-    struct GNUNET_MESH_ConnectionDestroy *dmsg;
-    struct GNUNET_MESH_ConnectionBroken  *bmsg;
-    uint32_t ttl;
-
-    case GNUNET_MESSAGE_TYPE_MESH_FWD:
-    case GNUNET_MESSAGE_TYPE_MESH_BCK:
-      emsg = (struct GNUNET_MESH_Encrypted *) data;
-      ttl = ntohl (emsg->ttl);
-      if (0 == ttl)
-      {
-        GNUNET_break_op (0);
-        return;
-      }
-      emsg->cid = c->id;
-      emsg->ttl = htonl (ttl - 1);
-      emsg->pid = htonl (fwd ? c->fwd_fc.next_pid++ : c->bck_fc.next_pid++);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " pid %u\n", ntohl (emsg->pid));
-      break;
-
-    case GNUNET_MESSAGE_TYPE_MESH_ACK:
-      amsg = (struct GNUNET_MESH_ACK *) data;
-      amsg->cid = c->id;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ntohl (amsg->ack));
-      break;
-
-    case GNUNET_MESSAGE_TYPE_MESH_POLL:
-      pmsg = (struct GNUNET_MESH_Poll *) data;
-      pmsg->cid = c->id;
-      pmsg->pid = htonl (fwd ? c->fwd_fc.last_pid_sent : 
c->bck_fc.last_pid_sent);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid));
-      break;
-
-    case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
-      dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data;
-      dmsg->cid = c->id;
-      dmsg->reserved = 0;
-      break;
-
-    case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
-      bmsg = (struct GNUNET_MESH_ConnectionBroken *) data;
-      bmsg->cid = c->id;
-      bmsg->reserved = 0;
-      break;
-
-    case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
-    case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
-      break;
-
-    default:
-      GNUNET_break (0);
-  }
-
-  queue_add (data,
-             type,
-             size,
-             c,
-             ch,
-             fwd);
-}
-
-/**
  * Send an ACK informing the predecessor about the available buffer space.
  *
  * Note that for fwd ack, the FWD mean forward *traffic* (root->dest),
@@ -1099,128 +992,6 @@
 
 
 /**
- * Method called whenever a given peer connects.
- *
- * @param cls closure
- * @param peer peer identity this notification is about
- */
-static void
-core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
-{
-  struct MeshPeer *pi;
-  struct MeshPeerPath *path;
-
-  DEBUG_CONN ("Peer connected\n");
-  DEBUG_CONN ("     %s\n", GNUNET_i2s (&my_full_id));
-  pi = peer_get (peer);
-  if (myid == pi->id)
-  {
-    DEBUG_CONN ("     (self)\n");
-    path = path_new (1);
-  }
-  else
-  {
-    DEBUG_CONN ("     %s\n", GNUNET_i2s (peer));
-    path = path_new (2);
-    path->peers[1] = pi->id;
-    GNUNET_PEER_change_rc (pi->id, 1);
-    GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
-  }
-  path->peers[0] = myid;
-  GNUNET_PEER_change_rc (myid, 1);
-  peer_add_path (pi, path, GNUNET_YES);
-
-  pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
-  return;
-}
-
-
-/**
- * Method called whenever a peer disconnects.
- *
- * @param cls closure
- * @param peer peer identity this notification is about
- */
-static void
-core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
-{
-  struct MeshPeer *pi;
-
-  DEBUG_CONN ("Peer disconnected\n");
-  pi = GNUNET_CONTAINER_multipeermap_get (peers, peer);
-  if (NULL == pi)
-  {
-    GNUNET_break (0);
-    return;
-  }
-
-  GNUNET_CONTAINER_multihashmap_iterate (pi->connections,
-                                         GMC_notify_broken,
-                                         pi);
-  GNUNET_CONTAINER_multihashmap_destroy (pi->connections);
-  pi->connections = NULL;
-  if (NULL != pi->core_transmit)
-    {
-      GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit);
-      pi->core_transmit = NULL;
-    }
-  if (myid == pi->id)
-  {
-    DEBUG_CONN ("     (self)\n");
-  }
-  GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO);
-
-  return;
-}
-
-
-
-/**
- * To be called on core init/fail.
- *
- * @param cls Closure (config)
- * @param identity the public identity of this peer
- */
-static void
-core_init (void *cls,
-           const struct GNUNET_PeerIdentity *identity)
-{
-  const struct GNUNET_CONFIGURATION_Handle *c = cls;
-  static int i = 0;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
-  if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                " core id %s\n",
-                GNUNET_i2s (identity));
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                " my id %s\n",
-                GNUNET_i2s (&my_full_id));
-    GNUNET_CORE_disconnect (core_handle);
-    core_handle = GNUNET_CORE_connect (c, /* Main configuration */
-                                       NULL,      /* Closure passed to MESH 
functions */
-                                       &core_init,        /* Call core_init 
once connected */
-                                       &core_connect,     /* Handle connects */
-                                       &core_disconnect,  /* remove peers on 
disconnects */
-                                       NULL,      /* Don't notify about all 
incoming messages */
-                                       GNUNET_NO, /* For header only in 
notification */
-                                       NULL,      /* Don't notify about all 
outbound messages */
-                                       GNUNET_NO, /* For header-only out 
notification */
-                                       core_handlers);    /* Register these 
handlers */
-    if (10 < i++)
-      GNUNET_abort();
-  }
-  GML_start ();
-  return;
-}
-
-
-
-
-
-/**
  * Core handler for connection creation.
  *
  * @param cls Closure (unused).
@@ -1998,6 +1769,61 @@
 }
 
 
+
+/**
+ * Initialize the connections subsystem
+ *
+ * @param c Configuration handle.
+ */
+void
+GMC_init (const struct GNUNET_CONFIGURATION_Handle *c)
+{
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE",
+                                             &max_msgs_queue))
+  {
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+                               "MESH", "MAX_MSGS_QUEUE", "MISSING");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_CONNECTIONS",
+                                             &max_connections))
+  {
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+                               "MESH", "MAX_CONNECTIONS", "MISSING");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_time (c, "MESH", 
"REFRESH_CONNECTION_TIME",
+                                           &refresh_connection_time))
+  {
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+                               "MESH", "REFRESH_CONNECTION_TIME", "MISSING");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
+}
+
+/**
+ * Shut down the connections subsystem.
+ */
+void
+GMC_shutdown (void)
+{
+  if (core_handle != NULL)
+  {
+    GNUNET_CORE_disconnect (core_handle);
+    core_handle = NULL;
+  }
+}
+
+
 struct MeshConnection *
 GMC_new (const struct GNUNET_HashCode *cid)
 {
@@ -2054,22 +1880,18 @@
 
 
 /**
- * Iterator to notify all connections of a broken link. Mark connections
+ * Notify other peers on a connection of a broken link. Mark connections
  * to destroy after all traffic has been sent.
  *
- * @param cls Closure (peer disconnected).
- * @param key Current key code (tid).
- * @param value Value in the hash map (connection).
- *
- * @return GNUNET_YES if we should continue to iterate,
- *         GNUNET_NO if not.
+ * @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).
  */
-int
-GMC_notify_broken (void *cls,
-                   const struct GNUNET_HashCode *key,
-                   void *value)
+void
+GMC_notify_broken (struct MeshConnection *c,
+                   struct MeshPeer *peer,
+                   struct GNUNET_PeerIdentity *my_full_id)
 {
-  struct MeshPeer *peer = cls;
   struct MeshConnection *c = value;
   struct GNUNET_MESH_ConnectionBroken msg;
   int fwd;
@@ -2087,9 +1909,9 @@
   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.peer1 = *my_full_id;
   msg.peer2 = *GNUNET_PEER_resolve2 (peer->id);
-  send_prebuilt_message_connection (&msg.header, c, NULL, fwd);
+  GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
   c->destroy = GNUNET_YES;
 
   return GNUNET_YES;
@@ -2097,77 +1919,6 @@
 
 
 /**
- * Initialize the connections subsystem
- *
- * @param c Configuration handle.
- */
-void
-GMC_init (const struct GNUNET_CONFIGURATION_Handle *c)
-{
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE",
-                                             &max_msgs_queue))
-  {
-    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
-                               "MESH", "MAX_MSGS_QUEUE", "MISSING");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_CONNECTIONS",
-                                             &max_connections))
-  {
-    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
-                               "MESH", "MAX_CONNECTIONS", "MISSING");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_time (c, "MESH", 
"REFRESH_CONNECTION_TIME",
-                                           &refresh_connection_time))
-  {
-    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
-                               "MESH", "REFRESH_CONNECTION_TIME", "MISSING");
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
-
-  core_handle = GNUNET_CORE_connect (c, /* Main configuration */
-                                     NULL,      /* Closure passed to MESH 
functions */
-                                     &core_init,        /* Call core_init once 
connected */
-                                     &core_connect,     /* Handle connects */
-                                     &core_disconnect,  /* remove peers on 
disconnects */
-                                     NULL,      /* Don't notify about all 
incoming messages */
-                                     GNUNET_NO, /* For header only in 
notification */
-                                     NULL,      /* Don't notify about all 
outbound messages */
-                                     GNUNET_NO, /* For header-only out 
notification */
-                                     core_handlers);    /* Register these 
handlers */
-  if (NULL == core_handle)
-  {
-    GNUNET_break (0);
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-}
-
-/**
- * Shut down the connections subsystem.
- */
-void
-GMC_shutdown (void)
-{
-  if (core_handle != NULL)
-  {
-    GNUNET_CORE_disconnect (core_handle);
-    core_handle = NULL;
-  }
-}
-
-
-/**
  * Is this peer the first one on the connection?
  *
  * @param c Connection.
@@ -2214,4 +1965,97 @@
   for (count = 0, iter = head; NULL != iter; iter = iter->next, count++);
 
   return count;
+}
+
+
+/**
+ * Sends an already built message on a connection, properly registering
+ * all used resources.
+ *
+ * @param message Message to send. Function makes a copy of it.
+ *                If message is not hop-by-hop, decrements TTL of copy.
+ * @param c Connection on which this message is transmitted.
+ * @param ch Channel on which this message is transmitted, or NULL.
+ * @param fwd Is this a fwd message?
+ */
+void
+GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
+                           struct MeshConnection *c,
+                           struct MeshChannel *ch,
+                           int fwd)
+{
+  void *data;
+  size_t size;
+  uint16_t type;
+
+  size = ntohs (message->size);
+  data = GNUNET_malloc (size);
+  memcpy (data, message, size);
+  type = ntohs (message->type);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u) on connection %s\n",
+              GNUNET_MESH_DEBUG_M2S (type), size, GNUNET_h2s (&c->id));
+
+  switch (type)
+  {
+    struct GNUNET_MESH_Encrypted *emsg;
+    struct GNUNET_MESH_ACK       *amsg;
+    struct GNUNET_MESH_Poll      *pmsg;
+    struct GNUNET_MESH_ConnectionDestroy *dmsg;
+    struct GNUNET_MESH_ConnectionBroken  *bmsg;
+    uint32_t ttl;
+
+    case GNUNET_MESSAGE_TYPE_MESH_FWD:
+    case GNUNET_MESSAGE_TYPE_MESH_BCK:
+      emsg = (struct GNUNET_MESH_Encrypted *) data;
+      ttl = ntohl (emsg->ttl);
+      if (0 == ttl)
+      {
+        GNUNET_break_op (0);
+        return;
+      }
+      emsg->cid = c->id;
+      emsg->ttl = htonl (ttl - 1);
+      emsg->pid = htonl (fwd ? c->fwd_fc.next_pid++ : c->bck_fc.next_pid++);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " pid %u\n", ntohl (emsg->pid));
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_ACK:
+      amsg = (struct GNUNET_MESH_ACK *) data;
+      amsg->cid = c->id;
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ntohl (amsg->ack));
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_POLL:
+      pmsg = (struct GNUNET_MESH_Poll *) data;
+      pmsg->cid = c->id;
+      pmsg->pid = htonl (fwd ? c->fwd_fc.last_pid_sent : 
c->bck_fc.last_pid_sent);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid));
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
+      dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data;
+      dmsg->cid = c->id;
+      dmsg->reserved = 0;
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
+      bmsg = (struct GNUNET_MESH_ConnectionBroken *) data;
+      bmsg->cid = c->id;
+      bmsg->reserved = 0;
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
+    case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
+      break;
+
+    default:
+      GNUNET_break (0);
+  }
+
+  GMP_queue_add (data,
+                 type,
+                 size,
+                 c,
+                 ch,
+                 fwd);
 }
\ No newline at end of file

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-08 09:59:46 UTC 
(rev 29974)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.h    2013-10-08 10:30:26 UTC 
(rev 29975)
@@ -109,20 +109,17 @@
 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
 
 /**
- * Iterator to notify all connections of a broken link. Mark connections
+ * Notify other peers on a connection of a broken link. Mark connections
  * to destroy after all traffic has been sent.
  *
- * @param cls Closure (peer disconnected).
- * @param key Current key code (tid).
- * @param value Value in the hash map (connection).
- *
- * @return GNUNET_YES if we should continue to iterate,
- *         GNUNET_NO if not.
+ * @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).
  */
-int
-GMC_notify_broken (void *cls,
-                   const struct GNUNET_HashCode *key,
-                   void *value);
+void
+GMC_notify_broken (struct MeshConnection *c,
+                   struct MeshPeer *peer,
+                   struct GNUNET_PeerIdentity *my_full_id);
 
 /**
  * @brief Queue and pass message to core when possible.
@@ -192,6 +189,21 @@
 int
 GMC_is_terminal (struct MeshConnection *c, int fwd);
 
+/**
+ * Sends an already built message on a connection, properly registering
+ * all used resources.
+ *
+ * @param message Message to send. Function makes a copy of it.
+ *                If message is not hop-by-hop, decrements TTL of copy.
+ * @param c Connection on which this message is transmitted.
+ * @param ch Channel on which this message is transmitted, or NULL.
+ * @param fwd Is this a fwd message?
+ */
+void
+GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
+                           struct MeshConnection *c,
+                           struct MeshChannel *ch,
+                           int fwd);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

Modified: gnunet/src/mesh/gnunet-service-mesh_local.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_local.c 2013-10-08 09:59:46 UTC (rev 
29974)
+++ gnunet/src/mesh/gnunet-service-mesh_local.c 2013-10-08 10:30:26 UTC (rev 
29975)
@@ -22,7 +22,9 @@
 #include "platform.h"
 #include "mesh_enc.h"
 #include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared
+
 #include "gnunet-service-mesh_local.h"
+#include "gnunet-service-mesh_tunnel.h"
 
 
/******************************************************************************/
 /********************************   STRUCTS  
**********************************/
@@ -394,7 +396,7 @@
     msgcc.port = msg->port;
     msgcc.opt = msg->opt;
 
-    tunnel_queue_data (t, ch, &msgcc.header, GNUNET_YES);
+    GMT_queue_data (t, ch, &msgcc.header, GNUNET_YES);
   }
 
   GNUNET_SERVER_receive_done (client, GNUNET_OK);

Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-08 09:59:46 UTC (rev 
29974)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c  2013-10-08 10:30:26 UTC (rev 
29975)
@@ -22,9 +22,12 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
+#include "gnunet_core_service.h"
+
 #include "gnunet-service-mesh_peer.h"
 #include "gnunet-service-mesh_dht.h"
 #include "gnunet-service-mesh_connection.h"
+#include "gnunet-service-mesh_local.h"
 #include "mesh_path.h"
 
 
/******************************************************************************/
@@ -112,12 +115,162 @@
  */
 static unsigned long long drop_percent;
 
+/**
+ * Handle to communicate with core.
+ */
+static struct GNUNET_CORE_Handle *core_handle;
+
+/**
+ * Local peer own ID (full value).
+ */
+const static struct GNUNET_PeerIdentity *my_full_id;
+
 
/******************************************************************************/
 /***************************** CORE CALLBACKS 
*********************************/
 
/******************************************************************************/
 
 
 /**
+ * Iterator to notify all connections of a broken link. Mark connections
+ * to destroy after all traffic has been sent.
+ *
+ * @param cls Closure (peer disconnected).
+ * @param key Current key code (peer id).
+ * @param value Value in the hash map (connection).
+ *
+ * @return GNUNET_YES if we should continue to iterate,
+ *         GNUNET_NO if not.
+ */
+static int
+notify_broken (void *cls,
+               const struct GNUNET_HashCode *key,
+               void *value)
+{
+  struct MeshPeer *peer = cls;
+  struct MeshConnection *c = value;
+
+  GMC_notify_broken (c, peer, my_full_id);
+
+  return GNUNET_YES;
+}
+
+/**
+ * Method called whenever a given peer connects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct MeshPeer *pi;
+  struct MeshPeerPath *path;
+
+  LOG ("Peer connected\n");
+  LOG ("     %s\n", GNUNET_i2s (&my_full_id));
+  pi = peer_get (peer);
+  if (myid == pi->id)
+  {
+    DEBUG_CONN ("     (self)\n");
+    path = path_new (1);
+  }
+  else
+  {
+    DEBUG_CONN ("     %s\n", GNUNET_i2s (peer));
+    path = path_new (2);
+    path->peers[1] = pi->id;
+    GNUNET_PEER_change_rc (pi->id, 1);
+    GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
+  }
+  path->peers[0] = myid;
+  GNUNET_PEER_change_rc (myid, 1);
+  peer_add_path (pi, path, GNUNET_YES);
+
+  pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
+  return;
+}
+
+
+/**
+ * Method called whenever a peer disconnects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  struct MeshPeer *pi;
+
+  DEBUG_CONN ("Peer disconnected\n");
+  pi = GNUNET_CONTAINER_multipeermap_get (peers, peer);
+  if (NULL == pi)
+  {
+    GNUNET_break (0);
+    return;
+  }
+
+  GNUNET_CONTAINER_multihashmap_iterate (pi->connections, &notify_broken, pi);
+  GNUNET_CONTAINER_multihashmap_destroy (pi->connections);
+  pi->connections = NULL;
+  if (NULL != pi->core_transmit)
+    {
+      GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit);
+      pi->core_transmit = NULL;
+    }
+  if (myid == pi->id)
+  {
+    DEBUG_CONN ("     (self)\n");
+  }
+  GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO);
+
+  return;
+}
+
+
+
+/**
+ * To be called on core init/fail.
+ *
+ * @param cls Closure (config)
+ * @param identity the public identity of this peer
+ */
+static void
+core_init (void *cls,
+           const struct GNUNET_PeerIdentity *identity)
+{
+  const struct GNUNET_CONFIGURATION_Handle *c = cls;
+  static int i = 0;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
+  if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                " core id %s\n",
+                GNUNET_i2s (identity));
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                " my id %s\n",
+                GNUNET_i2s (&my_full_id));
+    GNUNET_CORE_disconnect (core_handle);
+    core_handle = GNUNET_CORE_connect (c, /* Main configuration */
+                                       NULL,      /* Closure passed to MESH 
functions */
+                                       &core_init,        /* Call core_init 
once connected */
+                                       &core_connect,     /* Handle connects */
+                                       &core_disconnect,  /* remove peers on 
disconnects */
+                                       NULL,      /* Don't notify about all 
incoming messages */
+                                       GNUNET_NO, /* For header only in 
notification */
+                                       NULL,      /* Don't notify about all 
outbound messages */
+                                       GNUNET_NO, /* For header-only out 
notification */
+                                       core_handlers);    /* Register these 
handlers */
+    if (10 < i++)
+      GNUNET_abort();
+  }
+  GML_start ();
+  return;
+}
+
+/**
   * Core callback to write a pre-constructed data packet to core buffer
   *
   * @param cls Closure (MeshTransmissionDescriptor with data in "data" member).
@@ -1145,10 +1298,13 @@
  * Initialize the peer subsystem.
  *
  * @param c Configuration.
+ * @param id Peer identity
  */
 void
-GMP_init (const struct GNUNET_CONFIGURATION_Handle *c)
+GMP_init (const struct GNUNET_CONFIGURATION_Handle *c,
+          const struct GNUNET_PeerIdentity *id)
 {
+  my_full_id = id;
   peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS",
@@ -1174,6 +1330,23 @@
                 "Remove the DROP_PERCENT option from your configuration.\n"
                 "***************************************\n");
   }
+
+  core_handle = GNUNET_CORE_connect (c, /* Main configuration */
+                                     NULL,      /* Closure passed to MESH 
functions */
+                                     &core_init,        /* Call core_init once 
connected */
+                                     &core_connect,     /* Handle connects */
+                                     &core_disconnect,  /* remove peers on 
disconnects */
+                                     NULL,      /* Don't notify about all 
incoming messages */
+                                     GNUNET_NO, /* For header only in 
notification */
+                                     NULL,      /* Don't notify about all 
outbound messages */
+                                     GNUNET_NO, /* For header-only out 
notification */
+                                     core_handlers);    /* Register these 
handlers */
+  if (NULL == core_handle)
+  {
+    GNUNET_break (0);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
 }
 
 /**

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-08 09:59:46 UTC 
(rev 29974)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-08 10:30:26 UTC 
(rev 29975)
@@ -21,6 +21,8 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
+#include "mesh_protocol_enc.h"
+
 #include "gnunet-service-mesh_tunnel.h"
 #include "gnunet-service-mesh_connection.h"
 #include "gnunet-service-mesh_channel.h"
@@ -370,11 +372,11 @@
  * @param msg Message itself (copy will be made).
  * @param fwd Is this fwd?
  */
-static void
-tunnel_queue_data (struct MeshTunnel2 *t,
-                   struct MeshChannel *ch,
-                   struct GNUNET_MessageHeader *msg,
-                   int fwd)
+void
+GMT_queue_data (struct MeshTunnel2 *t,
+                struct MeshChannel *ch,
+                struct GNUNET_MessageHeader *msg,
+                int fwd)
 {
   struct MeshTunnelQueue *tq;
   uint16_t size = ntohs (msg->size);
@@ -476,8 +478,8 @@
  * @param t Tunnel whose state to change.
  * @param state New state.
  */
-static void
-tunnel_change_state (struct MeshTunnel2* t, enum MeshTunnelState state)
+void
+GMT_change_state (struct MeshTunnel2* t, enum MeshTunnelState state)
 {
   if (NULL == t)
     return;
@@ -657,7 +659,7 @@
  * @return Short ID of the peer disconnected (either p1 or p2).
  *         0 if the tunnel remained unaffected.
  */
-static GNUNET_PEER_Id
+GNUNET_PEER_Id
 GMT_notify_connection_broken (struct MeshTunnel2* t,
                               GNUNET_PEER_Id p1, GNUNET_PEER_Id p2)
 {
@@ -850,5 +852,5 @@
   }
   msg->reserved = 0;
 
-  send_prebuilt_message_connection (&msg->header, c, ch, fwd);
+  GMC_send_prebuilt_message (&msg->header, c, ch, fwd);
 }

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.h        2013-10-08 09:59:46 UTC 
(rev 29974)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.h        2013-10-08 10:30:26 UTC 
(rev 29975)
@@ -68,7 +68,30 @@
 void
 GMT_shutdown (void);
 
+/**
+ * Change the tunnel state.
+ *
+ * @param t Tunnel whose state to change.
+ * @param state New state.
+ */
+void
+GMT_change_state (struct MeshTunnel2* t, enum MeshTunnelState state);
 
+
+/**
+ * Cache a message to be sent once tunnel is online.
+ *
+ * @param t Tunnel to hold the message.
+ * @param ch Channel the message is about.
+ * @param msg Message itself (copy will be made).
+ * @param fwd Is this fwd?
+ */
+void
+GMT_queue_data (struct MeshTunnel2 *t,
+                struct MeshChannel *ch,
+                struct GNUNET_MessageHeader *msg,
+                int fwd);
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif




reply via email to

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