avoid failing hard if 'gnunetcheck' db does not exist
[oweals/gnunet.git] / src / cadet / test_cadet_local_mq.c
index 988ec725ecafa87c1025e840cd4ec5e987cab606..fc55610446c07516d2e09c63c674fec2f868538a 100644 (file)
@@ -1,25 +1,25 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2011 GNUnet e.V.
+     Copyright (C) 2017 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
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
- * @file cadet/test_cadet_local.c
+ * @file cadet/test_cadet_local_mq.c
  * @brief test cadet local: test of cadet channels with just one peer
  * @author Bartlomiej Polot
  */
@@ -123,7 +123,9 @@ do_shutdown (void *cls)
 static void
 do_abort (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ABORT from line %ld\n", (long) cls);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "ABORT from line %ld\n",
+              (long) cls);
   result = GNUNET_SYSERR;
   abort_task = NULL;
   GNUNET_SCHEDULER_shutdown ();
@@ -132,12 +134,12 @@ do_abort (void *cls)
 /**
  * Method called whenever a peer connects to a port in MQ-based CADET.
  *
- * @param cls Closure from #GNUNET_CADET_open_porT.
+ * @param cls Closure from #GNUNET_CADET_open_port.
  * @param channel New handle to the channel.
  * @param source Peer that started this channel.
  * @return Closure for the incoming @a channel. It's given to:
  *         - The #GNUNET_CADET_DisconnectEventHandler (given to
- *           #GNUNET_CADET_open_porT) when the channel dies.
+ *           #GNUNET_CADET_open_port) when the channel dies.
  *         - Each the #GNUNET_MQ_MessageCallback handlers for each message
  *           received on the @a channel.
  */
@@ -148,7 +150,8 @@ connected (void *cls,
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "connected %s, cls: %p\n",
-              GNUNET_i2s(source), cls);
+              GNUNET_i2s(source),
+              cls);
   return channel;
 }
 
@@ -168,8 +171,8 @@ disconnected (void *cls,
               const struct GNUNET_CADET_Channel *channel)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "disconnected cls: %p\n",
-              cls);
+              "disconnected channel %p, cls: %p\n",
+              channel, cls);
   if (channel == ch)
     ch = NULL;
 }
@@ -189,8 +192,9 @@ handle_data_received (void *cls,
 
   payload = GNUNET_ntohll (msg->payload);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Data callback payload %lu with cls: %p! Shutting down.\n",
-              payload, cls);
+              "Data callback payload %llu with cls: %p! Shutting down.\n",
+              (unsigned long long) payload,
+              cls);
   GNUNET_assert (42 == payload);
   got_data = GNUNET_YES;
   GNUNET_SCHEDULER_shutdown ();
@@ -205,7 +209,8 @@ handle_data_received (void *cls,
 static void
 message_sent (void *cls)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "message sent\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "message sent\n");
 }
 
 
@@ -234,7 +239,7 @@ do_connect (void *cls)
   GNUNET_TESTING_peer_get_identity (me, &id);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "creating channel\n");
-  ch = GNUNET_CADET_channel_creatE (cadet_peer_1, /* cadet handle */
+  ch = GNUNET_CADET_channel_create (cadet_peer_1, /* cadet handle */
                                     NULL,         /* channel cls */
                                     &id,          /* destination */
                                     GC_u2h (TEST_MESSAGE_TYPE), /* port */
@@ -265,47 +270,47 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  struct GNUNET_TIME_Relative start_delay;
+  struct GNUNET_MQ_MessageHandler handlers[] = {
+    GNUNET_MQ_hd_fixed_size (data_received,
+                             TEST_MESSAGE_TYPE,
+                             struct GNUNET_CADET_TestMsg,
+                             cadet_peer_2),
+    GNUNET_MQ_handler_end ()
+  };
+  struct GNUNET_TIME_Relative delay;
+
   me = peer;
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
                                  NULL);
-  abort_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                    (GNUNET_TIME_UNIT_SECONDS, 15),
-                                   &do_abort,
-                                    (void *) (long) __LINE__);
-  cadet_peer_1 = GNUNET_CADET_connecT (cfg);
-  cadet_peer_2 = GNUNET_CADET_connecT (cfg);
+  delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15);
+  abort_task = GNUNET_SCHEDULER_add_delayed (delay,
+                                             &do_abort,
+                                             (void *) (long) __LINE__);
+  cadet_peer_1 = GNUNET_CADET_connect (cfg);
+  cadet_peer_2 = GNUNET_CADET_connect (cfg);
 
   if ( (NULL == cadet_peer_1) ||
        (NULL == cadet_peer_2) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-               "Couldn't connect to cadet\n");
+                "Couldn't connect to cadet\n");
     result = GNUNET_SYSERR;
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 1: %p\n", cadet_peer_1);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CADET 2: %p\n", cadet_peer_2);
-  struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (data_received,
-                             TEST_MESSAGE_TYPE,
-                             struct GNUNET_CADET_TestMsg,
-                             cadet_peer_2),
-    GNUNET_MQ_handler_end ()
-  };
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handlers 2: %p\n", handlers);
-  GNUNET_CADET_open_porT (cadet_peer_2,          /* cadet handle */
+  GNUNET_CADET_open_port (cadet_peer_2,          /* cadet handle */
                           GC_u2h (TEST_PORT_ID), /* port id */
                           &connected,            /* connect handler */
                           (void *) 2L,           /* handle for #connected */
                           NULL,                  /* window size handler */
                           &disconnected,         /* disconnect handler */
                           handlers);             /* traffic handlers */
-  start_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2);
+  delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2);
   if (NULL == connect_task)
-    connect_task = GNUNET_SCHEDULER_add_delayed (start_delay,
+    connect_task = GNUNET_SCHEDULER_add_delayed (delay,
                                                  &do_connect,
                                                  NULL);
 }