2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file transport-testing-send.c
20 * @brief convenience transmission function for tests
21 * @author Christian Grothoff
23 #include "transport-testing.h"
26 * Acceptable transmission delay.
28 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
32 * Return @a cx in @a cls.
36 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
40 if (GNUNET_NO == cx->connected)
47 * Send a test message of type @a mtype and size @a msize from
48 * peer @a sender to peer @a receiver. The peers should be
49 * connected when this function is called.
51 * @param sender the sending peer
52 * @param receiver the receiving peer
53 * @param mtype message type to use
54 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)`
55 * @param num unique message number
56 * @param cont continuation to call after transmission
57 * @param cont_cls closure for @a cont
58 * @return #GNUNET_OK if message was queued,
59 * #GNUNET_NO if peers are not connected
60 * #GNUNET_SYSERR if @a msize is illegal
63 GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
64 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
68 GNUNET_SCHEDULER_TaskCallback cont,
71 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
72 struct GNUNET_MQ_Envelope *env;
73 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
75 if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))
81 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender,
86 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver,
101 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
104 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
106 GNUNET_i2s (&sender->id),
109 GNUNET_free (receiver_s);
111 env = GNUNET_MQ_msg_extra (test,
112 msize - sizeof (*test),
114 test->num = htonl (num);
117 msize - sizeof (*test));
118 GNUNET_MQ_notify_sent (env,
121 GNUNET_MQ_send (cr->mq,
128 * Task that sends a test message from the
129 * first peer to the second peer.
131 * @param ccc context which should contain at least two peers, the
132 * first two of which should be currently connected
133 * @param size desired message size
134 * @param cont continuation to call after transmission
135 * @param cont_cls closure for @a cont
138 do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
140 GNUNET_SCHEDULER_TaskCallback cont,
145 ccc->global_ret = GNUNET_SYSERR;
146 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0],
148 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
153 GNUNET_assert (GNUNET_SYSERR != ret);
154 if (GNUNET_NO == ret)
157 ccc->global_ret = GNUNET_SYSERR;
158 GNUNET_SCHEDULER_shutdown ();
164 * Task that sends a minimalistic test message from the
165 * first peer to the second peer.
167 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
168 * which should contain at least two peers, the first two
169 * of which should be currently connected
172 GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
174 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
178 if (0 < sc->num_messages)
181 done = (0 == sc->num_messages);
185 done = 0; /* infinite loop */
187 msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
188 if (NULL != sc->get_size_cb)
189 msize = sc->get_size_cb (sc->num_messages);
190 /* if this was the last message, call the continuation,
191 otherwise call this function again */
194 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
195 done ? sc->cont_cls : sc);
200 * Task that sends a large test message from the
201 * first peer to the second peer.
203 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
204 * which should contain at least two peers, the first two
205 * of which should be currently connected
208 GNUNET_TRANSPORT_TESTING_large_send (void *cls)
210 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
214 if (0 < sc->num_messages)
217 done = (0 == sc->num_messages);
221 done = 0; /* infinite loop */
224 if (NULL != sc->get_size_cb)
225 msize = sc->get_size_cb (sc->num_messages);
226 /* if this was the last message, call the continuation,
227 otherwise call this function again */
230 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
231 done ? sc->cont_cls : sc);
234 /* end of transport-testing-send.c */