more transport testing hacking
authorChristian Grothoff <christian@grothoff.org>
Tue, 12 Jul 2016 08:08:17 +0000 (08:08 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 12 Jul 2016 08:08:17 +0000 (08:08 +0000)
21 files changed:
po/POTFILES.in
src/peerstore/gnunet-service-peerstore.c
src/transport/Makefile.am
src/transport/test_transport_address_switch.c
src/transport/test_transport_api.c
src/transport/test_transport_api_limited_sockets.c
src/transport/test_transport_api_restart_1peer.c
src/transport/test_transport_api_restart_1peer_peer1.conf [new file with mode: 0644]
src/transport/test_transport_api_restart_1peer_peer2.conf [new file with mode: 0644]
src/transport/test_transport_api_restart_2peers.c
src/transport/test_transport_api_restart_2peers_peer1.conf [new file with mode: 0644]
src/transport/test_transport_api_restart_2peers_peer2.conf [new file with mode: 0644]
src/transport/test_transport_api_timeout.c
src/transport/test_transport_blacklisting.c
src/transport/test_transport_testing_restart.c
src/transport/test_transport_testing_startstop.c
src/transport/transport-testing-main.c
src/transport/transport-testing.c
src/transport/transport-testing.h
src/transport/transport_api.c
src/util/server_mst.c

index 067d12f4d516c9f1e8d2ea57aa88630198d55a86..6c1eff093a2215bc0536f8125c0be5db3649a3aa 100644 (file)
@@ -406,10 +406,15 @@ src/transport/plugin_transport_wlan.c
 src/transport/transport_api_address_to_string.c
 src/transport/transport_api_blacklist.c
 src/transport/transport_api.c
+src/transport/transport_api_core.c
+src/transport/transport_api_get_hello.c
 src/transport/transport_api_monitor_peers.c
 src/transport/transport_api_monitor_plugins.c
-src/transport/transport_api_monitor_validation.c
+src/transport/transport_api_offer_hello.c
 src/transport/transport-testing.c
+src/transport/transport-testing-filenames.c
+src/transport/transport-testing-loggers.c
+src/transport/transport-testing-main.c
 src/tun/regex.c
 src/tun/tun.c
 src/util/bandwidth.c
index af6438bb253c1496f58a14ea0884ad4f7ad734f0..a074d132aa08b8aaaecc8d376994e858493ba16c 100644 (file)
@@ -472,10 +472,11 @@ handle_store (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Received a store request (size: %lu).\n" " Sub system `%s'\n"
-              " Peer `%s'\n" " Key `%s'\n" " Value size %lu\n"
-              " Options: %d.\n", record->value_size, record->sub_system,
-              GNUNET_i2s (record->peer), record->key, record->value_size,
+              "Received a store request (size: %u). Sub system `%s' Peer `%s Key `%s' Options: %d.\n",
+             (unsigned int) record->value_size,
+             record->sub_system,
+              GNUNET_i2s (record->peer),
+             record->key,
               ntohl (srm->options));
   record->client = client;
   if (GNUNET_OK !=
index 2c6c7dfd8a38ec76b4fd0978603c9c7698901990..767031e6f599b25766aa790fd1a78e3b90f86a44 100644 (file)
@@ -509,7 +509,6 @@ AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PAT
 TESTS = \
  test_transport_testing_startstop \
  test_transport_testing_restart \
- test_transport_testing \
  test_plugin_tcp \
  test_plugin_udp \
  $(UNIX_TEST) \
@@ -1266,6 +1265,8 @@ test_transport_api_timeout_tcp_peer1.conf\
 test_transport_api_timeout_tcp_peer2.conf\
 test_transport_api_multi_peer1.conf\
 test_transport_api_multi_peer2.conf\
+test_transport_api_restart_1peer_peer1.conf\
+test_transport_api_restart_1peer_peer2.conf\
 test_transport_api_reliability_http_peer1.conf\
 test_transport_api_reliability_http_peer2.conf\
 test_transport_api_reliability_https_peer1.conf\
@@ -1284,6 +1285,10 @@ test_transport_api_manipulation_recv_tcp_peer1.conf\
 test_transport_api_manipulation_recv_tcp_peer2.conf\
 test_transport_api_manipulation_cfg_peer1.conf\
 test_transport_api_manipulation_cfg_peer2.conf\
+test_transport_api_restart_1peer_peer1.conf\
+test_transport_api_restart_1peer_peer2.conf\
+test_transport_api_restart_2peers_peer1.conf\
+test_transport_api_restart_2peers_peer2.conf\
 test_transport_api_tcp_nat_peer1.conf\
 test_transport_api_tcp_nat_peer2.conf\
 test_transport_api_tcp_peer1.conf\
index 96e11b7de9a528c71de15e72b8552e32b6dd488b..198e82118cbde09c480c5480714e6474140e9be5 100644 (file)
@@ -486,7 +486,7 @@ main (int argc,
 {
   struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
     .connect_continuation = &connected_cb,
-    .config_file = "test_transport_startonly.conf",
+    .config_file = "test_transport_api.conf",
     .rec = &notify_receive,
     .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
     .nd = &notify_disconnect,
index ad078f5821a1ed9124462adc389956643fd3b838..bc0061363ae6cee41614e6a206dfb01f1fab35c8 100644 (file)
@@ -72,7 +72,7 @@ notify_receive (void *cls,
     char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n",
+                "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
                 receiver->no,
                 ps,
                 ntohs (message->type),
index 6948d3e6a97e7fc6180dc43d6b8745763ad1cd0d..0b7fd645cc7d56eb49c302027fec837eef3ed15e 100644 (file)
@@ -254,6 +254,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             &notify_receive,
                                             &notify_connect,
                                             &notify_disconnect,
+                                           NULL,
                                             &start_cb,
                                             NULL);
   p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
@@ -262,6 +263,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             &notify_receive,
                                             &notify_connect,
                                             &notify_disconnect,
+                                           NULL,
                                             &start_cb,
                                             NULL);
   if ((p1 == NULL) || (p2 == NULL))
index e814ad817364f20bc9c94433ea6d9935e362361e..7a63ed16b3b545a4bebe12f7f4113dd3bc972aa9 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009, 2010, 2015 GNUnet e.V.
+     Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
 #define MTYPE 12345
 
-static char *test_name;
 
-static int ok;
-
-static struct GNUNET_SCHEDULER_Task *die_task;
-
-static struct GNUNET_SCHEDULER_Task *send_task;
+static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
 
 static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
-
 static int p1_connected;
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
-
 static int p2_connected;
 
-static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
-
 static struct GNUNET_TRANSPORT_TransmitHandle *th;
 
-static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
-
-static char *cfg_file_p1;
-
-static char *cfg_file_p2;
+static struct GNUNET_SCHEDULER_Task *send_task;
 
 static int restarted;
 
 
 static void
-end ()
+custom_shutdown (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Stopping peers\n");
-
-  if (NULL != send_task)
-  {
-    GNUNET_SCHEDULER_cancel (send_task);
-    send_task = NULL;
-  }
   if (NULL != ats_sh)
   {
     GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
     ats_sh = NULL;
   }
-  if (NULL != die_task)
-  {
-    GNUNET_SCHEDULER_cancel (die_task);
-    die_task = NULL;
-  }
   if (NULL != th)
   {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
     th = NULL;
   }
-  if (NULL != p1)
-  {
-    GNUNET_TRANSPORT_TESTING_stop_peer (p1);
-    p1 = NULL;
-  }
-  if (NULL != p2)
-  {
-    GNUNET_TRANSPORT_TESTING_stop_peer (p2);
-    p2 = NULL;
-  }
-}
-
-
-static void
-end_badly (void *cls)
-{
-  die_task = NULL;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Fail! Stopping peers\n");
-
-  if (restarted == GNUNET_YES)
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peer was restarted\n");
-
-  if (restarted == GNUNET_NO)
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peer was NOT restarted\n");
-  if (NULL != cc)
+  if (NULL != send_task)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Fail! Could not connect peers\n"));
-    GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
-    cc = NULL;
+    GNUNET_SCHEDULER_cancel (send_task);
+    send_task = NULL;
   }
-  end ();
-  ok = GNUNET_SYSERR;
 }
 
 
 static void
-restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
+restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
+           void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Restarted peer %u (`%4s'), issuing reconnect\n",
+              "Restarted peer %u (`%s'), issuing reconnect\n",
               p->no,
               GNUNET_i2s (&p->id));
   ats_sh = GNUNET_ATS_connectivity_suggest (p->ats,
-                                            &p2->id,
+                                            &ccc->p[1]->id,
                                             1);
 }
 
@@ -155,81 +96,75 @@ static void
 restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Restarting peer %u (`%4s')\n",
+              "Restarting peer %u (`%s')\n",
               p->no,
               GNUNET_i2s (&p->id));
-  GNUNET_TRANSPORT_TESTING_restart_peer (p,
-                                         &restart_cb,
-                                         p);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_TRANSPORT_TESTING_restart_peer (p,
+                                                       &restart_cb,
+                                                       p));
 }
 
 
 static void
 notify_receive (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
+                struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
+                const struct GNUNET_PeerIdentity *sender,
                 const struct GNUNET_MessageHeader *message)
 {
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
-
-  if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
-    t = p1;
-  if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
-    t = p2;
-  GNUNET_assert (t != NULL);
-
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
-              p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
-              GNUNET_i2s (&t->id));
-  GNUNET_free (ps);
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
+                receiver->no,
+                ps,
+                ntohs (message->type),
+                ntohs (message->size),
+                GNUNET_i2s (sender));
+    GNUNET_free (ps);
+  }
   if ((MTYPE == ntohs (message->type)) &&
       (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
   {
-    if (restarted == GNUNET_NO)
+    if (GNUNET_NO == restarted)
     {
       restarted = GNUNET_YES;
-      restart (p1);
+      restart (ccc->p[0]);
       return;
     }
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Restarted peers connected and message was sent, stopping test...\n");
-      ok = 0;
-      end ();
+      ccc->global_ret = GNUNET_OK;
+      GNUNET_SCHEDULER_shutdown ();
     }
   }
   else
   {
     GNUNET_break (0);
-    ok = 1;
-    if (die_task != NULL)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+    ccc->global_ret = GNUNET_SYSERR;
+    GNUNET_SCHEDULER_shutdown ();    
   }
 }
 
 
 static size_t
