This file is part of GNUnet.
Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file transport/test_quota_compliance.c
/**
* Testcase timeout
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 480)
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
-
-#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 80)
static struct GNUNET_SCHEDULER_Task *measure_task;
-struct GNUNET_TRANSPORT_TransmitHandle *th;
-
static char *gen_cfgs[2];
static unsigned long long quota_in[] = { 10000, 10000 };
* 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
* messages may be dropped even for a reliable transport.
*/
-#define TOTAL_MSGS (1024 * 2)
-
-#define MTYPE 12345
-
-GNUNET_NETWORK_STRUCT_BEGIN
-struct TestMessage
-{
- struct GNUNET_MessageHeader header;
+#define TOTAL_MSGS (1024 * 32)
- uint32_t num GNUNET_PACKED;
-};
-GNUNET_NETWORK_STRUCT_END
-
-static int msg_scheduled;
-
-static int msg_sent;
-
-static unsigned long long total_bytes_sent;
+static unsigned long long total_bytes_recv;
static struct GNUNET_TIME_Absolute start_time;
unsigned long long datarate;
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
- datarate = (total_bytes_sent * 1000 * 1000) / delta;
+ if (0 == delta)
+ delta = 1;
+ datarate = (total_bytes_recv * 1000 * 1000) / delta;
FPRINTF (stderr,
"Throughput was %llu b/s\n",
datarate);
-
- if (datarate > quota_in[1])
+ ccc->global_ret = GNUNET_OK;
+ if (datarate > 1.5 * quota_in[1])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n",
+ "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n",
datarate,
quota_in[1]);
ccc->global_ret = GNUNET_SYSERR;
}
- if (datarate > quota_out[0])
+ if (datarate > 1.5 * quota_out[0])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n",
+ "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n",
datarate,
quota_out[0]);
ccc->global_ret = GNUNET_SYSERR;
GNUNET_SCHEDULER_cancel (measure_task);
measure_task = NULL;
}
- if (NULL != th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
report ();
}
-static unsigned int
+static size_t
get_size (unsigned int iter)
{
- unsigned int ret;
+ size_t ret;
- ret = (iter * iter * iter);
- return sizeof (struct TestMessage) + (ret % 60000);
+ ret = (iter * iter * iter) % 60000;
+ ret += sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
+ return ret;
}
notify_receive (void *cls,
struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
{
- const struct TestMessage *hdr;
- hdr = (const struct TestMessage *) message;
- if (MTYPE != ntohs (message->type))
+ if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
return;
+ total_bytes_recv += ntohs (hdr->header.size);
{
char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
receiver->no,
ps,
ntohl (hdr->num),
- ntohs (message->size),
+ ntohs (hdr->header.size),
GNUNET_i2s (sender));
GNUNET_free (ps);
}
}
-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 message %u of %u\n",
- msg_scheduled, TOTAL_MSGS);
- GNUNET_SCHEDULER_shutdown ();
- ccc->global_ret = GNUNET_SYSERR;
- return 0;
- }
-
- ret = 0;
- s = get_size (n);
- GNUNET_assert (size >= s);
- GNUNET_assert (buf != NULL);
- cbuf = buf;
- do
- {
- 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 (n % 5000 == 0)
- {
-#endif
- char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
- n, s,
- ccc->p[1]->no,
- GNUNET_i2s (&ccc->p[1]->id),
- ccc->p[0]->no,
- receiver_s);
- GNUNET_free (receiver_s);
-#if 0
- }
-#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);
- if (n < TOTAL_MSGS)
- {
- if (th == NULL)
- th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
- &ccc->p[0]->id,
- s,
- TIMEOUT_TRANSMIT,
- ¬ify_ready,
- NULL);
- msg_scheduled = n;
- }
- if (n % 5000 == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Returning total message block of size %u\n",
- ret);
- }
- total_bytes_sent += ret;
- if (n == TOTAL_MSGS)
- {
- FPRINTF (stderr, "%s", "\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All messages sent\n");
- }
- return ret;
-}
-
-
-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 (th != NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
- th = NULL;
- }
-}
-
-
-static void
-sendtask ()
-{
- start_time = GNUNET_TIME_absolute_get ();
- th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
- &ccc->p[0]->id,
- get_size (0),
- TIMEOUT_TRANSMIT,
- ¬ify_ready,
- NULL);
-}
-
-
static void
measure (void *cls)
{
static void
start_task (void *cls)
{
+ static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
+ .num_messages = TOTAL_MSGS,
+ .get_size_cb = &get_size
+ };
+
+ sc.ccc = ccc;
measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&measure,
NULL);
- GNUNET_SCHEDULER_add_now (&sendtask,
- NULL);
+ start_time = GNUNET_TIME_absolute_get ();
+ GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send,
+ &sc);
}
.config_file = "test_quota_compliance_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
};
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
if (GNUNET_OK !=
GNUNET_TRANSPORT_TESTING_main (2,
}
for (unsigned int i=0;i<2;i++)
{
- if ( (NULL != gen_cfgs[0]) &&
- (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[0])) )
+ if ( (NULL != gen_cfgs[i]) &&
+ (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[i])) )
{
- GNUNET_DISK_directory_remove (gen_cfgs[0]);
- GNUNET_free (gen_cfgs[0]);
+ GNUNET_DISK_directory_remove (gen_cfgs[i]);
+ GNUNET_free (gen_cfgs[i]);
}
}
return 0;