added test code for channel destroy bug
authort3sserakt <t3ss@posteo.de>
Tue, 26 Nov 2019 11:41:20 +0000 (12:41 +0100)
committert3sserakt <t3ss@posteo.de>
Fri, 3 Jan 2020 11:06:32 +0000 (12:06 +0100)
src/cadet/Makefile.am
src/cadet/cadet.h
src/cadet/cadet_api.c
src/cadet/cadet_api_drop_message.c
src/cadet/gnunet-service-cadet_tunnels.c
src/cadet/gnunet-service-cadet_tunnels.h
src/cadet/test_cadet.c
src/rest/rest.conf

index e7d42f60f1173d01b6f2194f09382b18fec28077..b94a502452f2bfa4e845075c0dd92e697cb53c6a 100644 (file)
@@ -34,6 +34,7 @@ lib_LTLIBRARIES = \
 
 libgnunetcadet_la_SOURCES = \
   cadet_api.c \
+  cadet_api_drop_message.c \
   cadet_api_get_channel.c \
   cadet_api_get_path.c \
   cadet_api_list_peers.c \
index adb9d356c72af46e16a716ed48225df5301ae1e1..b6c38e512d330868aedb4a8c19a6a0bd97d70f62 100644 (file)
@@ -95,7 +95,6 @@ extern "C" {
 
 GNUNET_NETWORK_STRUCT_BEGIN
 
-
 /**
  * Number uniquely identifying a channel of a client.
  */
@@ -111,6 +110,70 @@ struct GNUNET_CADET_ClientChannelNumber
   uint32_t channel_of_client GNUNET_PACKED;
 };
 
+/**
+ * Opaque handle to a channel.
+ */
+struct GNUNET_CADET_Channel
+{
+
+  /**
+   * Other end of the channel.
+   */
+  struct GNUNET_PeerIdentity peer;
+
+  /**
+   * Handle to the cadet this channel belongs to
+   */
+  struct GNUNET_CADET_Handle *cadet;
+
+  /**
+   * Channel's port, if incoming.
+   */
+  struct GNUNET_CADET_Port *incoming_port;
+
+  /**
+   * Any data the caller wants to put in here, used for the
+   * various callbacks (@e disconnects, @e window_changes, handlers).
+   */
+  void *ctx;
+
+  /**
+   * Message Queue for the channel (which we are implementing).
+   */
+  struct GNUNET_MQ_Handle *mq;
+
+  /**
+   * Task to allow mq to send more traffic.
+   */
+  struct GNUNET_SCHEDULER_Task *mq_cont;
+
+  /**
+   * Pending envelope with a message to be transmitted to the
+   * service as soon as we are allowed to.  Should only be
+   * non-NULL if @e allow_send is 0.
+   */
+  struct GNUNET_MQ_Envelope *pending_env;
+
+  /**
+   * Window change handler.
+   */
+  GNUNET_CADET_WindowSizeEventHandler window_changes;
+
+  /**
+   * Disconnect handler.
+   */
+  GNUNET_CADET_DisconnectEventHandler disconnects;
+
+  /**
+   * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
+   */
+  struct GNUNET_CADET_ClientChannelNumber ccn;
+
+  /**
+   * How many messages are we allowed to send to the service right now?
+   */
+  unsigned int allow_send;
+};
 
 /**
  * Message for a client to create and destroy channels.
index ff6f15543908f986c3baa25ebc8ee1fca39be9a9..f9efd533b63365c30e63e0b4cdae2ae3a2141485 100644 (file)
@@ -73,73 +73,6 @@ struct GNUNET_CADET_Handle
   struct GNUNET_TIME_Relative reconnect_time;
 };
 
-
-/**
- * Opaque handle to a channel.
- */
-struct GNUNET_CADET_Channel
-{
-
-  /**
-   * Other end of the channel.
-   */
-  struct GNUNET_PeerIdentity peer;
-
-  /**
-   * Handle to the cadet this channel belongs to
-   */
-  struct GNUNET_CADET_Handle *cadet;
-
-  /**
-   * Channel's port, if incoming.
-   */
-  struct GNUNET_CADET_Port *incoming_port;
-
-  /**
-   * Any data the caller wants to put in here, used for the
-   * various callbacks (@e disconnects, @e window_changes, handlers).
-   */
-  void *ctx;
-
-  /**
-   * Message Queue for the channel (which we are implementing).
-   */
-  struct GNUNET_MQ_Handle *mq;
-
-  /**
-   * Task to allow mq to send more traffic.
-   */
-  struct GNUNET_SCHEDULER_Task *mq_cont;
-
-  /**
-   * Pending envelope with a message to be transmitted to the
-   * service as soon as we are allowed to.  Should only be
-   * non-NULL if @e allow_send is 0.
-   */
-  struct GNUNET_MQ_Envelope *pending_env;
-
-  /**
-   * Window change handler.
-   */
-  GNUNET_CADET_WindowSizeEventHandler window_changes;
-
-  /**
-   * Disconnect handler.
-   */
-  GNUNET_CADET_DisconnectEventHandler disconnects;
-
-  /**
-   * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
-   */
-  struct GNUNET_CADET_ClientChannelNumber ccn;
-
-  /**
-   * How many messages are we allowed to send to the service right now?
-   */
-  unsigned int allow_send;
-};
-
-
 /**
  * Opaque handle to a port.
  */
