- adapt test cases / framework to new port system
authorBart Polot <bart@net.in.tum.de>
Wed, 20 Jul 2016 12:07:05 +0000 (12:07 +0000)
committerBart Polot <bart@net.in.tum.de>
Wed, 20 Jul 2016 12:07:05 +0000 (12:07 +0000)
src/cadet/cadet_test_lib.c
src/cadet/cadet_test_lib.h
src/cadet/gnunet-cadet-profiler.c
src/cadet/gnunet-service-cadet_channel.c
src/cadet/gnunet-service-cadet_local.c
src/cadet/gnunet-service-cadet_local.h
src/cadet/test_cadet.c
src/cadet/test_cadet_local.c
src/cadet/test_cadet_single.c

index cd9e47b0b860c90eff715c65ae0bc74781b89c07..9a70dad4937b9eef60d488940985aa3c783c3be9 100644 (file)
@@ -80,7 +80,7 @@ struct GNUNET_CADET_TEST_Context
   /**
    * Application ports.
    */
-  const uint32_t *ports;
+  const struct GNUNET_HashCode **ports;
 
 };
 
@@ -94,7 +94,7 @@ struct GNUNET_CADET_TEST_AdapterContext
    * Peer number for the particular peer.
    */
   unsigned int peer;
-
   /**
    * General context.
    */
@@ -124,6 +124,16 @@ cadet_connect_adapter (void *cls,
                            (void *) (long) actx->peer,
                            ctx->cleaner,
                            ctx->handlers);
+  if (NULL == ctx->ports)
+    return h;
+
+  for (int i = 0; NULL != ctx->ports[i]; i++)
+  {
+    (void ) GNUNET_CADET_open_port (h, ctx->ports[i],
+                                    ctx->new_channel,
+                                    (void *) (long) actx->peer);
+  }
+
   return h;
 }
 
