gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r37564 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r37564 - gnunet/src/transport
Date: Sat, 23 Jul 2016 00:02:38 +0200

Author: grothoff
Date: 2016-07-23 00:02:38 +0200 (Sat, 23 Jul 2016)
New Revision: 37564

Modified:
   gnunet/src/transport/test_transport_address_switch.c
Log:
migrate more tests to new transmission API

Modified: gnunet/src/transport/test_transport_address_switch.c
===================================================================
--- gnunet/src/transport/test_transport_address_switch.c        2016-07-22 
21:35:51 UTC (rev 37563)
+++ gnunet/src/transport/test_transport_address_switch.c        2016-07-22 
22:02:38 UTC (rev 37564)
@@ -48,40 +48,16 @@
 #include "transport-testing.h"
 
 
-GNUNET_NETWORK_STRUCT_BEGIN
-struct TestMessage
-{
-  struct GNUNET_MessageHeader header;
-  uint32_t num GNUNET_PACKED;
-};
-GNUNET_NETWORK_STRUCT_END
-
 /**
- * Message type for test messages
- */
-#define MTYPE 12345
-
-/**
- * Message size for test messages
- */
-#define MSIZE 2048
-
-/**
  * Testcase timeout
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 5)
 
-
 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
 
 static struct GNUNET_SCHEDULER_Task *measure_task;
 
-static struct GNUNET_TRANSPORT_TransmitHandle *th;
 
 /**
  * Statistics we track per peer.
@@ -243,11 +219,6 @@
       stats[i].stat = NULL;
     }
   }
-  if (NULL != th)
-  {
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
-    th = NULL;
-  }
 
   result = 0;
   FPRINTF (stderr, "\n");
@@ -293,7 +264,8 @@
   if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
        (bytes_sent_after_switch == 0) )
   {
-    FPRINTF (stderr, "No data sent after switching!\n");
+    FPRINTF (stderr,
+            "No data sent after switching!\n");
     GNUNET_break (0);
     result++;
   }
@@ -300,7 +272,8 @@
   if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
        (bytes_recv_after_switch == 0) )
   {
-    FPRINTF (stderr, "No data received after switching!\n");
+    FPRINTF (stderr,
+            "No data received after switching!\n");
     GNUNET_break (0);
     result++;
   }
@@ -315,10 +288,10 @@
                 const struct GNUNET_PeerIdentity *sender,
                 const struct GNUNET_MessageHeader *message)
 {
-  const struct TestMessage *hdr;
+  const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
 
-  hdr = (const struct TestMessage *) message;
-  if (MTYPE != ntohs (message->type))
+  hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
+  if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
     return;
 
   {
@@ -338,7 +311,8 @@
         (stats[1].switch_attempts == stats[1].switch_fail + 
stats[1].switch_success) )
   {
     bytes_recv_after_switch += ntohs(hdr->header.size);
-    if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
+    if ( (bytes_sent_after_switch > 0) &&
+        (bytes_recv_after_switch > 0) )
     {
       /* A peer switched addresses and sent and received data after the
        * switch operations */
@@ -348,80 +322,31 @@
 }
 
 
-static size_t
-notify_ready (void *cls, size_t size, void *buf)
+static void
+notify_send (void *cls)
 {
-  static uint32_t counter;
-  char *cbuf = buf;
-  struct TestMessage hdr;
+  static uint32_t cnt;
 
-  th = NULL;
-  if (buf == NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-               "Timeout occurred while waiting for transmit_ready for 
message\n");
-    ccc->global_ret = GNUNET_SYSERR;
-    GNUNET_SCHEDULER_shutdown ();
-    return 0;
-  }
-
-  GNUNET_assert(size >= MSIZE);
-  GNUNET_assert(buf != NULL);
-  cbuf = buf;
-
-  hdr.header.size = htons (MSIZE);
-  hdr.header.type = htons (MTYPE);
-  hdr.num = htonl (counter++);
-  GNUNET_memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage));
-  memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct 
TestMessage));
-
-  {
-    char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
-
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Sending message %u of size %u from peer %u (`%4s') -> peer %u 
(`%s') !\n",
-                (unsigned int) (counter - 1),
-                MSIZE,
-                ccc->p[1]->no,
-                GNUNET_i2s (&ccc->p[1]->id),
-                ccc->p[0]->no,
-                receiver_s);
-    GNUNET_free(receiver_s);
-  }
-
-  if (th == NULL)
-    th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
-                                                 &ccc->p[0]->id,
-                                                 MSIZE,
-                                                 TIMEOUT_TRANSMIT,
-                                                 &notify_ready,
-                                                 NULL);
-
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
+                                               ccc->p[0],
+                                               
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+                                               
GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
+                                               ++cnt,
+                                               &notify_send,
+                                               NULL));
   if ( ( (stats[0].switch_attempts >= 1) ||
          (stats[1].switch_attempts >= 1) ) &&
        (stats[0].switch_attempts == stats[0].switch_fail + 
stats[0].switch_success) &&
        (stats[1].switch_attempts == stats[1].switch_fail + 
stats[1].switch_success) )
   {
-    bytes_sent_after_switch += MSIZE;
+    bytes_sent_after_switch
+      += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE;
   }
-  return MSIZE;
 }
 
 
 static void
-notify_disconnect (void *cls,
-                   struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
-                   const struct GNUNET_PeerIdentity *other)
-{
-  if (NULL != th)
-  {
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
-    th = NULL;
-  }
-}
-
-
-static void
 progress_indicator (void *cls)
 {
   static int counter;
@@ -472,11 +397,14 @@
                                                &progress_indicator,
                                                NULL);
   /* Peers are connected, start transmit test messages */
-  th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
-                                               &ccc->p[0]->id, MSIZE,
-                                               TIMEOUT_TRANSMIT,
-                                               &notify_ready, NULL);
-
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_TRANSPORT_TESTING_send (ccc->p[1],
+                                               ccc->p[0],
+                                               
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+                                               
GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
+                                               0,
+                                               &notify_send,
+                                               NULL));
 }
 
 
@@ -489,7 +417,6 @@
     .config_file = "test_transport_api.conf",
     .rec = &notify_receive,
     .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
-    .nd = &notify_disconnect,
     .shutdown_task = &custom_shutdown,
     .timeout = TIMEOUT
   };




reply via email to

[Prev in Thread] Current Thread [Next in Thread]