From 1d6a0664a68f141c1d2537c04ad5778803c72480 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 22 Jan 2017 18:02:13 +0100 Subject: [PATCH] misc bugfixes --- src/cadet/gnunet-service-cadet-new_channel.c | 6 +++--- .../gnunet-service-cadet-new_connection.c | 13 ++++++++++-- src/cadet/gnunet-service-cadet-new_paths.c | 2 +- src/cadet/gnunet-service-cadet-new_peer.c | 4 ++++ src/cadet/gnunet-service-cadet-new_tunnels.c | 20 +++++++++++-------- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index c129022ca..d83bab280 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c @@ -71,7 +71,7 @@ enum CadetChannelState /** * Connection create message sent, waiting for ACK. */ - CADET_CHANNEL_CREATE_SENT, + CADET_CHANNEL_OPEN_SENT, /** * Connection confirmed, ready to carry traffic. @@ -453,7 +453,7 @@ send_channel_open (void *cls) msgcc.opt = htonl (options); msgcc.port = ch->port; msgcc.ctn = ch->ctn; - ch->state = CADET_CHANNEL_CREATE_SENT; + ch->state = CADET_CHANNEL_OPEN_SENT; ch->last_control_qe = GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, @@ -821,7 +821,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch) /* this should be impossible */ GNUNET_break (0); break; - case CADET_CHANNEL_CREATE_SENT: + case CADET_CHANNEL_OPEN_SENT: if (NULL == ch->owner) { /* We're not the owner, wrong direction! */ diff --git a/src/cadet/gnunet-service-cadet-new_connection.c b/src/cadet/gnunet-service-cadet-new_connection.c index 01fb100c8..c44511400 100644 --- a/src/cadet/gnunet-service-cadet-new_connection.c +++ b/src/cadet/gnunet-service-cadet-new_connection.c @@ -176,6 +176,11 @@ GCC_destroy (struct CadetConnection *cc) GCP_request_mq_cancel (cc->mq_man, env); cc->mq_man = NULL; + if (NULL != cc->task) + { + GNUNET_SCHEDULER_cancel (cc->task); + cc->task = NULL; + } GCPP_del_connection (cc->path, cc->off, cc); @@ -329,6 +334,7 @@ send_create_ack (void *cls) struct GNUNET_MQ_Envelope *env; cc->task = NULL; + GNUNET_assert (CADET_CONNECTION_CREATE_RECEIVED == cc->state); LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION_CREATE_ACK message for %s\n", GCC_2s (cc)); @@ -357,8 +363,9 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) if (GNUNET_YES == cc->mqm_ready) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got duplicate CREATE for %s, scheduling another ACK\n", - GCC_2s (cc)); + "Got duplicate CREATE for %s, scheduling another ACK (%s)\n", + GCC_2s (cc), + (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); /* Tell tunnel that we are not ready for transmission anymore (until CREATE_ACK is done) */ cc->ready_cb (cc->ready_cb_cls, @@ -366,6 +373,8 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) /* Revert back to the state of having only received the 'CREATE', and immediately proceed to send the CREATE_ACK. */ cc->state = CADET_CONNECTION_CREATE_RECEIVED; + if (NULL != cc->task) + GNUNET_SCHEDULER_cancel (cc->task); cc->task = GNUNET_SCHEDULER_add_now (&send_create_ack, cc); } diff --git a/src/cadet/gnunet-service-cadet-new_paths.c b/src/cadet/gnunet-service-cadet-new_paths.c index c9fdbcb3a..86424968c 100644 --- a/src/cadet/gnunet-service-cadet-new_paths.c +++ b/src/cadet/gnunet-service-cadet-new_paths.c @@ -535,7 +535,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path, /* Shrink path to actual useful length */ GNUNET_array_grow (path->entries, path->entries_length, - i); + i + 1); LOG (GNUNET_ERROR_TYPE_DEBUG, "Created new path %s based on information from DHT\n", GCPP_2s (path)); diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c index f824caee6..fe40d76b6 100644 --- a/src/cadet/gnunet-service-cadet-new_peer.c +++ b/src/cadet/gnunet-service-cadet-new_peer.c @@ -668,6 +668,8 @@ GCP_path_entry_add (struct CadetPeer *cp, struct CadetPeerPathEntry *entry, unsigned int off) { + GNUNET_assert (cp == GCPP_get_peer_at_offset (entry->path, + off)); LOG (GNUNET_ERROR_TYPE_DEBUG, "Discovered that peer %s is on path %s at offset %u\n", GCP_2s (cp), @@ -759,6 +761,8 @@ GCP_attach_path (struct CadetPeer *cp, GNUNET_CONTAINER_HeapCostType root_desirability; struct GNUNET_CONTAINER_HeapNode *hn; + GNUNET_assert (cp == GCPP_get_peer_at_offset (path, + off)); if (NULL == cp->path_heap) { /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */ diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c index 58486dce5..e5fb91f44 100644 --- a/src/cadet/gnunet-service-cadet-new_tunnels.c +++ b/src/cadet/gnunet-service-cadet-new_tunnels.c @@ -1279,6 +1279,7 @@ send_kx (struct CadetTunnel *t, &msg->ephemeral_key); GNUNET_CRYPTO_ecdhe_key_get_public (ax->DHRs, &msg->ratchet_key); + ct->is_ready = GNUNET_NO; GCC_transmit (cc, env); t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay); @@ -1540,7 +1541,11 @@ destroy_tunnel (void *cls) GNUNET_free (ct); } while (NULL != (tq = t->tq_head)) + { + if (NULL != tq->cont) + tq->cont (tq->cont_cls); GCT_send_cancel (tq); + } GCP_drop_tunnel (t->destination, t); GNUNET_CONTAINER_multihashmap32_destroy (t->channels); @@ -2163,36 +2168,35 @@ decrypted_error_cb (void *cls, struct CadetTunnel * GCT_create_tunnel (struct CadetPeer *destination) { + struct CadetTunnel *t = GNUNET_new (struct CadetTunnel); struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_fixed_size (plaintext_keepalive, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE, struct GNUNET_MessageHeader, - NULL), + t), GNUNET_MQ_hd_var_size (plaintext_data, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA, struct GNUNET_CADET_ChannelAppDataMessage, - NULL), + t), GNUNET_MQ_hd_fixed_size (plaintext_data_ack, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK, struct GNUNET_CADET_ChannelDataAckMessage, - NULL), + t), GNUNET_MQ_hd_fixed_size (plaintext_channel_open, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN, struct GNUNET_CADET_ChannelOpenMessage, - NULL), + t), GNUNET_MQ_hd_fixed_size (plaintext_channel_open_ack, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK, struct GNUNET_CADET_ChannelManageMessage, - NULL), + t), GNUNET_MQ_hd_fixed_size (plaintext_channel_destroy, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY, struct GNUNET_CADET_ChannelManageMessage, - NULL), + t), GNUNET_MQ_handler_end () }; - struct CadetTunnel *t; - t = GNUNET_new (struct CadetTunnel); new_ephemeral (t); t->ax.kx_0 = GNUNET_CRYPTO_ecdhe_key_create (); t->destination = destination; -- 2.25.1