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
56 #define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED UINT64_MAX
59 * Function called by the transport service to initialize a
60 * message queue given address information about another peer.
61 * If and when the communication channel is established, the
62 * communicator must call #GNUNET_TRANSPORT_communicator_mq_add()
63 * to notify the service that the channel is now up. It is
64 * the responsibility of the communicator to manage sane
65 * retries and timeouts for any @a peer/@a address combination
66 * provided by the transport service. Timeouts and retries
67 * do not need to be signalled to the transport service.
70 * @param peer identity of the other peer
71 * @param address where to send the message, human-readable
72 * communicator-specific format, 0-terminated, UTF-8
73 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is
76 typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) (
78 const struct GNUNET_PeerIdentity *peer,
83 * Opaque handle to the transport service for communicators.
85 struct GNUNET_TRANSPORT_CommunicatorHandle;
89 * What characteristics does this communicator have?
91 * FIXME: may want to distinguish bi-directional as well,
92 * should we define a bit for that? Needed in DV logic (handle_dv_learn)!
94 enum GNUNET_TRANSPORT_CommunicatorCharacteristics
97 * Characteristics are unknown (i.e. DV).
99 GNUNET_TRANSPORT_CC_UNKNOWN = 0,
102 * Transmission is reliabile (with ACKs), i.e. TCP/HTTP/HTTPS.
104 GNUNET_TRANSPORT_CC_RELIABLE = 1,
107 * Transmission is unreliable (i.e. UDP)
109 GNUNET_TRANSPORT_CC_UNRELIABLE = 2
114 * Function called when the transport service has received a
115 * backchannel message for this communicator (!) via a different
118 * Typically used to receive messages of type
119 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS or
120 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
121 * as well as communicator-specific messages to assist with
125 * @param sender which peer sent the notification
128 typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) (
130 const struct GNUNET_PeerIdentity *sender,
131 const struct GNUNET_MessageHeader *msg);
135 * Connect to the transport service.
137 * @param cfg configuration to use
138 * @param config_section section of the configuration to use for options
139 * @param addr_prefix address prefix for addresses supported by this
140 * communicator, could be NULL for incoming-only communicators
141 * @param cc what characteristics does the communicator have?
142 * @param mq_init function to call to initialize a message queue given
143 * the address of another peer, can be NULL if the
144 * communicator only supports receiving messages
145 * @param mq_init_cls closure for @a mq_init
146 * @param notify_cb function to pass backchannel messages to communicator
147 * @param notify_cb_cls closure for @a notify_cb
148 * @return NULL on error
150 struct GNUNET_TRANSPORT_CommunicatorHandle *
151 GNUNET_TRANSPORT_communicator_connect (
152 const struct GNUNET_CONFIGURATION_Handle *cfg,
153 const char *config_section_name,
154 const char *addr_prefix,
155 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
156 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
158 GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
159 void *notify_cb_cls);
163 * Disconnect from the transport service.
165 * @param ch handle returned from connect
168 GNUNET_TRANSPORT_communicator_disconnect (
169 struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
172 /* ************************* Receiving *************************** */
175 * Function called to notify communicator that we have received
176 * and processed the message. Used for flow control (if supported
177 * by the communicator).
180 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
181 * #GNUNET_OK on success
184 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
189 * Notify transport service that the communicator has received
192 * @param handle connection to transport service
193 * @param sender presumed sender of the message (details to be checked
195 * @param msg the message
196 * @param expected_addr_validity how long does the communicator believe it
197 * will continue to be able to receive messages from the same address
198 * on which it received this message?
199 * @param cb function to call once handling the message is done, NULL if
200 * flow control is not supported by this communicator
201 * @param cb_cls closure for @a cb
202 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
203 * immediately dropped due to memory limitations (communicator
204 * should try to apply back pressure),
205 * #GNUNET_SYSERR if the message could not be delivered because
206 * the tranport service is not yet up
209 GNUNET_TRANSPORT_communicator_receive (
210 struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
211 const struct GNUNET_PeerIdentity *sender,
212 const struct GNUNET_MessageHeader *msg,
213 struct GNUNET_TIME_Relative expected_addr_validity,
214 GNUNET_TRANSPORT_MessageCompletedCallback cb,
218 /* ************************* Discovery *************************** */
221 * Handle returned to identify the internal data structure the transport
222 * API has created to manage a message queue to a particular peer.
224 struct GNUNET_TRANSPORT_QueueHandle;
228 * Possible states of a connection.
230 enum GNUNET_TRANSPORT_ConnectionStatus
233 * Connection is down.
235 GNUNET_TRANSPORT_CS_DOWN = -1,
238 * this is an outbound connection (transport initiated)
240 GNUNET_TRANSPORT_CS_OUTBOUND = 0,
243 * this is an inbound connection (communicator initiated)
245 GNUNET_TRANSPORT_CS_INBOUND = 1
250 * Notify transport service that a MQ became available due to an
251 * "inbound" connection or because the communicator discovered the
252 * presence of another peer.
254 * @param ch connection to transport service
255 * @param peer peer with which we can now communicate
256 * @param address address in human-readable format, 0-terminated, UTF-8
257 * @param mtu maximum message size supported by queue, 0 if
258 * sending is not supported, SIZE_MAX for no MTU
259 * @param q_len number of messages that can be send through this queue
260 * @param priority queue priority. Queues with highest priority should be
262 * @param nt which network type does the @a address belong to?
263 * @param cs what is the connection status of the queue?
264 * @param mq message queue of the @a peer
265 * @return API handle identifying the new MQ
267 struct GNUNET_TRANSPORT_QueueHandle *
268 GNUNET_TRANSPORT_communicator_mq_add (
269 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
270 const struct GNUNET_PeerIdentity *peer,
275 enum GNUNET_NetworkType nt,
276 enum GNUNET_TRANSPORT_ConnectionStatus cs,
277 struct GNUNET_MQ_Handle *mq);
280 * Notify transport service that an MQ was updated
282 * @param ch connection to transport service
283 * @param qh the queue to update
284 * @param q_len number of messages that can be send through this queue
285 * @param priority queue priority. Queues with highest priority should be
289 GNUNET_TRANSPORT_communicator_mq_update (
290 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
291 const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
296 * Notify transport service that an MQ became unavailable due to a
297 * disconnect or timeout.
299 * @param qh handle for the queue that must be invalidated
302 GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh);
306 * Internal representation of an address a communicator is
307 * currently providing for the transport service.
309 struct GNUNET_TRANSPORT_AddressIdentifier;
313 * Notify transport service about an address that this communicator
314 * provides for this peer.
316 * @param ch connection to transport service
317 * @param address our address in human-readable format, 0-terminated, UTF-8
318 * @param nt which network type does the address belong to?
319 * @param expiration when does the communicator forsee this address expiring?
321 struct GNUNET_TRANSPORT_AddressIdentifier *
322 GNUNET_TRANSPORT_communicator_address_add (
323 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
325 enum GNUNET_NetworkType nt,
326 struct GNUNET_TIME_Relative expiration);
330 * Notify transport service about an address that this communicator
331 * no longer provides for this peer.
333 * @param ai address that is no longer provided
336 GNUNET_TRANSPORT_communicator_address_remove (
337 struct GNUNET_TRANSPORT_AddressIdentifier *ai);
341 * The communicator asks the transport service to route a message via
342 * a different path to another communicator service at another peer.
343 * This must only be done for special control traffic (as there is no
344 * flow control for this API), such as acknowledgements, and generally
345 * only be done if the communicator is uni-directional (i.e. cannot
346 * send the message back itself).
348 * While backchannel messages are signed and encrypted, communicators
349 * must protect against replay attacks when using this backchannel
352 * @param ch handle of this communicator
353 * @param pid peer to send the message to
354 * @param comm name of the communicator to send the message to
355 * @param header header of the message to transmit and pass via the
356 * notify-API to @a pid's communicator @a comm
359 GNUNET_TRANSPORT_communicator_notify (
360 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
361 const struct GNUNET_PeerIdentity *pid,
363 const struct GNUNET_MessageHeader *header);
366 #if 0 /* keep Emacsens' auto-indent happy */
373 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
376 /** @} */ /* end of group */
378 /* end of gnunet_transport_communicator_service.h */