2 This file is part of GNUnet.
3 Copyright (C) 2009-2019 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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
25 * API of the transport service towards the communicator processes.
27 * @defgroup transport TRANSPORT service
28 * Low-level communication with other peers
30 * @see [Documentation](https://gnunet.org/transport-service)
35 #ifndef GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
36 #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
40 #if 0 /* keep Emacsens' auto-indent happy */
45 #include "gnunet_util_lib.h"
46 #include "gnunet_nt_lib.h"
49 * Version number of the transport communication API.
51 #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000
55 * Function called by the transport service to initialize a
56 * message queue given address information about another peer.
57 * If and when the communication channel is established, the
58 * communicator must call #GNUNET_TRANSPORT_communicator_mq_add()
59 * to notify the service that the channel is now up. It is
60 * the responsibility of the communicator to manage sane
61 * retries and timeouts for any @a peer/@a address combination
62 * provided by the transport service. Timeouts and retries
63 * do not need to be signalled to the transport service.
66 * @param peer identity of the other peer
67 * @param address where to send the message, human-readable
68 * communicator-specific format, 0-terminated, UTF-8
69 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is
72 typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) (
74 const struct GNUNET_PeerIdentity *peer,
79 * Opaque handle to the transport service for communicators.
81 struct GNUNET_TRANSPORT_CommunicatorHandle;
85 * What characteristics does this communicator have?
87 * FIXME: may want to distinguish bi-directional as well,
88 * should we define a bit for that? Needed in DV logic (handle_dv_learn)!
90 enum GNUNET_TRANSPORT_CommunicatorCharacteristics {
92 * Characteristics are unknown (i.e. DV).
94 GNUNET_TRANSPORT_CC_UNKNOWN = 0,
97 * Transmission is reliabile (with ACKs), i.e. TCP/HTTP/HTTPS.
99 GNUNET_TRANSPORT_CC_RELIABLE = 1,
102 * Transmission is unreliable (i.e. UDP)
104 GNUNET_TRANSPORT_CC_UNRELIABLE = 2
109 * Function called when the transport service has received a
110 * backchannel message for this communicator (!) via a different
113 * Typically used to receive messages of type
114 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS or
115 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
116 * as well as communicator-specific messages to assist with
120 * @param sender which peer sent the notification
123 typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) (
125 const struct GNUNET_PeerIdentity *sender,
126 const struct GNUNET_MessageHeader *msg);
130 * Connect to the transport service.
132 * @param cfg configuration to use
133 * @param config_section section of the configuration to use for options
134 * @param addr_prefix address prefix for addresses supported by this
135 * communicator, could be NULL for incoming-only communicators
136 * @param cc what characteristics does the communicator have?
137 * @param mq_init function to call to initialize a message queue given
138 * the address of another peer, can be NULL if the
139 * communicator only supports receiving messages
140 * @param mq_init_cls closure for @a mq_init
141 * @param notify_cb function to pass backchannel messages to communicator
142 * @param notify_cb_cls closure for @a notify_cb
143 * @return NULL on error
145 struct GNUNET_TRANSPORT_CommunicatorHandle *
146 GNUNET_TRANSPORT_communicator_connect(
147 const struct GNUNET_CONFIGURATION_Handle *cfg,
148 const char *config_section_name,
149 const char *addr_prefix,
150 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
151 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
153 GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
154 void *notify_cb_cls);
158 * Disconnect from the transport service.
160 * @param ch handle returned from connect
163 GNUNET_TRANSPORT_communicator_disconnect(
164 struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
167 /* ************************* Receiving *************************** */
170 * Function called to notify communicator that we have received
171 * and processed the message. Used for flow control (if supported
172 * by the communicator).
175 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
176 * #GNUNET_OK on success
178 typedef void (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
183 * Notify transport service that the communicator has received
186 * @param handle connection to transport service
187 * @param sender presumed sender of the message (details to be checked
189 * @param msg the message
190 * @param expected_addr_validity how long does the communicator believe it
191 * will continue to be able to receive messages from the same address
192 * on which it received this message?
193 * @param cb function to call once handling the message is done, NULL if
194 * flow control is not supported by this communicator
195 * @param cb_cls closure for @a cb
196 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
197 * immediately dropped due to memory limitations (communicator
198 * should try to apply back pressure),
199 * #GNUNET_SYSERR if the message could not be delivered because
200 * the tranport service is not yet up
203 GNUNET_TRANSPORT_communicator_receive(
204 struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
205 const struct GNUNET_PeerIdentity *sender,
206 const struct GNUNET_MessageHeader *msg,
207 struct GNUNET_TIME_Relative expected_addr_validity,
208 GNUNET_TRANSPORT_MessageCompletedCallback cb,
212 /* ************************* Discovery *************************** */
215 * Handle returned to identify the internal data structure the transport
216 * API has created to manage a message queue to a particular peer.
218 struct GNUNET_TRANSPORT_QueueHandle;
222 * Possible states of a connection.
224 enum GNUNET_TRANSPORT_ConnectionStatus {
226 * Connection is down.
228 GNUNET_TRANSPORT_CS_DOWN = -1,
231 * this is an outbound connection (transport initiated)
233 GNUNET_TRANSPORT_CS_OUTBOUND = 0,
236 * this is an inbound connection (communicator initiated)
238 GNUNET_TRANSPORT_CS_INBOUND = 1
243 * Notify transport service that a MQ became available due to an
244 * "inbound" connection or because the communicator discovered the
245 * presence of another peer.
247 * @param ch connection to transport service
248 * @param peer peer with which we can now communicate
249 * @param address address in human-readable format, 0-terminated, UTF-8
250 * @param mtu maximum message size supported by queue, 0 if
251 * sending is not supported, SIZE_MAX for no MTU
252 * @param nt which network type does the @a address belong to?
253 * @param cs what is the connection status of the queue?
254 * @param mq message queue of the @a peer
255 * @return API handle identifying the new MQ
257 struct GNUNET_TRANSPORT_QueueHandle *
258 GNUNET_TRANSPORT_communicator_mq_add(
259 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
260 const struct GNUNET_PeerIdentity *peer,
263 enum GNUNET_NetworkType nt,
264 enum GNUNET_TRANSPORT_ConnectionStatus cs,
265 struct GNUNET_MQ_Handle *mq);
269 * Notify transport service that an MQ became unavailable due to a
270 * disconnect or timeout.
272 * @param qh handle for the queue that must be invalidated
275 GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh);
279 * Internal representation of an address a communicator is
280 * currently providing for the transport service.
282 struct GNUNET_TRANSPORT_AddressIdentifier;
286 * Notify transport service about an address that this communicator
287 * provides for this peer.
289 * @param ch connection to transport service
290 * @param address our address in human-readable format, 0-terminated, UTF-8
291 * @param nt which network type does the address belong to?
292 * @param expiration when does the communicator forsee this address expiring?
294 struct GNUNET_TRANSPORT_AddressIdentifier *
295 GNUNET_TRANSPORT_communicator_address_add(
296 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
298 enum GNUNET_NetworkType nt,
299 struct GNUNET_TIME_Relative expiration);
303 * Notify transport service about an address that this communicator
304 * no longer provides for this peer.
306 * @param ai address that is no longer provided
309 GNUNET_TRANSPORT_communicator_address_remove(
310 struct GNUNET_TRANSPORT_AddressIdentifier *ai);
314 * The communicator asks the transport service to route a message via
315 * a different path to another communicator service at another peer.
316 * This must only be done for special control traffic (as there is no
317 * flow control for this API), such as acknowledgements, and generally
318 * only be done if the communicator is uni-directional (i.e. cannot
319 * send the message back itself).
321 * While backchannel messages are signed and encrypted, communicators
322 * must protect against replay attacks when using this backchannel
325 * @param ch handle of this communicator
326 * @param pid peer to send the message to
327 * @param comm name of the communicator to send the message to
328 * @param header header of the message to transmit and pass via the
329 * notify-API to @a pid's communicator @a comm
332 GNUNET_TRANSPORT_communicator_notify(
333 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
334 const struct GNUNET_PeerIdentity *pid,
336 const struct GNUNET_MessageHeader *header);
339 #if 0 /* keep Emacsens' auto-indent happy */
346 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
349 /** @} */ /* end of group */
351 /* end of gnunet_transport_communicator_service.h */