-notify_ready (void *cls, size_t size, void *buf)
+notify_ready (void *cls,
+             size_t size,
+             void *buf)
 {
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
   struct GNUNET_MessageHeader *hdr;
 
   th = NULL;
-
   if (NULL == buf)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout occurred while waiting for transmit_ready\n");
-    if (NULL != die_task)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
-    ok = 42;
+    GNUNET_SCHEDULER_shutdown ();
+    ccc->global_ret = 42;
     return 0;
   }
 
@@ -239,11 +174,12 @@ notify_ready (void *cls, size_t size, void *buf)
   hdr->type = htons (MTYPE);
 
   {
-    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+    char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
+
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
-                p2->no,
+                "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n",
+                ccc->p[1]->no,
                 ps,
                 ntohs (hdr->type),
                 ntohs (hdr->size),
@@ -259,212 +195,99 @@ static void
 sendtask (void *cls)
 {
   send_task = NULL;
-  char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
-              p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
-  GNUNET_free (receiver_s);
-
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
-                                               &p1->id,
+  {
+    char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
+    
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
+               ccc->p[1]->no,
+               GNUNET_i2s (&ccc->p[1]->id),
+               ccc->p[0]->no,
+               receiver_s);
+    GNUNET_free (receiver_s);
+  }
+  th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
+                                               &ccc->p[0]->id,
                                                256,
                                                TIMEOUT_TRANSMIT,
                                                &notify_ready,
-                                               p1);
+                                               ccc->p[0]);
 }
 
 
 static void
 notify_connect (void *cls,
-                const struct GNUNET_PeerIdentity *peer)
+               struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+               const struct GNUNET_PeerIdentity *other)
 {
-  static int c;
-
-  c++;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
-
-  if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
-  {
+  GNUNET_TRANSPORT_TESTING_log_connect (cls,
+                                       me,
+                                       other);
+  if (0 == memcmp (other,
+                  &ccc->p[0]->id,
+                  sizeof (struct GNUNET_PeerIdentity)))
     p1_connected = GNUNET_YES;
-    t = p1;
-  }
-  if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
-  {
+  if (0 == memcmp (other,
+                  &ccc->p[1]->id,
+                  sizeof (struct GNUNET_PeerIdentity)))
     p2_connected = GNUNET_YES;
-    t = p2;
-  }
-  GNUNET_assert (t != NULL);
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
-              t->no, GNUNET_i2s (peer));
-  GNUNET_free (ps);
-
-  if ( (restarted == GNUNET_YES) &&
-       (p1_connected == GNUNET_YES) &&
-       (p2_connected == GNUNET_YES) )
+  if ( (GNUNET_YES == restarted) &&
+       (GNUNET_YES == p1_connected) &&
+       (GNUNET_YES == p2_connected) )
   {
     /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
-    send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
+    send_task = GNUNET_SCHEDULER_add_now (&sendtask,
+                                         NULL);
   }
 }
 
 
 static void
-notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_disconnect (void *cls,
+                   struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+                   const struct GNUNET_PeerIdentity *other)
 {
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
-  if ( (NULL != p1) &&
-       (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))))
-  {
+  GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
+                                           me,
+                                           other);
+  if (me == ccc->p[0])
     p1_connected = GNUNET_NO;
-  }
-  if ( (NULL != p2) &&
-       (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))))
-  {
+  if (me == ccc->p[1])
     p2_connected = GNUNET_NO;
-  }
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
-              GNUNET_i2s (peer));
-  GNUNET_free (ps);
-
-  if (th != NULL)
+  if (NULL != th)
+  {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
-  th = NULL;
+    th = NULL;
+  }
   if (NULL != send_task)
-    GNUNET_SCHEDULER_cancel (send_task);
-  send_task = NULL;
-}
-
-
-static void
-testing_connect_cb (void *cls)
-{
-  cc = NULL;
-  char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peers connected: %u (%s) <-> %u (%s)\n",
-              p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
-  GNUNET_free (p1_c);
-
-  send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
-}
-
-
-
-static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
-{
-  static int started;
-
-  started++;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
-              GNUNET_i2s (&p->id));
-
-  if (started != 2)
-    return;
-
-  char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
-              p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
-  GNUNET_free (sender_c);
-
-  cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
-                                               p2,
-                                               &testing_connect_cb,
-                                               NULL);
-
-}
-
-static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
-  p1_connected = GNUNET_NO;
-  p2_connected = GNUNET_NO;
-  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
-                                            cfg_file_p1,
-                                            1,
-                                            &notify_receive,
-                                            &notify_connect,
-                                            &notify_disconnect,
-                                            &start_cb,
-                                            NULL);
-
-  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
-                                            cfg_file_p2,
-                                            2,
-                                            &notify_receive,
-                                            &notify_connect,
-                                            &notify_disconnect,
-                                            &start_cb,
-                                            NULL);
-
-  if ((p1 == NULL) || (p2 == NULL))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Fail! Could not start peers!\n");
-    if (die_task != NULL)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly,
-                                         NULL);
-    return;
+    GNUNET_SCHEDULER_cancel (send_task);
+    send_task = NULL;
   }
 }
 
 
