diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-21 23:10:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-21 23:10:54 +0000 |
commit | 0979ddcbd310b856b7c36c6ed9c8dc17c0b032db (patch) | |
tree | 18b0fa2c1b2ecd41187d8197dcf3f88d82417d32 /src/transport/transport-testing-send.c | |
parent | ae9918852bed2d822c12e110d6b754520e601388 (diff) | |
download | gnunet-0979ddcbd310b856b7c36c6ed9c8dc17c0b032db.tar.gz gnunet-0979ddcbd310b856b7c36c6ed9c8dc17c0b032db.zip |
generalize send API for transport tests
Diffstat (limited to 'src/transport/transport-testing-send.c')
-rw-r--r-- | src/transport/transport-testing-send.c | 72 |
1 files changed, 62 insertions, 10 deletions
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c index 20d1f2fbc..60fed23a6 100644 --- a/src/transport/transport-testing-send.c +++ b/src/transport/transport-testing-send.c | |||
@@ -58,7 +58,7 @@ notify_ready (void *cls, | |||
58 | GNUNET_assert (size >= msize); | 58 | GNUNET_assert (size >= msize); |
59 | if (NULL != buf) | 59 | if (NULL != buf) |
60 | { | 60 | { |
61 | memset (buf, '\0', msize); | 61 | memset (buf, sj->num, msize); |
62 | test = buf; | 62 | test = buf; |
63 | test->header.size = htons (msize); | 63 | test->header.size = htons (msize); |
64 | test->header.type = htons (sj->mtype); | 64 | test->header.type = htons (sj->mtype); |
@@ -79,6 +79,9 @@ notify_ready (void *cls, | |||
79 | GNUNET_i2s (&receiver->id)); | 79 | GNUNET_i2s (&receiver->id)); |
80 | GNUNET_free (ps); | 80 | GNUNET_free (ps); |
81 | } | 81 | } |
82 | if (NULL != sj->cont) | ||
83 | GNUNET_SCHEDULER_add_now (sj->cont, | ||
84 | sj->cont_cls); | ||
82 | GNUNET_free (sj); | 85 | GNUNET_free (sj); |
83 | return msize; | 86 | return msize; |
84 | } | 87 | } |
@@ -107,6 +110,8 @@ find_cr (void *cls, | |||
107 | * @param mtype message type to use | 110 | * @param mtype message type to use |
108 | * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)` | 111 | * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)` |
109 | * @param num unique message number | 112 | * @param num unique message number |
113 | * @param cont continuation to call after transmission | ||
114 | * @param cont_cls closure for @a cont | ||
110 | * @return #GNUNET_OK if message was queued, | 115 | * @return #GNUNET_OK if message was queued, |
111 | * #GNUNET_NO if peers are not connected | 116 | * #GNUNET_NO if peers are not connected |
112 | * #GNUNET_SYSERR if @a msize is illegal | 117 | * #GNUNET_SYSERR if @a msize is illegal |
@@ -116,7 +121,9 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
116 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 121 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
117 | uint16_t mtype, | 122 | uint16_t mtype, |
118 | uint16_t msize, | 123 | uint16_t msize, |
119 | uint32_t num) | 124 | uint32_t num, |
125 | GNUNET_SCHEDULER_TaskCallback cont, | ||
126 | void *cont_cls) | ||
120 | { | 127 | { |
121 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth; | 128 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth; |
122 | struct TRANSPORT_TESTING_SendJob *sj; | 129 | struct TRANSPORT_TESTING_SendJob *sj; |
@@ -147,6 +154,8 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
147 | sj->num = num; | 154 | sj->num = num; |
148 | sj->sender = sender; | 155 | sj->sender = sender; |
149 | sj->receiver = receiver; | 156 | sj->receiver = receiver; |
157 | sj->cont = cont; | ||
158 | sj->cont_cls = cont_cls; | ||
150 | sj->mtype = mtype; | 159 | sj->mtype = mtype; |
151 | sj->msize = msize; | 160 | sj->msize = msize; |
152 | GNUNET_CONTAINER_DLL_insert (tth->sj_head, | 161 | GNUNET_CONTAINER_DLL_insert (tth->sj_head, |
@@ -180,10 +189,15 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
180 | * | 189 | * |
181 | * @param ccc context which should contain at least two peers, the | 190 | * @param ccc context which should contain at least two peers, the |
182 | * first two of which should be currently connected | 191 | * first two of which should be currently connected |
192 | * @param size desired message size | ||
193 | * @param cont continuation to call after transmission | ||
194 | * @param cont_cls closure for @a cont | ||
183 | */ | 195 | */ |
184 | static void | 196 | static void |
185 | do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | 197 | do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, |
186 | uint16_t size) | 198 | uint16_t size, |
199 | GNUNET_SCHEDULER_TaskCallback cont, | ||
200 | void *cont_cls) | ||
187 | { | 201 | { |
188 | int ret; | 202 | int ret; |
189 | 203 | ||
@@ -192,7 +206,9 @@ do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | |||
192 | ccc->p[1], | 206 | ccc->p[1], |
193 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 207 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
194 | size, | 208 | size, |
195 | ccc->send_num_gen++); | 209 | ccc->send_num_gen++, |
210 | cont, | ||
211 | cont_cls); | ||
196 | GNUNET_assert (GNUNET_SYSERR != ret); | 212 | GNUNET_assert (GNUNET_SYSERR != ret); |
197 | if (GNUNET_NO == ret) | 213 | if (GNUNET_NO == ret) |
198 | { | 214 | { |
@@ -214,10 +230,28 @@ do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | |||
214 | void | 230 | void |
215 | GNUNET_TRANSPORT_TESTING_simple_send (void *cls) | 231 | GNUNET_TRANSPORT_TESTING_simple_send (void *cls) |
216 | { | 232 | { |
217 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 233 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; |
234 | int done; | ||
235 | size_t msize; | ||
218 | 236 | ||
219 | do_send (ccc, | 237 | if (0 < sc->num_messages) |
220 | sizeof (struct GNUNET_MessageHeader)); | 238 | { |
239 | sc->num_messages--; | ||
240 | done = (0 == sc->num_messages); | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | done = 0; /* infinite loop */ | ||
245 | } | ||
246 | msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage); | ||
247 | if (NULL != sc->get_size_cb) | ||
248 | msize = sc->get_size_cb (sc->num_messages); | ||
249 | /* if this was the last message, call the continuation, | ||
250 | otherwise call this function again */ | ||
251 | do_send (sc->ccc, | ||
252 | msize, | ||
253 | done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, | ||
254 | done ? sc->cont_cls : sc); | ||
221 | } | 255 | } |
222 | 256 | ||
223 | 257 | ||
@@ -232,10 +266,28 @@ GNUNET_TRANSPORT_TESTING_simple_send (void *cls) | |||
232 | void | 266 | void |
233 | GNUNET_TRANSPORT_TESTING_large_send (void *cls) | 267 | GNUNET_TRANSPORT_TESTING_large_send (void *cls) |
234 | { | 268 | { |
235 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | 269 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; |
270 | int done; | ||
271 | size_t msize; | ||
236 | 272 | ||
237 | do_send (ccc, | 273 | if (0 < sc->num_messages) |
238 | 2600); | 274 | { |
275 | sc->num_messages--; | ||
276 | done = (0 == sc->num_messages); | ||
277 | } | ||
278 | else | ||
279 | { | ||
280 | done = 0; /* infinite loop */ | ||
281 | } | ||
282 | msize = 2600; | ||
283 | if (NULL != sc->get_size_cb) | ||
284 | msize = sc->get_size_cb (sc->num_messages); | ||
285 | /* if this was the last message, call the continuation, | ||
286 | otherwise call this function again */ | ||
287 | do_send (sc->ccc, | ||
288 | msize, | ||
289 | done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, | ||
290 | done ? sc->cont_cls : sc); | ||
239 | } | 291 | } |
240 | 292 | ||
241 | /* end of transport-testing-send.c */ | 293 | /* end of transport-testing-send.c */ |