Browse Source

add backchannel test; fix udp basic

Schanzenbach, Martin 4 years ago
parent
commit
65b645e3c3

+ 21 - 2
src/transport/Makefile.am

@@ -599,7 +599,9 @@ check_PROGRAMS += \
   test_communicator_basic-unix \
   test_communicator_basic-tcp \
   test_communicator_basic-udp \
-  test_communicator_rekey-tcp
+  test_communicator_rekey-tcp \
+  test_communicator_rekey-udp \
+  test_communicator_backchannel-udp
 endif
 endif
 
@@ -813,6 +815,19 @@ test_communicator_rekey_tcp_LDADD = \
  $(top_builddir)/src/testing/libgnunettesting.la \
  $(top_builddir)/src/util/libgnunetutil.la
 
+test_communicator_rekey_udp_SOURCES = \
+ test_communicator_basic.c
+test_communicator_rekey_udp_LDADD = \
+ libgnunettransporttesting2.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
+test_communicator_backchannel_udp_SOURCES = \
+ test_communicator_basic.c
+test_communicator_backchannel_udp_LDADD = \
+ libgnunettransporttesting2.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la
 endif
 
 test_plugin_unix_SOURCES = \
@@ -1519,4 +1534,8 @@ test_communicator_basic_tcp_peer2.conf \
 test_communicator_basic_udp_peer1.conf \
 test_communicator_basic_udp_peer2.conf \
 test_communicator_rekey_tcp_peer1.conf \
-test_communicator_rekey_tcp_peer2.conf
+test_communicator_rekey_tcp_peer2.conf \
+test_communicator_rekey_udp_peer1.conf \
+test_communicator_rekey_udp_peer2.conf \
+test_communicator_backchannel_udp_peer1.conf \
+test_communicator_backchannel_udp_peer2.conf

+ 36 - 0
src/transport/test_communicator_udp_backchannel_peer1.conf

@@ -0,0 +1,36 @@
+@INLINE@ test_transport_defaults.conf
+
+[PATHS]
+GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/
+
+[PEER]
+PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-1/private.key
+
+[transport-tcp]
+PORT = 52400
+
+[transport-udp]
+PORT = 52401
+
+[transport]
+PORT = 60000
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-transport_test_1.sock
+
+[nat]
+UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/nat.sock
+ENABLE_IPSCAN = YES
+
+[communicator-unix]
+UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock
+
+[communicator-tcp]
+BINDTO = 60002
+DISABLE_V6 = YES
+
+[communicator-udp]
+BINDTO = 60002
+DISABLE_V6 = YES
+MAX_QUEUE_LENGTH=5000
+
+[communicator-test]
+BACKCHANNEL_ENABLED = YES

+ 36 - 0
src/transport/test_communicator_udp_backchannel_peer2.conf

@@ -0,0 +1,36 @@
+@INLINE@ test_transport_defaults.conf
+
+[PATHS]
+GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-plugin-transport/
+
+[PEER]
+PRIVATE_KEY = $GNUNET_TMP/test-communicator-unix-2/private.key
+
+
+[transport-tcp]
+PORT = 52400
+
+[transport-udp]
+PORT = 52401
+
+[transport]
+PORT = 60001
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-transport_test_2.sock
+
+[nat]
+UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
+
+[communicator-unix]
+UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock
+
+[communicator-tcp]
+BINDTO = 60003
+DISABLE_V6 = YES
+
+[communicator-udp]
+BINDTO = 60003
+DISABLE_V6 = YES
+MAX_QUEUE_LENGTH=5000
+
+[communicator-test]
+BACKCHANNEL_ENABLED = YES

+ 0 - 0
src/transport/test_communicator_udp_peer1.conf → src/transport/test_communicator_udp_basic_peer1.conf


+ 30 - 3
src/transport/transport-testing2.c

@@ -150,6 +150,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
    * @brief Closure to the callback
    */
   void *cb_cls;
+
+  /**
+   * Backchannel supported
+   */
+  int bc_enabled;
 };
 
 
@@ -320,9 +325,28 @@ handle_communicator_backchannel (void *cls,
   struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
   struct GNUNET_MessageHeader *msg;
   msg = (struct GNUNET_MessageHeader *) &bc_msg[1];
-  size_t payload_len = ntohs (msg->size) - sizeof (struct
-                                                   GNUNET_MessageHeader);
-
+  struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi;
+  struct GNUNET_MQ_Envelope *env;
+  uint16_t isize = ntohs (msg->size);
+  const char *target_communicator = ((const char *) msg) + isize;
+  if (tc_h->bc_enabled != GNUNET_YES)
+  {
+    GNUNET_SERVICE_client_continue (tc_h->client);
+    return;
+  }
+  /* Find client providing this communicator */
+  /* Finally, deliver backchannel message to communicator */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Delivering backchannel message of type %u to %s\n",
+              ntohs (msg->type),
+              target_communicator);
+  env = GNUNET_MQ_msg_extra (
+    cbi,
+    isize,
+    GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING);
+  cbi->pid = bc_msg->pid;
+  memcpy (&cbi[1], msg, isize);
+  GNUNET_MQ_send (tc_h->c_mq, env);
   GNUNET_SERVICE_client_continue (tc_h->client);
 }
 
@@ -873,6 +897,9 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
     GNUNET_free (tc_h);
     return NULL;
   }
+  tc_h->bc_enabled = GNUNET_CONFIGURATION_get_value_yesno (tc_h->cfg,
+                                                           "communicator-test",
+                                                           "BACKCHANNEL_ENABLED");
   tc_h->communicator_available_cb = communicator_available_cb;
   tc_h->add_address_cb = add_address_cb;
   tc_h->queue_create_reply_cb = queue_create_reply_cb;