-static int
-check ()
-{
-  static char *const argv[] = { "test-transport-api",
-    "-c",
-    "test_transport_api_data.conf",
-    NULL
-  };
-  static struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-
-  send_task = NULL;
-
-  ok = 1;
-  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name,
-                      "nohelp", options, &run, &ok);
-
-  return ok;
-}
-
 int
 main (int argc, char *argv[])
 {
-  int ret;
-
-  test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
-  GNUNET_log_setup (test_name,
-                    "WARNING",
-                    NULL);
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-  GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf");
-  GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf");
-  ret = check ();
-  GNUNET_free (cfg_file_p1);
-  GNUNET_free (cfg_file_p2);
-  GNUNET_free (test_name);
-  GNUNET_TRANSPORT_TESTING_done (tth);
-  return ret;
+  struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
+    .connect_continuation = &sendtask,
+    .config_file = "test_transport_api_data.conf",
+    .rec = &notify_receive,
+    .nc = &notify_connect,
+    .nd = &notify_disconnect,
+    .shutdown_task = &custom_shutdown,
+    .timeout = TIMEOUT
+  };
+
+  ccc = &my_ccc;
+  if (GNUNET_OK !=
+      GNUNET_TRANSPORT_TESTING_main (2,
+                                     &GNUNET_TRANSPORT_TESTING_connect_check,
+                                     ccc))
+    return 1;
+  return 0;
 }
 
 /* end of test_transport_api_restart_1peer.c */
diff --git a/src/transport/test_transport_api_restart_1peer_peer1.conf b/src/transport/test_transport_api_restart_1peer_peer1.conf
new file mode 100644 (file)
index 0000000..4bfe9b6
--- /dev/null
@@ -0,0 +1,9 @@
+@INLINE@ template_cfg_peer1.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_restart_1peer_peer2.conf b/src/transport/test_transport_api_restart_1peer_peer2.conf
new file mode 100644 (file)
index 0000000..e68cdbe
--- /dev/null
@@ -0,0 +1,9 @@
+@INLINE@ template_cfg_peer2.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
index 876b7209c7fd994ed2fb1675910ee7f5e901b29f..40f2876239bab0698786cf217d2e2d1e067bc609 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009, 2010, 2015 GNUnet e.V.
+     Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
      Boston, MA 02110-1301, USA.
 */
 /**
- * @file transport/test_transport_api_restart_2peers.c
+ * @file transport/test_transport_api_restart_1peer.c
  * @brief base test case for transport implementations
  *
  * This test case starts 2 peers, connects and exchanges a message
- * boths peer are restarted and tested if peers reconnect
+ * 1 peer is restarted and tested if peers reconnect
+ * C code apparently.
  */
 #include "platform.h"
 #include "gnunet_transport_service.h"
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
 /**
  * How long until we give up on transmitting the message?
  */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
 #define MTYPE 12345
 
-static char *test_name;
 
-static int ok;
-
-static struct GNUNET_SCHEDULER_Task *die_task;
-
-static struct GNUNET_SCHEDULER_Task *send_task;
+static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
 
 static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
 
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
-
-static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
+static int p1_connected;
 
-static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
+static int p2_connected;
 
 static struct GNUNET_TRANSPORT_TransmitHandle *th;
 
-static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
-
-static char *cfg_file_p1;
-
-static char *cfg_file_p2;
+static struct GNUNET_SCHEDULER_Task *send_task;
 
 static int restarted;
 
 
 static void
-end ()
+custom_shutdown (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
-  if (NULL != send_task)
-  {
-    GNUNET_SCHEDULER_cancel (send_task);
-    send_task = NULL;
-  }
   if (NULL != ats_sh)
   {
     GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
     ats_sh = NULL;
   }
-  if (NULL != die_task)
-  {
-    GNUNET_SCHEDULER_cancel (die_task);
-    die_task = NULL;
-  }
   if (NULL != th)
   {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
     th = NULL;
   }
-  if (NULL != p1)
-  {
-    GNUNET_TRANSPORT_TESTING_stop_peer (p1);
-    p1 = NULL;
-  }
-  if (NULL != p2)
-  {
-    GNUNET_TRANSPORT_TESTING_stop_peer (p2);
-    p2 = NULL;
-  }
-}
-
-
-static void
-end_badly (void *cls)
-{
-  die_task = NULL;
-
-  if (restarted == GNUNET_YES)
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peer was restarted, but communication did not resume\n");
-
-  if (restarted == GNUNET_NO)
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Peer was NOT (even) restarted\n");
-  if (cc != NULL)
+  if (NULL != send_task)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Fail! Could not connect peers\n"));
-    GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
-    cc = NULL;
+    GNUNET_SCHEDULER_cancel (send_task);
+    send_task = NULL;
   }
-  end ();
-  ok = GNUNET_SYSERR;
 }
 
 
