gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r16599 - gnunet/src/mesh
Date: Mon, 22 Aug 2011 19:35:25 +0200

Author: bartpolot
Date: 2011-08-22 19:35:24 +0200 (Mon, 22 Aug 2011)
New Revision: 16599

Modified:
   gnunet/src/mesh/Makefile.am
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api_new.c
   gnunet/src/mesh/test_mesh_api.c
   gnunet/src/mesh/test_mesh_small.c
   gnunet/src/mesh/test_mesh_small.conf
Log:
Various changes, can't get indent to work


Modified: gnunet/src/mesh/Makefile.am
===================================================================
--- gnunet/src/mesh/Makefile.am 2011-08-22 11:58:34 UTC (rev 16598)
+++ gnunet/src/mesh/Makefile.am 2011-08-22 17:35:24 UTC (rev 16599)
@@ -9,6 +9,8 @@
   XLIB = -lgcov
 endif
 
+AM_CLFAGS = -g
+
 bin_PROGRAMS = \
  gnunet-service-mesh
 
@@ -67,7 +69,7 @@
   libgnunetmeshnew.la
 
 if ENABLE_TEST_RUN
-TESTS = test_mesh_api
+TESTS = test_mesh_small
 endif
 
 EXTRA_DIST = \

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-08-22 11:58:34 UTC (rev 
16598)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-08-22 17:35:24 UTC (rev 
16599)
@@ -55,7 +55,7 @@
 #include "mesh_protocol.h"
 #include "gnunet_dht_service.h"
 
-#define MESH_DEBUG              0
+#define MESH_DEBUG              GNUNET_YES
 
 #if MESH_DEBUG
 /**
@@ -70,7 +70,7 @@
   {
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s", s);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s", s);
 }
 #endif
 
@@ -462,6 +462,7 @@
  */
 GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
 
+
 
/******************************************************************************/
 /******************      GENERAL HELPER FUNCTIONS      
************************/
 
/******************************************************************************/
@@ -818,7 +819,7 @@
   GNUNET_PEER_resolve (myid, &id);
   for (i = 0; i < n_applications; i++)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting PUT for app %d\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %d\n",
                 applications[i]);
     *p = htonl (applications[i]);
     GNUNET_CRYPTO_hash (buffer, 12, &hash);
@@ -829,7 +830,7 @@
                                               APP_ANNOUNCE_TIME),
                     APP_ANNOUNCE_TIME,
 #if MESH_DEBUG
-                    &mesh_debug, "DHT_put for app completed\n");
+                    &mesh_debug, "MESH: DHT_put for app completed\n");
 #else
                     NULL, NULL);
 #endif
@@ -909,7 +910,7 @@
 
   if (0 == size && NULL == buf)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting create path\n");
     GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id);
     GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
                                        GNUNET_TIME_UNIT_FOREVER_REL, &id,
@@ -1293,7 +1294,7 @@
   struct MeshPeerInfo *orig_peer_info;
   struct MeshTunnel *t;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a MESH path create msg\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a MESH path create 
msg\n");
   size = ntohs (message->size);
   if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
   {
@@ -1324,7 +1325,7 @@
 
   if (NULL == t)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tunnel\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n");
     t = GNUNET_malloc (sizeof (struct MeshTunnel));
     t->id.oid = GNUNET_PEER_intern (pi);
     t->id.tid = tid;
@@ -1993,7 +1994,7 @@
   unsigned int i;
   unsigned int j;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n");
   c = clients;
   while (NULL != c)
   {
@@ -2044,12 +2045,12 @@
     }
     else
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   ... searching\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:    ... searching\n");
       c = c->next;
     }
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "   done!\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:    done!\n");
   return;
 }
 
@@ -2074,7 +2075,7 @@
   uint16_t j;
   int known;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n");
   /* Check data sanity */
   size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
   cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
@@ -2136,7 +2137,7 @@
       }
     }
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u+%u subscriptions\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:  client has %u+%u 
subscriptions\n",
               c->type_counter, c->app_counter);
 
   GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c);
@@ -2704,7 +2705,7 @@
            const struct GNUNET_PeerIdentity *identity,
            const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n");
   core_handle = server;
   myid = GNUNET_PEER_intern (identity);
   announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls);
@@ -2726,11 +2727,11 @@
   struct MeshPeerInfo *peer_info;
   struct MeshPath *path;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n");
   peer_info = get_peer_info (peer);
   if (myid == peer_info->id)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "     (self)\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:      (self)\n");
   }
   path = GNUNET_malloc (sizeof (struct MeshPath));
   path->length = 2;
@@ -2753,7 +2754,7 @@
   struct MeshPeerInfo *pi;
   unsigned int i;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer disconnected\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer disconnected\n");
   pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
   if (!pi)
   {
@@ -2771,7 +2772,7 @@
   }
   if (myid == pi->id)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "     (self)\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH:      (self)\n");
   }
   return;
 }
@@ -2790,7 +2791,7 @@
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shutting down\n");
   if (core_handle != NULL)
   {
     GNUNET_CORE_disconnect (core_handle);
@@ -2806,7 +2807,11 @@
     GNUNET_SERVER_notification_context_destroy (nc);
     nc = NULL;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
+  if (0 != announce_id_task) {
+      GNUNET_SCHEDULER_cancel(announce_id_task);
+      announce_id_task = 0;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shut down\n");
 }
 
 /**
@@ -2820,7 +2825,7 @@
 run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: starting to run\n");
   GNUNET_SERVER_add_handlers (server, plugin_handlers);
   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
   server_handle = server;
@@ -2868,7 +2873,7 @@
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
                                 NULL);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of run()\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: end of run()\n");
 }
 
 /**
@@ -2883,10 +2888,11 @@
 {
   int ret;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: main()\n");
   ret =
       (GNUNET_OK ==
        GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, 
&run,
                            NULL)) ? 0 : 1;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of main()\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: main() END\n");
   return ret;
 }

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-08-22 11:58:34 UTC (rev 16598)
+++ gnunet/src/mesh/mesh_api_new.c      2011-08-22 17:35:24 UTC (rev 16599)
@@ -26,8 +26,9 @@
  * STRUCTURE:
  * - CONSTANTS
  * - DATA STRUCTURES
+ * - AUXILIARY FUNCTIONS
+ * - RECEIVE HANDLERS
  * - SEND CALLBACKS
- * - RECEIVE HANDLERS
  * - API CALL DEFINITIONS
  */
 
@@ -185,7 +186,208 @@
 }
 
 
+
 
/******************************************************************************/
+/***********************      RECEIVE HANDLERS     
****************************/
+/******************************************************************************/
+
+/**
+ * Process the new tunnel notification and add it to the tunnels in the handle
+ * 
+ * @param h     The mesh handle
+ * @param msg   A message with the details of the new incoming tunnel
+ */
+static void
+process_tunnel_create (struct GNUNET_MESH_Handle *h,
+                       const struct GNUNET_MESH_TunnelMessage *msg)
+{
+    struct GNUNET_MESH_Tunnel *t;
+    MESH_TunnelNumber tid;
+
+    tid = ntohl (msg->tunnel_id);
+    if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "MESH: received an incoming tunnel with tid in local range 
(%X)\n",
+                    tid);
+                    GNUNET_break_op (0);
+                    return;                     //FIXME abort? reconnect?
+    }
+    t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel));
+    t->cls = h->cls;
+    t->mesh = h;
+    t->tid = tid;
+
+    return;
+}
+
+
+/**
+ * Process the new peer event and notify the upper level of it
+ * 
+ * @param h     The mesh handle
+ * @param msg   A message with the details of the peer event
+ */
+static void
+process_peer_event (struct GNUNET_MESH_Handle *h,
+                    const struct GNUNET_MESH_PeerControl *msg)
+{
+    struct GNUNET_MESH_Tunnel *t;
+    uint16_t size;
+
+    size = ntohs (msg->header.size);
+    if (size != sizeof (struct GNUNET_MESH_PeerControl))
+    {
+        GNUNET_break_op (0);
+        return;
+    }
+    t = retrieve_tunnel (h, ntohl (msg->tunnel_id));
+    if (NULL == t)
+    {
+        GNUNET_break_op (0);
+        return;
+    }
+    if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type)
+    {
+        if (NULL != t->connect_handler)
+        {
+            t->connect_handler (t->cls, &msg->peer, NULL);    /* FIXME atsi */
+        }
+    }
+    else
+    {
+        if (NULL != t->disconnect_handler)
+        {
+            t->disconnect_handler (t->cls, &msg->peer);
+        }
+    }
+}
+
+
+/**
+ * Process the incoming data packets
+ * 
+ * @param h     The mesh handle
+ * @param msh   A message encapsulating the data
+ */
+static void
+process_incoming_data (struct GNUNET_MESH_Handle *h,
+                       const struct GNUNET_MessageHeader *message)
+{
+    const struct GNUNET_MessageHeader *payload;
+    const struct GNUNET_MESH_MessageHandler *handler;
+    const struct GNUNET_PeerIdentity *peer;
+    struct GNUNET_MESH_Unicast *ucast;
+    struct GNUNET_MESH_Multicast *mcast;
+    struct GNUNET_MESH_ToOrigin *to_orig;
+    struct GNUNET_MESH_Tunnel *t;
+    uint16_t type;
+    int i;
+
+    type = ntohs (message->type);
+    switch (type)
+    {
+        case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+            ucast = (struct GNUNET_MESH_Unicast *) message;
+            t = retrieve_tunnel (h, ntohl (ucast->tid));
+            payload = (struct GNUNET_MessageHeader *) &ucast[1];
+            peer = &ucast->oid;
+            break;
+        case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+            mcast = (struct GNUNET_MESH_Multicast *) message;
+            t = retrieve_tunnel (h, ntohl (mcast->tid));
+            payload = (struct GNUNET_MessageHeader *) &mcast[1];
+            peer = &mcast->oid;
+            break;
+        case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+            to_orig = (struct GNUNET_MESH_ToOrigin *) message;
+            t = retrieve_tunnel (h, ntohl (to_orig->tid));
+            payload = (struct GNUNET_MessageHeader *) &to_orig[1];
+            peer = &to_orig->sender;
+            break;
+        default:
+            GNUNET_break_op (0);
+            return;
+    }
+    if (NULL == t)
+    {
+        GNUNET_break_op (0);
+        return;
+    }
+    for (i = 0; i < h->n_handlers; i++)
+    {
+        handler = &h->message_handlers[i];
+        if (handler->type == type)
+        {
+            if (GNUNET_OK == handler->callback (h->cls, t, NULL,      /* FIXME 
ctx */
+                peer, payload, NULL)) /* FIXME atsi */
+            {
+                GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                            "MESH: callback completed successfully\n");
+            }
+            else
+            {
+                GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                            "MESH: callback caused disconnection\n");
+                GNUNET_MESH_disconnect (h);
+            }
+        }
+    }
+    return;
+}
+
+
+/**
+ * Function to process all messages received from the service
+ *
+ * @param cls closure
+ * @param msg message received, NULL on timeout or fatal error
+ */
+static void
+msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
+{
+    struct GNUNET_MESH_Handle *h = cls;
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "mesh: received a message from MESH\n");
+    if (msg == NULL)
+    {
+        GNUNET_break_op (0);
+        return;
+    }
+
+    switch (ntohs (msg->type))
+    {
+        /* Notify of a new incoming tunnel */
+        case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
+            process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) 
msg);
+            break;
+            /* Notify of a new peer or a peer disconnect in the tunnel */
+            case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED:
+            case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED:
+                process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg);
+                break;
+                /* Notify of a new data packet in the tunnel */
+                case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+                case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
+                case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+                    process_incoming_data (h, msg);
+                    break;
+                    /* We shouldn't get any other packages, log and ignore */
+                    default:
+                        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                                    "MESH: unsolicited message form service 
(type %d)\n",
+                                    ntohs (msg->type));
+    }
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n");
+    GNUNET_CLIENT_receive (h->client, &msg_received, h,
+                           GNUNET_TIME_UNIT_FOREVER_REL);
+    return;
+}
+
+
+/******************************************************************************/
 /************************       SEND CALLBACKS     
****************************/
 
