/**
* Acceptable transmission delay.
*/
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
-
-
-static size_t
-notify_ready (void *cls,
- size_t size,
- void *buf)
-{
- struct TRANSPORT_TESTING_SendJob *sj = cls;
- struct GNUNET_TRANSPORT_TESTING_PeerContext *sender = sj->sender;
- struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver = sj->receiver;
- struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth;
- uint16_t msize = sj->msize;
- struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
-
- sj->th = NULL;
- GNUNET_CONTAINER_DLL_remove (tth->sj_head,
- tth->sj_tail,
- sj);
- if (NULL == buf)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout occurred while waiting for transmit_ready\n");
- GNUNET_SCHEDULER_shutdown ();
- GNUNET_free (sj);
- return 0;
- }
-
- GNUNET_assert (size >= msize);
- if (NULL != buf)
- {
- memset (buf, '\0', msize);
- test = buf;
- test->header.size = htons (msize);
- test->header.type = htons (sj->mtype);
- test->num = htonl (sj->num);
- }
-
- {
- char *ps = GNUNET_strdup (GNUNET_i2s (&sender->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sending message %u from %u (%s) with type %u and size %u bytes to peer %u (%s)\n",
- (unsigned int) sj->num,
- sender->no,
- ps,
- sj->mtype,
- msize,
- receiver->no,
- GNUNET_i2s (&receiver->id));
- GNUNET_free (ps);
- }
- GNUNET_free (sj);
- return msize;
-}
+#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
{
struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
+ if (GNUNET_NO == cx->connected)
+ return;
*cr = cx;
}
* @param mtype message type to use
* @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)`
* @param num unique message number
+ * @param cont continuation to call after transmission
+ * @param cont_cls closure for @a cont
* @return #GNUNET_OK if message was queued,
* #GNUNET_NO if peers are not connected
* #GNUNET_SYSERR if @a msize is illegal
struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
uint16_t mtype,
uint16_t msize,
- uint32_t num)
+ uint32_t num,
+ GNUNET_SCHEDULER_TaskCallback cont,
+ void *cont_cls)
{
- struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth;
- struct TRANSPORT_TESTING_SendJob *sj;
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
-
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
+
if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))
{
GNUNET_break (0);
sender,
&find_cr,
&cr);
- if ( (NULL == cr) ||
- (GNUNET_YES != cr->connected) )
+ if (NULL == cr)
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ if (NULL == cr->mq)
{
GNUNET_break (0);
return GNUNET_NO;
}
- sj = GNUNET_new (struct TRANSPORT_TESTING_SendJob);
- sj->num = num;
- sj->sender = sender;
- sj->receiver = receiver;
- sj->mtype = mtype;
- sj->msize = msize;
- GNUNET_CONTAINER_DLL_insert (tth->sj_head,
- tth->sj_tail,
- sj);
{
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
receiver_s);
GNUNET_free (receiver_s);
}
- sj->th = GNUNET_TRANSPORT_notify_transmit_ready (sender->th,
- &receiver->id,
- msize,
- TIMEOUT_TRANSMIT,
- ¬ify_ready,
- sj);
- GNUNET_assert (NULL != sj->th);
+ env = GNUNET_MQ_msg_extra (test,
+ msize - sizeof (*test),
+ mtype);
+ test->num = htonl (num);
+ memset (&test[1],
+ num,
+ msize - sizeof (*test));
+ GNUNET_MQ_notify_sent (env,
+ cont,
+ cont_cls);
+ GNUNET_MQ_send (cr->mq,
+ env);
return GNUNET_OK;
}
*
* @param ccc context which should contain at least two peers, the
* first two of which should be currently connected
+ * @param size desired message size
+ * @param cont continuation to call after transmission
+ * @param cont_cls closure for @a cont
*/
static void
do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
- uint16_t size)
+ uint16_t size,
+ GNUNET_SCHEDULER_TaskCallback cont,
+ void *cont_cls)
{
int ret;
ccc->p[1],
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
size,
- ccc->send_num_gen++);
+ ccc->send_num_gen++,
+ cont,
+ cont_cls);
GNUNET_assert (GNUNET_SYSERR != ret);
if (GNUNET_NO == ret)
{
void
GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
{
- struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
+ struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
+ int done;
+ size_t msize;
- do_send (ccc,
- sizeof (struct GNUNET_MessageHeader));
+ if (0 < sc->num_messages)
+ {
+ sc->num_messages--;
+ done = (0 == sc->num_messages);
+ }
+ else
+ {
+ done = 0; /* infinite loop */
+ }
+ msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
+ if (NULL != sc->get_size_cb)
+ msize = sc->get_size_cb (sc->num_messages);
+ /* if this was the last message, call the continuation,
+ otherwise call this function again */
+ do_send (sc->ccc,
+ msize,
+ done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
+ done ? sc->cont_cls : sc);
}
void
GNUNET_TRANSPORT_TESTING_large_send (void *cls)
{
- struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
+ struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
+ int done;
+ size_t msize;
- do_send (ccc,
- 2600);
+ if (0 < sc->num_messages)
+ {
+ sc->num_messages--;
+ done = (0 == sc->num_messages);
+ }
+ else
+ {
+ done = 0; /* infinite loop */
+ }
+ msize = 2600;
+ if (NULL != sc->get_size_cb)
+ msize = sc->get_size_cb (sc->num_messages);
+ /* if this was the last message, call the continuation,
+ otherwise call this function again */
+ do_send (sc->ccc,
+ msize,
+ done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
+ done ? sc->cont_cls : sc);
}
/* end of transport-testing-send.c */