add changelog
[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 /**
52  * @brief Function signature for callbacks that are called when new
53  * communicators become available
54  *
55  * @param cls Closure
56  * @param tc_h Communicator handle
57  * @param cc Characteristics of communicator
58  * @param address_prefix Prefix of the address
59  */
60 typedef void
61 (*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls,
62                                                           struct
63                                                           GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
64                                                           *tc_h,
65                                                           enum
66                                                           GNUNET_TRANSPORT_CommunicatorCharacteristics
67                                                           cc,
68                                                           char *address_prefix);
69
70
71 /**
72  * @brief Receive information about the address of a communicator.
73  *
74  * @param cls Closure
75  * @param tc_h Communicator handle
76  * @param address Address represented as string
77  * @param expiration Expiration
78  * @param aid Aid
79  * @param nt Network Type
80  */
81 typedef void
82 (*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls,
83                                                struct
84                                                GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
85                                                *tc_h,
86                                                const char *address,
87                                                struct GNUNET_TIME_Relative
88                                                expiration,
89                                                uint32_t aid,
90                                                enum GNUNET_NetworkType nt);
91
92
93 /**
94  * @brief Get informed about the success of a queue request.
95  *
96  * @param cls Closure
97  * @param tc_h Communicator handle
98  * @param will_try #GNUNET_YES if communicator will try to create queue
99  */
100 typedef void
101 (*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls,
102                                                      struct
103                                                      GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
104                                                      *tc_h,
105                                                      int will_try);
106
107
108 /**
109  * @brief Handle opening of queue
110  *
111  * @param cls Closure
112  * @param tc_h Communicator handle
113  * @param tc_queue Handle to newly opened queue
114  */
115 typedef void
116 (*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
117                                              struct
118                                              GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
119                                              *tc_h,
120                                              struct
121                                              GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
122                                              *tc_queue);
123
124
125 /**
126  * @brief Handle an incoming message
127  *
128  * @param cls Closure
129  * @param tc_h Handle to the receiving communicator
130  * @param msg Received message
131  */
132 typedef void
133 (*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls,
134                                                     struct
135                                                     GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
136                                                     *tc_h,
137                                                     const struct
138                                                     GNUNET_MessageHeader *msg);
139
140
141 /**
142  * @brief Start communicator part of transport service and communicator
143  *
144  * @param service_name Name of the service
145  * @param cfg Configuration handle
146  * @param communicator_available Callback that is called when a new
147  * communicator becomes available
148  * @param add_address_cb Callback handling new addresses
149  * @param queue_create_reply_cb Callback handling success of queue requests
150  * @param add_queue_cb Callback handling freshly created queues
151  * @param incoming_message_cb Callback handling incoming messages
152  * @param cb_cls Closure to @p communicator_available
153  *
154  * @return Handle to the communicator duo
155  */
156 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
157 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
158   const char *service_name,
159   const char *binary_name,
160   const char *cfg_filename,
161   GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
162   communicator_available_cb,
163   GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
164   GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
165   GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
166   GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
167   void *cb_cls);
168
169
170 /**
171  * @brief Instruct communicator to open a queue
172  *
173  * @param tc_h Handle to communicator which shall open queue
174  * @param peer_id Towards which peer
175  * @param address For which address
176  */
177 void
178 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct
179                                                             GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
180                                                             *tc_h,
181                                                             const struct
182                                                             GNUNET_PeerIdentity
183                                                             *peer_id,
184                                                             const char *address);
185
186
187 /**
188  * @brief Instruct communicator to send data
189  *
190  * @param tc_queue The queue to use for sending
191  * @param payload Data to send
192  * @param payload_size Size of the payload
193  *
194  * @return Handle to the transmission
195  */
196 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
197 GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct
198                                                       GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
199                                                       *tc_queue,
200                                                       const void *payload,
201                                                       size_t payload_size /*,
202                          GNUNET_TRANSPORT_TESTING_SuccessStatus cb,
203                          void *cb_cls*/               );