/******************************************************************************/
 
@@ -204,62 +406,67 @@
 static size_t
 send_connect_packet (void *cls, size_t size, void *buf)
 {
-  struct GNUNET_MESH_Handle *h = cls;
-  struct GNUNET_MESH_ClientConnect *msg;
-  uint16_t *types;
-  uint16_t ntypes;
-  GNUNET_MESH_ApplicationType *apps;
-  uint16_t napps;
+    struct GNUNET_MESH_Handle           *h = cls;
+    struct GNUNET_MESH_ClientConnect    *msg;
+    GNUNET_MESH_ApplicationType         *apps;
+    uint16_t                            napps;
+    uint16_t                            *types;
+    uint16_t                            ntypes;
 
-  h->th = NULL;
-  if (0 == size || buf == NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Send connect packet: buffer size 0 or buffer invalid\n");
-    // FIXME: disconnect, reconnect, retry!
-    return 0;
-  }
-  if (sizeof (struct GNUNET_MessageHeader) > size)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Send connect packet: buffer size too small\n");
-    // FIXME: disconnect, reconnect, retry!
-    return 0;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Send connect packet: %lu bytes buffer\n", size);
-  msg = (struct GNUNET_MESH_ClientConnect *) buf;
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "mesh: Send connect packet()\n", size);
+    h->th = NULL;
+    if (0 == size || NULL == buf)
+    {
+        // FIXME: disconnect, reconnect, retry?
+        return 0;
+    }
+    if (sizeof (struct GNUNET_MessageHeader) > size)
+    {
+        GNUNET_break(0);
+        // FIXME: disconnect, reconnect, retry!
+        return 0;
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "mesh: Send connect packet: %lu bytes buffer\n", size);
+    msg = (struct GNUNET_MESH_ClientConnect *) buf;
+    msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
 
-  for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++)
-  {
-    types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1));
-    types[ntypes] = h->message_handlers[ntypes].type;
-  }
+    for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++)
+    {
+        types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1));
+        types[ntypes] = h->message_handlers[ntypes].type;
+    }
 
-  for (napps = 0, apps = NULL; napps < h->n_applications; napps++)
-  {
-    apps =
-        GNUNET_realloc (apps,
-                        sizeof (GNUNET_MESH_ApplicationType) * (napps + 1));
-    apps[napps] = h->applications[napps];
-  }
+    for (napps = 0, apps = NULL; napps < h->n_applications; napps++)
+    {
+        apps =
+            GNUNET_realloc (apps,
+                            sizeof (GNUNET_MESH_ApplicationType) * (napps + 
1));
+        apps[napps] = h->applications[napps];
+    }
 
-  msg->header.size =
-      htons (sizeof (struct GNUNET_MESH_ClientConnect) +
-             sizeof (uint16_t) * ntypes +
-             sizeof (GNUNET_MESH_ApplicationType) * napps);
+    msg->header.size =
+        htons (sizeof (struct GNUNET_MESH_ClientConnect) +
+                sizeof (uint16_t) * ntypes +
+                sizeof (GNUNET_MESH_ApplicationType) * napps);
 
-  memcpy (&msg[1], types, sizeof (uint16_t) * ntypes);
-  memcpy (&msg[1] + sizeof (uint16_t) * ntypes, apps,
-          sizeof (GNUNET_MESH_ApplicationType) * napps);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sent %lu bytes long message %d types and %d apps\n",
-              ntohs (msg->header.size), ntypes, napps);
-  msg->applications = htons (napps);
-  msg->types = htons (ntypes);
+    memcpy (&msg[1], types, sizeof (uint16_t) * ntypes);
+    memcpy (&msg[1] + sizeof (uint16_t) * ntypes, apps,
+            sizeof (GNUNET_MESH_ApplicationType) * napps);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "mesh: Sent %lu bytes long message %d types and %d apps\n",
+                ntohs (msg->header.size), ntypes, napps);
+    msg->applications = htons (napps);
+    msg->types = htons (ntypes);
 
-  return ntohs (msg->header.size);
+    /* start listening */
+    GNUNET_CLIENT_receive (h->client, &msg_received, h,
+                           GNUNET_TIME_UNIT_FOREVER_REL);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "mesh: Send connect packet() END\n", size);
+
+    return ntohs (msg->header.size);
 }
 
 
