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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file transport-testing-send.c
22 * @brief convenience transmission function for tests
23 * @author Christian Grothoff
25 #include "transport-testing.h"
28 * Acceptable transmission delay.
30 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
34 * Return @a cx in @a cls.
38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
42 if (GNUNET_NO == cx->connected)
49 * Send a test message of type @a mtype and size @a msize from
50 * peer @a sender to peer @a receiver. The peers should be
51 * connected when this function is called.
53 * @param sender the sending peer
54 * @param receiver the receiving peer
55 * @param mtype message type to use
56 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)`
57 * @param num unique message number
58 * @param cont continuation to call after transmission
59 * @param cont_cls closure for @a cont
60 * @return #GNUNET_OK if message was queued,
61 * #GNUNET_NO if peers are not connected
62 * #GNUNET_SYSERR if @a msize is illegal
65 GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
70 GNUNET_SCHEDULER_TaskCallback cont,
73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
74 struct GNUNET_MQ_Envelope *env;
75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
77 if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))
83 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender,
88 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver,
103 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
106 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
108 GNUNET_i2s (&sender->id),
111 GNUNET_free (receiver_s);
113 env = GNUNET_MQ_msg_extra (test,
114 msize - sizeof (*test),
116 test->num = htonl (num);
119 msize - sizeof (*test));
120 GNUNET_MQ_notify_sent (env,
123 GNUNET_MQ_send (cr->mq,
130 * Task that sends a test message from the
131 * first peer to the second peer.
133 * @param ccc context which should contain at least two peers, the
134 * first two of which should be currently connected
135 * @param size desired message size
136 * @param cont continuation to call after transmission
137 * @param cont_cls closure for @a cont
140 do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
142 GNUNET_SCHEDULER_TaskCallback cont,
147 ccc->global_ret = GNUNET_SYSERR;
148 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0],
150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
155 GNUNET_assert (GNUNET_SYSERR != ret);
156 if (GNUNET_NO == ret)
159 ccc->global_ret = GNUNET_SYSERR;
160 GNUNET_SCHEDULER_shutdown ();
166 * Task that sends a minimalistic test message from the
167 * first peer to the second peer.
169 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
170 * which should contain at least two peers, the first two
171 * of which should be currently connected
174 GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
180 if (0 < sc->num_messages)
183 done = (0 == sc->num_messages);
187 done = 0; /* infinite loop */
189 msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
190 if (NULL != sc->get_size_cb)
191 msize = sc->get_size_cb (sc->num_messages);
192 /* if this was the last message, call the continuation,
193 otherwise call this function again */
196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
197 done ? sc->cont_cls : sc);
202 * Task that sends a large test message from the
203 * first peer to the second peer.
205 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
206 * which should contain at least two peers, the first two
207 * of which should be currently connected
210 GNUNET_TRANSPORT_TESTING_large_send (void *cls)
212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
216 if (0 < sc->num_messages)
219 done = (0 == sc->num_messages);
223 done = 0; /* infinite loop */
226 if (NULL != sc->get_size_cb)
227 msize = sc->get_size_cb (sc->num_messages);
228 /* if this was the last message, call the continuation,
229 otherwise call this function again */
232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
233 done ? sc->cont_cls : sc);
236 /* end of transport-testing-send.c */