-some code cleanup (indentation, redundant branches, etc.)
authorChristian Grothoff <christian@grothoff.org>
Sat, 7 Nov 2015 00:06:26 +0000 (00:06 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 7 Nov 2015 00:06:26 +0000 (00:06 +0000)
src/transport/plugin_transport_http_common.c
src/transport/test_quota_compliance.c
src/transport/test_transport_api_bidirectional_connect.c
src/transport/test_transport_api_blacklisting.c
src/transport/test_transport_api_manipulation_cfg.c
src/transport/test_transport_api_manipulation_recv_tcp.c
src/transport/test_transport_api_manipulation_send_tcp.c
src/transport/test_transport_api_monitor_peers.c
src/transport/test_transport_api_monitor_validation.c
src/transport/test_transport_api_restart_1peer.c

index 13f01f7131b6bc5a97f9cae4ba95a13e1075def5..9c0e93a3782083ff6bcc29ea543590e2dd761ba3 100644 (file)
@@ -567,7 +567,7 @@ http_common_plugin_address_to_url (void *cls,
     GNUNET_break(0);
     return NULL;
   }
-  if (0 >= addrlen)
+  if (0 == addrlen)
   {
     GNUNET_break(0);
     return NULL;
@@ -611,14 +611,14 @@ http_common_plugin_address_to_string (const char *plugin,
 
   GNUNET_assert(NULL != plugin);
   if (NULL == addr)
-    return NULL ;
+    return NULL;
   if (0 == addrlen)
-    return NULL ;
+    return NULL;
   if (addrlen != http_common_address_get_size (address))
-    return NULL ;
+    return NULL;
   addr_str = (char *) &address[1];
   if (addr_str[ntohl (address->urlen) - 1] != '\0')
-    return NULL ;
+    return NULL;
   GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options),
       &address[1]);
   if (strlen (res) + 1 < 500)
@@ -629,7 +629,7 @@ http_common_plugin_address_to_string (const char *plugin,
   }
   GNUNET_break(0);
   GNUNET_free(res);
-  return NULL ;
+  return NULL;
 }
 
 /**
@@ -772,7 +772,7 @@ http_common_socket_from_address (const void *addr,
     GNUNET_break (0);
     return NULL;
   }
-  if (0 >= addrlen)
+  if (0 == addrlen)
   {
     GNUNET_break (0);
     return NULL;
@@ -868,14 +868,14 @@ http_common_cmp_addresses (const void *addr1,
 
   if (NULL == a1)
     return GNUNET_SYSERR;
-  if (0 >= addrlen1)
+  if (0 == addrlen1)
     return GNUNET_SYSERR;
   if (a1[addrlen1 - 1] != '\0')
     return GNUNET_SYSERR;
 
   if (NULL == a2)
     return GNUNET_SYSERR;
-  if (0 >= addrlen2)
+  if (0 == addrlen2)
     return GNUNET_SYSERR;
   if (a2[addrlen2 - 1] != '\0')
     return GNUNET_SYSERR;
index b53bda514e953c9b9fa2a668ec196a1a2cf6f196..d01d335f839757431826e6b3863ec4634d84fe09 100644 (file)
@@ -209,23 +209,29 @@ get_size (unsigned int iter)
 
 
 static void
-notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
+notify_receive (void *cls,
+                const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_MessageHeader *message)
 {
   const struct TestMessage *hdr;
+  struct PeerContext *p = cls;
 
   hdr = (const struct TestMessage *) message;
   if (MTYPE != ntohs (message->type))
     return;
 
-  struct PeerContext *p = cls;
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
-              p->no, ps, ntohl (hdr->num), ntohs (message->size),
-              GNUNET_i2s (peer));
-  GNUNET_free (ps);
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
+                p->no,
+                ps,
+                ntohl (hdr->num),
+                ntohs (message->size),
+                GNUNET_i2s (peer));
+    GNUNET_free (ps);
+  }
 }
 
 
@@ -315,8 +321,10 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 
   struct PeerContext *p = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n",
-              p->no, GNUNET_i2s (peer));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Peer %u (`%4s') connected to us!\n",
+              p->no,
+              GNUNET_i2s (peer));
 }
 
 
@@ -325,7 +333,9 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   struct PeerContext *p = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Peer %u (`%4s') disconnected!\n",
+              p->no,
               GNUNET_i2s (peer));
   if (th != NULL)
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
index 5c9ae36fe073ccf42a4d261c42746e9944b9e0df..f7f284a9a2474f08c1555b6ac9482434c25abb55 100644 (file)
@@ -185,20 +185,24 @@ 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);
 }
 
@@ -229,7 +233,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 +242,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 +260,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 +288,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 +302,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);
 }
 
 
index 9c3a0c4607790a1c85ab2cae5be637236518f022..f2265028f6e5be3811eb7b5ddfbce899ebe046c2 100644 (file)
@@ -236,24 +236,28 @@ notify_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_MESSAGE_TYPE);
 
-  if (buf != NULL)
   {
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_MESSAGE_TYPE);
-  }
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "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);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "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 TEST_MESSAGE_SIZE;
 }
 
+
 static void
 sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -291,12 +295,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_DEBUG,
-              "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_DEBUG,
+                "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
+                p->no,
+                ps,
+                t->no,
+                GNUNET_i2s (peer));
+    GNUNET_free (ps);
+  }
 }
 
 
index 41ad7f68f37cd37ca653c70b53683ec8c0708703..ce968a4975d41b769f9739d18325349420f0f086 100644 (file)
@@ -107,6 +107,7 @@ end ()
   GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
 }
 
+
 static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -180,26 +181,31 @@ notify_request_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
-  if (buf != NULL)
+  memset (buf, '\0', TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE);
+
   {
-    memset (buf, '\0', TEST_MESSAGE_SIZE);
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE);
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Sending request message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n",
+                p1->no, ps,
+                ntohs (hdr->type),
+                ntohs (hdr->size),
+                p->no,
+                GNUNET_i2s (&p->id));
+    GNUNET_free (ps);
   }
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending request message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n",
-              p1->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
-              GNUNET_i2s (&p->id));
-  GNUNET_free (ps);
   return TEST_MESSAGE_SIZE;
 }
 
 
 static void
-sendtask_request_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+sendtask_request_task (void *cls,
+                       const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   send_task = NULL;
 
@@ -240,42 +246,55 @@ notify_response_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
-  if (buf != NULL)
+  memset (buf, '\0', TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE);
+
   {
-    memset (buf, '\0', TEST_MESSAGE_SIZE);
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE);
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Sending response message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n",
+                p1->no,
+                ps,
+                ntohs (hdr->type),
+                ntohs (hdr->size),
+                p->no,
+                GNUNET_i2s (&p->id));
+    GNUNET_free (ps);
   }
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending response message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n",
-              p1->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no,
-              GNUNET_i2s (&p->id));
-  GNUNET_free (ps);
-
   return TEST_MESSAGE_SIZE;
 }
 
+
 static void
-sendtask_response_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+sendtask_response_task (void *cls,
+                        const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   send_task = NULL;
 
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     return;
-  char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
+  {
+    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);
+    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);
+  }
 
   s_sending = GNUNET_YES;
-       start_response = GNUNET_TIME_absolute_get();
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE,
-                                               TIMEOUT_TRANSMIT, &notify_response_ready,
+  start_response = GNUNET_TIME_absolute_get();
+  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
+                                               &p1->id,
+                                               TEST_MESSAGE_SIZE,
+                                               TIMEOUT_TRANSMIT,
+                                               &notify_response_ready,
                                                p1);
 }
 
index 8a820fa162a433b79f24b9794b67d1d1f32b6a6d..48e0fe418ad9ce918111dbe5b62aba2d0df179ff 100644 (file)
@@ -264,27 +264,32 @@ notify_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
-  if (buf != NULL)
+  memset (buf, '\0', TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_MESSAGE_TYPE);
+
   {
-    memset (buf, '\0', TEST_MESSAGE_SIZE);
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_MESSAGE_TYPE);
-  }
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
 
-  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);
+    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 TEST_MESSAGE_SIZE;
 }
 
 
 static void
-sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+sendtask (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   send_task = NULL;
 
@@ -300,22 +305,26 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   if (0 == messages_recv)
   {
-       start_normal = GNUNET_TIME_absolute_get();
+    start_normal = GNUNET_TIME_absolute_get();
   }
   if (1 == messages_recv)
   {
-               start_delayed = GNUNET_TIME_absolute_get();
+    start_delayed = GNUNET_TIME_absolute_get();
   }
 
   s_sending = GNUNET_YES;
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE,
-                                               TIMEOUT_TRANSMIT, &notify_ready,
+  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
+                                               &p1->id,
+                                               TEST_MESSAGE_SIZE,
+                                               TIMEOUT_TRANSMIT,
+                                               &notify_ready,
                                                p1);
 }
 
 
 static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+                const struct GNUNET_PeerIdentity *peer)
 {
   static int c;
 
@@ -329,42 +338,63 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
     t = p2;
   GNUNET_assert (t != NULL);
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+  {
+    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);
+    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);
+  }
 }
 
 
 static void
-notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+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_DEBUG,
-              "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
-              GNUNET_i2s (peer));
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
 
-  GNUNET_free (ps);
+    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_notify_transmit_ready_cancel (th);
-  th = NULL;
+    th = NULL;
+  }
 }
 
 
 static void
-testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
+testing_connect_cb (struct PeerContext *p1,
+                    struct PeerContext *p2,
+                    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);
+  {
+    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);
+  }
 
   s_connected = GNUNET_YES;
   send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
@@ -377,21 +407,31 @@ start_cb (struct PeerContext *p, void *cls)
   static int started;
   started++;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Peer %u (`%s') started\n",
+              p->no,
               GNUNET_i2s (&p->id));
 
   if (started != 2)
     return;
   else
     s_started = GNUNET_YES;
-  char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
+  {
+    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);
+    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 (tth, p1, p2, &testing_connect_cb,
+  cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth,
+                                               p1,
+                                               p2,
+                                               &testing_connect_cb,
                                                NULL);
 
 }
index 0a52556abe7db4cf5813308b61fc9df36970521d..a1f9055ea38330e0cff202d6acef5609624b5403 100644 (file)
@@ -85,6 +85,7 @@ static struct GNUNET_TIME_Relative dur_normal;
 static struct GNUNET_TIME_Absolute start_delayed;
 static struct GNUNET_TIME_Relative dur_delayed;
 
+
 static void
 end ()
 {
@@ -104,6 +105,7 @@ end ()
   GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
 }
 
+
 static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -160,6 +162,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
+
 static void
 notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_MessageHeader *message)
@@ -173,13 +176,19 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
     t = p2;
   GNUNET_assert (t != NULL);
 
-  char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
+  {
+    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);
+    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);
+  }
 
   if ((TEST_MESSAGE_TYPE == ntohs (message->type)) &&
       (TEST_MESSAGE_SIZE == ntohs (message->size)))
@@ -252,21 +261,24 @@ notify_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
-  if (buf != NULL)
+  memset (buf, '\0', TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_MESSAGE_TYPE);
+
   {
-    memset (buf, '\0', TEST_MESSAGE_SIZE);
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_MESSAGE_TYPE);
+    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 TEST_MESSAGE_SIZE;
 }
 
@@ -291,7 +303,6 @@ sendtask (void *cls,
               receiver_s);
   GNUNET_free (receiver_s);
 
-
   if (0 == messages_recv)
   {
     start_normal = GNUNET_TIME_absolute_get ();
@@ -325,23 +336,27 @@ static void
 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   static int c;
-
-  c++;
   struct PeerContext *p = cls;
   struct 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));
+  {
+    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);
+    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);
+  }
 }
 
 
@@ -349,17 +364,23 @@ 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_DEBUG,
-              "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
-              GNUNET_i2s (peer));
+  {
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
 
-  GNUNET_free (ps);
+    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_notify_transmit_ready_cancel (th);
-  th = NULL;
+    th = NULL;
+  }
 }
 
 
@@ -367,12 +388,18 @@ static void
 testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, 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);
+  {
+    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);
+  }
 
   s_connected = GNUNET_YES;
   send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
@@ -385,7 +412,9 @@ start_cb (struct PeerContext *p, void *cls)
   static int started;
   started++;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Peer %u (`%s') started\n",
+              p->no,
               GNUNET_i2s (&p->id));
 
   if (started != 2)
index 8cd952cc541a3962c751a402b6e8d93bc9405a30..38884f7d512ea2e853012d53c4f871e0e04210b8 100644 (file)
@@ -237,21 +237,25 @@ notify_ready (void *cls, size_t size, void *buf)
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
-  if (buf != NULL)
+  memset (buf, '\0', TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_MESSAGE_TYPE);
+
   {
-    memset (buf, '\0', TEST_MESSAGE_SIZE);
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_MESSAGE_TYPE);
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "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_INFO,
-              "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 TEST_MESSAGE_SIZE;
 }
 
index 76fa66949bfce5c8aed3075b9fa416057ac5dc8d..ac7a1805b31cbb75a127e56878cf386800edcc37 100644 (file)
@@ -229,40 +229,45 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
 
 
 static size_t
-notify_ready (void *cls, size_t size, void *buf)
+notify_ready (void *cls,
+              size_t size,
+              void *buf)
 {
   struct PeerContext *p = cls;
   struct GNUNET_MessageHeader *hdr;
 
   th = NULL;
-
-  if (buf == 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);
+    die_task = GNUNET_SCHEDULER_add_now (&end_badly,
+                                         NULL);
     ok = 42;
     return 0;
   }
 
   GNUNET_assert (size >= TEST_MESSAGE_SIZE);
-  if (buf != NULL)
+  memset (buf, '\0', TEST_MESSAGE_SIZE);
+  hdr = buf;
+  hdr->size = htons (TEST_MESSAGE_SIZE);
+  hdr->type = htons (TEST_MESSAGE_TYPE);
+
   {
-    memset (buf, '\0', TEST_MESSAGE_SIZE);
-    hdr = buf;
-    hdr->size = htons (TEST_MESSAGE_SIZE);
-    hdr->type = htons (TEST_MESSAGE_TYPE);
+    char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "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_INFO,
-              "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 TEST_MESSAGE_SIZE;
 }
 
@@ -290,9 +295,13 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 done ()
 {
-  if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c) && p1_c_notify && p2_c_notify)
+  if ( (GNUNET_YES == p1_c) &&
+       (GNUNET_YES == p2_c) &&
+       p1_c_notify &&
+       p2_c_notify)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Both peers state to be connected\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Both peers state to be connected\n");
     ok = 0;
     end();
   }
@@ -403,7 +412,7 @@ monitor1_cb (void *cls,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Monitor 1: %s %s %s\n",
-             GNUNET_i2s (&address->peer), 
+             GNUNET_i2s (&address->peer),
              GNUNET_TRANSPORT_vs2s (state),
              GNUNET_STRINGS_absolute_time_to_string(valid_until));
   if (0 == memcmp (&address->peer,
@@ -427,7 +436,7 @@ monitor2_cb (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Monitor 2: %s %s %s\n",
              GNUNET_i2s (&address->peer),
-             GNUNET_TRANSPORT_vs2s(state), 
+             GNUNET_TRANSPORT_vs2s(state),
              GNUNET_STRINGS_absolute_time_to_string(valid_until));
   if (0 == memcmp (&address->peer,
                   &p1->id,
index 2c4382e9cee469cd9257e626bce8fbb16cf0b2c8..86eb299ef1f6a4643570295091913cbc6f694ba1 100644 (file)
@@ -225,7 +225,7 @@ notify_ready (void *cls, size_t size, void *buf)
 
   th = NULL;
 
-  if (buf == NULL)
+  if (NULL == buf)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout occurred while waiting for transmit_ready\n");
@@ -237,20 +237,23 @@ 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);
 }
 
@@ -269,14 +272,18 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
               p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
   GNUNET_free (receiver_s);
 
-  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256,
-                                               TIMEOUT_TRANSMIT, &notify_ready,
+  th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
+                                               &p1->id,
+                                               256,
+                                               TIMEOUT_TRANSMIT,
+                                               &notify_ready,
                                                p1);
 }
 
 
 static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+                const struct GNUNET_PeerIdentity *peer)
 {
   static int c;