aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-15 21:41:11 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-15 21:41:11 +0000
commitd0fdba92b0c8c861d223312f19f9278ba63e7f98 (patch)
treeb3794d2fa0490917513c2faeeaf89d4b075ee23c /src/transport/test_transport_api.c
parent948b042072a8e50f36ad63a0f0c5b78c9140f59d (diff)
downloadgnunet-d0fdba92b0c8c861d223312f19f9278ba63e7f98.tar.gz
gnunet-d0fdba92b0c8c861d223312f19f9278ba63e7f98.zip
towards having sending in transport-testing API (not yet flexible enough)
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r--src/transport/test_transport_api.c117
1 files changed, 5 insertions, 112 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index bc0061363..4da4f2533 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -36,31 +36,8 @@
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, 5)
43
44#define TEST_MESSAGE_SIZE 2600
45
46#define TEST_MESSAGE_TYPE 12345
47
48
49static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 39static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
50 40
51static struct GNUNET_TRANSPORT_TransmitHandle *th;
52
53
54static void
55custom_shutdown (void *cls)
56{
57 if (NULL != th)
58 {
59 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
60 th = NULL;
61 }
62}
63
64 41
65static void 42static void
66notify_receive (void *cls, 43notify_receive (void *cls,
@@ -81,8 +58,8 @@ notify_receive (void *cls,
81 GNUNET_free (ps); 58 GNUNET_free (ps);
82 } 59 }
83 60
84 if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && 61 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) &&
85 (TEST_MESSAGE_SIZE == ntohs (message->size))) 62 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (message->size)))
86 { 63 {
87 ccc->global_ret = GNUNET_OK; 64 ccc->global_ret = GNUNET_OK;
88 GNUNET_SCHEDULER_shutdown (); 65 GNUNET_SCHEDULER_shutdown ();
@@ -96,90 +73,6 @@ notify_receive (void *cls,
96} 73}
97 74
98 75
99static size_t
100notify_ready (void *cls,
101 size_t size,
102 void *buf)
103{
104 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
105 struct GNUNET_MessageHeader *hdr;
106
107 th = NULL;
108 if (buf == NULL)
109 {
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
111 "Timeout occurred while waiting for transmit_ready\n");
112 GNUNET_SCHEDULER_shutdown ();
113 ccc->global_ret = 42;
114 return 0;
115 }
116
117 GNUNET_assert (size >= TEST_MESSAGE_SIZE);
118 if (NULL != buf)
119 {
120 memset (buf, '\0', TEST_MESSAGE_SIZE);
121 hdr = buf;
122 hdr->size = htons (TEST_MESSAGE_SIZE);
123 hdr->type = htons (TEST_MESSAGE_TYPE);
124 }
125
126 {
127 char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id));
128 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
129 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
130 ccc->p[1]->no,
131 ps,
132 ntohs (hdr->type),
133 ntohs (hdr->size),
134 p->no,
135 GNUNET_i2s (&p->id));
136 GNUNET_free (ps);
137 }
138 return TEST_MESSAGE_SIZE;
139}
140
141
142static void
143sendtask (void *cls)
144{
145 {
146 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
147
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
149 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
150 ccc->p[1]->no,
151 GNUNET_i2s (&ccc->p[1]->id),
152 ccc->p[0]->no,
153 receiver_s);
154 GNUNET_free (receiver_s);
155 }
156 ccc->global_ret = GNUNET_SYSERR;
157 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
158 &ccc->p[0]->id,
159 TEST_MESSAGE_SIZE,
160 TIMEOUT_TRANSMIT,
161 &notify_ready,
162 ccc->p[0]);
163 GNUNET_assert (NULL != th);
164}
165
166
167static void
168notify_disconnect (void *cls,
169 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
170 const struct GNUNET_PeerIdentity *other)
171{
172 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
173 me,
174 other);
175 if (NULL != th)
176 {
177 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
178 th = NULL;
179 }
180}
181
182
183/** 76/**
184 * Runs the test. 77 * Runs the test.
185 * 78 *
@@ -192,12 +85,12 @@ test (char *argv[],
192 int bi_directional) 85 int bi_directional)
193{ 86{
194 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 87 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
195 .connect_continuation = &sendtask, 88 .connect_continuation = &GNUNET_TRANSPORT_TESTING_large_send,
89 .connect_continuation_cls = &my_ccc,
196 .config_file = "test_transport_api_data.conf", 90 .config_file = "test_transport_api_data.conf",
197 .rec = &notify_receive, 91 .rec = &notify_receive,
198 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 92 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
199 .nd = &notify_disconnect, 93 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
200 .shutdown_task = &custom_shutdown,
201 .timeout = TIMEOUT, 94 .timeout = TIMEOUT,
202 .bi_directional = bi_directional 95 .bi_directional = bi_directional
203 }; 96 };