@@ -132,17 +82,17 @@ static void
 restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
             void *cls)
 {
-  static int c;
+  static unsigned int c;
 
   c++;
   if (c != 2)
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Restarted peer %u (`%4s'), issuing reconnect\n",
+              "Restarted peer %u (`%s'), issuing reconnect\n",
               p->no,
               GNUNET_i2s (&p->id));
-  ats_sh = GNUNET_ATS_connectivity_suggest (p->ats,
-                                            &p2->id,
+  ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats,
+                                            &ccc->p[1]->id,
                                             1);
 }
 
@@ -150,78 +100,66 @@ restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
 static void
 restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
 {
-  GNUNET_assert (NULL != p);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Restarting peer %u (`%4s')\n",
+              "Restarting peer %u (`%s')\n",
               p->no,
               GNUNET_i2s (&p->id));
-  GNUNET_TRANSPORT_TESTING_restart_peer (p,
-                                         &restart_cb,
-                                         p);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_TRANSPORT_TESTING_restart_peer (p,
+                                                       &restart_cb,
+                                                       p));
 }
 
 
 static void
 notify_receive (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
+                struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
+                const struct GNUNET_PeerIdentity *sender,
                 const struct GNUNET_MessageHeader *message)
 {
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
-
-  if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
-    t = p1;
-  if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
-    t = p2;
-  GNUNET_assert (t != NULL);
-
   {
-    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+    char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
-                p->no,
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
+                receiver->no,
                 ps,
                 ntohs (message->type),
                 ntohs (message->size),
-                t->no,
-                GNUNET_i2s (&t->id));
+                GNUNET_i2s (sender));
     GNUNET_free (ps);
   }
-
   if ((MTYPE == ntohs (message->type)) &&
       (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
   {
-    if (restarted == GNUNET_NO)
+    if (GNUNET_NO == restarted)
     {
       restarted = GNUNET_YES;
-      restart (p1);
-      restart (p2);
+      restart (ccc->p[0]);
+      restart (ccc->p[1]);
       return;
     }
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Restarted peers connected, stopping test...\n");
-      ok = 0;
-      end ();
+                  "Restarted peers connected and message was sent, stopping test...\n");
+      ccc->global_ret = GNUNET_OK;
+      GNUNET_SCHEDULER_shutdown ();
     }
   }
   else
   {
     GNUNET_break (0);
-    ok = 1;
-    if (die_task != NULL)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+    ccc->global_ret = GNUNET_SYSERR;
+    GNUNET_SCHEDULER_shutdown ();    
   }
 }
 
 
 static size_t
 notify_ready (void *cls,
-              size_t size,
-              void *buf)
+             size_t size,
+             void *buf)
 {
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
   struct GNUNET_MessageHeader *hdr;
@@ -231,10 +169,8 @@ notify_ready (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout occurred while waiting for transmit_ready\n");
-    if (NULL != die_task)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
-    ok = 42;
+    GNUNET_SCHEDULER_shutdown ();
+    ccc->global_ret = 42;
     return 0;
   }
 
@@ -244,11 +180,11 @@ notify_ready (void *cls,
   hdr->type = htons (MTYPE);
 
   {
-    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+    char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
-                p2->no,
+                "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n",
+                ccc->p[1]->no,
                 ps,
                 ntohs (hdr->type),
                 ntohs (hdr->size),
@@ -256,7 +192,6 @@ notify_ready (void *cls,
                 GNUNET_i2s (&p->id));
     GNUNET_free (ps);
   }
-
   return sizeof (struct GNUNET_MessageHeader);
 }
 
@@ -266,82 +201,66 @@ sendtask (void *cls)
 {
   send_task = NULL;
   {
-    char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
+    char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
+    
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
-                p2->no,
-                GNUNET_i2s (&p2->id),
-                p1->no,
-                receiver_s);
+               "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
+               ccc->p[1]->no,
+               GNUNET_i2s (&ccc->p[1]->id),
+               ccc->p[0]->no,
+               receiver_s);
     GNUNET_free (receiver_s);
   }
-
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
-                                               &p1->id,
+  th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
+                                               &ccc->p[0]->id,
                                                256,
                                                TIMEOUT_TRANSMIT,
                                                &notify_ready,