@@ -285,22 +492,19 @@
   h->th = NULL;
   if (0 == size || buf == NULL)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Send connect packet: buffer size 0 or buffer invalid\n");
-    // FIXME: disconnect, reconnect, retry!
+    // FIXME: disconnect, reconnect, retry?
     return 0;
   }
-  if (sizeof (struct GNUNET_MessageHeader) > size)
+  if (sizeof (struct GNUNET_MESH_TunnelMessage) > size)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Send connect packet: buffer size too small\n");
-    // FIXME: disconnect, reconnect, retry!
+    GNUNET_break(0);
+    // FIXME: disconnect, reconnect, retry?
     return 0;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Send connect packet: %lu bytes buffer\n", size);
+              "Send create tunnel packet: %lu bytes buffer\n", size);
   msg = (struct GNUNET_MESH_TunnelMessage *) buf;
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
 
   msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
   msg->tunnel_id = htonl (t->tid);
@@ -308,207 +512,56 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n",
               ntohs (msg->header.size));
 
-  return ntohs (msg->header.size);
+  return sizeof (struct GNUNET_MESH_TunnelMessage);
 }
 
 
-/******************************************************************************/
-/***********************      RECEIVE HANDLERS     
****************************/
-/******************************************************************************/
-
 /**
- * Process the new tunnel notification and add it to the tunnels in the handle
- * 
- * @param h     The mesh handle
- * @param msg   A message with the details of the new incoming tunnel
+ * Function called to send a destroy tunnel message, specifying the tunnel
+ * number chosen by the client.
+ * "buf" will be NULL and "size" zero if the socket was closed for
+ * writing in the meantime.
+ *
+ * @param cls closure, the tunnel handle
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the create tunnel message
+ * @return number of bytes written to buf
  */
-static void
-process_tunnel_create (struct GNUNET_MESH_Handle *h,
-                       const struct GNUNET_MESH_TunnelMessage *msg)
+static size_t
+send_tunnel_destroy_packet (void *cls, size_t size, void *buf)
 {
-  struct GNUNET_MESH_Tunnel *t;
-  MESH_TunnelNumber tid;
+    struct GNUNET_MESH_Tunnel           *t = cls;
+    struct GNUNET_MESH_Handle           *h;
+    struct GNUNET_MESH_TunnelMessage    *msg;
 
-  tid = ntohl (msg->tunnel_id);
-  if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "MESH: received an incoming tunnel with tid in local range 
(%X)\n",
-                tid);
-    GNUNET_break_op (0);
-    return;                     //FIXME abort? reconnect?
-  }
-  t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel));
-  t->cls = h->cls;
-  t->mesh = h;
-  t->tid = tid;
-
-  return;
-}
-
-
-/**
- * Process the new peer event and notify the upper level of it
- * 
- * @param h     The mesh handle
- * @param msg   A message with the details of the peer event
- */
-static void
-process_peer_event (struct GNUNET_MESH_Handle *h,
-                    const struct GNUNET_MESH_PeerControl *msg)
-{
-  struct GNUNET_MESH_Tunnel *t;
-  uint16_t size;
-
-  size = ntohs (msg->header.size);
-  if (size != sizeof (struct GNUNET_MESH_PeerControl))
-  {
-    GNUNET_break_op (0);
-    return;
-  }
-  t = retrieve_tunnel (h, ntohl (msg->tunnel_id));
-  if (NULL == t)
-  {
-    GNUNET_break_op (0);
-    return;
-  }
-  if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type)
-  {
-    if (NULL != t->connect_handler)
+    h = t->mesh;
+    h->th = NULL;
+    if (0 == size || buf == NULL)
     {
-      t->connect_handler (t->cls, &msg->peer, NULL);    /* FIXME atsi */
+        return 0;
     }
-  }
-  else
-  {
-    if (NULL != t->disconnect_handler)
+    if (sizeof (struct GNUNET_MESH_TunnelMessage) > size)
     {
-      t->disconnect_handler (t->cls, &msg->peer);
+        GNUNET_break(0);
+        // FIXME: disconnect, reconnect, retry!
+        return 0;
     }
-  }
-}
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Send tunnel destroy packet: %lu bytes buffer\n", size);
+    msg = (struct GNUNET_MESH_TunnelMessage *) buf;
+    msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
 
+    msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
+    msg->tunnel_id = htonl (t->tid);
 
-/**
- * Process the incoming data packets
- * 
- * @param h     The mesh handle
- * @param msh   A message encapsulating the data
- */
-static void
-process_incoming_data (struct GNUNET_MESH_Handle *h,
-                       const struct GNUNET_MessageHeader *message)
-{
-  const struct GNUNET_MessageHeader *payload;
-  const struct GNUNET_MESH_MessageHandler *handler;
-  const struct GNUNET_PeerIdentity *peer;
-  struct GNUNET_MESH_Unicast *ucast;
-  struct GNUNET_MESH_Multicast *mcast;
-  struct GNUNET_MESH_ToOrigin *to_orig;
-  struct GNUNET_MESH_Tunnel *t;
-  uint16_t type;
-  int i;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n",
+                ntohs (msg->header.size));
+    GNUNET_free(t);
 
