- fix coverity
[oweals/gnunet.git] / src / transport / test_transport_api_bidirectional_connect.c
index 85925b1bf24254e50dffbfe0a428966f3d56f653..a5d6b6b710884ba6a6855dd9c5272531893bc468 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2010 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
@@ -57,8 +57,8 @@ static struct PeerContext *p1;
 
 static struct PeerContext *p2;
 
-static GNUNET_TRANSPORT_TESTING_ConnectRequest cc1;
-static GNUNET_TRANSPORT_TESTING_ConnectRequest cc2;
+static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc1;
+static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc2;
 
 static struct GNUNET_TRANSPORT_TransmitHandle *th;
 
@@ -95,7 +95,7 @@ end ()
 
 
 static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+end_badly (void *cls)
 {
   die_task = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
@@ -185,33 +185,35 @@ notify_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= 256);
+  hdr = buf;
+  hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
+  hdr->type = htons (MTYPE);
 
-  if (buf != NULL)
   {
-    hdr = buf;
-    hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
-    hdr->type = htons (MTYPE);
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->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,
+                ps,
+                ntohs (hdr->type),
+                ntohs (hdr->size),
+                p->no,
+                GNUNET_i2s (&p->id));
+    GNUNET_free (ps);
   }
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p2->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, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
-              GNUNET_i2s (&p->id));
-  GNUNET_free (ps);
   return sizeof (struct GNUNET_MessageHeader);
 }
 
 
 static void
-sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+sendtask (void *cls)
 {
-  send_task = NULL;
-
-  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
-    return;
-  char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
+  char *receiver_s;
 
+  send_task = NULL;
+  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);
@@ -229,7 +231,6 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
   static int c;
 
   c++;
-  GNUNET_assert (NULL != cls);
   struct PeerContext *p = cls;
   struct PeerContext *t = NULL;
 
@@ -239,12 +240,17 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
     t = p2;
   GNUNET_assert (t != NULL);
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps,
-              t->no, GNUNET_i2s (peer));
-  GNUNET_free (ps);
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
+                p->no,
+                ps,
+                t->no,
+                GNUNET_i2s (peer));
+    GNUNET_free (ps);
+  }
 }
 
 
@@ -252,14 +258,17 @@ static void
 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   struct PeerContext *p = cls;
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
-              p->no, ps,
-              GNUNET_i2s (peer));
-  GNUNET_free (ps);
 
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
+                p->no,
+                ps,
+                GNUNET_i2s (peer));
+    GNUNET_free (ps);
+  }
   if (NULL != send_task)
   {
     GNUNET_SCHEDULER_cancel(send_task);
@@ -277,7 +286,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 static void
 testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
 {
-       static int connected = GNUNET_NO;
+  static int connected = GNUNET_NO;
+
   if ((cls == cc1) && (NULL != cc2))
   {
     GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc2);
@@ -290,14 +300,23 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
   cc2 = NULL;
 
   if (connected > 0)
-       return;
-  connected  ++;
-  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_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+    return;
+  connected++;
+
+  {
+    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_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                            &sendtask,
+                                            NULL);
 }