-remove debug message
[oweals/gnunet.git] / src / transport / transport-testing2.h
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.h
23  * @brief functions and structures 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_ats_transport_service.h"
30 #include "transport.h"
31
32
33 /**
34  * @brief Handle to a transport communicator
35  */
36 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle;
37
38
39 /**
40  * @brief Queue of a communicator and some context
41  */
42 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue;
43
44
45 /**
46  * @brief Handle/Context to a single transmission
47  */
48 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission;
49
50 /**
51  * @brief Function signature for callbacks that are called when new
52  * backchannel message arrived
53  *
54  * @param cls Closure
55  * @param msg Backchannel message
56  * @param pid Target peer
57  */
58 typedef struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
59 (*GNUNET_TRANSPORT_TESTING_BackchannelCallback)(void *cls,
60                                                 struct GNUNET_MessageHeader *msg,
61                                                 struct GNUNET_PeerIdentity *pid);
62
63
64 /**
65  * @brief Function signature for callbacks that are called when new
66  * communicators become available
67  *
68  * @param cls Closure
69  * @param tc_h Communicator handle
70  * @param cc Characteristics of communicator
71  * @param address_prefix Prefix of the address
72  */
73 typedef void
74 (*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls,
75                                                           struct
76                                                           GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
77                                                           *tc_h,
78                                                           enum
79                                                           GNUNET_TRANSPORT_CommunicatorCharacteristics
80                                                           cc,
81                                                           char *address_prefix);
82
83
84 /**
85  * @brief Receive information about the address of a communicator.
86  *
87  * @param cls Closure
88  * @param tc_h Communicator handle
89  * @param address Address represented as string
90  * @param expiration Expiration
91  * @param aid Aid
92  * @param nt Network Type
93  */
94 typedef void
95 (*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls,
96                                                struct
97                                                GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
98                                                *tc_h,
99                                                const char *address,
100                                                struct GNUNET_TIME_Relative
101                                                expiration,
102                                                uint32_t aid,
103                                                enum GNUNET_NetworkType nt);
104
105
106 /**
107  * @brief Get informed about the success of a queue request.
108  *
109  * @param cls Closure
110  * @param tc_h Communicator handle
111  * @param will_try #GNUNET_YES if communicator will try to create queue
112  */
113 typedef void
114 (*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls,
115                                                      struct
116                                                      GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
117                                                      *tc_h,
118                                                      int will_try);
119
120
121 /**
122  * @brief Handle opening of queue
123  *
124  * @param cls Closure
125  * @param tc_h Communicator handle
126  * @param tc_queue Handle to newly opened queue
127  */
128 typedef void
129 (*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
130                                              struct
131                                              GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
132                                              *tc_h,
133                                              struct
134                                              GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
135                                              *tc_queue,
136                                              size_t mtu);
137
138
139 /**
140  * @brief Handle an incoming message
141  *
142  * @param cls Closure
143  * @param tc_h Handle to the receiving communicator
144  * @param msg Received message
145  */
146 typedef void
147 (*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls,
148                                                     struct
149                                                     GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
150                                                     *tc_h,
151                                                     const char*payload,
152                                                     size_t payload_len);
153
154
155 /**
156  * @brief Start communicator part of transport service and communicator
157  *
158  * @param service_name Name of the service
159  * @param cfg Configuration handle
160  * @param communicator_available Callback that is called when a new
161  * communicator becomes available
162  * @param add_address_cb Callback handling new addresses
163  * @param queue_create_reply_cb Callback handling success of queue requests
164  * @param add_queue_cb Callback handling freshly created queues
165  * @param incoming_message_cb Callback handling incoming messages
166  * @param cb_cls Closure to @p communicator_available
167  *
168  * @return Handle to the communicator duo
169  */
170 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
171 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
172   const char *service_name,
173   const char *binary_name,
174   const char *cfg_filename,
175   const struct GNUNET_PeerIdentity *peer_id,
176   GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
177   communicator_available_cb,
178   GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
179   GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
180   GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
181   GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
182   GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb,
183   void *cb_cls);
184
185
186 void
187 GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (
188   struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h);
189
190
191 /**
192  * @brief Instruct communicator to open a queue
193  *
194  * @param tc_h Handle to communicator which shall open queue
195  * @param peer_id Towards which peer
196  * @param address For which address
197  */
198 void
199 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct
200                                                             GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
201                                                             *tc_h,
202                                                             const struct
203                                                             GNUNET_PeerIdentity
204                                                             *peer_id,
205                                                             const char *address);
206
207
208 /**
209  * @brief Instruct communicator to send data
210  *
211  * @param tc_queue The queue to use for sending
212  * @param cont function to call when done sending
213  * @param cont_cls closure for @a cont
214  * @param payload Data to send
215  * @param payload_size Size of the @a payload
216  */
217 void
218 GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct
219                                                       GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
220                                                       *tc_h,
221                                                       GNUNET_SCHEDULER_TaskCallback
222                                                       cont,
223                                                       void *cont_cls,
224                                                       const void *payload,
225                                                       size_t payload_size);