aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/plugin_transport_http_client.c10
-rw-r--r--src/transport/test_transport_api.c6
-rw-r--r--src/transport/test_transport_api_limited_sockets.c96
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c180
-rw-r--r--src/transport/test_transport_api_reliability.c230
-rw-r--r--src/transport/transport-testing-send.c72
-rw-r--r--src/transport/transport-testing.h58
7 files changed, 243 insertions, 409 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 4e0cde998..ceed94af8 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -1061,8 +1061,10 @@ client_send_cb (void *stream,
1061 "Session %p/request %p: nothing to send, suspending\n", 1061 "Session %p/request %p: nothing to send, suspending\n",
1062 s, 1062 s,
1063 s->put.easyhandle); 1063 s->put.easyhandle);
1064 s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, 1064 s->put_disconnect_task
1065 &client_put_disconnect, s); 1065 = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
1066 &client_put_disconnect,
1067 s);
1066 s->put.state = H_PAUSED; 1068 s->put.state = H_PAUSED;
1067 return CURL_READFUNC_PAUSE; 1069 return CURL_READFUNC_PAUSE;
1068 } 1070 }
@@ -1071,7 +1073,9 @@ client_send_cb (void *stream,
1071 /* calculate how much fits in buffer */ 1073 /* calculate how much fits in buffer */
1072 len = GNUNET_MIN (msg->size - msg->pos, 1074 len = GNUNET_MIN (msg->size - msg->pos,
1073 size * nmemb); 1075 size * nmemb);
1074 GNUNET_memcpy (stream, &msg->buf[msg->pos], len); 1076 GNUNET_memcpy (stream,
1077 &msg->buf[msg->pos],
1078 len);
1075 msg->pos += len; 1079 msg->pos += len;
1076 if (msg->pos == msg->size) 1080 if (msg->pos == msg->size)
1077 { 1081 {
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 4da4f2533..d4ae1cf53 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -84,9 +84,12 @@ static int
84test (char *argv[], 84test (char *argv[],
85 int bi_directional) 85 int bi_directional)
86{ 86{
87 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
88 .num_messages = 1
89 };
87 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 90 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
88 .connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send, 91 .connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send,
89 .connect_continuation_cls = &my_ccc, 92 .connect_continuation_cls = &sc,
90 .config_file = "test_transport_api_data.conf", 93 .config_file = "test_transport_api_data.conf",
91 .rec = &notify_receive, 94 .rec = &notify_receive,
92 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 95 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
@@ -96,6 +99,7 @@ test (char *argv[],
96 }; 99 };
97 100
98 ccc = &my_ccc; 101 ccc = &my_ccc;
102 sc.ccc = ccc;
99 if (GNUNET_OK != 103 if (GNUNET_OK !=
100 GNUNET_TRANSPORT_TESTING_main (2, 104 GNUNET_TRANSPORT_TESTING_main (2,
101 &GNUNET_TRANSPORT_TESTING_connect_check, 105 &GNUNET_TRANSPORT_TESTING_connect_check,
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c
index 25e8550c0..1b82ade70 100644
--- a/src/transport/test_transport_api_limited_sockets.c
+++ b/src/transport/test_transport_api_limited_sockets.c
@@ -35,20 +35,11 @@
35 */ 35 */
36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
37 37
38/**
39 * How long until we give up on transmitting the message?
40 */
41#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
42
43#define MTYPE 12345
44
45#define MAX_FILES 50 38#define MAX_FILES 50
46 39
47 40
48#if HAVE_SETRLIMIT 41#if HAVE_SETRLIMIT
49 42
50static struct GNUNET_TRANSPORT_TransmitHandle *th;
51
52static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 43static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
53 44
54 45
@@ -62,8 +53,10 @@ notify_receive (void *cls,
62 "Received message of type %d from peer %s!\n", 53 "Received message of type %d from peer %s!\n",
63 ntohs (message->type), 54 ntohs (message->type),
64 GNUNET_i2s (sender)); 55 GNUNET_i2s (sender));
65 if ((MTYPE == ntohs (message->type)) && 56 if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE ==
66 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 57 ntohs (message->type)) &&
58 (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) ==
59 ntohs (message->size)) )
67 { 60 {
68 ccc->global_ret = GNUNET_OK; 61 ccc->global_ret = GNUNET_OK;
69 } 62 }
@@ -75,83 +68,27 @@ notify_receive (void *cls,
75} 68}
76 69
77 70
78static size_t
79notify_ready (void *cls, size_t size, void *buf)
80{
81 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
82 struct GNUNET_MessageHeader *hdr;
83
84 th = NULL;
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Transmitting message with %u bytes to peer %s\n",
87 (unsigned int) sizeof (struct GNUNET_MessageHeader),
88 GNUNET_i2s (&p->id));
89 GNUNET_assert (size >= 256);
90 if (buf != NULL)
91 {
92 hdr = buf;
93 hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
94 hdr->type = htons (MTYPE);
95 }
96 return sizeof (struct GNUNET_MessageHeader);
97}
98
99
100static void
101notify_disconnect (void *cls,
102 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
103 const struct GNUNET_PeerIdentity *other)
104{
105 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
106 me,
107 other);
108 if (NULL != th)
109 {
110 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
111 th = NULL;
112 }
113}
114
115
116static void
117custom_shutdown (void *cls)
118{
119 if (NULL != th)
120 {
121 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
122 th = NULL;
123 }
124}
125
126
127static void
128sendtask (void *cls)
129{
130 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[0]->th,
131 &ccc->p[1]->id,
132 256,
133 TIMEOUT,
134 &notify_ready,
135 ccc->p[0]);
136}
137
138
139int 71int
140main (int argc, char *argv[]) 72main (int argc, char *argv[])
141{ 73{
74 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
75 .num_messages = 1
76 };
142 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 77 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
143 .connect_continuation = &sendtask, 78 .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
79 .connect_continuation_cls = &sc,
144 .config_file = "test_transport_api_data.conf", 80 .config_file = "test_transport_api_data.conf",
145 .rec = &notify_receive, 81 .rec = &notify_receive,
146 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 82 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
147 .nd = &notify_disconnect, 83 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
148 .shutdown_task = &custom_shutdown, 84 .timeout = TIMEOUT,
149 .timeout = TIMEOUT 85 .global_ret = GNUNET_SYSERR
150 }; 86 };
151 struct rlimit r_file_old; 87 struct rlimit r_file_old;
152 struct rlimit r_file_new; 88 struct rlimit r_file_new;
153 int res; 89 int res;
154 90
91 sc.ccc = &my_ccc;
155 res = getrlimit (RLIMIT_NOFILE, 92 res = getrlimit (RLIMIT_NOFILE,
156 &r_file_old); 93 &r_file_old);
157 r_file_new.rlim_cur = MAX_FILES; 94 r_file_new.rlim_cur = MAX_FILES;
@@ -183,8 +120,9 @@ main (int argc, char *argv[])
183int 120int
184main (int argc, char *argv[]) 121main (int argc, char *argv[])
185{ 122{
186 fprintf (stderr, "Cannot run test on this system\n"); 123 fprintf (stderr,
187 return 0; 124 "Cannot run test on this system\n");
125 return 77;
188} 126}
189 127
190#endif 128#endif
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c
index 902cac6c2..7e73f0b9c 100644
--- a/src/transport/test_transport_api_manipulation_send_tcp.c
+++ b/src/transport/test_transport_api_manipulation_send_tcp.c
@@ -36,22 +36,11 @@
36 */ 36 */
37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 38
39/**
40 * How long until we give up on transmitting the message?
41 */
42#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
43
44#define TEST_MESSAGE_SIZE 2600 39#define TEST_MESSAGE_SIZE 2600
45 40
46#define TEST_MESSAGE_TYPE 12345
47
48 41
49static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 42static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
50 43
51static struct GNUNET_TRANSPORT_TransmitHandle *th;
52
53static struct GNUNET_SCHEDULER_Task *send_task;
54
55static int messages_recv; 44static int messages_recv;
56 45
57static struct GNUNET_TIME_Absolute start_normal; 46static struct GNUNET_TIME_Absolute start_normal;
@@ -63,27 +52,50 @@ static struct GNUNET_TIME_Absolute start_delayed;
63static struct GNUNET_TIME_Relative dur_delayed; 52static struct GNUNET_TIME_Relative dur_delayed;
64 53
65 54
55static size_t
56get_size (unsigned int cnt_down)
57{
58 return TEST_MESSAGE_SIZE;
59}
60
61
66static void 62static void
67custom_shutdown (void *cls) 63sendtask (void *cls)
68{ 64{
69 if (NULL != th) 65 struct GNUNET_TIME_Relative delay;
66 struct GNUNET_ATS_Properties prop;
67 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
68 .num_messages = 1,
69 .get_size_cb = &get_size,
70 .ccc = ccc
71 };
72
73 if (0 == messages_recv)
70 { 74 {
71 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 75 start_normal = GNUNET_TIME_absolute_get ();
72 th = NULL;
73 } 76 }
74 if (NULL != send_task) 77 if (1 == messages_recv)
75 { 78 {
76 GNUNET_SCHEDULER_cancel (send_task); 79 memset (&prop, 0, sizeof (prop));
77 send_task = NULL; 80 delay = GNUNET_TIME_UNIT_SECONDS;
81 GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th,
82 &ccc->p[0]->id,
83 &prop,
84 GNUNET_TIME_UNIT_ZERO,
85 delay);
86 prop.distance = 10;
87 GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th,
88 &ccc->p[1]->id,
89 &prop,
90 delay,
91 delay);
92 start_delayed = GNUNET_TIME_absolute_get();
78 } 93 }
94 GNUNET_TRANSPORT_TESTING_simple_send (&sc);
79} 95}
80 96
81 97
82static void 98static void
83sendtask (void *cls);
84
85
86static void
87notify_receive (void *cls, 99notify_receive (void *cls,
88 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 100 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
89 const struct GNUNET_PeerIdentity *sender, 101 const struct GNUNET_PeerIdentity *sender,
@@ -102,8 +114,8 @@ notify_receive (void *cls,
102 GNUNET_free (ps); 114 GNUNET_free (ps);
103 } 115 }
104 116
105 if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && 117 if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) &&
106 (TEST_MESSAGE_SIZE == ntohs (message->size))) 118 (TEST_MESSAGE_SIZE == ntohs (message->size)) )
107 { 119 {
108 if (GNUNET_NO == ccc->global_ret) 120 if (GNUNET_NO == ccc->global_ret)
109 ccc->global_ret = GNUNET_OK; 121 ccc->global_ret = GNUNET_OK;
@@ -125,8 +137,8 @@ notify_receive (void *cls,
125 messages_recv, 137 messages_recv,
126 GNUNET_STRINGS_relative_time_to_string (dur_normal, 138 GNUNET_STRINGS_relative_time_to_string (dur_normal,
127 GNUNET_YES)); 139 GNUNET_YES));
128 send_task = GNUNET_SCHEDULER_add_now (&sendtask, 140 GNUNET_SCHEDULER_add_now (&sendtask,
129 NULL); 141 NULL);
130 } 142 }
131 if (1 == messages_recv) 143 if (1 == messages_recv)
132 { 144 {
@@ -152,124 +164,18 @@ notify_receive (void *cls,
152} 164}
153 165
154 166
155static size_t
156notify_ready (void *cls, size_t size, void *buf)
157{
158 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
159 struct GNUNET_MessageHeader *hdr;
160
161 th = NULL;
162 if (NULL == buf)
163 {
164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
165 "Timeout occurred while waiting for transmit_ready\n");
166 GNUNET_SCHEDULER_shutdown ();
167 ccc->global_ret = 42;
168 return 0;
169 }
170
171 GNUNET_assert (size >= TEST_MESSAGE_SIZE);
172 memset (buf, '\0', TEST_MESSAGE_SIZE);
173 hdr = buf;
174 hdr->size = htons (TEST_MESSAGE_SIZE);
175 hdr->type = htons (TEST_MESSAGE_TYPE);
176
177 {
178 char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
179
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
181 "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n",
182 ccc->p[1]->no,
183 ps,
184 ntohs (hdr->type),
185 ntohs (hdr->size),
186 p->no,
187 GNUNET_i2s (&p->id));
188 GNUNET_free (ps);
189 }
190
191 return TEST_MESSAGE_SIZE;
192}
193
194
195static void
196sendtask (void *cls)
197{
198 struct GNUNET_TIME_Relative delay;
199 struct GNUNET_ATS_Properties prop;
200
201 if (NULL == send_task)
202 ccc->global_ret = GNUNET_NO; /* first call! */
203 send_task = NULL;
204 {
205 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
206
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
209 ccc->p[1]->no,
210 GNUNET_i2s (&ccc->p[1]->id),
211 ccc->p[0]->no,
212 receiver_s);
213 GNUNET_free (receiver_s);
214 }
215
216 if (0 == messages_recv)
217 {
218 start_normal = GNUNET_TIME_absolute_get ();
219 }
220 if (1 == messages_recv)
221 {
222 memset (&prop, 0, sizeof (prop));
223 delay = GNUNET_TIME_UNIT_SECONDS;
224 GNUNET_TRANSPORT_set_traffic_metric (ccc->p[1]->th,
225 &ccc->p[0]->id,
226 &prop,
227 GNUNET_TIME_UNIT_ZERO,
228 delay);
229 prop.distance = 10;
230 GNUNET_TRANSPORT_set_traffic_metric (ccc->p[0]->th,
231 &ccc->p[1]->id,
232 &prop,
233 delay,
234 delay);
235 start_delayed = GNUNET_TIME_absolute_get();
236 }
237 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
238 &ccc->p[0]->id,
239 TEST_MESSAGE_SIZE,
240 TIMEOUT_TRANSMIT,
241 &notify_ready,
242 ccc->p[0]);
243}
244
245
246static void
247notify_disconnect (void *cls,
248 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
249 const struct GNUNET_PeerIdentity *other)
250{
251 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
252 me,
253 other);
254 if (NULL != th)
255 {
256 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
257 th = NULL;
258 }
259}
260
261
262int 167int
263main (int argc, char *argv[]) 168main (int argc,
169 char *argv[])
264{ 170{
265 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 171 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
266 .connect_continuation = &sendtask, 172 .connect_continuation = &sendtask,
267 .config_file = "test_transport_api_data.conf", 173 .config_file = "test_transport_api_data.conf",
268 .rec = &notify_receive, 174 .rec = &notify_receive,
269 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 175 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
270 .nd = &notify_disconnect, 176 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
271 .shutdown_task = &custom_shutdown, 177 .timeout = TIMEOUT,
272 .timeout = TIMEOUT 178 .global_ret = GNUNET_NO
273 }; 179 };
274 180
275 ccc = &my_ccc; 181 ccc = &my_ccc;
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index e1ce4da18..24ad4b81e 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -46,38 +46,13 @@
46#define TOTAL_MSGS (1024 * 3 * FACTOR) 46#define TOTAL_MSGS (1024 * 3 * FACTOR)
47 47
48/** 48/**
49 * Message type of test messages
50 */
51#define MTYPE 12345
52
53/**
54 * Testcase timeout 49 * Testcase timeout
55 */ 50 */
56#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90 * FACTOR) 51#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR)
57
58/**
59 * How long until we give up on transmitting the message?
60 */
61#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60 * FACTOR)
62
63
64GNUNET_NETWORK_STRUCT_BEGIN
65
66/**
67 * Struct for the test message
68 */
69struct TestMessage
70{
71 struct GNUNET_MessageHeader header;
72 uint32_t num GNUNET_PACKED;
73};
74GNUNET_NETWORK_STRUCT_END
75 52
76 53
77static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 54static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
78 55
79static struct GNUNET_TRANSPORT_TransmitHandle *th;
80
81/** 56/**
82 * Total amount of bytes sent 57 * Total amount of bytes sent
83 */ 58 */
@@ -89,19 +64,9 @@ static unsigned long long total_bytes;
89static struct GNUNET_TIME_Absolute start_time; 64static struct GNUNET_TIME_Absolute start_time;
90 65
91/** 66/**
92 * No. of message currently scheduled to be send
93 */
94static int msg_scheduled;
95
96/**
97 * No. of last message sent
98 */
99static int msg_sent;
100
101/**
102 * No. of last message received 67 * No. of last message received
103 */ 68 */
104static int msg_recv; 69static unsigned int msg_recv;
105 70
106/** 71/**
107 * Bitmap storing which messages were received 72 * Bitmap storing which messages were received
@@ -109,20 +74,41 @@ static int msg_recv;
109static char bitmap[TOTAL_MSGS / 8]; 74static char bitmap[TOTAL_MSGS / 8];
110 75
111 76
112static unsigned int 77/**
78 * Get the desired message size for message number @a iter.
79 */
80static size_t
113get_size (unsigned int iter) 81get_size (unsigned int iter)
114{ 82{
115 unsigned int ret; 83 size_t ret;
116 84
117 ret = (iter * iter * iter); 85 ret = (iter * iter * iter);
118
119#ifndef LINUX 86#ifndef LINUX
120 /* FreeBSD/OSX etc. Unix DGRAMs do not work 87 /* FreeBSD/OSX etc. Unix DGRAMs do not work
121 * with large messages */ 88 * with large messages */
122 if (0 == strcmp ("unix", test_plugin)) 89 if (0 == strcmp ("unix", test_plugin))
123 return sizeof (struct TestMessage) + (ret % 1024); 90 ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024);
124#endif 91#endif
125 return sizeof (struct TestMessage) + (ret % 60000); 92 ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000);
93 return ret;
94}
95
96
97/**
98 * Implementation of the callback for obtaining the
99 * size of messages for transmission. Counts the total
100 * number of bytes sent as a side-effect.
101 *
102 * @param cnt_down count down from `TOTAL_MSGS - 1`
103 * @return message size of the message
104 */
105static size_t
106get_size_cnt (unsigned int cnt_down)
107{
108 size_t ret = get_size (TOTAL_MSGS - 1 - cnt_down);
109
110 total_bytes += ret;
111 return ret;
126} 112}
127 113
128 114
@@ -181,14 +167,8 @@ custom_shutdown (void *cls)
181{ 167{
182 unsigned long long delta; 168 unsigned long long delta;
183 unsigned long long rate; 169 unsigned long long rate;
184 unsigned int i;
185 int ok; 170 int ok;
186 171
187 if (NULL != th)
188 {
189 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
190 th = NULL;
191 }
192 /* Calculcate statistics */ 172 /* Calculcate statistics */
193 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 173 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
194 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); 174 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta);
@@ -197,6 +177,7 @@ custom_shutdown (void *cls)
197 rate); 177 rate);
198 { 178 {
199 char *value_name; 179 char *value_name;
180
200 GNUNET_asprintf (&value_name, 181 GNUNET_asprintf (&value_name,
201 "unreliable_%s", 182 "unreliable_%s",
202 ccc->test_plugin); 183 ccc->test_plugin);
@@ -208,7 +189,7 @@ custom_shutdown (void *cls)
208 } 189 }
209 190
210 ok = 0; 191 ok = 0;
211 for (i = 0; i < TOTAL_MSGS; i++) 192 for (unsigned int i = 0; i < TOTAL_MSGS; i++)
212 { 193 {
213 if (get_bit (bitmap, i) == 0) 194 if (get_bit (bitmap, i) == 0)
214 { 195 {
@@ -230,14 +211,13 @@ notify_receive (void *cls,
230 const struct GNUNET_MessageHeader *message) 211 const struct GNUNET_MessageHeader *message)
231{ 212{
232 static int n; 213 static int n;
233
234 unsigned int s; 214 unsigned int s;
235 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 215 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
236 const struct TestMessage *hdr; 216 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
237 217
238 hdr = (const struct TestMessage *) message; 218 hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
239 219
240 if (MTYPE != ntohs (message->type)) 220 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
241 return; 221 return;
242 msg_recv = ntohl (hdr->num); 222 msg_recv = ntohl (hdr->num);
243 s = get_size (ntohl (hdr->num)); 223 s = get_size (ntohl (hdr->num));
@@ -255,19 +235,24 @@ notify_receive (void *cls,
255 return; 235 return;
256 } 236 }
257 237
258 memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); 238 memset (cbuf,
259 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) 239 ntohl (hdr->num),
240 s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage));
241 if (0 !=
242 memcmp (cbuf,
243 &hdr[1],
244 s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)))
260 { 245 {
261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
262 "Expected message %u with bits %u, but body did not match\n", 247 "Expected message %u with bits %u, but body did not match\n",
263 ntohl (hdr->num), 248 ntohl (hdr->num),
264 (unsigned char) n); 249 (unsigned char) ntohl (hdr->num));
265 ccc->global_ret = GNUNET_SYSERR; 250 ccc->global_ret = GNUNET_SYSERR;
266 GNUNET_SCHEDULER_shutdown (); 251 GNUNET_SCHEDULER_shutdown ();
267 return; 252 return;
268 } 253 }
269#if VERBOSE 254#if VERBOSE
270 if (ntohl (hdr->num) % 5 == 0) 255 if (0 == ntohl (hdr->num) % 5)
271 { 256 {
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Got message %u of size %u\n", 258 "Got message %u of size %u\n",
@@ -290,141 +275,34 @@ notify_receive (void *cls,
290 if (n == TOTAL_MSGS) 275 if (n == TOTAL_MSGS)
291 { 276 {
292 /* end testcase with success */ 277 /* end testcase with success */
278 ccc->global_ret = GNUNET_OK;
293 GNUNET_SCHEDULER_shutdown (); 279 GNUNET_SCHEDULER_shutdown ();
294 } 280 }
295} 281}
296 282
297 283
298static size_t
299notify_ready (void *cls,
300 size_t size,
301 void *buf)
302{
303 static int n;
304 char *cbuf = buf;
305 struct TestMessage hdr;
306 unsigned int s;
307 unsigned int ret;
308
309 th = NULL;
310 if (NULL == buf)
311 {
312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
313 "Timeout occurred while waiting for transmit_ready for msg %u of %u\n",
314 msg_scheduled,
315 TOTAL_MSGS);
316 GNUNET_SCHEDULER_shutdown ();
317 ccc->global_ret = 42;
318 return 0;
319 }
320 ret = 0;
321 s = get_size (n);
322 GNUNET_assert (size >= s);
323 GNUNET_assert (buf != NULL);
324 GNUNET_assert (n < TOTAL_MSGS);
325 cbuf = buf;
326 do
327 {
328 GNUNET_assert (n < TOTAL_MSGS);
329 hdr.header.size = htons (s);
330 hdr.header.type = htons (MTYPE);
331 hdr.num = htonl (n);
332 msg_sent = n;
333 GNUNET_memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
334 ret += sizeof (struct TestMessage);
335 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
336 ret += s - sizeof (struct TestMessage);
337
338#if VERBOSE
339 if (0 == n % 5000)
340 {
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
342 "Sending message %u of size %u\n",
343 n,
344 s);
345 }
346#endif
347 n++;
348 s = get_size (n);
349 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
350 break; /* sometimes pack buffer full, sometimes not */
351 }
352 while ((size - ret >= s) && (n < TOTAL_MSGS));
353 if (n < TOTAL_MSGS)
354 {
355 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
356 &ccc->p[0]->id,
357 s,
358 TIMEOUT_TRANSMIT,
359 &notify_ready,
360 NULL);
361 msg_scheduled = n;
362 }
363 else
364 {
365 FPRINTF (stderr,
366 "%s",
367 "\n");
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
369 "All messages scheduled to be sent\n");
370 }
371 if (0 == n % 5000)
372 {
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "Returning total message block of size %u\n",
375 ret);
376 }
377 total_bytes += ret;
378 return ret;
379}
380
381
382static void
383sendtask (void *cls)
384{
385 start_time = GNUNET_TIME_absolute_get ();
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
387 "Starting to send %u messages\n",
388 TOTAL_MSGS);
389 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
390 &ccc->p[0]->id,
391 get_size (0),
392 TIMEOUT_TRANSMIT,
393 &notify_ready,
394 NULL);
395}
396
397
398static void
399notify_disconnect (void *cls,
400 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
401 const struct GNUNET_PeerIdentity *other)
402{
403 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
404 me,
405 other);
406 if (NULL != th)
407 {
408 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
409 th = NULL;
410 }
411}
412
413
414int 284int
415main (int argc, char *argv[]) 285main (int argc, char *argv[])
416{ 286{
287 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
288 .num_messages = TOTAL_MSGS,
289 .get_size_cb = &get_size_cnt
290 };
417 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 291 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
418 .connect_continuation = &sendtask, 292 .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
293 .connect_continuation_cls = &sc,
419 .config_file = "test_transport_api_data.conf", 294 .config_file = "test_transport_api_data.conf",
420 .rec = &notify_receive, 295 .rec = &notify_receive,
421 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 296 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
422 .nd = &notify_disconnect, 297 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
423 .shutdown_task = &custom_shutdown, 298 .shutdown_task = &custom_shutdown,
424 .timeout = TIMEOUT 299 .timeout = TIMEOUT,
300 .global_ret = GNUNET_SYSERR
425 }; 301 };
426 302
427 ccc = &my_ccc; 303 ccc = &my_ccc;
304 sc.ccc = ccc;
305 start_time = GNUNET_TIME_absolute_get ();
428 if (GNUNET_OK != 306 if (GNUNET_OK !=
429 GNUNET_TRANSPORT_TESTING_main (2, 307 GNUNET_TRANSPORT_TESTING_main (2,
430 &GNUNET_TRANSPORT_TESTING_connect_check, 308 &GNUNET_TRANSPORT_TESTING_connect_check,
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 */
184static void 196static void
185do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 197do_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,
214void 230void
215GNUNET_TRANSPORT_TESTING_simple_send (void *cls) 231GNUNET_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)
232void 266void
233GNUNET_TRANSPORT_TESTING_large_send (void *cls) 267GNUNET_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 */
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 42daa4596..dc26950cb 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -256,6 +256,16 @@ struct TRANSPORT_TESTING_SendJob
256 struct GNUNET_TRANSPORT_TransmitHandle *th; 256 struct GNUNET_TRANSPORT_TransmitHandle *th;
257 257
258 /** 258 /**
259 * Function to call upon completion.
260 */
261 GNUNET_SCHEDULER_TaskCallback cont;
262
263 /**
264 * Closure for @e cont.
265 */
266 void *cont_cls;
267
268 /**
259 * Number of the message. 269 * Number of the message.
260 */ 270 */
261 uint32_t num; 271 uint32_t num;
@@ -774,6 +784,8 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
774 * @param mtype message type to use 784 * @param mtype message type to use
775 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)` 785 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)`
776 * @param num unique message number 786 * @param num unique message number
787 * @param cont continuation to call after transmission
788 * @param cont_cls closure for @a cont
777 * @return #GNUNET_OK if message was queued, 789 * @return #GNUNET_OK if message was queued,
778 * #GNUNET_NO if peers are not connected 790 * #GNUNET_NO if peers are not connected
779 * #GNUNET_SYSERR if @a msize is illegal 791 * #GNUNET_SYSERR if @a msize is illegal
@@ -783,7 +795,9 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
783 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 795 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
784 uint16_t mtype, 796 uint16_t mtype,
785 uint16_t msize, 797 uint16_t msize,
786 uint32_t num); 798 uint32_t num,
799 GNUNET_SCHEDULER_TaskCallback cont,
800 void *cont_cls);
787 801
788 802
789/** 803/**
@@ -808,10 +822,48 @@ GNUNET_NETWORK_STRUCT_END
808 822
809 823
810/** 824/**
825 * Type of the closure argument to pass to
826 * #GNUNET_TRANSPORT_TESTING_simple_send() and
827 * #GNUNET_TRANSPORT_TESTING_large_send().
828 */
829struct GNUNET_TRANSPORT_TESTING_SendClosure
830{
831 /**
832 * Context for the transmission.
833 */
834 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
835
836 /**
837 * Function that returns the desired message size. Overrides
838 * the message size, can be NULL in which case the message
839 * size is the default.
840 */
841 size_t (*get_size_cb)(unsigned int n);
842
843 /**
844 * Number of messages to be transmitted in a loop.
845 * Use zero for "forever" (until external shutdown).
846 */
847 unsigned int num_messages;
848
849 /**
850 * Function to call after all transmissions, can be NULL.
851 */
852 GNUNET_SCHEDULER_TaskCallback cont;
853
854 /**
855 * Closure for @e cont.
856 */
857 void *cont_cls;
858
859};
860
861
862/**
811 * Task that sends a minimalistic test message from the 863 * Task that sends a minimalistic test message from the
812 * first peer to the second peer. 864 * first peer to the second peer.
813 * 865 *
814 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 866 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
815 * which should contain at least two peers, the first two 867 * which should contain at least two peers, the first two
816 * of which should be currently connected 868 * of which should be currently connected
817 */ 869 */
@@ -829,7 +881,7 @@ GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
829 * Task that sends a large test message from the 881 * Task that sends a large test message from the
830 * first peer to the second peer. 882 * first peer to the second peer.
831 * 883 *
832 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 884 * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
833 * which should contain at least two peers, the first two 885 * which should contain at least two peers, the first two
834 * of which should be currently connected 886 * of which should be currently connected
835 */ 887 */