- disable try_connect to force topology
[oweals/gnunet.git] / src / mesh / test_mesh2_local.c
index 49ea791e2deab4f2551ed555f194384b2a4bb393..b62cc9ac82a0539a1be5d3239a04af331b20d9bb 100644 (file)
@@ -19,8 +19,8 @@
 */
 
 /**
- * @file mesh/test_mesh_local_1.c
- * @brief test mesh local: test of tunnels with just one peer
+ * @file mesh/test_mesh2_local.c
+ * @brief test mesh2 local: test of mesh2 tunnels with just one peer
  * @author Bartlomiej Polot
  */
 
@@ -81,7 +81,7 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
   result = GNUNET_SYSERR;
-  abort_task = 0;
+  abort_task = GNUNET_SCHEDULER_NO_TASK;
   if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
   {
     GNUNET_SCHEDULER_cancel (shutdown_task);
@@ -114,6 +114,7 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
   shutdown_task =
     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
                                   NULL);
+  GNUNET_MESH_receive_done (tunnel);
   return GNUNET_OK;
 }
 
@@ -138,7 +139,7 @@ inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "test: received incoming tunnel on peer %d, port %u\n",
               id, port);
-  if (id != 1L)
+  if (id != 2L)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "test: wrong peer\n");
@@ -161,13 +162,13 @@ static void
 inbound_end (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
              void *tunnel_ctx)
 {
-  unsigned int id = *(unsigned int *) cls;
+  long id = (long) cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: incoming tunnel closed\n");
-  if (id != 1)
+  if (id != 2)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "test: received closing tunnel on peer 2\n");
+                "test: received closing tunnel on peer != 2\n");
     result = GNUNET_SYSERR;
   }
 }
@@ -185,8 +186,27 @@ static struct GNUNET_MESH_MessageHandler handlers1[] = {
 /**
  * Handler array for traffic received on peer2 (none expected)
  */
-static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} };
+static struct GNUNET_MESH_MessageHandler handlers2[] = {
+  {&data_callback, 1, 0},
+  {NULL, 0, 0}
+};
+
+static size_t
+do_send (void *cls, size_t size, void *buf)
+{
+  struct GNUNET_MessageHeader *m = buf;
 
+  if (NULL == buf)
+  {
+    GNUNET_break (0);
+    result = GNUNET_SYSERR;
+    return 0;
+  }
+  m->size = htons (sizeof (struct GNUNET_MessageHeader));
+  m->type = htons (1);
+  GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
+  return sizeof (struct GNUNET_MessageHeader);
+}
 
 /**
  * Start looking for a peer by type
@@ -197,8 +217,12 @@ do_find (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GNUNET_PeerIdentity id;
 
   GNUNET_TESTING_peer_get_identity (me, &id);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CONNECT BY TYPE\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CONNECT BY PORT\n");
   t = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, &id, 1);
+  GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
+                                     GNUNET_TIME_UNIT_FOREVER_REL,
+                                     sizeof (struct GNUNET_MessageHeader),
+                                     &do_send, NULL);
 }
 
 
@@ -215,7 +239,7 @@ run (void *cls,
   me = peer;
   abort_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort,
+                                    (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
                                     NULL);
   mesh_peer_1 = GNUNET_MESH_connect (cfg,       /* configuration */
                                      (void *) 1L,     /* cls */
@@ -251,7 +275,7 @@ int
 main (int argc, char *argv[])
 {
   if (0 != GNUNET_TESTING_peer_run ("test-mesh-local-1",
-                                    "test_mesh.conf",
+                                    "test_mesh2.conf",
                                 &run, NULL))
     return 1;
   return (result == GNUNET_OK) ? 0 : 1;