summaryrefslogtreecommitdiff
path: root/src/transport/transport-testing-send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing-send.c')
-rw-r--r--src/transport/transport-testing-send.c206
1 files changed, 103 insertions, 103 deletions
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c
index cb4be57de..42735e4c1 100644
--- a/src/transport/transport-testing-send.c
+++ b/src/transport/transport-testing-send.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport-testing-send.c 21 * @file transport-testing-send.c
22 * @brief convenience transmission function for tests 22 * @brief convenience transmission function for tests
@@ -27,15 +27,15 @@
27/** 27/**
28 * Acceptable transmission delay. 28 * Acceptable transmission delay.
29 */ 29 */
30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
31 31
32 32
33/** 33/**
34 * Return @a cx in @a cls. 34 * Return @a cx in @a cls.
35 */ 35 */
36static void 36static void
37find_cr (void *cls, 37find_cr(void *cls,
38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
39{ 39{
40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; 40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
41 41
@@ -62,72 +62,72 @@ find_cr (void *cls,
62 * #GNUNET_SYSERR if @a msize is illegal 62 * #GNUNET_SYSERR if @a msize is illegal
63 */ 63 */
64int 64int
65GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 65GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
67 uint16_t mtype, 67 uint16_t mtype,
68 uint16_t msize, 68 uint16_t msize,
69 uint32_t num, 69 uint32_t num,
70 GNUNET_SCHEDULER_TaskCallback cont, 70 GNUNET_SCHEDULER_TaskCallback cont,
71 void *cont_cls) 71 void *cont_cls)
72{ 72{
73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; 73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
74 struct GNUNET_MQ_Envelope *env; 74 struct GNUNET_MQ_Envelope *env;
75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test; 75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
76 76
77 if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)) 77 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
78 { 78 {
79 GNUNET_break (0); 79 GNUNET_break(0);
80 return GNUNET_SYSERR; 80 return GNUNET_SYSERR;
81 } 81 }
82 cr = NULL; 82 cr = NULL;
83 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender, 83 GNUNET_TRANSPORT_TESTING_find_connecting_context(sender,
84 receiver, 84 receiver,
85 &find_cr, 85 &find_cr,
86 &cr); 86 &cr);
87 if (NULL == cr) 87 if (NULL == cr)
88 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver, 88 GNUNET_TRANSPORT_TESTING_find_connecting_context(receiver,
89 sender, 89 sender,
90 &find_cr, 90 &find_cr,
91 &cr); 91 &cr);
92 if (NULL == cr) 92 if (NULL == cr)
93 {
94 GNUNET_break(0);
95 return GNUNET_NO;
96 }
97 if (NULL == cr->mq)
98 {
99 GNUNET_break(0);
100 return GNUNET_NO;
101 }
93 { 102 {
94 GNUNET_break (0); 103 char *receiver_s = GNUNET_strdup(GNUNET_i2s(&receiver->id));
95 return GNUNET_NO; 104
105 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
106 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
107 sender->no,
108 GNUNET_i2s(&sender->id),
109 receiver->no,
110 receiver_s);
111 GNUNET_free(receiver_s);
96 } 112 }
97 if (NULL == cr->mq) 113 env = GNUNET_MQ_msg_extra(test,
98 { 114 msize - sizeof(*test),
99 GNUNET_break (0); 115 mtype);
100 return GNUNET_NO; 116 test->num = htonl(num);
101 } 117 memset(&test[1],
102 { 118 num,
103 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 119 msize - sizeof(*test));
104 120 GNUNET_MQ_notify_sent(env,
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 121 cont,
106 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", 122 cont_cls);
107 sender->no, 123 GNUNET_MQ_send(cr->mq,
108 GNUNET_i2s (&sender->id), 124 env);
109 receiver->no,
110 receiver_s);
111 GNUNET_free (receiver_s);
112 }
113 env = GNUNET_MQ_msg_extra (test,
114 msize - sizeof (*test),
115 mtype);
116 test->num = htonl (num);
117 memset (&test[1],
118 num,
119 msize - sizeof (*test));
120 GNUNET_MQ_notify_sent (env,
121 cont,
122 cont_cls);
123 GNUNET_MQ_send (cr->mq,
124 env);
125 return GNUNET_OK; 125 return GNUNET_OK;
126} 126}
127 127
128 128
129/** 129/**
130 * Task that sends a test message from the 130 * Task that sends a test message from the
131 * first peer to the second peer. 131 * first peer to the second peer.
132 * 132 *
133 * @param ccc context which should contain at least two peers, the 133 * @param ccc context which should contain at least two peers, the
@@ -137,33 +137,33 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
137 * @param cont_cls closure for @a cont 137 * @param cont_cls closure for @a cont
138 */ 138 */
139static void 139static void
140do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 140do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
141 uint16_t size, 141 uint16_t size,
142 GNUNET_SCHEDULER_TaskCallback cont, 142 GNUNET_SCHEDULER_TaskCallback cont,
143 void *cont_cls) 143 void *cont_cls)
144{ 144{
145 int ret; 145 int ret;
146 146
147 ccc->global_ret = GNUNET_SYSERR; 147 ccc->global_ret = GNUNET_SYSERR;
148 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0], 148 ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[0],
149 ccc->p[1], 149 ccc->p[1],
150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
151 size, 151 size,
152 ccc->send_num_gen++, 152 ccc->send_num_gen++,
153 cont, 153 cont,
154 cont_cls); 154 cont_cls);
155 GNUNET_assert (GNUNET_SYSERR != ret); 155 GNUNET_assert(GNUNET_SYSERR != ret);
156 if (GNUNET_NO == ret) 156 if (GNUNET_NO == ret)
157 { 157 {
158 GNUNET_break (0); 158 GNUNET_break(0);
159 ccc->global_ret = GNUNET_SYSERR; 159 ccc->global_ret = GNUNET_SYSERR;
160 GNUNET_SCHEDULER_shutdown (); 160 GNUNET_SCHEDULER_shutdown();
161 } 161 }
162} 162}
163 163
164 164
165/** 165/**
166 * Task that sends a minimalistic test message from the 166 * Task that sends a minimalistic test message from the
167 * first peer to the second peer. 167 * first peer to the second peer.
168 * 168 *
169 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 169 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
@@ -171,35 +171,35 @@ do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
171 * of which should be currently connected 171 * of which should be currently connected
172 */ 172 */
173void 173void
174GNUNET_TRANSPORT_TESTING_simple_send (void *cls) 174GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
175{ 175{
176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
177 int done; 177 int done;
178 size_t msize; 178 size_t msize;
179 179
180 if (0 < sc->num_messages) 180 if (0 < sc->num_messages)
181 { 181 {
182 sc->num_messages--; 182 sc->num_messages--;
183 done = (0 == sc->num_messages); 183 done = (0 == sc->num_messages);
184 } 184 }
185 else 185 else
186 { 186 {
187 done = 0; /* infinite loop */ 187 done = 0; /* infinite loop */
188 } 188 }
189 msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage); 189 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
190 if (NULL != sc->get_size_cb) 190 if (NULL != sc->get_size_cb)
191 msize = sc->get_size_cb (sc->num_messages); 191 msize = sc->get_size_cb(sc->num_messages);
192 /* if this was the last message, call the continuation, 192 /* if this was the last message, call the continuation,
193 otherwise call this function again */ 193 otherwise call this function again */
194 do_send (sc->ccc, 194 do_send(sc->ccc,
195 msize, 195 msize,
196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, 196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
197 done ? sc->cont_cls : sc); 197 done ? sc->cont_cls : sc);
198} 198}
199 199
200 200
201/** 201/**
202 * Task that sends a large test message from the 202 * Task that sends a large test message from the
203 * first peer to the second peer. 203 * first peer to the second peer.
204 * 204 *
205 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 205 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
@@ -207,30 +207,30 @@ GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
207 * of which should be currently connected 207 * of which should be currently connected
208 */ 208 */
209void 209void
210GNUNET_TRANSPORT_TESTING_large_send (void *cls) 210GNUNET_TRANSPORT_TESTING_large_send(void *cls)
211{ 211{
212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
213 int done; 213 int done;
214 size_t msize; 214 size_t msize;
215 215
216 if (0 < sc->num_messages) 216 if (0 < sc->num_messages)
217 { 217 {
218 sc->num_messages--; 218 sc->num_messages--;
219 done = (0 == sc->num_messages); 219 done = (0 == sc->num_messages);
220 } 220 }
221 else 221 else
222 { 222 {
223 done = 0; /* infinite loop */ 223 done = 0; /* infinite loop */
224 } 224 }
225 msize = 2600; 225 msize = 2600;
226 if (NULL != sc->get_size_cb) 226 if (NULL != sc->get_size_cb)
227 msize = sc->get_size_cb (sc->num_messages); 227 msize = sc->get_size_cb(sc->num_messages);
228 /* if this was the last message, call the continuation, 228 /* if this was the last message, call the continuation,
229 otherwise call this function again */ 229 otherwise call this function again */
230 do_send (sc->ccc, 230 do_send(sc->ccc,
231 msize, 231 msize,
232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, 232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
233 done ? sc->cont_cls : sc); 233 done ? sc->cont_cls : sc);
234} 234}
235 235
236/* end of transport-testing-send.c */ 236/* end of transport-testing-send.c */