@@ -269,7 +279,7 @@ GNUNET_CADET_TEST_run (const char *testname,
                       GNUNET_CADET_InboundChannelNotificationHandler new_channel,
                       GNUNET_CADET_ChannelEndHandler cleaner,
                       struct GNUNET_CADET_MessageHandler* handlers,
-                      const uint32_t *ports)
+                      const struct GNUNET_HashCode **ports)
 {
   struct GNUNET_CADET_TEST_Context *ctx;
 
index f517fdd4b11a1c3cbffcf6383273550175daec85..464977d42d1245ad6308bf528500a8fb952dc7d5 100644 (file)
@@ -71,7 +71,7 @@ typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls,
  * @param new_channel Handler for incoming tunnels.
  * @param cleaner Cleaner for destroyed incoming tunnels.
  * @param handlers Message handlers.
- * @param ports Ports the peers offer.
+ * @param ports Ports the peers offer, NULL-terminated.
  */
 void
 GNUNET_CADET_TEST_run (const char *testname,
@@ -82,7 +82,7 @@ GNUNET_CADET_TEST_run (const char *testname,
                       GNUNET_CADET_InboundChannelNotificationHandler new_channel,
                       GNUNET_CADET_ChannelEndHandler cleaner,
                       struct GNUNET_CADET_MessageHandler* handlers,
-                      const uint32_t* ports);
+                      const struct GNUNET_HashCode **ports);
 
 
 /**
index 65e8f32190ab8de936e029e4c173b05e604d8ce6..d688dc60b59bdbe09722b4739bdfcefa9492b1f4 100644 (file)
@@ -816,7 +816,8 @@ static struct GNUNET_CADET_MessageHandler handlers[] = {
 static void *
 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
                  const struct GNUNET_PeerIdentity *initiator,
-                 uint32_t port, enum GNUNET_CADET_ChannelOption options)
+                 const struct GNUNET_HashCode *port,
+                  enum GNUNET_CADET_ChannelOption options)
 {
   long n = (long) cls;
   struct CadetPeer *peer;
@@ -921,7 +922,7 @@ start_test (void *cls)
     peers[i].dest = select_random_peer (&peers[i]);
     peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
                                                &peers[i].dest->id,
-                                               1, flags);
+                                               GC_u2h (1), flags);
     if (NULL == peers[i].ch)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
@@ -966,7 +967,7 @@ warmup (void)
                 i, get_index (peer));
     peers[i].warmup_ch =
       GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
-                                  1, GNUNET_CADET_OPTION_DEFAULT);
+                                  GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT);
     if (NULL == peers[i].warmup_ch)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
@@ -1083,7 +1084,7 @@ tmain (void *cls,
 int
 main (int argc, char *argv[])
 {
-  static uint32_t ports[2];
+  static const struct GNUNET_HashCode *ports[2];
   const char *config_file;
 
   config_file = ".profiler.conf";
@@ -1135,7 +1136,7 @@ main (int argc, char *argv[])
   GNUNET_assert (NULL != ids);
   p_ids = 0;
   test_finished = GNUNET_NO;
-  ports[0] = 1;
+  ports[0] = GC_u2h (1);
   ports[1] = 0;
   GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
                         &tmain, NULL, /* tmain cls */
index d01356c3a820bf6951983bfca0f032f878bb2eb0..d1dcfdd2d59c7528f56b44d8a2062e5f6ed62af4 100644 (file)
@@ -2149,7 +2149,7 @@ GCCH_handle_create (struct CadetTunnel *t,
   struct CadetChannel *ch;
   struct CadetClient *c;
   int new_channel;
-  struct GNUNET_HashCode *port;
+  const struct GNUNET_HashCode *port;
 
   chid = ntohl (msg->chid);
 
index 5e73887e6fa4514b39d542e2cad87a8ca8fb90a7..d2efb7bef3ba2fa6deda4599523ec17a9f27e4bd 100644 (file)
@@ -1312,7 +1312,7 @@ GML_client_get (struct GNUNET_SERVER_Client *client)
  * @return non-NULL if a client has the port.
  */
 struct CadetClient *
-GML_client_get_by_port (struct GNUNET_HashCode *port)
+GML_client_get_by_port (const struct GNUNET_HashCode *port)
 {
   return GNUNET_CONTAINER_multihashmap_get (ports, port);
 }
index 877f8ad6eb209209f0150acfcf182ce564f10f0a..f89745092ca702149a70f57d26dce0f4729b329f 100644 (file)
@@ -134,7 +134,7 @@ GML_client_get (struct GNUNET_SERVER_Client *client);
  * @return non-NULL if a client has the port.
  */
 struct CadetClient *
-GML_client_get_by_port (struct GNUNET_HashCode *port);
+GML_client_get_by_port (const struct GNUNET_HashCode *port);
 
 /**
  * Deletes a tunnel from a client (either owner or destination).
index 557524ca3d4c136f0509f5f4792af51429fbb5d6..e2d3902e5d53e10c1daf9e95d6e5d0484451b4c6 100644 (file)
@@ -96,6 +96,11 @@ struct GNUNET_TESTBED_Operation *t_op[2];
  */
 struct GNUNET_PeerIdentity *p_id[2];
 
+/**
+ * Port ID
+ */
+struct GNUNET_HashCode port;
+
 /**
  * Peer ids counter.
  */
@@ -761,12 +766,13 @@ static struct GNUNET_CADET_MessageHandler handlers[] = {
 static void *
 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
                  const struct GNUNET_PeerIdentity *initiator,
-                 uint32_t port, enum GNUNET_CADET_ChannelOption options)
+                 const struct GNUNET_HashCode *port,
+                 enum GNUNET_CADET_ChannelOption options)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Incoming channel from %s to peer %d\n",
+              "Incoming channel from %s to peer %d:%s\n",
               GNUNET_i2s (initiator),
-              (int) (long) cls);
+              (int) (long) cls, GNUNET_h2s (port));
   ok++;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
   if ((long) cls == peers_requested - 1)
@@ -865,7 +871,8 @@ do_test (void *cls)
     test = SPEED;
     flags |= GNUNET_CADET_OPTION_RELIABLE;
   }
-  ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], 1, flags);
+
+  ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], &port, flags);
 
   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
                                                   &gather_stats_and_exit,
@@ -965,8 +972,10 @@ int
 main (int argc, char *argv[])
 {
   initialized = GNUNET_NO;
-  static uint32_t ports[2];
+  static const struct GNUNET_HashCode *ports[2];
   const char *config_file;
+  char port_id[] = "test port";
+  GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port);
 
   GNUNET_log_setup ("test", "DEBUG", NULL);
   config_file = "test_cadet.conf";
@@ -1066,8 +1075,8 @@ main (int argc, char *argv[])
   }
 
   p_ids = 0;