-  type = ntohs (message->type);
-  switch (type)
-  {
-  case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
-    ucast = (struct GNUNET_MESH_Unicast *) message;
-    t = retrieve_tunnel (h, ntohl (ucast->tid));
-    payload = (struct GNUNET_MessageHeader *) &ucast[1];
-    peer = &ucast->oid;
-    break;
-  case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
-    mcast = (struct GNUNET_MESH_Multicast *) message;
-    t = retrieve_tunnel (h, ntohl (mcast->tid));
-    payload = (struct GNUNET_MessageHeader *) &mcast[1];
-    peer = &mcast->oid;
-    break;
-  case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
-    to_orig = (struct GNUNET_MESH_ToOrigin *) message;
-    t = retrieve_tunnel (h, ntohl (to_orig->tid));
-    payload = (struct GNUNET_MessageHeader *) &to_orig[1];
-    peer = &to_orig->sender;
-    break;
-  default:
-    GNUNET_break_op (0);
-    return;
-  }
-  if (NULL == t)
-  {
-    GNUNET_break_op (0);
-    return;
-  }
-  for (i = 0; i < h->n_handlers; i++)
-  {
-    handler = &h->message_handlers[i];
-    if (handler->type == type)
-    {
-      if (GNUNET_OK == handler->callback (h->cls, t, NULL,      /* FIXME ctx */
-                                          peer, payload, NULL)) /* FIXME atsi 
*/
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "MESH: callback completed successfully\n");
-      }
-      else
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "MESH: callback caused disconnection\n");
-        GNUNET_MESH_disconnect (h);
-      }
-    }
-  }
-  return;
+    return sizeof (struct GNUNET_MESH_TunnelMessage);
 }
 
 
-/**
- * Function to process all messages received from the service
- *
- * @param cls closure
- * @param msg message received, NULL on timeout or fatal error
- */
-static void
-msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
-{
-  struct GNUNET_MESH_Handle *h = cls;
-
-  if (msg == NULL)
-  {
-    GNUNET_break_op (0);
-    return;
-  }
-
-  switch (ntohs (msg->type))
-  {
-    /* Notify of a new incoming tunnel */
-  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
-    process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg);
-    break;
-    /* Notify of a new peer or a peer disconnect in the tunnel */
-  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED:
-  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED:
-    process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg);
-    break;
-    /* Notify of a new data packet in the tunnel */
-  case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
-  case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
-  case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
-    process_incoming_data (h, msg);
-    break;
-    /* We shouldn't get any other packages, log and ignore */
-  default:
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "MESH: unsolicited message form service (type %d)\n",
-                ntohs (msg->type));
-  }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received a message from mesh\n");
-  GNUNET_CLIENT_receive (h->client, &msg_received, h,
-                         GNUNET_TIME_UNIT_FOREVER_REL);
-  return;
-}
-
 
/******************************************************************************/
 /**********************      API CALL DEFINITIONS     
*************************/
 
/******************************************************************************/
@@ -534,17 +587,17 @@
                      const struct GNUNET_MESH_MessageHandler *handlers,
                      const GNUNET_MESH_ApplicationType *stypes)
 {
-  struct GNUNET_MESH_Handle *h;
-  size_t size;
+  struct GNUNET_MESH_Handle     *h;
+  size_t                        size;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n");
   h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
 
   h->cleaner = cleaner;
   h->client = GNUNET_CLIENT_connect ("mesh", cfg);
-  GNUNET_CLIENT_receive (h->client, &msg_received, h,
-                         GNUNET_TIME_UNIT_FOREVER_REL);
   if (h->client == NULL)
   {
+    GNUNET_break(0);
     GNUNET_free (h);
     return NULL;
   }
@@ -561,11 +614,18 @@
   size += h->n_handlers * sizeof (uint16_t);
   size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType);
 
+  if (NULL != h->th) {
+      /* FIXME implement queue system instead */
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "mesh: overwriting th of mesh\n");
+      GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+  }
   h->th =
       GNUNET_CLIENT_notify_transmit_ready (h->client, size,
                                            GNUNET_TIME_UNIT_FOREVER_REL,
                                            GNUNET_YES, &send_connect_packet,
                                            (void *) h);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n");
 
   return h;
 }
@@ -608,7 +668,7 @@
 {
   struct GNUNET_MESH_Tunnel *tunnel;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating new tunnel\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n");
   tunnel = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel));
 
   tunnel->connect_handler = connect_handler;
@@ -617,7 +677,12 @@
   tunnel->mesh = h;
   tunnel->tid = h->next_tid++;
   h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK;      // keep in range
