2 This file is part of GNUnet.
3 Copyright (C) 2009, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
16 * @file util/test_client.c
17 * @brief tests for client.c
18 * @author Christian Grothoff
21 #include "gnunet_util_lib.h"
23 static int global_ret;
25 static struct GNUNET_MQ_Handle *client_mq;
31 * Callback that just bounces the message back to the sender.
34 handle_echo (void *cls,
35 const struct GNUNET_MessageHeader *message)
37 struct GNUNET_SERVICE_Client *c = cls;
38 struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (c);
39 struct GNUNET_MQ_Envelope *env;
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
42 "Receiving message from client, bouncing back\n");
43 env = GNUNET_MQ_msg_copy (message);
46 GNUNET_SERVICE_client_continue (c);
51 handle_bounce (void *cls,
52 const struct GNUNET_MessageHeader *got)
54 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
55 "Receiving bounce, checking content\n");
56 GNUNET_assert (NULL != got);
58 GNUNET_MQ_destroy (client_mq);
64 * Generic error handler, called with the appropriate error code and
65 * the same closure specified at the creation of the message queue.
66 * Not every message queue implementation supports an error handler.
68 * @param cls closure with the `struct GNUNET_STATISTICS_Handle *`
69 * @param error error code
72 mq_error_handler (void *cls,
73 enum GNUNET_MQ_Error error)
75 GNUNET_assert (0); /* should never happen */
81 const struct GNUNET_CONFIGURATION_Handle *cfg,
82 struct GNUNET_SERVICE_Handle *sh)
84 struct GNUNET_MQ_MessageHandler chandlers[] = {
85 GNUNET_MQ_hd_fixed_size (bounce,
87 struct GNUNET_MessageHeader,
89 GNUNET_MQ_handler_end ()
91 struct GNUNET_MQ_Envelope *env;
92 struct GNUNET_MessageHeader *msg;
94 /* test that ill-configured client fails instantly */
95 GNUNET_assert (NULL ==
96 GNUNET_CLIENT_connect (cfg,
101 client_mq = GNUNET_CLIENT_connect (cfg,
106 GNUNET_assert (NULL != client_mq);
107 env = GNUNET_MQ_msg (msg,
109 GNUNET_MQ_send (client_mq,
115 * Function called when the client connects to the service.
117 * @param cls the name of the service
118 * @param c connecting client
119 * @param mq message queue to talk to the client
123 connect_cb (void *cls,
124 struct GNUNET_SERVICE_Client *c,
125 struct GNUNET_MQ_Handle *mq)
132 * Function called when the client disconnects.
134 * @param cls our service name
135 * @param c disconnecting client
136 * @param internal_cls must match @a c
139 disconnect_cb (void *cls,
140 struct GNUNET_SERVICE_Client *c,
145 GNUNET_SCHEDULER_shutdown ();
155 struct GNUNET_MQ_MessageHandler shandlers[] = {
156 GNUNET_MQ_hd_fixed_size (echo,
158 struct GNUNET_MessageHeader,
160 GNUNET_MQ_handler_end ()
162 char * test_argv[] = {
163 (char *) "test_client",
165 "test_client_data.conf",
169 GNUNET_log_setup ("test_client",
172 if (0 != strstr (argv[0],
174 test_argv[2] = "test_client_unix.conf";
177 GNUNET_SERVICE_run_ (3,
180 GNUNET_SERVICE_OPTION_NONE,
190 /* end of test_client.c */