index 1d9030af8912a2dbab1e411c6be8aa854eda29fd..808d0d4f70aff9629268567bd52f73739c0df5d5 100644 (file)
  * @author t3sserakt
  */
 #include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_constants.h"
-#include "gnunet_cadet_service.h"
 #include "cadet.h"
-#include "cadet_protocol.h"
 
 
 /**
- * Operation handle.
- */
-struct GNUNET_CADET_ChannelMonitor
-{
-
-  /**
-   * Channel callback.
-   */
-  GNUNET_CADET_ChannelCB channel_cb;
-
-  /**
-   * Info callback closure for @c channel_cb.
-   */
-  void *channel_cb_cls;
-
-  /**
-   * Configuration we use.
-   */
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  /**
-   * Message queue to talk to CADET service.
-   */
-  struct GNUNET_MQ_Handle *mq;
-  
-  /**
-   * Task to reconnect.
-   */
-  struct GNUNET_SCHEDULER_Task *reconnect_task;
-
-  /**
-   * Backoff for reconnect attempts.
-   */
-  struct GNUNET_TIME_Relative backoff;
-
-  /**
-   * Peer we want information about.
-   */
-  struct GNUNET_PeerIdentity peer;
-
-};
-
-
-/**
- * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE request.
+ * Drop the next cadet message of a given type..
  *
- * @param cls client Identification of the client.
- * @param message The actual message.
+ * @param mq message queue
+ * @param ccn client channel number.
+ * @param type of cadet message to be dropped.
  */
-static void
-handle_drop_message (void *cls,
-                     const struct GNUNET_CADET_RequestDropCadetMessage *message)
+void
+GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq,
+                          struct GNUNET_CADET_ClientChannelNumber ccn,
+                          uint16_t type)
 {
-  struct CadetClient *c = cls;
-  struct CadetChannel *ch;
+  struct GNUNET_CADET_RequestDropCadetMessage *message;
+  struct GNUNET_MQ_Envelope *env;
 
-  ch = lookup_channel (c,
-                       message->ccn);
+  env = GNUNET_MQ_msg (message, GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE);
 
-  GCCH_assign_type_to_drop(ch, message);
+  message->ccn = ccn;
+  message->type = type;
   
-  GNUNET_SERVICE_client_continue (c->client);
-}
-
-/**
- * Reconnect to the service and try again.
- *
- * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
- */
-static void
-reconnect (struct GNUNET_CADET_Handle *h);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Dropping message for channel of type \n");
 
