[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: fixing tng testcase unix communicator
From: |
gnunet |
Subject: |
[gnunet] branch master updated: fixing tng testcase unix communicator |
Date: |
Sun, 22 Dec 2019 04:29:19 +0100 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new dc090c05b fixing tng testcase unix communicator
dc090c05b is described below
commit dc090c05b18f416543266e9f47f6a2cff0125b92
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Sun Dec 22 12:26:04 2019 +0900
fixing tng testcase unix communicator
---
src/transport/Makefile.am | 1 +
src/transport/gnunet-communicator-unix.c | 34 ++++-
src/transport/test_communicator_unix.c | 212 ++++++++++++++++---------------
src/transport/transport-testing2.c | 22 +++-
src/transport/transport-testing2.h | 2 +-
5 files changed, 155 insertions(+), 116 deletions(-)
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index ae77899a0..a5b9aaaa8 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -786,6 +786,7 @@ test_communicator_unix_SOURCES = \
test_communicator_unix.c
test_communicator_unix_LDADD = \
libgnunettransporttesting2.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la
test_plugin_unix_SOURCES = \
diff --git a/src/transport/gnunet-communicator-unix.c
b/src/transport/gnunet-communicator-unix.c
index 58a144ecb..404bcfb7f 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -114,7 +114,7 @@ struct Queue
* Message currently scheduled for transmission, non-NULL if and only
* if this queue is in the #queue_head DLL.
*/
- const struct GNUNET_MessageHeader *msg;
+ struct UNIXMessage *msg;
/**
* Message queue we are providing for the #ch.
@@ -142,6 +142,10 @@ struct Queue
struct GNUNET_SCHEDULER_Task *timeout_task;
};
+/**
+ * My Peer Identity
+ */
+static struct GNUNET_PeerIdentity my_identity;
/**
* ID of read task
@@ -357,7 +361,7 @@ lookup_queue_it (void *cls, const struct
GNUNET_PeerIdentity *key, void *value)
struct LookupCtx *lctx = cls;
struct Queue *queue = value;
- if ((queue->address_len = lctx->un_len) &&
+ if ((queue->address_len == lctx->un_len) &&
(0 == memcmp (lctx->un, queue->address, queue->address_len)))
{
lctx->res = queue;
@@ -383,6 +387,7 @@ lookup_queue (const struct GNUNET_PeerIdentity *peer,
lctx.un = un;
lctx.un_len = un_len;
+ lctx.res = NULL;
GNUNET_CONTAINER_multipeermap_get_multiple (queue_map,
peer,
&lookup_queue_it,
@@ -401,7 +406,7 @@ static void
select_write_cb (void *cls)
{
struct Queue *queue = queue_tail;
- const struct GNUNET_MessageHeader *msg = queue->msg;
+ const struct GNUNET_MessageHeader *msg = &queue->msg->header;
size_t msg_size = ntohs (msg->size);
ssize_t sent;
@@ -514,10 +519,15 @@ mq_send (struct GNUNET_MQ_Handle *mq,
void *impl_state)
{
struct Queue *queue = impl_state;
+ size_t msize = ntohs (msg->size);
GNUNET_assert (mq == queue->mq);
GNUNET_assert (NULL == queue->msg);
- queue->msg = msg;
+ //Convert to UNIXMessage
+ queue->msg = GNUNET_malloc (msize + sizeof (struct UNIXMessage));
+ queue->msg->header.size = htons(msize + sizeof (struct UNIXMessage));
+ queue->msg->sender = my_identity;
+ memcpy (&queue->msg[1], msg, msize);
GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue);
GNUNET_assert (NULL != unix_sock);
if (NULL == write_task)
@@ -747,6 +757,9 @@ select_read_cb (void *cls)
msize = ntohs (msg->header.size);
if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Wrong message size: %d bytes\n",
+ msize);
GNUNET_break_op (0);
return;
}
@@ -974,9 +987,22 @@ run (void *cls,
struct sockaddr_un *un;
socklen_t un_len;
char *my_addr;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
(void) cls;
+ my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
+ if (NULL == my_private_key)
+ {
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "UNIX communicator is lacking key configuration settings.
Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
COMMUNICATOR_CONFIG_SECTION,
diff --git a/src/transport/test_communicator_unix.c
b/src/transport/test_communicator_unix.c
index db355c93e..83ab1ea26 100644
--- a/src/transport/test_communicator_unix.c
+++ b/src/transport/test_communicator_unix.c
@@ -1,33 +1,34 @@
/*
- This file is part of GNUnet.
- Copyright (C) 2019 GNUnet e.V.
+ This file is part of GNUnet.
+ Copyright (C) 2019 GNUnet e.V.
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ 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
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
- SPDX-License-Identifier: AGPL3.0-or-later
- */
+ SPDX-License-Identifier: AGPL3.0-or-later
+*/
/**
- * @file transport/test_communicator_unix.c
- * @brief test the unix communicator
- * @author Julius Bünger
- */
+* @file transport/test_communicator_unix.c
+* @brief test the unix communicator
+* @author Julius Bünger
+*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "transport-testing2.h"
#include "gnunet_ats_transport_service.h"
#include "gnunet_signatures.h"
+#include "gnunet_testing_lib.h"
#include "transport.h"
#include <inttypes.h>
@@ -41,9 +42,17 @@
static struct GNUNET_PeerIdentity peer_id[NUM_PEERS];
+static char *communicator_binary;
+
static struct
GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS];
+static struct GNUNET_CONFIGURATION_Handle *cfg_peers[NUM_PEERS];
+
+static char **cfg_peers_name;
+
+static int ret;
+
// static char *addresses[NUM_PEERS];
@@ -53,7 +62,6 @@ GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
*tc_hs[NUM_PEERS];
// static char payload[] = "TEST PAYLOAD";
static uint32_t payload = 42;
-
static void
communicator_available_cb (void *cls,
struct
@@ -62,7 +70,7 @@ communicator_available_cb (void *cls,
enum GNUNET_TRANSPORT_CommunicatorCharacteristics
cc,
char *address_prefix)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"Communicator available. (cc: %u, prefix: %s)\n",
cc,
address_prefix);
@@ -85,9 +93,12 @@ add_address_cb (void *cls,
aid,
nt);
// addresses[1] = GNUNET_strdup (address);
- GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0],
- &peer_id[1],
- address);
+ if (0 == strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1]))
+ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0],
+ &peer_id[
+ NUM_PEERS
+ - 1],
+ address);
}
@@ -156,11 +167,20 @@ void
incoming_message_cb (void *cls,
struct
GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
*tc_h,
- const struct GNUNET_MessageHeader *msg)
+ const struct GNUNET_TRANSPORT_IncomingMessage *msg)
{
+ char *payload_ptr;
+ if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1]))
+ return; // TODO?
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s received data (%lu bytes payload)\n",
+ (char*) cls,
+ ntohs (msg->header.size) - sizeof (struct
GNUNET_TRANSPORT_IncomingMessage));
+ payload_ptr = (char*)&msg[1] + sizeof (struct GNUNET_MessageHeader);
+ ret = memcmp (payload_ptr, &payload, sizeof (payload));
+ GNUNET_SCHEDULER_shutdown ();
}
-
/**
* @brief Main function called by the scheduler
*
@@ -169,28 +189,19 @@ incoming_message_cb (void *cls,
static void
run (void *cls)
{
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
-
- tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
- "transport",
- "gnunet-communicator-unix",
- "test_communicator_1.conf",
- &communicator_available_cb,
- NULL,
- &queue_create_reply_cb,
- &add_queue_cb,
- NULL,
- NULL); /* cls */
- tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
- "transport",
- "gnunet-communicator-unix",
- "test_communicator_2.conf",
- &communicator_available_cb,
- &add_address_cb,
- NULL,
- &add_queue_cb,
- NULL,
- NULL); /* cls */
+ for (int i = 0; i < NUM_PEERS; i++)
+ {
+ tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
+ "transport",
+ communicator_binary,
+ cfg_peers_name[i],
+ &communicator_available_cb,
+ &add_address_cb,
+ &queue_create_reply_cb,
+ &add_queue_cb,
+ &incoming_message_cb,
+ cfg_peers_name[i]); /* cls */
+ }
}
@@ -198,81 +209,72 @@ int
main (int argc,
char *const *argv)
{
- char *cfg_filename;
- char *opt_cfg_filename;
- const char *xdg;
- char *loglev;
- char *logfile;
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- struct GNUNET_GETOPT_CommandLineOption service_options[] = {
- GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
- GNUNET_GETOPT_option_help (NULL),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_logfile (&logfile),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix",
- loglev,
- logfile))
+ struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
+ char *communicator_name;
+ char *cfg_peer;
+ ret = 1;
+
+ communicator_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
+ GNUNET_asprintf (&communicator_binary, "gnunet-communicator-%s",
+ communicator_name);
+ cfg_peers_name = GNUNET_malloc (sizeof(char*) * NUM_PEERS);
+ if (GNUNET_OK != GNUNET_log_setup ("test_communicator",
+ "DEBUG",
+ "test_communicator.log"))
{
+ fprintf (stderr, "Unable to setup log\n");
GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- xdg = getenv ("XDG_CONFIG_HOME");
- if (NULL != xdg)
- GNUNET_asprintf (&cfg_filename,
- "%s%s%s",
- xdg,
- DIR_SEPARATOR_STR,
- GNUNET_OS_project_data_get ()->config_file);
- else
- cfg_filename = GNUNET_strdup (
- GNUNET_OS_project_data_get ()->user_config_file);
- cfg = GNUNET_CONFIGURATION_create ();
- if (NULL != opt_cfg_filename)
- {
- if ((GNUNET_YES !=
- GNUNET_DISK_file_test (opt_cfg_filename)) ||
- (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- opt_cfg_filename)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Malformed configuration file `%s', exit ...\n"),
- opt_cfg_filename);
- return GNUNET_SYSERR;
- }
+ return 2;
}
- else
+ for (int i = 0; i < NUM_PEERS; i++)
{
+ GNUNET_asprintf ((&cfg_peer),
+ "test_communicator_%s_peer%u.conf",
+ communicator_name, i + 1);
+ cfg_peers_name[i] = cfg_peer;
+ cfg_peers[i] = GNUNET_CONFIGURATION_create ();
if (GNUNET_YES ==
- GNUNET_DISK_file_test (cfg_filename))
+ GNUNET_DISK_file_test (cfg_peers_name[i]))
{
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- cfg_filename))
+ GNUNET_CONFIGURATION_load (cfg_peers[i],
+ cfg_peers_name[i]))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Malformed configuration file `%s', exit ...\n"),
- cfg_filename);
- return GNUNET_SYSERR;
+ fprintf (stderr,
+ "Malformed configuration file `%s', exiting ...\n",
+ cfg_peers_name[i]);
+ return 1;
}
}
else
{
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
+ GNUNET_CONFIGURATION_load (cfg_peers[i],
NULL))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Malformed configuration, exit ...\n"));
- return GNUNET_SYSERR;
+ fprintf (stderr,
+ "Configuration file %s does not exist, exiting ...\n",
+ cfg_peers_name[i]);
+ return 1;
}
}
+ private_key =
+ GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg_peers[i]);
+ if (NULL == private_key)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Unable to get peer ID\n");
+ return 1;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (private_key,
+ &peer_id[i].public_key);
+ GNUNET_free (private_key);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Identity of peer %u is %s\n",
+ i, GNUNET_i2s_full (&peer_id[i]));
}
+ fprintf (stderr, "Starting test...\n");
GNUNET_SCHEDULER_run (&run,
- cfg);
+ NULL);
+ return ret;
}
diff --git a/src/transport/transport-testing2.c
b/src/transport/transport-testing2.c
index 7204d26da..b354f7c2a 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -306,14 +306,14 @@ handle_add_address (void *cls,
{
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
uint16_t size;
-
size = ntohs (msg->header.size) - sizeof(*msg);
if (0 == size)
return; /* receive-only communicator */
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "received add address cb %u\n", size);
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 add_address_cb()\n");
tc_h->add_address_cb (tc_h->cb_cls,
tc_h,
tc_h->c_address,
@@ -366,7 +366,7 @@ handle_incoming_msg (void *cls,
{
tc_h->incoming_msg_cb (tc_h->cb_cls,
tc_h,
- (const struct GNUNET_MessageHeader *) msg);
+ msg);
}
else
{
@@ -452,9 +452,19 @@ handle_add_queue_message (void *cls,
struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
tc_queue = tc_h->queue_head;
- while (tc_queue->qid != msg->qid)
+ if (NULL != tc_queue)
{
- tc_queue = tc_queue->next;
+ while (tc_queue->qid != msg->qid)
+ {
+ tc_queue = tc_queue->next;
+ }
+ } else {
+ tc_queue =
+ GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
+ tc_queue->tc_h = tc_h;
+ tc_queue->qid = msg->qid;
+ tc_queue->peer_id = msg->receiver;
+ GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
}
GNUNET_assert (tc_queue->qid == msg->qid);
GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
@@ -663,7 +673,7 @@ communicator_start (
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!");
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "started communicator\n");
+ LOG (GNUNET_ERROR_TYPE_INFO, "started communicator\n");
GNUNET_free (binary);
/* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator,
tc_h->c_proc);
diff --git a/src/transport/transport-testing2.h
b/src/transport/transport-testing2.h
index b136be125..49e4791aa 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -135,7 +135,7 @@ typedef void
GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
*tc_h,
const struct
- GNUNET_MessageHeader *msg);
+
GNUNET_TRANSPORT_IncomingMessage *msg);
/**
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: fixing tng testcase unix communicator,
gnunet <=