-
+  if (NULL != h->th) {
+      /* FIXME implement queue system instead */
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                 "mesh: overwriting th of mesh\n");
+      GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+  }
   h->th =
       GNUNET_CLIENT_notify_transmit_ready (h->client,
                                            sizeof (struct
@@ -632,6 +697,32 @@
 
 
 /**
+ * Destroy an existing tunnel.
+ *
+ * @param tun tunnel handle
+ */
+void
+GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun)
+{
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
+    if (NULL != tun->mesh->th) {
+        /* FIXME implement queue system instead */
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+                   "mesh: overwriting th of mesh\n");
+        GNUNET_CLIENT_notify_transmit_ready_cancel(tun->mesh->th);
+    }
+    tun->mesh->th = GNUNET_CLIENT_notify_transmit_ready (
+                                         tun->mesh->client,
+                                         sizeof (struct
+                                         GNUNET_MESH_TunnelMessage),
+                                         GNUNET_TIME_UNIT_FOREVER_REL,
+                                         GNUNET_YES,
+                                         &send_tunnel_destroy_packet,
+                                         (void *) tun);
+}
+
+
+/**
  * Request that a peer should be added to the tunnel.  The existing
  * connect handler will be called ONCE with either success or failure.
  *

Modified: gnunet/src/mesh/test_mesh_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_api.c     2011-08-22 11:58:34 UTC (rev 16598)
+++ gnunet/src/mesh/test_mesh_api.c     2011-08-22 17:35:24 UTC (rev 16599)
@@ -67,25 +67,33 @@
 static void
 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+    fprintf(stderr, "++++++++ STARTING SHUTDOWN\n");
+    fprintf(stderr, "+++++++++ ABORT TASK\n");
   if (0 != abort_task)
   {
     GNUNET_SCHEDULER_cancel (abort_task);
   }
+  fprintf(stderr, "+++++++++ DISCONNECT MESH\n");
   if (NULL != mesh)
   {
     GNUNET_MESH_disconnect (mesh);
   }
+  fprintf(stderr, "+++++++++ KILL PROCESS\n");
   if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
   }
+  fprintf(stderr, "+++++++++ WAIT\n");
   GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
+  fprintf(stderr, "+++++++++ PROCESS CLOSE\n");
   GNUNET_OS_process_close (arm_pid);
+  fprintf(stderr, "++++++++ END SHUTDOWN\n");
 }
 
 static void
 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+    fprintf(stderr, "++++++++ STARTING ABORT\n");
   if (0 != test_task)
   {
     GNUNET_SCHEDULER_cancel (test_task);
@@ -93,19 +101,18 @@
   result = GNUNET_SYSERR;
   abort_task = 0;
   do_shutdown (cls, tc);
+  fprintf(stderr, "++++++++ END ABORT\n");
 }
 
 static void
 test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
-  GNUNET_MESH_ApplicationType app[3];
+  static const GNUNET_MESH_ApplicationType app[] = {1,2,3,0};
 
+  fprintf(stderr, "++++++++ STARTING TEST\n");
   test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
-  app[0] = (GNUNET_MESH_ApplicationType) 1;
-  app[1] = (GNUNET_MESH_ApplicationType) 2;
-  app[2] = (GNUNET_MESH_ApplicationType) 0;
-  mesh = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, &app);
+  mesh = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, app);
   if (NULL == mesh)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
@@ -116,9 +123,8 @@
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
   }
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown,
-                                NULL);
+  GNUNET_SCHEDULER_add_delayed 
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), &do_shutdown, 
NULL);
+  fprintf(stderr, "++++++++ END TEST\n");
 }
 
 
@@ -126,6 +132,14 @@
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+    fprintf(stderr, "++++++++ STARTING RUN\n");
+  GNUNET_log_setup ("test_mesh_small",
+#if VERBOSE
+                      "DEBUG",
+#else
+                      "WARNING",
+#endif
+                      NULL);
   arm_pid =
       GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm",
@@ -138,11 +152,10 @@
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort,
                                     NULL);
-  test_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 1), &test,
-                                    (void *) cfg);
+    test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &test, 
(void *)cfg);
+//       GNUNET_SCHEDULER_add_now (&test, (void *)cfg);
 
+      fprintf(stderr, "++++++++ END RUN\n");
 }
 
 
@@ -150,7 +163,6 @@
 main (int argc, char *argv[])
 {
   int ret;
-
   char *const argv2[] = { "test-mesh-api",
     "-c", "test_mesh.conf",
 #if VERBOSE
@@ -161,13 +173,8 @@
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-  GNUNET_log_setup ("test-mesh-api",
-#if VERBOSE
-                    "DEBUG",
-#else
-                    "WARNING",
-#endif
-                    NULL);
+
+  fprintf(stderr, "++++++++ STARTING TEST_API\n");
   ret =
       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
                           "test-mesh-api", "nohelp", options, &run, NULL);
@@ -183,5 +190,7 @@
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
     return 1;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n");
+  fprintf(stderr, "++++++++ END TEST_API\n");
   return 0;
 }

Modified: gnunet/src/mesh/test_mesh_small.c
===================================================================
--- gnunet/src/mesh/test_mesh_small.c   2011-08-22 11:58:34 UTC (rev 16598)
+++ gnunet/src/mesh/test_mesh_small.c   2011-08-22 17:35:24 UTC (rev 16599)
@@ -24,9 +24,10 @@
  */
 #include "platform.h"
 #include "gnunet_testing_lib.h"
-#include "gnunet_mesh_service.h"
+#include "gnunet_mesh_service_new.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
+#define REMOVE_DIR GNUNET_YES
 
 struct MeshPeer
 {
@@ -179,37 +180,105 @@
   if (data_file != NULL)
     GNUNET_DISK_file_close (data_file);
   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+  GNUNET_CONFIGURATION_destroy(testing_cfg);
 }
 
 
+/**
+ * Handlers, for diverse services
+ */
+static struct GNUNET_MESH_MessageHandler handlers[] = {
+//    {&callback, 1, 0},
+    {NULL, 0, 0}
+};
+
+
+/**
+ * Function called whenever an inbound tunnel is destroyed.  Should clean up
+ * any associated state.
+ *
+ * @param cls closure (set from GNUNET_MESH_connect)
+ * @param tunnel connection to the other end (henceforth invalid)
+ * @param tunnel_ctx place where local state associated
+ *                   with the tunnel is stored
+ */
 static void
