diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-09-19 08:40:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-09-19 08:40:49 +0000 |
commit | 08f1726b6552ac29830637e9f7be4d42e2ea4294 (patch) | |
tree | 093a456dd05228fa3c592285085aae25eaba1164 /src | |
parent | 9f649cbc9454317228c4a4d3580de3a8f8f008a8 (diff) | |
download | gnunet-08f1726b6552ac29830637e9f7be4d42e2ea4294.tar.gz gnunet-08f1726b6552ac29830637e9f7be4d42e2ea4294.zip |
-modifying tests to use new service MQ API, implementing more of service MQ API
Diffstat (limited to 'src')
-rw-r--r-- | src/util/Makefile.am | 20 | ||||
-rw-r--r-- | src/util/service_new.c | 102 | ||||
-rw-r--r-- | src/util/test_client.c | 210 | ||||
-rw-r--r-- | src/util/test_client_data.conf | 3 | ||||
-rw-r--r-- | src/util/test_client_unix.conf | 6 | ||||
-rw-r--r-- | src/util/test_mq_client.c | 182 | ||||
-rw-r--r-- | src/util/test_service_data.conf | 1 |
7 files changed, 215 insertions, 309 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index b7e60022f..0172df67f 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -265,6 +265,7 @@ endif | |||
265 | check_PROGRAMS = \ | 265 | check_PROGRAMS = \ |
266 | test_bio \ | 266 | test_bio \ |
267 | test_client.nc \ | 267 | test_client.nc \ |
268 | test_client_unix.nc \ | ||
268 | $(SSH_USING_TESTS) \ | 269 | $(SSH_USING_TESTS) \ |
269 | test_common_allocation \ | 270 | test_common_allocation \ |
270 | test_common_endian \ | 271 | test_common_endian \ |
@@ -299,7 +300,6 @@ check_PROGRAMS = \ | |||
299 | test_connection_timeout_no_connect.nc \ | 300 | test_connection_timeout_no_connect.nc \ |
300 | test_connection_transmit_cancel.nc \ | 301 | test_connection_transmit_cancel.nc \ |
301 | test_mq \ | 302 | test_mq \ |
302 | test_mq_client.nc \ | ||
303 | test_os_network \ | 303 | test_os_network \ |
304 | test_peer \ | 304 | test_peer \ |
305 | test_plugin \ | 305 | test_plugin \ |
@@ -325,18 +325,18 @@ check_PROGRAMS = \ | |||
325 | # Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart | 325 | # Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart |
326 | # sequential execution order for them | 326 | # sequential execution order for them |
327 | TEST_EXTENSIONS = .nc | 327 | TEST_EXTENSIONS = .nc |
328 | test_connection.log: test_client.log | 328 | test_connection.log: test_client.log |
329 | test_connection_addressing.log: test_connection.log | 329 | test_connection_addressing.log: test_connection.log |
330 | test_connection_timeout_no_connect.log: test_connection_addressing.log | 330 | test_connection_timeout_no_connect.log: test_connection_addressing.log |
331 | test_connection_transmit_cancel.log: test_connection_timeout_no_connect.log | 331 | test_connection_transmit_cancel.log: test_connection_timeout_no_connect.log |
332 | test_connection_receive_cancel.log: test_connection_transmit_cancel.log | 332 | test_connection_receive_cancel.log: test_connection_transmit_cancel.log |
333 | test_connection_timeout.log: test_connection_receive_cancel.log | 333 | test_connection_timeout.log: test_connection_receive_cancel.log |
334 | test_mq_client.log: test_connection_timeout.log | 334 | test_resolver_api.log: test_connection_timeout.log |
335 | test_resolver_api.log: test_mq_client.log | ||
336 | test_server.log: test_resolver_api.log | 335 | test_server.log: test_resolver_api.log |
337 | test_server_disconnect.log: test_server.log | 336 | test_server_disconnect.log: test_server.log |
338 | test_server_with_client.log: test_server_disconnect.log | 337 | test_server_with_client.log: test_server_disconnect.log |
339 | test_server_mst_interrupt.log: test_server_with_client.log | 338 | test_server_mst_interrupt.log: test_server_with_client.log |
339 | test_client_unix.log: test_server_mst_interrupt.log | ||
340 | 340 | ||
341 | test_bio_SOURCES = \ | 341 | test_bio_SOURCES = \ |
342 | test_bio.c | 342 | test_bio.c |
@@ -357,6 +357,11 @@ test_client_nc_SOURCES = \ | |||
357 | test_client_nc_LDADD = \ | 357 | test_client_nc_LDADD = \ |
358 | libgnunetutil.la | 358 | libgnunetutil.la |
359 | 359 | ||
360 | test_client_unix_nc_SOURCES = \ | ||
361 | test_client.c | ||
362 | test_client_unix_nc_LDADD = \ | ||
363 | libgnunetutil.la | ||
364 | |||
360 | test_socks_nc_SOURCES = \ | 365 | test_socks_nc_SOURCES = \ |
361 | test_socks.c | 366 | test_socks.c |
362 | test_socks_nc_LDADD = \ | 367 | test_socks_nc_LDADD = \ |
@@ -538,11 +543,6 @@ test_mq_SOURCES = \ | |||
538 | test_mq_LDADD = \ | 543 | test_mq_LDADD = \ |
539 | libgnunetutil.la | 544 | libgnunetutil.la |
540 | 545 | ||
541 | test_mq_client_nc_SOURCES = \ | ||
542 | test_mq_client.c | ||
543 | test_mq_client_nc_LDADD = \ | ||
544 | libgnunetutil.la | ||
545 | |||
546 | test_os_network_SOURCES = \ | 546 | test_os_network_SOURCES = \ |
547 | test_os_network.c | 547 | test_os_network.c |
548 | test_os_network_LDADD = \ | 548 | test_os_network_LDADD = \ |
@@ -670,6 +670,8 @@ perf_malloc_LDADD = \ | |||
670 | 670 | ||
671 | 671 | ||
672 | EXTRA_DIST = \ | 672 | EXTRA_DIST = \ |
673 | test_client_data.conf \ | ||
674 | test_client_unix.conf \ | ||
673 | test_configuration_data.conf \ | 675 | test_configuration_data.conf \ |
674 | test_program_data.conf \ | 676 | test_program_data.conf \ |
675 | test_resolver_api_data.conf \ | 677 | test_resolver_api_data.conf \ |
diff --git a/src/util/service_new.c b/src/util/service_new.c index d6eda3250..fe8e79f17 100644 --- a/src/util/service_new.c +++ b/src/util/service_new.c | |||
@@ -266,6 +266,11 @@ struct GNUNET_SERVICE_Client | |||
266 | struct GNUNET_SCHEDULER_Task *send_task; | 266 | struct GNUNET_SCHEDULER_Task *send_task; |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * Pointer to the message to be transmitted by @e send_task. | ||
270 | */ | ||
271 | const struct GNUNET_MessageHeader *msg; | ||
272 | |||
273 | /** | ||
269 | * User context value, value returned from | 274 | * User context value, value returned from |
270 | * the connect callback. | 275 | * the connect callback. |
271 | */ | 276 | */ |
@@ -276,6 +281,11 @@ struct GNUNET_SERVICE_Client | |||
276 | * to the application. | 281 | * to the application. |
277 | */ | 282 | */ |
278 | struct GNUNET_TIME_Absolute warn_start; | 283 | struct GNUNET_TIME_Absolute warn_start; |
284 | |||
285 | /** | ||
286 | * Current position in @e msg at which we are transmitting. | ||
287 | */ | ||
288 | size_t msg_pos; | ||
279 | 289 | ||
280 | /** | 290 | /** |
281 | * Persist the file handle for this client no matter what happens, | 291 | * Persist the file handle for this client no matter what happens, |
@@ -1776,24 +1786,86 @@ GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh) | |||
1776 | 1786 | ||
1777 | 1787 | ||
1778 | /** | 1788 | /** |
1789 | * Task run when we are ready to transmit data to the | ||
1790 | * client. | ||
1791 | * | ||
1792 | * @param cls the `struct GNUNET_SERVICE_Client *` to send to | ||
1793 | */ | ||
1794 | static void | ||
1795 | do_send (void *cls) | ||
1796 | { | ||
1797 | struct GNUNET_SERVICE_Client *client = cls; | ||
1798 | ssize_t ret; | ||
1799 | size_t left; | ||
1800 | const char *buf; | ||
1801 | |||
1802 | client->send_task = NULL; | ||
1803 | buf = (const char *) client->msg; | ||
1804 | left = ntohs (client->msg->size) - client->msg_pos; | ||
1805 | ret = GNUNET_NETWORK_socket_send (client->sock, | ||
1806 | &buf[client->msg_pos], | ||
1807 | left); | ||
1808 | GNUNET_assert (ret <= (ssize_t) left); | ||
1809 | if (0 == ret) | ||
1810 | { | ||
1811 | GNUNET_MQ_inject_error (client->mq, | ||
1812 | GNUNET_MQ_ERROR_WRITE); | ||
1813 | return; | ||
1814 | } | ||
1815 | if (-1 == ret) | ||
1816 | { | ||
1817 | if ( (EAGAIN == errno) || | ||
1818 | (EINTR == errno) ) | ||
1819 | { | ||
1820 | /* ignore */ | ||
1821 | ret = 0; | ||
1822 | } | ||
1823 | else | ||
1824 | { | ||
1825 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
1826 | "send"); | ||
1827 | GNUNET_MQ_inject_error (client->mq, | ||
1828 | GNUNET_MQ_ERROR_WRITE); | ||
1829 | return; | ||
1830 | } | ||
1831 | } | ||
1832 | client->msg_pos += ret; | ||
1833 | if (left > ret) | ||
1834 | { | ||
1835 | client->send_task | ||
1836 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1837 | client->sock, | ||
1838 | &do_send, | ||
1839 | client); | ||
1840 | return; | ||
1841 | } | ||
1842 | GNUNET_MQ_impl_send_continue (client->mq); | ||
1843 | } | ||
1844 | |||
1845 | |||
1846 | /** | ||
1779 | * Signature of functions implementing the sending functionality of a | 1847 | * Signature of functions implementing the sending functionality of a |
1780 | * message queue. | 1848 | * message queue. |
1781 | * | 1849 | * |
1782 | * @param mq the message queue | 1850 | * @param mq the message queue |
1783 | * @param msg the message to send | 1851 | * @param msg the message to send |
1784 | * @param impl_state state of the implementation | 1852 | * @param impl_state our `struct GNUNET_SERVICE_Client *` |
1785 | */ | 1853 | */ |
1786 | static void | 1854 | static void |
1787 | service_mq_send (struct GNUNET_MQ_Handle *mq, | 1855 | service_mq_send (struct GNUNET_MQ_Handle *mq, |
1788 | const struct GNUNET_MessageHeader *msg, | 1856 | const struct GNUNET_MessageHeader *msg, |
1789 | void *impl_state) | 1857 | void *impl_state) |
1790 | { | 1858 | { |
1791 | // struct GNUNET_SERVICE_Client *client = cls; | 1859 | struct GNUNET_SERVICE_Client *client = impl_state; |
1792 | 1860 | ||
1793 | // FIXME 1: setup "client->send_task" for transmission. | 1861 | GNUNET_assert (NULL == client->send_task); |
1794 | // FIXME 2: I seriously hope we do not need to make a copy of `msg`! | 1862 | client->msg = msg; |
1795 | // OPTIMIZATION: ideally, we'd like the ability to peak at the rest of | 1863 | client->msg_pos = 0; |
1796 | // the queue and transmit more than one message if possible. | 1864 | client->send_task |
1865 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1866 | client->sock, | ||
1867 | &do_send, | ||
1868 | client); | ||
1797 | } | 1869 | } |
1798 | 1870 | ||
1799 | 1871 | ||
@@ -1807,8 +1879,9 @@ static void | |||
1807 | service_mq_cancel (struct GNUNET_MQ_Handle *mq, | 1879 | service_mq_cancel (struct GNUNET_MQ_Handle *mq, |
1808 | void *impl_state) | 1880 | void *impl_state) |
1809 | { | 1881 | { |
1810 | // struct GNUNET_SERVICE_Client *client = cls; | 1882 | struct GNUNET_SERVICE_Client *client = impl_state; |
1811 | 1883 | ||
1884 | GNUNET_assert (0); // not implemented | ||
1812 | // FIXME: stop transmission! (must be possible, otherwise | 1885 | // FIXME: stop transmission! (must be possible, otherwise |
1813 | // we must have told MQ that the message was sent!) | 1886 | // we must have told MQ that the message was sent!) |
1814 | } | 1887 | } |
@@ -2334,4 +2407,17 @@ GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c) | |||
2334 | } | 2407 | } |
2335 | 2408 | ||
2336 | 2409 | ||
2410 | /** | ||
2411 | * Obtain the message queue of @a c. Convenience function. | ||
2412 | * | ||
2413 | * @param c the client to continue receiving from | ||
2414 | * @return the message queue of @a c | ||
2415 | */ | ||
2416 | struct GNUNET_MQ_Handle * | ||
2417 | GNUNET_SERVICE_client_get_mq (struct GNUNET_SERVICE_Client *c) | ||
2418 | { | ||
2419 | return c->mq; | ||
2420 | } | ||
2421 | |||
2422 | |||
2337 | /* end of service_new.c */ | 2423 | /* end of service_new.c */ |
diff --git a/src/util/test_client.c b/src/util/test_client.c index 558a3cf1e..aa4d84495 100644 --- a/src/util/test_client.c +++ b/src/util/test_client.c | |||
@@ -20,95 +20,48 @@ | |||
20 | /** | 20 | /** |
21 | * @file util/test_client.c | 21 | * @file util/test_client.c |
22 | * @brief tests for client.c | 22 | * @brief tests for client.c |
23 | * @author Christian Grothoff | ||
23 | */ | 24 | */ |
24 | #include "platform.h" | 25 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
26 | 27 | ||
28 | static int global_ret; | ||
27 | 29 | ||
28 | #define PORT 14325 | 30 | static struct GNUNET_MQ_Handle *client_mq; |
29 | |||
30 | #define MYNAME "test_client" | ||
31 | |||
32 | static struct GNUNET_MQ_Handle *mq; | ||
33 | |||
34 | static struct GNUNET_SERVER_Handle *server; | ||
35 | |||
36 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
37 | 31 | ||
38 | #define MY_TYPE 130 | 32 | #define MY_TYPE 130 |
39 | 33 | ||
40 | struct CopyContext | ||
41 | { | ||
42 | struct GNUNET_SERVER_Client *client; | ||
43 | struct GNUNET_MessageHeader *cpy; | ||
44 | }; | ||
45 | |||
46 | |||
47 | static size_t | ||
48 | copy_msg (void *cls, size_t size, void *buf) | ||
49 | { | ||
50 | struct CopyContext *ctx = cls; | ||
51 | struct GNUNET_MessageHeader *cpy = ctx->cpy; | ||
52 | |||
53 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (cpy->size)); | ||
54 | GNUNET_assert (size >= ntohs (cpy->size)); | ||
55 | GNUNET_memcpy (buf, cpy, ntohs (cpy->size)); | ||
56 | GNUNET_SERVER_receive_done (ctx->client, GNUNET_OK); | ||
57 | GNUNET_free (cpy); | ||
58 | GNUNET_free (ctx); | ||
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
60 | "Message bounced back to client\n"); | ||
61 | return sizeof (struct GNUNET_MessageHeader); | ||
62 | } | ||
63 | |||
64 | 34 | ||
65 | /** | 35 | /** |
66 | * Callback that just bounces the message back to the sender. | 36 | * Callback that just bounces the message back to the sender. |
67 | */ | 37 | */ |
68 | static void | 38 | static void |
69 | echo_cb (void *cls, | 39 | handle_echo (void *cls, |
70 | struct GNUNET_SERVER_Client *client, | 40 | const struct GNUNET_MessageHeader *message) |
71 | const struct GNUNET_MessageHeader *message) | ||
72 | { | 41 | { |
73 | struct CopyContext *cc; | 42 | struct GNUNET_SERVICE_Client *c = cls; |
74 | struct GNUNET_MessageHeader *cpy; | 43 | struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (c); |
44 | struct GNUNET_MQ_Envelope *env; | ||
75 | 45 | ||
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 46 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
77 | "Receiving message from client, bouncing back\n"); | 47 | "Receiving message from client, bouncing back\n"); |
78 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); | 48 | env = GNUNET_MQ_msg_copy (message); |
79 | cc = GNUNET_new (struct CopyContext); | 49 | GNUNET_MQ_send (mq, |
80 | cc->client = client; | 50 | env); |
81 | cpy = GNUNET_malloc (ntohs (message->size)); | 51 | GNUNET_SERVICE_client_continue (c); |
82 | GNUNET_memcpy (cpy, message, ntohs (message->size)); | ||
83 | cc->cpy = cpy; | ||
84 | GNUNET_assert (NULL != | ||
85 | GNUNET_SERVER_notify_transmit_ready (client, | ||
86 | ntohs (message->size), | ||
87 | GNUNET_TIME_UNIT_SECONDS, | ||
88 | ©_msg, cc)); | ||
89 | } | 52 | } |
90 | 53 | ||
91 | 54 | ||
92 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
93 | {&echo_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, | ||
94 | {NULL, NULL, 0, 0} | ||
95 | }; | ||
96 | |||
97 | |||
98 | static void | 55 | static void |
99 | handle_bounce (void *cls, | 56 | handle_bounce (void *cls, |
100 | const struct GNUNET_MessageHeader *got) | 57 | const struct GNUNET_MessageHeader *got) |
101 | { | 58 | { |
102 | int *ok = cls; | ||
103 | |||
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
105 | "Receiving bounce, checking content\n"); | 60 | "Receiving bounce, checking content\n"); |
106 | GNUNET_assert (NULL != got); | 61 | GNUNET_assert (NULL != got); |
107 | GNUNET_MQ_destroy (mq); | 62 | global_ret = 2; |
108 | mq = NULL; | 63 | GNUNET_MQ_destroy (client_mq); |
109 | GNUNET_SERVER_destroy (server); | 64 | client_mq = NULL; |
110 | server = NULL; | ||
111 | *ok = 0; | ||
112 | } | 65 | } |
113 | 66 | ||
114 | 67 | ||
@@ -129,13 +82,10 @@ mq_error_handler (void *cls, | |||
129 | 82 | ||
130 | 83 | ||
131 | static void | 84 | static void |
132 | task (void *cls) | 85 | task (void *cls, |
86 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
87 | struct GNUNET_SERVICE_Handle *sh) | ||
133 | { | 88 | { |
134 | struct sockaddr_in sa; | ||
135 | struct sockaddr *sap[2]; | ||
136 | socklen_t slens[2]; | ||
137 | struct GNUNET_MQ_Envelope *env; | ||
138 | struct GNUNET_MessageHeader *msg; | ||
139 | struct GNUNET_MQ_MessageHandler chandlers[] = { | 89 | struct GNUNET_MQ_MessageHandler chandlers[] = { |
140 | GNUNET_MQ_hd_fixed_size (bounce, | 90 | GNUNET_MQ_hd_fixed_size (bounce, |
141 | MY_TYPE, | 91 | MY_TYPE, |
@@ -143,61 +93,103 @@ task (void *cls) | |||
143 | cls), | 93 | cls), |
144 | GNUNET_MQ_handler_end () | 94 | GNUNET_MQ_handler_end () |
145 | }; | 95 | }; |
96 | struct GNUNET_MQ_Envelope *env; | ||
97 | struct GNUNET_MessageHeader *msg; | ||
146 | 98 | ||
147 | /* test that ill-configured client fails instantly */ | 99 | /* test that ill-configured client fails instantly */ |
148 | GNUNET_assert (NULL == GNUNET_CLIENT_connecT (cfg, | 100 | GNUNET_assert (NULL == |
149 | "invalid-service", | 101 | GNUNET_CLIENT_connecT (cfg, |
150 | NULL, | 102 | "invalid-service", |
151 | &mq_error_handler, | 103 | NULL, |
152 | NULL)); | 104 | &mq_error_handler, |
153 | 105 | NULL)); | |
154 | /* test IPC between client and server */ | 106 | client_mq = GNUNET_CLIENT_connecT (cfg, |
155 | sap[0] = (struct sockaddr *) &sa; | 107 | "test_client", |
156 | slens[0] = sizeof (sa); | 108 | chandlers, |
157 | sap[1] = NULL; | 109 | &mq_error_handler, |
158 | slens[1] = 0; | 110 | NULL); |
159 | memset (&sa, 0, sizeof (sa)); | 111 | GNUNET_assert (NULL != client_mq); |
160 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
161 | sa.sin_len = sizeof (sa); | ||
162 | #endif | ||
163 | sa.sin_family = AF_INET; | ||
164 | sa.sin_port = htons (PORT); | ||
165 | server = | ||
166 | GNUNET_SERVER_create (NULL, NULL, sap, slens, | ||
167 | GNUNET_TIME_relative_multiply | ||
168 | (GNUNET_TIME_UNIT_SECONDS, 10), GNUNET_NO); | ||
169 | GNUNET_assert (server != NULL); | ||
170 | handlers[0].callback_cls = cls; | ||
171 | handlers[1].callback_cls = cls; | ||
172 | GNUNET_SERVER_add_handlers (server, handlers); | ||
173 | mq = GNUNET_CLIENT_connecT (cfg, | ||
174 | MYNAME, | ||
175 | chandlers, | ||
176 | &mq_error_handler, | ||
177 | NULL); | ||
178 | GNUNET_assert (NULL != mq); | ||
179 | env = GNUNET_MQ_msg (msg, | 112 | env = GNUNET_MQ_msg (msg, |
180 | MY_TYPE); | 113 | MY_TYPE); |
181 | GNUNET_MQ_send (mq, | 114 | GNUNET_MQ_send (client_mq, |
182 | env); | 115 | env); |
183 | } | 116 | } |
184 | 117 | ||
185 | 118 | ||
119 | /** | ||
120 | * Function called when the client connects to the service. | ||
121 | * | ||
122 | * @param cls the name of the service | ||
123 | * @param c connecting client | ||
124 | * @param mq message queue to talk to the client | ||
125 | * @return @a c | ||
126 | */ | ||
127 | static void * | ||
128 | connect_cb (void *cls, | ||
129 | struct GNUNET_SERVICE_Client *c, | ||
130 | struct GNUNET_MQ_Handle *mq) | ||
131 | { | ||
132 | return c; | ||
133 | } | ||
134 | |||
135 | |||
136 | /** | ||
137 | * Function called when the client disconnects. | ||
138 | * | ||
139 | * @param cls our service name | ||
140 | * @param c disconnecting client | ||
141 | * @param internal_cls must match @a c | ||
142 | */ | ||
143 | static void | ||
144 | disconnect_cb (void *cls, | ||
145 | struct GNUNET_SERVICE_Client *c, | ||
146 | void *internal_cls) | ||
147 | { | ||
148 | if (2 == global_ret) | ||
149 | { | ||
150 | GNUNET_SCHEDULER_shutdown (); | ||
151 | global_ret = 0; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | |||
186 | int | 156 | int |
187 | main (int argc, char *argv[]) | 157 | main (int argc, |
158 | char *argv[]) | ||
188 | { | 159 | { |
189 | int ok; | 160 | struct GNUNET_MQ_MessageHandler shandlers[] = { |
161 | GNUNET_MQ_hd_fixed_size (echo, | ||
162 | MY_TYPE, | ||
163 | struct GNUNET_MessageHeader, | ||
164 | NULL), | ||
165 | GNUNET_MQ_handler_end () | ||
166 | }; | ||
167 | char * test_argv[] = { | ||
168 | (char *) "test_client", | ||
169 | "-c", | ||
170 | "test_client_data.conf", | ||
171 | NULL | ||
172 | }; | ||
190 | 173 | ||
191 | GNUNET_log_setup ("test_client", | 174 | GNUNET_log_setup ("test_client", |
192 | "WARNING", | 175 | "WARNING", |
193 | NULL); | 176 | NULL); |
194 | cfg = GNUNET_CONFIGURATION_create (); | 177 | if (0 != strstr (argv[0], |
195 | GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); | 178 | "unix")) |
196 | GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "localhost"); | 179 | test_argv[2] = "test_client_unix.conf"; |
197 | ok = 1; | 180 | global_ret = 1; |
198 | GNUNET_SCHEDULER_run (&task, &ok); | 181 | if (0 != |
199 | GNUNET_CONFIGURATION_destroy (cfg); | 182 | GNUNET_SERVICE_ruN_ (3, |
200 | return ok; | 183 | test_argv, |
184 | "test_client", | ||
185 | GNUNET_SERVICE_OPTION_NONE, | ||
186 | &task, | ||
187 | &connect_cb, | ||
188 | &disconnect_cb, | ||
189 | NULL, | ||
190 | shandlers)) | ||
191 | global_ret = 3; | ||
192 | return global_ret; | ||
201 | } | 193 | } |
202 | 194 | ||
203 | /* end of test_client.c */ | 195 | /* end of test_client.c */ |
diff --git a/src/util/test_client_data.conf b/src/util/test_client_data.conf new file mode 100644 index 000000000..fa9a0be03 --- /dev/null +++ b/src/util/test_client_data.conf | |||
@@ -0,0 +1,3 @@ | |||
1 | [test_client] | ||
2 | PORT=14325 | ||
3 | HOSTNAME=localhost | ||
diff --git a/src/util/test_client_unix.conf b/src/util/test_client_unix.conf new file mode 100644 index 000000000..d3d90627d --- /dev/null +++ b/src/util/test_client_unix.conf | |||
@@ -0,0 +1,6 @@ | |||
1 | [test_client] | ||
2 | PORT=0 | ||
3 | HOSTNAME=localhost | ||
4 | UNIXPATH=$GNUNET_RUNTIME_DIR/test-client-unix.sock | ||
5 | UNIX_MATCH_UID = YES | ||
6 | UNIX_MATCH_GID = YES | ||
diff --git a/src/util/test_mq_client.c b/src/util/test_mq_client.c deleted file mode 100644 index f436d1a4c..000000000 --- a/src/util/test_mq_client.c +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/test_mq_client.c | ||
23 | * @brief tests for mq with connection client | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | |||
28 | #define PORT 23336 | ||
29 | |||
30 | #define MY_TYPE 128 | ||
31 | |||
32 | |||
33 | static struct GNUNET_SERVER_Handle *server; | ||
34 | |||
35 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
36 | |||
37 | static int ok; | ||
38 | |||
39 | static int notify = GNUNET_NO; | ||
40 | |||
41 | static int received = 0; | ||
42 | |||
43 | |||
44 | static void | ||
45 | recv_cb (void *cls, | ||
46 | struct GNUNET_SERVER_Client *argclient, | ||
47 | const struct GNUNET_MessageHeader *message) | ||
48 | { | ||
49 | received++; | ||
50 | if (received == 2) | ||
51 | { | ||
52 | GNUNET_SERVER_receive_done (argclient, | ||
53 | GNUNET_NO); | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | /* can happen if notify does not work */ | ||
58 | GNUNET_assert (received < 2); | ||
59 | |||
60 | GNUNET_SERVER_receive_done (argclient, GNUNET_YES); | ||
61 | } | ||
62 | |||
63 | |||
64 | static void | ||
65 | clean_up (void *cls) | ||
66 | { | ||
67 | GNUNET_SERVER_destroy (server); | ||
68 | server = NULL; | ||
69 | GNUNET_CONFIGURATION_destroy (cfg); | ||
70 | cfg = NULL; | ||
71 | } | ||
72 | |||
73 | |||
74 | /** | ||
75 | * Functions with this signature are called whenever a client | ||
76 | * is disconnected on the network level. | ||
77 | * | ||
78 | * @param cls closure | ||
79 | * @param client identification of the client | ||
80 | */ | ||
81 | static void | ||
82 | notify_disconnect (void *cls, | ||
83 | struct GNUNET_SERVER_Client *client) | ||
84 | { | ||
85 | if (client == NULL) | ||
86 | return; | ||
87 | ok = 0; | ||
88 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | ||
89 | } | ||
90 | |||
91 | |||
92 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
93 | {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, | ||
94 | {NULL, NULL, 0, 0} | ||
95 | }; | ||
96 | |||
97 | |||
98 | static void | ||
99 | send_cb (void *cls) | ||
100 | { | ||
101 | /* the notify should only be called once */ | ||
102 | GNUNET_assert (GNUNET_NO == notify); | ||
103 | notify = GNUNET_YES; | ||
104 | } | ||
105 | |||
106 | static void | ||
107 | send_trap_cb (void *cls) | ||
108 | { | ||
109 | GNUNET_assert (0); | ||
110 | } | ||
111 | |||
112 | |||
113 | static void | ||
114 | test_mq () | ||
115 | { | ||
116 | struct GNUNET_MQ_Handle *mq; | ||
117 | struct GNUNET_MQ_Envelope *mqm; | ||
118 | |||
119 | /* FIXME: test handling responses */ | ||
120 | mq = GNUNET_CLIENT_connecT (cfg, | ||
121 | "test", | ||
122 | NULL, NULL, NULL); | ||
123 | |||
124 | mqm = GNUNET_MQ_msg_header (MY_TYPE); | ||
125 | GNUNET_MQ_send (mq, mqm); | ||
126 | |||
127 | mqm = GNUNET_MQ_msg_header (MY_TYPE); | ||
128 | GNUNET_MQ_notify_sent (mqm, &send_trap_cb, NULL); | ||
129 | GNUNET_MQ_send (mq, mqm); | ||
130 | GNUNET_MQ_send_cancel (mqm); | ||
131 | |||
132 | mqm = GNUNET_MQ_msg_header (MY_TYPE); | ||
133 | GNUNET_MQ_notify_sent (mqm, &send_cb, NULL); | ||
134 | GNUNET_MQ_send (mq, mqm); | ||
135 | } | ||
136 | |||
137 | |||
138 | static void | ||
139 | task (void *cls) | ||
140 | { | ||
141 | struct sockaddr_in sa; | ||
142 | struct sockaddr *sap[2]; | ||
143 | socklen_t slens[2]; | ||
144 | |||
145 | sap[0] = (struct sockaddr *) &sa; | ||
146 | slens[0] = sizeof (sa); | ||
147 | sap[1] = NULL; | ||
148 | slens[1] = 0; | ||
149 | memset (&sa, 0, sizeof (sa)); | ||
150 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
151 | sa.sin_len = sizeof (sa); | ||
152 | #endif | ||
153 | sa.sin_family = AF_INET; | ||
154 | sa.sin_port = htons (PORT); | ||
155 | server = | ||
156 | GNUNET_SERVER_create (NULL, NULL, sap, slens, | ||
157 | GNUNET_TIME_relative_multiply | ||
158 | (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); | ||
159 | GNUNET_assert (server != NULL); | ||
160 | handlers[0].callback_cls = cls; | ||
161 | GNUNET_SERVER_add_handlers (server, handlers); | ||
162 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); | ||
163 | cfg = GNUNET_CONFIGURATION_create (); | ||
164 | GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); | ||
165 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); | ||
166 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
167 | "localhost"); | ||
168 | test_mq (); | ||
169 | } | ||
170 | |||
171 | |||
172 | int | ||
173 | main (int argc, char *argv[]) | ||
174 | { | ||
175 | GNUNET_log_setup ("test-mq-client", | ||
176 | "INFO", | ||
177 | NULL); | ||
178 | ok = 1; | ||
179 | GNUNET_SCHEDULER_run (&task, NULL); | ||
180 | GNUNET_assert (GNUNET_YES == notify); | ||
181 | return ok; | ||
182 | } | ||
diff --git a/src/util/test_service_data.conf b/src/util/test_service_data.conf index 7f6baaab1..c04626b5b 100644 --- a/src/util/test_service_data.conf +++ b/src/util/test_service_data.conf | |||
@@ -2,7 +2,6 @@ | |||
2 | PORT=12435 | 2 | PORT=12435 |
3 | BINDTO=localhost | 3 | BINDTO=localhost |
4 | PIDFILE=/tmp/test-service.pid | 4 | PIDFILE=/tmp/test-service.pid |
5 | TIMEOUT=30 s | ||
6 | MAXBUF=1024 | 5 | MAXBUF=1024 |
7 | DISABLEV6=NO | 6 | DISABLEV6=NO |
8 | ACCEPT_FROM=127.0.0.1; | 7 | ACCEPT_FROM=127.0.0.1; |