-
-/**
- * Function called on connection trouble.  Reconnects.
- *
- * @param cls a `struct GNUNET_CADET_ChannelMonitor``
- * @param error error code from MQ
- */
-static void
-error_handler (void *cls,
-              enum GNUNET_MQ_Error error)
-{
-  struct GNUNET_CADET_ChannelMonitor *cm = cls;
-
-  GNUNET_MQ_destroy (cm->mq);
-  cm->mq = NULL;
-  cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff,
-                                               GNUNET_TIME_UNIT_MINUTES);
-  cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff,
-                                                    &reconnect,
-                                                    cm);
-}
-
-
-/**
- * Reconnect to the service and try again.
- *
- * @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
- */
-static void
-reconnect (void *clsstruct GNUNET_CADET_Handle *h)
-{
+  GNUNET_MQ_send (mq, env);
   
-  struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (drop_message,
-                            GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE,
-                            struct GNUNET_CADET_RequestDropCadetMessage,
-                            NULL),
-    GNUNET_MQ_handler_end ()
-  };
-  GNUNET_assert (NULL == h->mq);
-  h->mq =
-    GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &error_handler, h);
-}
-
-
-/**
- * Request information about a specific channel of the running cadet peer.
- *
- * @param cfg configuration to use
- * @param peer ID of the other end of the channel.
- * @param callback Function to call with the requested data.
- * @param callback_cls Closure for @c callback.
- * @return NULL on error
- */
-struct GNUNET_CADET_ChannelMonitor *
-GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                          struct GNUNET_PeerIdentity *peer,
-                          GNUNET_CADET_ChannelCB callback,
-                          void *callback_cls)
-{
-  struct GNUNET_CADET_ChannelMonitor *cm;
-
-  if (NULL == callback)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor);
-  cm->channel_cb = callback;
-  cm->channel_cb_cls = callback_cls;
-  cm->cfg = cfg;
-  cm->peer = *peer;
-  reconnect (cm);
-  if (NULL == cm->mq)
-  {
-    GNUNET_free (cm);
-    return NULL;
-  }
-  return cm;
 }
 
 
 
 
-/* end of cadet_api_get_channel.c */
+/* end of cadet_api_drop_message.c */
index d9e4141ac02c0a3ca9dead9c325ac13264ba8cee..4ecdefc65fd2c9aa43f8ad3e97b7bebba376887f 100644 (file)
@@ -9,7 +9,7 @@
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHsendANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
     
      You should have received a copy of the GNU Affero General Public License
@@ -464,9 +464,10 @@ struct CadetTunnel
  * @param other the other peer
  * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
  */
-static int
-alice_or_betty (const struct GNUNET_PeerIdentity *other)
+int
+GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other)
 {
+
   if (0 > GNUNET_memcmp (&my_full_id,
                                            other))
     return GNUNET_YES;
@@ -477,7 +478,7 @@ alice_or_betty (const struct GNUNET_PeerIdentity *other)
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
-  }
+    }
 }
 
 
@@ -1346,7 +1347,7 @@ send_kx (struct CadetTunnel *t,
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Will we ever send a KX message?\n");
   
-  if (GNUNET_YES != alice_or_betty (GCP_get_id (t->destination)))
+  if (GNUNET_YES != GCT_alice_or_betty (GCP_get_id (t->destination)))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Only Alice may send KX to %s!\n",
@@ -1531,7 +1532,7 @@ update_ax_by_kx (struct CadetTunnelAxolotl *ax,
   const char salt[] = "CADET Axolotl salt";
   int am_I_alice;
 
-  if (GNUNET_SYSERR == (am_I_alice = alice_or_betty (pid)))
+  if (GNUNET_SYSERR == (am_I_alice = GCT_alice_or_betty (pid)))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
@@ -1733,7 +1734,7 @@ GCT_handle_kx (struct CadetTConnection *ct,
                             1,
                             GNUNET_NO);
   if (GNUNET_YES ==
-      alice_or_betty (GCP_get_id (t->destination)))
+      GCT_alice_or_betty (GCP_get_id (t->destination)))
   {
     /* Betty/Bob is not allowed to send KX! */
     GNUNET_break_op (0);
index 3ee2c9852c6bee2cd3356629a47462ee263a9728..9da81881c9a8e3ec848a22834ad0689eaae986e1 100644 (file)
@@ -82,6 +82,14 @@ enum CadetTunnelEState
 
 };
 
+/**
+ * Am I Alice or Betty (some call her Bob), or talking to myself?
+ *
+ * @param other the other peer
+ * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
+ */
+int
+GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other);
 
 /**
  * Get the static string for the peer this tunnel is directed.
index ae4a8fd8bed9805f6266a9e2fe24f252554d95e4..458f345be3437eb8911fb517d3d95047b23f553c 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include <stdio.h>
 #include "platform.h"
+#include "cadet.h"
 #include "cadet_test_lib.h"
 #include "gnunet_cadet_service.h"
 #include "gnunet_statistics_service.h"
@@ -200,11 +201,6 @@ static struct GNUNET_SCHEDULER_Task *send_next_msg_task;
  */
 static struct GNUNET_CADET_Handle *h1;
 