+tunnel_cleaner (void *cls,
+                const struct GNUNET_MESH_Tunnel * tunnel,
+                void **tunnel_ctx)
+{
+#if VERBOSE
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "tunnel disconnected\n");
+#endif
+    return;
+}
+
+/**
+ * Method called whenever a tunnel falls apart.
+ *
+ * @param cls closure
+ * @param peer peer identity the tunnel stopped working with
+ */
+static void
+dh (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "peer disconnected\n");
+    return;
+}
+
+
+/**
+ * Method called whenever a tunnel is established.
+ *
+ * @param cls closure
+ * @param peer peer identity the tunnel was created to, NULL on timeout
+ * @param atsi performance data for the connection
+ */
+static void
+ch (void *cls,
+    const struct GNUNET_PeerIdentity * peer,
+    const struct GNUNET_TRANSPORT_ATS_Information * atsi)
+{
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "peer connected\n");
+    return;
+}
+
+
+/**
+ * connect_mesh_service: connect to the mesh service of one of the peers
+ * 
+ */
+static void
 connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-//   struct NSEPeer *current_peer;
-  unsigned int i;
+    struct GNUNET_TESTING_Daemon        *d;
+    struct GNUNET_MESH_Handle           *h;
+    struct GNUNET_MESH_Tunnel           *t;
+    GNUNET_MESH_ApplicationType         app;
 
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "connect_mesh_service\n");
+
+    d = GNUNET_TESTING_daemon_get(pg, 1);
+    app = (GNUNET_MESH_ApplicationType) 0;
+
 #if VERBOSE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mesh service of 
peers\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "connecting to mesh service of peer %s\n",
+                GNUNET_i2s(&d->id));
 #endif
-  for (i = 0; i < num_peers; i++)
-  {
-//       if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 
0))
-    continue;
+    h = GNUNET_MESH_connect(d->cfg, NULL, &tunnel_cleaner, handlers, &app);
 #if VERBOSE
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "test_mesh_small: connecting to mesh service of peer %d\n", i);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "connected to mesh service of peer %s\n",
+                GNUNET_i2s(&d->id));
 #endif
-/*      current_peer = GNUNET_malloc(sizeof(struct NSEPeer));
-      current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i);
-      if (GNUNET_YES == 
GNUNET_TESTING_daemon_running(GNUNET_TESTING_daemon_get(pg, i)))
-        {
-          current_peer->nse_handle = GNUNET_NSE_connect 
(current_peer->daemon->cfg,
-                                                        &handle_estimate, 
-                                                        current_peer);
-          GNUNET_assert(current_peer->nse_handle != NULL);
-        }
-      GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);*/
-  }
+    t = GNUNET_MESH_tunnel_create(h, &ch, &dh, NULL);
+    GNUNET_MESH_tunnel_destroy(t);
+    GNUNET_MESH_disconnect(h);
 }
 
 
@@ -412,40 +481,47 @@
 }
 
 
+/**
+ * peergroup_ready: start test when all peers are connected
+ * @param cls closure
+ * @param emsg error message
+ */
 static void
-my_cb (void *cls, const char *emsg)
+peergroup_ready (void *cls, const char *emsg)
 {
-  char *buf;
-  int buf_len;
+    char        *buf;
+    int         buf_len;
 
-  if (emsg != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peergroup callback called with error, aborting test!\n");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
-    ok = 1;
-    GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
-    return;
-  }
+    if (emsg != NULL)
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Peergroup callback called with error, aborting test!\n");
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
+        ok = 1;
+        GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+        return;
+    }
+
 #if VERBOSE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n");
 #endif
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
-              total_connections);
-  if (data_file != NULL)
-  {
-    buf = NULL;
-    buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
-    if (buf_len > 0)
-      GNUNET_DISK_file_write (data_file, buf, buf_len);
-    GNUNET_free (buf);
-  }
-  peers_running = GNUNET_TESTING_daemons_running (pg);
 
-  GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
-  disconnect_task =
-      GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
+                total_connections);
+    if (data_file != NULL)
+    {
+        buf = NULL;
+        buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", 
total_connections);
+        if (buf_len > 0)
+        GNUNET_DISK_file_write (data_file, buf, buf_len);
+        GNUNET_free (buf);
+    }
+    peers_running = GNUNET_TESTING_daemons_running (pg);
 
+    GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
+    disconnect_task =
+        GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
+
 }
 
 
@@ -476,97 +552,121 @@
 }
 
 
+/**
+ * run: load configuration options and schedule test to run (start peergroup)
+ * @param cls closure
+ * @param args argv
+ * @param cfgfile configuration file name (can be NULL)
+ * @param cfg configuration handle
+ */
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  char *temp_str;
-  unsigned long long temp_wait;
-  struct GNUNET_TESTING_Host *hosts;
+    char                        *temp_str;
+    unsigned long long          temp_wait;
+    struct GNUNET_TESTING_Host  *hosts;
 
-  ok = 1;
-  testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg;     // 
GNUNET_CONFIGURATION_create();
+    ok = 1;
+    testing_cfg = GNUNET_CONFIGURATION_dup(cfg);
+
+    GNUNET_log_setup ("test_mesh_small",
 #if VERBOSE
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
-  GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
-                                         "use_progressbars", "YES");
+                      "DEBUG",
+#else
+                      "WARNING",
 #endif
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
-                                             "num_peers", &num_peers))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Option TESTING:NUM_PEERS is required!\n");
-    return;
-  }
+                      NULL);
 
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
-                                             "wait_time", &temp_wait))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Option nsetest_mesh_small:wait_time is required!\n");
-    return;
-  }
+#if VERBOSE
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
+    GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
+                                            "use_progressbars", "YES");
+#endif
 
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing",
-                                             "topology_output_file",
-                                             &topology_file))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Option test_mesh_small:topology_output_file is required!\n");
-    return;
-  }
+    if (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
+                                                "num_peers", &num_peers))
+    {
+        GNUNET_CONFIGURATION_load(testing_cfg, "test_mesh_small.conf");
+        if (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
+                                                "num_peers", &num_peers))
+        {
+            GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                        "Option TESTING:NUM_PEERS is required!\n");
+            return;
+        }
+    }
 
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
-                                             "data_output_file",
-                                             &data_filename))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Option test_mesh_small:data_output_file is required!\n");
-    return;
-  }
+    if (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
+                                                "wait_time", &temp_wait))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Option nsetest_mesh_small:wait_time is required!\n");
+        return;
+    }
 
