2 This file is part of GNUnet.
3 Copyright (C) 2009-2018 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
41 #if 0 /* keep Emacsens' auto-indent happy */
46 #include "gnunet_util_lib.h"
47 #include "gnunet_nt_lib.h"
50 * Version number of the transport communication API.
52 #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000
56 * Function called by the transport service to initialize a
57 * message queue given address information about another peer.
58 * If and when the communication channel is established, the
59 * communicator must call #GNUNET_TRANSPORT_communicator_mq_add()
60 * to notify the service that the channel is now up. It is
61 * the responsibility of the communicator to manage sane
62 * retries and timeouts for any @a peer/@a address combination
63 * provided by the transport service. Timeouts and retries
64 * do not need to be signalled to the transport service.
67 * @param peer identity of the other peer
68 * @param address where to send the message, human-readable
69 * communicator-specific format, 0-terminated, UTF-8
70 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid
73 (*GNUNET_TRANSPORT_CommunicatorMqInit) (void *cls,
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 enum GNUNET_TRANSPORT_CommunicatorCharacteristics {
90 * Characteristics are unknown (i.e. DV).
92 GNUNET_TRANSPORT_CC_UNKNOWN = 0,
95 * Transmission is reliabile (with ACKs), i.e. TCP/HTTP/HTTPS.
97 GNUNET_TRANSPORT_CC_RELIABLE = 1,
100 * Transmission is unreliable (i.e. UDP)
102 GNUNET_TRANSPORT_CC_UNRELIABILE = 2
108 * Function called when the transport service has received an
109 * acknowledgement for this communicator (!) via a different return
112 * Typically used to receive messages of type
113 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS or
114 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
115 * as well as communicator-specific messages to assist with
119 * @param sender which peer sent the notification
123 (*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls,
124 const struct GNUNET_PeerIdentity *sender,
125 const struct GNUNET_MessageHeader *msg);
129 * Connect to the transport service.
131 * @param cfg configuration to use
132 * @param config_section section of the configuration to use for options
133 * @param addr_prefix address prefix for addresses supported by this
134 * communicator, could be NULL for incoming-only communicators
135 * @param cc what characteristics does the communicator have?
136 * @param mq_init function to call to initialize a message queue given
137 * the address of another peer, can be NULL if the
138 * communicator only supports receiving messages
139 * @param mq_init_cls closure for @a mq_init
140 * @param notify_cb function to pass backchannel messages to communicator
141 * @param notify_cb_cls closure for @a notify_cb
142 * @return NULL on error
144 struct GNUNET_TRANSPORT_CommunicatorHandle *
145 GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
146 const char *config_section_name,
147 const char *addr_prefix,
148 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
149 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
151 GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
152 void *notify_cb_cls);
156 * Disconnect from the transport service.
158 * @param ch handle returned from connect
161 GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
164 /* ************************* Receiving *************************** */
167 * Function called to notify communicator that we have received
168 * and processed the message.
171 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
172 * #GNUNET_OK on success
175 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
180 * Notify transport service that the communicator has received
183 * @param handle connection to transport service
184 * @param sender presumed sender of the message (details to be checked
186 * @param msg the message
187 * @param cb function to call once handling the message is done, NULL if
188 * flow control is not supported by this communicator
189 * @param cb_cls closure for @a cb
190 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
191 * immediately dropped due to memory limitations (communicator
192 * should try to apply back pressure),
193 * #GNUNET_SYSERR if the message could not be delivered because
194 * the tranport service is not yet up
197 GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
198 const struct GNUNET_PeerIdentity *sender,
199 const struct GNUNET_MessageHeader *msg,
200 GNUNET_TRANSPORT_MessageCompletedCallback cb,
204 /* ************************* Discovery *************************** */
207 * Handle returned to identify the internal data structure the transport
208 * API has created to manage a message queue to a particular peer.
210 struct GNUNET_TRANSPORT_QueueHandle;
214 * Possible states of a connection.
216 enum GNUNET_TRANSPORT_ConnectionStatus {
219 * Connection is down.
221 GNUNET_TRANSPORT_CS_DOWN = -1,
224 * this is an outbound connection (transport initiated)
226 GNUNET_TRANSPORT_CS_OUTBOUND = 0,
229 * this is an inbound connection (communicator initiated)
231 GNUNET_TRANSPORT_CS_INBOUND = 1
236 * Notify transport service that a MQ became available due to an
237 * "inbound" connection or because the communicator discovered the
238 * presence of another peer.
240 * @param ch connection to transport service
241 * @param peer peer with which we can now communicate
242 * @param address address in human-readable format, 0-terminated, UTF-8
243 * @param mtu maximum message size supported by queue, 0 if
244 * sending is not supported, SIZE_MAX for no MTU
245 * @param nt which network type does the @a address belong to?
246 * @param cs what is the connection status of the queue?
247 * @param mq message queue of the @a peer
248 * @return API handle identifying the new MQ
250 struct GNUNET_TRANSPORT_QueueHandle *
251 GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
252 const struct GNUNET_PeerIdentity *peer,
255 enum GNUNET_NetworkType nt,
256 enum GNUNET_TRANSPORT_ConnectionStatus cs,
257 struct GNUNET_MQ_Handle *mq);
261 * Notify transport service that an MQ became unavailable due to a
262 * disconnect or timeout.
264 * @param qh handle for the queue that must be invalidated
267 GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh);
271 * Internal representation of an address a communicator is
272 * currently providing for the transport service.
274 struct GNUNET_TRANSPORT_AddressIdentifier;
278 * Notify transport service about an address that this communicator
279 * provides for this peer.
281 * @param ch connection to transport service
282 * @param address our address in human-readable format, 0-terminated, UTF-8
283 * @param nt which network type does the address belong to?
284 * @param expiration when does the communicator forsee this address expiring?
286 struct GNUNET_TRANSPORT_AddressIdentifier *
287 GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
289 enum GNUNET_NetworkType nt,
290 struct GNUNET_TIME_Relative expiration);
294 * Notify transport service about an address that this communicator
295 * no longer provides for this peer.
297 * @param ai address that is no longer provided
300 GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIdentifier *ai);
304 * The communicator asks the transport service to route a message via
305 * a different path to another communicator service at another peer.
306 * This must only be done for special control traffic (as there is no
307 * flow control for this API), such as acknowledgements, and generally
308 * only be done if the communicator is uni-directional (i.e. cannot
309 * send the message back itself).
311 * @param ch handle of this communicator
312 * @param pid peer to send the message to
313 * @param comm name of the communicator to send the message to
314 * @param header header of the message to transmit and pass via the
315 * notify-API to @a pid's communicator @a comm
318 GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
319 const struct GNUNET_PeerIdentity *pid,
321 const struct GNUNET_MessageHeader *header);
324 #if 0 /* keep Emacsens' auto-indent happy */
331 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
334 /** @} */ /* end of group */
336 /* end of gnunet_transport_communicator_service.h */