-/**
- * Cadet handle for the first leaf peer
- */
-static struct GNUNET_CADET_Handle *h2;
-
 /**
  * Channel handle for the root peer
  */
@@ -246,6 +242,17 @@ static unsigned int ka_received;
  */
 static unsigned int msg_dropped;
 
+/**
+ * Drop the next cadet message of a given type..
+ *
+ * @param mq message queue
+ * @param ccn client channel number.
+ * @param type of cadet message to be dropped.
+ */
+void
+GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq,
+                          struct GNUNET_CADET_ClientChannelNumber ccn,
+                          uint16_t type);
 
 /******************************************************************************/
 
@@ -1021,18 +1028,32 @@ start_test (void *cls)
 
   ch->ch = outgoing_ch;
 
+  /*if (DESTROY == test)
+  {
+
+    GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch),
+                              outgoing_ch->ccn,
+                              GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE);
+    GNUNET_CADET_channel_destroy(outgoing_ch);
+
+    outgoing_ch = GNUNET_CADET_channel_create (h1,
+                                             ch,
+                                             p_id[1],
+                                             &port,
+                                             NULL,
+                                             &disconnect_handler,
+                                             handlers);
+
+    ch->ch = outgoing_ch;
+    
+    }*/
+
+  
   disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
                                                   &gather_stats_and_exit,
                                                   (void *) __LINE__);
   if (KEEPALIVE == test)
     return;                     /* Don't send any data. */
-
-  if (DESTROY == test)
-  {
-
-    
-    
-  }
   
   data_received = 0;
   data_sent = 0;
@@ -1121,8 +1142,13 @@ tmain (void *cls,
   peers_running = num_peers;
   GNUNET_assert (peers_running == peers_requested);
   testbed_peers = peers;
-  h1 = cadets[0];
-  h2 = cadets[num_peers - 1];
+  if (0 < GNUNET_memcmp (p_id[0], p_id[num_peers - 1]))
+  {
+    h1 = cadets[0];
+  }else
+  {  
+    h1 = cadets[num_peers - 1];
+  }  
   disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
                                                   &disconnect_cadet_peers,
                                                   (void *) __LINE__);
index 2b690b5b3a091794924a10c8690bbdae1d688e42..7a074e999d41c790fc2e532fcd08f2ea22255a11 100644 (file)
@@ -9,3 +9,10 @@ REST_ALLOW_HEADERS=Authorization,Accept,Content-Type
 REST_ECHO_ORIGIN_WEBEXT=YES
 REST_ALLOW_ORIGIN=http://localhost:4200
 REST_ALLOW_CREDENTIALS=true
+
+# Do we require users that want to access the rest service to run this process
+# (usually not a good idea)
+UNIX_MATCH_UID = NO
+
+# Do we require users that want to access the rest service to be in the 'gnunet' group?
+UNIX_MATCH_GID = YES
\ No newline at end of file