-                                               p1);
+                                               ccc->p[0]);
 }
 
 
 static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+               struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+               const struct GNUNET_PeerIdentity *other)
 {
-  static int c;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
-
-  c++;
-  if (0 == memcmp (peer,
-                   &p1->id,
-                   sizeof (struct GNUNET_PeerIdentity)))
-    t = p1;
-  if (0 == memcmp (peer,
-                   &p2->id,
-                   sizeof (struct GNUNET_PeerIdentity)))
-    t = p2;
-  GNUNET_assert (t != NULL);
-
-  {
-    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
-                p->no,
-                ps,
-                t->no,
-                GNUNET_i2s (peer));
-    GNUNET_free (ps);
-  }
-
-  if ((restarted == GNUNET_YES) && (c == 4))
+  GNUNET_TRANSPORT_TESTING_log_connect (cls,
+                                       me,
+                                       other);
+  if (0 == memcmp (other,
+                  &ccc->p[0]->id,
+                  sizeof (struct GNUNET_PeerIdentity)))
+    p1_connected = GNUNET_YES;
+  if (0 == memcmp (other,
+                  &ccc->p[1]->id,
+                  sizeof (struct GNUNET_PeerIdentity)))
+    p2_connected = GNUNET_YES;
+
+  if ( (GNUNET_YES == restarted) &&
+       (GNUNET_YES == p1_connected) &&
+       (GNUNET_YES == p2_connected) )
   {
+    /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
     send_task = GNUNET_SCHEDULER_add_now (&sendtask,
-                                          NULL);
+                                         NULL);
   }
 }
 
 
 static void
 notify_disconnect (void *cls,
-                   const struct GNUNET_PeerIdentity *peer)
+                   struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
+                   const struct GNUNET_PeerIdentity *other)
 {
-  struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
-
-  {
-    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
-                p->no,
-                ps,
-                GNUNET_i2s (peer));
-    GNUNET_free (ps);
-  }
-
-  if (th != NULL)
+  GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
+                                           me,
+                                           other);
+  if (me == ccc->p[0])
+    p1_connected = GNUNET_NO;
+  if (me == ccc->p[1])
+    p2_connected = GNUNET_NO;
+  if (NULL != th)
   {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
     th = NULL;
@@ -354,137 +273,26 @@ notify_disconnect (void *cls,
 }
 
 
-static void
-testing_connect_cb (void *cls)
-{
-  cc = NULL;
-
-  {
-    char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Peers connected: %u (%s) <-> %u (%s)\n",
-                p1->no,
-                p1_c,
-                p2->no,
-                GNUNET_i2s (&p2->id));
-    GNUNET_free (p1_c);
-  }
-  send_task = GNUNET_SCHEDULER_add_now (&sendtask,
-                                        NULL);
-}
-
-
-static void
-start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
-{
-  static int started;
-
-  started++;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer %u (`%s') started\n",
-              p->no,
-              GNUNET_i2s (&p->id));
-  if (started != 2)
-    return;
-
-  {
-    char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
-                p1->no,
-                sender_c,
-                p2->no,
-                GNUNET_i2s (&p2->id));
-    GNUNET_free (sender_c);
-  }
-
-  cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
-                                               p2,
-                                               &testing_connect_cb,
-                                               NULL);
-}
-
-
-static void
-run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                           &end_badly,
-                                           NULL);
-  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
-                                            cfg_file_p1,
-                                            1,
-                                            &notify_receive,
-                                            &notify_connect,
-                                            &notify_disconnect,
-                                            &start_cb,
-                                            NULL);
-
-  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
-                                            cfg_file_p2,
-                                            2,
-                                            &notify_receive,
-                                            &notify_connect,
-                                            &notify_disconnect,
-                                            &start_cb,
-                                            NULL);
-
-  if ((p1 == NULL) || (p2 == NULL))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
-    if (die_task != NULL)
-      GNUNET_SCHEDULER_cancel (die_task);
-    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
-    return;
-  }
-}
-
-
-static int
-check ()
-{
-  static char *const argv[] = { "test-transport-api",
-    "-c",
-    "test_transport_api_data.conf",
-    NULL
-  };
-  static struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-
-  send_task = NULL;
-
-  ok = 1;
-  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name,
-                      "nohelp", options, &run, NULL);
-
-  return ok;
-}
-
-
 int
 main (int argc, char *argv[])
 {
-  int ret;
-
-  test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
-  GNUNET_log_setup (test_name,
-                    "WARNING",
-                    NULL);
-  tth = GNUNET_TRANSPORT_TESTING_init ();
-  GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf");
-  GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf");
-  ret = check ();
-  GNUNET_free (cfg_file_p1);
-  GNUNET_free (cfg_file_p2);
-  GNUNET_free (test_name);
-  GNUNET_TRANSPORT_TESTING_done (tth);
-  return ret;
+  struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
+    .connect_continuation = &sendtask,
+    .config_file = "test_transport_api_data.conf",
+    .rec = &notify_receive,
+    .nc = &notify_connect,
+    .nd = &notify_disconnect,
+    .shutdown_task = &custom_shutdown,
+    .timeout = TIMEOUT
+  };
+
+  ccc = &my_ccc;
+  if (GNUNET_OK !=
+      GNUNET_TRANSPORT_TESTING_main (2,
+                                     &GNUNET_TRANSPORT_TESTING_connect_check,
+                                     ccc))
+    return 1;
+  return 0;
 }
 
-/* end of test_transport_api_restart_2peers.c */
+/* end of test_transport_api_restart_1peer.c */
diff --git a/src/transport/test_transport_api_restart_2peers_peer1.conf b/src/transport/test_transport_api_restart_2peers_peer1.conf
new file mode 100644 (file)
index 0000000..4bfe9b6
--- /dev/null
@@ -0,0 +1,9 @@
+@INLINE@ template_cfg_peer1.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_restart_2peers_peer2.conf b/src/transport/test_transport_api_restart_2peers_peer2.conf
new file mode 100644 (file)
index 0000000..e68cdbe
--- /dev/null
@@ -0,0 +1,9 @@
+@INLINE@ template_cfg_peer2.conf
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/
+
+[transport]
+PLUGINS = tcp
+
+#[transport]
+#PREFIX = valgrind
index fcc0b044e3ea8bb619f3e74be024a1fade1c7f44..29d69c879db2985aaf065a188f5c31f0ef108526 100644 (file)
@@ -261,6 +261,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             &notify_receive,
                                             &notify_connect,
                                             &notify_disconnect,
+                                           NULL,
                                             &start_cb,
                                             NULL);
   p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
@@ -269,6 +270,7 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             &notify_receive,
                                             &notify_connect,
                                             &notify_disconnect,
+                                           NULL,
                                             &start_cb,
                                             NULL);
 
index 3696dc71a112b06259b22a450c9ad3637de427d1..4c1f73152d40e025dddc890571a1d0d18cec3daa 100644 (file)
@@ -275,6 +275,7 @@ run_stage (void *cls)
                                                 1,
                                                 NULL,
                                                 NULL,
+                                               NULL,
                                                 NULL,
                                                 &start_cb,
                                                 NULL);
@@ -284,6 +285,7 @@ run_stage (void *cls)
                                                 2,
                                                 NULL,
                                                 NULL,
+                                               NULL,
                                                 NULL,
                                                 &start_cb,
                                                 NULL);
@@ -297,10 +299,12 @@ run_stage (void *cls)
       p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p1,
                                                 1, NULL, NULL, NULL,
+                                               NULL,
                                                 &start_cb, NULL);
       p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p2, 2,
                                                 NULL, NULL, NULL,
+                                               NULL,
                                                 &start_cb, NULL);
 
       /* check if configuration contain correct blacklist entries */
@@ -328,6 +332,7 @@ run_stage (void *cls)
                                                 cfg_p1,
                                                 1,
                                                 NULL,
+                                               NULL,
                                                 NULL,
                                                 NULL,
                                                 &start_cb,
@@ -337,6 +342,7 @@ run_stage (void *cls)
                                                 cfg_p2, 2,
                                                 NULL,
                                                 NULL,
+                                               NULL,
                                                 NULL,
                                                 &start_cb,
                                                 NULL);
@@ -363,11 +369,13 @@ run_stage (void *cls)
 
       p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p1, 1,
+                                               NULL,
                                                 NULL, NULL, NULL,
                                                 &start_cb, NULL);
 
       p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p2, 2,
+                                               NULL,
                                                 NULL, NULL, NULL,
                                                 &start_cb, NULL);
 
@@ -391,11 +399,13 @@ run_stage (void *cls)
 
       p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p1, 1,
+                                               NULL,
                                                 NULL, NULL, NULL,
                                                 &start_cb, NULL);
 
       p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p2, 2,
+                                               NULL,
                                                 NULL, NULL,
                                                 NULL,
                                                 &start_cb, NULL);
@@ -421,11 +431,13 @@ run_stage (void *cls)
 
       p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p1, 1,
+                                               NULL,
                                                 NULL, NULL, NULL,
                                                 &start_cb, NULL);
 
       p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
                                                 cfg_p2, 2,
+                                               NULL,
                                                 NULL, NULL, NULL,
                                                 &start_cb, NULL);
 
index 2d06bf6681d9a4de10d21b4782c0d29f34348bb2..4d54337131c9d9ade82f2fb526a46363bb481424 100644 (file)
@@ -122,6 +122,7 @@ run (void *cls,
                                           NULL, /* receive cb */
                                           NULL, /* connect cb */
                                           NULL, /* disconnect cb */
+                                         NULL, /* nc/nd closure */
                                           start_cb, /* startup cb */
                                           NULL); /* closure */
   if (NULL == p)
index c516d4277ab2c24ff205cb85bbef113bf2f28eac..0846357e66f9ef35c1c2c6e3d4e8c493e521e5b8 100644 (file)
@@ -91,14 +91,15 @@ run (void *cls,
                                     &end_badly,
                                     NULL);
 
-  p = GNUNET_TRANSPORT_TESTING_start_peer(tth,
-                                          cfgfile,
-                                          1,
-                                          NULL, /* receive cb */
-                                          NULL, /* connect cb */
-                                          NULL, /* disconnect cb */
-                                          &start_cb, /* startup cb */
-                                          NULL); /* closure */
+  p = GNUNET_TRANSPORT_TESTING_start_peer (tth,
+                                          cfgfile,
+                                          1,
+                                          NULL, /* receive cb */
+                                          NULL, /* connect cb */
+                                          NULL, /* disconnect cb */
+                                          NULL, /* nc/nd closure */
+                                          &start_cb, /* startup cb */
+                                          NULL); /* closure */
   if (NULL == p)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n");
index de2ec3d0c651d769ec7ae5255066139bb8f22170..f196d586bffd23a94d31ddc8db591575a1b5e34a 100644 (file)
@@ -383,6 +383,7 @@ connect_check_run (void *cls,
                                                      &my_rec,
                                                      &my_nc,
                                                      &my_nd,
+                                                    &ccc->ip[i],
                                                      &start_cb,
                                                      &ccc->ip[i]);
     if (NULL == ccc->p[i])
index ae878a79e5daca2501e9c5a5cde91b882883f30a..322627459169abbb08a5cc37df7d87c32590f0a4 100644 (file)
@@ -186,7 +186,7 @@ get_hello (void *cb_cls,
          p->no,
          GNUNET_i2s (&p->id));
     p->start_cb (p,
-                 p->cb_cls);
+                 p->start_cb_cls);
     p->start_cb = NULL;
   }
 }
@@ -200,8 +200,9 @@ get_hello (void *cb_cls,
  * @param rec receive callback
  * @param nc connect callback
  * @param nd disconnect callback
- * @param start_cb start callback
  * @param cb_cls closure for callback
+ * @param start_cb start callback
+ * @param start_cb_cls closure for callback
  * @return the peer context
  */
 struct GNUNET_TRANSPORT_TESTING_PeerContext *
@@ -211,8 +212,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
                                      GNUNET_TRANSPORT_ReceiveCallback rec,
                                      GNUNET_TRANSPORT_NotifyConnect nc,
                                      GNUNET_TRANSPORT_NotifyDisconnect nd,
+                                    void *cb_cls,
                                      GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
-                                     void *cb_cls)
+                                     void *start_cb_cls)
 {
   char *emsg = NULL;
   struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
@@ -231,11 +233,12 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
   p->nc = nc;
   p->nd = nd;
   p->rec = rec;
-  p->start_cb = start_cb;
-  if (cb_cls != NULL)
+  if (NULL != cb_cls)
     p->cb_cls = cb_cls;
   else
     p->cb_cls = p;
+  p->start_cb = start_cb;
+  p->start_cb_cls = start_cb_cls;
   GNUNET_CONTAINER_DLL_insert (tth->p_head,
                                tth->p_tail,
                                p);
@@ -341,13 +344,13 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
  *
  * @param p the peer
  * @param restart_cb callback to call when restarted
- * @param cb_cls callback closure
+ * @param restart_cb_cls callback closure
  * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
  */
 int
 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
                                        GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
-                                       void *cb_cls)
+                                       void *restart_cb_cls)
 {
   /* shutdown */
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -397,7 +400,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
 
   GNUNET_assert (NULL == p->start_cb);
   p->start_cb = restart_cb;
-  p->cb_cls = cb_cls;
+  p->start_cb_cls = restart_cb_cls;
 
   p->th = GNUNET_TRANSPORT_connect (p->cfg,
                                     NULL,
index b78d11dbe876acb2926abac2b6d513de7279a5e9..4be451d3520f20bc11825884d2cf8e80406619cd 100644 (file)
@@ -140,10 +140,15 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext
   struct GNUNET_HELLO_Message *hello;
 
   /**
-   * Closure for the callbacks
+   * Closure for the @a nc and @a nd callbacks
    */
   void *cb_cls;
 
+  /**
+   * Closure for @e start_cb.
+   */
+  void *start_cb_cls;
+  
   /**
    * An unique number to identify the peer
    */
@@ -266,8 +271,9 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
  * @param rec receive callback
  * @param nc connect callback
  * @param nd disconnect callback
+ * @param cb_cls closure for @a nc and @a nd callback
  * @param start_cb start callback
- * @param cb_cls closure for callback
+ * @param start_cb_cls closure for @a start_cb
  * @return the peer context
  */
 struct GNUNET_TRANSPORT_TESTING_PeerContext *
@@ -277,8 +283,9 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
                                      GNUNET_TRANSPORT_ReceiveCallback rec,
                                      GNUNET_TRANSPORT_NotifyConnect nc,
                                      GNUNET_TRANSPORT_NotifyDisconnect nd,
+                                    void *cb_cls,
                                      GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
-                                     void *cb_cls);
+                                     void *start_cb_cls);
 
 
 /**
@@ -295,13 +302,13 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext
  *
  * @param p the peer
  * @param restart_cb restart callback
- * @param cb_cls callback closure
+ * @param restart_cb_cls callback closure
  * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
  */
 int
 GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
                                        GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
-                                       void *cb_cls);
+                                       void *restart_cb_cls);
 
 
 
index e7db5493eaf3c29dc29e317ae12719e0616dd696..83b7732e401fdd0d7e56d6c780d6d683559f0d12 100644 (file)
@@ -817,6 +817,7 @@ transmit_ready (struct GNUNET_TRANSPORT_Handle *h)
       GNUNET_MQ_discard (env);
       continue;
     }
+    obm->header.size = htons (mret + sizeof (*obm));
     if (NULL != n->unready_warn_task)
       n->unready_warn_task
         = GNUNET_SCHEDULER_add_delayed (UNREADY_WARN_TIME,
index 41b2e8ed98ab763a10f24bca9040076c54fa8fa6..89a25983c0fd766fd59939cdd0926460100943e2 100644 (file)
@@ -244,7 +244,7 @@ do_align:
       want = ntohs (hdr->size);
       if (want < sizeof (struct GNUNET_MessageHeader))
       {
-        GNUNET_break_op (0);
+       GNUNET_break_op (0);
         mst->off = 0;
         return GNUNET_SYSERR;
       }