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 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.
16 * @file transport-testing-send.c
17 * @brief convenience transmission function for tests
18 * @author Christian Grothoff
20 #include "transport-testing.h"
23 * Acceptable transmission delay.
25 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
29 * Return @a cx in @a cls.
33 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
35 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
37 if (GNUNET_NO == cx->connected)
44 * Send a test message of type @a mtype and size @a msize from
45 * peer @a sender to peer @a receiver. The peers should be
46 * connected when this function is called.
48 * @param sender the sending peer
49 * @param receiver the receiving peer
50 * @param mtype message type to use
51 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)`
52 * @param num unique message number
53 * @param cont continuation to call after transmission
54 * @param cont_cls closure for @a cont
55 * @return #GNUNET_OK if message was queued,
56 * #GNUNET_NO if peers are not connected
57 * #GNUNET_SYSERR if @a msize is illegal
60 GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
61 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
65 GNUNET_SCHEDULER_TaskCallback cont,
68 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
69 struct GNUNET_MQ_Envelope *env;
70 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
72 if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))
78 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender,
83 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver,
98 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
100 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
101 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
103 GNUNET_i2s (&sender->id),
106 GNUNET_free (receiver_s);
108 env = GNUNET_MQ_msg_extra (test,
109 msize - sizeof (*test),
111 test->num = htonl (num);
114 msize - sizeof (*test));
115 GNUNET_MQ_notify_sent (env,
118 GNUNET_MQ_send (cr->mq,
125 * Task that sends a test message from the
126 * first peer to the second peer.
128 * @param ccc context which should contain at least two peers, the
129 * first two of which should be currently connected
130 * @param size desired message size
131 * @param cont continuation to call after transmission
132 * @param cont_cls closure for @a cont
135 do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
137 GNUNET_SCHEDULER_TaskCallback cont,
142 ccc->global_ret = GNUNET_SYSERR;
143 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0],
145 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
150 GNUNET_assert (GNUNET_SYSERR != ret);
151 if (GNUNET_NO == ret)
154 ccc->global_ret = GNUNET_SYSERR;
155 GNUNET_SCHEDULER_shutdown ();
161 * Task that sends a minimalistic test message from the
162 * first peer to the second peer.
164 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
165 * which should contain at least two peers, the first two
166 * of which should be currently connected
169 GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
171 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
175 if (0 < sc->num_messages)
178 done = (0 == sc->num_messages);
182 done = 0; /* infinite loop */
184 msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
185 if (NULL != sc->get_size_cb)
186 msize = sc->get_size_cb (sc->num_messages);
187 /* if this was the last message, call the continuation,
188 otherwise call this function again */
191 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
192 done ? sc->cont_cls : sc);
197 * Task that sends a large test message from the
198 * first peer to the second peer.
200 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
201 * which should contain at least two peers, the first two
202 * of which should be currently connected
205 GNUNET_TRANSPORT_TESTING_large_send (void *cls)
207 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
211 if (0 < sc->num_messages)
214 done = (0 == sc->num_messages);
218 done = 0; /* infinite loop */
221 if (NULL != sc->get_size_cb)
222 msize = sc->get_size_cb (sc->num_messages);
223 /* if this was the last message, call the continuation,
224 otherwise call this function again */
227 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
228 done ? sc->cont_cls : sc);
231 /* end of transport-testing-send.c */