"Session %p/request %p: nothing to send, suspending\n",
s,
s->put.easyhandle);
- s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
- &client_put_disconnect, s);
+ s->put_disconnect_task
+ = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
+ &client_put_disconnect,
+ s);
s->put.state = H_PAUSED;
return CURL_READFUNC_PAUSE;
}
/* calculate how much fits in buffer */
len = GNUNET_MIN (msg->size - msg->pos,
size * nmemb);
- GNUNET_memcpy (stream, &msg->buf[msg->pos], len);
+ GNUNET_memcpy (stream,
+ &msg->buf[msg->pos],
+ len);
msg->pos += len;
if (msg->pos == msg->size)
{
test (char *argv[],
int bi_directional)
{
+ struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
+ .num_messages = 1
+ };
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
.connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send,
- .connect_continuation_cls = &my_ccc,
+ .connect_continuation_cls = &sc,
.config_file = "test_transport_api_data.conf",
.rec = ¬ify_receive,
.nc = &GNUNET_TRANSPORT_TESTING_log_connect,
};
ccc = &my_ccc;
+ sc.ccc = ccc;
if (GNUNET_OK !=
GNUNET_TRANSPORT_TESTING_main (2,
&GNUNET_TRANSPORT_TESTING_connect_check,
*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
-
-#define MTYPE 12345
-
#define MAX_FILES 50
#if HAVE_SETRLIMIT
-static struct GNUNET_TRANSPORT_TransmitHandle *th;
-
static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
"Received message of type %d from peer %s!\n",
ntohs (message->type),
GNUNET_i2s (sender));
- if ((MTYPE == ntohs (message->type)) &&
- (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
+ if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE ==
+ ntohs (message->type)) &&
+ (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) ==
+ ntohs (message->size)) )
{
ccc->global_ret = GNUNET_OK;
}
}
-static size_t
-notify_ready (void *cls, size_t size, void *buf)
-{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
- struct GNUNET_MessageHeader *hdr;
-
- th = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting message with %u bytes to peer %s\n",
- (unsigned int) sizeof (struct GNUNET_MessageHeader),
- GNUNET_i2s (&p->id));
- GNUNET_assert (size >= 256);
- if (buf != NULL)
- {
- hdr = buf;
- hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
- hdr->type = htons (MTYPE);
- }
- return sizeof (struct GNUNET_MessageHeader);
-}
-
-
-static void
-notify_disconnect (void *cls,
- struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
- const struct GNUNET_PeerIdentity *other)
-{
- GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
- me,
- other);
- if (NULL != th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
-}
-
-
-static void
-custom_shutdown (void *cls)
-{
- if (NULL != th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
-}
-
-
-static void
-sendtask (void *cls)
-{
- th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[0]->th,
- &ccc->p[1]->id,
- 256,
- TIMEOUT,
- ¬ify_ready,
- ccc->p[0]);
-}
-
-
int
main (int argc, char *argv[])
{
+ struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
+ .num_messages = 1
+ };
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
- .connect_continuation = &sendtask,
+ .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
+ .connect_continuation_cls = &sc,
.config_file = "test_transport_api_data.conf",
.rec = ¬ify_receive,
.nc = &GNUNET_TRANSPORT_TESTING_log_connect,
- .nd = ¬ify_disconnect,
- .shutdown_task = &custom_shutdown,
- .timeout = TIMEOUT
+ .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
+ .timeout = TIMEOUT,
+ .global_ret = GNUNET_SYSERR
};
struct rlimit r_file_old;
struct rlimit r_file_new;
int res;
-
+
+ sc.ccc = &my_ccc;
res = getrlimit (RLIMIT_NOFILE,
&r_file_old);
r_file_new.rlim_cur = MAX_FILES;
int
main (int argc, char *argv[])
{
- fprintf (stderr, "Cannot run test on this system\n");
- return 0;
+ fprintf (stderr,
+ "Cannot run test on this system\n");
+ return 77;
}
#endif
*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-
#define TEST_MESSAGE_SIZE 2600
-#define TEST_MESSAGE_TYPE 12345
-
static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
-static struct GNUNET_TRANSPORT_TransmitHandle *th;
-
-static struct GNUNET_SCHEDULER_Task *send_task;
-
static int messages_recv;
static struct GNUNET_TIME_Absolute start_normal;
static struct GNUNET_TIME_Relative dur_delayed;
+static size_t
+get_size (unsigned int cnt_down)
+{
+ return TEST_MESSAGE_SIZE;
+}
+
+
static void
-custom_shutdown (void *cls)
+sendtask (void *cls)
{
- if (NULL != th)
+ struct GNUNET_TIME_Relative delay;
+ struct GNUNET_ATS_Properties prop;
+ struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
+ .num_messages = 1,
+ .get_size_cb = &get_size,
+ .ccc = ccc
+ };
+
+ if (0 == messages_recv)
{
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
+ start_normal = GNUNET_TIME_absolute_get ();
}
- if (NULL != send_task)
+ if (1 == messages_recv)
{
- GNUNET_SCHEDULER_cancel (send_task);
- send_task = NULL;
+ memset (&prop, 0, sizeof (prop));
+ delay = GNUNET_TIME_UNIT_SECONDS;
+ GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th,
+ &ccc->p[0]->id,
+ &prop,
+ GNUNET_TIME_UNIT_ZERO,
+ delay);
+ prop.distance = 10;
+ GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th,
+ &ccc->p[1]->id,
+ &prop,
+ delay,
+ delay);
+ start_delayed = GNUNET_TIME_absolute_get();
}
+ GNUNET_TRANSPORT_TESTING_simple_send (&sc);
}
-static void
-sendtask (void *cls);
-
-
static void
notify_receive (void *cls,
struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
GNUNET_free (ps);
}
- if ((TEST_MESSAGE_TYPE == ntohs (message->type)) &&
- (TEST_MESSAGE_SIZE == ntohs (message->size)))
+ if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) &&
+ (TEST_MESSAGE_SIZE == ntohs (message->size)) )
{
if (GNUNET_NO == ccc->global_ret)
ccc->global_ret = GNUNET_OK;
messages_recv,
GNUNET_STRINGS_relative_time_to_string (dur_normal,
GNUNET_YES));
- send_task = GNUNET_SCHEDULER_add_now (&sendtask,
- NULL);
+ GNUNET_SCHEDULER_add_now (&sendtask,
+ NULL);
}
if (1 == messages_recv)
{
}
-static size_t
-notify_ready (void *cls, size_t size, void *buf)
-{
- struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
- struct GNUNET_MessageHeader *hdr;
-
- th = NULL;
- if (NULL == buf)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout occurred while waiting for transmit_ready\n");
- GNUNET_SCHEDULER_shutdown ();
- ccc->global_ret = 42;
- return 0;
- }
-
- GNUNET_assert (size >= TEST_MESSAGE_SIZE);
- memset (buf, '\0', TEST_MESSAGE_SIZE);
- hdr = buf;
- hdr->size = htons (TEST_MESSAGE_SIZE);
- hdr->type = htons (TEST_MESSAGE_TYPE);
-
- {
- char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n",
- ccc->p[1]->no,
- ps,
- ntohs (hdr->type),
- ntohs (hdr->size),
- p->no,
- GNUNET_i2s (&p->id));
- GNUNET_free (ps);
- }
-
- return TEST_MESSAGE_SIZE;
-}
-
-
-static void
-sendtask (void *cls)
-{
- struct GNUNET_TIME_Relative delay;
- struct GNUNET_ATS_Properties prop;
-
- if (NULL == send_task)
- ccc->global_ret = GNUNET_NO; /* first call! */
- send_task = NULL;
- {
- char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
- ccc->p[1]->no,
- GNUNET_i2s (&ccc->p[1]->id),
- ccc->p[0]->no,
- receiver_s);
- GNUNET_free (receiver_s);
- }
-
- if (0 == messages_recv)
- {
- start_normal = GNUNET_TIME_absolute_get ();
- }
- if (1 == messages_recv)
- {
- memset (&prop, 0, sizeof (prop));
- delay = GNUNET_TIME_UNIT_SECONDS;
- GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th,
- &ccc->p[0]->id,
- &prop,
- GNUNET_TIME_UNIT_ZERO,
- delay);
- prop.distance = 10;
- GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th,
- &ccc->p[1]->id,
- &prop,
- delay,
- delay);
- start_delayed = GNUNET_TIME_absolute_get();
- }
- th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
- &ccc->p[0]->id,
- TEST_MESSAGE_SIZE,
- TIMEOUT_TRANSMIT,
- ¬ify_ready,
- ccc->p[0]);
-}
-
-
-static void
-notify_disconnect (void *cls,
- struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
- const struct GNUNET_PeerIdentity *other)
-{
- GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
- me,
- other);
- if (NULL != th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
-}
-
-
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
.connect_continuation = &sendtask,
.config_file = "test_transport_api_data.conf",
.rec = ¬ify_receive,
.nc = &GNUNET_TRANSPORT_TESTING_log_connect,
- .nd = ¬ify_disconnect,
- .shutdown_task = &custom_shutdown,
- .timeout = TIMEOUT
+ .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
+ .timeout = TIMEOUT,
+ .global_ret = GNUNET_NO
};
ccc = &my_ccc;
*/
#define TOTAL_MSGS (1024 * 3 * FACTOR)
-/**
- * Message type of test messages
- */
-#define MTYPE 12345
-
/**
* Testcase timeout
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90 * FACTOR)
-
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60 * FACTOR)
-
-
-GNUNET_NETWORK_STRUCT_BEGIN
-
-/**
- * Struct for the test message
- */
-struct TestMessage
-{
- struct GNUNET_MessageHeader header;
- uint32_t num GNUNET_PACKED;
-};
-GNUNET_NETWORK_STRUCT_END
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR)
static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
-static struct GNUNET_TRANSPORT_TransmitHandle *th;
-
/**
* Total amount of bytes sent
*/
*/
static struct GNUNET_TIME_Absolute start_time;
-/**
- * No. of message currently scheduled to be send
- */
-static int msg_scheduled;
-
-/**
- * No. of last message sent
- */
-static int msg_sent;
-
/**
* No. of last message received
*/
-static int msg_recv;
+static unsigned int msg_recv;
/**
* Bitmap storing which messages were received
static char bitmap[TOTAL_MSGS / 8];
-static unsigned int
+/**
+ * Get the desired message size for message number @a iter.
+ */
+static size_t
get_size (unsigned int iter)
{
- unsigned int ret;
+ size_t ret;
ret = (iter * iter * iter);
-
#ifndef LINUX
/* FreeBSD/OSX etc. Unix DGRAMs do not work
* with large messages */
if (0 == strcmp ("unix", test_plugin))
- return sizeof (struct TestMessage) + (ret % 1024);
+ ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024);
#endif
- return sizeof (struct TestMessage) + (ret % 60000);
+ ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000);
+ return ret;
+}
+
+
+/**
+ * Implementation of the callback for obtaining the
+ * size of messages for transmission. Counts the total
+ * number of bytes sent as a side-effect.
+ *
+ * @param cnt_down count down from `TOTAL_MSGS - 1`
+ * @return message size of the message
+ */
+static size_t
+get_size_cnt (unsigned int cnt_down)
+{
+ size_t ret = get_size (TOTAL_MSGS - 1 - cnt_down);
+
+ total_bytes += ret;
+ return ret;
}
{
unsigned long long delta;
unsigned long long rate;
- unsigned int i;
int ok;
- if (NULL != th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
/* Calculcate statistics */
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
rate = (1000LL* 1000ll * total_bytes) / (1024 * delta);
rate);
{
char *value_name;
+
GNUNET_asprintf (&value_name,
"unreliable_%s",
ccc->test_plugin);
}
ok = 0;
- for (i = 0; i < TOTAL_MSGS; i++)
+ for (unsigned int i = 0; i < TOTAL_MSGS; i++)
{
if (get_bit (bitmap, i) == 0)
{
const struct GNUNET_MessageHeader *message)
{
static int n;
-
unsigned int s;
char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
- const struct TestMessage *hdr;
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
- hdr = (const struct TestMessage *) message;
+ hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
- if (MTYPE != ntohs (message->type))
+ if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
return;
msg_recv = ntohl (hdr->num);
s = get_size (ntohl (hdr->num));
return;
}
- memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage));
- if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
+ memset (cbuf,
+ ntohl (hdr->num),
+ s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage));
+ if (0 !=
+ memcmp (cbuf,
+ &hdr[1],
+ s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Expected message %u with bits %u, but body did not match\n",
ntohl (hdr->num),
- (unsigned char) n);
+ (unsigned char) ntohl (hdr->num));
ccc->global_ret = GNUNET_SYSERR;
GNUNET_SCHEDULER_shutdown ();
return;
}
#if VERBOSE
- if (ntohl (hdr->num) % 5 == 0)
+ if (0 == ntohl (hdr->num) % 5)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Got message %u of size %u\n",
if (n == TOTAL_MSGS)
{
/* end testcase with success */
+ ccc->global_ret = GNUNET_OK;
GNUNET_SCHEDULER_shutdown ();
}
}
-static size_t
-notify_ready (void *cls,
- size_t size,
- void *buf)
-{
- static int n;
- char *cbuf = buf;
- struct TestMessage hdr;
- unsigned int s;
- unsigned int ret;
-
- th = NULL;
- if (NULL == buf)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Timeout occurred while waiting for transmit_ready for msg %u of %u\n",
- msg_scheduled,
- TOTAL_MSGS);
- GNUNET_SCHEDULER_shutdown ();
- ccc->global_ret = 42;
- return 0;
- }
- ret = 0;
- s = get_size (n);
- GNUNET_assert (size >= s);
- GNUNET_assert (buf != NULL);
- GNUNET_assert (n < TOTAL_MSGS);
- cbuf = buf;
- do
- {
- GNUNET_assert (n < TOTAL_MSGS);
- hdr.header.size = htons (s);
- hdr.header.type = htons (MTYPE);
- hdr.num = htonl (n);
- msg_sent = n;
- GNUNET_memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
- ret += sizeof (struct TestMessage);
- memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
- ret += s - sizeof (struct TestMessage);
-
-#if VERBOSE
- if (0 == n % 5000)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u\n",
- n,
- s);
- }
-#endif
- n++;
- s = get_size (n);
- if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
- break; /* sometimes pack buffer full, sometimes not */
- }
- while ((size - ret >= s) && (n < TOTAL_MSGS));
- if (n < TOTAL_MSGS)
- {
- th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
- &ccc->p[0]->id,
- s,
- TIMEOUT_TRANSMIT,
- ¬ify_ready,
- NULL);
- msg_scheduled = n;
- }
- else
- {
- FPRINTF (stderr,
- "%s",
- "\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All messages scheduled to be sent\n");
- }
- if (0 == n % 5000)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
- }
- total_bytes += ret;
- return ret;
-}
-
-
-static void
-sendtask (void *cls)
-{
- start_time = GNUNET_TIME_absolute_get ();
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting to send %u messages\n",
- TOTAL_MSGS);
- th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
- &ccc->p[0]->id,
- get_size (0),
- TIMEOUT_TRANSMIT,
- ¬ify_ready,
- NULL);
-}
-
-
-static void
-notify_disconnect (void *cls,
- struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
- const struct GNUNET_PeerIdentity *other)
-{
- GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
- me,
- other);
- if (NULL != th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
-}
-
-
int
main (int argc, char *argv[])
{
+ struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
+ .num_messages = TOTAL_MSGS,
+ .get_size_cb = &get_size_cnt
+ };
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
- .connect_continuation = &sendtask,
+ .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
+ .connect_continuation_cls = &sc,
.config_file = "test_transport_api_data.conf",
.rec = ¬ify_receive,
.nc = &GNUNET_TRANSPORT_TESTING_log_connect,
- .nd = ¬ify_disconnect,
+ .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
.shutdown_task = &custom_shutdown,
- .timeout = TIMEOUT
+ .timeout = TIMEOUT,
+ .global_ret = GNUNET_SYSERR
};
ccc = &my_ccc;
+ sc.ccc = ccc;
+ start_time = GNUNET_TIME_absolute_get ();
if (GNUNET_OK !=
GNUNET_TRANSPORT_TESTING_main (2,
&GNUNET_TRANSPORT_TESTING_connect_check,
GNUNET_assert (size >= msize);
if (NULL != buf)
{
- memset (buf, '\0', msize);
+ memset (buf, sj->num, msize);
test = buf;
test->header.size = htons (msize);
test->header.type = htons (sj->mtype);
GNUNET_i2s (&receiver->id));
GNUNET_free (ps);
}
+ if (NULL != sj->cont)
+ GNUNET_SCHEDULER_add_now (sj->cont,
+ sj->cont_cls);
GNUNET_free (sj);
return msize;
}
* @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;
sj->num = num;
sj->sender = sender;
sj->receiver = receiver;
+ sj->cont = cont;
+ sj->cont_cls = cont_cls;
sj->mtype = mtype;
sj->msize = msize;
GNUNET_CONTAINER_DLL_insert (tth->sj_head,
*
* @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 */
*/
struct GNUNET_TRANSPORT_TransmitHandle *th;
+ /**
+ * Function to call upon completion.
+ */
+ GNUNET_SCHEDULER_TaskCallback cont;
+
+ /**
+ * Closure for @e cont.
+ */
+ void *cont_cls;
+
/**
* Number of the message.
*/
* @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);
/**
GNUNET_NETWORK_STRUCT_END
+/**
+ * Type of the closure argument to pass to
+ * #GNUNET_TRANSPORT_TESTING_simple_send() and
+ * #GNUNET_TRANSPORT_TESTING_large_send().
+ */
+struct GNUNET_TRANSPORT_TESTING_SendClosure
+{
+ /**
+ * Context for the transmission.
+ */
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
+
+ /**
+ * Function that returns the desired message size. Overrides
+ * the message size, can be NULL in which case the message
+ * size is the default.
+ */
+ size_t (*get_size_cb)(unsigned int n);
+
+ /**
+ * Number of messages to be transmitted in a loop.
+ * Use zero for "forever" (until external shutdown).
+ */
+ unsigned int num_messages;
+
+ /**
+ * Function to call after all transmissions, can be NULL.
+ */
+ GNUNET_SCHEDULER_TaskCallback cont;
+
+ /**
+ * Closure for @e cont.
+ */
+ void *cont_cls;
+
+};
+
+
/**
* Task that sends a minimalistic test message from the
* first peer to the second peer.
*
- * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
+ * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
* which should contain at least two peers, the first two
* of which should be currently connected
*/
* Task that sends a large test message from the
* first peer to the second peer.
*
- * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
+ * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
* which should contain at least two peers, the first two
* of which should be currently connected
*/