From fd2c163785e39d6346bc872ad4f496dffe00b4fd Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Tue, 26 Nov 2019 12:41:20 +0100 Subject: [PATCH] added test code for channel destroy bug --- src/cadet/Makefile.am | 1 + src/cadet/cadet.h | 65 ++++++++- src/cadet/cadet_api.c | 67 --------- src/cadet/cadet_api_drop_message.c | 165 +++-------------------- src/cadet/gnunet-service-cadet_tunnels.c | 15 ++- src/cadet/gnunet-service-cadet_tunnels.h | 8 ++ src/cadet/test_cadet.c | 54 ++++++-- src/rest/rest.conf | 7 + 8 files changed, 145 insertions(+), 237 deletions(-) diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index e7d42f60f..b94a50245 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am @@ -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 \ diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index adb9d356c..b6c38e512 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h @@ -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. diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index ff6f15543..f9efd533b 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c @@ -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. */ diff --git a/src/cadet/cadet_api_drop_message.c b/src/cadet/cadet_api_drop_message.c index 1d9030af8..808d0d4f7 100644 --- a/src/cadet/cadet_api_drop_message.c +++ b/src/cadet/cadet_api_drop_message.c @@ -23,168 +23,37 @@ * @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 */ diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c index d9e4141ac..4ecdefc65 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.c +++ b/src/cadet/gnunet-service-cadet_tunnels.c @@ -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); diff --git a/src/cadet/gnunet-service-cadet_tunnels.h b/src/cadet/gnunet-service-cadet_tunnels.h index 3ee2c9852..9da81881c 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.h +++ b/src/cadet/gnunet-service-cadet_tunnels.h @@ -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. diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index ae4a8fd8b..458f345be 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c @@ -25,6 +25,7 @@ */ #include #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__); diff --git a/src/rest/rest.conf b/src/rest/rest.conf index 2b690b5b3..7a074e999 100644 --- a/src/rest/rest.conf +++ b/src/rest/rest.conf @@ -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 -- 2.25.1