-  ports[0] = 1;
-  ports[1] = 0;
+  ports[0] = &port;
+  ports[1] = NULL;
   GNUNET_CADET_TEST_run ("test_cadet_small",
                         config_file,
                         peers_requested,
index d52e06282528866b385c36e748074f3fdbf5eaf1..ce6f0b29f6e29e0160e2a4faa955fd7e0e3d3a7f 100644 (file)
@@ -149,15 +149,15 @@ static void *
 inbound_channel (void *cls,
                  struct GNUNET_CADET_Channel *channel,
                  const struct GNUNET_PeerIdentity *initiator,
-                 uint32_t port,
+                 const struct GNUNET_HashCode *port,
                  enum GNUNET_CADET_ChannelOption options)
 {
   long id = (long) cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "received incoming channel on peer %d, port %u\n",
+              "received incoming channel on peer %d, port %s\n",
               (int) id,
-              (unsigned int) port);
+              GNUNET_h2s (port));
   if (id != 2L)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -259,7 +259,7 @@ do_connect (void *cls)
   connect_task = NULL;
   GNUNET_TESTING_peer_get_identity (me, &id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
-  ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1,
+  ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, GC_u2h (1),
                                    GNUNET_CADET_OPTION_DEFAULT);
   mth = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
                                            GNUNET_TIME_UNIT_FOREVER_REL,
@@ -280,8 +280,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  static uint32_t ports[] = {1, 0};
-
   me = peer;
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   abort_task =
@@ -291,17 +289,16 @@ run (void *cls,
                                     NULL);
   cadet_peer_1 = GNUNET_CADET_connect (cfg,       /* configuration */
                                      (void *) 1L,       /* cls */
-                                     NULL,              /* inbound new hndlr */
                                      &channel_end,      /* channel end hndlr */
-                                     handlers1, /* traffic handlers */
-                                     NULL);     /* ports offered */
+                                     handlers1); /* traffic handlers */
 
   cadet_peer_2 = GNUNET_CADET_connect (cfg,       /* configuration */
                                      (void *) 2L,     /* cls */
-                                     &inbound_channel,   /* inbound new hndlr */
                                      &channel_end,      /* channel end hndlr */
-                                     handlers2, /* traffic handlers */
-                                     ports);     /* ports offered */
+                                     handlers2); /* traffic handlers */
+  GNUNET_CADET_open_port (cadet_peer_2, GC_u2h (1),
+                          &inbound_channel, (void *) 2L);
+
   if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
index b9ab7e23a283782718c7005ce57ccfea014ad4fa..9bfaeda0d696374d2a3cd85ea816affc3850fdab 100644 (file)
@@ -160,12 +160,13 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
  */
 static void *
 inbound_channel (void *cls, struct GNUNET_CADET_Channel *channel,
-                const struct GNUNET_PeerIdentity *initiator,
-                uint32_t port, enum GNUNET_CADET_ChannelOption options)
+                 const struct GNUNET_PeerIdentity *initiator,
+                 const struct GNUNET_HashCode *port,
+                 enum GNUNET_CADET_ChannelOption options)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "received incoming channel on port %u\n",
-              port);
+              "received incoming channel on port %s\n",
+              GNUNET_h2s (port));
   ch2 = channel;
   return NULL;
 }
@@ -249,8 +250,8 @@ do_connect (void *cls)
   connect_task = NULL;
   GNUNET_TESTING_peer_get_identity (me, &id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
-  ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1,
-                                    GNUNET_CADET_OPTION_DEFAULT);
+  ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, GC_u2h (1),
+                                     GNUNET_CADET_OPTION_DEFAULT);
   GNUNET_CADET_notify_transmit_ready (ch1, GNUNET_NO,
                                      GNUNET_TIME_UNIT_FOREVER_REL,
                                      size, &do_send, NULL);
@@ -269,8 +270,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  static uint32_t ports[] = {1, 0};
-
   me = peer;
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   abort_task =
@@ -279,10 +278,10 @@ run (void *cls,
                                     NULL);
   cadet = GNUNET_CADET_connect (cfg,       /* configuration */
                               (void *) 1L,     /* cls */
-                              &inbound_channel,   /* inbound new hndlr */
                               &channel_end,      /* inbound end hndlr */
-                              handlers1, /* traffic handlers */
-                              ports);     /* ports offered */
+                              handlers1); /* traffic handlers */
+  GNUNET_CADET_open_port (cadet, GC_u2h (1), &inbound_channel, (void *) 1L);
+
 
   if (NULL == cadet)
   {