-  data_file =
-      GNUNET_DISK_file_open (data_filename,
-                             GNUNET_DISK_OPEN_READWRITE |
-                             GNUNET_DISK_OPEN_CREATE,
-                             GNUNET_DISK_PERM_USER_READ |
-                             GNUNET_DISK_PERM_USER_WRITE);
-  if (data_file == NULL)
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
-                data_filename);
-  GNUNET_free (data_filename);
+    if (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing",
+                                                "topology_output_file",
+                                                &topology_file))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Option test_mesh_small:topology_output_file is 
required!\n");
+        return;
+    }
 
-  wait_time =
-      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
+    if (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
+                                                "data_output_file",
+                                                &data_filename))
+    {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Option test_mesh_small:data_output_file is required!\n");
+        return;
+    }
 
-  if (GNUNET_YES ==
-      GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
-                                             "output_file", &temp_str))
-  {
-    output_file =
-        GNUNET_DISK_file_open (temp_str,
-                               GNUNET_DISK_OPEN_READWRITE |
-                               GNUNET_DISK_OPEN_CREATE,
-                               GNUNET_DISK_PERM_USER_READ |
-                               GNUNET_DISK_PERM_USER_WRITE);
-    if (output_file == NULL)
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
-                  temp_str);
-  }
-  GNUNET_free_non_null (temp_str);
+    data_file = GNUNET_DISK_file_open (data_filename,
+                                        GNUNET_DISK_OPEN_READWRITE |
+                                        GNUNET_DISK_OPEN_CREATE,
+                                        GNUNET_DISK_PERM_USER_READ |
+                                        GNUNET_DISK_PERM_USER_WRITE);
+    if (data_file == NULL) {
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                    "Failed to open %s for output!\n",
+                    data_filename);
+        GNUNET_free (data_filename);
+    }
 
-  hosts = GNUNET_TESTING_hosts_load (testing_cfg);
+    wait_time =
+        GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
 
-  pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
-                                       &connect_cb, &my_cb, NULL, hosts);
-  GNUNET_assert (pg != NULL);
-  shutdown_handle =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
-                                    &shutdown_task, NULL);
+    if (GNUNET_YES ==
+        GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
+                                                "output_file", &temp_str))
+    {
+        output_file = GNUNET_DISK_file_open (temp_str,
+                                            GNUNET_DISK_OPEN_READWRITE |
+                                            GNUNET_DISK_OPEN_CREATE,
+                                            GNUNET_DISK_PERM_USER_READ |
+                                            GNUNET_DISK_PERM_USER_WRITE);
+        if (output_file == NULL)
+            GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                        "Failed to open %s for output!\n",
+                        temp_str);
+    }
+    GNUNET_free_non_null (temp_str);
+
+    hosts = GNUNET_TESTING_hosts_load (testing_cfg);
+
+    pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
+                                        &connect_cb, &peergroup_ready, NULL, 
hosts);
+    GNUNET_assert (pg != NULL);
+    shutdown_handle = GNUNET_SCHEDULER_add_delayed (
+                                        GNUNET_TIME_relative_get_forever (),
+                                        &shutdown_task, NULL);
 }
 
 
@@ -582,23 +682,19 @@
 };
 
 
+/**
+ * Main: start test
+ */
 int
 main (int argc, char *argv[])
 {
-  GNUNET_log_setup ("test_mesh_small",
-#if VERBOSE
-                    "DEBUG",
-#else
-                    "WARNING",
-#endif
-                    NULL);
-  GNUNET_PROGRAM_run (argc, argv, "test_mesh_small",
+    GNUNET_PROGRAM_run (argc, argv, "test_mesh_small",
                       gettext_noop ("Test mesh in a small network."), options,
                       &run, NULL);
 #if REMOVE_DIR
-  GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
+    GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
 #endif
-  return ok;
+    return ok;
 }
 
 /* end of test_mesh_small.c */

Modified: gnunet/src/mesh/test_mesh_small.conf
===================================================================
--- gnunet/src/mesh/test_mesh_small.conf        2011-08-22 11:58:34 UTC (rev 
16598)
+++ gnunet/src/mesh/test_mesh_small.conf        2011-08-22 17:35:24 UTC (rev 
16599)
@@ -114,7 +114,7 @@
 F2F = NO
 CONNECT_TIMEOUT = 60
 CONNECT_ATTEMPTS = 3
-#DEBUG = YES
+DEBUG = YES
 HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
 MAX_CONCURRENT_SSH = 10
 USE_PROGRESSBARS = YES
@@ -128,6 +128,6 @@
 DELETE_FILES = YES
 
 [test_mesh_small]
-WAIT_TIME = 10
+WAIT_TIME = 2
 CONNECTION_LIMIT = 10
 DATA_OUTPUT_FILE=data_output
\ No newline at end of file




reply via email to

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