* 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.
struct GNUNET_SCHEDULER_Task *timeout_task;
};
+/**
+ * My Peer Identity
+ */
+static struct GNUNET_PeerIdentity my_identity;
/**
* ID of read task
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;
lctx.un = un;
lctx.un_len = un_len;
+ lctx.res = NULL;
GNUNET_CONTAINER_multipeermap_get_multiple (queue_map,
peer,
&lookup_queue_it,
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;
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)
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;
}
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,
/*
- 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>
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];
// static char payload[] = "TEST PAYLOAD";
static uint32_t payload = 42;
-
static void
communicator_available_cb (void *cls,
struct
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);
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);
}
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
*
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 */
+ }
}
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;
}
{
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,
{
tc_h->incoming_msg_cb (tc_h->cb_cls,
tc_h,
- (const struct GNUNET_MessageHeader *) msg);
+ msg);
}
else
{
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));
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);