From 14537ef71b43ac47fe342c4e88f7bd3675ed1e39 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 4 Jun 2019 21:05:01 +0200 Subject: misc bugfixes --- src/transport/transport-testing2.c | 209 +++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 111 deletions(-) (limited to 'src/transport/transport-testing2.c') diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index 2abe6c9ce..9bbd15983 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c @@ -35,7 +35,7 @@ #include "transport.h" -#define LOG(kind,...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle @@ -110,7 +110,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle /** * @brief Callback called when a new communicator connects */ - GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb; + GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback + communicator_available_cb; /** * @brief Callback called when a new communicator connects @@ -203,8 +204,9 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * @return GNUNET_YES in case message is correct */ static int -check_communicator_available (void *cls, - const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) +check_communicator_available ( + void *cls, + const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) { uint16_t size; @@ -223,8 +225,9 @@ check_communicator_available (void *cls, * @param msg Message struct */ static void -handle_communicator_available (void *cls, - const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) +handle_communicator_available ( + void *cls, + const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; uint16_t size; @@ -236,8 +239,7 @@ handle_communicator_available (void *cls, tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]); if (NULL != tc_h->communicator_available_cb) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "calling communicator_available_cb()\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); tc_h->communicator_available_cb (tc_h->cb_cls, tc_h, tc_h->c_characteristics, @@ -283,8 +285,7 @@ handle_add_address (void *cls, tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]); if (NULL != tc_h->add_address_cb) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "calling communicator_available()\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); tc_h->add_address_cb (tc_h->cb_cls, tc_h, tc_h->c_address, @@ -304,25 +305,22 @@ handle_queue_create_ok (void *cls, if (NULL != tc_h->queue_create_reply_cb) { - tc_h->queue_create_reply_cb (tc_h->cb_cls, - tc_h, - GNUNET_YES); + tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES); } GNUNET_SERVICE_client_continue (tc_h->client); } static void -handle_queue_create_fail (void *cls, - const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) +handle_queue_create_fail ( + void *cls, + const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; if (NULL != tc_h->queue_create_reply_cb) { - tc_h->queue_create_reply_cb (tc_h->cb_cls, - tc_h, - GNUNET_NO); + tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO); } GNUNET_SERVICE_client_continue (tc_h->client); } @@ -362,16 +360,13 @@ handle_add_queue_message (void *cls, tc_queue = tc_queue->next; } GNUNET_assert (tc_queue->qid == msg->qid); - GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, - &msg->receiver)); + GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); tc_queue->nt = msg->nt; tc_queue->mtu = msg->mtu; tc_queue->cs = msg->cs; if (NULL != tc_h->add_queue_cb) { - tc_h->add_queue_cb (tc_h->cb_cls, - tc_h, - tc_queue); + tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue); } GNUNET_SERVICE_client_continue (tc_h->client); } @@ -408,17 +403,17 @@ connect_cb (void *cls, struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Client connected.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); tc_h->client = client; tc_h->c_mq = mq; - if (NULL == tc_h->queue_head) return tc_h; + if (NULL == tc_h->queue_head) + return tc_h; while (NULL != (tc_queue_iter = tc_h->queue_head)) { - if (NULL == tc_queue_iter->open_queue_env) continue; - GNUNET_MQ_send (tc_h->c_mq, - tc_queue_iter->open_queue_env); + if (NULL == tc_queue_iter->open_queue_env) + continue; + GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); tc_queue_iter->open_queue_env = NULL; } return tc_h; @@ -439,8 +434,7 @@ disconnect_cb (void *cls, { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Client disconnected.\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); tc_h->client = NULL; } @@ -453,21 +447,22 @@ disconnect_cb (void *cls, * @param cfg Configuration */ static void -transport_communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) +transport_communicator_start ( + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) { struct GNUNET_MQ_MessageHandler mh[] = { GNUNET_MQ_hd_var_size (communicator_available, - GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, - struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, - &tc_h), + GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, + struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, + &tc_h), //GNUNET_MQ_hd_var_size (communicator_backchannel, // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, // struct GNUNET_TRANSPORT_CommunicatorBackchannel, // NULL), GNUNET_MQ_hd_var_size (add_address, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, - struct GNUNET_TRANSPORT_AddAddressMessage, - &tc_h), + GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, + struct GNUNET_TRANSPORT_AddAddressMessage, + &tc_h), //GNUNET_MQ_hd_fixed_size (del_address, // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, // struct GNUNET_TRANSPORT_DelAddressMessage, @@ -477,17 +472,17 @@ transport_communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunica // struct GNUNET_TRANSPORT_IncomingMessage, // NULL), GNUNET_MQ_hd_fixed_size (queue_create_ok, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, - struct GNUNET_TRANSPORT_CreateQueueResponse, - tc_h), + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, + struct GNUNET_TRANSPORT_CreateQueueResponse, + tc_h), GNUNET_MQ_hd_fixed_size (queue_create_fail, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, - struct GNUNET_TRANSPORT_CreateQueueResponse, - tc_h), + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, + struct GNUNET_TRANSPORT_CreateQueueResponse, + tc_h), GNUNET_MQ_hd_var_size (add_queue_message, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, - struct GNUNET_TRANSPORT_AddQueueMessage, - NULL), + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, + struct GNUNET_TRANSPORT_AddQueueMessage, + NULL), //GNUNET_MQ_hd_fixed_size (del_queue_message, // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, // struct GNUNET_TRANSPORT_DelQueueMessage, @@ -506,12 +501,10 @@ transport_communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunica tc_h, mh); if (NULL == h) - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed starting service!\n"); + LOG (GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); else { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Started service\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h); } } @@ -527,16 +520,14 @@ shutdown_communicator (void *cls) { struct GNUNET_OS_Process *proc = cls; - if (GNUNET_OK != GNUNET_OS_process_kill (proc, - SIGTERM)) + if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGTERM)) { LOG (GNUNET_ERROR_TYPE_WARNING, - "Error shutting down communicator with SIGERM, trying SIGKILL\n"); - if (GNUNET_OK != GNUNET_OS_process_kill (proc, - SIGKILL)) + "Error shutting down communicator with SIGERM, trying SIGKILL\n"); + if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGKILL)) { LOG (GNUNET_ERROR_TYPE_ERROR, - "Error shutting down communicator with SIGERM and SIGKILL\n"); + "Error shutting down communicator with SIGERM and SIGKILL\n"); } } GNUNET_OS_process_destroy (proc); @@ -549,30 +540,29 @@ shutdown_communicator (void *cls) * @param cfgname Name of the communicator */ static void -communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) +communicator_start ( + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) { char *binary; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "communicator_start\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); binary = GNUNET_OS_get_libexec_binary_path ("gnunet-communicator-unix"); - tc_h->c_proc = - GNUNET_OS_start_process (GNUNET_YES, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - NULL, NULL, NULL, - binary, - "./gnunet-communicator-unix", - "-c", - tc_h->cfg_filename, - NULL); + tc_h->c_proc = GNUNET_OS_start_process (GNUNET_YES, + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, + NULL, + NULL, + binary, + "./gnunet-communicator-unix", + "-c", + tc_h->cfg_filename, + NULL); if (NULL == tc_h->c_proc) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to start communicator!"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "started communicator\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); GNUNET_free (binary); /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator, tc_h->c_proc); @@ -592,27 +582,30 @@ communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * @return Handle to the communicator duo */ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * -GNUNET_TRANSPORT_TESTING_transport_communicator_service_start - (const char *service_name, - const char *cfg_filename, - GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, - GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, - GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, - GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, - void *cb_cls) +GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( + const char *service_name, + const char *cfg_filename, + GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback + communicator_available_cb, + GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, + GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, + GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, + void *cb_cls) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; - tc_h = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); + tc_h = + GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); tc_h->cfg_filename = GNUNET_strdup (cfg_filename); tc_h->cfg = GNUNET_CONFIGURATION_create (); - if ( (GNUNET_SYSERR == - GNUNET_CONFIGURATION_load (tc_h->cfg, - cfg_filename)) ) + if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration file `%s', exit ...\n"), - cfg_filename); + _ ("Malformed configuration file `%s', exit ...\n"), + cfg_filename); + GNUNET_free (tc_h->cfg_filename); + GNUNET_CONFIGURATION_destroy (tc_h->cfg); + GNUNET_free (tc_h); return NULL; } tc_h->communicator_available_cb = communicator_available_cb; @@ -631,10 +624,10 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start void -GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue - (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, - const struct GNUNET_PeerIdentity *peer_id, - const char *address) +GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( + struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, + const struct GNUNET_PeerIdentity *peer_id, + const char *address) { struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; static uint32_t idgen; @@ -643,36 +636,33 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue struct GNUNET_MQ_Envelope *env; size_t alen; - tc_queue = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); + tc_queue = + GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); prefix = GNUNET_HELLO_address_to_prefix (address); if (NULL == prefix) { GNUNET_break (0); /* We got an invalid address!? */ + GNUNET_free (tc_queue); return; } + GNUNET_free (prefix); alen = strlen (address) + 1; - env = GNUNET_MQ_msg_extra (msg, - alen, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); + env = + GNUNET_MQ_msg_extra (msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); msg->request_id = htonl (idgen++); tc_queue->qid = msg->request_id; msg->receiver = *peer_id; tc_queue->peer_id = *peer_id; - memcpy (&msg[1], - address, - alen); + memcpy (&msg[1], address, alen); if (NULL != tc_h->c_mq) { - GNUNET_MQ_send (tc_h->c_mq, - env); + GNUNET_MQ_send (tc_h->c_mq, env); } else { tc_queue->open_queue_env = env; } - GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, - tc_h->queue_tail, - tc_queue); + GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue); } @@ -684,7 +674,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls*/) { - struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t; + // struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t; struct GNUNET_TRANSPORT_SendMessageTo *msg; struct GNUNET_MQ_Envelope *env; @@ -694,11 +684,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send msg->qid = htonl (tc_queue->qid); msg->mid = tc_queue->mid++; msg->receiver = tc_queue->peer_id; - memcpy (&msg[1], - payload, - payload_size); - GNUNET_MQ_send (tc_queue->tc_h->c_mq, - env); - return tc_t; + memcpy (&msg[1], payload, payload_size); + GNUNET_MQ_send (tc_queue->tc_h->c_mq, env); + GNUNET_break (0); /* fixme: return value? */ + return NULL; // tc_t; } - -- cgit v1.2.3