summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am47
-rw-r--r--src/transport/gnunet-communicator-tcp.c136
-rw-r--r--src/transport/gnunet-communicator-udp.c149
-rw-r--r--src/transport/gnunet-service-tng.c358
-rw-r--r--src/transport/tcp_service_legacy.c14
-rw-r--r--src/transport/test_transport_api2_tcp_node1.conf3
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c131
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_broadcast.c398
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_dv.c375
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c112
-rwxr-xr-xsrc/transport/test_transport_simple_send.sh10
-rwxr-xr-xsrc/transport/test_transport_simple_send_broadcast.sh11
-rw-r--r--src/transport/test_transport_simple_send_broadcast_topo.conf4
-rwxr-xr-xsrc/transport/test_transport_simple_send_dv.sh11
-rwxr-xr-xsrc/transport/test_transport_simple_send_string.sh19
-rw-r--r--src/transport/test_transport_simple_send_topo.conf6
-rw-r--r--src/transport/test_transport_start_with_config.c77
-rwxr-xr-xsrc/transport/test_transport_udp_backchannel.sh12
-rw-r--r--src/transport/test_transport_udp_backchannel_topo.conf7
-rw-r--r--src/transport/transport-testing-cmds.h204
-rw-r--r--src/transport/transport_api2_communication.c9
-rw-r--r--src/transport/transport_api2_core.c5
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c602
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c359
-rw-r--r--src/transport/transport_api_cmd_send_simple.c160
-rw-r--r--src/transport/transport_api_cmd_start_peer.c221
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c10
-rw-r--r--src/transport/transport_api_traits.c32
28 files changed, 2660 insertions, 822 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 0df422976..751bc40c1 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -123,6 +123,7 @@ endif
noinst_PROGRAMS = \
+ test_transport_start_with_config \
gnunet-transport-profiler \
gnunet-communicator-udp \
$(WLAN_BIN_SENDER) \
@@ -158,7 +159,9 @@ libgnunettransporttesting_la_LDFLAGS = \
$(GN_LIB_LDFLAGS)
libgnunettransporttesting2_la_SOURCES = \
+ transport_api_traits.c \
transport_api_cmd_connecting_peers.c \
+ transport_api_cmd_backchannel_check.c \
transport_api_cmd_start_peer.c \
transport_api_cmd_stop_peer.c \
transport_api_cmd_send_simple.c \
@@ -389,6 +392,8 @@ plugin_LTLIBRARIES = \
$(WLAN_PLUGIN_LA) \
$(BT_PLUGIN_LA) \
libgnunet_test_transport_plugin_cmd_simple_send.la \
+ libgnunet_test_transport_plugin_cmd_simple_send_broadcast.la \
+ libgnunet_test_transport_plugin_cmd_simple_send_dv.la \
libgnunet_test_transport_plugin_cmd_udp_backchannel.la
libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \
@@ -425,6 +430,40 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
+libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_SOURCES = \
+ test_transport_plugin_cmd_simple_send_broadcast.c
+libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_LIBADD = \
+ libgnunettransporttesting2.la \
+ libgnunettransportapplication.la \
+ libgnunettransportcore.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/ats/libgnunetats.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(LTLIBINTL)
+libgnunet_test_transport_plugin_cmd_simple_send_broadcast_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
+libgnunet_test_transport_plugin_cmd_simple_send_dv_la_SOURCES = \
+ test_transport_plugin_cmd_simple_send_dv.c
+libgnunet_test_transport_plugin_cmd_simple_send_dv_la_LIBADD = \
+ libgnunettransporttesting2.la \
+ libgnunettransportapplication.la \
+ libgnunettransportcore.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/ats/libgnunetats.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(LTLIBINTL)
+libgnunet_test_transport_plugin_cmd_simple_send_dv_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
if HAVE_EXPERIMENTAL
plugin_LTLIBRARIES += \
libgnunet_plugin_transport_udp.la
@@ -570,7 +609,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
$(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS
check_PROGRAMS = \
- test_transport_start_with_config \
test_transport_address_switch_tcp \
test_transport_testing_startstop \
test_transport_testing_restart \
@@ -718,7 +756,6 @@ test_transport_api_slow_ats
endif
if HAVE_EXPERIMENTAL
TESTS += \
- test_transport_start_with_config \
test_transport_address_switch_udp \
test_plugin_udp \
test_transport_api_udp \
@@ -737,15 +774,16 @@ endif
endif
check_SCRIPTS= \
+ test_transport_simple_send_string.sh \
test_transport_simple_send.sh \
- test_transport_udp_backchannel.sh
+ test_transport_simple_send_broadcast.sh \
+ test_transport_udp_backchannel.sh
test_transport_start_with_config_SOURCES = \
test_transport_start_with_config.c
test_transport_start_with_config_LDADD = \
$(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/testbed/libgnunettestbed.la \
$(top_builddir)/src/hello/libgnunethello.la \
libgnunettransportcore.la \
libgnunettransporttesting2.la
@@ -1481,6 +1519,7 @@ test_transport_api_slow_ats_LDADD = \
EXTRA_DIST = \
+$(check_SCRIPTS) \
gnunet-transport-certificate-creation.in \
communicator-unix.conf \
test_plugin_hostkey \
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index d8bf7c1a8..2a5e33e2b 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -1119,6 +1119,10 @@ pass_plaintext_to_core (struct Queue *queue,
const struct GNUNET_MessageHeader *hdr = plaintext;
int ret;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "pass message from %s to core\n",
+ GNUNET_i2s (&queue->target));
+
if (ntohs (hdr->size) != plaintext_len)
{
/* NOTE: If we ever allow multiple CORE messages in one
@@ -1132,6 +1136,8 @@ pass_plaintext_to_core (struct Queue *queue,
ADDRESS_VALIDITY_PERIOD,
&core_read_finished_cb,
queue);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "passed to core\n");
if (GNUNET_OK == ret)
queue->backpressure++;
GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
@@ -1795,7 +1801,7 @@ try_handle_plaintext (struct Queue *queue)
queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
&queue->target,
foreign_addr,
- UINT32_MAX, /* no MTU */
+ UINT16_MAX, /* no MTU */
GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
0, /* Priority */
queue->nt,
@@ -2004,7 +2010,8 @@ queue_read (void *cls)
* @return The struct sockaddr *.
*/
static struct sockaddr *
-tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
+tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len,
+ struct sockaddr_in6 v6,
unsigned int port)
{
struct sockaddr *in;
@@ -2031,7 +2038,8 @@ tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
* @return The struct sockaddr *.
*/
static struct sockaddr *
-tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4,
+tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len,
+ struct sockaddr_in v4,
unsigned int port)
{
struct sockaddr *in;
@@ -2116,7 +2124,7 @@ tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
static char *
extract_address (const char *bindto)
{
-
+ char *addr;
char *start;
char *token;
char *cp;
@@ -2141,6 +2149,7 @@ extract_address (const char *bindto)
{
start++; /* skip over '['*/
cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
+ addr = GNUNET_strdup (start);
}
else
{
@@ -2148,23 +2157,21 @@ extract_address (const char *bindto)
if (strlen (bindto) == strlen (token))
{
token = strtok_r (cp, ":", &rest);
+ addr = GNUNET_strdup (token);
}
else
{
token++;
res = GNUNET_strdup (token);
- GNUNET_free (cp);
- return res;
+ addr = GNUNET_strdup (res);
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "extract address 3\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "extract address with start %s\n",
- start);
-
- return GNUNET_strdup (start);
+ "tcp address: %s\n",
+ addr);
+ GNUNET_free (cp);
+ return addr;
}
@@ -2235,6 +2242,7 @@ extract_port (const char *addr_and_port)
GNUNET_free (cp);
return 0;
}
+ GNUNET_free (cp);
}
else
{
@@ -2244,7 +2252,6 @@ extract_port (const char *addr_and_port)
port = 0;
}
-
return port;
}
@@ -2265,9 +2272,8 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
struct sockaddr_in6 v6;
char *start;
- // cp = GNUNET_strdup (bindto);
start = extract_address (bindto);
-
+ // FIXME: check NULL == start
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"start %s\n",
start);
@@ -2444,7 +2450,7 @@ boot_queue (struct Queue *queue)
* Generate and transmit our ephemeral key and the signature for
* the initial KX with the other peer. Must be called first, before
* any other bytes are ever written to the output buffer. Note that
- * our cipher must already be initialized when calling this function.
+ * our cipher must already be initialized when calling thi function.
* Helper function for #start_initial_kx_out().
*
* @param queue queue to do KX for
@@ -2550,11 +2556,17 @@ handshake_monotime_cb (void *cls,
handshake_monotonic_time = &queue->handshake_monotonic_time;
pid = &queue->target;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp handshake with us %s\n",
+ GNUNET_i2s (&my_identity));
if (NULL == record)
{
queue->handshake_monotime_get = NULL;
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tcp handshake from peer %s\n",
+ GNUNET_i2s (pid));
if (sizeof(*mtbe) != record->value_size)
{
GNUNET_break (0);
@@ -2604,6 +2616,7 @@ decrypt_and_check_tc (struct Queue *queue,
char *ibuf)
{
struct TcpHandshakeSignature ths;
+ enum GNUNET_GenericReturnValue ret;
GNUNET_assert (
0 ==
@@ -2619,18 +2632,20 @@ decrypt_and_check_tc (struct Queue *queue,
memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
ths.monotonic_time = tc->monotonic_time;
ths.challenge = tc->challenge;
- queue->handshake_monotime_get =
- GNUNET_PEERSTORE_iterate (peerstore,
- "transport_tcp_communicator",
- &queue->target,
- GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE,
- &handshake_monotime_cb,
- queue);
- return GNUNET_CRYPTO_eddsa_verify (
+ ret = GNUNET_CRYPTO_eddsa_verify (
GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE,
&ths,
&tc->sender_sig,
&tc->sender.public_key);
+ if (GNUNET_YES == ret)
+ queue->handshake_monotime_get =
+ GNUNET_PEERSTORE_iterate (peerstore,
+ "transport_tcp_communicator",
+ &queue->target,
+ GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE,
+ &handshake_monotime_cb,
+ queue);
+ return ret;
}
@@ -2725,6 +2740,9 @@ proto_read_kx (void *cls)
queue->listen_sock = pq->listen_sock;
queue->sock = pq->sock;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "created queue with target %s\n",
+ GNUNET_i2s (&queue->target));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"start kx proto\n");
@@ -2984,6 +3002,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
queue->sock = sock;
queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND;
boot_queue (queue);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "booted queue with target %s\n",
+ GNUNET_i2s (&queue->target));
// queue->mq_awaits_continue = GNUNET_YES;
queue->read_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
@@ -3254,7 +3275,7 @@ init_socket (struct sockaddr *addr,
return GNUNET_SYSERR;
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"address %s\n",
GNUNET_a2s (addr, in_len));
@@ -3388,35 +3409,35 @@ init_socket (struct sockaddr *addr,
static void
nat_register ()
{
-
struct sockaddr **saddrs;
socklen_t *saddr_lens;
int i;
- struct Addresses *pos;
-
+ size_t len;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"starting nat register!\n");
-
+ len = 0;
i = 0;
- saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *));
-
- saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t));
-
- for (pos = addrs_head; NULL != pos; pos = pos->next)
+ saddrs = GNUNET_malloc ((addrs_lens) * sizeof(struct sockaddr *));
+ saddr_lens = GNUNET_malloc ((addrs_lens) * sizeof(socklen_t));
+ for (struct Addresses *pos = addrs_head; NULL != pos; pos = pos->next)
{
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"registering address %s\n",
GNUNET_a2s (addrs_head->addr, addrs_head->addr_len));
saddr_lens[i] = addrs_head->addr_len;
+ len += saddr_lens[i];
saddrs[i] = GNUNET_memdup (addrs_head->addr, saddr_lens[i]);
-
i++;
-
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "registering addresses %lu %lu %lu %lu\n",
+ (addrs_lens) * sizeof(struct sockaddr *),
+ (addrs_lens) * sizeof(socklen_t),
+ len,
+ sizeof(COMMUNICATOR_CONFIG_SECTION));
nat = GNUNET_NAT_register (cfg,
COMMUNICATOR_CONFIG_SECTION,
IPPROTO_TCP,
@@ -3426,9 +3447,6 @@ nat_register ()
&nat_address_cb,
NULL /* FIXME: support reversal: #5529 */,
NULL /* closure */);
-
- i = 0;
-
for (i = addrs_lens - 1; i >= 0; i--)
GNUNET_free (saddrs[i]);
GNUNET_free (saddrs);
@@ -3461,7 +3479,7 @@ init_socket_resolv (void *cls,
struct sockaddr *in;
(void) cls;
- if (NULL != addr)
+ if (NULL != addr)
{
if (AF_INET == addr->sa_family)
{
@@ -3495,7 +3513,6 @@ init_socket_resolv (void *cls,
return;
}
nat_register ();
-
}
}
@@ -3567,25 +3584,19 @@ run (void *cls,
if (1 == sscanf (bindto, "%u%1s", &bind_port, dummy))
{
po = tcp_address_to_sockaddr_port_only (bindto, &bind_port);
-
addr_len_ipv4 = po->addr_len_ipv4;
-
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"address po %s\n",
GNUNET_a2s (po->addr_ipv4, addr_len_ipv4));
-
if (NULL != po->addr_ipv4)
{
init_socket (po->addr_ipv4, addr_len_ipv4);
}
-
if (NULL != po->addr_ipv6)
{
addr_len_ipv6 = po->addr_len_ipv6;
init_socket (po->addr_ipv6, addr_len_ipv6);
}
-
GNUNET_free (po);
nat_register ();
GNUNET_free (bindto);
@@ -3593,7 +3604,7 @@ run (void *cls,
}
start = extract_address (bindto);
-
+ // FIXME: check for NULL == start...
if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
{
bind_port = extract_port (bindto);
@@ -3617,10 +3628,9 @@ run (void *cls,
return;
}
-
bind_port = extract_port (bindto);
-
- resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":",
+ resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto,
+ ":",
&rest),
AF_UNSPEC,
GNUNET_TIME_UNIT_MINUTES,
@@ -3646,16 +3656,22 @@ main (int argc, char *const *argv)
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
+ "transport",
+ "Starting tcp communicator\n");
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
return 2;
- ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-communicator-tcp",
- _ ("GNUnet TCP communicator"),
- options,
- &run,
- NULL))
+ ret = (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-communicator-tcp",
+ _ ("GNUnet TCP communicator"),
+ options,
+ &run,
+ NULL))
? 0
: 1;
GNUNET_free_nz ((void *) argv);
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index ef7b1d6c0..201e94e80 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -1494,7 +1494,27 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
GNUNET_assert (NULL != ss);
GNUNET_assert (NULL != receiver);
- GNUNET_assert (NULL != receiver->d_qh);
+
+ if (NULL == receiver->d_qh)
+ {
+ receiver->d_qh =
+ GNUNET_TRANSPORT_communicator_mq_add (ch,
+ &receiver->target,
+ receiver->foreign_addr,
+ receiver->d_mtu,
+ acks_to_add,
+ 1, /* Priority */
+ receiver->nt,
+ GNUNET_TRANSPORT_CS_OUTBOUND,
+ receiver->d_mq);
+ }
+ else
+ {
+ GNUNET_TRANSPORT_communicator_mq_update (ch,
+ receiver->d_qh,
+ acks_to_add,
+ 1);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Tell transport we have %u more acks!\n",
@@ -1502,10 +1522,7 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%u kce for rekeying.\n",
receiver->number_rekeying_kce);
- GNUNET_TRANSPORT_communicator_mq_update (ch,
- receiver->d_qh,
- acks_to_add,
- 1);
+
// Until here for alternativ 1
/* move ss to head to avoid discarding it anytime soon! */
@@ -1744,7 +1761,7 @@ kce_generate_cb (void *cls)
if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available <
KCN_TARGET) ) ||
((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) &&
- (ss->sender->acks_available < 128)))
+ (ss->sender->acks_available < KCN_TARGET)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1754,20 +1771,24 @@ kce_generate_cb (void *cls)
for (int i = 0; i < GENERATE_AT_ONCE; i++)
kce_generate (ss, ++ss->sequence_allowed);
- ss->sender->kce_task = GNUNET_SCHEDULER_add_delayed (
- WORKING_QUEUE_INTERVALL,
- kce_generate_cb,
- ss);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "We have enough keys.\n");
- ss_finished = ss;
- ss->sender->kce_task_finished = GNUNET_YES;
+ if (KCN_TARGET > ss->sender->acks_available)
+ {
+ ss->sender->kce_task = GNUNET_SCHEDULER_add_delayed (
+ WORKING_QUEUE_INTERVALL,
+ kce_generate_cb,
+ ss);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "We have enough keys.\n");
+ ss_finished = ss;
+ ss->sender->kce_task_finished = GNUNET_YES;
+ }
}
+
}
@@ -1850,7 +1871,17 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
kce_generate (ss, ++ss->sequence_allowed);
}*/
- if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial))
+ if (NULL != kce_task)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "kce_task is not NULL\n");
+ if (kce_task_finished)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "kce_task_finished: GNUNET_YES\n");
+ if (initial)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "initial: GNUNET_YES\n");
+
+ if ( kce_task_finished || (GNUNET_NO == initial))
{
struct UDPAck ack;
struct SharedSecret *ss_tell;
@@ -1877,8 +1908,7 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
if (GNUNET_NO != initial)
{
destroy_all_secrets (ss, GNUNET_YES);
- kce_task = NULL;
- kce_task_finished = GNUNET_NO;
+ ss->sender->kce_task_finished = GNUNET_NO;
}
}
else if ((NULL == kce_task) && ((KCN_THRESHOLD >
@@ -2232,6 +2262,7 @@ static void
sock_read (void *cls)
{
struct sockaddr_storage sa;
+ struct sockaddr_in *addr_verify;
socklen_t salen = sizeof(sa);
char buf[UINT16_MAX];
ssize_t rcvd;
@@ -2311,12 +2342,29 @@ sock_read (void *cls)
{
const struct UDPBroadcast *ub;
struct UdpBroadcastSignature uhs;
+ struct GNUNET_PeerIdentity sender;
+ addr_verify = GNUNET_memdup (&sa, salen);
+ addr_verify->sin_port = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "received UDPBroadcast from %s\n",
+ GNUNET_a2s ((const struct sockaddr *) addr_verify, salen));
ub = (const struct UDPBroadcast *) buf;
uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
uhs.purpose.size = htonl (sizeof(uhs));
uhs.sender = ub->sender;
- GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
+ sender = ub->sender;
+ if (0 == memcmp (&sender, &my_identity, sizeof (struct
+ GNUNET_PeerIdentity)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received our own broadcast\n");
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "checking UDPBroadcastSignature for %s\n",
+ GNUNET_i2s (&sender));
+ GNUNET_CRYPTO_hash ((struct sockaddr *) addr_verify, salen, &uhs.h_address);
if (GNUNET_OK ==
GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
&uhs,
@@ -2332,10 +2380,23 @@ sock_read (void *cls)
/* use our own mechanism to determine network type */
nt =
GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
- GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "validating address %s received from UDPBroadcast\n",
+ GNUNET_i2s (&sender));
+ GNUNET_TRANSPORT_application_validate (ah, &sender, nt, addr_s);
GNUNET_free (addr_s);
return;
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "VerifyingPeer %s is verifying UDPBroadcast\n",
+ GNUNET_i2s (&my_identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Verifying UDPBroadcast from %s failed\n",
+ GNUNET_i2s (&ub->sender));
+ }
+ GNUNET_free (addr_verify);
/* continue with KX, mostly for statistics... */
}
@@ -2678,8 +2739,10 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq,
receiver->address_len))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending KX to %s\n", GNUNET_a2s (receiver->address,
- receiver->address_len));
+ "Sending KX with payload size %u to %s\n",
+ msize,
+ GNUNET_a2s (receiver->address,
+ receiver->address_len));
GNUNET_MQ_impl_send_continue (mq);
}
@@ -2940,7 +3003,8 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
receiver->address_len))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending UDPBox %u acks left\n",
+ "Sending UDPBox with payload size %u, %u acks left\n",
+ msize,
receiver->acks_available);
GNUNET_MQ_impl_send_continue (mq);
receiver->acks_available--;
@@ -3135,17 +3199,6 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
receiver->nt,
GNUNET_TRANSPORT_CS_OUTBOUND,
receiver->kx_mq);
- receiver->d_qh =
- GNUNET_TRANSPORT_communicator_mq_add (ch,
- &receiver->target,
- receiver->foreign_addr,
- receiver->d_mtu,
- 0, /* Initialize with 0 acks */
- 1, /* Priority */
- receiver->nt,
- GNUNET_TRANSPORT_CS_OUTBOUND,
- receiver->d_mq);
-
}
@@ -3455,7 +3508,7 @@ ifc_broadcast (void *cls)
delay.rel_value_us =
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
bi->broadcast_task =
- GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi);
+ GNUNET_SCHEDULER_add_delayed (delay, &ifc_broadcast, bi);
switch (bi->sa->sa_family)
{
@@ -3472,6 +3525,12 @@ ifc_broadcast (void *cls)
sizeof(int)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "creating UDPBroadcast from %s\n",
+ GNUNET_i2s (&(bi->bcm.sender)));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "sending UDPBroadcast to add %s\n",
+ GNUNET_a2s (bi->ba, bi->salen));
sent = GNUNET_NETWORK_socket_sendto (udp_sock,
&bi->bcm,
sizeof(bi->bcm),
@@ -3499,6 +3558,8 @@ ifc_broadcast (void *cls)
dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "sending UDPBroadcast\n");
sent = GNUNET_NETWORK_socket_sendto (udp_sock,
&bi->bcm,
sizeof(bi->bcm),
@@ -3586,6 +3647,9 @@ iface_proc (void *cls,
ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
ubs.purpose.size = htonl (sizeof(ubs));
ubs.sender = my_identity;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "creating UDPBroadcastSignature for %s\n",
+ GNUNET_a2s (addr, addrlen));
GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
GNUNET_CRYPTO_eddsa_sign (my_private_key,
&ubs,
@@ -3755,9 +3819,11 @@ run (void *cls,
GNUNET_free (bindto);
in = (struct sockaddr *) &in_sto;
in_len = sto_len;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Bound to `%s'\n",
- GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
+ GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
+ "transport",
+ "Bound to `%s'\n",
+ GNUNET_a2s ((const struct sockaddr *) &in_sto,
+ sto_len));
switch (in->sa_family)
{
case AF_INET:
@@ -3853,6 +3919,9 @@ main (int argc, char *const *argv)
};
int ret;
+ GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
+ "transport",
+ "Starting udp communicator\n");
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index a7e2a8c04..f67bc0db5 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -1736,6 +1736,11 @@ struct Queue
const char *address;
/**
+ * Is this queue of unlimited length.
+ */
+ unsigned int unlimited_length;
+
+ /**
* Task scheduled for the time when this queue can (likely) transmit the
* next message.
*/
@@ -1787,6 +1792,11 @@ struct Queue
unsigned int queue_length;
/**
+ * Capacity of the queue.
+ */
+ uint64_t q_capacity;
+
+ /**
* Queue priority
*/
uint32_t priority;
@@ -3446,6 +3456,35 @@ transmit_on_queue (void *cls);
/**
+ * Check if the communicator has another queue with higher prio ready for sending.
+ */
+static unsigned int
+check_for_queue_with_higher_prio (struct Queue *queue, struct Queue *queue_head)
+{
+ for (struct Queue *s = queue_head; NULL != s;
+ s = s->next_client)
+ {
+ if (s->tc->details.communicator.address_prefix !=
+ queue->tc->details.communicator.address_prefix)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "queue address %s qid %u compare with queue: address %s qid %u\n",
+ queue->address,
+ queue->qid,
+ s->address,
+ s->qid);
+ if ((s->priority > queue->priority) && (0 < s->q_capacity) &&
+ (QUEUE_LENGTH_LIMIT > s->queue_length) )
+ return GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Lower prio\n");
+ }
+ }
+ return GNUNET_NO;
+}
+
+
+/**
* Called whenever something changed that might effect when we
* try to do the next transmission on @a queue using #transmit_on_queue().
*
@@ -3456,6 +3495,11 @@ static void
schedule_transmit_on_queue (struct Queue *queue,
enum GNUNET_SCHEDULER_Priority p)
{
+ if (check_for_queue_with_higher_prio (queue,
+ queue->tc->details.communicator.
+ queue_head))
+ return;
+
if (queue->tc->details.communicator.total_queue_length >=
COMMUNICATOR_TOTAL_QUEUE_LIMIT)
{
@@ -3480,6 +3524,19 @@ schedule_transmit_on_queue (struct Queue *queue,
queue->idle = GNUNET_NO;
return;
}
+ if (0 == queue->q_capacity)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission throttled due to communicator message queue qid %u has capacity %lu.\n",
+ queue->qid,
+ queue->q_capacity);
+ GNUNET_STATISTICS_update (GST_stats,
+ "# Transmission throttled due to message queue capacity",
+ 1,
+ GNUNET_NO);
+ queue->idle = GNUNET_NO;
+ return;
+ }
/* queue might indeed be ready, schedule it */
if (NULL != queue->transmit_task)
GNUNET_SCHEDULER_cancel (queue->transmit_task);
@@ -3582,8 +3639,9 @@ free_queue (struct Queue *queue)
tc->details.communicator.queue_head,
tc->details.communicator.queue_tail,
queue);
- maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
- tc->details.communicator.total_queue_length);
+ maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT <=
+ tc->details.communicator.
+ total_queue_length);
while (NULL != (qe = queue->queue_head))
{
GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
@@ -3597,7 +3655,7 @@ free_queue (struct Queue *queue)
GNUNET_free (qe);
}
GNUNET_assert (0 == queue->queue_length);
- if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
+ if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT >
tc->details.communicator.total_queue_length))
{
/* Communicator dropped below threshold, resume all _other_ queues */
@@ -4223,18 +4281,36 @@ queue_send_msg (struct Queue *queue,
if (NULL != pm)
{
qe->pm = pm;
- GNUNET_assert (NULL == pm->qe);
+ // TODO Why do we have a retransmission. When we know, make decision if we still want this.
+ // GNUNET_assert (NULL == pm->qe);
+ /*if (NULL != pm->qe)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Retransmitting message <%llu> remove pm from qe with MID: %llu \n",
+ pm->logging_uuid,
+ (unsigned long long) pm->qe->mid);
+ pm->qe->pm = NULL;
+ }*/
pm->qe = qe;
}
GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
queue->queue_length++;
queue->tc->details.communicator.total_queue_length++;
+ if (GNUNET_NO == queue->unlimited_length)
+ queue->q_capacity--;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue %s with qid %u has capacity %lu\n",
+ queue->address,
+ queue->qid,
+ queue->q_capacity);
if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
queue->tc->details.communicator.total_queue_length)
queue->idle = GNUNET_NO;
if (QUEUE_LENGTH_LIMIT == queue->queue_length)
queue->idle = GNUNET_NO;
+ if (0 == queue->q_capacity)
+ queue->idle = GNUNET_NO;
GNUNET_MQ_send (queue->tc->mq, env);
}
}
@@ -4662,18 +4738,28 @@ send_dv_to_neighbour (void *cls,
* @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
*/
static struct GNUNET_TIME_Relative
-route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
+route_control_message_without_fc (struct VirtualLink *vl,
+// route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
const struct GNUNET_MessageHeader *hdr,
enum RouteMessageOptions options)
{
- struct VirtualLink *vl;
+ // struct VirtualLink *vl;
struct Neighbour *n;
struct DistanceVector *dv;
struct GNUNET_TIME_Relative rtt1;
struct GNUNET_TIME_Relative rtt2;
+ const struct GNUNET_PeerIdentity *target = &vl->target;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to route message of type %u to %s without fc\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (target));
- vl = lookup_virtual_link (target);
+ // TODO Do this elsewhere. vl should be given as parameter to method.
+ // vl = lookup_virtual_link (target);
GNUNET_assert (NULL != vl);
+ if (NULL == vl)
+ return GNUNET_TIME_UNIT_FOREVER_REL;
n = vl->n;
dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
@@ -4718,6 +4804,10 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
if (NULL != n)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Try to route message of type %u to %s without fc via neighbour\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (target));
rtt1 = route_via_neighbour (n, hdr, options);
}
if (NULL != dv)
@@ -4804,7 +4894,7 @@ consider_sending_fc (void *cls)
fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used);
fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size);
fc.sender_time = GNUNET_TIME_absolute_hton (monotime);
- rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE);
+ rtt = route_control_message_without_fc (vl, &fc.header, RMO_NONE);
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
{
rtt = GNUNET_TIME_UNIT_SECONDS;
@@ -4889,7 +4979,9 @@ check_vl_transmission (struct VirtualLink *vl)
schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue busy or invalid\n");
+ "Neighbour Queue QID: %u (%u) busy or invalid\n",
+ queue->qid,
+ queue->idle);
}
}
/* Notify queues via DV that we are interested */
@@ -4910,6 +5002,11 @@ check_vl_transmission (struct VirtualLink *vl)
(queue->validated_until.abs_value_us > now.abs_value_us))
schedule_transmit_on_queue (queue,
GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV Queue QID: %u (%u) busy or invalid\n",
+ queue->qid,
+ queue->idle);
}
}
}
@@ -4991,13 +5088,16 @@ handle_communicator_backchannel (
void *cls,
const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
{
+ struct Neighbour *n;
+ struct VirtualLink *vl;
struct TransportClient *tc = cls;
const struct GNUNET_MessageHeader *inbox =
(const struct GNUNET_MessageHeader *) &cb[1];
uint16_t isize = ntohs (inbox->size);
const char *is = ((const char *) &cb[1]) + isize;
+ size_t slen = strlen (is) + 1;
char
- mbuf[isize
+ mbuf[slen + isize
+ sizeof(struct
TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
struct TransportBackchannelEncapsulationMessage *be =
@@ -5006,9 +5106,10 @@ handle_communicator_backchannel (
/* 0-termination of 'is' was checked already in
#check_communicator_backchannel() */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Preparing backchannel transmission to %s:%s of type %u\n",
+ "Preparing backchannel transmission to %s:%s of type %u and size %u\n",
GNUNET_i2s (&cb->pid),
is,
+ ntohs (inbox->type),
ntohs (inbox->size));
/* encapsulate and encrypt message */
be->header.type =
@@ -5019,7 +5120,22 @@ handle_communicator_backchannel (
+ isize],
is,
strlen (is) + 1);
- route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
+ // route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
+ vl = lookup_virtual_link (&cb->pid);
+ if (NULL != vl)
+ {
+ route_control_message_without_fc (vl, &be->header, RMO_DV_ALLOWED);
+ }
+ else
+ {
+ /* Use route via neighbour */
+ n = lookup_neighbour (&cb->pid);
+ if (NULL != n)
+ route_via_neighbour (
+ n,
+ &be->header,
+ RMO_NONE);
+ }
GNUNET_SERVICE_client_continue (tc->client);
}
@@ -5264,6 +5380,11 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
uint16_t size = ntohs (mh->size);
int have_core;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Handling raw message of type %u with %u bytes\n",
+ (unsigned int) ntohs (mh->type),
+ (unsigned int) ntohs (mh->size));
+
if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
(size < sizeof(struct GNUNET_MessageHeader)))
{
@@ -5290,6 +5411,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
1,
GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "CORE messages of type %u with %u bytes dropped (virtual link still down)\n",
+ (unsigned int) ntohs (mh->type),
+ (unsigned int) ntohs (mh->size));
finish_cmc_handling (cmc);
return;
}
@@ -5299,7 +5424,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
"# CORE messages dropped (FC arithmetic overflow)",
1,
GNUNET_NO);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "CORE messages of type %u with %u bytes dropped (FC arithmetic overflow)\n",
+ (unsigned int) ntohs (mh->type),
+ (unsigned int) ntohs (mh->size));
finish_cmc_handling (cmc);
return;
}
@@ -5309,6 +5437,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
"# CORE messages dropped (FC window overflow)",
1,
GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "CORE messages of type %u with %u bytes dropped (FC window overflow)\n",
+ (unsigned int) ntohs (mh->type),
+ (unsigned int) ntohs (mh->size));
finish_cmc_handling (cmc);
return;
}
@@ -5345,6 +5477,10 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
perspective of the other peer! */
vl->incoming_fc_window_size_used += size;
/* TODO-M1 */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropped message of type %u with %u bytes to CORE: no CORE client connected!",
+ (unsigned int) ntohs (mh->type),
+ (unsigned int) ntohs (mh->size));
finish_cmc_handling (cmc);
return;
}
@@ -5423,9 +5559,11 @@ destroy_ack_cummulator (void *cls)
static void
transmit_cummulative_ack_cb (void *cls)
{
+ struct Neighbour *n;
+ struct VirtualLink *vl;
struct AcknowledgementCummulator *ac = cls;
char buf[sizeof(struct TransportReliabilityAckMessage)
- + ac->ack_counter
+ + ac->ack_counter + ac->num_acks
* sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN;
struct TransportReliabilityAckMessage *ack =
(struct TransportReliabilityAckMessage *) buf;
@@ -5436,12 +5574,12 @@ transmit_cummulative_ack_cb (void *cls)
"Sending ACK with %u components to %s\n",
ac->ack_counter,
GNUNET_i2s (&ac->target));
- GNUNET_assert (0 < ac->ack_counter);
+ GNUNET_assert (0 <= ac->ack_counter);
ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
ack->header.size =
htons (sizeof(*ack)
+ ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP));
- ack->ack_counter = htonl (ac->ack_counter++);
+ ack->ack_counter = htonl (ac->ack_counter += ac->num_acks);
ap = (struct TransportCummulativeAckPayloadP *) &ack[1];
for (unsigned int i = 0; i < ac->ack_counter; i++)
{
@@ -5449,7 +5587,28 @@ transmit_cummulative_ack_cb (void *cls)
ap[i].ack_delay = GNUNET_TIME_relative_hton (
GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time));
}
- route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED);
+ /*route_control_message_without_fc (
+ &ac->target,
+ &ack->header,
+ RMO_DV_ALLOWED);*/
+ vl = lookup_virtual_link (&ac->target);
+ if (NULL != vl)
+ {
+ route_control_message_without_fc (
+ vl,
+ &ack->header,
+ RMO_DV_ALLOWED);
+ }
+ else
+ {
+ /* Use route via neighbour */
+ n = lookup_neighbour (&ac->target);
+ if (NULL != n)
+ route_via_neighbour (
+ n,
+ &ack->header,
+ RMO_NONE);
+ }
ac->num_acks = 0;
ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT,
&destroy_ack_cummulator,
@@ -6074,6 +6233,15 @@ handle_backchannel_encapsulation (
(const struct GNUNET_MessageHeader *) &be[1];
uint16_t isize = ntohs (inbox->size);
const char *target_communicator = ((const char *) inbox) + isize;
+ char *sender;
+ char *self;
+
+ GNUNET_asprintf (&sender,
+ "%s",
+ GNUNET_i2s (&cmc->im.sender));
+ GNUNET_asprintf (&self,
+ "%s",
+ GNUNET_i2s (&GST_my_identity));
/* Find client providing this communicator */
for (tc = clients_head; NULL != tc; tc = tc->next)
@@ -6095,8 +6263,9 @@ handle_backchannel_encapsulation (
}
/* Finally, deliver backchannel message to communicator */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering backchannel message from %s of type %u to %s\n",
- GNUNET_i2s (&cmc->im.sender),
+ "Delivering backchannel message from %s to %s of type %u to %s\n",
+ sender,
+ self,
ntohs (inbox->type),
target_communicator);
env = GNUNET_MQ_msg_extra (
@@ -6431,6 +6600,8 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
const struct DVPathEntryP *hops,
struct GNUNET_TIME_Absolute in_time)
{
+ struct Neighbour *n;
+ struct VirtualLink *vl;
struct DVPathEntryP *dhops;
char buf[sizeof(struct TransportDVLearnMessage)
+ (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN;
@@ -6462,18 +6633,34 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
struct DvHopPS dhp = {
.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
.purpose.size = htonl (sizeof(dhp)),
- .pred = dhops[nhops - 1].hop,
+ .pred = (0 == nhops) ? msg->initiator : dhops[nhops - 1].hop,
.succ = *next_hop,
.challenge = msg->challenge
};
-
GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
&dhp,
&dhops[nhops].hop_sig);
}
- route_control_message_without_fc (next_hop,
+ /*route_control_message_without_fc (next_hop,
&fwd->header,
- RMO_UNCONFIRMED_ALLOWED);
+ RMO_UNCONFIRMED_ALLOWED);*/
+ vl = lookup_virtual_link (next_hop);
+ if (NULL != vl)
+ {
+ route_control_message_without_fc (vl,
+ &fwd->header,
+ RMO_UNCONFIRMED_ALLOWED);
+ }
+ else
+ {
+ /* Use route via neighbour */
+ n = lookup_neighbour (next_hop);
+ if (NULL != n)
+ route_via_neighbour (
+ n,
+ &fwd->header,
+ RMO_UNCONFIRMED_ALLOWED);
+ }
}
@@ -6752,7 +6939,14 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
struct GNUNET_TIME_Absolute in_time;
struct Neighbour *n;
- nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "handle dv learn message sender %s\n",
+ GNUNET_i2s (&cmc->im.sender));
+
+ nhops = ntohs (dvl->num_hops); /* 0 = sender is initiator */
bi_history = ntohs (dvl->bidirectional);
hops = (const struct DVPathEntryP *) &dvl[1];
if (0 == nhops)
@@ -6767,6 +6961,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
}
else
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "handle dv learn message last hop %s\n",
+ GNUNET_i2s (&hops[nhops - 1].hop));
/* sanity check */
if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender))
{
@@ -6782,6 +6979,10 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
cc); // FIXME: add bi-directional flag to cc?
in_time = GNUNET_TIME_absolute_get ();
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "2 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
+
/* continue communicator here, everything else can happen asynchronous! */
finish_cmc_handling (cmc);
@@ -6792,6 +6993,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
(GNUNET_TIME_absolute_ntoh (dvl->monotonic_time).abs_value_us <
n->last_dv_learn_monotime.abs_value_us))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV learn from %s discarded due to time travel",
+ GNUNET_i2s (&dvl->initiator));
GNUNET_STATISTICS_update (GST_stats,
"# DV learn discarded due to time travel",
1,
@@ -6803,6 +7007,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
&dvl->challenge,
&dvl->init_sig))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV learn signature from %s invalid",
+ GNUNET_i2s (&dvl->initiator));
GNUNET_break_op (0);
return;
}
@@ -6824,6 +7031,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
n);
}
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "3 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
/* OPTIMIZE-FIXME: asynchronously (!) verify signatures!,
If signature verification load too high, implement random drop strategy */
for (unsigned int i = 0; i < nhops; i++)
@@ -6842,11 +7052,29 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
&hops[i].hop_sig,
&hops[i].hop.public_key))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DV learn from %s signature of hop %u invalid\n",
+ GNUNET_i2s (&dvl->initiator),
+ i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "signature of hop %s invalid\n",
+ GNUNET_i2s (&hops[i].hop));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "pred %s\n",
+ GNUNET_i2s (&dhp.pred));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "succ %s\n",
+ GNUNET_i2s (&dhp.succ));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "hash %s\n",
+ GNUNET_sh2s (&dhp.challenge.value));
GNUNET_break_op (0);
return;
}
}
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "4 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
if (GNUNET_EXTRA_LOGGING > 0)
{
char *path;
@@ -6871,7 +7099,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
GNUNET_i2s (&GST_my_identity));
GNUNET_free (path);
}
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "5 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
do_fwd = GNUNET_YES;
if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator))
{
@@ -6916,6 +7146,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
do_fwd = GNUNET_NO;
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "6 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
if (bi_hop)
{
/* last hop was bi-directional, we could learn something here! */
@@ -6972,13 +7205,18 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
}
}
}
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "7 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
if (MAX_DV_HOPS_ALLOWED == nhops)
{
/* At limit, we're out of here! */
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "8 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
/* Forward to initiator, if path non-trivial and possible */
bi_history = (bi_history << 1) | (bi_hop ? 1 : 0);
did_initiator = GNUNET_NO;
@@ -7032,6 +7270,9 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
&dv_neighbour_transmission,
&nsc);
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "9 handle dv learn message from %s\n",
+ GNUNET_i2s (&dvl->initiator));
}
@@ -7810,7 +8051,8 @@ handle_validation_challenge (
vl = lookup_virtual_link (&sender);
if (NULL != vl)
{
- route_control_message_without_fc (&cmc->im.sender,
+ // route_control_message_without_fc (&cmc->im.sender,
+ route_control_message_without_fc (vl,
&tvr.header,
RMO_ANYTHING_GOES | RMO_REDUNDANT);
}
@@ -8407,14 +8649,15 @@ fragment_message (struct Queue *queue,
struct PendingMessage *ff;
uint16_t mtu;
- mtu = (0 == queue->mtu)
+ mtu = (UINT16_MAX == queue->mtu)
? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)
: queue->mtu;
set_pending_message_uuid (pm);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Fragmenting message %llu <%llu> to %s for MTU %u\n",
+ "Fragmenting message %llu <%llu> with size %u to %s for MTU %u\n",
(unsigned long long) pm->msg_uuid.uuid,
pm->logging_uuid,
+ pm->bytes_msg,
GNUNET_i2s (&pm->vl->target),
(unsigned int) mtu);
pa = prepare_pending_acknowledgement (queue, dvh, pm);
@@ -8700,7 +8943,7 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
GNUNET_TRANSPORT_SendMessageTo))
||
(NULL != pos->head_frag /* fragments already exist, should
- respect that even if MTU is 0 for
+ respect that even if MTU is UINT16_MAX for
this queue */))
{
frag = GNUNET_YES;
@@ -9069,12 +9312,17 @@ handle_send_message_ack (void *cls,
qep = qep->next)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "QueueEntry MID: %llu, Ack MID: %llu\n",
+ "QueueEntry MID: %llu on queue QID: %llu, Ack MID: %llu\n",
(unsigned long long) qep->mid,
+ (unsigned long long) queue->qid,
(unsigned long long) sma->mid);
if (qep->mid != sma->mid)
continue;
qe = qep;
+ if ((NULL != qe->pm)&&(qe->pm->qe != qe))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "For pending message %llu we had retransmissions.\n",
+ qe->pm->logging_uuid);
break;
}
}
@@ -9125,12 +9373,26 @@ handle_send_message_ack (void *cls,
GNUNET_NO);
schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
}
+ else if (1 == qe->queue->q_capacity)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission rescheduled due to communicator message queue with qid %u has capacity %lu.\n",
+ qe->queue->qid,
+ qe->queue->q_capacity);
+ /* message queue has capacity; only resume this one queue */
+ /* queue dropped below threshold; only resume this one queue */
+ GNUNET_STATISTICS_update (GST_stats,
+ "# Transmission throttled due to message queue capacity",
+ -1,
+ GNUNET_NO);
+ schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
+ }
if (NULL != (pm = qe->pm))
{
struct VirtualLink *vl;
- GNUNET_assert (qe == pm->qe);
+ // GNUNET_assert (qe == pm->qe);
pm->qe = NULL;
/* If waiting for this communicator may have blocked transmission
of pm on other queues for this neighbour, force schedule
@@ -9671,16 +9933,20 @@ handle_add_queue_message (void *cls,
addr_len = ntohs (aqm->header.size) - sizeof(*aqm);
addr = (const char *) &aqm[1];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New queue %s to %s available with QID %llu\n",
+ "New queue %s to %s available with QID %llu and q_len %lu \n",
addr,
GNUNET_i2s (&aqm->receiver),
- (unsigned long long) aqm->qid);
+ (unsigned long long) aqm->qid,
+ GNUNET_ntohll (aqm->q_len));
queue = GNUNET_malloc (sizeof(struct Queue) + addr_len);
queue->tc = tc;
queue->address = (const char *) &queue[1];
queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
queue->qid = aqm->qid;
queue->neighbour = neighbour;
+ if (GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED == GNUNET_ntohll (aqm->q_len))
+ queue->unlimited_length = GNUNET_YES;
+ queue->q_capacity = GNUNET_ntohll (aqm->q_len);
memcpy (&queue[1], addr, addr_len);
/* notify monitors about new queue */
{
@@ -9752,10 +10018,14 @@ handle_update_queue_message (void *cls,
target_queue->mtu = ntohl (msg->mtu);
target_queue->cs = msg->cs;
target_queue->priority = ntohl (msg->priority);
- /* The update message indicates how many _additional_
- * messages the queue should be able to handle
+ /* The update message indicates how many messages
+ * the queue should be able to handle.
*/
- target_queue->queue_length += GNUNET_ntohll (msg->q_len);
+ if (GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED == GNUNET_ntohll (msg->q_len))
+ target_queue->unlimited_length = GNUNET_YES;
+ else
+ target_queue->unlimited_length = GNUNET_NO;
+ target_queue->q_capacity = GNUNET_ntohll (msg->q_len);
GNUNET_SERVICE_client_continue (tc->client);
}
@@ -10179,8 +10449,18 @@ static void
shutdown_task (void *cls)
{
in_shutdown = GNUNET_YES;
+
if (NULL == clients_head)
- do_shutdown (cls);
+ {
+ for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "client still connected: %u\n",
+ tc->type);
+ }
+ }
+ do_shutdown (cls);
+
}
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index 8606b353b..65b090187 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -29,7 +29,7 @@
#include "gnunet_constants.h"
#include "gnunet_resolver_service.h"
-#if HAVE_MALLINFO
+#if HAVE_MALLINFO2
#include <malloc.h>
#include "gauger.h"
#endif
@@ -1450,7 +1450,7 @@ shutdown:
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
GNUNET_break (0 == close (sctx.ready_confirm_fd));
}
-#if HAVE_MALLINFO
+#if HAVE_MALLINFO2
{
char *counter;
@@ -1462,9 +1462,9 @@ shutdown:
"GAUGER_HEAP",
&counter)))
{
- struct mallinfo mi;
+ struct mallinfo2 mi;
- mi = mallinfo ();
+ mi = mallinfo2 ();
GAUGER (service_name, counter, mi.usmblks, "blocks");
GNUNET_free (counter);
}
@@ -1599,7 +1599,7 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
{
unsigned int i;
-#if HAVE_MALLINFO
+#if HAVE_MALLINFO2
{
char *counter;
@@ -1611,9 +1611,9 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
"GAUGER_HEAP",
&counter)))
{
- struct mallinfo mi;
+ struct mallinfo2 mi;
- mi = mallinfo ();
+ mi = mallinfo2 ();
GAUGER (sctx->service_name, counter, mi.usmblks, "blocks");
GNUNET_free (counter);
}
diff --git a/src/transport/test_transport_api2_tcp_node1.conf b/src/transport/test_transport_api2_tcp_node1.conf
index 11306fd6a..e38744949 100644
--- a/src/transport/test_transport_api2_tcp_node1.conf
+++ b/src/transport/test_transport_api2_tcp_node1.conf
@@ -5,7 +5,7 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p1/
[transport]
BINARY = gnunet-service-tng
PLUGINS = tcp
-#PREFIX = valgrind --log-file=/tmp/vg_peer1-%p
+# PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/vg_peer1-%p
UNIXPATH = $GNUNET_RUNTIME_DIR/tng-p1.sock
[communicator-tcp]
@@ -15,6 +15,7 @@ DISABLE_V6 = YES
IMMEDIATE_START = YES
UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock
#PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p
+#PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
[communicator-udp]
BINARY = gnunet-communicator-udp
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 5384bf24d..154c0abca 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_application_service.h"
#include "transport-testing2.h"
@@ -58,6 +59,11 @@ struct TestState
*
*/
char *cfgname;
+
+ /**
+ * The complete topology information.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
};
static struct GNUNET_TESTING_Command block_send;
@@ -66,6 +72,8 @@ static struct GNUNET_TESTING_Command block_receive;
static struct GNUNET_TESTING_Command connect_peers;
+static struct GNUNET_TESTING_Command local_prepared;
+
/**
* Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
@@ -89,14 +97,15 @@ static void
handle_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- struct GNUNET_TESTING_AsyncContext *ac;
+ const struct GNUNET_TESTING_AsyncContext *ac;
GNUNET_TESTING_get_trait_async_context (&block_receive,
&ac);
- if ((NULL == ac) || (NULL == ac->cont))
- GNUNET_TESTING_async_fail (ac);
+ GNUNET_assert (NULL != ac);
+ if (NULL == ac->cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
else
- GNUNET_TESTING_async_finish (ac);
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
}
@@ -107,14 +116,15 @@ handle_test (void *cls,
static void
all_peers_started ()
{
- struct GNUNET_TESTING_AsyncContext *ac;
+ const struct GNUNET_TESTING_AsyncContext *ac;
GNUNET_TESTING_get_trait_async_context (&block_send,
&ac);
- if ((NULL == ac) || (NULL == ac->cont))
- GNUNET_TESTING_async_fail (ac);
+ GNUNET_assert (NULL != ac);
+ if (NULL == ac->cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
else
- GNUNET_TESTING_async_finish (ac);
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
}
@@ -136,10 +146,15 @@ handle_result (void *cls,
rv);
reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message prepared\n");
ts->write_message (reply,
ntohs (reply->size));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message send\n");
GNUNET_free (ts->testdir);
GNUNET_free (ts->cfgname);
+ GNUNET_TESTING_free_topology (ts->topology);
GNUNET_free (ts);
}
@@ -149,24 +164,44 @@ handle_result (void *cls,
*
*/
static void *
-notify_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+notify_connect (struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_PeerIdentity *peer)
{
- struct ConnectPeersState *cps;
+ const struct ConnectPeersState *cps;
+ const struct GNUNET_TESTING_Command *cmd;
- GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
- &cps);
+ cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ "connect-peers");
+ GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd,
+ &cps);
void *ret = NULL;
- cps->notify_connect (cps,
- peer,
- mq);
+ cps->notify_connect (is,
+ peer);
return ret;
}
/**
+ * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
+ */
+static void
+all_local_tests_prepared ()
+{
+ const struct LocalPreparedState *lfs;
+
+ GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
+ &lfs);
+ GNUNET_assert (NULL != &lfs->ac);
+ if (NULL == lfs->ac.cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
+ else
+ GNUNET_TESTING_async_finish ((struct
+ GNUNET_TESTING_AsyncContext *) &lfs->ac);
+}
+
+
+/**
* Function to start a local test case.
*
* @param write_message Callback to send a message to the master loop.
@@ -181,7 +216,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *node_ip,
char *m,
char *n,
- char *local_m)
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file)
{
unsigned int n_int;
@@ -189,37 +226,51 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
unsigned int local_m_int;
unsigned int num;
struct TestState *ts = GNUNET_new (struct TestState);
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ if (GNUNET_YES == *read_file)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read from file\n");
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ }
+ else
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+
+ ts->topology = topology;
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
- if (0 == m_int)
- num = n_int;
+ if (0 == n_int)
+ num = m_int;
else
num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
- block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
+ block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "block");
block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
"block-receive");
connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
"start-peer",
"system-create",
num,
- NULL);
+ topology,
+ 0);
+ local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
+ "local-test-prepared",
+ write_message);
-
- sscanf (m, "%u", &m_int);
- sscanf (n, "%u", &n_int);
- sscanf (local_m, "%u", &local_m_int);
-
GNUNET_asprintf (&ts->cfgname,
"test_transport_api2_tcp_node1.conf");
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"plugin cfgname: %s\n",
ts->cfgname);
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"node ip: %s\n",
node_ip);
@@ -246,21 +297,28 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
node_ip,
handlers,
ts->cfgname,
- notify_connect),
+ notify_connect,
+ GNUNET_NO),
GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
write_message),
block_send,
connect_peers,
GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
"start-peer",
- num),
+ "system-create",
+ num,
+ topology),
block_receive,
+ local_prepared,
GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
"start-peer"),
GNUNET_TESTING_cmd_system_destroy ("system-destroy",
- "system-create")
+ "system-create"),
+ GNUNET_TESTING_cmd_end ()
};
+ ts->write_message = write_message;
+
GNUNET_TESTING_run (commands,
GNUNET_TIME_UNIT_FOREVER_REL,
&handle_result,
@@ -280,9 +338,14 @@ libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
{
struct GNUNET_TESTING_PluginFunctions *api;
+ GNUNET_log_setup ("simple-send",
+ "DEBUG",
+ NULL);
+
api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
api->start_testcase = &start_testcase;
api->all_peers_started = &all_peers_started;
+ api->all_local_tests_prepared = all_local_tests_prepared;
return api;
}
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
new file mode 100644
index 000000000..9d6844be1
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
@@ -0,0 +1,398 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 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 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/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file testbed/plugin_cmd_simple_send_broadcast.c
+ * @brief a plugin to provide the API for running test cases.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing2.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define BASE_DIR "testdir"
+
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
+
+struct TestState
+{
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
+ TESTING_CMD_HELPER_write_cb write_message;
+
+ /**
+ * The name for a specific test environment directory.
+ *
+ */
+ char *testdir;
+
+ /**
+ * The name for the configuration file of the specific node.
+ *
+ */
+ char *cfgname;
+
+ /**
+ * The complete topology information.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
+};
+
+static struct GNUNET_TESTING_Command block_send;
+
+static struct GNUNET_TESTING_Command block_receive;
+
+static struct GNUNET_TESTING_Command connect_peers;
+
+static struct GNUNET_TESTING_Command local_prepared;
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
+ * received.
+ *
+ */
+static int
+check_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
+ * being received.
+ *
+ */
+static void
+handle_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ const struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_TESTING_get_trait_async_context (&block_receive,
+ &ac);
+ GNUNET_assert (NULL != ac);
+ if ((GNUNET_NO == ac->finished) && (NULL == ac->cont))
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
+ else if (GNUNET_NO == ac->finished)
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
+}
+
+
+/**
+ * Callback to set the flag indicating all peers started. Will be called via the plugin api.
+ *
+ */
+static void
+all_peers_started ()
+{
+ const struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message\n");
+ GNUNET_TESTING_get_trait_async_context (&block_send,
+ &ac);
+ GNUNET_assert (NULL != ac);
+ if (NULL == ac->cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
+ else
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
+}
+
+
+/**
+ * Function called with the final result of the test.
+ *
+ * @param cls the `struct MainParams`
+ * @param rv #GNUNET_OK if the test passed
+ */
+static void
+handle_result (void *cls,
+ enum GNUNET_GenericReturnValue rv)
+{
+ struct TestState *ts = cls;
+ struct GNUNET_MessageHeader *reply;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Local test exits with status %d\n",
+ rv);
+ reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message prepared\n");
+ ts->write_message (reply,
+ ntohs (reply->size));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message send\n");
+ GNUNET_free (ts->testdir);
+ GNUNET_free (ts->cfgname);
+ GNUNET_TESTING_free_topology (ts->topology);
+ GNUNET_free (ts);
+}
+
+
+/**
+ * Callback from start peer cmd for signaling a peer got connected.
+ *
+ */
+static void *
+notify_connect (struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ const struct GNUNET_TESTING_AsyncContext *ac;
+ void *ret = NULL;
+ const struct GNUNET_TESTING_Command *cmd;
+ struct BlockState *bs;
+
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "notify_connect\n");
+
+ GNUNET_TESTING_get_trait_async_context (&connect_peers,
+ &ac);
+
+ if (NULL != ac->is)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "notify_connect running\n");
+ GNUNET_assert (NULL != ac);
+ if (NULL == ac->cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
+ else
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
+ }
+ else
+ {
+ cmd = GNUNET_TESTING_interpreter_lookup_future_command (is,
+ "connect-peers");
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "block state %s\n",
+ cmd->label);
+ GNUNET_TESTING_get_trait_block_state (
+ cmd,
+ (const struct BlockState **) &bs);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "block state %u\n",
+ bs->asynchronous_finish);
+ bs->asynchronous_finish = GNUNET_YES;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "block state %u\n",
+ bs->asynchronous_finish);
+ }
+
+ return ret;
+}
+
+
+/**
+ * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
+ */
+static void
+all_local_tests_prepared ()
+{
+ const struct LocalPreparedState *lfs;
+
+ GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
+ &lfs);
+ GNUNET_assert (NULL != &lfs->ac);
+ if (NULL == lfs->ac.cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
+ else
+ GNUNET_TESTING_async_finish ((struct
+ GNUNET_TESTING_AsyncContext *) &lfs->ac);
+}
+
+
+/**
+ * Function to start a local test case.
+ *
+ * @param write_message Callback to send a message to the master loop.
+ * @param router_ip Global address of the network namespace.
+ * @param node_ip Local address of a node i a network namespace.
+ * @param m The number of the node in a network namespace.
+ * @param n The number of the network namespace.
+ * @param local_m The number of nodes in a network namespace.
+ */
+static void
+start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
+ char *node_ip,
+ char *m,
+ char *n,
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file)
+{
+ unsigned int n_int;
+ unsigned int m_int;
+ unsigned int local_m_int;
+ unsigned int num;
+ struct TestState *ts = GNUNET_new (struct TestState);
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+
+
+ if (GNUNET_YES == *read_file)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read from file\n");
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ }
+ else
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+
+ ts->topology = topology;
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
+
+ if (0 == n_int)
+ num = m_int;
+ else
+ num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
+
+ block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
+ block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "block-receive");
+ connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "connect-peers");
+ local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
+ "local-test-prepared",
+ write_message);
+
+
+ GNUNET_asprintf (&ts->cfgname,
+ "test_transport_api2_tcp_node1.conf");
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "plugin cfgname: %s\n",
+ ts->cfgname);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "node ip: %s\n",
+ node_ip);
+
+ GNUNET_asprintf (&ts->testdir,
+ "%s%s%s",
+ BASE_DIR,
+ m,
+ n);
+
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (test,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ ts),
+ GNUNET_MQ_handler_end ()
+ };
+
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_system_create ("system-create",
+ ts->testdir),
+ GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
+ "system-create",
+ num,
+ node_ip,
+ handlers,
+ ts->cfgname,
+ notify_connect,
+ GNUNET_YES),
+ GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
+ write_message),
+ block_send,
+ connect_peers,
+ GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
+ "start-peer",
+ "system-create",
+ num,
+ topology),
+ block_receive,
+ local_prepared,
+ GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
+ "start-peer"),
+ GNUNET_TESTING_cmd_system_destroy ("system-destroy",
+ "system-create"),
+ GNUNET_TESTING_cmd_end ()
+ };
+
+ ts->write_message = write_message;
+
+ GNUNET_TESTING_run (commands,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &handle_result,
+ ts);
+
+}
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls NULL
+ * @return the exported block API
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api;
+
+ GNUNET_log_setup ("simple-send",
+ "DEBUG",
+ NULL);
+
+ api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
+ api->start_testcase = &start_testcase;
+ api->all_peers_started = &all_peers_started;
+ api->all_local_tests_prepared = all_local_tests_prepared;
+ return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
+ * @return NULL
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ return NULL;
+}
+
+
+/* end of plugin_cmd_simple_send_broadcast.c */
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_dv.c b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
new file mode 100644
index 000000000..e73e5a0b2
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
@@ -0,0 +1,375 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 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 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/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file testbed/plugin_cmd_simple_send_broadcast.c
+ * @brief a plugin to provide the API for running test cases.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing2.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define BASE_DIR "testdir"
+
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
+
+struct TestState
+{
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
+ TESTING_CMD_HELPER_write_cb write_message;
+
+ /**
+ * The name for a specific test environment directory.
+ *
+ */
+ char *testdir;
+
+ /**
+ * The name for the configuration file of the specific node.
+ *
+ */
+ char *cfgname;
+
+ /**
+ * The complete topology information.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
+};
+
+static struct GNUNET_TESTING_Command block_send;
+
+static struct GNUNET_TESTING_Command block_receive;
+
+static struct GNUNET_TESTING_Command connect_peers;
+
+static struct GNUNET_TESTING_Command local_prepared;
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
+ * received.
+ *
+ */
+static int
+check_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
+ * being received.
+ *
+ */
+static void
+handle_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ const struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received test message\n");
+ GNUNET_TESTING_get_trait_async_context (&block_receive,
+ &ac);
+ GNUNET_assert (NULL != ac);
+ if (NULL == ac->cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
+ else
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
+}
+
+
+/**
+ * Callback to set the flag indicating all peers started. Will be called via the plugin api.
+ *
+ */
+static void
+all_peers_started ()
+{
+ const struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message\n");
+ GNUNET_TESTING_get_trait_async_context (&block_send,
+ &ac);
+ GNUNET_assert (NULL != ac);
+ if (NULL == ac->cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
+ else
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
+}
+
+
+/**
+ * Function called with the final result of the test.
+ *
+ * @param cls the `struct MainParams`
+ * @param rv #GNUNET_OK if the test passed
+ */
+static void
+handle_result (void *cls,
+ enum GNUNET_GenericReturnValue rv)
+{
+ struct TestState *ts = cls;
+ struct GNUNET_MessageHeader *reply;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Local test exits with status %d\n",
+ rv);
+ reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message prepared\n");
+ ts->write_message (reply,
+ ntohs (reply->size));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message send\n");
+ GNUNET_free (ts->testdir);
+ GNUNET_free (ts->cfgname);
+ GNUNET_TESTING_free_topology (ts->topology);
+ GNUNET_free (ts);
+}
+
+
+/**
+ * Callback from start peer cmd for signaling a peer got connected.
+ *
+ */
+static void *
+notify_connect (struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ const struct ConnectPeersState *cps;
+ const struct GNUNET_TESTING_Command *cmd;
+ void *ret = NULL;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "notify_connect peer %s\n",
+ GNUNET_i2s (peer));
+ cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
+ "connect-peers");
+ GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd,
+ &cps);
+ cps->notify_connect (is,
+ peer);
+
+ return ret;
+}
+
+
+/**
+ * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
+ */
+static void
+all_local_tests_prepared ()
+{
+ const struct LocalPreparedState *lfs;
+
+ GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
+ &lfs);
+ GNUNET_assert (NULL != &lfs->ac);
+ if (NULL == lfs->ac.cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
+ else
+ GNUNET_TESTING_async_finish ((struct
+ GNUNET_TESTING_AsyncContext *) &lfs->ac);
+}
+
+
+/**
+ * Function to start a local test case.
+ *
+ * @param write_message Callback to send a message to the master loop.
+ * @param router_ip Global address of the network namespace.
+ * @param node_ip Local address of a node i a network namespace.
+ * @param m The number of the node in a network namespace.
+ * @param n The number of the network namespace.
+ * @param local_m The number of nodes in a network namespace.
+ */
+static void
+start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
+ char *node_ip,
+ char *m,
+ char *n,
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file)
+{
+ unsigned int n_int;
+ unsigned int m_int;
+ unsigned int local_m_int;
+ unsigned int num;
+ struct TestState *ts = GNUNET_new (struct TestState);
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+
+
+ if (GNUNET_YES == *read_file)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read from file\n");
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ }
+ else
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+
+ ts->topology = topology;
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
+
+ if (0 == n_int)
+ num = m_int;
+ else
+ num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
+
+ block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
+ block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "block-receive");
+ connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
+ "start-peer",
+ "system-create",
+ num,
+ topology,
+ 8);
+ local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
+ "local-test-prepared",
+ write_message);
+
+
+ GNUNET_asprintf (&ts->cfgname,
+ "test_transport_api2_tcp_node1.conf");
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "plugin cfgname: %s\n",
+ ts->cfgname);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "node ip: %s\n",
+ node_ip);
+
+ GNUNET_asprintf (&ts->testdir,
+ "%s%s%s",
+ BASE_DIR,
+ m,
+ n);
+
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (test,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ ts),
+ GNUNET_MQ_handler_end ()
+ };
+
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_system_create ("system-create",
+ ts->testdir),
+ GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
+ "system-create",
+ num,
+ node_ip,
+ handlers,
+ ts->cfgname,
+ notify_connect,
+ GNUNET_YES),
+ GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
+ write_message),
+ block_send,
+ connect_peers,
+ GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
+ "start-peer",
+ "system-create",
+ num,
+ topology),
+ block_receive,
+ local_prepared,
+ GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
+ "start-peer"),
+ GNUNET_TESTING_cmd_system_destroy ("system-destroy",
+ "system-create"),
+ GNUNET_TESTING_cmd_end ()
+ };
+
+ ts->write_message = write_message;
+
+ GNUNET_TESTING_run (commands,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &handle_result,
+ ts);
+
+}
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls NULL
+ * @return the exported block API
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_dv_init (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api;
+
+ GNUNET_log_setup ("simple-send",
+ "DEBUG",
+ NULL);
+
+ api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
+ api->start_testcase = &start_testcase;
+ api->all_peers_started = &all_peers_started;
+ api->all_local_tests_prepared = all_local_tests_prepared;
+ return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
+ * @return NULL
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_dv_done (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ return NULL;
+}
+
+
+/* end of plugin_cmd_simple_send_broadcast.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 108e1ac09..537832e61 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_application_service.h"
#include "transport-testing2.h"
@@ -58,14 +59,19 @@ struct TestState
*
*/
char *cfgname;
+
+ /**
+ * The complete topology information.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
};
static struct GNUNET_TESTING_Command block_send;
-static struct GNUNET_TESTING_Command block_receive;
-
static struct GNUNET_TESTING_Command connect_peers;
+static struct GNUNET_TESTING_Command local_prepared;
+
/**
* Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
@@ -89,14 +95,14 @@ static void
handle_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- struct GNUNET_TESTING_AsyncContext *ac;
+ // struct GNUNET_TESTING_AsyncContext *ac;
- GNUNET_TESTING_get_trait_async_context (&block_receive,
+ /*GNUNET_TESTING_get_trait_async_context (&block_receive,
&ac);
if ((NULL == ac) || (NULL == ac->cont))
GNUNET_TESTING_async_fail (ac);
else
- GNUNET_TESTING_async_finish (ac);
+ GNUNET_TESTING_async_finish (ac);*/
}
@@ -107,14 +113,15 @@ handle_test (void *cls,
static void
all_peers_started ()
{
- struct GNUNET_TESTING_AsyncContext *ac;
+ const struct GNUNET_TESTING_AsyncContext *ac;
GNUNET_TESTING_get_trait_async_context (&block_send,
&ac);
- if ((NULL == ac) || (NULL == ac->cont))
- GNUNET_TESTING_async_fail (ac);
+ GNUNET_assert (NULL != ac);
+ if ((NULL == ac->cont))
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
else
- GNUNET_TESTING_async_finish (ac);
+ GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
}
@@ -136,10 +143,14 @@ handle_result (void *cls,
rv);
reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "message prepared\n");
ts->write_message (reply,
ntohs (reply->size));
+
GNUNET_free (ts->testdir);
GNUNET_free (ts->cfgname);
+ GNUNET_TESTING_free_topology (ts->topology);
GNUNET_free (ts);
}
@@ -149,22 +160,37 @@ handle_result (void *cls,
*
*/
static void *
-notify_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+notify_connect (struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_PeerIdentity *peer)
{
- struct ConnectPeersState *cps;
+ const struct ConnectPeersState *cps;
- GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
- &cps);
+ GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers,
+ &cps);
void *ret = NULL;
- cps->notify_connect (cps,
- peer,
- mq);
+ cps->notify_connect (is,
+ peer);
return ret;
}
+/**
+ * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
+ */
+static void
+all_local_tests_prepared ()
+{
+ const struct LocalPreparedState *lfs;
+
+ GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
+ &lfs);
+ GNUNET_assert (NULL != &lfs->ac);
+ if (NULL == lfs->ac.cont)
+ GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
+ else
+ GNUNET_TESTING_async_finish ((struct
+ GNUNET_TESTING_AsyncContext *) &lfs->ac);
+}
/**
* Function to start a local test case.
@@ -181,7 +207,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *node_ip,
char *m,
char *n,
- char *local_m)
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file)
{
unsigned int n_int;
@@ -190,8 +218,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
unsigned int num;
struct TestState *ts = GNUNET_new (struct TestState);
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ if (GNUNET_YES == *read_file)
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ else
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+
+ ts->topology = topology;
sscanf (m, "%u", &m_int);
sscanf (n, "%u", &n_int);
@@ -203,23 +237,26 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
else
num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
- block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
- block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
- "block-receive");
+ block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "block");
connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
"start-peer",
"system-create",
num,
- NULL);
+ topology,
+ 0);
+ local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
+ "local-test-prepared",
+ write_message);
GNUNET_asprintf (&ts->cfgname,
"test_transport_api2_tcp_node1.conf");
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"plugin cfgname: %s\n",
ts->cfgname);
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"node ip: %s\n",
node_ip);
@@ -246,21 +283,29 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
node_ip,
handlers,
ts->cfgname,
- notify_connect),
+ notify_connect,
+ GNUNET_NO),
GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
write_message),
block_send,
connect_peers,
- GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
- "start-peer",
- num),
- block_receive,
+ GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check",
+ "start-peer",
+ "system-create",
+ num,
+ m_int,
+ n_int,
+ topology),
+ local_prepared,
GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
"start-peer"),
GNUNET_TESTING_cmd_system_destroy ("system-destroy",
- "system-create")
+ "system-create"),
+ GNUNET_TESTING_cmd_end ()
};
+ ts->write_message = write_message;
+
GNUNET_TESTING_run (commands,
GNUNET_TIME_UNIT_FOREVER_REL,
&handle_result,
@@ -287,6 +332,7 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_init (void *cls)
api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
api->start_testcase = &start_testcase;
api->all_peers_started = &all_peers_started;
+ api->all_local_tests_prepared = all_local_tests_prepared;
return api;
}
diff --git a/src/transport/test_transport_simple_send.sh b/src/transport/test_transport_simple_send.sh
index 2dd269fcc..3d5266622 100755
--- a/src/transport/test_transport_simple_send.sh
+++ b/src/transport/test_transport_simple_send.sh
@@ -1,2 +1,10 @@
#!/bin/bash
-exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf"
+if ! [ -d "/run/netns" ]; then
+ echo You have to create the directory /run/netns.
+fi
+if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" == 1 ]; then
+ exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf"
+else
+ echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
+ exit 78
+fi
diff --git a/src/transport/test_transport_simple_send_broadcast.sh b/src/transport/test_transport_simple_send_broadcast.sh
new file mode 100755
index 000000000..f264b1203
--- /dev/null
+++ b/src/transport/test_transport_simple_send_broadcast.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+if ! [ -d "/run/netns" ]; then
+ echo You have to create the directory /run/netns.
+fi
+if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" == 1 ]; then
+ # exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip/sed/bash ./test_transport_start_with_config test_transport_simple_send_broadcast_topo.conf"
+ exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_broadcast_topo.conf"
+else
+ echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
+ exit 78
+fi
diff --git a/src/transport/test_transport_simple_send_broadcast_topo.conf b/src/transport/test_transport_simple_send_broadcast_topo.conf
new file mode 100644
index 000000000..aa4964f81
--- /dev/null
+++ b/src/transport/test_transport_simple_send_broadcast_topo.conf
@@ -0,0 +1,4 @@
+M:2
+N:1
+X:0
+T:libgnunet_test_transport_plugin_cmd_simple_send_broadcast \ No newline at end of file
diff --git a/src/transport/test_transport_simple_send_dv.sh b/src/transport/test_transport_simple_send_dv.sh
new file mode 100755
index 000000000..fa127cfa4
--- /dev/null
+++ b/src/transport/test_transport_simple_send_dv.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+if ! [ -d "/run/netns" ]; then
+ echo You have to create the directory /run/netns.
+fi
+if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" == 1 ]; then
+ # exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip/sed/bash ./test_transport_start_with_config test_transport_distance_vector_topo.conf"
+ exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_distance_vector_topo.conf"
+else
+ echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
+ exit 78
+fi
diff --git a/src/transport/test_transport_simple_send_string.sh b/src/transport/test_transport_simple_send_string.sh
new file mode 100755
index 000000000..b2bd05d5f
--- /dev/null
+++ b/src/transport/test_transport_simple_send_string.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+string=$(cat << EOF
+M:2
+N:1
+X:0
+T:libgnunet_test_transport_plugin_cmd_simple_send
+P:1:1|{connect:{P:1:2:tcp}}
+P:1:2|{connect:{P:1:1:tcp}}
+EOF
+ )
+if ! [ -d "/run/netns" ]; then
+ echo You have to create the directory /run/netns.
+fi
+if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" == 1 ]; then
+ exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config -s '$string'"
+else
+ echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
+ exit 78
+fi
diff --git a/src/transport/test_transport_simple_send_topo.conf b/src/transport/test_transport_simple_send_topo.conf
new file mode 100644
index 000000000..2c16201f5
--- /dev/null
+++ b/src/transport/test_transport_simple_send_topo.conf
@@ -0,0 +1,6 @@
+M:2
+N:1
+X:0
+T:libgnunet_test_transport_plugin_cmd_simple_send
+P:1:1|{connect:{P:1:2:tcp}}
+P:1:2|{connect:{P:1:1:tcp}} \ No newline at end of file
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
index 932b0e583..c3411becc 100644
--- a/src/transport/test_transport_start_with_config.c
+++ b/src/transport/test_transport_start_with_config.c
@@ -25,6 +25,8 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+#include "transport-testing-cmds.h"
#include "gnunet_util_lib.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
@@ -34,27 +36,86 @@ int
main (int argc,
char *const *argv)
{
- char *topology_config;
+ char *topology_data;
+ char *topology_data_script;
+ struct GNUNET_TESTING_NetjailTopology *topology;
+ unsigned int read_file = GNUNET_YES;
+ int ret;
+ char *rest = NULL;
+ char *token;
+ size_t single_line_len;
+ size_t data_len;
GNUNET_log_setup ("test-netjail",
"DEBUG",
NULL);
- topology_config = argv[1];
+ if (0 == strcmp ("-s", argv[1]))
+ {
+ data_len = strlen (argv[2]);
+ topology_data = GNUNET_malloc (data_len);
+ topology_data_script = GNUNET_malloc (data_len);
+ token = strtok_r (argv[2], "\n", &rest);
+ while (NULL != token)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "token1 %s\n",
+ token);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "token2 %s\n",
+ token);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "topology_data %s\n",
+ topology_data);
+ strcat (topology_data_script, token);
+ strcat (topology_data_script, " ");
+ strcat (topology_data, token);
+ strcat (topology_data, "\n");
+ token = strtok_r (NULL, "\n", &rest);
+ }
+ single_line_len = strlen (topology_data);
+ topology_data_script [single_line_len - 1] = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "read from string\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "topology_data %s\n",
+ topology_data);
+ read_file = GNUNET_NO;
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+ }
+ else
+ {
+ topology_data = argv[1];
+ topology_data_script = argv[1];
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ }
struct GNUNET_TESTING_Command commands[] = {
GNUNET_TESTING_cmd_netjail_start ("netjail-start",
- topology_config),
+ topology_data_script,
+ &read_file),
GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
- topology_config),
+ topology,
+ &read_file,
+ topology_data_script),
GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
"netjail-start-testbed",
- topology_config),
+ topology),
GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
- topology_config),
+ topology_data_script,
+ &read_file),
GNUNET_TESTING_cmd_end ()
};
- return GNUNET_TESTING_main (commands,
- TIMEOUT);
+ ret = GNUNET_TESTING_main (commands,
+ TIMEOUT);
+
+ if (0 == strcmp ("-s", argv[1]))
+ {
+ GNUNET_free (topology_data_script);
+ GNUNET_free (topology_data);
+ }
+ GNUNET_TESTING_free_topology (topology);
+
+ return ret;
}
diff --git a/src/transport/test_transport_udp_backchannel.sh b/src/transport/test_transport_udp_backchannel.sh
index 3322e5853..1b0e283b5 100755
--- a/src/transport/test_transport_udp_backchannel.sh
+++ b/src/transport/test_transport_udp_backchannel.sh
@@ -1,2 +1,12 @@
#!/bin/bash
-exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
+if ! [ -d "/run/netns" ]; then
+ echo You have to create the directory /run/netns.
+fi
+if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" == 1 ]; then
+#exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=/usr/bin/awk,/usr/bin/cut,/usr/bin/seq,/sbin/ip ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
+exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; GNUNET_FORCE_LOG='transport;;;;DEBUG' GNUNET_FORCE_LOGFILE='test.out' ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
+# exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; valgrind --leak-check=full --track-origins=yes ./test_transport_start_with_config test_transport_udp_backchannel_topo.conf"
+else
+ echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
+ exit 78
+fi
diff --git a/src/transport/test_transport_udp_backchannel_topo.conf b/src/transport/test_transport_udp_backchannel_topo.conf
new file mode 100644
index 000000000..ad35bde0a
--- /dev/null
+++ b/src/transport/test_transport_udp_backchannel_topo.conf
@@ -0,0 +1,7 @@
+M:1
+N:1
+X:1
+T:libgnunet_test_transport_plugin_cmd_udp_backchannel
+K:1|{connect:{P:1:1:tcp}}
+R:1|{tcp_port:1}|{udp_port:0}
+P:1:1|{connect:{K:1:udp}}
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index f6e34df62..af6f47962 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -29,6 +29,10 @@
#include "gnunet_testing_lib.h"
+typedef void *
+(*GNUNET_TRANSPORT_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_PeerIdentity *peer);
+
/**
* Struct to store information needed in callbacks.
*
@@ -40,12 +44,12 @@ struct ConnectPeersState
*/
struct GNUNET_TESTING_AsyncContext ac;
- GNUNET_TRANSPORT_NotifyConnect notify_connect;
+ GNUNET_TRANSPORT_notify_connect_cb notify_connect;
/**
* The testing system of this node.
*/
- struct GNUNET_TESTING_System *tl_system;
+ const struct GNUNET_TESTING_System *tl_system;
// Label of the cmd which started the test system.
const char *create_label;
@@ -63,12 +67,6 @@ struct ConnectPeersState
const char *start_peer_label;
/**
- * The peer identity of this peer.
- *
- */
- struct GNUNET_PeerIdentity *id;
-
- /**
* The topology of the test setup.
*/
struct GNUNET_TESTING_NetjailTopology *topology;
@@ -84,6 +82,21 @@ struct ConnectPeersState
* Number of connections.
*/
unsigned int con_num;
+
+ /**
+ * Number of additional connects this cmd will wait for not triggered by this cmd.
+ */
+ unsigned int additional_connects;
+
+ /**
+ * Number of connections we already have a notification for.
+ */
+ unsigned int con_num_notified;
+
+ /**
+ * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for.
+ */
+ unsigned int additional_connects_notified;
};
struct StartPeerState
@@ -167,33 +180,31 @@ struct StartPeerState
struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
- struct GNUNET_TESTING_System *tl_system;
+ const struct GNUNET_TESTING_System *tl_system;
- GNUNET_TRANSPORT_NotifyConnect notify_connect;
+ GNUNET_TRANSPORT_notify_connect_cb notify_connect;
+ /**
+ * Flag indicating, if udp broadcast should be switched on.
+ */
+ unsigned int broadcast;
};
/**
- * Function to get the trait with the struct ConnectPeersState.
- *
- * @param[out] sps struct ConnectPeersState.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ * Create command.
*
+ * @param label name for command.
+ * @param system_label Label of the cmd to setup a test environment.
+ * @param m The number of the local node of the actual network namespace.
+ * @param n The number of the actual namespace.
+ * @param local_m Number of local nodes in each namespace.
+ * @param handlers Handler for messages received by this peer.
+ * @param cfgname Configuration file name for this peer.
+ * @param notify_connect Method which will be called, when a peer connects.
+ * @param broadcast Flag indicating, if broadcast should be switched on.
+ * @return command.
*/
-int
-GNUNET_TESTING_get_trait_connect_peer_state (
- const struct GNUNET_TESTING_Command *cmd,
- struct ConnectPeersState **cps);
-
-
-int
-GNUNET_TRANSPORT_get_trait_state (const struct
- GNUNET_TESTING_Command
- *cmd,
- struct StartPeerState **sps);
-
-
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_start_peer (const char *label,
const char *system_label,
@@ -201,7 +212,9 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
char *node_ip,
struct GNUNET_MQ_MessageHandler *handlers,
const char *cfgname,
- GNUNET_TRANSPORT_NotifyConnect notify_connect);
+ GNUNET_TRANSPORT_notify_connect_cb
+ notify_connect,
+ unsigned int broadcast);
struct GNUNET_TESTING_Command
@@ -209,68 +222,125 @@ GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
const char *start_label);
+/**
+ * Create command
+ *
+ * @param label name for command
+ * @param start_peer_label Label of the cmd to start a peer.
+ * @param create_peer_label Label of the cmd which started the test system.
+ * @param num Number globally identifying the node.
+ * @param The topology for the test setup.
+ * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd.
+ * @return command.
+ */
struct GNUNET_TESTING_Command
-GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
- const char *start_peer_label,
- const char *create_label,
- uint32_t num,
- struct GNUNET_TESTING_NetjailTopology *
- topology);
+GNUNET_TRANSPORT_cmd_connect_peers (
+ const char *label,
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num,
+ struct GNUNET_TESTING_NetjailTopology *topology,
+ unsigned int additional_connects);
/**
* Create command.
*
* @param label name for command.
- * @param m The number of the local node of the actual network namespace.
- * @param n The number of the actual namespace.
- * @param num Number globally identifying the node.
* @param start_peer_label Label of the cmd to start a peer.
+ * @param create_peer_label Label of the cmd which started the test system.
+ * @param num Number globally identifying the node.
+ * @param The topology for the test setup.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_send_simple (const char *label,
const char *start_peer_label,
- uint32_t num);
+ const char *create_label,
+ uint32_t num,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology);
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param start_peer_label Label of the cmd to start a peer.
+ * @param create_label Label of the cmd to create the testing system.
+ * @param num Number globally identifying the node.
+ * @param node_n The number of the node in a network namespace.
+ * @param namespace_n The number of the network namespace.
+ * @param The topology for the test setup.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num,
+ unsigned int node_n,
+ unsigned int namespace_n,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology);
+/**
+ * Create headers for a trait with name @a name for
+ * statically allocated data of type @a type.
+ */
+#define GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT(name,type) \
+ enum GNUNET_GenericReturnValue \
+ GNUNET_TRANSPORT_get_trait_ ## name ( \
+ const struct GNUNET_TESTING_Command *cmd, \
+ type **ret); \
+ struct GNUNET_TESTING_Trait \
+ GNUNET_TRANSPORT_make_trait_ ## name ( \
+ type * value);
-int
-GNUNET_TRANSPORT_get_trait_peer_id (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_PeerIdentity **id);
+/**
+ * Create C implementation for a trait with name @a name for statically
+ * allocated data of type @a type.
+ */
+#define GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
+ enum GNUNET_GenericReturnValue \
+ GNUNET_TRANSPORT_get_trait_ ## name ( \
+ const struct GNUNET_TESTING_Command *cmd, \
+ type **ret) \
+ { \
+ if (NULL == cmd->traits) return GNUNET_SYSERR; \
+ return cmd->traits (cmd->cls, \
+ (const void **) ret, \
+ GNUNET_S (name), \
+ 0); \
+ } \
+ struct GNUNET_TESTING_Trait \
+ GNUNET_TRANSPORT_make_trait_ ## name ( \
+ type * value) \
+ { \
+ struct GNUNET_TESTING_Trait ret = { \
+ .trait_name = GNUNET_S (name), \
+ .ptr = (const void *) value \
+ }; \
+ return ret; \
+ }
-int
-GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
- GNUNET_TESTING_Command
- *cmd,
- struct
- GNUNET_CONTAINER_MultiShortmap
- *
- *
- connected_peers_map);
-int
-GNUNET_TRANSPORT_get_trait_hello_size (const struct
- GNUNET_TESTING_Command
- *cmd,
- size_t **hello_size);
-int
-GNUNET_TRANSPORT_get_trait_hello (const struct
- GNUNET_TESTING_Command
- *cmd,
- char **hello);
+/**
+ * Call #op on all simple traits.
+ */
+#define GNUNET_TRANSPORT_SIMPLE_TRAITS(op) \
+ op (peer_id, const struct GNUNET_PeerIdentity) \
+ op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \
+ op (hello_size, const size_t) \
+ op (hello, const char) \
+ op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \
+ op (connect_peer_state, const struct ConnectPeersState) \
+ op (state, const struct StartPeerState)
+GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT)
-int
-GNUNET_TRANSPORT_get_trait_application_handle (const struct
- GNUNET_TESTING_Command *cmd,
- struct
- GNUNET_TRANSPORT_ApplicationHandle
- **ah);
#endif
/* end of transport_testing.h */
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index 446add6f6..2a80db87b 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -904,6 +904,10 @@ GNUNET_TRANSPORT_communicator_receive (
struct GNUNET_TRANSPORT_IncomingMessage *im;
uint16_t msize;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "communicator receive\n");
+
if (NULL == ch->mq)
return GNUNET_SYSERR;
if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length))
@@ -986,6 +990,9 @@ GNUNET_TRANSPORT_communicator_mq_add (
{
struct GNUNET_TRANSPORT_QueueHandle *qh;
+ // Do not notify the service if there is no intial capacity.
+ GNUNET_assert (0 < q_len);
+
qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle);
qh->ch = ch;
qh->peer = *peer;
@@ -1106,7 +1113,7 @@ GNUNET_TRANSPORT_communicator_address_remove (
*/
void
GNUNET_TRANSPORT_communicator_address_remove_all (
- struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
+ struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
{
for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
ai = ai->next)
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c
index 002af81fc..8cd0b7c8c 100644
--- a/src/transport/transport_api2_core.c
+++ b/src/transport/transport_api2_core.c
@@ -244,7 +244,8 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
struct GNUNET_TRANSPORT_CoreHandle *h = cls;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving from transport service, disconnecting temporarily.\n");
+ "Error %u received from transport service, disconnecting temporarily.\n",
+ error);
disconnect_and_schedule_reconnect (h);
}
@@ -522,6 +523,8 @@ check_recv (void *cls, const struct InboundMessage *im)
const struct GNUNET_MessageHeader *imm;
uint16_t size;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "check_recv\n");
size = ntohs (im->header.size) - sizeof(*im);
if (size < sizeof(struct GNUNET_MessageHeader))
{
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
new file mode 100644
index 000000000..1bec3abd3
--- /dev/null
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -0,0 +1,602 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 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 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/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file testing_api_cmd_backchannel_check.c
+ * @brief cmd to start a peer.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "gnunet_hello_lib.h"
+#include "gnunet_transport_service.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define UDP "udp"
+
+/**
+ * Maximum length allowed for line input.
+ */
+#define MAX_LINE_LENGTH 1024
+
+/**
+ * Struct to store information needed in callbacks.
+ *
+ */
+struct CheckState
+{
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
+ * The number of the node in a network namespace.
+ */
+ unsigned int node_n;
+
+ /**
+ * The number of the network namespace.
+ */
+ unsigned int namespace_n;
+
+ /**
+ * The testing system of this node.
+ */
+ const struct GNUNET_TESTING_System *tl_system;
+
+ // Label of the cmd which started the test system.
+ const char *create_label;
+
+ /**
+ * Number globally identifying the node.
+ *
+ */
+ uint32_t num;
+
+ /**
+ * Label of the cmd to start a peer.
+ *
+ */
+ const char *start_peer_label;
+
+ /**
+ * The topology of the test setup.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ /**
+ * Connections to other peers.
+ */
+ struct GNUNET_TESTING_NodeConnection *node_connections_head;
+
+ /**
+ * Number of connections.
+ */
+ unsigned int con_num;
+
+ /**
+ * Number of received backchannel messages.
+ */
+ unsigned int received_backchannel_msgs;
+
+ /**
+ * Array with search strings.
+ */
+ char **search_string;
+
+ /**
+ * File handle for log file.
+ */
+ struct GNUNET_DISK_FileHandle *fh;
+
+ /**
+ * Task which handles the reading
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Stream to read log file lines.
+ */
+ FILE *stream;
+};
+
+/**
+ *
+ * @param cls The cmd state CheckState.
+ */
+static void
+read_from_log (void *cls)
+{
+ struct CheckState *cs = cls;
+ char line[MAX_LINE_LENGTH + 1];
+ char *search_string;
+
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read_from_log\n");
+
+ cs->fh = GNUNET_DISK_file_open ("test.out",
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ);
+
+ cs->task = NULL;
+
+ /* read message from line and handle it */
+ cs->stream = fdopen (cs->fh->fd, "r");
+ memset (line, 0, MAX_LINE_LENGTH + 1);
+
+ // fgets (line, MAX_LINE_LENGTH, cs->stream);
+ // while (NULL != line && 0 != strcmp (line, ""))// '\0' != line[0])
+ while (NULL != fgets (line, MAX_LINE_LENGTH, cs->stream))
+ {
+ /*LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "cs->received_backchannel_msgs: %u\n",
+ cs->received_backchannel_msgs);*/
+ /*if (NULL == strstr (line, "line"))
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "line: %s",
+ line);*/
+
+
+ for (int i = 0; i < cs->con_num; i++)
+ {
+ search_string = cs->search_string[i];
+ /*LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "search %u %u: %s %p\n",
+ i,
+ cs->con_num,
+ cs->search_string[i],
+ cs->search_string);
+ fprintf (stderr,
+ line);*/
+ if (NULL != strstr (line,
+ search_string))
+ // "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"))
+ // cs->search_string[i]))
+ {
+ cs->received_backchannel_msgs++;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "received_backchannel_msgs %u con_num %u\n",
+ cs->received_backchannel_msgs,
+ cs->con_num);
+ if (cs->received_backchannel_msgs == cs->con_num)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "search finished %lu %lu %u\n",
+ strlen (cs->search_string[i]),
+ strlen (
+ "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp"),
+ strcmp (
+ "Delivering backchannel message from 4TTC to F7B5 of type 1460 to udp",
+ cs->search_string[i]));
+ GNUNET_TESTING_async_finish (&cs->ac);
+ fclose (cs->stream);
+ return;
+ }
+ }
+ }
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read_from_log end\n");
+ fclose (cs->stream);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &read_from_log,
+ cs);
+ /*if (NULL == fgets (line, MAX_LINE_LENGTH, cs->stream))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read null\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &read_from_log,
+ cs);
+ return;
+ }*/
+ /*else {
+ cs->task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ cs->fh,
+ &read_from_log,
+ cs);
+
+
+ }*/
+}
+
+
+static enum GNUNET_GenericReturnValue
+will_the_other_node_connect_via_udp (
+ struct CheckState *cs,
+ const struct GNUNET_TESTING_NetjailNode *node)
+// struct GNUNET_TESTING_NodeConnection *connection)
+{
+ // struct GNUNET_TESTING_NetjailTopology *topology = cs->topology;
+ // unsigned int node_n = connection->node_n;
+ // unsigned int namespace_n = connection->namespace_n;
+ // struct GNUNET_HashCode hc;
+ // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
+ // struct GNUNET_HashCode hc_namespace;
+ /*struct GNUNET_ShortHashCode *key_namespace = GNUNET_new (struct
+ GNUNET_ShortHashCode);*/
+ // struct GNUNET_TESTING_NetjailNode *node;
+ struct GNUNET_TESTING_NodeConnection *pos_connection;
+ struct GNUNET_TESTING_AddressPrefix *pos_prefix;
+ // struct GNUNET_TESTING_NetjailNamespace *namespace;
+ // struct GNUNET_CONTAINER_MultiShortmap *map;
+
+ /* if (0 == connection->namespace_n) */
+ /* { */
+ /* map = topology->map_globals; */
+ /* } */
+ /* else */
+ /* { */
+ /* GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc_namespace); */
+ /* memcpy (key_namespace, */
+ /* &hc_namespace, */
+ /* sizeof (*key_namespace)); */
+ /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
+ /* topology->map_namespaces, */
+ /* key_namespace)) */
+ /* { */
+ /* namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, */
+ /* key_namespace); */
+ /* map = namespace->nodes; */
+ /* } */
+ /* else */
+ /* GNUNET_assert (0); */
+ /* } */
+
+ /* GNUNET_CRYPTO_hash (&node_n, sizeof(node_n), &hc); */
+ /* memcpy (key, */
+ /* &hc, */
+ /* sizeof (*key)); */
+ /* if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( */
+ /* map, */
+ /* key)) */
+ /* { */
+ /* node = GNUNET_CONTAINER_multishortmap_get (cs->topology->map_globals, */
+ /* key); */
+ /* for (pos_connection = node->node_connections_head; NULL != pos_connection; */
+ /* pos_connection = pos_connection->next) */
+ /* { */
+ /* if ((node->namespace_n == pos_connection->namespace_n) && */
+ /* (node->node_n == pos_connection->node_n) ) */
+ /* { */
+ /* for (pos_prefix = pos_connection->address_prefixes_head; NULL != */
+ /* pos_prefix; */
+ /* pos_prefix = */
+ /* pos_prefix->next) */
+ /* { */
+ /* if (0 == strcmp (UDP, pos_prefix->address_prefix)) */
+ /* { */
+ /* return GNUNET_YES; */
+ /* } */
+ /* } */
+ /* } */
+ /* } */
+ /* } */
+
+ for (pos_connection = node->node_connections_head; NULL != pos_connection;
+ pos_connection = pos_connection->next)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "connect via udp %u %u %u %u\n",
+ node->namespace_n,
+ cs->namespace_n,
+ node->node_n,
+ cs->node_n);
+ if ((pos_connection->namespace_n == cs->namespace_n) &&
+ (pos_connection->node_n == cs->node_n) )
+ {
+ for (pos_prefix = pos_connection->address_prefixes_head; NULL !=
+ pos_prefix;
+ pos_prefix =
+ pos_prefix->next)
+ {
+ if (0 == strcmp (UDP, pos_prefix->address_prefix))
+ {
+ return GNUNET_YES;
+ }
+ }
+ }
+ }
+
+ return GNUNET_NO;
+}
+
+static void
+add_search_string (struct CheckState *cs, const struct
+ GNUNET_TESTING_NetjailNode *node)
+{
+ unsigned int num;
+ struct GNUNET_PeerIdentity *peer;
+ struct GNUNET_PeerIdentity *us;
+ char *buf;
+ char *part_one = "Delivering backchannel message from ";
+ char *part_two = " to ";
+ char *part_three = " of type 1460 to udp";
+ char *peer_id;
+ char *us_id;
+
+ if (0 == node->namespace_n)
+ num = node->node_n;
+ else
+ num = (node->namespace_n - 1) * cs->topology->nodes_m + node->node_n
+ + cs->topology->nodes_x;
+
+ // num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology);
+ peer = GNUNET_TESTING_get_pub_key (num, cs->tl_system);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "peer: %s num %u\n",
+ GNUNET_i2s (peer),
+ num);
+ us = GNUNET_TESTING_get_pub_key (cs->num, cs->tl_system);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "us: %s cs->num %d\n",
+ GNUNET_i2s (us),
+ cs->num);
+
+ GNUNET_asprintf (&peer_id,
+ "%s",
+ GNUNET_i2s (peer));
+ GNUNET_asprintf (&us_id,
+ "%s",
+ GNUNET_i2s (us));
+
+ if (0 < GNUNET_asprintf (&buf,
+ "%s%s%s%s%s",
+ part_one,
+ us_id,
+ part_two,
+ peer_id,
+ part_three))
+ {
+ GNUNET_array_append (cs->search_string,
+ cs->con_num,
+ buf);
+ /*LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "con_num: %u search: %s %p\n",
+ cs->con_num,
+ cs->search_string[cs->con_num - 1],
+ cs->search_string);*/
+ }
+ else
+ GNUNET_assert (0);
+}
+
+
+/**
+ * The run method of this cmd will connect to peers.
+ *
+ */
+static void
+backchannel_check_run (void *cls,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct CheckState *cs = cls;
+ // char *buf;
+ // char *part_one = "Delivering backchannel message from ";
+ // char *part_two = " of type 1460 to udp";
+ const struct GNUNET_TESTING_Command *system_cmd;
+ const struct GNUNET_TESTING_System *tl_system;
+ const struct GNUNET_TESTING_Command *peer1_cmd;
+ const struct GNUNET_TRANSPORT_ApplicationHandle *ah;
+ // struct GNUNET_PeerIdentity *peer;
+ // uint32_t num;
+ // struct GNUNET_TESTING_NodeConnection *pos_connection;
+ // unsigned int con_num = 0;
+ struct GNUNET_CONTAINER_MultiShortmapIterator *node_it;
+ struct GNUNET_CONTAINER_MultiShortmapIterator *namespace_it;
+ struct GNUNET_ShortHashCode node_key;
+ struct GNUNET_ShortHashCode namespace_key;
+ const struct GNUNET_TESTING_NetjailNode *node;
+ const struct GNUNET_TESTING_NetjailNamespace *namespace;
+
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ cs->start_peer_label);
+ GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
+ &ah);
+
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ cs->create_label);
+ GNUNET_TESTING_get_trait_test_system (system_cmd,
+ &tl_system);
+
+ cs->tl_system = tl_system;
+
+ cs->node_connections_head = GNUNET_TESTING_get_connections (cs->num,
+ cs->topology);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "check run\n");
+
+
+ node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
+ cs->topology->map_globals);
+
+ while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
+ &node_key,
+ (const
+ void**) &
+ node))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "namespace_n %u node_n %u\n",
+ node->namespace_n,
+ node->node_n);
+ if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
+ {
+ add_search_string (cs, node);
+ }
+ }
+ namespace_it = GNUNET_CONTAINER_multishortmap_iterator_create (
+ cs->topology->map_namespaces);
+ while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (
+ namespace_it,
+ &namespace_key,
+ (const
+ void**) &namespace))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "namespace_n %u\n",
+ node->namespace_n);
+ node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
+ namespace->nodes);
+ while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (node_it,
+ &node_key,
+ (const
+ void**)
+ &node))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "namespace_n %u node_n %u\n",
+ node->namespace_n,
+ node->node_n);
+ if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node))
+ {
+ add_search_string (cs, node);
+ }
+ }
+ }
+ /* for (pos_connection = cs->node_connections_head; NULL != pos_connection; */
+ /* pos_connection = pos_connection->next) */
+ /* { */
+
+ /* if (GNUNET_YES == will_the_other_node_connect_via_udp (cs, node)) */
+ /* { */
+ /* num = GNUNET_TESTING_calculate_num (pos_connection, cs->topology); */
+ /* peer = GNUNET_TESTING_get_pub_key (num, tl_system); */
+ /* LOG (GNUNET_ERROR_TYPE_DEBUG, */
+ /* "peer: %s\n", */
+ /* GNUNET_i2s (peer)); */
+
+ /* if (0 < GNUNET_asprintf (&buf, */
+ /* "%s%s%s", */
+ /* part_one, */
+ /* GNUNET_i2s (peer), */
+ /* part_two)) */
+ /* { */
+ /* GNUNET_array_append (cs->search_string, */
+ /* con_num, */
+ /* buf); */
+ /* /\*LOG (GNUNET_ERROR_TYPE_DEBUG, */
+ /* "con_num: %u search: %s %p\n", */
+ /* con_num, */
+ /* cs->search_string[con_num - 1], */
+ /* cs->search_string);*\/ */
+ /* } */
+ /* else */
+ /* GNUNET_assert (0); */
+ /* } */
+
+
+ /* } */
+ // cs->con_num = con_num;
+ if (0 != cs->con_num)
+ {
+ cs->task =
+ GNUNET_SCHEDULER_add_now (&read_from_log,
+ cs);
+ }
+ else
+ GNUNET_TESTING_async_finish (&cs->ac);
+
+}
+
+
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
+static int
+backchannel_check_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
+static void
+backchannel_check_cleanup (void *cls)
+{
+ struct ConnectPeersState *cs = cls;
+
+ GNUNET_free (cs);
+}
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param start_peer_label Label of the cmd to start a peer.
+ * @param create_label Label of the cmd to create the testing system.
+ * @param num Number globally identifying the node.
+ * @param node_n The number of the node in a network namespace.
+ * @param namespace_n The number of the network namespace.
+ * @param The topology for the test setup.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num,
+ unsigned int node_n,
+ unsigned int namespace_n,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology)
+{
+ struct CheckState *cs;
+
+ cs = GNUNET_new (struct CheckState);
+ cs->start_peer_label = start_peer_label;
+ cs->num = num;
+ cs->create_label = create_label;
+ cs->topology = topology;
+ cs->node_n = node_n;
+ cs->namespace_n = namespace_n;
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = cs,
+ .label = label,
+ .run = &backchannel_check_run,
+ .ac = &cs->ac,
+ .cleanup = &backchannel_check_cleanup,
+ .traits = &backchannel_check_traits
+ };
+
+ return cmd;
+}
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 2e51363f6..fc925675d 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_transport_service.h"
@@ -36,242 +37,6 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
-
-#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
-
-#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
-
-#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
-
-#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
-
-#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
-
-#define PREFIX_TCP "tcp"
-
-#define PREFIX_UDP "udp"
-
-
-
-
-static struct GNUNET_PeerIdentity *
-get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
-{
- struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
- struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
- GNUNET_CRYPTO_EddsaPublicKey);
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
- GNUNET_CRYPTO_EddsaPrivateKey);
-
- priv_key = GNUNET_TESTING_hostkey_get (tl_system,
- num,
- peer);
-
- GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
- pub_key);
- peer->public_key = *pub_key;
- return peer;
-}
-
-
-static int
-log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
-{
- struct GNUNET_TESTING_NetjailNode *node = value;
- struct GNUNET_TESTING_NodeConnection *pos_connection;
- struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin: %s space: %u node: %u global: %u\n",
- node->plugin,
- node->namespace_n,
- node->node_n,
- node->is_global);
-
- for (pos_connection = node->node_connections_head; NULL != pos_connection;
- pos_connection = pos_connection->next)
- {
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "namespace_n: %u node_n: %u node_type: %u\n",
- pos_connection->namespace_n,
- pos_connection->node_n,
- pos_connection->node_type);
-
- for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
- pos_prefix =
- pos_prefix->next)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "prefix: %s\n",
- pos_prefix->address_prefix);
- }
- }
- return GNUNET_YES;
-}
-
-
-static int
-log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
-{
- struct GNUNET_TESTING_NetjailNamespace *namespace = value;
- struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "router_tcp: %u router_udp: %u spaces: %u\n",
- router->tcp_port,
- router->udp_port,
- namespace->namespace_n);
- GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
- return GNUNET_YES;
-}
-
-
-static int
-log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
-{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin: %s spaces: %u nodes: %u known: %u\n",
- topology->plugin,
- topology->namespaces_n,
- topology->nodes_m,
- topology->nodes_x);
-
- GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
- log_namespaces, NULL);
- GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
- NULL);
- return GNUNET_YES;
-}
-
-
-static struct GNUNET_TESTING_NodeConnection *
-get_connections (unsigned int num, struct
- GNUNET_TESTING_NetjailTopology *topology)
-{
- struct GNUNET_TESTING_NetjailNode *node;
- struct GNUNET_ShortHashCode *hkey;
- struct GNUNET_HashCode hc;
- struct GNUNET_TESTING_NetjailNamespace *namespace;
- unsigned int namespace_n, node_m;
-
- log_topo (topology);
-
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- if (topology->nodes_x >= num)
- {
-
- GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
- hkey);
- }
- else
- {
- namespace_n = (unsigned int) floor ((num - topology->nodes_x)
- / topology->nodes_m);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
- num,
- topology->nodes_x,
- topology->nodes_m,
- namespace_n);
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
- hkey);
- node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
- hkey);
- }
-
-
- return node->node_connections_head;
-}
-
-
-static unsigned int
-calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
- struct GNUNET_TESTING_NetjailTopology *topology)
-{
- unsigned int n, m, num;
-
- n = node_connection->namespace_n;
- m = node_connection->node_n;
-
- if (0 == n)
- num = m;
- else
- num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
-
- return num;
-}
-
-
-static char *
-get_address (struct GNUNET_TESTING_NodeConnection *connection,
- char *prefix)
-{
- struct GNUNET_TESTING_NetjailNode *node;
- char *addr;
-
- node = connection->node;
- if (connection->namespace_n == node->namespace_n)
- {
- if (0 == strcmp (PREFIX_TCP, prefix))
- {
-
- GNUNET_asprintf (&addr,
- CONNECT_ADDRESS_TEMPLATE_TCP,
- connection->node_n);
- }
- else if (0 == strcmp (PREFIX_UDP, prefix))
- {
- GNUNET_asprintf (&addr,
- CONNECT_ADDRESS_TEMPLATE_UDP,
- connection->node_n);
- }
- else
- {
- GNUNET_break (0);
- }
- }
- else
- {
- if (0 == strcmp (PREFIX_TCP, prefix))
- {
-
- GNUNET_asprintf (&addr,
- ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
- connection->namespace_n);
- }
- else if (0 == strcmp (PREFIX_UDP, prefix))
- {
- GNUNET_asprintf (&addr,
- ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
- connection->namespace_n);
- }
- else
- {
- GNUNET_break (0);
- }
- }
-
- return addr;
-}
-
-
/**
* The run method of this cmd will connect to peers.
*
@@ -282,17 +47,17 @@ connect_peers_run (void *cls,
{
struct ConnectPeersState *cps = cls;
const struct GNUNET_TESTING_Command *system_cmd;
- struct GNUNET_TESTING_System *tl_system;
+ const struct GNUNET_TESTING_System *tl_system;
const struct GNUNET_TESTING_Command *peer1_cmd;
- struct GNUNET_TRANSPORT_ApplicationHandle *ah;
+ const struct GNUNET_TRANSPORT_ApplicationHandle *ah;
struct GNUNET_PeerIdentity *peer;
char *addr;
enum GNUNET_NetworkType nt = 0;
uint32_t num;
struct GNUNET_TESTING_NodeConnection *pos_connection;
- struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
+ struct GNUNET_TESTING_AddressPrefix *pos_prefix;
unsigned int con_num = 0;
cps->is = is;
@@ -308,38 +73,40 @@ connect_peers_run (void *cls,
cps->tl_system = tl_system;
- cps->node_connections_head = get_connections (cps->num, cps->topology);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "cps->num: %u \n",
+ cps->num);
+
+ cps->node_connections_head = GNUNET_TESTING_get_connections (cps->num,
+ cps->topology);
for (pos_connection = cps->node_connections_head; NULL != pos_connection;
pos_connection = pos_connection->next)
{
con_num++;
- num = calculate_num (pos_connection, cps->topology);
+ num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
pos_prefix =
pos_prefix->next)
{
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "prefix: %s\n",
- pos_prefix->address_prefix);
-
- addr = get_address (pos_connection, pos_prefix->address_prefix);
-
- peer = get_pub_key (num, tl_system);
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "num: %u pub_key %s addr: %s\n",
- num,
- GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
- addr);
-
- cps->id = peer;
-
- GNUNET_TRANSPORT_application_validate (ah,
- peer,
- nt,
- addr);
+ addr = GNUNET_TESTING_get_address (pos_connection,
+ pos_prefix->address_prefix);
+ if (NULL != addr)
+ {
+ peer = GNUNET_TESTING_get_pub_key (num, tl_system);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "validating peer number %u with identity %s\n",
+ num,
+ GNUNET_i2s (peer));
+ GNUNET_TRANSPORT_application_validate ((struct
+ GNUNET_TRANSPORT_ApplicationHandle
+ *) ah,
+ peer,
+ nt,
+ addr);
+ GNUNET_free (peer);
+ GNUNET_free (addr);
+ }
}
}
cps->con_num = con_num;
@@ -351,29 +118,36 @@ connect_peers_run (void *cls,
*
*/
static void *
-notify_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+notify_connect (struct GNUNET_TESTING_Interpreter *is,
+ const struct GNUNET_PeerIdentity *peer)
{
- struct ConnectPeersState *cps = cls;
+ const struct GNUNET_TESTING_Command *cmd;
+ struct ConnectPeersState *cps;
struct GNUNET_PeerIdentity *peer_connection;
- unsigned int con_num = 0;
struct GNUNET_TESTING_NodeConnection *pos_connection;
unsigned int num;
+ unsigned int con_num;
void *ret = NULL;
+ cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
+ "connect-peers");
+ cps = cmd->cls;
+ con_num = cps->con_num_notified;
for (pos_connection = cps->node_connections_head; NULL != pos_connection;
pos_connection = pos_connection->next)
{
- num = calculate_num (pos_connection, cps->topology);
- peer_connection = get_pub_key (num, cps->tl_system);
+ num = GNUNET_TESTING_calculate_num (pos_connection, cps->topology);
+ peer_connection = GNUNET_TESTING_get_pub_key (num, cps->tl_system);
if (0 == GNUNET_memcmp (peer,
peer_connection))
- con_num++;
+ cps->con_num_notified++;
+ GNUNET_free (peer_connection);
}
-
-
if (cps->con_num == con_num)
+ cps->additional_connects_notified++;
+
+ if (cps->con_num + cps->additional_connects == cps->con_num_notified
+ + cps->additional_connects_notified)
{
GNUNET_TESTING_async_finish (&cps->ac);
}
@@ -390,7 +164,6 @@ connect_peers_cleanup (void *cls)
{
struct ConnectPeersState *cps = cls;
- GNUNET_free (cps->id);
GNUNET_free (cps);
}
@@ -399,19 +172,15 @@ connect_peers_cleanup (void *cls)
* This function prepares an array with traits.
*
*/
-static int
+enum GNUNET_GenericReturnValue
connect_peers_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
- struct StartPeerState *cps = cls;
+ struct ConnectPeersState *cps = cls;
struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "state",
- .ptr = (const void *) cps,
- },
+ GNUNET_TRANSPORT_make_trait_connect_peer_state ((const void *) cps),
GNUNET_TESTING_trait_end ()
};
return GNUNET_TESTING_get_trait (traits,
@@ -422,31 +191,24 @@ connect_peers_traits (void *cls,
/**
- * Function to get the trait with the struct ConnectPeersState.
- *
- * @param[out] sps struct ConnectPeersState.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ * Create command
*
+ * @param label name for command
+ * @param start_peer_label Label of the cmd to start a peer.
+ * @param create_peer_label Label of the cmd which started the test system.
+ * @param num Number globally identifying the node.
+ * @param The topology for the test setup.
+ * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd.
+ * @return command.
*/
-int
-GNUNET_TESTING_get_trait_connect_peer_state (
- const struct GNUNET_TESTING_Command *cmd,
- struct ConnectPeersState **cps)
-{
- return cmd->traits (cmd->cls,
- (const void **) cps,
- "state",
- (unsigned int) 0);
-}
-
-
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
const char *start_peer_label,
const char *create_label,
uint32_t num,
struct GNUNET_TESTING_NetjailTopology *
- topology)
+ topology,
+ unsigned int additional_connects)
{
struct ConnectPeersState *cps;
@@ -455,7 +217,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
cps->num = num;
cps->create_label = create_label;
cps->topology = topology;
- cps->notify_connect = &notify_connect;
+ cps->notify_connect = notify_connect;
+ cps->additional_connects = additional_connects;
{
struct GNUNET_TESTING_Command cmd = {
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 0631f7051..ade0cc914 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -26,10 +26,16 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "transport-testing2.h"
#include "transport-testing-cmds.h"
/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+/**
* Struct to hold information for callbacks.
*
*/
@@ -46,21 +52,18 @@ struct SendSimpleState
*
*/
const char *start_peer_label;
-};
+ /**
+ * Label of the cmd which started the test system.
+ *
+ */
+ const char *create_label;
-/**
- * Trait function of this cmd does nothing.
- *
- */
-static int
-send_simple_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_OK;
-}
+ /**
+ * The topology we get the connected nodes from.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
+};
/**
@@ -76,8 +79,34 @@ send_simple_cleanup (void *cls)
}
+static int
+send_simple_cb (void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *value)
+{
+ struct SendSimpleState *sss = cls;
+ struct GNUNET_MQ_Handle *mq = value;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending simple test message\n");
+
+ env = GNUNET_MQ_msg_extra (test,
+ 1000 - sizeof(*test),
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
+ test->num = htonl (sss->num);
+ memset (&test[1],
+ sss->num,
+ 1000 - sizeof(*test));
+ GNUNET_MQ_send (mq,
+ env);
+ return GNUNET_OK;
+}
+
+
/**
- * The run method of this cmd will send a simple message to the connected peer.
+ * The run method of this cmd will send a simple message to the connected peers.
*
*/
static void
@@ -85,39 +114,63 @@ send_simple_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct SendSimpleState *sss = cls;
- struct GNUNET_MQ_Envelope *env;
- struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
- struct GNUNET_MQ_Handle *mq;
- struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
+ const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
const struct GNUNET_TESTING_Command *peer1_cmd;
- struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
+ // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
struct GNUNET_HashCode hc;
- int node_number;
+ struct GNUNET_TESTING_NodeConnection *node_connections_head;
+ struct GNUNET_PeerIdentity *peer;
+ struct GNUNET_CRYPTO_EddsaPublicKey public_key;
+ uint32_t num;
+ struct GNUNET_TESTING_NodeConnection *pos_connection;
+ const struct GNUNET_TESTING_Command *system_cmd;
+ const struct GNUNET_TESTING_System *tl_system;
peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
sss->start_peer_label);
GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
&connected_peers_map);
- node_number = 1;
- GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
- memcpy (key,
- &hc,
- sizeof (*key));
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
+ sss->create_label);
+ GNUNET_TESTING_get_trait_test_system (system_cmd,
+ &tl_system);
- mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
- key);
+ node_connections_head = GNUNET_TESTING_get_connections (sss->num,
+ sss->topology);
- env = GNUNET_MQ_msg_extra (test,
- 2600 - sizeof(*test),
- GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
- test->num = htonl (sss->num);
- memset (&test[1],
- sss->num,
- 2600 - sizeof(*test));
- GNUNET_MQ_send (mq,
- env);
- GNUNET_free (key);
+ GNUNET_CONTAINER_multishortmap_iterate (
+ (struct GNUNET_CONTAINER_MultiShortmap *)
+ connected_peers_map, send_simple_cb,
+ sss);
+ /*for (int i = 0; i < 1; i++)
+ {
+ for (pos_connection = node_connections_head; NULL != pos_connection;
+ pos_connection = pos_connection->next)
+ {
+ num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology);
+ peer = GNUNET_TESTING_get_pub_key (num, tl_system);
+ public_key = peer->public_key;
+ GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
+
+ memcpy (key,
+ &hc,
+ sizeof (*key));
+ mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
+ key);
+ env = GNUNET_MQ_msg_extra (test,
+ 1000 - sizeof(*test),
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
+ test->num = htonl (sss->num);
+ memset (&test[1],
+ sss->num,
+ 1000 - sizeof(*test));
+ GNUNET_MQ_send (mq,
+ env);
+ }
+ }*/
+
+ // GNUNET_free (key);
}
@@ -126,31 +179,34 @@ send_simple_run (void *cls,
* Create command.
*
* @param label name for command.
- * @param m The number of the local node of the actual network namespace.
- * @param n The number of the actual namespace.
- * @param num Number globally identifying the node.
* @param start_peer_label Label of the cmd to start a peer.
+ * @param start_peer_label Label of the cmd which started the test system.
+ * @param num Number globally identifying the node.
+ * @param The topology for the test setup.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_send_simple (const char *label,
const char *start_peer_label,
- uint32_t num)
+ const char *create_label,
+ uint32_t num,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology)
{
struct SendSimpleState *sss;
sss = GNUNET_new (struct SendSimpleState);
sss->num = num;
sss->start_peer_label = start_peer_label;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = sss,
- .label = label,
- .run = &send_simple_run,
- .cleanup = &send_simple_cleanup,
- .traits = &send_simple_traits
- };
-
- return cmd;
- }
+ sss->create_label = create_label;
+ sss->topology = topology;
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sss,
+ .label = label,
+ .run = &send_simple_run,
+ .cleanup = &send_simple_cleanup
+ };
+
+ return cmd;
}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index dc19f10eb..be2ea25b4 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"
@@ -125,12 +126,13 @@ notify_connect (void *cls,
void *ret = NULL;
-
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Peer %s connected to peer %u (`%s')\n",
- GNUNET_i2s (peer),
- sps->no,
+ "This Peer %s \n",
GNUNET_i2s (&sps->id));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %s connected to peer number %u\n",
+ GNUNET_i2s (peer),
+ sps->no);
GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
@@ -145,9 +147,8 @@ notify_connect (void *cls,
GNUNET_free (key);
- sps->notify_connect (cls,
- peer,
- mq);
+ sps->notify_connect (sps->ac.is,
+ peer);
// TODO what does the handler function need?
return ret;
@@ -166,12 +167,13 @@ start_peer_run (void *cls,
char *emsg = NULL;
struct GNUNET_PeerIdentity dummy;
const struct GNUNET_TESTING_Command *system_cmd;
- struct GNUNET_TESTING_System *tl_system;
+ const struct GNUNET_TESTING_System *tl_system;
char *home;
char *transport_unix_path;
char *tcp_communicator_unix_path;
char *udp_communicator_unix_path;
char *bindto;
+ char *bindto_udp;
if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
{
@@ -207,10 +209,18 @@ start_peer_run (void *cls,
"%s:60002",
sps->node_ip);
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_asprintf (&bindto_udp,
+ "2086");
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"node_ip %s\n",
bindto);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "bind_udp %s\n",
+ GNUNET_YES == sps->broadcast ?
+ bindto_udp : bindto);
+
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
home);
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
@@ -220,7 +230,8 @@ start_peer_run (void *cls,
bindto);
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
"BINDTO",
- bindto);
+ GNUNET_YES == sps->broadcast ?
+ bindto_udp : bindto);
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
"UNIXPATH",
tcp_communicator_unix_path);
@@ -235,11 +246,16 @@ start_peer_run (void *cls,
sps->tl_system = tl_system;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating testing library with key number %u\n",
+ sps->no);
+
if (GNUNET_SYSERR ==
- GNUNET_TESTING_configuration_create (tl_system,
+ GNUNET_TESTING_configuration_create ((struct
+ GNUNET_TESTING_System *) tl_system,
sps->cfg))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Testing library failed to create unique configuration based on `%s'\n",
sps->cfgname);
GNUNET_CONFIGURATION_destroy (sps->cfg);
@@ -247,7 +263,9 @@ start_peer_run (void *cls,
return;
}
- sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
+ sps->peer = GNUNET_TESTING_peer_configure ((struct
+ GNUNET_TESTING_System *) sps->
+ tl_system,
sps->cfg,
sps->no,
NULL,
@@ -255,9 +273,10 @@ start_peer_run (void *cls,
if (NULL == sps->peer)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Testing library failed to create unique configuration based on `%s': `%s'\n",
+ "Testing library failed to create unique configuration based on `%s': `%s' with key number %u\n",
sps->cfgname,
- emsg);
+ emsg,
+ sps->no);
GNUNET_free (emsg);
GNUNET_TESTING_interpreter_fail (is);
return;
@@ -337,6 +356,12 @@ start_peer_run (void *cls,
return;
}
sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
+ GNUNET_free (home);
+ GNUNET_free (transport_unix_path);
+ GNUNET_free (tcp_communicator_unix_path);
+ GNUNET_free (udp_communicator_unix_path);
+ GNUNET_free (bindto);
+ GNUNET_free (bindto_udp);
}
@@ -385,36 +410,14 @@ start_peer_traits (void *cls,
struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "application_handle",
- .ptr = (const void *) ah,
- },
- {
- .index = 1,
- .trait_name = "peer_id",
- .ptr = (const void *) id,
- },
- {
- .index = 2,
- .trait_name = "connected_peers_map",
- .ptr = (const void *) connected_peers_map,
- },
- {
- .index = 3,
- .trait_name = "hello",
- .ptr = (const void *) hello,
- },
- {
- .index = 4,
- .trait_name = "hello_size",
- .ptr = (const void *) hello_size,
- },
- {
- .index = 5,
- .trait_name = "state",
- .ptr = (const void *) sps,
- },
+ GNUNET_TRANSPORT_make_trait_application_handle ((const void *) ah),
+ GNUNET_TRANSPORT_make_trait_peer_id ((const void *) id),
+ GNUNET_TRANSPORT_make_trait_connected_peers_map ((const
+ void *)
+ connected_peers_map),
+ GNUNET_TRANSPORT_make_trait_hello ((const void *) hello),
+ GNUNET_TRANSPORT_make_trait_hello_size ((const void *) hello_size),
+ GNUNET_TRANSPORT_make_trait_state ((const void *) sps),
GNUNET_TESTING_trait_end ()
};
@@ -426,127 +429,6 @@ start_peer_traits (void *cls,
/**
- * Function to get the trait with the struct StartPeerState.
- *
- * @param[out] sps struct StartPeerState.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- *
- */
-int
-GNUNET_TRANSPORT_get_trait_state (
- const struct GNUNET_TESTING_Command *cmd,
- struct StartPeerState **sps)
-{
- return cmd->traits (cmd->cls,
- (const void **) sps,
- "state",
- (unsigned int) 5);
-}
-
-
-/**
- * Function to get the trait with the size of the hello.
- *
- * @param[out] hello_size size of hello.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- *
- */
-int
-GNUNET_TRANSPORT_get_trait_hello_size (const struct
- GNUNET_TESTING_Command
- *cmd,
- size_t **hello_size)
-{
- return cmd->traits (cmd->cls,
- (const void **) hello_size,
- "hello_size",
- (unsigned int) 4);
-}
-
-
-/**
- * Function to get the trait with the hello.
- *
- * @param[out] hello The hello for the peer.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- *
- */
-int
-GNUNET_TRANSPORT_get_trait_hello (const struct
- GNUNET_TESTING_Command
- *cmd,
- char **hello)
-{
- return cmd->traits (cmd->cls,
- (const void **) hello,
- "hello",
- (unsigned int) 3);
-}
-
-
-/**
- * Function to get the trait with the map of connected peers.
- *
- * @param[out] connected_peers_map The map with connected peers.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- *
- */
-int
-GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
- GNUNET_TESTING_Command
- *cmd,
- struct
- GNUNET_CONTAINER_MultiShortmap
- *
- *
- connected_peers_map)
-{
- return cmd->traits (cmd->cls,
- (const void **) connected_peers_map,
- "connected_peers_map",
- (unsigned int) 2);
-}
-
-
-/**
- * Function to get the trait with the transport application handle.
- *
- * @param[out] ah The application handle.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- */
-int
-GNUNET_TRANSPORT_get_trait_application_handle (const struct
- GNUNET_TESTING_Command *cmd,
- struct
- GNUNET_TRANSPORT_ApplicationHandle
- **ah)
-{
- return cmd->traits (cmd->cls,
- (const void **) ah,
- "application_handle",
- (unsigned int) 0);
-}
-
-
-/**
- * Function to get the trait with the peer id.
- *
- * @param[out] id The peer id.
- * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
- */
-int
-GNUNET_TRANSPORT_get_trait_peer_id (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_PeerIdentity **id)
-{
- return cmd->traits (cmd->cls,
- (const void **) id,
- "peer_id",
- (unsigned int) 1);
-}
-
-
-/**
* Create command.
*
* @param label name for command.
@@ -556,6 +438,8 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
* @param local_m Number of local nodes in each namespace.
* @param handlers Handler for messages received by this peer.
* @param cfgname Configuration file name for this peer.
+ * @param notify_connect Method which will be called, when a peer connects.
+ * @param broadcast Flag indicating, if broadcast should be switched on.
* @return command.
*/
struct GNUNET_TESTING_Command
@@ -565,7 +449,9 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
char *node_ip,
struct GNUNET_MQ_MessageHandler *handlers,
const char *cfgname,
- GNUNET_TRANSPORT_NotifyConnect notify_connect)
+ GNUNET_TRANSPORT_notify_connect_cb
+ notify_connect,
+ unsigned int broadcast)
{
struct StartPeerState *sps;
struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
@@ -579,6 +465,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
sps->cfgname = cfgname;
sps->node_ip = node_ip;
sps->notify_connect = notify_connect;
+ sps->broadcast = broadcast;
if (NULL != handlers)
{
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index dcb982a65..4ca730add 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"
@@ -57,7 +58,7 @@ stop_peer_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct StopPeerState *stop_ps = cls;
- struct StartPeerState *sps;
+ const struct StartPeerState *sps;
const struct GNUNET_TESTING_Command *start_cmd;
start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
@@ -68,24 +69,20 @@ stop_peer_run (void *cls,
if (NULL != sps->pic)
{
GNUNET_PEERSTORE_iterate_cancel (sps->pic);
- sps->pic = NULL;
}
if (NULL != sps->th)
{
GNUNET_TRANSPORT_core_disconnect (sps->th);
- sps->th = NULL;
}
if (NULL != sps->ah)
{
GNUNET_TRANSPORT_application_done (sps->ah);
- sps->ah = NULL;
}
if (NULL != sps->ph)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting from PEERSTORE service\n");
GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
- sps->ph = NULL;
}
if (NULL != sps->peer)
{
@@ -98,12 +95,9 @@ stop_peer_run (void *cls,
GNUNET_i2s (&sps->id));
}
GNUNET_TESTING_peer_destroy (sps->peer);
- sps->peer = NULL;
}
if (NULL != sps->rh_task)
GNUNET_SCHEDULER_cancel (sps->rh_task);
- sps->rh_task = NULL;
-
}
diff --git a/src/transport/transport_api_traits.c b/src/transport/transport_api_traits.c
new file mode 100644
index 000000000..7e66cc3d1
--- /dev/null
+++ b/src/transport/transport_api_traits.c
@@ -0,0 +1,32 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2021 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 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/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file transport/test_transport_start_with_config.c
+ * @brief Generic program to start testcases in an configurable topology.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+#include "transport-testing-cmds.h"
+#include "gnunet_util_lib.h"
+
+GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT)