diff options
Diffstat (limited to 'src/transport/transport-testing2.c')
-rw-r--r-- | src/transport/transport-testing2.c | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c new file mode 100644 index 000000000..0a7aa1da0 --- /dev/null +++ b/src/transport/transport-testing2.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2019 GNUnet e.V. | ||
4 | |||
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. | ||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/transport-testing2.c | ||
23 | * @brief functions related to testing-tng | ||
24 | * @author Christian Grothoff | ||
25 | * @author Julius Bünger | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_constants.h" | ||
31 | #include "transport-testing2.h" | ||
32 | #include "gnunet_ats_transport_service.h" | ||
33 | #include "gnunet_signatures.h" | ||
34 | #include "transport.h" | ||
35 | |||
36 | |||
37 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) | ||
38 | |||
39 | |||
40 | /** | ||
41 | * @brief Check whether incoming msg indicating available communicator is | ||
42 | * correct | ||
43 | * | ||
44 | * @param cls Closure | ||
45 | * @param msg Message struct | ||
46 | * | ||
47 | * @return GNUNET_YES in case message is correct | ||
48 | */ | ||
49 | static int | ||
50 | check_communicator_available (void *cls, | ||
51 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) | ||
52 | { | ||
53 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
54 | "check_communicator_available()\n"); | ||
55 | return GNUNET_YES; | ||
56 | } | ||
57 | |||
58 | |||
59 | /** | ||
60 | * @brief Handle new communicator | ||
61 | * | ||
62 | * @param cls Closure | ||
63 | * @param msg Message struct | ||
64 | */ | ||
65 | static void | ||
66 | handle_communicator_available (void *cls, | ||
67 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) | ||
68 | { | ||
69 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available = cls; | ||
70 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
71 | "handle_communicator_available()\n"); | ||
72 | if (NULL != communicator_available) | ||
73 | { | ||
74 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
75 | "calling communicator_available()\n"); | ||
76 | communicator_available (NULL, msg); | ||
77 | } | ||
78 | //GNUNET_SERVICE_client_continue (client); | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * @brief Shut down the service | ||
84 | * | ||
85 | * @param cls Closure - Handle to the service | ||
86 | */ | ||
87 | static void | ||
88 | shutdown_service (void *cls) | ||
89 | { | ||
90 | struct GNUNET_SERVICE_Handle *h = cls; | ||
91 | |||
92 | GNUNET_SERVICE_stop (h); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * @brief Start the communicator part of the transport service | ||
98 | * | ||
99 | * @param communicator_available Callback to be called when a new communicator | ||
100 | * becomes available | ||
101 | * @param cfg Configuration | ||
102 | */ | ||
103 | static void | ||
104 | transport_communicator_start (GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available, | ||
105 | struct GNUNET_CONFIGURATION_Handle *cfg) | ||
106 | { | ||
107 | struct GNUNET_MQ_MessageHandler mh[] = { | ||
108 | GNUNET_MQ_hd_var_size (communicator_available, | ||
109 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, | ||
110 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, | ||
111 | &communicator_available), | ||
112 | //GNUNET_MQ_hd_var_size (communicator_backchannel, | ||
113 | // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, | ||
114 | // struct GNUNET_TRANSPORT_CommunicatorBackchannel, | ||
115 | // NULL), | ||
116 | //GNUNET_MQ_hd_var_size (add_address, | ||
117 | // GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, | ||
118 | // struct GNUNET_TRANSPORT_AddAddressMessage, | ||
119 | // NULL), | ||
120 | //GNUNET_MQ_hd_fixed_size (del_address, | ||
121 | // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, | ||
122 | // struct GNUNET_TRANSPORT_DelAddressMessage, | ||
123 | // NULL), | ||
124 | //GNUNET_MQ_hd_var_size (incoming_msg, | ||
125 | // GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, | ||
126 | // struct GNUNET_TRANSPORT_IncomingMessage, | ||
127 | // NULL), | ||
128 | //GNUNET_MQ_hd_fixed_size (queue_create_ok, | ||
129 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, | ||
130 | // struct GNUNET_TRANSPORT_CreateQueueResponse, | ||
131 | // NULL), | ||
132 | //GNUNET_MQ_hd_fixed_size (queue_create_fail, | ||
133 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, | ||
134 | // struct GNUNET_TRANSPORT_CreateQueueResponse, | ||
135 | // NULL), | ||
136 | //GNUNET_MQ_hd_var_size (add_queue_message, | ||
137 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, | ||
138 | // struct GNUNET_TRANSPORT_AddQueueMessage, | ||
139 | // NULL), | ||
140 | //GNUNET_MQ_hd_fixed_size (del_queue_message, | ||
141 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, | ||
142 | // struct GNUNET_TRANSPORT_DelQueueMessage, | ||
143 | // NULL), | ||
144 | //GNUNET_MQ_hd_fixed_size (send_message_ack, | ||
145 | // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, | ||
146 | // struct GNUNET_TRANSPORT_SendMessageToAck, | ||
147 | // NULL), | ||
148 | }; | ||
149 | struct GNUNET_SERVICE_Handle *h; | ||
150 | |||
151 | h = GNUNET_SERVICE_start ("transport", | ||
152 | cfg, | ||
153 | NULL, | ||
154 | NULL, | ||
155 | NULL, | ||
156 | mh); | ||
157 | if (NULL == h) | ||
158 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
159 | "Failed starting service!\n"); | ||
160 | else | ||
161 | { | ||
162 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
163 | "Started service\n"); | ||
164 | GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | |||
169 | /** | ||
170 | * @brief Start the communicator | ||
171 | * | ||
172 | * @param cfgname Name of the communicator | ||
173 | */ | ||
174 | static void | ||
175 | communicator_start (const char *cfgname) | ||
176 | { | ||
177 | char *binary; | ||
178 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
179 | struct GNUNET_OS_Process *proc; | ||
180 | |||
181 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
182 | "communicator_start\n"); | ||
183 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-communicator-unix"); | ||
184 | cfg = GNUNET_CONFIGURATION_create (); | ||
185 | proc = | ||
186 | GNUNET_OS_start_process (GNUNET_YES, | ||
187 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
188 | NULL, NULL, NULL, | ||
189 | binary, | ||
190 | "./gnunet-communicator-unix", | ||
191 | "-c", | ||
192 | cfgname, | ||
193 | NULL); | ||
194 | if (NULL == proc) | ||
195 | { | ||
196 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
197 | "Failed to start communicator!"); | ||
198 | return; | ||
199 | } | ||
200 | GNUNET_assert (GNUNET_OK == | ||
201 | GNUNET_CONFIGURATION_load (cfg, | ||
202 | cfgname)); | ||
203 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "started communicator\n"); | ||
205 | GNUNET_free (binary); | ||
206 | } | ||
207 | |||
208 | |||
209 | /** | ||
210 | * @brief Start communicator part of transport service and communicator | ||
211 | * | ||
212 | * @param service_name Name of the service | ||
213 | * @param cfg Configuration handle | ||
214 | * @param communicator_available Callback that is called when a new | ||
215 | * communicator becomes available | ||
216 | * @param cb_cls Closure to @p communicator_available | ||
217 | * | ||
218 | * @return Handle to the communicator duo | ||
219 | */ | ||
220 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * | ||
221 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start | ||
222 | (const char *service_name, | ||
223 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
224 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available, | ||
225 | //GNUNET_TRANSPORT_TESTING_Callback2 cb2, | ||
226 | //GNUNET_TRANSPORT_TESTING_Callback3 cb3, | ||
227 | //GNUNET_TRANSPORT_TESTING_Callback4 cb4, | ||
228 | void *cb_cls) | ||
229 | { | ||
230 | |||
231 | /* Start communicator part of service */ | ||
232 | transport_communicator_start (communicator_available, cfg); | ||
233 | |||
234 | /* Schedule start communicator */ | ||
235 | communicator_start ("test_communicator_1.conf"); | ||
236 | } | ||
237 | |||
238 | //void | ||
239 | //GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue | ||
240 | // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch, | ||
241 | // const char *address); | ||
242 | // | ||
243 | //struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * | ||
244 | //GNUNET_TRANSPORT_TESTING_transport_communicator_send | ||
245 | // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq, | ||
246 | // const struct GNUNET_MessageHeader *hdr, | ||
247 | // GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls); | ||
248 | |||