diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-05 11:51:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-05 11:51:32 +0000 |
commit | 0b8a02cc156081ad9a087ea91952a5cfc4270475 (patch) | |
tree | 1d7ea9dd11882d0d5d97c6fff8dbd7cfc8947a79 /src | |
parent | 904c393e01da94dc9e842b1c3050eea7ae96b4f0 (diff) | |
download | gnunet-0b8a02cc156081ad9a087ea91952a5cfc4270475.tar.gz gnunet-0b8a02cc156081ad9a087ea91952a5cfc4270475.zip |
update tests to use new MQ API
Diffstat (limited to 'src')
-rw-r--r-- | src/util/test_client.c | 2 | ||||
-rw-r--r-- | src/util/test_server.c | 130 | ||||
-rw-r--r-- | src/util/test_service.c | 90 | ||||
-rw-r--r-- | src/util/test_socks.c | 2 |
4 files changed, 96 insertions, 128 deletions
diff --git a/src/util/test_client.c b/src/util/test_client.c index 97fe10110..89adf41a3 100644 --- a/src/util/test_client.c +++ b/src/util/test_client.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009 GNUnet e.V. | 3 | Copyright (C) 2009, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
diff --git a/src/util/test_server.c b/src/util/test_server.c index 189c13e18..f82ecb2b1 100644 --- a/src/util/test_server.c +++ b/src/util/test_server.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2014 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2014, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -52,7 +52,7 @@ static struct GNUNET_SERVER_Handle *server; | |||
52 | /** | 52 | /** |
53 | * Handle for the client. | 53 | * Handle for the client. |
54 | */ | 54 | */ |
55 | static struct GNUNET_CLIENT_Connection *cc; | 55 | static struct GNUNET_MQ_Handle *mq; |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Handle of the server for the client. | 58 | * Handle of the server for the client. |
@@ -81,7 +81,7 @@ finish_up (void *cls) | |||
81 | GNUNET_assert (7 == ok); | 81 | GNUNET_assert (7 == ok); |
82 | ok = 0; | 82 | ok = 0; |
83 | GNUNET_SERVER_destroy (server); | 83 | GNUNET_SERVER_destroy (server); |
84 | GNUNET_CLIENT_disconnect (cc); | 84 | GNUNET_MQ_destroy (mq); |
85 | GNUNET_CONFIGURATION_destroy (cfg); | 85 | GNUNET_CONFIGURATION_destroy (cfg); |
86 | } | 86 | } |
87 | 87 | ||
@@ -106,32 +106,6 @@ recv_fin_cb (void *cls, | |||
106 | 106 | ||
107 | 107 | ||
108 | /** | 108 | /** |
109 | * The client connected to the server and is now allowed | ||
110 | * to send a second message. We send one. | ||
111 | * | ||
112 | * @param cls NULL | ||
113 | * @param size number of bytes that can be transmitted | ||
114 | * @param buf where to copy the message | ||
115 | * @return number of bytes copied to @a buf | ||
116 | */ | ||
117 | static size_t | ||
118 | transmit_second_message (void *cls, | ||
119 | size_t size, | ||
120 | void *buf) | ||
121 | { | ||
122 | struct GNUNET_MessageHeader msg; | ||
123 | |||
124 | GNUNET_assert (5 == ok); | ||
125 | ok = 6; | ||
126 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | ||
127 | msg.type = htons (MY_TYPE2); | ||
128 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
129 | memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); | ||
130 | return sizeof (struct GNUNET_MessageHeader); | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * We have received the reply from the server, check that we are at | 109 | * We have received the reply from the server, check that we are at |
136 | * the right stage and queue the next message to the server. Cleans | 110 | * the right stage and queue the next message to the server. Cleans |
137 | * up #argclient. | 111 | * up #argclient. |
@@ -140,18 +114,18 @@ transmit_second_message (void *cls, | |||
140 | * @param msg message we got from the server | 114 | * @param msg message we got from the server |
141 | */ | 115 | */ |
142 | static void | 116 | static void |
143 | first_reply_handler (void *cls, | 117 | handle_reply (void *cls, |
144 | const struct GNUNET_MessageHeader *msg) | 118 | const struct GNUNET_MessageHeader *msg) |
145 | { | 119 | { |
120 | struct GNUNET_MQ_Envelope *env; | ||
121 | struct GNUNET_MessageHeader *m; | ||
122 | |||
146 | GNUNET_assert (4 == ok); | 123 | GNUNET_assert (4 == ok); |
147 | ok = 5; | 124 | ok = 6; |
148 | GNUNET_assert (NULL != | 125 | env = GNUNET_MQ_msg (m, |
149 | GNUNET_CLIENT_notify_transmit_ready (cc, | 126 | MY_TYPE2); |
150 | sizeof (struct GNUNET_MessageHeader), | 127 | GNUNET_MQ_send (mq, |
151 | TIMEOUT, | 128 | env); |
152 | GNUNET_YES, | ||
153 | &transmit_second_message, | ||
154 | NULL)); | ||
155 | } | 129 | } |
156 | 130 | ||
157 | 131 | ||
@@ -210,41 +184,13 @@ recv_cb (void *cls, | |||
210 | GNUNET_assert (NULL != | 184 | GNUNET_assert (NULL != |
211 | GNUNET_SERVER_notify_transmit_ready (client, | 185 | GNUNET_SERVER_notify_transmit_ready (client, |
212 | ntohs (message->size), | 186 | ntohs (message->size), |
213 | TIMEOUT, &reply_msg, | 187 | TIMEOUT, |
188 | &reply_msg, | ||
214 | NULL)); | 189 | NULL)); |
215 | } | 190 | } |
216 | 191 | ||
217 | 192 | ||
218 | /** | 193 | /** |
219 | * The client connected to the server and is now allowed | ||
220 | * to send a first message. We transmit a simple message, | ||
221 | * ask for a second transmission and get ready to receive | ||
222 | * a response. | ||
223 | * | ||
224 | * @param cls NULL | ||
225 | * @param size number of bytes that can be transmitted | ||
226 | * @param buf where to copy the message | ||
227 | * @return number of bytes copied to @a buf | ||
228 | */ | ||
229 | static size_t | ||
230 | transmit_initial_message (void *cls, | ||
231 | size_t size, | ||
232 | void *buf) | ||
233 | { | ||
234 | struct GNUNET_MessageHeader msg; | ||
235 | |||
236 | GNUNET_assert (1 == ok); | ||
237 | ok = 2; | ||
238 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | ||
239 | msg.type = htons (MY_TYPE); | ||
240 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
241 | memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); | ||
242 | GNUNET_CLIENT_receive (cc, &first_reply_handler, NULL, TIMEOUT); | ||
243 | return sizeof (struct GNUNET_MessageHeader); | ||
244 | } | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Message handlers for the server. | 194 | * Message handlers for the server. |
249 | */ | 195 | */ |
250 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | 196 | static struct GNUNET_SERVER_MessageHandler handlers[] = { |
@@ -255,6 +201,22 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
255 | 201 | ||
256 | 202 | ||
257 | /** | 203 | /** |
204 | * Generic error handler, called with the appropriate error code and | ||
205 | * the same closure specified at the creation of the message queue. | ||
206 | * Not every message queue implementation supports an error handler. | ||
207 | * | ||
208 | * @param cls closure with the `struct GNUNET_STATISTICS_Handle *` | ||
209 | * @param error error code | ||
210 | */ | ||
211 | static void | ||
212 | mq_error_handler (void *cls, | ||
213 | enum GNUNET_MQ_Error error) | ||
214 | { | ||
215 | GNUNET_assert (0); /* should never happen */ | ||
216 | } | ||
217 | |||
218 | |||
219 | /** | ||
258 | * First task run by the scheduler. Initializes the server and | 220 | * First task run by the scheduler. Initializes the server and |
259 | * a client and asks for a transmission from the client to the | 221 | * a client and asks for a transmission from the client to the |
260 | * server. | 222 | * server. |
@@ -267,6 +229,16 @@ task (void *cls) | |||
267 | struct sockaddr_in sa; | 229 | struct sockaddr_in sa; |
268 | struct sockaddr *sap[2]; | 230 | struct sockaddr *sap[2]; |
269 | socklen_t slens[2]; | 231 | socklen_t slens[2]; |
232 | struct GNUNET_MQ_Envelope *env; | ||
233 | struct GNUNET_MessageHeader *msg; | ||
234 | GNUNET_MQ_hd_fixed_size (reply, | ||
235 | MY_TYPE, | ||
236 | struct GNUNET_MessageHeader); | ||
237 | struct GNUNET_MQ_MessageHandler chandlers[] = { | ||
238 | make_reply_handler (cls), | ||
239 | GNUNET_MQ_handler_end () | ||
240 | }; | ||
241 | |||
270 | 242 | ||
271 | sap[0] = (struct sockaddr *) &sa; | 243 | sap[0] = (struct sockaddr *) &sa; |
272 | slens[0] = sizeof (sa); | 244 | slens[0] = sizeof (sa); |
@@ -296,15 +268,17 @@ task (void *cls) | |||
296 | "resolver", | 268 | "resolver", |
297 | "HOSTNAME", | 269 | "HOSTNAME", |
298 | "localhost"); | 270 | "localhost"); |
299 | cc = GNUNET_CLIENT_connect ("test-server", cfg); | 271 | mq = GNUNET_CLIENT_connecT (cfg, |
300 | GNUNET_assert (cc != NULL); | 272 | "test-server", |
301 | GNUNET_assert (NULL != | 273 | chandlers, |
302 | GNUNET_CLIENT_notify_transmit_ready (cc, | 274 | &mq_error_handler, |
303 | sizeof (struct | 275 | NULL); |
304 | GNUNET_MessageHeader), | 276 | GNUNET_assert (NULL != mq); |
305 | TIMEOUT, GNUNET_YES, | 277 | ok = 2; |
306 | &transmit_initial_message, | 278 | env = GNUNET_MQ_msg (msg, |
307 | NULL)); | 279 | MY_TYPE); |
280 | GNUNET_MQ_send (mq, | ||
281 | env); | ||
308 | } | 282 | } |
309 | 283 | ||
310 | 284 | ||
diff --git a/src/util/test_service.c b/src/util/test_service.c index f340b724d..707f8658b 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2013 GNUnet e.V. | 3 | Copyright (C) 2009, 2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -37,16 +37,16 @@ static struct GNUNET_SERVICE_Context *sctx; | |||
37 | 37 | ||
38 | static int ok = 1; | 38 | static int ok = 1; |
39 | 39 | ||
40 | static struct GNUNET_CLIENT_Connection *client; | 40 | static struct GNUNET_MQ_Handle *mq; |
41 | 41 | ||
42 | 42 | ||
43 | static void | 43 | static void |
44 | do_stop (void *cls) | 44 | do_stop (void *cls) |
45 | { | 45 | { |
46 | if (NULL != client) | 46 | if (NULL != mq) |
47 | { | 47 | { |
48 | GNUNET_CLIENT_disconnect (client); | 48 | GNUNET_MQ_destroy (mq); |
49 | client = NULL; | 49 | mq = NULL; |
50 | } | 50 | } |
51 | if (NULL != sctx) | 51 | if (NULL != sctx) |
52 | { | 52 | { |
@@ -60,49 +60,33 @@ do_stop (void *cls) | |||
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | static size_t | ||
64 | build_msg (void *cls, size_t size, void *buf) | ||
65 | { | ||
66 | struct GNUNET_MessageHeader *msg = buf; | ||
67 | |||
68 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
69 | { | ||
70 | /* timeout */ | ||
71 | GNUNET_break (0); | ||
72 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | ||
73 | ok = 1; | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected, transmitting\n"); | ||
78 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | ||
79 | msg->type = htons (MY_TYPE); | ||
80 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
81 | return sizeof (struct GNUNET_MessageHeader); | ||
82 | } | ||
83 | |||
84 | |||
85 | static void | 63 | static void |
86 | ready (void *cls, | 64 | ready (void *cls, |
87 | int result) | 65 | int result) |
88 | { | 66 | { |
89 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 67 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
68 | struct GNUNET_MQ_Envelope *env; | ||
69 | struct GNUNET_MessageHeader *msg; | ||
90 | 70 | ||
91 | GNUNET_assert (GNUNET_YES == result); | 71 | GNUNET_assert (GNUNET_YES == result); |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); | ||
93 | client = GNUNET_CLIENT_connect ("test_service", cfg); | ||
94 | GNUNET_assert (client != NULL); | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 72 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
96 | "Client connecting, waiting to transmit\n"); | 73 | "Service confirmed running\n"); |
97 | GNUNET_CLIENT_notify_transmit_ready (client, | 74 | mq = GNUNET_CLIENT_connecT (cfg, |
98 | sizeof (struct GNUNET_MessageHeader), | 75 | "test_service", |
99 | GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, | 76 | NULL, |
100 | &build_msg, NULL); | 77 | NULL, |
78 | NULL); | ||
79 | GNUNET_assert (NULL != mq); | ||
80 | env = GNUNET_MQ_msg (msg, | ||
81 | MY_TYPE); | ||
82 | GNUNET_MQ_send (mq, | ||
83 | env); | ||
101 | } | 84 | } |
102 | 85 | ||
103 | 86 | ||
104 | static void | 87 | static void |
105 | recv_cb (void *cls, struct GNUNET_SERVER_Client *sc, | 88 | recv_cb (void *cls, |
89 | struct GNUNET_SERVER_Client *sc, | ||
106 | const struct GNUNET_MessageHeader *message) | 90 | const struct GNUNET_MessageHeader *message) |
107 | { | 91 | { |
108 | GNUNET_assert (NULL != message); | 92 | GNUNET_assert (NULL != message); |
@@ -120,11 +104,14 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = { | |||
120 | 104 | ||
121 | 105 | ||
122 | static void | 106 | static void |
123 | runner (void *cls, struct GNUNET_SERVER_Handle *server, | 107 | runner (void *cls, |
108 | struct GNUNET_SERVER_Handle *server, | ||
124 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 109 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
125 | { | 110 | { |
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n"); | 111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
127 | GNUNET_SERVER_add_handlers (server, myhandlers); | 112 | "Service initializing\n"); |
113 | GNUNET_SERVER_add_handlers (server, | ||
114 | myhandlers); | ||
128 | GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS, | 115 | GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS, |
129 | &ready, (void *) cfg); | 116 | &ready, (void *) cfg); |
130 | } | 117 | } |
@@ -158,21 +145,28 @@ ready6 (void *cls, | |||
158 | int result) | 145 | int result) |
159 | { | 146 | { |
160 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 147 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
148 | struct GNUNET_MQ_Envelope *env; | ||
149 | struct GNUNET_MessageHeader *msg; | ||
161 | 150 | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n"); | ||
163 | GNUNET_assert (GNUNET_YES == result); | 151 | GNUNET_assert (GNUNET_YES == result); |
164 | client = GNUNET_CLIENT_connect ("test_service6", cfg); | 152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
165 | GNUNET_assert (client != NULL); | 153 | "V6 ready\n"); |
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); | 154 | mq = GNUNET_CLIENT_connecT (cfg, |
167 | GNUNET_CLIENT_notify_transmit_ready (client, | 155 | "test_service6", |
168 | sizeof (struct GNUNET_MessageHeader), | 156 | NULL, |
169 | GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, | 157 | NULL, |
170 | &build_msg, NULL); | 158 | NULL); |
159 | GNUNET_assert (NULL != mq); | ||
160 | env = GNUNET_MQ_msg (msg, | ||
161 | MY_TYPE); | ||
162 | GNUNET_MQ_send (mq, | ||
163 | env); | ||
171 | } | 164 | } |
172 | 165 | ||
173 | 166 | ||
174 | static void | 167 | static void |
175 | runner6 (void *cls, struct GNUNET_SERVER_Handle *server, | 168 | runner6 (void *cls, |
169 | struct GNUNET_SERVER_Handle *server, | ||
176 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
177 | { | 171 | { |
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/util/test_socks.c b/src/util/test_socks.c index d63cce571..4b86d25dc 100644 --- a/src/util/test_socks.c +++ b/src/util/test_socks.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2015 GNUnet e.V. | 3 | Copyright (C) 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |