2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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"
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.
59 * @param peer identity of the other peer
60 * @param address where to send the message, human-readable
61 * communicator-specific format, 0-terminated, UTF-8
62 * @return NULL if the provided address is invalid, otherwise an MQ to
63 * send messages to that peer
65 typedef struct GNUNET_MQ_Handle *
66 (*GNUNET_TRANSPORT_CommunicatorMqInit) (void *cls,
67 const struct GNUNET_PeerIdentity *peer,
72 * Opaque handle to the transport service for communicators.
74 struct GNUNET_TRANSPORT_CommunicatorHandle;
78 * Connect to the transport service.
80 * @param cfg configuration to use
81 * @param name name of the communicator that is connecting
82 * @param mtu maximum message size supported by communicator, 0 if
83 * sending is not supported
84 * @param mq_init function to call to initialize a message queue given
85 * the address of another peer, can be NULL if the
86 * communicator only supports receiving messages
87 * @param mq_init_cls closure for @a mq_init
88 * @return NULL on error
90 struct GNUNET_TRANSPORT_CommunicatorHandle *
91 GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
94 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
99 * Disconnect from the transport service.
101 * @param ch handle returned from connect
104 GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
107 /* ************************* Receiving *************************** */
110 * Function called to notify communicator that we have received
111 * and processed the message.
114 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
115 * #GNUNET_OK on success
118 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
123 * Notify transport service that the communicator has received
126 * @param handle connection to transport service
127 * @param sender presumed sender of the message (details to be checked
129 * @param msg the message
130 * @param cb function to call once handling the message is done, NULL if
131 * flow control is not supported by this communicator
132 * @param cb_cls closure for @a cb
133 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
134 * immediately dropped due to memory limitations (communicator
135 * should try to apply back pressure),
136 * #GNUNET_SYSERR if the message is ill formed and communicator
137 * should try to reset stream
140 GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
141 const struct GNUNET_PeerIdentity *sender,
142 const struct GNUNET_MessageHeader *msg,
143 GNUNET_TRANSPORT_MessageCompletedCallback cb,
147 /* ************************* Discovery *************************** */
151 * Notify transport service that an MQ became available due to an
152 * "inbound" connection or because the communicator discovered the
153 * presence of another peer.
155 * @param handle connection to transport service
156 * @param peer peer with which we can now communicate
157 * @param address address in human-readable format, 0-terminated, UTF-8
158 * @param nt which network type does the @a address belong to?
159 * @param mq message queue of the @a peer
162 GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
163 const struct GNUNET_PeerIdentity *peer,
165 enum GNUNET_ATS_Network_Type nt,
166 struct GNUNET_MQ_Handle *mq);
170 * Notify transport service that an MQ became unavailable due to a
171 * disconnect or timeout.
173 * @param handle connection to transport service
174 * @param peer peer with which we can no longer communicate via the given mq
175 * @param address address in human-readable format, 0-terminated, UTF-8
176 * @param nt which network type does the @a address belong to?
177 * @param mq message queue of the @a peer
180 GNUNET_TRANSPORT_communicator_mq_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
181 const struct GNUNET_PeerIdentity *peer,
183 enum GNUNET_ATS_Network_Type nt,
184 struct GNUNET_MQ_Handle *mq);
188 * Notify transport service about an address that this communicator
189 * provides for this peer.
191 * @param handle connection to transport service
192 * @param address our address in human-readable format, 0-terminated, UTF-8
193 * @param nt which network type does the address belong to?
194 * @param expiration when does the communicator forsee this address expiring?
197 GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
199 enum GNUNET_ATS_Network_Type nt,
200 struct GNUNET_TIME_Absolute expiration);
204 * Notify transport service about an address that this communicator
205 * no longer provides for this peer.
207 * @param handle connection to transport service
208 * @param address our former address in human-readable format,
209 * 0-terminated, in UTF-8
212 GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
213 const char *address);
216 #if 0 /* keep Emacsens' auto-indent happy */
223 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
226 /** @} */ /* end of group */
228 /* end of gnunet_transport_communicator_service.h */